aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/random.h13
-rw-r--r--src/script_sys.c4
-rw-r--r--src/shader_sys.c30
-rw-r--r--src/shader_sys.h8
-rw-r--r--src/texture_sys.c20
-rw-r--r--src/texture_sys.h8
-rw-r--r--src/utils.h17
7 files changed, 66 insertions, 34 deletions
diff --git a/src/random.h b/src/random.h
new file mode 100644
index 0000000..0c3845f
--- /dev/null
+++ b/src/random.h
@@ -0,0 +1,13 @@
+#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/script_sys.c b/src/script_sys.c
index 79f0395..e9488fc 100644
--- a/src/script_sys.c
+++ b/src/script_sys.c
@@ -14,7 +14,7 @@ static void(*script_init)(void) = NULL;
static void(*script_update)(void) = NULL;
static void(*script_exit)(void) = NULL;
-static long current_mod = -1;
+static i32 current_mod = -1;
static void restart(void)
{
@@ -48,7 +48,7 @@ void init_script_sys(void)
void update_script(void)
{
- long new_mod = GetFileModTime("assets/src/main.c");
+ i32 new_mod = GetFileModTime("assets/src/main.c");
if(new_mod != current_mod){
current_mod = new_mod;
diff --git a/src/shader_sys.c b/src/shader_sys.c
index 180bdef..0fcc6ce 100644
--- a/src/shader_sys.c
+++ b/src/shader_sys.c
@@ -21,28 +21,28 @@ static char* shader_block_preprocess(const char* shader_source, ShaderStep shade
char* parsed_total = NULL;
- int start_idx = TextFindIndex(shader_source, start_markers[shader_step]);
+ i32 start_idx = TextFindIndex(shader_source, start_markers[shader_step]);
if (start_idx == BLANK_DEFAULT){
TRACELOG(LOG_ERROR, "%s could not be found.", start_markers[shader_step]);
goto parse_err;
}
start_idx += TextLength(start_markers[shader_step]);
- int end_idx = TextFindIndex(shader_source, end_markers[shader_step]);
+ i32 end_idx = TextFindIndex(shader_source, end_markers[shader_step]);
if (end_idx == BLANK_DEFAULT){
TRACELOG(LOG_ERROR, "%s could not be found. Don't forget to end blocks!", end_markers[shader_step]);
goto parse_err;
}
- int block_sz = end_idx - start_idx;
+ i32 block_sz = end_idx - start_idx;
const char* block = TextSubtext(shader_source, start_idx, block_sz);
- int total_block_size = block_sz + TextLength(version_statement);
+ i32 total_block_size = block_sz + TextLength(version_statement);
parsed_total = (char*)RL_MALLOC(total_block_size + NULL_TERM_SZ);
- int cursor = 0;
+ i32 cursor = 0;
TextAppend(parsed_total, version_statement, &cursor);
TextAppend(parsed_total, block, &cursor);
@@ -81,22 +81,22 @@ vertex_err:
}
static Shader shader_slots[MAX_SHADER_SIZE] = {0};
-static long shader_modtimes[MAX_SHADER_SIZE] = {0};
+static i32 shader_modtimes[MAX_SHADER_SIZE] = {0};
static const char* shader_paths[MAX_SHADER_SIZE] = {0};
void init_shader_sys(void)
{
- for(int i = 0; i < MAX_SHADER_SIZE; ++i){
+ for(i32 i = 0; i < MAX_SHADER_SIZE; ++i){
shader_slots[i] = (Shader){0};
shader_modtimes[i] = BLANK_DEFAULT;
shader_paths[i] = NULL;
}
}
-int load_new_shader(const char* path)
+i32 load_new_shader(const char* path)
{
- int current_idx = BLANK_DEFAULT;
- for(int i = 0; i < MAX_SHADER_SIZE; ++i){
+ i32 current_idx = BLANK_DEFAULT;
+ for(i32 i = 0; i < MAX_SHADER_SIZE; ++i){
if(shader_slots[i].id <= 0){
current_idx = i;
shader_slots[current_idx] = load_joined_shader(path);
@@ -112,7 +112,7 @@ int load_new_shader(const char* path)
return current_idx;
}
-void set_active_shader(int idx)
+void set_active_shader(i32 idx)
{
if(idx < 0 || idx >= MAX_SHADER_SIZE)
TRACELOG(LOG_WARNING,"Bounds check: Attempted to set shader at non-existent index %i.\n", idx);
@@ -122,9 +122,9 @@ void set_active_shader(int idx)
void update_shaders(void)
{
- for(int i = 0; i < MAX_SHADER_SIZE; ++i){
+ for(i32 i = 0; i < MAX_SHADER_SIZE; ++i){
if(shader_slots[i].id > 0){
- long current_mod = GetFileModTime(shader_paths[i]);
+ i32 current_mod = GetFileModTime(shader_paths[i]);
if(current_mod != shader_modtimes[i]){
shader_modtimes[i] = current_mod;
@@ -141,7 +141,7 @@ void reset_active_shader(void)
EndShaderMode();
}
-void unload_shader(int idx)
+void unload_shader(i32 idx)
{
if(idx < 0 || idx >= MAX_SHADER_SIZE){
TRACELOG(LOG_WARNING,"Bounds check: Attempted to unload shader at non-existent index %i.\n", idx);
@@ -156,7 +156,7 @@ void unload_shader(int idx)
void unload_active_shaders(void)
{
- for(int i = 0; i < MAX_SHADER_SIZE; ++i){
+ for(i32 i = 0; i < MAX_SHADER_SIZE; ++i){
if(shader_slots[i].id > 0)
unload_shader(i);
}
diff --git a/src/shader_sys.h b/src/shader_sys.h
index 3df03c2..d0eff2c 100644
--- a/src/shader_sys.h
+++ b/src/shader_sys.h
@@ -1,15 +1,17 @@
#pragma once
+#include "utils.h"
+
void init_shader_sys(void);
-int load_new_shader(const char* path);
+i32 load_new_shader(const char* path);
-void set_active_shader(int idx);
+void set_active_shader(i32 idx);
void update_shaders(void);
void reset_active_shader(void);
-void unload_shader(int idx);
+void unload_shader(i32 idx);
void unload_active_shaders(void); \ No newline at end of file
diff --git a/src/texture_sys.c b/src/texture_sys.c
index 170e124..3481a69 100644
--- a/src/texture_sys.c
+++ b/src/texture_sys.c
@@ -5,22 +5,22 @@
#define MAX_TEX_SIZE 16
static Texture2D texture_slots[MAX_TEX_SIZE] = {0};
-static long texture_modtimes[MAX_TEX_SIZE] = {0};
+static i32 texture_modtimes[MAX_TEX_SIZE] = {0};
static const char* texture_paths[MAX_TEX_SIZE] = {0};
void init_tex_sys(void)
{
- for(int i = 0; i < MAX_TEX_SIZE; ++i){
+ for(i32 i = 0; i < MAX_TEX_SIZE; ++i){
texture_slots[i] = (Texture2D){0};
texture_modtimes[i] = BLANK_DEFAULT;
texture_paths[i] = NULL;
}
}
-int load_new_tex(const char* path)
+i32 load_new_tex(const char* path)
{
- int current_idx = BLANK_DEFAULT;
- for(int i = 0; i < MAX_TEX_SIZE; ++i){
+ i32 current_idx = BLANK_DEFAULT;
+ for(i32 i = 0; i < MAX_TEX_SIZE; ++i){
if(texture_slots[i].id <= 0){
current_idx = i;
texture_slots[current_idx] = LoadTexture(path);
@@ -36,7 +36,7 @@ int load_new_tex(const char* path)
return current_idx;
}
-void draw_texture(int idx, int x, int y)
+void draw_texture(i32 idx, i32 x, i32 y)
{
if(idx < 0 || idx >= MAX_TEX_SIZE){
TRACELOG(LOG_WARNING,"Bounds check: Attempted to draw texture from non-existent index %i.\n", idx);
@@ -47,9 +47,9 @@ void draw_texture(int idx, int x, int y)
void update_textures(void)
{
- for(int i = 0; i < MAX_TEX_SIZE; ++i){
+ for(i32 i = 0; i < MAX_TEX_SIZE; ++i){
if(texture_slots[i].id > 0){
- long current_mod = GetFileModTime(texture_paths[i]);
+ i32 current_mod = GetFileModTime(texture_paths[i]);
if(current_mod != texture_modtimes[i]){
texture_modtimes[i] = current_mod;
@@ -61,7 +61,7 @@ void update_textures(void)
}
}
-void unload_tex(int idx)
+void unload_tex(i32 idx)
{
if(idx < 0 || idx >= MAX_TEX_SIZE){
TRACELOG(LOG_WARNING,"Bounds check: Attempted to unload texture from non-existent index %i.\n", idx);
@@ -75,7 +75,7 @@ void unload_tex(int idx)
void unload_active_textures(void)
{
- for(int i = 0; i < MAX_TEX_SIZE; ++i){
+ for(i32 i = 0; i < MAX_TEX_SIZE; ++i){
if(texture_slots[i].id > 0)
unload_tex(i);
}
diff --git a/src/texture_sys.h b/src/texture_sys.h
index 67c9e19..a5ed941 100644
--- a/src/texture_sys.h
+++ b/src/texture_sys.h
@@ -1,13 +1,15 @@
#pragma once
+#include "utils.h"
+
void init_tex_sys(void);
-int load_new_tex(const char* path);
+i32 load_new_tex(const char* path);
-void draw_texture(int idx, int x, int y);
+void draw_texture(i32 idx, i32 x, i32 y);
void update_textures(void);
-void unload_tex(int idx);
+void unload_tex(i32 idx);
void unload_active_textures(void);
diff --git a/src/utils.h b/src/utils.h
index 2d367d0..92f64ba 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -5,4 +5,19 @@
#define BLANK_DEFAULT -1
#define NULL_TERM '\0'
-#define NULL_TERM_SZ 1 \ No newline at end of file
+#define NULL_TERM_SZ 1
+
+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 TO_FIXED(x) ((fx32)(x) << FIXED_POINT_BITS)
+#define FROM_FIXED(x) ((x) >> FIXED_POINT_BITS) \ No newline at end of file