twn_input: singleton rework, twn_control.h and fixes
This commit is contained in:
@ -19,44 +19,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();
|
||||
}
|
||||
|
||||
|
@ -17,22 +17,22 @@ static void update_timers(Player *player) {
|
||||
}
|
||||
|
||||
|
||||
static void input_move(InputState *input, Player *player) {
|
||||
static void input_move(Player *player) {
|
||||
/* apply horizontal damping when the player stops moving */
|
||||
/* in other words, make it decelerate to a standstill */
|
||||
if (!input_is_action_pressed(input, "player_left") &&
|
||||
!input_is_action_pressed(input, "player_right"))
|
||||
if (!input_is_action_pressed("player_left") &&
|
||||
!input_is_action_pressed("player_right"))
|
||||
{
|
||||
player->dx *= player->horizontal_damping;
|
||||
}
|
||||
|
||||
int input_dir = 0;
|
||||
if (input_is_action_pressed(input, "player_left"))
|
||||
if (input_is_action_pressed("player_left"))
|
||||
input_dir = -1;
|
||||
if (input_is_action_pressed(input, "player_right"))
|
||||
if (input_is_action_pressed("player_right"))
|
||||
input_dir = 1;
|
||||
if (input_is_action_pressed(input, "player_left") &&
|
||||
input_is_action_pressed(input, "player_right"))
|
||||
if (input_is_action_pressed("player_left") &&
|
||||
input_is_action_pressed("player_right"))
|
||||
input_dir = 0;
|
||||
|
||||
player->dx += (float)input_dir * player->run_horizontal_speed;
|
||||
@ -53,10 +53,10 @@ static void jump(Player *player) {
|
||||
}
|
||||
|
||||
|
||||
static void input_jump(InputState *input, Player *player) {
|
||||
static void input_jump(Player *player) {
|
||||
player->current_gravity_multiplier = player->jump_default_multiplier;
|
||||
|
||||
if (input_is_action_just_pressed(input, "player_jump")) {
|
||||
if (input_is_action_just_pressed("player_jump")) {
|
||||
player->jump_air_timer = 0;
|
||||
player->jump_buffer_timer = player->jump_buffer_ticks;
|
||||
|
||||
@ -65,7 +65,7 @@ static void input_jump(InputState *input, Player *player) {
|
||||
}
|
||||
}
|
||||
|
||||
if (input_is_action_pressed(input, "player_jump")) {
|
||||
if (input_is_action_pressed("player_jump")) {
|
||||
if (player->action != PLAYER_ACTION_GROUND && player->jump_air_timer > 0) {
|
||||
player->current_gravity_multiplier = player->jump_boosted_multiplier;
|
||||
player->dy += player->jump_force_increase;
|
||||
@ -284,8 +284,8 @@ void player_destroy(Player *player) {
|
||||
void player_calc(Player *player) {
|
||||
update_timers(player);
|
||||
|
||||
input_move(&ctx.input, player);
|
||||
input_jump(&ctx.input, player);
|
||||
input_move(player);
|
||||
input_jump(player);
|
||||
|
||||
player->rect.x += player->dx;
|
||||
update_collider_x(player);
|
||||
|
@ -16,22 +16,22 @@ 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;
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,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