26#include <portability.h>
43void * _tgf_win_malloc(
size_t size)
46 char *
p = (
char*)GlobalAlloc(GMEM_FIXED, size + 3*
sizeof(
int));
47 *(
int*)(
p) = size + 3*
sizeof(int);
48 *((
int*)
p + 1) = 123456789;
49 *((
int*)(
p + size + 3*
sizeof(
int)) - 1) = 987654321;
51 return p + 2*
sizeof(int);
53 char *
p = (
char*)GlobalAlloc(GMEM_FIXED, size +
sizeof(
int));
58 return p +
sizeof(int);
63void * _tgf_win_calloc(
size_t num,
size_t size)
65 void *
p = _tgf_win_malloc(num * size);
66 memset(
p, 0, num * size);
71void * _tgf_win_realloc(
void * memblock,
size_t size)
74 _tgf_win_free(memblock);
78 void *
p = _tgf_win_malloc(size);
83 if (memblock != NULL) {
86 min(*(
int*)((
char*)memblock-2*
sizeof(
int)) - 3*
sizeof(
int), (
int)size));
88 memcpy(
p, memblock,
min(*(
int*)((
char*)memblock-
sizeof(
int)), (
int)size));
90 _tgf_win_free(memblock);
96void _tgf_win_free(
void * memblock)
103 char *
p = (
char*)memblock - 2*
sizeof(
int);
105 if (!_CrtIsValidPointer(
p,
sizeof(
int), TRUE)) {
109 if (!_CrtIsValidPointer(
p, *(
int*)
p, TRUE)) {
113 if (*((
int*)
p + 1) != 123456789) {
117 if(*((
int*)(
p + *(
int*)
p ) - 1) != 987654321) {
121 GlobalFree((
char*)memblock - 2*
sizeof(
int));
123 GlobalFree((
char*)memblock -
sizeof(
int));
128char * _tgf_win_strdup(
const char * str)
130 char * s = (
char*)_tgf_win_malloc(strlen(str)+1);
172 for (i = 0; i < n; i++) {
173 pvt->
val[i] = pvt->
val[i + 1];
179 sum /= (
tdble)(n + w);
207 int h = (int)(sec / 3600.0);
209 int m = (int)(sec / 60.0);
213 int c = (int)floor((sec) * 100.0);
216 snprintf(result, resultSize,
"%s%2.2d:%2.2d:%2.2d:%2.2d",
sign, h, m, s, c);
218 snprintf(result, resultSize,
" %s%2.2d:%2.2d:%2.2d",
sign, m, s, c);
220 snprintf(result, resultSize,
" %s%2.2d:%2.2d",
sign, s, c);
294 while ((1 << r) < x) {
314 const int BUFSIZE = 1024;
316 size_t pathLen = strlen(path);
317 if (pathLen >= BUFSIZE) {
318 GfError(
"GfCreateDir: path too long: %s\n", path);
321 memcpy(buf, path, pathLen + 1);
324#define mkdir(x) _mkdir(x)
327 const char DELIM =
'\\';
329 for (i = 0; i < BUFSIZE && buf[i] !=
'\0'; i++) {
336#define mkdir(x) mkdir((x), S_IRWXU);
338 const char DELIM =
'/';
342 int err =
mkdir(buf);
344 if (
errno == ENOENT) {
345 char *end = strrchr(buf, DELIM);
354 if (err == -1 &&
errno != EEXIST) {
370 if (filenameandpath == 0) {
374 const char* lastdelim = strrchr(filenameandpath,
'/');
375 if (lastdelim != NULL && lastdelim != filenameandpath) {
376 const int BUFSIZE = 1024;
378 const int size =
MIN(lastdelim - filenameandpath, BUFSIZE - 1);
379 snprintf(buf, BUFSIZE,
"%s", filenameandpath);
Scalar min(Scalar x, Scalar y)
void GfParmInit(void)
Parameter set library API initialization, set up parameter set handle cache.
float tdble
Floating point type used in TORCS.
void GfTime2Str(char *result, int resultSize, tdble sec, int sgn)
Convert a time in seconds (float) to an ascii string.
tdble val[GF_MEAN_MAX_VAL+1]
static int singleTextureMode
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.
void gfOsInit(void)
Init of the module.
int GfCreateDirForFile(const char *filenameandpath)
Create directory for given file path recursively, so all missing parent directories are created as we...
int GetSingleTextureMode(void)
tdble gfMean(tdble v, tMeanVal *pvt, int n, int w)
void SetLibDir(char *buf)
The Gaming Framework API.
#define GF_DIR_CREATION_FAILED