Create RNG module

This commit is contained in:
2025-10-18 17:43:22 +01:00
parent c1f339484b
commit f992dd3d39
5 changed files with 50 additions and 13 deletions

14
game.c
View File

@@ -2,12 +2,11 @@
#include "input.h"
#include "renderer.h"
#include "rng.h"
#include <assert.h>
#include <linux/input-event-codes.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#define FIRE_MEAN -0.15
#define FIRE_JITTER 0.01
@@ -204,11 +203,6 @@ static void remove_entity(unsigned id)
--entity_count;
}
static float rand_plusminus()
{
return 2.0f * ((float)rand() / RAND_MAX - 0.5f);
}
static void ship_update()
{
entity_t *ship = entities + ship_entity_id;
@@ -221,7 +215,7 @@ static void ship_update()
shape_t *fire = shapes + fire_shape_id;
fire->visible = input.fwd != 0;
fire->verts[0].y = FIRE_MEAN + FIRE_JITTER * rand_plusminus();
fire->verts[0].y = FIRE_MEAN + FIRE_JITTER * rng_plusminus();
}
void game_init(float _aspect)
@@ -230,10 +224,6 @@ void game_init(float _aspect)
input_on_release(key_release_callback);
input_on_repeat(key_repeat_callback);
struct timeval tv;
gettimeofday(&tv, NULL);
srand(tv.tv_usec);
aspect = _aspect;
quit = false;