diff --git a/code/core/impl/math.c b/code/core/impl/math.c index 430a5fc..8859ff0 100644 --- a/code/core/impl/math.c +++ b/code/core/impl/math.c @@ -160,4 +160,46 @@ Mat4x4FInv M4x4F_CameraView(V3f x, V3f y, V3f z, V3f p) { return result; } +// Random +Random Random_Seed(U64 seed) { + Random result = { seed }; + return result; +} + +U64 Random_Next(Random *rnd) { + U64 result = rnd->state; + + result ^= (result << 13); + result ^= (result >> 7); + result ^= (result << 17); + + rnd->state = result; + + return result; +} + +F32 Random_F32(Random *rnd, F32 min, F32 max) { + F32 result = min + (Random_Unilateral(rnd) * (max - min)); + return result; +} + +F64 Random_F64(Random *rnd, F64 min, F64 max) { + F64 result = min + (Random_Unilateral(rnd) * (max - min)); + return result; +} + +U32 Random_U32(Random *rnd, U32 min, U32 max) { + U32 result = min + (U32) (Random_Unilateral(rnd) * (max - min)); + return result; +} + +F32 Random_Unilateral(Random *rnd) { + F32 result = Random_Next(rnd) / (F32) U64_MAX; + return result; +} + +F32 Random_Bilateral(Random *rnd) { + F32 result = -1.0f + (2.0f * Random_Unilateral(rnd)); + return result; +} diff --git a/code/core/math.h b/code/core/math.h index 0b219d8..7ac915d 100644 --- a/code/core/math.h +++ b/code/core/math.h @@ -4,6 +4,11 @@ #define PI_F32 (3.14159265358979323846264338f) #define TAU_F32 (2.0f * PI_F32) +typedef struct Random Random; +struct Random { + U64 state; +}; + typedef union V2f V2f; union V2f { struct { @@ -114,4 +119,18 @@ function V3f M4x4F_VMul3(Mat4x4F m, V3f v); function Mat4x4FInv M4x4F_Perspective(F32 fov, F32 aspect, F32 nearp, F32 farp); function Mat4x4FInv M4x4F_CameraView(V3f x, V3f y, V3f z, V3f p); +// Random + +function Random Random_Seed(U64 seed); + +function U64 Random_Next(Random *rnd); + +function F32 Random_F32(Random *rnd, F32 min, F32 max); +function F64 Random_F64(Random *rnd, F64 min, F64 max); + +function U32 Random_U32(Random *rnd, U32 min, U32 max); + +function F32 Random_Unilateral(Random *rnd); +function F32 Random_Bilateral(Random *rnd); + #endif // LD_CORE_MATH_H_ diff --git a/code/draw/core.h b/code/draw/core.h index e565bf2..f4e24c8 100644 --- a/code/draw/core.h +++ b/code/draw/core.h @@ -1,7 +1,7 @@ #if !defined(LD_DRAW_CORE_H_) #define LD_DRAW_CORE_H_ -#define D_MAX_RECTS 1024 +#define D_MAX_RECTS (262144) typedef struct D_Image D_Image; struct D_Image { diff --git a/code/first.c b/code/first.c index 6741e03..59fd591 100644 --- a/code/first.c +++ b/code/first.c @@ -96,13 +96,6 @@ int main(int argc, char **argv) { world->player.pos.y = 0; } - Vk_Buffer rbo = { 0 }; - rbo.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT; - rbo.size = KB(4); - rbo.host_visible = true; - - Vk_BufferCreate(&rbo); - bool running = true; printf("%zu size in bytes\n", sizeof(TestNavMesh)); @@ -126,7 +119,7 @@ int main(int argc, char **argv) { game->draw.window_width = w; game->draw.window_height = h; - G_CalulateCamera(&game->camera, (F32) w / (F32) h); + G_CalculateCamera(&game->camera, (F32) w / (F32) h); Vk_Frame *frame = Vk_FrameBegin(window); VkCommandBuffer cmd = frame->cmd; diff --git a/code/game/core.c b/code/game/core.c index a6b7569..9fbc249 100644 --- a/code/game/core.c +++ b/code/game/core.c @@ -290,7 +290,7 @@ void G_PipelinesLoad(G_State *game) { Vk_PipelineCreate(basic); } -void G_CalulateCamera(G_Camera *camera, F32 aspect) { +void G_CalculateCamera(G_Camera *camera, F32 aspect) { Mat4x4FInv proj = M4x4F_Perspective(camera->fov, aspect, camera->nearp, camera->farp); Mat4x4FInv view = M4x4F_CameraView(camera->x, camera->y, camera->z, camera->p); diff --git a/code/game/core.h b/code/game/core.h index 7a71f7e..263a242 100644 --- a/code/game/core.h +++ b/code/game/core.h @@ -26,7 +26,7 @@ struct G_State { function void G_ImagesLoad(G_State *game); function void G_PipelinesLoad(G_State *game); -function void G_CalulateCamera(G_Camera *camera, F32 aspect); +function void G_CalculateCamera(G_Camera *camera, F32 aspect); #include "aabb.h" #include "player.h" diff --git a/code/game/impl/world.c b/code/game/impl/world.c index e39dd09..405601f 100644 --- a/code/game/impl/world.c +++ b/code/game/impl/world.c @@ -8,10 +8,10 @@ void UpdateWorld(F32 delta, World *world) { } void UpdateNPCs(F32 delta, World *world) { - for(int i = 0; i < world->npcCount; i++) { + for(U32 i = 0; i < world->npcCount; i++) { updateNPC(delta, &world->npcs[i], world); } -} +} void ProcessEvents(SDL_Event *event, World *world) { PlayerUpdate(event, &world->player); diff --git a/code/game/world.h b/code/game/world.h index c75c134..433070b 100644 --- a/code/game/world.h +++ b/code/game/world.h @@ -25,7 +25,7 @@ struct World { NPC npcs[128]; ////Bandit - // The bandit the player is after. + // The bandit the player is after. Bandit bandit; // NPC points of interest, places to walk to.