diff options
Diffstat (limited to 'src/util')
| -rw-r--r-- | src/util/allocator.h | 18 | ||||
| -rw-r--r-- | src/util/input.cpp | 10 | ||||
| -rw-r--r-- | src/util/input.h | 8 |
3 files changed, 28 insertions, 8 deletions
diff --git a/src/util/allocator.h b/src/util/allocator.h index 7927b9c..27b21c0 100644 --- a/src/util/allocator.h +++ b/src/util/allocator.h @@ -165,8 +165,12 @@ struct LIST { if( size > capacity ) reserve( size * 2 ); - if( size < capacity ) { - for( U32 i = size; i < capacity; ++i ) + if( size < capacity / 4 ) + shrink(); + + if( this->size < size ) { + memset( &data[this->size], 0, sizeof(T) * (size - this->size) ); + for( U32 i = this->size; i < size; ++i ) data[i] = T(); } @@ -262,6 +266,16 @@ struct LIST { return -1; } + I32 idx_of( const T* what ) { + for( U32 i = 0; i < size; ++i ) { + if( &data[i] == what ) { + return i; + } + } + + return -1; + } + I32 idx_where( ON_SEARCH_FN what ) { for( U32 i = 0; i < size; ++i ) { if( what( &data[i] ) ) { diff --git a/src/util/input.cpp b/src/util/input.cpp index 225b696..284ebfe 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.mpitch; + input.mouse.pos_delta.y += (F32)e->motion.yrel * input.myaw; } break; case SDL_KEYDOWN: { input.keys[e->key.keysym.sym & 0xff] = 1; @@ -79,8 +79,12 @@ void input_frame_end() { input.mouse.wheel = 0; } +U8 input_is_key_down( U32 key ) { + return input.keys[key]; +} + void input_capture_mouse( bool capture ) { input_reset_mouse_accumulator(); - input.mouse_captured = capture; + input.mouselock = capture; SDL_SetRelativeMouseMode( capture ? SDL_TRUE : SDL_FALSE ); } diff --git a/src/util/input.h b/src/util/input.h index ec901ab..86d715c 100644 --- a/src/util/input.h +++ b/src/util/input.h @@ -38,8 +38,10 @@ using ON_INPUT_FN = std::function<void( SDL_Event* )>; struct INPUT_DATA { MOUSE_DATA mouse; U8 keys[0xff]; - bool mouse_captured; - F32 mouse_sensitivity = .3f; + bool mouselock; + F32 msens = .3f; + F32 myaw = 1.f; + F32 mpitch = 1.f; INPUT_KEYBINDS binds; LIST<ON_INPUT_FN> on_input; @@ -51,7 +53,7 @@ extern INPUT_DATA input; extern void input_frame_end(); 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 U8 input_is_key_down( U32 key ); extern void input_capture_mouse( bool capture ); extern void input_reset_mouse_accumulator(); |
