Skip to content

Commit 3a81f74

Browse files
committed
And cleaned up more files in src/common.
1 parent b83320a commit 3a81f74

8 files changed

Lines changed: 82 additions & 84 deletions

src/common/DevSettingsHandler.cxx

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ DevSettingsHandler::DevSettingsHandler(OSystem& osystem)
3838
void DevSettingsHandler::loadSettings(SettingsSet set)
3939
{
4040
const bool devSettings = set == SettingsSet::developer;
41-
const string& prefix = devSettings ? "dev." : "plr.";
41+
const string prefix = devSettings ? "dev." : "plr.";
4242
const Settings& settings = myOSystem.settings();
4343

4444
myFrameStats[set] = settings.getBool(prefix + "stats");
4545
myDetectedInfo[set] = settings.getBool(prefix + "detectedinfo");
4646
// AtariVox/SaveKey/PlusROM access
4747
myExternAccess[set] = settings.getBool(prefix + "extaccess");
48-
myConsole[set] = settings.getString(prefix + "console") == "7800" ? 1 : 0;
48+
myConsole[set] = settings.getString(prefix + "console") == "7800";
4949
myPlusROM[set] = devSettings ? settings.getBool("dev.plusroms.on") : true;
5050
// Randomization
5151
myRandomBank[set] = settings.getBool(prefix + "bankrandom");
@@ -102,12 +102,12 @@ void DevSettingsHandler::loadSettings(SettingsSet set)
102102
void DevSettingsHandler::saveSettings(SettingsSet set)
103103
{
104104
const bool devSettings = set == SettingsSet::developer;
105-
const string& prefix = devSettings ? "dev." : "plr.";
105+
const string prefix = devSettings ? "dev." : "plr.";
106106
Settings& settings = myOSystem.settings();
107107

108108
settings.setValue(prefix + "stats", myFrameStats[set]);
109109
settings.setValue(prefix + "detectedinfo", myDetectedInfo[set]);
110-
settings.setValue(prefix + "console", myConsole[set] == 1 ? "7800" : "2600");
110+
settings.setValue(prefix + "console", myConsole[set] ? "7800" : "2600");
111111
if(myOSystem.hasConsole())
112112
myOSystem.eventHandler().set7800Mode();
113113

@@ -181,51 +181,63 @@ void DevSettingsHandler::applySettings(SettingsSet set)
181181
// *** Emulation tab ***
182182
myOSystem.frameBuffer().showFrameStats(myFrameStats[set]);
183183

184-
if(myOSystem.hasConsole())
184+
const bool hasConsole = myOSystem.hasConsole();
185+
186+
if(hasConsole)
185187
{
186-
myOSystem.console().cartridge().enableRandomHotspots(myRandomHotspots[set]);
187-
myOSystem.console().tia().driveUnusedPinsRandom(myUndrivenPins[set]);
188-
myOSystem.console().cartridge().enablePlusROM(myPlusROM[set]);
188+
auto& console = myOSystem.console();
189+
auto& tia = console.tia();
190+
191+
console.cartridge().enableRandomHotspots(myRandomHotspots[set]);
192+
tia.driveUnusedPinsRandom(myUndrivenPins[set]);
193+
console.cartridge().enablePlusROM(myPlusROM[set]);
189194
// Notes:
190195
// - thumb exceptions not updated, because set in cart constructor
191196
// - other missing settings are used on-the-fly
192197
}
193198

194199
#ifdef DEBUGGER_SUPPORT
195200
// Read from write ports and write to read ports breaks
196-
if(myOSystem.hasConsole())
201+
if(hasConsole)
197202
{
198-
myOSystem.console().system().m6502().setReadFromWritePortBreak(myRWPortBreak[set]);
199-
myOSystem.console().system().m6502().setWriteToReadPortBreak(myWRPortBreak[set]);
203+
auto& m6502 = myOSystem.console().system().m6502();
204+
205+
m6502.setReadFromWritePortBreak(myRWPortBreak[set]);
206+
m6502.setWriteToReadPortBreak(myWRPortBreak[set]);
200207
}
201208
#endif
202209

203210
// *** TIA tab ***
204-
if(myOSystem.hasConsole())
211+
if(hasConsole)
205212
{
206-
myOSystem.console().tia().setPlInvertedPhaseClock(myPlInvPhase[set]);
207-
myOSystem.console().tia().setMsInvertedPhaseClock(myMsInvPhase[set]);
208-
myOSystem.console().tia().setBlInvertedPhaseClock(myBlInvPhase[set]);
209-
myOSystem.console().tia().setPlShortLateHMove(myPlLateHMove[set]);
210-
myOSystem.console().tia().setMsShortLateHMove(myMsLateHMove[set]);
211-
myOSystem.console().tia().setBlShortLateHMove(myBlLateHMove[set]);
212-
myOSystem.console().tia().setPFBitsDelay(myPFBits[set]);
213-
myOSystem.console().tia().setPFColorDelay(myPFColor[set]);
214-
myOSystem.console().tia().setPFScoreGlitch(myPFScore[set]);
215-
myOSystem.console().tia().setBKColorDelay(myBKColor[set]);
216-
myOSystem.console().tia().setPlSwapDelay(myPlSwap[set]);
217-
myOSystem.console().tia().setBlSwapDelay(myBlSwap[set]);
213+
auto& tia = myOSystem.console().tia();
214+
215+
tia.setPlInvertedPhaseClock(myPlInvPhase[set]);
216+
tia.setMsInvertedPhaseClock(myMsInvPhase[set]);
217+
tia.setBlInvertedPhaseClock(myBlInvPhase[set]);
218+
tia.setPlShortLateHMove(myPlLateHMove[set]);
219+
tia.setMsShortLateHMove(myMsLateHMove[set]);
220+
tia.setBlShortLateHMove(myBlLateHMove[set]);
221+
tia.setPFBitsDelay(myPFBits[set]);
222+
tia.setPFColorDelay(myPFColor[set]);
223+
tia.setPFScoreGlitch(myPFScore[set]);
224+
tia.setBKColorDelay(myBKColor[set]);
225+
tia.setPlSwapDelay(myPlSwap[set]);
226+
tia.setBlSwapDelay(myBlSwap[set]);
218227
}
219228

220229
// *** Video tab ***
221-
if(myOSystem.hasConsole())
230+
if(hasConsole)
222231
{
232+
auto& console = myOSystem.console();
233+
auto& tia = console.tia();
234+
223235
// TV Jitter
224-
myOSystem.console().tia().toggleJitter(myTVJitter[set] ? 1 : 0);
225-
myOSystem.console().tia().setJitterSensitivity(myTVJitterSense[set]);
226-
myOSystem.console().tia().setJitterRecoveryFactor(myTVJitterRec[set]);
236+
tia.toggleJitter(myTVJitter[set] ? 1 : 0);
237+
tia.setJitterSensitivity(myTVJitterSense[set]);
238+
tia.setJitterRecoveryFactor(myTVJitterRec[set]);
227239
// PAL color loss
228-
myOSystem.console().enableColorLoss(myColorLoss[set]);
240+
console.enableColorLoss(myColorLoss[set]);
229241
}
230242

231243
// Debug colours

src/common/DevSettingsHandler.hxx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ class DevSettingsHandler
5050
std::array<bool, numSets> myFrameStats{};
5151
std::array<bool, numSets> myDetectedInfo{};
5252
std::array<bool, numSets> myExternAccess{};
53-
std::array<int, numSets> myConsole{};
54-
std::array<int, numSets> myPlusROM{};
53+
std::array<bool, numSets> myConsole{};
54+
std::array<bool, numSets> myPlusROM{};
5555
std::array<bool, numSets> myRandomBank{};
5656
std::array<bool, numSets> myRandomizeTIA{};
5757
std::array<bool, numSets> myRandomizeRAM{};
@@ -93,6 +93,7 @@ class DevSettingsHandler
9393
private:
9494
void handleEnableDebugColors(bool enable);
9595

96+
private:
9697
// Following constructors and assignment operators not supported
9798
DevSettingsHandler() = delete;
9899
DevSettingsHandler(const DevSettingsHandler&) = delete;
@@ -101,4 +102,4 @@ class DevSettingsHandler
101102
DevSettingsHandler& operator=(DevSettingsHandler&&) = delete;
102103
};
103104

104-
#endif
105+
#endif // DEV_SETTINGS_HANDLER_HXX

src/common/EventHandlerSDL.cxx

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,16 @@ EventHandlerSDL::EventHandlerSDL(OSystem& osystem)
2828
ASSERT_MAIN_THREAD;
2929

3030
#ifdef GUI_SUPPORT
31-
{
32-
std::ostringstream buf;
33-
myQwertz = int{'y'} == static_cast<int>
34-
(SDL_GetKeyFromScancode(static_cast<SDL_Scancode>(KBDK_Z), static_cast<SDL_Keymod>(StellaMod::KBDM_NONE), false));
35-
buf << "Keyboard: " << (myQwertz ? "QWERTZ" : "QWERTY");
36-
Logger::debug(buf.view());
37-
}
31+
myQwertz = int{'y'} == static_cast<int>
32+
(SDL_GetKeyFromScancode(static_cast<SDL_Scancode>(KBDK_Z),
33+
static_cast<SDL_Keymod>(StellaMod::KBDM_NONE), false));
34+
Logger::debug(std::format("Keyboard: {}", myQwertz ? "QWERTZ" : "QWERTY"));
3835
#endif
3936

4037
#ifdef JOYSTICK_SUPPORT
4138
if(!SDL_InitSubSystem(SDL_INIT_JOYSTICK))
42-
{
43-
std::ostringstream buf;
44-
buf << "ERROR: Couldn't initialize SDL joystick support: "
45-
<< SDL_GetError() << '\n';
46-
Logger::error(buf.view());
47-
}
39+
Logger::error(std::format("ERROR: Couldn't initialize SDL joystick support: {}\n",
40+
SDL_GetError()));
4841
Logger::debug("EventHandlerSDL::EventHandlerSDL SDL_INIT_JOYSTICK");
4942
#endif
5043

@@ -66,7 +59,7 @@ EventHandlerSDL::~EventHandlerSDL()
6659
void EventHandlerSDL::copyText(const string& text) const
6760
{
6861
SDL_SetClipboardText(text.c_str());
69-
};
62+
}
7063

7164
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7265
string EventHandlerSDL::pasteText(string& text) const
@@ -77,7 +70,7 @@ string EventHandlerSDL::pasteText(string& text) const
7770
text = "";
7871

7972
return text;
80-
};
73+
}
8174

8275
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8376
void EventHandlerSDL::pollEvent()
@@ -214,11 +207,11 @@ void EventHandlerSDL::pollEvent()
214207
break;
215208
case SDL_EVENT_WINDOW_MOVED:
216209
handleSystemEvent(SystemEvent::WINDOW_MOVED,
217-
myEvent.window.data1, myEvent.window.data1);
210+
myEvent.window.data1, myEvent.window.data2);
218211
break;
219212
case SDL_EVENT_WINDOW_RESIZED:
220213
handleSystemEvent(SystemEvent::WINDOW_RESIZED,
221-
myEvent.window.data1, myEvent.window.data1);
214+
myEvent.window.data1, myEvent.window.data2);
222215
break;
223216
case SDL_EVENT_WINDOW_MINIMIZED:
224217
handleSystemEvent(SystemEvent::WINDOW_MINIMIZED);
@@ -266,8 +259,8 @@ EventHandlerSDL::JoystickSDL::JoystickSDL(int idx)
266259
// havoc with the idea that a joystick will always have the same name.
267260
// So we truncate the number.
268261
const char* const sdlname = SDL_GetJoystickName(myStick);
269-
const string& desc = BSPF::startsWithIgnoreCase(sdlname, "XInput Controller")
270-
? "XInput Controller" : sdlname;
262+
const string desc = BSPF::startsWithIgnoreCase(sdlname, "XInput Controller")
263+
? "XInput Controller" : sdlname;
271264

272265
initialize(SDL_GetJoystickID(myStick), desc,
273266
SDL_GetNumJoystickAxes(myStick),

src/common/EventHandlerSDL.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class EventHandlerSDL : public EventHandler
6060
{
6161
public:
6262
explicit JoystickSDL(int idx);
63-
virtual ~JoystickSDL();
63+
~JoystickSDL() override;
6464

6565
private:
6666
SDL_Joystick* myStick{nullptr};

src/common/FSNodeFactory.hxx

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
class AbstractFSNode;
2222

23+
#include <cassert>
24+
2325
#ifdef ZIP_SUPPORT
2426
#include "FSNodeZIP.hxx"
2527
#endif
@@ -41,6 +43,8 @@ class AbstractFSNode;
4143
class FSNodeFactory
4244
{
4345
public:
46+
FSNodeFactory() = delete;
47+
4448
enum class Type: uInt8 { SYSTEM, ZIP };
4549

4650
public:
@@ -56,26 +60,17 @@ class FSNodeFactory
5660
#elif defined(__LIB_RETRO__)
5761
return std::make_unique<FSNodeLIBRETRO>(path);
5862
#endif
59-
break;
6063
case Type::ZIP:
6164
#ifdef ZIP_SUPPORT
6265
return std::make_unique<FSNodeZIP>(path);
66+
#else
67+
throw std::runtime_error("ZIP support not compiled in");
6368
#endif
64-
break;
6569
default:
66-
break;
70+
assert(false); // all Type values handled above
6771
}
6872
return nullptr; // satisfy compiler
6973
}
70-
71-
private:
72-
// Following constructors and assignment operators not supported
73-
FSNodeFactory() = delete;
74-
~FSNodeFactory() = delete;
75-
FSNodeFactory(const FSNodeFactory&) = delete;
76-
FSNodeFactory(FSNodeFactory&&) = delete;
77-
FSNodeFactory& operator=(const FSNodeFactory&) = delete;
78-
FSNodeFactory& operator=(FSNodeFactory&&) = delete;
7974
};
8075

8176
#endif

src/common/FpsMeter.cxx

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818
#include "FpsMeter.hxx"
1919

20-
using namespace std::chrono;
20+
using std::chrono::duration;
21+
using std::chrono::duration_cast;
22+
using std::chrono::high_resolution_clock;
2123

2224
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2325
FpsMeter::FpsMeter(uInt32 queueSize)
@@ -32,7 +34,7 @@ void FpsMeter::reset(uInt32 garbageFrameLimit)
3234
myQueue.clear();
3335
myQueueOffset = 0;
3436
myFrameCount = 0;
35-
myFps = 0;
37+
myFps = 0.F;
3638
myGarbageFrameCounter = 0;
3739
myGarbageFrameLimit = garbageFrameLimit;
3840
}
@@ -46,27 +48,22 @@ void FpsMeter::render(uInt32 frameCount)
4648
}
4749

4850
const size_t queueSize = myQueue.capacity();
49-
entry e_first, e_last;
50-
51-
e_last.frames = frameCount;
52-
e_last.timestamp = high_resolution_clock::now();
51+
const Entry e_last{frameCount, high_resolution_clock::now()};
5352

5453
if (myQueue.size() < queueSize) {
5554
myQueue.push_back(e_last);
5655
myFrameCount += frameCount;
57-
58-
e_first = myQueue.at(myQueueOffset);
5956
} else {
60-
myFrameCount = myFrameCount - myQueue.at(myQueueOffset).frames + frameCount;
61-
myQueue.at(myQueueOffset) = e_last;
57+
myFrameCount = myFrameCount - myQueue[myQueueOffset].frames + frameCount;
58+
myQueue[myQueueOffset] = e_last;
6259

63-
myQueueOffset = (myQueueOffset + 1) % queueSize;
64-
e_first = myQueue.at(myQueueOffset);
60+
if(++myQueueOffset == queueSize) myQueueOffset = 0;
6561
}
62+
const Entry& e_first = myQueue[myQueueOffset];
6663

67-
const float myTimeInterval =
68-
duration_cast<duration<float>>(e_last.timestamp - e_first.timestamp).count();
64+
const float timeInterval = duration_cast<duration<float>>
65+
(e_last.timestamp - e_first.timestamp).count();
6966

70-
if (myTimeInterval > 0)
71-
myFps = (myFrameCount - e_first.frames) / myTimeInterval;
67+
if (timeInterval > 0)
68+
myFps = (myFrameCount - e_first.frames) / timeInterval;
7269
}

src/common/FpsMeter.hxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ class FpsMeter
3737

3838
private:
3939

40-
struct entry {
40+
struct Entry {
4141
uInt32 frames{0};
42-
std::chrono::time_point<std::chrono::high_resolution_clock> timestamp;
42+
std::chrono::time_point<std::chrono::high_resolution_clock> timestamp{};
4343
};
4444

4545
private:
4646

47-
vector<entry> myQueue;
47+
vector<Entry> myQueue;
4848

4949
uInt32 myQueueOffset{0};
5050

src/common/PhysicalJoystick.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class PhysicalJoystick
5151
};
5252

5353
PhysicalJoystick() = default;
54-
~PhysicalJoystick() = default;
54+
virtual ~PhysicalJoystick() = default;
5555

5656
nlohmann::json getMap() const;
5757
bool setMap(const nlohmann::json& map);

0 commit comments

Comments
 (0)