-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmutable.rs
1084 lines (988 loc) · 34.3 KB
/
mutable.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// This file is auto-generated by `gen/scripts/frames`. Do not edit.
//! Mutable (in-progress) frame data.
//!
//! You’ll only encounter mutable frame data if you’re parsing live games.
#![allow(unused_variables)]
#![allow(dead_code)]
use arrow2::{
array::{MutableArray, MutablePrimitiveArray},
bitmap::MutableBitmap,
offset::Offsets,
};
use byteorder::ReadBytesExt;
use std::io::Result;
use crate::{
frame::{transpose, PortOccupancy},
game::Port,
io::slippi::Version,
};
type BE = byteorder::BigEndian;
/// Frame data for a single character (ICs are two characters).
pub struct Data {
pub pre: Pre,
pub post: Post,
pub validity: Option<MutableBitmap>,
}
impl Data {
pub fn with_capacity(capacity: usize, version: Version) -> Self {
Self {
pre: Pre::with_capacity(capacity, version),
post: Post::with_capacity(capacity, version),
validity: None,
}
}
pub fn len(&self) -> usize {
self.pre.len()
}
pub fn push_null(&mut self, version: Version) {
let len = self.len();
self.validity
.get_or_insert_with(|| MutableBitmap::from_len_set(len))
.push(false);
self.pre.push_null(version);
self.post.push_null(version);
}
pub fn transpose_one(&self, i: usize, version: Version) -> transpose::Data {
transpose::Data {
pre: self.pre.transpose_one(i, version),
post: self.post.transpose_one(i, version),
}
}
}
/// Frame data for a single port.
pub struct PortData {
pub port: Port,
pub leader: Data,
/// The "backup" ICs character
pub follower: Option<Data>,
}
impl PortData {
pub fn with_capacity(capacity: usize, version: Version, port: PortOccupancy) -> Self {
Self {
port: port.port,
leader: Data::with_capacity(capacity, version),
follower: match port.follower {
true => Some(Data::with_capacity(capacity, version)),
_ => None,
},
}
}
pub fn len(&self) -> usize {
self.leader.len()
}
pub fn transpose_one(&self, i: usize, version: Version) -> transpose::PortData {
transpose::PortData {
port: self.port,
leader: self.leader.transpose_one(i, version),
follower: self.follower.as_ref().map(|f| f.transpose_one(i, version)),
}
}
}
/// All frame data for a single game, in struct-of-arrays format.
pub struct Frame {
/// Frame IDs start at `-123` and increment each frame. May repeat in case of rollbacks
pub id: MutablePrimitiveArray<i32>,
/// Port-specific data
pub ports: Vec<PortData>,
/// Start-of-frame data
pub start: Option<Start>,
/// End-of-frame data
pub end: Option<End>,
/// Logically, each frame has its own array of items. But we represent all item data in a flat array, with this field indicating the start of each sub-array
pub item_offset: Option<Offsets<i32>>,
/// Item data
pub item: Option<Item>,
}
impl Frame {
pub fn with_capacity(capacity: usize, version: Version, ports: &[PortOccupancy]) -> Self {
Self {
id: MutablePrimitiveArray::<i32>::with_capacity(capacity),
ports: ports
.iter()
.map(|p| PortData::with_capacity(capacity, version, *p))
.collect(),
start: version
.gte(2, 2)
.then(|| Start::with_capacity(capacity, version)),
end: version
.gte(3, 0)
.then(|| End::with_capacity(capacity, version)),
item_offset: version
.gte(3, 0)
.then(|| Offsets::<i32>::with_capacity(capacity)),
item: version.gte(3, 0).then(|| Item::with_capacity(0, version)),
}
}
pub fn len(&self) -> usize {
self.id.len()
}
pub fn transpose_one(&self, i: usize, version: Version) -> transpose::Frame {
transpose::Frame {
id: self.id.values()[i],
ports: self
.ports
.iter()
.map(|p| p.transpose_one(i, version))
.collect(),
start: version
.gte(2, 2)
.then(|| self.start.as_ref().unwrap().transpose_one(i, version)),
end: version
.gte(3, 0)
.then(|| self.end.as_ref().unwrap().transpose_one(i, version)),
items: version.gte(3, 0).then(|| {
let (start, end) = self.item_offset.as_ref().unwrap().start_end(i);
(start..end)
.map(|i| self.item.as_ref().unwrap().transpose_one(i, version))
.collect()
}),
}
}
}
/// Information about the end of the game.
pub struct End {
/// *Added: v3.7* Index of the latest frame which is guaranteed not to happen again (rollback)
pub latest_finalized_frame: Option<MutablePrimitiveArray<i32>>,
/// Indicates which indexes are valid (`None` means "all valid"). Invalid indexes can occur on frames where a character is absent (ICs or 2v2 games)
pub validity: Option<MutableBitmap>,
}
impl End {
fn with_capacity(capacity: usize, version: Version) -> Self {
Self {
latest_finalized_frame: version
.gte(3, 7)
.then(|| MutablePrimitiveArray::<i32>::with_capacity(capacity)),
validity: version
.lt(3, 7)
.then(|| MutableBitmap::with_capacity(capacity)),
}
}
pub fn len(&self) -> usize {
self.validity
.as_ref()
.map(|v| v.len())
.unwrap_or_else(|| self.latest_finalized_frame.as_ref().unwrap().len())
}
pub fn push_null(&mut self, version: Version) {
let len = self.len();
self.validity
.get_or_insert_with(|| MutableBitmap::from_len_set(len))
.push(false);
if version.gte(3, 7) {
self.latest_finalized_frame.as_mut().unwrap().push_null()
}
}
pub fn read_push(&mut self, r: &mut &[u8], version: Version) -> Result<()> {
if version.gte(3, 7) {
r.read_i32::<BE>()
.map(|x| self.latest_finalized_frame.as_mut().unwrap().push(Some(x)))?
};
self.validity.as_mut().map(|v| v.push(true));
Ok(())
}
pub fn transpose_one(&self, i: usize, version: Version) -> transpose::End {
transpose::End {
latest_finalized_frame: self.latest_finalized_frame.as_ref().map(|x| x.values()[i]),
}
}
}
/// An active item (includes projectiles).
pub struct Item {
/// Item type
pub r#type: MutablePrimitiveArray<u16>,
/// Item’s action state
pub state: MutablePrimitiveArray<u8>,
/// Direction item is facing
pub direction: MutablePrimitiveArray<f32>,
/// Item’s velocity
pub velocity: Velocity,
/// Item’s position
pub position: Position,
/// Amount of damage item has taken
pub damage: MutablePrimitiveArray<u16>,
/// Frames remaining until item expires
pub timer: MutablePrimitiveArray<f32>,
/// Unique, serial ID per item spawned
pub id: MutablePrimitiveArray<u32>,
/// *Added: v3.2* Miscellaneous item state
pub misc: Option<ItemMisc>,
/// *Added: v3.6* Port that owns the item (-1 when unowned)
pub owner: Option<MutablePrimitiveArray<i8>>,
/// *Added: v3.16* Inherited instance ID of the owner (0 when unowned)
pub instance_id: Option<MutablePrimitiveArray<u16>>,
/// Indicates which indexes are valid (`None` means "all valid"). Invalid indexes can occur on frames where a character is absent (ICs or 2v2 games)
pub validity: Option<MutableBitmap>,
}
impl Item {
fn with_capacity(capacity: usize, version: Version) -> Self {
Self {
r#type: MutablePrimitiveArray::<u16>::with_capacity(capacity),
state: MutablePrimitiveArray::<u8>::with_capacity(capacity),
direction: MutablePrimitiveArray::<f32>::with_capacity(capacity),
velocity: Velocity::with_capacity(capacity, version),
position: Position::with_capacity(capacity, version),
damage: MutablePrimitiveArray::<u16>::with_capacity(capacity),
timer: MutablePrimitiveArray::<f32>::with_capacity(capacity),
id: MutablePrimitiveArray::<u32>::with_capacity(capacity),
misc: version
.gte(3, 2)
.then(|| ItemMisc::with_capacity(capacity, version)),
owner: version
.gte(3, 6)
.then(|| MutablePrimitiveArray::<i8>::with_capacity(capacity)),
instance_id: version
.gte(3, 16)
.then(|| MutablePrimitiveArray::<u16>::with_capacity(capacity)),
validity: None,
}
}
pub fn len(&self) -> usize {
self.r#type.len()
}
pub fn push_null(&mut self, version: Version) {
let len = self.len();
self.validity
.get_or_insert_with(|| MutableBitmap::from_len_set(len))
.push(false);
self.r#type.push_null();
self.state.push_null();
self.direction.push_null();
self.velocity.push_null(version);
self.position.push_null(version);
self.damage.push_null();
self.timer.push_null();
self.id.push_null();
if version.gte(3, 2) {
self.misc.as_mut().unwrap().push_null(version);
if version.gte(3, 6) {
self.owner.as_mut().unwrap().push_null();
if version.gte(3, 16) {
self.instance_id.as_mut().unwrap().push_null()
}
}
}
}
pub fn read_push(&mut self, r: &mut &[u8], version: Version) -> Result<()> {
r.read_u16::<BE>().map(|x| self.r#type.push(Some(x)))?;
r.read_u8().map(|x| self.state.push(Some(x)))?;
r.read_f32::<BE>().map(|x| self.direction.push(Some(x)))?;
self.velocity.read_push(r, version)?;
self.position.read_push(r, version)?;
r.read_u16::<BE>().map(|x| self.damage.push(Some(x)))?;
r.read_f32::<BE>().map(|x| self.timer.push(Some(x)))?;
r.read_u32::<BE>().map(|x| self.id.push(Some(x)))?;
if version.gte(3, 2) {
self.misc.as_mut().unwrap().read_push(r, version)?;
if version.gte(3, 6) {
r.read_i8()
.map(|x| self.owner.as_mut().unwrap().push(Some(x)))?;
if version.gte(3, 16) {
r.read_u16::<BE>()
.map(|x| self.instance_id.as_mut().unwrap().push(Some(x)))?
}
}
};
self.validity.as_mut().map(|v| v.push(true));
Ok(())
}
pub fn transpose_one(&self, i: usize, version: Version) -> transpose::Item {
transpose::Item {
r#type: self.r#type.values()[i],
state: self.state.values()[i],
direction: self.direction.values()[i],
velocity: self.velocity.transpose_one(i, version),
position: self.position.transpose_one(i, version),
damage: self.damage.values()[i],
timer: self.timer.values()[i],
id: self.id.values()[i],
misc: self.misc.as_ref().map(|x| x.transpose_one(i, version)),
owner: self.owner.as_ref().map(|x| x.values()[i]),
instance_id: self.instance_id.as_ref().map(|x| x.values()[i]),
}
}
}
/// Miscellaneous item state.
pub struct ItemMisc(
pub MutablePrimitiveArray<u8>,
pub MutablePrimitiveArray<u8>,
pub MutablePrimitiveArray<u8>,
pub MutablePrimitiveArray<u8>,
);
impl ItemMisc {
fn with_capacity(capacity: usize, version: Version) -> Self {
Self(
MutablePrimitiveArray::<u8>::with_capacity(capacity),
MutablePrimitiveArray::<u8>::with_capacity(capacity),
MutablePrimitiveArray::<u8>::with_capacity(capacity),
MutablePrimitiveArray::<u8>::with_capacity(capacity),
)
}
pub fn len(&self) -> usize {
self.0.len()
}
pub fn push_null(&mut self, version: Version) {
self.0.push_null();
self.1.push_null();
self.2.push_null();
self.3.push_null()
}
pub fn read_push(&mut self, r: &mut &[u8], version: Version) -> Result<()> {
r.read_u8().map(|x| self.0.push(Some(x)))?;
r.read_u8().map(|x| self.1.push(Some(x)))?;
r.read_u8().map(|x| self.2.push(Some(x)))?;
r.read_u8().map(|x| self.3.push(Some(x)))?;
Ok(())
}
pub fn transpose_one(&self, i: usize, version: Version) -> transpose::ItemMisc {
transpose::ItemMisc(
self.0.values()[i],
self.1.values()[i],
self.2.values()[i],
self.3.values()[i],
)
}
}
/// 2D position.
pub struct Position {
pub x: MutablePrimitiveArray<f32>,
pub y: MutablePrimitiveArray<f32>,
/// Indicates which indexes are valid (`None` means "all valid"). Invalid indexes can occur on frames where a character is absent (ICs or 2v2 games)
pub validity: Option<MutableBitmap>,
}
impl Position {
fn with_capacity(capacity: usize, version: Version) -> Self {
Self {
x: MutablePrimitiveArray::<f32>::with_capacity(capacity),
y: MutablePrimitiveArray::<f32>::with_capacity(capacity),
validity: None,
}
}
pub fn len(&self) -> usize {
self.x.len()
}
pub fn push_null(&mut self, version: Version) {
let len = self.len();
self.validity
.get_or_insert_with(|| MutableBitmap::from_len_set(len))
.push(false);
self.x.push_null();
self.y.push_null()
}
pub fn read_push(&mut self, r: &mut &[u8], version: Version) -> Result<()> {
r.read_f32::<BE>().map(|x| self.x.push(Some(x)))?;
r.read_f32::<BE>().map(|x| self.y.push(Some(x)))?;
self.validity.as_mut().map(|v| v.push(true));
Ok(())
}
pub fn transpose_one(&self, i: usize, version: Version) -> transpose::Position {
transpose::Position {
x: self.x.values()[i],
y: self.y.values()[i],
}
}
}
/// Post-frame update data, for making decisions about game states (such as computing stats).
///
/// Information is collected at the end of collision detection, which is the last consideration of the game engine.
pub struct Post {
/// In-game character (can only change for Zelda/Sheik)
pub character: MutablePrimitiveArray<u8>,
/// Character’s action state
pub state: MutablePrimitiveArray<u16>,
/// Character’s position
pub position: Position,
/// Direction the character is facing
pub direction: MutablePrimitiveArray<f32>,
/// Damage taken (percent)
pub percent: MutablePrimitiveArray<f32>,
/// Size/health of shield
pub shield: MutablePrimitiveArray<f32>,
/// Last attack ID that this character landed
pub last_attack_landed: MutablePrimitiveArray<u8>,
/// Combo count (as defined by the game)
pub combo_count: MutablePrimitiveArray<u8>,
/// Port that last hit this player. Bugged in Melee: will be set to `6` in certain situations
pub last_hit_by: MutablePrimitiveArray<u8>,
/// Number of stocks remaining
pub stocks: MutablePrimitiveArray<u8>,
/// *Added: v0.2* Number of frames action state has been active. Can have a fractional component
pub state_age: Option<MutablePrimitiveArray<f32>>,
/// *Added: v2.0* State flags
pub state_flags: Option<StateFlags>,
/// *Added: v2.0* Used for different things. While in hitstun, contains hitstun frames remaining
pub misc_as: Option<MutablePrimitiveArray<f32>>,
/// *Added: v2.0* Is the character airborne?
pub airborne: Option<MutablePrimitiveArray<u8>>,
/// *Added: v2.0* Ground ID the character last touched
pub ground: Option<MutablePrimitiveArray<u16>>,
/// *Added: v2.0* Number of jumps remaining
pub jumps: Option<MutablePrimitiveArray<u8>>,
/// *Added: v2.0* L-cancel status (0 = none, 1 = successful, 2 = unsuccessful)
pub l_cancel: Option<MutablePrimitiveArray<u8>>,
/// *Added: v2.1* Hurtbox state (0 = vulnerable, 1 = invulnerable, 2 = intangible)
pub hurtbox_state: Option<MutablePrimitiveArray<u8>>,
/// *Added: v3.5* Self-induced and knockback velocities
pub velocities: Option<Velocities>,
/// *Added: v3.8* Hitlag frames remaining
pub hitlag: Option<MutablePrimitiveArray<f32>>,
/// *Added: v3.11* Animation the character is in
pub animation_index: Option<MutablePrimitiveArray<u32>>,
/// *Added: v3.16* Instance ID of the player/item that last hit this player
pub last_hit_by_instance: Option<MutablePrimitiveArray<u16>>,
/// *Added: v3.16* Unique, serial ID for each new action state across all characters. Resets to 0 on death
pub instance_id: Option<MutablePrimitiveArray<u16>>,
/// Indicates which indexes are valid (`None` means "all valid"). Invalid indexes can occur on frames where a character is absent (ICs or 2v2 games)
pub validity: Option<MutableBitmap>,
}
impl Post {
fn with_capacity(capacity: usize, version: Version) -> Self {
Self {
character: MutablePrimitiveArray::<u8>::with_capacity(capacity),
state: MutablePrimitiveArray::<u16>::with_capacity(capacity),
position: Position::with_capacity(capacity, version),
direction: MutablePrimitiveArray::<f32>::with_capacity(capacity),
percent: MutablePrimitiveArray::<f32>::with_capacity(capacity),
shield: MutablePrimitiveArray::<f32>::with_capacity(capacity),
last_attack_landed: MutablePrimitiveArray::<u8>::with_capacity(capacity),
combo_count: MutablePrimitiveArray::<u8>::with_capacity(capacity),
last_hit_by: MutablePrimitiveArray::<u8>::with_capacity(capacity),
stocks: MutablePrimitiveArray::<u8>::with_capacity(capacity),
state_age: version
.gte(0, 2)
.then(|| MutablePrimitiveArray::<f32>::with_capacity(capacity)),
state_flags: version
.gte(2, 0)
.then(|| StateFlags::with_capacity(capacity, version)),
misc_as: version
.gte(2, 0)
.then(|| MutablePrimitiveArray::<f32>::with_capacity(capacity)),
airborne: version
.gte(2, 0)
.then(|| MutablePrimitiveArray::<u8>::with_capacity(capacity)),
ground: version
.gte(2, 0)
.then(|| MutablePrimitiveArray::<u16>::with_capacity(capacity)),
jumps: version
.gte(2, 0)
.then(|| MutablePrimitiveArray::<u8>::with_capacity(capacity)),
l_cancel: version
.gte(2, 0)
.then(|| MutablePrimitiveArray::<u8>::with_capacity(capacity)),
hurtbox_state: version
.gte(2, 1)
.then(|| MutablePrimitiveArray::<u8>::with_capacity(capacity)),
velocities: version
.gte(3, 5)
.then(|| Velocities::with_capacity(capacity, version)),
hitlag: version
.gte(3, 8)
.then(|| MutablePrimitiveArray::<f32>::with_capacity(capacity)),
animation_index: version
.gte(3, 11)
.then(|| MutablePrimitiveArray::<u32>::with_capacity(capacity)),
last_hit_by_instance: version
.gte(3, 16)
.then(|| MutablePrimitiveArray::<u16>::with_capacity(capacity)),
instance_id: version
.gte(3, 16)
.then(|| MutablePrimitiveArray::<u16>::with_capacity(capacity)),
validity: None,
}
}
pub fn len(&self) -> usize {
self.character.len()
}
pub fn push_null(&mut self, version: Version) {
let len = self.len();
self.validity
.get_or_insert_with(|| MutableBitmap::from_len_set(len))
.push(false);
self.character.push_null();
self.state.push_null();
self.position.push_null(version);
self.direction.push_null();
self.percent.push_null();
self.shield.push_null();
self.last_attack_landed.push_null();
self.combo_count.push_null();
self.last_hit_by.push_null();
self.stocks.push_null();
if version.gte(0, 2) {
self.state_age.as_mut().unwrap().push_null();
if version.gte(2, 0) {
self.state_flags.as_mut().unwrap().push_null(version);
self.misc_as.as_mut().unwrap().push_null();
self.airborne.as_mut().unwrap().push_null();
self.ground.as_mut().unwrap().push_null();
self.jumps.as_mut().unwrap().push_null();
self.l_cancel.as_mut().unwrap().push_null();
if version.gte(2, 1) {
self.hurtbox_state.as_mut().unwrap().push_null();
if version.gte(3, 5) {
self.velocities.as_mut().unwrap().push_null(version);
if version.gte(3, 8) {
self.hitlag.as_mut().unwrap().push_null();
if version.gte(3, 11) {
self.animation_index.as_mut().unwrap().push_null();
if version.gte(3, 16) {
self.last_hit_by_instance.as_mut().unwrap().push_null();
self.instance_id.as_mut().unwrap().push_null()
}
}
}
}
}
}
}
}
pub fn read_push(&mut self, r: &mut &[u8], version: Version) -> Result<()> {
r.read_u8().map(|x| self.character.push(Some(x)))?;
r.read_u16::<BE>().map(|x| self.state.push(Some(x)))?;
self.position.read_push(r, version)?;
r.read_f32::<BE>().map(|x| self.direction.push(Some(x)))?;
r.read_f32::<BE>().map(|x| self.percent.push(Some(x)))?;
r.read_f32::<BE>().map(|x| self.shield.push(Some(x)))?;
r.read_u8().map(|x| self.last_attack_landed.push(Some(x)))?;
r.read_u8().map(|x| self.combo_count.push(Some(x)))?;
r.read_u8().map(|x| self.last_hit_by.push(Some(x)))?;
r.read_u8().map(|x| self.stocks.push(Some(x)))?;
if version.gte(0, 2) {
r.read_f32::<BE>()
.map(|x| self.state_age.as_mut().unwrap().push(Some(x)))?;
if version.gte(2, 0) {
self.state_flags.as_mut().unwrap().read_push(r, version)?;
r.read_f32::<BE>()
.map(|x| self.misc_as.as_mut().unwrap().push(Some(x)))?;
r.read_u8()
.map(|x| self.airborne.as_mut().unwrap().push(Some(x)))?;
r.read_u16::<BE>()
.map(|x| self.ground.as_mut().unwrap().push(Some(x)))?;
r.read_u8()
.map(|x| self.jumps.as_mut().unwrap().push(Some(x)))?;
r.read_u8()
.map(|x| self.l_cancel.as_mut().unwrap().push(Some(x)))?;
if version.gte(2, 1) {
r.read_u8()
.map(|x| self.hurtbox_state.as_mut().unwrap().push(Some(x)))?;
if version.gte(3, 5) {
self.velocities.as_mut().unwrap().read_push(r, version)?;
if version.gte(3, 8) {
r.read_f32::<BE>()
.map(|x| self.hitlag.as_mut().unwrap().push(Some(x)))?;
if version.gte(3, 11) {
r.read_u32::<BE>().map(|x| {
self.animation_index.as_mut().unwrap().push(Some(x))
})?;
if version.gte(3, 16) {
r.read_u16::<BE>().map(|x| {
self.last_hit_by_instance.as_mut().unwrap().push(Some(x))
})?;
r.read_u16::<BE>()
.map(|x| self.instance_id.as_mut().unwrap().push(Some(x)))?
}
}
}
}
}
}
};
self.validity.as_mut().map(|v| v.push(true));
Ok(())
}
pub fn transpose_one(&self, i: usize, version: Version) -> transpose::Post {
transpose::Post {
character: self.character.values()[i],
state: self.state.values()[i],
position: self.position.transpose_one(i, version),
direction: self.direction.values()[i],
percent: self.percent.values()[i],
shield: self.shield.values()[i],
last_attack_landed: self.last_attack_landed.values()[i],
combo_count: self.combo_count.values()[i],
last_hit_by: self.last_hit_by.values()[i],
stocks: self.stocks.values()[i],
state_age: self.state_age.as_ref().map(|x| x.values()[i]),
state_flags: self
.state_flags
.as_ref()
.map(|x| x.transpose_one(i, version)),
misc_as: self.misc_as.as_ref().map(|x| x.values()[i]),
airborne: self.airborne.as_ref().map(|x| x.values()[i]),
ground: self.ground.as_ref().map(|x| x.values()[i]),
jumps: self.jumps.as_ref().map(|x| x.values()[i]),
l_cancel: self.l_cancel.as_ref().map(|x| x.values()[i]),
hurtbox_state: self.hurtbox_state.as_ref().map(|x| x.values()[i]),
velocities: self
.velocities
.as_ref()
.map(|x| x.transpose_one(i, version)),
hitlag: self.hitlag.as_ref().map(|x| x.values()[i]),
animation_index: self.animation_index.as_ref().map(|x| x.values()[i]),
last_hit_by_instance: self.last_hit_by_instance.as_ref().map(|x| x.values()[i]),
instance_id: self.instance_id.as_ref().map(|x| x.values()[i]),
}
}
}
/// Pre-frame update data, required to reconstruct a replay.
///
/// Information is collected right before controller inputs are used to figure out the character’s next action.
pub struct Pre {
/// Random seed
pub random_seed: MutablePrimitiveArray<u32>,
/// Character’s action state
pub state: MutablePrimitiveArray<u16>,
/// Character’s position
pub position: Position,
/// Direction the character is facing
pub direction: MutablePrimitiveArray<f32>,
/// Processed analog joystick position
pub joystick: Position,
/// Processed analog c-stick position
pub cstick: Position,
/// Processed analog trigger position
pub triggers: MutablePrimitiveArray<f32>,
/// Processed button-state bitmask
pub buttons: MutablePrimitiveArray<u32>,
/// Physical button-state bitmask
pub buttons_physical: MutablePrimitiveArray<u16>,
/// Physical analog trigger positions (useful for IPM)
pub triggers_physical: TriggersPhysical,
/// *Added: v1.2* Raw joystick x-position
pub raw_analog_x: Option<MutablePrimitiveArray<i8>>,
/// *Added: v1.4* Damage taken (percent)
pub percent: Option<MutablePrimitiveArray<f32>>,
/// *Added: v3.15* Raw joystick y-position
pub raw_analog_y: Option<MutablePrimitiveArray<i8>>,
/// Indicates which indexes are valid (`None` means "all valid"). Invalid indexes can occur on frames where a character is absent (ICs or 2v2 games)
pub validity: Option<MutableBitmap>,
}
impl Pre {
fn with_capacity(capacity: usize, version: Version) -> Self {
Self {
random_seed: MutablePrimitiveArray::<u32>::with_capacity(capacity),
state: MutablePrimitiveArray::<u16>::with_capacity(capacity),
position: Position::with_capacity(capacity, version),
direction: MutablePrimitiveArray::<f32>::with_capacity(capacity),
joystick: Position::with_capacity(capacity, version),
cstick: Position::with_capacity(capacity, version),
triggers: MutablePrimitiveArray::<f32>::with_capacity(capacity),
buttons: MutablePrimitiveArray::<u32>::with_capacity(capacity),
buttons_physical: MutablePrimitiveArray::<u16>::with_capacity(capacity),
triggers_physical: TriggersPhysical::with_capacity(capacity, version),
raw_analog_x: version
.gte(1, 2)
.then(|| MutablePrimitiveArray::<i8>::with_capacity(capacity)),
percent: version
.gte(1, 4)
.then(|| MutablePrimitiveArray::<f32>::with_capacity(capacity)),
raw_analog_y: version
.gte(3, 15)
.then(|| MutablePrimitiveArray::<i8>::with_capacity(capacity)),
validity: None,
}
}
pub fn len(&self) -> usize {
self.random_seed.len()
}
pub fn push_null(&mut self, version: Version) {
let len = self.len();
self.validity
.get_or_insert_with(|| MutableBitmap::from_len_set(len))
.push(false);
self.random_seed.push_null();
self.state.push_null();
self.position.push_null(version);
self.direction.push_null();
self.joystick.push_null(version);
self.cstick.push_null(version);
self.triggers.push_null();
self.buttons.push_null();
self.buttons_physical.push_null();
self.triggers_physical.push_null(version);
if version.gte(1, 2) {
self.raw_analog_x.as_mut().unwrap().push_null();
if version.gte(1, 4) {
self.percent.as_mut().unwrap().push_null();
if version.gte(3, 15) {
self.raw_analog_y.as_mut().unwrap().push_null()
}
}
}
}
pub fn read_push(&mut self, r: &mut &[u8], version: Version) -> Result<()> {
r.read_u32::<BE>().map(|x| self.random_seed.push(Some(x)))?;
r.read_u16::<BE>().map(|x| self.state.push(Some(x)))?;
self.position.read_push(r, version)?;
r.read_f32::<BE>().map(|x| self.direction.push(Some(x)))?;
self.joystick.read_push(r, version)?;
self.cstick.read_push(r, version)?;
r.read_f32::<BE>().map(|x| self.triggers.push(Some(x)))?;
r.read_u32::<BE>().map(|x| self.buttons.push(Some(x)))?;
r.read_u16::<BE>()
.map(|x| self.buttons_physical.push(Some(x)))?;
self.triggers_physical.read_push(r, version)?;
if version.gte(1, 2) {
r.read_i8()
.map(|x| self.raw_analog_x.as_mut().unwrap().push(Some(x)))?;
if version.gte(1, 4) {
r.read_f32::<BE>()
.map(|x| self.percent.as_mut().unwrap().push(Some(x)))?;
if version.gte(3, 15) {
r.read_i8()
.map(|x| self.raw_analog_y.as_mut().unwrap().push(Some(x)))?
}
}
};
self.validity.as_mut().map(|v| v.push(true));
Ok(())
}
pub fn transpose_one(&self, i: usize, version: Version) -> transpose::Pre {
transpose::Pre {
random_seed: self.random_seed.values()[i],
state: self.state.values()[i],
position: self.position.transpose_one(i, version),
direction: self.direction.values()[i],
joystick: self.joystick.transpose_one(i, version),
cstick: self.cstick.transpose_one(i, version),
triggers: self.triggers.values()[i],
buttons: self.buttons.values()[i],
buttons_physical: self.buttons_physical.values()[i],
triggers_physical: self.triggers_physical.transpose_one(i, version),
raw_analog_x: self.raw_analog_x.as_ref().map(|x| x.values()[i]),
percent: self.percent.as_ref().map(|x| x.values()[i]),
raw_analog_y: self.raw_analog_y.as_ref().map(|x| x.values()[i]),
}
}
}
/// Initialization data such as game mode, settings, characters & stage.
pub struct Start {
/// Random seed
pub random_seed: MutablePrimitiveArray<u32>,
/// *Added: v3.10* Scene frame counter. Starts at 0, and increments every frame (even when paused)
pub scene_frame_counter: Option<MutablePrimitiveArray<u32>>,
/// Indicates which indexes are valid (`None` means "all valid"). Invalid indexes can occur on frames where a character is absent (ICs or 2v2 games)
pub validity: Option<MutableBitmap>,
}
impl Start {
fn with_capacity(capacity: usize, version: Version) -> Self {
Self {
random_seed: MutablePrimitiveArray::<u32>::with_capacity(capacity),
scene_frame_counter: version
.gte(3, 10)
.then(|| MutablePrimitiveArray::<u32>::with_capacity(capacity)),
validity: None,
}
}
pub fn len(&self) -> usize {
self.random_seed.len()
}
pub fn push_null(&mut self, version: Version) {
let len = self.len();
self.validity
.get_or_insert_with(|| MutableBitmap::from_len_set(len))
.push(false);
self.random_seed.push_null();
if version.gte(3, 10) {
self.scene_frame_counter.as_mut().unwrap().push_null()
}
}
pub fn read_push(&mut self, r: &mut &[u8], version: Version) -> Result<()> {
r.read_u32::<BE>().map(|x| self.random_seed.push(Some(x)))?;
if version.gte(3, 10) {
r.read_u32::<BE>()
.map(|x| self.scene_frame_counter.as_mut().unwrap().push(Some(x)))?
};
self.validity.as_mut().map(|v| v.push(true));
Ok(())
}
pub fn transpose_one(&self, i: usize, version: Version) -> transpose::Start {
transpose::Start {
random_seed: self.random_seed.values()[i],
scene_frame_counter: self.scene_frame_counter.as_ref().map(|x| x.values()[i]),
}
}
}
/// Miscellaneous state flags.
pub struct StateFlags(
pub MutablePrimitiveArray<u8>,
pub MutablePrimitiveArray<u8>,
pub MutablePrimitiveArray<u8>,
pub MutablePrimitiveArray<u8>,
pub MutablePrimitiveArray<u8>,
);
impl StateFlags {
fn with_capacity(capacity: usize, version: Version) -> Self {
Self(
MutablePrimitiveArray::<u8>::with_capacity(capacity),
MutablePrimitiveArray::<u8>::with_capacity(capacity),
MutablePrimitiveArray::<u8>::with_capacity(capacity),
MutablePrimitiveArray::<u8>::with_capacity(capacity),
MutablePrimitiveArray::<u8>::with_capacity(capacity),
)
}
pub fn len(&self) -> usize {
self.0.len()
}
pub fn push_null(&mut self, version: Version) {
self.0.push_null();
self.1.push_null();
self.2.push_null();
self.3.push_null();
self.4.push_null()
}
pub fn read_push(&mut self, r: &mut &[u8], version: Version) -> Result<()> {
r.read_u8().map(|x| self.0.push(Some(x)))?;
r.read_u8().map(|x| self.1.push(Some(x)))?;
r.read_u8().map(|x| self.2.push(Some(x)))?;
r.read_u8().map(|x| self.3.push(Some(x)))?;
r.read_u8().map(|x| self.4.push(Some(x)))?;
Ok(())
}
pub fn transpose_one(&self, i: usize, version: Version) -> transpose::StateFlags {
transpose::StateFlags(
self.0.values()[i],
self.1.values()[i],
self.2.values()[i],
self.3.values()[i],
self.4.values()[i],
)
}
}
/// Trigger state.
pub struct TriggersPhysical {
pub l: MutablePrimitiveArray<f32>,
pub r: MutablePrimitiveArray<f32>,
/// Indicates which indexes are valid (`None` means "all valid"). Invalid indexes can occur on frames where a character is absent (ICs or 2v2 games)
pub validity: Option<MutableBitmap>,
}
impl TriggersPhysical {
fn with_capacity(capacity: usize, version: Version) -> Self {
Self {
l: MutablePrimitiveArray::<f32>::with_capacity(capacity),
r: MutablePrimitiveArray::<f32>::with_capacity(capacity),
validity: None,
}
}
pub fn len(&self) -> usize {
self.l.len()
}
pub fn push_null(&mut self, version: Version) {
let len = self.len();
self.validity
.get_or_insert_with(|| MutableBitmap::from_len_set(len))
.push(false);
self.l.push_null();
self.r.push_null()
}
pub fn read_push(&mut self, r: &mut &[u8], version: Version) -> Result<()> {
r.read_f32::<BE>().map(|x| self.l.push(Some(x)))?;
r.read_f32::<BE>().map(|x| self.r.push(Some(x)))?;
self.validity.as_mut().map(|v| v.push(true));
Ok(())
}
pub fn transpose_one(&self, i: usize, version: Version) -> transpose::TriggersPhysical {
transpose::TriggersPhysical {
l: self.l.values()[i],
r: self.r.values()[i],
}
}
}
/// Self-induced and knockback velocities.
pub struct Velocities {
/// Self-induced x-velocity (airborne)
pub self_x_air: MutablePrimitiveArray<f32>,
/// Self-induced y-velocity
pub self_y: MutablePrimitiveArray<f32>,
/// Knockback-induced x-velocity
pub knockback_x: MutablePrimitiveArray<f32>,
/// Knockback-induced y-velocity
pub knockback_y: MutablePrimitiveArray<f32>,
/// Self-induced x-velocity (grounded)
pub self_x_ground: MutablePrimitiveArray<f32>,
/// Indicates which indexes are valid (`None` means "all valid"). Invalid indexes can occur on frames where a character is absent (ICs or 2v2 games)
pub validity: Option<MutableBitmap>,
}
impl Velocities {
fn with_capacity(capacity: usize, version: Version) -> Self {
Self {
self_x_air: MutablePrimitiveArray::<f32>::with_capacity(capacity),
self_y: MutablePrimitiveArray::<f32>::with_capacity(capacity),
knockback_x: MutablePrimitiveArray::<f32>::with_capacity(capacity),
knockback_y: MutablePrimitiveArray::<f32>::with_capacity(capacity),
self_x_ground: MutablePrimitiveArray::<f32>::with_capacity(capacity),
validity: None,
}
}