rework input to be in line with rendering semantics
This commit is contained in:
@ -19,40 +19,13 @@ void game_tick(void) {
|
||||
state->ctx = &ctx;
|
||||
state->scene = title_scene(state);
|
||||
}
|
||||
|
||||
input_add_action("debug_toggle");
|
||||
input_bind_action_control("debug_toggle", CONTROL_BACKSPACE);
|
||||
|
||||
input_add_action("debug_dump_atlases");
|
||||
input_bind_action_control("debug_dump_atlases", CONTROL_HOME);
|
||||
|
||||
input_add_action("player_left");
|
||||
input_bind_action_control("player_left", CONTROL_A);
|
||||
|
||||
input_add_action("player_right");
|
||||
input_bind_action_control("player_right", CONTROL_D);
|
||||
|
||||
input_add_action("player_forward");
|
||||
input_bind_action_control("player_forward", CONTROL_W);
|
||||
|
||||
input_add_action("player_backward");
|
||||
input_bind_action_control("player_backward", CONTROL_S);
|
||||
|
||||
input_add_action("player_jump");
|
||||
input_bind_action_control("player_jump", CONTROL_SPACE);
|
||||
|
||||
input_add_action("player_run");
|
||||
input_bind_action_control("player_run", CONTROL_LSHIFT);
|
||||
|
||||
input_add_action("ui_accept");
|
||||
input_bind_action_control("ui_accept", CONTROL_RETURN);
|
||||
|
||||
input_add_action("mouse_capture_toggle");
|
||||
input_bind_action_control("mouse_capture_toggle", CONTROL_ESCAPE);
|
||||
}
|
||||
|
||||
State *state = ctx.udata;
|
||||
|
||||
input_bind_action_control("debug_toggle", CONTROL_BACKSPACE);
|
||||
input_bind_action_control("debug_dump_atlases", CONTROL_HOME);
|
||||
|
||||
if (input_is_action_just_pressed("debug_toggle")) {
|
||||
ctx.debug = !ctx.debug;
|
||||
}
|
||||
|
@ -15,7 +15,15 @@
|
||||
static void ingame_tick(State *state) {
|
||||
SceneIngame *scn = (SceneIngame *)state->scene;
|
||||
|
||||
if (input_is_mouse_captured()) {
|
||||
input_bind_action_control("player_left", CONTROL_A);
|
||||
input_bind_action_control("player_right", CONTROL_D);
|
||||
input_bind_action_control("player_forward", CONTROL_W);
|
||||
input_bind_action_control("player_backward", CONTROL_S);
|
||||
input_bind_action_control("player_jump", CONTROL_SPACE);
|
||||
input_bind_action_control("player_run", CONTROL_LSHIFT);
|
||||
input_bind_action_control("mouse_capture_toggle", CONTROL_ESCAPE);
|
||||
|
||||
if (scn->mouse_captured) {
|
||||
const float sensitivity = 0.6f; /* TODO: put this in a better place */
|
||||
scn->yaw += (float)ctx.mouse_movement.x * sensitivity;
|
||||
scn->pitch -= (float)ctx.mouse_movement.y * sensitivity;
|
||||
@ -52,9 +60,10 @@ static void ingame_tick(State *state) {
|
||||
scn->cam.pos.y -= speed;
|
||||
|
||||
/* toggle mouse capture with end key */
|
||||
if (input_is_action_just_pressed("mouse_capture_toggle")) {
|
||||
input_set_mouse_captured(!input_is_mouse_captured());
|
||||
}
|
||||
if (input_is_action_just_pressed("mouse_capture_toggle"))
|
||||
scn->mouse_captured = !scn->mouse_captured;
|
||||
|
||||
input_set_mouse_captured(scn->mouse_captured);
|
||||
|
||||
draw_camera(&scn->cam);
|
||||
|
||||
@ -106,6 +115,7 @@ Scene *ingame_scene(State *state) {
|
||||
new_scene->base.end = ingame_end;
|
||||
|
||||
new_scene->cam = (Camera){ .pos = { 32, 0, 1 }, .up = { 0, 1, 0 }, .fov = (float)M_PI_2 };
|
||||
new_scene->mouse_captured = true;
|
||||
|
||||
m_audio(m_set(path, "music/mod65.xm"),
|
||||
m_opt(channel, "soundtrack"),
|
||||
|
@ -6,6 +6,8 @@
|
||||
#include "../state.h"
|
||||
#include "scene.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
typedef struct SceneIngame {
|
||||
Scene base;
|
||||
@ -16,6 +18,8 @@ typedef struct SceneIngame {
|
||||
float yaw;
|
||||
float pitch;
|
||||
float roll;
|
||||
|
||||
bool mouse_captured;
|
||||
} SceneIngame;
|
||||
|
||||
|
||||
|
@ -11,6 +11,8 @@ static void title_tick(State *state) {
|
||||
SceneTitle *scn = (SceneTitle *)state->scene;
|
||||
(void)scn;
|
||||
|
||||
input_bind_action_control("ui_accept", CONTROL_RETURN);
|
||||
|
||||
if (input_is_action_just_pressed("ui_accept")) {
|
||||
switch_to(state, ingame_scene);
|
||||
return;
|
||||
|
Reference in New Issue
Block a user