X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=vg_platform.h;h=5ec7287ab436d692f8fb40141627b790ed423cd5;hb=3b14f3dcd5bf9dd3c85144f2123d667bfa4bb63f;hp=1b0317c0c30b0b43ff971fa97c01370eb89987de;hpb=127f6fa3df70c71f53199b32d4468c79e8bcd022;p=vg.git diff --git a/vg_platform.h b/vg_platform.h index 1b0317c..5ec7287 100644 --- a/vg_platform.h +++ b/vg_platform.h @@ -1,31 +1,7 @@ -#ifndef VG_PLATFORM_H -#define VG_PLATFORM_H +#pragma once -#ifdef VG_RELEASE - #define VG_STATIC static -#else - #define VG_STATIC -#endif - -//#include "vg.h" +#if 0 #include "vg_stdint.h" - -/* Copyright (C) 2021-2022 Harry Godden (hgn) - All Rights Reserved */ - -typedef unsigned int uint; - -typedef int v2i[2]; -typedef int v3i[3]; -typedef int v4i[4]; -typedef float v2f[2]; -typedef float v3f[3]; -typedef float v4f[4]; -typedef v2f m2x2f[2]; -typedef v3f m3x3f[3]; -typedef v3f m4x3f[4]; -typedef v4f m4x4f[4]; -typedef v3f boxf[2]; - // Resource types typedef struct vg_tex2d vg_tex2d; @@ -36,9 +12,9 @@ struct vg_achievement }; #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)) + #include #include #include @@ -50,103 +26,40 @@ struct vg_achievement #include #include #include +#include +#endif -enum strncpy_behaviour{ - k_strncpy_always_add_null = 0, - k_strncpy_allow_cutoff = 1, - k_strncpy_overflow_fatal = 2 -}; - -VG_STATIC void vg_fatal_error( const char *fmt, ... ); -VG_STATIC u32 vg_strncpy( const char *src, char *dst, u32 len, - enum strncpy_behaviour behaviour ) -{ - for( u32 i=0; ibuffer = buffer; - str->buffer[0] = '\0'; - str->i = 0; - str->len = len; -} - -VG_STATIC void vg_strcat( vg_str *str, const char *append ) -{ - if( !append ) return; - for( u32 i=0; str->i < str->len; i++, str->i ++ ){ - str->buffer[ str->i ] = append[i]; - - if( append[i] == '\0' ) return; - } -} - -VG_STATIC int vg_strgood( vg_str *str ) -{ - if( str->i == str->len ){ - if( str->buffer[str->i -1] == '\0' ) return 1; - else return 0; - } - else return 1; -} - -VG_STATIC char *vg_strch( vg_str *str, char c ) -{ - char *ptr = NULL; - for( u32 i=0; ii; i++ ){ - if( str->buffer[i] == c ) - ptr = str->buffer+i; - } - - return ptr; -} - -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; -} - -VG_STATIC int vg_strdjb2_eq( const char *s1, u32 h1, - const char *s2, u32 h2 ) -{ - if( h1 == h2 ){ - if(!strcmp(s1, s2)) return 1; - else return 0; - } else return 0; -} +#include +#include + +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; -#define VG_STRDJB2_EQ( CS1, S2, H2 ) \ - vg_strdjb2_eq( CS1, vg_strdjb2(CS1), S2, H2 ) +typedef unsigned int uint; +typedef int v2i[2]; +typedef int v3i[3]; +typedef int v4i[4]; +typedef float v2f[2]; +typedef float v3f[3]; +typedef float v4f[4]; +typedef v2f m2x2f[2]; +typedef v3f m3x3f[3]; +typedef v3f m4x3f[4]; +typedef v4f m4x4f[4]; +typedef v3f boxf[2]; +/* anything compiled against VG shall implement this function somewhere. */ +void vg_fatal_error( const char *fmt, ... ); #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]))