PastelChime2.DungeonDataLoad: Remove hardcoded dungeon dimensions

Replaced the hardcoded 40x3x40 dungeon size with dimensions read
dynamically from the `m_dsd` data structure. This allows for loading
dungeons of various sizes.
This commit is contained in:
kichikuou
2025-09-26 10:24:15 +09:00
parent 199c91dd6c
commit fe61704b90
+10 -5
View File
@@ -391,22 +391,27 @@ static bool PastelChime2_DungeonDataLoad(int id, struct page **dungeon)
return false;
}
int slot_m_dsd = find_struct_slot(&ain->structures[(*dungeon)->index], "m_dsd");
variable_set(*dungeon, slot_m_dsd, AIN_STRUCT, vm_int(heap_alloc_page(read_struct(&r, true))));
struct page *m_dsd = read_struct(&r, true);
variable_set(*dungeon, slot_m_dsd, AIN_STRUCT, vm_int(heap_alloc_page(m_dsd)));
struct page *map_size = heap_get_page(struct_get_var(m_dsd, "xyzMapSize")->i);
int size_x = struct_get_var(map_size, "x")->i;
int size_y = struct_get_var(map_size, "y")->i;
int size_z = struct_get_var(map_size, "z")->i;
// Read dungeon cells
int index = 0;
if (ctx->dgn)
dgn_free(ctx->dgn);
ctx->dgn = dgn_new(40, 3, 40);
ctx->dgn = dgn_new(size_x, size_y, size_z);
while (buffer_remaining(&r) > 0) {
int count = buffer_read_u8(&r) + 1;
uint8_t cell_buf[128];
buffer_read_bytes(&r, cell_buf, sizeof(cell_buf));
while (--count >= 0) {
int y = index / (40 * 40);
int z = (index / 40) % 40;
int x = index % 40;
int y = index / (size_x * size_z);
int z = (index / size_x) % size_z;
int x = index % size_x;
index++;
struct dgn_cell *cell = dgn_cell_at(ctx->dgn, x, y, z);
struct buffer cr;