mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-07-11 13:08:33 -04:00
Fix map loader gameRegions literally being 2.7 MiB of recursive arrays
Just moving it to std::vector, easy enough.
This commit is contained in:
@@ -1,79 +1,67 @@
|
||||
#pragma once
|
||||
|
||||
struct RoomEntry {
|
||||
static constexpr int MAX_POINTS = 70;
|
||||
|
||||
u8 roomNo;
|
||||
s16 roomPoints[MAX_POINTS] = {};
|
||||
int numPoints;
|
||||
std::vector<s16> roomPoints = {};
|
||||
|
||||
constexpr RoomEntry() : roomNo(0), numPoints(0) {}
|
||||
constexpr RoomEntry() : roomNo(0) {}
|
||||
constexpr RoomEntry(const RoomEntry& other) = default;
|
||||
|
||||
template <int N>
|
||||
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<RoomEntry> mapRooms = {};
|
||||
|
||||
constexpr MapEntry() : mapName(nullptr), mapFile(nullptr), numRooms(0) {}
|
||||
constexpr MapEntry() : mapName(nullptr), mapFile(nullptr) {}
|
||||
constexpr MapEntry(const MapEntry& other) = default;
|
||||
|
||||
template <int N>
|
||||
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 <int N>
|
||||
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<MapEntry> maps = {};
|
||||
|
||||
template <int N>
|
||||
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",
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user