[nostalgia] Make almost everyting noexcept

This commit is contained in:
2021-04-20 01:56:41 -05:00
parent 161780cb91
commit 6ece0b6f9b
22 changed files with 139 additions and 136 deletions
+6 -6
View File
@@ -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])]));
}
+17 -17
View File
@@ -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);
+2 -2
View File
@@ -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 -10
View File
@@ -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;
}