Etterna 0.74.4
Loading...
Searching...
No Matches
Replay.h
1#ifndef REPLAY_H
2#define REPLAY_H
3
4#include "Etterna/Models/Misc/EnumHelper.h"
5#include "ReplayConstantsAndTypes.h"
6#include "Etterna/Models/NoteData/NoteData.h"
7#include <set>
8
9struct HighScore;
10class TimingData;
11class Steps;
12class Style;
13
14class Replay
15{
16 public:
17 Replay();
18 Replay(const HighScore* hs);
19 ~Replay();
20
21 inline auto GetBasicPath() const -> const std::string
22 {
23 return BASIC_REPLAY_DIR + scoreKey;
24 }
25
26 inline auto GetFullPath() const -> const std::string
27 {
28 return FULL_REPLAY_DIR + scoreKey;
29 }
30
31 inline auto GetInputPath() const -> const std::string
32 {
33 return INPUT_DATA_DIR + scoreKey;
34 }
35
36 inline auto GetOnlinePath() const -> const std::string
37 {
38 return ONLINE_DATA_DIR + scoreKey;
39 }
40
41 auto GetOffsetVector() const -> const std::vector<float>&
42 {
43 return vOffsetVector;
44 }
45 auto GetCopyOfOffsetVector() const -> std::vector<float>
46 {
47 return vOffsetVector;
48 }
49 void SetOffsetVector(const std::vector<float>& v) { vOffsetVector = v; }
50
51 auto GetNoteRowVector() const -> const std::vector<int>&
52 {
53 return vNoteRowVector;
54 }
55 auto GetCopyOfNoteRowVector() const -> std::vector<int>
56 {
57 return vNoteRowVector;
58 }
59 void SetNoteRowVector(const std::vector<int>& v) { vNoteRowVector = v; }
60
61 auto GetTrackVector() const -> const std::vector<int>&
62 {
63 return vTrackVector;
64 }
65 auto GetCopyOfTrackVector() const -> std::vector<int>
66 {
67 return vTrackVector;
68 }
69 void SetTrackVector(const std::vector<int>& v) { vTrackVector = v; }
70
71 auto GetTapNoteTypeVector() const -> const std::vector<TapNoteType>&
72 {
73 return vTapNoteTypeVector;
74 }
75 auto GetCopyOfTapNoteTypeVector() const -> std::vector<TapNoteType>
76 {
77 return vTapNoteTypeVector;
78 }
79 void SetTapNoteTypeVector(const std::vector<TapNoteType>& v)
80 {
81 vTapNoteTypeVector = v;
82 }
83
84 auto GetHoldReplayDataVector() const -> const std::vector<HoldReplayResult>&
85 {
86 return vHoldReplayDataVector;
87 }
88 auto GetCopyOfHoldReplayDataVector() const -> std::vector<HoldReplayResult>
89 {
90 return vHoldReplayDataVector;
91 }
92 void SetHoldReplayDataVector(const std::vector<HoldReplayResult>& v)
93 {
94 vHoldReplayDataVector = v;
95 }
96
97 auto GetMineReplayDataVector() const -> const std::vector<MineReplayResult>&
98 {
99 return vMineReplayDataVector;
100 }
101 auto GetCopyOfMineReplayDataVector() const -> std::vector<MineReplayResult>
102 {
103 return vMineReplayDataVector;
104 }
105 void SetMineReplayDataVector(const std::vector<MineReplayResult>& v)
106 {
107 vMineReplayDataVector = v;
108 }
109
110 auto GetOnlineReplayTimestampVector() const -> const std::vector<float>&
111 {
112 return vOnlineReplayTimestampVector;
113 }
114 auto GetCopyOfOnlineReplayTimestampVector() const -> std::vector<float>
115 {
116 return vOnlineReplayTimestampVector;
117 }
118 void SetOnlineReplayTimestampVector(const std::vector<float>& v)
119 {
120 vOnlineReplayTimestampVector = v;
121 }
122
123 auto GetInputDataVector() const -> const std::vector<InputDataEvent>&
124 {
125 return InputData;
126 }
127 auto GetCopyOfInputDataVector() const -> std::vector<InputDataEvent>
128 {
129 return InputData;
130 }
131 void SetInputDataVector(const std::vector<InputDataEvent>& v)
132 {
133 InputData = v;
134 }
135
136 auto GetMissReplayDataVector() const -> const std::vector<MissReplayResult>&
137 {
138 return vMissReplayDataVector;
139 }
140 auto GetCopyOfMissReplayDataVector() const -> std::vector<MissReplayResult>
141 {
142 return vMissReplayDataVector;
143 }
144 void SetMissReplayDataVector(const std::vector<MissReplayResult>& v)
145 {
146 vMissReplayDataVector = v;
147 }
148
149 auto GetReplaySnapshotMap() const -> const std::map<int, ReplaySnapshot>&
150 {
151 return m_ReplaySnapshotMap;
152 }
153 auto GetCopyOfReplaySnapshotMap() const -> std::map<int, ReplaySnapshot>
154 {
155 return m_ReplaySnapshotMap;
156 }
157 void SetReplaySnapshotMap(const std::map<int, ReplaySnapshot>& m)
158 {
159 m_ReplaySnapshotMap = m;
160 }
161
162 auto GetJudgeInfo() -> JudgeInfo& { return judgeInfo; }
163 auto GetCopyOfJudgeInfo() const -> JudgeInfo { return judgeInfo; }
164 void SetJudgeInfo(const JudgeInfo& ji) { judgeInfo = ji; }
165
166 auto GetScoreKey() const -> std::string { return scoreKey; }
167 void SetScoreKey(std::string& key) { scoreKey = key; }
168 auto GetChartKey() const -> std::string { return chartKey; }
169 void SetChartKey(std::string& key) { chartKey = key; }
170 auto GetMusicRate() const -> float { return fMusicRate; }
171 void SetMusicRate(float f) { fMusicRate = f; }
172 auto GetSongOffset() const -> float { return fSongOffset; }
173 void SetSongOffset(float f) { fSongOffset = f; }
174 auto GetGlobalOffset() const -> float { return fGlobalOffset; }
175 void SetGlobalOffset(float f) { fGlobalOffset = f; }
176 auto GetRngSeed() const -> int { return rngSeed; }
177 void SetRngSeed(int seed) { rngSeed = seed; }
178 auto GetModifiers() const -> std::string { return mods; }
179 void SetModifiers(std::string& modstr) { mods = modstr; }
180
181 void SetUseReprioritizedNoteRows(bool b)
182 {
183 if (b != useReprioritizedNoterows) {
184 if (IsOnlineScore()) {
185 if (vOnlineNoteRowVector.empty() &&
187 // initial backup
188 vOnlineOffsetVector = GetCopyOfOffsetVector();
189 vOnlineNoteRowVector = GetCopyOfNoteRowVector();
190 vOnlineTrackVector = GetCopyOfTrackVector();
191 vOnlineTapNoteTypeVector = GetCopyOfTapNoteTypeVector();
192 }
193 }
194 ClearPrimitiveVectors();
195 ClearReprioritizedVectors();
196 }
197 if (generatedInputData) {
198 InputData.clear();
199 vMissReplayDataVector.clear();
200 vHoldReplayDataVector.clear();
201 vMineReplayDataVector.clear();
202 generatedInputData = false;
203 }
204 useReprioritizedNoterows = b;
205 }
206 auto UsingReprioritizedNoteRows() -> bool
207 {
208 return useReprioritizedNoterows;
209 }
210 auto GetReprioritizedMissData() const
211 -> const std::vector<MissReplayResult>&
212 {
213 return vReprioritizedMissData;
214 }
215 auto GetCopyOfReprioritizedMissData() const -> std::vector<MissReplayResult>
216 {
217 return vReprioritizedMissData;
218 }
219 void SetReprioritizedMissData(const std::vector<MissReplayResult>& v) {
220 vReprioritizedMissData = v;
221 }
222 auto GetReprioritizedHoldData() const
223 -> const std::vector<HoldReplayResult>&
224 {
225 return vReprioritizedHoldData;
226 }
227 auto GetCopyOfReprioritizedHoldData() const -> std::vector<HoldReplayResult>
228 {
229 return vReprioritizedHoldData;
230 }
231 void SetReprioritizedHoldData(const std::vector<HoldReplayResult>& v)
232 {
233 vReprioritizedHoldData = v;
234 }
235 auto GetReprioritizedMineData() const
236 -> const std::vector<MineReplayResult>&
237 {
238 return vReprioritizedMineData;
239 }
240 auto GetCopyOfReprioritizedMineData() const -> std::vector<MineReplayResult>
241 {
242 return vReprioritizedMineData;
243 }
244 void SetReprioritizedMineData(const std::vector<MineReplayResult>& v)
245 {
246 vReprioritizedMineData = v;
247 }
248
249 auto GetRelevantMissData() const -> const std::vector<MissReplayResult>&
250 {
251 if (useReprioritizedNoterows) {
252 return vReprioritizedMissData;
253 } else {
254 return vMissReplayDataVector;
255 }
256 }
257 auto GetRelevantHoldData() const -> const std::vector<HoldReplayResult>& {
258 if (useReprioritizedNoterows) {
259 return vReprioritizedHoldData;
260 } else {
261 return vHoldReplayDataVector;
262 }
263 }
264 auto GetRelevantMineData() const -> const std::vector<MineReplayResult>& {
265 if (useReprioritizedNoterows) {
266 return vReprioritizedMineData;
267 } else {
268 return vMineReplayDataVector;
269 }
270 }
271
272
273 ReplayType GetReplayType() const
274 {
275 if (!InputData.empty()) {
276 // detailed data
277 return ReplayType_Input;
278 } else if (!vTrackVector.empty()) {
279 // column data
280 return ReplayType_V2;
281 } else if (!vNoteRowVector.empty()) {
282 // no column/extra data
283 return ReplayType_V1;
284 } else {
285 // it probably isn't loaded
286 return ReplayType_Invalid;
287 }
288 }
289
291 auto HasColumnData() const -> bool
292 {
293 const auto t = GetReplayType();
294 return t >= ReplayType_V2 && t < NUM_ReplayType;
295 }
296
297 auto WriteReplayData() -> bool;
298 auto WriteInputData() -> bool;
299 auto LoadReplayData() -> bool;
300 auto HasReplayData() -> bool;
301 auto HasWrittenReplayData() -> bool;
302
305 auto FillInBlanksForInputData() -> bool;
306
309 auto GeneratePrimitiveVectors() -> bool;
311 auto GenerateNoterowsFromTimestamps() -> bool;
313 auto GenerateInputData() -> bool;
314
317 auto ReprioritizeInputData() -> bool;
318
320 auto GeneratePlaybackEvents(int startRow = 0)
321 -> std::map<int, std::vector<PlaybackEvent>>;
322
324 auto GenerateJudgeInfoAndReplaySnapshots(int startingRow = 0,
325 float timingScale = 1.F) -> bool;
326
327 // Instead of making some complex iterator...
328 // Just offer both solutions
331 auto GenerateDroppedHoldColumnsToRowsMap(int startRow = 0)
332 -> std::map<int, std::set<int>>;
335 auto GenerateDroppedHoldRowsToColumnsMap(int startRow = 0)
336 -> std::map<int, std::set<int>>;
337
339 void ValidateOffsets();
340
347 auto ValidateInputDataNoterows() -> bool;
348
353
358
359 auto GetHighScore() -> HighScore*;
360 auto GetSteps() -> Steps*;
361 auto GetNoteData(Steps* pSteps = nullptr, bool bTransform = true)
362 -> NoteData;
363 auto GetTimingData() -> TimingData*;
364 auto GetStyle() -> const Style*;
365
366 auto GetReplaySnapshotForNoterow(int row)
367 -> std::shared_ptr<ReplaySnapshot>;
368
370 auto CanSafelyTransformNoteData() -> bool;
371
372 bool IsOnlineScore() const
373 {
374 return scoreKey.find("Online_") != std::string::npos;
375 }
376
377 void Unload()
378 {
379 useReprioritizedNoterows = false;
380 generatedInputData = false;
381
382 // stats
383 m_ReplaySnapshotMap.clear();
384
385 ClearReprioritizedVectors();
386
387 // replay data
388 ClearPrimitiveVectors();
389
390 InputData.clear();
391 vMissReplayDataVector.clear();
392 vHoldReplayDataVector.clear();
393 vMineReplayDataVector.clear();
394
395 InputData.shrink_to_fit();
396 vMissReplayDataVector.shrink_to_fit();
397 vHoldReplayDataVector.shrink_to_fit();
398 vMineReplayDataVector.shrink_to_fit();
399
400 // extra online data "backups"
401 vOnlineOffsetVector.clear();
402 vOnlineNoteRowVector.clear();
403 vOnlineTrackVector.clear();
404 vOnlineTapNoteTypeVector.clear();
405 vOnlineOffsetVector.shrink_to_fit();
406 vOnlineNoteRowVector.shrink_to_fit();
407 vOnlineTrackVector.shrink_to_fit();
408 vOnlineTapNoteTypeVector.shrink_to_fit();
409 }
410
413 auto SetHighScoreMods() -> void;
414
416 void PushSelf(lua_State* L);
417
418 private:
419 auto LoadReplayDataBasic(const std::string& replayDir = BASIC_REPLAY_DIR)
420 -> bool;
421 auto LoadReplayDataFull(const std::string& replayDir = FULL_REPLAY_DIR)
422 -> bool;
423 auto LoadInputData(const std::string& replayDir = INPUT_DATA_DIR) -> bool;
424 auto LoadOnlineDataFromDisk(const std::string& replayDir = ONLINE_DATA_DIR)
425 -> bool;
426 auto LoadStoredOnlineData() -> bool;
427
431 auto GenerateReplayV2DataPresumptively() -> bool;
432
433 void ClearPrimitiveVectors() {
434 vOffsetVector.clear();
435 vNoteRowVector.clear();
436 vTrackVector.clear();
437 vTapNoteTypeVector.clear();
438 vOnlineReplayTimestampVector.clear();
439
440 vOffsetVector.shrink_to_fit();
441 vNoteRowVector.shrink_to_fit();
442 vTrackVector.shrink_to_fit();
443 vTapNoteTypeVector.shrink_to_fit();
444 vOnlineReplayTimestampVector.shrink_to_fit();
445 }
446
447 void ClearReprioritizedVectors() {
448 vReprioritizedMissData.clear();
449 vReprioritizedHoldData.clear();
450 vReprioritizedMineData.clear();
451 vReprioritizedMissData.shrink_to_fit();
452 vReprioritizedHoldData.shrink_to_fit();
453 vReprioritizedMineData.shrink_to_fit();
454 }
455
456 std::map<int, ReplaySnapshot> m_ReplaySnapshotMap{};
457 JudgeInfo judgeInfo{};
458
459 // optimization for ReplaySnapshot generation
460 // filled out by RegenerateJudgmentInfo
461 std::set<int> significantNoterows{};
462
463 // for snapshot stuff and rescoring
464 // set by Lua, data filled by ReprioritizeInputData
465 bool useReprioritizedNoterows = false;
466 std::vector<MissReplayResult> vReprioritizedMissData{};
467 std::vector<MineReplayResult> vReprioritizedMineData{};
468 std::vector<HoldReplayResult> vReprioritizedHoldData{};
469
470 std::string scoreKey{};
471 std::string chartKey{};
472 float fMusicRate = 1.F;
473 float fSongOffset = 0.F;
474 float fGlobalOffset = 0.F;
475 std::string mods{};
476 int rngSeed = 0;
477
478 std::vector<InputDataEvent> InputData{};
479 std::vector<MissReplayResult> vMissReplayDataVector{};
480 std::vector<float> vOffsetVector{};
481 std::vector<int> vNoteRowVector{};
482 std::vector<int> vTrackVector{};
483 std::vector<TapNoteType> vTapNoteTypeVector{};
484 std::vector<HoldReplayResult> vHoldReplayDataVector{};
485 std::vector<MineReplayResult> vMineReplayDataVector{};
486 std::vector<float> vOnlineReplayTimestampVector{};
487
488 // mainly useful for the noterow reprioritization stuff
489 // because if we switch that and it is generated, force generate
490 // the reason is that given only v2, we generate inputdata
491 // that input data outputs a separate set of v2 data
492 // and reloading that v2 data generates wrong input data
493 // so this just refreshes the whole process
494 bool generatedInputData = false;
495
496 // if we failed to load data, dont try again and waste time
497 bool attemptedToLoadInputData = false;
498 bool loadResultInputData = false;
499 bool attemptedToLoadReplayV2 = false;
500 bool loadResultReplayV2 = false;
501 bool attemptedToLoadReplayV1 = false;
502 bool loadResultReplayV1 = false;
503
504 bool LoadedInputData(bool b) {
505 attemptedToLoadInputData = true;
506 loadResultInputData = b;
507 return b;
508 }
509 bool LoadedReplayV2(bool b) {
510 attemptedToLoadReplayV2 = true;
511 loadResultReplayV2 = b;
512 return b;
513 }
514 bool LoadedReplayV1(bool b) {
515 attemptedToLoadReplayV1 = true;
516 loadResultReplayV1 = b;
517 return b;
518 }
519
521 // storage of vectors temporarily for online scores only
522 std::vector<float> vOnlineOffsetVector{};
523 std::vector<int> vOnlineNoteRowVector{};
524 std::vector<int> vOnlineTrackVector{};
525 std::vector<TapNoteType> vOnlineTapNoteTypeVector{};
527};
528
529#endif
Holds data about the notes that the player is supposed to hit.
Definition NoteData.h:43
Definition Replay.h:15
auto GenerateNoterowsFromTimestamps() -> bool
Generate Noterow vector using online timestamp replay format.
Definition Replay.cpp:1754
void VerifyInputDataAndReplayData()
Definition Replay.cpp:2416
void ValidateOffsets()
Offsets can be really weird - Remove all impossible offsets.
Definition Replay.cpp:1821
auto GeneratePrimitiveVectors() -> bool
Definition Replay.cpp:1393
auto GeneratePlaybackEvents(int startRow=0) -> std::map< int, std::vector< PlaybackEvent > >
Generate events used for playing back replay in gameplay.
Definition Replay.cpp:2998
auto ReprioritizeInputData() -> bool
Definition Replay.cpp:2606
void VerifyGeneratedInputDataMatchesReplayData()
Definition Replay.cpp:2239
auto HasColumnData() const -> bool
true for V2 and InputData
Definition Replay.h:291
void PushSelf(lua_State *L)
Lua.
auto CanSafelyTransformNoteData() -> bool
A check to see if the Replay has an RNG seed, if it uses shuffle.
Definition Replay.cpp:244
auto GenerateDroppedHoldRowsToColumnsMap(int startRow=0) -> std::map< int, std::set< int > >
Definition Replay.cpp:3077
auto GenerateDroppedHoldColumnsToRowsMap(int startRow=0) -> std::map< int, std::set< int > >
Definition Replay.cpp:3058
auto SetHighScoreMods() -> void
Definition Replay.cpp:223
auto GenerateInputData() -> bool
Generate InputData using any ReplayData.
Definition Replay.cpp:2850
auto FillInBlanksForInputData() -> bool
Definition Replay.cpp:1143
auto ValidateInputDataNoterows() -> bool
Definition Replay.cpp:1862
auto GenerateJudgeInfoAndReplaySnapshots(int startingRow=0, float timingScale=1.F) -> bool
For Stats and ReplaySnapshots.
Definition Replay.cpp:3096
auto WriteInputData() -> bool
Definition Replay.cpp:399
Holds note information for a Song.
Definition Steps.h:42
Definition Style.h:22
Holds data for translating beats<->seconds.
Definition TimingData.h:54
The high score that is earned by a player.
Definition HighScore.h:18
Definition ReplayConstantsAndTypes.h:228