From ade0f4103b3fd5b7829fd2103a88fa9d8579d663 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 29 Dec 2012 20:49:45 -0800 Subject: [PATCH] Don't let native's log output spoil tests. Also, log to stderr, makes more sense anyway. --- Core/HLE/sceIo.cpp | 7 +++---- Core/Host.h | 3 +++ headless/Headless.cpp | 18 +++++++----------- headless/StubHost.h | 2 ++ headless/WindowsHeadlessHost.cpp | 31 +++++++++++++++++++++++++++++-- headless/WindowsHeadlessHost.h | 4 ++++ 6 files changed, 48 insertions(+), 17 deletions(-) diff --git a/Core/HLE/sceIo.cpp b/Core/HLE/sceIo.cpp index c3b1386894..ef817f557c 100644 --- a/Core/HLE/sceIo.cpp +++ b/Core/HLE/sceIo.cpp @@ -22,6 +22,7 @@ #include "../System.h" #include "../Config.h" +#include "../Host.h" #include "../SaveState.h" #include "HLE.h" #include "../MIPS/MIPS.h" @@ -644,10 +645,8 @@ u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 outPtr, std::string data(Memory::GetCharPointer(argAddr), argLen); if (PSP_CoreParameter().printfEmuLog) { - printf("%s", data.c_str()); -#ifdef _WIN32 - OutputDebugString(data.c_str()); -#endif + host->SendDebugOutput(data.c_str()); + // Also collect the debug output emuDebugOutput += data; } diff --git a/Core/Host.h b/Core/Host.h index 5600e01393..056395184c 100644 --- a/Core/Host.h +++ b/Core/Host.h @@ -60,6 +60,9 @@ public: virtual bool IsDebuggingEnabled() {return true;} virtual bool AttemptLoadSymbolMap() {return false;} virtual void SetWindowTitle(const char *message) {} + + // Used for headless. + virtual void SendDebugOutput(const std::string &output) {} }; extern Host *host; diff --git a/headless/Headless.cpp b/headless/Headless.cpp index aaeb2ae7d9..b4d0880b85 100644 --- a/headless/Headless.cpp +++ b/headless/Headless.cpp @@ -12,8 +12,6 @@ #include "../Core/Host.h" #include "Log.h" #include "LogManager.h" -#include "file/vfs.h" -#include "file/zip_read.h" #include "StubHost.h" #ifdef _WIN32 @@ -28,20 +26,20 @@ public: switch (level) { case LogTypes::LDEBUG: - printf("D %s", msg); + fprintf(stderr, "D %s", msg); break; case LogTypes::LINFO: - printf("I %s", msg); + fprintf(stderr, "I %s", msg); break; case LogTypes::LERROR: - printf("E %s", msg); + fprintf(stderr, "E %s", msg); break; case LogTypes::LWARNING: - printf("W %s", msg); + fprintf(stderr, "W %s", msg); break; case LogTypes::LNOTICE: default: - printf("N %s", msg); + fprintf(stderr, "N %s", msg); break; } } @@ -118,9 +116,6 @@ int main(int argc, const char* argv[]) return 1; } - VFSRegister("", new DirectoryAssetReader("assets/")); - VFSRegister("", new DirectoryAssetReader("")); - HeadlessHost *headlessHost = new HEADLESSHOST_CLASS(); host = headlessHost; host->InitGL(); @@ -160,8 +155,9 @@ int main(int argc, const char* argv[]) return 1; } - coreState = CORE_RUNNING; + host->BootDone(); + coreState = CORE_RUNNING; while (coreState == CORE_RUNNING) { // Run for a frame at a time, just because. diff --git a/headless/StubHost.h b/headless/StubHost.h index 5c9e4364fb..9445aee06c 100644 --- a/headless/StubHost.h +++ b/headless/StubHost.h @@ -49,5 +49,7 @@ public: virtual bool IsDebuggingEnabled() {return false;} virtual bool AttemptLoadSymbolMap() {return false;} + virtual void SendDebugOutput(const std::string &output) { printf("%s", output.c_str()); } + virtual bool isGLWorking() { return false; } }; \ No newline at end of file diff --git a/headless/WindowsHeadlessHost.cpp b/headless/WindowsHeadlessHost.cpp index ce7086d41d..dd473a8279 100644 --- a/headless/WindowsHeadlessHost.cpp +++ b/headless/WindowsHeadlessHost.cpp @@ -19,9 +19,13 @@ #include #include +#include -#include "../native/gfx_es2/gl_state.h" -#include "../native/gfx/gl_common.h" +#include "gfx_es2/gl_state.h" +#include "gfx/gl_common.h" +#include "gfx/gl_lost_manager.h" +#include "file/vfs.h" +#include "file/zip_read.h" const bool WINDOW_VISIBLE = false; const int WINDOW_WIDTH = 480; @@ -64,6 +68,27 @@ void SetVSync(int value) wglSwapIntervalEXT(value); } +void WindowsHeadlessHost::LoadNativeAssets() +{ + // Native is kinda talkative, but that's annoying in our case. + out = _fdopen(_dup(_fileno(stdout)), "wt"); + freopen("NUL", "wt", stdout); + + VFSRegister("", new DirectoryAssetReader("assets/")); + VFSRegister("", new DirectoryAssetReader("")); + VFSRegister("", new DirectoryAssetReader("../")); + + gl_lost_manager_init(); + + // See SendDebugOutput() for how things get back on track. +} + +void WindowsHeadlessHost::SendDebugOutput(const std::string &output) +{ + fprintf_s(out, "%s", output.c_str()); + OutputDebugString(output.c_str()); +} + void WindowsHeadlessHost::InitGL() { glOkay = false; @@ -99,6 +124,8 @@ void WindowsHeadlessHost::InitGL() glewInit(); glstate.Initialize(); + LoadNativeAssets(); + if (ResizeGL()) glOkay = true; } diff --git a/headless/WindowsHeadlessHost.h b/headless/WindowsHeadlessHost.h index 2dc2b5b0b4..28e51ee543 100644 --- a/headless/WindowsHeadlessHost.h +++ b/headless/WindowsHeadlessHost.h @@ -34,11 +34,15 @@ public: virtual void ShutdownGL(); virtual bool isGLWorking() { return glOkay; } + virtual void SendDebugOutput(const std::string &output); + private: bool ResizeGL(); + void LoadNativeAssets(); bool glOkay; HWND hWnd; HDC hDC; HGLRC hRC; + FILE *out; }; \ No newline at end of file