From d9f7b2ea1c4e19dc11e9d4909d856873b2e1ac14 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Tue, 14 Jan 2025 21:13:42 -0600 Subject: [PATCH] [nostalgia/core] Add clearCbb functions --- .../modules/core/include/nostalgia/core/gfx.hpp | 4 ++++ .../core/include/nostalgia/core/studio.hpp | 11 +++++++++++ .../core/include/nostalgia/core/tilesheet.hpp | 17 +++++++++++++++++ .../src/nostalgia/modules/core/src/gba/gfx.cpp | 13 +++++++++++++ .../nostalgia/modules/core/src/opengl/gfx.cpp | 12 ++++++++++++ 5 files changed, 57 insertions(+) create mode 100644 deps/nostalgia/src/nostalgia/modules/core/include/nostalgia/core/studio.hpp diff --git a/deps/nostalgia/src/nostalgia/modules/core/include/nostalgia/core/gfx.hpp b/deps/nostalgia/src/nostalgia/modules/core/include/nostalgia/core/gfx.hpp index c8c8ed7..e5f32be 100644 --- a/deps/nostalgia/src/nostalgia/modules/core/include/nostalgia/core/gfx.hpp +++ b/deps/nostalgia/src/nostalgia/modules/core/include/nostalgia/core/gfx.hpp @@ -142,6 +142,10 @@ ox::Error loadBgTileSheet( unsigned cbb, TileSheetSet const&set) noexcept; +void clearCbb(Context &ctx, unsigned cbb) noexcept; + +void clearCbbs(Context &ctx) noexcept; + ox::Error loadBgTileSheet( Context &ctx, unsigned cbb, diff --git a/deps/nostalgia/src/nostalgia/modules/core/include/nostalgia/core/studio.hpp b/deps/nostalgia/src/nostalgia/modules/core/include/nostalgia/core/studio.hpp new file mode 100644 index 0000000..0e6ad2c --- /dev/null +++ b/deps/nostalgia/src/nostalgia/modules/core/include/nostalgia/core/studio.hpp @@ -0,0 +1,11 @@ +/* + * Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved. + */ + +#pragma once + +#include + +namespace nostalgia::core { + +} diff --git a/deps/nostalgia/src/nostalgia/modules/core/include/nostalgia/core/tilesheet.hpp b/deps/nostalgia/src/nostalgia/modules/core/include/nostalgia/core/tilesheet.hpp index f31a7d1..6348903 100644 --- a/deps/nostalgia/src/nostalgia/modules/core/include/nostalgia/core/tilesheet.hpp +++ b/deps/nostalgia/src/nostalgia/modules/core/include/nostalgia/core/tilesheet.hpp @@ -18,6 +18,23 @@ namespace nostalgia::core { +struct SubSheetTemplate { + static constexpr auto TypeName = "net.drinkingtea.nostalgia.gfx.SubSheetTemplate"; + static constexpr auto TypeVersion = 1; + ox::String name; + int32_t width{}; + int32_t height{}; + ox::Vector subsheets; +}; + +OX_MODEL_BEGIN(SubSheetTemplate) + OX_MODEL_FIELD(name) + OX_MODEL_FIELD(width) + OX_MODEL_FIELD(height) + OX_MODEL_FIELD(subsheets) +OX_MODEL_END() + + // Predecessor to TileSheet, kept for backward compatibility struct TileSheetV1 { static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.NostalgiaGraphic"; diff --git a/deps/nostalgia/src/nostalgia/modules/core/src/gba/gfx.cpp b/deps/nostalgia/src/nostalgia/modules/core/src/gba/gfx.cpp index 3d58ce5..eac447b 100644 --- a/deps/nostalgia/src/nostalgia/modules/core/src/gba/gfx.cpp +++ b/deps/nostalgia/src/nostalgia/modules/core/src/gba/gfx.cpp @@ -63,6 +63,19 @@ ox::Error loadSpritePalette( return {}; } +void clearCbb(Context&, unsigned const cbb) noexcept { + for (auto &v : MEM_BG_TILES[cbb]) { + v = 0; + } +} + +void clearCbbs(Context &ctx) noexcept { + clearCbb(ctx, 0); + clearCbb(ctx, 1); + clearCbb(ctx, 2); + clearCbb(ctx, 3); +} + static ox::Error loadTileSheetSet( Context &ctx, ox::Span tileMapTargetMem, diff --git a/deps/nostalgia/src/nostalgia/modules/core/src/opengl/gfx.cpp b/deps/nostalgia/src/nostalgia/modules/core/src/opengl/gfx.cpp index 686b878..baadfef 100644 --- a/deps/nostalgia/src/nostalgia/modules/core/src/opengl/gfx.cpp +++ b/deps/nostalgia/src/nostalgia/modules/core/src/opengl/gfx.cpp @@ -586,6 +586,18 @@ static void copyPixels( } } +void clearCbb(Context &ctx, unsigned const cbb) noexcept { + for (auto &v : ctx.cbbs[cbb].pixels) { + v = 0; + } +} + +void clearCbbs(Context &ctx) noexcept { + for (unsigned i = 0 ; i < ctx.cbbs.size(); ++i) { + clearCbb(ctx, i); + } +} + ox::Error loadBgTileSheet( Context &ctx, unsigned const cbb,