Skip to content

Commit

Permalink
[Chores] Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasnoble authored Sep 11, 2023
1 parent 22cfc50 commit 9f6f544
Show file tree
Hide file tree
Showing 49 changed files with 856 additions and 2,058 deletions.
10 changes: 4 additions & 6 deletions src/cdrom/cdriso.cc
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,10 @@ uint8_t *PCSX::CDRIso::getBuffer() {

void PCSX::CDRIso::printTracks() {
for (int i = 1; i <= m_numtracks; i++) {
PCSX::g_system->printf(_("Track %.2d (%s) - Start %.2d:%.2d:%.2d, Length %.2d:%.2d:%.2d\n"), i,
(m_ti[i].type == TrackType::DATA ? "DATA"
: m_ti[i].cddatype == trackinfo::CCDDA ? "CZDA"
: "CDDA"),
m_ti[i].start.m, m_ti[i].start.s, m_ti[i].start.f, m_ti[i].length.m, m_ti[i].length.s,
m_ti[i].length.f);
PCSX::g_system->printf(

Check warning on line 251 in src/cdrom/cdriso.cc

View check run for this annotation

Codecov / codecov/patch

src/cdrom/cdriso.cc#L251

Added line #L251 was not covered by tests
_("Track %.2d (%s) - Start %.2d:%.2d:%.2d, Length %.2d:%.2d:%.2d\n"), i,
(m_ti[i].type == TrackType::DATA ? "DATA" : m_ti[i].cddatype == trackinfo::CCDDA ? "CZDA" : "CDDA"),
m_ti[i].start.m, m_ti[i].start.s, m_ti[i].start.f, m_ti[i].length.m, m_ti[i].length.s, m_ti[i].length.f);

Check warning on line 254 in src/cdrom/cdriso.cc

View check run for this annotation

Codecov / codecov/patch

src/cdrom/cdriso.cc#L253-L254

Added lines #L253 - L254 were not covered by tests
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/cdrom/cdriso.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ class CDRIso {
IEC60908b::MSF pregap;
IEC60908b::MSF start;
IEC60908b::MSF length;
IO<File> handle = nullptr; // for multi-track images CDDA
enum CDDAType { NONE = 0, BIN = 1, CCDDA = 2 } cddatype = NONE; // BIN, WAV, MP3, APE
uint32_t start_offset = 0; // byte offset from start of above file
IO<File> handle = nullptr; // for multi-track images CDDA
enum CDDAType { NONE = 0, BIN = 1, CCDDA = 2 } cddatype = NONE; // BIN, WAV, MP3, APE
uint32_t start_offset = 0; // byte offset from start of above file
};

static constexpr unsigned MAXTRACKS = 100; /* How many tracks can a CD hold? */
Expand Down
14 changes: 8 additions & 6 deletions src/core/gpu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1097,9 +1097,10 @@ void PCSX::GPU::Poly<shading, shape, textured, blend, modulation>::drawLogNode(u
ImGui::SameLine();
std::string label = fmt::format(f_("Go to texture##{}"), n);
if (ImGui::Button(label.c_str())) {
const auto mode = tpage.texDepth == TexDepth::Tex16Bits ? Events::GUI::VRAMFocus::VRAM_16BITS
: tpage.texDepth == TexDepth::Tex8Bits ? Events::GUI::VRAMFocus::VRAM_8BITS
: Events::GUI::VRAMFocus::VRAM_4BITS;
const auto mode = tpage.texDepth == TexDepth::Tex16Bits
? Events::GUI::VRAMFocus::VRAM_16BITS
: tpage.texDepth == TexDepth::Tex8Bits ? Events::GUI::VRAMFocus::VRAM_8BITS

Check warning on line 1102 in src/core/gpu.cc

View check run for this annotation

Codecov / codecov/patch

src/core/gpu.cc#L1100-L1102

Added lines #L1100 - L1102 were not covered by tests
: Events::GUI::VRAMFocus::VRAM_4BITS;

Check warning on line 1103 in src/core/gpu.cc

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

drawLogNode already has high cyclomatic complexity, and now it increases in Lines of Code from 84 to 85. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
g_system->m_eventBus->signal(Events::GUI::SelectClut{clutX(), clutY()});
g_system->m_eventBus->signal(
Events::GUI::VRAMFocus{int(minU + tx), int(minV + ty), int(maxU + tx), int(maxV + ty), mode});
Expand Down Expand Up @@ -1193,9 +1194,10 @@ void PCSX::GPU::Rect<size, textured, blend, modulation>::drawLogNode(unsigned n)
ImGui::SameLine();
std::string label = fmt::format(f_("Go to texture##{}"), n);
if (ImGui::Button(label.c_str())) {
const auto mode = tpage.texDepth == TexDepth::Tex16Bits ? Events::GUI::VRAMFocus::VRAM_16BITS
: tpage.texDepth == TexDepth::Tex8Bits ? Events::GUI::VRAMFocus::VRAM_8BITS
: Events::GUI::VRAMFocus::VRAM_4BITS;
const auto mode = tpage.texDepth == TexDepth::Tex16Bits
? Events::GUI::VRAMFocus::VRAM_16BITS
: tpage.texDepth == TexDepth::Tex8Bits ? Events::GUI::VRAMFocus::VRAM_8BITS

Check warning on line 1199 in src/core/gpu.cc

View check run for this annotation

Codecov / codecov/patch

src/core/gpu.cc#L1197-L1199

Added lines #L1197 - L1199 were not covered by tests
: Events::GUI::VRAMFocus::VRAM_4BITS;

Check warning on line 1200 in src/core/gpu.cc

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

drawLogNode already has high cyclomatic complexity, and now it increases in Lines of Code from 84 to 85. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
g_system->m_eventBus->signal(Events::GUI::SelectClut{clutX(), clutY()});
g_system->m_eventBus->signal(Events::GUI::VRAMFocus{int((u >> shift) + tx), int(v + ty),
int(((u + w) >> shift) + tx), int(v + h + ty), mode});
Expand Down
21 changes: 8 additions & 13 deletions src/core/isoffi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,17 @@ end

local function createIsoBuilderWrapper(wrapper)
local iso = {
_wrapper = ffi.gc(wrapper, function(self) C.isoBuilderClose(self) C.deleteIsoBuilder(self) end),
_wrapper = ffi.gc(wrapper, function(self)
C.isoBuilderClose(self)
C.deleteIsoBuilder(self)
end),
writeLicense = function(self, file)
if not file then file = Support.File.failedFile() end
C.isoBuilderWriteLicense(self._wrapper, file._wrapper)
end,
writeSector = function(self, sectorData, mode)
if not mode then mode = 'M2_FORM1' end
if Support.isLuaBuffer(sectorData) then
sectorData = sectorData.data
end
if Support.isLuaBuffer(sectorData) then sectorData = sectorData.data end
C.isoBuilderWriteSector(self._wrapper, sectorData, mode)
end,
close = function(self) C.isoBuilderClose(self._wrapper) end,
Expand All @@ -116,9 +117,7 @@ PCSX.isoTools = {
local mul = 1
while bcd ~= 0 do
local digit = bcd % 16
if digit >= 10 then
error('Invalid BCD digit: ' .. digit)
end
if digit >= 10 then error('Invalid BCD digit: ' .. digit) end
dec = dec + mul * digit
mul = mul * 10
bcd = math.floor(bcd / 16)
Expand All @@ -140,12 +139,8 @@ PCSX.isoTools = {
m = PCSX.isoTools.fromBCD(m)
s = PCSX.isoTools.fromBCD(s)
f = PCSX.isoTools.fromBCD(f)
if s >= 60 then
error('Invalid MSF seconds: ' .. s)
end
if f >= 75 then
error('Invalid MSF frames: ' .. f)
end
if s >= 60 then error('Invalid MSF seconds: ' .. s) end
if f >= 75 then error('Invalid MSF frames: ' .. f) end
return (m * 60 + s) * 75 + f - 150
end,
toMSF = function(lba)
Expand Down
2 changes: 1 addition & 1 deletion src/core/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ enum class LogClass : unsigned {
template <LogClass logClass, bool enabled>
struct Logger {
template <typename... Args>
static void Log(const char *format, const Args &...args) {
static void Log(const char *format, const Args &... args) {
if (!enabled) return;
std::string s = fmt::sprintf(format, args...);
g_system->log(logClass, std::move(s));
Expand Down
7 changes: 6 additions & 1 deletion src/core/pcsxffi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,12 @@ PCSX = {
GPU = {
takeScreenShot = function()
local ss = C.takeScreenShot()
return { data = Support.File._createSliceWrapper(ss.data), width = ss.width, height = ss.height, bpp = ss.bpp }
return {
data = Support.File._createSliceWrapper(ss.data),
width = ss.width,
height = ss.height,
bpp = ss.bpp,
}
end,
},
createSaveState = function()
Expand Down
4 changes: 1 addition & 3 deletions src/core/pio-cart.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ namespace PCSX {

class PIOCart {
public:
PIOCart() : m_pal(this) {
memset(m_detachedMemory, 0xff, sizeof(m_detachedMemory));
}
PIOCart() : m_pal(this) { memset(m_detachedMemory, 0xff, sizeof(m_detachedMemory)); }

void setLuts();

Expand Down
16 changes: 8 additions & 8 deletions src/core/psxemulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,14 @@ class Emulator {
typedef SettingPath<TYPESTRING("EXP1BrowsePath")> SettingEXP1BrowsePath;
typedef Setting<bool, TYPESTRING("PIOConnected")> SettingPIOConnected;

Settings<SettingMcd1, SettingMcd2, SettingBios, SettingPpfDir, SettingPsxExe,
SettingXa, SettingSpuIrq, SettingBnWMdec, SettingScaler, SettingAutoVideo, SettingVideo, SettingFastBoot,
SettingDebugSettings, SettingRCntFix, SettingIsoPath, SettingLocale, SettingMcd1Inserted,
SettingMcd2Inserted, SettingDynarec, Setting8MB, SettingGUITheme, SettingDither, SettingCachedDithering,
SettingGLErrorReporting, SettingGLErrorReportingSeverity, SettingFullCaching, SettingHardwareRenderer,
SettingShownAutoUpdateConfig, SettingAutoUpdate, SettingMSAA, SettingLinearFiltering, SettingKioskMode,
SettingMcd1Pocketstation, SettingMcd2Pocketstation, SettingBiosBrowsePath, SettingEXP1Filepath,
SettingEXP1BrowsePath, SettingPIOConnected>
Settings<SettingMcd1, SettingMcd2, SettingBios, SettingPpfDir, SettingPsxExe, SettingXa, SettingSpuIrq,
SettingBnWMdec, SettingScaler, SettingAutoVideo, SettingVideo, SettingFastBoot, SettingDebugSettings,
SettingRCntFix, SettingIsoPath, SettingLocale, SettingMcd1Inserted, SettingMcd2Inserted, SettingDynarec,
Setting8MB, SettingGUITheme, SettingDither, SettingCachedDithering, SettingGLErrorReporting,
SettingGLErrorReportingSeverity, SettingFullCaching, SettingHardwareRenderer, SettingShownAutoUpdateConfig,
SettingAutoUpdate, SettingMSAA, SettingLinearFiltering, SettingKioskMode, SettingMcd1Pocketstation,
SettingMcd2Pocketstation, SettingBiosBrowsePath, SettingEXP1Filepath, SettingEXP1BrowsePath,
SettingPIOConnected>
settings;
class PcsxConfig {
public:
Expand Down
3 changes: 2 additions & 1 deletion src/core/psxmem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,8 @@ void PCSX::Memory::write32(uint32_t address, uint32_t value) {
address);
} else {
g_system->log(LogClass::CPU, _("32-bit write to unknown address: %8.8lx\n"), address);
if (g_emulator->settings.get<Emulator::SettingDebugSettings>().get<Emulator::DebugSettings::Debug>()) {
if (g_emulator->settings.get<Emulator::SettingDebugSettings>()
.get<Emulator::DebugSettings::Debug>()) {

Check warning on line 549 in src/core/psxmem.cc

View check run for this annotation

Codecov / codecov/patch

src/core/psxmem.cc#L548-L549

Added lines #L548 - L549 were not covered by tests
g_system->pause();
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/core/r3000a.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,8 @@ Formula One 2001
uint32_t pcOffset = pc & 0xffffff;
uint32_t pcCache = pc & 0xfff;

uint8_t * iAddr = m_regs.iCacheAddr;
uint8_t * iCode = m_regs.iCacheCode;
uint8_t *iAddr = m_regs.iCacheAddr;
uint8_t *iCode = m_regs.iCacheCode;

// cached - RAM
if (pcBank == 0x00 || pcBank == 0x80) {
Expand Down Expand Up @@ -504,8 +504,10 @@ Formula One 2001
PCdrvFile(const std::filesystem::path &filename) : IO<File>(new PosixFile(filename)) {}
PCdrvFile(const std::filesystem::path &filename, FileOps::ReadWrite)
: IO<File>(new PosixFile(filename, FileOps::READWRITE)) {}
PCdrvFile(const std::filesystem::path &filename, FileOps::Truncate) : IO<File>(new PosixFile(filename, FileOps::TRUNCATE)) {}
PCdrvFile(const std::filesystem::path &filename, FileOps::Create) : IO<File>(new PosixFile(filename, FileOps::CREATE)) {}
PCdrvFile(const std::filesystem::path &filename, FileOps::Truncate)
: IO<File>(new PosixFile(filename, FileOps::TRUNCATE)) {}
PCdrvFile(const std::filesystem::path &filename, FileOps::Create)
: IO<File>(new PosixFile(filename, FileOps::CREATE)) {}

Check warning on line 510 in src/core/r3000a.h

View check run for this annotation

Codecov / codecov/patch

src/core/r3000a.h#L509-L510

Added lines #L509 - L510 were not covered by tests
virtual ~PCdrvFile() = default;
std::string m_relativeFilename;
};
Expand Down
6 changes: 3 additions & 3 deletions src/core/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,21 @@ class System {

// Legacy printf stuff; needs to be replaced with loggers
template <typename... Args>
void printf(const char *format, const Args &...args) {
void printf(const char *format, const Args &... args) {
std::string s = fmt::sprintf(format, args...);
printf(std::move(s));
}
virtual void printf(std::string &&) = 0;
// Add a log line
template <typename... Args>
void log(LogClass logClass, const char *format, const Args &...args) {
void log(LogClass logClass, const char *format, const Args &... args) {
std::string s = fmt::sprintf(format, args...);
log(logClass, std::move(s));
}
virtual void log(LogClass, std::string &&) = 0;
// Display a popup message to the user
template <typename... Args>
void message(const char *format, const Args &...args) {
void message(const char *format, const Args &... args) {

Check warning on line 143 in src/core/system.h

View check run for this annotation

Codecov / codecov/patch

src/core/system.h#L143

Added line #L143 was not covered by tests
std::string s = fmt::sprintf(format, args...);
message(std::move(s));
}
Expand Down
1 change: 0 additions & 1 deletion src/gui/extra.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
-- along with this program; if not, write to the
-- Free Software Foundation, Inc.,
-- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

PCSX.Helpers = PCSX.Helpers or {}
PCSX.Helpers.UI = {
imageCoordinates = function(x, y, w, h, imageW, imageH)
Expand Down
1 change: 0 additions & 1 deletion src/gui/imguiextraffi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
-- along with this program; if not, write to the
-- Free Software Foundation, Inc.,
-- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

ffi.cdef [[
typedef struct { float x, y; } ImVec2;

Expand Down
16 changes: 11 additions & 5 deletions src/gui/luanvg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,30 @@ void guiDrawBezierArrow(PCSX::GUI* gui, float width, ImVec2 p1, ImVec2 c1, ImVec

void nvgRGBWrapper(unsigned char r, unsigned char g, unsigned char b, NVGcolor* ret) { *ret = nvgRGB(r, g, b); }
void nvgRGBfWrapper(float r, float g, float b, NVGcolor* ret) { *ret = nvgRGBf(r, g, b); }
void nvgRGBAWrapper(unsigned char r, unsigned char g, unsigned char b, unsigned char a, NVGcolor* ret) { *ret = nvgRGBA(r, g, b, a); }
void nvgRGBAWrapper(unsigned char r, unsigned char g, unsigned char b, unsigned char a, NVGcolor* ret) {
*ret = nvgRGBA(r, g, b, a);
}

Check warning on line 37 in src/gui/luanvg.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/luanvg.cc#L35-L37

Added lines #L35 - L37 were not covered by tests
void nvgRGBAfWrapper(float r, float g, float b, float a, NVGcolor* ret) { *ret = nvgRGBAf(r, g, b, a); }
void nvgLerpRGBAWrapper(NVGcolor c0, NVGcolor c1, float u, NVGcolor* ret) { *ret = nvgLerpRGBA(c0, c1, u); }
void nvgTransRGBAWrapper(NVGcolor c0, unsigned char a, NVGcolor* ret) { *ret = nvgTransRGBA(c0, a); }
void nvgTransRGBAfWrapper(NVGcolor c0, float a, NVGcolor* ret) { *ret = nvgTransRGBAf(c0, a); }
void nvgHSLWrapper(float h, float s, float l, NVGcolor* ret) { *ret = nvgHSL(h, s, l); }
void nvgHSLAWrapper(float h, float s, float l, unsigned char a, NVGcolor* ret) { *ret = nvgHSLA(h, s, l, a); }

void nvgLinearGradientWrapper(NVGcontext* ctx, float sx, float sy, float ex, float ey, NVGcolor icol, NVGcolor ocol, NVGpaint* ret) {
void nvgLinearGradientWrapper(NVGcontext* ctx, float sx, float sy, float ex, float ey, NVGcolor icol, NVGcolor ocol,

Check warning on line 45 in src/gui/luanvg.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/luanvg.cc#L45

Added line #L45 was not covered by tests
NVGpaint* ret) {
*ret = nvgLinearGradient(ctx, sx, sy, ex, ey, icol, ocol);
}
void nvgBoxGradientWrapper(NVGcontext* ctx, float x, float y, float w, float h, float r, float f, NVGcolor icol, NVGcolor ocol, NVGpaint* ret) {
void nvgBoxGradientWrapper(NVGcontext* ctx, float x, float y, float w, float h, float r, float f, NVGcolor icol,

Check warning on line 49 in src/gui/luanvg.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/luanvg.cc#L49

Added line #L49 was not covered by tests
NVGcolor ocol, NVGpaint* ret) {
*ret = nvgBoxGradient(ctx, x, y, w, h, r, f, icol, ocol);
}
void nvgRadialGradientWrapper(NVGcontext* ctx, float cx, float cy, float inr, float outr, NVGcolor icol, NVGcolor ocol, NVGpaint* ret) {
void nvgRadialGradientWrapper(NVGcontext* ctx, float cx, float cy, float inr, float outr, NVGcolor icol, NVGcolor ocol,

Check warning on line 53 in src/gui/luanvg.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/luanvg.cc#L53

Added line #L53 was not covered by tests
NVGpaint* ret) {
*ret = nvgRadialGradient(ctx, cx, cy, inr, outr, icol, ocol);
}
void nvgImagePatternWrapper(NVGcontext* ctx, float ox, float oy, float ex, float ey, float angle, int image, float alpha, NVGpaint* ret) {
void nvgImagePatternWrapper(NVGcontext* ctx, float ox, float oy, float ex, float ey, float angle, int image,

Check warning on line 57 in src/gui/luanvg.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/luanvg.cc#L57

Added line #L57 was not covered by tests
float alpha, NVGpaint* ret) {
*ret = nvgImagePattern(ctx, ox, oy, ex, ey, angle, image, alpha);
}

Expand Down
1 change: 0 additions & 1 deletion src/gui/nvgffi-cdefs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
-- along with this program; if not, write to the
-- Free Software Foundation, Inc.,
-- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

ffi.cdef [[
typedef struct NVGcontext NVGcontext;

Expand Down
Loading

0 comments on commit 9f6f544

Please sign in to comment.