summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2023-03-05 06:38:09 -0500
committerrealtradam <[email protected]>2023-03-05 06:38:09 -0500
commite58d0577634b1405a40a4b1ebd0a36323fa81970 (patch)
treee0facd0d5e396b07ef161dc7ef885c71694d0cbb
parenteb6a382d03c5b9c915a949ea1119c2cbf72f1d6e (diff)
downloadRodeoKit-e58d0577634b1405a40a4b1ebd0a36323fa81970.tar.gz
RodeoKit-e58d0577634b1405a40a4b1ebd0a36323fa81970.zip
initial rewrite to follow new styleguide
-rw-r--r--CMakeLists.txt16
-rw-r--r--include/rodeo.h95
-rw-r--r--include/rodeo_math.h2
-rw-r--r--include/rodeo_types.h19
-rw-r--r--src/compile_flags.txt3
-rw-r--r--src/private/rodeo_internal.h4
-rw-r--r--src/private/rodeo_internal_types.h7
-rw-r--r--src/rodeo.c98
-rw-r--r--src/rodeo_error.c2
-rw-r--r--src/rodeo_math.c2
-rw-r--r--src/rodeo_types.c8
11 files changed, 145 insertions, 111 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a5d3514..1c9fdec 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -24,14 +24,14 @@ file(GLOB SOURCES
add_library(${PROJECT_NAME} ${SOURCES})
-#if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
-#target_compile_options(${PROJECT_NAME} PRIVATE
-#-Wall
-#-Wextra
-#-Wpedantic
-##-Werror
-#)
-#endif()
+if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
+target_compile_options(${PROJECT_NAME} PRIVATE
+-Wall
+-Wextra
+-Wpedantic
+#-Werror
+)
+endif()
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
diff --git a/include/rodeo.h b/include/rodeo.h
index 97a5e61..713e260 100644
--- a/include/rodeo.h
+++ b/include/rodeo.h
@@ -8,68 +8,103 @@
#include <string.h>
#include <limits.h>
-
+#define mrodeo_name_concat(prefix, suffix) prefix##suffix
+#define mrodeo_macrovar(prefix) mrodeo_name_concat(prefix##_, __LINE__)
+
+#define mrodeo_defer_do(start, end) for( \
+ int mrodeo_macrovar(_macrovar_) = (start, 0); \
+ !mrodeo_macrovar(_macrovar_); \
+ (mrodeo_macrovar(_macrovar_) += 1), end) \
+
+#define \
+mrodeo_window_do( \
+ state, \
+ screen_height, \
+ screen_width, \
+ title \
+) \
+ mrodeo_defer_do( \
+ rodeo_window_init( \
+ &state, \
+ screen_height, \
+ screen_width, \
+ title \
+ ), \
+ rodeo_window_deinit(state) \
+ )
void
-Rodeo__\
-init_window(
- Rodeo__data_p *state,
+rodeo_\
+window_init(
+ rodeo_data_p *state,
int screen_height,
int screen_width,
char* title
);
void
-Rodeo__\
-deinit_window(Rodeo__data_p state);
+rodeo_\
+window_deinit(rodeo_data_p state);
void
-Rodeo__\
-quit();
+rodeo_\
+deinit(void);
+
+#define \
+mrodeo_do( \
+ state \
+) \
+ mrodeo_defer_do( \
+ rodeo_begin(state), \
+ rodeo_end(state) \
+ )
void
-Rodeo__\
-begin(Rodeo__data_p state);
+rodeo_\
+begin(rodeo_data_p state);
void
-Rodeo__\
-end(Rodeo__data_p state);
+rodeo_\
+end(rodeo_data_p state);
void
-Rodeo__\
-execute_main_loop(
- Rodeo__data_p state,
- Rodeo__main_loop_p main_loop_function
+rodeo_\
+mainloop_set(
+ rodeo_data_p state,
+ rodeo_mainloop_func main_loop_function
);
bool
-Rodeo__\
-should_quit(Rodeo__data_p state);
+rodeo_\
+window_check_quit(rodeo_data_p state);
void
-Rodeo__\
-set_quit(Rodeo__data_p state, bool quit);
+rodeo_\
+set_quit(rodeo_data_p state, bool quit);
void
-Rodeo__\
-draw_debug_text(uint16_t x, uint16_t y, const char *format, ...);
+rodeo_\
+debug_text_draw(uint16_t x, uint16_t y, const char *format, ...);
+// rodeo_renderer_name_get
const char *
-Rodeo__\
-get_renderer_name_as_string();
+rodeo_\
+renderer_name_get(void);
+// rodeo_renderer_flush
void
-Rodeo__\
-flush_batch(Rodeo__data_p state);
+rodeo_\
+renderer_flush(rodeo_data_p state);
+// rodeo_rectangle_draw
void
-Rodeo__\
-draw_rectangle(
- Rodeo__data_p state,
+rodeo_\
+rectangle_draw(
+ rodeo_data_p state,
uint16_t x,
uint16_t y,
uint16_t width,
uint16_t height,
- Rodeo__color_rgba_t color
+ rodeo_rgba_t color
);
diff --git a/include/rodeo_math.h b/include/rodeo_math.h
index f7df53f..4dee9ae 100644
--- a/include/rodeo_math.h
+++ b/include/rodeo_math.h
@@ -8,4 +8,4 @@
uint32_t
Rodeo__\
Math__\
-color_rgba_to_uint32(const Rodeo__color_rgba_t color);
+color_rgba_to_uint32(const rodeo_rgba_t color);
diff --git a/include/rodeo_types.h b/include/rodeo_types.h
index 47d2db9..e35c482 100644
--- a/include/rodeo_types.h
+++ b/include/rodeo_types.h
@@ -6,37 +6,34 @@
typedef
struct
-Rodeo__\
-color_rgba
{
float red;
float green;
float blue;
float alpha;
}
-Rodeo__\
-color_rgba_t;
+rodeo_\
+rgba_t;
typedef
struct
-Rodeo__position_color_vertex
{
float x;
float y;
float z;
uint32_t abgr;
}
-Rodeo__\
+rodeo_\
position_color_vertex_t;
+//rodeo_poscolvert_t
typedef
struct
-Rodeo__data
-*Rodeo__\
-data_p;
+rodeo_data_t
+*rodeo_data_p;
typedef
void
-(*Rodeo__\
-main_loop_p)
+(*rodeo_\
+mainloop_func)
(void);
diff --git a/src/compile_flags.txt b/src/compile_flags.txt
index 0d92969..2cccc56 100644
--- a/src/compile_flags.txt
+++ b/src/compile_flags.txt
@@ -4,3 +4,6 @@
-I../external/bgfx/include
-I../external/bx/include
-I../external/cglm/include
+-Wall
+-Wextra
+-Wpedantic
diff --git a/src/private/rodeo_internal.h b/src/private/rodeo_internal.h
index f01ac87..0773f12 100644
--- a/src/private/rodeo_internal.h
+++ b/src/private/rodeo_internal.h
@@ -3,5 +3,5 @@
#include "private/rodeo_internal_types.h"
bgfx_shader_handle_t
-_Rodeo__\
-load_shader(const char* path);
+irodeo_\
+shader_load(const char* path);
diff --git a/src/private/rodeo_internal_types.h b/src/private/rodeo_internal_types.h
index 2114942..20b8c43 100644
--- a/src/private/rodeo_internal_types.h
+++ b/src/private/rodeo_internal_types.h
@@ -13,8 +13,7 @@
#include "bgfx/c99/bgfx.h"
struct
-Rodeo__\
-data
+rodeo_data_t
{
SDL_Window* window;
SDL_Surface* screen_surface;
@@ -28,11 +27,11 @@ data
bgfx_dynamic_vertex_buffer_handle_t vertex_buffer_handle;
bgfx_dynamic_index_buffer_handle_t index_buffer_handle;
uint16_t vertex_size;
- Rodeo__position_color_vertex_t batched_vertices[RODEO__MAX_VERTEX_SIZE];
+ rodeo_position_color_vertex_t batched_vertices[RODEO__MAX_VERTEX_SIZE];
uint16_t index_count;
uint16_t index_size;
uint16_t batched_indices[(RODEO__MAX_VERTEX_SIZE / 4) * 6];
bgfx_shader_handle_t vertex_shader;
bgfx_shader_handle_t fragment_shader;
bgfx_program_handle_t program_shader;
-} Rodeo__data_t;
+} rodeo_data_t;
diff --git a/src/rodeo.c b/src/rodeo.c
index 3a60b92..10654ac 100644
--- a/src/rodeo.c
+++ b/src/rodeo.c
@@ -1,4 +1,4 @@
-
+// -- internal --
// public internal
#include "rodeo.h"
#include "rodeo_math.h"
@@ -8,7 +8,7 @@
#include "private/rodeo_internal_types.h"
#include "private/rodeo_error.h"
-// external
+// -- external --
#if __EMSCRIPTEN__
#include <emscripten/emscripten.h>
#endif
@@ -21,21 +21,21 @@
#include "cglm/cglm.h"
void
-Rodeo__\
-init_window(
- Rodeo__data_p *state_p,
+rodeo_\
+window_init(
+ rodeo_data_p *state_p,
int screen_height,
int screen_width,
char* title
)
{
- *state_p = (Rodeo__data_p)malloc(sizeof(Rodeo__data_t));
- Rodeo__data_p state = *state_p;
+ *state_p = (rodeo_data_p)malloc(sizeof(rodeo_data_t));
+ rodeo_data_p state = *state_p;
if(!state)
{
Rodeo__error_exit(
RODEO__ERROR__UNINITIALIZED_STATE,
- __FUNCTION__,
+ __func__,
__LINE__,
"Malloc failed to initialize state."
);
@@ -161,8 +161,8 @@ init_window(
fragment_path[shader_length + fragment_length] = 0;
vertex_path[shader_length + vertex_length] = 0;
- state->vertex_shader = _Rodeo__load_shader(vertex_path);
- state->fragment_shader = _Rodeo__load_shader(fragment_path);
+ state->vertex_shader = irodeo_shader_load(vertex_path);
+ state->fragment_shader = irodeo_shader_load(fragment_path);
state->program_shader = bgfx_create_program(
state->vertex_shader,
state->fragment_shader,
@@ -171,14 +171,14 @@ init_window(
}
void
-Rodeo__\
-deinit_window(Rodeo__data_p state)
+rodeo_\
+window_deinit(rodeo_data_p state)
{
if(!state)
{
Rodeo__error_exit(
RODEO__ERROR__UNINITIALIZED_STATE,
- __FUNCTION__,
+ __func__,
__LINE__,
RODEO__EMPTY_ERROR_MESSAGE
);
@@ -191,21 +191,21 @@ deinit_window(Rodeo__data_p state)
}
void
-Rodeo__\
-quit()
+rodeo_\
+deinit(void)
{
SDL_Quit();
}
void
-Rodeo__\
-begin(Rodeo__data_p state)
+rodeo_\
+begin(rodeo_data_p state)
{
if(!state)
{
Rodeo__error_exit(
RODEO__ERROR__UNINITIALIZED_STATE,
- __FUNCTION__,
+ __func__,
__LINE__,
RODEO__EMPTY_ERROR_MESSAGE
);
@@ -239,19 +239,19 @@ begin(Rodeo__data_p state)
}
void
-Rodeo__\
-end(Rodeo__data_p state)
+rodeo_\
+end(rodeo_data_p state)
{
if(!state)
{
Rodeo__error_exit(
RODEO__ERROR__UNINITIALIZED_STATE,
- __FUNCTION__,
+ __func__,
__LINE__,
RODEO__EMPTY_ERROR_MESSAGE
);
}
- Rodeo__flush_batch(state);
+ rodeo_renderer_flush(state);
bgfx_frame(false);
@@ -265,16 +265,16 @@ end(Rodeo__data_p state)
}
void
-Rodeo__\
-execute_main_loop(
- Rodeo__data_p state,
- Rodeo__main_loop_p main_loop_function
+rodeo_\
+mainloop_set(
+ rodeo_data_p state,
+ rodeo_mainloop_func main_loop_function
)
{
#if __EMSCRIPTEN__
emscripten_set_main_loop(main_loop_function, 0, 1);
#else
- while(!Rodeo__should_quit(state))
+ while(!rodeo_window_check_quit(state))
{
main_loop_function();
}
@@ -282,22 +282,22 @@ execute_main_loop(
}
bool
-Rodeo__\
-should_quit(Rodeo__data_p state)
+rodeo_\
+window_check_quit(rodeo_data_p state)
{
return state->quit;
}
void
-Rodeo__\
-set_quit(Rodeo__data_p state, bool quit)
+rodeo_\
+set_quit(rodeo_data_p state, bool quit)
{
state->quit = quit;
}
void
-Rodeo__\
-draw_debug_text(u_int16_t x, u_int16_t y, const char *format, ...)
+rodeo_\
+debug_text_draw(u_int16_t x, u_int16_t y, const char *format, ...)
{
va_list argList;
va_start(argList, format);
@@ -306,21 +306,21 @@ draw_debug_text(u_int16_t x, u_int16_t y, const char *format, ...)
}
const char *
-Rodeo__\
-get_renderer_name_as_string()
+rodeo_\
+renderer_name_get(void)
{
return bgfx_get_renderer_name(bgfx_get_renderer_type());
}
void
-Rodeo__\
-flush_batch(Rodeo__data_p state)
+rodeo_\
+renderer_flush(rodeo_data_p state)
{
if(state->vertex_size > 0)
{
// upload remaining batched vertices
bgfx_set_dynamic_vertex_buffer(0, state->vertex_buffer_handle, 0, state->vertex_size);
- const bgfx_memory_t* vbm = bgfx_copy(state->batched_vertices, sizeof(Rodeo__position_color_vertex_t) * state->vertex_size);
+ const bgfx_memory_t* vbm = bgfx_copy(state->batched_vertices, sizeof(rodeo_position_color_vertex_t) * state->vertex_size);
bgfx_update_dynamic_vertex_buffer(state->vertex_buffer_handle, 0, vbm);
// upload remaining batched indices
@@ -349,39 +349,39 @@ flush_batch(Rodeo__data_p state)
}
void
-Rodeo__\
-draw_rectangle(
- Rodeo__data_p state,
+rodeo_\
+rectangle_draw(
+ rodeo_data_p state,
u_int16_t x,
u_int16_t y,
u_int16_t width,
u_int16_t height,
- Rodeo__color_rgba_t color
+ rodeo_rgba_t color
)
{
const uint32_t abgr = Rodeo__Math__color_rgba_to_uint32(color);
if(state->vertex_size < RODEO__MAX_VERTEX_SIZE)
{
state->batched_vertices[state->vertex_size] =
- (Rodeo__position_color_vertex_t)
+ (rodeo_position_color_vertex_t)
{
(float)width + (float)x, (float)height + (float)y, 0.0f, abgr
};
state->vertex_size += 1;
state->batched_vertices[state->vertex_size] =
- (Rodeo__position_color_vertex_t)
+ (rodeo_position_color_vertex_t)
{
(float)width + (float)x, (float)y, 0.0f, abgr
};
state->vertex_size += 1;
state->batched_vertices[state->vertex_size] =
- (Rodeo__position_color_vertex_t)
+ (rodeo_position_color_vertex_t)
{
(float)x, (float)y, 0.0f, abgr
};
state->vertex_size += 1;
state->batched_vertices[state->vertex_size] =
- (Rodeo__position_color_vertex_t)
+ (rodeo_position_color_vertex_t)
{
(float)x, (float)height + (float)y, 0.0f, abgr
};
@@ -411,13 +411,13 @@ draw_rectangle(
if(state->vertex_size >= RODEO__MAX_VERTEX_SIZE)
{
- Rodeo__flush_batch(state);
+ rodeo_renderer_flush(state);
}
}
bgfx_shader_handle_t
-_Rodeo__\
-load_shader(const char* path)
+irodeo_\
+shader_load(const char* path)
{
bgfx_shader_handle_t invalid = BGFX_INVALID_HANDLE;
diff --git a/src/rodeo_error.c b/src/rodeo_error.c
index 1b5b03d..4190883 100644
--- a/src/rodeo_error.c
+++ b/src/rodeo_error.c
@@ -38,7 +38,7 @@ error_exit(
default:
Rodeo__error_exit(
RODEO__ERROR__UNREACHABLE_REACHED,
- __FUNCTION__,
+ __func__,
__LINE__,
"Unhandled error code."
);
diff --git a/src/rodeo_math.c b/src/rodeo_math.c
index 248e600..f45c6e6 100644
--- a/src/rodeo_math.c
+++ b/src/rodeo_math.c
@@ -6,7 +6,7 @@
uint32_t
Rodeo__\
Math__\
-color_rgba_to_uint32(const Rodeo__color_rgba_t color)
+color_rgba_to_uint32(const rodeo_rgba_t color)
{
return
((uint32_t)(uint8_t)(color.red * 255))
diff --git a/src/rodeo_types.c b/src/rodeo_types.c
index ff87e27..f7e5285 100644
--- a/src/rodeo_types.c
+++ b/src/rodeo_types.c
@@ -12,8 +12,6 @@
#include "bgfx/c99/bgfx.h"
struct
-Rodeo__\
-data_t
{
SDL_Window* window;
SDL_Surface* screen_surface;
@@ -27,11 +25,13 @@ data_t
bgfx_dynamic_vertex_buffer_handle_t vertex_buffer_handle;
bgfx_dynamic_index_buffer_handle_t index_buffer_handle;
uint16_t vertex_size;
- Rodeo__position_color_vertex_t batched_vertices[RODEO__MAX_VERTEX_SIZE];
+ rodeo_position_color_vertex_t batched_vertices[RODEO__MAX_VERTEX_SIZE];
uint16_t index_count;
uint16_t index_size;
uint16_t batched_indices[(RODEO__MAX_VERTEX_SIZE / 4) * 6];
bgfx_shader_handle_t vertex_shader;
bgfx_shader_handle_t fragment_shader;
bgfx_program_handle_t program_shader;
-};
+}
+rodeo_\
+data_t;