Cleaned map a bit

This commit is contained in:
2025-03-04 11:50:47 -06:00
parent ad9e8a78d3
commit f19636edb1
13 changed files with 192 additions and 134 deletions

View File

@ -8,5 +8,5 @@ target_sources(${DUSK_TARGET_NAME}
PRIVATE
transforms.c
entities.c
map.c
mapshaderdata.c
)

View File

@ -1,50 +0,0 @@
/**
* 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);
}

View File

@ -0,0 +1,50 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "mapshaderdata.h"
#include "assert/assert.h"
#include "util/memory.h"
shaderbuffer_t MAP_SHADER_DATA_BUFFER;
mapshaderdata_t MAP_SHADER_DATA_DATA;
void mapShaderDataInit() {
memoryZero(&MAP_SHADER_DATA_DATA, sizeof(mapshaderdata_t));
shaderBufferInit(&MAP_SHADER_DATA_BUFFER, sizeof(mapshaderdata_t));
assertTrue(
sizeof(MAP_SHADER_DATA_DATA.tileIds) == sizeof(OVERWORLD.map.tileIds),
"Map shader tile data and Overworld tile data are not the same size."
);
}
void mapShaderDataUpdate() {
// Copy tile ids.
memoryCopyRangeSafe(
MAP_SHADER_DATA_DATA.tileIds,
OVERWORLD.map.tileIds,
&OVERWORLD.map.tileIds[
OVERWORLD.map.width * OVERWORLD.map.height * OVERWORLD.map.layerCount
],
sizeof(MAP_SHADER_DATA_DATA.tileIds)
);
// Copy map size.
memoryCopyRangeSafe(
&MAP_SHADER_DATA_DATA.mapSize,
&OVERWORLD.map.width,
&OVERWORLD.map.layerCount + sizeof(uint8_t),
sizeof(MAP_SHADER_DATA_DATA.mapSize)
);
shaderBufferBind(&MAP_SHADER_DATA_BUFFER);
shaderBufferSetData(&MAP_SHADER_DATA_BUFFER, &MAP_SHADER_DATA_DATA);
}
void mapShaderDataDispose() {
shaderBufferDispose(&MAP_SHADER_DATA_BUFFER);
}

View File

@ -16,22 +16,22 @@ typedef struct {
uvec4_t tileIds[OVERWORLD_TILE_COUNT_MAX / MAP_TILE_PACK_SIZE];
uint_t mapSize;
uvec3_t _p0;
} mapdata_t;
} mapshaderdata_t;
extern shaderbuffer_t MAP_BUFFER;
extern mapdata_t MAP_DATA;
extern shaderbuffer_t MAP_SHADER_DATA_BUFFER;
extern mapshaderdata_t MAP_SHADER_DATA_DATA;
/**
* Initializes the map buffer and data.
*/
void mapInit();
void mapShaderDataInit();
/**
* Updates the map buffer with the current data.
*/
void mapUpdate();
void mapShaderDataUpdate();
/**
* Destroys the map buffer.
*/
void mapDispose();
void mapShaderDataDispose();

View File

@ -7,7 +7,7 @@
#include "mapshader.h"
#include "util/memory.h"
#include "display/shader/data/map.h"
#include "display/shader/data/mapshaderdata.h"
#include "display/shader/data/transforms.h"
#include "map_vert.glsl.h"
#include "map_frag.glsl.h"
@ -37,7 +37,7 @@ void mapShaderInit() {
void mapShaderUse() {
shaderUse(&MAP_SHADER.shader);
shaderBufferBindToBlock(&MAP_BUFFER, MAP_SHADER.mapBlock);
shaderBufferBindToBlock(&MAP_SHADER_DATA_BUFFER, MAP_SHADER.mapBlock);
shaderBufferBindToBlock(&TRANSFORMS_BUFFER, MAP_SHADER.transformsBlock);
}

View File

@ -9,14 +9,14 @@
#include "assert/assert.h"
#include "display/shader/data/transforms.h"
#include "display/shader/data/entities.h"
#include "display/shader/data/map.h"
#include "display/shader/data/mapshaderdata.h"
#include "display/shader/entityshader/entityshader.h"
#include "display/shader/mapshader/mapshader.h"
shadermanagerdatacallback_t SHADER_MANAGER_DATA_CALLBACKS[] = {
{ transformsInit, transformsUpdate, transformsDispose },
{ entitiesInit, entitiesUpdate, entitiesDispose },
{ mapInit, mapUpdate, mapDispose }
{ mapShaderDataInit, mapShaderDataUpdate, mapShaderDataDispose }
};