twn_input: singleton rework, twn_control.h and fixes
This commit is contained in:
@ -20,44 +20,44 @@ void game_tick(void) {
|
||||
state->scene = title_scene(state);
|
||||
}
|
||||
|
||||
input_add_action(&ctx.input, "debug_toggle");
|
||||
input_bind_action_scancode(&ctx.input, "debug_toggle", SCANCODE_BACKSPACE);
|
||||
input_add_action("debug_toggle");
|
||||
input_bind_action_control("debug_toggle", CONTROL_BACKSPACE);
|
||||
|
||||
input_add_action(&ctx.input, "debug_dump_atlases");
|
||||
input_bind_action_scancode(&ctx.input, "debug_dump_atlases", SCANCODE_HOME);
|
||||
input_add_action("debug_dump_atlases");
|
||||
input_bind_action_control("debug_dump_atlases", CONTROL_HOME);
|
||||
|
||||
input_add_action(&ctx.input, "player_left");
|
||||
input_bind_action_scancode(&ctx.input, "player_left", SCANCODE_A);
|
||||
input_add_action("player_left");
|
||||
input_bind_action_control("player_left", CONTROL_A);
|
||||
|
||||
input_add_action(&ctx.input, "player_right");
|
||||
input_bind_action_scancode(&ctx.input, "player_right", SCANCODE_D);
|
||||
input_add_action("player_right");
|
||||
input_bind_action_control("player_right", CONTROL_D);
|
||||
|
||||
input_add_action(&ctx.input, "player_forward");
|
||||
input_bind_action_scancode(&ctx.input, "player_forward", SCANCODE_W);
|
||||
input_add_action("player_forward");
|
||||
input_bind_action_control("player_forward", CONTROL_W);
|
||||
|
||||
input_add_action(&ctx.input, "player_backward");
|
||||
input_bind_action_scancode(&ctx.input, "player_backward", SCANCODE_S);
|
||||
input_add_action("player_backward");
|
||||
input_bind_action_control("player_backward", CONTROL_S);
|
||||
|
||||
input_add_action(&ctx.input, "player_jump");
|
||||
input_bind_action_scancode(&ctx.input, "player_jump", SCANCODE_SPACE);
|
||||
input_add_action("player_jump");
|
||||
input_bind_action_control("player_jump", CONTROL_SPACE);
|
||||
|
||||
input_add_action(&ctx.input, "player_run");
|
||||
input_bind_action_scancode(&ctx.input, "player_run", SCANCODE_LSHIFT);
|
||||
input_add_action("player_run");
|
||||
input_bind_action_control("player_run", CONTROL_LSHIFT);
|
||||
|
||||
input_add_action(&ctx.input, "ui_accept");
|
||||
input_bind_action_scancode(&ctx.input, "ui_accept", SCANCODE_RETURN);
|
||||
input_add_action("ui_accept");
|
||||
input_bind_action_control("ui_accept", CONTROL_RETURN);
|
||||
|
||||
input_add_action(&ctx.input, "mouse_capture_toggle");
|
||||
input_bind_action_scancode(&ctx.input, "mouse_capture_toggle", SCANCODE_ESCAPE);
|
||||
input_add_action("mouse_capture_toggle");
|
||||
input_bind_action_control("mouse_capture_toggle", CONTROL_ESCAPE);
|
||||
}
|
||||
|
||||
State *state = ctx.udata;
|
||||
|
||||
if (input_is_action_just_pressed(&ctx.input, "debug_toggle")) {
|
||||
if (input_is_action_just_pressed("debug_toggle")) {
|
||||
ctx.debug = !ctx.debug;
|
||||
}
|
||||
|
||||
if (input_is_action_just_pressed(&ctx.input, "debug_dump_atlases")) {
|
||||
if (input_is_action_just_pressed("debug_dump_atlases")) {
|
||||
textures_dump_atlases();
|
||||
}
|
||||
|
||||
|
@ -15,10 +15,10 @@
|
||||
static void ingame_tick(State *state) {
|
||||
SceneIngame *scn = (SceneIngame *)state->scene;
|
||||
|
||||
if (input_is_mouse_captured(&ctx.input)) {
|
||||
if (input_is_mouse_captured()) {
|
||||
const float sensitivity = 0.6f; /* TODO: put this in a better place */
|
||||
scn->yaw += (float)ctx.input.mouse_relative_position.x * sensitivity;
|
||||
scn->pitch -= (float)ctx.input.mouse_relative_position.y * sensitivity;
|
||||
scn->yaw += (float)ctx.mouse_relative_position.x * sensitivity;
|
||||
scn->pitch -= (float)ctx.mouse_relative_position.y * sensitivity;
|
||||
scn->pitch = clampf(scn->pitch, -89.0f, 89.0f);
|
||||
|
||||
const float yaw_rad = scn->yaw * (float)DEG2RAD;
|
||||
@ -33,27 +33,27 @@ static void ingame_tick(State *state) {
|
||||
|
||||
const Vec3 right = m_vec_norm(m_vec_cross(scn->cam.target, scn->cam.up));
|
||||
const float speed = 0.04f; /* TODO: put this in a better place */
|
||||
if (input_is_action_pressed(&ctx.input, "player_left"))
|
||||
if (input_is_action_pressed("player_left"))
|
||||
scn->cam.pos = vec3_sub(scn->cam.pos, m_vec_scale(right, speed));
|
||||
|
||||
if (input_is_action_pressed(&ctx.input, "player_right"))
|
||||
if (input_is_action_pressed("player_right"))
|
||||
scn->cam.pos = vec3_add(scn->cam.pos, m_vec_scale(right, speed));
|
||||
|
||||
if (input_is_action_pressed(&ctx.input, "player_forward"))
|
||||
if (input_is_action_pressed("player_forward"))
|
||||
scn->cam.pos = vec3_add(scn->cam.pos, m_vec_scale(scn->cam.target, speed));
|
||||
|
||||
if (input_is_action_pressed(&ctx.input, "player_backward"))
|
||||
if (input_is_action_pressed("player_backward"))
|
||||
scn->cam.pos = vec3_sub(scn->cam.pos, m_vec_scale(scn->cam.target, speed));
|
||||
|
||||
if (input_is_action_pressed(&ctx.input, "player_jump"))
|
||||
if (input_is_action_pressed("player_jump"))
|
||||
scn->cam.pos.y += speed;
|
||||
|
||||
if (input_is_action_pressed(&ctx.input, "player_run"))
|
||||
if (input_is_action_pressed("player_run"))
|
||||
scn->cam.pos.y -= speed;
|
||||
|
||||
/* toggle mouse capture with end key */
|
||||
if (input_is_action_just_pressed(&ctx.input, "mouse_capture_toggle")) {
|
||||
input_set_mouse_captured(&ctx.input, !input_is_mouse_captured(&ctx.input));
|
||||
if (input_is_action_just_pressed("mouse_capture_toggle")) {
|
||||
input_set_mouse_captured(!input_is_mouse_captured());
|
||||
}
|
||||
|
||||
draw_camera(&scn->cam);
|
||||
@ -111,7 +111,7 @@ Scene *ingame_scene(State *state) {
|
||||
m_opt(channel, "soundtrack"),
|
||||
m_opt(repeat, true));
|
||||
|
||||
input_set_mouse_captured(&ctx.input, true);
|
||||
input_set_mouse_captured(true);
|
||||
|
||||
return (Scene *)new_scene;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ static void title_tick(State *state) {
|
||||
SceneTitle *scn = (SceneTitle *)state->scene;
|
||||
(void)scn;
|
||||
|
||||
if (input_is_action_just_pressed(&state->ctx->input, "ui_accept")) {
|
||||
if (input_is_action_just_pressed("ui_accept")) {
|
||||
switch_to(state, ingame_scene);
|
||||
return;
|
||||
}
|
||||
|
Reference in New Issue
Block a user