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

Headless: Use more consistent logic to find assets #17105

Merged
merged 2 commits into from
Mar 13, 2023
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 GPU/Common/ReplacedTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.

#include <algorithm>
#include "ppsspp_config.h"

#include <png.h>
Expand Down
31 changes: 20 additions & 11 deletions headless/Headless.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,21 +474,27 @@ int main(int argc, const char* argv[])
InitSysDirectories();
#endif

Path executablePath = File::GetExeDirectory();
#if !PPSSPP_PLATFORM(ANDROID) && !PPSSPP_PLATFORM(WINDOWS)
g_Config.memStickDirectory = Path(std::string(getenv("HOME"))) / ".ppsspp";
g_Config.flash0Directory = File::GetExeDirectory() / "assets/flash0";
g_Config.flash0Directory = executablePath / "assets/flash0";
#endif

// Try to find the flash0 directory. Often this is from a subdirectory.
for (int i = 0; i < 4 && !File::Exists(g_Config.flash0Directory); ++i) {
if (File::Exists(g_Config.flash0Directory / ".." / "assets/flash0"))
g_Config.flash0Directory = g_Config.flash0Directory / ".." / "assets/flash0";
else
g_Config.flash0Directory = g_Config.flash0Directory / ".." / ".." / "flash0";
Path nextPath = executablePath;
for (int i = 0; i < 5; ++i) {
if (File::Exists(nextPath / "assets/flash0")) {
g_Config.flash0Directory = nextPath / "assets/flash0";
#if !PPSSPP_PLATFORM(ANDROID)
g_VFS.Register("", new DirectoryReader(nextPath / "assets"));
#endif
break;
}

if (!nextPath.CanNavigateUp())
break;
nextPath = nextPath.NavigateUp();
}
// Or else, maybe in the executable's dir.
if (!File::Exists(g_Config.flash0Directory))
g_Config.flash0Directory = File::GetExeDirectory() / "assets/flash0";

if (screenshotFilename)
headlessHost->SetComparisonScreenshot(Path(std::string(screenshotFilename)), testOptions.maxScreenshotError);
Expand All @@ -502,8 +508,11 @@ int main(int argc, const char* argv[])
if (File::Exists(Path("/data/app/org.ppsspp.ppsspp.apk"))) {
g_VFS.Register("", ZipFileReader::Create(Path("/data/app/org.ppsspp.ppsspp.apk"), "assets/"));
}
#elif !PPSSPP_PLATFORM(WINDOWS)
g_VFS.Register("", new DirectoryReader(g_Config.flash0Directory / ".."));
#elif PPSSPP_PLATFORM(LINUX)
g_VFS.Register("", new DirectoryReader(Path("/usr/local/share/ppsspp/assets")));
g_VFS.Register("", new DirectoryReader(Path("/usr/local/share/games/ppsspp/assets")));
g_VFS.Register("", new DirectoryReader(Path("/usr/share/ppsspp/assets")));
g_VFS.Register("", new DirectoryReader(Path("/usr/share/games/ppsspp/assets")));
#endif

UpdateUIState(UISTATE_INGAME);
Expand Down
8 changes: 0 additions & 8 deletions headless/SDLHeadlessHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,6 @@ class GLDummyGraphicsContext : public GraphicsContext {
SDL_GLContext glContext_;
};

void SDLHeadlessHost::LoadNativeAssets() {
g_VFS.Register("", new DirectoryReader(Path("assets")));
g_VFS.Register("", new DirectoryReader(Path("")));
g_VFS.Register("", new DirectoryReader(Path("..")));
}

bool GLDummyGraphicsContext::InitFromRenderThread(std::string *errorMessage) {
SDL_Init(SDL_INIT_VIDEO);

Expand Down Expand Up @@ -203,8 +197,6 @@ bool SDLHeadlessHost::InitGraphics(std::string *error_message, GraphicsContext *
});
th.detach();

LoadNativeAssets();

threadState_ = RenderThreadState::START_REQUESTED;
while (threadState_ == RenderThreadState::START_REQUESTED || threadState_ == RenderThreadState::STARTING)
sleep_ms(1);
Expand Down
2 changes: 0 additions & 2 deletions headless/SDLHeadlessHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ class SDLHeadlessHost : public HeadlessHost
void SwapBuffers() override;

protected:
void LoadNativeAssets();

enum class RenderThreadState {
IDLE,
START_REQUESTED,
Expand Down
12 changes: 0 additions & 12 deletions headless/WindowsHeadlessHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,6 @@ HWND CreateHiddenWindow() {
return CreateWindowEx(0, L"PPSSPPHeadless", L"PPSSPPHeadless", style, CW_USEDEFAULT, CW_USEDEFAULT, WINDOW_WIDTH, WINDOW_HEIGHT, NULL, NULL, NULL, NULL);
}

void WindowsHeadlessHost::LoadNativeAssets()
{
g_VFS.Register("", new DirectoryReader(Path("assets")));
g_VFS.Register("", new DirectoryReader(Path("")));
g_VFS.Register("", new DirectoryReader(Path("..")));
g_VFS.Register("", new DirectoryReader(Path("../assets")));
g_VFS.Register("", new DirectoryReader(Path("../Windows/assets")));
g_VFS.Register("", new DirectoryReader(Path("../Windows")));
}

void WindowsHeadlessHost::SendDebugOutput(const std::string &output)
{
fwrite(output.data(), sizeof(char), output.length(), stdout);
Expand Down Expand Up @@ -152,8 +142,6 @@ bool WindowsHeadlessHost::InitGraphics(std::string *error_message, GraphicsConte
th.detach();
}

LoadNativeAssets();

if (needRenderThread) {
threadState_ = RenderThreadState::START_REQUESTED;
while (threadState_ == RenderThreadState::START_REQUESTED || threadState_ == RenderThreadState::STARTING)
Expand Down
2 changes: 0 additions & 2 deletions headless/WindowsHeadlessHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ class WindowsHeadlessHost : public HeadlessHost
void SendDebugOutput(const std::string &output) override;

protected:
void LoadNativeAssets();

enum class RenderThreadState {
IDLE,
START_REQUESTED,
Expand Down