From c9159e1ebfc8c6ac7fbcba84c45132a558af4068 Mon Sep 17 00:00:00 2001 From: MikolajG Date: Thu, 11 Jul 2024 14:10:54 +0200 Subject: [PATCH] Revert "stuff I did while I was away" This reverts commit 0fee74976c9b0e01633c8cb09ede341631eaee51. --- .cargo/config | 3 + .vscode/settings.json | 2 +- .vscode/tasks.json | 9 - Cargo.lock | 12 +- Cargo.toml | 3 +- src/config_utils.rs | 36 -- src/lib.rs | 6 +- src/main.rs | 2 +- src/player_utils/character_controller.rs | 434 ++++++++++++----------- src/player_utils/player_look.rs | 4 +- src/weapon_framework.rs | 1 - src/weapon_framework/gun_framework.rs | 25 -- 12 files changed, 239 insertions(+), 298 deletions(-) create mode 100644 .cargo/config delete mode 100644 src/config_utils.rs delete mode 100644 src/weapon_framework/gun_framework.rs diff --git a/.cargo/config b/.cargo/config new file mode 100644 index 0000000..ec26773 --- /dev/null +++ b/.cargo/config @@ -0,0 +1,3 @@ +[target.x86_64-unknown-linux-gnu] +linker = "clang" +rustflags = ["-Clink-arg=-fuse-ld=mold"] \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 89a5e75..ab4fd48 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,9 +1,9 @@ { + "rust-analyzer.debug.engine": "vadimcn.vscode-lldb", "cSpell.words": [ "Gamepad", "qeury", "Substep", "xpbd" ], - "rust-analyzer.checkOnSave": false } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 268c937..7856b66 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -48,15 +48,6 @@ "--run", "steam-run cargo fmt --all" ] - }, - { - "label": "generate docs", - "type": "shell", - "command": "nix-shell", - "args": [ - "--run", - "cargo doc" - ] } ] } \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 1bfcff3..4be259a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1209,8 +1209,7 @@ dependencies = [ [[package]] name = "bevy_xpbd_3d" version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0425ea7361b9b27c2a382e0663deb42f41147eee60fb2b3d5fa7e42d363ea848" +source = "git+https://git.opencodebox.com/MikolajG/bevy_xpbd?branch=reflect-serialize#489e53505abda9649a9ee6e9de6e03a7d5801e28" dependencies = [ "bevy", "bevy_math", @@ -1227,9 +1226,9 @@ dependencies = [ [[package]] name = "bevy_xpbd_derive" version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e1ef1d5e328abe1b76df974245f78e17fd17867583883d5e77444c6a8223a64" +source = "git+https://git.opencodebox.com/MikolajG/bevy_xpbd?branch=reflect-serialize#489e53505abda9649a9ee6e9de6e03a7d5801e28" dependencies = [ + "proc-macro2", "quote", "syn 2.0.55", ] @@ -3707,9 +3706,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.117" +version = "1.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" +checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" dependencies = [ "itoa", "ryu", @@ -4186,7 +4185,6 @@ dependencies = [ "embed-resource", "image", "rand", - "serde_json", "webbrowser", "winit", ] diff --git a/Cargo.toml b/Cargo.toml index 0b4a6a1..d6f4a87 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -68,12 +68,11 @@ bevy_asset_loader = { version = "0.20" } rand = { version = "0.8.3" } webbrowser = { version = "0.8", features = ["hardened"] } bevy_editor_pls = "0.8.1" -bevy_xpbd_3d = "0.4.2" +bevy_xpbd_3d = {git = "https://git.opencodebox.com/MikolajG/bevy_xpbd", branch = "reflect-serialize"} # keep the following in sync with Bevy's dependencies winit = { version = "0.29", default-features = false } image = { version = "0.24", default-features = false } -serde_json = "1.0.117" [build-dependencies] diff --git a/src/config_utils.rs b/src/config_utils.rs deleted file mode 100644 index 651da60..0000000 --- a/src/config_utils.rs +++ /dev/null @@ -1,36 +0,0 @@ -/* -Trouble in Terror Town: Community Edition -Copyright (C) 2024 Mikolaj Wojciech Gorski - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License 3.0 as published by -the Free Software Foundation. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -See the GNU General Public License 3.0 for more details. - -You should have received a copy of the GNU General Public License 3.0 -along with this program. If not, see . -*/ - -use bevy::prelude::*; -use serde::Deserialize; -use std::fs::*; -use std::time::{Duration, SystemTime}; - -#[derive(Deserialize, Clone, Debug)] -struct CharacterControllerConfig { - movement_acceleration: f32, - air_control_factor: f32, - movement_dampening_factor: f32, - jump_impulse: f32, - gravity: [f32; 3], - max_slope_angle: f32, - axis_speed_limit: f32, - max_acceleration: f32, - friction: f32, -} - - diff --git a/src/lib.rs b/src/lib.rs index 8b902e9..c3c85e7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -79,7 +79,7 @@ fn setup( commands, meshes, materials, - 0.7, + 0.5, CharacterControllerBundle::new(Collider::capsule(1.0, 0.5), CharacterController::default()), ); } @@ -105,9 +105,7 @@ fn spawn_map( RigidBody::Static, )); - - is_map_spawned.0 = true; - println!("map spawned!"); + is_map_spawned.0 = true } diff --git a/src/main.rs b/src/main.rs index 2d6b10d..265ac68 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,7 +34,7 @@ fn main() { .insert_resource(ClearColor(Color::rgb(0.4, 0.4, 0.4))) .add_plugins(DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { - title: "Trouble in Terror Town: Community Edition".to_string(), // ToDo + title: "Trouble in Terror Town: Source Crossed".to_string(), // ToDo // Bind to canvas included in `index.html` canvas: Some("#bevy".to_owned()), // Tells wasm not to override default event handling, like F5 and Ctrl+R diff --git a/src/player_utils/character_controller.rs b/src/player_utils/character_controller.rs index 02dbd0a..252e5e2 100644 --- a/src/player_utils/character_controller.rs +++ b/src/player_utils/character_controller.rs @@ -37,8 +37,8 @@ pub struct CharacterControllerPlugin; impl Plugin for CharacterControllerPlugin { fn build(&self, app: &mut App) { app.add_systems(Update, move_character); - app.add_systems(FixedUpdate, (apply_gravity, update_grounded, dampen_movement)); - app.add_systems(SubstepSchedule, collide_and_slide.in_set(SubstepSet::SolveUserConstraints)); + app.add_systems(FixedUpdate, (apply_gravity, update_grounded, dampen_movement,)); + app.add_systems(SubstepSchedule, kinematic_controller_collisions.in_set(SubstepSet::SolveUserConstraints)); } } @@ -52,12 +52,10 @@ pub struct CharacterController { pub air_control_factor: Scalar, pub movement_dampening_factor: Scalar, pub jump_impulse: Scalar, - /// direction in which gravity pulls the character look at [`new_fall_velocity`] pub gravity: Vector, pub max_slope_angle: Scalar, pub axis_speed_limit: f32, pub max_acceleration: f32, - /// value used for holding current calculated friction, do not change on spawn pub friction: f32, } @@ -67,7 +65,7 @@ impl Default for CharacterController { movement_acceleration: 20.0, air_control_factor: 0.5, movement_dampening_factor: 0.95, - jump_impulse: 6.0, + jump_impulse: 4.0, gravity: Vector::NEG_Y * 9.81 * 2.0, max_slope_angle: (45.0 as Scalar).to_radians(), axis_speed_limit: 6668.5, @@ -143,38 +141,212 @@ fn get_lateral_acceleration( } -/// project a point on a plane +// function "borrowed" from UE fn point_plane_project(point: Vec3, plane_base: Vec3, plane_normal: Vec3) -> Vec3 { - point - plane_normal * plane_normal.dot(point - plane_base) + let projection = point - plane_normal * plane_normal.dot(point - plane_base); + projection } -/// calculating gravity, later you'll have to pass custom terminal velocity +// function "borrowed" from UE fn new_fall_velocity(initial_velocity: LinearVelocity, gravity: Vec3, delta_time: f32, speed_limit: f32) -> Vec3 { let mut result: Vec3 = Vec3 { x: initial_velocity.x, y: initial_velocity.y, z: initial_velocity.z }; let terminal_velocity: f32 = 50.0; - // Apply gravity. - result += gravity * delta_time; + if delta_time > 0.0 + { - // Don't exceed terminal velocity. - let terminal_limit: f32 = f32::abs(terminal_velocity); //FMath::Abs(GetPhysicsVolume()->TerminalVelocity); - if result.length_squared() > (terminal_limit * terminal_limit) - { - let gravity_dir: Vec3 = gravity.normalize(); + // Apply gravity. + result += gravity * delta_time; - if result.y > terminal_limit || gravity_dir.y > terminal_limit + + // Don't exceed terminal velocity. + let terminal_limit: f32 = f32::abs(terminal_velocity); //FMath::Abs(GetPhysicsVolume()->TerminalVelocity); + if result.length_squared() > (terminal_limit * terminal_limit) { - result = point_plane_project(result, Vec3::ZERO, gravity_dir) + gravity_dir * terminal_limit; - } - } + let gravity_dir: Vec3 = gravity.normalize(); + + if result.y > terminal_limit || gravity_dir.y > terminal_limit + { + result = point_plane_project(result, Vec3::ZERO, gravity_dir) + gravity_dir * terminal_limit; + } + } + } result.z = f32::clamp(result.z, -speed_limit, speed_limit); return result; } +fn apply_gravity( + time: Res