copy random noise resource to memory on startup
This commit is contained in:
parent
e6cea55854
commit
d78adcb9c9
24
src/app.c
24
src/app.c
@ -118,30 +118,6 @@ void app_register_exit_callback(app_exit_callback_func *func)
|
||||
sys_mutex_unlock(&lock);
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
* Generate random number file
|
||||
* (unused function)
|
||||
* ========================== */
|
||||
|
||||
#if 0
|
||||
#include "rng.h"
|
||||
INTERNAL void gen_random_file(struct string path, u32 count)
|
||||
{
|
||||
{
|
||||
/* Clear file */
|
||||
struct sys_file f = sys_file_open_write(path);
|
||||
sys_file_write(f, BUFFER(0, 0));
|
||||
sys_file_close(f);
|
||||
}
|
||||
struct sys_file f = sys_file_open_append(path);
|
||||
for (u32 i = 0; i < count; ++i) {
|
||||
u64 rand = rng_rand_u64();
|
||||
sys_file_write(f, BUFFER_FROM_STRUCT(&rand));
|
||||
}
|
||||
sys_file_close(f);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ========================== *
|
||||
* Entry point
|
||||
* ========================== */
|
||||
|
||||
@ -29,7 +29,7 @@
|
||||
|
||||
#define PIXELS_PER_UNIT 256.0
|
||||
|
||||
#define GAME_FPS 100.0
|
||||
#define GAME_FPS 50.0
|
||||
#define GAME_TIMESCALE 1
|
||||
|
||||
#define GAME_PHYSICS_SUBSTEPS 4
|
||||
|
||||
30
src/rng.c
30
src/rng.c
@ -1,12 +1,37 @@
|
||||
#include "rng.h"
|
||||
#include "sys.h"
|
||||
#include "resource.h"
|
||||
#include "arena.h"
|
||||
|
||||
GLOBAL struct {
|
||||
struct arena arena;
|
||||
u64 *noise;
|
||||
u64 noise_count;
|
||||
} G = ZI, DEBUG_ALIAS(G, G_rng);
|
||||
|
||||
/* ========================== *
|
||||
* Generate random number file
|
||||
* (unused function)
|
||||
* ========================== */
|
||||
|
||||
#if 0
|
||||
INTERNAL void gen_random_file(struct string path, u32 count)
|
||||
{
|
||||
{
|
||||
/* Clear file */
|
||||
struct sys_file f = sys_file_open_write(path);
|
||||
sys_file_write(f, BUFFER(0, 0));
|
||||
sys_file_close(f);
|
||||
}
|
||||
struct sys_file f = sys_file_open_append(path);
|
||||
for (u32 i = 0; i < count; ++i) {
|
||||
u64 rand = rng_rand_u64();
|
||||
sys_file_write(f, BUFFER_FROM_STRUCT(&rand));
|
||||
}
|
||||
sys_file_close(f);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ========================== *
|
||||
* Startup
|
||||
* ========================== */
|
||||
@ -14,11 +39,14 @@ GLOBAL struct {
|
||||
struct rng_startup_receipt rng_startup(struct resource_startup_receipt *resource_sr)
|
||||
{
|
||||
(UNUSED)resource_sr;
|
||||
G.arena = arena_alloc(GIGABYTE(64));
|
||||
struct string rand_path = STR("res/rand.dat");
|
||||
if (resource_exists(rand_path)) {
|
||||
struct resource r = resource_open(rand_path);
|
||||
G.noise = (u64 *)r.bytes.data;
|
||||
G.noise_count = r.bytes.size / sizeof(*G.noise);
|
||||
G.noise = arena_push_array(&G.arena, u64, G.noise_count);
|
||||
MEMCPY(G.noise, r.bytes.data, r.bytes.size);
|
||||
resource_close(r);
|
||||
} else {
|
||||
sys_panic(STR("Failed to locate pre-computed noise resource"));
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user