From b6b090de78fc21b2c8364d101d748f3729e2deb3 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Wed, 22 Jan 2025 06:45:56 -0800 Subject: [PATCH] physics: place version code into lib.rs --- engine/physics/src/lib.rs | 39 +++++++++++++++++++++++++++++++++++ engine/physics/src/physics.rs | 39 ----------------------------------- engine/session/src/session.rs | 2 +- 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/engine/physics/src/lib.rs b/engine/physics/src/lib.rs index 8d255ef..f78e037 100644 --- a/engine/physics/src/lib.rs +++ b/engine/physics/src/lib.rs @@ -4,3 +4,42 @@ mod face_crawler; mod model; pub mod physics; + +// Physics bug fixes can easily desync all bots. +// +// When replaying a bot, use the exact physics version which it was recorded with. +// +// When validating a new bot, ignore the version and use the latest version, +// and overwrite the version in the file. +// +// Compatible physics versions should be determined +// empirically at development time via leaderboard resimulation. +// +// Compatible physics versions should result in an identical leaderboard state, +// or the only bots which fail are ones exploiting a surgically patched bug. +#[derive(Clone,Copy,Hash,Debug,id::Id,Eq,PartialEq,Ord,PartialOrd)] +pub struct PhysicsVersion(u32); +pub const VERSION:PhysicsVersion=PhysicsVersion(0); +const LATEST_COMPATIBLE_VERSION:[u32;1+VERSION.0 as usize]=const{ + let compat=[0]; + + let mut input_version=0; + while input_versionResult{ + if (version as usize)Result{ - if (version as usize); type MouseState=strafesnet_common::mouse::MouseState; diff --git a/engine/session/src/session.rs b/engine/session/src/session.rs index 5b1fa0d..7749f2b 100644 --- a/engine/session/src/session.rs +++ b/engine/session/src/session.rs @@ -299,7 +299,7 @@ impl InstructionConsumer> for Session{ std::thread::spawn(move ||{ std::fs::create_dir_all("replays").unwrap(); let file=std::fs::File::create(file_name).unwrap(); - strafesnet_snf::bot::write_bot(std::io::BufWriter::new(file),physics::VERSION.get(),replay.recording.instructions).unwrap(); + strafesnet_snf::bot::write_bot(std::io::BufWriter::new(file),strafesnet_physics::VERSION.get(),replay.recording.instructions).unwrap(); println!("Finished writing bot file!"); }); },