+++ /dev/null
-/* Copyright (C) 2021-2022 Harry Godden (hgn) - All Rights Reserved */
-
-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 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]; /* TODO why this is 4x4 too? */
-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]))
-
-/* Pthred emulation for windows */
-#ifdef _WIN32
- #include <windows.h>
- #define MUTEX_TYPE HANDLE
- #define MUTEX_INITIALIZER NULL
- #define MUTEX_SETUP(x) (x) = CreateMutex(NULL, FALSE, NULL)
-
- /* TODO: Why is this defined but never used? */
- #define MUTEX_CLEANUP(x) (CloseHandle(x))
- #define MUTEX_LOCK(x) emulate_pthread_mutex_lock(&(x))
- #define MUTEX_UNLOCK(x) (ReleaseMutex(x))
-
- int emulate_pthread_mutex_lock( volatile MUTEX_TYPE *mx )
- {
- if( *mx == NULL ) /* static initializer? */
- {
- HANDLE p = CreateMutex( NULL, FALSE, NULL );
- if( InterlockedCompareExchangePointer( (PVOID*)mx, (PVOID)p, NULL )
- != NULL )
- CloseHandle(p);
- }
-
- return WaitForSingleObject( *mx, INFINITE ) == WAIT_FAILED;
- }
-#else
- #include <pthread.h>
- #define MUTEX_LOCK(x) pthread_mutex_lock(&(x))
- #define MUTEX_UNLOCK(x) pthread_mutex_unlock(&(x))
- #define MUTEX_TYPE pthread_mutex_t
- #define MUTEX_INITIALIZER {0}
-#endif
-
-
-int vg_thread_run( void *pfunc, void *data )
-{
-#ifdef _WIN32
- HANDLE hThread = CreateThread
- (
- NULL, /* Thread attributes */
- 0, /* Stack size (0 = use default) */
- pfunc, /* Thread start address */
- data, /* Parameter to pass to the thread */
- 0, /* Creation flags */
- NULL /* Thread id */
- );
-
- if ( hThread == NULL )
- {
- /*
- * Thread creation failed.
- * More details can be retrieved by calling GetLastError()
- */
- return 1;
- }
- else
- {
- CloseHandle( hThread );
- return 0;
- }
-#else
- pthread_t hThread;
- if( pthread_create( &hThread, NULL, pfunc, data ) )
- {
- return 1;
- }
- else
- {
- pthread_detach( hThread );
- return 0;
- }
-#endif
-}