Skip to content

Commit 0649ed7

Browse files
committed
tweak run extraction and rendering to filter only for longer runs that start from pallet.
1 parent bcf80d2 commit 0649ed7

File tree

2 files changed

+51
-15
lines changed

2 files changed

+51
-15
lines changed

large-scale-viz/high_perf_character_render/src/bin/extract_compact_runs.rs

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,41 @@ struct Args {
2222
progress_file: PathBuf,
2323

2424
/// Minimum run duration in seconds
25+
/// 60 secs might be around 1200 steps.
26+
/// for longer run we should do at least 240 seconds
2527
#[arg(long, default_value = "60")]
2628
min_duration_secs: i64,
2729

2830
/// Maximum coordinates per run
31+
// this gets converted to u16 so 2^16 is max safe value!
32+
// 65528 <- safe value with 8 padding
33+
// lets try 32768
2934
#[arg(long, default_value = "2000")]
3035
max_coords_per_run: usize,
36+
37+
#[arg(long)]
38+
pallet_start_only: bool,
39+
3140
}
3241

42+
/*
43+
// original, bigger than needed
3344
#[repr(C, packed)]
3445
#[derive(Debug, Clone, Copy)]
3546
struct CompactCoord {
3647
x: u16,
3748
y: u16,
3849
map_id: u16,
3950
}
51+
*/
52+
53+
#[repr(C, packed)]
54+
#[derive(Debug, Clone, Copy)]
55+
struct UltraCompactCoord {
56+
x: u8,
57+
y: u8,
58+
map_id: u8,
59+
}
4060

4161
fn main() -> Result<()> {
4262
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
@@ -93,7 +113,8 @@ fn main() -> Result<()> {
93113
);
94114

95115
let mut total_runs_extracted = 0;
96-
let reset_maps = vec![0i64, 37, 40];
116+
let starting_maps = vec![0i64, 37, 40, 39, 38];
117+
let starting_and_adjacent_maps = vec![0i64, 37, 40, 39, 38, 12, 32];
97118
let gap_threshold = Duration::minutes(2);
98119
let min_duration = Duration::seconds(args.min_duration_secs);
99120

@@ -159,12 +180,12 @@ fn main() -> Result<()> {
159180
let prev_map = frames[j-1].coords[2];
160181

161182
let should_split = time_gap >= gap_threshold
162-
|| (reset_maps.contains(&curr_map) && !reset_maps.contains(&prev_map));
183+
|| (starting_maps.contains(&curr_map) && !starting_and_adjacent_maps.contains(&prev_map));
163184

164185
if should_split {
165186
let duration = frames[j-1].timestamp - frames[run_start].timestamp;
166-
167-
if duration >= min_duration {
187+
let pallet_start_ok = if args.pallet_start_only { starting_maps.contains(&frames[run_start].coords[2]) } else { true };
188+
if duration >= min_duration && pallet_start_ok {
168189
// Write this run
169190
write_compact_run(
170191
&mut output_file,
@@ -183,8 +204,8 @@ fn main() -> Result<()> {
183204
// Final run
184205
if run_start < user_env_end {
185206
let duration = frames[user_env_end - 1].timestamp - frames[run_start].timestamp;
186-
187-
if duration >= min_duration {
207+
let pallet_start_ok = if args.pallet_start_only { starting_maps.contains(&frames[run_start].coords[2]) } else { true };
208+
if duration >= min_duration && pallet_start_ok {
188209
write_compact_run(
189210
&mut output_file,
190211
run_sprite_id,
@@ -238,16 +259,25 @@ fn write_compact_run<W: Write>(
238259

239260
// Write coords
240261
for frame in frames.iter().take(max_coords) {
241-
let compact = CompactCoord {
242-
x: frame.coords[0] as u16,
243-
y: frame.coords[1] as u16,
244-
map_id: frame.coords[2] as u16,
262+
263+
// flag out invalid map id or coordinates
264+
let compact = match (
265+
u8::try_from(frame.coords[0]),
266+
u8::try_from(frame.coords[1]),
267+
u8::try_from(frame.coords[2]),
268+
) {
269+
(Ok(x), Ok(y), Ok(map_id)) => UltraCompactCoord { x, y, map_id },
270+
_ => UltraCompactCoord {
271+
x: 0,
272+
y: 0,
273+
map_id: 255,
274+
},
245275
};
246276

247277
let bytes = unsafe {
248278
std::slice::from_raw_parts(
249-
&compact as *const CompactCoord as *const u8,
250-
std::mem::size_of::<CompactCoord>(),
279+
&compact as *const UltraCompactCoord as *const u8,
280+
std::mem::size_of::<UltraCompactCoord>(),
251281
)
252282
};
253283

large-scale-viz/high_perf_character_render/src/bin/render_compact_runs.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,16 @@ struct Args {
5353
max_frames: Option<usize>,
5454
}
5555

56+
/*
57+
//use this to read old data
5658
#[repr(C, packed)]
5759
#[derive(Debug, Clone, Copy)]
5860
struct CompactCoord {
5961
x: u16,
6062
y: u16,
6163
map_id: u16,
6264
}
65+
*/
6366

6467
#[repr(C, packed)]
6568
#[derive(Debug, Clone, Copy)]
@@ -342,7 +345,7 @@ fn load_compact_runs(path: &PathBuf) -> Result<Vec<CompactRun>> {
342345
let coord_count = u16::from_le_bytes(count_buf) as usize;
343346

344347
// Read coords
345-
let bytes_to_read = coord_count * std::mem::size_of::<CompactCoord>();
348+
let bytes_to_read = coord_count * std::mem::size_of::<UltraCompactCoordMem>();
346349
if buffer.len() < bytes_to_read {
347350
buffer.resize(bytes_to_read, 0);
348351
}
@@ -351,10 +354,12 @@ fn load_compact_runs(path: &PathBuf) -> Result<Vec<CompactRun>> {
351354

352355
let mut coords = Vec::with_capacity(coord_count);
353356
for i in 0..coord_count {
354-
let offset = i * std::mem::size_of::<CompactCoord>();
357+
let offset = i * std::mem::size_of::<UltraCompactCoordMem>();
355358
let coord = unsafe {
356-
std::ptr::read_unaligned(buffer[offset..].as_ptr() as *const CompactCoord)
359+
std::ptr::read_unaligned(buffer[offset..].as_ptr() as *const UltraCompactCoordMem)
357360
};
361+
coords.push(coord);
362+
/*
358363
let x = coord.x;
359364
let y = coord.y;
360365
let map_id = coord.map_id;
@@ -379,6 +384,7 @@ fn load_compact_runs(path: &PathBuf) -> Result<Vec<CompactRun>> {
379384
map_id: map_id as u8,
380385
};
381386
coords.push(packy_coords);
387+
*/
382388
}
383389

384390
runs.push(CompactRun { sprite_id, coords });

0 commit comments

Comments
 (0)