Skip to content

Commit

Permalink
Change approach (call from NativeFrame instead). Add Mac support
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Jan 18, 2024
1 parent d45f95e commit b899a17
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 18 deletions.
1 change: 1 addition & 0 deletions Common/System/System.h
Expand Up @@ -246,6 +246,7 @@ enum class UIMessage {
SAVESTATE_DISPLAY_SLOT,
GAMESETTINGS_SEARCH,
SAVEDATA_SEARCH,
RESTART_GRAPHICS,
};

std::string System_GetProperty(SystemProperty prop);
Expand Down
15 changes: 0 additions & 15 deletions Core/Core.cpp
Expand Up @@ -61,7 +61,6 @@ static std::set<CoreLifecycleFunc> lifecycleFuncs;
static std::set<CoreStopRequestFunc> stopFuncs;
static bool windowHidden = false;
static bool powerSaving = false;
static bool g_restartGraphics = false;

static MIPSExceptionInfo g_exceptionInfo;

Expand Down Expand Up @@ -212,27 +211,13 @@ void UpdateRunLoop(GraphicsContext *ctx) {
}
}

void Core_DebugRestartGraphics() {
g_restartGraphics = true;
}

// Note: not used on Android.
void Core_RunLoop(GraphicsContext *ctx) {
if (windowHidden && g_Config.bPauseWhenMinimized) {
sleep_ms(16);
return;
}

#if PPSSPP_PLATFORM(WINDOWS)
// This can only be accessed from Windows currently, and causes linking errors with headless etc.
if (g_restartGraphics) {
// Used for debugging only.
NativeShutdownGraphics();
NativeInitGraphics(ctx);
g_restartGraphics = false;
}
#endif

NativeFrame(ctx);
}

Expand Down
1 change: 0 additions & 1 deletion Core/Core.h
Expand Up @@ -44,7 +44,6 @@ bool Core_NextFrame();
void Core_DoSingleStep();
void Core_UpdateSingleStep();
void Core_ProcessStepping();
void Core_DebugRestartGraphics();

// Changes every time we enter stepping.
int Core_GetSteppingCounter();
Expand Down
9 changes: 9 additions & 0 deletions SDL/CocoaBarItems.mm
Expand Up @@ -405,6 +405,10 @@ -(NSMenu *)makeDebugMenu {
copyBaseAddr.target = self;
copyBaseAddr.tag = 11;

NSMenuItem *restartGraphicsAction = [[NSMenuItem alloc] initWithTitle:DESKTOPUI_LOCALIZED("Restart Graphics") action:@selector(restartGraphics) keyEquivalent:@""];
restartGraphicsAction.target = self;
restartGraphicsAction.tag = 12;

MENU_ITEM(showDebugStatsAction, DESKTOPUI_LOCALIZED("Show Debug Statistics"), @selector(toggleShowDebugStats:), ((DebugOverlay)g_Config.iDebugOverlay == DebugOverlay::DEBUG_STATS), 12)

[parent addItem:loadSymbolMapAction];
Expand All @@ -421,6 +425,7 @@ -(NSMenu *)makeDebugMenu {
[parent addItem:takeScreenshotAction];
[parent addItem:dumpNextFrameToLogAction];
[parent addItem:showDebugStatsAction];
[parent addItem:restartGraphicsAction];

[parent addItem:[NSMenuItem separatorItem]];
[parent addItem:copyBaseAddr];
Expand Down Expand Up @@ -462,6 +467,10 @@ -(void)copyAddr {
[NSPasteboard.generalPasteboard setString:stringToCopy forType:NSPasteboardTypeString];
}

-(void)restartGraphics {
System_PostUIMessage(UIMessage::RESTART_GRAPHICS);
}

-(NSURL *)presentOpenPanelWithAllowedFileTypes: (NSArray<NSString *> *)allowedFileTypes {
NSOpenPanel *openPanel = [[NSOpenPanel alloc] init];
openPanel.allowedFileTypes = allowedFileTypes;
Expand Down
13 changes: 12 additions & 1 deletion UI/NativeApp.cpp
Expand Up @@ -183,6 +183,7 @@ static Draw::DrawContext *g_draw;
static Draw::Pipeline *colorPipeline;
static Draw::Pipeline *texColorPipeline;
static UIContext *uiContext;
static bool g_restartGraphics;

#ifdef _WIN32
WindowsAudioBackend *winAudioBackend;
Expand Down Expand Up @@ -1035,6 +1036,14 @@ static void SendMouseDeltaAxis();
void NativeFrame(GraphicsContext *graphicsContext) {
PROFILE_END_FRAME();

// This can only be accessed from Windows currently, and causes linking errors with headless etc.
if (g_restartGraphics) {
// Used for debugging only.
NativeShutdownGraphics();
NativeInitGraphics(graphicsContext);
g_restartGraphics = false;
}

double startTime = time_now_d();

ProcessWheelRelease(NKCODE_EXT_MOUSEWHEEL_UP, startTime, false);
Expand Down Expand Up @@ -1173,7 +1182,9 @@ void NativeFrame(GraphicsContext *graphicsContext) {
}

bool HandleGlobalMessage(UIMessage message, const std::string &value) {
if (message == UIMessage::SAVESTATE_DISPLAY_SLOT) {
if (message == UIMessage::RESTART_GRAPHICS) {
g_restartGraphics = true;
} else if (message == UIMessage::SAVESTATE_DISPLAY_SLOT) {
auto sy = GetI18NCategory(I18NCat::SYSTEM);
std::string msg = StringFromFormat("%s: %d", sy->T("Savestate Slot"), SaveState::GetCurrentSlot() + 1);
// Show for the same duration as the preview.
Expand Down
2 changes: 1 addition & 1 deletion Windows/MainWindowMenu.cpp
Expand Up @@ -926,7 +926,7 @@ namespace MainWindow {
break;

case ID_DEBUG_RESTARTGRAPHICS:
Core_DebugRestartGraphics();
System_PostUIMessage(UIMessage::RESTART_GRAPHICS);
break;

case ID_FILE_DUMPFRAMES:
Expand Down

0 comments on commit b899a17

Please sign in to comment.