diff options
| author | nathan <nathansmith@disroot.org> | 2025-10-26 00:10:58 +0000 |
|---|---|---|
| committer | nathan <nathansmith@disroot.org> | 2025-10-26 00:10:58 +0000 |
| commit | 5925230971875ba3e6e591f0655cf84b739b50fc (patch) | |
| tree | a08383647602ec9afc4cce49da4f25242e9e236b | |
| parent | 361c596fa09e9bac1d256ee21da63e352d796fa3 (diff) | |
| download | FindThings-5925230971875ba3e6e591f0655cf84b739b50fc.tar.gz FindThings-5925230971875ba3e6e591f0655cf84b739b50fc.tar.bz2 FindThings-5925230971875ba3e6e591f0655cf84b739b50fc.zip | |
New entity system is working (:
| -rw-r--r-- | src/entities/bush.c | 4 | ||||
| -rw-r--r-- | src/entities/bush.h | 1 | ||||
| -rw-r--r-- | src/entities/flower.c | 4 | ||||
| -rw-r--r-- | src/entities/flower.h | 1 | ||||
| -rw-r--r-- | src/entities/tree.c | 4 | ||||
| -rw-r--r-- | src/entities/tree.h | 1 | ||||
| -rw-r--r-- | src/entitiesInclude.h | 14 | ||||
| -rw-r--r-- | src/entity.c | 184 | ||||
| -rw-r--r-- | src/entity.h | 37 | ||||
| -rw-r--r-- | src/player.c | 2 | ||||
| -rw-r--r-- | src/world.c | 9 |
11 files changed, 85 insertions, 176 deletions
diff --git a/src/entities/bush.c b/src/entities/bush.c index 884ffef..2fc5f6a 100644 --- a/src/entities/bush.c +++ b/src/entities/bush.c @@ -2,11 +2,11 @@ void initBush(Entity* entity) { - entity->box = entityBoxFromScale(1.0, BUSH_WIDTH, BUSH_HEIGHT); + entity->box = entityBoxFromScale(BUSH_SCALE, BUSH_WIDTH, BUSH_HEIGHT); } void updateBush(Entity* entity, Game* game) { DrawBillboard(game->player.camera, game->assets.textures[BUSH_TEXTURE], - entity->position, 1.0, WHITE); + entity->position, BUSH_SCALE, WHITE); } diff --git a/src/entities/bush.h b/src/entities/bush.h index 70ac282..a46d439 100644 --- a/src/entities/bush.h +++ b/src/entities/bush.h @@ -4,6 +4,7 @@ #ifndef BUSH_H #define BUSH_H +#define BUSH_SCALE 3.0 #define BUSH_WIDTH 87.0 #define BUSH_HEIGHT 62.0 diff --git a/src/entities/flower.c b/src/entities/flower.c index 00f27fc..89378bb 100644 --- a/src/entities/flower.c +++ b/src/entities/flower.c @@ -2,11 +2,11 @@ void initFlower(Entity* entity) { - entity->box = entityBoxFromScale(1.0, FLOWER_WIDTH, FLOWER_HEIGHT); + entity->box = entityBoxFromScale(FLOWER_SCALE, FLOWER_WIDTH, FLOWER_HEIGHT); } void updateFlower(Entity* entity, Game* game) { DrawBillboard(game->player.camera, game->assets.textures[FLOWER_TEXTURE], - entity->position, 1.0, WHITE); + entity->position, FLOWER_SCALE, WHITE); } diff --git a/src/entities/flower.h b/src/entities/flower.h index de33197..279c162 100644 --- a/src/entities/flower.h +++ b/src/entities/flower.h @@ -4,6 +4,7 @@ #ifndef FLOWER_H #define FLOWER_H +#define FLOWER_SCALE 3.0 #define FLOWER_WIDTH 32.0 #define FLOWER_HEIGHT 54.0 diff --git a/src/entities/tree.c b/src/entities/tree.c index 7db5842..9f89b8f 100644 --- a/src/entities/tree.c +++ b/src/entities/tree.c @@ -2,11 +2,11 @@ void initTree(Entity* entity) { - entity->box = entityBoxFromScale(1.0, TREE_WIDTH, TREE_HEIGHT); + entity->box = entityBoxFromScale(TREE_SCALE, TREE_WIDTH, TREE_HEIGHT); } void updateTree(Entity* entity, Game* game) { DrawBillboard(game->player.camera, game->assets.textures[TREE_TEXTURE], - entity->position, 1.0, WHITE); + entity->position, TREE_SCALE, WHITE); } diff --git a/src/entities/tree.h b/src/entities/tree.h index 59b32ba..1c0e7d8 100644 --- a/src/entities/tree.h +++ b/src/entities/tree.h @@ -4,6 +4,7 @@ #ifndef TREE_H #define TREE_H +#define TREE_SCALE 40.0 #define TREE_WIDTH 113.0 #define TREE_HEIGHT 250.0 diff --git a/src/entitiesInclude.h b/src/entitiesInclude.h new file mode 100644 index 0000000..1a10068 --- /dev/null +++ b/src/entitiesInclude.h @@ -0,0 +1,14 @@ +#include "entities/bush.h" +#include "entities/flower.h" +#include "entities/john.h" +#include "entities/medicalTrash.h" +#include "entities/oldMint.h" +#include "entities/pond.h" +#include "entities/ron.h" +#include "entities/samantha.h" +#include "entities/samanthasSpot.h" +#include "entities/stickyNickel.h" +#include "entities/trash.h" +#include "entities/trashcan.h" +#include "entities/tree.h" +#include "entities/utilityPole.h" diff --git a/src/entity.c b/src/entity.c index caba91a..aff0295 100644 --- a/src/entity.c +++ b/src/entity.c @@ -1,7 +1,22 @@ #include "entity.h" #include "game.h" +#include "entitiesInclude.h" const EntityEntry entityEntries[ENTITY_COUNT] = { + (EntityEntry){initOldMint, updateOldMint, NULL, false, true}, + (EntityEntry){initStickyNickel, updateStickyNickel, NULL, false, true}, + (EntityEntry){initTree, updateTree, NULL, false, true}, + (EntityEntry){initBush, updateBush, NULL, false, true}, + (EntityEntry){initFlower, updateFlower, NULL, false, true}, + (EntityEntry){initPond, updatePond, NULL, true, true}, + (EntityEntry){initUtilityPole, NULL, NULL, false, false}, + (EntityEntry){initSamantha, updateSamantha, NULL, false, true}, + (EntityEntry){initSamanthasSpot, updateSamanthasSpot, NULL, true, false}, + (EntityEntry){initTrashcan, updateTrashcan, NULL, false, true}, + (EntityEntry){initTrash, updateTrash, NULL, false, true}, + (EntityEntry){initMedicalTrash, updateMedicalTrash, NULL, false, true}, + (EntityEntry){initJohn, updateJohn, NULL, false, true}, + (EntityEntry){initRon, updateRon, NULL, false, true} }; Entity createEntity(EntityId id, Vector3 position) @@ -11,78 +26,12 @@ Entity createEntity(EntityId id, Vector3 position) entity.state = ENTITY_DEFAULT_STATE; entity.data = NULL; - // Bounding boxes. - switch (id) - { - case OLD_MINT: - case STICKY_NICKEL: - entity.box = entityBoxFromScale(1.0, 32.0, 32.0); - break; - case TREE: - entity.box = entityBoxFromScale(TREE_SCALE, 113.0, 250.0); - break; - case BUSH: - entity.box = entityBoxFromScale(BUSH_SCALE, 87.0, 62.0); - break; - case FLOWER: - entity.box = entityBoxFromScale(FLOWER_SCALE, 32.0, 54.0); - break; - case POND: - entity.box = (BoundingBox){ - .min = (Vector3){-POND_SIZE, -POND_HEIGHT, -POND_SIZE}, - .max = (Vector3){POND_SIZE, POND_HEIGHT, POND_SIZE} - }; - - break; - case UTILITY_POLE: - entity.box = (BoundingBox){ - .min = (Vector3){-UTILITY_POLE_RADIUS, -UTILITY_POLE_HEIGHT, - -UTILITY_POLE_RADIUS}, - .max = (Vector3){UTILITY_POLE_RADIUS, UTILITY_POLE_HEIGHT, - UTILITY_POLE_RADIUS}, - }; + // Run init callback. + InitEntityCallback initCallback = entityEntries[id].initCallback; - break; - case SAMANTHA: - entity.box = (BoundingBox){ - .min = (Vector3){-SAMANTHA_WIDTH, -SAMANTHA_HEIGHT, -SAMANTHA_THICKNESS}, - .max = (Vector3){SAMANTHA_WIDTH, SAMANTHA_HEIGHT, SAMANTHA_THICKNESS} - }; - - break; - case SAMANTHAS_SPOT: - entity.box = (BoundingBox){ - .min = (Vector3){-SAMANTHAS_SPOT_SIZE, -SAMANTHAS_SPOT_HEIGHT, - -SAMANTHAS_SPOT_SIZE}, - .max = (Vector3){SAMANTHAS_SPOT_SIZE, SAMANTHAS_SPOT_HEIGHT, - SAMANTHAS_SPOT_SIZE}, - }; - - break; - case TRASHCAN: - entity.box = entityBoxFromScale(TRASHCAN_SCALE, TRASHCAN_WIDTH, - TRASHCAN_HEIGHT); - break; - case TRASH: - entity.box = entityBoxFromScale(TRASH_SCALE, 202.0, 122.0); - break; - - case MEDICAL_TRASH: - entity.box = entityBoxFromScale(MEDICAL_TRASH_SCALE, 200.0, 132.0); - break; - // TODO: do the thing - case JOHN: - case RON: // John and Ron ARE NOT the same person. - entity.box = (BoundingBox){ - .min = (Vector3){-SHOPKEEPER_WIDTH, -SHOPKEEPER_HEIGHT, - -SHOPKEEPER_THICKNESS}, - .max = (Vector3){SHOPKEEPER_WIDTH, SHOPKEEPER_HEIGHT, - SHOPKEEPER_THICKNESS} - }; - - break; - default: - break; + if (initCallback != NULL) + { + initCallback(&entity); } entity.position = Vector3Zero(); @@ -92,65 +41,32 @@ Entity createEntity(EntityId id, Vector3 position) void updateEntity(Entity* entity, Game* game) { - //DrawBoundingBox(entity->box, RED); + //DrawBoundingBox(entity->box, BLUE); + + UpdateEntityCallback updateCallback = + entityEntries[entity->id].updateCallback; + + if (updateCallback != NULL) + { + updateCallback(entity, game); + } +} + +void closeEntity(Entity* entity) +{ + if (entity->id == ENTITY_NONE) + { + return; + } - switch (entity->id) + CloseEntityCallback closeCallback = entityEntries[entity->id].closeCallback; + + if (closeCallback != NULL) { - case OLD_MINT: - DrawBillboard(game->player.camera, game->assets.textures[MINT_TEXTURE], - entity->position, 1.0, WHITE); - break; - case STICKY_NICKEL: - DrawBillboard(game->player.camera, game->assets.textures[NICKEL_TEXTURE], - entity->position, 1.0, WHITE); - break; - case TREE: - DrawBillboard(game->player.camera, game->assets.textures[TREE_TEXTURE], - entity->position, TREE_SCALE, WHITE); - break; - case BUSH: - DrawBillboard(game->player.camera, game->assets.textures[BUSH_TEXTURE], - entity->position, BUSH_SCALE, WHITE); - break; - case FLOWER: - DrawBillboard(game->player.camera, game->assets.textures[FLOWER_TEXTURE], - entity->position, FLOWER_SCALE, WHITE); - break; - case POND: - DrawPlane( - Vector3Add(entity->position, (Vector3){0.0, POND_HEIGHT, 0.0}), - (Vector2){POND_SIZE * 2.5, POND_SIZE * 2.5}, BLUE); - break; - case SAMANTHA: - //updateSamantha(entity, game); - break; - case SAMANTHAS_SPOT: - DrawModel(game->world.samanthasSpotFloor, - Vector3Add(entity->position, - (Vector3){0.0, -SAMANTHAS_SPOT_HEIGHT + 0.01, 0.0}), - 1.0, WHITE); - break; - case TRASHCAN: - //updateTrashcan(entity, game); - break; - case TRASH: - DrawBillboard(game->player.camera, game->assets.textures[TRASH_TEXTURE], - entity->position, TRASH_SCALE, WHITE); - break; - case MEDICAL_TRASH: - DrawBillboard(game->player.camera, - game->assets.textures[MEDICAL_TRASH_TEXTURE], - entity->position, MEDICAL_TRASH_SCALE, WHITE); - break; - case JOHN: - DrawModel(game->assets.models[JOHN_MODEL], entity->position, 1.0, WHITE); - break; - case RON: - DrawModel(game->assets.models[RON_MODEL], entity->position, 1.0, WHITE); - break; - default: - break; + closeCallback(entity); } + + entity->id = ENTITY_NONE; } void setEntityPosition(Entity* entity, Vector3 position) @@ -172,15 +88,14 @@ void placeEntityOnGround(Entity* entity, const World* world) setEntityPosition(entity, position); } +bool entityIsPlace(EntityId id) +{ + return entityEntries[id].isPlace; +} + bool entityCanBeSelected(EntityId id) { - switch (id) - { - case SAMANTHAS_SPOT: - return false; - default: - return true; - } + return entityEntries[id].canBeSelected; } InteractionCommand interactWithOldMint(Entity* entity, Game* game, @@ -221,4 +136,3 @@ BoundingBox entityBoxFromScale(float scale, float width, float height) .max = (Vector3){size.x, size.y, size.x} }; } - diff --git a/src/entity.h b/src/entity.h index 3170059..a394d7a 100644 --- a/src/entity.h +++ b/src/entity.h @@ -7,39 +7,6 @@ #define ENTITY_COUNT 14 -#define TREE_SCALE 40.0 -#define BUSH_SCALE 3.0 -#define FLOWER_SCALE 3.0 - -#define POND_SIZE 250.0 -#define POND_HEIGHT 15.0 - -#define UTILITY_POLE_HEIGHT 100.0 -#define UTILITY_POLE_RADIUS 3.0 - -#define SAMANTHA_WIDTH (2.65966 / 2.0) -#define SAMANTHA_HEIGHT (3.21054 / 2.0) -#define SAMANTHA_THICKNESS (1.46845 / 2.0) -#define SAMANTHA_STATIC_SPEED 24 -#define SAMANTHA_STATIC_FRAMES 4 - -#define SAMANTHAS_SPOT_SIZE 10 -#define SAMANTHAS_SPOT_HEIGHT 5 - -#define TRASHCAN_SCALE 2.0 -#define TRASHCAN_FRAMES 4 -#define TRASHCAN_ANIMATION_SPEED 6 -#define TRASHCAN_WIDTH 45.0 -#define TRASHCAN_HEIGHT 60.0 - -#define TRASH_SCALE 2.0 - -#define MEDICAL_TRASH_SCALE 2.0 - -#define SHOPKEEPER_WIDTH (2.04211 / 2.0) -#define SHOPKEEPER_HEIGHT (2.59521 / 2.0) -#define SHOPKEEPER_THICKNESS (0.493349 / 2.0) - #define INTERACTION_MENU_MAX 9 #define INTERACTION_LABEL_MAX 64 #define ENTITY_DEFAULT_STATE -1 @@ -109,8 +76,12 @@ extern const EntityEntry entityEntries[ENTITY_COUNT]; Entity createEntity(EntityId id, Vector3 position); void updateEntity(Entity* entity, Game* game); +void closeEntity(Entity* entity); + void setEntityPosition(Entity* entity, Vector3 position); void placeEntityOnGround(Entity* entity, const World* world); + +bool entityIsPlace(EntityId id); bool entityCanBeSelected(EntityId id); InteractionCommand interactWithEntity(Entity* entity, Game* game, diff --git a/src/player.c b/src/player.c index 5c1c150..4fe468e 100644 --- a/src/player.c +++ b/src/player.c @@ -93,7 +93,7 @@ void updatePlayer(Player* player, Game* game) int tests; WorldUID uid = castRayAtWorld(&game->world, ray, false, &tests); - printf("%d\n", tests); + //printf("%d\n", tests); if (uid != -1) { diff --git a/src/world.c b/src/world.c index dd76cf8..5ffec66 100644 --- a/src/world.c +++ b/src/world.c @@ -1,6 +1,7 @@ #include "world.h" #include "game.h" #include "entity.h" +#include "entitiesInclude.h" size_t buildWorldBVHLeafs(BVHNode leafs[WORLD_ENTITY_MAX], const World* world) { @@ -873,6 +874,12 @@ void freeWorld(World world) UnloadModel(world.heightmap); UnloadModel(world.samanthasSpotFloor); freeWorldBVH(world.bvh); + + // Close the entities. + for (int index = 0; index < WORLD_ENTITY_MAX; ++index) + { + closeEntity(&world.entities[index]); + } } Vector2 worldPositionToPixel(const World* world, float x, float y) @@ -963,7 +970,7 @@ void castRayBVH(const World* world, BVHNode node, Ray ray, bool allowAll, world->entities[node.entities[index]].position, ray.position); - // Don't include places. + // Don't include things that can't be selected. if (!allowAll && !entityCanBeSelected(world->entities[node.entities[index]].id)) { |
