Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Even more fixes #19523

Merged
merged 3 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Common/File/DiskFree.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
#include "Common/File/Path.h"

// If this fails, false is returned and space is negative.
// Try to avoid calling this from the main thread, if possible. Can be SLOW.
bool free_disk_space(const Path &path, int64_t &space);
2 changes: 1 addition & 1 deletion Core/FileSystems/BlobFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,6 @@ bool BlobFileSystem::RemoveFile(const std::string &filename) {
return false;
}

u64 BlobFileSystem::FreeSpace(const std::string &path) {
u64 BlobFileSystem::FreeDiskSpace(const std::string &path) {
return 0;
}
2 changes: 1 addition & 1 deletion Core/FileSystems/BlobFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class BlobFileSystem : public IFileSystem {
bool RmDir(const std::string &dirname) override;
int RenameFile(const std::string &from, const std::string &to) override;
bool RemoveFile(const std::string &filename) override;
u64 FreeSpace(const std::string &path) override;
u64 FreeDiskSpace(const std::string &path) override;

bool ComputeRecursiveDirSizeIfFast(const std::string &path, int64_t *size) override { return false; }

Expand Down
2 changes: 1 addition & 1 deletion Core/FileSystems/DirectoryFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ std::vector<PSPFileInfo> DirectoryFileSystem::GetDirListing(const std::string &p
return ReplayApplyDiskListing(myVector, CoreTiming::GetGlobalTimeUs());
}

u64 DirectoryFileSystem::FreeSpace(const std::string &path) {
u64 DirectoryFileSystem::FreeDiskSpace(const std::string &path) {
int64_t result = 0;
if (free_disk_space(GetLocalPath(path), result)) {
return ReplayApplyDisk64(ReplayAction::FREESPACE, (uint64_t)result, CoreTiming::GetGlobalTimeUs());
Expand Down
4 changes: 2 additions & 2 deletions Core/FileSystems/DirectoryFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class DirectoryFileSystem : public IFileSystem {
int RenameFile(const std::string &from, const std::string &to) override;
bool RemoveFile(const std::string &filename) override;
FileSystemFlags Flags() override { return flags; }
u64 FreeSpace(const std::string &path) override;
u64 FreeDiskSpace(const std::string &path) override;

bool ComputeRecursiveDirSizeIfFast(const std::string &path, int64_t *size) override;

Expand Down Expand Up @@ -129,7 +129,7 @@ class VFSFileSystem : public IFileSystem {
int RenameFile(const std::string &from, const std::string &to) override;
bool RemoveFile(const std::string &filename) override;
FileSystemFlags Flags() override { return FileSystemFlags::FLASH; }
u64 FreeSpace(const std::string &path) override { return 0; }
u64 FreeDiskSpace(const std::string &path) override { return 0; }

bool ComputeRecursiveDirSizeIfFast(const std::string &path, int64_t *size) override { return false; }

Expand Down
4 changes: 2 additions & 2 deletions Core/FileSystems/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class IFileSystem {
virtual int Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen, int &usec) = 0;
virtual PSPDevType DevType(u32 handle) = 0;
virtual FileSystemFlags Flags() = 0;
virtual u64 FreeSpace(const std::string &path) = 0;
virtual u64 FreeDiskSpace(const std::string &path) = 0;
virtual bool ComputeRecursiveDirSizeIfFast(const std::string &path, int64_t *size) = 0;
};

Expand Down Expand Up @@ -175,7 +175,7 @@ class EmptyFileSystem : public IFileSystem {
int Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen, int &usec) override { return SCE_KERNEL_ERROR_ERRNO_FUNCTION_NOT_SUPPORTED; }
PSPDevType DevType(u32 handle) override { return PSPDevType::INVALID; }
FileSystemFlags Flags() override { return FileSystemFlags::NONE; }
u64 FreeSpace(const std::string &path) override { return 0; }
u64 FreeDiskSpace(const std::string &path) override { return 0; }
bool ComputeRecursiveDirSizeIfFast(const std::string &path, int64_t *size) override { return false; }
};

Expand Down
4 changes: 2 additions & 2 deletions Core/FileSystems/ISOFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ISOFileSystem : public IFileSystem {
int Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen, int &usec) override;
PSPDevType DevType(u32 handle) override;
FileSystemFlags Flags() override;
u64 FreeSpace(const std::string &path) override { return 0; }
u64 FreeDiskSpace(const std::string &path) override { return 0; }

size_t WriteFile(u32 handle, const u8 *pointer, s64 size) override;
size_t WriteFile(u32 handle, const u8 *pointer, s64 size, int &usec) override;
Expand Down Expand Up @@ -146,7 +146,7 @@ class ISOBlockSystem : public IFileSystem {
return isoFileSystem_->DevType(handle);
}
FileSystemFlags Flags() override { return isoFileSystem_->Flags(); }
u64 FreeSpace(const std::string &path) override { return isoFileSystem_->FreeSpace(path); }
u64 FreeDiskSpace(const std::string &path) override { return isoFileSystem_->FreeDiskSpace(path); }

size_t WriteFile(u32 handle, const u8 *pointer, s64 size) override {
return isoFileSystem_->WriteFile(handle, pointer, size);
Expand Down
11 changes: 4 additions & 7 deletions Core/FileSystems/MetaFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,20 +606,18 @@ int MetaFileSystem::ReadEntireFile(const std::string &filename, std::vector<u8>
return 0;
}

u64 MetaFileSystem::FreeSpace(const std::string &path)
{
u64 MetaFileSystem::FreeDiskSpace(const std::string &path) {
std::lock_guard<std::recursive_mutex> guard(lock);
std::string of;
IFileSystem *system;
int error = MapFilePath(path, of, &system);
if (error == 0)
return system->FreeSpace(of);
return system->FreeDiskSpace(of);
else
return 0;
}

void MetaFileSystem::DoState(PointerWrap &p)
{
void MetaFileSystem::DoState(PointerWrap &p) {
std::lock_guard<std::recursive_mutex> guard(lock);

auto s = p.Section("MetaFileSystem", 1);
Expand All @@ -634,8 +632,7 @@ void MetaFileSystem::DoState(PointerWrap &p)
u32 n = (u32) fileSystems.size();
Do(p, n);
bool skipPfat0 = false;
if (n != (u32) fileSystems.size())
{
if (n != (u32) fileSystems.size()) {
if (n == (u32) fileSystems.size() - 1) {
skipPfat0 = true;
} else {
Expand Down
2 changes: 1 addition & 1 deletion Core/FileSystems/MetaFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class MetaFileSystem : public IHandleAllocator, public IFileSystem {
int Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen, int &usec) override;
PSPDevType DevType(u32 handle) override;
FileSystemFlags Flags() override { return FileSystemFlags::NONE; }
u64 FreeSpace(const std::string &path) override;
u64 FreeDiskSpace(const std::string &path) override;

// Convenience helper - returns < 0 on failure.
int ReadEntireFile(const std::string &filename, std::vector<u8> &data, bool quiet = false);
Expand Down
2 changes: 1 addition & 1 deletion Core/FileSystems/VirtualDiscFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class VirtualDiscFileSystem: public IFileSystem {
PSPDevType DevType(u32 handle) override;
std::vector<PSPFileInfo> GetDirListing(const std::string &path, bool *exists = nullptr) override;
FileSystemFlags Flags() override { return FileSystemFlags::UMD; }
u64 FreeSpace(const std::string &path) override { return 0; }
u64 FreeDiskSpace(const std::string &path) override { return 0; }

// unsupported operations
size_t WriteFile(u32 handle, const u8 *pointer, s64 size) override;
Expand Down
6 changes: 4 additions & 2 deletions Core/HW/MemoryStick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static void MemoryStick_CalcInitialFree() {

AndroidJNIThreadContext jniContext;

memstickInitialFree = pspFileSystem.FreeSpace("ms0:/") + pspFileSystem.ComputeRecursiveDirectorySize("ms0:/PSP/SAVEDATA/");
memstickInitialFree = pspFileSystem.FreeDiskSpace("ms0:/") + pspFileSystem.ComputeRecursiveDirectorySize("ms0:/PSP/SAVEDATA/");

std::unique_lock<std::mutex> guard(freeCalcMutex);
freeCalcStatus = FreeCalcStatus::DONE;
Expand All @@ -122,10 +122,12 @@ static void MemoryStick_WaitInitialFree() {
}

u64 MemoryStick_FreeSpace() {
NOTICE_LOG(Log::IO, "Calculated free disk space");

MemoryStick_WaitInitialFree();

const CompatFlags &flags = PSP_CoreParameter().compat.flags();
u64 realFreeSpace = pspFileSystem.FreeSpace("ms0:/");
u64 realFreeSpace = pspFileSystem.FreeDiskSpace("ms0:/");

// Cap the memory stick size to avoid math errors when old games get sizes that were
// not planned for back then (even though 2GB cards were available.)
Expand Down
30 changes: 25 additions & 5 deletions UI/BackgroundAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,32 @@ void SoundEffectMixer::LoadDefaultSample(UI::UISound sound) {
samples_[(size_t)sound] = std::unique_ptr<Sample>(sample);
}

void SoundEffectMixer::LoadSamples() {
class SampleLoadTask : public Task {
public:
SampleLoadTask(SoundEffectMixer *mixer) : mixer_(mixer) {}
TaskType Type() const override { return TaskType::IO_BLOCKING; }
TaskPriority Priority() const override {
return TaskPriority::NORMAL;
}
virtual void Run() {
mixer_->LoadSamplesOnThread();
}
private:
SoundEffectMixer *mixer_;
};

void SoundEffectMixer::Init() {
samples_.resize((size_t)UI::UISound::COUNT);
UI::SetSoundCallback([](UI::UISound sound, float volume) {
g_BackgroundAudio.SFX().Play(sound, volume);
});

// Load samples in the background.

g_threadManager.EnqueueTask(new SampleLoadTask(this));
}

void SoundEffectMixer::LoadSamplesOnThread() {
LoadDefaultSample(UI::UISound::BACK);
LoadDefaultSample(UI::UISound::SELECT);
LoadDefaultSample(UI::UISound::CONFIRM);
Expand All @@ -582,8 +606,4 @@ void SoundEffectMixer::LoadSamples() {
} else {
LoadDefaultSample(UI::UISound::LEADERBOARD_SUBMITTED);
}

UI::SetSoundCallback([](UI::UISound sound, float volume) {
g_BackgroundAudio.SFX().Play(sound, volume);
});
}
7 changes: 5 additions & 2 deletions UI/BackgroundAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ struct Sample {
// Mixer for things played on top of everything.
class SoundEffectMixer {
public:
void LoadSamples();

void Init();
void Mix(int16_t *buffer, int sz, int sampleRateHz);
void Play(UI::UISound sfx, float volume);

Expand All @@ -44,7 +43,11 @@ class SoundEffectMixer {
bool done;
};

// This can be called on a thread.
void LoadSamplesOnThread();
private:
bool samplesLoaded_ = false;

std::mutex mutex_;
std::vector<PlayInstance> queue_;
std::vector<PlayInstance> plays_;
Expand Down
51 changes: 41 additions & 10 deletions UI/MemStickScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,14 @@ ConfirmMemstickMoveScreen::~ConfirmMemstickMoveScreen() {
moveDataTask_->BlockUntilReady();
delete moveDataTask_;
}
if (oldSpaceTask_) {
oldSpaceTask_->BlockUntilReady();
delete oldSpaceTask_;
}
if (newSpaceTask_) {
newSpaceTask_->BlockUntilReady();
delete newSpaceTask_;
}
}

void ConfirmMemstickMoveScreen::CreateViews() {
Expand All @@ -479,7 +487,7 @@ void ConfirmMemstickMoveScreen::CreateViews() {

root_ = new LinearLayout(ORIENT_HORIZONTAL);

Path oldMemstickFolder = g_Config.memStickDirectory;
Path &oldMemstickFolder = g_Config.memStickDirectory;

Spacer *spacerColumn = new Spacer(new LinearLayoutParams(20.0, FILL_PARENT, 0.0f));
ViewGroup *leftColumn = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(1.0));
Expand All @@ -488,18 +496,20 @@ void ConfirmMemstickMoveScreen::CreateViews() {
root_->Add(leftColumn);
root_->Add(rightColumn);

int64_t freeSpaceNew;
int64_t freeSpaceOld;
free_disk_space(newMemstickFolder_, freeSpaceNew);
free_disk_space(oldMemstickFolder, freeSpaceOld);

leftColumn->Add(new TextView(ms->T("Selected PSP Data Folder"), ALIGN_LEFT, false));
if (!initialSetup_) {
leftColumn->Add(new NoticeView(NoticeLevel::WARN, ms->T("PPSSPP will restart after the change"), ""));
}
leftColumn->Add(new TextView(newMemstickFolder_.ToVisualString(), ALIGN_LEFT, false));
std::string newFreeSpaceText = std::string(ms->T("Free space")) + ": " + FormatSpaceString(freeSpaceNew);
leftColumn->Add(new TextView(newFreeSpaceText, ALIGN_LEFT, false));

newFreeSpaceView_ = leftColumn->Add(new TextView(ms->T("Free space"), ALIGN_LEFT, false));

newSpaceTask_ = Promise<SpaceResult *>::Spawn(&g_threadManager, [&]() -> SpaceResult * {
int64_t freeSpaceNew;
free_disk_space(newMemstickFolder_, freeSpaceNew);
return new SpaceResult{ freeSpaceNew };
}, TaskType::IO_BLOCKING, TaskPriority::HIGH);

if (existingFilesInNewFolder_) {
leftColumn->Add(new NoticeView(NoticeLevel::SUCCESS, ms->T("Already contains PSP data"), ""));
if (!moveData_) {
Expand All @@ -511,11 +521,15 @@ void ConfirmMemstickMoveScreen::CreateViews() {
}

if (!oldMemstickFolder.empty()) {
std::string oldFreeSpaceText = std::string(ms->T("Free space")) + ": " + FormatSpaceString(freeSpaceOld);
oldSpaceTask_ = Promise<SpaceResult *>::Spawn(&g_threadManager, [&]() -> SpaceResult * {
int64_t freeSpaceOld;
free_disk_space(oldMemstickFolder, freeSpaceOld);
return new SpaceResult{ freeSpaceOld };
}, TaskType::IO_BLOCKING, TaskPriority::HIGH);

rightColumn->Add(new TextView(std::string(ms->T("Current")) + ":", ALIGN_LEFT, false));
rightColumn->Add(new TextView(oldMemstickFolder.ToVisualString(), ALIGN_LEFT, false));
rightColumn->Add(new TextView(oldFreeSpaceText, ALIGN_LEFT, false));
oldFreeSpaceView_ = rightColumn->Add(new TextView(ms->T("Free space"), ALIGN_LEFT, false));
}

if (moveDataTask_) {
Expand Down Expand Up @@ -567,6 +581,23 @@ void ConfirmMemstickMoveScreen::update() {
moveDataTask_ = nullptr;
}
}

if (newSpaceTask_ && newFreeSpaceView_) {
SpaceResult *result = newSpaceTask_->Poll();
if (result) {
newFreeSpaceView_->SetText(std::string(ms->T("Free space")) + ": " + FormatSpaceString(result->bytesFree));
delete newSpaceTask_;
newSpaceTask_ = nullptr;
}
}
if (oldSpaceTask_ && oldFreeSpaceView_) {
SpaceResult *result = oldSpaceTask_->Poll();
if (result) {
oldFreeSpaceView_->SetText(std::string(ms->T("Free space")) + ": " + FormatSpaceString(result->bytesFree));
delete oldSpaceTask_;
oldSpaceTask_ = nullptr;
}
}
}

UI::EventReturn ConfirmMemstickMoveScreen::OnConfirm(UI::EventParams &params) {
Expand Down
8 changes: 8 additions & 0 deletions UI/MemStickScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ class MemStickScreen : public UIDialogScreenWithBackground {
#endif
};

struct SpaceResult {
int64_t bytesFree;
};

class ConfirmMemstickMoveScreen : public UIDialogScreenWithBackground {
public:
ConfirmMemstickMoveScreen(const Path &newMemstickFolder, bool initialSetup);
Expand Down Expand Up @@ -121,8 +125,12 @@ class ConfirmMemstickMoveScreen : public UIDialogScreenWithBackground {

MoveProgressReporter progressReporter_;
UI::TextView *progressView_ = nullptr;
UI::TextView *newFreeSpaceView_ = nullptr;
UI::TextView *oldFreeSpaceView_ = nullptr;

Promise<MoveResult *> *moveDataTask_ = nullptr;
Promise<SpaceResult *> *oldSpaceTask_ = nullptr;
Promise<SpaceResult *> *newSpaceTask_ = nullptr;

std::string error_;
};
3 changes: 1 addition & 2 deletions UI/NativeApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -729,8 +729,7 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
}
#endif

// TODO: Load these in the background instead of synchronously.
g_BackgroundAudio.SFX().LoadSamples();
g_BackgroundAudio.SFX().Init();

if (!boot_filename.empty() && stateToLoad.Valid()) {
SaveState::Load(stateToLoad, -1, [](SaveState::Status status, std::string_view message, void *) {
Expand Down
9 changes: 4 additions & 5 deletions android/src/org/ppsspp/ppsspp/TextRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static void init(Context ctx) {

private static Point measureLine(String string, double textSize) {
int w;
if (string.length() > 0) {
if (!string.isEmpty()) {
textPaint.setTextSize((float) textSize);
w = (int) textPaint.measureText(string);
// Round width up to even already here to avoid annoyances from odd-width 16-bit textures
Expand All @@ -55,7 +55,7 @@ private static Point measureLine(String string, double textSize) {
}

private static Point measure(String string, double textSize) {
String lines[] = string.replaceAll("\\r", "").split("\n");
String [] lines = string.replaceAll("\\r", "").split("\n");
Point total = new Point();
total.x = 0;
for (String line : lines) {
Expand Down Expand Up @@ -95,10 +95,9 @@ public static int[] renderText(String string, double textSize) {
String lines[] = string.replaceAll("\\r", "").split("\n");
float y = 1.0f;

Path path = new Path();

Path path = null;
for (String line : lines) {
if (line.length() > 0) {
if (!line.isEmpty()) {
if (highContrastFontsEnabled) {
// This is a workaround for avoiding "High Contrast Fonts" screwing up our
// single-channel font rendering.
Expand Down
Loading