From 6ece0b6f9bd14ffde2763f964a67e2e4b47537fe Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Tue, 20 Apr 2021 01:56:41 -0500 Subject: [PATCH] [nostalgia] Make almost everyting noexcept --- src/nostalgia/core/core.hpp | 9 +++-- src/nostalgia/core/gba/core.arm.cpp | 2 +- src/nostalgia/core/gba/core.cpp | 12 +++--- src/nostalgia/core/gba/gfx.cpp | 46 +++++++++++----------- src/nostalgia/core/gba/media.cpp | 6 +-- src/nostalgia/core/gba/tests.cpp | 7 ++-- src/nostalgia/core/gfx.cpp | 2 +- src/nostalgia/core/gfx.hpp | 36 ++++++++--------- src/nostalgia/core/input.hpp | 3 +- src/nostalgia/core/media.cpp | 9 ++--- src/nostalgia/core/media.hpp | 6 +-- src/nostalgia/core/qt/gfx.cpp | 14 +++---- src/nostalgia/core/sdl/core.cpp | 10 ++--- src/nostalgia/core/sdl/gfx.cpp | 10 ++--- src/nostalgia/core/userland/gfx.cpp | 12 +++--- src/nostalgia/core/userland/gfx_opengl.cpp | 34 ++++++++-------- src/nostalgia/core/userland/glutils.hpp | 4 +- src/nostalgia/core/userland/media.cpp | 24 ++++++----- src/nostalgia/player/main.cpp | 10 +++-- src/nostalgia/studio/lib/project.cpp | 3 +- src/nostalgia/studio/lib/project.hpp | 10 ++--- src/nostalgia/studio/mainwindow.cpp | 6 +-- 22 files changed, 139 insertions(+), 136 deletions(-) diff --git a/src/nostalgia/core/core.hpp b/src/nostalgia/core/core.hpp index db129fe3..c989d6e3 100644 --- a/src/nostalgia/core/core.hpp +++ b/src/nostalgia/core/core.hpp @@ -19,16 +19,17 @@ namespace nostalgia::core { using event_handler = int(*)(Context*); -ox::Error init(Context *ctx); +ox::Error init(Context *ctx) noexcept; -ox::Error run(Context *ctx); +ox::Error run(Context *ctx) noexcept; // Sets event handler that sleeps for the time given in the return value. The // sleep time is a minimum of ~16 milliseconds. -void setEventHandler(event_handler); +void setEventHandler(event_handler) noexcept; // Returns the number of milliseconds that have passed since the start of the // program. -[[nodiscard]] uint64_t ticksMs(); +[[nodiscard]] +uint64_t ticksMs() noexcept; } diff --git a/src/nostalgia/core/gba/core.arm.cpp b/src/nostalgia/core/gba/core.arm.cpp index 4289f688..47398d21 100644 --- a/src/nostalgia/core/gba/core.arm.cpp +++ b/src/nostalgia/core/gba/core.arm.cpp @@ -21,7 +21,7 @@ extern volatile gba_timer_t g_timerMs; gba_timer_t g_wakeupTime; event_handler g_eventHandler = nullptr; -ox::Error run(Context *ctx) { +ox::Error run(Context *ctx) noexcept { g_wakeupTime = 0; while (1) { if (g_wakeupTime <= g_timerMs && g_eventHandler) { diff --git a/src/nostalgia/core/gba/core.cpp b/src/nostalgia/core/gba/core.cpp index 8006b219..24cb0f1b 100644 --- a/src/nostalgia/core/gba/core.cpp +++ b/src/nostalgia/core/gba/core.cpp @@ -27,12 +27,12 @@ extern event_handler g_eventHandler; extern volatile gba_timer_t g_timerMs; -static void initIrq() { +static void initIrq() noexcept { REG_ISR = isr; REG_IME = 1; // enable interrupts } -static void initTimer() { +static void initTimer() noexcept { // make timer0 a ~1 millisecond timer REG_TIMER0 = TicksMs59ns; REG_TIMER0CTL = 0b11000000; @@ -40,22 +40,22 @@ static void initTimer() { REG_IE = REG_IE | Int_timer0; } -ox::Error init(Context *ctx) { +ox::Error init(Context *ctx) noexcept { oxReturnError(initGfx(ctx)); initTimer(); initIrq(); return OxError(0); } -void setEventHandler(event_handler h) { +void setEventHandler(event_handler h) noexcept { g_eventHandler = h; } -uint64_t ticksMs() { +uint64_t ticksMs() noexcept { return g_timerMs; } -bool buttonDown(Key k) { +bool buttonDown(Key k) noexcept { return !(REG_GAMEPAD & k); } diff --git a/src/nostalgia/core/gba/gfx.cpp b/src/nostalgia/core/gba/gfx.cpp index c6c93c57..c9ae74fb 100644 --- a/src/nostalgia/core/gba/gfx.cpp +++ b/src/nostalgia/core/gba/gfx.cpp @@ -85,7 +85,7 @@ ox::Error modelRead(T *io, GbaTileMapTarget *t) { return io->template field("tileMap", handleTileMap); } -ox::Error initGfx(Context*) { +ox::Error initGfx(Context*) noexcept { REG_DISPCTL = DispCtl_Mode0 | DispCtl_SpriteMap1D | DispCtl_Obj; @@ -96,42 +96,43 @@ ox::Error initGfx(Context*) { return OxError(0); } -ox::Error shutdownGfx(Context*) { +ox::Error shutdownGfx(Context*) noexcept { return OxError(0); } -int getScreenWidth(Context*) { +int getScreenWidth(Context*) noexcept { return 240; } -int getScreenHeight(Context*) { +int getScreenHeight(Context*) noexcept { return 160; } -common::Size getScreenSize(Context*) { +common::Size getScreenSize(Context*) noexcept { return {240, 160}; } -uint8_t bgStatus(Context*) { +uint8_t bgStatus(Context*) noexcept { return (REG_DISPCTL >> 8) & 0b1111; } -void setBgStatus(Context*, uint32_t status) { +void setBgStatus(Context*, uint32_t status) noexcept { constexpr auto Bg0Status = 8; REG_DISPCTL = (REG_DISPCTL & ~0b111100000000u) | status << Bg0Status; } -bool bgStatus(Context*, unsigned bg) { +bool bgStatus(Context*, unsigned bg) noexcept { return (REG_DISPCTL >> (8 + bg)) & 1; } -void setBgStatus(Context*, unsigned bg, bool status) { +void setBgStatus(Context*, unsigned bg, bool status) noexcept { constexpr auto Bg0Status = 8; const auto mask = static_cast(status) << (Bg0Status + bg); REG_DISPCTL = REG_DISPCTL | ((REG_DISPCTL & ~mask) | mask); } -[[nodiscard]] constexpr volatile uint32_t &bgCtl(int bg) noexcept { +[[nodiscard]] +constexpr volatile uint32_t &bgCtl(int bg) noexcept { switch (bg) { case 0: return REG_BG0CTL; @@ -148,16 +149,13 @@ void setBgStatus(Context*, unsigned bg, bool status) { } // Do NOT rely on Context in the GBA version of this function. -ox::Error initConsole(Context *ctx) { +ox::Error initConsole(Context *ctx) noexcept { constexpr auto TilesheetAddr = "/TileSheets/Charset.ng"; constexpr auto PaletteAddr = "/Palettes/Charset.npal"; setBgStatus(ctx, 0b0001); if (!ctx) { ctx = new (ox_alloca(sizeof(Context))) Context(); - auto rom = loadRom(); - if (!rom) { - return OxError(1); - } + oxRequire(rom, loadRom()); ox::FileStore32 fs(rom, 32 * ox::units::MB); ctx->rom = new (ox_alloca(sizeof(ox::FileSystem32))) ox::FileSystem32(fs); } @@ -167,7 +165,7 @@ ox::Error initConsole(Context *ctx) { ox::Error loadBgTileSheet(Context *ctx, int section, ox::FileAddress tilesheetAddr, - ox::FileAddress paletteAddr) { + ox::FileAddress paletteAddr) noexcept { oxRequire(tsStat, ctx->rom->stat(tilesheetAddr)); oxRequire(ts, ctx->rom->directAccess(tilesheetAddr)); GbaTileMapTarget target; @@ -187,7 +185,7 @@ ox::Error loadBgTileSheet(Context *ctx, ox::Error loadSpriteTileSheet(Context *ctx, int section, ox::FileAddress tilesheetAddr, - ox::FileAddress paletteAddr) { + ox::FileAddress paletteAddr) noexcept { oxRequire(tsStat, ctx->rom->stat(tilesheetAddr)); oxRequire(ts, ctx->rom->directAccess(tilesheetAddr)); GbaTileMapTarget target; @@ -205,7 +203,7 @@ ox::Error loadSpriteTileSheet(Context *ctx, return OxError(0); } -ox::Error loadBgPalette(Context *ctx, int section, ox::FileAddress paletteAddr) { +ox::Error loadBgPalette(Context *ctx, int section, ox::FileAddress paletteAddr) noexcept { GbaPaletteTarget target; target.palette = &MEM_BG_PALETTE[section]; oxRequire(palStat, ctx->rom->stat(paletteAddr)); @@ -214,7 +212,7 @@ ox::Error loadBgPalette(Context *ctx, int section, ox::FileAddress paletteAddr) return OxError(0); } -ox::Error loadSpritePalette(Context *ctx, int section, ox::FileAddress paletteAddr) { +ox::Error loadSpritePalette(Context *ctx, int section, ox::FileAddress paletteAddr) noexcept { GbaPaletteTarget target; target.palette = &MEM_SPRITE_PALETTE[section]; oxRequire(palStat, ctx->rom->stat(paletteAddr)); @@ -224,23 +222,23 @@ ox::Error loadSpritePalette(Context *ctx, int section, ox::FileAddress paletteAd } // Do NOT use Context in the GBA version of this function. -void puts(Context *ctx, int column, int row, const char *str) { +void puts(Context *ctx, int column, int row, const char *str) noexcept { for (int i = 0; str[i]; i++) { setTile(ctx, 0, column + i, row, static_cast(charMap[static_cast(str[i])])); } } -void setTile(Context*, int layer, int column, int row, uint8_t tile) { +void setTile(Context*, int layer, int column, int row, uint8_t tile) noexcept { MEM_BG_MAP[layer][row * GbaTileColumns + column] = tile; } // Do NOT use Context in the GBA version of this function. -void clearTileLayer(Context*, int layer) { +void clearTileLayer(Context*, int layer) noexcept { memset(&MEM_BG_MAP[layer], 0, GbaTileRows * GbaTileColumns); } [[maybe_unused]] -void hideSprite(Context*, unsigned idx) { +void hideSprite(Context*, unsigned idx) noexcept { oxAssert(g_spriteUpdates < config::GbaSpriteBufferLen, "Sprite update buffer overflow"); GbaSpriteAttrUpdate oa; oa.attr0 = 2 << 8; @@ -269,7 +267,7 @@ void setSprite(Context*, unsigned tileIdx, unsigned spriteShape, unsigned spriteSize, - unsigned flipX) { + unsigned flipX) noexcept { oxAssert(g_spriteUpdates < config::GbaSpriteBufferLen, "Sprite update buffer overflow"); GbaSpriteAttrUpdate oa; oa.attr0 = static_cast(y & ox::onMask(7)) diff --git a/src/nostalgia/core/gba/media.cpp b/src/nostalgia/core/gba/media.cpp index eee8bc38..dbf89a6c 100644 --- a/src/nostalgia/core/gba/media.cpp +++ b/src/nostalgia/core/gba/media.cpp @@ -14,7 +14,7 @@ namespace nostalgia::core { -char *loadRom(const char*) { +ox::Result loadRom(const char*) noexcept { // put the header in the wrong order to prevent mistaking this code for the // media section constexpr auto headerP2 = "_HEADER_________"; @@ -29,10 +29,10 @@ char *loadRom(const char*) { return current + headerLen; } } - return nullptr; + return OxError(1); } -void unloadRom(char*) { +void unloadRom(char*) noexcept { } } diff --git a/src/nostalgia/core/gba/tests.cpp b/src/nostalgia/core/gba/tests.cpp index 4c08ed1e..35789e55 100644 --- a/src/nostalgia/core/gba/tests.cpp +++ b/src/nostalgia/core/gba/tests.cpp @@ -13,11 +13,12 @@ namespace ox::heapmgr { -[[nodiscard]] void *malloc(std::size_t allocSize); +[[nodiscard]] +void *malloc(std::size_t allocSize) noexcept; -void free(void *ptr); +void free(void *ptr) noexcept; -void initHeap(char *heapBegin, char *heapEnd); +void initHeap(char *heapBegin, char *heapEnd) noexcept; } diff --git a/src/nostalgia/core/gfx.cpp b/src/nostalgia/core/gfx.cpp index 64e38a00..0aa72cab 100644 --- a/src/nostalgia/core/gfx.cpp +++ b/src/nostalgia/core/gfx.cpp @@ -141,7 +141,7 @@ char charMap[128] = { 0, // ~ }; -void setSprite(Context *c, const Sprite &s) { +void setSprite(Context *c, const Sprite &s) noexcept { setSprite(c, s.idx, s.x, s.y, s.tileIdx, s.spriteShape, s.spriteSize, s.flipX); } diff --git a/src/nostalgia/core/gfx.hpp b/src/nostalgia/core/gfx.hpp index a06d47f4..46c07c80 100644 --- a/src/nostalgia/core/gfx.hpp +++ b/src/nostalgia/core/gfx.hpp @@ -72,50 +72,50 @@ struct Sprite { unsigned flipX = 0; }; -ox::Error initGfx(Context *ctx); +ox::Error initGfx(Context *ctx) noexcept; -ox::Error shutdownGfx(Context *ctx); +ox::Error shutdownGfx(Context *ctx) noexcept; [[nodiscard]] -int getScreenWidth(Context *ctx); +int getScreenWidth(Context *ctx) noexcept; [[nodiscard]] -int getScreenHeight(Context *ctx); +int getScreenHeight(Context *ctx) noexcept; [[nodiscard]] -common::Size getScreenSize(Context *ctx); +common::Size getScreenSize(Context *ctx) noexcept; [[nodiscard]] -uint8_t bgStatus(Context *ctx); +uint8_t bgStatus(Context *ctx) noexcept; -void setBgStatus(Context *ctx, uint32_t status); +void setBgStatus(Context *ctx, uint32_t status) noexcept; -bool bgStatus(Context *ctx, unsigned bg); +bool bgStatus(Context *ctx, unsigned bg) noexcept; -void setBgStatus(Context *ctx, unsigned bg, bool status); +void setBgStatus(Context *ctx, unsigned bg, bool status) noexcept; -ox::Error initConsole(Context *ctx); +ox::Error initConsole(Context *ctx) noexcept; /** * @param section describes which section of the selected TileSheetSpace to use (e.g. MEM_PALLETE_BG[section]) */ -ox::Error loadBgTileSheet(Context *ctx, int section, ox::FileAddress tilesheet, ox::FileAddress palette = nullptr); +ox::Error loadBgTileSheet(Context *ctx, int section, ox::FileAddress tilesheet, ox::FileAddress palette = nullptr) noexcept; ox::Error loadSpriteTileSheet(Context *ctx, int section, ox::FileAddress tilesheetAddr, - ox::FileAddress paletteAddr); + ox::FileAddress paletteAddr) noexcept; -void puts(Context *ctx, int column, int row, const char *str); +void puts(Context *ctx, int column, int row, const char *str) noexcept; -void setTile(Context *ctx, int layer, int column, int row, uint8_t tile); +void setTile(Context *ctx, int layer, int column, int row, uint8_t tile) noexcept; -void clearTileLayer(Context *ctx, int layer); +void clearTileLayer(Context *ctx, int layer) noexcept; -void hideSprite(Context *ctx, unsigned); +void hideSprite(Context *ctx, unsigned) noexcept; -void setSprite(Context *ctx, unsigned idx, unsigned x, unsigned y, unsigned tileIdx, unsigned spriteShape = 0, unsigned spriteSize = 0, unsigned flipX = 0); +void setSprite(Context *ctx, unsigned idx, unsigned x, unsigned y, unsigned tileIdx, unsigned spriteShape = 0, unsigned spriteSize = 0, unsigned flipX = 0) noexcept; -void setSprite(Context *ctx, const Sprite &s); +void setSprite(Context *ctx, const Sprite &s) noexcept; } diff --git a/src/nostalgia/core/input.hpp b/src/nostalgia/core/input.hpp index 46d8f944..42ab5462 100644 --- a/src/nostalgia/core/input.hpp +++ b/src/nostalgia/core/input.hpp @@ -24,6 +24,7 @@ enum Key { GamePad_L = 512, }; -[[nodiscard]] bool buttonDown(Key); +[[nodiscard]] +bool buttonDown(Key) noexcept; } diff --git a/src/nostalgia/core/media.cpp b/src/nostalgia/core/media.cpp index fdcb335d..8a29ce58 100644 --- a/src/nostalgia/core/media.cpp +++ b/src/nostalgia/core/media.cpp @@ -10,20 +10,17 @@ namespace nostalgia::core { -ox::FileSystem *loadRomFs(const char *path) { +ox::Result loadRomFs(const char *path) noexcept { const auto lastDot = ox_lastIndexOf(path, '.'); const auto fsExt = lastDot != -1 ? path + lastDot : ""; if (ox_strcmp(fsExt, ".oxfs") == 0) { - auto rom = core::loadRom(path); - if (!rom) { - return nullptr; - } + oxRequire(rom, core::loadRom(path)); return new ox::FileSystem32(rom, 32 * ox::units::MB, unloadRom); } else { #ifdef OX_HAS_PASSTHROUGHFS return new ox::PassThroughFS(path); #else - return nullptr; + return OxError(2); #endif } } diff --git a/src/nostalgia/core/media.hpp b/src/nostalgia/core/media.hpp index 78f97baf..26ae9beb 100644 --- a/src/nostalgia/core/media.hpp +++ b/src/nostalgia/core/media.hpp @@ -12,10 +12,10 @@ namespace nostalgia::core { -ox::FileSystem *loadRomFs(const char *path); +ox::Result loadRomFs(const char *path) noexcept; -char *loadRom(const char *path = ""); +ox::Result loadRom(const char *path = "") noexcept; -void unloadRom(char*); +void unloadRom(char*) noexcept; } diff --git a/src/nostalgia/core/qt/gfx.cpp b/src/nostalgia/core/qt/gfx.cpp index 5fdcc825..9aac3b44 100644 --- a/src/nostalgia/core/qt/gfx.cpp +++ b/src/nostalgia/core/qt/gfx.cpp @@ -10,35 +10,35 @@ namespace nostalgia::core { -ox::Error initGfx(Context*) { +ox::Error initGfx(Context*) noexcept { return OxError(1); } -ox::Error shutdownGfx(Context*) { +ox::Error shutdownGfx(Context*) noexcept { return OxError(1); } -ox::Error initConsole(Context*) { +ox::Error initConsole(Context*) noexcept { return OxError(1); } ox::Error loadBgTileSheet(Context*, int, ox::FileAddress, - ox::FileAddress) { + ox::FileAddress) noexcept { return OxError(1); } -void puts(Context *ctx, int column, int row, const char *str) { +void puts(Context *ctx, int column, int row, const char *str) noexcept { for (int i = 0; str[i]; i++) { setTile(ctx, 0, column + i, row, static_cast(charMap[static_cast(str[i])])); } } -void setTile(Context*, int, int, int, uint8_t) { +void setTile(Context*, int, int, int, uint8_t) noexcept { } -void setSprite(Context*, unsigned, unsigned, unsigned, unsigned, unsigned, unsigned, unsigned) { +void setSprite(Context*, unsigned, unsigned, unsigned, unsigned, unsigned, unsigned, unsigned) noexcept { } } diff --git a/src/nostalgia/core/sdl/core.cpp b/src/nostalgia/core/sdl/core.cpp index 7a0348dc..4626497c 100644 --- a/src/nostalgia/core/sdl/core.cpp +++ b/src/nostalgia/core/sdl/core.cpp @@ -22,12 +22,12 @@ static uint64_t g_wakeupTime; void draw(Context *ctx); -ox::Error init(Context *ctx) { +ox::Error init(Context *ctx) noexcept { oxReturnError(initGfx(ctx)); return OxError(0); } -ox::Error run(Context *ctx) { +ox::Error run(Context *ctx) noexcept { const auto id = ctx->windowerData(); // try adaptive vsync if (SDL_GL_SetSwapInterval(config::SdlVsyncOption) < 0) { @@ -64,15 +64,15 @@ ox::Error run(Context *ctx) { return OxError(0); } -void setEventHandler(event_handler h) { +void setEventHandler(event_handler h) noexcept { g_eventHandler = h; } -uint64_t ticksMs() { +uint64_t ticksMs() noexcept { return SDL_GetTicks(); } -bool buttonDown(Key) { +bool buttonDown(Key) noexcept { return false; } diff --git a/src/nostalgia/core/sdl/gfx.cpp b/src/nostalgia/core/sdl/gfx.cpp index c5dcc45a..a744a7ce 100644 --- a/src/nostalgia/core/sdl/gfx.cpp +++ b/src/nostalgia/core/sdl/gfx.cpp @@ -22,7 +22,7 @@ namespace nostalgia::core { constexpr auto Scale = 5; -ox::Error initGfx(Context *ctx) { +ox::Error initGfx(Context *ctx) noexcept { auto id = new SdlImplData; ctx->setWindowerData(id); id->window = SDL_CreateWindow("nostalgia", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, @@ -42,7 +42,7 @@ ox::Error initGfx(Context *ctx) { return OxError(0); } -ox::Error shutdownGfx(Context *ctx) { +ox::Error shutdownGfx(Context *ctx) noexcept { oxReturnError(renderer::shutdown(ctx)); auto id = ctx->windowerData(); SDL_GL_DeleteContext(id->renderer); @@ -52,21 +52,21 @@ ox::Error shutdownGfx(Context *ctx) { return OxError(0); } -int getScreenWidth(Context *ctx) { +int getScreenWidth(Context *ctx) noexcept { auto id = ctx->windowerData(); int x = 0, y = 0; SDL_GetWindowSize(id->window, &x, &y); return x; } -int getScreenHeight(Context *ctx) { +int getScreenHeight(Context *ctx) noexcept { auto id = ctx->windowerData(); int x = 0, y = 0; SDL_GetWindowSize(id->window, &x, &y); return y; } -common::Size getScreenSize(Context *ctx) { +common::Size getScreenSize(Context *ctx) noexcept { auto id = ctx->windowerData(); int x = 0, y = 0; SDL_GetWindowSize(id->window, &x, &y); diff --git a/src/nostalgia/core/userland/gfx.cpp b/src/nostalgia/core/userland/gfx.cpp index b2bfb382..a4761371 100644 --- a/src/nostalgia/core/userland/gfx.cpp +++ b/src/nostalgia/core/userland/gfx.cpp @@ -14,7 +14,7 @@ namespace nostalgia::core { -static ox::Result> readFile(Context *ctx, const ox::FileAddress &file) { +static ox::Result> readFile(Context *ctx, const ox::FileAddress &file) noexcept { oxRequire(stat, ctx->rom->stat(file)); ox::Vector buff(stat.size); oxReturnError(ctx->rom->read(file, buff.data(), buff.size())); @@ -22,14 +22,14 @@ static ox::Result> readFile(Context *ctx, const ox::FileAddress } template -ox::Result readObj(Context *ctx, const ox::FileAddress &file) { +ox::Result readObj(Context *ctx, const ox::FileAddress &file) noexcept { oxRequire(buff, readFile(ctx, file)); T t; oxReturnError(ox::readClaw(buff.data(), buff.size(), &t)); return ox::move(t); } -ox::Error initConsole(Context *ctx) { +ox::Error initConsole(Context *ctx) noexcept { constexpr auto TilesheetAddr = "/TileSheets/Charset.ng"; constexpr auto PaletteAddr = "/Palettes/Charset.npal"; setBgStatus(ctx, 0b0001); @@ -39,14 +39,14 @@ ox::Error initConsole(Context *ctx) { ox::Error loadSpriteTileSheet(Context*, int, ox::FileAddress, - ox::FileAddress) { + ox::FileAddress) noexcept { return OxError(0); } ox::Error loadBgTileSheet(Context *ctx, int section, ox::FileAddress tilesheetPath, - ox::FileAddress palettePath) { + ox::FileAddress palettePath) noexcept { oxRequire(tilesheet, readObj(ctx, tilesheetPath)); if (!palettePath) { palettePath = tilesheet.defaultPalette; @@ -72,7 +72,7 @@ ox::Error loadBgTileSheet(Context *ctx, return renderer::loadBgTexture(ctx, section, pixels.data(), width, height); } -void puts(Context *ctx, int column, int row, const char *str) { +void puts(Context *ctx, int column, int row, const char *str) noexcept { for (int i = 0; str[i]; ++i) { setTile(ctx, 0, column + i, row, static_cast(charMap[static_cast(str[i])])); } diff --git a/src/nostalgia/core/userland/gfx_opengl.cpp b/src/nostalgia/core/userland/gfx_opengl.cpp index 674568dc..bd200f8b 100644 --- a/src/nostalgia/core/userland/gfx_opengl.cpp +++ b/src/nostalgia/core/userland/gfx_opengl.cpp @@ -131,7 +131,7 @@ static Buffer genBuffer() noexcept { return Buffer(buff); } -static void initBackgroundBufferset(Context *ctx, GLuint shader, Background *bg) { +static void initBackgroundBufferset(Context *ctx, GLuint shader, Background *bg) noexcept { // vao bg->vao = genVertexArrayObject(); glBindVertexArray(bg->vao); @@ -151,7 +151,7 @@ static void initBackgroundBufferset(Context *ctx, GLuint shader, Background *bg) ox::bit_cast(2 * sizeof(float))); } -static Texture loadTexture(GLsizei w, GLsizei h, void *pixels) { +static Texture loadTexture(GLsizei w, GLsizei h, void *pixels) noexcept { GLuint texId = 0; glGenTextures(1, &texId); Texture tex(texId); @@ -167,7 +167,7 @@ static Texture loadTexture(GLsizei w, GLsizei h, void *pixels) { return ox::move(tex); } -static void tickFps(GlImplData *id) { +static void tickFps(GlImplData *id) noexcept { ++id->draws; if (id->draws >= 500) { using namespace std::chrono; @@ -183,7 +183,7 @@ static void tickFps(GlImplData *id) { } } -static void drawBackground(Background *bg) { +static void drawBackground(Background *bg) noexcept { if (bg->enabled) { glBindVertexArray(bg->vao); if (bg->updated) { @@ -195,7 +195,7 @@ static void drawBackground(Background *bg) { } } -static void drawBackgrounds(GlImplData *id) { +static void drawBackgrounds(GlImplData *id) noexcept { // load background shader and its uniforms glUseProgram(id->bgShader); const auto uniformTileHeight = static_cast(glGetUniformLocation(id->bgShader, "vTileHeight")); @@ -205,7 +205,7 @@ static void drawBackgrounds(GlImplData *id) { } } -ox::Error init(Context *ctx) { +ox::Error init(Context *ctx) noexcept { const auto id = new GlImplData; ctx->setRendererData(id); oxReturnError(buildShaderProgram(bgvshad, bgfshad).moveTo(&id->bgShader)); @@ -215,14 +215,14 @@ ox::Error init(Context *ctx) { return OxError(0); } -ox::Error shutdown(Context *ctx) { +ox::Error shutdown(Context *ctx) noexcept { const auto id = ctx->rendererData(); ctx->setRendererData(nullptr); delete id; return OxError(0); } -ox::Error loadBgTexture(Context *ctx, int section, void *pixels, int w, int h) { +ox::Error loadBgTexture(Context *ctx, int section, void *pixels, int w, int h) noexcept { oxTracef("nostalgia::core::gfx::gl", "loadBgTexture: { section: {}, w: {}, h: {} }", section, w, h); const auto &id = ctx->rendererData(); auto &tex = id->backgrounds[static_cast(section)].tex; @@ -232,7 +232,7 @@ ox::Error loadBgTexture(Context *ctx, int section, void *pixels, int w, int h) { } -uint8_t bgStatus(Context *ctx) { +uint8_t bgStatus(Context *ctx) noexcept { const auto &id = ctx->rendererData(); uint8_t out = 0; for (unsigned i = 0; i < id->backgrounds.size(); ++i) { @@ -241,25 +241,25 @@ uint8_t bgStatus(Context *ctx) { return out; } -void setBgStatus(Context *ctx, uint32_t status) { +void setBgStatus(Context *ctx, uint32_t status) noexcept { const auto &id = ctx->rendererData(); for (unsigned i = 0; i < id->backgrounds.size(); ++i) { id->backgrounds[i].enabled = (status >> i) & 1; } } -bool bgStatus(Context *ctx, unsigned bg) { +bool bgStatus(Context *ctx, unsigned bg) noexcept { const auto &id = ctx->rendererData(); return id->backgrounds[bg].enabled; } -void setBgStatus(Context *ctx, unsigned bg, bool status) { +void setBgStatus(Context *ctx, unsigned bg, bool status) noexcept { const auto &id = ctx->rendererData(); id->backgrounds[bg].enabled = status; } -void draw(Context *ctx) { +void draw(Context *ctx) noexcept { const auto id = ctx->rendererData(); renderer::tickFps(id); // clear screen @@ -269,14 +269,14 @@ void draw(Context *ctx) { renderer::drawBackgrounds(id); } -void clearTileLayer(Context *ctx, int layer) { +void clearTileLayer(Context *ctx, int layer) noexcept { const auto id = ctx->rendererData(); auto &bg = id->backgrounds[static_cast(layer)]; initBackgroundBufferObjects(ctx, &bg); bg.updated = true; } -void hideSprite(Context*, unsigned) { +void hideSprite(Context*, unsigned) noexcept { } void setSprite(Context*, @@ -286,10 +286,10 @@ void setSprite(Context*, unsigned, unsigned, unsigned, - unsigned) { + unsigned) noexcept { } -void setTile(Context *ctx, int layer, int column, int row, uint8_t tile) { +void setTile(Context *ctx, int layer, int column, int row, uint8_t tile) noexcept { const auto id = ctx->rendererData(); const auto z = static_cast(layer); const auto y = static_cast(row); diff --git a/src/nostalgia/core/userland/glutils.hpp b/src/nostalgia/core/userland/glutils.hpp index 3412c618..ac0ccaeb 100644 --- a/src/nostalgia/core/userland/glutils.hpp +++ b/src/nostalgia/core/userland/glutils.hpp @@ -26,7 +26,7 @@ struct TextureBase { GLsizei width = 0; GLsizei height = 0; - constexpr TextureBase() = default; + constexpr TextureBase() noexcept = default; constexpr TextureBase(TextureBase &&tb) noexcept { width = tb.width; @@ -51,7 +51,7 @@ struct GLobject: public Base { GLuint id = 0; - constexpr GLobject() = default; + constexpr GLobject() noexcept = default; explicit constexpr GLobject(GLuint id) { this->id = id; diff --git a/src/nostalgia/core/userland/media.cpp b/src/nostalgia/core/userland/media.cpp index 01fbcf73..272ca394 100644 --- a/src/nostalgia/core/userland/media.cpp +++ b/src/nostalgia/core/userland/media.cpp @@ -14,21 +14,25 @@ namespace nostalgia::core { -char *loadRom(const char *path) { +ox::Result loadRom(const char *path) noexcept { std::ifstream file(path, std::ios::binary | std::ios::ate); if (!file.good()) { - oxTrace("nostalgia::core::userland::loadRom") << "Read failed:" << path; - return nullptr; + oxErrorf("Could not find ROM file: {}", path); + return OxError(1, "Could not find ROM file"); + } + try { + const auto size = file.tellg(); + file.seekg(0, std::ios::beg); + auto buff = new char[static_cast(size)]; + file.read(buff, size); + return buff; + } catch (const std::ios_base::failure &e) { + oxErrorf("Could not read ROM file: {}", e.what()); + return OxError(2, "Could not read ROM file"); } - - const auto size = file.tellg(); - file.seekg(0, std::ios::beg); - auto buff = new char[static_cast(size)]; - file.read(buff, size); - return buff; } -void unloadRom(char *rom) { +void unloadRom(char *rom) noexcept { delete rom; } diff --git a/src/nostalgia/player/main.cpp b/src/nostalgia/player/main.cpp index 9cc92ea2..b2a9d141 100644 --- a/src/nostalgia/player/main.cpp +++ b/src/nostalgia/player/main.cpp @@ -15,11 +15,15 @@ int main(int argc, const char **argv) { if (argc > 1) { ox::trace::init(); auto path = argv[1]; - auto fs = nostalgia::core::loadRomFs(path); - auto err = run(fs); + auto [fs, err] = nostalgia::core::loadRomFs(path); + if (err) { + oxAssert(err, "Something went wrong..."); + return static_cast(err); + } + err = run(fs); oxAssert(err, "Something went wrong..."); delete fs; - return err; + return static_cast(err); } return 1; } diff --git a/src/nostalgia/studio/lib/project.cpp b/src/nostalgia/studio/lib/project.cpp index 85e32cdf..6678ddee 100644 --- a/src/nostalgia/studio/lib/project.cpp +++ b/src/nostalgia/studio/lib/project.cpp @@ -41,8 +41,7 @@ void Project::mkdir(QString path) const { } ox::FileStat Project::stat(QString path) const { - auto [s, e] = m_fs.stat(path.toUtf8().data()); - oxThrowError(e); + oxRequireT(s, m_fs.stat(path.toUtf8().data())); return s; } diff --git a/src/nostalgia/studio/lib/project.hpp b/src/nostalgia/studio/lib/project.hpp index dbae80d0..bfc3529f 100644 --- a/src/nostalgia/studio/lib/project.hpp +++ b/src/nostalgia/studio/lib/project.hpp @@ -95,22 +95,20 @@ class NOSTALGIASTUDIO_EXPORT Project: public QObject { template void Project::writeObj(QString path, T *obj) const { // write MetalClaw - auto [buff, err] = ox::writeClaw(obj, ox::ClawFormat::Metal); - oxThrowError(err); + oxRequireMT(buff, ox::writeClaw(obj, ox::ClawFormat::Metal)); // write to FS writeBuff(path, ox::bit_cast(buff.data()), buff.size()); // write type descriptor const auto type = ox::buildTypeDef(obj); - auto typeOut = ox::writeClaw(type.value, ox::ClawFormat::Organic); - oxThrowError(typeOut); + oxRequireMT(typeOut, ox::writeClaw(type.value, ox::ClawFormat::Organic)); // replace garbage last character with new line - typeOut.value.back().value = '\n'; + typeOut.back().value = '\n'; // write to FS QString descPath = "/.nostalgia/type_descriptors/"; const auto typePath = descPath + type.value->typeName.c_str(); mkdir(descPath); - writeBuff(typePath, ox::bit_cast(typeOut.value.data()), typeOut.value.size()); + writeBuff(typePath, ox::bit_cast(typeOut.data()), typeOut.size()); emit fileUpdated(path); } diff --git a/src/nostalgia/studio/mainwindow.cpp b/src/nostalgia/studio/mainwindow.cpp index 61d34684..f412c6f7 100644 --- a/src/nostalgia/studio/mainwindow.cpp +++ b/src/nostalgia/studio/mainwindow.cpp @@ -258,7 +258,7 @@ void MainWindow::addDockWidget(Qt::DockWidgetArea area, QDockWidget *dockWidget) QAction *MainWindow::addAction(QMenu *menu, QString text, QString toolTip, const QObject *tgt, const char *cb) { auto action = menu->addAction(text); action->setStatusTip(toolTip); - auto conn = connect(action, SIGNAL(triggered()), tgt, cb); + connect(action, SIGNAL(triggered()), tgt, cb); return action; } @@ -267,7 +267,7 @@ QAction *MainWindow::addAction(QMenu *menu, QString text, QString toolTip, auto action = menu->addAction(text); action->setShortcuts(key); action->setStatusTip(toolTip); - auto conn = connect(action, SIGNAL(triggered()), tgt, cb); + connect(action, SIGNAL(triggered()), tgt, cb); return action; } @@ -276,7 +276,7 @@ QAction *MainWindow::addAction(QMenu *menu, QString text, QString toolTip, auto action = menu->addAction(text); action->setShortcuts(key); action->setStatusTip(toolTip); - auto conn = connect(action, &QAction::triggered, cb); + connect(action, &QAction::triggered, cb); return action; }