formatting
This commit is contained in:
parent
a5582f098f
commit
070fb5427a
390
src/sys.h
390
src/sys.h
@ -3,29 +3,6 @@
|
|||||||
|
|
||||||
struct snc_counter;
|
struct snc_counter;
|
||||||
|
|
||||||
/* ========================== *
|
|
||||||
* Exit
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
|
|
||||||
#define SYS_EXIT_FUNC(name) void name(void)
|
|
||||||
typedef SYS_EXIT_FUNC(sys_exit_func);
|
|
||||||
|
|
||||||
/* Registers a function to be called during graceful shutdown (in reverse order) */
|
|
||||||
void sys_on_exit(sys_exit_func *func);
|
|
||||||
|
|
||||||
/* Signals the program to shut down gracefully and run exit callbacks */
|
|
||||||
void sys_exit(void);
|
|
||||||
|
|
||||||
/* Forcefully exits the program and displays `msg` to the user */
|
|
||||||
void sys_panic(struct string msg);
|
|
||||||
|
|
||||||
/* ========================== *
|
|
||||||
* Scheduler
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
i64 sys_current_scheduler_period_ns(void);
|
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Wait
|
* Wait
|
||||||
* ========================== */
|
* ========================== */
|
||||||
@ -95,176 +72,6 @@ struct sys_scratch_ctx {
|
|||||||
|
|
||||||
struct sys_scratch_ctx *sys_scratch_ctx_from_fiber_id(i16 fiber_id);
|
struct sys_scratch_ctx *sys_scratch_ctx_from_fiber_id(i16 fiber_id);
|
||||||
|
|
||||||
/* ========================== *
|
|
||||||
* App entry point
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
/* Must be defined by app */
|
|
||||||
|
|
||||||
void sys_app_startup(struct string args_str);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ========================== *
|
|
||||||
* Events
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
enum sys_event_kind {
|
|
||||||
SYS_EVENT_KIND_NONE,
|
|
||||||
|
|
||||||
SYS_EVENT_KIND_BUTTON_DOWN,
|
|
||||||
SYS_EVENT_KIND_BUTTON_UP,
|
|
||||||
SYS_EVENT_KIND_CURSOR_MOVE,
|
|
||||||
SYS_EVENT_KIND_MOUSE_MOVE,
|
|
||||||
SYS_EVENT_KIND_TEXT,
|
|
||||||
SYS_EVENT_KIND_QUIT,
|
|
||||||
|
|
||||||
SYS_EVENT_KIND_COUNT
|
|
||||||
};
|
|
||||||
|
|
||||||
enum sys_btn {
|
|
||||||
SYS_BTN_NONE,
|
|
||||||
|
|
||||||
SYS_BTN_M1,
|
|
||||||
SYS_BTN_M2,
|
|
||||||
SYS_BTN_M3,
|
|
||||||
SYS_BTN_M4,
|
|
||||||
SYS_BTN_M5,
|
|
||||||
|
|
||||||
SYS_BTN_MWHEELUP,
|
|
||||||
SYS_BTN_MWHEELDOWN,
|
|
||||||
|
|
||||||
SYS_BTN_ESC,
|
|
||||||
SYS_BTN_F1,
|
|
||||||
SYS_BTN_F2,
|
|
||||||
SYS_BTN_F3,
|
|
||||||
SYS_BTN_F4,
|
|
||||||
SYS_BTN_F5,
|
|
||||||
SYS_BTN_F6,
|
|
||||||
SYS_BTN_F7,
|
|
||||||
SYS_BTN_F8,
|
|
||||||
SYS_BTN_F9,
|
|
||||||
SYS_BTN_F10,
|
|
||||||
SYS_BTN_F11,
|
|
||||||
SYS_BTN_F12,
|
|
||||||
SYS_BTN_F13,
|
|
||||||
SYS_BTN_F14,
|
|
||||||
SYS_BTN_F15,
|
|
||||||
SYS_BTN_F16,
|
|
||||||
SYS_BTN_F17,
|
|
||||||
SYS_BTN_F18,
|
|
||||||
SYS_BTN_F19,
|
|
||||||
SYS_BTN_F20,
|
|
||||||
SYS_BTN_F21,
|
|
||||||
SYS_BTN_F22,
|
|
||||||
SYS_BTN_F23,
|
|
||||||
SYS_BTN_F24,
|
|
||||||
SYS_BTN_GRAVE_ACCENT,
|
|
||||||
SYS_BTN_0,
|
|
||||||
SYS_BTN_1,
|
|
||||||
SYS_BTN_2,
|
|
||||||
SYS_BTN_3,
|
|
||||||
SYS_BTN_4,
|
|
||||||
SYS_BTN_5,
|
|
||||||
SYS_BTN_6,
|
|
||||||
SYS_BTN_7,
|
|
||||||
SYS_BTN_8,
|
|
||||||
SYS_BTN_9,
|
|
||||||
SYS_BTN_MINUS,
|
|
||||||
SYS_BTN_EQUAL,
|
|
||||||
SYS_BTN_BACKSPACE,
|
|
||||||
SYS_BTN_DELETE,
|
|
||||||
SYS_BTN_TAB,
|
|
||||||
SYS_BTN_A,
|
|
||||||
SYS_BTN_B,
|
|
||||||
SYS_BTN_C,
|
|
||||||
SYS_BTN_D,
|
|
||||||
SYS_BTN_E,
|
|
||||||
SYS_BTN_F,
|
|
||||||
SYS_BTN_G,
|
|
||||||
SYS_BTN_H,
|
|
||||||
SYS_BTN_I,
|
|
||||||
SYS_BTN_J,
|
|
||||||
SYS_BTN_K,
|
|
||||||
SYS_BTN_L,
|
|
||||||
SYS_BTN_M,
|
|
||||||
SYS_BTN_N,
|
|
||||||
SYS_BTN_O,
|
|
||||||
SYS_BTN_P,
|
|
||||||
SYS_BTN_Q,
|
|
||||||
SYS_BTN_R,
|
|
||||||
SYS_BTN_S,
|
|
||||||
SYS_BTN_T,
|
|
||||||
SYS_BTN_U,
|
|
||||||
SYS_BTN_V,
|
|
||||||
SYS_BTN_W,
|
|
||||||
SYS_BTN_X,
|
|
||||||
SYS_BTN_Y,
|
|
||||||
SYS_BTN_Z,
|
|
||||||
SYS_BTN_SPACE,
|
|
||||||
SYS_BTN_ENTER,
|
|
||||||
SYS_BTN_CTRL,
|
|
||||||
SYS_BTN_SHIFT,
|
|
||||||
SYS_BTN_ALT,
|
|
||||||
SYS_BTN_UP,
|
|
||||||
SYS_BTN_LEFT,
|
|
||||||
SYS_BTN_DOWN,
|
|
||||||
SYS_BTN_RIGHT,
|
|
||||||
SYS_BTN_PAGE_UP,
|
|
||||||
SYS_BTN_PAGE_DOWN,
|
|
||||||
SYS_BTN_HOME,
|
|
||||||
SYS_BTN_END,
|
|
||||||
SYS_BTN_FORWARD_SLASH,
|
|
||||||
SYS_BTN_PERIOD,
|
|
||||||
SYS_BTN_COMMA,
|
|
||||||
SYS_BTN_QUOTE,
|
|
||||||
SYS_BTN_LEFT_BRACKET,
|
|
||||||
SYS_BTN_RIGHT_BRACKET,
|
|
||||||
SYS_BTN_INSERT,
|
|
||||||
SYS_BTN_SEMICOLON,
|
|
||||||
|
|
||||||
SYS_BTN_COUNT
|
|
||||||
};
|
|
||||||
|
|
||||||
struct sys_event {
|
|
||||||
enum sys_event_kind kind;
|
|
||||||
|
|
||||||
/* SYS_EVENT_KIND_BUTTON_DOWN */
|
|
||||||
/* SYS_EVENT_KIND_BUTTON_UP */
|
|
||||||
enum sys_btn button;
|
|
||||||
b32 is_repeat;
|
|
||||||
|
|
||||||
/* SYS_EVENT_KIND_TEXT */
|
|
||||||
u32 text_codepoint;
|
|
||||||
|
|
||||||
/* SYS_EVENT_KIND_CURSOR_MOVE */
|
|
||||||
struct v2 cursor_position;
|
|
||||||
|
|
||||||
/* SYS_EVENT_KIND_MOUSE_MOVE */
|
|
||||||
struct v2 mouse_delta;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct sys_event_array {
|
|
||||||
u64 count;
|
|
||||||
struct sys_event *events;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Memory
|
* Memory
|
||||||
* ========================== */
|
* ========================== */
|
||||||
@ -427,6 +234,150 @@ void sys_watch_wake(struct sys_watch *dw);
|
|||||||
|
|
||||||
struct sys_watch_info_list sys_watch_info_copy(struct arena *arena, struct sys_watch_info_list src);
|
struct sys_watch_info_list sys_watch_info_copy(struct arena *arena, struct sys_watch_info_list src);
|
||||||
|
|
||||||
|
/* ========================== *
|
||||||
|
* Window event
|
||||||
|
* ========================== */
|
||||||
|
|
||||||
|
enum sys_window_event_kind {
|
||||||
|
SYS_EVENT_KIND_NONE,
|
||||||
|
|
||||||
|
SYS_EVENT_KIND_BUTTON_DOWN,
|
||||||
|
SYS_EVENT_KIND_BUTTON_UP,
|
||||||
|
SYS_EVENT_KIND_CURSOR_MOVE,
|
||||||
|
SYS_EVENT_KIND_MOUSE_MOVE,
|
||||||
|
SYS_EVENT_KIND_TEXT,
|
||||||
|
SYS_EVENT_KIND_QUIT,
|
||||||
|
|
||||||
|
SYS_EVENT_KIND_COUNT
|
||||||
|
};
|
||||||
|
|
||||||
|
enum sys_btn {
|
||||||
|
SYS_BTN_NONE,
|
||||||
|
|
||||||
|
SYS_BTN_M1,
|
||||||
|
SYS_BTN_M2,
|
||||||
|
SYS_BTN_M3,
|
||||||
|
SYS_BTN_M4,
|
||||||
|
SYS_BTN_M5,
|
||||||
|
|
||||||
|
SYS_BTN_MWHEELUP,
|
||||||
|
SYS_BTN_MWHEELDOWN,
|
||||||
|
|
||||||
|
SYS_BTN_ESC,
|
||||||
|
SYS_BTN_F1,
|
||||||
|
SYS_BTN_F2,
|
||||||
|
SYS_BTN_F3,
|
||||||
|
SYS_BTN_F4,
|
||||||
|
SYS_BTN_F5,
|
||||||
|
SYS_BTN_F6,
|
||||||
|
SYS_BTN_F7,
|
||||||
|
SYS_BTN_F8,
|
||||||
|
SYS_BTN_F9,
|
||||||
|
SYS_BTN_F10,
|
||||||
|
SYS_BTN_F11,
|
||||||
|
SYS_BTN_F12,
|
||||||
|
SYS_BTN_F13,
|
||||||
|
SYS_BTN_F14,
|
||||||
|
SYS_BTN_F15,
|
||||||
|
SYS_BTN_F16,
|
||||||
|
SYS_BTN_F17,
|
||||||
|
SYS_BTN_F18,
|
||||||
|
SYS_BTN_F19,
|
||||||
|
SYS_BTN_F20,
|
||||||
|
SYS_BTN_F21,
|
||||||
|
SYS_BTN_F22,
|
||||||
|
SYS_BTN_F23,
|
||||||
|
SYS_BTN_F24,
|
||||||
|
SYS_BTN_GRAVE_ACCENT,
|
||||||
|
SYS_BTN_0,
|
||||||
|
SYS_BTN_1,
|
||||||
|
SYS_BTN_2,
|
||||||
|
SYS_BTN_3,
|
||||||
|
SYS_BTN_4,
|
||||||
|
SYS_BTN_5,
|
||||||
|
SYS_BTN_6,
|
||||||
|
SYS_BTN_7,
|
||||||
|
SYS_BTN_8,
|
||||||
|
SYS_BTN_9,
|
||||||
|
SYS_BTN_MINUS,
|
||||||
|
SYS_BTN_EQUAL,
|
||||||
|
SYS_BTN_BACKSPACE,
|
||||||
|
SYS_BTN_DELETE,
|
||||||
|
SYS_BTN_TAB,
|
||||||
|
SYS_BTN_A,
|
||||||
|
SYS_BTN_B,
|
||||||
|
SYS_BTN_C,
|
||||||
|
SYS_BTN_D,
|
||||||
|
SYS_BTN_E,
|
||||||
|
SYS_BTN_F,
|
||||||
|
SYS_BTN_G,
|
||||||
|
SYS_BTN_H,
|
||||||
|
SYS_BTN_I,
|
||||||
|
SYS_BTN_J,
|
||||||
|
SYS_BTN_K,
|
||||||
|
SYS_BTN_L,
|
||||||
|
SYS_BTN_M,
|
||||||
|
SYS_BTN_N,
|
||||||
|
SYS_BTN_O,
|
||||||
|
SYS_BTN_P,
|
||||||
|
SYS_BTN_Q,
|
||||||
|
SYS_BTN_R,
|
||||||
|
SYS_BTN_S,
|
||||||
|
SYS_BTN_T,
|
||||||
|
SYS_BTN_U,
|
||||||
|
SYS_BTN_V,
|
||||||
|
SYS_BTN_W,
|
||||||
|
SYS_BTN_X,
|
||||||
|
SYS_BTN_Y,
|
||||||
|
SYS_BTN_Z,
|
||||||
|
SYS_BTN_SPACE,
|
||||||
|
SYS_BTN_ENTER,
|
||||||
|
SYS_BTN_CTRL,
|
||||||
|
SYS_BTN_SHIFT,
|
||||||
|
SYS_BTN_ALT,
|
||||||
|
SYS_BTN_UP,
|
||||||
|
SYS_BTN_LEFT,
|
||||||
|
SYS_BTN_DOWN,
|
||||||
|
SYS_BTN_RIGHT,
|
||||||
|
SYS_BTN_PAGE_UP,
|
||||||
|
SYS_BTN_PAGE_DOWN,
|
||||||
|
SYS_BTN_HOME,
|
||||||
|
SYS_BTN_END,
|
||||||
|
SYS_BTN_FORWARD_SLASH,
|
||||||
|
SYS_BTN_PERIOD,
|
||||||
|
SYS_BTN_COMMA,
|
||||||
|
SYS_BTN_QUOTE,
|
||||||
|
SYS_BTN_LEFT_BRACKET,
|
||||||
|
SYS_BTN_RIGHT_BRACKET,
|
||||||
|
SYS_BTN_INSERT,
|
||||||
|
SYS_BTN_SEMICOLON,
|
||||||
|
|
||||||
|
SYS_BTN_COUNT
|
||||||
|
};
|
||||||
|
|
||||||
|
struct sys_window_event {
|
||||||
|
enum sys_window_event_kind kind;
|
||||||
|
|
||||||
|
/* SYS_EVENT_KIND_BUTTON_DOWN */
|
||||||
|
/* SYS_EVENT_KIND_BUTTON_UP */
|
||||||
|
enum sys_btn button;
|
||||||
|
b32 is_repeat;
|
||||||
|
|
||||||
|
/* SYS_EVENT_KIND_TEXT */
|
||||||
|
u32 text_codepoint;
|
||||||
|
|
||||||
|
/* SYS_EVENT_KIND_CURSOR_MOVE */
|
||||||
|
struct v2 cursor_position;
|
||||||
|
|
||||||
|
/* SYS_EVENT_KIND_MOUSE_MOVE */
|
||||||
|
struct v2 mouse_delta;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct sys_window_event_array {
|
||||||
|
u64 count;
|
||||||
|
struct sys_window_event *events;
|
||||||
|
};
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Window
|
* Window
|
||||||
* ========================== */
|
* ========================== */
|
||||||
@ -471,7 +422,7 @@ struct sys_window *sys_window_alloc(void);
|
|||||||
|
|
||||||
void sys_window_release(struct sys_window *sys_window);
|
void sys_window_release(struct sys_window *sys_window);
|
||||||
|
|
||||||
struct sys_event_array sys_window_pop_events(struct arena *arena, struct sys_window *sys_window);
|
struct sys_window_event_array sys_window_pop_events(struct arena *arena, struct sys_window *sys_window);
|
||||||
|
|
||||||
void sys_window_update_settings(struct sys_window *sys_window, struct sys_window_settings *settings);
|
void sys_window_update_settings(struct sys_window *sys_window, struct sys_window_settings *settings);
|
||||||
|
|
||||||
@ -496,29 +447,6 @@ void sys_window_cursor_enable_clip(struct sys_window *sys_window, struct rect bo
|
|||||||
|
|
||||||
void sys_window_cursor_disable_clip(struct sys_window *sys_window);
|
void sys_window_cursor_disable_clip(struct sys_window *sys_window);
|
||||||
|
|
||||||
/* ========================== *
|
|
||||||
* Thread
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
#define SYS_THREAD_DEF(name, arg_name) void name(void *arg_name)
|
|
||||||
typedef SYS_THREAD_DEF(sys_thread_func, data);
|
|
||||||
|
|
||||||
/* Creates a new thread running in the supplied `entry_point` */
|
|
||||||
struct sys_thread *sys_thread_alloc(
|
|
||||||
sys_thread_func *entry_point,
|
|
||||||
void *thread_data, /* Passed as arg to `entry_point` */
|
|
||||||
struct string thread_name,
|
|
||||||
i32 profiler_group
|
|
||||||
);
|
|
||||||
|
|
||||||
void sys_thread_wait_release(struct sys_thread *thread);
|
|
||||||
|
|
||||||
b32 sys_thread_try_release(struct sys_thread *thread, f32 timeout_seconds); /* Returns 0 if the thread could not release in specified timeout (e.g. because it is still running) */
|
|
||||||
|
|
||||||
void sys_thread_force_release(struct sys_thread *thread);
|
|
||||||
|
|
||||||
u32 sys_current_thread_id(void);
|
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Address
|
* Address
|
||||||
* ========================== */
|
* ========================== */
|
||||||
@ -583,4 +511,32 @@ void sys_true_rand(struct string b);
|
|||||||
|
|
||||||
u32 sys_num_logical_processors(void);
|
u32 sys_num_logical_processors(void);
|
||||||
|
|
||||||
|
u32 sys_current_thread_id(void);
|
||||||
|
|
||||||
|
i64 sys_current_scheduler_period_ns(void);
|
||||||
|
|
||||||
|
/* ========================== *
|
||||||
|
* Exit
|
||||||
|
* ========================== */
|
||||||
|
|
||||||
|
|
||||||
|
#define SYS_EXIT_FUNC(name) void name(void)
|
||||||
|
typedef SYS_EXIT_FUNC(sys_exit_func);
|
||||||
|
|
||||||
|
/* Registers a function to be called during graceful shutdown (in reverse order) */
|
||||||
|
void sys_on_exit(sys_exit_func *func);
|
||||||
|
|
||||||
|
/* Signals the program to shut down gracefully and run exit callbacks */
|
||||||
|
void sys_exit(void);
|
||||||
|
|
||||||
|
/* Forcefully exits the program and displays `msg` to the user */
|
||||||
|
void sys_panic(struct string msg);
|
||||||
|
|
||||||
|
/* ========================== *
|
||||||
|
* App entry point
|
||||||
|
* ========================== */
|
||||||
|
|
||||||
|
/* Must be defined by app */
|
||||||
|
void sys_app_startup(struct string args_str);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
759
src/sys_win32.c
759
src/sys_win32.c
File diff suppressed because it is too large
Load Diff
@ -93,8 +93,8 @@ GLOBAL struct {
|
|||||||
b32 debug_console;
|
b32 debug_console;
|
||||||
|
|
||||||
/* Window -> user */
|
/* Window -> user */
|
||||||
struct snc_mutex sys_events_mutex;
|
struct snc_mutex sys_window_events_mutex;
|
||||||
struct arena *sys_events_arena;
|
struct arena *sys_window_events_arena;
|
||||||
|
|
||||||
/* User -> local sim */
|
/* User -> local sim */
|
||||||
struct snc_mutex user_sim_cmd_mutex;
|
struct snc_mutex user_sim_cmd_mutex;
|
||||||
@ -695,7 +695,7 @@ INTERNAL void user_update(struct sys_window *window)
|
|||||||
{
|
{
|
||||||
__profn("Process sys events");
|
__profn("Process sys events");
|
||||||
|
|
||||||
struct sys_event_array events = sys_window_pop_events(scratch.arena, window);
|
struct sys_window_event_array events = sys_window_pop_events(scratch.arena, window);
|
||||||
|
|
||||||
/* Reset bind pressed / released states */
|
/* Reset bind pressed / released states */
|
||||||
for (u32 i = 0; i < countof(G.bind_states); ++i) {
|
for (u32 i = 0; i < countof(G.bind_states); ++i) {
|
||||||
@ -705,7 +705,7 @@ INTERNAL void user_update(struct sys_window *window)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (u64 ent_index = 0; ent_index < events.count; ++ent_index) {
|
for (u64 ent_index = 0; ent_index < events.count; ++ent_index) {
|
||||||
struct sys_event *event = &events.events[ent_index];
|
struct sys_window_event *event = &events.events[ent_index];
|
||||||
if (event->kind == SYS_EVENT_KIND_QUIT) {
|
if (event->kind == SYS_EVENT_KIND_QUIT) {
|
||||||
sys_exit();
|
sys_exit();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user