summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/fnv.h8
-rw-r--r--src/util/input.cpp2
-rw-r--r--src/util/input.h4
-rw-r--r--src/util/string.h30
4 files changed, 32 insertions, 12 deletions
diff --git a/src/util/fnv.h b/src/util/fnv.h
index 534063d..679bea9 100644
--- a/src/util/fnv.h
+++ b/src/util/fnv.h
@@ -1,4 +1,5 @@
#pragma once
+#include "string.h"
#include "typedef.h"
typedef U32 FNV1A;
@@ -8,13 +9,6 @@ enum : FNV1A {
FNV1A_BASIS = 0x811C9DC5
};
-inline constexpr U32 strlen_ct( const char* str ) {
- U32 s = 0;
- for( ; !!str[s]; ++s );
-
- return s;
-}
-
inline constexpr FNV1A fnv1a( const U8* data, const U32 size ) {
FNV1A out = FNV1A_BASIS;
diff --git a/src/util/input.cpp b/src/util/input.cpp
index 284ebfe..1222658 100644
--- a/src/util/input.cpp
+++ b/src/util/input.cpp
@@ -83,7 +83,7 @@ U8 input_is_key_down( U32 key ) {
return input.keys[key];
}
-void input_capture_mouse( bool capture ) {
+void input_capture_mouse( U8 capture ) {
input_reset_mouse_accumulator();
input.mouselock = capture;
SDL_SetRelativeMouseMode( capture ? SDL_TRUE : SDL_FALSE );
diff --git a/src/util/input.h b/src/util/input.h
index 86d715c..1317f94 100644
--- a/src/util/input.h
+++ b/src/util/input.h
@@ -38,7 +38,7 @@ using ON_INPUT_FN = std::function<void( SDL_Event* )>;
struct INPUT_DATA {
MOUSE_DATA mouse;
U8 keys[0xff];
- bool mouselock;
+ U8 mouselock;
F32 msens = .3f;
F32 myaw = 1.f;
F32 mpitch = 1.f;
@@ -54,7 +54,7 @@ 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 U8 input_is_key_down( U32 key );
-extern void input_capture_mouse( bool capture );
+extern void input_capture_mouse( U8 capture );
extern void input_reset_mouse_accumulator();
#define kb_down( key ) input_is_key_down( key )
diff --git a/src/util/string.h b/src/util/string.h
index b261e76..47da1a0 100644
--- a/src/util/string.h
+++ b/src/util/string.h
@@ -3,9 +3,15 @@
#include "typedef.h"
+constexpr U32 strlen_ct( const char* str ) {
+ U32 len = 0;
+ for( ; !!str[len]; ++len );
+ return len;
+}
+
template <U32 N>
struct STR {
- char data[N];
+ char data[N]{ 0 };
enum {
size = N
};
@@ -13,11 +19,31 @@ struct STR {
memset( data, 0, N );
}
STR( const char* str ) {
- memcpy( data, str, N );
+ memcpy( data, str, strlen_ct( str ) );
}
STR( const STR<N>& str ) {
memcpy( data, str.data, N );
}
+ template <U32 other>
+ auto operator+( const STR<other>& rhs ) {
+ constexpr U32 l1 = strlen_ct( data );
+ constexpr U32 l2 = strlen_ct( rhs.data );
+
+ constexpr U32 high = N > other ? N : other;
+ constexpr U32 max = (l1 + l2 > high) ? l1 + l2 + 1 : high;
+
+ STR<max> result;
+ memcpy( result.data, data, l1 );
+ memcpy( result.data + l1, rhs.data, l2 );
+ result.data[l1 + l2] = '\0';
+ return result;
+ }
+
+ template <U32 other>
+ auto concat( const STR<other>& str ) {
+ return *this + str;
+ }
+
operator char*() { return data; }
};