From c4d0189175f9791fbe7e1c663810f973551834a3 Mon Sep 17 00:00:00 2001 From: PJB3005 Date: Fri, 27 Mar 2026 17:34:05 +0100 Subject: [PATCH] Fix map loader gameRegions literally being 2.7 MiB of recursive arrays Just moving it to std::vector, easy enough. --- include/dusk/map_loader_definitions.h | 46 ++++++++++----------------- src/dusk/imgui/ImGuiMapLoader.cpp | 14 ++++---- 2 files changed, 24 insertions(+), 36 deletions(-) diff --git a/include/dusk/map_loader_definitions.h b/include/dusk/map_loader_definitions.h index c2c9e4fedb..31dfef7157 100644 --- a/include/dusk/map_loader_definitions.h +++ b/include/dusk/map_loader_definitions.h @@ -1,79 +1,67 @@ #pragma once struct RoomEntry { - static constexpr int MAX_POINTS = 70; - u8 roomNo; - s16 roomPoints[MAX_POINTS] = {}; - int numPoints; + std::vector roomPoints = {}; - constexpr RoomEntry() : roomNo(0), numPoints(0) {} + constexpr RoomEntry() : roomNo(0) {} constexpr RoomEntry(const RoomEntry& other) = default; template constexpr RoomEntry(const u8 roomNo, const s16 (&points)[N]) : - roomNo(roomNo), numPoints(N) { - static_assert(N <= MAX_POINTS); + roomNo(roomNo) { for (int i = 0; i < N; i++) { - roomPoints[i] = points[i]; + roomPoints.push_back(points[i]); } } constexpr RoomEntry(const u8 roomNo) : - roomNo(roomNo), numPoints(1) { - roomPoints[0] = 0; + roomNo(roomNo) { + roomPoints.push_back(0); } }; struct MapEntry { - static constexpr int MAX_ROOMS = 50; - const char* mapName; const char* mapFile; - RoomEntry mapRooms[MAX_ROOMS] = {}; - int numRooms; + std::vector mapRooms = {}; - constexpr MapEntry() : mapName(nullptr), mapFile(nullptr), numRooms(0) {} + constexpr MapEntry() : mapName(nullptr), mapFile(nullptr) {} constexpr MapEntry(const MapEntry& other) = default; template constexpr MapEntry(const char* mapName, const char* mapFile, const RoomEntry (&rooms)[N], const char*) : mapName(mapName), - mapFile(mapFile), numRooms(N) { - static_assert(N <= MAX_ROOMS); + mapFile(mapFile) { for (int i = 0; i < N; i++) { - mapRooms[i] = rooms[i]; + mapRooms.push_back(rooms[i]); } } template constexpr MapEntry(const char* mapName, const char* mapFile, const RoomEntry (&rooms)[N]) : - mapName(mapName), mapFile(mapFile), numRooms(N) { - static_assert(N <= MAX_ROOMS); + mapName(mapName), mapFile(mapFile) { for (int i = 0; i < N; i++) { - mapRooms[i] = rooms[i]; + mapRooms.push_back(rooms[i]); } } constexpr MapEntry(const char* mapName, const char* mapFile) : mapName(mapName), - mapFile(mapFile), numRooms(0) {} + mapFile(mapFile) {} }; struct RegionEntry { - static constexpr int MAX_MAPS = 22; const char* regionName = nullptr; - int numMaps = 0; - MapEntry maps[MAX_MAPS] = {}; + std::vector maps = {}; template - constexpr RegionEntry(const char* regionName, const MapEntry (&maps)[N]) : regionName(regionName), numMaps(N) { - static_assert(N <= MAX_MAPS); + constexpr RegionEntry(const char* regionName, const MapEntry (&maps)[N]) : regionName(regionName) { for (int i = 0; i < N; i++) { - this->maps[i] = maps[i]; + this->maps.push_back(maps[i]); } } }; -constexpr auto gameRegions = std::to_array({ +static const auto gameRegions = std::to_array({ RegionEntry("Hyrule Field", { MapEntry("Hyrule Field", "F_SP121", { diff --git a/src/dusk/imgui/ImGuiMapLoader.cpp b/src/dusk/imgui/ImGuiMapLoader.cpp index 44b1b7c583..89ab6aa120 100644 --- a/src/dusk/imgui/ImGuiMapLoader.cpp +++ b/src/dusk/imgui/ImGuiMapLoader.cpp @@ -57,7 +57,7 @@ namespace dusk { if (ImGui::BeginCombo("Select Map", previewMap.data())) { int prevMapIdx = m_mapLoaderInfo.mapIdx; - for (int i = 0; i < region.numMaps; ++i) { + for (int i = 0; i < region.maps.size(); ++i) { const auto& map = region.maps[i]; std::string label = m_mapLoaderInfo.showInternalNames ? fmt::format("{} ({})", map.mapName, map.mapFile) : map.mapName; if (ImGui::Selectable(label.data())) { @@ -79,20 +79,20 @@ namespace dusk { const auto& map = region.maps[m_mapLoaderInfo.mapIdx]; const auto& room = map.mapRooms[m_mapLoaderInfo.roomNoIdx]; - if (map.numRooms > 1) { + if (map.mapRooms.size() > 1) { ImGui::Text("Selected Room: %2d", room.roomNo); ImGui::SameLine(); if (ImGui::Button("-###RoomNoIdxDec")) { m_mapLoaderInfo.roomNoIdx--; if (m_mapLoaderInfo.roomNoIdx < 0) { - m_mapLoaderInfo.roomNoIdx = map.numRooms - 1; + m_mapLoaderInfo.roomNoIdx = map.mapRooms.size() - 1; } m_mapLoaderInfo.pointNoIdx = 0; } ImGui::SameLine(); if (ImGui::Button("+###RoomNoIdxInc")) { m_mapLoaderInfo.roomNoIdx++; - if (m_mapLoaderInfo.roomNoIdx >= map.numRooms) { + if (m_mapLoaderInfo.roomNoIdx >= map.mapRooms.size()) { m_mapLoaderInfo.roomNoIdx = 0; } m_mapLoaderInfo.pointNoIdx = 0; @@ -117,19 +117,19 @@ namespace dusk { } } - if (room.numPoints > 1) { + if (room.roomPoints.size() > 1) { ImGui::Text("Selected Point: %3d", room.roomPoints[m_mapLoaderInfo.pointNoIdx]); ImGui::SameLine(); if (ImGui::Button("-###PointNoIdxDec")) { m_mapLoaderInfo.pointNoIdx--; if (m_mapLoaderInfo.pointNoIdx < 0) { - m_mapLoaderInfo.pointNoIdx = room.numPoints - 1; + m_mapLoaderInfo.pointNoIdx = room.roomPoints.size() - 1; } } ImGui::SameLine(); if (ImGui::Button("+###PointNoIdxInc")) { m_mapLoaderInfo.pointNoIdx++; - if (m_mapLoaderInfo.pointNoIdx >= room.numPoints) { + if (m_mapLoaderInfo.pointNoIdx >= room.roomPoints.size()) { m_mapLoaderInfo.pointNoIdx = 0; } }