libgui 2.01
libgui is a GUI library for the GameCube, Wii, and Wii U
 
Loading...
Searching...
No Matches
WutPlatform.cpp
1/****************************************************************************
2 * Platform Abstraction Layer (WUT driver)
3 * Daryl Borth 2026
4 * WutPlatform.cpp
5 ***************************************************************************/
6#include <stdlib.h>
7
8#include "WutPlatform.h"
9
10#include <sysapp/launch.h>
11#include <proc_ui/procui.h>
12#include <unistd.h>
13
15{
16 this->config = config;
17
18 WHBProcInit();
19
20 this->threadDriver = new WutThreadDriver();
21 this->threadDriver->init();
22
23 this->videoDriver = new WutVideoDriver();
24 this->videoDriver->init(config.canvasWidth, config.canvasHeight);
25
26 this->audioDriver = new WutAudioDriver();
27 this->audioDriver->init();
28
29 this->inputDriver = new WutInputDriver();
30 this->inputDriver->init();
31
32 this->fileSystemDriver = new WutFileSystemDriver();
33 this->fileSystemDriver->init();
34
35#if LOGGING_ENABLED
36 this->logger = new Logger();
37 this->logger->registerBackend(LOGGER_OSREPORT, new WutLoggerOSReport());
38 this->logger->registerBackend(LOGGER_UDP, new WutLoggerUdp());
39 this->logger->registerBackend(LOGGER_SERIAL, new WutLoggerUsbSerial());
40 this->logger->registerBackend(LOGGER_FILE, new LoggerFile());
41
42 LogConfig logConfig;
43 static const int deviceCandidates[] = { DEVICE_SD };
44
45 const char * mountPath = FindFirstMountedPath(this->fileSystemDriver, deviceCandidates, 1);
46
47 if(mountPath[0] != '\0') {
48 // mountPath already ends in "/" (eg. "/vol/external01/") - no separator needed.
49 snprintf(logConfig.filePath, sizeof(logConfig.filePath), "%sdebug.log", mountPath);
50 }
51 this->logger->init(logConfig);
52#endif
53}
54
56{
57 if (logger) {
58 logger->shutdown();
59 delete logger;
60 logger = nullptr;
61 }
62
63 if(fileSystemDriver)
64 {
65 fileSystemDriver->shutdown();
66 delete fileSystemDriver;
67 fileSystemDriver = nullptr;
68 }
69
70 if(inputDriver)
71 {
72 inputDriver->shutdown();
73 delete inputDriver;
74 inputDriver = nullptr;
75 }
76
77 if(audioDriver)
78 {
79 audioDriver->shutdown();
80 delete audioDriver;
81 audioDriver = nullptr;
82 }
83
84 if(videoDriver)
85 {
86 videoDriver->shutdown();
87 delete videoDriver;
88 videoDriver = nullptr;
89 }
90
91 if(threadDriver)
92 {
93 threadDriver->shutdown();
94 delete threadDriver;
95 threadDriver = nullptr;
96 }
97}
98
99// Either WHBProcIsRunning() returned false already and we're leaving
100// because the OS requested it (eg: Close button was used in the Wii U
101// menu), or the user explicitly exited from within the app - in which
102// case we're still in the foreground and need to tell Cafe OS we're
103// ready to shut down.
105{
106 // If the exit was user-initiated, Cafe OS has not been notified yet.
107 // SYSLaunchMenu() tells Cafe OS to switch back to the system menu or loader.
108 if(ProcUIIsRunning()) {
109 SYSLaunchMenu();
110
111 // On real hardware this resolves within a frame or two. Cemu doesn't
112 // implement SYSLaunchMenu(), so ProcUI never leaves the foreground and
113 // this would spin forever - cap the wait so we can still exit cleanly there.
114 const int timeoutMs = 2000;
115 for (int waited = 0; WHBProcIsRunning() && waited < timeoutMs; waited++) {
116 usleep(1000);
117 }
118 }
119 this->shutdown();
120 WHBProcShutdown();
121 exit(0);
122}
123
127{
128 // Once latched in Exiting, always return ShutdownRequested
129 if (status == Status::Exiting)
131
132 // WHBProcIsRunning() pumps the ProcUI message queue - only call this once per frame
133 if (!WHBProcIsRunning())
134 {
135 status = Status::Exiting;
137 }
138
139 // Fast in-memory check for focus/foreground state
140 if (!ProcUIInForeground())
141 {
142 status = Status::Paused;
143 }
144 else
145 {
146 status = Status::Running;
147 }
148
149 return SystemEvent::None;
150}
Log backend that appends to a file through the platform's devoptab path.
Definition LoggerFile.h:26
Central fan-out dispatcher.
Definition Logger.h:191
PlatformConfig config
Set by init() in every concrete Platform - store the passed-in config as the very first line of the o...
Definition Platform.h:117
Wii U AudioDriver: AX (sndcore2), 16 fixed AXVoice slots for one-shots plus a dedicated stereo stream...
SD: a plain WHBMountSdCard() FSA mount, done once in init().
Wii U InputDriver: VPAD for the GamePad (stick, buttons, and touch, channel 0 only) plus KPAD/WPAD fo...
Log backend writing to the console debug output via OSReport.
Non-blocking UDP log backend over nsysnet sockets.
Log backend writing to a USB serial adapter (requires the optional usbserial module).
SystemEvent getSystemEvent() override
Polls Cafe OS process events.
void shutdown() override
Shuts down and releases all five drivers.
void requestExit() override
Tears down the platform (via shutdown()) and then performs whatever platform-appropriate action actua...
void init(const PlatformConfig &config) override
Constructs and initializes all five drivers for this platform.
Wii U ThreadDriver, built on coreinit's OSThread/OSMutex/OSCondition.
Wii U VideoDriver: GX2 + libwhb's WHBGfx* helpers.
SystemEvent
A hardware/OS-level system event a Platform can report.
Definition Platform.h:37
@ ShutdownRequested
Power button pressed (console or, on Wii, a Wiimote) - or, on Wii U, the OS asking the app to exit.
Definition Platform.h:41
Full runtime configuration for the Logger.
Definition Logger.h:101
char filePath[1024]
Path of the log file for the file backend. Each platform's init() points this at debug....
Definition Logger.h:134
Settings passed to Platform::init().
Definition Platform.h:50