mirror of
https://codeberg.org/demostf/tf-demos-viewer.git
synced 2026-06-03 10:04:12 +02:00
halve framerate
This commit is contained in:
parent
5031746e8b
commit
8c8e1c2f2e
3 changed files with 45 additions and 32 deletions
38
Cargo.lock
generated
38
Cargo.lock
generated
|
|
@ -20,23 +20,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
|
||||
[[package]]
|
||||
name = "bitstream_reader"
|
||||
version = "0.6.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
version = "0.7.0"
|
||||
dependencies = [
|
||||
"bitstream_reader_derive 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bytecount 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bitstream_reader_derive 0.7.1",
|
||||
"memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitstream_reader_derive"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
version = "0.7.1"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn_util 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn_util 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -44,11 +42,6 @@ name = "bumpalo"
|
|||
version = "2.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "bytecount"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.3.2"
|
||||
|
|
@ -399,12 +392,12 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "syn_util"
|
||||
version = "0.3.0"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -422,7 +415,7 @@ dependencies = [
|
|||
name = "tf-demo-parser"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bitstream_reader 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bitstream_reader 0.7.0",
|
||||
"enumflags2 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"err-derive 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"main_error 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
@ -639,10 +632,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
"checksum aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d"
|
||||
"checksum anyhow 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "9267dff192e68f3399525901e709a48c1d3982c9c072fa32f2127a0cb0babf14"
|
||||
"checksum autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2"
|
||||
"checksum bitstream_reader 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "af1a60e9456844ac6f5fbbe8c8ddc2d97a9e54080197dbac7cba53e1c7be56b8"
|
||||
"checksum bitstream_reader_derive 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "14e4573210a0cc968772847e1db9705e546f60cc1525c5cbfbf470dfa1fa391c"
|
||||
"checksum bumpalo 2.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ad807f2fc2bf185eeb98ff3a901bd46dc5ad58163d0fa4577ba0d25674d71708"
|
||||
"checksum bytecount 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "be0fdd54b507df8f22012890aadd099979befdba27713c767993f8380112ca7c"
|
||||
"checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5"
|
||||
"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
|
||||
"checksum console_error_panic_hook 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "b8d976903543e0c48546a91908f21588a680a8c8f984df9a5d69feccb2b2a211"
|
||||
|
|
@ -687,7 +677,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
"checksum sourcefile 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf77cb82ba8453b42b6ae1d692e4cdc92f9a47beaf89a847c8be83f4e328ad3"
|
||||
"checksum syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)" = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5"
|
||||
"checksum syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)" = "dff0acdb207ae2fe6d5976617f887eb1e35a2ba52c13c7234c790960cdad9238"
|
||||
"checksum syn_util 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "50518d8ba51dbea1b0981d7bff56cecc2a20a02f22bf6fcf71a924bc241ee4a0"
|
||||
"checksum syn_util 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6754c4559b79657554e9d8a0d56e65e490c76d382b9c23108364ec4125dea23c"
|
||||
"checksum synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545"
|
||||
"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
|
||||
"checksum toml 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "01d1404644c8b12b16bfcffa4322403a91a451584daaaa7c28d3152e6cbc98cf"
|
||||
|
|
|
|||
12
src/lib.rs
12
src/lib.rs
|
|
@ -1,8 +1,9 @@
|
|||
#![feature(const_generics)]
|
||||
#![allow(incomplete_features)]
|
||||
#![macro_use]
|
||||
|
||||
use crate::state::ParsedDemo;
|
||||
use tf_demo_parser::demo::parser::gamestateanalyser::{GameState, GameStateAnalyser};
|
||||
use tf_demo_parser::demo::parser::gamestateanalyser::GameStateAnalyser;
|
||||
use tf_demo_parser::{Demo, DemoParser, ParseError};
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
|
|
@ -17,7 +18,7 @@ pub fn parse_demo(buffer: Box<[u8]>) -> Result<(), JsValue> {
|
|||
let buffer = buffer.into_vec();
|
||||
let parsed = parse_demo_inner(buffer).map_err(|e| JsValue::from(e.to_string()))?;
|
||||
|
||||
log!("{:?}", parsed.players[2].get(10));
|
||||
log!("{:?}, size {}", parsed.players[2].get(10), parsed.size());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -25,13 +26,18 @@ pub fn parse_demo(buffer: Box<[u8]>) -> Result<(), JsValue> {
|
|||
pub fn parse_demo_inner(buffer: Vec<u8>) -> Result<ParsedDemo, ParseError> {
|
||||
let demo = Demo::new(buffer);
|
||||
let parser = DemoParser::new_with_analyser(demo.get_stream(), GameStateAnalyser::default());
|
||||
let (header, mut ticker) = parser.ticker()?;
|
||||
let (_header, mut ticker) = parser.ticker()?;
|
||||
|
||||
let mut parsed_demo = ParsedDemo::new();
|
||||
|
||||
let mut skip = false;
|
||||
while ticker.tick()? {
|
||||
if !skip {
|
||||
// halve framerate
|
||||
parsed_demo.push_state(ticker.state());
|
||||
}
|
||||
skip = !skip;
|
||||
}
|
||||
|
||||
Ok(parsed_demo)
|
||||
}
|
||||
|
|
|
|||
25
src/state.rs
25
src/state.rs
|
|
@ -1,10 +1,7 @@
|
|||
use std::ops::Index;
|
||||
use tf_demo_parser::demo::parser::gamestateanalyser::{Class, GameState, Team};
|
||||
use tf_demo_parser::demo::vector::VectorXY;
|
||||
|
||||
macro_rules! log {
|
||||
($($arg:tt)*) => (web_sys::console::log_1(&wasm_bindgen::prelude::JsValue::from(format!($($arg)*))))
|
||||
}
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default)]
|
||||
pub struct Angle(u16);
|
||||
|
|
@ -53,6 +50,12 @@ impl ParsedDemo {
|
|||
}
|
||||
self.tick += 1;
|
||||
}
|
||||
|
||||
pub fn size(&self) -> usize {
|
||||
self.players
|
||||
.iter()
|
||||
.fold(0, |size, player| size + player.size())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
|
|
@ -113,6 +116,14 @@ impl ParsedPlayer {
|
|||
class: self.class[index],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn size(&self) -> usize {
|
||||
self.position.len() * std::mem::size_of::<VectorXY>()
|
||||
+ self.team.size()
|
||||
+ self.class.size()
|
||||
+ self.health.size()
|
||||
+ self.angle.size()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
|
|
@ -120,6 +131,12 @@ pub struct SparseVec<T: Default, const N: usize> {
|
|||
inner: Vec<T>,
|
||||
}
|
||||
|
||||
impl<T: Default, const N: usize> SparseVec<T, N> {
|
||||
pub fn size(&self) -> usize {
|
||||
self.inner.len() * std::mem::size_of::<T>()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Default, const N: usize> SparseVec<T, N> {
|
||||
fn push_index(&mut self, index: usize, val: T) {
|
||||
if index % N == 0 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue