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