diff options
| author | 0scar <qgt268@alumni.ku.dk> | 2024-02-05 17:57:05 +0000 |
|---|---|---|
| committer | 0scar <qgt268@alumni.ku.dk> | 2024-02-05 17:57:05 +0000 |
| commit | d52bd1c709456164b167cc7389b641b690c97ee5 (patch) | |
| tree | 7cc8ccb610bfaa72b83fdf878b23e6efd892d73e /src/core/include/engine | |
| parent | 4813a8dde26422657c07ae03fe2b47a6b92f0935 (diff) | |
Organize the header files
Diffstat (limited to 'src/core/include/engine')
| -rw-r--r-- | src/core/include/engine/core/dltools.h | 16 | ||||
| -rw-r--r-- | src/core/include/engine/core/logging.h | 49 | ||||
| -rw-r--r-- | src/core/include/engine/core/memory.h | 25 | ||||
| -rw-r--r-- | src/core/include/engine/core/state.h | 31 | ||||
| -rw-r--r-- | src/core/include/engine/core/types.h | 34 | ||||
| -rw-r--r-- | src/core/include/engine/engine.h | 130 |
6 files changed, 285 insertions, 0 deletions
diff --git a/src/core/include/engine/core/dltools.h b/src/core/include/engine/core/dltools.h new file mode 100644 index 0000000..5a53f49 --- /dev/null +++ b/src/core/include/engine/core/dltools.h @@ -0,0 +1,16 @@ +#ifndef DLTOOLS_H +#define DLTOOLS_H + +#include <stdbool.h> + +/* 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); + +/* 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); +char* dynamic_library_get_error(void); + +#endif diff --git a/src/core/include/engine/core/logging.h b/src/core/include/engine/core/logging.h new file mode 100644 index 0000000..d1c5890 --- /dev/null +++ b/src/core/include/engine/core/logging.h @@ -0,0 +1,49 @@ +#ifndef LOGGING_H +#define LOGGING_H + +#include <math.h> +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.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_YELLOW "\033[33m" +#define TERM_COLOR_BLUE "\033[34m" +#define TERM_COLOR_PURPLE "\033[35m" +#else +#define TERM_COLOR_RESET +#define TERM_COLOR_RED +#define TERM_COLOR_GREEN +#define TERM_COLOR_YELLOW +#define TERM_COLOR_BLUE +#define TERM_COLOR_PURPLE +#endif + +#define STR(a) (#a) + +void _log(FILE* stream, const char* prefix, const char* fmt, va_list ap); + +void LOG(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, ...); +#else +#define DEBUG(...) +#endif + +void WARN(const char* fmt, ...); + +void ERROR(const char* fmt, ...); + +#endif diff --git a/src/core/include/engine/core/memory.h b/src/core/include/engine/core/memory.h new file mode 100644 index 0000000..04c24d5 --- /dev/null +++ b/src/core/include/engine/core/memory.h @@ -0,0 +1,25 @@ +#ifndef MEMORY_H +#define MEMORY_H + +#include "types.h" +// #include <stdlib.h> + +typedef struct memory { + void* data; + usize size; + usize pos; + usize free; +} memory; + +memory* memory_new(usize max_size); + +/* Returns a pointer to the allocated data */ +void* memory_allocate(memory* mem, usize size); + +memory memory_init(void* data, usize size); + +void memory_free(memory* mem, usize size); + +void memory_clear(memory* mem); + +#endif diff --git a/src/core/include/engine/core/state.h b/src/core/include/engine/core/state.h new file mode 100644 index 0000000..13593ed --- /dev/null +++ b/src/core/include/engine/core/state.h @@ -0,0 +1,31 @@ +#ifndef STATE_H +#define STATE_H + +#include <engine/memory.h> + +typedef enum StateType { + STATE_null, +#define State(name) STATE_##name, +#include <states/list_of_states.h> +#undef State + STATE_quit, +} StateType; + +extern const char* StateTypeStr[]; + +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); + +/* 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); + +#else +#define State_reload(_, _0, _1) true +#endif + +#endif diff --git a/src/core/include/engine/core/types.h b/src/core/include/engine/core/types.h new file mode 100644 index 0000000..934cb63 --- /dev/null +++ b/src/core/include/engine/core/types.h @@ -0,0 +1,34 @@ +#ifndef ENGINE_TYPES_H +#define ENGINE_TYPES_H + +#include <stdbool.h> +#include <stdint.h> + +/* Signed */ +typedef int8_t i8; +typedef int16_t i16; +typedef int32_t i32; +typedef int64_t i64; + +/* Unsigned */ +typedef uint8_t u8; +typedef uint16_t u16; +typedef uint32_t u32; +typedef uint64_t u64; + +/* floating points */ +typedef float f32; +typedef double f64; + +/* sizes */ +#if __x86_64__ || __ppc64__ || _WIN64 +typedef u64 usize; +typedef i64 isize; +#else +typedef u32 usize; +typedef i32 isize; +#endif + +typedef bool(predicate_t)(const void*); + +#endif diff --git a/src/core/include/engine/engine.h b/src/core/include/engine/engine.h new file mode 100644 index 0000000..e8a5ace --- /dev/null +++ b/src/core/include/engine/engine.h @@ -0,0 +1,130 @@ +#ifndef ENGINE_H +#define ENGINE_H + +#include <stdbool.h> + +#include <engine/input.h> +#include <engine/logging.h> +#include <engine/memory.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; +} RenderUnit; + +typedef struct Window Window; + +#define NUM_GLOBAL_BINDINGS 1 +typedef struct { + void* data; /* Contains textures and such */ + u64 data_len; + + Window* window; + bool quit; + + u64 frame; + f32 fps_target; + + /* TODO: Move mouse data to input ctx */ + v2_i32 mouse_pos; + + v2_i32 mousedown; + v2_i32 mouseup; + + bool mouse_lclick; + bool mouse_rclick; + + i32 camera_x; + i32 camera_y; + + /* Text input/editing is currently not used/implemented */ + char* edit_text; + usize edit_pos; + + memory* mem; + + i_ctx** bindings; + usize bindings_sz; + usize bindings_len; + + struct RenderObject *testobject; + + binding_t bindings_global[NUM_GLOBAL_BINDINGS]; +} Platform; + +/* Essential functions */ +Platform* engine_init(const char* windowtitle, v2_i32 windowsize, + const f32 render_scale, const u32 flags, + const usize initial_memory, const Asset_FontSpec* fonts[], + const Asset_TextureSpec* textures[]); + +i32 engine_run(Platform* p, StateType initial_state); + +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); + +f64 get_time(void); +v2_i32 get_windowsize(void); +v2_i32* get_mousepos(void); + +/* Input handling */ +void engine_input_ctx_push(i_ctx* ctx); +void engine_input_ctx_pop(void); +void engine_input_ctx_reset(void); + +#include "rendering.h" + +#ifdef ENGINE_INTERNALS + +#include <glad/gl.h> +#define GLFW_INCLUDE_NONE +#include <GLFW/glfw3.h> + +/* Window */ +struct Window { + GLFWwindow* window; + GladGLContext* context; + f32 render_scale; + + v2_i32 windowsize; + + i32* game_w; + i32* game_h; +}; + +typedef struct { + const i32 tilesize; + const i32 width; + const i32 height; +} Texture; + +struct Resources { + usize textures_len; + usize textures_size; + usize fonts_len; + + usize texturepaths_len; + usize fontpaths_len; + + /* Paths for our sources, kept in case the user wants to reload them */ + Asset_TextureSpec** texture_paths; + Asset_FontSpec** font_paths; + + /* Our actual sources */ + Texture** textures; + //TTF_Font** fonts; +}; + +#endif +#endif |
