TORCS  1.3.9
The Open Racing Car Simulator
tgf.h File Reference

The Gaming Framework API. More...

#include <stdio.h>
#include <sys/param.h>
#include <assert.h>
#include <stdlib.h>
#include <stdarg.h>
#include <cstring>
#include <math.h>
#include <osspec.h>
Include dependency graph for tgf.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  t3Df
 
struct  t3Dd
 3D point. More...
 
struct  t3Di
 
struct  tPosd
 6 DOF position. More...
 
struct  tDynPt
 Dynamic point structure. More...
 
struct  tForces
 Forces and moments. More...
 
struct  ModInfo
 Module information structure. More...
 
struct  ModList
 list of module interfaces More...
 
struct  FList
 List of (DLL) files for a Directory. More...
 
struct  tMeanVal
 

Macros

#define MAX(x, y)   ((x) > (y) ? (x) : (y))
 
#define MIN(x, y)   ((x) < (y) ? (x) : (y))
 
#define FREEZ(x)
 
#define freez   FREEZ
 
#define RADS2RPM(x)   ((x)*9.549296585)
 Radian/s to RPM conversion. More...
 
#define RPM2RADS(x)   ((x)*.104719755)
 RPM to Radian/s conversion. More...
 
#define RAD2DEG(x)   ((x)*(180.0/PI))
 Radian to degree conversion. More...
 
#define DEG2RAD(x)   ((x)*(PI/180.0))
 Degree to radian conversion. More...
 
#define FEET2M(x)   ((x)*0.304801)
 Feet to meter conversion. More...
 
#define SIGN(x)   ((x) < 0.0f ? -1.0f : 1.0f)
 Sign of the expression. More...
 
#define NORM0_2PI(x)
 Angle normalization between 0 and 2 * PI. More...
 
#define NORM_PI_PI(x)
 Angle normalization between -PI and PI. More...
 
#define DIST(x1, y1, x2, y2)   sqrt(((x1) - (x2)) * ((x1) - (x2)) + ((y1) - (y2)) * ((y1) - (y2)))
 Distance between two points. More...
 
#define MAX_MOD_ITF   10
 Maximum number of interface in one DLL. More...
 
#define GFPARM_PARAMETER   0
 Parameter file. More...
 
#define GFPARM_TEMPLATE   1
 Template file. More...
 
#define GFPARM_PARAM_STR   "param"
 
#define GFPARM_TEMPL_STR   "template"
 
#define GFPARM_MODIFIABLE   1
 Parameter file allowed to be modified. More...
 
#define GFPARM_WRITABLE   2
 Parameter file allowed to be saved on disk. More...
 
#define GFPARM_RMODE_STD   0x01
 if handle already openned return it More...
 
#define GFPARM_RMODE_REREAD   0x02
 reread the parameters from file and release the previous ones More...
 
#define GFPARM_RMODE_CREAT   0x04
 Create the file if doesn't exist. More...
 
#define GFPARM_RMODE_PRIVATE   0x08
 
#define GFPARM_MMODE_SRC   1
 use ref and modify existing parameters with tgt More...
 
#define GFPARM_MMODE_DST   2
 use tgt and verify ref parameters More...
 
#define GFPARM_MMODE_RELSRC   4
 release ref after the merge More...
 
#define GFPARM_MMODE_RELDST   8
 release tgt after the merge More...
 
#define GfTrace   printf
 
#define GfError   printf
 
#define GfOut   printf
 
#define GF_MEAN_MAX_VAL   5
 
#define GF_TAILQ_HEAD(name, type)
 Head type definition. More...
 
#define GF_TAILQ_ENTRY(type)
 Entry in structure. More...
 
#define GF_TAILQ_FIRST(head)   ((head)->tqh_first)
 First element of a TAILQ. More...
 
#define GF_TAILQ_NEXT(elm, field)   ((elm)->field.tqe_next)
 Next element of a TAILQ. More...
 
#define GF_TAILQ_END(head)   NULL
 End of a TAILQ. More...
 
#define GF_TAILQ_LAST(head, headname)   (*(((struct headname *)((head)->tqh_last))->tqh_last))
 Last element of a TAILQ. More...
 
#define GF_TAILQ_PREV(elm, headname, field)   (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
 Previous element of a TAILQ. More...
 
#define GF_TAILQ_INIT(head)
 Head initialization (Mandatory) More...
 
#define GF_TAILQ_INIT_ENTRY(elm, field)
 Entry initialization (optionnal if inserted) More...
 
#define GF_TAILQ_INSERT_HEAD(head, elm, field)
 Insert an element at the head. More...
 
#define GF_TAILQ_INSERT_TAIL(head, elm, field)
 Insert an element at the tail. More...
 
#define GF_TAILQ_INSERT_AFTER(head, listelm, elm, field)
 Insert an element after another element. More...
 
#define GF_TAILQ_INSERT_BEFORE(listelm, elm, field)
 Insert an element before another element. More...
 
#define GF_TAILQ_REMOVE(head, elm, field)
 Remove an element. More...
 
#define START_PROFILE(a)
 
#define STOP_PROFILE(a)
 
#define STOP_ACTIVE_PROFILES()
 
#define PRINT_PROFILE()
 
#define GF_HASH_TYPE_STR   0
 String key based hash table. More...
 
#define GF_HASH_TYPE_BUF   1
 Memory buffer key based hash table. More...
 
#define GF_DIR_CREATION_FAILED   0
 
#define GF_DIR_CREATED   1
 

Typedefs

typedef float tdble
 Floating point type used in TORCS. More...
 
typedef int(* tfModPrivInit) (int index, void *)
 initialisation of the function table More...
 
typedef struct ModInfo tModInfo
 Module information structure. More...
 
typedef int(* tfModInfo) (tModInfo *)
 
typedef struct ModList tModList
 list of module interfaces More...
 
typedef struct FList tFList
 List of (DLL) files for a Directory. More...
 
typedef void(* tfDirfreeUserData) (void *)
 Function to call for releasing the user data associated with file entry. More...
 
typedef void(* tfHashFree) (const void *)
 Function to call for releasing the user data associated with hash table. More...
 

Functions

void GfInit (void)
 
int GfModLoad (unsigned int gfid, char *dllname, tModList **modlist)
 Load the specified DLLs. More...
 
int GfModLoadDir (unsigned int gfid, char *dir, tModList **modlist)
 Load the DLLs in the specified directory. More...
 
int GfModUnloadList (tModList **modlist)
 Unload the DLLs of a list. More...
 
int GfModInfo (unsigned int gfid, char *filename, tModList **modlist)
 Get the generic information of the specified DLL. More...
 
int GfModInfoDir (unsigned int gfid, char *dir, int level, tModList **modlist)
 Get the generic module information of the DLLs of the specified directory. More...
 
int GfModFreeInfoList (tModList **modlist)
 Free the info contained in the specified list. More...
 
tFListGfDirGetList (const char *dir)
 Get the list of files of a given directory. More...
 
tFListGfDirGetListFiltered (const char *dir, const char *suffix)
 Get the list of files with matching suffix of a given directory. More...
 
void GfDirFreeList (tFList *list, tfDirfreeUserData freeUserDatabool, bool freename=false, bool freedispname=false)
 Free a directory list. More...
 
void * GfParmReadFile (const char *file, int mode)
 Read parameter set from file and return handle to parameter set. More...
 
int GfParmWriteFile (const char *file, void *handle, const char *name)
 Write parameter set into file. More...
 
int GfParmCreateDirectory (const char *file, void *parmHandle)
 Create directory for parameter set handle if it does not yet exist. More...
 
char * GfParmGetName (void *handle)
 Get the name property of the parameter set handle. More...
 
char * GfParmGetFileName (void *handle)
 Get the filename property of the parameter set handle. More...
 
void GfParmSetDTD (void *parmHandle, char *dtd, char *header)
 Set the dtd path and header. More...
 
const char * GfParmGetStr (void *handle, const char *path, const char *key, const char *deflt)
 Get a string parameter from the parameter set handle. More...
 
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. More...
 
int GfParmSetStr (void *handle, const char *path, const char *key, const char *val)
 Set a string parameter in the parameter set handle. More...
 
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. More...
 
tdble GfParmGetNum (void *handle, const char *path, const char *key, const char *unit, tdble deflt)
 Get a numerical parameter from the parameter set handle. More...
 
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. More...
 
int GfParmSetNum (void *handle, const char *path, const char *key, const char *unit, tdble val)
 Set a numerical parameter in the parameter set handle. More...
 
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. More...
 
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. More...
 
void GfParmClean (void *handle)
 Clean all the parameters of a parameter set. More...
 
void GfParmReleaseHandle (void *handle)
 Release given parameter set handle parmHandle. More...
 
tdble GfParmUnit2SI (const char *unit, tdble val)
 Convert a value given in unit to SI. More...
 
tdble GfParmSI2Unit (const char *unit, tdble val)
 Convert a value from SI to given unit. More...
 
int GfParmCheckHandle (void *ref, void *tgt)
 Check the values in the parameter set tgt against the min/max/within definitions in the ref parameter set. More...
 
void * GfParmMergeHandles (void *ref, void *tgt, int mode)
 Merge two parameter sets into a new one, either containing parameters from ref, tgt or from both sets, the ref and tgt sets are not changed. More...
 
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. More...
 
int GfParmGetEltNb (void *handle, const char *path)
 Count the number of subsections in a section in the parameter set handle. More...
 
int GfParmListSeekFirst (void *handle, const char *path)
 Go the the first subsection element in the parameter set handle. More...
 
int GfParmListSeekNext (void *handle, const char *path)
 Go the the next subsection element in the parameter set handle. More...
 
char * GfParmListGetCurEltName (void *handle, const char *path)
 Get current subsection name of the parameter set handle during subsection iteration. More...
 
int GfParmListClean (void *handle, const char *path)
 Remove all the subsections in a section in the parameter set handle. More...
 
static void GfFatal (const char *fmt,...)
 
double GfTimeClock (void)
 Get the time in seconds. More...
 
tdble gfMean (tdble v, tMeanVal *pvt, int n, int w)
 
void gfMeanReset (tdble v, tMeanVal *pvt)
 
char * GetLocalDir (void)
 
void SetLocalDir (char *buf)
 
char * GetLibDir (void)
 
void SetLibDir (char *buf)
 
char * GetDataDir (void)
 
void SetDataDir (char *buf)
 
int GetSingleTextureMode (void)
 
void SetSingleTextureMode (void)
 
int GfNearestPow2 (int x)
 
int GfCreateDir (char *path)
 Create directory for given path recursively, so all missing parent directories are created as well. More...
 
int GfCreateDirForFile (const char *filenameandpath)
 Create directory for given file path recursively, so all missing parent directories are created as well. More...
 
void * GfHashCreate (int type)
 Create a new hash table. More...
 
int GfHashAddStr (void *hash, const char *key, const void *data)
 Add an element with a string key to a hash table. More...
 
const void * GfHashRemStr (void *hash, char *key)
 Remove an element with a string key from a hash table. More...
 
const void * GfHashGetStr (void *hash, const char *key)
 Get the user data associated with a string key. More...
 
void GfHashAddBuf (void *hash, char *key, size_t sz, void *data)
 Add an element with a memory buffer key to a hash table. More...
 
const void * GfHashRemBuf (void *hash, char *key, size_t sz)
 Remove an element with a memory buffer key from a hash table. More...
 
const void * GfHashGetBuf (void *hash, char *key, size_t sz)
 Get the user data associated with a memory buffer key. More...
 
void GfHashRelease (void *hash, tfHashFree hashFree)
 Release a hash table. More...
 
const void * GfHashGetFirst (void *hash)
 Get the first user data of a hash table, this is used for table scans. More...
 
const void * GfHashGetNext (void *hash)
 Get the next user data of a hash table, this is used for table scans. More...
 

Variables

const double PI = 3.14159265358979323846
 PI. More...
 
const tdble G = 9.80665f
 m/s/s More...
 

Detailed Description

The Gaming Framework API.

Author
Bernhard Wymann, Eric Espie
Version
$Id$

Definition in file tgf.h.

Macro Definition Documentation

◆ DEG2RAD

#define DEG2RAD (   x)    ((x)*(PI/180.0))

Degree to radian conversion.

Definition at line 76 of file tgf.h.

◆ DIST

#define DIST (   x1,
  y1,
  x2,
  y2 
)    sqrt(((x1) - (x2)) * ((x1) - (x2)) + ((y1) - (y2)) * ((y1) - (y2)))

Distance between two points.

Definition at line 97 of file tgf.h.

◆ FEET2M

#define FEET2M (   x)    ((x)*0.304801)

Feet to meter conversion.

Definition at line 77 of file tgf.h.

◆ FREEZ

#define FREEZ (   x)
Value:
do { \
if (x) { \
free(x); \
x = 0; \
} \
} while (0)

Definition at line 60 of file tgf.h.

◆ freez

#define freez   FREEZ

Definition at line 67 of file tgf.h.

◆ GF_DIR_CREATED

#define GF_DIR_CREATED   1

Definition at line 623 of file tgf.h.

◆ GF_DIR_CREATION_FAILED

#define GF_DIR_CREATION_FAILED   0

Definition at line 622 of file tgf.h.

◆ GF_HASH_TYPE_BUF

#define GF_HASH_TYPE_BUF   1

Memory buffer key based hash table.

Definition at line 607 of file tgf.h.

◆ GF_HASH_TYPE_STR

#define GF_HASH_TYPE_STR   0

String key based hash table.

Definition at line 606 of file tgf.h.

◆ GF_MEAN_MAX_VAL

#define GF_MEAN_MAX_VAL   5

Definition at line 383 of file tgf.h.

◆ GfError

#define GfError   printf

Definition at line 351 of file tgf.h.

◆ GfOut

#define GfOut   printf

Definition at line 373 of file tgf.h.

◆ GFPARM_MMODE_DST

#define GFPARM_MMODE_DST   2

use tgt and verify ref parameters

Definition at line 314 of file tgf.h.

◆ GFPARM_MMODE_RELDST

#define GFPARM_MMODE_RELDST   8

release tgt after the merge

Definition at line 316 of file tgf.h.

◆ GFPARM_MMODE_RELSRC

#define GFPARM_MMODE_RELSRC   4

release ref after the merge

Definition at line 315 of file tgf.h.

◆ GFPARM_MMODE_SRC

#define GFPARM_MMODE_SRC   1

use ref and modify existing parameters with tgt

Definition at line 313 of file tgf.h.

◆ GFPARM_MODIFIABLE

#define GFPARM_MODIFIABLE   1

Parameter file allowed to be modified.

Definition at line 261 of file tgf.h.

◆ GFPARM_PARAM_STR

#define GFPARM_PARAM_STR   "param"

Definition at line 257 of file tgf.h.

◆ GFPARM_PARAMETER

#define GFPARM_PARAMETER   0

Parameter file.

Definition at line 255 of file tgf.h.

◆ GFPARM_RMODE_CREAT

#define GFPARM_RMODE_CREAT   0x04

Create the file if doesn't exist.

Definition at line 267 of file tgf.h.

◆ GFPARM_RMODE_PRIVATE

#define GFPARM_RMODE_PRIVATE   0x08

Definition at line 268 of file tgf.h.

◆ GFPARM_RMODE_REREAD

#define GFPARM_RMODE_REREAD   0x02

reread the parameters from file and release the previous ones

Definition at line 266 of file tgf.h.

◆ GFPARM_RMODE_STD

#define GFPARM_RMODE_STD   0x01

if handle already openned return it

Definition at line 265 of file tgf.h.

◆ GFPARM_TEMPL_STR

#define GFPARM_TEMPL_STR   "template"

Definition at line 258 of file tgf.h.

◆ GFPARM_TEMPLATE

#define GFPARM_TEMPLATE   1

Template file.

Definition at line 256 of file tgf.h.

◆ GFPARM_WRITABLE

#define GFPARM_WRITABLE   2

Parameter file allowed to be saved on disk.

Definition at line 262 of file tgf.h.

◆ GfTrace

#define GfTrace   printf

Definition at line 336 of file tgf.h.

◆ MAX

#define MAX (   x,
  y 
)    ((x) > (y) ? (x) : (y))

Definition at line 53 of file tgf.h.

◆ MAX_MOD_ITF

#define MAX_MOD_ITF   10

Maximum number of interface in one DLL.

See also
ModList

Definition at line 185 of file tgf.h.

◆ MIN

#define MIN (   x,
  y 
)    ((x) < (y) ? (x) : (y))

Definition at line 57 of file tgf.h.

◆ NORM0_2PI

#define NORM0_2PI (   x)
Value:
do { \
while ((x) > 2.0*PI) { (x) -= (tdble) (2.0*PI); } \
while ((x) < 0.0) { (x) += (tdble) (2.0*PI); } \
} while (0)
const double PI
PI.
Definition: tgf.h:69
float tdble
Floating point type used in TORCS.
Definition: tgf.h:48

Angle normalization between 0 and 2 * PI.

Definition at line 81 of file tgf.h.

◆ NORM_PI_PI

#define NORM_PI_PI (   x)
Value:
do { \
while ((x) > PI) { (x) -= (tdble) (2.0*PI); } \
while ((x) < -PI) { (x) += (tdble) (2.0*PI); } \
} while (0)
const double PI
PI.
Definition: tgf.h:69
float tdble
Floating point type used in TORCS.
Definition: tgf.h:48

Angle normalization between -PI and PI.

Definition at line 88 of file tgf.h.

◆ PRINT_PROFILE

#define PRINT_PROFILE ( )

Definition at line 600 of file tgf.h.

◆ RAD2DEG

#define RAD2DEG (   x)    ((x)*(180.0/PI))

Radian to degree conversion.

Definition at line 75 of file tgf.h.

◆ RADS2RPM

#define RADS2RPM (   x)    ((x)*9.549296585)

Radian/s to RPM conversion.

Definition at line 73 of file tgf.h.

◆ RPM2RADS

#define RPM2RADS (   x)    ((x)*.104719755)

RPM to Radian/s conversion.

Definition at line 74 of file tgf.h.

◆ SIGN

#define SIGN (   x)    ((x) < 0.0f ? -1.0f : 1.0f)

Sign of the expression.

Definition at line 78 of file tgf.h.

◆ START_PROFILE

#define START_PROFILE (   a)

Definition at line 597 of file tgf.h.

◆ STOP_ACTIVE_PROFILES

#define STOP_ACTIVE_PROFILES ( )

Definition at line 599 of file tgf.h.

◆ STOP_PROFILE

#define STOP_PROFILE (   a)

Definition at line 598 of file tgf.h.

Typedef Documentation

◆ tfDirfreeUserData

typedef void(* tfDirfreeUserData) (void *)

Function to call for releasing the user data associated with file entry.

Definition at line 240 of file tgf.h.

◆ tfHashFree

typedef void(* tfHashFree) (const void *)

Function to call for releasing the user data associated with hash table.

Definition at line 609 of file tgf.h.

◆ tFList

typedef struct FList tFList

List of (DLL) files for a Directory.

See also
GfDirGetList

◆ tfModInfo

typedef int(* tfModInfo) (tModInfo *)

Definition at line 200 of file tgf.h.

◆ tfModPrivInit

typedef int(* tfModPrivInit) (int index, void *)

initialisation of the function table

See also
ModInfo

Definition at line 180 of file tgf.h.

◆ tModInfo

typedef struct ModInfo tModInfo

Module information structure.

◆ tModList

typedef struct ModList tModList

list of module interfaces

Function Documentation

◆ GetDataDir()

char* GetDataDir ( void  )

Definition at line 257 of file tgf.cpp.

◆ GetLibDir()

char* GetLibDir ( void  )

Definition at line 244 of file tgf.cpp.

◆ GetLocalDir()

char* GetLocalDir ( void  )

Definition at line 231 of file tgf.cpp.

◆ GetSingleTextureMode()

int GetSingleTextureMode ( void  )

Definition at line 273 of file tgf.cpp.

◆ GfCreateDir()

int GfCreateDir ( char *  path)

Create directory for given path recursively, so all missing parent directories are created as well.

Parameters
[in]pathPath
Returns
GF_DIR_CREATED if directory was created or already exits
GF_DIR_CREATION_FAILED if directory could not be created

Definition at line 309 of file tgf.cpp.

Here is the call graph for this function:

◆ GfCreateDirForFile()

int GfCreateDirForFile ( const char *  filenameandpath)

Create directory for given file path recursively, so all missing parent directories are created as well.

Parameters
[in]filenameandpathPath including file name
Returns
GF_DIR_CREATED if directory was created or already exits
GF_DIR_CREATION_FAILED if directory could not be created
See also
GfCreateDir

Definition at line 364 of file tgf.cpp.

Here is the call graph for this function:

◆ GfFatal()

static void GfFatal ( const char *  fmt,
  ... 
)
inlinestatic

Definition at line 339 of file tgf.h.

◆ GfInit()

void GfInit ( void  )

Definition at line 138 of file tgf.cpp.

Here is the call graph for this function:

◆ gfMean()

tdble gfMean ( tdble  v,
tMeanVal pvt,
int  n,
int  w 
)

Definition at line 157 of file tgf.cpp.

◆ gfMeanReset()

void gfMeanReset ( tdble  v,
tMeanVal pvt 
)

Definition at line 147 of file tgf.cpp.

◆ GfNearestPow2()

int GfNearestPow2 ( int  x)

Definition at line 285 of file tgf.cpp.

◆ GfTimeClock()

double GfTimeClock ( void  )

Get the time in seconds.

Returns
Time in seconds since the start of the system

Definition at line 50 of file os.cpp.

◆ SetDataDir()

void SetDataDir ( char *  buf)

Definition at line 263 of file tgf.cpp.

◆ SetLibDir()

void SetLibDir ( char *  buf)

Definition at line 250 of file tgf.cpp.

◆ SetLocalDir()

void SetLocalDir ( char *  buf)

Definition at line 237 of file tgf.cpp.

◆ SetSingleTextureMode()

void SetSingleTextureMode ( void  )

Definition at line 279 of file tgf.cpp.

Variable Documentation

◆ G

const tdble G = 9.80665f

m/s/s

Definition at line 70 of file tgf.h.

◆ PI

const double PI = 3.14159265358979323846

PI.

Definition at line 69 of file tgf.h.