diff --git a/src/base/base_entry_point.c b/src/base/base_entry_point.c index 68d3440..84bb0a7 100644 --- a/src/base/base_entry_point.c +++ b/src/base/base_entry_point.c @@ -1 +1,7 @@ -internal void main_thread_entry_point(void) { ThreadNameF("[main thread]"); } +internal void main_thread_entry_point(void) { + ThreadNameF("[main thread]"); + +#if defined(OS_GFX_H) + os_gfx_init(); +#endif +} diff --git a/src/goff/goff.c b/src/goff/goff.c new file mode 100644 index 0000000..f0c5e37 --- /dev/null +++ b/src/goff/goff.c @@ -0,0 +1,20 @@ +internal void update_and_render(OS_Handle repaint_window_handle) { + Temp scratch = scratch_begin(0, 0); + + // pick target hz + f32 target_hz = os_get_gfx_info()->default_referesh_rate; + + // Target HZ -> delta time + f32 dt = 1.f / target_hz; + + // Get events from OS + OS_EventList events = {0}; + if (os_handle_match(repaint_window_handle, os_handle_zero())) { + events = os_get_events(scratch.arena, df_gfx_state->num_frames_requested == 0); + } + + // begin frames + { + df_core_begin(scratch.arena, + } +} diff --git a/src/goff/goff.h b/src/goff/goff.h new file mode 100644 index 0000000..a905b21 --- /dev/null +++ b/src/goff/goff.h @@ -0,0 +1,6 @@ +#ifndef GOFF_H +#define GOFF_H + +internal void update_and_render(OS_HANDLE repaint_window); + +#endif // GOFF_H diff --git a/src/goff/goff_main.c b/src/goff/goff_main.c index b85c0a8..f5dd6ed 100644 --- a/src/goff/goff_main.c +++ b/src/goff/goff_main.c @@ -10,4 +10,28 @@ // clang-format on -u64 main(int argc, char **argv) { return 0; } +// Entry Point + +internal void entry_point() { + Temp scratch = scratch_begin(0, 0); + + // Setup layers + // { + // df_core_init(); + // df_gfx_init(); +} + +// Main application loop +{ + for (;;) { + + // Update and render frame here + OS_Handle repaint_window = {0}; + update_and_render(repaint_window); + + // Quit + } +} + +scratch_end(scratch); +} diff --git a/src/os/core/os_core.h b/src/os/core/os_core.h index 9690d4f..5d35c2f 100644 --- a/src/os/core/os_core.h +++ b/src/os/core/os_core.h @@ -11,6 +11,12 @@ struct OS_SystemInfo { String8 machine_name; }; +// Handle types +typedef struct OS_Handle OS_Handle; +struct OS_Handle { + u64 l_u64[1]; +} + // Process Information typedef struct OS_ProcessInfo OS_ProcessInfo; struct OS_ProcessInfo { diff --git a/src/os/gfx/os_gfx.h b/src/os/gfx/os_gfx.h new file mode 100644 index 0000000..3c80983 --- /dev/null +++ b/src/os/gfx/os_gfx.h @@ -0,0 +1,33 @@ +#ifndefine OS_GFX_H +#define OS_GFX_H + +typedef void OS_WindowRepaintFunctionType(OS_Handle window, void *user_data); + +ty + +typedef struct OS_Event OS_Event; +struct OS_Event { + OS_Event *next; + OS_Event *previous; + u64 timestamp_us; + OS_Handle window; + OS_EventKind kind; + OS_EventFlag flags; + OS_Key key; + b32 is_repeat; + b32 right_sided; + u32 character; + u32 repeat_count; + Vec2F32 position; + Vec2F32 delta; + String8List strings; +}; + +typedef struct OS_EventList OS_EventList; +struct OS_EventList { + u64 count; + OS_Event *first; + OS_Event *last; +}; + +#endif // OS_GFX_H diff --git a/src/os/gfx/win32/os_gfx_win32.c b/src/os/gfx/win32/os_gfx_win32.c new file mode 100644 index 0000000..3beaef4 --- /dev/null +++ b/src/os/gfx/win32/os_gfx_win32.c @@ -0,0 +1,4 @@ +internal void os_gfx_init(void) { + Arena *arena = arena_alloc(); + os_w32_gfx_state = +} diff --git a/src/os/gfx/win32/os_gfx_win32.h b/src/os/gfx/win32/os_gfx_win32.h new file mode 100644 index 0000000..9158298 --- /dev/null +++ b/src/os/gfx/win32/os_gfx_win32.h @@ -0,0 +1,51 @@ +#ifndef OS_GFX_WIN32_H +#define OS_GFX_WIN32_H + +// Windows +typedef struct OS_W32_Window OS_W32_Window; +struct OS_W32_Window { + OS_W32_Window *next; + OS_W32_Window *prev; + HWND *hwnd; + WINDOWPLACEMENT last_window_placement; + OS_WindowRepaintFunctionType *repaint; + void *repaint_user_data; + f32 dpi; + b32 first_paint_done; + b32 maximized; + Arena *pain_arena; +}; + +// Global State +typedef struct OS_W32_GfxState OS_W32_GfxState; +struct OS_W32_GfxState { + Arena *arena; + u32 gfx_thread_id; + HINSTANCE hInstance; + HCURSOR hCursor; + OS_GfxInfo gfx_info; + OS_W32_Window *first_window; + OS_W32_Window *last_window; + OS_W32_Window *free_window; + OS_KEY key_from_vkey_table[256]; +}; + +// Globals +global OS_W32_GfxState *os_w32_gfx_state = 0; +global OS_EventList os_w32_event_list = {0}; +global Arena *os_w32_event_arena = 0; +b32 os_w32_resizing = 0; + +// Windows +internal OS_Handle os_w32_handle_from_window(OS_W32_Window *window); +internal OS_W32_Window *os_w32_window_from_handle(OS_Handle window); +internal OS_W32_Window *os_w32_window_from_hwnd(HWND hwnd); +internal HWND os_w32_hwnd_from_window(OS_W32_Window *window); +internal OS_W32_Window *os_w32_window_alloc(void); +internal void os_w32_window_release(OS_W32_Window *window); +internal OS_Event *os_w32_push_event(OS_EventKind kind, OS_W32_Window *window); +internal OS_Key os_w32_os_key_from_vkey(WPARAM vkey); +internal WPARAM os_w32_vkey_from_os_key(OS_Key key); +internal LRESULT os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); + +#endif // OS_GFX_WIN32_H