aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornathan <nathan@disroot.org>2025-07-30 06:40:46 +0000
committernathan <nathan@disroot.org>2025-07-30 06:40:46 +0000
commit384fa265c8493aff5f37921cf98034bb847915a2 (patch)
tree706c292f763402abd092bf28167a1595b95e09cc
parent7faa1cbde913ad8c56bc43bc01512799d4cf6d02 (diff)
downloadFindThings-384fa265c8493aff5f37921cf98034bb847915a2.tar.gz
FindThings-384fa265c8493aff5f37921cf98034bb847915a2.tar.bz2
FindThings-384fa265c8493aff5f37921cf98034bb847915a2.zip
Working on pond generator
-rw-r--r--src/game.c2
-rw-r--r--src/utils.c36
-rw-r--r--src/utils.h3
-rw-r--r--src/world.c32
-rw-r--r--src/world.h3
5 files changed, 66 insertions, 10 deletions
diff --git a/src/game.c b/src/game.c
index 427ffdf..7f61ddb 100644
--- a/src/game.c
+++ b/src/game.c
@@ -30,7 +30,7 @@ void initGame(Game* game)
CUBEMAP_LAYOUT_AUTO_DETECT);
// World.
- game->world = createWorld(134235234);
+ game->world = createWorld(103489);
// Player.
game->player = createPlayer();
diff --git a/src/utils.c b/src/utils.c
index 635a1f7..e49623c 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -1,3 +1,39 @@
#include "utils.h"
+#define RANDOM_DIRECTION_UNITS 4096
+
+Vector2 randomDirection2(int seed, int* nextSeed)
+{
+ Vector2 direction;
+ direction.x = FT_RANDOM16(seed) % RANDOM_DIRECTION_UNITS;
+ direction.y = FT_RANDOM16(seed) % RANDOM_DIRECTION_UNITS;
+ direction.x -= RANDOM_DIRECTION_UNITS / 2.0;
+ direction.y -= RANDOM_DIRECTION_UNITS / 2.0;
+
+ if (nextSeed != NULL)
+ {
+ *nextSeed = seed;
+ }
+
+ return Vector2Normalize(direction);
+}
+
+Vector3 randomDirection3(int seed, int* nextSeed)
+{
+ Vector3 direction;
+ direction.x = FT_RANDOM16(seed) % RANDOM_DIRECTION_UNITS;
+ direction.y = FT_RANDOM16(seed) % RANDOM_DIRECTION_UNITS;
+ direction.z = FT_RANDOM16(seed) % RANDOM_DIRECTION_UNITS;
+ direction.x -= RANDOM_DIRECTION_UNITS / 2.0;
+ direction.y -= RANDOM_DIRECTION_UNITS / 2.0;
+ direction.z -= RANDOM_DIRECTION_UNITS / 2.0;
+
+ if (nextSeed != NULL)
+ {
+ *nextSeed = seed;
+ }
+
+ return Vector3Normalize(direction);
+}
+
// Why does the universe feel strange to exist in?
diff --git a/src/utils.h b/src/utils.h
index 63785eb..4f6bf6d 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -61,4 +61,7 @@ typedef enum FTError {
FTSUCCESS = 0
} FTError;
+Vector2 randomDirection2(int seed, int* nextSeed);
+Vector3 randomDirection3(int seed, int* nextSeed);
+
#endif
diff --git a/src/world.c b/src/world.c
index 5db0130..87ca0d4 100644
--- a/src/world.c
+++ b/src/world.c
@@ -328,6 +328,20 @@ void buildWorldBVH(World* world)
world->bvhDebugSelect = 0;
}
+// Doesnt set y to a useful value.
+Vector3 getRandomPositionFromCenter(const World* world, Seed* seed,
+ float min, float max)
+{
+ Vector3 position = Vector3Scale(world->size, 0.5);
+ Vector2 direction = randomDirection2(*seed, seed);
+ float distance = Wrap(FT_RANDOM16(*seed), min, max);
+ direction = Vector2Scale(direction, distance);
+ position.x += direction.x;
+ position.z += direction.y;
+
+ return position;
+}
+
Seed generateWorldPlants(World* world, Seed seed, int start, int end)
{
for (int index = start; index < end; ++index)
@@ -381,14 +395,10 @@ Seed generateWorldItems(World* world, Seed seed, int start, int end)
Seed generatePond(World* world, Color* heightmap, WorldUID id, Seed seed)
{
- // Get position.
- int distanceRange = PLACE_POND_MAX_DISTANCE * 2;
- Vector3 position = Vector3Scale(world->size, 0.5);
- position.x += FT_RANDOM16(seed) % distanceRange - PLACE_POND_MAX_DISTANCE;
- position.z += FT_RANDOM16(seed) % distanceRange - PLACE_POND_MAX_DISTANCE;
-
+ Vector3 position = getRandomPositionFromCenter(world, &seed,
+ PLACE_POND_MIN_DISTANCE,
+ PLACE_POND_MAX_DISTANCE);
Entity pond = createEntity(POND, position);
- placeEntityOnGround(&pond, world);
world->entities[id] = pond;
return seed;
@@ -429,7 +439,7 @@ World createWorld(Seed seed)
image = (Image){
.data = colors,
.width = WORLD_IMAGE_WIDTH,
- .height = WORLD_IMAGE_WIDTH,
+ .height = WORLD_IMAGE_HEIGHT,
.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8,
.mipmaps = 1
};
@@ -439,6 +449,12 @@ World createWorld(Seed seed)
world.heightmapTexture = LoadTextureFromImage(image);
UnloadImage(image);
+ // Put places on ground.
+ for (int index = 0; index < WORLD_PLACE_COUNT; ++index)
+ {
+ placeEntityOnGround(&world.entities[index], &world);
+ }
+
// Model texture.
world.heightmap.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture =
generateGroundTexture();
diff --git a/src/world.h b/src/world.h
index 2097c94..6060b90 100644
--- a/src/world.h
+++ b/src/world.h
@@ -24,7 +24,8 @@
#define BVH_BOX_MAX 100.0
// Places.
-#define PLACE_POND_MAX_DISTANCE 100 // Max distance from center.
+#define PLACE_POND_MIN_DISTANCE 400 // Pond distance from center.
+#define PLACE_POND_MAX_DISTANCE 600
// UID for anything in the world.
typedef int16_t WorldUID;