Skip to content

Commit 97943f2

Browse files
committed
add option to render exact floating point values
1 parent 045af16 commit 97943f2

File tree

3 files changed

+65
-15
lines changed

3 files changed

+65
-15
lines changed

src/PrimeWatch.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ void PrimeWatch::initGlAndImgui(const int width, const int height) {
9797
};
9898

9999
// TODO: probably remove this
100-
if (std::filesystem::exists("../mem1.raw")) {
101-
GameMemory::loadFromPath("../mem1.raw");
100+
if (std::filesystem::exists("./mem1.raw")) {
101+
GameMemory::loadFromPath("./mem1.raw");
102102
}
103103
}
104104

@@ -142,7 +142,7 @@ void PrimeWatch::processInput() {
142142

143143
// if shift + '1', save and enable ghost 1, etc for 1-5
144144
auto keys = std::array{ GLFW_KEY_1, GLFW_KEY_2, GLFW_KEY_3, GLFW_KEY_4, GLFW_KEY_5 };
145-
assert(worldRenderer.playerGhosts == keys.size());
145+
assert(worldRenderer.playerGhosts.size() == keys.size());
146146
for (int i = 0; i < keys.size(); i++) {
147147
if (io.KeysDown[keys[i]]) {
148148
if (io.KeyShift) {
@@ -471,6 +471,7 @@ void PrimeWatch::doMainMenu() {
471471
if (ImGui::MenuItem("Raw Demo View", nullptr, showDemoView)) {
472472
showDemoView = !showDemoView;
473473
}
474+
TOGGLE_MENU("Show exact floating point values", GameObjectRenderers::render_exact_values);
474475
ImGui::EndMenu();
475476
}
476477
ImGui::EndMainMenuBar();

src/defs/GameObjectRenderers.cpp

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ using namespace std;
99
using namespace GameDefinitions;
1010

1111
namespace GameObjectRenderers {
12+
bool render_exact_values = false;
1213
unordered_map<string, RenderFunc> specialRenderers{ // NOLINT(cert-err58-cpp) // it won't throw (or at least I don't care if it does right now)
1314
{"u8", &primitiveRenderer},
1415
{"u16", &primitiveRenderer},
@@ -194,12 +195,22 @@ namespace GameObjectRenderers {
194195
} else if (typ[0] == 'f') {
195196
if (typ == "f32") {
196197
float f = member.read_f32();
197-
itemText += fmt::format("{:0.3f}", f);
198-
clip = fmt::format("{:f}", f);
198+
if (render_exact_values) {
199+
itemText += fmt::format("{:0.8f}", f);
200+
clip = fmt::format("{:f} {:x}", f, *reinterpret_cast<uint32_t *>(&f));
201+
} else {
202+
itemText += fmt::format("{:0.3f}", f);
203+
clip = fmt::format("{:f}", f, *reinterpret_cast<uint32_t *>(&f));
204+
}
199205
} else {
200206
double d = member.read_f64();
201-
itemText += fmt::format("{:0.3f}", d);
202-
clip = fmt::format("{:f}", d);
207+
if (render_exact_values) {
208+
itemText += fmt::format("{:0.16f}", d);
209+
clip = fmt::format("{:f} {:x}", d, *reinterpret_cast<uint64_t *>(&d));
210+
} else {
211+
itemText += fmt::format("{:0.3f}", d);
212+
clip = fmt::format("{:f}", d);
213+
}
203214
}
204215
} else {
205216
itemText += fmt::format("Unknown number type {}", typ);
@@ -219,11 +230,24 @@ namespace GameObjectRenderers {
219230
float x = GameMemory::read_float(addr);
220231
float y = GameMemory::read_float(addr + 4);
221232
float z = GameMemory::read_float(addr + 8);
233+
string msg;
234+
if (render_exact_values) {
235+
msg = fmt::format("{} [{:0.8f}, {:0.8f}, {:0.8f}]", member.name, x, y, z);
236+
} else {
237+
msg = fmt::format("{} [{:0.3f}, {:0.3f}, {:0.3f}]", member.name, x, y, z);;
238+
}
222239

223-
string msg = fmt::format("{} [{:0.3f}, {:0.3f}, {:0.3f}]", member.name, x, y, z);
224240
ImGui::Text("%s", msg.c_str());
225241
if (ImGui::IsItemClicked()) {
226-
string clip = fmt::format("{:f}, {:f}, {:f}", x, y, z);
242+
string clip;
243+
if (render_exact_values) {
244+
clip = fmt::format("{:f} {:x}, {:f} {:x}, {:f} {:x}",
245+
x, *reinterpret_cast<uint32_t *>(&x),
246+
y, *reinterpret_cast<uint32_t *>(&y),
247+
z, *reinterpret_cast<uint32_t *>(&z));
248+
} else {
249+
clip = fmt::format("{:f}, {:f}, {:f}", x, y, z);
250+
}
227251
ImGui::SetClipboardText(clip.c_str());
228252
}
229253
if (ImGui::IsItemHovered()) {
@@ -239,11 +263,25 @@ namespace GameObjectRenderers {
239263
float z = GameMemory::read_float(addr + 8);
240264
float w = GameMemory::read_float(addr + 12);
241265

242-
string msg = fmt::format("{} [{:0.3f}, {:0.3f}, {:0.3f}, {:0.3f}]", member.name, x, y, z, w);
266+
string msg;
267+
if (render_exact_values) {
268+
msg = fmt::format("{} [{:0.8f}, {:0.8f}, {:0.8f}, {:0.8f}]", member.name, x, y, z, w);
269+
} else {
270+
msg = fmt::format("{} [{:0.3f}, {:0.3f}, {:0.3f}, {:0.3f}]", member.name, x, y, z, w);
271+
}
243272

244273
ImGui::Text("%s", msg.c_str());
245274
if (ImGui::IsItemClicked()) {
246-
string clip = fmt::format("{:f}, {:f}, {:f}, {:f}", x, y, z, w);
275+
string clip;
276+
if (render_exact_values) {
277+
clip = fmt::format("{:f} {:x}, {:f} {:x}, {:f} {:x}, {:f} {:x}",
278+
x, *reinterpret_cast<uint32_t *>(&x),
279+
y, *reinterpret_cast<uint32_t *>(&y),
280+
z, *reinterpret_cast<uint32_t *>(&z),
281+
w, *reinterpret_cast<uint32_t *>(&w));
282+
} else {
283+
clip = fmt::format("{:f}, {:f}, {:f}, {:f}", x, y, z, w);
284+
}
247285
ImGui::SetClipboardText(clip.c_str());
248286
}
249287
if (ImGui::IsItemHovered()) {
@@ -265,8 +303,13 @@ namespace GameObjectRenderers {
265303
string clip;
266304
for (int c = 0; c < 3; c++) {
267305
float v = GameMemory::read_float(addr + (c * 4 + r) * 4);
268-
row += fmt::format("{:0.2f}, ", v);
269-
clip += fmt::format("{}, ", v);
306+
if (render_exact_values) {
307+
row += fmt::format("{:0.8f}, ", v);
308+
clip += fmt::format("{:f} {:x}, ", v, *reinterpret_cast<uint32_t *>(&v));
309+
} else {
310+
row += fmt::format("{:0.2f}, ", v);
311+
clip += fmt::format("{:f}, ", v);
312+
}
270313
}
271314
ImGui::Text("%s", row.c_str());
272315
if (ImGui::IsItemHovered()) {
@@ -294,8 +337,13 @@ namespace GameObjectRenderers {
294337
string clip;
295338
for (int c = 0; c < 4; c++) {
296339
float v = GameMemory::read_float(addr + (c * 4 + r) * 4);
297-
row += fmt::format("{:0.2f}, ", v);
298-
clip += fmt::format("{}, ", v);
340+
if (render_exact_values) {
341+
row += fmt::format("{:0.8f}, ", v);
342+
clip += fmt::format("{:f} {:x}, ", v, *reinterpret_cast<uint32_t *>(&v));
343+
} else {
344+
row += fmt::format("{:0.2f}, ", v);
345+
clip += fmt::format("{:f}, ", v);
346+
}
299347
}
300348
ImGui::Text("%s", row.c_str());
301349
if (ImGui::IsItemHovered()) {

src/defs/GameObjectRenderers.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "GameDefinitions.hpp"
99

1010
namespace GameObjectRenderers {
11+
extern bool render_exact_values;
1112
void render(const GameDefinitions::GameMember &member, bool addTree = true);
1213

1314
void renderEnumOrStruct(const GameDefinitions::GameMember &member, bool addTree);

0 commit comments

Comments
 (0)