summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2023-06-16 01:18:13 -0400
committerrealtradam <[email protected]>2023-06-16 01:18:13 -0400
commita47cc44ef7191d03f8ca1b8d4e6b9dd34fba1807 (patch)
treef7e358545f5043df20695d0cf51dcf8caa10cb12
parent425516a9c53183179c43517f1b6501a790378a05 (diff)
downloadRodeoKit-a47cc44ef7191d03f8ca1b8d4e6b9dd34fba1807.tar.gz
RodeoKit-a47cc44ef7191d03f8ca1b8d4e6b9dd34fba1807.zip
matrix math wrapper as well as various refactors for consistant and cleaner code
-rw-r--r--CMakeLists.txt5
-rw-r--r--include/rodeo.h33
-rw-r--r--include/rodeo/gfx_t.h4
-rw-r--r--include/rodeo/math.h17
-rw-r--r--include/rodeo/math/mat4.h38
-rw-r--r--include/rodeo/math/mat4_t.h19
-rw-r--r--include/rodeo/math/rng.h48
-rw-r--r--include/rodeo/math/rng_t.h16
-rw-r--r--include/rodeo/math/vec2.h53
-rw-r--r--include/rodeo/math/vec2_t.h17
-rw-r--r--include/rodeo/math/vec3.h53
-rw-r--r--include/rodeo/math/vec3_t.h18
-rw-r--r--include/rodeo/math_t.h5
-rw-r--r--include/rodeo/window.h4
-rw-r--r--src/gfx/irodeo_gfx_t.h11
-rw-r--r--src/gfx/rodeo_gfx.c161
-rw-r--r--src/math/irodeo_mat4.h8
-rw-r--r--src/math/irodeo_math.h16
-rw-r--r--src/math/irodeo_math_t.h1
-rw-r--r--src/math/irodeo_rng_t.h23
-rw-r--r--src/math/irodeo_vec2.h14
-rw-r--r--src/math/irodeo_vec3.h15
-rw-r--r--src/math/rodeo_mat4.c171
-rw-r--r--src/math/rodeo_math.c20
-rw-r--r--src/math/rodeo_rng.c81
-rw-r--r--src/math/rodeo_vec2.c189
-rw-r--r--src/math/rodeo_vec3.c191
-rw-r--r--src/rodeo.c47
-rw-r--r--src/rodeo_internal.h17
-rw-r--r--src/rodeo_internal_types.h24
-rw-r--r--src/rodeo_math.c20
-rw-r--r--src/window/rodeo_window.c8
32 files changed, 1149 insertions, 198 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 60dd94f..5f04b54 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -14,6 +14,11 @@ add_library(${PROJECT_NAME}
"src/collision/rodeo_collision.c"
"src/gfx/rodeo_gfx.c"
"src/window/rodeo_window.c"
+ "src/math/rodeo_math.c"
+ "src/math/rodeo_vec2.c"
+ "src/math/rodeo_vec3.c"
+ "src/math/rodeo_mat4.c"
+ "src/math/rodeo_rng.c"
)
set_property(TARGET RodeoKit PROPERTY C_STANDARD 99)
diff --git a/include/rodeo.h b/include/rodeo.h
index f60d527..795d6f7 100644
--- a/include/rodeo.h
+++ b/include/rodeo.h
@@ -9,17 +9,10 @@
#include "rodeo/collision.h"
#include "rodeo/gfx.h"
#include "rodeo/window.h"
-
-// -- external --
-#include "stc/cstr.h"
+#include "rodeo/math.h"
// -- system --
-#include <stdbool.h>
-#include <stdio.h>
#include <stdint.h>
-#include <stdarg.h>
-#include <string.h>
-#include <limits.h>
/// --- Math ---
@@ -29,15 +22,6 @@ rodeo_color_RGBAFloat_to_RGBA8(const rodeo_color_RGBAFloat_t color);
rodeo_color_RGBAFloat_t
rodeo_color_RGBA8_to_RGBAFloat(const rodeo_color_RGBA8_t color);
-void
-rodeo_random_seed_set(uint64_t seed);
-
-double
-rodeo_random_double_get(void);
-
-uint64_t
-rodeo_random_uint64_get(void);
-
/// --- Core ---
void
@@ -48,3 +32,18 @@ rodeo_mainLoop_run(
void
rodeo_debug_text_draw(uint16_t x, uint16_t y, const char *format, ...);
+// intialize all subsystems
+void
+rodeo_init(float width, float height, cstr window_name, uint32_t audio_channels);
+
+// deintialize all subsystems
+void
+rodeo_deinit(void);
+
+// macro to intialize/deinitialize all subsystems
+#define \
+mrodeo_do(width, height, window_name, audio_channels) \
+ mrodeo_defer_do( \
+ rodeo_init(width, height, window_name, audio_channels), \
+ rodeo_deinit() \
+ )
diff --git a/include/rodeo/gfx_t.h b/include/rodeo/gfx_t.h
index 9ed5f14..40ea58c 100644
--- a/include/rodeo/gfx_t.h
+++ b/include/rodeo/gfx_t.h
@@ -6,12 +6,12 @@
// -- system --
#include <inttypes.h>
-typedef struct irodeo_gfx_texture_internal irodeo_gfx_texture_internal_t;
+typedef struct irodeo_gfx_texture_2d irodeo_gfx_texture_2d_t;
typedef
struct
{
- irodeo_gfx_texture_internal_t *internal_texture;
+ irodeo_gfx_texture_2d_t *data;
uint32_t width;
uint32_t height;
}
diff --git a/include/rodeo/math.h b/include/rodeo/math.h
new file mode 100644
index 0000000..3896fef
--- /dev/null
+++ b/include/rodeo/math.h
@@ -0,0 +1,17 @@
+#pragma once
+
+// --- internal ---
+// public
+#include "rodeo/math_t.h"
+#include "rodeo/math/vec2.h"
+#include "rodeo/math/vec3.h"
+#include "rodeo/math/mat4.h"
+#include "rodeo/math/rng.h"
+
+#define mrodeo_math_pi 3.1415927410125732421875f
+
+float
+rodeo_math_radians_to_turns(float radians);
+
+float
+rodeo_math_turns_to_radians(float turns);
diff --git a/include/rodeo/math/mat4.h b/include/rodeo/math/mat4.h
new file mode 100644
index 0000000..5dbc872
--- /dev/null
+++ b/include/rodeo/math/mat4.h
@@ -0,0 +1,38 @@
+#pragma once
+
+// -- internal --
+// public
+#include "rodeo/math/mat4_t.h"
+#include "rodeo/math.h"
+
+rodeo_math_mat4_t
+rodeo_math_mat4_identity(void);
+
+rodeo_math_mat4_t
+rodeo_math_mat4_zero(void);
+
+rodeo_math_mat4_t
+rodeo_math_mat4_transpose(rodeo_math_mat4_t m);
+
+rodeo_math_mat4_t
+rodeo_math_mat4_translate(rodeo_math_mat4_t m, rodeo_math_vec3_t v);
+
+rodeo_math_mat4_t
+rodeo_math_mat4_scale(rodeo_math_mat4_t m, rodeo_math_vec3_t v);
+
+rodeo_math_mat4_t
+rodeo_math_mat4_rotate(rodeo_math_mat4_t m, float turns, rodeo_math_vec3_t v);
+
+rodeo_math_mat4_t
+rodeo_math_mat4_multiply(rodeo_math_mat4_t a, rodeo_math_mat4_t b);
+
+rodeo_math_mat4_t
+rodeo_math_mat4_orthographic(
+ float left,
+ float right,
+ float bottom,
+ float top,
+ float near,
+ float far
+);
+
diff --git a/include/rodeo/math/mat4_t.h b/include/rodeo/math/mat4_t.h
new file mode 100644
index 0000000..e00656c
--- /dev/null
+++ b/include/rodeo/math/mat4_t.h
@@ -0,0 +1,19 @@
+#pragma once
+
+typedef
+struct
+{
+ float m00, m01, m02, m03;
+ float m10, m11, m12, m13;
+ float m20, m21, m22, m23;
+ float m30, m31, m32, m33;
+}
+rodeo_math_mat4_val_t;
+
+typedef
+union
+{
+ rodeo_math_mat4_val_t val;
+ float raw[4][4];
+}
+rodeo_math_mat4_t;
diff --git a/include/rodeo/math/rng.h b/include/rodeo/math/rng.h
new file mode 100644
index 0000000..53f1f76
--- /dev/null
+++ b/include/rodeo/math/rng.h
@@ -0,0 +1,48 @@
+#pragma once
+
+// -- internal --
+#include "rodeo/math/rng_t.h"
+
+// -- system --
+#include <inttypes.h>
+
+void
+rodeo_math_rng_init(void);
+
+void
+rodeo_math_rng_deinit(void);
+
+rodeo_math_rng_generator_t
+rodeo_math_rng_generator_create(uint64_t seed);
+
+void
+rodeo_math_rng_generator_destroy(rodeo_math_rng_generator_t generator);
+
+double
+rodeo_math_rng_double_get(rodeo_math_rng_generator_t generator);
+
+#define irodeo_math_rng_double_get_default() rodeo_math_rng_double_get((rodeo_math_rng_generator_t){0})
+
+float
+rodeo_math_rng_float_get(rodeo_math_rng_generator_t generator);
+
+#define irodeo_math_rng_float_get_default() rodeo_math_rng_float_get((rodeo_math_rng_generator_t){0})
+
+uint64_t
+rodeo_math_rng_uint64_get(rodeo_math_rng_generator_t generator);
+
+#define irodeo_math_rng_uint64_get_default() rodeo_math_rng_uint64_get((rodeo_math_rng_generator_t){0})
+
+uint32_t
+rodeo_math_rng_uint32_get(rodeo_math_rng_generator_t generator);
+
+#define irodeo_math_rng_uint32_get_default() rodeo_math_rng_uint32_get((rodeo_math_rng_generator_t){0})
+
+#define \
+mrodeo_math_rng_do( \
+) \
+ mrodeo_defer_do( \
+ rodeo_math_rng_init(), \
+ rodeo_math_rng_deinit() \
+ )
+
diff --git a/include/rodeo/math/rng_t.h b/include/rodeo/math/rng_t.h
new file mode 100644
index 0000000..8c527ed
--- /dev/null
+++ b/include/rodeo/math/rng_t.h
@@ -0,0 +1,16 @@
+#pragma once
+
+// -- system --
+#include <inttypes.h>
+
+typedef struct irodeo_math_rng_generator irodeo_math_rng_generator_t;
+
+typedef
+struct
+{
+ // note: a seed value of '0' is reserved for when using the
+ // global seed is desired.
+ uint64_t seed;
+ irodeo_math_rng_generator_t *data;
+}
+rodeo_math_rng_generator_t;
diff --git a/include/rodeo/math/vec2.h b/include/rodeo/math/vec2.h
new file mode 100644
index 0000000..88d524f
--- /dev/null
+++ b/include/rodeo/math/vec2.h
@@ -0,0 +1,53 @@
+#pragma once
+
+// -- internal --
+// public
+#include "rodeo/math/vec2_t.h"
+
+rodeo_math_vec2_t
+rodeo_math_vec2_zero(void);
+
+rodeo_math_vec2_t
+rodeo_math_vec2_one(void);
+
+float
+rodeo_math_vec2_dot(rodeo_math_vec2_t a, rodeo_math_vec2_t b);
+
+float
+rodeo_math_vec2_cross(rodeo_math_vec2_t a, rodeo_math_vec2_t b);
+
+rodeo_math_vec2_t
+rodeo_math_vec2_add(rodeo_math_vec2_t a, rodeo_math_vec2_t b);
+
+rodeo_math_vec2_t
+rodeo_math_vec2_subtract(rodeo_math_vec2_t a, rodeo_math_vec2_t b);
+
+rodeo_math_vec2_t
+rodeo_math_vec2_multiply(rodeo_math_vec2_t a, rodeo_math_vec2_t b);
+
+rodeo_math_vec2_t
+rodeo_math_vec2_scale(rodeo_math_vec2_t a, float b);
+
+rodeo_math_vec2_t
+rodeo_math_vec2_divide(rodeo_math_vec2_t a, rodeo_math_vec2_t b);
+
+rodeo_math_vec2_t
+rodeo_math_vec2_negate(rodeo_math_vec2_t a);
+
+rodeo_math_vec2_t
+rodeo_math_vec2_normalize(rodeo_math_vec2_t a);
+
+rodeo_math_vec2_t
+rodeo_math_vec2_rotate(rodeo_math_vec2_t a, float turns);
+
+float
+rodeo_math_vec2_distance(rodeo_math_vec2_t a, rodeo_math_vec2_t b);
+
+float
+rodeo_math_vec2_distanceSq(rodeo_math_vec2_t a, rodeo_math_vec2_t b);
+
+rodeo_math_vec2_t
+rodeo_math_vec2_clamp(rodeo_math_vec2_t a, float minimum, float maximum);
+
+rodeo_math_vec2_t
+rodeo_math_vec2_lerp(rodeo_math_vec2_t from, rodeo_math_vec2_t to, float t);
diff --git a/include/rodeo/math/vec2_t.h b/include/rodeo/math/vec2_t.h
new file mode 100644
index 0000000..22717c6
--- /dev/null
+++ b/include/rodeo/math/vec2_t.h
@@ -0,0 +1,17 @@
+#pragma once
+
+typedef
+struct
+{
+ float x;
+ float y;
+}
+rodeo_math_vec2_val_t;
+
+typedef
+union
+{
+ rodeo_math_vec2_val_t val;
+ float raw[2];
+}
+rodeo_math_vec2_t;
diff --git a/include/rodeo/math/vec3.h b/include/rodeo/math/vec3.h
new file mode 100644
index 0000000..1b9cd31
--- /dev/null
+++ b/include/rodeo/math/vec3.h
@@ -0,0 +1,53 @@
+#pragma once
+
+// -- internal --
+// public
+#include "rodeo/math/vec3_t.h"
+
+rodeo_math_vec3_t
+rodeo_math_vec3_zero(void);
+
+rodeo_math_vec3_t
+rodeo_math_vec3_one(void);
+
+float
+rodeo_math_vec3_dot(rodeo_math_vec3_t a, rodeo_math_vec3_t b);
+
+float
+rodeo_math_vec3_cross(rodeo_math_vec3_t a, rodeo_math_vec3_t b);
+
+rodeo_math_vec3_t
+rodeo_math_vec3_add(rodeo_math_vec3_t a, rodeo_math_vec3_t b);
+
+rodeo_math_vec3_t
+rodeo_math_vec3_subtract(rodeo_math_vec3_t a, rodeo_math_vec3_t b);
+
+rodeo_math_vec3_t
+rodeo_math_vec3_multiply(rodeo_math_vec3_t a, rodeo_math_vec3_t b);
+
+rodeo_math_vec3_t
+rodeo_math_vec3_scale(rodeo_math_vec3_t a, float b);
+
+rodeo_math_vec3_t
+rodeo_math_vec3_divide(rodeo_math_vec3_t a, rodeo_math_vec3_t b);
+
+rodeo_math_vec3_t
+rodeo_math_vec3_negate(rodeo_math_vec3_t a);
+
+rodeo_math_vec3_t
+rodeo_math_vec3_normalize(rodeo_math_vec3_t a);
+
+rodeo_math_vec3_t
+rodeo_math_vec3_rotate(rodeo_math_vec3_t a, float turns, rodeo_math_vec3_t axis);
+
+float
+rodeo_math_vec3_distance(rodeo_math_vec3_t a, rodeo_math_vec3_t b);
+
+float
+rodeo_math_vec3_distanceSq(rodeo_math_vec3_t a, rodeo_math_vec3_t b);
+
+rodeo_math_vec3_t
+rodeo_math_vec3_clamp(rodeo_math_vec3_t a, float minimum, float maximum);
+
+rodeo_math_vec3_t
+rodeo_math_vec3_lerp(rodeo_math_vec3_t from, rodeo_math_vec3_t to, float t);
diff --git a/include/rodeo/math/vec3_t.h b/include/rodeo/math/vec3_t.h
new file mode 100644
index 0000000..a3b3a36
--- /dev/null
+++ b/include/rodeo/math/vec3_t.h
@@ -0,0 +1,18 @@
+#pragma once
+
+typedef
+struct
+{
+ float x;
+ float y;
+ float z;
+}
+rodeo_math_vec3_val_t;
+
+typedef
+union
+{
+ rodeo_math_vec3_val_t val;
+ float raw[3];
+}
+rodeo_math_vec3_t;
diff --git a/include/rodeo/math_t.h b/include/rodeo/math_t.h
new file mode 100644
index 0000000..9374c2a
--- /dev/null
+++ b/include/rodeo/math_t.h
@@ -0,0 +1,5 @@
+#pragma once
+
+// --- internal ---
+// public
+#include "rodeo/math/vec2_t.h"
diff --git a/include/rodeo/window.h b/include/rodeo/window.h
index 2dcfab2..df73b4f 100644
--- a/include/rodeo/window.h
+++ b/include/rodeo/window.h
@@ -13,8 +13,8 @@
void
rodeo_window_init(
- uint16_t screen_height,
- uint16_t screen_width,
+ uint32_t screen_height,
+ uint32_t screen_width,
cstr title
);
diff --git a/src/gfx/irodeo_gfx_t.h b/src/gfx/irodeo_gfx_t.h
index b367e0f..5320d82 100644
--- a/src/gfx/irodeo_gfx_t.h
+++ b/src/gfx/irodeo_gfx_t.h
@@ -3,11 +3,10 @@
// -- internal --
// public
#include "rodeo/gfx_t.h"
+#include "rodeo/math.h"
// -- external --
#include "bgfx/c99/bgfx.h"
-#define CGLM_FORCE_DEPTH_ZERO_TO_ONE
-#include "cglm/mat4.h"
typedef uint16_t irodeo_index_type_t;
@@ -33,8 +32,10 @@ struct
bgfx_uniform_handle_t texture_uniforms[2];
float target_width;
float target_height;
- mat4 view_matrix;
- mat4 proj_matrix;
+ //mat4 view_matrix;
+ //mat4 proj_matrix;
+ rodeo_math_mat4_t view_matrix;
+ rodeo_math_mat4_t proj_matrix;
uint64_t frame_count;
uint32_t frame_limit;
uint32_t frame_start;
@@ -44,7 +45,7 @@ struct
irodeo_gfx_state_t;
struct
-irodeo_gfx_texture_internal
+irodeo_gfx_texture_2d
{
bgfx_texture_handle_t texture_bgfx;
};
diff --git a/src/gfx/rodeo_gfx.c b/src/gfx/rodeo_gfx.c
index 33c4be3..f55963a 100644
--- a/src/gfx/rodeo_gfx.c
+++ b/src/gfx/rodeo_gfx.c
@@ -12,14 +12,12 @@
// -- external --
#include "bgfx/c99/bgfx.h"
-#define CGLM_FORCE_DEPTH_ZERO_TO_ONE
-#include "cglm/cglm.h"
#include "SDL_image.h"
#include "SDL.h" // used for timing, need to replace in this file with BGFX at some point
static irodeo_gfx_state_t irodeo_gfx_state = {0};
- void
+void
rodeo_gfx_init(float width, float height)
{
@@ -139,7 +137,7 @@ rodeo_gfx_init(float width, float height)
//bgfx_texture_handle_t default_bgfx_texture = rodeo_texture_2d_create_default();
- irodeo_gfx_state.default_texture.internal_texture = malloc(sizeof(irodeo_gfx_texture_internal_t));
+ irodeo_gfx_state.default_texture.data = malloc(sizeof(*irodeo_gfx_state.default_texture.data));
// used for binding textures to shader uniforms
irodeo_gfx_state.texture_uniforms[0] = bgfx_create_uniform("default_texture", BGFX_UNIFORM_TYPE_SAMPLER, 1);
@@ -152,7 +150,7 @@ rodeo_gfx_init(float width, float height)
0xff, 0xff, 0xff, 0xff,
};
- irodeo_gfx_state.default_texture.internal_texture->texture_bgfx =
+ irodeo_gfx_state.default_texture.data->texture_bgfx =
bgfx_create_texture_2d(
1,
1,
@@ -168,7 +166,7 @@ rodeo_gfx_init(float width, float height)
irodeo_gfx_state.default_texture.width = 1;
irodeo_gfx_state.default_texture.height = 1;
- irodeo_gfx_state.active_texture_p = &irodeo_gfx_state.default_texture.internal_texture->texture_bgfx;
+ irodeo_gfx_state.active_texture_p = &irodeo_gfx_state.default_texture.data->texture_bgfx;
}
SDL_SetWindowResizable(irodeo_window_get(), true);
@@ -181,33 +179,22 @@ rodeo_gfx_init(float width, float height)
BGFX_TEXTURE_FORMAT_COUNT
);
- rodeo_random_seed_set(SDL_GetTicks64());
-
irodeo_gfx_state.frame_end = (uint32_t)SDL_GetPerformanceCounter();
}
- void
+void
rodeo_gfx_deinit(void)
{
- free(irodeo_gfx_state.default_texture.internal_texture);
+ free(irodeo_gfx_state.default_texture.data);
bgfx_destroy_program(irodeo_gfx_state.program_shader);
bgfx_shutdown();
}
- void
+void
rodeo_gfx_frame_begin(void)
{
- //vec3 eye = {0.0f, 0.0f, -35.0f};
- //vec3 center = {0.0f, 0.0f, 0.0f};
- //vec3 up = {0, 1, 0};
-
- //glm_lookat(eye, center, up, view);
-
- glm_mat4_identity(irodeo_gfx_state.view_matrix);
-
- //glm_perspective(glm_rad(60.f), 640.f / 480.f, 0.1f, 100.0f, proj);
// scale the game screen to fit window size with letterbox
// what size we declare the game screen to be within
@@ -227,29 +214,33 @@ rodeo_gfx_frame_begin(void)
result_height *= (game_aspect) / window_aspect;
}
- // make the game screen centered in the window.
- // "2" is 1 full screen width, therefore we multiply
- // the target and result ratio by 1 for it to be a
- // half of the screen size
- vec3 offset = {
- 1 - (1 * (target_width / result_width)), // x
- -(1 - (1 * (target_height / result_height))), // y
- 0
+ // get identity
+ irodeo_gfx_state.view_matrix = rodeo_math_mat4_identity();
+ irodeo_gfx_state.proj_matrix = rodeo_math_mat4_identity();
+
+ // calculate orthographic
+ rodeo_math_mat4_t ortho = rodeo_math_mat4_orthographic(
+ 0,
+ result_width,
+ result_height,
+ 0,
+ -100.0f,
+ 100.0f
+ );
+
+ // calculate translation
+ rodeo_math_vec3_t offset = {
+ .val.x = 1 - (1 * (target_width / result_width)), // x
+ .val.y = -(1 - (1 * (target_height / result_height))), // y
+ .val.z = 0
};
- glm_ortho_rh_zo(
- 0,
- result_width,
- result_height,
- 0,
- -100.0f,
- 100.0f,
- irodeo_gfx_state.proj_matrix
- );
-
- glm_translated(irodeo_gfx_state.proj_matrix, offset);
+ // apply translation * orthographic
+ irodeo_gfx_state.proj_matrix = rodeo_math_mat4_translate(irodeo_gfx_state.proj_matrix, offset);
+ irodeo_gfx_state.proj_matrix = rodeo_math_mat4_multiply(irodeo_gfx_state.proj_matrix, ortho);
- bgfx_set_view_transform(0, irodeo_gfx_state.view_matrix, irodeo_gfx_state.proj_matrix);
+ // push the result to bgfx
+ bgfx_set_view_transform(0, irodeo_gfx_state.view_matrix.raw, irodeo_gfx_state.proj_matrix.raw);
bgfx_set_view_rect(0, 0, 0, (uint16_t)rodeo_window_width_get(), (uint16_t)rodeo_window_height_get());
irodeo_gfx_render_buffer_transient_alloc();
@@ -258,7 +249,7 @@ rodeo_gfx_frame_begin(void)
irodeo_gfx_state.frame_start = irodeo_gfx_state.frame_end;
}
- void
+void
rodeo_gfx_frame_end(void)
{
rodeo_gfx_renderer_flush();
@@ -279,19 +270,19 @@ rodeo_gfx_frame_end(void)
#endif
}
- float
+float
rodeo_gfx_width_get(void)
{
return irodeo_gfx_state.target_width;
}
- float
+float
rodeo_gfx_height_get(void)
{
return irodeo_gfx_state.target_height;
}
- rodeo_rectangle_t
+rodeo_rectangle_t
rodeo_gfx_letterbox_first_get(void)
{
const float target_width = irodeo_gfx_state.target_width;
@@ -310,7 +301,7 @@ rodeo_gfx_letterbox_first_get(void)
result_height *= (game_aspect) / window_aspect;
}
- rodeo_rectangle_t result = {0};
+rodeo_rectangle_t result = {0};
// while checking for float equality should generally never be done
// in this case it is ok because the case where they are exactly equal
@@ -329,10 +320,10 @@ rodeo_gfx_letterbox_first_get(void)
return result;
}
- rodeo_rectangle_t
+rodeo_rectangle_t
rodeo_gfx_letterbox_second_get(void)
{
- rodeo_rectangle_t result = rodeo_gfx_letterbox_first_get();
+rodeo_rectangle_t result = rodeo_gfx_letterbox_first_get();
if(rodeo_gfx_width_get() != result.width)
{ // second box needs to be offset to the right
result.x += rodeo_gfx_width_get() + result.width;
@@ -344,13 +335,13 @@ rodeo_gfx_letterbox_second_get(void)
return result;
}
- float
+float
rodeo_gfx_frame_time_get(void)
{
return irodeo_gfx_state.frame_time; //(float)bgfx_get_stats()->cpuTimeFrame;
}
- float
+float
rodeo_gfx_frame_perSecond_get(void)
{
return 1.0f / (rodeo_gfx_frame_time_get() / 1000.0f);
@@ -359,7 +350,7 @@ rodeo_gfx_frame_perSecond_get(void)
// measures how much time there is left in the remaining frame until
// the frame target time is reached. If we surpassed the target time
// then this will be negative
- float
+float
irodeo_gfx_frame_remaining_get(void)
{
#ifdef __EMSCRIPTEN__
@@ -376,7 +367,7 @@ irodeo_gfx_frame_remaining_get(void)
// used internally at the end of every frame to fill for time
// in order to reach the desired framerate
- void
+void
irodeo_gfx_frame_stall(void)
{
// if no frame limit then run as fast as possible
@@ -400,14 +391,14 @@ irodeo_gfx_frame_stall(void)
}
}
- void
+void
rodeo_gfx_renderer_flush(void)
{
// set default texture
bgfx_set_texture(
0,
irodeo_gfx_state.texture_uniforms[0],
- rodeo_gfx_texture_2d_default_get().internal_texture->texture_bgfx,
+ rodeo_gfx_texture_2d_default_get().data->texture_bgfx,
UINT32_MAX
);
if(irodeo_gfx_state.active_texture_p != NULL)
@@ -426,7 +417,7 @@ rodeo_gfx_renderer_flush(void)
bgfx_set_texture(
1,
irodeo_gfx_state.texture_uniforms[1],
- rodeo_gfx_texture_2d_default_get().internal_texture->texture_bgfx,
+ rodeo_gfx_texture_2d_default_get().data->texture_bgfx,
UINT32_MAX
);
}
@@ -469,13 +460,13 @@ rodeo_gfx_renderer_flush(void)
irodeo_gfx_state.active_texture_p = NULL;
}
- rodeo_gfx_texture_2d_t
+rodeo_gfx_texture_2d_t
rodeo_gfx_texture_2d_default_get(void)
{
return irodeo_gfx_state.default_texture;
}
- rodeo_gfx_texture_2d_t
+rodeo_gfx_texture_2d_t
rodeo_gfx_texture_2d_create_from_RGBA8(
const uint16_t width,
const uint16_t height,
@@ -483,9 +474,9 @@ rodeo_gfx_texture_2d_create_from_RGBA8(
)
{
rodeo_gfx_texture_2d_t texture;
- texture.internal_texture = malloc(sizeof(irodeo_gfx_texture_internal_t));
+ texture.data = malloc(sizeof(*texture.data));
bgfx_copy(memory, (uint32_t)width * (uint32_t)height * sizeof(uint8_t) * 4);
- texture.internal_texture->texture_bgfx =
+ texture.data->texture_bgfx =
bgfx_create_texture_2d(
width,
height,
@@ -502,18 +493,18 @@ rodeo_gfx_texture_2d_create_from_RGBA8(
return texture;
}
- void
+void
rodeo_gfx_texture_2d_destroy(rodeo_gfx_texture_2d_t texture)
{
- bgfx_destroy_texture(texture.internal_texture->texture_bgfx);
- free(texture.internal_texture);
+ bgfx_destroy_texture(texture.data->texture_bgfx);
+ free(texture.data);
}
- void
+void
rodeo_gfx_rectangle_draw(
- const rodeo_rectangle_t rectangle,
- const rodeo_color_RGBAFloat_t color
- )
+ const rodeo_rectangle_t rectangle,
+ const rodeo_color_RGBAFloat_t color
+)
{
rodeo_gfx_texture_2d_draw(
rectangle,
@@ -525,21 +516,21 @@ rodeo_gfx_rectangle_draw(
void
rodeo_gfx_texture_2d_draw(
- // cant be NULL
- const rodeo_rectangle_t destination,
- // default: entire texture
- const rodeo_rectangle_t source,
- // default: white
- const rodeo_color_RGBAFloat_t color,
- // default: default texture
- const rodeo_gfx_texture_2d_t texture
- )
+ // cant be NULL
+ const rodeo_rectangle_t destination,
+ // default: entire texture
+ const rodeo_rectangle_t source,
+ // default: white
+ const rodeo_color_RGBAFloat_t color,
+ // default: default texture
+ const rodeo_gfx_texture_2d_t texture
+)
{
// whether to use default or custom texture
float texture_uniform_slot = 0.0;
rodeo_rectangle_t source_applied;
- if((source.height != 0 || source.width != 0) && texture.internal_texture != NULL)
+ if((source.height != 0 || source.width != 0) && texture.data != NULL)
{
source_applied = (rodeo_rectangle_t){
.x = source.x / (float)texture.width,
@@ -562,17 +553,17 @@ rodeo_gfx_texture_2d_draw(
// otherwise check what current texture is active
// if none or the same: set it
// if different: flush and then set it
- if(texture.internal_texture != NULL)
+ if(texture.data != NULL)
{
if(irodeo_gfx_state.active_texture_p != NULL)
{
- if(&texture.internal_texture->texture_bgfx != irodeo_gfx_state.active_texture_p)
+ if(&texture.data->texture_bgfx != irodeo_gfx_state.active_texture_p)
{
rodeo_gfx_renderer_flush();
}
}
texture_uniform_slot = 1.0;
- irodeo_gfx_state.active_texture_p = &texture.internal_texture->texture_bgfx;
+ irodeo_gfx_state.active_texture_p = &texture.data->texture_bgfx;
}
@@ -655,7 +646,7 @@ rodeo_gfx_texture_2d_draw(
}
}
- rodeo_gfx_texture_2d_t
+rodeo_gfx_texture_2d_t
rodeo_gfx_texture_2d_create_from_path(cstr path)
{
// load image to surface
@@ -711,13 +702,13 @@ rodeo_gfx_texture_2d_create_from_path(cstr path)
return texture;
}
- uint64_t
+uint64_t
rodeo_gfx_frame_count_get(void)
{
return irodeo_gfx_state.frame_count;
}
- void
+void
rodeo_gfx_frame_limit_set(uint32_t limit)
{
#ifdef __EMSCRIPTEN__
@@ -730,7 +721,7 @@ rodeo_gfx_frame_limit_set(uint32_t limit)
#endif
}
- uint32_t
+uint32_t
rodeo_gfx_frame_limit_get(void)
{
#ifdef __EMSCRIPTEN__
@@ -740,7 +731,7 @@ rodeo_gfx_frame_limit_get(void)
#endif
}
- cstr
+cstr
rodeo_gfx_renderer_name_get(void)
{
return cstr_from(
@@ -748,7 +739,7 @@ rodeo_gfx_renderer_name_get(void)
);
}
- bgfx_shader_handle_t
+bgfx_shader_handle_t
irodeo_gfx_shader_load(const cstr path)
{
const char* path_cstr = cstr_str(&path);
@@ -802,7 +793,7 @@ irodeo_gfx_shader_load(const cstr path)
return shader;
}
- void
+void
irodeo_gfx_render_buffer_transient_alloc(void)
{
bgfx_alloc_transient_vertex_buffer(&irodeo_gfx_state.vertex_buffer_handle, mrodeo_vertex_size_max, &irodeo_gfx_state.vertex_layout);
diff --git a/src/math/irodeo_mat4.h b/src/math/irodeo_mat4.h
new file mode 100644
index 0000000..ff625a7
--- /dev/null
+++ b/src/math/irodeo_mat4.h
@@ -0,0 +1,8 @@
+#pragma once
+
+// -- internal --
+// public
+#include "rodeo/math/mat4_t.h"
+
+void
+irodeo_print_matrix(rodeo_math_mat4_t mat);
diff --git a/src/math/irodeo_math.h b/src/math/irodeo_math.h
new file mode 100644
index 0000000..beed68f
--- /dev/null
+++ b/src/math/irodeo_math.h
@@ -0,0 +1,16 @@
+#pragma once
+
+// external needs to be first here
+// -- external --
+/*#define CGLM_FORCE_LEFT_HANDED*/
+#define CGLM_FORCE_DEPTH_ZERO_TO_ONE
+/*#define CGLM_CLIPSPACE_INCLUDE_ALL*/
+#include "cglm/struct.h"
+
+// -- internal --
+// private
+#include "math/irodeo_vec2.h"
+#include "math/irodeo_vec3.h"
+//#include "math/irodeo_mat4.h"
+
+
diff --git a/src/math/irodeo_math_t.h b/src/math/irodeo_math_t.h
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/src/math/irodeo_math_t.h
@@ -0,0 +1 @@
+
diff --git a/src/math/irodeo_rng_t.h b/src/math/irodeo_rng_t.h
new file mode 100644
index 0000000..0419496
--- /dev/null
+++ b/src/math/irodeo_rng_t.h
@@ -0,0 +1,23 @@
+#pragma once
+
+// -- internal --
+// public
+#include "rodeo/math/rng_t.h"
+// private
+#include "math/irodeo_rng_t.h"
+
+// -- external --
+#include "stc/crand.h"
+
+typedef
+struct
+{
+ rodeo_math_rng_generator_t global_generator;
+}
+irodeo_math_rng_state_t;
+
+struct
+irodeo_math_rng_generator
+{
+ crand_t crand;
+};
diff --git a/src/math/irodeo_vec2.h b/src/math/irodeo_vec2.h
new file mode 100644
index 0000000..0b79032
--- /dev/null
+++ b/src/math/irodeo_vec2.h
@@ -0,0 +1,14 @@
+#pragma once
+
+// -- internal --
+// public
+#include "rodeo/math/vec2_t.h"
+// private
+#include "math/irodeo_math.h"
+
+rodeo_math_vec2_t
+irodeo_math_cglmVec2_to_rodeoVec2(vec2s in);
+
+vec2s
+irodeo_math_rodeoVec2_to_cglmVec2(rodeo_math_vec2_t in);
+
diff --git a/src/math/irodeo_vec3.h b/src/math/irodeo_vec3.h
new file mode 100644
index 0000000..bbfffac
--- /dev/null
+++ b/src/math/irodeo_vec3.h
@@ -0,0 +1,15 @@
+
+#pragma once
+
+// -- internal --
+// public
+#include "rodeo/math/vec3_t.h"
+// private
+#include "math/irodeo_math.h"
+
+rodeo_math_vec3_t
+irodeo_math_cglmVec3_to_rodeoVec3(vec3s in);
+
+vec3s
+irodeo_math_rodeoVec3_to_cglmVec3(rodeo_math_vec3_t in);
+
diff --git a/src/math/rodeo_mat4.c b/src/math/rodeo_mat4.c
new file mode 100644
index 0000000..70d0226
--- /dev/null
+++ b/src/math/rodeo_mat4.c
@@ -0,0 +1,171 @@
+
+// -- internal --
+// public
+#include "rodeo/math.h"
+#include "rodeo/log.h"
+// private
+#include "math/irodeo_math.h"
+
+static inline
+rodeo_math_mat4_t
+irodeo_math_cglmMat4_to_rodeoMat4(mat4s in)
+{
+ return (rodeo_math_mat4_t){
+ .val = {
+ .m00 = in.raw[0][0], .m01 = in.raw[0][1], .m02 = in.raw[0][2], .m03 = in.raw[0][3],
+ .m10 = in.raw[1][0], .m11 = in.raw[1][1], .m12 = in.raw[1][2], .m13 = in.raw[1][3],
+ .m20 = in.raw[2][0], .m21 = in.raw[2][1], .m22 = in.raw[2][2], .m23 = in.raw[2][3],
+ .m30 = in.raw[3][0], .m31 = in.raw[3][1], .m32 = in.raw[3][2], .m33 = in.raw[3][3]
+ }
+ };
+}
+
+static inline
+mat4s
+irodeo_math_rodeoMat4_to_cglmMat4(rodeo_math_mat4_t in)
+{
+ return (mat4s){
+ .raw = {
+ {
+ in.val.m00, in.val.m01, in.val.m02, in.val.m03
+ },
+ {
+ in.val.m10, in.val.m11, in.val.m12, in.val.m13
+ },
+ {
+ in.val.m20, in.val.m21, in.val.m22, in.val.m23
+ },
+ {
+ in.val.m30, in.val.m31, in.val.m32, in.val.m33
+ },
+ }
+ };
+}
+
+void
+irodeo_print_matrix(rodeo_math_mat4_t mat)
+{
+ rodeo_log(
+ rodeo_logLevel_warning,
+ "%.05f, %.05f, %.05f, %.05f",
+ mat.raw[0][0],
+ mat.raw[0][1],
+ mat.raw[0][2],
+ mat.raw[0][3]
+ );
+ rodeo_log(
+ rodeo_logLevel_info,
+ "%.05f, %.05f, %.05f, %.05f",
+ mat.raw[1][0],
+ mat.raw[1][1],
+ mat.raw[1][2],
+ mat.raw[1][3]
+ );
+ rodeo_log(
+ rodeo_logLevel_info,
+ "%.05f, %.05f, %.05f, %.05f",
+ mat.raw[2][0],
+ mat.raw[2][1],
+ mat.raw[2][2],
+ mat.raw[2][3]
+ );
+ rodeo_log(
+ rodeo_logLevel_info,
+ "%.05f, %.05f, %.05f, %.05f",
+ mat.raw[3][0],
+ mat.raw[3][1],
+ mat.raw[3][2],
+ mat.raw[3][3]
+ );
+}
+
+
+rodeo_math_mat4_t
+rodeo_math_mat4_identity(void)
+{
+ return irodeo_math_cglmMat4_to_rodeoMat4(glms_mat4_identity());
+}
+
+rodeo_math_mat4_t
+rodeo_math_mat4_zero(void)
+{
+ return irodeo_math_cglmMat4_to_rodeoMat4(glms_mat4_zero());
+}
+
+rodeo_math_mat4_t
+rodeo_math_mat4_transpose(rodeo_math_mat4_t m)
+{
+ return irodeo_math_cglmMat4_to_rodeoMat4(
+ glms_mat4_transpose(
+ irodeo_math_rodeoMat4_to_cglmMat4(m)
+ )
+ );
+}
+
+rodeo_math_mat4_t
+rodeo_math_mat4_translate(rodeo_math_mat4_t m, rodeo_math_vec3_t v)
+{
+ return irodeo_math_cglmMat4_to_rodeoMat4(
+ glms_translate(
+ irodeo_math_rodeoMat4_to_cglmMat4(m),
+ irodeo_math_rodeoVec3_to_cglmVec3(v)
+ )
+ );
+}
+
+rodeo_math_mat4_t
+rodeo_math_mat4_scale(rodeo_math_mat4_t m, rodeo_math_vec3_t v)
+{
+ return irodeo_math_cglmMat4_to_rodeoMat4(
+ glms_scale(
+ irodeo_math_rodeoMat4_to_cglmMat4(m),
+ irodeo_math_rodeoVec3_to_cglmVec3(v)
+ )
+ );
+}
+
+rodeo_math_mat4_t
+rodeo_math_mat4_rotate(rodeo_math_mat4_t m, float turns, rodeo_math_vec3_t v)
+{
+ return irodeo_math_cglmMat4_to_rodeoMat4(
+ glms_rotate(
+ irodeo_math_rodeoMat4_to_cglmMat4(m),
+ turns,
+ irodeo_math_rodeoVec3_to_cglmVec3(v)
+ )
+ );
+}
+
+rodeo_math_mat4_t
+rodeo_math_mat4_multiply(rodeo_math_mat4_t a, rodeo_math_mat4_t b)
+{
+ return irodeo_math_cglmMat4_to_rodeoMat4(
+ glms_mat4_mul(
+ irodeo_math_rodeoMat4_to_cglmMat4(a),
+ irodeo_math_rodeoMat4_to_cglmMat4(b)
+ )
+ );
+}
+
+rodeo_math_mat4_t
+rodeo_math_mat4_orthographic(
+ float left,
+ float right,
+ float bottom,
+ float top,
+ float near,
+ float far
+)
+{
+ return irodeo_math_cglmMat4_to_rodeoMat4(
+ glms_ortho_rh_zo(
+ left,
+ right,
+ bottom,
+ top,
+ near,
+ far
+ )
+ );
+}
+
diff --git a/src/math/rodeo_math.c b/src/math/rodeo_math.c
new file mode 100644
index 0000000..20516e3
--- /dev/null
+++ b/src/math/rodeo_math.c
@@ -0,0 +1,20 @@
+
+// -- internal --
+// public
+#include "rodeo/math.h"
+
+// -- system --
+#include "math.h"
+
+float
+rodeo_math_radians_to_turns(float radians)
+{
+ return (radians / mrodeo_math_pi) / 2.0f;
+}
+
+float
+rodeo_math_turns_to_radians(float turns)
+{
+ return turns * mrodeo_math_pi * 2.0f;
+}
+
diff --git a/src/math/rodeo_rng.c b/src/math/rodeo_rng.c
new file mode 100644
index 0000000..bf94e0b
--- /dev/null
+++ b/src/math/rodeo_rng.c
@@ -0,0 +1,81 @@
+
+// internal
+// public
+#include "rodeo/math/rng.h"
+// private
+#include "math/irodeo_rng_t.h"
+
+// external
+#include "stc/crand.h"
+#include "SDL.h"
+
+// system
+#include <inttypes.h>
+
+void
+rodeo_math_rng_init(void)
+{
+ csrand(SDL_GetTicks64());
+}
+
+void
+rodeo_math_rng_deinit(void)
+{
+ // no need to do anything
+}
+
+rodeo_math_rng_generator_t
+rodeo_math_rng_generator_create(uint64_t seed)
+{
+ rodeo_math_rng_generator_t result = {
+ .seed = seed,
+ .data = malloc(sizeof(*(rodeo_math_rng_generator_t){0}.data))
+ };
+ result.data->crand = crand_init(seed);
+ return result;
+}
+
+void
+rodeo_math_rng_generator_destroy(rodeo_math_rng_generator_t generator)
+{
+ free(generator.data);
+}
+
+double
+rodeo_math_rng_double_get(rodeo_math_rng_generator_t generator)
+{
+ if(generator.seed == 0)
+ {
+ return crandf();
+ }
+ else
+ {
+ return crand_f64(&generator.data->crand);
+ }
+}
+
+float
+rodeo_math_rng_float_get(rodeo_math_rng_generator_t generator)
+{
+ return (float)rodeo_math_rng_double_get(generator);
+}
+
+uint64_t
+rodeo_math_rng_uint64_get(rodeo_math_rng_generator_t generator)
+{
+ if(generator.seed == 0)
+ {
+ return crand();
+ }
+ else
+ {
+ return crand_u64(&generator.data->crand);
+ }
+}
+
+uint32_t
+rodeo_math_rng_uint32_get(rodeo_math_rng_generator_t generator)
+{
+ return (uint32_t)rodeo_math_rng_uint64_get(generator);
+}
+
diff --git a/src/math/rodeo_vec2.c b/src/math/rodeo_vec2.c
new file mode 100644
index 0000000..be9d7ff
--- /dev/null
+++ b/src/math/rodeo_vec2.c
@@ -0,0 +1,189 @@
+
+// -- internal --
+// public
+#include "rodeo/math.h"
+#include "rodeo/math/vec2.h"
+// private
+#include "math/irodeo_math.h"
+#include "math/irodeo_vec2.h"
+
+rodeo_math_vec2_t
+irodeo_math_cglmVec2_to_rodeoVec2(vec2s in)
+{
+ return (rodeo_math_vec2_t){
+ .raw[0] = in.raw[0],
+ .raw[1] = in.raw[1]
+ };
+}
+
+vec2s
+irodeo_math_rodeoVec2_to_cglmVec2(rodeo_math_vec2_t in)
+{
+ return (vec2s){
+ .raw[0] = in.raw[0],
+ .raw[1] = in.raw[1]
+ };
+}
+
+
+rodeo_math_vec2_t
+rodeo_math_vec2_zero(void)
+{
+ return irodeo_math_cglmVec2_to_rodeoVec2(glms_vec2_zero());
+}
+
+rodeo_math_vec2_t
+rodeo_math_vec2_one(void)
+{
+ return irodeo_math_cglmVec2_to_rodeoVec2(glms_vec2_one());
+}
+
+float
+rodeo_math_vec2_dot(rodeo_math_vec2_t a, rodeo_math_vec2_t b)
+{
+ return glms_vec2_dot(
+ irodeo_math_rodeoVec2_to_cglmVec2(a),
+ irodeo_math_rodeoVec2_to_cglmVec2(b)
+ );
+}
+
+float
+rodeo_math_vec2_cross(rodeo_math_vec2_t a, rodeo_math_vec2_t b)
+{
+ return glms_vec2_dot(
+ irodeo_math_rodeoVec2_to_cglmVec2(a),
+ irodeo_math_rodeoVec2_to_cglmVec2(b)
+ );
+}
+
+rodeo_math_vec2_t
+rodeo_math_vec2_add(rodeo_math_vec2_t a, rodeo_math_vec2_t b)
+{
+ return irodeo_math_cglmVec2_to_rodeoVec2(
+ glms_vec2_add(
+ irodeo_math_rodeoVec2_to_cglmVec2(a),
+ irodeo_math_rodeoVec2_to_cglmVec2(b)
+ )
+ );
+}
+
+rodeo_math_vec2_t
+rodeo_math_vec2_subtract(rodeo_math_vec2_t a, rodeo_math_vec2_t b)
+{
+ return irodeo_math_cglmVec2_to_rodeoVec2(
+ glms_vec2_sub(
+ irodeo_math_rodeoVec2_to_cglmVec2(a),
+ irodeo_math_rodeoVec2_to_cglmVec2(b)
+ )
+ );
+}
+
+rodeo_math_vec2_t
+rodeo_math_vec2_multiply(rodeo_math_vec2_t a, rodeo_math_vec2_t b)
+{
+ return irodeo_math_cglmVec2_to_rodeoVec2(
+ glms_vec2_mul(
+ irodeo_math_rodeoVec2_to_cglmVec2(a),
+ irodeo_math_rodeoVec2_to_cglmVec2(b)
+ )
+ );
+}
+
+rodeo_math_vec2_t
+rodeo_math_vec2_scale(rodeo_math_vec2_t a, float b)
+{
+ return irodeo_math_cglmVec2_to_rodeoVec2(
+ glms_vec2_scale(
+ irodeo_math_rodeoVec2_to_cglmVec2(a),
+ b
+ )
+ );
+}
+
+rodeo_math_vec2_t
+rodeo_math_vec2_divide(rodeo_math_vec2_t a, rodeo_math_vec2_t b)
+{
+ return irodeo_math_cglmVec2_to_rodeoVec2(
+ glms_vec2_div(
+ irodeo_math_rodeoVec2_to_cglmVec2(a),
+ irodeo_math_rodeoVec2_to_cglmVec2(b)
+ )
+ );
+}
+
+rodeo_math_vec2_t
+rodeo_math_vec2_negate(rodeo_math_vec2_t a)
+{
+ return irodeo_math_cglmVec2_to_rodeoVec2(
+ glms_vec2_negate(
+ irodeo_math_rodeoVec2_to_cglmVec2(a)
+ )
+ );
+}
+
+rodeo_math_vec2_t
+rodeo_math_vec2_normalize(rodeo_math_vec2_t a)
+{
+ return irodeo_math_cglmVec2_to_rodeoVec2(
+ glms_vec2_normalize(
+ irodeo_math_rodeoVec2_to_cglmVec2(a)
+ )
+ );
+}
+
+rodeo_math_vec2_t
+rodeo_math_vec2_rotate(rodeo_math_vec2_t a, float turns)
+{
+ return irodeo_math_cglmVec2_to_rodeoVec2(
+ glms_vec2_rotate(
+ irodeo_math_rodeoVec2_to_cglmVec2(a),
+ rodeo_math_radians_to_turns(turns)
+ )
+ );
+}
+
+float
+rodeo_math_vec2_distance(rodeo_math_vec2_t a, rodeo_math_vec2_t b)
+{
+ return (
+ glms_vec2_distance(
+ irodeo_math_rodeoVec2_to_cglmVec2(a),
+ irodeo_math_rodeoVec2_to_cglmVec2(b)
+ )
+ );
+}
+
+float
+rodeo_math_vec2_distanceSq(rodeo_math_vec2_t a, rodeo_math_vec2_t b)
+{
+ return (
+ glms_vec2_distance2(
+ irodeo_math_rodeoVec2_to_cglmVec2(a),
+ irodeo_math_rodeoVec2_to_cglmVec2(b)
+ )
+ );
+}
+
+rodeo_math_vec2_t
+rodeo_math_vec2_clamp(rodeo_math_vec2_t a, float minimum, float maximum)
+{
+ return irodeo_math_cglmVec2_to_rodeoVec2(
+ glms_vec2_clamp(
+ irodeo_math_rodeoVec2_to_cglmVec2(a),
+ minimum,
+ maximum
+ )
+ );
+}
+
+rodeo_math_vec2_t
+rodeo_math_vec2_lerp(rodeo_math_vec2_t from, rodeo_math_vec2_t to, float t)
+{
+ return irodeo_math_cglmVec2_to_rodeoVec2(
+ glms_vec2_lerp(
+ irodeo_math_rodeoVec2_to_cglmVec2(from),
+ irodeo_math_rodeoVec2_to_cglmVec2(to),
+ t
+ )
+ );
+}
diff --git a/src/math/rodeo_vec3.c b/src/math/rodeo_vec3.c
new file mode 100644
index 0000000..c94ecd3
--- /dev/null
+++ b/src/math/rodeo_vec3.c
@@ -0,0 +1,191 @@
+
+// -- internal --
+// public
+#include "rodeo/math.h"
+#include "rodeo/math/vec3.h"
+// private
+#include "math/irodeo_math.h"
+#include "math/irodeo_vec3.h"
+
+rodeo_math_vec3_t
+irodeo_math_cglmVec3_to_rodeoVec3(vec3s in)
+{
+ return (rodeo_math_vec3_t){
+ .raw[0] = in.raw[0],
+ .raw[1] = in.raw[1],
+ .raw[2] = in.raw[2]
+ };
+}
+
+vec3s
+irodeo_math_rodeoVec3_to_cglmVec3(rodeo_math_vec3_t in)
+{
+ return (vec3s){
+ .raw[0] = in.raw[0],
+ .raw[1] = in.raw[1],
+ .raw[2] = in.raw[2],
+ };
+}
+
+rodeo_math_vec3_t
+rodeo_math_vec3_zero(void)
+{
+ return irodeo_math_cglmVec3_to_rodeoVec3(glms_vec3_zero());
+}
+
+rodeo_math_vec3_t
+rodeo_math_vec3_one(void)
+{
+ return irodeo_math_cglmVec3_to_rodeoVec3(glms_vec3_one());
+}
+
+float
+rodeo_math_vec3_dot(rodeo_math_vec3_t a, rodeo_math_vec3_t b)
+{
+ return glms_vec3_dot(
+ irodeo_math_rodeoVec3_to_cglmVec3(a),
+ irodeo_math_rodeoVec3_to_cglmVec3(b)
+ );
+}
+
+float
+rodeo_math_vec3_cross(rodeo_math_vec3_t a, rodeo_math_vec3_t b)
+{
+ return glms_vec3_dot(
+ irodeo_math_rodeoVec3_to_cglmVec3(a),
+ irodeo_math_rodeoVec3_to_cglmVec3(b)
+ );
+}
+
+rodeo_math_vec3_t
+rodeo_math_vec3_add(rodeo_math_vec3_t a, rodeo_math_vec3_t b)
+{
+ return irodeo_math_cglmVec3_to_rodeoVec3(
+ glms_vec3_add(
+ irodeo_math_rodeoVec3_to_cglmVec3(a),
+ irodeo_math_rodeoVec3_to_cglmVec3(b)
+ )
+ );
+}
+
+rodeo_math_vec3_t
+rodeo_math_vec3_subtract(rodeo_math_vec3_t a, rodeo_math_vec3_t b)
+{
+ return irodeo_math_cglmVec3_to_rodeoVec3(
+ glms_vec3_sub(
+ irodeo_math_rodeoVec3_to_cglmVec3(a),
+ irodeo_math_rodeoVec3_to_cglmVec3(b)
+ )
+ );
+}
+
+rodeo_math_vec3_t
+rodeo_math_vec3_multiply(rodeo_math_vec3_t a, rodeo_math_vec3_t b)
+{
+ return irodeo_math_cglmVec3_to_rodeoVec3(
+ glms_vec3_mul(
+ irodeo_math_rodeoVec3_to_cglmVec3(a),
+ irodeo_math_rodeoVec3_to_cglmVec3(b)
+ )
+ );
+}
+
+rodeo_math_vec3_t
+rodeo_math_vec3_scale(rodeo_math_vec3_t a, float b)
+{
+ return irodeo_math_cglmVec3_to_rodeoVec3(
+ glms_vec3_scale(
+ irodeo_math_rodeoVec3_to_cglmVec3(a),
+ b
+ )
+ );
+}
+
+rodeo_math_vec3_t
+rodeo_math_vec3_divide(rodeo_math_vec3_t a, rodeo_math_vec3_t b)
+{
+ return irodeo_math_cglmVec3_to_rodeoVec3(
+ glms_vec3_div(
+ irodeo_math_rodeoVec3_to_cglmVec3(a),
+ irodeo_math_rodeoVec3_to_cglmVec3(b)
+ )
+ );
+}
+
+rodeo_math_vec3_t
+rodeo_math_vec3_negate(rodeo_math_vec3_t a)
+{
+ return irodeo_math_cglmVec3_to_rodeoVec3(
+ glms_vec3_negate(
+ irodeo_math_rodeoVec3_to_cglmVec3(a)
+ )
+ );
+}
+
+rodeo_math_vec3_t
+rodeo_math_vec3_normalize(rodeo_math_vec3_t a)
+{
+ return irodeo_math_cglmVec3_to_rodeoVec3(
+ glms_vec3_normalize(
+ irodeo_math_rodeoVec3_to_cglmVec3(a)
+ )
+ );
+}
+
+rodeo_math_vec3_t
+rodeo_math_vec3_rotate(rodeo_math_vec3_t a, float turns, rodeo_math_vec3_t axis)
+{
+ return irodeo_math_cglmVec3_to_rodeoVec3(
+ glms_vec3_rotate(
+ irodeo_math_rodeoVec3_to_cglmVec3(a),
+ rodeo_math_radians_to_turns(turns),
+ irodeo_math_rodeoVec3_to_cglmVec3(axis)
+ )
+ );
+}
+
+float
+rodeo_math_vec3_distance(rodeo_math_vec3_t a, rodeo_math_vec3_t b)
+{
+ return (
+ glms_vec3_distance(
+ irodeo_math_rodeoVec3_to_cglmVec3(a),
+ irodeo_math_rodeoVec3_to_cglmVec3(b)
+ )
+ );
+}
+
+float
+rodeo_math_vec3_distanceSq(rodeo_math_vec3_t a, rodeo_math_vec3_t b)
+{
+ return (
+ glms_vec3_distance2(
+ irodeo_math_rodeoVec3_to_cglmVec3(a),
+ irodeo_math_rodeoVec3_to_cglmVec3(b)
+ )
+ );
+}
+
+rodeo_math_vec3_t
+rodeo_math_vec3_clamp(rodeo_math_vec3_t a, float minimum, float maximum)
+{
+ return irodeo_math_cglmVec3_to_rodeoVec3(
+ glms_vec3_clamp(
+ irodeo_math_rodeoVec3_to_cglmVec3(a),
+ minimum,
+ maximum
+ )
+ );
+}
+
+rodeo_math_vec3_t
+rodeo_math_vec3_lerp(rodeo_math_vec3_t from, rodeo_math_vec3_t to, float t)
+{
+ return irodeo_math_cglmVec3_to_rodeoVec3(
+ glms_vec3_lerp(
+ irodeo_math_rodeoVec3_to_cglmVec3(from),
+ irodeo_math_rodeoVec3_to_cglmVec3(to),
+ t
+ )
+ );
+}
diff --git a/src/rodeo.c b/src/rodeo.c
index 4699f86..4131bc5 100644
--- a/src/rodeo.c
+++ b/src/rodeo.c
@@ -3,31 +3,36 @@
// public
#include "rodeo.h"
#include "rodeo_types.h"
-// private
-#include "rodeo_internal.h"
-#include "rodeo_internal_types.h"
// -- external --
#if __EMSCRIPTEN__
#include <emscripten/emscripten.h>
#endif
-#include "SDL.h"
-#include "SDL_image.h"
-#include "SDL_mixer.h"
-#include "SDL_syswm.h"
-#include "SDL.h"
#include "bgfx/c99/bgfx.h"
-/*#define CGLM_FORCE_LEFT_HANDED*/
-#define CGLM_FORCE_DEPTH_ZERO_TO_ONE
-/*#define CGLM_CLIPSPACE_INCLUDE_ALL*/
-#include "cglm/cglm.h"
-#include "stc/crandom.h"
// -- system --
#include <time.h>
#include <inttypes.h>
-static irodeo_state_t state = {0};
+// intialize all subsystems
+void
+rodeo_init(float width, float height, cstr window_name, uint32_t audio_channels)
+{
+ rodeo_window_init((uint32_t)width, (uint32_t)height, window_name);
+ rodeo_math_rng_init();
+ rodeo_audio_init(audio_channels);
+ rodeo_gfx_init(width, height);
+}
+
+// deintialize all subsystems
+void
+rodeo_deinit(void)
+{
+ rodeo_window_deinit();
+ rodeo_math_rng_deinit();
+ rodeo_audio_deinit();
+ rodeo_gfx_deinit();
+}
void
rodeo_mainLoop_run(
@@ -45,7 +50,7 @@ rodeo_mainLoop_run(
}
void
-rodeo_debug_text_draw(u_int16_t x, u_int16_t y, const char *format, ...)
+rodeo_debug_text_draw(uint16_t x, uint16_t y, const char *format, ...)
{
mrodeo_vargs_do(format)
{
@@ -53,15 +58,3 @@ rodeo_debug_text_draw(u_int16_t x, u_int16_t y, const char *format, ...)
}
}
-void
-irodeo_random_seed_set(stc64_t seed)
-{
- state.random_seed = seed;
-}
-
-stc64_t*
-irodeo_random_seed_get(void)
-{
- return &state.random_seed;
-}
-
diff --git a/src/rodeo_internal.h b/src/rodeo_internal.h
index cc76df7..c0fb727 100644
--- a/src/rodeo_internal.h
+++ b/src/rodeo_internal.h
@@ -1,17 +1,2 @@
-// -- internal --
-// public
-#include "rodeo.h"
-// private
-#include "rodeo_internal_types.h"
-
-// -- external --
-#include "SDL.h"
-
-
-void
-irodeo_random_seed_set(stc64_t seed);
-
-stc64_t*
-irodeo_random_seed_get(void);
-
+// - empty -
diff --git a/src/rodeo_internal_types.h b/src/rodeo_internal_types.h
index 263b9c0..19b657e 100644
--- a/src/rodeo_internal_types.h
+++ b/src/rodeo_internal_types.h
@@ -1,27 +1,11 @@
#pragma once
-// -- internal --
-// public
-#include "rodeo_config.h"
-#include "rodeo_types.h"
+// -- system --
+#include <inttypes.h>
-// -- external --
-#if __EMSCRIPTEN__
- #include <emscripten/emscripten.h>
-#endif
-#include "SDL.h"
-#include "SDL_syswm.h"
-#include "bgfx/c99/bgfx.h"
-#include "stc/crandom.h"
-/*#define CGLM_FORCE_LEFT_HANDED*/
-#define CGLM_FORCE_DEPTH_ZERO_TO_ONE
-/*#define CGLM_CLIPSPACE_INCLUDE_ALL*/
-#include "cglm/cglm.h"
-
-typedef struct
+typedef
+struct
{
- stc64_t random_seed;
-
uint64_t frame_count;
uint32_t frame_limit;
}
diff --git a/src/rodeo_math.c b/src/rodeo_math.c
index 06b6240..df6ea0f 100644
--- a/src/rodeo_math.c
+++ b/src/rodeo_math.c
@@ -38,26 +38,6 @@ rodeo_color_RGBA8_to_RGBAFloat(const rodeo_color_RGBA8_t color)
};
}
-void
-rodeo_random_seed_set(uint64_t seed)
-{
- irodeo_random_seed_set(stc64_new(seed));
-}
-
-double
-rodeo_random_double_get(void)
-{
- stc64_t *seed = irodeo_random_seed_get();
- return stc64_randf(seed);
-}
-
-uint64_t
-rodeo_random_uint64_get(void)
-{
- stc64_t *seed = irodeo_random_seed_get();
- return stc64_rand(seed);
-}
-
// need to test this, might be wrong
/*
rodeo_vector2_t
diff --git a/src/window/rodeo_window.c b/src/window/rodeo_window.c
index 59c7c18..40c1ccf 100644
--- a/src/window/rodeo_window.c
+++ b/src/window/rodeo_window.c
@@ -14,8 +14,8 @@ static irodeo_window_state_t irodeo_window_state = {0};
void
rodeo_window_init(
- uint16_t width,
- uint16_t height,
+ uint32_t width,
+ uint32_t height,
cstr title
)
{
@@ -58,8 +58,8 @@ rodeo_window_init(
cstr_str(&title),
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
- width,
- height,
+ (int32_t)width,
+ (int32_t)height,
SDL_WINDOW_SHOWN //| SDL_WINDOW_RESIZABLE
);
if(irodeo_window_state.window == NULL)