Prepping map stuff

This commit is contained in:
2025-11-11 12:25:46 -06:00
parent 26bfb912f1
commit 5adf8a0773
16 changed files with 249 additions and 175 deletions

View File

@@ -9,6 +9,7 @@
#include "scene/scenedata.h"
#include "display/spritebatch.h"
#include "assert/assert.h"
#include "asset/asset.h"
#include "rpg/entity/entity.h"
#include "rpg/world/map.h"
#include "display/screen.h"
@@ -16,6 +17,7 @@
#include "util/memory.h"
#define TILE_SIZE 16
assetmapmodel_t mesh;
errorret_t sceneMapInit(scenedata_t *data) {
// Init the camera.
@@ -34,6 +36,8 @@ errorret_t sceneMapInit(scenedata_t *data) {
);
data->sceneMap.camera.lookatPixelPerfect.pixelsPerUnit = 1.0f;
errorChain(assetLoad("map/map.dmf", &mesh));
errorOk();
}
@@ -61,15 +65,18 @@ void sceneMapEntityGetPosition(const entity_t *entity, vec3 outPosition) {
float_t animPercentage = entity->animTime / ENTITY_ANIM_WALK_DURATION;
// Get facing rel, we know we moved from the inverse direction.
worldunits_t x, y;
entityDirGetRelative(entity->direction, &x, &y);
x = -x, y = -y;
// Add tile size times percentage to posMin/max
vec3 offset = {
x * TILE_SIZE * animPercentage,
y * TILE_SIZE * animPercentage,
0.0f
(
(float_t)entity->position.x - (float_t)entity->lastPosition.x
) * TILE_SIZE * -animPercentage,
(
(float_t)entity->position.y - (float_t)entity->lastPosition.y
) * TILE_SIZE * -animPercentage,
(
(float_t)entity->position.z - (float_t)entity->lastPosition.z
) * TILE_SIZE * -animPercentage
};
glm_vec3_add(outPosition, offset, outPosition);
break;
@@ -107,7 +114,10 @@ void sceneMapRender(scenedata_t *data) {
cameraPushMatrix(&data->sceneMap.camera);
// Render map probably.
sceneMapRenderMap();
// sceneMapRenderMap();
textureBind(NULL);
meshDraw(&mesh.mesh, -1, -1);
// Render ents
entity_t *ent = ENTITIES;
@@ -125,11 +135,10 @@ void sceneMapRenderEntity(entity_t *entity) {
if(entity->type == ENTITY_TYPE_NULL) return;
vec3 posCenter, posMin, posMax;
vec3 halfSize = { TILE_SIZE / 2.0f, TILE_SIZE / 2.0f, TILE_SIZE / 2.0f };
sceneMapEntityGetPosition(entity, posCenter);
glm_vec3_sub(posCenter, halfSize, posMin);
glm_vec3_add(posCenter, halfSize, posMax);
vec3 posMin, posMax;
vec3 size = { TILE_SIZE, TILE_SIZE, TILE_SIZE };
sceneMapEntityGetPosition(entity, posMin);
glm_vec3_add(posMin, size, posMax);
// TEST: Change color depending on dir.
color_t testColor;
@@ -167,11 +176,6 @@ void sceneMapRenderMap() {
min[1] = chunk->position.y * CHUNK_HEIGHT * TILE_SIZE;
min[2] = chunk->position.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];
@@ -195,4 +199,5 @@ void sceneMapRenderMap() {
}
void sceneMapDispose(scenedata_t *data) {
meshDispose(&mesh.mesh);
}