[nostalgia] Make almost everyting noexcept
This commit is contained in:
parent
161780cb91
commit
6ece0b6f9b
@ -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;
|
||||
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,7 @@ ox::Error modelRead(T *io, GbaTileMapTarget *t) {
|
||||
return io->template field<uint8_t, decltype(handleTileMap)>("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<uint32_t>(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<uint8_t>(charMap[static_cast<int>(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<uint16_t>(y & ox::onMask<uint8_t>(7))
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
char *loadRom(const char*) {
|
||||
ox::Result<char*> 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 {
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ enum Key {
|
||||
GamePad_L = 512,
|
||||
};
|
||||
|
||||
[[nodiscard]] bool buttonDown(Key);
|
||||
[[nodiscard]]
|
||||
bool buttonDown(Key) noexcept;
|
||||
|
||||
}
|
||||
|
@ -10,20 +10,17 @@
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
ox::FileSystem *loadRomFs(const char *path) {
|
||||
ox::Result<ox::FileSystem*> 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
|
||||
}
|
||||
}
|
||||
|
@ -12,10 +12,10 @@
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
ox::FileSystem *loadRomFs(const char *path);
|
||||
ox::Result<ox::FileSystem*> loadRomFs(const char *path) noexcept;
|
||||
|
||||
char *loadRom(const char *path = "");
|
||||
ox::Result<char*> loadRom(const char *path = "") noexcept;
|
||||
|
||||
void unloadRom(char*);
|
||||
void unloadRom(char*) noexcept;
|
||||
|
||||
}
|
||||
|
@ -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<uint8_t>(charMap[static_cast<int>(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 {
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<SdlImplData>();
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
@ -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<SdlImplData>();
|
||||
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<SdlImplData>();
|
||||
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<SdlImplData>();
|
||||
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<SdlImplData>();
|
||||
int x = 0, y = 0;
|
||||
SDL_GetWindowSize(id->window, &x, &y);
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
static ox::Result<ox::Vector<char>> readFile(Context *ctx, const ox::FileAddress &file) {
|
||||
static ox::Result<ox::Vector<char>> readFile(Context *ctx, const ox::FileAddress &file) noexcept {
|
||||
oxRequire(stat, ctx->rom->stat(file));
|
||||
ox::Vector<char> buff(stat.size);
|
||||
oxReturnError(ctx->rom->read(file, buff.data(), buff.size()));
|
||||
@ -22,14 +22,14 @@ static ox::Result<ox::Vector<char>> readFile(Context *ctx, const ox::FileAddress
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ox::Result<T> readObj(Context *ctx, const ox::FileAddress &file) {
|
||||
ox::Result<T> 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<NostalgiaGraphic>(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<uint8_t>(charMap[static_cast<int>(str[i])]));
|
||||
}
|
||||
|
@ -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<void*>(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<GLint>(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<GlImplData>();
|
||||
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<GlImplData>();
|
||||
auto &tex = id->backgrounds[static_cast<std::size_t>(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<renderer::GlImplData>();
|
||||
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<renderer::GlImplData>();
|
||||
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<renderer::GlImplData>();
|
||||
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<renderer::GlImplData>();
|
||||
id->backgrounds[bg].enabled = status;
|
||||
}
|
||||
|
||||
|
||||
void draw(Context *ctx) {
|
||||
void draw(Context *ctx) noexcept {
|
||||
const auto id = ctx->rendererData<renderer::GlImplData>();
|
||||
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<renderer::GlImplData>();
|
||||
auto &bg = id->backgrounds[static_cast<std::size_t>(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<renderer::GlImplData>();
|
||||
const auto z = static_cast<unsigned>(layer);
|
||||
const auto y = static_cast<unsigned>(row);
|
||||
|
@ -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;
|
||||
|
@ -14,21 +14,25 @@
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
char *loadRom(const char *path) {
|
||||
ox::Result<char*> 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<std::size_t>(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<std::size_t>(size)];
|
||||
file.read(buff, size);
|
||||
return buff;
|
||||
}
|
||||
|
||||
void unloadRom(char *rom) {
|
||||
void unloadRom(char *rom) noexcept {
|
||||
delete rom;
|
||||
}
|
||||
|
||||
|
@ -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<int>(err);
|
||||
}
|
||||
err = run(fs);
|
||||
oxAssert(err, "Something went wrong...");
|
||||
delete fs;
|
||||
return err;
|
||||
return static_cast<int>(err);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -95,22 +95,20 @@ class NOSTALGIASTUDIO_EXPORT Project: public QObject {
|
||||
template<typename T>
|
||||
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<uint8_t*>(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<uint8_t*>(typeOut.value.data()), typeOut.value.size());
|
||||
writeBuff(typePath, ox::bit_cast<uint8_t*>(typeOut.data()), typeOut.size());
|
||||
emit fileUpdated(path);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user