Begin adding entities to editor
Some checks failed
Build Dusk / build-linux (push) Failing after 56s
Build Dusk / build-psp (push) Failing after 1m8s

This commit is contained in:
2025-11-22 10:38:16 -06:00
parent 3697cc3eef
commit 6f33522c1c
17 changed files with 261 additions and 56 deletions

View File

@@ -188,4 +188,13 @@ entity_t * entityGetAt(const worldpos_t position) {
} while(++ent, ent < &ENTITIES[ENTITY_COUNT]);
return NULL;
}
uint8_t entityGetAvailable() {
entity_t *ent = ENTITIES;
do {
if(ent->type == ENTITY_TYPE_NULL) return ent - ENTITIES;
} while(++ent, ent < &ENTITIES[ENTITY_COUNT]);
return 0xFF;
}

View File

@@ -11,8 +11,6 @@
#include "entitytype.h"
#include "npc.h"
#define ENTITY_COUNT 256
typedef struct map_s map_t;
typedef struct entity_s {
@@ -69,4 +67,11 @@ void entityWalk(entity_t *entity, const entitydir_t direction);
* @param pos The world position to check.
* @return Pointer to the entity at the position, or NULL if none.
*/
entity_t *entityGetAt(const worldpos_t pos);
entity_t *entityGetAt(const worldpos_t pos);
/**
* Gets an available entity index.
*
* @return The index of an available entity, or 0xFF if none are available.
*/
uint8_t entityGetAvailable();

View File

@@ -6,17 +6,11 @@
*/
#pragma once
#include "duskdefs.h"
#include "rpg/entity/player.h"
#include "npc.h"
typedef enum {
ENTITY_TYPE_NULL = 0,
ENTITY_TYPE_PLAYER,
ENTITY_TYPE_NPC,
ENTITY_TYPE_COUNT
} entitytype_t;
typedef uint8_t entitytype_t;
typedef union {
player_t player;

View File

@@ -13,6 +13,7 @@
#include "rpgcamera.h"
#include "rpgtextbox.h"
#include "util/memory.h"
#include "assert/assert.h"
errorret_t rpgInit(void) {
memoryZero(ENTITIES, sizeof(ENTITIES));
@@ -26,17 +27,14 @@ errorret_t rpgInit(void) {
rpgTextboxInit();
// TEST: Create some entities.
entity_t *ent;
ent = &ENTITIES[0];
uint8_t entIndex = entityGetAvailable();
assertTrue(entIndex != 0xFF, "No available entity slots!.");
entity_t *ent = &ENTITIES[entIndex];
entityInit(ent, ENTITY_TYPE_PLAYER);
RPG_CAMERA.mode = RPG_CAMERA_MODE_FOLLOW_ENTITY;
RPG_CAMERA.followEntity.followEntityId = ent->id;
ent->position.x = 2, ent->position.y = 2;
ent = &ENTITIES[1];
entityInit(ent, ENTITY_TYPE_NPC);
ent->position.x = 4, ent->position.y = 0, ent->position.z = 1;
// All Good!
errorOk();
}

View File

@@ -17,6 +17,7 @@ typedef struct chunk_s {
uint8_t meshCount;
meshvertex_t vertices[CHUNK_VERTEX_COUNT_MAX];
mesh_t meshes[CHUNK_MESH_COUNT_MAX];
uint8_t entities[CHUNK_ENTITY_COUNT_MAX];
} chunk_t;
/**

View File

@@ -9,6 +9,7 @@
#include "util/memory.h"
#include "assert/assert.h"
#include "asset/asset.h"
#include "rpg/entity/entity.h"
map_t MAP;
@@ -126,6 +127,11 @@ void mapDispose() {
}
void mapChunkUnload(chunk_t* chunk) {
for(uint8_t i = 0; i < CHUNK_ENTITY_COUNT_MAX; i++) {
if(chunk->entities[i] == 0xFF) break;
entity_t *entity = &ENTITIES[chunk->entities[i]];
entity->type = ENTITY_TYPE_NULL;
}
for(uint8_t i = 0; i < chunk->meshCount; i++) {
if(chunk->meshes[i].vertexCount == 0) continue;
meshDispose(&chunk->meshes[i]);
@@ -137,6 +143,7 @@ errorret_t mapChunkLoad(chunk_t* chunk) {
chunk->meshCount = 0;
memoryZero(chunk->meshes, sizeof(chunk->meshes));
memorySet(chunk->entities, 0xFF, sizeof(chunk->entities));
snprintf(buffer, sizeof(buffer), "map/map/%d_%d_%d.dcf",
chunk->position.x,