2022-11-11 12:02:22 +01:00
|
|
|
#include "MainApplicationState.h"
|
|
|
|
#include "input/CombinedInput.h"
|
|
|
|
#include "input/VPADInput.h"
|
|
|
|
#include "input/WPADInput.h"
|
|
|
|
#include "utils/DownloadUtils.h"
|
|
|
|
#include "utils/DrawUtils.h"
|
|
|
|
#include "utils/logger.h"
|
|
|
|
#include <coreinit/energysaver.h>
|
|
|
|
#include <filesystem>
|
2023-01-19 13:05:56 +01:00
|
|
|
#include <mocha/mocha.h>
|
2022-11-11 12:02:22 +01:00
|
|
|
#include <sndcore2/core.h>
|
|
|
|
#include <whb/proc.h>
|
|
|
|
|
|
|
|
void main_loop() {
|
|
|
|
DEBUG_FUNCTION_LINE_VERBOSE("Creating state");
|
|
|
|
std::unique_ptr<MainApplicationState> state = std::make_unique<MainApplicationState>();
|
|
|
|
CombinedInput baseInput;
|
|
|
|
VPadInput vpadInput;
|
|
|
|
WPADInput wpadInputs[4] = {
|
|
|
|
WPAD_CHAN_0,
|
|
|
|
WPAD_CHAN_1,
|
|
|
|
WPAD_CHAN_2,
|
|
|
|
WPAD_CHAN_3};
|
|
|
|
|
|
|
|
DEBUG_FUNCTION_LINE_VERBOSE("Entering main loop");
|
|
|
|
while (WHBProcIsRunning()) {
|
|
|
|
baseInput.reset();
|
|
|
|
if (vpadInput.update(1280, 720)) {
|
|
|
|
baseInput.combine(vpadInput);
|
|
|
|
}
|
|
|
|
for (auto &wpadInput : wpadInputs) {
|
|
|
|
if (wpadInput.update(1280, 720)) {
|
|
|
|
baseInput.combine(wpadInput);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
baseInput.process();
|
|
|
|
state->update(&baseInput);
|
|
|
|
state->render();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
initLogging();
|
|
|
|
|
|
|
|
WHBProcInit();
|
|
|
|
if (!DrawUtils::Init()) {
|
|
|
|
OSFatal("Failed to init DrawUtils");
|
|
|
|
}
|
|
|
|
AXInit();
|
|
|
|
WPADInput::init();
|
|
|
|
|
|
|
|
if (!DownloadUtils::Init()) {
|
|
|
|
DEBUG_FUNCTION_LINE_ERR("Failed to init DownloadUtils");
|
|
|
|
OSFatal("Failed to init DownloadUtils");
|
|
|
|
}
|
|
|
|
|
2023-01-19 13:05:56 +01:00
|
|
|
int mochaInitResult;
|
|
|
|
if ((mochaInitResult = Mocha_InitLibrary()) != MOCHA_RESULT_SUCCESS) {
|
|
|
|
DEBUG_FUNCTION_LINE_ERR("Mocha_InitLibrary() failed %d", mochaInitResult);
|
|
|
|
}
|
|
|
|
|
2022-11-11 12:02:22 +01:00
|
|
|
uint32_t isAPDEnabled;
|
|
|
|
IMIsAPDEnabled(&isAPDEnabled);
|
|
|
|
|
|
|
|
if (isAPDEnabled) {
|
|
|
|
DEBUG_FUNCTION_LINE_VERBOSE("Disable auto shutdown");
|
|
|
|
IMDisableAPD();
|
|
|
|
}
|
|
|
|
|
|
|
|
main_loop();
|
|
|
|
|
|
|
|
if (isAPDEnabled) {
|
|
|
|
DEBUG_FUNCTION_LINE_VERBOSE("Enable auto shutdown");
|
|
|
|
IMEnableAPD();
|
|
|
|
}
|
|
|
|
|
2023-01-19 13:05:56 +01:00
|
|
|
if (mochaInitResult == MOCHA_RESULT_SUCCESS) {
|
|
|
|
Mocha_DeInitLibrary();
|
|
|
|
}
|
|
|
|
|
2022-11-11 12:02:22 +01:00
|
|
|
DownloadUtils::Deinit();
|
|
|
|
|
|
|
|
WPADInput::close();
|
|
|
|
|
|
|
|
DrawUtils::DeInit();
|
|
|
|
|
|
|
|
AXQuit();
|
|
|
|
deinitLogging();
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|