mirror of
https://github.com/wiiu-env/wut.git
synced 2025-01-05 21:18:15 +01:00
Improve the helloworld sample.
This commit is contained in:
parent
4a32445ed5
commit
cdc540938a
@ -4,6 +4,8 @@ include("${WUT_ROOT}/share/wut.cmake" REQUIRED)
|
||||
|
||||
add_executable(helloworld main.cpp)
|
||||
target_link_libraries(helloworld
|
||||
whb
|
||||
defaultheap
|
||||
coreinit
|
||||
proc_ui
|
||||
sysapp)
|
||||
|
@ -1,89 +1,35 @@
|
||||
#include <coreinit/core.h>
|
||||
#include <coreinit/debug.h>
|
||||
#include <coreinit/thread.h>
|
||||
#include <coreinit/foreground.h>
|
||||
#include <proc_ui/procui.h>
|
||||
#include <sysapp/launch.h>
|
||||
#include <string>
|
||||
#include <coreinit/time.h>
|
||||
#include <coreinit/systeminfo.h>
|
||||
|
||||
bool isAppRunning = true;
|
||||
std::string testStr = "Initial Value";
|
||||
|
||||
static void
|
||||
SaveCallback()
|
||||
{
|
||||
OSSavesDone_ReadyToRelease(); // Required
|
||||
}
|
||||
|
||||
static bool
|
||||
AppRunning()
|
||||
{
|
||||
if (!OSIsMainCore()) {
|
||||
ProcUISubProcessMessages(true);
|
||||
} else {
|
||||
ProcUIStatus status = ProcUIProcessMessages(true);
|
||||
|
||||
if (status == PROCUI_STATUS_EXITING) {
|
||||
// Being closed, deinit, free, and prepare to exit
|
||||
testStr = "PROCUI_STATUS_EXITING";
|
||||
isAppRunning = false;
|
||||
ProcUIShutdown();
|
||||
} else if (status == PROCUI_STATUS_RELEASE_FOREGROUND) {
|
||||
// Free up MEM1 to next foreground app, deinit screen, etc.
|
||||
testStr = "PROCUI_STATUS_RELEASE_FOREGROUND";
|
||||
ProcUIDrawDoneRelease();
|
||||
} else if(status == PROCUI_STATUS_IN_FOREGROUND) {
|
||||
// Executed while app is in foreground
|
||||
testStr = "PROCUI_STATUS_IN_FOREGROUND";
|
||||
}
|
||||
}
|
||||
|
||||
return isAppRunning;
|
||||
}
|
||||
|
||||
static int
|
||||
CoreEntryPoint(int argc, const char **argv)
|
||||
{
|
||||
OSReport("Hello world from %s %s", argv[0], testStr.c_str());
|
||||
return argc;
|
||||
}
|
||||
#include <whb/proc.h>
|
||||
#include <whb/log.h>
|
||||
#include <whb/log_console.h>
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
ProcUIInit(&SaveCallback);
|
||||
OSReport("Main thread running on core %d", OSGetCoreId());
|
||||
OSCalendarTime tm;
|
||||
|
||||
// Run thread on core 0
|
||||
OSThread *threadCore0 = OSGetDefaultThread(0);
|
||||
WHBProcInit();
|
||||
WHBLogConsoleInit();
|
||||
WHBLogPrintf("Hello World!");
|
||||
|
||||
const char *core0Args[] = {
|
||||
"Core 0"
|
||||
};
|
||||
while(WHBProcIsRunning()) {
|
||||
OSTicksToCalendarTime(OSGetTime(), &tm);
|
||||
WHBLogPrintf("%02d/%02d/%04d %02d:%02d:%02d I'm still here.",
|
||||
tm.tm_mday, tm.tm_mon, tm.tm_year,
|
||||
tm.tm_hour, tm.tm_min, tm.tm_sec);
|
||||
|
||||
OSRunThread(threadCore0, CoreEntryPoint, 0, core0Args);
|
||||
WHBLogConsoleDraw();
|
||||
OSSleepTicks(OSMilliseconds(1000));
|
||||
}
|
||||
|
||||
// Run thread on core 2
|
||||
OSThread *threadCore2 = OSGetDefaultThread(2);
|
||||
WHBLogPrintf("Exiting... good bye.");
|
||||
WHBLogConsoleDraw();
|
||||
OSSleepTicks(OSMilliseconds(1000));
|
||||
|
||||
const char *core2Args[] = {
|
||||
"Core 2"
|
||||
};
|
||||
|
||||
OSRunThread(threadCore2, CoreEntryPoint, 2, core2Args);
|
||||
|
||||
// Wait for threads to return
|
||||
int resultCore0 = -1, resultCore2 = -1;
|
||||
OSJoinThread(threadCore0, &resultCore0);
|
||||
OSJoinThread(threadCore2, &resultCore2);
|
||||
|
||||
OSReport("Core 0 thread returned %d", resultCore0);
|
||||
OSReport("Core 2 thread returned %d", resultCore2);
|
||||
|
||||
// Sends messages for ProcUI to release foreground, exit
|
||||
// and launch into the system menu immediately.
|
||||
SYSLaunchMenu();
|
||||
|
||||
while(AppRunning());
|
||||
WHBLogConsoleFree();
|
||||
WHBProcShutdown();
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user