summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/input.cpp11
-rw-r--r--src/util/input.h15
2 files changed, 21 insertions, 5 deletions
diff --git a/src/util/input.cpp b/src/util/input.cpp
index 7e94c47..225b696 100644
--- a/src/util/input.cpp
+++ b/src/util/input.cpp
@@ -27,8 +27,8 @@ void input_on_event( SDL_Event* e ) {
case SDL_MOUSEMOTION: {
input.mouse.pos.x = (F32)e->motion.x;
input.mouse.pos.y = (F32)e->motion.y;
- input.mouse.pos_delta.x = (F32)e->motion.xrel;
- input.mouse.pos_delta.y = (F32)e->motion.yrel;
+ input.mouse.pos_delta.x += (F32)e->motion.xrel;
+ input.mouse.pos_delta.y += (F32)e->motion.yrel;
} break;
case SDL_KEYDOWN: {
input.keys[e->key.keysym.sym & 0xff] = 1;
@@ -39,6 +39,10 @@ void input_on_event( SDL_Event* e ) {
}
}
+extern void input_reset_mouse_accumulator() {
+ input.mouse.pos_delta.x = 0;
+ input.mouse.pos_delta.y = 0;
+}
void input_on_mouse( I32 type, I32 x, I32 y ) {
if( type == MOUSEEV_MOVE ) {
@@ -73,11 +77,10 @@ void input_on_mouse( I32 type, I32 x, I32 y ) {
void input_frame_end() {
input.mouse.wheel = 0;
- input.mouse.pos_delta.x = 0;
- input.mouse.pos_delta.y = 0;
}
void input_capture_mouse( bool capture ) {
+ input_reset_mouse_accumulator();
input.mouse_captured = capture;
SDL_SetRelativeMouseMode( capture ? SDL_TRUE : SDL_FALSE );
}
diff --git a/src/util/input.h b/src/util/input.h
index 4885f0f..ec901ab 100644
--- a/src/util/input.h
+++ b/src/util/input.h
@@ -23,15 +23,27 @@ struct MOUSE_DATA {
U8 wheel;
};
+struct INPUT_KEYBINDS {
+ U8 fwd = 'w';
+ U8 back = 's';
+ U8 left = 'a';
+ U8 right = 'd';
+
+ U8 jump = ' ';
+ U8 crouch = SDL_SCANCODE_LCTRL;
+};
+
using ON_INPUT_FN = std::function<void( SDL_Event* )>;
struct INPUT_DATA {
MOUSE_DATA mouse;
U8 keys[0xff];
bool mouse_captured;
- F32 mouse_sensitivity = 1.0f;
+ F32 mouse_sensitivity = .3f;
+ INPUT_KEYBINDS binds;
LIST<ON_INPUT_FN> on_input;
+
};
extern INPUT_DATA input;
@@ -41,5 +53,6 @@ extern void input_on_event( SDL_Event* e );
extern void input_on_mouse( I32 type, I32 x, I32 y );
extern void input_is_key_down( U32 key );
extern void input_capture_mouse( bool capture );
+extern void input_reset_mouse_accumulator();
#define kb_down( key ) input_is_key_down( key )