A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
KTestSystem.hh
Go to the documentation of this file.
1#pragma once
2
3#include "host/KSystem.hh"
4#include "host/Option.hh"
5
8#include <egg/math/Quat.hh>
9
11
12#include <queue>
13
14namespace Kinoko {
15
17class KTestSystem final : public KSystem {
18public:
19 void init() override;
20 void calc() override;
21 bool run() override;
22 void parseOptions(int argc, char **argv) override;
23
25 static void DestroyInstance();
26
28 return static_cast<KTestSystem *>(s_instance);
29 }
30
31private:
32 struct TestCase {
33 std::string name;
34 std::string rkgPath;
35 std::string krkgPath;
37 };
38
58
60
62 ~KTestSystem() override;
63
64 KTestSystem(const KTestSystem &) = delete;
66
67 template <IntegralType T>
68 void checkDesync(const T &t0, const T &t1, const char *name) {
69 if (t0 == t1) {
70 return;
71 }
72
73 if (m_sync) {
74 REPORT("Test Case Failed: %s [%d / %d]", getCurrentTestCase().name.c_str(),
76 }
77
78 REPORT("DESYNC! Name: %s", name);
79 REPORT("Expected: %d", t0);
80 REPORT("Observed: %d", t1);
81
82 m_sync = false;
83 }
84
85 template <typename T>
86 void checkDesync(const T &t0, const T &t1, const char *name) {
87 if (t0 == t1) {
88 return;
89 }
90
92
93 if (m_sync) {
94 REPORT("Test Case Failed: %s [%d / %d]", getCurrentTestCase().name.c_str(),
96 }
97
98 REPORT("DESYNC! Name: %s", name);
99 std::string s0(t0);
100 std::string s1(t1);
101 REPORT("Expected: %s", s0.c_str());
102 REPORT("Observed: %s", s1.c_str());
103
105
106 m_sync = false;
107 }
108
109 void checkDesync(const f32 &t0, const f32 &t1, const char *name) {
110 if (t0 == t1) {
111 return;
112 }
113
115
116 if (m_sync) {
117 REPORT("Test Case Failed: %s [%d / %d]", getCurrentTestCase().name.c_str(),
119 }
120
121 REPORT("DESYNC! Name: %s", name);
122 std::string s0 = std::to_string(t0);
123 std::string s1 = std::to_string(t1);
124 REPORT("Expected: 0x%08X | %s", f2u(t0), s0.c_str());
125 REPORT("Observed: 0x%08X | %s", f2u(t1), s1.c_str());
126
128
129 m_sync = false;
130 }
131
132 void initSuite();
133
134 void startNextTestCase();
135 bool popTestCase();
136
137 bool calcTest();
138 TestData findCurrentFrameEntry();
139 void testFrame(const TestData &data);
140
141 bool runTest();
142 void writeTestOutput() const;
143
144 const TestCase &getCurrentTestCase() const;
145
146 static void OnInit(System::RaceConfig *config, void *arg);
147
150 std::queue<TestCase, std::deque<TestCase, EGG::Allocator<TestCase>>> m_testCases;
152
157 bool m_sync;
158};
159
160} // namespace Kinoko
#define EGG_NEW_DELETE_FRIEND
Grants Kinoko::EGG::egg_new and Kinoko::EGG::egg_delete access to a class' private constructors/destr...
Definition Heap.hh:186
#define REPORT(m,...)
Definition Logger.hh:38
void disableAllocation()
Definition Heap.hh:48
void enableAllocation()
Definition Heap.hh:52
A stream of data stored in memory.
Definition Stream.hh:81
Manages the scene stack and transitions between scenes.
Scene * currentScene() const
Heap * heap() const
Definition Scene.hh:61
Base interface for a Kinoko system.
Definition KSystem.hh:10
static KSystem * s_instance
Definition KSystem.hh:33
void checkDesync(const T &t0, const T &t1, const char *name)
Host::EOption m_testMode
Differentiates between test suite and ghost+krkg.
static KTestSystem * CreateInstance()
bool run() override
Executes a run.
void parseOptions(int argc, char **argv) override
Parses non-generic command line options.
static void OnInit(System::RaceConfig *config, void *arg)
Initializes the race configuration as needed for test cases.
const TestCase & getCurrentTestCase() const
Gets the current test case.
EGG::SceneManager * m_sceneMgr
void startNextTestCase()
Starts the next test case.
EGG::RamStream m_stream
void writeTestOutput() const
Writes details about the current test to file.
static void DestroyInstance()
KTestSystem(const KTestSystem &)=delete
void testFrame(const TestData &data)
Tests the frame against the provided test data.
void calc() override
Executes a frame.
void checkDesync(const f32 &t0, const f32 &t1, const char *name)
TestData findCurrentFrameEntry()
Finds the test data of the current frame.
std::queue< TestCase, std::deque< TestCase, EGG::Allocator< TestCase > > > m_testCases
bool runTest()
Runs a single test case, and ends when the test is finished or when a desync is found.
void init() override
Initializes the system.
bool popTestCase()
Pops the current test case and frees the KRKG buffer.
static KTestSystem * Instance()
bool calcTest()
Checks one frame in the test.
KTestSystem(KTestSystem &&)=delete
Initializes the player with parameters specified in the provided ghost file.
Definition RaceConfig.hh:23
float f32
Definition Memory.hh:21
uint8_t u8
Definition Memory.hh:16
uint16_t u16
Definition Memory.hh:17
A quaternion, used to represent 3D rotation.
Definition Quat.hh:12
A 3D float vector.
Definition Vector.hh:108