summaryrefslogtreecommitdiff
path: root/include/engine
diff options
context:
space:
mode:
Diffstat (limited to 'include/engine')
-rw-r--r--include/engine/btree.h41
-rw-r--r--include/engine/dltools.h6
-rw-r--r--include/engine/engine.h82
-rw-r--r--include/engine/fov.h19
-rw-r--r--include/engine/hashmap.h81
-rw-r--r--include/engine/input.h66
-rw-r--r--include/engine/list.h12
-rw-r--r--include/engine/logging.h29
-rw-r--r--include/engine/memory.h14
-rw-r--r--include/engine/rendering.h66
-rw-r--r--include/engine/resources.h63
-rw-r--r--include/engine/stack.h21
-rw-r--r--include/engine/state.h13
-rw-r--r--include/engine/types.h16
-rw-r--r--include/engine/ui.h186
-rw-r--r--include/engine/utils.h24
-rw-r--r--include/engine/vector.h30
17 files changed, 392 insertions, 377 deletions
diff --git a/include/engine/btree.h b/include/engine/btree.h
index 5405e7e..04f9ff8 100644
--- a/include/engine/btree.h
+++ b/include/engine/btree.h
@@ -8,9 +8,9 @@
#define BTREE_SIZE_MIN 8
#define BTREE_SIZE_MAX 4096
-#define BTREE_CMP_LT ( -1 )
-#define BTREE_CMP_EQ ( 0 )
-#define BTREE_CMP_GT ( 1 )
+#define BTREE_CMP_LT (-1)
+#define BTREE_CMP_EQ (0)
+#define BTREE_CMP_GT (1)
struct btree;
struct btree_iter_t;
@@ -22,36 +22,33 @@ struct btree_iter_t;
* This function just calls `btree_new_with_allocator` with `free` and `malloc`
* as initializers.
*/
-struct btree* btree_new(size_t elem_size,
- size_t t,
- int (*cmp)(const void *a, const void *b));
+struct btree* btree_new(size_t elem_size, size_t t,
+ int (*cmp)(const void* a, const void* b));
/* Same as `btree_new`, except that it actually initializes a btree, but with
* the given allocators.
*/
-struct btree* btree_new_with_allocator(
- size_t elem_size,
- size_t t,
- int (*cmp)(const void *a, const void *b),
- void *(*alloc)(size_t),
- void (*dealloc)(void*));
+struct btree* btree_new_with_allocator(size_t elem_size, size_t t,
+ int (*cmp)(const void* a, const void* b),
+ void* (*alloc)(size_t),
+ void (*dealloc)(void*));
-void btree_free(struct btree **btree);
+void btree_free(struct btree** btree);
-void* btree_search(struct btree *btree, void *elem);
-void btree_insert(struct btree *btree, void *elem);
-int btree_delete(struct btree *btree, void *elem);
+void* btree_search(struct btree* btree, void* elem);
+void btree_insert(struct btree* btree, void* elem);
+int btree_delete(struct btree* btree, void* elem);
-void btree_print(struct btree *btree, void (*print_elem)(const void*));
+void btree_print(struct btree* btree, void (*print_elem)(const void*));
-void* btree_first(struct btree *btree);
-void* btree_last(struct btree *btree);
+void* btree_first(struct btree* btree);
+void* btree_last(struct btree* btree);
-size_t btree_size(struct btree *btree);
+size_t btree_size(struct btree* btree);
struct btree_iter_t* btree_iter_t_new(struct btree* tree);
-void btree_iter_t_reset(struct btree *tree, struct btree_iter_t** it);
+void btree_iter_t_reset(struct btree* tree, struct btree_iter_t** it);
-void* btree_iter(struct btree *tree, struct btree_iter_t *iter);
+void* btree_iter(struct btree* tree, struct btree_iter_t* iter);
#endif
diff --git a/include/engine/dltools.h b/include/engine/dltools.h
index 9306ae7..e883f20 100644
--- a/include/engine/dltools.h
+++ b/include/engine/dltools.h
@@ -3,12 +3,12 @@
/* Utility functions for handling runtime linked shared libraries */
bool dynamic_library_close(void* shared_library);
-void* dynamic_library_open(const char *library_path);
-void* dynamic_library_reload(void* shared_library, const char *library_path);
+void* dynamic_library_open(const char* library_path);
+void* dynamic_library_reload(void* shared_library, const char* library_path);
/* Returns the address of symbol in the provided shared_library handle.
* NULL on error*/
-void* dynamic_library_get_symbol(void* shared_library, const char *symbol);
+void* dynamic_library_get_symbol(void* shared_library, const char* symbol);
char* dynamic_library_get_error(void);
#endif
diff --git a/include/engine/engine.h b/include/engine/engine.h
index 4d92645..a8b5459 100644
--- a/include/engine/engine.h
+++ b/include/engine/engine.h
@@ -3,35 +3,34 @@
#include <stdbool.h>
-#include <engine/types.h>
+#include <engine/input.h>
#include <engine/logging.h>
-#include <engine/stack.h>
-#include <engine/vector.h>
#include <engine/memory.h>
-#include <engine/input.h>
-#include <engine/state.h>
#include <engine/resources.h>
+#include <engine/stack.h>
+#include <engine/state.h>
+#include <engine/types.h>
+#include <engine/vector.h>
typedef struct {
u32 texture_id;
- i32 x, y,
- w, h;
+ i32 x, y, w, h;
} RenderUnit;
typedef struct Window Window;
#define NUM_GLOBAL_BINDINGS 1
typedef struct {
- void *data; /* Contains textures and such */
+ void* data; /* Contains textures and such */
u64 data_len;
- Window *window;
- bool quit;
+ Window* window;
+ bool quit;
u64 frame;
f32 fps_target;
- /* TODO: Move mouse data to input ctx */
+ /* TODO: Move mouse data to input ctx */
v2_i32 mouse_pos;
v2_i32 mousedown;
@@ -44,12 +43,12 @@ typedef struct {
i32 camera_y;
/* Text input/editing is currently not used/implemented */
- char *edit_text;
+ char* edit_text;
usize edit_pos;
- memory *mem;
+ memory* mem;
- i_ctx **bindings;
+ i_ctx** bindings;
usize bindings_sz;
usize bindings_len;
@@ -57,41 +56,37 @@ typedef struct {
} Platform;
/* Essential functions */
-Platform *engine_init(
- const char *windowtitle,
- v2_i32 windowsize,
- const f32 render_scale,
- const u32 flags,
- const usize initial_memory,
- const FontSpec *fonts[],
- const TextureSpec *textures[]);
+Platform* engine_init(const char* windowtitle, v2_i32 windowsize,
+ const f32 render_scale, const u32 flags,
+ const usize initial_memory, const FontSpec* fonts[],
+ const TextureSpec* textures[]);
-i32 engine_run(Platform *p, StateType initial_state);
+i32 engine_run(Platform* p, StateType initial_state);
-void engine_stop(Platform *p);
+void engine_stop(Platform* p);
/* Utility functions */
void engine_fps_max(u64 cap);
void render_set_zoom(f32 new_zoom);
void render_adjust_zoom(f32 diff);
-void render_add_unit(RenderUnit *u);
+void render_add_unit(RenderUnit* u);
u32 get_time(void);
-v2_i32 get_windowsize(void);
-v2_i32 *get_mousepos(void);
+v2_i32 get_windowsize(void);
+v2_i32* get_mousepos(void);
#include "rendering.h"
#ifdef ENGINE_INTERNALS
-#define MAX(a,b) (a > b ? a : b)
+#define MAX(a, b) (a > b ? a : b)
/* Window */
struct Window {
- SDL_Window *window;
- SDL_Renderer *renderer;
- f32 render_scale;
+ SDL_Window* window;
+ SDL_Renderer* renderer;
+ f32 render_scale;
v2_i32 windowsize;
@@ -100,29 +95,28 @@ struct Window {
};
typedef struct {
- SDL_Texture *texture;
+ SDL_Texture* texture;
const i32 tilesize;
const i32 width;
const i32 height;
} Texture;
struct Resources {
- usize textures_len;
- usize textures_size;
- usize fonts_len;
+ usize textures_len;
+ usize textures_size;
+ usize fonts_len;
- usize texturepaths_len;
- usize fontpaths_len;
+ usize texturepaths_len;
+ usize fontpaths_len;
- /* Paths for our sources, kept in case the user wants to reload them */
- TextureSpec **texture_paths;
- FontSpec **font_paths;
+ /* Paths for our sources, kept in case the user wants to reload them */
+ TextureSpec** texture_paths;
+ FontSpec** font_paths;
- /* Our actual sources */
- Texture **textures;
- TTF_Font **fonts;
+ /* Our actual sources */
+ Texture** textures;
+ TTF_Font** fonts;
};
-
#endif
#endif
diff --git a/include/engine/fov.h b/include/engine/fov.h
index 3af421e..15ef38b 100644
--- a/include/engine/fov.h
+++ b/include/engine/fov.h
@@ -1,26 +1,21 @@
#ifndef ENGINE_FOV_H
#define ENGINE_FOV_H
-#include <stdbool.h>
#include "types.h"
#include "vector.h"
+#include <stdbool.h>
/* `fov_shadowcast`: */
/* map: your 2D enum tile grid
* mapsize: x: width, y: height of the map
* visblocking: pointer to a function that returns `true` when receiving a
* pointer to a LOS blocking tile
- * lightmap: [out] 2D lightmap, this is simply overwritten with the distance to
- * the source.
- * range: visibility range/radius.
- * src: 2D point to calculate FOV from
+ * lightmap: [out] 2D lightmap, this is simply overwritten with the
+ * distance to the source. range: visibility range/radius. src: 2D
+ * point to calculate FOV from
* */
-void fov_shadowcast(
- const void *map,
- const v2_i32 mapsize,
- bool (*visblocking)(const void*),
- i32 *lightmap,
- const i32 range,
- v2_i32 src);
+void fov_shadowcast(const void* map, const v2_i32 mapsize,
+ bool (*visblocking)(const void*), i32* lightmap,
+ const i32 range, v2_i32 src);
#endif
diff --git a/include/engine/hashmap.h b/include/engine/hashmap.h
index 4b97b8e..bf1d87c 100644
--- a/include/engine/hashmap.h
+++ b/include/engine/hashmap.h
@@ -3,53 +3,52 @@
#include "types.h"
-#include <stdlib.h>
#include "list.h"
#include "memory.h"
-
+#include <stdlib.h>
i32 lolhash(const usize s, i32 v);
/* Define a linked list before using this */
/* Example: DEFINE_LLIST(i32) */
-#define DEFINE_HASHMAP(type, lsize, cmp, type_to_int) \
-typedef DEFINE_LLIST(type); \
-typedef struct hashmap_##type { \
- usize size; \
- List_##type elems[64]; \
-} hashmap_##type; \
- \
-type* hashmap_##type##_lookup(hashmap_##type* hmap, const type* val) { \
- const i32 idx = lolhash(64, type_to_int(val)); \
- List_##type *head = &hmap->elems[idx]; \
- while (head != NULL) { \
- if (!cmp(&(head->value), val)) return &(head->value); \
- head = head->next; \
- } \
- return NULL; \
-} \
- \
-void hashmap_##type##_insert(memory *m, hashmap_##type *hmap, const type *val) { \
- const i32 idx = lolhash(64, type_to_int(val)); \
- List_##type *head = &(hmap->elems[idx]); \
- \
- /* This is highly dependant on whether the memory is zero-initialized */ \
- if (!type_to_int(&(head->value))) \
- { \
- memcpy(&(head->value), val, sizeof(type)); \
- return; \
- } \
- \
- \
- while (head->next != NULL && cmp(&head->value, val)) { \
- head = head->next; \
- } \
- \
- if (!cmp(&head->value, val)) memcpy(&(head->value), val, sizeof(type)); \
- else { \
- head->next = memory_allocate(m, sizeof(List_##type)); \
- memcpy(&(head->next->value), val, sizeof(type)); \
- } \
-}
+#define DEFINE_HASHMAP(type, lsize, cmp, type_to_int) \
+ typedef DEFINE_LLIST(type); \
+ typedef struct hashmap_##type { \
+ usize size; \
+ List_##type elems[64]; \
+ } hashmap_##type; \
+ \
+ type* hashmap_##type##_lookup(hashmap_##type* hmap, const type* val) { \
+ const i32 idx = lolhash(64, type_to_int(val)); \
+ List_##type* head = &hmap->elems[idx]; \
+ while (head != NULL) { \
+ if (!cmp(&(head->value), val)) return &(head->value); \
+ head = head->next; \
+ } \
+ return NULL; \
+ } \
+ \
+ void hashmap_##type##_insert(memory* m, hashmap_##type* hmap, \
+ const type* val) { \
+ const i32 idx = lolhash(64, type_to_int(val)); \
+ List_##type* head = &(hmap->elems[idx]); \
+ \
+ /* This is highly dependant on whether the memory is zero-initialized */ \
+ if (!type_to_int(&(head->value))) { \
+ memcpy(&(head->value), val, sizeof(type)); \
+ return; \
+ } \
+ \
+ while (head->next != NULL && cmp(&head->value, val)) { \
+ head = head->next; \
+ } \
+ \
+ if (!cmp(&head->value, val)) \
+ memcpy(&(head->value), val, sizeof(type)); \
+ else { \
+ head->next = memory_allocate(m, sizeof(List_##type)); \
+ memcpy(&(head->next->value), val, sizeof(type)); \
+ } \
+ }
#endif
diff --git a/include/engine/input.h b/include/engine/input.h
index 767de1e..c93d74d 100644
--- a/include/engine/input.h
+++ b/include/engine/input.h
@@ -35,7 +35,7 @@ typedef struct binding_t {
action_t action;
// Change type depending on input handling back-end. like u16 for GLFW_KEY
- //enum SDL_Scancode keycode;
+ // enum SDL_Scancode keycode;
scancode_t scancode;
scancode_t scancode_alt;
@@ -43,53 +43,51 @@ typedef struct binding_t {
} binding_t;
typedef struct i_ctx {
- binding_t* bindings;
- isize len;
+ binding_t* bindings;
+ isize len;
} i_ctx;
void i_ctx_t_free(i_ctx* c);
/* Executes all callbacks that has been pushed onto the callstack and resets the
* callstack */
void i_flush_bindings(usize numcalls, void* state_mem, input_callback_t* c[]);
-action_t i_get_action(const i_ctx *restrict ctx, u32 time, scancode_t scancode);
+action_t i_get_action(const i_ctx* restrict ctx, u32 time, scancode_t scancode);
-void i_ctx_push(i_ctx *ctx);
+void i_ctx_push(i_ctx* ctx);
void i_ctx_pop(void);
void i_ctx_reset(void);
/* Finds and updates the scancode of a binding with the given action in ctx */
-void i_bind_ctx(i_ctx *c, scancode_t s, action_t *a);
-void i_bind_ctx_alt(i_ctx *c, scancode_t s, action_t *a);
+void i_bind_ctx(i_ctx* c, scancode_t s, action_t* a);
+void i_bind_ctx_alt(i_ctx* c, scancode_t s, action_t* a);
/* Update the scancode of a binding */
-void i_bind(binding_t *b, scancode_t s);
-void i_bind_alt(binding_t *b, scancode_t s);
+void i_bind(binding_t* b, scancode_t s);
+void i_bind_alt(binding_t* b, scancode_t s);
-#define BindAction(key, altkey, f_action) \
- (binding_t){\
- .action = (action_t){.action = {\
- .type = InputType_action,\
- .callback = (input_callback_t*)&f_action,\
- .callback_str = strdup( #f_action ),\
- }},\
- .scancode = key,\
- .scancode_alt = altkey,\
- .since_last_activation = 0\
-}
-
-#define BindState(key, altkey, f_activate, f_deactivate) \
- (binding_t){\
- .action = (action_t){.state = {\
- .type = InputType_state,\
- .activate = (input_callback_t*)&f_activate,\
- .deactivate = (input_callback_t*)&f_deactivate,\
- .activate_str = strdup( #f_activate ),\
- .deactivate_str = strdup( #f_deactivate ),\
- }},\
- .scancode = key,\
- .scancode_alt = altkey,\
- .since_last_activation = 0\
-}
+#define BindAction(key, altkey, f_action) \
+ (binding_t) { \
+ .action = (action_t){.action = \
+ { \
+ .type = InputType_action, \
+ .callback = (input_callback_t*)&f_action, \
+ .callback_str = strdup(#f_action), \
+ }}, \
+ .scancode = key, .scancode_alt = altkey, .since_last_activation = 0 \
+ }
+#define BindState(key, altkey, f_activate, f_deactivate) \
+ (binding_t) { \
+ .action = \
+ (action_t){.state = \
+ { \
+ .type = InputType_state, \
+ .activate = (input_callback_t*)&f_activate, \
+ .deactivate = (input_callback_t*)&f_deactivate, \
+ .activate_str = strdup(#f_activate), \
+ .deactivate_str = strdup(#f_deactivate), \
+ }}, \
+ .scancode = key, .scancode_alt = altkey, .since_last_activation = 0 \
+ }
#endif
diff --git a/include/engine/list.h b/include/engine/list.h
index 5d3f80b..37857f0 100644
--- a/include/engine/list.h
+++ b/include/engine/list.h
@@ -1,11 +1,11 @@
#ifndef ENGINE_LIST_H
#define ENGINE_LIST_H
-#define DEFINE_LLIST(type) \
-struct List_##type { \
- type value; \
- struct List_##type* next; \
- /* Force the user to add `;` for style consistency */\
-} List_##type
+#define DEFINE_LLIST(type) \
+ struct List_##type { \
+ type value; \
+ struct List_##type* next; \
+ /* Force the user to add `;` for style consistency */ \
+ } List_##type
#endif
diff --git a/include/engine/logging.h b/include/engine/logging.h
index 8d5ef31..d1c5890 100644
--- a/include/engine/logging.h
+++ b/include/engine/logging.h
@@ -1,20 +1,20 @@
#ifndef LOGGING_H
#define LOGGING_H
+#include <math.h>
+#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
-#include <stdarg.h>
#include <string.h>
-#include <math.h>
#include "types.h"
#if defined __linux__ || defined __APPLE__
-#define TERM_COLOR_RESET "\033[0m"
-#define TERM_COLOR_RED "\033[31m"
-#define TERM_COLOR_GREEN "\033[32m"
+#define TERM_COLOR_RESET "\033[0m"
+#define TERM_COLOR_RED "\033[31m"
+#define TERM_COLOR_GREEN "\033[32m"
#define TERM_COLOR_YELLOW "\033[33m"
-#define TERM_COLOR_BLUE "\033[34m"
+#define TERM_COLOR_BLUE "\033[34m"
#define TERM_COLOR_PURPLE "\033[35m"
#else
#define TERM_COLOR_RESET
@@ -27,22 +27,23 @@
#define STR(a) (#a)
-void _log(FILE *stream, const char *prefix, const char *fmt, va_list ap);
+void _log(FILE* stream, const char* prefix, const char* fmt, va_list ap);
-void LOG(const char *fmt, ...);
+void LOG(const char* fmt, ...);
-void INFO_(const char *fmt, ...);
-void INFO(const char *fmt, ...);
+void INFO_(const char* fmt, ...);
+void INFO(const char* fmt, ...);
#ifdef _DEBUG
-#define DEBUG(fmt, ...) __DEBUG(__FILE__,__LINE__, __func__, fmt, __VA_ARGS__)
-void __DEBUG(const char* file, const i32 line, const char* func, const char *fmt, ...);
+#define DEBUG(fmt, ...) __DEBUG(__FILE__, __LINE__, __func__, fmt, __VA_ARGS__)
+void __DEBUG(const char* file, const i32 line, const char* func,
+ const char* fmt, ...);
#else
#define DEBUG(...)
#endif
-void WARN(const char *fmt, ...);
+void WARN(const char* fmt, ...);
-void ERROR(const char *fmt, ...);
+void ERROR(const char* fmt, ...);
#endif
diff --git a/include/engine/memory.h b/include/engine/memory.h
index 8b37747..04c24d5 100644
--- a/include/engine/memory.h
+++ b/include/engine/memory.h
@@ -2,24 +2,24 @@
#define MEMORY_H
#include "types.h"
-//#include <stdlib.h>
+// #include <stdlib.h>
typedef struct memory {
- void *data;
+ void* data;
usize size;
usize pos;
usize free;
} memory;
-memory *memory_new(usize max_size);
+memory* memory_new(usize max_size);
/* Returns a pointer to the allocated data */
-void *memory_allocate(memory* mem, usize size);
+void* memory_allocate(memory* mem, usize size);
-memory memory_init(void *data, usize size);
+memory memory_init(void* data, usize size);
-void memory_free(memory *mem, usize size);
+void memory_free(memory* mem, usize size);
-void memory_clear(memory *mem);
+void memory_clear(memory* mem);
#endif
diff --git a/include/engine/rendering.h b/include/engine/rendering.h
index 3ec8416..cfd9679 100644
--- a/include/engine/rendering.h
+++ b/include/engine/rendering.h
@@ -5,8 +5,9 @@
#include "vector.h"
/* Definitions */
-#define RGBA(_r,_g,_b,_a) ((Engine_color){.r=_r, .g=_g, .b=_b, .a=_a})
-#define RGB(_r,_g,_b) RGBA(_r,_g,_b,0xFF)
+#define RGBA(_r, _g, _b, _a) \
+ ((Engine_color){.r = _r, .g = _g, .b = _b, .a = _a})
+#define RGB(_r, _g, _b) RGBA(_r, _g, _b, 0xFF)
/* Types */
typedef struct {
@@ -17,18 +18,18 @@ typedef struct {
} Engine_color;
typedef struct {
- u32 texture_id;
+ u32 texture_id;
v2_i32 coord;
} Sprite;
-#include "ui.h"
#include "engine.h"
+#include "ui.h"
/* Rendering functions */
-void render_begin(Window *w);
-void render_present(Window *w);
+void render_begin(Window* w);
+void render_present(Window* w);
void drawcall_reset(void);
-void render(Window *w);
+void render(Window* w);
/* Misc */
void engine_window_resize_pointers(i32* w, i32* h);
@@ -36,10 +37,12 @@ void engine_window_resize_pointers_reset(void);
/* UI rendering */
/* See rendering_ui.c for implementation */
-i64 engine_render_text(i32 font_id, Engine_color fg, char *text, v2_i32 *size_out, bool wrapped);
-void engine_draw_uitree(UITree *t);
-void engine_draw_sprite(Sprite *s, v2_i32 *pos, f32 scale);
-void engine_draw_sprite_ex(Sprite *s, v2_i32 *pos, f32 scale, Engine_color colormod);
+i64 engine_render_text(i32 font_id, Engine_color fg, char* text,
+ v2_i32* size_out, bool wrapped);
+void engine_draw_uitree(UITree* t);
+void engine_draw_sprite(Sprite* s, v2_i32* pos, f32 scale);
+void engine_draw_sprite_ex(Sprite* s, v2_i32* pos, f32 scale,
+ Engine_color colormod);
Sprite sprite_new(u64 tid, u8 coord);
@@ -49,32 +52,33 @@ Sprite sprite_new(u64 tid, u8 coord);
#define TEXTURES_INCREMENT 512
typedef enum {
- RenderDrawCallType_UITree,
- /*RenderDrawCallType_UIButton,*/
- RenderDrawCallType_Text,
- RenderDrawCallType_Sprite,
+ RenderDrawCallType_UITree,
+ /*RenderDrawCallType_UIButton,*/
+ RenderDrawCallType_Text,
+ RenderDrawCallType_Sprite,
} RenderDrawCallType;
typedef struct {
- RenderDrawCallType type;
- union {
- void *data;
- struct {
- Sprite *sprite;
- i32 x; i32 y;
- f32 scale;
- SDL_Color mod;
- } sprite;
- } data;
+ RenderDrawCallType type;
+ union {
+ void* data;
+ struct {
+ Sprite* sprite;
+ i32 x;
+ i32 y;
+ f32 scale;
+ SDL_Color mod;
+ } sprite;
+ } data;
} RenderDrawCall;
-void render_uitree(Window *w, UITree *t);
+void render_uitree(Window* w, UITree* t);
-void render_container(Window *w, UITree_container *t);
-void render_button(Window *w, UITree_button *t);
-void render_title(Window *w, UITree_title *t);
-void render_text(Window *w, UITree_text *t);
-v2_i32 elem_size(UITree *root);
+void render_container(Window* w, UITree_container* t);
+void render_button(Window* w, UITree_button* t);
+void render_title(Window* w, UITree_title* t);
+void render_text(Window* w, UITree_text* t);
+v2_i32 elem_size(UITree* root);
#endif
diff --git a/include/engine/resources.h b/include/engine/resources.h
index 057a8a4..1689544 100644
--- a/include/engine/resources.h
+++ b/include/engine/resources.h
@@ -18,57 +18,52 @@
* */
enum Asset {
- Asset_error,
- Asset_font,
- Asset_texture,
- Asset_audio,
+ Asset_error,
+ Asset_font,
+ Asset_texture,
+ Asset_audio,
};
typedef struct {
- enum Asset type;
- const char *font_path;
- i32 ptsize;
+ enum Asset type;
+ const char* font_path;
+ i32 ptsize;
} Asset_FontSpec;
typedef struct {
- enum Asset type;
- const char *path;
- i32 width;
- i32 height;
+ enum Asset type;
+ const char* path;
+ i32 width;
+ i32 height;
} Asset_TextureSpec;
typedef struct {
- enum Asset type;
- const char *path;
+ enum Asset type;
+ const char* path;
} Asset_AudioSpec;
typedef union {
- enum Asset type;
- Asset_FontSpec font;
- Asset_TextureSpec texture;
- Asset_AudioSpec audio;
+ enum Asset type;
+ Asset_FontSpec font;
+ Asset_TextureSpec texture;
+ Asset_AudioSpec audio;
} asset_t;
-#define Resource_FontDefinition(_path, _fontsize) \
-(const Asset_FontSpec){ \
- .type = Asset_font, \
- .font_path = _path, \
- .ptsize = _fontsize \
-}
+#define Resource_FontDefinition(_path, _fontsize) \
+ (const Asset_FontSpec) { \
+ .type = Asset_font, .font_path = _path, .ptsize = _fontsize \
+ }
-#define Resource_TextureAtlasDefinition(_path, _subtexture_width, _subtexture_height) \
-(const Asset_TextureSpec){ \
- .type = Asset_texture, \
- .width = _subtexture_width, \
- .height = _subtexture_height, \
- .path = _path \
-}
+#define Resource_TextureAtlasDefinition(_path, _subtexture_width, \
+ _subtexture_height) \
+ (const Asset_TextureSpec) { \
+ .type = Asset_texture, .width = _subtexture_width, \
+ .height = _subtexture_height, .path = _path \
+ }
-#define TextureDefinition(_path, ...) \
- unimplemented
+#define TextureDefinition(_path, ...) unimplemented
-#define Resource_AudioDefinition(_path, ...) \
- unimplemented
+#define Resource_AudioDefinition(_path, ...) unimplemented
/* Each of resource_load_font, resource_load_texture, and resource_load_audio
* loads a given resource into the engines memory and returns an identifier.
diff --git a/include/engine/stack.h b/include/engine/stack.h
index 636c306..69975df 100644
--- a/include/engine/stack.h
+++ b/include/engine/stack.h
@@ -28,22 +28,23 @@
#include "types.h"
typedef struct {
- isize head; /* current number of elements */
+ isize head; /* current number of elements */
const usize elem_size; /* size in bytes of each element */
- usize size; /* current memory size used by the stack */
- const usize chunk_size; /* size of which the stack increases when running out of mem */
- void *data; /* memory buffer */
+ usize size; /* current memory size used by the stack */
+ const usize chunk_size; /* size of which the stack increases when running out
+ of mem */
+ void* data; /* memory buffer */
} Stack;
Stack stack_new_ex(const usize element_size, const usize size);
Stack stack_new(const usize element_size);
-void stack_free(Stack *s);
-void *stack_pop(Stack *s);
-void stack_push(Stack *s, void *elem);
-void *stack_peek(Stack *s);
-isize stack_size(const Stack *s);
-void stack_swap(Stack *s, Stack *t);
+void stack_free(Stack* s);
+void* stack_pop(Stack* s);
+void stack_push(Stack* s, void* elem);
+void* stack_peek(Stack* s);
+isize stack_size(const Stack* s);
+void stack_swap(Stack* s, Stack* t);
#endif
diff --git a/include/engine/state.h b/include/engine/state.h
index 9c832f5..13593ed 100644
--- a/include/engine/state.h
+++ b/include/engine/state.h
@@ -11,19 +11,18 @@ typedef enum StateType {
STATE_quit,
} StateType;
+extern const char* StateTypeStr[];
-extern const char *StateTypeStr[];
+StateType (*State_updateFunc(StateType type))(void*);
-StateType(*State_updateFunc(StateType type))(void*);
-
-void State_init(StateType type, memory *mem);
-void State_free(StateType type, memory *mem);
-StateType State_update(StateType type, memory *mem);
+void State_init(StateType type, memory* mem);
+void State_free(StateType type, memory* mem);
+StateType State_update(StateType type, memory* mem);
/* Reloads shared object file associated with state */
#ifdef DAW_BUILD_HOTRELOAD
#include <engine/input.h>
-bool State_reload(StateType type, i_ctx **ctx, usize ctx_len);
+bool State_reload(StateType type, i_ctx** ctx, usize ctx_len);
#else
#define State_reload(_, _0, _1) true
diff --git a/include/engine/types.h b/include/engine/types.h
index 181e245..934cb63 100644
--- a/include/engine/types.h
+++ b/include/engine/types.h
@@ -1,24 +1,24 @@
#ifndef ENGINE_TYPES_H
#define ENGINE_TYPES_H
-#include <stdint.h>
#include <stdbool.h>
+#include <stdint.h>
/* Signed */
-typedef int8_t i8;
-typedef int16_t i16;
-typedef int32_t i32;
-typedef int64_t i64;
+typedef int8_t i8;
+typedef int16_t i16;
+typedef int32_t i32;
+typedef int64_t i64;
/* Unsigned */
-typedef uint8_t u8;
+typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
/* floating points */
-typedef float f32;
-typedef double f64;
+typedef float f32;
+typedef double f64;
/* sizes */
#if __x86_64__ || __ppc64__ || _WIN64
diff --git a/include/engine/ui.h b/include/engine/ui.h
index bea8d3e..4a3cd3e 100644
--- a/include/engine/ui.h
+++ b/include/engine/ui.h
@@ -1,9 +1,9 @@
#ifndef ENGINE_UI_H
#define ENGINE_UI_H
+#include "list.h"
#include "types.h"
#include "vector.h"
-#include "list.h"
#define DIRECTION_HORIZONTAL true
#define DIRECTION_VERTICAL false
@@ -14,14 +14,18 @@ typedef enum {
ui_size_percent,
} ui_size_t;
-
typedef union {
ui_size_t type;
- struct {ui_size_t type; i32 value;} pixel;
- struct {ui_size_t type; f32 value;} percent;
+ struct {
+ ui_size_t type;
+ i32 value;
+ } pixel;
+ struct {
+ ui_size_t type;
+ f32 value;
+ } percent;
} ui_size;
-
typedef enum {
ui_constraint_width,
ui_constraint_height,
@@ -35,14 +39,12 @@ typedef enum {
ui_constraint_bottom,
} ui_constraint_t;
-
typedef enum {
ui_constraint_vertical_align_top,
ui_constraint_vertical_align_center,
ui_constraint_vertical_align_bottom,
} ui_constraint_vertical_align_t;
-
typedef enum {
ui_constraint_horizontal_align_left,
ui_constraint_horizontal_align_center,
@@ -50,38 +52,62 @@ typedef enum {
} ui_constraint_horizontal_align_t;
typedef union {
- struct {ui_size size;} width;
- struct {ui_size size;} height;
+ struct {
+ ui_size size;
+ } width;
+ struct {
+ ui_size size;
+ } height;
/* spacing is the padding between the aligned edge and the container itself */
- struct {ui_constraint_horizontal_align_t align; ui_size spacing;} horizontal_align;
- struct {ui_constraint_vertical_align_t align; ui_size spacing;} vertical_align;
+ struct {
+ ui_constraint_horizontal_align_t align;
+ ui_size spacing;
+ } horizontal_align;
+ struct {
+ ui_constraint_vertical_align_t align;
+ ui_size spacing;
+ } vertical_align;
- struct {ui_size pos;} left;
- struct {ui_size pos;} top;
- struct {ui_size pos;} right;
- struct {ui_size pos;} bottom;
+ struct {
+ ui_size pos;
+ } left;
+ struct {
+ ui_size pos;
+ } top;
+ struct {
+ ui_size pos;
+ } right;
+ struct {
+ ui_size pos;
+ } bottom;
} constraintval_t;
-#define CONSTRAINT_POSITION(axis, alignment_sub, margin, cnext) { \
- .value = { \
- .type = ui_constraint_##axis##_align, \
- .constraint.axis##_align = { \
- .align = ui_constraint_##axis##_align_##alignment_sub, \
- .spacing = margin, \
- }, \
- }, \
- .next = cnext, \
+#define CONSTRAINT_POSITION(axis, alignment_sub, margin, cnext) \
+ { \
+ .value = \
+ { \
+ .type = ui_constraint_##axis##_align, \
+ .constraint.axis##_align = \
+ { \
+ .align = ui_constraint_##axis##_align_##alignment_sub, \
+ .spacing = margin, \
+ }, \
+ }, \
+ .next = cnext, \
}
-#define CONSTRAINT_SIZE(c_type, csize, cnext) { \
- .value = { \
- .type = ui_constraint_##c_type, \
- .constraint.c_type = { \
- .size = csize, \
- }, \
- }, \
- .next = cnext, \
+#define CONSTRAINT_SIZE(c_type, csize, cnext) \
+ { \
+ .value = \
+ { \
+ .type = ui_constraint_##c_type, \
+ .constraint.c_type = \
+ { \
+ .size = csize, \
+ }, \
+ }, \
+ .next = cnext, \
}
typedef struct {
@@ -91,7 +117,6 @@ typedef struct {
typedef DEFINE_LLIST(ui_constraint);
-
enum uitype {
uitype_container,
uitype_button,
@@ -101,14 +126,13 @@ enum uitype {
uitype_MAX,
};
-
typedef struct UITree_container {
enum uitype type;
- bool visible;
- bool direction;
- i32 x, y, w, h;
- i32 padding;
- i32 margin;
+ bool visible;
+ bool direction;
+ i32 x, y, w, h;
+ i32 padding;
+ i32 margin;
Engine_color fg;
Engine_color bg;
@@ -117,13 +141,13 @@ typedef struct UITree_container {
usize children_len; /* Number of children */
usize children_size; /* Memory size */
union UITree** children;
- struct List_ui_constraint *constraints;
+ struct List_ui_constraint* constraints;
} UITree_container;
typedef struct UITree_button {
enum uitype type;
- bool enabled;
+ bool enabled;
u64 id;
i32 x, y, w, h;
@@ -133,11 +157,11 @@ typedef struct UITree_button {
Engine_color fg;
Engine_color bg;
- i32 font_id;
- const char *text_original;
- u64 text_texture_index;
- v2_i32 texture_size;
- struct List_ui_constraint *constraints;
+ i32 font_id;
+ const char* text_original;
+ u64 text_texture_index;
+ v2_i32 texture_size;
+ struct List_ui_constraint* constraints;
} UITree_button;
typedef struct UITree_title {
@@ -149,11 +173,11 @@ typedef struct UITree_title {
Engine_color fg;
- i32 font_id;
- const char *text_original;
- u64 text_texture_index;
- v2_i32 texture_size;
- struct List_ui_constraint *constraints;
+ i32 font_id;
+ const char* text_original;
+ u64 text_texture_index;
+ v2_i32 texture_size;
+ struct List_ui_constraint* constraints;
} UITree_title;
typedef struct UITree_text {
@@ -165,20 +189,20 @@ typedef struct UITree_text {
Engine_color fg;
- i32 font_id;
- const char *text_original;
- u64 text_texture_index;
- v2_i32 texture_size;
- struct List_ui_constraint *constraints;
+ i32 font_id;
+ const char* text_original;
+ u64 text_texture_index;
+ v2_i32 texture_size;
+ struct List_ui_constraint* constraints;
} UITree_text;
typedef union UITree {
enum uitype type;
UITree_container container;
- UITree_button button;
- UITree_title title;
- UITree_text text;
+ UITree_button button;
+ UITree_title title;
+ UITree_text text;
struct List_ui_constraint constraints;
} UITree;
@@ -191,34 +215,40 @@ i32 ui_size_percent_height_to_pixel(f32 percent);
i32 ui_size_percent_to_pixel(f32 percent);
i32 ui_size_to_pixel(ui_size s);
-#define ui_size_percent_new(p) {.percent = {.type = ui_size_percent, .value = p}}
-#define ui_size_pixel_new(p) {.pixel = {.type = ui_size_pixel, .value = p}}
+#define ui_size_percent_new(p) \
+ { \
+ .percent = {.type = ui_size_percent, .value = p } \
+ }
+#define ui_size_pixel_new(p) \
+ { \
+ .pixel = {.type = ui_size_pixel, .value = p } \
+ }
/* Constructors */
-UITree *ui_container(bool direction, struct List_ui_constraint *constraints);
-UITree *ui_button(u64 id, i32 font_id, char *text, struct List_ui_constraint *constraints);
-UITree *ui_title(i32 font_id, const char *text, struct List_ui_constraint *constraints);
-UITree *ui_text(i32 font_id, const char *text, struct List_ui_constraint *constraints);
+UITree* ui_container(bool direction, struct List_ui_constraint* constraints);
+UITree* ui_button(u64 id, i32 font_id, char* text,
+ struct List_ui_constraint* constraints);
+UITree* ui_title(i32 font_id, const char* text,
+ struct List_ui_constraint* constraints);
+UITree* ui_text(i32 font_id, const char* text,
+ struct List_ui_constraint* constraints);
/* Extended Constructors */
-UITree *ui_container_new_ex(
- Engine_color fg,
- Engine_color bg,
- Engine_color border,
- bool direction,
- struct List_ui_constraint *constraints);
+UITree* ui_container_new_ex(Engine_color fg, Engine_color bg,
+ Engine_color border, bool direction,
+ struct List_ui_constraint* constraints);
/* Destructors */
void clear_ui(void);
-void uitree_free(UITree *t);
+void uitree_free(UITree* t);
/* Manipulation */
-void ui_container_attach(UITree *container, UITree *child);
+void ui_container_attach(UITree* container, UITree* child);
void ui_resolve_constraints(void);
-void ui_button_enable(UITree_button *b);
-void ui_button_disable(UITree_button *b);
+void ui_button_enable(UITree_button* b);
+void ui_button_disable(UITree_button* b);
/* Tweaking default colors */
void ui_set_default_colors(Engine_color fg, Engine_color bg);
@@ -226,9 +256,9 @@ void ui_set_default_padding(i32 padding);
Engine_color ui_get_default_fg(void);
Engine_color ui_get_default_bg(void);
-#define ELEM_NOT_FOUND (-1)
-#define NO_CLICK (-2)
+#define ELEM_NOT_FOUND (-1)
+#define NO_CLICK (-2)
/* Returns -1 if not found */
-u64 ui_check_click(UITree *root);
+u64 ui_check_click(UITree* root);
#endif
diff --git a/include/engine/utils.h b/include/engine/utils.h
index b4b0e7d..e537f52 100644
--- a/include/engine/utils.h
+++ b/include/engine/utils.h
@@ -4,17 +4,17 @@
#include "types.h"
#include "vector.h"
-#define MIN(a,b) ((a < b) ? (a) : (b))
-#define MAX(a,b) ((a > b) ? (a) : (b))
+#define MIN(a, b) ((a < b) ? (a) : (b))
+#define MAX(a, b) ((a > b) ? (a) : (b))
#define MASK_TL (1 << 0)
-#define MASK_T (1 << 1)
+#define MASK_T (1 << 1)
#define MASK_TR (1 << 2)
-#define MASK_L (1 << 3)
-#define MASK_C (1 << 4)
-#define MASK_R (1 << 5)
+#define MASK_L (1 << 3)
+#define MASK_C (1 << 4)
+#define MASK_R (1 << 5)
#define MASK_BL (1 << 6)
-#define MASK_B (1 << 7)
+#define MASK_B (1 << 7)
#define MASK_BR (1 << 8)
/* Linear interpolate */
@@ -22,13 +22,15 @@ f32 lerp(f32 dt, f32 a, f32 b);
i32 int_lerp(f32 dt, i32 a, i32 b);
/* Hashes */
-u32 hash(char *str);
+u32 hash(char* str);
/* Masks surrounding tiles of a kernel size of 3x3 */
-/* In reality we only need 9 bits for this, but I think I had a reason for using i32 */
-i32* kernmap(const void *map, i32 *dstmap, const v2_i32 mapsize, predicate_t *predicate);
+/* In reality we only need 9 bits for this, but I think I had a reason for using
+ * i32 */
+i32* kernmap(const void* map, i32* dstmap, const v2_i32 mapsize,
+ predicate_t* predicate);
/* Returns an index from the given weights. */
-i32 pick_from_sample(const i32 *weights, i32 len);
+i32 pick_from_sample(const i32* weights, i32 len);
#endif
diff --git a/include/engine/vector.h b/include/engine/vector.h
index 396e12d..58bb0a2 100644
--- a/include/engine/vector.h
+++ b/include/engine/vector.h
@@ -3,8 +3,8 @@
#include "types.h"
-#include <stdio.h>
#include <stdbool.h>
+#include <stdio.h>
typedef struct {
i32 x;
@@ -13,19 +13,19 @@ typedef struct {
bool v2_i32_eq(const v2_i32 a, const v2_i32 b);
-v2_i32 v2_i32_add (v2_i32 a, v2_i32 b);
-v2_i32 v2_i32_add_i(v2_i32 a, i32 b);
-v2_i32 v2_i32_sub (v2_i32 a, v2_i32 b);
-v2_i32 v2_i32_sub_i(v2_i32 a, i32 b);
-v2_i32 v2_i32_div (v2_i32 a, v2_i32 b);
-v2_i32 v2_i32_div_i(v2_i32 a, i32 b);
-v2_i32 v2_i32_mul (v2_i32 a, v2_i32 b);
-v2_i32 v2_i32_mul_i(v2_i32 a, i32 b);
-v2_i32 v2_i32_mod (v2_i32 a, v2_i32 b);
-v2_i32 v2_i32_mod_i(v2_i32 a, i32 b);
-v2_i32 v2_i32_max (v2_i32 a, v2_i32 b);
-v2_i32 v2_i32_min (v2_i32 a, v2_i32 b);
-v2_i32 v2_i32_lerp (f32 dt, v2_i32 a, v2_i32 b);
+v2_i32 v2_i32_add(v2_i32 a, v2_i32 b);
+v2_i32 v2_i32_add_i(v2_i32 a, i32 b);
+v2_i32 v2_i32_sub(v2_i32 a, v2_i32 b);
+v2_i32 v2_i32_sub_i(v2_i32 a, i32 b);
+v2_i32 v2_i32_div(v2_i32 a, v2_i32 b);
+v2_i32 v2_i32_div_i(v2_i32 a, i32 b);
+v2_i32 v2_i32_mul(v2_i32 a, v2_i32 b);
+v2_i32 v2_i32_mul_i(v2_i32 a, i32 b);
+v2_i32 v2_i32_mod(v2_i32 a, v2_i32 b);
+v2_i32 v2_i32_mod_i(v2_i32 a, i32 b);
+v2_i32 v2_i32_max(v2_i32 a, v2_i32 b);
+v2_i32 v2_i32_min(v2_i32 a, v2_i32 b);
+v2_i32 v2_i32_lerp(f32 dt, v2_i32 a, v2_i32 b);
-void v2_i32_fprintf(FILE *stream, v2_i32 a);
+void v2_i32_fprintf(FILE* stream, v2_i32 a);
#endif