fork/slippc

git clone https://git.julia.blue/fork/slippc

Patrick CrainFixed heap allocation for SlippiItemFrame taking an inordinate amount of memory (prev. ~500MB, now about ~100MB); bumped parser version to 0.6.1210d608

0.6.1
4.2 KiB147 linesraw
1#ifndef REPLAY_H_
2#define REPLAY_H_
3
4#include <iostream>
5#include <fstream>
6
7#include "enums.h"
8#include "util.h"
9
10// Replay File (.slp) Spec: https://github.com/project-slippi/project-slippi/wiki/Replay-File-Spec
11
12const unsigned MAX_ITEMS     = 1024; //Max number of items to output
13const int32_t  MAX_ITEM_LIFE = 1024; //Max number of frames to track an item
14
15namespace slip {
16
17struct SlippiFrame {
18  //Parser stuff
19  bool     alive         = false;  //For checking if this frame was actually set
20
21  //Pre-frame stuff
22  int32_t  frame         = 0;
23  uint8_t  player        = 0;
24  bool     follower      = false;
25  uint32_t seed          = 0;
26  uint16_t action_pre    = 0;
27  float    pos_x_pre     = 0.0f;
28  float    pos_y_pre     = 0.0f;
29  float    face_dir_pre  = 0.0f;
30  float    joy_x         = 0.0f;
31  float    joy_y         = 0.0f;
32  float    c_x           = 0.0f;
33  float    c_y           = 0.0f;
34  float    trigger       = 0.0f;
35  uint16_t buttons       = 0;
36  float    phys_l        = 0.0f;
37  float    phys_r        = 0.0f;
38  uint8_t  ucf_x         = 0;
39  float    percent_pre   = 0.0f;
40
41  //Post-frame stuff
42  uint8_t  char_id       = 0;
43  uint16_t action_post   = 0;
44  float    pos_x_post    = 0.0f;
45  float    pos_y_post    = 0.0f;
46  float    face_dir_post = 0.0f;
47  float    percent_post  = 0.0f;
48  float    shield        = 0.0f;
49  uint8_t  hit_with      = 0;
50  uint8_t  combo         = 0;
51  uint8_t  hurt_by       = 0;
52  uint8_t  stocks        = 0;
53  float    action_fc     = 0.0f;
54  uint8_t  flags_1       = 0;
55  uint8_t  flags_2       = 0;
56  uint8_t  flags_3       = 0;
57  uint8_t  flags_4       = 0;
58  uint8_t  flags_5       = 0;
59  float    hitstun       = 0.0f;
60  bool     airborne      = false;
61  uint16_t ground_id     = 0;
62  uint8_t  jumps         = 0;
63  uint8_t  l_cancel      = 0;
64  uint8_t  hurtbox       = 0;
65  float    self_air_x    = 0;
66  float    self_air_y    = 0;
67  float    attack_x      = 0;
68  float    attack_y      = 0;
69  float    self_grd_x    = 0;
70  float    hitlag        = 0;
71};
72
73struct SlippiItemFrame {
74  int32_t  frame         = 0;
75  uint8_t  state         = 0;
76  float    face_dir      = 0;
77  float    xvel          = 0;
78  float    yvel          = 0;
79  float    xpos          = 0;
80  float    ypos          = 0;
81  uint16_t damage        = 0;
82  float    expire        = 0;
83  uint8_t  flags_1       = 0;
84  uint8_t  flags_2       = 0;
85  uint8_t  flags_3       = 0;
86  uint8_t  flags_4       = 0;
87  uint8_t  owner         = 0;
88};
89
90struct SlippiItem {
91  uint16_t         type       = 0;
92  uint32_t         spawn_id   = MAX_ITEMS+1;
93  uint32_t         num_frames = 0;
94  SlippiItemFrame* frame      = nullptr;
95};
96
97struct SlippiPlayer {
98  uint8_t      ext_char_id  = 0;
99  uint8_t      player_type  = 3;  //empty
100  uint8_t      start_stocks = 0;
101  uint8_t      end_stocks   = 0;
102  uint8_t      color        = 0;
103  uint8_t      team_id      = 0;
104  uint8_t      cpu_level    = 0;
105  uint32_t     dash_back    = 0;
106  uint32_t     shield_drop  = 0;
107  std::string  tag          = "";
108  std::string  tag_code     = "";
109  std::string  tag_css      = "";
110  SlippiFrame* frame        = nullptr;
111};
112
113struct SlippiReplay {
114  uint32_t        slippi_version_raw  = 0;
115  std::string     slippi_version      = "";
116  std::string     parser_version      = "";
117  std::string     game_start_raw      = "";
118  std::string     metadata            = "";
119  std::string     played_on           = "";
120  std::string     start_time          = "";
121  int8_t          winner_id           = -1;
122  bool            teams               = false;
123  uint16_t        stage               = 0;
124  uint32_t        seed                = 0;
125  bool            pal                 = false;
126  bool            frozen              = false;
127  uint8_t         end_type            = 0;
128  int8_t          lras                = -1;
129  int32_t         first_frame         = LOAD_FRAME;
130  int32_t         last_frame          = 0;
131  uint32_t        frame_count         = 0;
132  uint8_t         timer               = 0;
133  int8_t          items_on            = 0;
134  bool            sudden_death        = false;
135  uint32_t        num_items           = 0;
136  SlippiPlayer    player[8]           = {0};
137  SlippiItem      item[MAX_ITEMS]     = {0};
138
139  void setFrames(int32_t max_frames);
140  void cleanup();
141  std::string replayAsJson(bool delta);
142};
143
144
145}
146
147#endif /* REPLAY_H_ */