From bd2ead8d1327b4978562006f46f59ad13c3b34af Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Sat, 28 Nov 2020 18:06:49 -0330 Subject: [PATCH 1/5] Added JSON stuff to Xcode project. --- src/macos/stella.xcodeproj/project.pbxproj | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/macos/stella.xcodeproj/project.pbxproj b/src/macos/stella.xcodeproj/project.pbxproj index d0892bdce..0a337371d 100644 --- a/src/macos/stella.xcodeproj/project.pbxproj +++ b/src/macos/stella.xcodeproj/project.pbxproj @@ -413,6 +413,8 @@ DC8078DB0B4BD5F3005E9305 /* DebuggerExpressions.hxx in Headers */ = {isa = PBXBuildFile; fileRef = DC8078DA0B4BD5F3005E9305 /* DebuggerExpressions.hxx */; }; DC8078EA0B4BD697005E9305 /* UIDialog.cxx in Sources */ = {isa = PBXBuildFile; fileRef = DC8078E60B4BD697005E9305 /* UIDialog.cxx */; }; DC8078EB0B4BD697005E9305 /* UIDialog.hxx in Headers */ = {isa = PBXBuildFile; fileRef = DC8078E70B4BD697005E9305 /* UIDialog.hxx */; }; + DC816CF62572F92A00FBCCDA /* json.hxx in Headers */ = {isa = PBXBuildFile; fileRef = DC816CF42572F92A00FBCCDA /* json.hxx */; }; + DC816CF72572F92A00FBCCDA /* json_lib.hxx in Headers */ = {isa = PBXBuildFile; fileRef = DC816CF52572F92A00FBCCDA /* json_lib.hxx */; }; DC84397B247B294E00C6A4FC /* CartTVBoy.hxx in Headers */ = {isa = PBXBuildFile; fileRef = DC843979247B294D00C6A4FC /* CartTVBoy.hxx */; }; DC84397C247B294E00C6A4FC /* CartTVBoy.cxx in Sources */ = {isa = PBXBuildFile; fileRef = DC84397A247B294D00C6A4FC /* CartTVBoy.cxx */; }; DC84397F247B297A00C6A4FC /* CartTVBoyWidget.hxx in Headers */ = {isa = PBXBuildFile; fileRef = DC84397D247B297A00C6A4FC /* CartTVBoyWidget.hxx */; }; @@ -520,7 +522,6 @@ DCB60ACC25430FC600A5C1D2 /* FBBackend.hxx in Headers */ = {isa = PBXBuildFile; fileRef = DCB60ACB25430FC600A5C1D2 /* FBBackend.hxx */; }; DCB60AD02543100900A5C1D2 /* FBBackendSDL2.cxx in Sources */ = {isa = PBXBuildFile; fileRef = DCB60ACD2543100900A5C1D2 /* FBBackendSDL2.cxx */; }; DCB60AD12543100900A5C1D2 /* FBBackendSDL2.hxx in Headers */ = {isa = PBXBuildFile; fileRef = DCB60ACE2543100900A5C1D2 /* FBBackendSDL2.hxx */; }; - DCB60AD22543100900A5C1D2 /* audio in Resources */ = {isa = PBXBuildFile; fileRef = DCB60ACF2543100900A5C1D2 /* audio */; }; DCB87E581A104C1E00BF2A3B /* MediaFactory.hxx in Headers */ = {isa = PBXBuildFile; fileRef = DCB87E571A104C1E00BF2A3B /* MediaFactory.hxx */; }; DCBA539925557E2800087DD7 /* UndoHandler.hxx in Headers */ = {isa = PBXBuildFile; fileRef = DCBA539725557E2700087DD7 /* UndoHandler.hxx */; }; DCBA539A25557E2800087DD7 /* UndoHandler.cxx in Sources */ = {isa = PBXBuildFile; fileRef = DCBA539825557E2800087DD7 /* UndoHandler.cxx */; }; @@ -1182,6 +1183,8 @@ DC8078DA0B4BD5F3005E9305 /* DebuggerExpressions.hxx */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.h; path = DebuggerExpressions.hxx; sourceTree = ""; }; DC8078E60B4BD697005E9305 /* UIDialog.cxx */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = UIDialog.cxx; sourceTree = ""; }; DC8078E70B4BD697005E9305 /* UIDialog.hxx */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.h; path = UIDialog.hxx; sourceTree = ""; }; + DC816CF42572F92A00FBCCDA /* json.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = json.hxx; sourceTree = ""; }; + DC816CF52572F92A00FBCCDA /* json_lib.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = json_lib.hxx; sourceTree = ""; }; DC843979247B294D00C6A4FC /* CartTVBoy.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = CartTVBoy.hxx; sourceTree = ""; }; DC84397A247B294D00C6A4FC /* CartTVBoy.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CartTVBoy.cxx; sourceTree = ""; }; DC84397D247B297A00C6A4FC /* CartTVBoyWidget.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = CartTVBoyWidget.hxx; sourceTree = ""; }; @@ -1290,7 +1293,6 @@ DCB60ACB25430FC600A5C1D2 /* FBBackend.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = FBBackend.hxx; sourceTree = ""; }; DCB60ACD2543100900A5C1D2 /* FBBackendSDL2.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FBBackendSDL2.cxx; sourceTree = ""; }; DCB60ACE2543100900A5C1D2 /* FBBackendSDL2.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = FBBackendSDL2.hxx; sourceTree = ""; }; - DCB60ACF2543100900A5C1D2 /* audio */ = {isa = PBXFileReference; lastKnownFileType = folder; path = audio; sourceTree = ""; }; DCB87E571A104C1E00BF2A3B /* MediaFactory.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = MediaFactory.hxx; sourceTree = ""; }; DCBA539725557E2700087DD7 /* UndoHandler.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = UndoHandler.hxx; sourceTree = ""; }; DCBA539825557E2800087DD7 /* UndoHandler.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UndoHandler.cxx; sourceTree = ""; }; @@ -1563,6 +1565,7 @@ 2D605130089879BA00C6DE89 /* debugger */, 2D6050CC0898776500C6DE89 /* emucore */, 2D6050FA0898786C00C6DE89 /* gui */, + DC816CF32572F8B400FBCCDA /* json */, DCD6FC5A11C281A1005DA767 /* libpng */, 2D6050C60898771C00C6DE89 /* macos */, 2D6050C90898774B00C6DE89 /* unix */, @@ -1773,7 +1776,6 @@ isa = PBXGroup; children = ( DCC6A4AD20A2620D00863C59 /* audio */, - DCB60ACF2543100900A5C1D2 /* audio */, E09F413A201E901D004A3391 /* AudioQueue.cxx */, E09F4139201E901C004A3391 /* AudioQueue.hxx */, E0FABEEA20E9948100EB8E28 /* AudioSettings.cxx */, @@ -2274,6 +2276,15 @@ name = exception; sourceTree = ""; }; + DC816CF32572F8B400FBCCDA /* json */ = { + isa = PBXGroup; + children = ( + DC816CF52572F92A00FBCCDA /* json_lib.hxx */, + DC816CF42572F92A00FBCCDA /* json.hxx */, + ); + path = json; + sourceTree = ""; + }; DCC467EA14FBEC9600E15508 /* tv_filters */ = { isa = PBXGroup; children = ( @@ -2533,6 +2544,7 @@ DCBD31E92299ADB400567357 /* Rect.hxx in Headers */, DCBA539925557E2800087DD7 /* UndoHandler.hxx in Headers */, 2D91741A09BA90380026E9FF /* FSNode.hxx in Headers */, + DC816CF72572F92A00FBCCDA /* json_lib.hxx in Headers */, 2D91741B09BA90380026E9FF /* OSystem.hxx in Headers */, DC6A18F919B3E65500DEB242 /* CartMDMWidget.hxx in Headers */, 2D91741F09BA90380026E9FF /* AboutBox.h in Headers */, @@ -2743,6 +2755,7 @@ DCF8621A21C9D43300F95F52 /* StaggeredLogger.hxx in Headers */, DCAAE5E31715887B0080BB82 /* CartF0Widget.hxx in Headers */, DCAAE5E51715887B0080BB82 /* CartF4SCWidget.hxx in Headers */, + DC816CF62572F92A00FBCCDA /* json.hxx in Headers */, DCAAE5E71715887B0080BB82 /* CartF4Widget.hxx in Headers */, DC5963142139FA14002736F2 /* Bankswitch.hxx in Headers */, DCAAE5E91715887B0080BB82 /* CartF6SCWidget.hxx in Headers */, @@ -2876,7 +2889,6 @@ 2D91747109BA90380026E9FF /* docs in Resources */, 2D91747209BA90380026E9FF /* AboutBox.nib in Resources */, 2DEFB40C09C3386F00754289 /* Cart.icns in Resources */, - DCB60AD22543100900A5C1D2 /* audio in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; From c4354aeeea877a002922bc7f60bf159458c19634 Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Sat, 28 Nov 2020 20:52:13 -0330 Subject: [PATCH 2/5] Remove workarounds in pre-C++17 code. --- src/common/RewindManager.cxx | 7 ++----- src/emucore/MT24LC256.cxx | 15 +++------------ 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/src/common/RewindManager.cxx b/src/common/RewindManager.cxx index 044bc57e9..d6d277995 100644 --- a/src/common/RewindManager.cxx +++ b/src/common/RewindManager.cxx @@ -41,18 +41,15 @@ void RewindManager::setup() const string& prefix = myOSystem.settings().getBool("dev.settings") ? "dev." : "plr."; - // Work around a bug in XCode 11.2 with -O0 and -O1 - const uInt32 maxBufSize = MAX_BUF_SIZE; - // TODO - Add proper bounds checking (define constexpr variables for this) // Use those bounds in DeveloperDialog too mySize = std::min( - myOSystem.settings().getInt(prefix + "tm.size"), maxBufSize); + myOSystem.settings().getInt(prefix + "tm.size"), MAX_BUF_SIZE); if(mySize != myStateList.capacity()) resize(mySize); myUncompressed = std::min( - myOSystem.settings().getInt(prefix + "tm.uncompressed"), maxBufSize); + myOSystem.settings().getInt(prefix + "tm.uncompressed"), MAX_BUF_SIZE); myInterval = INTERVAL_CYCLES[0]; for(int i = 0; i < NUM_INTERVALS; ++i) diff --git a/src/emucore/MT24LC256.cxx b/src/emucore/MT24LC256.cxx index ba6d2348b..53004b804 100644 --- a/src/emucore/MT24LC256.cxx +++ b/src/emucore/MT24LC256.cxx @@ -64,11 +64,8 @@ MT24LC256::MT24LC256(const FilesystemNode& eepromfile, const System& system, if(!fileValid) { - // Work around a bug in XCode 11.2 with -O0 and -O1 - const uInt8 initialValue = INITIAL_VALUE; - myData = make_unique(FLASH_SIZE); - std::fill_n(myData.get(), FLASH_SIZE, initialValue); + std::fill_n(myData.get(), FLASH_SIZE, INITIAL_VALUE); myDataChanged = true; } @@ -142,24 +139,18 @@ void MT24LC256::systemReset() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void MT24LC256::eraseAll() { - // Work around a bug in XCode 11.2 with -O0 and -O1 - const uInt8 initialValue = INITIAL_VALUE; - - std::fill_n(myData.get(), FLASH_SIZE, initialValue); + std::fill_n(myData.get(), FLASH_SIZE, INITIAL_VALUE); myDataChanged = true; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void MT24LC256::eraseCurrent() { - // Work around a bug in XCode 11.2 with -O0 and -O1 - const uInt8 initialValue = INITIAL_VALUE; - for(uInt32 page = 0; page < PAGE_NUM; ++page) { if(myPageHit[page]) { - std::fill_n(myData.get() + page * PAGE_SIZE, PAGE_SIZE, initialValue); + std::fill_n(myData.get() + page * PAGE_SIZE, PAGE_SIZE, INITIAL_VALUE); myDataChanged = true; } } From ceabffe52b64fe556b30462b9fde863e03db405c Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Sat, 28 Nov 2020 22:16:47 -0330 Subject: [PATCH 3/5] Various code cleanups. --- src/common/AudioSettings.cxx | 3 +-- src/common/AudioSettings.hxx | 10 +++++----- src/common/FpsMeter.cxx | 4 ++++ src/common/PJoystickHandler.cxx | 2 +- src/common/PaletteHandler.cxx | 1 + src/common/PhosphorHandler.hxx | 2 +- src/common/tv_filters/AtariNTSC.hxx | 12 ++++++------ src/debugger/BreakpointMap.hxx | 6 +++--- src/debugger/Debugger.hxx | 7 ++----- src/emucore/EventHandlerConstants.hxx | 2 -- src/gui/DeveloperDialog.hxx | 6 +++--- src/gui/TabWidget.hxx | 4 ++-- 12 files changed, 29 insertions(+), 30 deletions(-) diff --git a/src/common/AudioSettings.cxx b/src/common/AudioSettings.cxx index 640ba9527..6f67d3d0a 100644 --- a/src/common/AudioSettings.cxx +++ b/src/common/AudioSettings.cxx @@ -43,8 +43,7 @@ namespace { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - AudioSettings::AudioSettings(Settings& settings) - : mySettings(settings), - myIsPersistent(true) + : mySettings(settings) { setPreset(normalizedPreset(mySettings.getInt(SETTING_PRESET))); } diff --git a/src/common/AudioSettings.hxx b/src/common/AudioSettings.hxx index d319671c3..1e9f0477f 100644 --- a/src/common/AudioSettings.hxx +++ b/src/common/AudioSettings.hxx @@ -131,13 +131,13 @@ class AudioSettings Preset myPreset; - uInt32 myPresetSampleRate; - uInt32 myPresetFragmentSize; - uInt32 myPresetBufferSize; - uInt32 myPresetHeadroom; + uInt32 myPresetSampleRate{0}; + uInt32 myPresetFragmentSize{0}; + uInt32 myPresetBufferSize{0}; + uInt32 myPresetHeadroom{0}; ResamplingQuality myPresetResamplingQuality; - bool myIsPersistent; + bool myIsPersistent{true}; }; #endif // AUDIO_PARAMTERS_HXX diff --git a/src/common/FpsMeter.cxx b/src/common/FpsMeter.cxx index be945e9e2..878a42ae0 100644 --- a/src/common/FpsMeter.cxx +++ b/src/common/FpsMeter.cxx @@ -19,12 +19,14 @@ using namespace std::chrono; +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - FpsMeter::FpsMeter(uInt32 queueSize) : myQueue(queueSize) { reset(); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void FpsMeter::reset(uInt32 garbageFrameLimit) { myQueue.clear(); @@ -35,6 +37,7 @@ void FpsMeter::reset(uInt32 garbageFrameLimit) myGarbageFrameLimit = garbageFrameLimit; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void FpsMeter::render(uInt32 frameCount) { if (myGarbageFrameCounter < myGarbageFrameLimit) { @@ -67,6 +70,7 @@ void FpsMeter::render(uInt32 frameCount) if (myTimeInterval > 0) myFps = (myFrameCount - first.frames) / myTimeInterval; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - float FpsMeter::fps() const { return myFps; diff --git a/src/common/PJoystickHandler.cxx b/src/common/PJoystickHandler.cxx index 323caea1c..e38fbf813 100644 --- a/src/common/PJoystickHandler.cxx +++ b/src/common/PJoystickHandler.cxx @@ -217,7 +217,7 @@ void PhysicalJoystickHandler::mapStelladaptors(const string& saport) // We know there will be only two such devices (at most), since the logic // in setupJoysticks take care of that int saCount = 0; - int saOrder[NUM_PORTS] = { 1, 2 }; + int saOrder[] = { 1, 2 }; if(BSPF::equalsIgnoreCase(saport, "rl")) { saOrder[0] = 2; saOrder[1] = 1; diff --git a/src/common/PaletteHandler.cxx b/src/common/PaletteHandler.cxx index f13c18ab1..aa66f5985 100644 --- a/src/common/PaletteHandler.cxx +++ b/src/common/PaletteHandler.cxx @@ -22,6 +22,7 @@ #include "PaletteHandler.hxx" +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PaletteHandler::PaletteHandler(OSystem& system) : myOSystem(system) { diff --git a/src/common/PhosphorHandler.hxx b/src/common/PhosphorHandler.hxx index efc77cf58..89d0df3a9 100644 --- a/src/common/PhosphorHandler.hxx +++ b/src/common/PhosphorHandler.hxx @@ -38,7 +38,7 @@ class PhosphorHandler @return Averaged value of the two RGB colors */ - static inline uInt32 getPixel(const uInt32 c, const uInt32 p) + static constexpr uInt32 getPixel(const uInt32 c, const uInt32 p) { // Mix current calculated frame with previous displayed frame const uInt8 rc = static_cast(c >> 16), diff --git a/src/common/tv_filters/AtariNTSC.hxx b/src/common/tv_filters/AtariNTSC.hxx index eb75bce3d..087e7c579 100644 --- a/src/common/tv_filters/AtariNTSC.hxx +++ b/src/common/tv_filters/AtariNTSC.hxx @@ -232,7 +232,7 @@ class AtariNTSC } // Common ntsc macros - static inline constexpr void ATARI_NTSC_CLAMP( uInt32& io, uInt32 shift ) { + static constexpr void ATARI_NTSC_CLAMP( uInt32& io, uInt32 shift ) { uInt32 sub = io >> (9-(shift)) & atari_ntsc_clamp_mask; uInt32 clamp = atari_ntsc_clamp_add - sub; io |= clamp; @@ -240,31 +240,31 @@ class AtariNTSC io &= clamp; } - static inline constexpr void RGB_TO_YIQ(float r, float g, float b, + static constexpr void RGB_TO_YIQ(float r, float g, float b, float& y, float& i, float& q) { y = r * 0.299F + g * 0.587F + b * 0.114F; i = r * 0.595716F - g * 0.274453F - b * 0.321263F; q = r * 0.211456F - g * 0.522591F + b * 0.311135F; } - static inline constexpr void YIQ_TO_RGB(float y, float i, float q, + static constexpr void YIQ_TO_RGB(float y, float i, float q, const float* to_rgb, int& ir, int& ig, int& ib) { ir = static_cast(y + to_rgb[0] * i + to_rgb[1] * q); ig = static_cast(y + to_rgb[2] * i + to_rgb[3] * q); ib = static_cast(y + to_rgb[4] * i + to_rgb[5] * q); } - static inline constexpr uInt32 PACK_RGB( int r, int g, int b ) { + static constexpr uInt32 PACK_RGB( int r, int g, int b ) { return r << 21 | g << 11 | b << 1; } // Converted from C-style macros; I don't even pretend to understand the logic here :) - static inline constexpr int PIXEL_OFFSET1( int ntsc, int scaled ) { + static constexpr int PIXEL_OFFSET1( int ntsc, int scaled ) { return (kernel_size / 2 + ((ntsc) - (scaled) / rescale_out * rescale_in) + ((((scaled) + rescale_out * 10) % rescale_out) != 0) + (rescale_out - (((scaled) + rescale_out * 10) % rescale_out)) % rescale_out + (kernel_size * 2 * (((scaled) + rescale_out * 10) % rescale_out))); } - static inline constexpr int PIXEL_OFFSET2( int ntsc ) { + static constexpr int PIXEL_OFFSET2( int ntsc ) { return 1.0F - (((ntsc) + 100) & 2); } diff --git a/src/debugger/BreakpointMap.hxx b/src/debugger/BreakpointMap.hxx index 492f4ef10..9a77bf8c3 100644 --- a/src/debugger/BreakpointMap.hxx +++ b/src/debugger/BreakpointMap.hxx @@ -30,12 +30,12 @@ class BreakpointMap { private: - static const uInt16 ADDRESS_MASK = 0x1fff; // either 0x1fff or 0xffff (not needed then) + static constexpr uInt16 ADDRESS_MASK = 0x1fff; // either 0x1fff or 0xffff (not needed then) public: // breakpoint flags - static const uInt32 ONE_SHOT = 1 << 0; // used for 'trace' command - static const uInt8 ANY_BANK = 255; // breakpoint valid in any bank + static constexpr uInt32 ONE_SHOT = 1 << 0; // used for 'trace' command + static constexpr uInt8 ANY_BANK = 255; // breakpoint valid in any bank struct Breakpoint { diff --git a/src/debugger/Debugger.hxx b/src/debugger/Debugger.hxx index 6a53238bb..f937d2b52 100644 --- a/src/debugger/Debugger.hxx +++ b/src/debugger/Debugger.hxx @@ -76,9 +76,6 @@ class Debugger : public DialogContainer Debugger(OSystem& osystem, Console& console); ~Debugger() override; - private: - static const Int8 ANY_BANK = -1; - public: /** Initialize the debugger dialog container. @@ -284,8 +281,6 @@ class Debugger : public DialogContainer */ Dialog* baseDialog() override { return myDialog; } - static const Int32 NOT_FOUND = -1; - private: /** Save state of each debugger subsystem and, by default, mark all @@ -367,6 +362,8 @@ class Debugger : public DialogContainer static std::array ourBuiltinFunctions; static std::array ourPseudoRegisters; + static constexpr Int8 ANY_BANK = -1; + private: // rewind/unwind n states uInt16 windStates(uInt16 numStates, bool unwind, string& message); diff --git a/src/emucore/EventHandlerConstants.hxx b/src/emucore/EventHandlerConstants.hxx index b67df420f..a736d5f95 100644 --- a/src/emucore/EventHandlerConstants.hxx +++ b/src/emucore/EventHandlerConstants.hxx @@ -74,8 +74,6 @@ enum JoyHatMask { EVENT_HATCENTER_M = 1<<4 }; -static const int NUM_PORTS = 2; - enum class EventMode { kEmulationMode, // active mapping used for emulation kMenuMode, // mapping used for dialogs diff --git a/src/gui/DeveloperDialog.hxx b/src/gui/DeveloperDialog.hxx index e3d31ecfd..fc16e302e 100644 --- a/src/gui/DeveloperDialog.hxx +++ b/src/gui/DeveloperDialog.hxx @@ -81,10 +81,10 @@ class DeveloperDialog : public Dialog enum SettingsSet { player = 0, developer = 1 }; // MUST be aligned with RewindManager! - static const int NUM_INTERVALS = 7; - static const int NUM_HORIZONS = 8; + static constexpr int NUM_INTERVALS = 7; + static constexpr int NUM_HORIZONS = 8; - static const int DEBUG_COLORS = 6; + static constexpr int DEBUG_COLORS = 6; TabWidget* myTab{nullptr}; // Emulator widgets diff --git a/src/gui/TabWidget.hxx b/src/gui/TabWidget.hxx index 141b29497..9d6f0837d 100644 --- a/src/gui/TabWidget.hxx +++ b/src/gui/TabWidget.hxx @@ -26,8 +26,8 @@ class TabWidget : public Widget, public CommandSender { public: - static const int NO_WIDTH = 0; - static const int AUTO_WIDTH = -1; + static constexpr int NO_WIDTH = 0; + static constexpr int AUTO_WIDTH = -1; enum { kTabChangedCmd = 'TBCH' From aa42c517097cb707add9812cb75daa95dc459a82 Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Sat, 28 Nov 2020 22:25:22 -0330 Subject: [PATCH 4/5] Fix gcc warning: use const references instead of pass by value for exceptions. --- src/common/JoyMap.cxx | 2 +- src/common/KeyMap.cxx | 2 +- src/common/PJoystickHandler.cxx | 2 +- src/common/PKeyboardHandler.cxx | 4 ++-- src/common/PhysicalJoystick.cxx | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/common/JoyMap.cxx b/src/common/JoyMap.cxx index 6b8c95b42..f62385160 100644 --- a/src/common/JoyMap.cxx +++ b/src/common/JoyMap.cxx @@ -240,7 +240,7 @@ int JoyMap::loadMapping(const json& eventMappings, const EventMode mode) ); i++; - } catch (json::exception) { + } catch (const json::exception&) { Logger::error("ignoring invalid joystick event"); } } diff --git a/src/common/KeyMap.cxx b/src/common/KeyMap.cxx index 2e493b331..de0ee2383 100644 --- a/src/common/KeyMap.cxx +++ b/src/common/KeyMap.cxx @@ -208,7 +208,7 @@ int KeyMap::loadMapping(const json& mappings, const EventMode mode) { ); i++; - } catch (json::exception) { + } catch (const json::exception&) { Logger::error("ignoring bad keyboard mapping"); } } diff --git a/src/common/PJoystickHandler.cxx b/src/common/PJoystickHandler.cxx index e38fbf813..3b41cf854 100644 --- a/src/common/PJoystickHandler.cxx +++ b/src/common/PJoystickHandler.cxx @@ -47,7 +47,7 @@ PhysicalJoystickHandler::PhysicalJoystickHandler( try { mappings = json::parse(serializedMapping); - } catch (json::exception) { + } catch (const json::exception&) { Logger::info("converting legacy joystick mappings"); mappings = convertLegacyMapping(serializedMapping); diff --git a/src/common/PKeyboardHandler.cxx b/src/common/PKeyboardHandler.cxx index 6b60ae914..5f3091aae 100644 --- a/src/common/PKeyboardHandler.cxx +++ b/src/common/PKeyboardHandler.cxx @@ -74,7 +74,7 @@ void PhysicalKeyboardHandler::loadSerializedMappings(const string& serializedMap try { mapping = json::parse(serializedMapping); - } catch (json::exception) { + } catch (const json::exception&) { Logger::info("converting legacy keyboard mappings"); mapping = KeyMap::convertLegacyMapping(serializedMapping); @@ -82,7 +82,7 @@ void PhysicalKeyboardHandler::loadSerializedMappings(const string& serializedMap try { myKeyMap.loadMapping(mapping, mode); - } catch (json::exception) { + } catch (const json::exception&) { Logger::error("ignoring bad keyboard mappings"); } } diff --git a/src/common/PhysicalJoystick.cxx b/src/common/PhysicalJoystick.cxx index 488d1f318..8cbb6a8d8 100644 --- a/src/common/PhysicalJoystick.cxx +++ b/src/common/PhysicalJoystick.cxx @@ -87,7 +87,7 @@ bool PhysicalJoystick::setMap(const json& map) try { joyMap.loadMapping(entry.value(), eventModeFromJsonName(entry.key())); - } catch (json::exception) { + } catch (const json::exception&) { Logger::error("ignoring invalid json mapping for " + entry.key()); } From f44f5654e4173ce31483139a52d1926120380abe Mon Sep 17 00:00:00 2001 From: Christian Speckner Date: Sun, 29 Nov 2020 11:05:31 +0100 Subject: [PATCH 5/5] Handle modekey mask properly. --- src/common/KeyMap.cxx | 52 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/src/common/KeyMap.cxx b/src/common/KeyMap.cxx index de0ee2383..730db8057 100644 --- a/src/common/KeyMap.cxx +++ b/src/common/KeyMap.cxx @@ -22,6 +22,52 @@ using json = nlohmann::json; +namespace { + json serializeModkeyMask(int mask) + { + if(mask == StellaMod::KBDM_NONE) return json(nullptr); + + json serializedMask = json::array(); + + for(StellaMod mod: { + StellaMod::KBDM_CTRL, + StellaMod::KBDM_SHIFT, + StellaMod::KBDM_ALT, + StellaMod::KBDM_GUI, + StellaMod::KBDM_LSHIFT, + StellaMod::KBDM_RSHIFT, + StellaMod::KBDM_LCTRL, + StellaMod::KBDM_RCTRL, + StellaMod::KBDM_LALT, + StellaMod::KBDM_RALT, + StellaMod::KBDM_LGUI, + StellaMod::KBDM_RGUI, + StellaMod::KBDM_NUM, + StellaMod::KBDM_CAPS, + StellaMod::KBDM_MODE, + StellaMod::KBDM_RESERVED + }) { + if((mask & mod) != mod) continue; + + serializedMask.push_back(json(mod)); + mask &= ~mod; + } + + return serializedMask.size() == 1 ? serializedMask.at(0) : serializedMask; + } + + int deserializeModkeyMask(json serializedMask) + { + if (serializedMask.is_null()) return StellaMod::KBDM_NONE; + if (!serializedMask.is_array()) return serializedMask.get(); + + int mask = 0; + for(const json& mod: serializedMask) mask |= mod.get(); + + return mask; + } +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void KeyMap::add(const Event::Type event, const Mapping& mapping) { @@ -186,7 +232,7 @@ json KeyMap::saveMapping(const EventMode mode) const mapping["key"] = item.first.key; if (item.first.mod != StellaMod::KBDM_NONE) - mapping["mod"] = item.first.mod; + mapping["mod"] = serializeModkeyMask(item.first.mod); mappings.push_back(mapping); } @@ -204,7 +250,7 @@ int KeyMap::loadMapping(const json& mappings, const EventMode mode) { mapping.at("event").get(), mode, mapping.at("key").get(), - mapping.contains("mod") ? mapping.at("mod").get() : StellaMod::KBDM_NONE + mapping.contains("mod") ? deserializeModkeyMask(mapping.at("mod")) : StellaMod::KBDM_NONE ); i++; @@ -235,7 +281,7 @@ json KeyMap::convertLegacyMapping(string list) mapping["event"] = Event::Type(event); mapping["key"] = StellaKey(key); - if (StellaMod(mod) != StellaMod::KBDM_NONE) mapping["mod"] = StellaMod(mod); + if (StellaMod(mod) != StellaMod::KBDM_NONE) mapping["mod"] = serializeModkeyMask(mod); convertedMapping.push_back(mapping); }