Tiny refactor
This commit is contained in:
@@ -167,14 +167,14 @@ Input_State :: struct {
|
||||
}
|
||||
|
||||
init_input :: () {
|
||||
input = .{};
|
||||
input.has_char = false;
|
||||
engine.input = .{};
|
||||
engine.input.has_char = false;
|
||||
|
||||
init_sdl_input();
|
||||
}
|
||||
|
||||
update_key_state :: (key: Key_Code, down: bool) {
|
||||
using input;
|
||||
using engine.input;
|
||||
flags := keys[key];
|
||||
|
||||
if down {
|
||||
@@ -187,7 +187,7 @@ update_key_state :: (key: Key_Code, down: bool) {
|
||||
|
||||
keys[key] = flags;
|
||||
|
||||
input.last_touched = .KEYBOARD_AND_MOUSE;
|
||||
engine.input.last_touched = .KEYBOARD_AND_MOUSE;
|
||||
}
|
||||
|
||||
update_gamepad_state :: (gamepad: *Gamepad, button: Gamepad_Button, down: bool) {
|
||||
@@ -196,7 +196,7 @@ update_gamepad_state :: (gamepad: *Gamepad, button: Gamepad_Button, down: bool)
|
||||
if down {
|
||||
if !(flags & Key_Flags.DOWN) {
|
||||
flags = Key_Flags.DOWN | Key_Flags.START;
|
||||
input.last_touched = .GAMEPAD;
|
||||
engine.input.last_touched = .GAMEPAD;
|
||||
}
|
||||
} else if flags & Key_Flags.DOWN {
|
||||
flags = Key_Flags.END;
|
||||
@@ -207,11 +207,11 @@ update_gamepad_state :: (gamepad: *Gamepad, button: Gamepad_Button, down: bool)
|
||||
}
|
||||
|
||||
update_input :: () {
|
||||
input.mouse.delta_x = 0.0;
|
||||
input.mouse.delta_y = 0.0;
|
||||
input.mouse.wheel = 0.0;
|
||||
input.has_char = false;
|
||||
remove_all_temp_key_flags(*input);
|
||||
engine.input.mouse.delta_x = 0.0;
|
||||
engine.input.mouse.delta_y = 0.0;
|
||||
engine.input.mouse.wheel = 0.0;
|
||||
engine.input.has_char = false;
|
||||
remove_all_temp_key_flags(*engine.input);
|
||||
|
||||
update_sdl_input();
|
||||
|
||||
@@ -245,11 +245,11 @@ eat_mouse_input :: (using input_state: *Input_State) {
|
||||
}
|
||||
|
||||
eat_key :: (key: Key_Code) {
|
||||
input.keys[key] |= Key_Flags.EATEN;
|
||||
engine.input.keys[key] |= Key_Flags.EATEN;
|
||||
}
|
||||
|
||||
action_down :: (action: Action) -> bool {
|
||||
mapping := input.action_mappings[action];
|
||||
mapping := engine.input.action_mappings[action];
|
||||
for 0..mapping.key_mapping_count-1 {
|
||||
if key_down(mapping.keys[it]) {
|
||||
return true;
|
||||
@@ -266,7 +266,7 @@ action_down :: (action: Action) -> bool {
|
||||
}
|
||||
|
||||
action_pressed :: (action: Action) -> bool {
|
||||
mapping := input.action_mappings[action];
|
||||
mapping := engine.input.action_mappings[action];
|
||||
for 0..mapping.key_mapping_count-1 {
|
||||
if key_pressed(mapping.keys[it]) {
|
||||
return true;
|
||||
@@ -283,7 +283,7 @@ action_pressed :: (action: Action) -> bool {
|
||||
}
|
||||
|
||||
action_up :: (action: Action) -> bool {
|
||||
mapping := input.action_mappings[action];
|
||||
mapping := engine.input.action_mappings[action];
|
||||
for 0..mapping.key_mapping_count-1 {
|
||||
if key_up(mapping.keys[it]) {
|
||||
return true;
|
||||
@@ -300,11 +300,11 @@ action_up :: (action: Action) -> bool {
|
||||
}
|
||||
|
||||
get_mouse_delta_x :: inline () -> float {
|
||||
return input.mouse.delta_x;
|
||||
return engine.input.mouse.delta_x;
|
||||
}
|
||||
|
||||
get_mouse_delta_y :: inline () -> float {
|
||||
return input.mouse.delta_y;
|
||||
return engine.input.mouse.delta_y;
|
||||
}
|
||||
|
||||
get_mouse_delta :: () -> float, float {
|
||||
@@ -312,11 +312,11 @@ get_mouse_delta :: () -> float, float {
|
||||
}
|
||||
|
||||
get_mouse_wheel_input :: () -> float {
|
||||
return input.mouse.wheel;
|
||||
return engine.input.mouse.wheel;
|
||||
}
|
||||
|
||||
get_horizontal_axis :: () -> float {
|
||||
if #complete input.last_touched == {
|
||||
if #complete engine.input.last_touched == {
|
||||
case .KEYBOARD_AND_MOUSE;
|
||||
if key_pressed(.A) || key_pressed(.LEFT) return -1.0;
|
||||
else if key_pressed(.D) || key_pressed(.RIGHT) return 1.0;
|
||||
@@ -324,12 +324,12 @@ get_horizontal_axis :: () -> float {
|
||||
case .GAMEPAD;
|
||||
if gamepad_pressed(0, .DPAD_LEFT) return -1.0;
|
||||
else if gamepad_pressed(0, .DPAD_RIGHT) return 1.0;
|
||||
return input.gamepads[0].left_stick_x;
|
||||
return engine.input.gamepads[0].left_stick_x;
|
||||
}
|
||||
}
|
||||
|
||||
get_vertical_axis :: () -> float {
|
||||
if #complete input.last_touched == {
|
||||
if #complete engine.input.last_touched == {
|
||||
case .KEYBOARD_AND_MOUSE;
|
||||
if key_pressed(.S) || key_pressed(.DOWN) return -1.0;
|
||||
else if key_pressed(.W) || key_pressed(.UP) return 1.0;
|
||||
@@ -337,51 +337,51 @@ get_vertical_axis :: () -> float {
|
||||
case .GAMEPAD;
|
||||
if gamepad_pressed(0, .DPAD_DOWN) return -1.0;
|
||||
else if gamepad_pressed(0, .DPAD_UP) return 1.0;
|
||||
return -input.gamepads[0].left_stick_y;
|
||||
return -engine.input.gamepads[0].left_stick_y;
|
||||
}
|
||||
}
|
||||
|
||||
get_right_horizontal_axis :: () -> float {
|
||||
if #complete input.last_touched == {
|
||||
if #complete engine.input.last_touched == {
|
||||
case .KEYBOARD_AND_MOUSE;
|
||||
return input.mouse.delta_x;
|
||||
return engine.input.mouse.delta_x;
|
||||
case .GAMEPAD;
|
||||
return input.gamepads[0].right_stick_x;
|
||||
return engine.input.gamepads[0].right_stick_x;
|
||||
}
|
||||
}
|
||||
|
||||
get_right_vertical_axis :: () -> float {
|
||||
if #complete input.last_touched == {
|
||||
if #complete engine.input.last_touched == {
|
||||
case .KEYBOARD_AND_MOUSE;
|
||||
return input.mouse.delta_y;
|
||||
return engine.input.mouse.delta_y;
|
||||
case .GAMEPAD;
|
||||
return -input.gamepads[0].right_stick_y;
|
||||
return -engine.input.gamepads[0].right_stick_y;
|
||||
}
|
||||
}
|
||||
|
||||
key_down :: (key: Key_Code) -> bool {
|
||||
flags := input.keys[key];
|
||||
flags := engine.input.keys[key];
|
||||
return flags & .START && !(flags & .EATEN);
|
||||
}
|
||||
|
||||
key_pressed :: (key: Key_Code) -> bool {
|
||||
flags := input.keys[key];
|
||||
flags := engine.input.keys[key];
|
||||
return flags & .DOWN && !(flags & .EATEN);
|
||||
}
|
||||
|
||||
key_up :: (key: Key_Code) -> bool {
|
||||
flags := input.keys[key];
|
||||
flags := engine.input.keys[key];
|
||||
return flags & .END && !(flags & .EATEN);
|
||||
}
|
||||
|
||||
gamepad_down :: (index: s32, button: Gamepad_Button) -> bool {
|
||||
return cast(bool)(input.gamepads[index].buttons[button] & .START);
|
||||
return cast(bool)(engine.input.gamepads[index].buttons[button] & .START);
|
||||
}
|
||||
|
||||
gamepad_pressed :: (index: s32, button: Gamepad_Button) -> bool {
|
||||
return cast(bool)(input.gamepads[index].buttons[button] & .DOWN);
|
||||
return cast(bool)(engine.input.gamepads[index].buttons[button] & .DOWN);
|
||||
}
|
||||
|
||||
gamepad_up :: (index: s32, button: Gamepad_Button) -> bool {
|
||||
return cast(bool)(input.gamepads[index].buttons[button] & .END);
|
||||
return cast(bool)(engine.input.gamepads[index].buttons[button] & .END);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user