2019-05-15 14:52:37 +00:00
# pragma once
# define _CRT_SECURE_NO_WARNINGS
# define _USE_MATH_DEFINES
# pragma warning(disable: 4244) // int to float
# pragma warning(disable: 4800) // int to bool
# pragma warning(disable: 4838) // narrowing conversion
2019-05-24 17:58:32 +00:00
# pragma warning(disable: 4996) // POSIX names
2019-05-15 14:52:37 +00:00
# include <stdint.h>
2020-03-27 19:53:47 +00:00
# include <string.h>
2019-05-15 14:52:37 +00:00
# include <math.h>
2021-01-16 13:44:59 +00:00
# if !defined RW_D3D9 && defined LIBRW
# undef WITHD3D
# undef WITHDINPUT
# endif
# if (defined WITHD3D && !defined LIBRW)
# define WITHWINDOWS
2020-03-27 19:53:47 +00:00
# endif
2021-01-16 13:44:59 +00:00
# if defined _WIN32 && defined WITHWINDOWS && !defined _INC_WINDOWS
2019-06-30 10:53:39 +00:00
# include <windows.h>
2020-07-22 11:56:28 +00:00
# endif
2021-01-16 13:44:59 +00:00
# ifdef WITHD3D
# ifdef LIBRW
# define WITH_D3D // librw includes d3d9 itself via this right now
# else
# ifndef USE_D3D9
# include <d3d8types.h>
# else
# include <d3d9types.h>
# endif
# endif
# endif
# ifdef WITHDINPUT
# define DIRECTINPUT_VERSION 0x0800
# include <dinput.h>
2019-05-30 11:35:13 +00:00
# endif
2019-05-15 14:52:37 +00:00
# include <rwcore.h>
# include <rpworld.h>
2020-04-15 12:05:24 +00:00
// gotta put this somewhere
# ifdef LIBRW
# define STREAMPOS(str) ((str)->tell())
# define STREAMFILE(str) (((rw::StreamFile*)(str))->file)
2020-04-23 20:25:18 +00:00
# define HIERNODEINFO(hier) ((hier)->nodeInfo)
# define HIERNODEID(hier, i) ((hier)->nodeInfo[i].id)
2020-06-01 18:28:04 +00:00
# define HANIMFRAME(anim, i) ((RwUInt8*)(anim)->keyframes + (i)*(anim)->interpInfo->animKeyFrameSize)
2020-04-15 12:05:24 +00:00
# else
2020-04-26 19:50:52 +00:00
# define RWHALFPIXEL // always d3d
2020-04-15 12:05:24 +00:00
# define STREAMPOS(str) ((str)->Type.memory.position)
# define STREAMFILE(str) ((str)->Type.file.fpFile)
2020-04-23 20:25:18 +00:00
# define HIERNODEINFO(hier) ((hier)->pNodeInfo)
# define HIERNODEID(hier, i) ((hier)->pNodeInfo[i].nodeID)
2020-06-01 18:28:04 +00:00
# define HANIMFRAME(anim, i) ((RwUInt8*)(anim)->pFrames + (i)*(anim)->interpInfo->keyFrameSize)
2020-07-24 21:29:33 +00:00
# define RpHAnimStdInterpFrame RpHAnimStdKeyFrame
2020-04-15 12:05:24 +00:00
# endif
2020-04-26 19:50:52 +00:00
# ifdef RWHALFPIXEL
# define HALFPX (0.5f)
# else
# define HALFPX (0.0f)
# endif
2019-05-15 14:52:37 +00:00
# define rwVENDORID_ROCKSTAR 0x0253F2
2020-04-19 16:34:08 +00:00
# define Max(a,b) ((a) > (b) ? (a) : (b))
# define Min(a,b) ((a) < (b) ? (a) : (b))
2020-03-27 19:53:47 +00:00
2020-04-30 10:48:01 +00:00
// Use this to add const that wasn't there in the original code
# define Const const
2019-06-16 22:16:38 +00:00
typedef uint8_t uint8 ;
typedef int8_t int8 ;
typedef uint16_t uint16 ;
typedef int16_t int16 ;
typedef uint32_t uint32 ;
typedef int32_t int32 ;
2019-05-15 14:52:37 +00:00
typedef uintptr_t uintptr ;
2020-12-21 20:26:32 +00:00
typedef intptr_t intptr ;
2019-06-16 22:16:38 +00:00
typedef uint64_t uint64 ;
typedef int64_t int64 ;
2019-06-01 21:17:39 +00:00
// hardcode ucs-2
2019-06-16 22:16:38 +00:00
typedef uint16_t wchar ;
2019-05-29 00:52:30 +00:00
2021-01-02 09:38:54 +00:00
typedef uint8 bool8 ;
typedef uint16 bool16 ;
typedef uint32 bool32 ;
2020-12-21 20:26:32 +00:00
# if defined(_MSC_VER)
typedef ptrdiff_t ssize_t ;
# endif
2020-04-15 12:05:24 +00:00
# ifndef nil
2020-04-19 16:34:08 +00:00
# define nil NULL
2020-04-15 12:05:24 +00:00
# endif
2019-05-15 14:52:37 +00:00
# include "config.h"
2020-04-23 20:25:18 +00:00
# include <rphanim.h>
# include <rpskin.h>
2020-08-03 10:58:37 +00:00
# ifdef __GNUC__
# define TYPEALIGN(n) __attribute__ ((aligned (n)))
# else
# ifdef _MSC_VER
# define TYPEALIGN(n) __declspec(align(n))
# else
# define TYPEALIGN(n) // unknown compiler...ignore
# endif
# endif
2019-05-15 14:52:37 +00:00
# define ALIGNPTR(p) (void*)((((uintptr)(void*)p) + sizeof(void*)-1) & ~(sizeof(void*)-1))
2019-07-05 20:19:52 +00:00
// PDP-10 like byte functions
# define MASK(p, s) (((1<<(s))-1) << (p))
inline uint32 dpb ( uint32 b , uint32 p , uint32 s , uint32 w )
{
uint32 m = MASK ( p , s ) ;
2020-10-04 19:39:54 +00:00
return ( w & ~ m ) | ( ( b < < p ) & m ) ;
2019-07-05 20:19:52 +00:00
}
inline uint32 ldb ( uint32 p , uint32 s , uint32 w )
{
return w > > p & ( 1 < < s ) - 1 ;
}
2019-06-30 10:53:39 +00:00
# include "skeleton.h"
2019-06-15 22:20:55 +00:00
# include "Draw.h"
2021-01-08 22:01:41 +00:00
# if defined(PROPER_SCALING)
# ifdef FORCE_PC_SCALING
# define DEFAULT_SCREEN_WIDTH (640)
# define DEFAULT_SCREEN_HEIGHT (448)
# else
# define DEFAULT_SCREEN_WIDTH (640)
# define DEFAULT_SCREEN_HEIGHT (480)
# endif
# elif defined(GTA_PS2)
# define DEFAULT_SCREEN_WIDTH (640)
# define DEFAULT_SCREEN_HEIGHT (480)
# else //elif defined(GTA_PC)
# define DEFAULT_SCREEN_WIDTH (640)
# define DEFAULT_SCREEN_HEIGHT (448)
# endif
2019-07-03 11:13:55 +00:00
# define DEFAULT_ASPECT_RATIO (4.0f / 3.0f)
2020-04-08 23:52:38 +00:00
# define DEFAULT_VIEWWINDOW (0.7f)
2019-07-03 11:13:55 +00:00
// game uses maximumWidth/Height, but this probably won't work
// with RW windowed mode
2021-01-08 22:01:41 +00:00
# ifdef GTA_PS2
# ifdef GTA_PAL
# define SCREEN_WIDTH ((float)640)
# define SCREEN_HEIGHT ((float)512)
# else
# define SCREEN_WIDTH ((float)640)
# define SCREEN_HEIGHT ((float)448)
# endif
# else
# define SCREEN_WIDTH ((float)RsGlobal.width)
2019-07-03 11:13:55 +00:00
# define SCREEN_HEIGHT ((float)RsGlobal.height)
2021-01-08 22:01:41 +00:00
# endif
# define SCREEN_HEIGHT_PAL ((float)512)
# define SCREEN_HEIGHT_NTSC ((float)448)
2019-06-15 22:20:55 +00:00
# define SCREEN_ASPECT_RATIO (CDraw::GetAspectRatio())
2020-06-21 12:50:00 +00:00
# define SCREEN_VIEWWINDOW (Tan(DEGTORAD(CDraw::GetScaledFOV() * 0.5f)))
2019-05-15 14:52:37 +00:00
2019-07-03 11:13:55 +00:00
// This scales from PS2 pixel coordinates to the real resolution
# define SCREEN_STRETCH_X(a) ((a) * (float) SCREEN_WIDTH / DEFAULT_SCREEN_WIDTH)
# define SCREEN_STRETCH_Y(a) ((a) * (float) SCREEN_HEIGHT / DEFAULT_SCREEN_HEIGHT)
# define SCREEN_STRETCH_FROM_RIGHT(a) (SCREEN_WIDTH - SCREEN_STRETCH_X(a))
# define SCREEN_STRETCH_FROM_BOTTOM(a) (SCREEN_HEIGHT - SCREEN_STRETCH_Y(a))
2019-05-15 14:52:37 +00:00
2019-07-03 11:13:55 +00:00
// This scales from PS2 pixel coordinates while optionally maintaining the aspect ratio
# define SCREEN_SCALE_X(a) SCREEN_SCALE_AR(SCREEN_STRETCH_X(a))
# define SCREEN_SCALE_Y(a) SCREEN_STRETCH_Y(a)
2019-06-20 00:31:03 +00:00
# define SCREEN_SCALE_FROM_RIGHT(a) (SCREEN_WIDTH - SCREEN_SCALE_X(a))
# define SCREEN_SCALE_FROM_BOTTOM(a) (SCREEN_HEIGHT - SCREEN_SCALE_Y(a))
2019-06-16 17:06:01 +00:00
2019-07-03 11:13:55 +00:00
# ifdef ASPECT_RATIO_SCALE
2019-10-05 13:04:27 +00:00
# define SCREEN_SCALE_AR(a) ((a) * DEFAULT_ASPECT_RATIO / SCREEN_ASPECT_RATIO)
2021-01-08 22:01:41 +00:00
# define SCALE_AND_CENTER_X(x) ((SCREEN_WIDTH == DEFAULT_SCREEN_WIDTH) ? (x) : (SCREEN_WIDTH - SCREEN_SCALE_X(DEFAULT_SCREEN_WIDTH)) / 2 + SCREEN_SCALE_X((x)))
# ifdef PROPER_SCALING
# ifndef FORCE_PC_SCALING
# undef SCREEN_SCALE_Y
# define SCREEN_SCALE_Y(a) CDraw::ScaleY(SCREEN_STRETCH_Y(a))
# endif
# endif
2019-07-03 11:13:55 +00:00
# else
# define SCREEN_SCALE_AR(a) (a)
2020-09-29 19:53:12 +00:00
# define SCALE_AND_CENTER_X(x) SCREEN_STRETCH_X(x)
2019-07-03 11:13:55 +00:00
# endif
2019-07-08 19:44:32 +00:00
# include "maths.h"
# include "Vector.h"
# include "Vector2D.h"
# include "Matrix.h"
# include "Rect.h"
2019-05-15 14:52:37 +00:00
class CRGBA
{
public :
2019-05-29 00:52:30 +00:00
union
{
uint32 color32 ;
struct { uint8 r , g , b , a ; } ;
struct { uint8 red , green , blue , alpha ; } ;
# ifdef RWCORE_H
struct { RwRGBA rwRGBA ; } ;
# endif
} ;
2019-05-15 14:52:37 +00:00
CRGBA ( void ) { }
CRGBA ( uint8 r , uint8 g , uint8 b , uint8 a ) : r ( r ) , g ( g ) , b ( b ) , a ( a ) { }
2019-08-15 01:43:00 +00:00
2020-06-27 21:01:51 +00:00
bool operator = = ( const CRGBA & right )
{
return this - > r = = right . r & & this - > g = = right . g & & this - > b = = right . b & & this - > a = = right . a ;
}
bool operator ! = ( const CRGBA & right )
{
return ! ( * this = = right ) ;
}
2019-08-29 22:44:57 +00:00
CRGBA & operator = ( const CRGBA & right )
2019-08-15 01:43:00 +00:00
{
this - > r = right . r ;
this - > g = right . g ;
this - > b = right . b ;
this - > a = right . a ;
return * this ;
}
2019-05-29 00:52:30 +00:00
# ifdef RWCORE_H
2019-05-29 22:47:33 +00:00
operator RwRGBA & ( void ) {
2019-05-29 00:52:30 +00:00
return rwRGBA ;
}
2019-05-29 22:47:33 +00:00
operator RwRGBA * ( void ) {
2019-05-29 00:52:30 +00:00
return & rwRGBA ;
}
2019-05-29 22:47:33 +00:00
operator RwRGBA ( void ) const {
2019-05-29 00:52:30 +00:00
return rwRGBA ;
}
2019-08-15 01:43:00 +00:00
2019-08-29 22:44:57 +00:00
CRGBA & operator = ( const RwRGBA & right )
2019-08-15 01:43:00 +00:00
{
this - > r = right . red ;
this - > g = right . green ;
this - > b = right . blue ;
this - > a = right . alpha ;
return * this ;
}
2019-05-29 00:52:30 +00:00
# endif
2019-05-15 14:52:37 +00:00
} ;
2019-10-29 23:12:58 +00:00
# if (defined(_MSC_VER))
extern int strcasecmp ( const char * str1 , const char * str2 ) ;
2020-05-08 13:59:57 +00:00
extern int strncasecmp ( const char * str1 , const char * str2 , size_t len ) ;
2019-10-29 23:12:58 +00:00
# endif
2020-11-23 22:25:44 +00:00
extern wchar * AllocUnicode ( const char * src ) ;
2019-05-29 22:47:33 +00:00
# define clamp(v, low, high) ((v)<(low) ? (low) : (v)>(high) ? (high) : (v))
2019-05-29 00:52:30 +00:00
2020-09-27 01:22:59 +00:00
# define clamp2(v, center, radius) ((v) < (center) ? Max(v, center - radius) : Min(v, center + radius))
2019-05-29 22:47:33 +00:00
inline float sq ( float x ) { return x * x ; }
# define SQR(x) ((x) * (x))
2019-05-29 00:52:30 +00:00
2019-08-16 18:17:15 +00:00
# define PI (float)M_PI
2019-07-18 13:41:09 +00:00
# define TWOPI (PI*2)
# define HALFPI (PI / 2)
2019-05-29 00:52:30 +00:00
# define DEGTORAD(x) ((x) * PI / 180.0f)
# define RADTODEG(x) ((x) * 180.0f / PI)
2019-05-15 14:52:37 +00:00
2019-06-02 22:25:46 +00:00
# ifdef USE_PS2_RAND
2019-05-30 21:49:06 +00:00
# define MYRAND_MAX 65535
# else
# define MYRAND_MAX 32767
# endif
2019-05-15 14:52:37 +00:00
int myrand ( void ) ;
void mysrand ( unsigned int seed ) ;
2019-08-16 18:17:15 +00:00
void re3_debug ( const char * format , . . . ) ;
void re3_trace ( const char * filename , unsigned int lineno , const char * func , const char * format , . . . ) ;
2019-06-02 21:42:51 +00:00
void re3_assert ( const char * expr , const char * filename , unsigned int lineno , const char * func ) ;
2020-05-07 06:26:16 +00:00
void re3_usererror ( const char * format , . . . ) ;
2019-06-02 21:42:51 +00:00
2019-06-11 09:30:53 +00:00
# define DEBUGBREAK() __debugbreak();
2020-12-09 00:41:45 +00:00
// Switch to enable development messages.
# if 1
# define DEV(f, ...)
# else
2019-07-31 15:54:18 +00:00
# define DEV(f, ...) re3_debug("[DEV]: " f, ## __VA_ARGS__)
2020-12-09 00:41:45 +00:00
# endif
# define debug(f, ...) re3_debug("[DBG]: " f, ## __VA_ARGS__)
2019-07-31 15:54:18 +00:00
# define TRACE(f, ...) re3_trace(__FILE__, __LINE__, __FUNCTION__, f, ## __VA_ARGS__)
# define Error(f, ...) re3_debug("[ERROR]: " f, ## __VA_ARGS__)
2020-05-07 06:26:16 +00:00
# define USERERROR(f, ...) re3_usererror(f, ## __VA_ARGS__)
2019-06-02 21:42:51 +00:00
# define assert(_Expression) (void)( (!!(_Expression)) || (re3_assert(#_Expression, __FILE__, __LINE__, __FUNCTION__), 0) )
2019-05-29 00:52:30 +00:00
# define ASSERT assert
2019-05-15 14:52:37 +00:00
2019-06-19 13:22:42 +00:00
# define _TODO(x)
2019-05-29 18:02:58 +00:00
# define _TODOCONST(x) (x)
2019-05-15 14:52:37 +00:00
2020-05-10 13:54:37 +00:00
# ifdef CHECK_STRUCT_SIZES
2019-05-29 18:02:58 +00:00
# define VALIDATE_SIZE(struc, size) static_assert(sizeof(struc) == size, "Invalid structure size of " #struc)
2020-05-10 13:54:37 +00:00
# else
# define VALIDATE_SIZE(struc, size)
# endif
2019-05-29 18:02:58 +00:00
# define VALIDATE_OFFSET(struc, member, offset) static_assert(offsetof(struc, member) == offset, "The offset of " #member " in " #struc " is not " #offset "...")
2019-06-16 22:16:38 +00:00
# define PERCENT(x, p) ((float(x) * (float(p) / 100.0f)))
2019-05-29 00:52:30 +00:00
# define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
2019-05-29 22:47:33 +00:00
# define BIT(num) (1<<(num))
2019-06-30 10:53:39 +00:00
2019-08-06 21:32:19 +00:00
# define ABS(a) (((a) < 0) ? (-(a)) : (a))
2019-08-02 20:20:12 +00:00
# define norm(value, min, max) (((value) < (min)) ? 0 : (((value) > (max)) ? 1 : (((value) - (min)) / ((max) - (min)))))
2020-04-01 21:04:56 +00:00
# define lerp(norm, min, max) ( (norm) * ((max) - (min)) + (min) )
2019-07-24 16:55:43 +00:00
# define STRINGIFY(x) #x
# define STR(x) STRINGIFY(x)
# define CONCAT_(x,y) x##y
# define CONCAT(x,y) CONCAT_(x,y)
// Tweaking stuff for debugmenu
# define TWEAKPATH ___tw___TWEAKPATH
# define SETTWEAKPATH(path) static const char *___tw___TWEAKPATH = path;
# define TWEAKFUNC(v) static CTweakFunc CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), TWEAKPATH);
# define TWEAKFUNCN(v, name) static CTweakFunc CONCAT(___tw___tweak, __COUNTER__)(&v, name, TWEAKPATH);
# define TWEAKBOOL(v) static CTweakBool CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), TWEAKPATH);
# define TWEAKBOOLN(v, name) static CTweakBool CONCAT(___tw___tweak, __COUNTER__)(&v, name, TWEAKPATH);
# define TWEAKINT32(v, lower, upper, step) static CTweakInt32 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH);
# define TWEAKINT32N(v, lower, upper, step, name) static CTweakInt32 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH);
# define TWEAKUINT32(v, lower, upper, step) static CTweakUInt32 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH);
# define TWEAKUINT32N(v, lower, upper, step, name) static CTweakUInt32 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH);
# define TWEAKINT16(v, lower, upper, step) static CTweakInt16 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH);
# define TWEAKINT16N(v, lower, upper, step, name) static CTweakInt16 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH);
# define TWEAKUINT16(v, lower, upper, step) static CTweakUInt16 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH);
# define TWEAKUINT16N(v, lower, upper, step, name) static CTweakUInt16 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH);
# define TWEAKINT8(v, lower, upper, step) static CTweakInt8 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH);
# define TWEAKINT8N(v, lower, upper, step, name) static CTweakInt8 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH);
# define TWEAKUINT8(v, lower, upper, step) static CTweakUInt8 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH);
# define TWEAKUINT8N(v, lower, upper, step, name) static CTweakUInt8 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH);
# define TWEAKFLOAT(v, lower, upper, step) static CTweakFloat CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH);
# define TWEAKFLOATN(v, lower, upper, step, name) static CTweakFloat CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH);
# define TWEAKSWITCH(v, lower, upper, str, f) static CTweakSwitch CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, str, f, TWEAKPATH);
# define TWEAKSWITCHN(v, lower, upper, str, f, name) static CTweakSwitch CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, str, f, TWEAKPATH);
// interface
class CTweakVar
{
public :
virtual void AddDBG ( const char * path ) = 0 ;
} ;
class CTweakVars
{
public :
static void Add ( CTweakVar * var ) ;
static void AddDBG ( const char * path ) ;
} ;
class CTweakFunc : public CTweakVar
{
const char * m_pPath , * m_pVarName ;
void ( * m_pFunc ) ( ) ;
public :
CTweakFunc ( void ( * pFunc ) ( ) , const char * strName , const char * strPath ) :
2020-04-19 16:34:08 +00:00
m_pPath ( strPath ) , m_pVarName ( strName ) , m_pFunc ( pFunc )
2019-07-24 16:55:43 +00:00
{
CTweakVars : : Add ( this ) ;
}
void AddDBG ( const char * path ) ;
} ;
class CTweakBool : public CTweakVar
{
const char * m_pPath , * m_pVarName ;
bool * m_pBoolVar ;
public :
CTweakBool ( bool * pBool , const char * strName , const char * strPath ) :
2020-04-19 16:34:08 +00:00
m_pPath ( strPath ) , m_pVarName ( strName ) , m_pBoolVar ( pBool )
2019-07-24 16:55:43 +00:00
{
CTweakVars : : Add ( this ) ;
}
void AddDBG ( const char * path ) ;
} ;
class CTweakSwitch : public CTweakVar
{
const char * m_pPath , * m_pVarName ;
void * m_pIntVar ;
int32 m_nMin , m_nMax ;
const char * * m_aStr ;
void ( * m_pFunc ) ( ) ;
public :
2020-04-19 16:34:08 +00:00
CTweakSwitch ( void * pInt , const char * strName , int32 nMin , int32 nMax , const char * * aStr ,
void ( * pFunc ) ( ) , const char * strPath )
: m_pPath ( strPath ) , m_pVarName ( strName ) , m_pIntVar ( pInt ) , m_nMin ( nMin ) , m_nMax ( nMax ) ,
m_aStr ( aStr )
2019-07-24 16:55:43 +00:00
{
CTweakVars : : Add ( this ) ;
}
void AddDBG ( const char * path ) ;
} ;
2020-04-19 16:34:08 +00:00
# define _TWEEKCLASS(name, type) \
class name : public CTweakVar \
{ \
public : \
const char * m_pPath , * m_pVarName ; \
type * m_pIntVar , m_nLoawerBound , m_nUpperBound , m_nStep ; \
\
name ( type * pInt , const char * strName , type nLower , type nUpper , type nStep , \
const char * strPath ) \
: m_pPath ( strPath ) , m_pVarName ( strName ) , m_pIntVar ( pInt ) , \
m_nLoawerBound ( nLower ) , m_nUpperBound ( nUpper ) , m_nStep ( nStep ) \
\
{ \
CTweakVars : : Add ( this ) ; \
} \
\
void AddDBG ( const char * path ) ; \
} ;
2019-07-24 16:55:43 +00:00
_TWEEKCLASS ( CTweakInt8 , int8 ) ;
_TWEEKCLASS ( CTweakUInt8 , uint8 ) ;
_TWEEKCLASS ( CTweakInt16 , int16 ) ;
_TWEEKCLASS ( CTweakUInt16 , uint16 ) ;
_TWEEKCLASS ( CTweakInt32 , int32 ) ;
_TWEEKCLASS ( CTweakUInt32 , uint32 ) ;
_TWEEKCLASS ( CTweakFloat , float ) ;
2019-07-24 17:59:16 +00:00
# undef _TWEEKCLASS
2019-10-08 20:07:11 +00:00
# ifdef VALIDATE_SAVE_SIZE
2020-03-11 07:12:40 +00:00
extern int32 _saveBufCount ;
# define INITSAVEBUF _saveBufCount = 0;
# define VALIDATESAVEBUF(b) assert(_saveBufCount == b);
2019-10-08 20:07:11 +00:00
# else
# define INITSAVEBUF
# define VALIDATESAVEBUF(b)
# endif
inline void SkipSaveBuf ( uint8 * & buf , int32 skip )
{
buf + = skip ;
# ifdef VALIDATE_SAVE_SIZE
2020-03-11 07:12:40 +00:00
_saveBufCount + = skip ;
2019-10-08 20:07:11 +00:00
# endif
}
2020-10-10 20:50:00 +00:00
inline void SkipSaveBuf ( uint8 * & buf , uint32 & length , int32 skip )
{
buf + = skip ;
length + = skip ;
# ifdef VALIDATE_SAVE_SIZE
_saveBufCount + = skip ;
# endif
}
2019-10-08 20:07:11 +00:00
template < typename T >
inline const T ReadSaveBuf ( uint8 * & buf )
2019-10-12 22:35:01 +00:00
{
2019-10-08 20:07:11 +00:00
T & value = * ( T * ) buf ;
SkipSaveBuf ( buf , sizeof ( T ) ) ;
return value ;
}
2020-10-10 20:50:00 +00:00
template < typename T >
inline const T ReadSaveBuf ( uint8 * & buf , uint32 & length )
{
T & value = * ( T * ) buf ;
SkipSaveBuf ( buf , length , sizeof ( T ) ) ;
return value ;
}
2019-10-08 20:07:11 +00:00
template < typename T >
inline T * WriteSaveBuf ( uint8 * & buf , const T & value )
2019-10-12 22:35:01 +00:00
{
T * p = ( T * ) buf ;
2019-10-08 20:07:11 +00:00
* p = value ;
SkipSaveBuf ( buf , sizeof ( T ) ) ;
return p ;
}
2020-10-10 20:50:00 +00:00
template < typename T >
inline T * WriteSaveBuf ( uint8 * & buf , uint32 & length , const T & value )
{
T * p = ( T * ) buf ;
* p = value ;
SkipSaveBuf ( buf , length , sizeof ( T ) ) ;
return p ;
}
2019-10-08 20:07:11 +00:00
# define SAVE_HEADER_SIZE (4*sizeof(char)+sizeof(uint32))
2019-10-12 22:35:01 +00:00
# define WriteSaveHeader(buf,a,b,c,d,size) \
WriteSaveBuf ( buf , a ) ; \
WriteSaveBuf ( buf , b ) ; \
WriteSaveBuf ( buf , c ) ; \
WriteSaveBuf ( buf , d ) ; \
2020-06-06 09:58:10 +00:00
WriteSaveBuf < uint32 > ( buf , size ) ;
2019-10-08 20:07:11 +00:00
2020-10-10 20:50:00 +00:00
# define WriteSaveHeaderWithLength(buf,len,a,b,c,d,size) \
WriteSaveBuf ( buf , len , a ) ; \
WriteSaveBuf ( buf , len , b ) ; \
WriteSaveBuf ( buf , len , c ) ; \
WriteSaveBuf ( buf , len , d ) ; \
WriteSaveBuf < uint32 > ( buf , len , size ) ;
2019-10-08 20:07:11 +00:00
# define CheckSaveHeader(buf,a,b,c,d,size)\
assert ( ReadSaveBuf < char > ( buf ) = = a ) ; \
assert ( ReadSaveBuf < char > ( buf ) = = b ) ; \
assert ( ReadSaveBuf < char > ( buf ) = = c ) ; \
assert ( ReadSaveBuf < char > ( buf ) = = d ) ; \
2019-10-27 17:39:17 +00:00
assert ( ReadSaveBuf < uint32 > ( buf ) = = size ) ;
2020-03-22 11:26:35 +00:00
2020-10-10 20:50:00 +00:00
# define CheckSaveHeaderWithLength(buf,len,a,b,c,d,size)\
assert ( ReadSaveBuf < char > ( buf , len ) = = a ) ; \
assert ( ReadSaveBuf < char > ( buf , len ) = = b ) ; \
assert ( ReadSaveBuf < char > ( buf , len ) = = c ) ; \
assert ( ReadSaveBuf < char > ( buf , len ) = = d ) ; \
assert ( ReadSaveBuf < uint32 > ( buf , len ) = = size ) ;
2020-03-22 11:26:35 +00:00
2020-11-23 22:25:44 +00:00
void cprintf ( char * , . . . ) ;