bad char
[vg.git] / vg_platform.h
index 52c26c0933fc67ecabb60b6bb2e5a772b6d50257..b846b06a4056356e8b0825f6621c3a337303a10b 100644 (file)
@@ -1,19 +1,21 @@
-#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"
-
-/* Copyright (C) 2021-2022 Harry Godden (hgn) - All Rights Reserved */
+#pragma once
+
+#include <stdlib.h>
+#include <stdint.h>
+
+typedef uint8_t  u8;
+typedef uint16_t u16;
+typedef uint32_t u32;
+typedef uint64_t u64;
+typedef int8_t   i8;
+typedef int16_t  i16;
+typedef int32_t  i32;
+typedef int64_t  i64;
+typedef float    f32;
+typedef double   f64;
+typedef uint8_t  bool;
 
 typedef unsigned int uint;
-
 typedef int            v2i[2];
 typedef int            v3i[3];
 typedef int            v4i[4];
@@ -26,56 +28,15 @@ typedef v3f                 m4x3f[4];
 typedef v4f       m4x4f[4];
 typedef v3f                    boxf[2];
 
-// Resource types
-typedef struct vg_tex2d vg_tex2d;
-
-struct vg_achievement
-{
-       int is_set;
-       const char *name;
-};
-
-#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))
-
-enum strncpy_behaviour{
-   k_strncpy_always_add_null = 0,
-   k_strncpy_allow_cutoff = 1
-};
+/* anything compiled against VG shall implement this function somewhere. */
+void vg_fatal_error( const char *fmt, ... );
 
-VG_STATIC void vg_strncpy( const char *src, char *dst, u32 len,
-                           enum strncpy_behaviour behaviour )
-{
-   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_ASSERT( ITEM, ... ) \
+   if( !( ITEM ) ) { \
+      vg_fatal_error( "Assertion failed: " VG_LOG_MCSTR(ITEM) "\n" \
+                      VG_LOG_WHERE ); \
    }
-}
-
-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>
-#include <string.h>
-#include <stdarg.h>
-#include <ctype.h>
-#include <math.h>
-#include <assert.h>
 
 #define VG_MIN( A, B ) ((A)<(B)?(A):(B))
 #define VG_MAX( A, B ) ((A)>(B)?(A):(B))
-#endif
+#define vg_list_size( A ) (sizeof(A)/sizeof(A[0]))