mirror of
https://github.com/korenkonder/ReDIVA.git
synced 2026-10-13 01:28:10 +03:00
v0.4.0.0
This commit is contained in:
+70
-74
@@ -7,7 +7,8 @@
|
||||
|
||||
#include "input.h"
|
||||
#include "../KKdLib/vec.h"
|
||||
#include "../CRE/microui.h"
|
||||
#define CIMGUI_DEFINE_ENUMS_AND_STRUCTS
|
||||
#include <cimgui.h>
|
||||
|
||||
#define KEYBOARD_KEYS 0xFF
|
||||
|
||||
@@ -17,8 +18,6 @@ typedef struct key_state {
|
||||
|
||||
typedef struct mouse_state {
|
||||
POINT position;
|
||||
double_t scroll_x;
|
||||
double_t scroll_y;
|
||||
} mouse_state;
|
||||
|
||||
key_state input_key_current_state;
|
||||
@@ -27,17 +26,19 @@ key_state input_key_last_state;
|
||||
mouse_state input_mouse_current_state;
|
||||
mouse_state input_mouse_last_state;
|
||||
|
||||
float_t input_movement_speed = 1.0f;
|
||||
float_t input_rotation_sensitivity = 0.5f;
|
||||
vec2 input_move;
|
||||
vec2 input_rotate;
|
||||
double_t input_movement_speed = 0.1;
|
||||
double_t input_rotation_sensitivity = 0.5;
|
||||
vec2d input_move;
|
||||
vec2d input_rotate;
|
||||
double_t input_roll;
|
||||
bool input_reset;
|
||||
bool input_reset_mouse_position;
|
||||
bool input_locked;
|
||||
|
||||
extern bool close;
|
||||
HANDLE input_lock = 0;
|
||||
lock_val(input_lock);
|
||||
extern HANDLE render_lock;
|
||||
extern HANDLE window_handle;
|
||||
extern HANDLE mu_input_lock;
|
||||
|
||||
void input_poll();
|
||||
|
||||
@@ -47,19 +48,22 @@ timer_val(input);
|
||||
|
||||
int32_t input_main(void* arg) {
|
||||
timer_init(input, "Input");
|
||||
input_lock = CreateMutexW(0, 0, L"Input");
|
||||
if (!input_lock)
|
||||
lock_init(input_lock);
|
||||
if (!input_lock_init)
|
||||
goto End;
|
||||
|
||||
while (state != RENDER_INITIALIZED)
|
||||
msleep(input_timer, 0.0625);
|
||||
|
||||
while (!close) {
|
||||
timer_calc_pre(input);
|
||||
WaitForSingleObject(input_lock, INFINITE);
|
||||
lock_lock(input_lock);
|
||||
input_poll();
|
||||
ReleaseMutex(input_lock);
|
||||
lock_unlock(input_lock);
|
||||
double_t cycle_time = timer_calc_post(input);
|
||||
msleep(input_timer, 1000.0 / FREQ - cycle_time);
|
||||
}
|
||||
CloseHandle(input_lock);
|
||||
lock_dispose(input_lock);
|
||||
|
||||
End:
|
||||
timer_dispose(input);
|
||||
@@ -70,6 +74,7 @@ void input_poll() {
|
||||
input_mouse_last_state = input_mouse_current_state;
|
||||
input_key_last_state = input_key_current_state;
|
||||
|
||||
ImGuiIO* io = igGetIO();
|
||||
for (uint8_t i = 0; i < KEYBOARD_KEYS; i++)
|
||||
input_key_current_state.key_states[i] = GetAsyncKeyState(i) < 0;
|
||||
|
||||
@@ -78,57 +83,69 @@ void input_poll() {
|
||||
ScreenToClient(window_handle, &input_mouse_current_state.position);
|
||||
}
|
||||
|
||||
input_rotate.x = 0.0f;
|
||||
input_rotate.y = 0.0f;
|
||||
input_move.x = 0.0f;
|
||||
input_move.y = 0.0f;
|
||||
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 (!window_handle || window_handle != GetForegroundWindow() || (muctx && muctx->text_input))
|
||||
if (!window_handle || window_handle != GetForegroundWindow())
|
||||
return;
|
||||
|
||||
float_t temp_input_movement_speed = input_movement_speed / 10.0f;
|
||||
if (input_is_down(VK_SHIFT))
|
||||
temp_input_movement_speed = input_movement_speed;
|
||||
else if (input_is_down(VK_CONTROL))
|
||||
temp_input_movement_speed = input_movement_speed / 100.0f;
|
||||
input_locked = false;
|
||||
classes_process_input(classes, classes_count);
|
||||
|
||||
if (input_is_down('W'))
|
||||
input_move.x += temp_input_movement_speed;
|
||||
if (input_is_down('A'))
|
||||
input_move.y -= temp_input_movement_speed;
|
||||
if (input_is_down('S'))
|
||||
input_move.x -= temp_input_movement_speed;
|
||||
if (input_is_down('D'))
|
||||
input_move.y += temp_input_movement_speed;
|
||||
if (!input_locked) {
|
||||
double_t speed;
|
||||
if (input_is_down(VK_SHIFT))
|
||||
speed = input_movement_speed * 10.0;
|
||||
else if (input_is_down(VK_CONTROL))
|
||||
speed = input_movement_speed / 10.0;
|
||||
else
|
||||
speed = input_movement_speed;
|
||||
|
||||
temp_input_movement_speed = input_movement_speed;
|
||||
if (input_is_down(VK_SHIFT))
|
||||
temp_input_movement_speed = input_movement_speed * 10.0f;
|
||||
else if (input_is_down(VK_CONTROL))
|
||||
temp_input_movement_speed = input_movement_speed / 10.0f;
|
||||
if (input_is_down('W'))
|
||||
input_move.x += speed;
|
||||
if (input_is_down('S'))
|
||||
input_move.x -= speed;
|
||||
|
||||
if (input_is_down(VK_UP))
|
||||
input_rotate.y += temp_input_movement_speed;
|
||||
if (input_is_down(VK_LEFT))
|
||||
input_rotate.x -= temp_input_movement_speed;
|
||||
if (input_is_down(VK_DOWN))
|
||||
input_rotate.y -= temp_input_movement_speed;
|
||||
if (input_is_down(VK_RIGHT))
|
||||
input_rotate.x += temp_input_movement_speed;
|
||||
if (input_is_down('A'))
|
||||
input_move.y -= speed;
|
||||
if (input_is_down('D'))
|
||||
input_move.y += speed;
|
||||
|
||||
if (input_is_tapped('R'))
|
||||
input_reset = true;
|
||||
if (input_is_down(VK_SHIFT))
|
||||
speed = input_movement_speed * 100.0;
|
||||
else if (input_is_down(VK_CONTROL))
|
||||
speed = input_movement_speed;
|
||||
else
|
||||
speed = input_movement_speed * 10.0;
|
||||
|
||||
for (size_t i = 0; i < classes_count; i++)
|
||||
if (classes[i].input)
|
||||
classes[i].input();
|
||||
if (input_is_down(VK_UP))
|
||||
input_rotate.y += speed;
|
||||
if (input_is_down(VK_DOWN))
|
||||
input_rotate.y -= speed;
|
||||
|
||||
if (input_is_down(VK_MBUTTON)) {
|
||||
if (input_is_down(VK_LEFT))
|
||||
input_rotate.x -= speed;
|
||||
if (input_is_down(VK_RIGHT))
|
||||
input_rotate.x += speed;
|
||||
|
||||
if (input_is_down('Q'))
|
||||
input_roll -= speed;
|
||||
if (input_is_down('E'))
|
||||
input_roll += speed;
|
||||
|
||||
if (input_is_tapped('R'))
|
||||
input_reset = true;
|
||||
}
|
||||
|
||||
if (!io->WantCaptureMouse && input_is_down(VK_MBUTTON)) {
|
||||
if (!input_reset_mouse_position) {
|
||||
POINT last = input_mouse_last_state.position;
|
||||
POINT curr = input_mouse_current_state.position;
|
||||
input_rotate.y += (float_t)(((double_t)last.y - (double_t)curr.y) * input_rotation_sensitivity);
|
||||
input_rotate.x += (float_t)(((double_t)curr.x - (double_t)last.x) * input_rotation_sensitivity);
|
||||
input_rotate.y += ((double_t)last.y - (double_t)curr.y) * input_rotation_sensitivity;
|
||||
input_rotate.x += ((double_t)curr.x - (double_t)last.x) * input_rotation_sensitivity;
|
||||
}
|
||||
input_reset_mouse_position = false;
|
||||
}
|
||||
@@ -163,24 +180,3 @@ inline bool input_was_up(uint8_t keycode) {
|
||||
inline POINT input_mouse_position() {
|
||||
return input_mouse_current_state.position;
|
||||
}
|
||||
|
||||
inline void input_mouse_reset_scroll() {
|
||||
input_mouse_current_state.scroll_x = 0.0f;
|
||||
input_mouse_current_state.scroll_y = 0.0f;
|
||||
}
|
||||
|
||||
inline double_t input_mouse_scroll_x() {
|
||||
return input_mouse_current_state.scroll_x;
|
||||
}
|
||||
|
||||
inline double_t input_mouse_scroll_y() {
|
||||
return input_mouse_current_state.scroll_y;
|
||||
}
|
||||
|
||||
inline void input_mouse_add_scroll_x(double_t value) {
|
||||
input_mouse_current_state.scroll_x += value;
|
||||
}
|
||||
|
||||
inline void input_mouse_add_scroll_y(double_t value) {
|
||||
input_mouse_current_state.scroll_y += value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user