fix run_replay
This commit is contained in:
@ -433,37 +433,29 @@ impl InstructionEmitter<StepInstruction> for Session{
|
||||
|
||||
#[cfg(test)]
|
||||
mod test{
|
||||
use crate::{file,physics,session};
|
||||
use crate::{file,physics};
|
||||
#[test]
|
||||
fn run_replay(){
|
||||
let map=file::load("bhop_maps/5692113331.snfm");
|
||||
let bot=file::load("replays/703s+098360278ns.snfb");
|
||||
println!("loading map file..");
|
||||
let map=file::load("../tools/bhop_maps/5692113331.snfm");
|
||||
println!("loading bot file..");
|
||||
let bot=file::load("../tools/replays/534s+997497968ns.snfb");
|
||||
if let (Ok(file::Format2::Map(map)),Ok(file::Format2::Bot(bot)))=(map,bot){
|
||||
// create recording
|
||||
let recording=session::Recording::new(bot.instructions);
|
||||
|
||||
// create timer starting at first instruction (or zero if the list is empty)
|
||||
let new_time=recording.instructions.first().map_or(physics::Time::ZERO,|ins|ins.time);
|
||||
let end_time=recording.instructions.last().map_or(physics::Time::ZERO,|ins|ins.time);
|
||||
let timer=strafesnet_common::timer::Timer::unpaused(strafesnet_common::session::Time::ZERO,new_time);
|
||||
|
||||
// create default physics state
|
||||
let simulation=session::Simulation::new(timer,Default::default());
|
||||
|
||||
// invent a new bot id and insert the replay
|
||||
let mut replay=session::Replay::new(
|
||||
recording,
|
||||
simulation,
|
||||
);
|
||||
let mut data=physics::PhysicsData::default();
|
||||
println!("loading map..");
|
||||
data.generate_models(&map);
|
||||
let mut physics_data=physics::PhysicsData::default();
|
||||
println!("generating models..");
|
||||
physics_data.generate_models(&map);
|
||||
println!("simulating...");
|
||||
replay.advance(&data,(end_time-new_time).coerce());
|
||||
match replay.simulation.physics.get_finish_time(){
|
||||
let mut physics=physics::PhysicsState::default();
|
||||
for ins in bot.instructions{
|
||||
physics::PhysicsContext::run_input_instruction(&mut physics,&physics_data,ins);
|
||||
}
|
||||
match physics.get_finish_time(){
|
||||
Some(time)=>println!("finish time:{}",time),
|
||||
None=>println!("simulation did not end in finished state"),
|
||||
}
|
||||
}else{
|
||||
panic!("missing files");
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
|
Reference in New Issue
Block a user