Fixes for suggestions from clang-tidy.

This commit is contained in:
Stephen Anthony 2023-10-15 13:53:46 -02:30
parent bc109182a0
commit e601801764
10 changed files with 64 additions and 87 deletions

View File

@ -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<Int32>(w * settings.getInt("bezel.win.left") / 100. + .5));
right = w - 1 - std::min(w - 1, static_cast<Int32>(w * settings.getInt("bezel.win.right") / 100. + .5));
top = std::min(h - 1, static_cast<Int32>(h * settings.getInt("bezel.win.top") / 100. + .5));
bottom = h - 1 - std::min(h - 1, static_cast<Int32>(h * settings.getInt("bezel.win.bottom") / 100. + .5));
left = std::min(w - 1, static_cast<Int32>(w * settings.getInt("bezel.win.left") / 100. + .5)); // NOLINT
right = w - 1 - std::min(w - 1, static_cast<Int32>(w * settings.getInt("bezel.win.right") / 100. + .5)); // NOLINT
top = std::min(h - 1, static_cast<Int32>(h * settings.getInt("bezel.win.top") / 100. + .5)); // NOLINT
bottom = h - 1 - std::min(h - 1, static_cast<Int32>(h * settings.getInt("bezel.win.bottom") / 100. + .5)); // NOLINT
}
//cerr << (int)(right - left + 1) << " x " << (int)(bottom - top + 1) << " = "

View File

@ -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

View File

@ -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);

View File

@ -113,34 +113,6 @@ bool PhysicalJoystick::setMap(const json& map)
return true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string PhysicalJoystick::getName(const PhysicalJoystick::Port _port) const
{
static constexpr std::array<string_view,
static_cast<int>(PhysicalJoystick::Port::NUM_PORTS)> NAMES =
{
"Auto", "Left", "Right"
};
return string{NAMES[static_cast<int>(_port)]};
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PhysicalJoystick::Port PhysicalJoystick::getPort(string_view portName) const
{
static constexpr std::array<string_view,
static_cast<int>(PhysicalJoystick::Port::NUM_PORTS)> NAMES =
{
"Auto", "Left", "Right"
};
for(int i = 0; i < static_cast<int>(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
{

View File

@ -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<string_view,
static_cast<int>(PhysicalJoystick::Port::NUM_PORTS)> NAMES = {
"Auto", "Left", "Right"
};
return string{NAMES[static_cast<int>(_port)]};
}
static Port getPort(string_view portName) {
static constexpr std::array<string_view,
static_cast<int>(PhysicalJoystick::Port::NUM_PORTS)> NAMES = {
"Auto", "Left", "Right"
};
for(int i = 0; i < static_cast<int>(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

View File

@ -46,7 +46,7 @@ const VideoModeHandler::Mode&
{
if(windowedRequested)
{
const double zoom = static_cast<double>(settings.getFloat("tia.zoom"));
const auto zoom = static_cast<double>(settings.getFloat("tia.zoom"));
ostringstream desc;
desc << (zoom * 100) << "%";

View File

@ -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<uInt8*>(&ff->dataStart);
myGraph = myAudio + totalLines;
myColor = const_cast<uInt8*>(myGraph) + 5 * myVisibleLines;
myColorBK = myColor + 5 * myVisibleLines;
myTimecode = myColorBK + 1 * myVisibleLines;
myColor = const_cast<uInt8*>(myGraph) +
static_cast<ptrdiff_t>(5 * myVisibleLines);
myColorBK = myColor + static_cast<ptrdiff_t>(5 * myVisibleLines);
myTimecode = myColorBK + static_cast<ptrdiff_t>(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<uInt8*>(myGraph) + 5 * myVisibleLines;
myTimecode = const_cast<uInt8*>(myGraph) +
static_cast<ptrdiff_t>(5 * myVisibleLines);
myColor = const_cast<uInt8*>(myTimecode) + 60;
myColorBK = myColor + 5*myVisibleLines;
myColorBK = myColor + static_cast<ptrdiff_t>(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)
{

View File

@ -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<double>(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<double>(myOSystem.settings().getFloat("tia.zoom"));
auto zoom = static_cast<double>(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<double>(myOSystem.settings().getFloat("tia.zoom"));
myOSystem.settings().setValue("tia.zoom",
BSPF::clamp(currentTIAZoom, supportedTIAMinZoom(), supportedTIAMaxZoom()));

View File

@ -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;

View File

@ -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.");