mirror of
https://github.com/LNH-team/pico-launcher.git
synced 2026-06-02 09:06:54 +02:00
Initial commit
This commit is contained in:
10
arm9/source/services/process/IProcess.h
Normal file
10
arm9/source/services/process/IProcess.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
class IProcess
|
||||
{
|
||||
public:
|
||||
virtual ~IProcess() { }
|
||||
|
||||
virtual void Run() = 0;
|
||||
virtual void Exit() = 0;
|
||||
};
|
||||
11
arm9/source/services/process/ProcessFactory.h
Normal file
11
arm9/source/services/process/ProcessFactory.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
#include <memory>
|
||||
#include "IProcess.h"
|
||||
|
||||
class ProcessFactory
|
||||
{
|
||||
ProcessFactory() { }
|
||||
public:
|
||||
template <class T>
|
||||
static std::unique_ptr<IProcess> Construct();
|
||||
};
|
||||
37
arm9/source/services/process/ProcessFactory.thumb.cpp
Normal file
37
arm9/source/services/process/ProcessFactory.thumb.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "common.h"
|
||||
#include "core/di.h"
|
||||
#include "services/settings/JsonAppSettingsService.h"
|
||||
#include "bgm/AudioStreamPlayer.h"
|
||||
#include "bgm/IBgmService.h"
|
||||
#include "bgm/BgmService.h"
|
||||
#include "App.h"
|
||||
#include "PicoLoaderProcess.h"
|
||||
#include "ProcessFactory.h"
|
||||
|
||||
namespace di = boost::di;
|
||||
|
||||
class injected_and_bound : public di::config
|
||||
{
|
||||
public:
|
||||
static auto policies(...) noexcept
|
||||
{
|
||||
using namespace di::policies;
|
||||
using namespace di::policies::operators;
|
||||
return di::make_policies(
|
||||
constructible(is_bound<di::_>{})
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
static auto diConfig = [] { return di::make_injector<injected_and_bound>(
|
||||
di::bind<RandomGenerator>().to((RandomGenerator&)*gRandomGenerator),
|
||||
di::bind<IAudioStreamPlayer>().to<AudioStreamPlayer>(),
|
||||
di::bind<IBgmService>().in(di::singleton).to<BgmService>(),
|
||||
di::bind<>().to((const char*)"/_pico/settings.json"),
|
||||
di::bind<IAppSettingsService>().in(di::singleton).to<JsonAppSettingsService>()
|
||||
); };
|
||||
|
||||
#define REGISTER_PROCESS(name) template <> std::unique_ptr<IProcess> ProcessFactory::Construct<name>() { return diConfig().create<std::unique_ptr<name>>(); }
|
||||
|
||||
REGISTER_PROCESS(App);
|
||||
REGISTER_PROCESS(PicoLoaderProcess);
|
||||
26
arm9/source/services/process/ProcessManager.cpp
Normal file
26
arm9/source/services/process/ProcessManager.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "common.h"
|
||||
#include <libtwl/rtos/rtosIrq.h>
|
||||
#include "ProcessManager.h"
|
||||
|
||||
static void vblankIrq(u32 irqMask)
|
||||
{
|
||||
VBlank::NotifyIrq();
|
||||
}
|
||||
|
||||
void ProcessManager::MainLoop()
|
||||
{
|
||||
SetupDefaultVBlankHandler();
|
||||
while (_nextProcConstructFunc)
|
||||
{
|
||||
_curProcess = _nextProcConstructFunc();
|
||||
_curProcess->Run();
|
||||
SetupDefaultVBlankHandler(); // reset because the currently registered one may use _curProcess
|
||||
_curProcess.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessManager::SetupDefaultVBlankHandler()
|
||||
{
|
||||
rtos_setIrqFunc(RTOS_IRQ_VBLANK, vblankIrq);
|
||||
rtos_enableIrqMask(RTOS_IRQ_VBLANK);
|
||||
}
|
||||
28
arm9/source/services/process/ProcessManager.h
Normal file
28
arm9/source/services/process/ProcessManager.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
#include <memory>
|
||||
#include "IProcess.h"
|
||||
#include "ProcessFactory.h"
|
||||
|
||||
class ProcessManager
|
||||
{
|
||||
std::unique_ptr<IProcess> (*_nextProcConstructFunc)();
|
||||
std::unique_ptr<IProcess> _curProcess;
|
||||
|
||||
public:
|
||||
constexpr ProcessManager()
|
||||
: _nextProcConstructFunc(nullptr) { }
|
||||
|
||||
void MainLoop();
|
||||
void SetupDefaultVBlankHandler();
|
||||
|
||||
template <class T>
|
||||
[[gnu::noinline]]
|
||||
void Goto()
|
||||
{
|
||||
_nextProcConstructFunc = ProcessFactory::Construct<T>;
|
||||
if (_curProcess)
|
||||
_curProcess->Exit();
|
||||
}
|
||||
|
||||
IProcess* GetRunningProcess() { return _curProcess.get(); }
|
||||
};
|
||||
Reference in New Issue
Block a user