Files
ps4-switch-emu 9146a38f7c PS4 Switch Emu: build scripts, tools and docs
Builds the emulator core (submodule eden/) for jailbroken PS4 consoles and packages it as a .pkg.
DolphinPS4 (vendor/DolphinPS4) provides the PS4 runtime and the Vulkan driver patch.
2026-10-08 10:23:27 -07:00

76 lines
2.2 KiB
C++

/*
** Sample Framework for deko3d Applications
** CApplication.cpp: Wrapper class containing common application boilerplate
*/
#include "CApplication.h"
// PS4 Switch Emu test: when non-zero, run() returns after this many nanoseconds (set by main.cpp).
u64 g_run_limit_ns = 0;
CApplication::CApplication()
{
appletLockExit();
appletSetFocusHandlingMode(AppletFocusHandlingMode_NoSuspend);
}
CApplication::~CApplication()
{
appletSetFocusHandlingMode(AppletFocusHandlingMode_SuspendHomeSleep);
appletUnlockExit();
}
void CApplication::run()
{
u64 tick_ref = armGetSystemTick();
u64 tick_saved = tick_ref;
bool focused = appletGetFocusState() == AppletFocusState_InFocus;
onOperationMode(appletGetOperationMode());
for (;;)
{
u32 msg = 0;
Result rc = appletGetMessage(&msg);
if (R_SUCCEEDED(rc))
{
bool should_close = !appletProcessMessage(msg);
if (should_close)
return;
switch (msg)
{
case AppletMessage_FocusStateChanged:
{
bool old_focused = focused;
AppletFocusState state = appletGetFocusState();
focused = state == AppletFocusState_InFocus;
onFocusState(state);
if (focused == old_focused)
break;
if (focused)
{
appletSetFocusHandlingMode(AppletFocusHandlingMode_NoSuspend);
tick_ref += armGetSystemTick() - tick_saved;
}
else
{
tick_saved = armGetSystemTick();
appletSetFocusHandlingMode(AppletFocusHandlingMode_SuspendHomeSleepNotify);
}
break;
}
case AppletMessage_OperationModeChanged:
onOperationMode(appletGetOperationMode());
break;
}
}
const u64 ns = armTicksToNs(armGetSystemTick() - tick_ref);
if (focused && !onFrame(ns))
break;
if (g_run_limit_ns && ns >= g_run_limit_ns)
break;
}
}