diff options
| author | nathan <nathansmith@disroot.org> | 2025-12-26 14:14:54 +0000 |
|---|---|---|
| committer | nathan <nathansmith@disroot.org> | 2025-12-26 14:14:54 +0000 |
| commit | c9ae1941816183553c8c4313eac27cc831cbefba (patch) | |
| tree | 053ab2ca0819f3c9021574bcce9a24fc69cadc95 | |
| parent | a5443e22bfce9ac00fdc6e746e17eb4aa68565f2 (diff) | |
| download | FindThings-c9ae1941816183553c8c4313eac27cc831cbefba.tar.gz FindThings-c9ae1941816183553c8c4313eac27cc831cbefba.tar.bz2 FindThings-c9ae1941816183553c8c4313eac27cc831cbefba.zip | |
Working on buildings
| -rw-r--r-- | src/entities/johnsStore.c | 13 | ||||
| -rw-r--r-- | src/entities/johnsStore.h | 11 | ||||
| -rw-r--r-- | src/entitiesInclude.h | 1 | ||||
| -rw-r--r-- | src/entity.c | 211 | ||||
| -rw-r--r-- | src/entity.h | 16 | ||||
| -rw-r--r-- | src/utils.c | 32 | ||||
| -rw-r--r-- | src/utils.h | 2 |
7 files changed, 264 insertions, 22 deletions
diff --git a/src/entities/johnsStore.c b/src/entities/johnsStore.c new file mode 100644 index 0000000..85f6303 --- /dev/null +++ b/src/entities/johnsStore.c @@ -0,0 +1,13 @@ +#include "johnsStore.h" + +void initJohnsStore(Entity* entity) +{ +} + +void updateJohnsStore(Entity* entity, Game* game) +{ +} + +void closeJohnsStore(Entity* entity) +{ +} diff --git a/src/entities/johnsStore.h b/src/entities/johnsStore.h new file mode 100644 index 0000000..d70e99f --- /dev/null +++ b/src/entities/johnsStore.h @@ -0,0 +1,11 @@ +#include "game.h" +#include "entity.h" + +#ifndef JOHNS_STORE_H +#define JOHNS_STORE_H + +void initJohnsStore(Entity* entity); +void updateJohnsStore(Entity* entity, Game* game); +void closeJohnsStore(Entity* entity); + +#endif diff --git a/src/entitiesInclude.h b/src/entitiesInclude.h index 1a10068..05ec2d0 100644 --- a/src/entitiesInclude.h +++ b/src/entitiesInclude.h @@ -1,6 +1,7 @@ #include "entities/bush.h" #include "entities/flower.h" #include "entities/john.h" +#include "entities/johnsStore.h" #include "entities/medicalTrash.h" #include "entities/oldMint.h" #include "entities/pond.h" diff --git a/src/entity.c b/src/entity.c index e25cc90..f6d51bf 100644 --- a/src/entity.c +++ b/src/entity.c @@ -3,27 +3,156 @@ #include "entitiesInclude.h" const EntityEntry entityEntries[ENTITY_COUNT] = { - (EntityEntry){"Old Mint", initOldMint, updateOldMint, NULL, NULL, false, - true}, - (EntityEntry){"Sticky Nickel", initStickyNickel, updateStickyNickel, NULL, - NULL, false, true}, - (EntityEntry){"Tree", initTree, updateTree, NULL, NULL, false, true}, - (EntityEntry){"Bush", initBush, updateBush, NULL, NULL, false, true}, - (EntityEntry){"Flower", initFlower, updateFlower, NULL, NULL, false, true}, - (EntityEntry){"Pond", initPond, updatePond, NULL, NULL, true, true}, - (EntityEntry){"Utility Pole", initUtilityPole, NULL, NULL, NULL, false, - false}, - (EntityEntry){"Samantha", initSamantha, updateSamantha, closeSamantha, - interactWithSamantha, false, true}, - (EntityEntry){"Samantha's Spot", initSamanthasSpot, updateSamanthasSpot, - NULL, NULL, true, false}, - (EntityEntry){"Trashcan", initTrashcan, updateTrashcan, NULL, NULL, false, - true}, - (EntityEntry){"Trash", initTrash, updateTrash, NULL, NULL, false, true}, - (EntityEntry){"Medical Trash", initMedicalTrash, updateMedicalTrash, NULL, - NULL, false, true}, - (EntityEntry){"John", initJohn, updateJohn, NULL, NULL, false, true}, - (EntityEntry){"Ron", initRon, updateRon, NULL, interactWithRon, false, true} + (EntityEntry){ + .name = "Old Mint", + .initCallback = initOldMint, + .updateCallback = updateOldMint, + .closeCallback = NULL, + .interactionCallback = NULL, + .isPlace = false, + .isBuilding = false, + .canBeSelected = true + }, + (EntityEntry){ + .name = "Sticky Nickel", + .initCallback = initStickyNickel, + .updateCallback = updateStickyNickel, + .closeCallback = NULL, + .interactionCallback = NULL, + .isPlace = false, + .isBuilding = false, + .canBeSelected = true + }, + (EntityEntry){ + .name = "Tree", + .initCallback = initTree, + .updateCallback = updateTree, + .closeCallback = NULL, + .interactionCallback = NULL, + .isPlace = false, + .isBuilding = false, + .canBeSelected = true + }, + (EntityEntry){ + .name = "Bush", + .initCallback = initBush, + .updateCallback = updateBush, + .closeCallback = NULL, + .interactionCallback = NULL, + .isPlace = false, + .isBuilding = false, + .canBeSelected = true + }, + (EntityEntry){ + .name = "Flower", + .initCallback = initFlower, + .updateCallback = updateFlower, + .closeCallback = NULL, + .interactionCallback = NULL, + .isPlace = false, + .isBuilding = false, + .canBeSelected = true + }, + (EntityEntry){ + .name = "Pond", + .initCallback = initPond, + .updateCallback = updatePond, + .closeCallback = NULL, + .interactionCallback = NULL, + .isPlace = true, + .isBuilding = false, + .canBeSelected = true + }, + (EntityEntry){ + .name = "Utility Pole", + .initCallback = initUtilityPole, + .updateCallback = NULL, + .closeCallback = NULL, + .interactionCallback = NULL, + .isPlace = false, + .isBuilding = false, + .canBeSelected = false + }, + (EntityEntry){ + .name = "Samantha", + .initCallback = initSamantha, + .updateCallback = updateSamantha, + .closeCallback = closeSamantha, + .interactionCallback = interactWithSamantha, + .isPlace = false, + .isBuilding = false, + .canBeSelected = true + }, + (EntityEntry){ + .name = "Samantha's Spot", + .initCallback = initSamanthasSpot, + .updateCallback = updateSamanthasSpot, + .closeCallback = NULL, + .interactionCallback = NULL, + .isPlace = true, + .isBuilding = false, + .canBeSelected = false + }, + (EntityEntry){ + .name = "Trashcan", + .initCallback = initTrashcan, + .updateCallback = updateTrashcan, + .closeCallback = NULL, + .interactionCallback = NULL, + .isPlace = false, + .isBuilding = false, + .canBeSelected = true + }, + (EntityEntry){ + .name = "Trash", + .initCallback = initTrash, + .updateCallback = updateTrash, + .closeCallback = NULL, + .interactionCallback = NULL, + .isPlace = false, + .isBuilding = false, + .canBeSelected = true + }, + (EntityEntry){ + .name = "Medical Trash", + .initCallback = initMedicalTrash, + .updateCallback = updateMedicalTrash, + .closeCallback = NULL, + .interactionCallback = NULL, + .isPlace = false, + .isBuilding = false, + .canBeSelected = true + }, + (EntityEntry){ + .name = "John", + .initCallback = initJohn, + .updateCallback = updateJohn, + .closeCallback = NULL, + .interactionCallback = NULL, + .isPlace = false, + .isBuilding = false, + .canBeSelected = true + }, + (EntityEntry){ + .name = "John's store", + .initCallback = initJohnsStore, + .updateCallback = updateJohnsStore, + .closeCallback = closeJohnsStore, + .interactionCallback = NULL, + .isPlace = true, + .isBuilding = true, + .canBeSelected = false + }, + (EntityEntry){ + .name = "Ron", + .initCallback = initRon, + .updateCallback = updateRon, + .closeCallback = NULL, + .interactionCallback = interactWithRon, + .isPlace = false, + .isBuilding = false, + .canBeSelected = true + } }; Entity createEntity(EntityId id, Vector3 position) @@ -117,6 +246,16 @@ bool entityIsPlace(EntityId id) return entityEntries[id].isPlace; } +bool entityIsBuilding(EntityId id) +{ + if (id == ENTITY_NONE) + { + return false; + } + + return entityEntries[id].isBuilding; +} + bool entityCanBeSelected(EntityId id) { if (id == ENTITY_NONE) @@ -171,3 +310,33 @@ BoundingBox entityBoxFromScale(float scale, float width, float height) .max = (Vector3){size.x, size.y, size.x} }; } + +EntityBuilding* createEntityBuilding(Image heightmap) +{ + EntityBuilding* entityBuilding = + (EntityBuilding*)FT_MALLOC(sizeof(EntityBuilding)); + + if (entityBuilding == NULL) + { + ALLOCATION_ERROR; + return NULL; + } + + *entityBuilding = (EntityBuilding){ + .model = LoadModelFromMesh(GenMeshCubicmap(heightmap, + ENTITY_BUILDING_CUBE_SIZE)), + .pixelMap = LoadImageColors(heightmap) + }; + + return entityBuilding; +} + +void freeEntityBuilding(EntityBuilding* entityBuilding) +{ + if (entityBuilding != NULL) + { + UnloadModel(entityBuilding->model); + UnloadImageColors(entityBuilding->pixelMap); + FT_FREE(entityBuilding); + } +} diff --git a/src/entity.h b/src/entity.h index 2391762..66e1973 100644 --- a/src/entity.h +++ b/src/entity.h @@ -5,7 +5,7 @@ #ifndef ENTITY_H #define ENTITY_H -#define ENTITY_COUNT 14 +#define ENTITY_COUNT 15 #define ENTITY_NAME_MAX 16 @@ -13,6 +13,8 @@ #define INTERACTION_LABEL_MAX 32 #define INTERACTION_CHAT_MAX 256 +#define ENTITY_BUILDING_CUBE_SIZE (Vector3){2.0, 2.0, 2.0} + typedef int8_t EntityId; typedef enum InteractionCommand InteractionCommand; typedef enum Selection Selection; @@ -40,6 +42,7 @@ enum { TRASH, MEDICAL_TRASH, JOHN, + JOHNS_STORE, RON }; @@ -66,6 +69,12 @@ struct Entity { void* data; }; +// Cubemap based building. +typedef struct { + Model model; + Color* pixelMap; +} EntityBuilding; + typedef struct { char name[ENTITY_NAME_MAX]; InitEntityCallback initCallback; @@ -73,6 +82,7 @@ typedef struct { CloseEntityCallback closeCallback; InteractionCallback interactionCallback; bool isPlace; + bool isBuilding; bool canBeSelected; } EntityEntry; @@ -90,6 +100,7 @@ void setEntityPosition(Entity* entity, Vector3 position); void placeEntityOnGround(Entity* entity, const World* world); bool entityIsPlace(EntityId id); +bool entityIsBuilding(EntityId id); bool entityCanBeSelected(EntityId id); float getEntityDistance(Entity entity, Vector3 position); @@ -100,4 +111,7 @@ int getInteractionMenuIndex(Selection selection); BoundingBox entityBoxFromScale(float scale, float width, float height); +EntityBuilding* createEntityBuilding(Image heightmap); +void freeEntityBuilding(EntityBuilding* entityBuilding); + #endif diff --git a/src/utils.c b/src/utils.c index 02d7388..6d09293 100644 --- a/src/utils.c +++ b/src/utils.c @@ -34,4 +34,36 @@ Vector3 randomDirection3(int seed, int* nextSeed) return Vector3Normalize(direction); } +Image generateCubemapImage(bool** cubemap, int width, int height) +{ + // Allocate pixel data. + Image image = (Image){ + .data = FT_CALLOC(width * height, sizeof(Color)), + .width = width, + .height = height, + .format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, + .mipmaps = 1 + }; + + if (image.data == NULL) + { + ALLOCATION_ERROR; + return image; + } + + // Convert cubemap to image data. + int index = 0; + + for (int y = 0; y < height; ++y) + { + for (int x = 0; x < width; ++x) + { + ((Color*)image.data)[index] = cubemap[y][x] ? BLACK : WHITE; + ++index; + } + } + + return image; +} + // Why does the universe feel strange to exist in? diff --git a/src/utils.h b/src/utils.h index fddfa9d..4fd2ab8 100644 --- a/src/utils.h +++ b/src/utils.h @@ -70,4 +70,6 @@ typedef enum FTError { Vector2 randomDirection2(int seed, int* nextSeed); Vector3 randomDirection3(int seed, int* nextSeed); +Image generateCubemapImage(bool** cubemap, int width, int height); + #endif |
