Skip to content

Commit

Permalink
Merge pull request #17105 from unknownbrackets/headless-assets
Browse files Browse the repository at this point in the history
Headless: Use more consistent logic to find assets
  • Loading branch information
hrydgard authored Mar 13, 2023
2 parents caab66b + 9f04d09 commit dc4190e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 35 deletions.
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

0 comments on commit dc4190e

Please sign in to comment.