@@ -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)]
3546struct 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
4161fn 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
0 commit comments