52#define MAX(x,y) ((x) > (y) ? (x) : (y))
56#define MIN(x,y) ((x) < (y) ? (x) : (y))
59#define FREEZ(x) do { \
68const double PI = 3.14159265358979323846;
72#define RADS2RPM(x) ((x)*9.549296585)
73#define RPM2RADS(x) ((x)*.104719755)
74#define RAD2DEG(x) ((x)*(180.0/PI))
75#define DEG2RAD(x) ((x)*(PI/180.0))
76#define FEET2M(x) ((x)*0.304801)
77#define SIGN(x) ((x) < 0.0f ? -1.0f : 1.0f)
82 while ((x) > 2.0*PI) { (x) -= (tdble) (2.0*PI); } \
83 while ((x) < 0.0) { (x) += (tdble) (2.0*PI); } \
87#define NORM_PI_PI(x) \
89 while ((x) > PI) { (x) -= (tdble) (2.0*PI); } \
90 while ((x) < -PI) { (x) += (tdble) (2.0*PI); } \
96#define DIST(x1, y1, x2, y2) sqrt(((x1) - (x2)) * ((x1) - (x2)) + ((y1) - (y2)) * ((y1) - (y2)))
101#define MIN(x,y) ((x) < (y) ? (x) : (y))
158#define malloc _tgf_win_malloc
159#define calloc _tgf_win_calloc
160#define realloc _tgf_win_realloc
161#define free _tgf_win_free
162#define strdup _tgf_win_strdup
163#define _strdup _tgf_win_strdup
164extern void * _tgf_win_malloc(
size_t size);
165extern void * _tgf_win_calloc(
size_t num,
size_t size);
166extern void * _tgf_win_realloc(
void * memblock,
size_t size);
167extern void _tgf_win_free(
void * memblock);
168extern char * _tgf_win_strdup(
const char * str);
184#define MAX_MOD_ITF 10
254#define GFPARM_PARAMETER 0
255#define GFPARM_TEMPLATE 1
256#define GFPARM_PARAM_STR "param"
257#define GFPARM_TEMPL_STR "template"
260#define GFPARM_MODIFIABLE 1
261#define GFPARM_WRITABLE 2
264#define GFPARM_RMODE_STD 0x01
265#define GFPARM_RMODE_REREAD 0x02
266#define GFPARM_RMODE_CREAT 0x04
267#define GFPARM_RMODE_PRIVATE 0x08
281extern const char *
GfParmGetStr(
void *handle,
const char *path,
const char *key,
const char *deflt);
283extern const char *
GfParmGetCurStr(
void *handle,
const char *path,
const char *key,
const char *deflt);
285extern int GfParmSetStr(
void *handle,
const char *path,
const char *key,
const char *val);
287extern int GfParmSetCurStr(
void *handle,
const char *path,
const char *key,
const char *val);
294extern int GfParmSetNum(
void *handle,
const char *path,
const char *key,
const char *unit,
tdble val);
297extern int GfParmSetCurNum(
void *handle,
const char *path,
const char *key,
const char *unit,
tdble val);
312#define GFPARM_MMODE_SRC 1
313#define GFPARM_MMODE_DST 2
314#define GFPARM_MMODE_RELSRC 4
315#define GFPARM_MMODE_RELDST 8
331#define GfTrace printf
332#define GfFatal printf
335#define GfTrace printf
350#define GfError printf
352#if !(_DEBUG || DEBUG)
364GfOut(
const char *fmt, ...)
382#define GF_MEAN_MAX_VAL 5
447#define GF_TAILQ_HEAD(name, type) \
448typedef struct name { \
455#define GF_TAILQ_ENTRY(type) \
463#define GF_TAILQ_FIRST(head) ((head)->tqh_first)
466#define GF_TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
469#define GF_TAILQ_END(head) NULL
472#define GF_TAILQ_LAST(head, headname) \
473 (*(((struct headname *)((head)->tqh_last))->tqh_last))
476#define GF_TAILQ_PREV(elm, headname, field) \
477 (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
484#define GF_TAILQ_INIT(head) do { \
485 (head)->tqh_first = NULL; \
486 (head)->tqh_last = &(head)->tqh_first; \
491#define GF_TAILQ_INIT_ENTRY(elm, field) do { \
492 (elm)->field.tqe_next = 0; \
493 (elm)->field.tqe_prev = 0; \
498#define GF_TAILQ_INSERT_HEAD(head, elm, field) do { \
499 if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
500 (head)->tqh_first->field.tqe_prev = \
501 &(elm)->field.tqe_next; \
503 (head)->tqh_last = &(elm)->field.tqe_next; \
504 (head)->tqh_first = (elm); \
505 (elm)->field.tqe_prev = &(head)->tqh_first; \
510#define GF_TAILQ_INSERT_TAIL(head, elm, field) do { \
511 (elm)->field.tqe_next = NULL; \
512 (elm)->field.tqe_prev = (head)->tqh_last; \
513 *(head)->tqh_last = (elm); \
514 (head)->tqh_last = &(elm)->field.tqe_next; \
519#define GF_TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
520 if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
521 (elm)->field.tqe_next->field.tqe_prev = \
522 &(elm)->field.tqe_next; \
524 (head)->tqh_last = &(elm)->field.tqe_next; \
525 (listelm)->field.tqe_next = (elm); \
526 (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
531#define GF_TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
532 (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
533 (elm)->field.tqe_next = (listelm); \
534 *(listelm)->field.tqe_prev = (elm); \
535 (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
540#define GF_TAILQ_REMOVE(head, elm, field) do { \
541 if (((elm)->field.tqe_next) != NULL) \
542 (elm)->field.tqe_next->field.tqe_prev = \
543 (elm)->field.tqe_prev; \
545 (head)->tqh_last = (elm)->field.tqe_prev; \
546 *(elm)->field.tqe_prev = (elm)->field.tqe_next; \
556#define START_PROFILE(name) Profiler::getInstance()->startProfile(name)
557#define STOP_PROFILE(name) Profiler::getInstance()->stopProfile()
558#define STOP_ACTIVE_PROFILES() Profiler::getInstance()->stopActiveProfiles()
559#define PRINT_PROFILE() Profiler::getInstance()->printProfile()
561class ProfileInstance {
563 ProfileInstance(
const char * pname);
572 std::map<ProfileInstance *, void *> mapChildren;
581 static Profiler * getInstance();
582 void startProfile(
const char * pname);
584 void stopActiveProfiles();
587 static Profiler * profiler;
588 ProfileInstance * curProfile;
590 std::vector<ProfileInstance *> vecProfiles;
591 std::vector<ProfileInstance *> stkProfiles;
592 std::map<ProfileInstance *, void *> mapWarning;
596#define START_PROFILE(a)
597#define STOP_PROFILE(a)
598#define STOP_ACTIVE_PROFILES()
599#define PRINT_PROFILE()
605#define GF_HASH_TYPE_STR 0
606#define GF_HASH_TYPE_BUF 1
611int GfHashAddStr(
void *hash,
const char *key,
const void *data);
614void GfHashAddBuf(
void *hash,
char *key,
size_t sz,
void *data);
615const void *
GfHashRemBuf(
void *hash,
char *key,
size_t sz);
616const void *
GfHashGetBuf(
void *hash,
char *key,
size_t sz);
621#define GF_DIR_CREATION_FAILED 0
622#define GF_DIR_CREATED 1
Scalar min(Scalar x, Scalar y)
Scalar max(Scalar x, Scalar y)
float tdble
Floating point type used in TORCS.
tFList * GfDirGetListFiltered(const char *dir, const char *suffix)
Get the list of files with matching suffix of a given directory.
void GfDirFreeList(tFList *list, tfDirfreeUserData freeUserDatabool, bool freename=false, bool freedispname=false)
Free a directory list.
tFList * GfDirGetList(const char *dir)
Get the list of files of a given directory.
const void * GfHashRemStr(void *hash, char *key)
Remove an element with a string key from a hash table.
const void * GfHashGetFirst(void *hash)
Get the first user data of a hash table, this is used for table scans.
void GfHashAddBuf(void *hash, char *key, size_t sz, void *data)
Add an element with a memory buffer key to a hash table.
void GfHashRelease(void *hash, tfHashFree hashFree)
Release a hash table.
int GfHashAddStr(void *hash, const char *key, const void *data)
Add an element with a string key to a hash table.
const void * GfHashGetStr(void *hash, const char *key)
Get the user data associated with a string key.
const void * GfHashRemBuf(void *hash, char *key, size_t sz)
Remove an element with a memory buffer key from a hash table.
const void * GfHashGetBuf(void *hash, char *key, size_t sz)
Get the user data associated with a memory buffer key.
void * GfHashCreate(int type)
Create a new hash table.
const void * GfHashGetNext(void *hash)
Get the next user data of a hash table, this is used for table scans.
int GfModUnloadList(tModList **modlist)
Unload the DLLs of a list.
int GfModLoad(unsigned int gfid, char *dllname, tModList **modlist)
Load the specified DLLs.
int GfModInfo(unsigned int gfid, char *filename, tModList **modlist)
Get the generic information of the specified DLL.
int GfModFreeInfoList(tModList **modlist)
Free the info contained in the specified list.
int GfModInfoDir(unsigned int gfid, char *dir, int level, tModList **modlist)
Get the generic module information of the DLLs of the specified directory.
int GfModLoadDir(unsigned int gfid, char *dir, tModList **modlist)
Load the DLLs in the specified directory.
int GfParmSetNumEx(void *handle, const char *path, const char *key, const char *unit, tdble val, tdble min, tdble max)
Set a numerical parameter and its bounds, creating it if necessary.
const char * GfParmGetStr(void *handle, const char *path, const char *key, const char *deflt)
Get a string parameter from the parameter set handle.
int GfParmSetStr(void *handle, const char *path, const char *key, const char *val)
Set a string 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.
tdble GfParmUnit2SI(const char *unit, tdble val)
Convert a value given in unit to SI.
char * GfParmGetName(void *handle)
Get the name property of the parameter set handle.
tdble GfParmSI2Unit(const char *unit, tdble val)
Convert a value from SI to given unit.
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.
int GfParmSetNum(void *handle, const char *path, const char *key, const char *unit, tdble val)
Set a numerical parameter in the parameter set handle.
void GfParmReleaseHandle(void *handle)
Release given parameter set handle parmHandle.
int GfParmCreateDirectory(const char *file, void *parmHandle)
Create directory for parameter set handle if it does not yet exist.
char * GfParmGetFileName(void *handle)
Get the filename property of the parameter set handle.
void GfParmClean(void *handle)
Clean all the parameters of a parameter set.
int GfParmWriteFile(const char *file, void *handle, const char *name)
Write parameter set into file.
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 * GfParmMergeHandles(void *ref, void *tgt, int mode)
Merge two parameter sets into a new private set.
void GfParmSetDTD(void *parmHandle, char *dtd, char *header)
Set the dtd path and header.
void * GfParmReadFile(const char *file, int mode)
Read parameter set from file and return handle to parameter set.
char * GfParmListGetCurEltName(void *handle, const char *path)
Get current subsection name of the parameter set handle during subsection iteration.
int GfParmListSeekNext(void *handle, const char *path)
Advance to the next immediate subsection.
int GfParmListClean(void *handle, const char *path)
Remove all the subsections in a section in the parameter set handle.
int GfParmListSeekFirst(void *handle, const char *path)
Select the first immediate subsection of a section.
int GfParmGetEltNb(void *handle, const char *path)
Count the number of subsections in a section in the parameter set handle.
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 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.
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.
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.
List of (DLL) files for a Directory.
struct FList * next
Next entry.
struct FList * prev
Previous entry.
char * dispName
Name to display on screen.
void * userData
User data.
Module information structure.
char * desc
description of the module (can be long)
int index
index if multiple interface in one dll
int prio
priority if needed
unsigned int gfId
supported framework version
char * name
name of the module (short) (NULL if no module)
tfModPrivInit fctInit
init function
int magic
magic number for integrity check
list of module interfaces
tModInfo modInfo[MAX_MOD_ITF]
module info list for this dll
char * sopath
path name of file
void * handle
handle of loaded module
struct ModList * next
next module in list
Parameter set handle structure, multiple handles can reference the same parameter set.
tdble val[GF_MEAN_MAX_VAL+1]
tdble ay
angle along y axis
tdble ax
angle along x axis
tdble az
angle along z axis
void(* tfDirfreeUserData)(void *)
Function to call for releasing the user data associated with file entry.
void SetDataDir(char *buf)
void SetSingleTextureMode(void)
void gfMeanReset(tdble v, tMeanVal *pvt)
void SetLocalDir(char *buf)
int GfCreateDir(char *path)
Create directory for given path recursively, so all missing parent directories are created as well.
#define MAX_MOD_ITF
Maximum number of interface in one DLL.
void(* tfHashFree)(const void *)
Function to call for releasing the user data associated with hash table.
struct ModList tModList
list of module interfaces
static void GfFatal(const char *fmt,...)
int GfCreateDirForFile(const char *filenameandpath)
Create directory for given file path recursively, so all missing parent directories are created as we...
int GetSingleTextureMode(void)
double GfTimeClock(void)
Get the time in seconds.
int(* tfModPrivInit)(int index, void *)
initialisation of the function table
struct FList tFList
List of (DLL) files for a Directory.
tdble gfMean(tdble v, tMeanVal *pvt, int n, int w)
int(* tfModInfo)(tModInfo *)
void SetLibDir(char *buf)
struct ModInfo tModInfo
Module information structure.