Skip to content

Commit 6c8335b

Browse files
committed
GPU Display Frontend: Use RTTI for configuring GPUDisplayControl
1 parent 07d4168 commit 6c8335b

4 files changed

Lines changed: 20 additions & 15 deletions

File tree

‎GPU/GPUTracking/display/frontend/GPUDisplayFrontendConfig.cxx‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ struct GPUDisplayFrontend::configKey {
4848
};
4949

5050
struct GPUDisplayFrontend::configRTTIInfo {
51-
static constexpr std::tuple configStructs{&GPUDisplay::mCfgL, &GPUDisplay::mCfgH, &GPUDisplay::mCfgR}; // Config structs with RTTI, as members of GPUDisplay
51+
static constexpr std::tuple configStructs{&GPUDisplay::mCfgL, &GPUDisplay::mCfgH, &GPUDisplay::mCfgR, &GPUDisplay::mCfgC}; // Config structs with RTTI, as members of GPUDisplay
5252
std::vector<configRTTIExt> rttiEntries;
5353
std::vector<configKeyCallback> configInfos; // SetInfo callback for an option, indexed like rttiEntries, called after the callback of a key bound to it
5454
std::vector<std::vector<uint32_t>> rttiReverseId; // [configStructIndex][offset] -> index in rttiEntries, INVALID_INDEX if no member at that offset
@@ -108,18 +108,21 @@ struct GPUDisplayFrontend::configRTTIInfo {
108108
return qConfig::print_type(*(const int32_t*)ptr);
109109
} else if (e.type == "uint32_t") {
110110
return qConfig::print_type(*(const uint32_t*)ptr);
111+
} else if (e.type == "std::string") {
112+
return *(const std::string*)ptr;
111113
}
112114
return std::nullopt;
113115
}
114116
template <class T, class M>
115117
uint32_t getRTTIIndex(GPUDisplay& display, M T::* member) // RTTI index of a direct member of a config struct
116118
{
117-
if constexpr (std::is_same_v<T, GPUDisplayControl>) {
118-
return INVALID_INDEX;
119-
} else {
120-
const T& obj = configStruct<T>(display);
121-
return rttiReverseId[configStructIndex<T>()][(const char*)&(obj.*member) - (const char*)&obj];
119+
if constexpr (std::is_same_v<T, GPUDisplayControl> && std::is_same_v<M, bool>) {
120+
if (member == &GPUDisplayControl::dummy) { // Keys / buttons that do not change a setting
121+
return INVALID_INDEX;
122+
}
122123
}
124+
const T& obj = configStruct<T>(display);
125+
return rttiReverseId[configStructIndex<T>()][(const char*)&(obj.*member) - (const char*)&obj];
123126
}
124127
void buildHelpText() // Keys left-aligned, the ':' aligned after the longest keys
125128
{

‎GPU/GPUTracking/display/frontend/GPUDisplayFrontendConfigInfo.inc‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
void GPUDisplay::buildConfigInfo()
2121
{
2222
auto addInfo = [this](std::pair<uint32_t, configKeyCallback>&& info) { mFrontend->mConfigRTTI->configInfos[info.first] = std::move(info.second); };
23+
addInfo(INFO_LAMBDA(mCfgC, mDisplayControl, if (val == 2) { SetInfo("Exiting", 1); }));
24+
addInfo(INFO_LAMBDA(mCfgC, mResetScene, SetInfo("View reset", 1);));
25+
addInfo(INFO_LAMBDA(mCfgC, mRequestScreenshot, SetInfo("Taking screenshot (%s)", mScreenshotFile.c_str());));
26+
addInfo(INFO_LAMBDA(mCfgC, mAnimateScreenshot, SetInfo("Writing screenshots from animation set to %d", val);));
27+
addInfo(INFO_LAMBDA(mCfgC, mAnimationChangeConfig, SetInfo("Interpolating visualization settings during Animation %s", val ? "enabled" : "disabled");));
28+
addInfo(INFO_LAMBDA(mCfgC, mPrintInfoTextAlways, SetInfo(val ? "Showing help text until disabled" : (mInfoHelpTimer.IsRunning() ? "Showing help text" : "Showing help text disabled"), 1);));
29+
addInfo(INFO_LAMBDA(mCfgC, mPrintInfoText, SetInfo("Info text display - console: %s, onscreen %s", (val & 2) ? "enabled" : "disabled", (val & 1) ? "enabled" : "disabled");));
2330
addInfo(INFO_LAMBDA(mCfgL, colorClusters, SetInfo("Color coding for seed / trrack attachmend %s", val ? "enabled" : "disabled");));
2431
addInfo(INFO_LAMBDA(mCfgL, drawSector, {
2532
if (val == -1) {

‎GPU/GPUTracking/display/frontend/GPUDisplayFrontendConfigKeys.inc‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ void GPUDisplay::buildConfigKeys()
3838
"Strafe up / down / Rotate left / right");
3939

4040
mFrontend->add_key_binding(
41-
KEY_LAMBDA(mFrontend->KEY_ESCAPE, mCfgC, mDisplayControl, val.store(2); SetInfo("Exiting", 1);),
41+
KEY_LAMBDA(mFrontend->KEY_ESCAPE, mCfgC, mDisplayControl, val.store(2);),
4242
KEY_LAMBDA('n', mCfgC, mDisplayControl, val.store(1);),
43-
KEY_LAMBDA('r', mCfgC, mResetScene, val.store(true); SetInfo("View reset", 1);), //
43+
KEY_LAMBDA('r', mCfgC, mResetScene, val.store(true);), //
4444
KEY_LAMBDA('q', mCfgC, dummy, {
4545
if (mFrontend->isGUIRunning()) {
4646
SetInfo("Stopping GUI", 1);
@@ -229,7 +229,7 @@ void GPUDisplay::buildConfigKeys()
229229

230230
mFrontend->add_key_binding(
231231
KEY_LAMBDA('t', mCfgC, mRequestScreenshot, takeScreenshot();),
232-
KEY_LAMBDA('T', mCfgC, mAnimateScreenshot, val ^= 1; SetInfo("Writing screenshots from animation set to %d", mCfgC.mAnimateScreenshot);), //
232+
KEY_LAMBDA('T', mCfgC, mAnimateScreenshot, val ^= 1;), //
233233
KEY_LAMBDA('Z', mCfgR, screenshotScaleFactor, {
234234
val += 1;
235235
if (val > 4) {
@@ -252,7 +252,7 @@ void GPUDisplay::buildConfigKeys()
252252
"Start Animation, Add / remove Animation point, Reset Points, Cycle animation camera mode (resets)");
253253

254254
mFrontend->add_key_binding(
255-
KEY_LAMBDA('>', mCfgC, mAnimationChangeConfig, val ^= 1; SetInfo("Interpolating visualization settings during Animation %s", mCfgC.mAnimationChangeConfig ? "enabled" : "disabled");),
255+
KEY_LAMBDA('>', mCfgC, mAnimationChangeConfig, val ^= 1;),
256256
KEY_DOWN_MAP('<', CHANGE_ANIMATION_INTERVAL), //
257257
"Toggle config interpolation during Animation / change Animation interval (via movement)");
258258

@@ -296,20 +296,16 @@ void GPUDisplay::buildConfigKeys()
296296
KEY_LAMBDA('h', mCfgC, mPrintInfoTextAlways, {
297297
if (val) {
298298
val = false;
299-
SetInfo("Showing help text disabled", 1);
300299
} else if (mInfoHelpTimer.IsRunning()) {
301300
val = true;
302301
mInfoHelpTimer.Reset();
303-
SetInfo("Showing help text until disabled", 1);
304302
} else {
305303
PrintHelp();
306-
SetInfo("Showing help text", 1);
307304
}
308305
}),
309306
KEY_LAMBDA('H', mCfgC, mPrintInfoText, {
310307
val += 1;
311308
val &= 3;
312-
SetInfo("Info text display - console: %s, onscreen %s", (val & 2) ? "enabled" : "disabled", (val & 1) ? "enabled" : "disabled");
313309
}), //
314310
"Print Help / Show info texts");
315311
}

‎GPU/GPUTracking/display/helpers/GPUDisplayHelpers.cxx‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ void GPUDisplay::takeScreenshot()
6161
static int32_t nScreenshot = 1;
6262
mCfgC.mRequestScreenshot = true;
6363
mScreenshotFile = mCfgC.mScreenShotname + std::to_string(nScreenshot++) + ".bmp";
64-
SetInfo("Taking screenshot (%s)", mScreenshotFile.c_str());
6564
}
6665

6766
void GPUDisplay::SaveGLPos()

0 commit comments

Comments
 (0)