add args to cursor clip set, stop rounding screen size to even number
This commit is contained in:
parent
744a6f8d65
commit
8b5b32ba76
@ -5,6 +5,7 @@
|
||||
* system. */
|
||||
#define RESOURCES_EMBEDDED !(DEVELOPER)
|
||||
|
||||
#define ASPECT_RATIO (16.0 / 9.0)
|
||||
#define PIXELS_PER_UNIT 256
|
||||
|
||||
#define GAME_FPS 30
|
||||
|
||||
@ -468,8 +468,8 @@ INTERNAL void game_update(void)
|
||||
ent->camera_target_xform.og = target_pos;
|
||||
#else
|
||||
/* "Look" style camera */
|
||||
f32 ratio_x = 0.33f;
|
||||
f32 ratio_y = 0.33f;
|
||||
f32 ratio_x = 0.33f;
|
||||
struct v2 camera_focus_dir = v2_mul_v2(follow->player_aim, V2(ratio_x, ratio_y));
|
||||
struct v2 camera_focus_pos = v2_add(follow->world_xform.og, camera_focus_dir);
|
||||
ent->camera_target_xform.og = camera_focus_pos;
|
||||
|
||||
@ -293,8 +293,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);
|
||||
void sys_window_cursor_enable_clip(struct sys_window *sys_window, struct rect bounds);
|
||||
void sys_window_cursor_disable_clip(struct sys_window *sys_window);
|
||||
|
||||
/* ========================== *
|
||||
* Mutex
|
||||
|
||||
@ -37,8 +37,8 @@ enum win32_window_cursor_set_flag {
|
||||
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
|
||||
WIN32_WINDOW_CURSOR_SET_FLAG_ENABLE_CLIP = 0X8,
|
||||
WIN32_WINDOW_CURSOR_SET_FLAG_DISABLE_CLIP = 0X10
|
||||
};
|
||||
|
||||
struct win32_window {
|
||||
@ -61,6 +61,7 @@ struct win32_window {
|
||||
|
||||
u32 cursor_set_flags;
|
||||
struct v2 cursor_set_position;
|
||||
struct rect cursor_clip_bounds;
|
||||
|
||||
b32 event_thread_shutdown;
|
||||
struct sys_thread event_thread;
|
||||
@ -565,17 +566,6 @@ INTERNAL void window_thread_entry_point(void *arg)
|
||||
MSG msg = {0};
|
||||
GetMessage(&msg, 0, 0, 0);
|
||||
|
||||
switch (msg.message) {
|
||||
case WM_QUIT: {
|
||||
win32_window_process_event(window, (struct sys_event) { .kind = SYS_EVENT_KIND_QUIT });
|
||||
} break;
|
||||
|
||||
default: {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
} break;
|
||||
}
|
||||
|
||||
/* Update cursor */
|
||||
if (GetFocus() == window->hwnd) {
|
||||
u32 cursor_flags = window->cursor_set_flags;
|
||||
@ -599,23 +589,38 @@ INTERNAL void window_thread_entry_point(void *arg)
|
||||
}
|
||||
|
||||
/* Stop keep in window */
|
||||
if (cursor_flags & WIN32_WINDOW_CURSOR_SET_FLAG_DISABLE_KEEP_IN_WINDOW) {
|
||||
if (cursor_flags & WIN32_WINDOW_CURSOR_SET_FLAG_DISABLE_CLIP) {
|
||||
ClipCursor(NULL);
|
||||
}
|
||||
|
||||
/* Start keep in window */
|
||||
if (cursor_flags & WIN32_WINDOW_CURSOR_SET_FLAG_ENABLE_KEEP_IN_WINDOW) {
|
||||
/* Clip cursor in window window */
|
||||
if (cursor_flags & WIN32_WINDOW_CURSOR_SET_FLAG_ENABLE_CLIP) {
|
||||
i32 left = window->x + math_round(window->cursor_clip_bounds.x);
|
||||
i32 right = left + math_round(window->cursor_clip_bounds.width);
|
||||
i32 top = window->y + math_round(window->cursor_clip_bounds.y);
|
||||
i32 bottom = top + math_round(window->cursor_clip_bounds.height);
|
||||
RECT clip = {
|
||||
.left = window->x,
|
||||
.right = window->x + window->width,
|
||||
.top = window->y,
|
||||
.bottom = window->y + window->height
|
||||
.left = clamp_i32(left, window->x, window->x + window->width),
|
||||
.right = clamp_i32(right, window->x, window->x + window->width),
|
||||
.top = clamp_i32(top, window->y, window->y + window->height),
|
||||
.bottom = clamp_i32(bottom, window->y, window->y + window->height)
|
||||
};
|
||||
ClipCursor(&clip);
|
||||
}
|
||||
|
||||
window->cursor_set_flags = 0;
|
||||
}
|
||||
|
||||
switch (msg.message) {
|
||||
case WM_QUIT: {
|
||||
win32_window_process_event(window, (struct sys_event) { .kind = SYS_EVENT_KIND_QUIT });
|
||||
} break;
|
||||
|
||||
default: {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1115,17 +1120,18 @@ 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)
|
||||
void sys_window_cursor_enable_clip(struct sys_window *sys_window, struct rect bounds)
|
||||
{
|
||||
struct win32_window *window = (struct win32_window *)sys_window->handle;
|
||||
window->cursor_set_flags |= WIN32_WINDOW_CURSOR_SET_FLAG_ENABLE_KEEP_IN_WINDOW;
|
||||
window->cursor_clip_bounds = bounds;
|
||||
window->cursor_set_flags |= WIN32_WINDOW_CURSOR_SET_FLAG_ENABLE_CLIP;
|
||||
win32_window_wake(window);
|
||||
}
|
||||
|
||||
void sys_window_cursor_disable_keep_in_window(struct sys_window *sys_window)
|
||||
void sys_window_cursor_disable_clip(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;
|
||||
window->cursor_set_flags |= WIN32_WINDOW_CURSOR_SET_FLAG_DISABLE_CLIP;
|
||||
win32_window_wake(window);
|
||||
}
|
||||
|
||||
|
||||
15
src/user.c
15
src/user.c
@ -343,12 +343,6 @@ INTERNAL void user_update(void)
|
||||
|
||||
/* Get screen dimensions */
|
||||
L.screen_size = sys_window_get_size(L.window);
|
||||
/* Make screen_size an even number */
|
||||
L.screen_size = V2(math_round(L.screen_size.x), math_round(L.screen_size.y));
|
||||
L.screen_size = V2(
|
||||
math_round(L.screen_size.x) % 2 == 0 ? L.screen_size.x : L.screen_size.x + 1,
|
||||
math_round(L.screen_size.y) % 2 == 0 ? L.screen_size.y : L.screen_size.y + 1
|
||||
);
|
||||
L.screen_center = v2_mul(L.screen_size, 0.5);
|
||||
|
||||
/* ========================== *
|
||||
@ -533,7 +527,7 @@ INTERNAL void user_update(void)
|
||||
}
|
||||
|
||||
if (L.debug_camera) {
|
||||
sys_window_cursor_disable_keep_in_window(L.window);
|
||||
sys_window_cursor_disable_clip(L.window);
|
||||
sys_window_cursor_show(L.window);
|
||||
|
||||
/* Pan view */
|
||||
@ -575,7 +569,7 @@ INTERNAL void user_update(void)
|
||||
} else {
|
||||
/* Keep cursor invisible and in screen */
|
||||
sys_window_cursor_hide(L.window);
|
||||
sys_window_cursor_enable_keep_in_window(L.window);
|
||||
sys_window_cursor_enable_clip(L.window, RECT(0, 0, L.screen_size.x, L.screen_size.y));
|
||||
|
||||
struct v2 center = active_camera->world_xform.og;
|
||||
f32 rot = xform_get_rotation(active_camera->world_xform);
|
||||
@ -852,12 +846,11 @@ INTERNAL void user_update(void)
|
||||
}
|
||||
|
||||
/* Queue cmd */
|
||||
struct game_cmd movement_cmd = (struct game_cmd) {
|
||||
queue_game_cmd(&cmd_list, (struct game_cmd) {
|
||||
.kind = GAME_CMD_KIND_PLAYER_MOVE,
|
||||
.move_dir = input_move_dir,
|
||||
.aim = input_aim
|
||||
};
|
||||
queue_game_cmd(&cmd_list, movement_cmd);
|
||||
});
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user