[keel,nostalgia,studio,turbine] Cleanup structure of Turbine
This commit is contained in:
@@ -27,7 +27,7 @@ class Context {
|
||||
|
||||
};
|
||||
|
||||
ox::Result<ox::UPtr<Context>> init(turbine::Context &tctx, InitParams const& = {}) noexcept;
|
||||
ox::Result<ox::UPtr<Context>> init(turbine::Context &tctx, InitParams const¶ms = {}) noexcept;
|
||||
|
||||
}
|
||||
|
||||
|
@@ -12,9 +12,10 @@ target_link_libraries(
|
||||
NostalgiaCore-GBA PUBLIC
|
||||
TeaGBA
|
||||
Keel
|
||||
Turbine
|
||||
)
|
||||
|
||||
if(TURBINE_BUILD_TYPE STREQUAL "GBA")
|
||||
set_source_files_properties(gfx.cpp PROPERTIES COMPILE_FLAGS -marm)
|
||||
target_link_libraries(NostalgiaCore PUBLIC NostalgiaCore-GBA)
|
||||
endif()
|
||||
endif()
|
||||
|
@@ -15,8 +15,8 @@ struct GbaContext: public core::Context {
|
||||
explicit GbaContext(turbine::Context &tctx) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
auto const&rom() const noexcept {
|
||||
return *turbine::rom(turbineCtx);
|
||||
ox::MemFS const&rom() const noexcept {
|
||||
return static_cast<ox::MemFS const&>(*turbine::rom(turbineCtx));
|
||||
}
|
||||
|
||||
};
|
||||
|
@@ -142,7 +142,7 @@ ox::Error loadBgTileSheet(
|
||||
ox::FileAddress const&tilesheetAddr,
|
||||
ox::FileAddress const&paletteAddr) noexcept {
|
||||
auto &gctx = static_cast<GbaContext&>(ctx);
|
||||
auto &rom = static_cast<const ox::MemFS&>(gctx.rom());
|
||||
auto &rom = gctx.rom();
|
||||
return loadBgTileSheet(rom, cbb, tilesheetAddr, paletteAddr);
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ ox::Error loadSpriteTileSheet(
|
||||
ox::FileAddress const&tilesheetAddr,
|
||||
ox::FileAddress const&paletteAddr) noexcept {
|
||||
auto &gctx = static_cast<GbaContext&>(ctx);
|
||||
auto &rom = static_cast<const ox::MemFS&>(gctx.rom());
|
||||
auto &rom = gctx.rom();
|
||||
oxRequire(tsStat, gctx.rom().stat(tilesheetAddr));
|
||||
oxRequire(ts, rom.directAccess(tilesheetAddr));
|
||||
GbaTileMapTarget target;
|
||||
@@ -169,7 +169,7 @@ ox::Error loadSpriteTileSheet(
|
||||
|
||||
ox::Error loadBgPalette(Context &ctx, unsigned, ox::FileAddress const&paletteAddr) noexcept {
|
||||
auto &gctx = static_cast<GbaContext&>(ctx);
|
||||
auto &rom = static_cast<const ox::MemFS&>(gctx.rom());
|
||||
auto &rom = gctx.rom();
|
||||
GbaPaletteTarget target;
|
||||
target.palette = MEM_BG_PALETTE;
|
||||
oxRequire(palStat, gctx.rom().stat(paletteAddr));
|
||||
@@ -180,7 +180,7 @@ ox::Error loadBgPalette(Context &ctx, unsigned, ox::FileAddress const&paletteAdd
|
||||
|
||||
ox::Error loadSpritePalette(Context &ctx, unsigned cbb, ox::FileAddress const&paletteAddr) noexcept {
|
||||
auto &gctx = static_cast<GbaContext&>(ctx);
|
||||
auto &rom = static_cast<const ox::MemFS&>(gctx.rom());
|
||||
auto &rom = gctx.rom();
|
||||
GbaPaletteTarget target;
|
||||
target.palette = &MEM_SPRITE_PALETTE[cbb];
|
||||
oxRequire(palStat, rom.stat(paletteAddr));
|
||||
|
@@ -43,7 +43,7 @@ ox::Array<char, 128> charMap = {
|
||||
0, // space
|
||||
38, // !
|
||||
0, // "
|
||||
0, // #
|
||||
49, // #
|
||||
0, // $
|
||||
0, // %
|
||||
0, // &
|
||||
@@ -132,9 +132,9 @@ ox::Array<char, 128> charMap = {
|
||||
25, // y
|
||||
26, // z
|
||||
46, // {
|
||||
0, // |
|
||||
51, // |
|
||||
48, // }
|
||||
0, // ~
|
||||
50, // ~
|
||||
};
|
||||
|
||||
void setSprite(Context &c, Sprite const&s) noexcept {
|
||||
|
@@ -435,7 +435,7 @@ ox::Error loadBgTileSheet(
|
||||
ox::FileAddress const&tilesheetAddr,
|
||||
ox::FileAddress const&paletteAddr) noexcept {
|
||||
auto &gctx = glctx(ctx);
|
||||
auto &kctx = gctx.turbineCtx.keelCtx;
|
||||
auto &kctx = keelCtx(gctx.turbineCtx);
|
||||
oxRequire(tilesheet, readObj<CompactTileSheet>(kctx, tilesheetAddr));
|
||||
oxRequire(palette, readObj<Palette>(kctx, paletteAddr ? paletteAddr : tilesheet->defaultPalette));
|
||||
oxRequire(tsd, loadTileSheet(ctx, *tilesheet).to([](TileSheetData const&t) -> TileSheetData {
|
||||
@@ -455,7 +455,7 @@ ox::Error loadSpriteTileSheet(
|
||||
ox::FileAddress const&tilesheetAddr,
|
||||
ox::FileAddress const&paletteAddr) noexcept {
|
||||
auto &gctx = glctx(ctx);
|
||||
auto &kctx = gctx.turbineCtx.keelCtx;
|
||||
auto &kctx = keelCtx(gctx.turbineCtx);
|
||||
oxRequire(tilesheet, readObj<CompactTileSheet>(kctx, tilesheetAddr));
|
||||
oxRequire(palette, readObj<Palette>(kctx, paletteAddr ? paletteAddr : tilesheet->defaultPalette));
|
||||
oxRequire(tsd, loadTileSheet(ctx, *tilesheet));
|
||||
|
@@ -19,7 +19,7 @@ constexpr uint64_t TileColumns = 128;
|
||||
constexpr uint64_t TileCount = TileRows * TileColumns;
|
||||
constexpr uint64_t SpriteCount = 128;
|
||||
constexpr uint64_t BgVertexVboRows = 4;
|
||||
constexpr uint64_t BgVertexVboRowLength = 4;
|
||||
constexpr uint64_t BgVertexVboRowLength = 5;
|
||||
constexpr uint64_t BgVertexVboLength = BgVertexVboRows * BgVertexVboRowLength;
|
||||
constexpr uint64_t BgVertexEboLength = 6;
|
||||
constexpr uint64_t SpriteVertexVboRows = 256;
|
||||
|
@@ -17,9 +17,9 @@ namespace nostalgia::core {
|
||||
|
||||
PaletteEditorImGui::PaletteEditorImGui(turbine::Context &ctx, ox::CRStringView path):
|
||||
m_ctx(ctx),
|
||||
m_itemPath(std::move(path)),
|
||||
m_itemPath(path),
|
||||
m_itemName(m_itemPath.substr(std::find(m_itemPath.rbegin(), m_itemPath.rend(), '/').offset() + 1)),
|
||||
m_pal(*keel::readObj<Palette>(m_ctx.keelCtx, ox::FileAddress(m_itemPath.c_str())).unwrapThrow()) {
|
||||
m_pal(*keel::readObj<Palette>(keelCtx(m_ctx), ox::FileAddress(m_itemPath.c_str())).unwrapThrow()) {
|
||||
}
|
||||
|
||||
ox::String const&PaletteEditorImGui::itemName() const noexcept {
|
||||
|
@@ -567,10 +567,10 @@ class PaletteChangeCommand: public TileSheetCommand {
|
||||
TileSheetEditorModel::TileSheetEditorModel(turbine::Context &ctx, ox::StringView path):
|
||||
m_ctx(ctx),
|
||||
m_path(path) {
|
||||
oxRequireT(img, readObj<TileSheet>(m_ctx.keelCtx, m_path));
|
||||
oxRequireT(img, readObj<TileSheet>(keelCtx(m_ctx), m_path));
|
||||
m_img = *img;
|
||||
if (m_img.defaultPalette) {
|
||||
oxThrowError(readObj<Palette>(m_ctx.keelCtx, m_img.defaultPalette).moveTo(&m_pal));
|
||||
oxThrowError(readObj<Palette>(keelCtx(m_ctx), m_img.defaultPalette).moveTo(&m_pal));
|
||||
}
|
||||
m_pal.updated.connect(this, &TileSheetEditorModel::markUpdated);
|
||||
m_undoStack.changeTriggered.connect(this, &TileSheetEditorModel::markUpdatedCmdId);
|
||||
@@ -634,7 +634,7 @@ ox::StringView TileSheetEditorModel::palPath() const noexcept {
|
||||
constexpr ox::StringView uuidPrefix = "uuid://";
|
||||
if (ox::beginsWith(path, uuidPrefix)) {
|
||||
auto uuid = ox::StringView(path.data() + uuidPrefix.bytes(), path.bytes() - uuidPrefix.bytes());
|
||||
auto out = m_ctx.keelCtx.uuidToPath.at(uuid);
|
||||
auto out = keelCtx(m_ctx).uuidToPath.at(uuid);
|
||||
if (out.error) {
|
||||
return {};
|
||||
}
|
||||
@@ -645,7 +645,7 @@ ox::StringView TileSheetEditorModel::palPath() const noexcept {
|
||||
}
|
||||
|
||||
ox::Error TileSheetEditorModel::setPalette(ox::String const&path) noexcept {
|
||||
oxRequire(uuid, m_ctx.keelCtx.pathToUuid.at(path));
|
||||
oxRequire(uuid, keelCtx(m_ctx).pathToUuid.at(path));
|
||||
pushCommand(ox::make<PaletteChangeCommand>(activeSubSheetIdx(), m_img, uuid->toString()));
|
||||
return {};
|
||||
}
|
||||
@@ -753,7 +753,7 @@ ox::Error TileSheetEditorModel::markUpdatedCmdId(const studio::UndoCommand *cmd)
|
||||
m_updated = true;
|
||||
const auto cmdId = cmd->commandId();
|
||||
if (static_cast<CommandId>(cmdId) == CommandId::PaletteChange) {
|
||||
oxReturnError(readObj<Palette>(m_ctx.keelCtx, ox::StringView(m_img.defaultPalette.getPath().value)).moveTo(&m_pal));
|
||||
oxReturnError(readObj<Palette>(keelCtx(m_ctx), ox::StringView(m_img.defaultPalette.getPath().value)).moveTo(&m_pal));
|
||||
}
|
||||
auto tsCmd = dynamic_cast<const TileSheetCommand*>(cmd);
|
||||
auto idx = m_img.validateSubSheetIdx(tsCmd->subsheetIdx());
|
||||
|
@@ -12,7 +12,7 @@ namespace nostalgia::scene {
|
||||
|
||||
class Scene {
|
||||
private:
|
||||
const SceneStatic &m_sceneStatic;
|
||||
SceneStatic const&m_sceneStatic;
|
||||
|
||||
public:
|
||||
explicit Scene(SceneStatic const&sceneStatic) noexcept;
|
||||
|
@@ -37,7 +37,7 @@ struct TileDoc {
|
||||
ox::Array<uint8_t, 4> layerAttachments;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr ox::Result<core::SubSheetId> getSubsheetId(const core::TileSheet &ts) const noexcept {
|
||||
constexpr ox::Result<core::SubSheetId> getSubsheetId(core::TileSheet const&ts) const noexcept {
|
||||
// prefer the already present ID
|
||||
if (subsheetId > -1) {
|
||||
return subsheetId;
|
||||
@@ -47,7 +47,7 @@ struct TileDoc {
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr ox::Result<ox::StringView> getSubsheetPath(
|
||||
const core::TileSheet &ts) const noexcept {
|
||||
core::TileSheet const&ts) const noexcept {
|
||||
// prefer the already present path
|
||||
if (!subsheetPath.len()) {
|
||||
return ts.getNameFor(subsheetId);
|
||||
@@ -88,7 +88,7 @@ struct SceneDoc {
|
||||
auto colCnt = layer[0].size();
|
||||
// find shortest row (they should all be the same, but you know this data
|
||||
// could come from a file)
|
||||
for (const auto &row : layer) {
|
||||
for (auto const&row : layer) {
|
||||
colCnt = ox::min(colCnt, row.size());
|
||||
}
|
||||
return {static_cast<int>(colCnt), rowCnt};
|
||||
|
@@ -16,12 +16,12 @@ ox::Error Scene::setupDisplay(core::Context &ctx) const noexcept {
|
||||
if (m_sceneStatic.palettes.empty()) {
|
||||
return OxError(1, "Scene has no palettes");
|
||||
}
|
||||
const auto &palette = m_sceneStatic.palettes[0];
|
||||
auto const&palette = m_sceneStatic.palettes[0];
|
||||
oxReturnError(core::loadBgTileSheet(
|
||||
ctx, 0, m_sceneStatic.tilesheet, palette));
|
||||
// disable all backgrounds
|
||||
core::setBgStatus(ctx, 0);
|
||||
for (auto layerNo = 0u; const auto &layer : m_sceneStatic.tileMapIdx) {
|
||||
for (auto layerNo = 0u; auto const&layer : m_sceneStatic.tileMapIdx) {
|
||||
setupLayer(ctx, layer, layerNo);
|
||||
++layerNo;
|
||||
}
|
||||
@@ -37,7 +37,7 @@ void Scene::setupLayer(
|
||||
auto x = 0;
|
||||
auto y = 0;
|
||||
const auto width = m_sceneStatic.rows[layerNo];
|
||||
for (const auto &tile : layer) {
|
||||
for (auto const&tile : layer) {
|
||||
const auto tile8 = static_cast<uint8_t>(tile);
|
||||
core::setTile(ctx, layerNo, x, y, tile8);
|
||||
core::setTile(ctx, layerNo, x + 1, y, tile8 + 1);
|
||||
|
@@ -50,7 +50,7 @@ void SceneEditorImGui::onActivated() noexcept {
|
||||
ox::Error SceneEditorImGui::saveItem() noexcept {
|
||||
const auto sctx = applicationData<studio::StudioContext>(m_ctx);
|
||||
oxReturnError(sctx->project->writeObj(m_itemPath, m_editor.scene()));
|
||||
oxReturnError(m_ctx.keelCtx.assetManager.setAsset(m_itemPath, m_editor.scene()));
|
||||
oxReturnError(keelCtx(m_ctx).assetManager.setAsset(m_itemPath, m_editor.scene()));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@@ -10,7 +10,7 @@ namespace nostalgia::scene {
|
||||
|
||||
SceneEditor::SceneEditor(turbine::Context &ctx, ox::CRStringView path):
|
||||
m_ctx(ctx),
|
||||
m_scene(*keel::readObj<SceneStatic>(m_ctx.keelCtx, path).unwrapThrow()) {
|
||||
m_scene(*keel::readObj<SceneStatic>(keelCtx(m_ctx), path).unwrapThrow()) {
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -24,7 +24,7 @@ class StudioModule: public studio::Module {
|
||||
}
|
||||
};
|
||||
|
||||
static StudioModule mod;
|
||||
static StudioModule const mod;
|
||||
const studio::Module *studioModule() noexcept {
|
||||
return &mod;
|
||||
}
|
||||
|
@@ -36,7 +36,7 @@ ox::Error run(ox::UniquePtr<ox::FileSystem> &&fs) noexcept {
|
||||
oxRequireM(tctx, turbine::init(std::move(fs), "Nostalgia"));
|
||||
oxRequireM(cctx, core::init(*tctx));
|
||||
constexpr ox::FileAddress SceneAddr = ox::StringLiteral("/Scenes/Chester.nscn");
|
||||
oxRequire(scn, keel::readObj<scene::SceneStatic>(tctx->keelCtx, SceneAddr));
|
||||
oxRequire(scn, keel::readObj<scene::SceneStatic>(keelCtx(*tctx), SceneAddr));
|
||||
turbine::setUpdateHandler(*tctx, updateHandler);
|
||||
turbine::setKeyEventHandler(*tctx, keyEventHandler);
|
||||
s_scene.emplace(*scn);
|
||||
|
Reference in New Issue
Block a user