From bac3eed958c8ec3e07b10e3512e0b1fe7405b13c Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 18 Jun 2023 20:28:08 -0500 Subject: [PATCH] [nostalgia/scene] Cleanup --- .../scene/include/nostalgia/scene/scene.hpp | 3 ++ src/nostalgia/modules/scene/src/scene.cpp | 41 +++++++++++-------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/nostalgia/modules/scene/include/nostalgia/scene/scene.hpp b/src/nostalgia/modules/scene/include/nostalgia/scene/scene.hpp index ab557e78..c8b8c6c2 100644 --- a/src/nostalgia/modules/scene/include/nostalgia/scene/scene.hpp +++ b/src/nostalgia/modules/scene/include/nostalgia/scene/scene.hpp @@ -17,6 +17,9 @@ class Scene { ox::Error setupDisplay(core::Context *ctx) const noexcept; + private: + void setupLayer(core::Context*, const ox::Vector &layer, unsigned layerNo) const noexcept; + }; } diff --git a/src/nostalgia/modules/scene/src/scene.cpp b/src/nostalgia/modules/scene/src/scene.cpp index 5efb0ae2..25dc7933 100644 --- a/src/nostalgia/modules/scene/src/scene.cpp +++ b/src/nostalgia/modules/scene/src/scene.cpp @@ -22,26 +22,33 @@ ox::Error Scene::setupDisplay(core::Context *ctx) const noexcept { // disable all backgrounds core::setBgStatus(ctx, 0); for (auto layerNo = 0u; const auto &layer : m_sceneStatic.tileMapIdx) { - core::setBgStatus(ctx, layerNo, true); - core::setBgCbb(ctx, layerNo, 0); - auto x = 0; - auto y = 0; - auto width = m_sceneStatic.rows[layerNo]; - for (const auto &tile : layer) { - auto tile8 = static_cast(tile); - core::setTile(ctx, layerNo, x, y, tile8); - core::setTile(ctx, layerNo, x + 1, y, tile8 + 1); - core::setTile(ctx, layerNo, x, y + 1, tile8 + 2); - core::setTile(ctx, layerNo, x + 1, y + 1, tile8 + 3); - x += 2; - if (x >= width * 2) { - x = 0; - y += 2; - } - } + setupLayer(ctx, layer, layerNo); ++layerNo; } return {}; } +void Scene::setupLayer( + core::Context *ctx, + const ox::Vector &layer, + unsigned layerNo) const noexcept { + core::setBgStatus(ctx, layerNo, true); + core::setBgCbb(ctx, layerNo, 0); + auto x = 0; + auto y = 0; + const auto width = m_sceneStatic.rows[layerNo]; + for (const auto &tile : layer) { + const auto tile8 = static_cast(tile); + core::setTile(ctx, layerNo, x, y, tile8); + core::setTile(ctx, layerNo, x + 1, y, tile8 + 1); + core::setTile(ctx, layerNo, x, y + 1, tile8 + 2); + core::setTile(ctx, layerNo, x + 1, y + 1, tile8 + 3); + x += 2; + if (x >= width * 2) { + x = 0; + y += 2; + } + } +} + }