From c5989ca9bcc1758f4d772d20b8bd4ae7762bc75e Mon Sep 17 00:00:00 2001 From: nathan Date: Wed, 6 Aug 2025 03:55:04 -0600 Subject: Working on utility poles --- design.org | 4 +-- src/entity.c | 18 +++++++++++ src/entity.h | 11 +++++-- src/world.c | 101 ++++++++++++++++++++++++++++++++++++----------------------- src/world.h | 3 +- 5 files changed, 91 insertions(+), 46 deletions(-) diff --git a/design.org b/design.org index 481f231..a28699e 100644 --- a/design.org +++ b/design.org @@ -94,12 +94,12 @@ creates is possible to beat. A little wack is fine as long as its beatable. Since most of the world will just be a height map a image will be generated first than rest of the world will be based around it. -* TODO World generation check list [4/8] +* TODO World generation check list [5/8] + [X] Basic terrain + [X] Ground texture + [X] Trees/plants + [X] Sky -+ [ ] Pond ++ [X] Pond + [ ] Power lines + [ ] Buildings + [ ] Roads diff --git a/src/entity.c b/src/entity.c index 97af95e..f9f7989 100644 --- a/src/entity.c +++ b/src/entity.c @@ -39,6 +39,15 @@ Entity createEntity(EntityId id, Vector3 position) .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}, + }; + break; default: break; @@ -49,8 +58,11 @@ Entity createEntity(EntityId id, Vector3 position) return entity; } +// TODO: Mesh instance the utility poles and make a 3d model void updateEntity(Entity* entity, Game* game) { + DrawBoundingBox(entity->box, RED); + switch (entity->id) { case OLD_MINT: @@ -78,6 +90,12 @@ void updateEntity(Entity* entity, Game* game) Vector3Add(entity->position, (Vector3){0.0, POND_HEIGHT * 2.0, 0.0}), (Vector2){POND_SIZE * 2.5, POND_SIZE * 2.5}, BLUE); break; + case UTILITY_POLE: + DrawCylinder(Vector3Subtract(entity->position, + (Vector3){0.0, UTILITY_POLE_HEIGHT}), + UTILITY_POLE_RADIUS, UTILITY_POLE_RADIUS, + UTILITY_POLE_HEIGHT * 2.0, 6, BROWN); + break; default: break; } diff --git a/src/entity.h b/src/entity.h index 231304f..68caf64 100644 --- a/src/entity.h +++ b/src/entity.h @@ -5,14 +5,18 @@ #ifndef ENTITY_H #define ENTITY_H -#define ENTITY_COUNT 6 +#define ENTITY_COUNT 7 #define TREE_SCALE 40.0 #define BUSH_SCALE 8.0 #define FLOWER_SCALE 3.0 + #define POND_SIZE 250.0 #define POND_HEIGHT 10.0 +#define UTILITY_POLE_HEIGHT 100.0 +#define UTILITY_POLE_RADIUS 3.0 + typedef int8_t EntityId; enum { @@ -22,12 +26,13 @@ enum { TREE, BUSH, FLOWER, - POND + POND, + UTILITY_POLE }; typedef struct { EntityId id; - Vector3 position; // Shouldnt be changed accessed directly. + Vector3 position; // Shouldnt be changed directly. BoundingBox box; } Entity; diff --git a/src/world.c b/src/world.c index 8547eef..1d0aa10 100644 --- a/src/world.c +++ b/src/world.c @@ -377,46 +377,6 @@ Seed putEntityInRandomPlace(const World* world, Seed seed, Entity* entity) return seed; } -Seed generateWorldPlants(World* world, Seed seed, int start, int end) -{ - for (int index = start; index < end; ++index) - { - FT_RANDOM16(seed); - - // Get id for plant. - EntityId plants[] = {TREE, BUSH, FLOWER}; - size_t plantsSize = 3; - EntityId id = plants[seed % plantsSize]; - - // Create entity. - Entity entity = createEntity(id, Vector3Zero()); - seed = putEntityInRandomPlace(world, seed, &entity); - - world->entities[index] = entity; - } - - return seed; -} - -Seed generateWorldItems(World* world, Seed seed, int start, int end) -{ - for (int index = start; index < end; ++index) - { - FT_RANDOM16(seed); - - EntityId items[] = {OLD_MINT, STICKY_NICKEL}; - size_t itemsSize = 2; - EntityId id = items[seed % itemsSize]; - - Entity entity = createEntity(id, Vector3Zero()); - seed = putEntityInRandomPlace(world, seed, &entity); - - world->entities[index] = entity; - } - - return seed; -} - Seed generatePond(World* world, Color* heightmap, WorldUID id, Seed seed) { // Create pond entity. @@ -492,6 +452,60 @@ Seed generatePond(World* world, Color* heightmap, WorldUID id, Seed seed) return seed; } +Seed generateWorldPlants(World* world, Seed seed, int start, int end) +{ + for (int index = start; index < end; ++index) + { + FT_RANDOM16(seed); + + // Get id for plant. + EntityId plants[] = {TREE, BUSH, FLOWER}; + size_t plantsSize = 3; + EntityId id = plants[seed % plantsSize]; + + // Create entity. + Entity entity = createEntity(id, Vector3Zero()); + seed = putEntityInRandomPlace(world, seed, &entity); + + world->entities[index] = entity; + } + + return seed; +} + +Seed generateWorldUtilityPoles(World* world, Seed seed, int start, int end) +{ + for (int index = start; index < end; ++index) + { + FT_RANDOM16(seed); + + Entity entity = createEntity(UTILITY_POLE, Vector3Zero()); + seed = putEntityInRandomPlace(world, seed, &entity); + world->entities[index] = entity; + } + + return seed; +} + +Seed generateWorldItems(World* world, Seed seed, int start, int end) +{ + for (int index = start; index < end; ++index) + { + FT_RANDOM16(seed); + + EntityId items[] = {OLD_MINT, STICKY_NICKEL}; + size_t itemsSize = 2; + EntityId id = items[seed % itemsSize]; + + Entity entity = createEntity(id, Vector3Zero()); + seed = putEntityInRandomPlace(world, seed, &entity); + + world->entities[index] = entity; + } + + return seed; +} + Texture generateGroundTexture() { Image image = GenImageWhiteNoise(WORLD_IMAGE_WIDTH, WORLD_IMAGE_HEIGHT, @@ -548,10 +562,17 @@ World createWorld(Seed seed) world.heightmap.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = generateGroundTexture(); + // Plants int start = placeId + 1; int end = WORLD_PLANT_COUNT + start; seed = generateWorldPlants(&world, seed, start, end); + // Utility poles. + start = end; + end = WORLD_UTILITY_POLE_COUNT + start; + seed = generateWorldUtilityPoles(&world, seed, start, end); + + // Items. start = end; end = WORLD_ENTITY_MAX; seed = generateWorldItems(&world, seed, start, end); diff --git a/src/world.h b/src/world.h index 8135a57..1d7dd72 100644 --- a/src/world.h +++ b/src/world.h @@ -5,8 +5,9 @@ #ifndef WORLD_H #define WORLD_H -#define WORLD_ENTITY_MAX 4500 +#define WORLD_ENTITY_MAX 5000 #define WORLD_PLANT_COUNT 2500 +#define WORLD_UTILITY_POLE_COUNT 50 #define WORLD_PLACE_COUNT 1 #define WORLD_SIZE (Vector3){4096.0, 256.0, 4096.0} -- cgit v1.2.3