physics: place version code into lib.rs
This commit is contained in:
parent
affbada62e
commit
b6b090de78
@ -4,3 +4,42 @@ mod face_crawler;
|
|||||||
mod model;
|
mod model;
|
||||||
|
|
||||||
pub mod physics;
|
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_version<compat.len(){
|
||||||
|
// compatible version must be greater that or equal to the input version
|
||||||
|
assert!(input_version as u32<=compat[input_version]);
|
||||||
|
// compatible version must be a version that exists
|
||||||
|
assert!(compat[input_version]<=VERSION.0);
|
||||||
|
input_version+=1;
|
||||||
|
}
|
||||||
|
compat
|
||||||
|
};
|
||||||
|
pub enum PhysicsVersionError{
|
||||||
|
UnknownPhysicsVersion,
|
||||||
|
}
|
||||||
|
pub const fn get_latest_compatible_version(PhysicsVersion(version):PhysicsVersion)->Result<PhysicsVersion,PhysicsVersionError>{
|
||||||
|
if (version as usize)<LATEST_COMPATIBLE_VERSION.len(){
|
||||||
|
Ok(PhysicsVersion(LATEST_COMPATIBLE_VERSION[version as usize]))
|
||||||
|
}else{
|
||||||
|
Err(PhysicsVersionError::UnknownPhysicsVersion)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -14,45 +14,6 @@ use strafesnet_common::integer::{self,vec3,mat3,Planar64,Planar64Vec3,Planar64Ma
|
|||||||
pub use strafesnet_common::physics::{Time,TimeInner};
|
pub use strafesnet_common::physics::{Time,TimeInner};
|
||||||
use gameplay::ModeState;
|
use gameplay::ModeState;
|
||||||
|
|
||||||
// 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_version<compat.len(){
|
|
||||||
// compatible version must be greater that or equal to the input version
|
|
||||||
assert!(input_version as u32<=compat[input_version]);
|
|
||||||
// compatible version must be a version that exists
|
|
||||||
assert!(compat[input_version]<=VERSION.0);
|
|
||||||
input_version+=1;
|
|
||||||
}
|
|
||||||
compat
|
|
||||||
};
|
|
||||||
pub enum PhysicsVersionError{
|
|
||||||
UnknownPhysicsVersion,
|
|
||||||
}
|
|
||||||
pub const fn get_latest_compatible_version(PhysicsVersion(version):PhysicsVersion)->Result<PhysicsVersion,PhysicsVersionError>{
|
|
||||||
if (version as usize)<LATEST_COMPATIBLE_VERSION.len(){
|
|
||||||
Ok(PhysicsVersion(LATEST_COMPATIBLE_VERSION[version as usize]))
|
|
||||||
}else{
|
|
||||||
Err(PhysicsVersionError::UnknownPhysicsVersion)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type Body=crate::body::Body<TimeInner>;
|
pub type Body=crate::body::Body<TimeInner>;
|
||||||
type MouseState=strafesnet_common::mouse::MouseState<TimeInner>;
|
type MouseState=strafesnet_common::mouse::MouseState<TimeInner>;
|
||||||
|
|
||||||
|
@ -299,7 +299,7 @@ impl InstructionConsumer<Instruction<'_>> for Session{
|
|||||||
std::thread::spawn(move ||{
|
std::thread::spawn(move ||{
|
||||||
std::fs::create_dir_all("replays").unwrap();
|
std::fs::create_dir_all("replays").unwrap();
|
||||||
let file=std::fs::File::create(file_name).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!");
|
println!("Finished writing bot file!");
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user