summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2023-06-16 01:15:57 -0400
committerrealtradam <[email protected]>2023-06-16 01:15:57 -0400
commit94625b3133193acd22b68595fe922b7228528b11 (patch)
treef7e358545f5043df20695d0cf51dcf8caa10cb12 /src
parentacc9db32d765728b63162d6fc74a278d0da10b83 (diff)
downloadRodeoKit-94625b3133193acd22b68595fe922b7228528b11.tar.gz
RodeoKit-94625b3133193acd22b68595fe922b7228528b11.zip
fix matrix wrapper as well as a lot of refactoring cleanupmatrixtemp
Diffstat (limited to 'src')
-rw-r--r--src/gfx/irodeo_gfx_t.h2
-rw-r--r--src/gfx/rodeo_gfx.c266
-rw-r--r--src/math/irodeo_mat4.h8
-rw-r--r--src/math/irodeo_rng_t.h23
-rw-r--r--src/math/rodeo_mat4.c41
-rw-r--r--src/math/rodeo_rng.c81
-rw-r--r--src/math/rodeo_vec2.c8
-rw-r--r--src/math/rodeo_vec3.c12
-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
13 files changed, 247 insertions, 310 deletions
diff --git a/src/gfx/irodeo_gfx_t.h b/src/gfx/irodeo_gfx_t.h
index f0cf5e6..5320d82 100644
--- a/src/gfx/irodeo_gfx_t.h
+++ b/src/gfx/irodeo_gfx_t.h
@@ -45,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 1e6f1bb..f55963a 100644
--- a/src/gfx/rodeo_gfx.c
+++ b/src/gfx/rodeo_gfx.c
@@ -17,7 +17,7 @@
static irodeo_gfx_state_t irodeo_gfx_state = {0};
- void
+void
rodeo_gfx_init(float width, float height)
{
@@ -137,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);
@@ -150,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,
@@ -166,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);
@@ -179,96 +179,20 @@ 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
-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]
- );
-}
-
-// TODO delete this
-#include "math/irodeo_math.h"
-static inline
-rodeo_math_mat4_t
-irodeo_math_cglmMat4_to_rodeoMat4(mat4 in)
-{
- return (rodeo_math_mat4_t){
- .val = {
- .m00 = in[0][0], .m01 = in[0][1], .m02 = in[0][2], .m03 = in[0][3],
- .m10 = in[1][0], .m11 = in[1][1], .m12 = in[1][2], .m13 = in[1][3],
- .m20 = in[2][0], .m21 = in[2][1], .m22 = in[2][2], .m23 = in[2][3],
- .m30 = in[3][0], .m31 = in[3][1], .m32 = in[3][2], .m33 = in[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.m20, in.val.m21, in.val.m22, in.val.m23
- },
- }
- };
-}
-
- void
rodeo_gfx_frame_begin(void)
{
@@ -290,51 +214,11 @@ rodeo_gfx_frame_begin(void)
result_height *= (game_aspect) / window_aspect;
}
-
- //irodeo_print_matrix(irodeo_gfx_state.proj_matrix);
- // ---
- //
- rodeo_log(
- rodeo_logLevel_error,
- "Start of new frame"
- );
-
// get identity
- mat4 old_view_matrix;
- glm_mat4_identity(old_view_matrix);
- mat4 old_proj_matrix;
- glm_mat4_identity(old_proj_matrix);
- rodeo_log(
- rodeo_logLevel_warning,
- "old identity"
- );
- irodeo_print_matrix(irodeo_math_cglmMat4_to_rodeoMat4(old_proj_matrix));
-
irodeo_gfx_state.view_matrix = rodeo_math_mat4_identity();
irodeo_gfx_state.proj_matrix = rodeo_math_mat4_identity();
- rodeo_log(
- rodeo_logLevel_warning,
- "new identity"
- );
- irodeo_print_matrix(irodeo_gfx_state.proj_matrix);
// calculate orthographic
- mat4 old_ortho;
- glm_ortho_rh_zo(
- 0,
- result_width,
- result_height,
- 0,
- -100.0f,
- 100.0f,
- old_ortho //old_proj_matrix
- );
- rodeo_log(
- rodeo_logLevel_warning,
- "old ortho"
- );
- irodeo_print_matrix(irodeo_math_cglmMat4_to_rodeoMat4(old_ortho));
-
rodeo_math_mat4_t ortho = rodeo_math_mat4_orthographic(
0,
result_width,
@@ -343,60 +227,20 @@ rodeo_gfx_frame_begin(void)
-100.0f,
100.0f
);
- rodeo_log(
- rodeo_logLevel_warning,
- "new ortho"
- );
- irodeo_print_matrix(ortho);
// calculate translation
- vec3 old_offset = {
- 1 - (1 * (target_width / result_width)), // x
- -(1 - (1 * (target_height / result_height))), // y
- 0
- };
-
rodeo_math_vec3_t offset = {
- .x = 1 - (1 * (target_width / result_width)), // x
- .y = -(1 - (1 * (target_height / result_height))), // y
- .z = 0
+ .val.x = 1 - (1 * (target_width / result_width)), // x
+ .val.y = -(1 - (1 * (target_height / result_height))), // y
+ .val.z = 0
};
// apply translation * orthographic
- glm_translate(old_proj_matrix, old_offset);
- rodeo_log(
- rodeo_logLevel_warning,
- "old translation apply to identity"
- );
- irodeo_print_matrix(irodeo_math_cglmMat4_to_rodeoMat4(old_proj_matrix));
-
irodeo_gfx_state.proj_matrix = rodeo_math_mat4_translate(irodeo_gfx_state.proj_matrix, offset);
- rodeo_log(
- rodeo_logLevel_warning,
- "new translation apply to identity"
- );
- irodeo_print_matrix(irodeo_gfx_state.proj_matrix);
- //irodeo_gfx_state.proj_matrix = rodeo_math_mat4_multiply(irodeo_gfx_state.proj_matrix, ortho);
- irodeo_gfx_state.proj_matrix = rodeo_math_mat4_multiply(irodeo_gfx_state.proj_matrix, irodeo_math_cglmMat4_to_rodeoMat4(old_ortho));
-
- rodeo_log(
- rodeo_logLevel_warning,
- "old ortho apply to identity"
- );
- glm_mat4_mul(old_proj_matrix, old_ortho, old_proj_matrix);
- irodeo_print_matrix(irodeo_math_cglmMat4_to_rodeoMat4(old_proj_matrix));
- rodeo_log(
- rodeo_logLevel_warning,
- "new ortho apply to identity"
- );
- irodeo_print_matrix(irodeo_gfx_state.proj_matrix);
+ irodeo_gfx_state.proj_matrix = rodeo_math_mat4_multiply(irodeo_gfx_state.proj_matrix, ortho);
// 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_transform(0, old_view_matrix, old_proj_matrix);
-
- // ---
-
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();
@@ -405,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();
@@ -426,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;
@@ -457,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
@@ -476,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;
@@ -491,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);
@@ -506,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__
@@ -523,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
@@ -547,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)
@@ -573,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
);
}
@@ -616,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,
@@ -630,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,
@@ -649,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,
@@ -672,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,
@@ -709,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;
}
@@ -802,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
@@ -858,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__
@@ -877,7 +721,7 @@ rodeo_gfx_frame_limit_set(uint32_t limit)
#endif
}
- uint32_t
+uint32_t
rodeo_gfx_frame_limit_get(void)
{
#ifdef __EMSCRIPTEN__
@@ -887,7 +731,7 @@ rodeo_gfx_frame_limit_get(void)
#endif
}
- cstr
+cstr
rodeo_gfx_renderer_name_get(void)
{
return cstr_from(
@@ -895,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);
@@ -949,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_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/rodeo_mat4.c b/src/math/rodeo_mat4.c
index 958e123..70d0226 100644
--- a/src/math/rodeo_mat4.c
+++ b/src/math/rodeo_mat4.c
@@ -2,6 +2,7 @@
// -- internal --
// public
#include "rodeo/math.h"
+#include "rodeo/log.h"
// private
#include "math/irodeo_math.h"
@@ -35,12 +36,50 @@ irodeo_math_rodeoMat4_to_cglmMat4(rodeo_math_mat4_t in)
in.val.m20, in.val.m21, in.val.m22, in.val.m23
},
{
- 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)
{
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
index a9e369e..be9d7ff 100644
--- a/src/math/rodeo_vec2.c
+++ b/src/math/rodeo_vec2.c
@@ -11,8 +11,8 @@ rodeo_math_vec2_t
irodeo_math_cglmVec2_to_rodeoVec2(vec2s in)
{
return (rodeo_math_vec2_t){
- .x = in.raw[0],
- .y = in.raw[1]
+ .raw[0] = in.raw[0],
+ .raw[1] = in.raw[1]
};
}
@@ -20,8 +20,8 @@ vec2s
irodeo_math_rodeoVec2_to_cglmVec2(rodeo_math_vec2_t in)
{
return (vec2s){
- .raw[0] = in.x,
- .raw[1] = in.y
+ .raw[0] = in.raw[0],
+ .raw[1] = in.raw[1]
};
}
diff --git a/src/math/rodeo_vec3.c b/src/math/rodeo_vec3.c
index bcdf86b..c94ecd3 100644
--- a/src/math/rodeo_vec3.c
+++ b/src/math/rodeo_vec3.c
@@ -11,9 +11,9 @@ rodeo_math_vec3_t
irodeo_math_cglmVec3_to_rodeoVec3(vec3s in)
{
return (rodeo_math_vec3_t){
- .x = in.raw[0],
- .y = in.raw[1],
- .z = in.raw[2]
+ .raw[0] = in.raw[0],
+ .raw[1] = in.raw[1],
+ .raw[2] = in.raw[2]
};
}
@@ -21,9 +21,9 @@ vec3s
irodeo_math_rodeoVec3_to_cglmVec3(rodeo_math_vec3_t in)
{
return (vec3s){
- .raw[0] = in.x,
- .raw[1] = in.y,
- .raw[2] = in.z
+ .raw[0] = in.raw[0],
+ .raw[1] = in.raw[1],
+ .raw[2] = in.raw[2],
};
}
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)