Skip to content

Commit

Permalink
Merge pull request #18581 from GermanAizek/lower-scope
Browse files Browse the repository at this point in the history
Reduced lower scope for local objects
  • Loading branch information
hrydgard committed Dec 20, 2023
2 parents d9c6d09 + 95f535d commit dd1396e
Show file tree
Hide file tree
Showing 45 changed files with 117 additions and 117 deletions.
5 changes: 3 additions & 2 deletions Common/Data/Text/Parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

// Not strictly a parser...
void NiceSizeFormat(uint64_t size, char *out, size_t bufSize) {
const char *sizes[] = { "B","KB","MB","GB","TB","PB","EB" };
int s = 0;
int frac = 0;
while (size >= 1024) {
Expand All @@ -18,8 +17,10 @@ void NiceSizeFormat(uint64_t size, char *out, size_t bufSize) {
float f = (float)size + ((float)frac / 1024.0f);
if (s == 0)
snprintf(out, bufSize, "%d B", (int)size);
else
else {
const char* sizes[] = { "B","KB","MB","GB","TB","PB","EB" };
snprintf(out, bufSize, "%3.2f %s", f, sizes[s]);
}
}

std::string NiceSizeFormat(uint64_t size) {
Expand Down
2 changes: 1 addition & 1 deletion Common/File/FileUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,8 @@ bool CreateDir(const Path &path) {
// Convert it to a "CreateDirIn" call, if possible, since that's
// what we can do with the storage API.
AndroidContentURI uri(path.ToString());
std::string newDirName = uri.GetLastPart();
if (uri.NavigateUp()) {
std::string newDirName = uri.GetLastPart();
INFO_LOG(COMMON, "Calling Android_CreateDirectory(%s, %s)", uri.ToString().c_str(), newDirName.c_str());
return Android_CreateDirectory(uri.ToString(), newDirName) == StorageError::SUCCESS;
} else {
Expand Down
2 changes: 1 addition & 1 deletion Common/File/PathBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ bool LoadRemoteFileList(const Path &url, const std::string &userAgent, bool *can
}

// Start by requesting the list of files from the server.
http::RequestParams req(baseURL.Resource(), "text/plain, text/html; q=0.9, */*; q=0.8");
if (http.Resolve(baseURL.Host().c_str(), baseURL.Port())) {
if (http.Connect(2, 20.0, cancel)) {
http::RequestParams req(baseURL.Resource(), "text/plain, text/html; q=0.9, */*; q=0.8");
net::RequestProgress progress(cancel);
code = http.GET(req, &result, responseHeaders, &progress);
http.Disconnect();
Expand Down
2 changes: 1 addition & 1 deletion Common/OSVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ std::string GetWindowsVersion() {

// Start from higher to lower
for (auto release = rbegin(windowsReleases); release != rend(windowsReleases); ++release) {
std::string previewText = release->first;
WindowsReleaseInfo releaseInfo = release->second;
bool buildMatch = DoesVersionMatchWindows(releaseInfo);
if (buildMatch) {
std::string previewText = release->first;
return previewText;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Common/UI/PopupScreens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ void SliderPopupScreen::UpdateTextBox() {
void SliderPopupScreen::CreatePopupContents(UI::ViewGroup *parent) {
using namespace UI;
UIContext &dc = *screenManager()->getUIContext();
auto di = GetI18NCategory(I18NCat::DIALOG);

sliderValue_ = *value_;
if (disabled_ && sliderValue_ < 0)
Expand Down Expand Up @@ -362,6 +361,7 @@ void SliderPopupScreen::CreatePopupContents(UI::ViewGroup *parent) {
lin->Add(new TextView(units_))->SetTextColor(dc.theme->itemStyle.fgColor);

if (defaultValue_ != NO_DEFAULT_FLOAT) {
auto di = GetI18NCategory(I18NCat::DIALOG);
lin->Add(new Button(di->T("Reset")))->OnClick.Add([=](UI::EventParams &) {
sliderValue_ = defaultValue_;
changing_ = true;
Expand All @@ -381,7 +381,6 @@ void SliderPopupScreen::CreatePopupContents(UI::ViewGroup *parent) {
void SliderFloatPopupScreen::CreatePopupContents(UI::ViewGroup *parent) {
using namespace UI;
UIContext &dc = *screenManager()->getUIContext();
auto di = GetI18NCategory(I18NCat::DIALOG);

sliderValue_ = *value_;
LinearLayout *vert = parent->Add(new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(UI::Margins(10, 10))));
Expand All @@ -406,6 +405,7 @@ void SliderFloatPopupScreen::CreatePopupContents(UI::ViewGroup *parent) {
lin->Add(new TextView(units_))->SetTextColor(dc.theme->itemStyle.fgColor);

if (defaultValue_ != NO_DEFAULT_FLOAT) {
auto di = GetI18NCategory(I18NCat::DIALOG);
lin->Add(new Button(di->T("Reset")))->OnClick.Add([=](UI::EventParams &) {
sliderValue_ = defaultValue_;
if (liveUpdate_) {
Expand Down
2 changes: 1 addition & 1 deletion Common/UI/UIScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,8 @@ void PopupScreen::CreateViews() {
box_->SetDropShadowExpand(std::max(g_display.dp_xres, g_display.dp_yres));
box_->SetSpacing(0.0f);

View *title = new PopupHeader(title_);
if (HasTitleBar()) {
View* title = new PopupHeader(title_);
box_->Add(title);
}

Expand Down
2 changes: 1 addition & 1 deletion Core/Dialog/PSPNetconfDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ int PSPNetconfDialog::Update(int animSpeed) {
UpdateButtons();
UpdateCommon();
auto di = GetI18NCategory(I18NCat::DIALOG);
auto err = GetI18NCategory(I18NCat::ERRORS);
u64 now = (u64)(time_now_d() * 1000000.0);

// It seems JPCSP doesn't check for NETCONF_STATUS_APNET
Expand All @@ -250,6 +249,7 @@ int PSPNetconfDialog::Update(int animSpeed) {
StartDraw();

if (!hideNotice) {
auto err = GetI18NCategory(I18NCat::ERRORS);
const float WRAP_WIDTH = 254.0f;
const int confirmBtn = GetConfirmButton();
const int cancelBtn = GetCancelButton();
Expand Down
2 changes: 1 addition & 1 deletion Core/Dialog/PSPNpSigninDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,11 @@ int PSPNpSigninDialog::Update(int animSpeed) {

UpdateButtons();
UpdateCommon();
auto di = GetI18NCategory(I18NCat::DIALOG);
auto err = GetI18NCategory(I18NCat::ERRORS);
u64 now = (u64)(time_now_d() * 1000000.0);

if (request.npSigninStatus == NP_SIGNIN_STATUS_NONE) {
auto di = GetI18NCategory(I18NCat::DIALOG);
UpdateFade(animSpeed);
StartDraw();

Expand Down
2 changes: 1 addition & 1 deletion Core/Dialog/SavedataParam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1391,10 +1391,10 @@ bool SavedataParam::GetSize(SceUtilitySavedataParam *param)

const std::string saveDir = savePath + GetGameName(param) + GetSaveName(param);
bool exists = false;
auto listing = pspFileSystem.GetDirListing(saveDir, &exists);

if (param->sizeInfo.IsValid())
{
auto listing = pspFileSystem.GetDirListing(saveDir, &exists);
const u64 freeBytes = MemoryStick_FreeSpace();

s64 overwriteBytes = 0;
Expand Down
2 changes: 1 addition & 1 deletion Core/FileSystems/BlockDevices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ BlockDevice *constructBlockDevice(FileLoader *fileLoader) {
}

void BlockDevice::NotifyReadError() {
auto err = GetI18NCategory(I18NCat::ERRORS);
if (!reportedError_) {
auto err = GetI18NCategory(I18NCat::ERRORS);
g_OSD.Show(OSDType::MESSAGE_WARNING, err->T("Game disc read error - ISO corrupt"), fileLoader_->GetPath().ToVisualString(), 6.0f);
reportedError_ = true;
}
Expand Down
3 changes: 1 addition & 2 deletions Core/HLE/Plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,6 @@ bool Load() {
auto sy = GetI18NCategory(I18NCat::SYSTEM);

for (const std::string &filename : prxPlugins) {
std::string shortName = Path(filename).GetFilename();

std::string error_string = "";
SceUID module = KernelLoadModule(filename, &error_string);
if (!error_string.empty() || module < 0) {
Expand All @@ -193,6 +191,7 @@ bool Load() {
if (ret < 0) {
ERROR_LOG(SYSTEM, "Unable to start plugin %s: %08x", filename.c_str(), ret);
} else {
std::string shortName = Path(filename).GetFilename();
g_OSD.Show(OSDType::MESSAGE_SUCCESS, ApplySafeSubstitutions(sy->T("Loaded plugin: %1"), shortName));
started = true;
}
Expand Down
2 changes: 1 addition & 1 deletion Core/HLE/proAdhoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1312,7 +1312,6 @@ void timeoutFriendsRecursive(SceNetAdhocctlPeerInfo * node, int32_t* count) {

void sendChat(const std::string &chatString) {
SceNetAdhocctlChatPacketC2S chat;
auto n = GetI18NCategory(I18NCat::NETWORKING);
chat.base.opcode = OPCODE_CHAT;
//TODO check network inited, check send success or not, chatlog.pushback error on failed send, pushback error on not connected
if (friendFinderRunning) {
Expand All @@ -1334,6 +1333,7 @@ void sendChat(const std::string &chatString) {
}
} else {
std::lock_guard<std::mutex> guard(chatLogLock);
auto n = GetI18NCategory(I18NCat::NETWORKING);
chatLog.push_back(n->T("You're in Offline Mode, go to lobby or online hall"));
chatMessageGeneration++;
}
Expand Down
4 changes: 2 additions & 2 deletions Core/HLE/sceAudiocodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ static int sceAudiocodecDecode(u32 ctxPtr, int codec) {
}

if (IsValidCodec(codec)){
// Use SimpleAudioDec to decode audio
auto ctx = PSPPointer<AudioCodecContext>::Create(ctxPtr); // On stack, no need to allocate.
int outbytes = 0;
// find a decoder in audioList
auto decoder = findDecoder(ctxPtr);
Expand All @@ -115,6 +113,8 @@ static int sceAudiocodecDecode(u32 ctxPtr, int codec) {
}

if (decoder != NULL) {
// Use SimpleAudioDec to decode audio
auto ctx = PSPPointer<AudioCodecContext>::Create(ctxPtr); // On stack, no need to allocate.
// Decode audio
decoder->Decode(Memory::GetPointer(ctx->inDataPtr), ctx->inDataSize, Memory::GetPointerWrite(ctx->outDataPtr), &outbytes);
}
Expand Down
2 changes: 1 addition & 1 deletion Core/HLE/sceFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,10 +519,10 @@ class FontLib {
fontMap.erase(fonts_[i]);
}
}
u32 args[2] = { userDataAddr(), (u32)handle_ };
// TODO: The return value of this is leaking.
if (handle_) { // Avoid calling free-callback on double-free
if (coreState != CORE_POWERDOWN) {
u32 args[2] = { userDataAddr(), (u32)handle_ };
hleEnqueueCall(freeFuncAddr(), 2, args);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Core/HLE/sceKernelModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2164,7 +2164,6 @@ int KernelStartModule(SceUID moduleId, u32 argsize, u32 argAddr, u32 returnValue

static void sceKernelStartModule(u32 moduleId, u32 argsize, u32 argAddr, u32 returnValueAddr, u32 optionAddr)
{
auto smoption = PSPPointer<SceKernelSMOption>::Create(optionAddr);
u32 error;
PSPModule *module = kernelObjects.Get<PSPModule>(moduleId, error);
if (!module) {
Expand All @@ -2190,6 +2189,7 @@ static void sceKernelStartModule(u32 moduleId, u32 argsize, u32 argAddr, u32 ret
moduleId,argsize,argAddr,returnValueAddr,optionAddr);

bool needsWait;
auto smoption = PSPPointer<SceKernelSMOption>::Create(optionAddr);
int ret = KernelStartModule(moduleId, argsize, argAddr, returnValueAddr, smoption.PtrOrNull(), &needsWait);

if (needsWait) {
Expand Down
2 changes: 1 addition & 1 deletion Core/MIPS/MIPSAnalyst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1179,10 +1179,10 @@ namespace MIPSAnalyst {
void FinalizeScan(bool insertSymbols) {
HashFunctions();

Path hashMapFilename = GetSysDirectory(DIRECTORY_SYSTEM) / "knownfuncs.ini";
if (g_Config.bFuncHashMap || g_Config.bFuncReplacements) {
LoadBuiltinHashMap();
if (g_Config.bFuncHashMap) {
Path hashMapFilename = GetSysDirectory(DIRECTORY_SYSTEM) / "knownfuncs.ini";
LoadHashMap(hashMapFilename);
StoreHashMap(hashMapFilename);
}
Expand Down
37 changes: 21 additions & 16 deletions Core/SaveState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ namespace SaveState
}

// Memory is a bit tricky when jit is enabled, since there's emuhacks in it.
auto savedReplacements = SaveAndClearReplacements();
if (MIPSComp::jit && p.mode == p.MODE_WRITE) {
std::lock_guard<std::recursive_mutex> guard(MIPSComp::jitLock);
if (MIPSComp::jit) {
Expand All @@ -388,8 +387,10 @@ namespace SaveState

// Don't bother restoring if reading, we'll deal with that in KernelModuleDoState.
// In theory, different functions might have been runtime loaded in the state.
if (p.mode != p.MODE_READ)
if (p.mode != p.MODE_READ) {
auto savedReplacements = SaveAndClearReplacements();
RestoreSavedReplacements(savedReplacements);
}

MemoryStick_DoState(p);
currentMIPS->DoState(p);
Expand Down Expand Up @@ -601,18 +602,20 @@ namespace SaveState
Load(fn, slot, callback, cbUserData);
}
} else {
auto sy = GetI18NCategory(I18NCat::SYSTEM);
if (callback)
if (callback) {
auto sy = GetI18NCategory(I18NCat::SYSTEM);
callback(Status::FAILURE, sy->T("Failed to load state. Error in the file system."), cbUserData);
}
}
}

bool UndoLoad(const Path &gameFilename, Callback callback, void *cbUserData)
{
if (g_Config.sStateLoadUndoGame != GenerateFullDiscId(gameFilename)) {
auto sy = GetI18NCategory(I18NCat::SYSTEM);
if (callback)
if (callback) {
auto sy = GetI18NCategory(I18NCat::SYSTEM);
callback(Status::FAILURE, sy->T("Error: load undo state is from a different game"), cbUserData);
}
return false;
}

Expand All @@ -621,20 +624,20 @@ namespace SaveState
Load(fn, LOAD_UNDO_SLOT, callback, cbUserData);
return true;
} else {
auto sy = GetI18NCategory(I18NCat::SYSTEM);
if (callback)
if (callback) {
auto sy = GetI18NCategory(I18NCat::SYSTEM);
callback(Status::FAILURE, sy->T("Failed to load state for load undo. Error in the file system."), cbUserData);
}
return false;
}
}

void SaveSlot(const Path &gameFilename, int slot, Callback callback, void *cbUserData)
{
Path fn = GenerateSaveSlotFilename(gameFilename, slot, STATE_EXTENSION);
Path shot = GenerateSaveSlotFilename(gameFilename, slot, SCREENSHOT_EXTENSION);
Path fnUndo = GenerateSaveSlotFilename(gameFilename, slot, UNDO_STATE_EXTENSION);
Path shotUndo = GenerateSaveSlotFilename(gameFilename, slot, UNDO_SCREENSHOT_EXTENSION);
if (!fn.empty()) {
Path shot = GenerateSaveSlotFilename(gameFilename, slot, SCREENSHOT_EXTENSION);
auto renameCallback = [=](Status status, const std::string &message, void *data) {
if (status != Status::FAILURE) {
if (g_Config.bEnableStateUndo) {
Expand All @@ -654,26 +657,28 @@ namespace SaveState
};
// Let's also create a screenshot.
if (g_Config.bEnableStateUndo) {
Path shotUndo = GenerateSaveSlotFilename(gameFilename, slot, UNDO_SCREENSHOT_EXTENSION);
DeleteIfExists(shotUndo);
RenameIfExists(shot, shotUndo);
}
SaveScreenshot(shot, Callback(), 0);
Save(fn.WithExtraExtension(".tmp"), slot, renameCallback, cbUserData);
} else {
auto sy = GetI18NCategory(I18NCat::SYSTEM);
if (callback)
if (callback) {
auto sy = GetI18NCategory(I18NCat::SYSTEM);
callback(Status::FAILURE, sy->T("Failed to save state. Error in the file system."), cbUserData);
}
}
}

bool UndoSaveSlot(const Path &gameFilename, int slot) {
Path fn = GenerateSaveSlotFilename(gameFilename, slot, STATE_EXTENSION);
Path shot = GenerateSaveSlotFilename(gameFilename, slot, SCREENSHOT_EXTENSION);
bool UndoSaveSlot(const Path &gameFilename, int slot) {
Path fnUndo = GenerateSaveSlotFilename(gameFilename, slot, UNDO_STATE_EXTENSION);
Path shotUndo = GenerateSaveSlotFilename(gameFilename, slot, UNDO_SCREENSHOT_EXTENSION);

// Do nothing if there's no undo.
if (File::Exists(fnUndo)) {
Path fn = GenerateSaveSlotFilename(gameFilename, slot, STATE_EXTENSION);
Path shot = GenerateSaveSlotFilename(gameFilename, slot, SCREENSHOT_EXTENSION);
Path shotUndo = GenerateSaveSlotFilename(gameFilename, slot, UNDO_SCREENSHOT_EXTENSION);
// Swap them so they can undo again to redo. Mistakes happen.
SwapIfExists(shotUndo, shot);
SwapIfExists(fnUndo, fn);
Expand Down
3 changes: 2 additions & 1 deletion Core/Util/DisArm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <cstdlib>
#include <cstring>
#include <array>

#include "Common/Arm64Emitter.h"
#include "Common/StringUtils.h"
Expand Down Expand Up @@ -496,7 +497,7 @@ static void DataProcessingRegister(uint32_t w, uint64_t addr, Instruction *instr
int op31 = (w >> 21) & 0x7;
int o0 = (w >> 15) & 1;
int Ra = (w >> 10) & 0x1f;
const char *opnames[8] = { 0, 0, "maddl", "msubl", "smulh", 0, 0, 0 };
static constexpr std::array<const char*, 8> opnames = { 0, 0, "maddl", "msubl", "smulh", 0, 0, 0 };

if (op31 == 0) {
// madd/msub supports both 32-bit and 64-bit modes
Expand Down
3 changes: 2 additions & 1 deletion GPU/Common/ShaderId.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <string>
#include <sstream>
#include <array>

#include "Common/GPU/thin3d.h"
#include "Common/StringUtils.h"
Expand Down Expand Up @@ -29,7 +30,7 @@ std::string VertexShaderDesc(const VShaderID &id) {
const char *uvprojModes[4] = { "TexProjPos ", "TexProjUV ", "TexProjNNrm ", "TexProjNrm " };
desc << uvprojModes[uvprojMode];
}
const char *uvgModes[4] = { "UV ", "UVMtx ", "UVEnv ", "UVUnk " };
static constexpr std::array<const char*, 4> uvgModes = { "UV ", "UVMtx ", "UVEnv ", "UVUnk " };
int ls0 = id.Bits(VS_BIT_LS0, 2);
int ls1 = id.Bits(VS_BIT_LS1, 2);

Expand Down
2 changes: 1 addition & 1 deletion GPU/Common/TextureCacheCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,6 @@ bool TextureCacheCommon::MatchFramebuffer(

void TextureCacheCommon::SetTextureFramebuffer(const AttachCandidate &candidate) {
VirtualFramebuffer *framebuffer = candidate.fb;
FramebufferMatchInfo fbInfo = candidate.match;
RasterChannel channel = candidate.channel;

if (candidate.match.reinterpret) {
Expand All @@ -1132,6 +1131,7 @@ void TextureCacheCommon::SetTextureFramebuffer(const AttachCandidate &candidate)
nextFramebufferTextureChannel_ = RASTER_COLOR;

if (framebufferManager_->UseBufferedRendering()) {
FramebufferMatchInfo fbInfo = candidate.match;
// Detect when we need to apply the horizontal texture swizzle.
u64 depthUpperBits = (channel == RASTER_DEPTH && framebuffer->fb_format == GE_FORMAT_8888) ? ((gstate.getTextureAddress(0) & 0x600000) >> 20) : 0;
bool needsDepthXSwizzle = depthUpperBits == 2;
Expand Down
2 changes: 1 addition & 1 deletion GPU/Common/TransformCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void Lighter::Light(float colorOut0[4], float colorOut1[4], const float colorIn[
Color4 diff = (lightDiff * *diffuse) * dot;

// Real PSP specular
Vec3f toViewer(0, 0, 1);
static const Vec3f toViewer(0, 0, 1);
// Better specular
// Vec3f toViewer = (viewer - pos).NormalizedOr001(cpu_info.bSSE4_1);

Expand Down
Loading

0 comments on commit dd1396e

Please sign in to comment.