summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/include/engine/core/platform.h55
-rw-r--r--src/core/include/engine/engine.h58
-rw-r--r--src/core/src/loop.c78
3 files changed, 80 insertions, 111 deletions
diff --git a/src/core/include/engine/core/platform.h b/src/core/include/engine/core/platform.h
new file mode 100644
index 0000000..3d965b7
--- /dev/null
+++ b/src/core/include/engine/core/platform.h
@@ -0,0 +1,55 @@
+#ifndef ENGINE_CORE_PLATFORM_H
+#define ENGINE_CORE_PLATFORM_H
+
+#include <engine/core/types.h>
+#include <engine/core/memory.h>
+#include <engine/ctrl/input.h>
+#include <engine/rendering/window.h>
+#include <engine/utils/vector.h>
+
+#define NUM_GLOBAL_BINDINGS 1
+
+/* Defines the internally used state of the engine.
+ * A single instance is created during `engine_init`, and used as a global
+ * variable (yeah, im sorry). Due to this design flaw the engine as a whole is
+ * not quite thread safe.
+ */
+typedef struct Platform {
+ 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;
+
+ /* The ctrl is probably the only sensible thing in this struct. */
+ i_ctx** bindings;
+ usize bindings_sz;
+ usize bindings_len;
+
+ struct RenderObject *testobject;
+
+ binding_t bindings_global[NUM_GLOBAL_BINDINGS];
+} Platform;
+
+#endif
diff --git a/src/core/include/engine/engine.h b/src/core/include/engine/engine.h
index 1715f8a..ec685f5 100644
--- a/src/core/include/engine/engine.h
+++ b/src/core/include/engine/engine.h
@@ -3,8 +3,9 @@
#include <stdbool.h>
-// TODO: Cleanup the includes, ideally this header file should only include all
-// "public-facing" headers.
+/* TODO: Cleanup the includes, ideally this header file should only include all
+ * "public-facing" headers.
+ */
#include <engine/core/types.h>
#include <engine/core/logging.h>
@@ -21,44 +22,7 @@ typedef struct {
} RenderUnit;
#include <engine/rendering/window.h>
-
-#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;
+#include <engine/core/platform.h>
/* Essential functions */
Platform* engine_init(const char* windowtitle, i32 windowWidth, i32 windowHeight,
@@ -77,23 +41,11 @@ 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);
+v2_i32* get_mousepos(void);
-//#include <engine/rendering/rendering.h>
-
-//#ifdef ENGINE_INTERNALS
-//
-//#include <glad/gl.h>
-//#define GLFW_INCLUDE_NONE
-//#include <GLFW/glfw3.h>
-//
-//
-//#endif
#endif
diff --git a/src/core/src/loop.c b/src/core/src/loop.c
index 2914bb3..a0cb868 100644
--- a/src/core/src/loop.c
+++ b/src/core/src/loop.c
@@ -407,43 +407,7 @@ i32 engine_run(Platform* p, StateType initial_state) {
//printf("\n FPS: %.1f \t ticks: %lu", (double)ticks / now, ticks);
}
-#ifdef BENCHMARK
- if (time - profile_interval_timer > profile_interval_ms) {
- /* Ticks/frames since last measurement */
- u32 fps = (ticks - profile_tick_counter) / profile_interval_scale;
- u64 drawcalls = profile_num_drawcalls / profile_interval_scale / fps;
-
- u32 sum = +profile_rendering
- //+ profile_slack
- + profile_input + profile_input_handling + profile_gameloop;
-
- /* Log fps and slack percentage */
- LOG("fps:%d\t"
- "rendering:%.2f%%\t"
- //"slack:%.2f%%\t"
- "input:%.2f%% (%.2f%%)\t"
- "gameloop:%.2f%%\t"
- "unaccounted:%llu / %llu ms\t"
- "avg drawcalls:%llu",
- fps, 100.0f * (f32)profile_rendering / (f32)sum,
- // 100.0f * (f32)profile_slack / (f32)sum,
- 100.0f * (f32)profile_input / (f32)sum,
- 100.0f * (f32)profile_input_handling / (f32)sum,
- 100.0f * (f32)profile_gameloop / (f32)sum,
- time - profile_interval_timer - sum, sum, drawcalls);
- /* Reset values */
- profile_tick_counter = ticks;
- profile_interval_timer = time;
- // profile_slack = 0;
- profile_rendering = 0;
- profile_gameloop = 0;
- profile_input = 0;
- profile_input_handling = 0;
- profile_num_drawcalls = 0;
- }
-#endif
-
- //glfwPollEvents();
+ glfwPollEvents();
/* Events */
// if (p->mouse_lclick) {
// p->mouseup.x = -1;
@@ -471,22 +435,21 @@ i32 engine_run(Platform* p, StateType initial_state) {
// callbacks_len = 0;
//
// /* update */
-// StateType next_state;
-// next_state = update_func((void*)(mem->data));
-//
-// if (next_state != STATE_null) {
-// if (next_state == STATE_quit) break;
-//
-// drawcall_reset();
-//
-// engine_window_resize_pointers_reset();
-// State_free(state, mem);
-// memory_clear(mem);
-//
-// engine_input_ctx_reset();
-//
-// state = next_state;
-// update_func = State_updateFunc(state);
+ StateType next_state;
+ next_state = update_func((void*)(mem->data));
+
+ if (next_state != STATE_null) {
+ if (next_state == STATE_quit) break;
+
+ drawcall_reset();
+
+ State_free(state, mem);
+ memory_clear(mem);
+
+ engine_input_ctx_reset();
+
+ state = next_state;
+ update_func = State_updateFunc(state);
//#ifdef BENCHMARK
// {
// f64 t = get_time();
@@ -495,9 +458,9 @@ i32 engine_run(Platform* p, StateType initial_state) {
// (int)((get_time() - t) * 1000.0));
// }
//#else
-// State_init(state, mem);
+ State_init(state, mem);
//#endif
-// } else {
+ } else {
//#ifdef BENCHMARK
// profile_num_drawcalls += drawcall_len;
//#endif
@@ -567,7 +530,7 @@ i32 engine_run(Platform* p, StateType initial_state) {
//gl->DisableVertexAttribArray(1);
render_present(p->window);
-// }
+ }
ticks++;
} while(
@@ -596,6 +559,7 @@ void engine_stop(Platform* p) {
//}
+ destroy_window(p->window);
}
/* Set the maximum framerate */
@@ -655,7 +619,5 @@ void engine_input_ctx_reset(void) {
i_ctx_t_free(GLOBAL_PLATFORM->bindings[--GLOBAL_PLATFORM->bindings_len]);
}
}
-
-f64 get_time(void) { return glfwGetTime(); }
//ivec2 get_windowsize(void) { return GLOBAL_PLATFORM->window->windowsize; }
v2_i32* get_mousepos(void) { return &GLOBAL_PLATFORM->mouse_pos; }