31 #include <sys/param.h> 53 #define MAX(x,y) ((x) > (y) ? (x) : (y)) 57 #define MIN(x,y) ((x) < (y) ? (x) : (y)) 60 #define FREEZ(x) do { \ 69 const double PI = 3.14159265358979323846;
73 #define RADS2RPM(x) ((x)*9.549296585) 74 #define RPM2RADS(x) ((x)*.104719755) 75 #define RAD2DEG(x) ((x)*(180.0/PI)) 76 #define DEG2RAD(x) ((x)*(PI/180.0)) 77 #define FEET2M(x) ((x)*0.304801) 78 #define SIGN(x) ((x) < 0.0f ? -1.0f : 1.0f) 81 #define NORM0_2PI(x) \ 83 while ((x) > 2.0*PI) { (x) -= (tdble) (2.0*PI); } \ 84 while ((x) < 0.0) { (x) += (tdble) (2.0*PI); } \ 88 #define NORM_PI_PI(x) \ 90 while ((x) > PI) { (x) -= (tdble) (2.0*PI); } \ 91 while ((x) < -PI) { (x) += (tdble) (2.0*PI); } \ 97 #define DIST(x1, y1, x2, y2) sqrt(((x1) - (x2)) * ((x1) - (x2)) + ((y1) - (y2)) * ((y1) - (y2))) 102 #define MIN(x,y) ((x) < (y) ? (x) : (y)) 159 #define malloc _tgf_win_malloc 160 #define calloc _tgf_win_calloc 161 #define realloc _tgf_win_realloc 162 #define free _tgf_win_free 163 #define strdup _tgf_win_strdup 164 #define _strdup _tgf_win_strdup 165 extern void * _tgf_win_malloc(
size_t size);
166 extern void * _tgf_win_calloc(
size_t num,
size_t size);
167 extern void * _tgf_win_realloc(
void * memblock,
size_t size);
168 extern void _tgf_win_free(
void * memblock);
169 extern char * _tgf_win_strdup(
const char * str);
185 #define MAX_MOD_ITF 10 255 #define GFPARM_PARAMETER 0 256 #define GFPARM_TEMPLATE 1 257 #define GFPARM_PARAM_STR "param" 258 #define GFPARM_TEMPL_STR "template" 261 #define GFPARM_MODIFIABLE 1 262 #define GFPARM_WRITABLE 2 265 #define GFPARM_RMODE_STD 0x01 266 #define GFPARM_RMODE_REREAD 0x02 267 #define GFPARM_RMODE_CREAT 0x04 268 #define GFPARM_RMODE_PRIVATE 0x08 282 extern const char *
GfParmGetStr(
void *handle,
const char *path,
const char *key,
const char *deflt);
284 extern const char *
GfParmGetCurStr(
void *handle,
const char *path,
const char *key,
const char *deflt);
286 extern int GfParmSetStr(
void *handle,
const char *path,
const char *key,
const char *val);
288 extern int GfParmSetCurStr(
void *handle,
const char *path,
const char *key,
const char *val);
291 extern tdble GfParmGetNum(
void *handle,
const char *path,
const char *key,
const char *unit,
tdble deflt);
295 extern int GfParmSetNum(
void *handle,
const char *path,
const char *key,
const char *unit,
tdble val);
298 extern int GfParmSetCurNum(
void *handle,
const char *path,
const char *key,
const char *unit,
tdble val);
313 #define GFPARM_MMODE_SRC 1 314 #define GFPARM_MMODE_DST 2 315 #define GFPARM_MMODE_RELSRC 4 316 #define GFPARM_MMODE_RELDST 8 317 extern void *GfParmMergeHandles(void *ref, void *tgt, int mode); 332 #define GfTrace printf 333 #define GfFatal printf 336 #define GfTrace printf 351 #define GfError printf 353 #if !(_DEBUG || DEBUG) 365 GfOut(
const char *fmt, ...)
383 #define GF_MEAN_MAX_VAL 5 448 #define GF_TAILQ_HEAD(name, type) \ 449 typedef struct name { \ 456 #define GF_TAILQ_ENTRY(type) \ 464 #define GF_TAILQ_FIRST(head) ((head)->tqh_first) 467 #define GF_TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) 470 #define GF_TAILQ_END(head) NULL 473 #define GF_TAILQ_LAST(head, headname) \ 474 (*(((struct headname *)((head)->tqh_last))->tqh_last)) 477 #define GF_TAILQ_PREV(elm, headname, field) \ 478 (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) 485 #define GF_TAILQ_INIT(head) do { \ 486 (head)->tqh_first = NULL; \ 487 (head)->tqh_last = &(head)->tqh_first; \ 492 #define GF_TAILQ_INIT_ENTRY(elm, field) do { \ 493 (elm)->field.tqe_next = 0; \ 494 (elm)->field.tqe_prev = 0; \ 499 #define GF_TAILQ_INSERT_HEAD(head, elm, field) do { \ 500 if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \ 501 (head)->tqh_first->field.tqe_prev = \ 502 &(elm)->field.tqe_next; \ 504 (head)->tqh_last = &(elm)->field.tqe_next; \ 505 (head)->tqh_first = (elm); \ 506 (elm)->field.tqe_prev = &(head)->tqh_first; \ 511 #define GF_TAILQ_INSERT_TAIL(head, elm, field) do { \ 512 (elm)->field.tqe_next = NULL; \ 513 (elm)->field.tqe_prev = (head)->tqh_last; \ 514 *(head)->tqh_last = (elm); \ 515 (head)->tqh_last = &(elm)->field.tqe_next; \ 520 #define GF_TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ 521 if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\ 522 (elm)->field.tqe_next->field.tqe_prev = \ 523 &(elm)->field.tqe_next; \ 525 (head)->tqh_last = &(elm)->field.tqe_next; \ 526 (listelm)->field.tqe_next = (elm); \ 527 (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \ 532 #define GF_TAILQ_INSERT_BEFORE(listelm, elm, field) do { \ 533 (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ 534 (elm)->field.tqe_next = (listelm); \ 535 *(listelm)->field.tqe_prev = (elm); \ 536 (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \ 541 #define GF_TAILQ_REMOVE(head, elm, field) do { \ 542 if (((elm)->field.tqe_next) != NULL) \ 543 (elm)->field.tqe_next->field.tqe_prev = \ 544 (elm)->field.tqe_prev; \ 546 (head)->tqh_last = (elm)->field.tqe_prev; \ 547 *(elm)->field.tqe_prev = (elm)->field.tqe_next; \ 557 #define START_PROFILE(name) Profiler::getInstance()->startProfile(name) 558 #define STOP_PROFILE(name) Profiler::getInstance()->stopProfile() 559 #define STOP_ACTIVE_PROFILES() Profiler::getInstance()->stopActiveProfiles() 560 #define PRINT_PROFILE() Profiler::getInstance()->printProfile() 562 class ProfileInstance {
564 ProfileInstance(
const char * pname);
573 std::map<ProfileInstance *, void *> mapChildren;
582 static Profiler * getInstance();
583 void startProfile(
const char * pname);
585 void stopActiveProfiles();
588 static Profiler * profiler;
589 ProfileInstance * curProfile;
591 std::vector<ProfileInstance *> vecProfiles;
592 std::vector<ProfileInstance *> stkProfiles;
593 std::map<ProfileInstance *, void *> mapWarning;
597 #define START_PROFILE(a) 598 #define STOP_PROFILE(a) 599 #define STOP_ACTIVE_PROFILES() 600 #define PRINT_PROFILE() 606 #define GF_HASH_TYPE_STR 0 607 #define GF_HASH_TYPE_BUF 1 609 typedef void (*tfHashFree)(const void*); 611 void *GfHashCreate(int type); 612 int GfHashAddStr(
void *hash,
const char *key,
const void *data);
615 void GfHashAddBuf(
void *hash,
char *key,
size_t sz,
void *data);
616 const void *
GfHashRemBuf(
void *hash,
char *key,
size_t sz);
617 const void *
GfHashGetBuf(
void *hash,
char *key,
size_t sz);
622 #define GF_DIR_CREATION_FAILED 0 623 #define GF_DIR_CREATED 1
int(* tfModPrivInit)(int index, void *)
initialisation of the function table
void SetLibDir(char *buf)
int GfParmSetStr(void *handle, const char *path, const char *key, const char *val)
Set a string parameter in the parameter set handle.
unsigned int gfId
supported framework version
tFList * GfDirGetListFiltered(const char *dir, const char *suffix)
Get the list of files with matching suffix of a given directory.
int GfModLoad(unsigned int gfid, char *dllname, tModList **modlist)
Load the specified DLLs.
tModInfo modInfo[MAX_MOD_ITF]
module info list for this dll
tdble GfParmUnit2SI(const char *unit, tdble val)
Convert a value given in unit to SI.
tdble gfMean(tdble v, tMeanVal *pvt, int n, int w)
static void GfFatal(const char *fmt,...)
void * userData
User data.
int GfParmCheckHandle(void *ref, void *tgt)
Check the values in the parameter set tgt against the min/max/within definitions in the ref parameter...
void * GfParmReadFile(const char *file, int mode)
Read parameter set from file and return handle to parameter set.
void(* tfHashFree)(const void *)
Function to call for releasing the user data associated with hash table.
int GfModInfoDir(unsigned int gfid, char *dir, int level, tModList **modlist)
Get the generic module information of the DLLs of the specified directory.
Scalar max(Scalar x, Scalar y)
int GfParmListSeekNext(void *handle, const char *path)
Go the the next subsection element in the parameter set handle.
int GfParmSetNumEx(void *handle, const char *path, const char *key, const char *unit, tdble val, tdble min, tdble max)
Set a numerical parameter in the parameter set handle including min and max.
int GfCreateDir(char *path)
Create directory for given path recursively, so all missing parent directories are created as well...
int GfModInfo(unsigned int gfid, char *filename, tModList **modlist)
Get the generic information of the specified DLL.
struct ModList * next
next module in list
const void * GfHashGetNext(void *hash)
Get the next user data of a hash table, this is used for table scans.
void GfParmReleaseHandle(void *handle)
Release given parameter set handle parmHandle.
tdble GfParmGetCurNum(void *handle, const char *path, const char *key, const char *unit, tdble deflt)
Get a numerical parameter from the parameter set handle based on subsection iteration.
#define MAX_MOD_ITF
Maximum number of interface in one DLL.
int prio
priority if needed
const void * GfHashGetFirst(void *hash)
Get the first user data of a hash table, this is used for table scans.
void GfHashRelease(void *hash, tfHashFree hashFree)
Release a hash table.
void GfParmSetDTD(void *parmHandle, char *dtd, char *header)
Set the dtd path and header.
const void * GfHashGetBuf(void *hash, char *key, size_t sz)
Get the user data associated with a memory buffer key.
List of (DLL) files for a Directory.
int GfParmWriteFile(const char *file, void *handle, const char *name)
Write parameter set into file.
const void * GfHashGetStr(void *hash, const char *key)
Get the user data associated with a string key.
tdble GfParmSI2Unit(const char *unit, tdble val)
Convert a value from SI to given unit.
int GfParmCreateDirectory(const char *file, void *parmHandle)
Create directory for parameter set handle if it does not yet exist.
tdble ay
angle along y axis
const char * GfParmGetStr(void *handle, const char *path, const char *key, const char *deflt)
Get a string parameter from the parameter set handle.
void GfHashAddBuf(void *hash, char *key, size_t sz, void *data)
Add an element with a memory buffer key to a hash table.
struct FList tFList
List of (DLL) files for a Directory.
char * GfParmListGetCurEltName(void *handle, const char *path)
Get current subsection name of the parameter set handle during subsection iteration.
struct ModList tModList
list of module interfaces
const void * GfHashRemBuf(void *hash, char *key, size_t sz)
Remove an element with a memory buffer key from a hash table.
int GfParmListSeekFirst(void *handle, const char *path)
Go the the first subsection element in the parameter set handle.
int GfParmGetNumBoundaries(void *handle, const char *path, const char *key, tdble *min, tdble *max)
Get the min and max of a numerical parameter from the parameter set handle.
struct FList * next
Next entry.
tfModPrivInit fctInit
init function
float tdble
Floating point type used in TORCS.
char * dispName
Name to display on screen.
char * sopath
path name of file
void(* tfDirfreeUserData)(void *)
Function to call for releasing the user data associated with file entry.
Parameter set handle structure, multiple handles can reference the same parameter set...
int GfParmSetCurStr(void *handle, const char *path, const char *key, const char *val)
Set a string parameter in the parameter set handle based on subsection iteration. ...
int magic
magic number for integrity check
void SetDataDir(char *buf)
int GfModUnloadList(tModList **modlist)
Unload the DLLs of a list.
int GfModFreeInfoList(tModList **modlist)
Free the info contained in the specified list.
const void * GfHashRemStr(void *hash, char *key)
Remove an element with a string key from a hash table.
void * handle
handle of loaded module
void GfDirFreeList(tFList *list, tfDirfreeUserData freeUserDatabool, bool freename=false, bool freedispname=false)
Free a directory list.
void GfParmClean(void *handle)
Clean all the parameters of a parameter set.
void SetLocalDir(char *buf)
int GfParmSetNum(void *handle, const char *path, const char *key, const char *unit, tdble val)
Set a numerical parameter in the parameter set handle.
tdble GfParmGetNum(void *handle, const char *path, const char *key, const char *unit, tdble deflt)
Get a numerical parameter from the parameter set handle.
Scalar min(Scalar x, Scalar y)
int GfParmSetCurNum(void *handle, const char *path, const char *key, const char *unit, tdble val)
Set a numerical parameter in the parameter set handle based on subsection iteration.
int GfParmListClean(void *handle, const char *path)
Remove all the subsections in a section in the parameter set handle.
struct FList * prev
Previous entry.
char * name
name of the module (short) (NULL if no module)
int index
index if multiple interface in one dll
int GetSingleTextureMode(void)
int GfHashAddStr(void *hash, const char *key, const void *data)
Add an element with a string key to a hash table.
void gfMeanReset(tdble v, tMeanVal *pvt)
tdble az
angle along z axis
double GfTimeClock(void)
Get the time in seconds.
int GfParmGetEltNb(void *handle, const char *path)
Count the number of subsections in a section in the parameter set handle.
char * GfParmGetFileName(void *handle)
Get the filename property of the parameter set handle.
int(* tfModInfo)(tModInfo *)
int GfModLoadDir(unsigned int gfid, char *dir, tModList **modlist)
Load the DLLs in the specified directory.
tdble ax
angle along x axis
char * desc
description of the module (can be long)
list of module interfaces
struct ModInfo tModInfo
Module information structure.
const char * GfParmGetCurStr(void *handle, const char *path, const char *key, const char *deflt)
Get a string parameter from the parameter set handle based on subsection iteration.
void SetSingleTextureMode(void)
char * GfParmGetName(void *handle)
Get the name property of the parameter set handle.
Module information structure.
tFList * GfDirGetList(const char *dir)
Get the list of files of a given directory.
int GfCreateDirForFile(const char *filenameandpath)
Create directory for given file path recursively, so all missing parent directories are created as we...