Skip to content

Commit d0db025

Browse files
committed
GPU Display: Several fixes to key handling
1 parent 47874b3 commit d0db025

6 files changed

Lines changed: 31 additions & 23 deletions

File tree

‎GPU/GPUTracking/Definitions/GPUSettingsListDisplay.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ AddOption(excludeClusters, int32_t, 0, "", 0, "Exclude clusters from selected dr
4444
AddOption(drawSector, int32_t, -1, "", 0, "Show individual sector", min(-1), max(35))
4545
AddOption(drawRelatedSectors, int32_t, 0, "", 0, "Show related sectors (if drawSector != -1)")
4646
AddOption(drawGrid, int32_t, 0, "", 0, "Highlight grid")
47-
AddOption(propagateTracks, int32_t, 0, "", 0, "Propagate final tracks further (inward / outward / show MC tracks)")
47+
AddOption(propagateTracks, int32_t, 0, "", 0, "Propagate final tracks further (inward / outward / show MC tracks)", min(0), max(3))
4848
AddOption(showCollision, int32_t, -1, "", 0, "Show only individual collision")
4949
AddOption(colorCollisions, int32_t, 0, "", 0, "Distinguish collisions in timeframe by color")
5050
AddOption(colorClusters, int32_t, 1, "", 0, "Color clusters belonging to track objects")
@@ -90,7 +90,7 @@ EndConfig()
9090
BeginSubConfig(GPUSettingsDisplayRenderer, renderer, configStandalone.display, "GLR", 'g', "Camera / window / renderer OpenGL display settings", display_camera)
9191
AddOption(camLookOrigin, bool, false, "", 0, "Make the camera look at the origin")
9292
AddOption(camYUp, bool, false, "", 0, "Orient the camera such that the y-axis is always upwards")
93-
AddOption(cameraMode, int32_t, 0, "", 0, "Camera mode")
93+
AddOption(cameraMode, int32_t, 0, "", 0, "Camera mode", min(0), max(3))
9494
AddOption(fullScreen, bool, false, "", 0, "Full Screen")
9595
AddOption(maximized, bool, true, "", 0, "Maximized window")
9696
AddOption(drawQualityMSAA, int32_t, 0, "", 0, "MultiSample Anti Aliasing", min(0), max(8))

‎GPU/GPUTracking/display/GPUDisplay.cxx‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,10 @@ void GPUDisplay::DrawGLScene_cameraAndAnimation(bool suspended, float animateTim
261261
mMouseWheelTmp = 0;
262262
}
263263
mFrontend->mMouseWheel = 0;
264-
bool lookOrigin = mCfgR.camLookOrigin ^ mFrontend->mKeys[mFrontend->mKeyDownMap[mFrontend->KEY_MAP_FOCUS_ORIGIN]];
265-
bool yUp = mCfgR.camYUp ^ mFrontend->mKeys[mFrontend->mKeyDownMap[mFrontend->KEY_MAP_FOCUS_ORIENT_UP]] ^ lookOrigin;
266-
bool rotateModelTPC = mCfgO.rotateAroundZ || mFrontend->mKeys[mFrontend->mKeyDownMap[mFrontend->KEY_MAP_ROTATE_AROUND_Z]];
267-
bool rotateModel = rotateModelTPC || mCfgO.rotateModel || mFrontend->mKeys[mFrontend->mKeyDownMap[mFrontend->KEY_MAP_ROTATE_MODEL]];
264+
bool lookOrigin = mCfgR.camLookOrigin ^ mFrontend->keyMapDown(mFrontend->KEY_MAP_FOCUS_ORIGIN);
265+
bool yUp = mCfgR.camYUp ^ mFrontend->keyMapDown(mFrontend->KEY_MAP_FOCUS_ORIENT_UP) ^ lookOrigin;
266+
bool rotateModelTPC = mCfgO.rotateAroundZ || mFrontend->keyMapDown(mFrontend->KEY_MAP_ROTATE_AROUND_Z);
267+
bool rotateModel = rotateModelTPC || mCfgO.rotateModel || mFrontend->keyMapDown(mFrontend->KEY_MAP_ROTATE_MODEL);
268268

269269
// Calculate rotation / translation scaling factors
270270
float scalefactor = mFrontend->mKeys[mFrontend->KEY_SHIFT] ? 0.2f : 1.0f;
@@ -304,12 +304,12 @@ void GPUDisplay::DrawGLScene_cameraAndAnimation(bool suspended, float animateTim
304304

305305
mCfgC.resetScene.store(false);
306306
} else {
307-
float moveZ = scalefactor * ((float)mMouseWheelTmp / 150 + (float)(mFrontend->mKeys[mFrontend->mKeyDownMap[mFrontend->KEY_MAP_FORWARD]] - mFrontend->mKeys[mFrontend->mKeyDownMap[mFrontend->KEY_MAP_BACKWARD]]) * (!mFrontend->mKeys[mFrontend->KEY_SHIFT]) * 0.2f * mFPSScale);
308-
float moveY = scalefactor * ((float)(mFrontend->mKeys[mFrontend->mKeyDownMap[mFrontend->KEY_MAP_STRAFE_DOWN]] - mFrontend->mKeys[mFrontend->mKeyDownMap[mFrontend->KEY_MAP_STRAFE_UP]]) * (!mFrontend->mKeys[mFrontend->KEY_SHIFT]) * 0.2f * mFPSScale);
309-
float moveX = scalefactor * ((float)(mFrontend->mKeys[mFrontend->mKeyDownMap[mFrontend->KEY_MAP_STRAFE_LEFT]] - mFrontend->mKeys[mFrontend->mKeyDownMap[mFrontend->KEY_MAP_STRAFE_RIGHT]]) * (!mFrontend->mKeys[mFrontend->KEY_SHIFT]) * 0.2f * mFPSScale);
310-
float rotRoll = rotatescalefactor * mFPSScale * 2 * (mFrontend->mKeys[mFrontend->mKeyDownMap[mFrontend->KEY_MAP_ROTATE_LEFT]] - mFrontend->mKeys[mFrontend->mKeyDownMap[mFrontend->KEY_MAP_ROTATE_RIGHT]]) * (!mFrontend->mKeys[mFrontend->KEY_SHIFT]);
311-
float rotYaw = rotatescalefactor * mFPSScale * 2 * (mFrontend->mKeys[mFrontend->mKeyDownMap[mFrontend->KEY_MAP_ROTATE_YAW_RIGHT]] - mFrontend->mKeys[mFrontend->mKeyDownMap[mFrontend->KEY_MAP_ROTATE_YAW_LEFT]]) * (!mFrontend->mKeys[mFrontend->KEY_SHIFT]);
312-
float rotPitch = rotatescalefactor * mFPSScale * 2 * (mFrontend->mKeys[mFrontend->mKeyDownMap[mFrontend->KEY_MAP_ROTATE_PITCH_DOWN]] - mFrontend->mKeys[mFrontend->mKeyDownMap[mFrontend->KEY_MAP_ROTATE_PITCH_UP]]) * (!mFrontend->mKeys[mFrontend->KEY_SHIFT]);
307+
float moveZ = scalefactor * ((float)mMouseWheelTmp / 150 + (float)(mFrontend->keyMapDown(mFrontend->KEY_MAP_FORWARD) - mFrontend->keyMapDown(mFrontend->KEY_MAP_BACKWARD)) * (!mFrontend->mKeys[mFrontend->KEY_SHIFT]) * 0.2f * mFPSScale);
308+
float moveY = scalefactor * ((float)(mFrontend->keyMapDown(mFrontend->KEY_MAP_STRAFE_DOWN) - mFrontend->keyMapDown(mFrontend->KEY_MAP_STRAFE_UP)) * (!mFrontend->mKeys[mFrontend->KEY_SHIFT]) * 0.2f * mFPSScale);
309+
float moveX = scalefactor * ((float)(mFrontend->keyMapDown(mFrontend->KEY_MAP_STRAFE_LEFT) - mFrontend->keyMapDown(mFrontend->KEY_MAP_STRAFE_RIGHT)) * (!mFrontend->mKeys[mFrontend->KEY_SHIFT]) * 0.2f * mFPSScale);
310+
float rotRoll = rotatescalefactor * mFPSScale * 2 * (mFrontend->keyMapDown(mFrontend->KEY_MAP_ROTATE_LEFT) - mFrontend->keyMapDown(mFrontend->KEY_MAP_ROTATE_RIGHT)) * (!mFrontend->mKeys[mFrontend->KEY_SHIFT]);
311+
float rotYaw = rotatescalefactor * mFPSScale * 2 * (mFrontend->keyMapDown(mFrontend->KEY_MAP_ROTATE_YAW_RIGHT) - mFrontend->keyMapDown(mFrontend->KEY_MAP_ROTATE_YAW_LEFT)) * (!mFrontend->mKeys[mFrontend->KEY_SHIFT]);
312+
float rotPitch = rotatescalefactor * mFPSScale * 2 * (mFrontend->keyMapDown(mFrontend->KEY_MAP_ROTATE_PITCH_DOWN) - mFrontend->keyMapDown(mFrontend->KEY_MAP_ROTATE_PITCH_UP)) * (!mFrontend->mKeys[mFrontend->KEY_SHIFT]);
313313

314314
float mouseScale = 1920.f / std::max<float>(1920.f, mBackend->mScreenWidth);
315315
if ((mFrontend->mMouseDnR && mFrontend->mMouseDn) || mFrontend->mMouseDnM) {
@@ -323,7 +323,7 @@ void GPUDisplay::DrawGLScene_cameraAndAnimation(bool suspended, float animateTim
323323
rotPitch += rotatescalefactor * mouseScale * ((float)mFrontend->mMouseMvY - (float)mFrontend->mMouseDnY);
324324
}
325325

326-
if (mFrontend->mKeys[mFrontend->mKeyDownMap[mFrontend->KEY_MAP_CHANGE_ANIMATION_INTERVAL]]) {
326+
if (mFrontend->keyMapDown(mFrontend->KEY_MAP_CHANGE_ANIMATION_INTERVAL)) {
327327
mCfgO.animationDelay += moveX;
328328
if (mCfgO.animationDelay < 0.05f) {
329329
mCfgO.animationDelay = 0.05f;
@@ -407,7 +407,7 @@ void GPUDisplay::DrawGLScene_cameraAndAnimation(bool suspended, float animateTim
407407

408408
// Graphichs Options
409409
float minSize = 0.4f / (mCfgR.drawQualityDownsampleFSAA > 1 ? mCfgR.drawQualityDownsampleFSAA : 1);
410-
int32_t deltaLine = (mFrontend->mKeys[mFrontend->mKeyDownMap[mFrontend->KEY_MAP_INCREASE_WIDTH]] - mFrontend->mKeys[mFrontend->mKeyDownMap[mFrontend->KEY_MAP_DECREASE_WIDTH]]) * mFrontend->mKeys[mFrontend->KEY_SHIFT];
410+
int32_t deltaLine = (mFrontend->keyMapDown(mFrontend->KEY_MAP_INCREASE_WIDTH) - mFrontend->keyMapDown(mFrontend->KEY_MAP_DECREASE_WIDTH)) * mFrontend->mKeys[mFrontend->KEY_SHIFT];
411411
mCfgL.lineWidth += (float)deltaLine * mFPSScale * 0.02f * mCfgL.lineWidth;
412412
if (mCfgL.lineWidth < minSize) {
413413
mCfgL.lineWidth = minSize;
@@ -417,7 +417,7 @@ void GPUDisplay::DrawGLScene_cameraAndAnimation(bool suspended, float animateTim
417417
mUpdateDrawCommands = true;
418418
}
419419
minSize *= 2;
420-
int32_t deltaPoint = (mFrontend->mKeys[mFrontend->mKeyDownMap[mFrontend->KEY_MAP_INCREASE_WIDTH]] - mFrontend->mKeys[mFrontend->mKeyDownMap[mFrontend->KEY_MAP_DECREASE_WIDTH]]) * !mFrontend->mKeys[mFrontend->KEY_SHIFT];
420+
int32_t deltaPoint = (mFrontend->keyMapDown(mFrontend->KEY_MAP_INCREASE_WIDTH) - mFrontend->keyMapDown(mFrontend->KEY_MAP_DECREASE_WIDTH)) * !mFrontend->mKeys[mFrontend->KEY_SHIFT];
421421
mCfgL.pointSize += (float)deltaPoint * mFPSScale * 0.02f * mCfgL.pointSize;
422422
if (mCfgL.pointSize < minSize) {
423423
mCfgL.pointSize = minSize;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,9 @@ void GPUDisplayConsole::runScript(std::string_view script)
287287
pos = end + 1;
288288
}
289289
mScriptQueue.insert(mScriptQueue.begin(), lines.begin(), lines.end()); // Before the remaining lines of a script running this one
290-
processScripts(false);
290+
if (mScriptDepth == 0) { // From a script, its processScripts loop continues with these lines
291+
processScripts(false);
292+
}
291293
}
292294

293295
void GPUDisplayConsole::processScripts(bool newFrame)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ void GPUDisplayFrontend::sendExternalGUIKey(int32_t v, uint32_t translationMode,
183183
}
184184

185185
bool GPUDisplayFrontend::consoleShown() const { return mDisplay->mCfgC.showConsole; }
186+
bool GPUDisplayFrontend::keyMapDown(uint32_t id) const { return mKeyDownMap[id] && mKeys[mKeyDownMap[id]]; } // Not mKeys[0] for unbound mappings: frontends may set it for unknown keys
186187

187188
int32_t GPUDisplayFrontend::getDisplayControl() const { return mDisplay->mCfgC.displayControl.load(); }
188189
void GPUDisplayFrontend::setDisplayControl(int32_t v) { mDisplay->mCfgC.displayControl.store(v); }

‎GPU/GPUTracking/display/frontend/GPUDisplayFrontend.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,10 @@ class GPUDisplayFrontend : public GPUDisplayFrontendInterface, public GPUDisplay
140140

141141
void HandleKey(uint8_t key); // Callback for handling key presses
142142
bool consoleShown() const; // Key presses go to the console, frontends do not set mKeys
143+
bool keyMapDown(uint32_t id) const; // Key of the KEY_MAP_* mapping held, never for unbound ones
143144
void HandleExternalGUISignals(); // Callback to handle signals from external GUIs
144145
bool processKeyLambda(uint32_t key); // Process key lambda callback
146+
uint32_t shiftedKey(uint32_t key) const; // Special keys with SHIFT held at code + SPECIAL_KEYS_SHIFTED, as in configKeys
145147
void showConfigInfo(uint32_t index); // Info for a changed option (index in the config RTTI): its info callback, or "struct.option changed to value"
146148
void ResizeScene(int32_t width, int32_t height); // Callback when GL window is resized
147149
int32_t InitDisplay(bool initFailure = false); // Callback to initialize the GL Display (to be called in StartDisplay)

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,9 @@ void GPUDisplay::checkAndApplyConfigChanges()
257257
mConsoleTimer.AddTime(start);
258258
mConsoleTimer.Start();
259259
if (mCfgC.showConsole) {
260+
const bool shift = mFrontend->mKeys[mFrontend->KEY_SHIFT]; // Kept while the console is shown (scrolling, shifted keys), frontends still update it
260261
std::fill(std::begin(mFrontend->mKeys), std::end(mFrontend->mKeys), false);
262+
mFrontend->mKeys[mFrontend->KEY_SHIFT] = shift;
261263
}
262264
}
263265
if (mCfgO.applyToAllPoints && oldCfgL.animationMode != mCfgL.animationMode) { // Also for keys; the animation's own changes are in mOldCfg, so this is only user input
@@ -716,11 +718,11 @@ void GPUDisplay::buildConfig()
716718
rtti->buildHelpText();
717719
}
718720

721+
uint32_t GPUDisplayFrontend::shiftedKey(uint32_t key) const { return key < N_SPECIAL_KEYS && mKeys[KEY_SHIFT] ? key + SPECIAL_KEYS_SHIFTED : key; }
722+
719723
bool GPUDisplayFrontend::processKeyLambda(uint32_t key)
720724
{
721-
if (key < N_SPECIAL_KEYS && mKeys[KEY_SHIFT]) {
722-
key += SPECIAL_KEYS_SHIFTED;
723-
}
725+
key = shiftedKey(key);
724726
const int32_t binding = key < mConfiguration->configKeys.size() ? mConfiguration->configKeys[key] : GPUDisplayConfiguration::KEY_UNBOUND;
725727
if (binding != GPUDisplayConfiguration::KEY_UNBOUND && !GPUDisplayConfiguration::isKeyMap(binding)) {
726728
const auto& action = mConfiguration->keyActions[binding];
@@ -745,16 +747,17 @@ void GPUDisplayFrontend::showConfigInfo(uint32_t index)
745747

746748
void GPUDisplay::HandleKey(uint8_t key, bool external, bool bypassConsole)
747749
{
748-
if (mCfgC.showConsole && !bypassConsole && mFrontend->mConfiguration->keyRTTIIndex(key) != mFrontend->mConfiguration->getRTTIIndex(*this, &GPUDisplayControl::showConsole)) { // All keys except the one toggling the console go to the console
750+
if (mCfgC.showConsole && !bypassConsole && mFrontend->mConfiguration->keyRTTIIndex(mFrontend->shiftedKey(key)) != mFrontend->mConfiguration->getRTTIIndex(*this, &GPUDisplayControl::showConsole)) { // All keys except the one toggling the console go to the console
749751
if (!external) {
750752
mFrontend->mConsole->handleConsoleKey(key, mFrontend->mKeys[mFrontend->KEY_SHIFT]);
751753
}
752754
return;
753755
}
754-
if (key == mFrontend->KEY_ALT) {
755-
mFrontend->mKeys[mFrontend->KEY_CTRL] = false; // Release CTRL with alt, to avoid orienting along y automatically!
756-
} else if (mFrontend->processKeyLambda(key)) {
756+
const uint8_t originKey = mFrontend->mKeyDownMap[mFrontend->KEY_MAP_FOCUS_ORIGIN], upKey = mFrontend->mKeyDownMap[mFrontend->KEY_MAP_FOCUS_ORIENT_UP];
757+
if (originKey && upKey && (key >= 'a' && key <= 'z' ? key + 'A' - 'a' : key) == originKey) { // mKeyDownMap has letters in upper case
758+
mFrontend->mKeys[upKey] = false; // Release the orient up key (CTRL) with the focus origin key (ALT), to avoid orienting along y automatically!
757759
}
760+
mFrontend->processKeyLambda(key);
758761
}
759762

760763
std::string GPUDisplayFrontend::GPUDisplayConfiguration::setValue(GPUDisplay& display, uint32_t index, const GPUDisplayConsole::consoleArg& value)

0 commit comments

Comments
 (0)