use urt_gameplay::client_timer::*; fn main() { let mut args = std::env::args().skip(1); let kind = args.next().unwrap(); let w: Vec = args.map(|s| s.parse().unwrap()).collect(); match kind.as_str() { "terminal" => { assert_eq!(w.len(), 8); let mut state = TimerTerminalState { entity_flag: w[5], client_flags: w[3], elapsed_total: w[6], }; let input = TimerTerminalInput { stamp: w[0], cooldown: w[1], tick: w[2], deadline: w[4], msec: w[7], }; timer_entity_deadline(&mut state, input); timer_terminal_tail(&mut state, input); println!( r#"{{"entity_flag":{},"client_flags":{},"elapsed_total":{},"deadline":{},"stamp":{}}}"#, state.entity_flag, state.client_flags, state.elapsed_total, input.deadline, input.stamp ); } "tick" => println!("{}", tick(&w)), "complete" => println!("{}", complete(&w)), "prepare" => { assert_eq!(w.len(), 6); let mut state = TimerPrepareState { connection: w[0], exception: w[1], command_time: w[2], current_time: w[3], quantize: w[4], copied_tick: 17, copied_command: 18, }; let out = prepare_client_timing(&mut state, w[5]); println!( r#"{{"proceed":{},"msec":{},"command_time":{},"current_time":{},"copied_tick":{},"copied_command":{}}}"#, out.proceed, out.msec.map(|v| v.to_string()).unwrap_or("null".into()), state.command_time, state.current_time, state.copied_tick, state.copied_command ); } _ => panic!("unknown timer policy"), } } fn list(v: &[u32]) -> String { format!( "[{}]", v.iter() .map(|v| v.to_string()) .collect::>() .join(",") ) } fn damage_json(v: &[TimerDamage]) -> String { v.iter().map(|r|format!(r#"{{"target":{},"inflictor":{},"attacker":{},"direction":{},"point":{},"amount":{},"flags":{},"means":{},"weapon":{}}}"#,r.target,r.inflictor,r.attacker,r.direction,r.point,r.amount,r.flags,r.means,r.weapon)).collect::>().join(",") } fn loop_state(w: &[u32]) -> TimerLoopState { TimerLoopState { flags: w[0], status: w[1], rate: w[2], phase: w[3], timer: w[4], residual: w[5], } } fn loop_words(s: TimerLoopState) -> [u32; 6] { [s.flags, s.status, s.rate, s.phase, s.timer, s.residual] } fn tick(w: &[u32]) -> String { assert_eq!(w.len(), 8); let mut s = loop_state(w); let input = TimerLoopInput { health: w[6], weapon: w[7], target: 2, owner: 3, }; let damage = timer_tick_loop(&mut s, input).unwrap(); format!( r#"{{"damage":[{}],"state":{},"health":{}}}"#, damage_json(&damage), list(&loop_words(s)), w[6] ) } fn digest(rows: &[urt_gameplay::native_policy::FilterRecord]) -> u64 { let mut h = 14695981039346656037u64; for r in rows { for w in [r.mask, r.comparison, r.metadata] { for b in w.to_le_bytes() { h = (h ^ b as u64).wrapping_mul(1099511628211); } } } h } fn expiry_rows(now: u32) -> Vec { let mut rows: Vec<_> = (0..4096) .map(|j| urt_gameplay::native_policy::FilterRecord { mask: 0x11223344, comparison: j + 1, metadata: u32::MAX, }) .collect(); for (j, t) in [0usize, 1, 2, 3, 4, 5, 63, 4095].into_iter().zip([ 0, now.wrapping_sub(1), now, now.wrapping_add(1), u32::MAX, 0x80000000, 60, 0, ]) { rows[j].metadata = t; } rows[5].comparison = u32::MAX; rows } fn complete(w: &[u32]) -> String { assert_eq!(w.len(), 24); let mut rows = expiry_rows(w[22]); let mut s = CompleteTimerState { activity: w[19], entity_bit: 17, terminal: TimerTerminalState { entity_flag: w[13], client_flags: w[11], elapsed_total: w[14], }, ticks: loop_state(w), }; let input = CompleteTimerInput { time: TimerTerminalInput { stamp: w[8], cooldown: w[9], tick: w[10], deadline: w[12], msec: w[15], }, velocity: [w[16], w[17], w[18]], last_tick: w[20], entity_bits: w[21], now: w[22], damage: TimerLoopInput { health: w[6], weapon: w[7], target: 2, owner: 3, }, }; let out = complete_client_timer(&mut rows, &mut s, input).unwrap(); let events = out .events .iter() .map(|e| match e { TimerEvent::Time => r#"{"op":"time"}"#.into(), TimerEvent::Damage(d) => { let raw = damage_json(&[*d]); format!("{{\"op\":\"damage\",{}", &raw[1..]) } }) .collect::>() .join(","); format!( r#"{{"events":[{}],"vector_squared":[{}],"prefix":[{},{}],"terminal":[{},{},{}],"state":{},"health":{},"velocity":{},"last_tick":{},"count":{},"checksum":{}}}"#, events, out.vector_squared .map(|v| v.to_string()) .unwrap_or_default(), s.activity, s.entity_bit, s.terminal.entity_flag, s.terminal.client_flags, s.terminal.elapsed_total, list(&loop_words(s.ticks)), w[6], list(&input.velocity), input.last_tick, w[23], digest(&rows) ) }