diagonal
[vg.git] / vg_platform.h
index 6707af7cab28a4862211f569b0c0660c5e84cc93..52c26c0933fc67ecabb60b6bb2e5a772b6d50257 100644 (file)
@@ -1,6 +1,12 @@
 #ifndef VG_PLATFORM_H
 #define VG_PLATFORM_H
 
+#ifdef VG_RELEASE
+ #define VG_STATIC static
+#else
+ #define VG_STATIC
+#endif
+
 //#include "vg.h"
 #include "vg_stdint.h"
 
@@ -29,28 +35,38 @@ struct vg_achievement
        const char *name;
 };
 
-#ifndef VG_STATIC
-#define VG_STATIC static
-#endif
-
 #define vg_static_assert _Static_assert
 #define vg_list_size( A ) (sizeof(A)/sizeof(A[0]))
 #define VG_MUST_USE_RESULT __attribute__((warn_unused_result))
 
-VG_STATIC void vg_strncpy( const char *src, char *dst, u32 len )
+enum strncpy_behaviour{
+   k_strncpy_always_add_null = 0,
+   k_strncpy_allow_cutoff = 1
+};
+
+VG_STATIC void vg_strncpy( const char *src, char *dst, u32 len,
+                           enum strncpy_behaviour behaviour )
 {
-   for( u32 i=0; i<len; i++ )
-   {
+   for( u32 i=0; i<len; i++ ){
       dst[i] = src[i];
 
       if( !src[i] )
          break;
+
+      if( (behaviour == k_strncpy_always_add_null) && (i == len-1) )
+         dst[i] = '\0';
    }
 }
 
-#define VG_REQUIRED_ASSET( TYPE, DECL, FN, PATH, ... )                         \
-   TYPE DECL = FN( PATH,##__VA_ARGS__ );                                       \
-   vg_required( DECL, "Resource is required but failed to load: '" PATH "'" );
+VG_STATIC u32 vg_strdjb2( const char *str )
+{
+   u32 hash = 5381, c;
+
+   while( (c = *str++) )
+      hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
+
+   return hash;
+}
 
 #include <stdio.h>
 #include <dirent.h>
@@ -62,5 +78,4 @@ VG_STATIC void vg_strncpy( const char *src, char *dst, u32 len )
 
 #define VG_MIN( A, B ) ((A)<(B)?(A):(B))
 #define VG_MAX( A, B ) ((A)>(B)?(A):(B))
-
 #endif