2023-09-09 17:14:40 -07:00
|
|
|
#pragma once
|
|
|
|
|
2023-09-08 18:08:57 -07:00
|
|
|
// Keywords
|
|
|
|
|
|
|
|
#define global static // Global variables
|
|
|
|
#define internal static // Internal linkage
|
|
|
|
#define local_persist static // Local Persisting variables
|
2023-09-08 21:01:53 -07:00
|
|
|
|
|
|
|
#define api_c extern "C"
|
2023-09-09 00:03:03 -07:00
|
|
|
|
|
|
|
// Casting
|
|
|
|
|
|
|
|
#define ccast( Type, Value ) ( * const_cast< Type* >( & (Value) ) )
|
|
|
|
#define pcast( Type, Value ) ( * reinterpret_cast< Type* >( & ( Value ) ) )
|
|
|
|
#define rcast( Type, Value ) reinterpret_cast< Type >( Value )
|
|
|
|
#define scast( Type, Value ) static_cast< Type >( Value )
|
2023-09-09 20:58:28 -07:00
|
|
|
|
|
|
|
#define do_once() \
|
|
|
|
do \
|
|
|
|
{ \
|
2023-09-18 17:16:40 -07:00
|
|
|
local_persist \
|
2023-09-09 20:58:28 -07:00
|
|
|
bool Done = false; \
|
|
|
|
if ( Done ) \
|
|
|
|
return; \
|
|
|
|
Done = true; \
|
|
|
|
} \
|
|
|
|
while(0)
|
|
|
|
|
|
|
|
#define do_once_start \
|
|
|
|
do \
|
|
|
|
{ \
|
2023-09-18 17:16:40 -07:00
|
|
|
local_persist \
|
2023-09-09 20:58:28 -07:00
|
|
|
bool Done = false; \
|
|
|
|
if ( Done ) \
|
|
|
|
break; \
|
|
|
|
Done = true;
|
|
|
|
|
|
|
|
#define do_once_end \
|
|
|
|
} \
|
2023-09-17 18:20:11 -07:00
|
|
|
while(0);
|
|
|
|
|
|
|
|
|
|
|
|
#define array_count( array ) ( sizeof( array ) / sizeof( ( array )[0] ) )
|
2023-09-18 17:16:40 -07:00
|
|
|
|
|
|
|
// TODO(Ed) : Move to memory header eventually
|
|
|
|
#define kilobytes( x ) ( ( x ) * ( s64 )( 1024 ) )
|
|
|
|
#define megabytes( x ) ( kilobytes( x ) * ( s64 )( 1024 ) )
|
|
|
|
#define gigabytes( x ) ( megabytes( x ) * ( s64 )( 1024 ) )
|
|
|
|
#define terabytes( x ) ( gigabytes( x ) * ( s64 )( 1024 ) )
|
|
|
|
|
|
|
|
// TODO(Ed) : Move to debug header eventually
|
|
|
|
|
|
|
|
#if Build_Development
|
|
|
|
# define assert( expression ) \
|
2023-09-21 23:16:40 -07:00
|
|
|
if ( !( expression ) ) \
|
|
|
|
{ \
|
|
|
|
__debugbreak(); \
|
2023-09-18 17:16:40 -07:00
|
|
|
}
|
|
|
|
// platform::assertion_failure( __FILE__, __LINE__, #expression );
|
|
|
|
#else
|
|
|
|
# define assert( expression )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// TODO(Ed) : Add this sauce later
|
|
|
|
#if 0
|
|
|
|
#define congrats( message )
|
|
|
|
#define ensure( condition, expression )
|
|
|
|
#define fatal( message )
|
|
|
|
#endif
|
2023-09-21 23:16:40 -07:00
|
|
|
|
|
|
|
// Just experimenting with a way to check for global variables being accessed from the wrong place.
|
|
|
|
// (Could also be done with gencpp technically)
|
|
|
|
#if 0
|
|
|
|
enum class EGlobalVarsAllowFuncs
|
|
|
|
{
|
|
|
|
ProcessPendingWindowMessages,
|
|
|
|
Num,
|
|
|
|
Invalid,
|
|
|
|
};
|
|
|
|
EGlobalVarsAllowFuncs to_type( char const* proc_name )
|
|
|
|
{
|
|
|
|
char const* global_vars_allowed_funcs[] {
|
|
|
|
"process_pending_window_messages"
|
|
|
|
};
|
|
|
|
|
|
|
|
if ( proc_name )
|
|
|
|
{
|
|
|
|
for ( u32 idx = 0; idx < array_count( global_vars_allowed_funcs ); ++idx )
|
|
|
|
{
|
|
|
|
if ( strcmp( proc_name, global_vars_allowed_funcs[idx] ) == 0 )
|
|
|
|
{
|
|
|
|
return scast( EGlobalVarsAllowFuncs, idx );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return EGlobalVarsAllowFuncs::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if Build_Development
|
|
|
|
# define checked_global_getter( global_var, procedure ) \
|
|
|
|
( ensure( to_type(procedure) != EGlobalVarsAllowFuncs::Invalid), global_var )
|
|
|
|
#else
|
|
|
|
# define checked_global_getter( global_var, procedure ) global_var
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|