diff --git a/src/config.h b/src/config.h index ad1fd000..5b2ea5ee 100644 --- a/src/config.h +++ b/src/config.h @@ -7,7 +7,7 @@ #define PIXELS_PER_UNIT 256 -#define GAME_FPS 50 +#define GAME_FPS 30 #define USER_FRAME_LIMIT 300 @@ -27,4 +27,4 @@ #define AUDIO_ENABLED 0 #define VSYNC_ENABLED 0 -#define MOUSE_SENSITIVITY 1.5 +#define MOUSE_SENSITIVITY 1 diff --git a/src/sys.h b/src/sys.h index 2be3294a..2dfa9f03 100644 --- a/src/sys.h +++ b/src/sys.h @@ -289,6 +289,8 @@ u64 sys_window_get_internal_handle(struct sys_window *sys_window); void sys_window_cursor_set_pos(struct sys_window *sys_window, struct v2 pos); void sys_window_cursor_show(struct sys_window *sys_window); void sys_window_cursor_hide(struct sys_window *sys_window); +void sys_window_cursor_enable_keep_in_window(struct sys_window *sys_window); +void sys_window_cursor_disable_keep_in_window(struct sys_window *sys_window); /* ========================== * * Mutex diff --git a/src/sys_win32.c b/src/sys_win32.c index 15e8c5ff..834a9ffa 100644 --- a/src/sys_win32.c +++ b/src/sys_win32.c @@ -33,10 +33,12 @@ struct win32_condition_variable { }; enum win32_window_cursor_set_flag { - WIN32_WINDOW_CURSOR_SET_FLAG_NONE = 0x0, - WIN32_WINDOW_CURSOR_SET_FLAG_POSITION = 0x1, - WIN32_WINDOW_CURSOR_SET_FLAG_HIDE = 0x2, - WIN32_WINDOW_CURSOR_SET_FLAG_SHOW = 0x4 + WIN32_WINDOW_CURSOR_SET_FLAG_NONE = 0x0, + WIN32_WINDOW_CURSOR_SET_FLAG_POSITION = 0x1, + WIN32_WINDOW_CURSOR_SET_FLAG_HIDE = 0x2, + WIN32_WINDOW_CURSOR_SET_FLAG_SHOW = 0x4, + WIN32_WINDOW_CURSOR_SET_FLAG_ENABLE_KEEP_IN_WINDOW = 0X8, + WIN32_WINDOW_CURSOR_SET_FLAG_DISABLE_KEEP_IN_WINDOW = 0X10 }; struct win32_window { @@ -597,6 +599,22 @@ INTERNAL void window_thread_entry_point(void *arg) SetCursorPos(p.x, p.y); } + /* Stop keep in window */ + if (cursor_flags & WIN32_WINDOW_CURSOR_SET_FLAG_DISABLE_KEEP_IN_WINDOW) { + ClipCursor(NULL); + } + + /* Start keep in window */ + if (cursor_flags & WIN32_WINDOW_CURSOR_SET_FLAG_ENABLE_KEEP_IN_WINDOW) { + RECT clip = { + .left = window->x, + .right = window->x + window->width, + .top = window->y, + .bottom = window->y + window->height + }; + ClipCursor(&clip); + } + window->cursor_set_flags = 0; } } @@ -865,13 +883,13 @@ INTERNAL LRESULT CALLBACK win32_window_proc(HWND hwnd, UINT msg, WPARAM wparam, case WM_RBUTTONUP: case WM_XBUTTONUP: { ReleaseCapture(); - is_release = 1; + is_release = true; } FALLTHROUGH; case WM_LBUTTONDOWN: case WM_MBUTTONDOWN: case WM_RBUTTONDOWN: case WM_XBUTTONDOWN: { - if(is_release == 0) { + if(!is_release) { SetCapture(hwnd); } @@ -1103,6 +1121,20 @@ void sys_window_cursor_hide(struct sys_window *sys_window) win32_window_wake(window); } +void sys_window_cursor_enable_keep_in_window(struct sys_window *sys_window) +{ + struct win32_window *window = (struct win32_window *)sys_window->handle; + window->cursor_set_flags |= WIN32_WINDOW_CURSOR_SET_FLAG_ENABLE_KEEP_IN_WINDOW; + win32_window_wake(window); +} + +void sys_window_cursor_disable_keep_in_window(struct sys_window *sys_window) +{ + struct win32_window *window = (struct win32_window *)sys_window->handle; + window->cursor_set_flags |= WIN32_WINDOW_CURSOR_SET_FLAG_DISABLE_KEEP_IN_WINDOW; + win32_window_wake(window); +} + /* ========================== * * Mutex * ========================== */ diff --git a/src/ttf_dwrite.cpp b/src/ttf_dwrite.cpp index 8d1b4d62..a59f986e 100644 --- a/src/ttf_dwrite.cpp +++ b/src/ttf_dwrite.cpp @@ -80,7 +80,7 @@ struct ttf_decode_result ttf_decode(struct arena *arena, struct buffer encoded, IDWriteFactory5 *factory = L.factory; - /* TOOD: handle errors */ + /* TODO: handle errors */ HRESULT error = 0; (UNUSED)error; diff --git a/src/user.c b/src/user.c index 0f9b8f56..9c0833d5 100644 --- a/src/user.c +++ b/src/user.c @@ -447,6 +447,7 @@ INTERNAL void user_update(void) /* Update mouse pos */ if (event->kind == SYS_EVENT_KIND_MOUSE_MOVE) { L.screen_mouse = event->mouse_position; + //L.screen_mouse_delta = v2_add(L.screen_mouse_delta, event->mouse_delta); } /* Update mouse delta */ @@ -503,6 +504,7 @@ INTERNAL void user_update(void) if (L.debug_camera) { sys_window_cursor_show(L.window); + sys_window_cursor_disable_keep_in_window(L.window); /* Pan view */ if (L.bind_states[USER_BIND_KIND_PAN].is_held) { @@ -546,9 +548,9 @@ INTERNAL void user_update(void) L.world_view.center = v2_add(L.world_view.center, offset); } } else { - /* Keep cursor invisible at center of screen */ + /* Keep cursor invisible and in screen */ sys_window_cursor_hide(L.window); - sys_window_cursor_set_pos(L.window, L.screen_center); + sys_window_cursor_enable_keep_in_window(L.window); } /* ========================== *