-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathReplay.hpp
More file actions
195 lines (159 loc) · 6.08 KB
/
Replay.hpp
File metadata and controls
195 lines (159 loc) · 6.08 KB
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
#pragma once
#include <cstdlib>
#include <string>
#include <utility>
#include <vector>
#include <map>
#include "sombrero/shared/FastVector3.hpp"
#include "sombrero/shared/FastQuaternion.hpp"
#include "sombrero/shared/Vector3Utils.hpp"
using namespace std;
struct ReplayInfo {
string version;
string gameVersion;
string timestamp;
ReplayInfo(string version, string gameVersion, string timestamp) : version(version),
gameVersion(gameVersion),
timestamp(timestamp) {}
string playerID;
string playerName;
string platform;
string trackingSystem;
string hmd;
string controller;
string hash;
string songName;
string mapper;
string difficulty;
int score;
string mode;
string environment;
string modifiers;
float jumpDistance = 0;
bool leftHanded = false;
float height = 0;
float startTime = 0;
float failTime = 0;
float speed = 0;
};
struct ReplayTransform {
Sombrero::FastVector3 position;
Sombrero::FastQuaternion rotation;
constexpr ReplayTransform(Sombrero::FastVector3 const &position, Sombrero::FastQuaternion const &rotation) : position(position),
rotation(rotation) {}
};
struct Frame {
float time;
int fps;
ReplayTransform head;
ReplayTransform leftHand;
ReplayTransform rightHand;
constexpr Frame(float time, int fps, ReplayTransform const &head, ReplayTransform const &leftHand, ReplayTransform const &rightHand) : time(
time), fps(fps), head(head), leftHand(leftHand), rightHand(rightHand) {}
};
struct ReplayNoteCutInfo {
bool speedOK;
bool directionOK;
bool saberTypeOK;
bool wasCutTooSoon;
float saberSpeed;
bool cutDistanceToCenterPositive;
Sombrero::FastVector3 saberDir;
int saberType;
float timeDeviation;
float cutDirDeviation;
Sombrero::FastVector3 cutPoint;
Sombrero::FastVector3 cutNormal;
float cutDistanceToCenter;
float cutAngle;
float beforeCutRating;
float afterCutRating;
};
enum struct NoteEventType {
GOOD = 0,
BAD = 1,
MISS = 2,
BOMB = 3
};
struct NoteEvent {
int noteID;
float spawnTime;
float eventTime;
NoteEventType eventType = NoteEventType::GOOD;
ReplayNoteCutInfo noteCutInfo;
constexpr NoteEvent(int noteId, float spawnTime) : noteID(noteId), spawnTime(spawnTime) {}
};
struct WallEvent {
int wallID;
float spawnTime;
float energy;
float time;
constexpr WallEvent(int wallId, float spawnTime) : wallID(wallId), spawnTime(spawnTime) {}
};
struct AutomaticHeight {
constexpr AutomaticHeight(float height, float time) : height(height), time(time) {}
float height;
float time;
};
struct Pause {
long duration;
float time;
};
struct SaberOffsets {
Sombrero::FastVector3 LeftSaberLocalPosition;
Sombrero::FastQuaternion LeftSaberLocalRotation;
Sombrero::FastVector3 RightSaberLocalPosition;
Sombrero::FastQuaternion RightSaberLocalRotation;
SaberOffsets() : LeftSaberLocalPosition(Sombrero::FastVector3(0, 0, 0)), LeftSaberLocalRotation(Sombrero::FastQuaternion(0, 0, 0, 1)), RightSaberLocalPosition(Sombrero::FastVector3(0, 0, 0)), RightSaberLocalRotation(Sombrero::FastQuaternion(0, 0, 0, 1)) {}
constexpr SaberOffsets(Sombrero::FastVector3 const &leftSaberLocalPosition, Sombrero::FastQuaternion const &leftSaberLocalRotation, Sombrero::FastVector3 const &rightSaberLocalPosition, Sombrero::FastQuaternion const &rightSaberLocalRotation) : LeftSaberLocalPosition(leftSaberLocalPosition), LeftSaberLocalRotation(leftSaberLocalRotation), RightSaberLocalPosition(rightSaberLocalPosition), RightSaberLocalRotation(rightSaberLocalRotation) {}
};
using CustomDataCallback = std::function<void(std::string, int*, void**)>;
class Replay
{
public:
void Encode(ofstream& stream) const;
static std::optional<ReplayInfo> DecodeInfo(ifstream& stream);
static std::map<std::string, CustomDataCallback> customDataProviders;
explicit Replay(ReplayInfo info) : info(std::move(info)) {}
Replay(Replay&&) = default; // make move default, avoid copying
ReplayInfo info;
vector<Frame> frames;
vector<NoteEvent> notes;
vector<WallEvent> walls;
vector<AutomaticHeight> heights;
vector<Pause> pauses;
SaberOffsets saberOffsets;
private:
static void Encode(char value, ofstream& stream);
static void Encode(int value, ofstream& stream);
static void Encode(long value, ofstream& stream);
static void Encode(bool value, ofstream& stream);
static void Encode(float value, ofstream& stream);
static void Encode(string value, ofstream& stream);
// template methods MUST be header only
template<class T>
static void Encode(vector<T> const& list, ofstream& stream) {
size_t count = list.size();
Encode((int)count, stream);
for (size_t i = 0; i < count; i++)
{
Encode(list[i], stream);
}
}
static void Encode(ReplayInfo const &info, ofstream& stream);
static void Encode(Sombrero::FastVector3 const &vector, ofstream& stream);
static void Encode(Sombrero::FastQuaternion const &quaternion, ofstream& stream);
static void Encode(Frame const &frame, ofstream& stream);
static void Encode(NoteEvent const ¬e, ofstream& stream);
static void Encode(WallEvent const &wall, ofstream& stream);
static void Encode(AutomaticHeight const &height, ofstream& stream);
static void Encode(Pause const &pause, ofstream& stream);
static void Encode(SaberOffsets const &saberOffsets, ofstream& stream);
static void EncodeCustomData(ofstream& stream);
static char DecodeChar(ifstream& stream);
static int DecodeInt(ifstream& stream);
static long DecodeLong(ifstream& stream);
static bool DecodeBool(ifstream& stream);
static float DecodeFloat(ifstream& stream);
static string DecodeString(ifstream& stream);
};