summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoronelin <oscar@nelin.dk>2025-11-28 20:16:32 +0000
committeronelin <oscar@nelin.dk>2025-12-18 21:14:13 +0000
commit7649615f710754582dcd6f9d17be30ad4682ca40 (patch)
tree82c8be00134ae85ab027ec641119a0630024c9a4 /src
parent9175e44d16dbda51d26d90fdacea7fc7b0a3c9cc (diff)
Add instance to state init & update
Diffstat (limited to 'src')
-rw-r--r--src/daw.c8
-rw-r--r--src/include/daw/state.h8
-rw-r--r--src/state.c16
3 files changed, 17 insertions, 15 deletions
diff --git a/src/daw.c b/src/daw.c
index 36604b8..284bfc7 100644
--- a/src/daw.c
+++ b/src/daw.c
@@ -175,7 +175,7 @@ i32 engine_run(Instance* p, StateType initial_state, void* state_arg) {
{
u64 state_init_time = get_time();
- State_init(state, mem, state_arg);
+ State_init(state, p->window, mem, state_arg);
if (!w->render_targets) {
// Create only 1 additional framebuffer, in addition to the default
// one. This is used to render a texture that is represented as a quad
@@ -198,7 +198,7 @@ i32 engine_run(Instance* p, StateType initial_state, void* state_arg) {
// Update ticks
u64 ticks = 0;
- StateType (*update_func)(f64, void*) = State_updateFunc(state);
+ StateType (*update_func)(Window *restrict, void*, f64) = State_updateFunc(state);
u64 last_fps_measurement = frame_end;
u64 last_fps_ticks = 0;
@@ -223,7 +223,7 @@ i32 engine_run(Instance* p, StateType initial_state, void* state_arg) {
/* Update */
StateType next_state;
- next_state = update_func(dt, (void*)(mem->data));
+ next_state = update_func(p->window, (void*)(mem->data), dt);
if (next_state != STATE_null) {
if (next_state == STATE_quit) break;
@@ -243,7 +243,7 @@ i32 engine_run(Instance* p, StateType initial_state, void* state_arg) {
update_func = State_updateFunc(state);
{
u64 state_init_time = get_time();
- State_init(state, mem, retval);
+ State_init(state, p->window, mem, retval);
if (!w->render_targets) {
// Create only 1 additional framebuffer, in addition to the default
// one. This is used to render a texture that is represented as a quad
diff --git a/src/include/daw/state.h b/src/include/daw/state.h
index f98d5ff..72fe2f0 100644
--- a/src/include/daw/state.h
+++ b/src/include/daw/state.h
@@ -6,6 +6,7 @@ extern "C" {
#endif
#include <daw/memory.h>
+#include <daw/window.h>
typedef enum StateType {
STATE_null,
@@ -17,11 +18,12 @@ typedef enum StateType {
extern const char* StateTypeStr[];
-StateType (*State_updateFunc(StateType type))(f64, void*);
+StateType (*State_updateFunc(StateType type))(Window *restrict, void*, f64);
-void State_init(StateType type, memory* mem, void* arg);
+// "mem" is userdefined memory representing the state of their statemachine
+void State_init(StateType type, Window *restrict w, memory* mem, void* arg);
void* State_free(StateType type, memory* mem);
-StateType State_update(StateType type, f64 dt, memory* mem);
+StateType State_update(StateType type, Window *restrict w, memory* mem, f64 dt);
/* Reloads shared object file associated with state */
#ifdef DAW_BUILD_HOTRELOAD
diff --git a/src/state.c b/src/state.c
index b5fcdc3..bc7a89e 100644
--- a/src/state.c
+++ b/src/state.c
@@ -7,7 +7,7 @@
//typedef void state_init_t(void*,void*);
//typedef void* (state_free_t(void*));
-typedef StateType state_update_t(f64, void*);
+typedef StateType state_update_t(Window *restrict, void*, f64);
const char* StateTypeStr[] = {
"null",
@@ -20,9 +20,9 @@ const char* StateTypeStr[] = {
// Setup API for states
#define State(name) \
typedef struct name##_state name##_state; \
- typedef void(state_##name##_init_t)(name##_state*,void*); \
+ typedef void(state_##name##_init_t)(Window *restrict,name##_state*,void*); \
typedef void*(state_##name##_free_t)(name##_state*); \
- typedef StateType(state_##name##_update_t)(f64,name##_state*);
+ typedef StateType(state_##name##_update_t)(Window *restrict,name##_state*,f64);
#include <states/list_of_states.h>
#undef State
@@ -51,11 +51,11 @@ const char* StateTypeStr[] = {
#include <states/all_states.h>
-void State_init(StateType type, memory* mem, void* arg) {
+void State_init(StateType type, Window *restrict w, memory* mem, void* arg) {
switch (type) {
#define State(name) \
case (STATE_##name): { \
- name##_init(memory_allocate(mem, sizeof(name##_state)), arg); \
+ name##_init(w, memory_allocate(mem, sizeof(name##_state)), arg); \
break; \
}
#include <states/list_of_states.h>
@@ -91,7 +91,7 @@ void* State_free(StateType type, memory* mem) {
}
/* Returns the update function of a given state type */
-StateType (*State_updateFunc(StateType type))(f64, void*) {
+StateType (*State_updateFunc(StateType type))(Window *restrict, void*, f64) {
switch (type) {
#ifdef DAW_BUILD_HOTRELOAD
#define State(name) \
@@ -118,12 +118,12 @@ StateType (*State_updateFunc(StateType type))(f64, void*) {
return NULL;
}
-StateType State_update(StateType type, f64 dt, memory* mem) {
+StateType State_update(StateType type, Window *restrict w, memory* mem, f64 dt) {
StateType next_state = STATE_null;
switch (type) {
#define State(name) \
case (STATE_##name): { \
- next_state = name##_update(dt, mem->data); \
+ next_state = name##_update(w, mem->data, dt); \
break; \
}
#include <states/list_of_states.h>