use crate::error::ReplayError;
use crate::util::read_entire_file;
use strafesnet_physics::physics::{PhysicsData,PhysicsState,PhysicsContext};

#[test]
#[ignore]
fn physics_bug_2()->Result<(),ReplayError>{
	println!("loading map file..");
	let data=read_entire_file("test_files/bhop_monster_jam.snfm")?;
	let map=strafesnet_snf::read_map(data)?.into_complete_map()?;

	// create recording
	println!("generating models..");
	let physics_data=PhysicsData::new(&map);
	println!("simulating...");

	//teleport to bug
	// body pos = Vector { array: [Fixed { bits: 554895163352 }, Fixed { bits: 1485633089990 }, Fixed { bits: 1279601007173 }] }
	// after the fix it's still happening, possibly for a different reason, new position to evince:
	// body pos = Vector { array: [Fixed { bits: 555690659654 }, Fixed { bits: 1490485868773 }, Fixed { bits: 1277783839382 }] }
	use strafesnet_common::integer::{vec3,Time};
	let body=strafesnet_physics::physics::Body::new(
		vec3::raw_xyz(555690659654,1490485868773,1277783839382),
		vec3::int(0,0,0),
		Time::ZERO,
	);
	let mut physics=PhysicsState::new_with_body(body);
	// wait one second to activate the bug
	// hit=Some(ModelId(2262))
	PhysicsContext::run_input_instruction(&mut physics,&physics_data,strafesnet_common::instruction::TimedInstruction{
		time:Time::from_millis(500),
		instruction:strafesnet_common::physics::Instruction::Idle,
	});

	Ok(())
}

#[test]
#[ignore]
fn physics_bug_3()->Result<(),ReplayError>{
	println!("loading map file..");
	let data=read_entire_file("../tools/bhop_maps/5692152916.snfm")?;
	let map=strafesnet_snf::read_map(data)?.into_complete_map()?;

	// create recording
	println!("generating models..");
	let physics_data=PhysicsData::new(&map);
	println!("simulating...");

	//teleport to bug
	use strafesnet_common::integer::{vec3,Time};
	let body=strafesnet_physics::physics::Body::new(
		// bhop_toc corner position after wall hits
		// vec3::raw_xyz(-1401734815424,3315081280280,-2466057177493),
		// vec3::raw_xyz(0,-96915585363,1265),
		// vec3::raw_xyz(0,-429496729600,0),
		// alternate room center position
		// vec3::raw_xyz(-1129043783837,3324870327882,-2014012350212),
		// vec3::raw_xyz(0,-96915585363,1265),
		// vec3::raw_xyz(0,-429496729600,0),
		// corner setup before wall hits
		// vec3::raw_xyz(-1392580080675,3325402529458,-2444727738679),
		// vec3::raw_xyz(-30259028820,-22950929553,-71141663007),
		// vec3::raw_xyz(0,-429496729600,0),
		// Actual bug 3 repro
		vec3::raw_xyz(-2505538624455,3357963283914,557275711118),
		vec3::raw_xyz(204188283920,-282280474198,166172785440),
		Time::ZERO,
	);
	let mut physics=PhysicsState::new_with_body(body);
	// wait one second to activate the bug
	PhysicsContext::run_input_instruction(&mut physics,&physics_data,strafesnet_common::instruction::TimedInstruction{
		time:Time::from_millis(500),
		instruction:strafesnet_common::physics::Instruction::Idle,
	});

	Ok(())
}
