diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/config.h | 17 | ||||
| -rw-r--r-- | src/rand_sys.c | 41 | ||||
| -rw-r--r-- | src/rand_sys.h | 11 | ||||
| -rw-r--r-- | src/random.h | 13 | ||||
| -rw-r--r-- | src/shader_sys.h | 1 | ||||
| -rw-r--r-- | src/texture_sys.h | 1 | ||||
| -rw-r--r-- | src/utils.h | 1 |
7 files changed, 72 insertions, 13 deletions
diff --git a/src/config.h b/src/config.h new file mode 100644 index 0000000..fc12544 --- /dev/null +++ b/src/config.h @@ -0,0 +1,17 @@ +#pragma once + +typedef int i32; +typedef long long i64; + +typedef unsigned int u32; +typedef unsigned long long u64; + +typedef float f32; +typedef double f64; + +// 24.8 format +typedef i32 fx32; +#define FIXED_POINT_BITS 8 +#define FIXED_POINT_ONE (1 << FIXED_POINT_BITS) +#define TO_FIXED(x) ((fx32)(x) << FIXED_POINT_BITS) +#define FROM_FIXED(x) ((x) >> FIXED_POINT_BITS)
\ No newline at end of file diff --git a/src/rand_sys.c b/src/rand_sys.c new file mode 100644 index 0000000..679ac94 --- /dev/null +++ b/src/rand_sys.c @@ -0,0 +1,41 @@ +#include "rand_sys.h" + +#define WIN32_LEAN_AND_MEAN +#define NOSERVICE +#define NOMCX +#define NOIME +#include <windows.h> + +static u32 state[2]; + +void rand_seed(void) +{ + FILETIME t; + GetSystemTimeAsFileTime(&t); + + u32 val = t.dwLowDateTime; + val ^= val >> 16; + val *= 0x85ebca6b; + val ^= val >> 13; + val *= 0xc2b2ae35; + val ^= val >> 16; + + state[0] = val; + state[1] = val ^ 0x49616e42U; +} + +u32 rand_u32(void) +{ + state[0] = (state[0] << 16) + (state[0] >> 16); + state[0] += state[1]; + state[1] += state[0]; + return state[0]; +} + +i32 rand_range(i32 min, i32 max) +{ + u32 range = (u32)(max - min + 1); + u32 num = rand_u32() % range; + + return min + (i32)num; +}
\ No newline at end of file diff --git a/src/rand_sys.h b/src/rand_sys.h new file mode 100644 index 0000000..75198a0 --- /dev/null +++ b/src/rand_sys.h @@ -0,0 +1,11 @@ +#pragma once + +#include "config.h" + +// Based on mattiasgustavsson's rnd.h header + +void rand_seed(void); + +u32 rand_u32(void); + +int rand_range(i32 min, i32 max);
\ No newline at end of file diff --git a/src/random.h b/src/random.h deleted file mode 100644 index 0c3845f..0000000 --- a/src/random.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include "utils.h" - -// Based on mattiasgustavsson's rnd.h header - -void rand_init(void); - -u32 rand_u32(void); - -fx32 rand_fx32(void); - -int rand_i32_range(i32 min, i32 max);
\ No newline at end of file diff --git a/src/shader_sys.h b/src/shader_sys.h index d0eff2c..1e30d7d 100644 --- a/src/shader_sys.h +++ b/src/shader_sys.h @@ -1,6 +1,7 @@ #pragma once #include "utils.h" +#include "config.h" void init_shader_sys(void); diff --git a/src/texture_sys.h b/src/texture_sys.h index a5ed941..50adc3a 100644 --- a/src/texture_sys.h +++ b/src/texture_sys.h @@ -1,6 +1,7 @@ #pragma once #include "utils.h" +#include "config.h" void init_tex_sys(void); diff --git a/src/utils.h b/src/utils.h index 92f64ba..079445a 100644 --- a/src/utils.h +++ b/src/utils.h @@ -19,5 +19,6 @@ typedef double f64; // 24.8 format typedef i32 fx32; #define FIXED_POINT_BITS 8 +#define FIXED_POINT_ONE (1 << FIXED_POINT_BITS) #define TO_FIXED(x) ((fx32)(x) << FIXED_POINT_BITS) #define FROM_FIXED(x) ((x) >> FIXED_POINT_BITS)
\ No newline at end of file |
