Skip to content

Commit

Permalink
[Chores] Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasnoble authored Nov 27, 2023
1 parent cf583e8 commit 8cc6f2e
Show file tree
Hide file tree
Showing 60 changed files with 864 additions and 2,066 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
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
30 changes: 20 additions & 10 deletions src/core/pad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,8 @@ void PadsImpl::setLua(PCSX::Lua L) {
L.getfieldtable(1);

L.declareFunc(
"getButton", [this, pad](PCSX::Lua L) -> int {
"getButton",
[this, pad](PCSX::Lua L) -> int {
int n = L.gettop();
if (n == 0) {
return L.error("Not enough arguments to getButton");
Expand All @@ -1316,9 +1317,11 @@ void PadsImpl::setLua(PCSX::Lua L) {
unsigned button = L.checknumber(1);
L.push(((overrides & buttons) & (1 << button)) == 0);
return 1;
}, -1);
},
-1);
L.declareFunc(
"setOverride", [this, pad](PCSX::Lua L) -> int {
"setOverride",
[this, pad](PCSX::Lua L) -> int {
int n = L.gettop();
if (n == 0) {
return L.error("Not enough arguments to setOverride");
Expand All @@ -1331,9 +1334,11 @@ void PadsImpl::setLua(PCSX::Lua L) {
button = 1 << button;
overrides &= ~button;
return 0;
}, -1);
},
-1);
L.declareFunc(
"clearOverride", [this, pad](PCSX::Lua L) -> int {
"clearOverride",
[this, pad](PCSX::Lua L) -> int {
int n = L.gettop();
if (n == 0) {
return L.error("Not enough arguments to clearOverride");
Expand All @@ -1346,22 +1351,27 @@ void PadsImpl::setLua(PCSX::Lua L) {
button = 1 << button;
overrides |= button;
return 0;
}, -1);
},
-1);
L.declareFunc(
"setAnalogMode", [this, pad](PCSX::Lua L) -> int {
"setAnalogMode",
[this, pad](PCSX::Lua L) -> int {
int n = L.gettop();
if (n == 0) {
m_pads[pad].m_analogMode = false;
} else {
m_pads[pad].m_analogMode = L.toboolean();
}
return 0;
}, -1);
},
-1);
L.declareFunc(
"map", [this, pad](PCSX::Lua L) -> int {
"map",
[this, pad](PCSX::Lua L) -> int {
m_pads[pad].map();
return 0;
}, -1);
},
-1);

Check warning on line 1374 in src/core/pad.cc

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Large Method

PadsImpl::setLua increases from 124 to 134 lines of code, threshold = 70. Large functions with many lines of code are generally harder to understand and lower the code health. Avoid adding more lines to this function.

L.pop();
L.pop();
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 @@ -548,7 +548,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 552 in src/core/psxmem.cc

View check run for this annotation

Codecov / codecov/patch

src/core/psxmem.cc#L551-L552

Added lines #L551 - L552 were not covered by tests
g_system->pause();
}
}
Expand Down
1 change: 0 additions & 1 deletion src/core/psxmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ class Memory {

// hopefully this should become private eventually, with only certain classes having direct access.
public:

uint8_t *m_wram = nullptr; // Kernel & User Memory (8 Meg)
uint8_t *m_exp1 = nullptr; // Expansion Region 1 (ROM/RAM) / Parallel Port (512K)
uint8_t *m_bios = nullptr; // BIOS ROM (512K)
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
4 changes: 1 addition & 3 deletions src/gui/gui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2471,9 +2471,7 @@ std::string PCSX::GUI::getSaveStatePrefix(bool includeSeparator) {
}
}

std::string PCSX::GUI::getSaveStatePostfix() {
return ".sstate";
}
std::string PCSX::GUI::getSaveStatePostfix() { return ".sstate"; }

Check warning on line 2474 in src/gui/gui.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/gui.cc#L2474

Added line #L2474 was not covered by tests

std::string PCSX::GUI::buildSaveStateFilename(int i) {
return fmt::format("{}{}{}", getSaveStatePrefix(false), getSaveStatePostfix(), i);
Expand Down
15 changes: 8 additions & 7 deletions src/gui/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,14 @@ class GUI final : public UI {
IdleSwapInterval, ShowLuaConsole, ShowLuaInspector, ShowLuaEditor, ShowMainVRAMViewer, ShowCLUTVRAMViewer,
ShowVRAMViewer1, ShowVRAMViewer2, ShowVRAMViewer3, ShowVRAMViewer4, ShowMemoryObserver, ShowTypedDebugger,
ShowMemcardManager, ShowRegisters, ShowAssembly, ShowDisassembly, ShowBreakpoints, ShowNamedSaveStates,
ShowEvents, ShowHandlers, ShowKernelLog, ShowCallstacks, ShowSIO1, ShowIsoBrowser, ShowGPULogger, MainFontSize,
MonoFontSize, GUITheme, AllowMouseCaptureToggle, EnableRawMouseMotion, WidescreenRatio, ShowPIOCartConfig,
ShowMemoryEditor1, ShowMemoryEditor2, ShowMemoryEditor3, ShowMemoryEditor4, ShowMemoryEditor5,
ShowMemoryEditor6, ShowMemoryEditor7, ShowMemoryEditor8, ShowParallelPortEditor, ShowScratchpadEditor,
ShowHWRegsEditor, ShowBiosEditor, ShowVRAMEditor, MemoryEditor1Addr, MemoryEditor2Addr, MemoryEditor3Addr,
MemoryEditor4Addr, MemoryEditor5Addr, MemoryEditor6Addr, MemoryEditor7Addr, MemoryEditor8Addr,
ParallelPortEditorAddr, ScratchpadEditorAddr, HWRegsEditorAddr, BiosEditorAddr, VRAMEditorAddr>
ShowEvents, ShowHandlers, ShowKernelLog, ShowCallstacks, ShowSIO1, ShowIsoBrowser, ShowGPULogger,
MainFontSize, MonoFontSize, GUITheme, AllowMouseCaptureToggle, EnableRawMouseMotion, WidescreenRatio,
ShowPIOCartConfig, ShowMemoryEditor1, ShowMemoryEditor2, ShowMemoryEditor3, ShowMemoryEditor4,
ShowMemoryEditor5, ShowMemoryEditor6, ShowMemoryEditor7, ShowMemoryEditor8, ShowParallelPortEditor,
ShowScratchpadEditor, ShowHWRegsEditor, ShowBiosEditor, ShowVRAMEditor, MemoryEditor1Addr,
MemoryEditor2Addr, MemoryEditor3Addr, MemoryEditor4Addr, MemoryEditor5Addr, MemoryEditor6Addr,
MemoryEditor7Addr, MemoryEditor8Addr, ParallelPortEditorAddr, ScratchpadEditorAddr, HWRegsEditorAddr,
BiosEditorAddr, VRAMEditorAddr>
settings;

// imgui can't handle more than one "instance", so...
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
21 changes: 5 additions & 16 deletions src/gui/imguisafe.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,20 @@
-- along with this program; if not, write to the
-- Free Software Foundation, Inc.,
-- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

if not imgui.safe then
imgui.safe = {}
end
if not imgui.safe then imgui.safe = {} end

function imgui.safe.builder(proxy, finalIfShown, final)
local function builder(...)
local args = { ... }
local lambda = args[#args]
if type(lambda) ~= 'function' then
error('Last argument must be a function')
end
if type(lambda) ~= 'function' then error('Last argument must be a function') end
args[#args] = nil
local rets = { proxy(...) }
local shown = rets[1]
local status, err = pcall(function() lambda(table.unpack(args)) end)
if shown and finalIfShown then
finalIfShown()
end
if final then
final()
end
if not status then
error(err)
end
if shown and finalIfShown then finalIfShown() end
if final then final() end
if not status then error(err) end
return table.unpack(rets)
end
return builder
Expand Down
Loading

0 comments on commit 8cc6f2e

Please sign in to comment.