Separate and improve player movement

This commit is contained in:
2025-11-30 22:45:29 +01:00
parent 4d61b14052
commit b3b6b6c30a
3 changed files with 158 additions and 98 deletions

View File

@@ -97,7 +97,7 @@ const CallbackContext = struct {
cursor_last_ypos: f64,
};
fn keyCallback(window: *glfw.Window, key_code: glfw.Key, _: c_int, action: glfw.Action, mods: glfw.Mods) callconv(.c) void {
fn keyCallback(window: *glfw.Window, key_code: glfw.Key, _: c_int, action: glfw.Action, _: glfw.Mods) callconv(.c) void {
const maybe_ctx = window.getUserPointer(CallbackContext);
if (key_code == .escape and action == .press and (window.getInputMode(.cursor) catch .normal) == .disabled) {
@@ -114,8 +114,8 @@ fn keyCallback(window: *glfw.Window, key_code: glfw.Key, _: c_int, action: glfw.
if (maybe_ctx) |ctx| {
if (ctx.focused) {
switch (action) {
.press => ctx.game.onKeyDown(key_code, mods),
.release => ctx.game.onKeyUp(key_code, mods),
.press => ctx.game.onKeyDown(key_code),
.release => ctx.game.onKeyUp(key_code),
.repeat => {},
}
}
@@ -135,7 +135,7 @@ fn cursorPosCallback(window: *glfw.Window, cursor_xpos: f64, cursor_ypos: f64) c
}
}
fn mouseButtonCallback(window: *glfw.Window, button: glfw.MouseButton, action: glfw.Action, mods: glfw.Mods) callconv(.c) void {
fn mouseButtonCallback(window: *glfw.Window, button: glfw.MouseButton, action: glfw.Action, _: glfw.Mods) callconv(.c) void {
const maybe_ctx = window.getUserPointer(CallbackContext);
if (button == .left and action == .press and (window.getInputMode(.cursor) catch .normal) == .normal) {
@@ -151,8 +151,8 @@ fn mouseButtonCallback(window: *glfw.Window, button: glfw.MouseButton, action: g
if (maybe_ctx) |ctx| {
if (ctx.focused) {
switch (action) {
.press => ctx.game.onMouseDown(button, mods),
.release => ctx.game.onMouseUp(button, mods),
.press => ctx.game.onMouseDown(button),
.release => ctx.game.onMouseUp(button),
.repeat => {},
}
}