mirror of
https://github.com/Ed94/HandmadeHero.git
synced 2024-11-10 03:44:53 -08:00
Ed_
dc43db117c
I'm splitting this implementation into parts since so much already happened... I fully updated the code the the latest convention I want to use for the project. Engine & Game replay should work.
114 lines
2.8 KiB
C++
114 lines
2.8 KiB
C++
#pragma once
|
|
|
|
// Keywords
|
|
|
|
#define global static // Global variables
|
|
#define internal static // Internal linkage
|
|
#define local_persist static // Local Persisting variables
|
|
|
|
#define api_c extern "C"
|
|
|
|
// 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 )
|
|
|
|
#define do_once() \
|
|
do \
|
|
{ \
|
|
local_persist \
|
|
bool done = false; \
|
|
if ( done ) \
|
|
return; \
|
|
done = true; \
|
|
} \
|
|
while(0)
|
|
|
|
#define do_once_start \
|
|
do \
|
|
{ \
|
|
local_persist \
|
|
bool done = false; \
|
|
if ( done ) \
|
|
break; \
|
|
done = true;
|
|
|
|
#define do_once_end \
|
|
} \
|
|
while(0);
|
|
|
|
|
|
#define array_count( array ) ( sizeof( array ) / sizeof( ( array )[0] ) )
|
|
|
|
// 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 ) \
|
|
if ( !( expression ) ) \
|
|
{ \
|
|
__debugbreak(); \
|
|
}
|
|
// platform::assertion_failure( __FILE__, __LINE__, #expression );
|
|
#else
|
|
# define assert( expression )
|
|
#endif
|
|
|
|
#ifdef COMPILER_CLANG
|
|
# define compiler_decorated_func_name __PRETTY_NAME__
|
|
#elif defined(COMPILER_MSVC)
|
|
# define compiler_decorated_func_name __FUNCDNAME__
|
|
#endif
|
|
|
|
// TODO(Ed) : Add this sauce later
|
|
#if 0
|
|
#define congrats( message )
|
|
#define ensure( condition, expression )
|
|
#define fatal( message )
|
|
#endif
|
|
|
|
// 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
|