Map loading and rendering

This commit is contained in:
2025-11-09 13:00:43 -06:00
parent 307f3a9dec
commit 5a8710cc76
6 changed files with 57 additions and 12 deletions

View File

@@ -10,6 +10,7 @@
#include "display/spritebatch.h"
#include "assert/assert.h"
#include "rpg/entity/entity.h"
#include "rpg/world/map.h"
#include "display/screen.h"
#include "rpg/rpgcamera.h"
#include "util/memory.h"
@@ -80,7 +81,6 @@ void sceneMapEntityGetPosition(const entity_t *entity, vec3 outPosition) {
}
}
void sceneMapRender(scenedata_t *data) {
// Look at target.
vec3 cameraTarget;
@@ -108,6 +108,9 @@ void sceneMapRender(scenedata_t *data) {
// Push camera
cameraPushMatrix(&data->sceneMap.camera);
// Render map probably.
sceneMapRenderMap();
// Render ents
entity_t *ent = ENTITIES;
do {
@@ -119,6 +122,8 @@ void sceneMapRender(scenedata_t *data) {
cameraPopMatrix();
}
void sceneMapRenderEntity(entity_t *entity) {
assertNotNull(entity, "Entity cannot be NULL");
@@ -156,5 +161,43 @@ void sceneMapRenderEntity(entity_t *entity) {
spriteBatchPush3D(NULL, posMin, posMax, testColor, uv0, uv1);
}
void sceneMapRenderMap() {
// For each chunk.
for(uint32_t i = 0; i < MAP_CHUNK_COUNT; i++) {
chunk_t *chunk = MAP.chunkOrder[i];
vec3 min, max;
min[0] = chunk->x * CHUNK_WIDTH * TILE_SIZE;
min[1] = chunk->y * CHUNK_HEIGHT * TILE_SIZE;
min[2] = chunk->z * CHUNK_DEPTH * TILE_SIZE;
// center tile
min[0] -= TILE_SIZE / 2.0f;
min[1] -= TILE_SIZE / 2.0f;
min[2] -= TILE_SIZE / 2.0f;
max[0] = min[0] + (CHUNK_WIDTH * TILE_SIZE);
max[1] = min[1] + (CHUNK_HEIGHT * TILE_SIZE);
max[2] = min[2];
color_t color = COLOR_WHITE;
if(chunk->x % 2 == 0) {
color = (chunk->y % 2 == 0) ? COLOR_BLACK : COLOR_WHITE;
} else {
color = (chunk->y % 2 == 0) ? COLOR_WHITE : COLOR_BLACK;
}
spriteBatchPush3D(
NULL,
min,
max,
color,
(vec2){ 0.0f, 0.0f },
(vec2){ 1.0f, 1.0f }
);
}
}
void sceneMapDispose(scenedata_t *data) {
}

View File

@@ -18,6 +18,7 @@ errorret_t sceneMapInit(scenedata_t *data);
void sceneMapUpdate(scenedata_t *data);
void sceneMapRender(scenedata_t *data);
void sceneMapRenderEntity(entity_t *entity);
void sceneMapRenderMap();
void sceneMapDispose(scenedata_t *data);
static scene_t SCENE_MAP = {