|
1 | 1 | use anyhow::{Context, Result}; |
2 | 2 | use clap::Parser; |
3 | | -use sprite_video_renderer::data::CoordinateMapper; |
| 3 | +use sprite_video_renderer::data::{CoordinateMapper, INVALID_MAP_ID_FLAG}; |
4 | 4 | use sprite_video_renderer::rendering::{GpuContext, SpriteInstance, SpriteRenderer, TextureAtlas}; |
5 | 5 | use sprite_video_renderer::video::ProResEncoder; |
6 | 6 | use std::fs::File; |
@@ -59,10 +59,18 @@ struct CompactCoord { |
59 | 59 | map_id: u16, |
60 | 60 | } |
61 | 61 |
|
| 62 | +#[repr(C, packed)] |
| 63 | +#[derive(Debug, Clone, Copy)] |
| 64 | +struct UltraCompactCoordMem { |
| 65 | + x: u8, |
| 66 | + y: u8, |
| 67 | + map_id: u8, |
| 68 | +} |
| 69 | + |
62 | 70 | #[derive(Debug)] |
63 | 71 | struct CompactRun { |
64 | 72 | sprite_id: u8, |
65 | | - coords: Vec<CompactCoord>, |
| 73 | + coords: Vec<UltraCompactCoordMem>, |
66 | 74 | } |
67 | 75 |
|
68 | 76 | fn main() -> Result<()> { |
@@ -170,6 +178,11 @@ async fn run() -> Result<()> { |
170 | 178 | let current_pos = coordinate_mapper.convert_coords(¤t_coords); |
171 | 179 | let next_pos = coordinate_mapper.convert_coords(&next_coords); |
172 | 180 |
|
| 181 | + // map id doesn't exist! (probably transitioning between world) |
| 182 | + if current_pos == INVALID_MAP_ID_FLAG || next_pos == INVALID_MAP_ID_FLAG { |
| 183 | + continue; |
| 184 | + } |
| 185 | + |
173 | 186 | // Check pixel distance - only interpolate if moving <= 16 pixels (1 tile) |
174 | 187 | let pixel_dx = (next_pos[0] - current_pos[0]).abs(); |
175 | 188 | let pixel_dy = (next_pos[1] - current_pos[1]).abs(); |
@@ -290,7 +303,9 @@ fn load_compact_runs(path: &PathBuf) -> Result<Vec<CompactRun>> { |
290 | 303 | let mut runs = Vec::new(); |
291 | 304 | let mut buffer = vec![0u8; 1024 * 1024]; // 1MB buffer for reading |
292 | 305 |
|
293 | | - loop { |
| 306 | + let mut skipped_runs: u32 = 0; |
| 307 | + |
| 308 | + 'runs_loop: loop { |
294 | 309 | // Read sprite_id |
295 | 310 | let mut sprite_id_buf = [0u8; 1]; |
296 | 311 | match reader.read_exact(&mut sprite_id_buf) { |
@@ -319,13 +334,36 @@ fn load_compact_runs(path: &PathBuf) -> Result<Vec<CompactRun>> { |
319 | 334 | let coord = unsafe { |
320 | 335 | std::ptr::read_unaligned(buffer[offset..].as_ptr() as *const CompactCoord) |
321 | 336 | }; |
322 | | - coords.push(coord); |
| 337 | + let x = coord.x; |
| 338 | + let y = coord.y; |
| 339 | + let map_id = coord.map_id; |
| 340 | + if x > u8::MAX as u16 { |
| 341 | + //log::error!("got x coord with value: {}", x); |
| 342 | + skipped_runs += 1; |
| 343 | + continue 'runs_loop; |
| 344 | + } |
| 345 | + if y > u8::MAX as u16 { |
| 346 | + //log::error!("got y coord with value: {}", y); |
| 347 | + skipped_runs += 1; |
| 348 | + continue 'runs_loop; |
| 349 | + } |
| 350 | + if map_id > u8::MAX as u16 { |
| 351 | + //log::error!("got map_id with value: {}", map_id); |
| 352 | + skipped_runs += 1; |
| 353 | + continue 'runs_loop; |
| 354 | + } |
| 355 | + let packy_coords = UltraCompactCoordMem { |
| 356 | + x: x as u8, |
| 357 | + y: y as u8, |
| 358 | + map_id: map_id as u8, |
| 359 | + }; |
| 360 | + coords.push(packy_coords); |
323 | 361 | } |
324 | 362 |
|
325 | 363 | runs.push(CompactRun { sprite_id, coords }); |
326 | 364 |
|
327 | 365 | if runs.len() % 100000 == 0 { |
328 | | - log::info!("Loaded {} runs...", runs.len()); |
| 366 | + log::info!("Loaded {} runs, skipped {}...", runs.len(), skipped_runs); |
329 | 367 | } |
330 | 368 | } |
331 | 369 |
|
|
0 commit comments