diff --git a/src/ReDIVA/app.cpp b/src/ReDIVA/app.cpp index 19a128c4..0dbe3b88 100644 --- a/src/ReDIVA/app.cpp +++ b/src/ReDIVA/app.cpp @@ -443,7 +443,7 @@ int32_t app_main(const app_init_struct& ais) { glfwSetWindowPos(window, 8, 31); #endif - Input::SetInputs(window); + Input::SetCallbacks(window); RECT window_rect; GetClientRect(window_handle, &window_rect); @@ -741,8 +741,6 @@ static void app_main_loop(render_context* rctx) { close |= !!glfwWindowShouldClose(window); - Input::EndFrame(); - app_swap_buffers(); render_timer->end_of_cycle(); } @@ -1095,71 +1093,72 @@ static void render_context_ctrl(render_context* rctx) { } } - if (Input::IsKeyTapped(GLFW_KEY_F4)) + const InputState* input_state = input_state_get(0); + if (input_state->CheckTapped(INPUT_BUTTON_F4)) game_state_set_game_state_next(GAME_STATE_ADVERTISE); #if PV_DEBUG - else if (Input::IsKeyTapped(GLFW_KEY_F5, GLFW_MOD_CONTROL)) { + else if (input_state->CheckTapped(INPUT_BUTTON_F5) && input_state->CheckDown(INPUT_BUTTON_CONTROL)) { pv_x = false; game_state_set_game_state_next(GAME_STATE_GAME); } #if BAKE_X_PACK - else if (Input::IsKeyTapped(GLFW_KEY_F5, GLFW_MOD_SHIFT)) { + else if (input_state->CheckTapped(INPUT_BUTTON_F5) && input_state->CheckDown(INPUT_BUTTON_SHIFT)) { pv_x = true; pv_x_bake = true; game_state_set_game_state_next(GAME_STATE_GAME); } - else if (Input::IsKeyTapped(GLFW_KEY_F5)) { + else if (input_state->CheckTapped(INPUT_BUTTON_F5)) { pv_x = true; pv_x_bake = false; game_state_set_game_state_next(GAME_STATE_GAME); } #else - else if (Input::IsKeyTapped(GLFW_KEY_F5)) { + else if (input_state->CheckTapped(INPUT_BUTTON_F5)) { pv_x = true; game_state_set_game_state_next(GAME_STATE_GAME); } #endif #else #if BAKE_X_PACK - else if (Input::IsKeyTapped(GLFW_KEY_F5, GLFW_MOD_SHIFT)) { + else if (input_state->CheckTapped(INPUT_BUTTON_F5) && input_state->CheckDown(INPUT_BUTTON_SHIFT)) { pv_x_bake = true; game_state_set_game_state_next(GAME_STATE_GAME); } - else if (Input::IsKeyTapped(GLFW_KEY_F5)) { + else if (input_state->CheckTapped(INPUT_BUTTON_F5)) { pv_x_bake = false; game_state_set_game_state_next(GAME_STATE_GAME); } #else - else if (Input::IsKeyTapped(GLFW_KEY_F5)) + else if (input_state->CheckTapped(INPUT_BUTTON_F5)) game_state_set_game_state_next(GAME_STATE_GAME); #endif #endif - else if (Input::IsKeyTapped(GLFW_KEY_F6)) + else if (input_state->CheckTapped(INPUT_BUTTON_F6)) game_state_set_game_state_next(GAME_STATE_DATA_TEST); - else if (Input::IsKeyTapped(GLFW_KEY_F7)) + else if (input_state->CheckTapped(INPUT_BUTTON_F7)) game_state_set_game_state_next(GAME_STATE_TEST_MODE); - else if (Input::IsKeyTapped(GLFW_KEY_F8)) + else if (input_state->CheckTapped(INPUT_BUTTON_F8)) game_state_set_game_state_next(GAME_STATE_APP_ERROR); - else if (Input::IsKeyTapped(GLFW_KEY_F9)) // Added + else if (input_state->CheckTapped(INPUT_BUTTON_F9)) // Added game_state_set_game_state_next(GAME_STATE_DATA_EDIT); // Added #if DISPLAY_IBL - else if (Input::IsKeyTapped(GLFW_KEY_L)) + else if (input_state->CheckTapped(INPUT_BUTTON_L)) display_ibl ^= true; - else if (Input::IsKeyTapped(GLFW_KEY_1)) + else if (input_state->CheckTapped(INPUT_BUTTON_1)) ibl_index = 0; - else if (Input::IsKeyTapped(GLFW_KEY_2)) + else if (input_state->CheckTapped(INPUT_BUTTON_2)) ibl_index = 1; - else if (Input::IsKeyTapped(GLFW_KEY_3)) + else if (input_state->CheckTapped(INPUT_BUTTON_3)) ibl_index = 2; - else if (Input::IsKeyTapped(GLFW_KEY_4)) + else if (input_state->CheckTapped(INPUT_BUTTON_4)) ibl_index = 3; - else if (Input::IsKeyTapped(GLFW_KEY_5)) + else if (input_state->CheckTapped(INPUT_BUTTON_5)) ibl_index = 4; - else if (Input::IsKeyTapped(GLFW_KEY_6)) + else if (input_state->CheckTapped(INPUT_BUTTON_6)) ibl_index = 5; - else if (Input::IsKeyTapped(GLFW_KEY_7)) + else if (input_state->CheckTapped(INPUT_BUTTON_7)) ibl_scale = max_def(ibl_scale - 1, 1); - else if (Input::IsKeyTapped(GLFW_KEY_8)) + else if (input_state->CheckTapped(INPUT_BUTTON_8)) ibl_scale = min_def(ibl_scale + 1, 64); #endif @@ -1167,6 +1166,7 @@ static void render_context_ctrl(render_context* rctx) { rctx_ptr = rctx; input_state_am_ctrl(); + input_state_pc_ctrl(); input_state_ctrl(); if (!get_pause() || !game_state_get_pause()) game_state_ctrl(); @@ -1176,6 +1176,7 @@ static void render_context_ctrl(render_context* rctx) { for (int32_t i = 1; i < fast_loader_speed; i++) { rctx_ptr = rctx; input_state_am_ctrl(); + input_state_pc_ctrl(); input_state_ctrl(); if (!get_pause() || !game_state_get_pause()) game_state_ctrl(); diff --git a/src/ReDIVA/classes/data_view/auth_3d.cpp b/src/ReDIVA/classes/data_view/auth_3d.cpp index 1b432151..d38509d0 100644 --- a/src/ReDIVA/classes/data_view/auth_3d.cpp +++ b/src/ReDIVA/classes/data_view/auth_3d.cpp @@ -7,7 +7,6 @@ #include "../../../KKdLib/database/item_table.hpp" #include "../../../CRE/auth_3d.hpp" #include "../../imgui_helper.hpp" -#include "../../input.hpp" static const char* auth_3d_fog_name[] = { "Depth", diff --git a/src/ReDIVA/data_edit/glitter_editor.cpp b/src/ReDIVA/data_edit/glitter_editor.cpp index 5ecc5383..4c9e65fe 100644 --- a/src/ReDIVA/data_edit/glitter_editor.cpp +++ b/src/ReDIVA/data_edit/glitter_editor.cpp @@ -22,7 +22,7 @@ #include "../../CRE/static_var.hpp" #include "../data_test/stage_test.hpp" #include "../imgui_helper.hpp" -#include "../input.hpp" +#include "../input_state.hpp" #include #include #include @@ -1104,23 +1104,24 @@ void GlitterEditor::disp() { } void GlitterEditor::window() { - if (Input::IsKeyTapped(GLFW_KEY_O, GLFW_MOD_CONTROL)) + const InputState* input_state = input_state_get(0); + if (input_state->CheckTapped(INPUT_BUTTON_O) && input_state->CheckDown(INPUT_BUTTON_CONTROL)) glitter_editor_open_window(this); - else if (Input::IsKeyTapped(GLFW_KEY_F4, GLFW_MOD_CONTROL)) + else if (input_state->CheckTapped(INPUT_BUTTON_F4) && input_state->CheckDown(INPUT_BUTTON_CONTROL)) close = true; - else if (Input::IsKeyTapped(GLFW_KEY_F3, GLFW_MOD_CONTROL)) + else if (input_state->CheckTapped(INPUT_BUTTON_F4) && input_state->CheckDown(INPUT_BUTTON_CONTROL)) close_editor = true; - else if (Input::IsKeyTapped(GLFW_KEY_Q, GLFW_MOD_CONTROL)) + else if (input_state->CheckTapped(INPUT_BUTTON_Q) && input_state->CheckDown(INPUT_BUTTON_CONTROL)) close = true; - else if (Input::IsKeyTapped(GLFW_KEY_P)) + else if (input_state->CheckTapped(INPUT_BUTTON_P)) test ^= true; - else if (Input::IsKeyTapped(GLFW_KEY_T)) + else if (input_state->CheckTapped(INPUT_BUTTON_T)) input_play = true; - else if (Input::IsKeyTapped(GLFW_KEY_Y)) + else if (input_state->CheckTapped(INPUT_BUTTON_Y)) input_reload = true; - else if (Input::IsKeyTapped(GLFW_KEY_F)) + else if (input_state->CheckTapped(INPUT_BUTTON_F)) input_pause = true; - else if (Input::IsKeyTapped(GLFW_KEY_G)) + else if (input_state->CheckTapped(INPUT_BUTTON_G)) input_reset = true; if (test) @@ -1130,9 +1131,12 @@ void GlitterEditor::window() { glitter_editor_popups(this); if (input_locked) { - if (Input::IsKeyTapped(GLFW_KEY_S, GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) + if (input_state->CheckTapped(INPUT_BUTTON_S) + && input_state->CheckDown(INPUT_BUTTON_CONTROL) + && input_state->CheckDown(INPUT_BUTTON_SHIFT)) glitter_editor_save_as_window(this); - else if (Input::IsKeyTapped(GLFW_KEY_S, GLFW_MOD_CONTROL)) + else if (input_state->CheckTapped(INPUT_BUTTON_S) + && input_state->CheckDown(INPUT_BUTTON_CONTROL)) glitter_editor_save_window(this); } } @@ -5546,7 +5550,8 @@ static void glitter_editor_curve_editor_selector_list_box_multi_selectable(Glitt if (!ImGui::Selectable(buf, crv_edt->type == type)) return; - if (Input::IsKeyDown(GLFW_KEY_LEFT_CONTROL) || Input::IsKeyDown(GLFW_KEY_RIGHT_CONTROL)) + const InputState* input_state = input_state_get(0); + if (input_state->CheckDown(INPUT_BUTTON_CONTROL)) glt_edt->curve_editor.SetFlag((Glitter::CurveTypeFlags)(1 << type)); else if (crv_edt->type != type) { glt_edt->curve_editor.ResetState(type); diff --git a/src/ReDIVA/data_edit/rob_chara_adjust.cpp b/src/ReDIVA/data_edit/rob_chara_adjust.cpp index bd3751cb..5e7be723 100644 --- a/src/ReDIVA/data_edit/rob_chara_adjust.cpp +++ b/src/ReDIVA/data_edit/rob_chara_adjust.cpp @@ -12,7 +12,7 @@ #include "../data_test/motion_test.hpp" #include "../dw.hpp" #include "../imgui_helper.hpp" -#include "../input.hpp" +#include "../input_state.hpp" static const char* chara_name[] = { "1P", @@ -128,7 +128,10 @@ bool RobCharaAdjust::dest() { } void RobCharaAdjust::window() { - if (Input::IsKeyTapped(GLFW_KEY_A, GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) + const InputState* input_state = input_state_get(0); + if (input_state->CheckTapped(INPUT_BUTTON_A) + && input_state->CheckDown(INPUT_BUTTON_CONTROL) + && input_state->CheckDown(INPUT_BUTTON_SHIFT)) visible ^= true; if (!visible) diff --git a/src/ReDIVA/dw.cpp b/src/ReDIVA/dw.cpp index 1257ed15..b31ac22a 100644 --- a/src/ReDIVA/dw.cpp +++ b/src/ReDIVA/dw.cpp @@ -3274,6 +3274,10 @@ void dw_gui_detail::Input::Ctrl() { mouse_pos.y = (float_t)mouse_pos_y; mouse_delta = mouse_pos - old_mouse_pos; + extern uint8_t disable_dw_input_update; + if (disable_dw_input_update) + return; + if (mouse_delta != 0.0f) enum_or(mouse_input, dw::MOUSE_INPUT_MOVE); diff --git a/src/ReDIVA/input.cpp b/src/ReDIVA/input.cpp index 4a3ca4bb..0b5e8422 100644 --- a/src/ReDIVA/input.cpp +++ b/src/ReDIVA/input.cpp @@ -8,11 +8,8 @@ #include "input.hpp" #include "../KKdLib/timer.hpp" #include "../KKdLib/vec.hpp" -#include -#include -#define CIMGUI_DEFINE_ENUMS_AND_STRUCTS -#include -#include +#include "input_state.hpp" +#include double_t input_movement_speed = 0.1; double_t input_rotation_sensitivity = 0.5; @@ -26,41 +23,34 @@ bool input_reset; bool input_reset_mouse_position; bool input_locked; +uint8_t disable_dw_input_update = false; +bool disable_cursor = false; + extern bool close; extern timer* render_timer; extern HWND window_handle; -extern ImGuiContext* imgui_context; -extern uint8_t disable_input_state_update; -extern bool disable_cursor; +extern void glut_get_modifiers(); +extern void glut_reset_modifiers(); + +extern void glut_keydown_cb(uint8_t key, int32_t x, int32_t y); +extern void glut_keyup_cb(uint8_t key, int32_t x, int32_t y); +extern void glut_skeydown_cb(int32_t key, int32_t x, int32_t y); +extern void glut_skeyup_cb(int32_t key, int32_t x, int32_t y); +extern void glut_mouse_cb(int32_t bn, int32_t state, int32_t x, int32_t y); +extern void glut_motion_cb(int32_t x, int32_t y); namespace Input { - struct Key { - int32_t key; - int32_t scancode; - int32_t action; - int32_t mods; - }; - - struct MouseButton { - int32_t button; - int32_t action; - int32_t mods; - }; - - std::vector keys; - std::vector mouse_buttons; - POINT pos; - double_t scroll; - - std::vector keys_prev; - std::vector mouse_buttons_prev; - POINT pos_prev; - double_t scroll_prev; + static vec2i pos; static bool is_key_mod(int32_t key); static bool is_key_numpad(int32_t key); + inline static void process_button(const InputState* input_state, double_t& value, InputButton button, + const double_t speed, const double_t speed_fast, const double_t speed_slow); + + static void CursorPosCallback(GLFWwindow* window, + double_t xpos, double_t ypos); static void KeyboardCallback(GLFWwindow* window, int32_t key, int32_t scancode, int32_t action, int32_t mods); static void MouseButtonCallback(GLFWwindow* window, @@ -68,157 +58,25 @@ namespace Input { static void ScrollCallback(GLFWwindow* window, double_t x_offset, double_t y_offset); - static Key* vector_Key_find(std::vector& keys, int32_t key); - static MouseButton* vector_MouseButton_find( - std::vector& mouse_buttons, int32_t button); - - bool IsKeyDown(int32_t key, int32_t mods) { - Key* k = vector_Key_find(keys, key); - if (k && (mods == -1 || k->mods == mods)) - return k->action != GLFW_RELEASE; - return false; - } - - bool IsKeyUp(int32_t key, int32_t mods) { - Key* k = vector_Key_find(keys, key); - if (k && (mods == -1 || k->mods == mods)) - return k->action == GLFW_RELEASE; - return false; - } - - bool IsKeyTapped(int32_t key, int32_t mods) { - Key* k = vector_Key_find(keys, key); - Key* k_prev = vector_Key_find(keys_prev, key); - if (k) - if (k_prev) { - if (mods == -1 || (k->mods == mods && k_prev->mods == mods)) - return k->action != GLFW_RELEASE && k_prev->action == GLFW_RELEASE; - } - else { - if (mods == -1 || k->mods == mods) - return k->action != GLFW_RELEASE; - } - return false; - } - - bool IsKeyReleased(int32_t key, int32_t mods) { - Key* k = vector_Key_find(keys, key); - Key* k_prev = vector_Key_find(keys_prev, key); - if (k) - if (k_prev) { - if ((k->mods == mods && k_prev->mods == mods)) - return k->action == GLFW_RELEASE && k_prev->action != GLFW_RELEASE; - } - else { - if (mods == -1 || k->mods == mods) - return k->action == GLFW_RELEASE; - } - return false; - } - - bool IsMouseButtonDown(int32_t button, int32_t mods) { - MouseButton* mb = vector_MouseButton_find(mouse_buttons, button); - if (mb && (mods == -1 || mb->mods == mods)) - return mb->action != GLFW_RELEASE; - return false; - } - - bool IsMouseButtonUp(int32_t button, int32_t mods) { - MouseButton* mb = vector_MouseButton_find(mouse_buttons, button); - if (mb && (mods == -1 || mb->mods == mods)) - return mb->action == GLFW_RELEASE; - return false; - } - - bool IsMouseButtonTapped(int32_t button, int32_t mods) { - MouseButton* mb = vector_MouseButton_find(mouse_buttons, button); - MouseButton* mb_prev = vector_MouseButton_find(mouse_buttons_prev, button); - if (mb) - if (mb_prev) { - if ((mods == -1 || mb->mods == mods && mb_prev->mods == mods)) - return mb->action != GLFW_RELEASE && mb_prev->action == GLFW_RELEASE; - } - else { - if (mods == -1 || mb->mods == mods) - return mb->action != GLFW_RELEASE; - } - return false; - } - - bool IsMouseButtonReleased(int32_t button, int32_t mods) { - MouseButton* mb = vector_MouseButton_find(mouse_buttons, button); - MouseButton* mb_prev = vector_MouseButton_find(mouse_buttons_prev, button); - if (mb) - if (mb_prev) { - if ((mods == -1 || mb->mods == mods && mb_prev->mods == mods)) - return mb->action == GLFW_RELEASE && mb_prev->action != GLFW_RELEASE; - } - else { - if (mods == -1 || mb->mods == mods) - return mb->action == GLFW_RELEASE; - } - return true; - } - - bool WasKeyDown(int32_t key, int32_t mods) { - Key* k_prev = vector_Key_find(keys_prev, key); - if (k_prev && (mods == -1 || k_prev->mods == mods)) - return k_prev->action != GLFW_RELEASE; - return false; - } - - bool WasKeyUp(int32_t key, int32_t mods) { - Key* k_prev = vector_Key_find(keys_prev, key); - if (k_prev && (mods == -1 || k_prev->mods == mods)) - return k_prev->action == GLFW_RELEASE; - return true; - } - - bool WasMouseButtonDown(int32_t button, int32_t mods) { - MouseButton* mb_prev = vector_MouseButton_find(mouse_buttons_prev, button); - if (mb_prev && (mods == -1 || mb_prev->mods == mods)) - return mb_prev->action != GLFW_RELEASE; - return true; - } - - bool WasMouseButtonUp(int32_t button, int32_t mods) { - MouseButton* mb_prev = vector_MouseButton_find(mouse_buttons_prev, button); - if (mb_prev && (mods == -1 || mb_prev->mods == mods)) - return mb_prev->action == GLFW_RELEASE; - return true; - } - - void EndFrame() { - keys_prev.assign(keys.begin(), keys.end()); - mouse_buttons_prev.assign(mouse_buttons.begin(), mouse_buttons.end()); - pos_prev = pos; - scroll_prev = scroll; - scroll = 0.0; - } - void NewFrame() { - if (window_handle) { - GetCursorPos(&pos); - ScreenToClient(window_handle, &pos); - } - input_move_x = 0.0; input_move_y = 0.0; input_rotate_x = 0.0; input_rotate_y = 0.0; input_roll = 0.0; - if (IsKeyTapped(GLFW_KEY_F3)) - disable_input_state_update ^= 0x01; - else if (IsKeyTapped(GLFW_KEY_F3, GLFW_MOD_CONTROL)) + const InputState* input_state = input_state_get(0); + if (input_state->CheckTapped(INPUT_BUTTON_F3)) + disable_dw_input_update ^= 0x01; + else if (input_state->CheckTapped(INPUT_BUTTON_F3) && input_state->CheckDown(INPUT_BUTTON_CONTROL)) disable_cursor ^= true; if (input_locked) - disable_input_state_update |= 0x02; + disable_dw_input_update |= 0x02; else - disable_input_state_update &= ~0x02; + disable_dw_input_update &= ~0x02; - if (!window_handle || window_handle != GetForegroundWindow() || !disable_input_state_update) + if (!window_handle || window_handle != GetForegroundWindow() || !disable_dw_input_update) return; double_t freq = render_timer->get_freq(); @@ -238,41 +96,10 @@ namespace Input { speed_fast *= frame_speed; speed_slow *= frame_speed; - if (IsKeyDown(GLFW_KEY_W) || IsKeyDown(GLFW_KEY_W, GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) - input_move_x += speed; - else if (IsKeyDown(GLFW_KEY_W, GLFW_MOD_SHIFT)) - input_move_x += speed_fast; - else if (IsKeyDown(GLFW_KEY_W, GLFW_MOD_CONTROL)) - input_move_x += speed_slow; - else if (IsKeyDown(GLFW_KEY_W, -1)) - input_move_x += speed; - - if (IsKeyDown(GLFW_KEY_S) || IsKeyDown(GLFW_KEY_S, GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) - input_move_x -= speed; - else if (IsKeyDown(GLFW_KEY_S, GLFW_MOD_SHIFT)) - input_move_x -= speed_fast; - else if (IsKeyDown(GLFW_KEY_S, GLFW_MOD_CONTROL)) - input_move_x -= speed_slow; - else if (IsKeyDown(GLFW_KEY_S, -1)) - input_move_x -= speed; - - if (IsKeyDown(GLFW_KEY_A) || IsKeyDown(GLFW_KEY_A, GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) - input_move_y -= speed; - else if (IsKeyDown(GLFW_KEY_A, GLFW_MOD_SHIFT)) - input_move_y -= speed_fast; - else if (IsKeyDown(GLFW_KEY_A, GLFW_MOD_CONTROL)) - input_move_y -= speed_slow; - else if (IsKeyDown(GLFW_KEY_A, -1)) - input_move_y -= speed; - - if (IsKeyDown(GLFW_KEY_D) || IsKeyDown(GLFW_KEY_D, GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) - input_move_y += speed; - else if (IsKeyDown(GLFW_KEY_D, GLFW_MOD_SHIFT)) - input_move_y += speed_fast; - else if (IsKeyDown(GLFW_KEY_D, GLFW_MOD_CONTROL)) - input_move_y += speed_slow; - else if (IsKeyDown(GLFW_KEY_D, -1)) - input_move_y += speed; + process_button(input_state, input_move_x, INPUT_BUTTON_W, speed, speed_fast, speed_slow); + process_button(input_state, input_move_x, INPUT_BUTTON_S, -speed, -speed_fast, -speed_slow); + process_button(input_state, input_move_y, INPUT_BUTTON_A, -speed, -speed_fast, -speed_slow); + process_button(input_state, input_move_y, INPUT_BUTTON_D, speed, speed_fast, speed_slow); speed = input_movement_speed; speed_fast = input_movement_speed * 2.0; @@ -284,67 +111,21 @@ namespace Input { speed_fast *= 10.0; speed_slow *= 10.0; - if (IsKeyDown(GLFW_KEY_UP) || IsKeyDown(GLFW_KEY_UP, GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) - input_rotate_y += speed; - else if (IsKeyDown(GLFW_KEY_UP, GLFW_MOD_SHIFT)) - input_rotate_y += speed_fast; - else if (IsKeyDown(GLFW_KEY_UP, GLFW_MOD_CONTROL)) - input_rotate_y += speed_slow; - else if (IsKeyDown(GLFW_KEY_UP, -1)) - input_rotate_y += speed; + process_button(input_state, input_rotate_y, INPUT_BUTTON_UP , speed, speed_fast, speed_slow); + process_button(input_state, input_rotate_y, INPUT_BUTTON_DOWN , -speed, -speed_fast, -speed_slow); + process_button(input_state, input_rotate_x, INPUT_BUTTON_LEFT , -speed, -speed_fast, -speed_slow); + process_button(input_state, input_rotate_x, INPUT_BUTTON_RIGHT, speed, speed_fast, speed_slow); - if (IsKeyDown(GLFW_KEY_DOWN) || IsKeyDown(GLFW_KEY_DOWN, GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) - input_rotate_y -= speed; - else if (IsKeyDown(GLFW_KEY_DOWN, GLFW_MOD_SHIFT)) - input_rotate_y -= speed_fast; - else if (IsKeyDown(GLFW_KEY_DOWN, GLFW_MOD_CONTROL)) - input_rotate_y -= speed_slow; - else if (IsKeyDown(GLFW_KEY_DOWN, -1)) - input_rotate_y -= speed; + process_button(input_state, input_roll, INPUT_BUTTON_Q, speed, speed_fast, speed_slow); + process_button(input_state, input_roll, INPUT_BUTTON_E, -speed, -speed_fast, -speed_slow); - if (IsKeyDown(GLFW_KEY_LEFT) || IsKeyDown(GLFW_KEY_LEFT, GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) - input_rotate_x -= speed; - else if (IsKeyDown(GLFW_KEY_LEFT, GLFW_MOD_SHIFT)) - input_rotate_x -= speed_fast; - else if (IsKeyDown(GLFW_KEY_LEFT, GLFW_MOD_CONTROL)) - input_rotate_x -= speed_slow; - else if (IsKeyDown(GLFW_KEY_LEFT, -1)) - input_rotate_x -= speed; - - if (IsKeyDown(GLFW_KEY_RIGHT) || IsKeyDown(GLFW_KEY_RIGHT, GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) - input_rotate_x += speed; - else if (IsKeyDown(GLFW_KEY_RIGHT, GLFW_MOD_SHIFT)) - input_rotate_x += speed_fast; - else if (IsKeyDown(GLFW_KEY_RIGHT, GLFW_MOD_CONTROL)) - input_rotate_x += speed_slow; - else if (IsKeyDown(GLFW_KEY_RIGHT, -1)) - input_rotate_x += speed; - - if (IsKeyDown(GLFW_KEY_Q) || IsKeyDown(GLFW_KEY_Q, GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) - input_roll += speed; - else if (IsKeyDown(GLFW_KEY_Q, GLFW_MOD_SHIFT)) - input_roll += speed_fast; - else if (IsKeyDown(GLFW_KEY_Q, GLFW_MOD_CONTROL)) - input_roll += speed_slow; - else if (IsKeyDown(GLFW_KEY_Q, -1)) - input_roll += speed; - - if (IsKeyDown(GLFW_KEY_E) || IsKeyDown(GLFW_KEY_E, GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) - input_roll -= speed; - else if (IsKeyDown(GLFW_KEY_E, GLFW_MOD_SHIFT)) - input_roll -= speed_fast; - else if (IsKeyDown(GLFW_KEY_E, GLFW_MOD_CONTROL)) - input_roll -= speed_slow; - else if (IsKeyDown(GLFW_KEY_E, -1)) - input_roll -= speed; - - if (IsKeyDown(GLFW_KEY_R)) + if (input_state->CheckDown(INPUT_BUTTON_R)) input_reset = true; - if (IsMouseButtonDown(GLFW_MOUSE_BUTTON_MIDDLE, -1)) { + if (input_state->CheckDown(INPUT_BUTTON_MOUSE_BUTTON_MIDDLE)) { if (!input_reset_mouse_position) { - input_rotate_y += ((double_t)pos_prev.y - (double_t)pos.y) * input_rotation_sensitivity; - input_rotate_x += ((double_t)pos.x - (double_t)pos_prev.x) * input_rotation_sensitivity; + input_rotate_y += -input_state->sub_14018CCC0(11) * input_rotation_sensitivity; + input_rotate_x += input_state->sub_14018CCC0(10) * input_rotation_sensitivity; } input_reset_mouse_position = false; } @@ -353,7 +134,8 @@ namespace Input { input_locked = false; } - void SetInputs(GLFWwindow* window) { + void SetCallbacks(GLFWwindow* window) { + glfwSetCursorPosCallback(window, (GLFWcursorposfun)CursorPosCallback); glfwSetKeyCallback(window, (GLFWkeyfun)KeyboardCallback); glfwSetMouseButtonCallback(window, (GLFWmousebuttonfun)MouseButtonCallback); glfwSetScrollCallback(window, (GLFWscrollfun)ScrollCallback); @@ -393,6 +175,29 @@ namespace Input { } } + inline static void process_button(const InputState* input_state, double_t& value, InputButton button, + const double_t speed, const double_t speed_fast, const double_t speed_slow) { + if (input_state->CheckDown(button) + && input_state->CheckDown(INPUT_BUTTON_CONTROL) && input_state->CheckDown(INPUT_BUTTON_SHIFT)) + value += speed; + else if (input_state->CheckDown(button) && input_state->CheckDown(INPUT_BUTTON_SHIFT)) + value += speed_fast; + else if (input_state->CheckDown(button) && input_state->CheckDown(INPUT_BUTTON_CONTROL)) + value += speed_slow; + else if (input_state->CheckDown(button)) + value += speed; + } + + static void CursorPosCallback(GLFWwindow* window, + double_t xpos, double_t ypos) { + pos.x = (int32_t)xpos; + pos.y = (int32_t)ypos; + + glut_get_modifiers(); + glut_motion_cb(pos.x, pos.y); + glut_reset_modifiers(); + } + static void KeyboardCallback(GLFWwindow* window, int32_t key, int32_t scancode, int32_t action, int32_t mods) { if (mods & GLFW_MOD_CAPS_LOCK) @@ -431,60 +236,112 @@ namespace Input { break; } - if (is_mod) { - if (action != GLFW_RELEASE) { - for (Key& i : keys) - if (!is_key_mod(i.key)) - i.mods |= mods; + if (is_mod) + return; - for (MouseButton& i : mouse_buttons) - i.mods |= mods; - } - else { - mods = ~mods; - for (Key& i : keys) - if (!is_key_mod(i.key)) - i.mods &= mods; + static const std::pair glut_key_table[] = { + { GLFW_KEY_ESCAPE , 0x1B }, + { GLFW_KEY_BACKSPACE, '\b' }, + { GLFW_KEY_TAB , '\t' }, + { GLFW_KEY_ENTER , '\r' }, + { GLFW_KEY_SPACE , ' ' }, + { GLFW_KEY_DELETE , 0x7F }, + }; - for (MouseButton& i : mouse_buttons) - i.mods &= mods; + static const std::pair glut_skey_table[] = { + { GLFW_KEY_F1 , 1, }, + { GLFW_KEY_F2 , 2, }, + { GLFW_KEY_F3 , 3, }, + { GLFW_KEY_F4 , 4, }, + { GLFW_KEY_F5 , 5, }, + { GLFW_KEY_F6 , 6, }, + { GLFW_KEY_F7 , 7, }, + { GLFW_KEY_F8 , 8, }, + { GLFW_KEY_F9 , 9, }, + { GLFW_KEY_F10 , 10, }, + { GLFW_KEY_F11 , 11, }, + { GLFW_KEY_F12 , 12, }, + { GLFW_KEY_LEFT , 100, }, + { GLFW_KEY_UP , 101, }, + { GLFW_KEY_RIGHT , 102, }, + { GLFW_KEY_DOWN , 103, }, + { GLFW_KEY_PAGE_UP , 104, }, + { GLFW_KEY_PAGE_DOWN, 105, }, + { GLFW_KEY_HOME , 106, }, + { GLFW_KEY_END , 107, }, + { GLFW_KEY_INSERT , 108, }, + }; + + glut_get_modifiers(); + + int32_t glut_key = -1; + + bool is_skey = false; + for (const auto& i : glut_skey_table) + if (i.first == key) { + glut_key = i.second; + is_skey = true; + break; } - mods = 0; + + if (is_skey) { + switch (action) { + case GLFW_RELEASE: + glut_skeyup_cb(glut_key, pos.x, pos.y); + break; + case GLFW_PRESS: + glut_skeydown_cb(glut_key, pos.x, pos.y); + break; + } + } + else { + for (const auto& i : glut_key_table) + if (i.first == key) { + glut_key = i.second; + break; + } + + if (glut_key == -1 + && ((key >= '0' && key <= '9') + || (key >= 'A' && key <= 'Z') + || (key >= 'a' && key <= 'z'))) + glut_key = key; + + if (glut_key != -1) + switch (action) { + case GLFW_RELEASE: + glut_keyup_cb(glut_key, pos.x, pos.y); + break; + case GLFW_PRESS: + glut_keydown_cb(glut_key, pos.x, pos.y); + break; + } } - Key* k = vector_Key_find(keys, key); - if (k) - *k = { key, scancode, action, mods }; - else - keys.push_back({ key, scancode, action, mods }); + glut_reset_modifiers(); } static void MouseButtonCallback(GLFWwindow* window, int32_t button, int32_t action, int32_t mods) { - MouseButton* mb = vector_MouseButton_find(mouse_buttons, button); - if (mb) - *mb = { button, action, mods }; - else - mouse_buttons.push_back({ button, action, mods }); + int32_t bn = -1; + if (button == GLFW_MOUSE_BUTTON_LEFT) + bn = 0; + else if (button == GLFW_MOUSE_BUTTON_MIDDLE) + bn = 1; + else if (button == GLFW_MOUSE_BUTTON_RIGHT) + bn = 2; + + int32_t state = action == GLFW_PRESS ? 0 : 1; + + glut_get_modifiers(); + glut_mouse_cb(bn, state, pos.x, pos.y); + glut_reset_modifiers(); } static void ScrollCallback(GLFWwindow* window, double_t x_offset, double_t y_offset) { - scroll += y_offset; - } - - static Key* vector_Key_find(std::vector& keys, int32_t key) { - for (Key& i : keys) - if (i.key == key) - return &i; - return 0; - } - - static MouseButton* vector_MouseButton_find( - std::vector& mouse_buttons, int32_t button) { - for (MouseButton& i : mouse_buttons) - if (i.button == button) - return &i; - return 0; + glut_get_modifiers(); + glut_mouse_cb(y_offset < 0.0f ? 4 : 3, 0, pos.x, pos.y); + glut_reset_modifiers(); } }; diff --git a/src/ReDIVA/input.hpp b/src/ReDIVA/input.hpp index 0e37c045..2d64ea24 100644 --- a/src/ReDIVA/input.hpp +++ b/src/ReDIVA/input.hpp @@ -6,27 +6,10 @@ #pragma once #include "../KKdLib/default.hpp" -#include + +struct GLFWwindow; namespace Input { - extern POINT pos; - extern double_t scroll; - extern POINT pos_prev; - extern double_t scroll_prev; - - extern bool IsKeyDown(int32_t key, int32_t mods = 0); - extern bool IsKeyUp(int32_t key, int32_t mods = 0); - extern bool IsKeyTapped(int32_t key, int32_t mods = 0); - extern bool IsKeyReleased(int32_t key, int32_t mods = 0); - extern bool IsMouseButtonDown(int32_t button, int32_t mods = 0); - extern bool IsMouseButtonUp(int32_t button, int32_t mods = 0); - extern bool IsMouseButtonTapped(int32_t button, int32_t mods = 0); - extern bool IsMouseButtonReleased(int32_t button, int32_t mods = 0); - extern bool WasKeyDown(int32_t key, int32_t mods = 0); - extern bool WasKeyUp(int32_t key, int32_t mods = 0); - extern bool WasMouseButtonDown(int32_t button, int32_t mods = 0); - extern bool WasMouseButtonUp(int32_t button, int32_t mods = 0); - extern void EndFrame(); extern void NewFrame(); - extern void SetInputs(GLFWwindow* window); + extern void SetCallbacks(struct GLFWwindow* window); }; diff --git a/src/ReDIVA/input_state.cpp b/src/ReDIVA/input_state.cpp index 98c82ea0..7210d3c2 100644 --- a/src/ReDIVA/input_state.cpp +++ b/src/ReDIVA/input_state.cpp @@ -5,8 +5,8 @@ #include "input_state.hpp" #include "../CRE/render_context.hpp" +#include "../CRE/resolution_mode.hpp" #include "config.hpp" -#include "input.hpp" #ifndef USE_OPENGL #if BAKE_PNG @@ -38,9 +38,23 @@ Bit / Name 11 JVS_L (also triggered by pressing L on Slider Panel) 12 JVS_R (also triggered by pressing R on Slider Panel) + 13 JVS_BUTTON_7 + 14 JVS_BUTTON_8 + 15 JVS_BUTTON_9 + 16 JVS_BUTTON_10 + 18 JVS_SW1 19 JVS_SW2 + 20 DIP_SW1 + 21 DIP_SW2 + 22 DIP_SW3 + 23 DIP_SW4 + 24 DIP_SW5 + 25 DIP_SW6 + 26 DIP_SW7 + 27 DIP_SW8 + 28 KEYBOARD_PRESS (any of keyboard keys) 29 '0' @@ -112,6 +126,7 @@ struct amInputState { amInputState(); void reset(); + void update_modifiers(bool get); }; struct amOutputState { @@ -137,6 +152,8 @@ static bool am_input_output_set_output(const amOutputState value, int32_t index) // Own stuff static void am_input_output_pc_ctrl(amInputState& input); +static int32_t get_modifiers(); + static void input_state_ctrl(InputState* input_state); static int32_t input_state_get_delta_frame(); @@ -144,9 +161,6 @@ amInputOutputState am_input_output; InputState* input_state; -uint8_t disable_input_state_update = 0; -bool disable_cursor = false; - extern render_context* rctx_ptr; InputState::DoubleTap::DoubleTap() : hold_frame(), frame(), state() { @@ -328,55 +342,30 @@ void InputState::Update(int32_t index, int32_t delta_frame) { Released |= am_input.released; if (updated) { - field_80[0] = am_input.field_30[0]; - field_80[1] = am_input.field_30[1]; - field_80[2] = am_input.field_30[2]; - field_80[3] = am_input.field_30[3]; - field_80[4] = am_input.field_30[4]; - field_80[5] = am_input.field_30[5]; - field_80[6] = am_input.field_30[6]; - field_80[7] = am_input.field_30[7]; + for (int32_t i = 0; i < 8; i++) + field_80[i] = am_input.field_30[i]; //Added - field_80[8] = am_input.field_30[8]; - field_80[9] = am_input.field_30[9]; - field_80[10] = am_input.field_30[10]; - field_80[11] = am_input.field_30[11]; + for (int32_t i = 8; i < 12; i++) + field_80[i] = am_input.field_30[i]; } - /*if (task_slider_control_get()->sub_140618C60(36)) - am_input.tapped[INPUT_BUTTON_JVS_L] = true; - else - am_input.tapped[INPUT_BUTTON_JVS_L] = false; + /*am_input.tapped[INPUT_BUTTON_JVS_L] = task_slider_control_get()->sub_140618C60(36); + am_input.released[INPUT_BUTTON_JVS_L] = task_slider_control_get()->sub_140618C40(36); + am_input.down[INPUT_BUTTON_JVS_L] = task_slider_control_get()->sub_140618C20(36); - if (task_slider_control_get()->sub_140618C40(36)) - am_input.released[INPUT_BUTTON_JVS_L] = true; - else - am_input.released[INPUT_BUTTON_JVS_L] = false; + am_input.tapped[INPUT_BUTTON_JVS_R] = task_slider_control_get()->sub_140618C60(37); + am_input.released[INPUT_BUTTON_JVS_R] = task_slider_control_get()->sub_140618C40(37); + am_input.down[INPUT_BUTTON_JVS_R] = task_slider_control_get()->sub_140618C20(37);*/ - if (task_slider_control_get()->sub_140618C20(36)) - am_input.down[INPUT_BUTTON_JVS_L] = true; - else - am_input.down[INPUT_BUTTON_JVS_L] = false; - - if (task_slider_control_get()->sub_140618C60(37)) - am_input.tapped[INPUT_BUTTON_JVS_R] = true; - else - am_input.tapped[INPUT_BUTTON_JVS_R] = false; - - if (task_slider_control_get()->sub_140618C40(37)) - am_input.released[INPUT_BUTTON_JVS_R] = true; - else - am_input.released[INPUT_BUTTON_JVS_R] = false; - - if (task_slider_control_get()->sub_140618C20(37)) - am_input.down[INPUT_BUTTON_JVS_R] = true; - else - am_input.down[INPUT_BUTTON_JVS_R] = false;*/ - - Tapped |= am_input.tapped; + Tapped |= am_input.tapped; Released |= am_input.released; - Down |= am_input.down; + Down |= am_input.down; + + // Added + key = 0; + if (am_input.key_ptr) + key = *am_input.key_ptr; Released &= ~Down; @@ -418,31 +407,29 @@ void InputState::Update(int32_t index, int32_t delta_frame) { Toggle ^= Down; ButtonState Down = this->Down; - ButtonState Up = ~this->Down; + ButtonState DownNew = this->Down & ~DownPrev; + ButtonState UpNew = ~this->Down & DownPrev; - ButtonState DoubleTapped; - for (int32_t i = 0; i < INPUT_BUTTON_MAX; i++) - if (DoubleTapData[i].Ctrl(delta_frame, Down[i], Up[i])) - DoubleTapped[i] = true; - else - DoubleTapped[i] = false; - this->DoubleTapped = DoubleTapped; + { + ButtonState DoubleTapped; + for (int32_t i = 0; i < INPUT_BUTTON_MAX; i++) + DoubleTapped[i] = DoubleTapData[i].Ctrl(delta_frame, DownNew[i], UpNew[i]); + this->DoubleTapped = DoubleTapped; + } - ButtonState Hold; - for (int32_t i = 0; i < INPUT_BUTTON_MAX; i++) - if (HoldTapData[i].Ctrl(delta_frame, Down[i], Up[i])) - Hold[i] = true; - else - Hold[i] = false; - this->Hold = Hold; + { + ButtonState Hold; + for (int32_t i = 0; i < INPUT_BUTTON_MAX; i++) + Hold[i] = HoldTapData[i].Ctrl(delta_frame, Down[i], UpNew[i]); + this->Hold = Hold; + } - ButtonState IntervalTapped; - for (int32_t i = 0; i < INPUT_BUTTON_MAX; i++) - if (IntervalTapData[i].Ctrl(delta_frame, Down[i])) - IntervalTapped[i] = true; - else - IntervalTapped[i] = false; - this->IntervalTapped = IntervalTapped; + { + ButtonState IntervalTapped; + for (int32_t i = 0; i < INPUT_BUTTON_MAX; i++) + IntervalTapped[i] = IntervalTapData[i].Ctrl(delta_frame, Down[i]); + this->IntervalTapped = IntervalTapped; + } } int32_t InputState::sub_14018CCC0(int32_t index) const { @@ -461,6 +448,12 @@ void input_state_am_ctrl() { am_input_output_ctrl(); } +// Own stuff +void input_state_pc_ctrl() { + if (input_state) + am_input_output_pc_ctrl(am_input_output.input[0]); +} + void input_state_ctrl() { if (input_state) input_state_ctrl(input_state); @@ -495,6 +488,45 @@ void amInputState::reset() { key_ptr = 0; } +void amInputState::update_modifiers(bool get) { + int32_t modifiers = 0x00; + if (get) + modifiers = get_modifiers(); + + if (modifiers & 0x01) { + if (!down[INPUT_BUTTON_SHIFT]) + tapped[INPUT_BUTTON_SHIFT] = true; + down[INPUT_BUTTON_SHIFT] = true; + } + else { + if (down[INPUT_BUTTON_SHIFT]) + released[INPUT_BUTTON_SHIFT] = true; + down[INPUT_BUTTON_SHIFT] = false; + } + + if (modifiers & 0x02) { + if (!down[INPUT_BUTTON_CONTROL]) + tapped[INPUT_BUTTON_CONTROL] = true; + down[INPUT_BUTTON_CONTROL] = true; + } + else { + if (down[INPUT_BUTTON_CONTROL]) + released[INPUT_BUTTON_CONTROL] = true; + down[INPUT_BUTTON_CONTROL] = false; + } + + if (modifiers & 0x04) { + if (!down[INPUT_BUTTON_ALT]) + tapped[INPUT_BUTTON_ALT] = true; + down[INPUT_BUTTON_ALT] = true; + } + else { + if (down[INPUT_BUTTON_ALT]) + released[INPUT_BUTTON_ALT] = true; + down[INPUT_BUTTON_ALT] = false; + } +} + amOutputState::amOutputState() : data() { } @@ -532,81 +564,78 @@ void amInputOutputState::ctrl() { /*if (v11) { if (v11->field_0[0] & 0x80) - input.down[0] = true; + input.down[INPUT_BUTTON_JVS_TEST] = true; if (v11->field_0[1] & 0x80) - input.down[2] = true; + input.down[JVS_SERVICE] = true; if (v11->field_0[1] & 0x40) - input.down[1] = true; + input.down[JVS_START] = true; if (v11->field_0[1] & 0x20) - input.down[3] = true; + input.down[JVS_UP] = true; if (v11->field_0[1] & 0x10) - input.down[4] = true; + input.down[JVS_DOWN] = true; if (v11->field_0[1] & 0x08) - input.down[5] = true; + input.down[JVS_LEFT] = true; if (v11->field_0[1] & 0x04) - input.down[6] = true; + input.down[JVS_RIGHT] = true; if (v11->field_0[1] & 0x02) - input.down[7] = true; + input.down[JVS_TRIANGLE] = true; if (v11->field_0[1] & 0x01) - input.down[8] = true; + input.down[JVS_SQUARE] = true; if (v11->field_0[2] & 0x80) - input.down[9] = true; + input.down[JVS_CROSS] = true; if (v11->field_0[2] & 0x40) - input.down[10] = true; + input.down[JVS_CIRCLE] = true; if (v11->field_0[2] & 0x20) - input.down[11] = true; + input.down[JVS_L] = true; if (v11->field_0[2] & 0x10) - input.down[12] = true; + input.down[JVS_R] = true; if (v11->field_0[2] & 0x08) - input.down[13] = true; + input.down[JVS_BUTTON_7] = true; if (v11->field_0[2] & 0x04) - input.down[14] = true; + input.down[JVS_BUTTON_8] = true; if (v11->field_0[2] & 0x02) - input.down[15] = true; + input.down[JVS_BUTTON_9] = true; if (v11->field_0[2] & 0x01) - input.down[16] = true; + input.down[JVS_BUTTON_10] = true; - uint16_t* v15 = v11->field_4; - for (size_t j = 0; j < 18; j++, v15++) + for (size_t j = 0; j < 18; j++) if (j < 2) - input.field_30[j] = *v15; + input.field_30[j] = v11->field_4[j]; }*/ - am_input_output_pc_ctrl(input); - - if (input.down[0]) - this->input[0].down[0] = true; - if (input.down[1]) - this->input[0].down[1] = true; + if (input.down[INPUT_BUTTON_JVS_TEST]) + this->input[0].down[INPUT_BUTTON_JVS_TEST] = true; + if (input.down[INPUT_BUTTON_JVS_SERVICE]) + this->input[0].down[INPUT_BUTTON_JVS_SERVICE] = true; } /*struc_807* v16 = sub_14066CA20(); if (v16->field_0[1] & 0x01) { - input[0].down[0] = true; - input[0].down[18] = true; + input[0].down[INPUT_BUTTON_JVS_TEST] = true; + input[0].down[INPUT_BUTTON_JVS_SW1] = true; } if (v16->field_0[1] & 0x02) { - input[0].down[1] = true; - input[0].down[19] = true; + input[0].down[INPUT_BUTTON_JVS_SERVICE] = true; + input[0].down[INPUT_BUTTON_JVS_SW2] = true; } if (v16->field_0[0] & 0x01) - input[0].down[20] = true; + input[0].down[INPUT_BUTTON_DIP_SW1] = true; if (v16->field_0[0] & 0x02) - input[0].down[21] = true; + input[0].down[INPUT_BUTTON_DIP_SW2] = true; if (v16->field_0[0] & 0x04) - input[0].down[22] = true; + input[0].down[INPUT_BUTTON_DIP_SW3] = true; if (v16->field_0[0] & 0x08) - input[0].down[23] = true; + input[0].down[INPUT_BUTTON_DIP_SW4] = true; if (v16->field_0[0] & 0x10) - input[0].down[24] = true; + input[0].down[INPUT_BUTTON_DIP_SW5] = true; if (v16->field_0[0] & 0x20) - input[0].down[25] = true; + input[0].down[INPUT_BUTTON_DIP_SW6] = true; if (v16->field_0[0] & 0x40) - input[0].down[26] = true; + input[0].down[INPUT_BUTTON_DIP_SW7] = true; if (v16->field_0[0] & 0x80) - input[0].down[27] = true;*/ + input[0].down[INPUT_BUTTON_DIP_SW8] = true;*/ for (size_t i = 0; i < 2; i++) { input[i].tapped = input[i].down & ~prev_down[i]; @@ -684,200 +713,38 @@ static bool am_input_output_get_input(amInputState* data, int32_t index) { return true; } +struct glut_input_struct { + uint8_t key; + uint8_t key_last; + int32_t motion_x; + int32_t motion_y; + int32_t scroll_up; + int32_t scroll_down; +}; + +int32_t glut_modifiers; +amInputState glut_pc_input[2]; +amInputState glut_key_input; +amInputState glut_mouse_input; +glut_input_struct glut_input; + // Own stuff static void am_input_output_pc_ctrl(amInputState& input) { - if (disable_input_state_update) - return; + void glut_input_ctrl(); + glut_input_ctrl(); - struct key_map { - int32_t index; - int32_t keys[3]; + input.tapped = glut_pc_input[0].tapped; + input.released = glut_pc_input[0].released; + input.down = glut_pc_input[0].down; - inline key_map() : index(), keys() { - for (int32_t& i : keys) - i = -1; - } - - inline key_map(int32_t index, int32_t key) : key_map() { - this->index = index; - this->keys[0] = key; - } - - inline key_map(int32_t index, int32_t key1, int32_t key2) : key_map() { - this->index = index; - this->keys[0] = key1; - this->keys[1] = key2; - } - - inline key_map(int32_t index, int32_t key1, int32_t key2, int32_t key3) : key_map() { - this->index = index; - this->keys[0] = key1; - this->keys[1] = key2; - this->keys[2] = key3; - } - }; - - static const key_map key_map_array[] = { - { INPUT_BUTTON_0, GLFW_KEY_0, }, - { INPUT_BUTTON_1, GLFW_KEY_1, }, - { INPUT_BUTTON_2, GLFW_KEY_2, }, - { INPUT_BUTTON_3, GLFW_KEY_3, }, - { INPUT_BUTTON_4, GLFW_KEY_4, }, - { INPUT_BUTTON_5, GLFW_KEY_5, }, - { INPUT_BUTTON_6, GLFW_KEY_6, }, - { INPUT_BUTTON_7, GLFW_KEY_7, }, - { INPUT_BUTTON_8, GLFW_KEY_8, }, - { INPUT_BUTTON_9, GLFW_KEY_9, }, - - { INPUT_BUTTON_A, GLFW_KEY_A, }, - { INPUT_BUTTON_B, GLFW_KEY_B, }, - { INPUT_BUTTON_C, GLFW_KEY_C, }, - { INPUT_BUTTON_D, GLFW_KEY_D, }, - { INPUT_BUTTON_E, GLFW_KEY_E, }, - { INPUT_BUTTON_F, GLFW_KEY_F, }, - { INPUT_BUTTON_G, GLFW_KEY_G, }, - { INPUT_BUTTON_H, GLFW_KEY_H, }, - { INPUT_BUTTON_I, GLFW_KEY_I, }, - { INPUT_BUTTON_J, GLFW_KEY_J, }, - { INPUT_BUTTON_K, GLFW_KEY_K, }, - { INPUT_BUTTON_L, GLFW_KEY_L, }, - { INPUT_BUTTON_M, GLFW_KEY_M, }, - { INPUT_BUTTON_N, GLFW_KEY_N, }, - { INPUT_BUTTON_O, GLFW_KEY_O, }, - { INPUT_BUTTON_P, GLFW_KEY_P, }, - { INPUT_BUTTON_Q, GLFW_KEY_Q, }, - { INPUT_BUTTON_R, GLFW_KEY_R, }, - { INPUT_BUTTON_S, GLFW_KEY_S, }, - { INPUT_BUTTON_T, GLFW_KEY_T, }, - { INPUT_BUTTON_U, GLFW_KEY_U, }, - { INPUT_BUTTON_V, GLFW_KEY_V, }, - { INPUT_BUTTON_W, GLFW_KEY_W, }, - { INPUT_BUTTON_X, GLFW_KEY_X, }, - { INPUT_BUTTON_Y, GLFW_KEY_Y, }, - { INPUT_BUTTON_Z, GLFW_KEY_Z, }, - - { INPUT_BUTTON_ESCAPE, GLFW_KEY_ESCAPE, }, - - { INPUT_BUTTON_F1 , GLFW_KEY_F1, }, - { INPUT_BUTTON_F2 , GLFW_KEY_F2, }, - { INPUT_BUTTON_F3 , GLFW_KEY_F3, }, - { INPUT_BUTTON_F4 , GLFW_KEY_F4, }, - { INPUT_BUTTON_F5 , GLFW_KEY_F5, }, - { INPUT_BUTTON_F6 , GLFW_KEY_F6, }, - { INPUT_BUTTON_F7 , GLFW_KEY_F7, }, - { INPUT_BUTTON_F8 , GLFW_KEY_F8, }, - { INPUT_BUTTON_F9 , GLFW_KEY_F9, }, - { INPUT_BUTTON_F10, GLFW_KEY_F10, }, - { INPUT_BUTTON_F11, GLFW_KEY_F11, }, - { INPUT_BUTTON_F12, GLFW_KEY_F12, }, - - { INPUT_BUTTON_BACKSPACE, GLFW_KEY_BACKSPACE, }, - { INPUT_BUTTON_TAB , GLFW_KEY_TAB, }, - { INPUT_BUTTON_ENTER , GLFW_KEY_ENTER, }, - - { INPUT_BUTTON_SHIFT , GLFW_KEY_LEFT_SHIFT, GLFW_KEY_RIGHT_SHIFT, }, - { INPUT_BUTTON_CONTROL, GLFW_KEY_LEFT_CONTROL, GLFW_KEY_RIGHT_CONTROL, }, - { INPUT_BUTTON_ALT , GLFW_KEY_LEFT_ALT, GLFW_KEY_RIGHT_ALT, }, - - { INPUT_BUTTON_SPACE, GLFW_KEY_SPACE, }, - - { INPUT_BUTTON_INSERT , GLFW_KEY_INSERT, }, - { INPUT_BUTTON_HOME , GLFW_KEY_HOME, }, - { INPUT_BUTTON_PAGE_UP , GLFW_KEY_PAGE_UP, }, - { INPUT_BUTTON_DELETE , GLFW_KEY_DELETE, }, - { INPUT_BUTTON_END , GLFW_KEY_END, }, - { INPUT_BUTTON_PAGE_DOWN, GLFW_KEY_PAGE_DOWN, }, - - { INPUT_BUTTON_UP , GLFW_KEY_UP, }, - { INPUT_BUTTON_LEFT , GLFW_KEY_LEFT, }, - { INPUT_BUTTON_DOWN , GLFW_KEY_DOWN, }, - { INPUT_BUTTON_RIGHT, GLFW_KEY_RIGHT, }, - }; - - static const key_map mouse_button_array[] = { - { INPUT_BUTTON_MOUSE_BUTTON_LEFT , GLFW_MOUSE_BUTTON_LEFT, }, - { INPUT_BUTTON_MOUSE_BUTTON_MIDDLE, GLFW_MOUSE_BUTTON_MIDDLE, }, - { INPUT_BUTTON_MOUSE_BUTTON_RIGHT , GLFW_MOUSE_BUTTON_RIGHT, }, - }; - - static const key_map copy_map_array[] = { - { INPUT_BUTTON_JVS_TEST , INPUT_BUTTON_F1, }, - { INPUT_BUTTON_JVS_SERVICE, INPUT_BUTTON_F2, }, - - { INPUT_BUTTON_JVS_START , INPUT_BUTTON_ENTER, }, - - { INPUT_BUTTON_JVS_UP , INPUT_BUTTON_UP, }, - { INPUT_BUTTON_JVS_DOWN , INPUT_BUTTON_DOWN, }, - { INPUT_BUTTON_JVS_LEFT , INPUT_BUTTON_LEFT, }, - { INPUT_BUTTON_JVS_RIGHT, INPUT_BUTTON_RIGHT, }, - - { INPUT_BUTTON_JVS_TRIANGLE, INPUT_BUTTON_W, INPUT_BUTTON_I, }, - { INPUT_BUTTON_JVS_SQUARE , INPUT_BUTTON_A, INPUT_BUTTON_J, }, - { INPUT_BUTTON_JVS_CROSS , INPUT_BUTTON_S, INPUT_BUTTON_K, }, - { INPUT_BUTTON_JVS_CIRCLE , INPUT_BUTTON_D, INPUT_BUTTON_L, }, - - { INPUT_BUTTON_JVS_L, INPUT_BUTTON_Q, INPUT_BUTTON_U, }, - { INPUT_BUTTON_JVS_R, INPUT_BUTTON_E, INPUT_BUTTON_O, }, - - { INPUT_BUTTON_JVS_SW1, INPUT_BUTTON_F11, }, - { INPUT_BUTTON_JVS_SW2, INPUT_BUTTON_F12, }, - }; - - for (const key_map& i : key_map_array) { - bool down = false; - - for (const int32_t& j : i.keys) { - if (j == -1) - break; - - if (!down) - if (Input::IsKeyDown(j, -1)) - down = true; - } - - input.down[i.index] = down; - } - - for (const key_map& i : mouse_button_array) { - bool down = false; - - for (const int32_t& j : i.keys) { - if (j == -1) - break; - - if (Input::IsMouseButtonDown(j)) { - down = true; - break; - } - } - - input.down[i.index] = down; - } - - { - const int32_t index = INPUT_BUTTON_MOUSE_SCROLL_UP; - - input.down[index] = Input::scroll > 0.0; - } - - { - const int32_t index = INPUT_BUTTON_MOUSE_SCROLL_DOWN; - - input.down[index] = Input::scroll < 0.0; - } - - for (const key_map& i : copy_map_array) { - bool down = false; - - for (const int32_t& j : i.keys) { - if (j == -1) - break; - - down |= input.down[j]; - } - - input.down[i.index] = down; - } + input.field_30[0] = glut_pc_input[0].field_30[0]; + input.field_30[1] = glut_pc_input[0].field_30[1]; + input.field_30[2] = glut_pc_input[0].field_30[2]; + input.field_30[3] = glut_pc_input[0].field_30[3]; + input.field_30[4] = glut_pc_input[0].field_30[4]; + input.field_30[5] = glut_pc_input[0].field_30[5]; + input.field_30[6] = glut_pc_input[0].field_30[6]; + input.field_30[7] = glut_pc_input[0].field_30[7]; #if BAKE_PNG || BAKE_VIDEO int32_t x_offset = 0; @@ -891,10 +758,22 @@ static void am_input_output_pc_ctrl(amInputState& input) { float_t y_scale = 720.0f / (float_t)rctx_ptr->sprite_height; #endif - input.field_30[8] = (int32_t)((float_t)(Input::pos.x - x_offset) * x_scale); - input.field_30[9] = (int32_t)((float_t)(Input::pos.y - y_offset) * y_scale); - input.field_30[10] = (int32_t)((float_t)(Input::pos_prev.x - Input::pos.x - x_offset) * x_scale); - input.field_30[11] = (int32_t)((float_t)(Input::pos_prev.y - Input::pos.y - y_offset) * y_scale); + input.field_30[8] = (int32_t)(((float_t)glut_pc_input[0].field_30[8] - x_offset) * x_scale); + input.field_30[9] = (int32_t)(((float_t)glut_pc_input[0].field_30[9] - y_offset) * y_scale); + input.field_30[10] = (int32_t)(((float_t)glut_pc_input[0].field_30[10] - x_offset) * x_scale); + input.field_30[11] = (int32_t)(((float_t)glut_pc_input[0].field_30[11] - y_offset) * y_scale); + + input.field_30[12] = glut_pc_input[0].field_30[12]; + input.field_30[13] = glut_pc_input[0].field_30[12]; + + input.key_ptr = glut_pc_input[0].key_ptr; +} + +static int32_t get_modifiers() { + if (glut_modifiers == -1) + return 0x00; + + return glut_modifiers; } static bool am_input_output_set_output(const amOutputState data, int32_t index) { @@ -914,3 +793,332 @@ static void input_state_ctrl(InputState* input_state) { static int32_t input_state_get_delta_frame() { return 1; } + +static void glut_pc_input_copy_button(InputButton src, InputButton dst); + +void glut_mouse_input_check_mouse_click() { + bool prev_down = glut_mouse_input.down[INPUT_BUTTON_MOUSE_PRESS]; + + glut_mouse_input.released[INPUT_BUTTON_MOUSE_PRESS] = false; + glut_mouse_input.tapped[INPUT_BUTTON_MOUSE_PRESS] = false; + glut_mouse_input.down[INPUT_BUTTON_MOUSE_PRESS] = false; + + if (glut_mouse_input.down[INPUT_BUTTON_MOUSE_BUTTON_LEFT] + || glut_mouse_input.down[INPUT_BUTTON_MOUSE_BUTTON_MIDDLE] + || glut_mouse_input.down[INPUT_BUTTON_MOUSE_BUTTON_RIGHT] + || glut_mouse_input.down[INPUT_BUTTON_MOUSE_SCROLL_UP] + || glut_mouse_input.down[INPUT_BUTTON_MOUSE_SCROLL_DOWN]) + glut_mouse_input.down[INPUT_BUTTON_MOUSE_PRESS] = true; + + if (prev_down) { + if (!glut_mouse_input.down[INPUT_BUTTON_MOUSE_PRESS]) + glut_mouse_input.released[INPUT_BUTTON_MOUSE_PRESS] = true; + } + else { + if (glut_mouse_input.down[INPUT_BUTTON_MOUSE_PRESS]) + glut_mouse_input.tapped[INPUT_BUTTON_MOUSE_PRESS] = true; + } +} + +void glut_input_ctrl() { + int32_t scroll_up = glut_input.scroll_up; + glut_input.scroll_up = 0; + + int32_t motion_x_delta = glut_input.motion_x - glut_mouse_input.field_30[8]; + glut_mouse_input.field_30[8] = glut_input.motion_x; + glut_mouse_input.field_30[10] = motion_x_delta; + + int32_t scroll_down = glut_input.scroll_down; + glut_input.scroll_down = 0; + + int32_t motion_y_delta = glut_input.motion_y - glut_mouse_input.field_30[9]; + glut_mouse_input.field_30[9] = glut_input.motion_y; + glut_mouse_input.field_30[11] = motion_y_delta; + + glut_mouse_input.field_30[12] = scroll_up + (scroll_up == 0 ? 0 : glut_mouse_input.field_30[12]); + glut_mouse_input.field_30[13] = scroll_down + (scroll_down == 0 ? 0 : glut_mouse_input.field_30[13]); + + if ((int32_t)glut_mouse_input.field_30[12] > 0) { + glut_mouse_input.tapped[INPUT_BUTTON_MOUSE_SCROLL_UP] = true; + glut_mouse_input.released[INPUT_BUTTON_MOUSE_SCROLL_UP] = true; + glut_mouse_input.down[INPUT_BUTTON_MOUSE_SCROLL_UP] = false; + } + + if ((int32_t)glut_mouse_input.field_30[13] > 0) { + glut_mouse_input.tapped[INPUT_BUTTON_MOUSE_SCROLL_DOWN] = true; + glut_mouse_input.released[INPUT_BUTTON_MOUSE_SCROLL_DOWN] = true; + glut_mouse_input.down[INPUT_BUTTON_MOUSE_SCROLL_DOWN] = false; + } + + glut_mouse_input_check_mouse_click(); + + if (!glut_key_input.down[INPUT_BUTTON_KEYBOARD_PRESS]) + glut_key_input.update_modifiers(false); + + if (!glut_mouse_input.down[INPUT_BUTTON_MOUSE_PRESS]) + glut_mouse_input.update_modifiers(false); + + glut_pc_input[0].down = glut_key_input.down | glut_mouse_input.down; + glut_pc_input[0].tapped = glut_key_input.tapped | glut_mouse_input.tapped; + glut_pc_input[0].released = glut_key_input.released | glut_mouse_input.released; + + glut_pc_input[0].tapped &= glut_pc_input[0].down; + glut_pc_input[0].released &= ~glut_pc_input[0].down; + + if (glut_mouse_input.tapped[INPUT_BUTTON_MOUSE_SCROLL_UP]) + glut_pc_input[0].tapped[INPUT_BUTTON_MOUSE_SCROLL_UP] = true; + if (glut_mouse_input.tapped[INPUT_BUTTON_MOUSE_SCROLL_DOWN]) + glut_pc_input[0].tapped[INPUT_BUTTON_MOUSE_SCROLL_DOWN] = true; + + for (int32_t i = 0; i < 14; i++) + glut_pc_input[0].field_30[i] = glut_mouse_input.field_30[i]; + + glut_pc_input[0].key_ptr = &glut_input.key_last; + + glut_pc_input_copy_button(INPUT_BUTTON_F1, INPUT_BUTTON_JVS_TEST ); + glut_pc_input_copy_button(INPUT_BUTTON_F2, INPUT_BUTTON_JVS_SERVICE); + + glut_pc_input_copy_button(INPUT_BUTTON_SPACE, INPUT_BUTTON_JVS_START); + + glut_pc_input_copy_button(INPUT_BUTTON_UP , INPUT_BUTTON_JVS_UP ); + glut_pc_input_copy_button(INPUT_BUTTON_DOWN , INPUT_BUTTON_JVS_DOWN ); + glut_pc_input_copy_button(INPUT_BUTTON_LEFT , INPUT_BUTTON_JVS_LEFT ); + glut_pc_input_copy_button(INPUT_BUTTON_RIGHT, INPUT_BUTTON_JVS_RIGHT); + + glut_pc_input_copy_button(INPUT_BUTTON_W, INPUT_BUTTON_JVS_TRIANGLE); + glut_pc_input_copy_button(INPUT_BUTTON_A, INPUT_BUTTON_JVS_SQUARE ); + glut_pc_input_copy_button(INPUT_BUTTON_S, INPUT_BUTTON_JVS_CROSS ); + glut_pc_input_copy_button(INPUT_BUTTON_D, INPUT_BUTTON_JVS_CIRCLE ); + + glut_pc_input_copy_button(INPUT_BUTTON_I, INPUT_BUTTON_JVS_TRIANGLE); + glut_pc_input_copy_button(INPUT_BUTTON_J, INPUT_BUTTON_JVS_SQUARE ); + glut_pc_input_copy_button(INPUT_BUTTON_K, INPUT_BUTTON_JVS_CROSS ); + glut_pc_input_copy_button(INPUT_BUTTON_L, INPUT_BUTTON_JVS_CIRCLE ); + + glut_pc_input_copy_button(INPUT_BUTTON_Q, INPUT_BUTTON_JVS_L); + glut_pc_input_copy_button(INPUT_BUTTON_E, INPUT_BUTTON_JVS_R); + + glut_pc_input_copy_button(INPUT_BUTTON_U, INPUT_BUTTON_JVS_L); + glut_pc_input_copy_button(INPUT_BUTTON_O, INPUT_BUTTON_JVS_R); + + glut_pc_input_copy_button(INPUT_BUTTON_F11, INPUT_BUTTON_JVS_SW1); + glut_pc_input_copy_button(INPUT_BUTTON_F12, INPUT_BUTTON_JVS_SW2); + + glut_input.key_last = glut_input.key; + glut_input.key = 0; + + glut_key_input.tapped = 0; + glut_key_input.released = 0; + glut_mouse_input.tapped = 0; + glut_mouse_input.released = 0; +} + +static void glut_pc_input_copy_button(InputButton src, InputButton dst) { + glut_pc_input[0].down[dst] = glut_pc_input[0].down[dst] | glut_pc_input[0].down[src]; + glut_pc_input[0].tapped[dst] = glut_pc_input[0].tapped[dst] | glut_pc_input[0].tapped[src]; + glut_pc_input[0].released[dst] = glut_pc_input[0].released[dst] | glut_pc_input[0].released[src]; + + glut_pc_input[0].tapped[dst] = glut_pc_input[0].tapped[dst] & glut_pc_input[0].down[dst]; + glut_pc_input[0].released[dst] = glut_pc_input[0].released[dst] & ~glut_pc_input[0].down[dst]; +} + +struct glut_table { + int32_t src; + InputButton dst; +}; + +const glut_table glut_key_table[] = { + { 0x1B, INPUT_BUTTON_ESCAPE }, + { '\b', INPUT_BUTTON_BACKSPACE }, + { '\t', INPUT_BUTTON_TAB }, + { '\r', INPUT_BUTTON_ENTER }, + { ' ', INPUT_BUTTON_SPACE }, + { 0x7F, INPUT_BUTTON_DELETE }, + { -1, INPUT_BUTTON_MAX }, +}; + +const glut_table glut_skey_table[] = { + { 1, INPUT_BUTTON_F1 }, + { 2, INPUT_BUTTON_F2 }, + { 3, INPUT_BUTTON_F3 }, + { 4, INPUT_BUTTON_F4 }, + { 5, INPUT_BUTTON_F5 }, + { 6, INPUT_BUTTON_F6 }, + { 7, INPUT_BUTTON_F7 }, + { 8, INPUT_BUTTON_F8 }, + { 9, INPUT_BUTTON_F9 }, + { 10, INPUT_BUTTON_F10 }, + { 11, INPUT_BUTTON_F11 }, + { 12, INPUT_BUTTON_F12 }, + { 100, INPUT_BUTTON_LEFT }, + { 101, INPUT_BUTTON_UP }, + { 102, INPUT_BUTTON_RIGHT }, + { 103, INPUT_BUTTON_DOWN }, + { 104, INPUT_BUTTON_PAGE_UP }, + { 105, INPUT_BUTTON_PAGE_DOWN }, + { 106, INPUT_BUTTON_HOME }, + { 107, INPUT_BUTTON_END }, + { 108, INPUT_BUTTON_INSERT }, + { -1, INPUT_BUTTON_MAX }, +}; + +void glut_motion_cb(int32_t x, int32_t y); + +static void glut_key_down(int32_t key, const glut_table* table); +static void glut_key_up(int32_t key, const glut_table* table); + +static void glut_mouse_input_down(InputButton button); +static void glut_mouse_input_up(InputButton button); + +static InputButton glut_translate_key(const glut_table* table, int32_t key); + +void glut_get_modifiers() { + int32_t modifiers = 0x00; + if (GetKeyState(VK_SHIFT) & 0xFF00) + modifiers |= 0x01; + if (GetKeyState(VK_CONTROL) & 0xFF00) + modifiers |= 0x02; + if (GetKeyState(VK_MENU) & 0xFF00) + modifiers |= 0x04; + glut_modifiers = modifiers; +} + +void glut_reset_modifiers() { + glut_modifiers = -1; +} + +void glut_keydown_cb(uint8_t key, int32_t x, int32_t y) { + glut_key_down(key, glut_key_table); + glut_input.key = key; +} + +void glut_keyup_cb(uint8_t key, int32_t x, int32_t y) { + glut_key_up(key, glut_key_table); +} + +void glut_skeydown_cb(int32_t key, int32_t x, int32_t y) { + glut_key_down(key, glut_skey_table); +} + +void glut_skeyup_cb(int32_t key, int32_t x, int32_t y) { + glut_key_up(key, glut_skey_table); +} + +void glut_mouse_cb(int32_t bn, int32_t state, int32_t x, int32_t y) { + InputButton button = INPUT_BUTTON_MAX; + + switch (bn) { + case 0: + button = INPUT_BUTTON_MOUSE_BUTTON_LEFT; + break; + case 1: + button = INPUT_BUTTON_MOUSE_BUTTON_MIDDLE; + break; + case 2: + button = INPUT_BUTTON_MOUSE_BUTTON_RIGHT; + break; + case 3: + glut_input.scroll_up++; + break; + case 4: + glut_input.scroll_down++; + break; + } + + if (button != INPUT_BUTTON_MAX) { + switch (state) { + case 0: + glut_mouse_input_down(button); + break; + case 1: + glut_mouse_input_up(button); + break; + } + } + + glut_mouse_input.update_modifiers(true); + + glut_motion_cb(x, y); +} + +void glut_motion_cb(int32_t x, int32_t y) { + resolution_struct res = *res_window_get(); + + glut_input.motion_x = x; + glut_input.motion_y = y; + + glut_input.motion_x = clamp_def(glut_input.motion_x, 0, res.width - 1); + glut_input.motion_y = clamp_def(glut_input.motion_y, 0, res.height - 1); +} + +static void glut_key_down(int32_t key, const glut_table* table) { + InputButton button = glut_translate_key(table, key); + if (button != INPUT_BUTTON_MAX) { + glut_key_input.tapped[button] = true; + glut_key_input.released[button] = false; + glut_key_input.down[button] = true; + + if (!glut_key_input.down[INPUT_BUTTON_KEYBOARD_PRESS]) { + glut_key_input.tapped[INPUT_BUTTON_KEYBOARD_PRESS] = true; + glut_key_input.released[INPUT_BUTTON_KEYBOARD_PRESS] = false; + } + + glut_key_input.down[INPUT_BUTTON_KEYBOARD_PRESS] = true; + } + + glut_key_input.update_modifiers(true); +} + +static void glut_key_up(int32_t key, const glut_table* table) { + InputButton button = glut_translate_key(table, key); + if (button != INPUT_BUTTON_MAX) { + glut_key_input.tapped[button] = false; + glut_key_input.released[button] = true; + glut_key_input.down[button] = false; + + if (glut_key_input.down[INPUT_BUTTON_KEYBOARD_PRESS]) { + glut_key_input.tapped[INPUT_BUTTON_KEYBOARD_PRESS] = false; + glut_key_input.released[INPUT_BUTTON_KEYBOARD_PRESS] = true; + } + + glut_key_input.down[INPUT_BUTTON_KEYBOARD_PRESS] = false; + } + + glut_key_input.update_modifiers(true); +} + +static void glut_mouse_input_down(InputButton button) { + glut_mouse_input.released[button] = false; + if (!glut_mouse_input.down[button]) + glut_mouse_input.tapped[button] = true; + glut_mouse_input.down[button] = true; +} + +static void glut_mouse_input_up(InputButton button) { + glut_mouse_input.tapped[button] = false; + if (glut_mouse_input.down[button]) + glut_mouse_input.released[button] = true; + glut_mouse_input.down[button] = false; +} + +static InputButton glut_translate_key(const glut_table* table, int32_t key) { + InputButton button = INPUT_BUTTON_MAX; + if (table == glut_key_table) { + if ((key - 'a') >= 0 && (key - 'a') <= ('z' - 'a')) + return (InputButton)(INPUT_BUTTON_A + (key - 'a')); // A - Z + else if ((key - 'A') >= 0 && (key - 'A') <= ('Z' - 'A')) + return (InputButton)(INPUT_BUTTON_A + (key - 'A')); // A - Z + else if ((key - '0') >= 0 && (key - '0') <= ('9' - '0')) + return (InputButton)(INPUT_BUTTON_0 + (key - '0')); // 0 - 9 + } + + while (table->src >= 0) { + if (table->src == key) { + button = table->dst; + break; + } + table++; + } + + return button; +} diff --git a/src/ReDIVA/input_state.hpp b/src/ReDIVA/input_state.hpp index 53211cbc..baff9b41 100644 --- a/src/ReDIVA/input_state.hpp +++ b/src/ReDIVA/input_state.hpp @@ -29,10 +29,24 @@ enum InputButton : int32_t { INPUT_BUTTON_JVS_L, INPUT_BUTTON_JVS_R, + INPUT_BUTTON_JVS_BUTTON_7, + INPUT_BUTTON_JVS_BUTTON_8, + INPUT_BUTTON_JVS_BUTTON_9, + INPUT_BUTTON_JVS_BUTTON_10, + INPUT_BUTTON_JVS_SW1 = 18, INPUT_BUTTON_JVS_SW2, - INPUT_BUTTON_KEYBOARD_PRESS = 28, + INPUT_BUTTON_DIP_SW1, + INPUT_BUTTON_DIP_SW2, + INPUT_BUTTON_DIP_SW3, + INPUT_BUTTON_DIP_SW4, + INPUT_BUTTON_DIP_SW5, + INPUT_BUTTON_DIP_SW6, + INPUT_BUTTON_DIP_SW7, + INPUT_BUTTON_DIP_SW8, + + INPUT_BUTTON_KEYBOARD_PRESS, INPUT_BUTTON_0, INPUT_BUTTON_1, @@ -196,6 +210,7 @@ struct InputState { extern void input_state_init(); extern void input_state_am_ctrl(); +extern void input_state_pc_ctrl(); extern void input_state_ctrl(); extern const InputState* input_state_get(int32_t index); extern void input_state_free(); diff --git a/src/ReDIVA/main.hpp b/src/ReDIVA/main.hpp index 7a0b1865..8306b7d4 100644 --- a/src/ReDIVA/main.hpp +++ b/src/ReDIVA/main.hpp @@ -7,4 +7,3 @@ #include "../KKdLib/default.hpp" #include "app.hpp" -#include "input.hpp" diff --git a/src/ReDIVA/pv_game/pv_game.cpp b/src/ReDIVA/pv_game/pv_game.cpp index bc408a1c..88cbabb5 100644 --- a/src/ReDIVA/pv_game/pv_game.cpp +++ b/src/ReDIVA/pv_game/pv_game.cpp @@ -21,7 +21,7 @@ #include "../am_data.hpp" #include "../game_state.hpp" #include "../imgui_helper.hpp" -#include "../input.hpp" +#include "../input_state.hpp" #include "../mask_screen.hpp" #include "../task_movie.hpp" #include "../wait_screen.hpp" @@ -4991,22 +4991,23 @@ void pv_game::sub_140104FB0() { } bool pv_game::sub_14010EF00() { - //InputState* input_state = input_state_get(0); + //const InputState* input_state = input_state_get(0); if (!wrap_collection_get()->give_up.get_value()) return false; /*bool v5 = task_slider_control_get()->sub_140618C20(38) - && input_state->sub_14018D480(10) && input_state->sub_14018D480(7); + && input_state->CheckDown(INPUT_BUTTON_JVS_CIRCLE) + && input_state->CheckDown(INPUT_BUTTON_JVS_TRIANGLE); switch (data.field_2DB34) { case 0: - if (v5 && input_state->sub_14018D510(2)) { + if (v5 && input_state->CheckTapped(INPUT_BUTTON_JVS_START)) { data.field_2DB34 = 1; data.field_2DB38.get_timestamp(); data.field_2D0AC = sub_14010F930(); } break; case 1: - if (!v5 || !input_state->sub_14018D480(2)) { + if (!v5 || !input_state->CheckDown(INPUT_BUTTON_JVS_START)) { sub_14010F030(); data.field_2DB34 = 0; data.field_2D0AC = 0; @@ -5315,12 +5316,13 @@ void TaskPvGame::window() { if (data.type != 2 || pv_game_parent_data.outer_state != 1) return; - if (Input::IsKeyTapped(GLFW_KEY_K, GLFW_MOD_CONTROL)) + const InputState* input_state = input_state_get(0); + if (input_state->CheckTapped(INPUT_BUTTON_K) && input_state->CheckDown(INPUT_BUTTON_CONTROL)) pv_game_ptr->end_pv = true; - else if (Input::IsKeyTapped(GLFW_KEY_K)) + else if (input_state->CheckTapped(INPUT_BUTTON_K)) pause ^= true; - if (Input::IsKeyTapped(GLFW_KEY_L)) { + if (input_state->CheckTapped(INPUT_BUTTON_L)) { pause = true; step_frame = true; } diff --git a/src/ReDIVA/x_pv_game.cpp b/src/ReDIVA/x_pv_game.cpp index 5cfecf59..08a757c1 100644 --- a/src/ReDIVA/x_pv_game.cpp +++ b/src/ReDIVA/x_pv_game.cpp @@ -55,7 +55,7 @@ #endif #include "information/dw_console.hpp" #include "imgui_helper.hpp" -#include "input.hpp" +#include "input_state.hpp" #include "print_work.hpp" #include @@ -8359,12 +8359,13 @@ void x_pv_game::window() { if (state_old != 20) return; - if (Input::IsKeyTapped(GLFW_KEY_K, GLFW_MOD_CONTROL)) + const InputState* input_state = input_state_get(0); + if (input_state->CheckTapped(INPUT_BUTTON_K) && input_state->CheckDown(INPUT_BUTTON_CONTROL)) state_old = 21; - else if (Input::IsKeyTapped(GLFW_KEY_K)) + else if (input_state->CheckTapped(INPUT_BUTTON_K)) pause ^= true; - if (Input::IsKeyTapped(GLFW_KEY_L)) { + if (input_state->CheckTapped(INPUT_BUTTON_L)) { pause = true; step_frame = true; }