[nostalgia] Make core::init take FileSystem and return Context, add core::setWindowTitle
This commit is contained in:
parent
2d3602fd05
commit
643239e104
@ -24,12 +24,21 @@ class Drawer {
|
||||
class Context {
|
||||
public:
|
||||
ox::FileSystem *rom = nullptr;
|
||||
ox::Vector<Drawer*, 5> drawer;
|
||||
ox::Vector<Drawer*, 5> drawers;
|
||||
private:
|
||||
void *m_windowerData = nullptr;
|
||||
void *m_rendererData = nullptr;
|
||||
|
||||
public:
|
||||
constexpr Context() noexcept = default;
|
||||
|
||||
constexpr Context(const Context &&other) noexcept {
|
||||
rom = ox::move(other.rom);
|
||||
drawers = ox::move(other.drawers);
|
||||
m_windowerData = ox::move(other.m_windowerData);
|
||||
m_rendererData = ox::move(other.m_rendererData);
|
||||
}
|
||||
|
||||
constexpr void setWindowerData(void *windowerData) noexcept {
|
||||
m_windowerData = windowerData;
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ namespace nostalgia::core {
|
||||
|
||||
using event_handler = int(*)(Context*);
|
||||
|
||||
ox::Error init(Context *ctx) noexcept;
|
||||
ox::Result<Context> init(ox::FileSystem *fs) noexcept;
|
||||
|
||||
ox::Error run(Context *ctx) noexcept;
|
||||
|
||||
|
@ -40,11 +40,13 @@ static void initTimer() noexcept {
|
||||
REG_IE = REG_IE | Int_timer0;
|
||||
}
|
||||
|
||||
ox::Error init(Context *ctx) noexcept {
|
||||
oxReturnError(initGfx(ctx));
|
||||
ox::Result<Context> init(ox::FileSystem *fs) noexcept {
|
||||
Context ctx;
|
||||
ctx.rom = fs;
|
||||
oxReturnError(initGfx(&ctx));
|
||||
initTimer();
|
||||
initIrq();
|
||||
return OxError(0);
|
||||
return ctx;
|
||||
}
|
||||
|
||||
void setEventHandler(Context*, event_handler h) noexcept {
|
||||
|
@ -100,6 +100,9 @@ ox::Error shutdownGfx(Context*) noexcept {
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
void setWindowTitle(Context*, const char*) noexcept {
|
||||
}
|
||||
|
||||
int getScreenWidth(Context*) noexcept {
|
||||
return 240;
|
||||
}
|
||||
|
@ -142,13 +142,13 @@ char charMap[128] = {
|
||||
};
|
||||
|
||||
void addCustomDrawer(Context *ctx, Drawer *cd) noexcept {
|
||||
ctx->drawer.emplace_back(cd);
|
||||
ctx->drawers.emplace_back(cd);
|
||||
}
|
||||
|
||||
void removeCustomDrawer(Context *ctx, Drawer *cd) noexcept {
|
||||
for (auto i = 0u; i < ctx->drawer.size(); ++i) {
|
||||
if (ctx->drawer[i] == cd) {
|
||||
oxIgnoreError(ctx->drawer.erase(i));
|
||||
for (auto i = 0u; i < ctx->drawers.size(); ++i) {
|
||||
if (ctx->drawers[i] == cd) {
|
||||
oxIgnoreError(ctx->drawers.erase(i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -80,6 +80,8 @@ void addCustomDrawer(Context *ctx, Drawer *cd) noexcept;
|
||||
|
||||
void removeCustomDrawer(Context *ctx, Drawer *cd) noexcept;
|
||||
|
||||
void setWindowTitle(Context *ctx, const char *title) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
int getScreenWidth(Context *ctx) noexcept;
|
||||
|
||||
|
@ -37,15 +37,17 @@ static void handleGlfwKeyEvent(GLFWwindow *window, int key, int, int action, int
|
||||
}
|
||||
}
|
||||
|
||||
ox::Error init(Context *ctx) noexcept {
|
||||
ox::Result<Context> init(ox::FileSystem *fs) noexcept {
|
||||
Context ctx;
|
||||
ctx.rom = fs;
|
||||
const auto id = new GlfwImplData;
|
||||
ctx->setWindowerData(id);
|
||||
ctx.setWindowerData(id);
|
||||
using namespace std::chrono;
|
||||
id->startTime = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
|
||||
glfwInit();
|
||||
oxReturnError(initGfx(ctx));
|
||||
oxReturnError(initGfx(&ctx));
|
||||
glfwSetKeyCallback(id->window, handleGlfwKeyEvent);
|
||||
return OxError(0);
|
||||
return ctx;
|
||||
}
|
||||
|
||||
ox::Error run(Context *ctx) noexcept {
|
||||
|
@ -57,6 +57,11 @@ ox::Error shutdownGfx(Context *ctx) noexcept {
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
void setWindowTitle(Context *ctx, const char *title) noexcept {
|
||||
const auto id = ctx->windowerData<GlfwImplData>();
|
||||
glfwSetWindowTitle(id->window, title);
|
||||
}
|
||||
|
||||
int getScreenWidth(Context *ctx) noexcept {
|
||||
auto id = ctx->windowerData<GlfwImplData>();
|
||||
int w = 0, h = 0;
|
||||
|
@ -278,7 +278,7 @@ void draw(Context *ctx) noexcept {
|
||||
renderer::drawBackgrounds(id);
|
||||
//bool showDemo = true;
|
||||
//ImGui::ShowDemoWindow(&showDemo);
|
||||
for (const auto cd : ctx->drawer) {
|
||||
for (const auto cd : ctx->drawers) {
|
||||
cd->draw(ctx);
|
||||
}
|
||||
if constexpr(config::ImGuiEnabled) {
|
||||
|
@ -33,9 +33,7 @@ static int eventHandler(core::Context *ctx) noexcept {
|
||||
}
|
||||
|
||||
ox::Error run(ox::FileSystem *fs) noexcept {
|
||||
core::Context ctx;
|
||||
ctx.rom = fs;
|
||||
oxReturnError(core::init(&ctx));
|
||||
oxRequireM(ctx, core::init(fs));
|
||||
constexpr auto TileSheetAddr = "/TileSheets/Charset.ng";
|
||||
constexpr auto PaletteAddr = "/Palettes/Charset.npal";
|
||||
oxReturnError(core::loadSpriteTileSheet(&ctx, 0, TileSheetAddr, PaletteAddr));
|
||||
|
Loading…
x
Reference in New Issue
Block a user