diff --git a/src/common/Bezel.cxx b/src/common/Bezel.cxx index a9147d5a0..22053bc13 100644 --- a/src/common/Bezel.cxx +++ b/src/common/Bezel.cxx @@ -33,14 +33,14 @@ Bezel::Bezel(OSystem& osystem) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -const string Bezel::getName(int& index) const +string Bezel::getName(int& index) const { if(++index == 1) return myOSystem.console().properties().get(PropType::Bezel_Name); // Try to generate bezel name from cart name const string& cartName = myOSystem.console().properties().get(PropType::Cart_Name); - size_t pos = cartName.find_first_of("("); + size_t pos = cartName.find_first_of('('); if(pos == std::string::npos) pos = cartName.length() + 1; if(index < 10 && pos != std::string::npos && pos > 0) @@ -71,15 +71,14 @@ const string Bezel::getName(int& index) const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt32 Bezel::borderSize(uInt32 x, uInt32 y, uInt32 size, Int32 step) const { - uInt32 *pixels{nullptr}, pitch; - uInt32 i; + uInt32 *pixels{nullptr}, pitch{0}; mySurface->basePtr(pixels, pitch); pixels += x + y * pitch; - for(i = 0; i < size; ++i, pixels += step) + for(uInt32 i = 0; i < size; ++i, pixels += step) { - uInt8 r, g, b, a; + uInt8 r{0}, g{0}, b{0}, a{0}; myFB.getRGBA(*pixels, &r, &g, &b, &a); if(a < 255) // transparent pixel? @@ -93,7 +92,7 @@ bool Bezel::load() { const Settings& settings = myOSystem.settings(); bool isValid = false; - string imageName = ""; + string imageName; #ifdef IMAGE_SUPPORT const bool show = myOSystem.eventHandler().inTIAMode() && @@ -118,7 +117,7 @@ bool Bezel::load() { // Note: JPG does not support transparency const string imagePath = path + imageName + ".png"; - FSNode node(imagePath); + const FSNode node(imagePath); if(node.exists()) { isValid = true; @@ -137,17 +136,16 @@ bool Bezel::load() { const Int32 w = mySurface->width(); const Int32 h = mySurface->height(); - uInt32 top, bottom, left, right; + uInt32 top{0}, bottom{0}, left{0}, right{0}; if(settings.getBool("bezel.win.auto")) { // Determine transparent window inside bezel image - uInt32 xCenter, yCenter; - xCenter = w >> 1; + const uInt32 xCenter = w >> 1; top = borderSize(xCenter, 0, h, w); bottom = h - 1 - borderSize(xCenter, h - 1, h, -w); - yCenter = (bottom + top) >> 1; + const uInt32 yCenter = (bottom + top) >> 1; left = borderSize(0, yCenter, w, 1); right = w - 1 - borderSize(w - 1, yCenter, w, -1); } @@ -157,10 +155,10 @@ bool Bezel::load() // HY: 12, 12, 0, 0% // P1: 25, 25, 11, 22% // P2: 23, 23, 7, 20% - left = std::min(w - 1, static_cast(w * settings.getInt("bezel.win.left") / 100. + .5)); - right = w - 1 - std::min(w - 1, static_cast(w * settings.getInt("bezel.win.right") / 100. + .5)); - top = std::min(h - 1, static_cast(h * settings.getInt("bezel.win.top") / 100. + .5)); - bottom = h - 1 - std::min(h - 1, static_cast(h * settings.getInt("bezel.win.bottom") / 100. + .5)); + left = std::min(w - 1, static_cast(w * settings.getInt("bezel.win.left") / 100. + .5)); // NOLINT + right = w - 1 - std::min(w - 1, static_cast(w * settings.getInt("bezel.win.right") / 100. + .5)); // NOLINT + top = std::min(h - 1, static_cast(h * settings.getInt("bezel.win.top") / 100. + .5)); // NOLINT + bottom = h - 1 - std::min(h - 1, static_cast(h * settings.getInt("bezel.win.bottom") / 100. + .5)); // NOLINT } //cerr << (int)(right - left + 1) << " x " << (int)(bottom - top + 1) << " = " diff --git a/src/common/Bezel.hxx b/src/common/Bezel.hxx index 8bdeec952..ecc036f65 100644 --- a/src/common/Bezel.hxx +++ b/src/common/Bezel.hxx @@ -113,7 +113,7 @@ class Bezel /* Generate bezel file name. */ - const string getName(int& index) const; + string getName(int& index) const; private: // The parent system for the bezel diff --git a/src/common/PJoystickHandler.cxx b/src/common/PJoystickHandler.cxx index b5ddb1cc3..52e3e96ba 100644 --- a/src/common/PJoystickHandler.cxx +++ b/src/common/PJoystickHandler.cxx @@ -377,7 +377,7 @@ void PhysicalJoystickHandler::setStickDefaultMapping( // A regular joystick defaults to left or right based on // the defined port or stick number being even or odd; // 'daptor' joysticks request a specific port - bool useLeftMappings; + bool useLeftMappings = true; if(j->type == PhysicalJoystick::Type::REGULAR) { useLeftMappings = j->port == PhysicalJoystick::Port::LEFT @@ -1095,7 +1095,7 @@ PhysicalJoystickHandler::MinStrickInfoList PhysicalJoystickHandler::minStickList for(const auto& [_name, _info] : myDatabase) { - MinStrickInfo stick(_name, + const MinStrickInfo stick(_name, _info.joy ? _info.joy->ID : -1, _info.joy ? _info.joy->port : PhysicalJoystick::Port::AUTO); diff --git a/src/common/PhysicalJoystick.cxx b/src/common/PhysicalJoystick.cxx index c04d13ee4..73bd323c8 100644 --- a/src/common/PhysicalJoystick.cxx +++ b/src/common/PhysicalJoystick.cxx @@ -113,34 +113,6 @@ bool PhysicalJoystick::setMap(const json& map) return true; } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string PhysicalJoystick::getName(const PhysicalJoystick::Port _port) const -{ - static constexpr std::array(PhysicalJoystick::Port::NUM_PORTS)> NAMES = - { - "Auto", "Left", "Right" - }; - - return string{NAMES[static_cast(_port)]}; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -PhysicalJoystick::Port PhysicalJoystick::getPort(string_view portName) const -{ - static constexpr std::array(PhysicalJoystick::Port::NUM_PORTS)> NAMES = - { - "Auto", "Left", "Right" - }; - - for(int i = 0; i < static_cast(PhysicalJoystick::Port::NUM_PORTS); ++i) - if (BSPF::equalsIgnoreCase(portName, NAMES[i])) - return PhysicalJoystick::Port{i}; - - return PhysicalJoystick::Port::AUTO; -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - json PhysicalJoystick::convertLegacyMapping(string_view mapping, string_view name) { @@ -185,18 +157,6 @@ void PhysicalJoystick::eraseEvent(Event::Type event, EventMode mode) joyMap.eraseEvent(event, mode); } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void PhysicalJoystick::getValues(string_view list, IntArray& map) -{ - map.clear(); - istringstream buf(string{list}); // TODO: fixed in C++20 - - int value{0}; - buf >> value; // we don't need to know the # of items at this point - while(buf >> value) - map.push_back(value); -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string PhysicalJoystick::about() const { diff --git a/src/common/PhysicalJoystick.hxx b/src/common/PhysicalJoystick.hxx index ee0aaa422..83f02e604 100644 --- a/src/common/PhysicalJoystick.hxx +++ b/src/common/PhysicalJoystick.hxx @@ -86,11 +86,28 @@ class PhysicalJoystick JoyMap joyMap; private: - static void getValues(string_view list, IntArray& map); - // Convert from string to Port type and vice versa - string getName(const Port _port) const; - Port getPort(string_view portName) const; + static string getName(const Port _port) { + static constexpr std::array(PhysicalJoystick::Port::NUM_PORTS)> NAMES = { + "Auto", "Left", "Right" + }; + + return string{NAMES[static_cast(_port)]}; + } + + static Port getPort(string_view portName) { + static constexpr std::array(PhysicalJoystick::Port::NUM_PORTS)> NAMES = { + "Auto", "Left", "Right" + }; + + for(int i = 0; i < static_cast(PhysicalJoystick::Port::NUM_PORTS); ++i) + if (BSPF::equalsIgnoreCase(portName, NAMES[i])) + return PhysicalJoystick::Port{i}; + + return PhysicalJoystick::Port::AUTO; + } friend ostream& operator<<(ostream& os, const PhysicalJoystick& s) { os << " ID: " << s.ID << ", name: " << s.name << ", numaxis: " << s.numAxes diff --git a/src/common/VideoModeHandler.cxx b/src/common/VideoModeHandler.cxx index d220dcb18..18bb2d46e 100644 --- a/src/common/VideoModeHandler.cxx +++ b/src/common/VideoModeHandler.cxx @@ -46,7 +46,7 @@ const VideoModeHandler::Mode& { if(windowedRequested) { - const double zoom = static_cast(settings.getFloat("tia.zoom")); + const auto zoom = static_cast(settings.getFloat("tia.zoom")); ostringstream desc; desc << (zoom * 100) << "%"; diff --git a/src/emucore/CartMVC.cxx b/src/emucore/CartMVC.cxx index b4b74b33e..a6893eec9 100755 --- a/src/emucore/CartMVC.cxx +++ b/src/emucore/CartMVC.cxx @@ -65,7 +65,7 @@ class StreamReader : public Serializable } void blankPartialLines(bool index) { - int colorSize = myVisibleLines * 5; + const int colorSize = myVisibleLines * 5; if (index) { // top line @@ -123,13 +123,14 @@ class StreamReader : public Serializable myVisibleLines = ff->visible; myEmbeddedFrame = ff->timecode[3] + 1; - int totalLines = myVSyncLines + myBlankLines + myOverscanLines + myVisibleLines; + const int totalLines = myVSyncLines + myBlankLines + myOverscanLines + myVisibleLines; myAudio = const_cast(&ff->dataStart); myGraph = myAudio + totalLines; - myColor = const_cast(myGraph) + 5 * myVisibleLines; - myColorBK = myColor + 5 * myVisibleLines; - myTimecode = myColorBK + 1 * myVisibleLines; + myColor = const_cast(myGraph) + + static_cast(5 * myVisibleLines); + myColorBK = myColor + static_cast(5 * myVisibleLines); + myTimecode = myColorBK + static_cast(1 * myVisibleLines); } else // previous format, ntsc assumed { @@ -139,13 +140,14 @@ class StreamReader : public Serializable myVisibleLines = 192; myEmbeddedFrame = offset[4 + 3 -1]; - int totalLines = myVSyncLines + myBlankLines + myOverscanLines + myVisibleLines; + const int totalLines = myVSyncLines + myBlankLines + myOverscanLines + myVisibleLines; myAudio = offset + 4 + 3; myGraph = myAudio + totalLines; - myTimecode = const_cast(myGraph) + 5 * myVisibleLines; + myTimecode = const_cast(myGraph) + + static_cast(5 * myVisibleLines); myColor = const_cast(myTimecode) + 60; - myColorBK = myColor + 5*myVisibleLines; + myColorBK = myColor + static_cast(5 * myVisibleLines); } if (!odd) @@ -182,13 +184,12 @@ class StreamReader : public Serializable uInt8 readAudio() { return *myAudio++; } - uInt8 getVisibleLines() { return myVisibleLines; } - uInt8 getVSyncLines() { return myVSyncLines; } - uInt8 getBlankLines() { return myBlankLines; } - uInt8 getOverscanLines() { return myOverscanLines; } - uInt8 getEmbeddedFrame() { return myEmbeddedFrame; } - - [[nodiscard]] uInt8 peekAudio() const { return *myAudio; } + [[nodiscard]] uInt8 getVisibleLines() const { return myVisibleLines; } + [[nodiscard]] uInt8 getVSyncLines() const { return myVSyncLines; } + [[nodiscard]] uInt8 getBlankLines() const { return myBlankLines; } + [[nodiscard]] uInt8 getOverscanLines() const { return myOverscanLines; } + [[nodiscard]] uInt8 getEmbeddedFrame() const { return myEmbeddedFrame; } + [[nodiscard]] uInt8 peekAudio() const { return *myAudio; } void startTimeCode() { myGraph = myTimecode; } @@ -932,7 +933,7 @@ static constexpr uInt8 RAINBOW_HEIGHT = 30, TITLE_HEIGHT = 12; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void MovieCart::setConsoleTiming(ConsoleTiming timing) { - uInt8 lines; + uInt8 lines = 0; switch(timing) { @@ -947,7 +948,7 @@ void MovieCart::setConsoleTiming(ConsoleTiming timing) break; } - uInt8 val = (lines - RAINBOW_HEIGHT - RAINBOW_HEIGHT - TITLE_HEIGHT * 2) / 2; + const uInt8 val = (lines - RAINBOW_HEIGHT - RAINBOW_HEIGHT - TITLE_HEIGHT * 2) / 2; writeROM(addr_title_gap1 + 1, val); writeROM(addr_title_gap2 + 1, val); @@ -1300,7 +1301,8 @@ void MovieCart::fill_addr_blank_lines() { myOdd = (myStream.getEmbeddedFrame() & 1); - uInt8 blankTotal = (myStream.getOverscanLines() + myStream.getVSyncLines() + myStream.getBlankLines()-1); // 70-1 + const uInt8 blankTotal = (myStream.getOverscanLines() + + myStream.getVSyncLines() + myStream.getBlankLines()-1); // 70-1 if(myOdd) { diff --git a/src/emucore/FrameBuffer.cxx b/src/emucore/FrameBuffer.cxx index 87221efc0..c91f26629 100644 --- a/src/emucore/FrameBuffer.cxx +++ b/src/emucore/FrameBuffer.cxx @@ -284,7 +284,7 @@ FBInitStatus FrameBuffer::createDisplay(string_view title, BufferType type, myBezel->load(); // make sure we have the correct bezel size // Determine possible TIA windowed zoom levels - const double currentTIAZoom = + const auto currentTIAZoom = static_cast(myOSystem.settings().getFloat("tia.zoom")); myOSystem.settings().setValue("tia.zoom", BSPF::clamp(currentTIAZoom, supportedTIAMinZoom(), supportedTIAMaxZoom())); @@ -1234,7 +1234,7 @@ void FrameBuffer::switchVideoMode(int direction) if(!fullScreen()) { // Windowed TIA modes support variable zoom levels - double zoom = static_cast(myOSystem.settings().getFloat("tia.zoom")); + auto zoom = static_cast(myOSystem.settings().getFloat("tia.zoom")); if(direction == +1) zoom += ZOOM_STEPS; else if(direction == -1) zoom -= ZOOM_STEPS; @@ -1288,7 +1288,7 @@ void FrameBuffer::toggleBezel(bool toggle) else { // Determine possible TIA windowed zoom levels - const double currentTIAZoom = + const auto currentTIAZoom = static_cast(myOSystem.settings().getFloat("tia.zoom")); myOSystem.settings().setValue("tia.zoom", BSPF::clamp(currentTIAZoom, supportedTIAMinZoom(), supportedTIAMaxZoom())); diff --git a/src/gui/RomImageWidget.cxx b/src/gui/RomImageWidget.cxx index b83bbdcf0..878115c48 100644 --- a/src/gui/RomImageWidget.cxx +++ b/src/gui/RomImageWidget.cxx @@ -621,7 +621,7 @@ void RomImageWidget::drawWidget(bool hilite) } } } // arrows - if(myImageList.size()) + if(!myImageList.empty()) { // Draw zoom icon const int dx = myZoomRect.w() / 2; diff --git a/src/gui/VideoAudioDialog.cxx b/src/gui/VideoAudioDialog.cxx index b7adba372..02d91f359 100644 --- a/src/gui/VideoAudioDialog.cxx +++ b/src/gui/VideoAudioDialog.cxx @@ -464,7 +464,7 @@ void VideoAudioDialog::addBezelTab() ypos += lineHeight + VGAP; // Bezel path - int bwidth = _font.getStringWidth("Bezel path" + ELLIPSIS) + fontWidth * 2 + 1; + const int bwidth = _font.getStringWidth("Bezel path" + ELLIPSIS) + fontWidth * 2 + 1; myOpenBrowserButton = new ButtonWidget(myTab, _font, xpos, ypos, bwidth, buttonHeight, "Bezel path" + ELLIPSIS, kChooseBezelDirCmd); myOpenBrowserButton->setToolTip("Select path for bezels.");