From 2aae6dcb8e4ab7261f4449e99b7724e665db3e3b Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 28 Jul 2025 19:18:25 -0600 Subject: Cant focus lmao --- src/entity.h | 4 ++-- src/utils.h | 18 +++++++++--------- src/world.c | 42 ++++++++++++++++++++++++++++-------------- src/world.h | 30 ++++++++++++++++++++---------- 4 files changed, 59 insertions(+), 35 deletions(-) diff --git a/src/entity.h b/src/entity.h index a1751aa..fdfe55e 100644 --- a/src/entity.h +++ b/src/entity.h @@ -5,8 +5,6 @@ #ifndef ENTITY_H #define ENTITY_H -typedef int8_t EntityId; - #define ENTITY_COUNT 5 // Entity scales. @@ -14,6 +12,8 @@ typedef int8_t EntityId; #define BUSH_SCALE 8.0 #define FLOWER_SCALE 3.0 +typedef int8_t EntityId; + enum { ENTITY_NONE = -1, OLD_MINT, diff --git a/src/utils.h b/src/utils.h index 6532660..63785eb 100644 --- a/src/utils.h +++ b/src/utils.h @@ -37,15 +37,6 @@ #define GLSL_VERSION 100 #endif -// Typedef hackery. -typedef struct Game Game; -typedef struct World World; - -typedef enum FTError { - FTERROR = -1, - FTSUCCESS = 0 -} FTError; - // Bit shit. #define SET_BIT(b, n) (b | (0x1 << n)) #define CLEAR_BIT(b, n) (b & ~(0x1 << n)) @@ -61,4 +52,13 @@ typedef enum FTError { #define PRINT_VECTOR2(v) printf("%f %f\n", v.x, v.y) #define PRINT_VECTOR3(v) printf("%f %f %f\n", v.x, v.y, v.z) +// Typedef hackery. +typedef struct Game Game; +typedef struct World World; + +typedef enum FTError { + FTERROR = -1, + FTSUCCESS = 0 +} FTError; + #endif diff --git a/src/world.c b/src/world.c index 6b8d60b..c2159d8 100644 --- a/src/world.c +++ b/src/world.c @@ -379,33 +379,46 @@ Seed generateWorldItems(World* world, Seed seed) return seed; } +Seed generatePond(World* world, Seed seed) +{ + Vector3 position; + return seed; +} + World createWorld(Seed seed) { World world; world.size = WORLD_SIZE; - // Heightmap image. + // Heightmap. int offsetX = FT_RANDOM16(seed); int offsetY = FT_RANDOM16(seed); Image image = GenImagePerlinNoise(WORLD_IMAGE_WIDTH, WORLD_IMAGE_HEIGHT, offsetX, offsetY, WORLD_IMAGE_SCALE); - // Heightmap. Mesh mesh = GenMeshHeightmap(image, world.size); world.heightmap = LoadModelFromMesh(mesh); + world.heightmapTexture = LoadTextureFromImage(image); + UnloadImage(image); - // Texture. - ImageColorTint(&image, WORLD_GROUND_COLOR); + // Model texture. + image = GenImageWhiteNoise(WORLD_IMAGE_WIDTH, WORLD_IMAGE_HEIGHT, + WORLD_GROUND_IMAGE_NOISE); ImageBlurGaussian(&image, WORLD_GROUND_BLUR); - world.texture = LoadTextureFromImage(image); + ImageColorContrast(&image, WORLD_GROUND_CONTRAST); + ImageColorTint(&image, WORLD_GROUND_COLOR); + world.heightmap.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = - world.texture; - + LoadTextureFromImage(image); UnloadImage(image); + // Places. + generatePond(&world, seed); + seed = generateWorldPlants(&world, seed); seed = generateWorldItems(&world, seed); + // Generate BVH. double currentTime = GetTime(); buildWorldBVH(&world); @@ -459,7 +472,6 @@ void updateWorld(World* world, Game* game) void freeWorldBVH(BVHNode bvh) { - // Play it safe to prevent memory leaks. for (int index = 0; index < BVH_MAX_BRANCH_COUNT; ++index) { if (bvh.branches[index] != NULL) @@ -472,15 +484,17 @@ void freeWorldBVH(BVHNode bvh) void freeWorld(World world) { - UnloadTexture(world.texture); + UnloadTexture(world.heightmapTexture); + UnloadTexture( + world.heightmap.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture); UnloadModel(world.heightmap); freeWorldBVH(world.bvh); } float getWorldHeightAtLocation(const World* world, float x, float y) { - float mapX = (float)world->texture.width / world->size.x * x; - float mapY = (float)world->texture.height / world->size.z * y; + float mapX = (float)WORLD_IMAGE_WIDTH / world->size.x * x; + float mapY = (float)WORLD_IMAGE_HEIGHT / world->size.z * y; for (int yOffset = -1; yOffset < 2; ++yOffset) { @@ -489,13 +503,13 @@ float getWorldHeightAtLocation(const World* world, float x, float y) int pixelX = mapX + xOffset; int pixelY = mapY + yOffset; - if (pixelX < 0 || pixelX >= world->texture.width || - pixelY < 0 || pixelY >= world->texture.height) + if (pixelX < 0 || pixelX >= WORLD_IMAGE_WIDTH || + pixelY < 0 || pixelY >= WORLD_IMAGE_HEIGHT) { continue; } - int verticeStart = (pixelY * (world->texture.width - 1) + pixelX) * 18; + int verticeStart = (pixelY * (WORLD_IMAGE_WIDTH - 1) + pixelX) * 18; float* vertices = &world->heightmap.meshes[0].vertices[verticeStart]; // Cast to triangles at pixel. Really hacky indeed. diff --git a/src/world.h b/src/world.h index 606ae46..3b1ca4d 100644 --- a/src/world.h +++ b/src/world.h @@ -5,24 +5,33 @@ #ifndef WORLD_H #define WORLD_H -#define BVH_MAX 4 // Max entities per node. -#define BVH_MAX_BRANCH_COUNT 8 -#define BVH_BOX_MAX 100.0 - #define WORLD_ENTITY_MAX 1500 -#define WORLD_SIZE (Vector3){1000.0, 100.0, 1000.0} -#define WORLD_IMAGE_WIDTH 100 -#define WORLD_IMAGE_HEIGHT 100 -#define WORLD_IMAGE_SCALE 5.0 #define WORLD_PLANT_COUNT 500 +#define WORLD_PLACE_COUNT 1 + +#define WORLD_SIZE (Vector3){4096.0, 256.0, 4096.0} +#define WORLD_IMAGE_WIDTH 512 +#define WORLD_IMAGE_HEIGHT 512 +#define WORLD_IMAGE_SCALE 5.0 #define WORLD_GROUND_COLOR GREEN -#define WORLD_GROUND_BLUR 4 +#define WORLD_GROUND_BLUR 2 +#define WORLD_GROUND_CONTRAST -30 +#define WORLD_GROUND_IMAGE_NOISE 0.3 + +#define BVH_MAX 4 // Max entities per node. +#define BVH_MAX_BRANCH_COUNT 8 +#define BVH_BOX_MAX 100.0 // UID for anything in the world. typedef int16_t WorldUID; typedef int Seed; +// Places. +enum { + PLACE_POND +}; + typedef struct BVHNode { BoundingBox box; Vector3 position; @@ -33,10 +42,11 @@ typedef struct BVHNode { struct World { Vector3 size; - Texture texture; + Texture heightmapTexture; Model heightmap; Entity entities[WORLD_ENTITY_MAX]; BVHNode bvh; + WorldUID places[WORLD_PLACE_COUNT]; int bvhDebugSelect; }; -- cgit v1.2.3