Tiny refactor
This commit is contained in:
@@ -80,7 +80,7 @@ update_sdl_input :: () {
|
||||
while SDL_PollEvent(*event) {
|
||||
if event.type == {
|
||||
case SDL_QUIT; {
|
||||
input.exit = true;
|
||||
engine.input.exit = true;
|
||||
}
|
||||
case SDL_KEYDOWN; {
|
||||
keycode, success := table_find(*key_mappings, event.key.keysym.sym);
|
||||
@@ -97,17 +97,17 @@ update_sdl_input :: () {
|
||||
}
|
||||
}
|
||||
case SDL_TEXTINPUT; {
|
||||
input.current_char = event.text.text[0];
|
||||
input.has_char = true;
|
||||
engine.input.current_char = event.text.text[0];
|
||||
engine.input.has_char = true;
|
||||
}
|
||||
case .SDL_MOUSEMOTION; {
|
||||
input.mouse.delta_x += xx event.motion.xrel;
|
||||
input.mouse.delta_y += xx event.motion.yrel;
|
||||
input.mouse.x = xx event.motion.x;
|
||||
input.mouse.y = xx event.motion.y;
|
||||
engine.input.mouse.delta_x += xx event.motion.xrel;
|
||||
engine.input.mouse.delta_y += xx event.motion.yrel;
|
||||
engine.input.mouse.x = xx event.motion.x;
|
||||
engine.input.mouse.y = xx event.motion.y;
|
||||
}
|
||||
case .SDL_MOUSEWHEEL; {
|
||||
input.mouse.wheel += event.wheel.y;
|
||||
engine.input.mouse.wheel += event.wheel.y;
|
||||
}
|
||||
case .SDL_CONTROLLERAXISMOTION; {
|
||||
sdl_gamepad_axis_update(event.caxis);
|
||||
@@ -143,27 +143,27 @@ update_sdl_input :: () {
|
||||
|
||||
//mouse_x, mouse_y : s32;
|
||||
//SDL_GetRelativeMouseState(*mouse_x, *mouse_y);
|
||||
//input.mouse.delta_x = xx mouse_x;
|
||||
//input.mouse.delta_y = xx mouse_y;
|
||||
//engine.input.mouse.delta_x = xx mouse_x;
|
||||
//engine.input.mouse.delta_y = xx mouse_y;
|
||||
}
|
||||
|
||||
sdl_connect_gamepad :: (input : *Input_State, id : SDL_JoystickID) {
|
||||
if !SDL_IsGameController(id) {
|
||||
return;
|
||||
} else if input.num_gamepads >= MAX_GAMEPADS {
|
||||
} else if engine.input.num_gamepads >= MAX_GAMEPADS {
|
||||
return;
|
||||
}
|
||||
|
||||
// @Incomplete: Is this necessary?
|
||||
//if input.gamepads[id].controller != null {
|
||||
//if engine.input.gamepads[id].controller != null {
|
||||
// print("Already connected gamepad with id %\n", id);
|
||||
// return;
|
||||
//}
|
||||
|
||||
gamepad : Gamepad;
|
||||
controller := xx SDL_GameControllerOpen(id);
|
||||
input.gamepads[id] = gamepad;
|
||||
input.num_gamepads += 1;
|
||||
engine.input.gamepads[id] = gamepad;
|
||||
engine.input.num_gamepads += 1;
|
||||
}
|
||||
|
||||
sdl_disconnect_gamepad :: (input : *Input_State, id : SDL_JoystickID) {
|
||||
@@ -171,18 +171,18 @@ update_sdl_input :: () {
|
||||
return;
|
||||
}
|
||||
|
||||
gamepad := input.gamepads[id];
|
||||
gamepad := engine.input.gamepads[id];
|
||||
//if !gamepad.controller {
|
||||
// return;
|
||||
//}
|
||||
|
||||
//input.gamepads[id].controller = null;
|
||||
//engine.input.gamepads[id].controller = null;
|
||||
}
|
||||
|
||||
update_gamepad_input :: () {
|
||||
// Deadzone checks
|
||||
for 0..input.num_gamepads-1 {
|
||||
gamepad := *input.gamepads[it];
|
||||
for 0..engine.input.num_gamepads-1 {
|
||||
gamepad := *engine.input.gamepads[it];
|
||||
|
||||
if abs(gamepad.left_stick_x) + abs(gamepad.left_stick_y) < LEFT_STICK_DEADZONE {
|
||||
gamepad.left_stick_x = 0.0;
|
||||
@@ -197,10 +197,10 @@ update_gamepad_input :: () {
|
||||
}
|
||||
|
||||
sdl_gamepad_axis_update :: (using event : SDL_ControllerAxisEvent) {
|
||||
if which < 0 || which >= input.num_gamepads {
|
||||
if which < 0 || which >= engine.input.num_gamepads {
|
||||
return;
|
||||
}
|
||||
gamepad := *input.gamepads[which];
|
||||
gamepad := *engine.input.gamepads[which];
|
||||
|
||||
if cast(SDL_GameControllerAxis) axis == {
|
||||
case SDL_CONTROLLER_AXIS_LEFTX; {
|
||||
@@ -233,13 +233,13 @@ sdl_gamepad_axis_update :: (using event : SDL_ControllerAxisEvent) {
|
||||
}
|
||||
|
||||
sdl_gamepad_button_update :: (using event : SDL_ControllerButtonEvent) {
|
||||
if which < 0 || which >= input.num_gamepads {
|
||||
if which < 0 || which >= engine.input.num_gamepads {
|
||||
return;
|
||||
}
|
||||
down := state == SDL_PRESSED;
|
||||
gamepad_button := sdl_button_map[button];
|
||||
|
||||
gamepad := *input.gamepads[which];
|
||||
gamepad := *engine.input.gamepads[which];
|
||||
|
||||
update_gamepad_state(gamepad, gamepad_button, down);
|
||||
}
|
||||
@@ -251,10 +251,10 @@ sdl_gamepad_device_event :: (using event : SDL_ControllerDeviceEvent) {
|
||||
|
||||
if type == {
|
||||
case SDL_CONTROLLERDEVICEADDED; {
|
||||
sdl_connect_gamepad(*input, which);
|
||||
sdl_connect_gamepad(*engine.input, which);
|
||||
}
|
||||
case SDL_CONTROLLERDEVICEREMOVED; {
|
||||
sdl_disconnect_gamepad(*input, which);
|
||||
sdl_disconnect_gamepad(*engine.input, which);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user