From 165c38a06b2ca9601365a77351d447644d7986b7 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Wed, 7 Aug 2024 17:08:31 -0700 Subject: [PATCH] physics: rework jumping and boosters --- Cargo.lock | 30 +++++++++++++++++++++--------- Cargo.toml | 4 ++-- src/physics.rs | 27 ++++++++++----------------- 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b658757..ae003db 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -326,9 +326,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.7" +version = "1.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26a5c3fd7bfa1ce3897a3a3501d362b2d87b7f2583ebcb4a949ec25911025cbc" +checksum = "504bdec147f2cc13c8b57ed9401fd8a147cc66b67ad5cb241394244f2c947549" dependencies = [ "jobserver", "libc", @@ -1890,7 +1890,7 @@ dependencies = [ "parking_lot", "pollster", "strafesnet_bsp_loader", - "strafesnet_common", + "strafesnet_common 0.3.0", "strafesnet_deferred_loader", "strafesnet_rbx_loader", "strafesnet_snf", @@ -1905,7 +1905,7 @@ source = "sparse+https://git.itzana.me/api/packages/strafesnet/cargo/" checksum = "6d4af68c422b5f57febbaa218f44ba02d413fd25e84afff9e45e557a8caee2ce" dependencies = [ "glam", - "strafesnet_common", + "strafesnet_common 0.2.3", "vbsp", "vmdl", ] @@ -1921,6 +1921,18 @@ dependencies = [ "id", ] +[[package]] +name = "strafesnet_common" +version = "0.3.0" +source = "sparse+https://git.itzana.me/api/packages/strafesnet/cargo/" +checksum = "1077d45a0b064964906a57de765a5a2bfe47b41f2f807d13b18c70765e76d3dd" +dependencies = [ + "arrayvec", + "bitflags 2.6.0", + "glam", + "id", +] + [[package]] name = "strafesnet_deferred_loader" version = "0.3.1" @@ -1928,7 +1940,7 @@ source = "sparse+https://git.itzana.me/api/packages/strafesnet/cargo/" checksum = "c3891dcbdbc20b03cf561786b810e839ae7c11dd8810fd005f2474805ee9cccc" dependencies = [ "lazy-regex", - "strafesnet_common", + "strafesnet_common 0.2.3", "vbsp", ] @@ -1946,18 +1958,18 @@ dependencies = [ "rbx_mesh", "rbx_reflection_database", "rbx_xml", - "strafesnet_common", + "strafesnet_common 0.2.3", ] [[package]] name = "strafesnet_snf" -version = "0.1.1" +version = "0.1.2" source = "sparse+https://git.itzana.me/api/packages/strafesnet/cargo/" -checksum = "78479f73437a3f10230efd2304be0f3ef30dff98c54d93613ed1621bfd6a7da6" +checksum = "d12fc351b2af5fd7a8183175d55ac43e21eb8fd1f76cc70cd4713c0d1a556c96" dependencies = [ "binrw 0.14.0", "id", - "strafesnet_common", + "strafesnet_common 0.3.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 070640b..d0cea52 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,10 +23,10 @@ id = { version = "0.1.0", registry = "strafesnet" } parking_lot = "0.12.1" pollster = "0.3.0" strafesnet_bsp_loader = { version = "0.1.3", registry = "strafesnet", optional = true } -strafesnet_common = { version = "0.2.1", registry = "strafesnet" } +strafesnet_common = { version = "0.3.0", registry = "strafesnet" } strafesnet_deferred_loader = { version = "0.3.1", features = ["legacy"], registry = "strafesnet", optional = true } strafesnet_rbx_loader = { version = "0.3.2", registry = "strafesnet", optional = true } -strafesnet_snf = { version = "0.1.0", registry = "strafesnet", optional = true } +strafesnet_snf = { version = "0.1.2", registry = "strafesnet", optional = true } wgpu = "22.0.0" winit = "0.30.4" diff --git a/src/physics.rs b/src/physics.rs index 17c0d8b..daacd0b 100644 --- a/src/physics.rs +++ b/src/physics.rs @@ -1325,25 +1325,10 @@ fn atomic_internal_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:Tim if let Some(mode)=data.modes.get_mode(state.mode_state.get_mode_id()){ run_teleport_behaviour(&general.wormhole,&data.models,mode,&state.style,&data.hitbox_mesh,&mut state.mode_state,&mut state.touching,&mut state.body,convex_mesh_id); } - match &general.booster{ - Some(booster)=>{ - //DELETE THIS when boosters get converted to height machines - match booster{ - //&gameplay_attributes::Booster::Affine(transform)=>v=transform.transform_point3(v), - &gameplay_attributes::Booster::Velocity(velocity)=>{ - let boosted_velocity=state.body.velocity+velocity; - //fall through boosters - state.cull_velocity(data,boosted_velocity); - }, - &gameplay_attributes::Booster::Energy{direction: _,energy: _}=>todo!(), - } - }, - None=>(), - } if state.style.get_control(Controls::Jump,state.input_state.controls){ if let (Some(jump_settings),Some(walk_state))=(&state.style.jump,state.move_state.get_walk_state()){ let jump_dir=walk_state.jump_direction.direction(&data.models,&data.hitbox_mesh,&walk_state.contact); - let jumped_velocity=jump_settings.jumped_velocity(&state.style,jump_dir,state.body.velocity); + let jumped_velocity=jump_settings.jumped_velocity(&state.style,jump_dir,state.body.velocity,general.booster.as_ref()); state.cull_velocity(data,jumped_velocity); } } @@ -1369,6 +1354,10 @@ fn atomic_internal_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:Tim (PhysicsCollisionAttributes::Intersect{intersecting:_,general},Collision::Intersect(_intersect))=>{ //I think that setting the velocity to 0 was preventing surface contacts from entering an infinite loop state.touching.insert(collision); + //insta booster! + if let Some(booster)=&general.booster{ + state.cull_velocity(data,booster.boost(state.body.velocity)); + } if let Some(mode)=data.modes.get_mode(state.mode_state.get_mode_id()){ let zone=mode.get_zone(convex_mesh_id.model_id.into()); match zone{ @@ -1526,7 +1515,11 @@ fn atomic_input_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedI if let Some(walk_state)=state.move_state.get_walk_state(){ if let Some(jump_settings)=&state.style.jump{ let jump_dir=walk_state.jump_direction.direction(&data.models,&data.hitbox_mesh,&walk_state.contact); - let jumped_velocity=jump_settings.jumped_velocity(&state.style,jump_dir,state.body.velocity); + let booster_option=match data.models.attr(walk_state.contact.convex_mesh_id.model_id){ + PhysicsCollisionAttributes::Contact{contacting:_,general}=>general.booster.as_ref(), + PhysicsCollisionAttributes::Intersect{..}=>None, + }; + let jumped_velocity=jump_settings.jumped_velocity(&state.style,jump_dir,state.body.velocity,booster_option); state.cull_velocity(&data,jumped_velocity); } }