50 lines
1.1 KiB
C

/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "map.h"
#include "assert/assert.h"
#include "util/memory.h"
shaderbuffer_t MAP_BUFFER;
mapdata_t MAP_DATA;
void mapInit() {
memoryZero(&MAP_DATA, sizeof(mapdata_t));
shaderBufferInit(&MAP_BUFFER, sizeof(mapdata_t));
assertTrue(
sizeof(MAP_DATA.tileIds) == sizeof(OVERWORLD.tileIds),
"Map shader tile data and Overworld tile data are not the same size."
);
}
void mapUpdate() {
// Copy tile ids.
memoryCopyRangeSafe(
MAP_DATA.tileIds,
OVERWORLD.tileIds,
&OVERWORLD.tileIds[
OVERWORLD.mapWidth * OVERWORLD.mapHeight * OVERWORLD.mapLayerCount
],
sizeof(MAP_DATA.tileIds)
);
// Copy map size.
memoryCopyRangeSafe(
&MAP_DATA.mapSize,
&OVERWORLD.mapWidth,
&OVERWORLD.mapLayerCount + sizeof(uint8_t),
sizeof(MAP_DATA.mapSize)
);
shaderBufferBind(&MAP_BUFFER);
shaderBufferSetData(&MAP_BUFFER, &MAP_DATA);
}
void mapDispose() {
shaderBufferDispose(&MAP_BUFFER);
}