From 32e795acb0c60a320b8449a3b7b6ee5fb5779c12 Mon Sep 17 00:00:00 2001 From: nathan Date: Sat, 25 Oct 2025 17:18:08 -0600 Subject: Switching to better entity system --- src/entity.h | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'src/entity.h') diff --git a/src/entity.h b/src/entity.h index 9727e51..3170059 100644 --- a/src/entity.h +++ b/src/entity.h @@ -45,7 +45,13 @@ #define ENTITY_DEFAULT_STATE -1 typedef int8_t EntityId; -typedef int8_t EntityState; +typedef int16_t EntityState; + +typedef struct Entity Entity; +typedef void (*InteractionCallback)(Entity* entity, Game* game); +typedef void (*InitEntityCallback)(Entity* entity); +typedef void (*UpdateEntityCallback)(Entity* entity, Game* game); +typedef void (*CloseEntityCallback)(Entity* entity); enum { ENTITY_NONE = -1, @@ -78,20 +84,29 @@ typedef enum { SELECTION_LEAVE } Selection; -typedef struct { +struct Entity { EntityId id; Vector3 position; // Shouldnt be changed directly. BoundingBox box; EntityState state; -} Entity; + void* data; +}; -typedef void (*InteractionCallback)(Entity* entity, Game* game); +typedef struct { + InitEntityCallback initCallback; + UpdateEntityCallback updateCallback; + CloseEntityCallback closeCallback; + bool isPlace; + bool canBeSelected; +} EntityEntry; typedef struct { char label[INTERACTION_LABEL_MAX]; InteractionCallback callback; } InteractionMenuEntry; +extern const EntityEntry entityEntries[ENTITY_COUNT]; + Entity createEntity(EntityId id, Vector3 position); void updateEntity(Entity* entity, Game* game); void setEntityPosition(Entity* entity, Vector3 position); @@ -101,4 +116,6 @@ bool entityCanBeSelected(EntityId id); InteractionCommand interactWithEntity(Entity* entity, Game* game, Selection selection); +BoundingBox entityBoxFromScale(float scale, float width, float height); + #endif -- cgit v1.2.3