tick fillup

This commit is contained in:
Robin Appelman 2022-09-18 17:01:45 +02:00
commit 7aa7961887
4 changed files with 84 additions and 80 deletions

60
Cargo.lock generated
View file

@ -4,9 +4,9 @@ version = 3
[[package]] [[package]]
name = "aho-corasick" name = "aho-corasick"
version = "0.7.18" version = "0.7.19"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e"
dependencies = [ dependencies = [
"memchr", "memchr",
] ]
@ -134,9 +134,9 @@ checksum = "3a471a38ef8ed83cd6e40aa59c1ffe17db6855c18e3604d9c4ed8c08ebc28678"
[[package]] [[package]]
name = "itertools" name = "itertools"
version = "0.10.3" version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" checksum = "d8bf247779e67a9082a4790b45e71ac7cfd1321331a5c856a74a9faebdab78d0"
dependencies = [ dependencies = [
"either", "either",
] ]
@ -149,9 +149,9 @@ checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754"
[[package]] [[package]]
name = "js-sys" name = "js-sys"
version = "0.3.59" version = "0.3.60"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "258451ab10b34f8af53416d1fdab72c22e805f0c92a1136d59470ec0b11138b2" checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47"
dependencies = [ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
@ -303,9 +303,9 @@ dependencies = [
[[package]] [[package]]
name = "once_cell" name = "once_cell"
version = "1.13.1" version = "1.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "074864da206b4973b84eb91683020dbefd6a8c3f0f38e054d93954e891935e4e" checksum = "2f7254b99e31cad77da24b08ebf628882739a608578bb1bcdfc1f9c21260d7c0"
[[package]] [[package]]
name = "parse-display" name = "parse-display"
@ -556,13 +556,13 @@ dependencies = [
"proc-macro2 1.0.43", "proc-macro2 1.0.43",
"quote 1.0.21", "quote 1.0.21",
"syn", "syn",
"unicode-xid 0.2.3", "unicode-xid 0.2.4",
] ]
[[package]] [[package]]
name = "tf-demo-parser" name = "tf-demo-parser"
version = "0.4.0" version = "0.4.0"
source = "git+https://github.com/demostf/parser#cf58a0609af6d135c09c8e0839a933e109938819" source = "git+https://github.com/demostf/parser#9e3f008e510a0b69cefd48e606adccb7669e700c"
dependencies = [ dependencies = [
"bitbuffer", "bitbuffer",
"enumflags2", "enumflags2",
@ -596,18 +596,18 @@ dependencies = [
[[package]] [[package]]
name = "thiserror" name = "thiserror"
version = "1.0.32" version = "1.0.35"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f5f6586b7f764adc0231f4c79be7b920e766bb2f3e51b3661cdb263828f19994" checksum = "c53f98874615aea268107765aa1ed8f6116782501d18e53d08b471733bea6c85"
dependencies = [ dependencies = [
"thiserror-impl", "thiserror-impl",
] ]
[[package]] [[package]]
name = "thiserror-impl" name = "thiserror-impl"
version = "1.0.32" version = "1.0.35"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12bafc5b54507e0149cdf1b145a5d80ab80a90bcd9275df43d4fff68460f6c21" checksum = "f8b463991b4eab2d801e724172285ec4195c650e8ec79b149e6c2a8e6dd3f783"
dependencies = [ dependencies = [
"proc-macro2 1.0.43", "proc-macro2 1.0.43",
"quote 1.0.21", "quote 1.0.21",
@ -625,9 +625,9 @@ dependencies = [
[[package]] [[package]]
name = "unicode-ident" name = "unicode-ident"
version = "1.0.3" version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd"
[[package]] [[package]]
name = "unicode-xid" name = "unicode-xid"
@ -637,9 +637,9 @@ checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
[[package]] [[package]]
name = "unicode-xid" name = "unicode-xid"
version = "0.2.3" version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]] [[package]]
name = "version_check" name = "version_check"
@ -649,9 +649,9 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]] [[package]]
name = "wasm-bindgen" name = "wasm-bindgen"
version = "0.2.82" version = "0.2.83"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d" checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"wasm-bindgen-macro", "wasm-bindgen-macro",
@ -659,9 +659,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-backend" name = "wasm-bindgen-backend"
version = "0.2.82" version = "0.2.83"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "662cd44805586bd52971b9586b1df85cdbbd9112e4ef4d8f41559c334dc6ac3f" checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142"
dependencies = [ dependencies = [
"bumpalo", "bumpalo",
"log", "log",
@ -687,9 +687,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro" name = "wasm-bindgen-macro"
version = "0.2.82" version = "0.2.83"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602" checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810"
dependencies = [ dependencies = [
"quote 1.0.21", "quote 1.0.21",
"wasm-bindgen-macro-support", "wasm-bindgen-macro-support",
@ -697,9 +697,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro-support" name = "wasm-bindgen-macro-support"
version = "0.2.82" version = "0.2.83"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da" checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c"
dependencies = [ dependencies = [
"proc-macro2 1.0.43", "proc-macro2 1.0.43",
"quote 1.0.21", "quote 1.0.21",
@ -710,9 +710,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-shared" name = "wasm-bindgen-shared"
version = "0.2.82" version = "0.2.83"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a" checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f"
[[package]] [[package]]
name = "wasm-bindgen-test" name = "wasm-bindgen-test"
@ -741,9 +741,9 @@ dependencies = [
[[package]] [[package]]
name = "web-sys" name = "web-sys"
version = "0.3.59" version = "0.3.60"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed055ab27f941423197eb86b2035720b1a3ce40504df082cac2ecc6ed73335a1" checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f"
dependencies = [ dependencies = [
"js-sys", "js-sys",
"wasm-bindgen", "wasm-bindgen",

View file

@ -1,7 +1,7 @@
{ {
"author": "Robin Appelman <robin@icewind.nl>", "author": "Robin Appelman <robin@icewind.nl>",
"name": "@demostf/parser-worker", "name": "@demostf/parser-worker",
"version": "0.1.0", "version": "0.1.1",
"scripts": { "scripts": {
"build": "rimraf dist pkg && webpack", "build": "rimraf dist pkg && webpack",
"start": "rimraf dist pkg && webpack-dev-server --open -d", "start": "rimraf dist pkg && webpack-dev-server --open -d",

View file

@ -84,7 +84,7 @@ impl FlatState {
boundaries: world.into(), boundaries: world.into(),
interval_per_tick: header.duration / (header.ticks as f32), interval_per_tick: header.duration / (header.ticks as f32),
data: flat.into_boxed_slice(), data: flat.into_boxed_slice(),
kill_ticks: parsed.kills.iter().map(|kill| kill.tick as u32).collect(), kill_ticks: parsed.kills.iter().map(|kill| kill.tick.into()).collect(),
attackers: parsed attackers: parsed
.kills .kills
.iter() .iter()
@ -185,14 +185,10 @@ pub fn parse_demo_inner(
let mut parsed_demo = ParsedDemo::new(header); let mut parsed_demo = ParsedDemo::new(header);
let mut skip = false;
while ticker.tick()? { while ticker.tick()? {
if !skip { parsed_demo.push_state(ticker.state());
// halve framerate let new_progress =
parsed_demo.push_state(ticker.state()); ((u32::from(ticker.state().tick) as f32 / total_ticks as f32) * 100.0).floor();
}
skip = !skip;
let new_progress = ((ticker.state().tick as f32 / total_ticks as f32) * 100.0).floor();
if new_progress > last_progress { if new_progress > last_progress {
last_progress = new_progress; last_progress = new_progress;
let _ = progress.call1(&JsValue::null(), &last_progress.into()); let _ = progress.call1(&JsValue::null(), &last_progress.into());

View file

@ -1,3 +1,4 @@
use tf_demo_parser::demo::data::DemoTick;
use tf_demo_parser::demo::header::Header; use tf_demo_parser::demo::header::Header;
use tf_demo_parser::demo::parser::analyser::UserInfo; use tf_demo_parser::demo::parser::analyser::UserInfo;
use tf_demo_parser::demo::parser::gamestateanalyser::{ use tf_demo_parser::demo::parser::gamestateanalyser::{
@ -25,6 +26,7 @@ impl From<Angle> for f32 {
#[derive(Debug)] #[derive(Debug)]
pub struct ParsedDemo { pub struct ParsedDemo {
last_tick: DemoTick,
pub tick: usize, pub tick: usize,
pub players: Vec<Vec<u8>>, pub players: Vec<Vec<u8>>,
pub buildings: Vec<Vec<u8>>, pub buildings: Vec<Vec<u8>>,
@ -37,6 +39,7 @@ pub struct ParsedDemo {
impl ParsedDemo { impl ParsedDemo {
pub fn new(header: Header) -> Self { pub fn new(header: Header) -> Self {
ParsedDemo { ParsedDemo {
last_tick: DemoTick::default(),
tick: 0, tick: 0,
players: Vec::new(), players: Vec::new(),
buildings: Vec::new(), buildings: Vec::new(),
@ -49,53 +52,58 @@ impl ParsedDemo {
pub fn push_state(&mut self, game_state: &GameState) { pub fn push_state(&mut self, game_state: &GameState) {
if let Some(world) = game_state.world.as_ref() { if let Some(world) = game_state.world.as_ref() {
for (index, player) in game_state.players.iter().enumerate() { for _tick in u32::from(self.last_tick)..u32::from(game_state.tick) {
let state = PlayerState { for (index, player) in game_state.players.iter().enumerate() {
position: player.position.into(), let state = PlayerState {
angle: Angle::from(player.view_angle), position: player.position.into(),
health: if player.state == PlayerAliveState::Alive { angle: Angle::from(player.view_angle),
player.health health: if player.state == PlayerAliveState::Alive {
} else { player.health
0 } else {
}, 0
team: player.team, },
class: player.class, team: player.team,
charge: player.charge, class: player.class,
}; charge: player.charge,
};
if let None = self.players.get(index) { if let None = self.players.get(index) {
let mut new_player = let mut new_player = Vec::with_capacity(
Vec::with_capacity(self.header.ticks as usize * PlayerState::PACKET_SIZE); self.header.ticks as usize * PlayerState::PACKET_SIZE,
// backfill with defaults );
new_player.resize(self.tick * PlayerState::PACKET_SIZE, 0); // backfill with defaults
self.players.push(new_player); new_player.resize(self.tick * PlayerState::PACKET_SIZE, 0);
}; self.players.push(new_player);
};
match (self.player_info.get(index), player.info.as_ref()) { match (self.player_info.get(index), player.info.as_ref()) {
(None, Some(info)) => self.player_info.push(info.clone()), (None, Some(info)) => self.player_info.push(info.clone()),
_ => {} _ => {}
}
let parsed_player = &mut self.players[index];
parsed_player.extend_from_slice(&state.pack(world));
} }
let parsed_player = &mut self.players[index]; self.max_building_count = self.max_building_count.max(game_state.buildings.len());
parsed_player.extend_from_slice(&state.pack(world)); for (index, building) in game_state.buildings.values().enumerate() {
let state = BuildingState::new(building);
if let None = self.buildings.get(index) {
let new_building = Vec::with_capacity(
self.header.ticks as usize * BuildingState::PACKET_SIZE,
);
self.buildings.push(new_building);
};
let parsed_building = &mut self.buildings[index];
parsed_building.resize(self.tick * BuildingState::PACKET_SIZE, 0);
parsed_building.extend_from_slice(&state.pack(world));
}
self.tick += 1;
} }
self.last_tick = game_state.tick;
self.max_building_count = self.max_building_count.max(game_state.buildings.len());
for (index, building) in game_state.buildings.values().enumerate() {
let state = BuildingState::new(building);
if let None = self.buildings.get(index) {
let new_building =
Vec::with_capacity(self.header.ticks as usize * BuildingState::PACKET_SIZE);
self.buildings.push(new_building);
};
let parsed_building = &mut self.buildings[index];
parsed_building.resize(self.tick * BuildingState::PACKET_SIZE, 0);
parsed_building.extend_from_slice(&state.pack(world));
}
self.tick += 1;
} }
} }