[nostalgia] Cleanup
All checks were successful
Build / build (push) Successful in 2m46s

This commit is contained in:
Gary Talent 2024-12-02 19:44:10 -06:00
parent e42126c956
commit 161640fa11
5 changed files with 98 additions and 57 deletions

View File

@ -121,11 +121,20 @@ ox::Error loadSpritePalette(
CompactPalette const&palette, CompactPalette const&palette,
size_t page = 0) noexcept; size_t page = 0) noexcept;
ox::Error loadBgPalette(
Context &ctx,
size_t palBank,
ox::StringViewCR palettePath) noexcept;
ox::Error loadBgPalette( ox::Error loadBgPalette(
Context &ctx, Context &ctx,
size_t palBank, size_t palBank,
ox::FileAddress const&paletteAddr) noexcept; ox::FileAddress const&paletteAddr) noexcept;
ox::Error loadSpritePalette(
Context &ctx,
ox::StringViewCR palettePath) noexcept;
ox::Error loadSpritePalette( ox::Error loadSpritePalette(
Context &ctx, Context &ctx,
ox::FileAddress const&paletteAddr) noexcept; ox::FileAddress const&paletteAddr) noexcept;
@ -143,6 +152,14 @@ ox::Error loadBgTileSheet(
size_t srcTileIdx, size_t srcTileIdx,
size_t tileCnt) noexcept; size_t tileCnt) noexcept;
ox::Error loadBgTileSheet(
Context &ctx,
unsigned cbb,
ox::StringViewCR tsPath,
size_t dstTileIdx,
size_t srcTileIdx,
size_t tileCnt) noexcept;
ox::Error loadBgTileSheet( ox::Error loadBgTileSheet(
Context &ctx, Context &ctx,
unsigned cbb, unsigned cbb,
@ -157,6 +174,12 @@ ox::Error loadBgTileSheet(
CompactTileSheet const&ts, CompactTileSheet const&ts,
ox::Optional<unsigned> const&paletteBank = {}) noexcept; ox::Optional<unsigned> const&paletteBank = {}) noexcept;
ox::Error loadBgTileSheet(
Context &ctx,
unsigned cbb,
ox::StringViewCR tilesheetPath,
ox::Optional<unsigned> const&paletteBank) noexcept;
ox::Error loadBgTileSheet( ox::Error loadBgTileSheet(
Context &ctx, Context &ctx,
unsigned cbb, unsigned cbb,
@ -168,6 +191,11 @@ ox::Error loadSpriteTileSheet(
CompactTileSheet const&ts, CompactTileSheet const&ts,
bool loadDefaultPalette) noexcept; bool loadDefaultPalette) noexcept;
ox::Error loadSpriteTileSheet(
Context &ctx,
ox::StringViewCR tilesheetPath,
bool loadDefaultPalette = false) noexcept;
ox::Error loadSpriteTileSheet( ox::Error loadSpriteTileSheet(
Context &ctx, Context &ctx,
ox::FileAddress const&tilesheetAddr, ox::FileAddress const&tilesheetAddr,

View File

@ -18,6 +18,14 @@ int tileRows(Context&) noexcept {
return GbaTileRows; return GbaTileRows;
} }
ox::Error loadBgPalette(
Context &ctx,
size_t palBank,
ox::StringViewCR palettePath) noexcept {
oxRequire(pal, keel::readObj<CompactPalette>(keelCtx(ctx), palettePath));
return loadBgPalette(ctx, palBank, *pal, 0);
}
ox::Error loadBgPalette( ox::Error loadBgPalette(
Context &ctx, Context &ctx,
size_t palBank, size_t palBank,
@ -26,6 +34,13 @@ ox::Error loadBgPalette(
return loadBgPalette(ctx, palBank, *pal, 0); return loadBgPalette(ctx, palBank, *pal, 0);
} }
ox::Error loadSpritePalette(
Context &ctx,
ox::StringViewCR palettePath) noexcept {
oxRequire(pal, keel::readObj<CompactPalette>(keelCtx(ctx), palettePath));
return loadSpritePalette(ctx, *pal, 0);
}
ox::Error loadSpritePalette( ox::Error loadSpritePalette(
Context &ctx, Context &ctx,
ox::FileAddress const&paletteAddr) noexcept { ox::FileAddress const&paletteAddr) noexcept {
@ -44,6 +59,26 @@ ox::Error loadBgTileSheet(
return loadBgTileSheet(ctx, cbb, *ts, dstTileIdx, srcTileIdx, tileCnt); return loadBgTileSheet(ctx, cbb, *ts, dstTileIdx, srcTileIdx, tileCnt);
} }
ox::Error loadBgTileSheet(
Context &ctx,
unsigned cbb,
ox::StringViewCR tsPath,
size_t dstTileIdx,
size_t srcTileIdx,
size_t tileCnt) noexcept {
oxRequire(ts, keel::readObj<CompactTileSheet>(keelCtx(ctx), tsPath));
return loadBgTileSheet(ctx, cbb, *ts, dstTileIdx, srcTileIdx, tileCnt);
}
ox::Error loadBgTileSheet(
Context &ctx,
unsigned cbb,
ox::StringViewCR tilesheetPath,
ox::Optional<unsigned> const&paletteBank) noexcept {
oxRequire(ts, keel::readObj<CompactTileSheet>(keelCtx(ctx), tilesheetPath));
return loadBgTileSheet(ctx, cbb, *ts, paletteBank);
}
ox::Error loadBgTileSheet( ox::Error loadBgTileSheet(
Context &ctx, Context &ctx,
unsigned cbb, unsigned cbb,
@ -53,6 +88,14 @@ ox::Error loadBgTileSheet(
return loadBgTileSheet(ctx, cbb, *ts, paletteBank); return loadBgTileSheet(ctx, cbb, *ts, paletteBank);
} }
ox::Error loadSpriteTileSheet(
Context &ctx,
ox::StringViewCR tilesheetPath,
bool loadDefaultPalette) noexcept {
oxRequire(ts, readObj<CompactTileSheet>(keelCtx(ctx), tilesheetPath));
return loadSpriteTileSheet(ctx, *ts, loadDefaultPalette);
}
ox::Error loadSpriteTileSheet( ox::Error loadSpriteTileSheet(
Context &ctx, Context &ctx,
ox::FileAddress const&tilesheetAddr, ox::FileAddress const&tilesheetAddr,
@ -213,12 +256,11 @@ void puts(
int const column, int const column,
int const row, int const row,
ox::StringViewCR str) noexcept { ox::StringViewCR str) noexcept {
auto const col = static_cast<uint_t>(column);
for (auto i = 0u; i < str.bytes(); ++i) { for (auto i = 0u; i < str.bytes(); ++i) {
setBgTile( setBgTile(
ctx, ctx,
0, 0,
static_cast<int>(col + i), column + static_cast<int>(i),
row, row,
static_cast<uint8_t>(charMap[static_cast<uint8_t>(str[i])])); static_cast<uint8_t>(charMap[static_cast<uint8_t>(str[i])]));
} }

View File

@ -1,7 +1,6 @@
add_executable( add_executable(
nostalgia WIN32 nostalgia WIN32
app.cpp app.cpp
main.cpp
) )
# enable LTO # enable LTO
@ -23,6 +22,8 @@ endif()
target_link_libraries( target_link_libraries(
nostalgia nostalgia
NostalgiaKeelModules NostalgiaKeelModules
NostalgiaProfile
OlympicApplib
OxLogConn OxLogConn
) )

View File

@ -65,8 +65,8 @@ static void testKeyEventHandler(turbine::Context &tctx, turbine::Key key, bool d
[[maybe_unused]] [[maybe_unused]]
static ox::Error runTest(turbine::Context &tctx) { static ox::Error runTest(turbine::Context &tctx) {
constexpr ox::FileAddress TileSheetAddr = ox::StringLiteral("/TileSheets/Charset.ng"); constexpr ox::StringView TileSheetAddr{"/TileSheets/Charset.ng"};
constexpr ox::FileAddress PaletteAddr = ox::StringLiteral("/Palettes/Chester.npal"); constexpr ox::StringView PaletteAddr{"/Palettes/Chester.npal"};
oxRequireM(cctx, core::init(tctx)); oxRequireM(cctx, core::init(tctx));
turbine::setApplicationData(tctx, cctx.get()); turbine::setApplicationData(tctx, cctx.get());
oxRequire(tsStat, turbine::rom(tctx)->stat(PaletteAddr)); oxRequire(tsStat, turbine::rom(tctx)->stat(PaletteAddr));
@ -84,24 +84,24 @@ static ox::Error runTest(turbine::Context &tctx) {
static ox::Error runTileSheetSetTest(turbine::Context &tctx) { static ox::Error runTileSheetSetTest(turbine::Context &tctx) {
// this should make the screen display 'ABCDB', with the A being upside down // this should make the screen display 'ABCDB', with the A being upside down
// and the first B being backwards // and the first B being backwards
constexpr ox::FileAddress PaletteAddr = ox::StringLiteral("/Palettes/Charset.npal"); constexpr ox::StringView PaletteAddr{"/Palettes/Charset.npal"};
oxRequireM(cctx, core::init(tctx)); oxRequireM(cctx, core::init(tctx));
turbine::setApplicationData(tctx, cctx.get()); turbine::setApplicationData(tctx, cctx.get());
oxRequire(tsStat, turbine::rom(tctx)->stat(PaletteAddr)); oxRequire(tsStat, turbine::rom(tctx)->stat(PaletteAddr));
core::TileSheetSet const set{ core::TileSheetSet const set{
.bpp = 4, .bpp = 4,
.entries = { .entries = {
{ .tilesheet = ox::StringLiteral("/TileSheets/Chester.ng"), .sections{{.begin = 0, .tiles = 1}} }, { .tilesheet = ox::StringLiteral{"/TileSheets/Chester.ng"}, .sections{{.begin = 0, .tiles = 1}} },
{ .tilesheet = ox::StringLiteral("/TileSheets/AB.ng"), .sections{{.begin = 0, .tiles = 2}} }, { .tilesheet = ox::StringLiteral{"/TileSheets/AB.ng"}, .sections{{.begin = 0, .tiles = 2}} },
{ .tilesheet = ox::StringLiteral("/TileSheets/CD.ng"), .sections{{.begin = 0, .tiles = 2}} }, { .tilesheet = ox::StringLiteral{"/TileSheets/CD.ng"}, .sections{{.begin = 0, .tiles = 2}} },
{ .tilesheet = ox::StringLiteral("/TileSheets/AB.ng"), .sections{{.begin = 1, .tiles = 1}} }, { .tilesheet = ox::StringLiteral{"/TileSheets/AB.ng"}, .sections{{.begin = 1, .tiles = 1}} },
}, },
}; };
constexpr auto bgPalBank = 1; constexpr auto bgPalBank = 1;
oxReturnError(core::loadBgTileSheet(*cctx, 0, set)); oxReturnError(core::loadBgTileSheet(*cctx, 0, set));
oxReturnError(core::loadSpriteTileSheet(*cctx, set)); oxReturnError(core::loadSpriteTileSheet(*cctx, set));
oxReturnError(core::loadBgPalette(*cctx, bgPalBank, PaletteAddr)); oxReturnError(core::loadBgPalette(*cctx, bgPalBank, PaletteAddr));
oxReturnError(core::loadBgPalette(*cctx, 0, ox::StringLiteral("/Palettes/Chester.npal"))); oxReturnError(core::loadBgPalette(*cctx, 0, PaletteAddr));
oxReturnError(core::loadSpritePalette(*cctx, PaletteAddr)); oxReturnError(core::loadSpritePalette(*cctx, PaletteAddr));
core::setBgStatus(*cctx, 0, true); core::setBgStatus(*cctx, 0, true);
core::setBgTile(*cctx, 0, 10, 9, { .tileIdx = 1, .palBank = bgPalBank, .flipX = 0, .flipY = 1 }); core::setBgTile(*cctx, 0, 10, 9, { .tileIdx = 1, .palBank = bgPalBank, .flipX = 0, .flipY = 1 });
@ -147,7 +147,7 @@ static void sceneKeyEventHandler(turbine::Context &tctx, turbine::Key key, bool
[[maybe_unused]] [[maybe_unused]]
static ox::Error runScene(turbine::Context &tctx) { static ox::Error runScene(turbine::Context &tctx) {
constexpr ox::FileAddress SceneAddr = ox::StringLiteral("/Scenes/Chester.nscn"); constexpr ox::StringView SceneAddr{"/Scenes/Chester.nscn"};
oxRequireM(cctx, core::init(tctx)); oxRequireM(cctx, core::init(tctx));
oxRequire(scn, keel::readObj<scene::SceneStatic>(keelCtx(tctx), SceneAddr)); oxRequire(scn, keel::readObj<scene::SceneStatic>(keelCtx(tctx), SceneAddr));
turbine::setUpdateHandler(tctx, sceneUpdateHandler); turbine::setUpdateHandler(tctx, sceneUpdateHandler);
@ -157,7 +157,20 @@ static ox::Error runScene(turbine::Context &tctx) {
return turbine::run(tctx); return turbine::run(tctx);
} }
ox::Error run(ox::UniquePtr<ox::FileSystem> &&fs) noexcept { namespace olympic {
oxRequireM(tctx, turbine::init(std::move(fs), "Nostalgia"));
ox::Error run(
[[maybe_unused]] ox::StringView project,
[[maybe_unused]] ox::StringView appName,
[[maybe_unused]] ox::StringView projectDataDir,
ox::SpanView<char const*> args) noexcept {
if (args.size() < 2) {
return OxError(1, "Please provide path to project directory or OxFS file.");
}
auto const path = args[1];
oxRequireM(fs, keel::loadRomFs(path));
oxRequireM(tctx, turbine::init(std::move(fs), project));
return runTileSheetSetTest(*tctx); return runTileSheetSetTest(*tctx);
} }
}

View File

@ -1,43 +0,0 @@
/*
* Copyright 2016 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <ox/logconn/def.hpp>
#include <ox/logconn/logconn.hpp>
#include <keel/media.hpp>
#include "../modules/keelmodules.hpp"
#include "app.hpp"
static ox::Error run(int argc, const char **argv) noexcept {
#ifndef OX_BARE_METAL
// GBA doesn't need the modules and calling this doubles the size of the
// binary.
nostalgia::registerKeelModules();
#endif
if (argc < 2) {
return OxError(1, "Please provide path to project directory or OxFS file.");
}
const auto path = argv[1];
oxRequireM(fs, keel::loadRomFs(path));
return run(std::move(fs));
}
#ifdef _WIN32
int WinMain() {
auto const argc = __argc;
auto const argv = const_cast<const char**>(__argv);
#else
int main(int argc, const char **argv) {
#endif
OX_INIT_DEBUG_LOGGER(loggerConn, "Nostalgia Player")
ox::Error err;
err = run(argc, argv);
oxAssert(err, "Something went wrong...");
if (err) {
oxErrf("Failure: {}\n", toStr(err));
}
return static_cast<int>(err);
}