trackgen: fix some cppcheck warnings

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@8149 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: 4000fd88f8ce71fe543d4905efca6e89e23de839
Former-commit-id: 386a7d1396281f07773db8ddde980af1a9801c92
This commit is contained in:
iobyte 2022-05-06 23:33:59 +00:00
parent d6a3042401
commit 82049a54e2
10 changed files with 96 additions and 105 deletions

View file

@ -42,9 +42,9 @@ Ac3dOpen(const std::string &filename, int nbObjects)
{ {
FILE *save_fd = fopen(filename.c_str(), "w"); FILE *save_fd = fopen(filename.c_str(), "w");
if (save_fd == NULL) { if (save_fd == nullptr) {
GfOut("Failed to open '%s' for writing (%s)", filename.c_str(), strerror(errno)); GfOut("Failed to open '%s' for writing (%s)", filename.c_str(), strerror(errno));
return NULL; return nullptr;
} }
fprintf(save_fd, "AC3Db\n"); fprintf(save_fd, "AC3Db\n");

View file

@ -1736,7 +1736,7 @@ groups(void)
r_node = (struct nod *)calloc(Nn, sizeof(struct nod)); r_node = (struct nod *)calloc(Nn, sizeof(struct nod));
r_elem = (struct ele *)calloc(Ne, sizeof(struct ele)); r_elem = (struct ele *)calloc(Ne, sizeof(struct ele));
r_side = (struct sid *)calloc(Ns, sizeof(struct sid)); r_side = (struct sid *)calloc(Ns, sizeof(struct sid));
if (r_side == NULL) { if (r_side == nullptr) {
fprintf(stderr, "Sorry, cannot allocate enough memory !\n"); fprintf(stderr, "Sorry, cannot allocate enough memory !\n");
return ; return ;
} }
@ -1993,9 +1993,9 @@ GenerateMesh(tTrack *Track, bool rightside, bool reverse, bool exterior, bool us
/* Right side */ /* Right side */
startNeeded = 1; startNeeded = 1;
for (i = 0, mseg = Track->seg->next; i < Track->nseg; i++, mseg = mseg->next) { for (i = 0, mseg = Track->seg->next; i < Track->nseg; i++, mseg = mseg->next) {
if (mseg->rside != NULL) { if (mseg->rside != nullptr) {
seg = mseg->rside; seg = mseg->rside;
if (seg->rside != NULL) { if (seg->rside != nullptr) {
seg = seg->rside; seg = seg->rside;
} }
} else { } else {
@ -2221,16 +2221,16 @@ GenerateTerrain(tTrack *track, void *TrackHandle, const std::string &outfile, FI
{ {
const char *FileName; const char *FileName;
const char *mat; const char *mat;
FILE *curFd = NULL; FILE *curFd = nullptr;
TrackStep = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_TSTEP, NULL, 10.0); TrackStep = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_TSTEP, nullptr, 10.0);
GfOut("Track step: %.2f\n", TrackStep); GfOut("Track step: %.2f\n", TrackStep);
Margin = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_BMARGIN, NULL, 100.0); Margin = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_BMARGIN, nullptr, 100.0);
GridStep = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_BSTEP, NULL, 10.0); GridStep = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_BSTEP, nullptr, 10.0);
ExtHeight = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_BHEIGHT, NULL, 0.0); ExtHeight = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_BHEIGHT, nullptr, 0.0);
GfOut("Border margin: %.2f step: %.2f height: %.2f\n", Margin, GridStep, ExtHeight); GfOut("Border margin: %.2f step: %.2f height: %.2f\n", Margin, GridStep, ExtHeight);
GroupSize = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_GRPSZ, NULL, 100.0); GroupSize = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_GRPSZ, nullptr, 100.0);
XGroupOffset = track->min.x - Margin; XGroupOffset = track->min.x - Margin;
YGroupOffset = track->min.y - Margin; YGroupOffset = track->min.y - Margin;
@ -2250,16 +2250,16 @@ GenerateTerrain(tTrack *track, void *TrackHandle, const std::string &outfile, FI
sprintf(buf, "%s/%s", TRK_SECT_SURFACES, mat); sprintf(buf, "%s/%s", TRK_SECT_SURFACES, mat);
} }
TexName = GfParmGetStr(TrackHandle, buf, TRK_ATT_TEXTURE, "grass.png"); TexName = GfParmGetStr(TrackHandle, buf, TRK_ATT_TEXTURE, "grass.png");
TexSize = GfParmGetNum(TrackHandle, buf, TRK_ATT_TEXSIZE, (char*)NULL, 20.0f); TexSize = GfParmGetNum(TrackHandle, buf, TRK_ATT_TEXSIZE, nullptr, 20.0f);
TexRand = GfParmGetNum(TrackHandle, buf, TRK_ATT_SURFRAND, (char*)NULL, (tdble)(TexSize / 10.0)); TexRand = GfParmGetNum(TrackHandle, buf, TRK_ATT_SURFRAND, nullptr, (tdble)(TexSize / 10.0));
FileName = GfParmGetStr(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_RELIEF, NULL); FileName = GfParmGetStr(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_RELIEF, nullptr);
if (FileName) { if (FileName) {
sprintf(buf, "tracks/%s/%s/%s", track->category, track->internalname, FileName); sprintf(buf, "tracks/%s/%s/%s", track->category, track->internalname, FileName);
LoadRelief(TrackHandle, buf); LoadRelief(TrackHandle, buf);
} }
if (noElevation == -1) { if (noElevation == -1) {
FileName = GfParmGetStr(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_ELEVATION, NULL); FileName = GfParmGetStr(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_ELEVATION, nullptr);
if (FileName) { if (FileName) {
sprintf(buf, "tracks/%s/%s/%s", track->category, track->internalname, FileName); sprintf(buf, "tracks/%s/%s/%s", track->category, track->internalname, FileName);
LoadElevation(track, TrackHandle, buf); LoadElevation(track, TrackHandle, buf);

View file

@ -63,7 +63,7 @@ void LoadElevation(tTrack *track, void *TrackHandle, const std::string &imgFile)
printf("Loading Elevation Map %s\n", imgFile.c_str()); printf("Loading Elevation Map %s\n", imgFile.c_str());
Margin = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_BMARGIN, NULL, Margin); Margin = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_BMARGIN, nullptr, Margin);
xmin = track->min.x - Margin; xmin = track->min.x - Margin;
xmax = track->max.x + Margin; xmax = track->max.x + Margin;
@ -76,8 +76,8 @@ void LoadElevation(tTrack *track, void *TrackHandle, const std::string &imgFile)
dY = -ymin * kY; dY = -ymin * kY;
ElvOk = 1; ElvOk = 1;
zmin = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_ALT_MIN, NULL, track->min.z); zmin = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_ALT_MIN, nullptr, track->min.z);
zmax = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_ALT_MAX, NULL, track->max.z); zmax = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_ALT_MAX, nullptr, track->max.z);
dZ = zmin; dZ = zmin;
kZ = (zmax - dZ) / MAX_CLR; kZ = (zmax - dZ) / MAX_CLR;
@ -86,14 +86,11 @@ void LoadElevation(tTrack *track, void *TrackHandle, const std::string &imgFile)
tdble GetElevation(tdble x, tdble y, tdble z) tdble GetElevation(tdble x, tdble y, tdble z)
{ {
int iX, iY;
int clr;
if (ElvOk) { if (ElvOk) {
iX = (int)(x * kX + dX); int iX = (int)(x * kX + dX);
iY = (int)(y * kY + dY); int iY = (int)(y * kY + dY);
/* RGBA */ /* RGBA */
clr = ElvImage[4 * (iY * width + iX)]; int clr = ElvImage[4 * (iY * width + iX)];
return (tdble)clr * kZ + dZ; return (tdble)clr * kZ + dZ;
} }
@ -101,7 +98,7 @@ tdble GetElevation(tdble x, tdble y, tdble z)
} }
void SaveElevation(tTrack *track, void *TrackHandle, const std::string &imgFile, const std::string &meshFile, int dispf, int heightSteps) void SaveElevation(tTrack *track, void *TrackHandle, const std::string &imgFile, const std::string &meshFile, int disp, int heightSteps)
{ {
ssgLoaderOptionsEx options; ssgLoaderOptionsEx options;
float zmin, zmax; float zmin, zmax;
@ -117,12 +114,12 @@ void SaveElevation(tTrack *track, void *TrackHandle, const std::string &imgFile,
s = getenv("COLUMNS"); s = getenv("COLUMNS");
if (s) { if (s) {
columns = strtol(getenv("COLUMNS"), NULL, 0); columns = strtol(getenv("COLUMNS"), nullptr, 0);
} else { } else {
columns = 80; columns = 80;
} }
Margin = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_BMARGIN, NULL, Margin); Margin = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_BMARGIN, nullptr, Margin);
xmin = track->min.x - Margin; xmin = track->min.x - Margin;
xmax = track->max.x + Margin; xmax = track->max.x + Margin;
@ -138,11 +135,11 @@ void SaveElevation(tTrack *track, void *TrackHandle, const std::string &imgFile,
kY = (ymax - ymin) / height; kY = (ymax - ymin) / height;
dY = ymin; dY = ymin;
zmin = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_ALT_MIN, NULL, track->min.z); zmin = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_ALT_MIN, nullptr, track->min.z);
zmax = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_ALT_MAX, NULL, track->max.z); zmax = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_ALT_MAX, nullptr, track->max.z);
heightStep = (float)(zmax - zmin) / (float)heightSteps; heightStep = (float)(zmax - zmin) / (float)heightSteps;
if (dispf == 2) { if (disp == 2) {
printf("Height of steps = %f\n", heightStep); printf("Height of steps = %f\n", heightStep);
} }
@ -161,7 +158,7 @@ void SaveElevation(tTrack *track, void *TrackHandle, const std::string &imgFile,
ssgModelPath(buf); ssgModelPath(buf);
root = (ssgRoot*)ssgLoadAC(meshFile.c_str()); root = (ssgRoot*)ssgLoadAC(meshFile.c_str());
if (root == NULL) { if (root == nullptr) {
printf("Could not load %s, ", meshFile.c_str()); printf("Could not load %s, ", meshFile.c_str());
printf("please generate it with \"trackgen -c %s -n %s -a\"\n", track->category, track->internalname); printf("please generate it with \"trackgen -c %s -n %s -a\"\n", track->category, track->internalname);
return; return;
@ -187,7 +184,7 @@ void SaveElevation(tTrack *track, void *TrackHandle, const std::string &imgFile,
y = j * kY + dY; y = j * kY + dY;
z = getHOT(root, x, y); z = getHOT(root, x, y);
if (z != -1000000.0f) { if (z != -1000000.0f) {
switch (dispf) { switch (disp) {
case 0: case 0:
clr = 0; clr = 0;
break; break;

View file

@ -201,7 +201,7 @@ bool Application::parseOptions()
} }
else if (itOpt->strLongName == "saveelev") else if (itOpt->strLongName == "saveelev")
{ {
DoSaveElevation = strtol(itOpt->strValue.c_str(), NULL, 0); DoSaveElevation = strtol(itOpt->strValue.c_str(), nullptr, 0);
TrackOnly = false; TrackOnly = false;
} }
else if (itOpt->strLongName == "category") else if (itOpt->strLongName == "category")
@ -210,7 +210,7 @@ bool Application::parseOptions()
} }
else if (itOpt->strLongName == "steps4") else if (itOpt->strLongName == "steps4")
{ {
HeightSteps = strtol(itOpt->strValue.c_str(), NULL, 0); HeightSteps = strtol(itOpt->strValue.c_str(), nullptr, 0);
} }
} }
@ -273,7 +273,7 @@ int Application::generate()
std::string OutputFileName(buf2); std::string OutputFileName(buf2);
// Number of groups for the complete track. // Number of groups for the complete track.
FILE *outfd = NULL; FILE *outfd = nullptr;
if (TrackOnly) { if (TrackOnly) {
// Track. // Track.
if (!Bump && !Raceline) if (!Bump && !Raceline)

View file

@ -46,9 +46,9 @@
static char path[1024]; static char path[1024];
static char buf[1024]; static char buf[1024];
static ssgRoot *Root = NULL; static ssgRoot *Root = nullptr;
static ssgRoot *GroupRoot = NULL; static ssgRoot *GroupRoot = nullptr;
static ssgRoot *TrackRoot = NULL; static ssgRoot *TrackRoot = nullptr;
struct group struct group
{ {
@ -112,7 +112,7 @@ InitObjects(tTrack *track, void *TrackHandle)
ObjUniqId = 0; ObjUniqId = 0;
srand((unsigned int)GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_SEED, NULL, 1)); srand((unsigned int)GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_SEED, nullptr, 1));
ssgSetCurrentOptions ( &options ) ; ssgSetCurrentOptions ( &options ) ;
@ -131,8 +131,8 @@ InitObjects(tTrack *track, void *TrackHandle)
for (int i = 0; i < objnb; i++) for (int i = 0; i < objnb; i++)
{ {
objdef *curObj = (struct objdef *)malloc(sizeof(struct objdef)); objdef *curObj = (struct objdef *)malloc(sizeof(struct objdef));
curObj->color = (unsigned int)GfParmGetCurNum(TrackHandle, TRK_SECT_OBJECTS, TRK_ATT_COLOR, NULL, 0); curObj->color = (unsigned int)GfParmGetCurNum(TrackHandle, TRK_SECT_OBJECTS, TRK_ATT_COLOR, nullptr, 0);
const char *objName = GfParmGetCurStr(TrackHandle, TRK_SECT_OBJECTS, TRK_ATT_OBJECT, NULL); const char *objName = GfParmGetCurStr(TrackHandle, TRK_SECT_OBJECTS, TRK_ATT_OBJECT, nullptr);
if (!objName) if (!objName)
{ {
@ -152,8 +152,8 @@ InitObjects(tTrack *track, void *TrackHandle)
if (strcmp(GfParmGetCurStr(TrackHandle, TRK_SECT_OBJECTS, TRK_ATT_ORIENTATION_TYPE, ""), "random") == 0) if (strcmp(GfParmGetCurStr(TrackHandle, TRK_SECT_OBJECTS, TRK_ATT_ORIENTATION_TYPE, ""), "random") == 0)
{ {
curObj->deltaHeight = GfParmGetCurNum(TrackHandle, TRK_SECT_OBJECTS, TRK_ATT_DH, NULL, 0); curObj->deltaHeight = GfParmGetCurNum(TrackHandle, TRK_SECT_OBJECTS, TRK_ATT_DH, nullptr, 0);
curObj->deltaVert = GfParmGetCurNum(TrackHandle, TRK_SECT_OBJECTS, TRK_ATT_DV, NULL, 5.0); curObj->deltaVert = GfParmGetCurNum(TrackHandle, TRK_SECT_OBJECTS, TRK_ATT_DV, nullptr, 5.0);
curObj->random = true; curObj->random = true;
} }
else else
@ -185,7 +185,7 @@ InitObjects(tTrack *track, void *TrackHandle)
if (strcmp(GfParmGetCurStr(TrackHandle, TRK_SECT_OBJECTS, TRK_ATT_ORIENTATION_TYPE, ""), "border") == 0) if (strcmp(GfParmGetCurStr(TrackHandle, TRK_SECT_OBJECTS, TRK_ATT_ORIENTATION_TYPE, ""), "border") == 0)
{ {
curObj->borderOriented = true; curObj->borderOriented = true;
curObj->distance = GfParmGetCurNum(TrackHandle, TRK_SECT_OBJECTS, TRK_ATT_BORDER_DISTANCE, NULL, 1.0); curObj->distance = GfParmGetCurNum(TrackHandle, TRK_SECT_OBJECTS, TRK_ATT_BORDER_DISTANCE, nullptr, 1.0);
} }
else else
{ {
@ -343,18 +343,18 @@ ssgSaveLeaf (ssgEntity *ent, FILE *save_fd)
{ {
const char* tfname = ss->getTextureFilename (); const char* tfname = ss->getTextureFilename ();
if ((tfname != NULL) && (tfname[0] != 0)) if ((tfname != nullptr) && (tfname[0] != 0))
{ {
if (writeTextureWithoutPath) if (writeTextureWithoutPath)
{ {
char *s = strrchr ((char *)tfname, '\\'); char *s = strrchr ((char *)tfname, '\\');
if (s == NULL) if (s == nullptr)
{ {
s = strrchr ((char *)tfname, '/'); s = strrchr ((char *)tfname, '/');
} }
if (s == NULL) if (s == nullptr)
{ {
fprintf (save_fd, "texture \"%s\"\n", tfname); fprintf (save_fd, "texture \"%s\"\n", tfname);
} }
@ -485,8 +485,8 @@ Group(tTrack *track, void *TrackHandle, ssgEntity *ent)
GroupRoot = new ssgRoot(); GroupRoot = new ssgRoot();
Margin = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_BMARGIN, NULL, 100.0); Margin = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_BMARGIN, nullptr, 100.0);
GroupSize = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_GRPSZ, NULL, 100.0); GroupSize = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_GRPSZ, nullptr, 100.0);
XGroupOffset = track->min.x - Margin; XGroupOffset = track->min.x - Margin;
YGroupOffset = track->min.y - Margin; YGroupOffset = track->min.y - Margin;
@ -509,17 +509,12 @@ void
GenerateObjects(tTrack *track, void *TrackHandle, void *CfgHandle, FILE *save_fd, const std::string &meshFile, const std::string &outputFile) GenerateObjects(tTrack *track, void *TrackHandle, void *CfgHandle, FILE *save_fd, const std::string &meshFile, const std::string &outputFile)
{ {
ssgLoaderOptionsEx options; ssgLoaderOptionsEx options;
int i, j;
const char *map;
unsigned char *MapImage;
int width, height; int width, height;
tdble xmin, xmax, ymin, ymax; tdble xmin, xmax, ymin, ymax;
tdble Margin; tdble Margin;
tdble kX, kY, dX, dY; tdble kX, kY, dX, dY;
unsigned int clr; unsigned int clr;
int index; int index;
const char *extName;
FILE *curFd;
ssgSetCurrentOptions(&options); ssgSetCurrentOptions(&options);
sprintf(buf, "tracks/%s/%s;data/textures;data/img;.", track->category, track->internalname); sprintf(buf, "tracks/%s/%s;data/textures;data/img;.", track->category, track->internalname);
@ -530,7 +525,7 @@ GenerateObjects(tTrack *track, void *TrackHandle, void *CfgHandle, FILE *save_fd
InitObjects(track, TrackHandle); InitObjects(track, TrackHandle);
Margin = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_BMARGIN, NULL, 0); Margin = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_BMARGIN, nullptr, 0);
xmin = track->min.x - Margin; xmin = track->min.x - Margin;
xmax = track->max.x + Margin; xmax = track->max.x + Margin;
@ -552,11 +547,11 @@ GenerateObjects(tTrack *track, void *TrackHandle, void *CfgHandle, FILE *save_fd
Root = new ssgRoot(); Root = new ssgRoot();
index++; index++;
map = GfParmGetCurStr(TrackHandle, path, TRK_ATT_OBJMAP, ""); const char *map = GfParmGetCurStr(TrackHandle, path, TRK_ATT_OBJMAP, "");
sprintf(buf, "tracks/%s/%s/%s", track->category, track->internalname, map); sprintf(buf, "tracks/%s/%s/%s", track->category, track->internalname, map);
printf("Processing object map %s\n", buf); printf("Processing object map %s\n", buf);
MapImage = GfTexReadImageFromPNG(buf, 2.2, &width, &height, 0, 0, false); unsigned char *MapImage = GfTexReadImageFromPNG(buf, 2.2, &width, &height, 0, 0, false);
if (!MapImage) if (!MapImage)
{ {
@ -568,9 +563,9 @@ GenerateObjects(tTrack *track, void *TrackHandle, void *CfgHandle, FILE *save_fd
kY = (ymax - ymin) / height; kY = (ymax - ymin) / height;
dY = ymin; dY = ymin;
for (j = 0; j < height; j++) for (int j = 0; j < height; j++)
{ {
for (i = 0; i < width; i++) for (int i = 0; i < width; i++)
{ {
clr = (MapImage[4 * (i + width * j)] << 16) + (MapImage[4 * (i + width * j) + 1] << 8) + MapImage[4 * (i + width * j) + 2]; clr = (MapImage[4 * (i + width * j)] << 16) + (MapImage[4 * (i + width * j) + 1] << 8) + MapImage[4 * (i + width * j) + 2];
@ -583,9 +578,9 @@ GenerateObjects(tTrack *track, void *TrackHandle, void *CfgHandle, FILE *save_fd
Group(track, TrackHandle, Root); Group(track, TrackHandle, Root);
extName = GfParmGetStr(CfgHandle, "Files", "object", "obj"); const char *extName = GfParmGetStr(CfgHandle, "Files", "object", "obj");
sprintf(buf, "%s-%s-%d.ac", outputFile.c_str(), extName, index); sprintf(buf, "%s-%s-%d.ac", outputFile.c_str(), extName, index);
curFd = Ac3dOpen(buf, 1); FILE *curFd = Ac3dOpen(buf, 1);
ssgSaveACInner(GroupRoot, curFd); ssgSaveACInner(GroupRoot, curFd);
Ac3dClose(curFd); Ac3dClose(curFd);

View file

@ -33,7 +33,7 @@ struct RacelineSegment
}; };
static const double SegLength = 2.0; static const double SegLength = 2.0;
static RacelineSegment* rlseg = NULL; static RacelineSegment* rlseg = nullptr;
static int nSegments = 0; static int nSegments = 0;
static double SideDistExt = 2.0; // Security distance wrt outside static double SideDistExt = 2.0; // Security distance wrt outside
static double SideDistInt = 2.0; // Security distance wrt inside static double SideDistInt = 2.0; // Security distance wrt inside
@ -43,7 +43,7 @@ static const double SecurityR = 100.0; // Security radius
static void SplitTrack(tTrack *ptrack) static void SplitTrack(tTrack *ptrack)
{ {
const tTrackSeg *seg = ptrack->seg; const tTrackSeg *seg = ptrack->seg;
const tTrackSeg *first = NULL; const tTrackSeg *first = nullptr;
// Find pointer to start (seems not to start at the "start" all the time, e.g e-track-1) // Find pointer to start (seems not to start at the "start" all the time, e.g e-track-1)
do { do {
if (seg->lgfromstart == 0.0) if (seg->lgfromstart == 0.0)

View file

@ -55,7 +55,7 @@ tRingListHead ExteriorList;
static tdble GridStep; static tdble GridStep;
static ssgEntity *Root = NULL; static ssgEntity *Root = nullptr;
/* /*
* Read the faces from AC3D file * Read the faces from AC3D file
@ -87,7 +87,7 @@ LoadRelief(void *TrackHandle, const char *reliefFile)
GF_TAILQ_INIT(&InteriorList); GF_TAILQ_INIT(&InteriorList);
GF_TAILQ_INIT(&ExteriorList); GF_TAILQ_INIT(&ExteriorList);
GridStep = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_BSTEP, NULL, GridStep); GridStep = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_BSTEP, nullptr, GridStep);
ssgLoaderOptions *loaderopt = new ssgLoaderOptions(); ssgLoaderOptions *loaderopt = new ssgLoaderOptions();
@ -124,7 +124,7 @@ CountRelief(bool interior, int *nb_vert, int *nb_seg)
*nb_vert = *nb_seg = 0; *nb_vert = *nb_seg = 0;
if (Root == NULL) { if (Root == nullptr) {
return; return;
} }
@ -135,7 +135,7 @@ CountRelief(bool interior, int *nb_vert, int *nb_seg)
} }
curLine = GF_TAILQ_FIRST(curHead); curLine = GF_TAILQ_FIRST(curHead);
while (curLine != NULL) { while (curLine != nullptr) {
ssgBranch *br = curLine->branch->getParent(0); ssgBranch *br = curLine->branch->getParent(0);
ssgBranch *br2 = new ssgBranch(); ssgBranch *br2 = new ssgBranch();
@ -200,7 +200,7 @@ GenRelief(bool interior)
tRingListHead *curHead; tRingListHead *curHead;
if (Root == NULL) { if (Root == nullptr) {
return; return;
} }
@ -211,7 +211,7 @@ GenRelief(bool interior)
} }
curLine = GF_TAILQ_FIRST(curHead); curLine = GF_TAILQ_FIRST(curHead);
while (curLine != NULL) { while (curLine != nullptr) {
genRec((ssgEntity *)curLine->branch); genRec((ssgEntity *)curLine->branch);
curLine = GF_TAILQ_NEXT(curLine, link); curLine = GF_TAILQ_NEXT(curLine, link);

View file

@ -86,8 +86,8 @@ static tdble TrackStep;
static void initPits(tTrack *theTrack, void *TrackHandle, tTrackPitInfo *pits) { static void initPits(tTrack *theTrack, void *TrackHandle, tTrackPitInfo *pits) {
tTrackSeg *curMainSeg; tTrackSeg *curMainSeg;
tTrackSeg *curPitSeg = NULL; tTrackSeg *curPitSeg = nullptr;
tTrackSeg *pitBuildingsStart = NULL; tTrackSeg *pitBuildingsStart = nullptr;
const char *segName; const char *segName;
tTrkLocPos curPos; tTrkLocPos curPos;
int i; int i;
@ -112,7 +112,7 @@ static void initPits(tTrack *theTrack, void *TrackHandle, tTrackPitInfo *pits) {
curPos.type = TR_TOMIDDLE; curPos.type = TR_TOMIDDLE;
//TR_LPOS_MAIN; //NB: TR_LPOS_MAIN not handled by RtTrackLocal2Global! //TR_LPOS_MAIN; //NB: TR_LPOS_MAIN not handled by RtTrackLocal2Global!
segName = GfParmGetStr(TrackHandle, path2, TRK_ATT_BUILDINGS_START, NULL); segName = GfParmGetStr(TrackHandle, path2, TRK_ATT_BUILDINGS_START, nullptr);
if (segName != 0) { if (segName != 0) {
pitBuildingsStart = theTrack->seg; pitBuildingsStart = theTrack->seg;
found = false; found = false;
@ -131,12 +131,12 @@ static void initPits(tTrack *theTrack, void *TrackHandle, tTrackPitInfo *pits) {
if (!found) if (!found)
{ {
pitBuildingsStart = NULL; pitBuildingsStart = nullptr;
} }
} }
if (pitBuildingsStart == NULL) { if (pitBuildingsStart == nullptr) {
if (pits->pitStart == NULL) { if (pits->pitStart == nullptr) {
GfLogError("Can't find pit start\n"); GfLogError("Can't find pit start\n");
exit(1); exit(1);
} }
@ -256,7 +256,7 @@ InitScene(tTrack *Track, void *TrackHandle, bool bump, bool raceline)
{ {
int i; int i;
tTrackSeg *seg; tTrackSeg *seg;
tTrackSeg *lastSeg = NULL; tTrackSeg *lastSeg = nullptr;
tTrackSeg *mseg; tTrackSeg *mseg;
int nbvert; int nbvert;
tdble width; tdble width;
@ -272,7 +272,7 @@ InitScene(tTrack *Track, void *TrackHandle, bool bump, bool raceline)
tdble xprev = 0; tdble xprev = 0;
tdble yprev = 0; tdble yprev = 0;
tDispElt *aDispElt = NULL; tDispElt *aDispElt = nullptr;
unsigned int prevTexId; unsigned int prevTexId;
unsigned int curTexId = 0; unsigned int curTexId = 0;
int curTexType = 0; int curTexType = 0;
@ -281,8 +281,8 @@ InitScene(tTrack *Track, void *TrackHandle, bool bump, bool raceline)
tdble curTexSeg; tdble curTexSeg;
tdble curTexSize = 0; tdble curTexSize = 0;
tdble curHeight; tdble curHeight;
tTexElt *texList = (tTexElt*)NULL; tTexElt *texList = nullptr;
tTexElt *curTexElt = NULL; tTexElt *curTexElt = nullptr;
tTrackBarrier *curBarrier; tTrackBarrier *curBarrier;
tdble texLen; tdble texLen;
tdble texStep; tdble texStep;
@ -297,7 +297,7 @@ InitScene(tTrack *Track, void *TrackHandle, bool bump, bool raceline)
tdble tmHSpace = Track->graphic.turnMarksInfo.hSpace; tdble tmHSpace = Track->graphic.turnMarksInfo.hSpace;
char buf[256]; char buf[256];
int hasBorder; int hasBorder;
tDispElt *theCurDispElt = NULL; tDispElt *theCurDispElt = nullptr;
char sname[256]; char sname[256];
// float dmax = 0; // float dmax = 0;
@ -344,9 +344,9 @@ InitScene(tTrack *Track, void *TrackHandle, bool bump, bool raceline)
if (raceline) if (raceline)
{ {
double SideDistExt = GfParmGetNum(TrackHandle, TRK_SECT_MAIN, TRK_ATT_RLEXT, (char*)NULL, 2.0); double SideDistExt = GfParmGetNum(TrackHandle, TRK_SECT_MAIN, TRK_ATT_RLEXT, nullptr, 2.0);
double SideDistInt = GfParmGetNum(TrackHandle, TRK_SECT_MAIN, TRK_ATT_RLINT, (char*)NULL, 2.0); double SideDistInt = GfParmGetNum(TrackHandle, TRK_SECT_MAIN, TRK_ATT_RLINT, nullptr, 2.0);
rlWidthScale = GfParmGetNum(TrackHandle, TRK_SECT_MAIN, TRK_ATT_RLWIDTHSCALE, (char*)NULL, 1.0); rlWidthScale = GfParmGetNum(TrackHandle, TRK_SECT_MAIN, TRK_ATT_RLWIDTHSCALE, nullptr, 1.0);
rlOffset = (1.0 - 1.0/rlWidthScale)/2.0; rlOffset = (1.0 - 1.0/rlWidthScale)/2.0;
generateRaceLine(Track, SideDistExt, SideDistInt); generateRaceLine(Track, SideDistExt, SideDistInt);
} }
@ -356,7 +356,7 @@ InitScene(tTrack *Track, void *TrackHandle, bool bump, bool raceline)
#define SETTEXTURE(texname, texnamebump, texnameraceline, _mipmap) do { \ #define SETTEXTURE(texname, texnamebump, texnameraceline, _mipmap) do { \
int found = 0; \ int found = 0; \
curTexElt = texList; \ curTexElt = texList; \
if (curTexElt == NULL) { \ if (curTexElt == nullptr) { \
curTexElt = (tTexElt*)calloc(1, sizeof(tTexElt)); \ curTexElt = (tTexElt*)calloc(1, sizeof(tTexElt)); \
curTexElt->next = curTexElt; \ curTexElt->next = curTexElt; \
texList = curTexElt; \ texList = curTexElt; \
@ -392,7 +392,7 @@ InitScene(tTrack *Track, void *TrackHandle, bool bump, bool raceline)
#define NEWDISPLIST(texchange, _name, _id) do { \ #define NEWDISPLIST(texchange, _name, _id) do { \
if (!bump || (*(curTexElt->namebump) != 0)) { \ if (!bump || (*(curTexElt->namebump) != 0)) { \
if (theCurDispElt != NULL) { \ if (theCurDispElt != nullptr) { \
startNeeded = texchange; \ startNeeded = texchange; \
if (theCurDispElt->start != nbvert) { \ if (theCurDispElt->start != nbvert) { \
theCurDispElt->nb = nbvert - theCurDispElt->start; \ theCurDispElt->nb = nbvert - theCurDispElt->start; \
@ -448,7 +448,7 @@ InitScene(tTrack *Track, void *TrackHandle, bool bump, bool raceline)
texnamebump = GfParmGetStr(TrackHandle, path_, TRK_ATT_BUMPNAME, ""); \ texnamebump = GfParmGetStr(TrackHandle, path_, TRK_ATT_BUMPNAME, ""); \
texnameraceline = GfParmGetStr(TrackHandle, path_, TRK_ATT_RACELINENAME, "raceline.png"); \ texnameraceline = GfParmGetStr(TrackHandle, path_, TRK_ATT_RACELINENAME, "raceline.png"); \
texname = GfParmGetStr(TrackHandle, path_, TRK_ATT_TEXTURE, "tr-asphalt.png"); \ texname = GfParmGetStr(TrackHandle, path_, TRK_ATT_TEXTURE, "tr-asphalt.png"); \
mipmap = (int)GfParmGetNum(TrackHandle, path_, TRK_ATT_TEXMIPMAP, (char*)NULL, 0); \ mipmap = (int)GfParmGetNum(TrackHandle, path_, TRK_ATT_TEXMIPMAP, nullptr, 0); \
SETTEXTURE(texname, texnamebump, texnameraceline, mipmap); \ SETTEXTURE(texname, texnamebump, texnameraceline, mipmap); \
if ((curTexId != prevTexId) || (startNeeded)) { \ if ((curTexId != prevTexId) || (startNeeded)) { \
const char *textype; \ const char *textype; \
@ -456,7 +456,7 @@ InitScene(tTrack *Track, void *TrackHandle, bool bump, bool raceline)
curTexType = 1; \ curTexType = 1; \
curTexLink = 1; \ curTexLink = 1; \
curTexOffset = -off; \ curTexOffset = -off; \
curTexSize = GfParmGetNum(TrackHandle, path_, TRK_ATT_BUMPSIZE, (char*)NULL, 20.0); \ curTexSize = GfParmGetNum(TrackHandle, path_, TRK_ATT_BUMPSIZE, nullptr, 20.0); \
} else { \ } else { \
textype = GfParmGetStr(TrackHandle, path_, TRK_ATT_TEXTYPE, "continuous"); \ textype = GfParmGetStr(TrackHandle, path_, TRK_ATT_TEXTYPE, "continuous"); \
if (strcmp(textype, "continuous") == 0) \ if (strcmp(textype, "continuous") == 0) \
@ -473,7 +473,7 @@ InitScene(tTrack *Track, void *TrackHandle, bool bump, bool raceline)
curTexOffset = -off; \ curTexOffset = -off; \
else \ else \
curTexOffset = 0; \ curTexOffset = 0; \
curTexSize = GfParmGetNum(TrackHandle, path_, TRK_ATT_TEXSIZE, (char*)NULL, 20.0); \ curTexSize = GfParmGetNum(TrackHandle, path_, TRK_ATT_TEXSIZE, nullptr, 20.0); \
} \ } \
prevTexId = curTexId; \ prevTexId = curTexId; \
NEWDISPLIST(1, name, id); \ NEWDISPLIST(1, name, id); \
@ -707,7 +707,7 @@ InitScene(tTrack *Track, void *TrackHandle, bool bump, bool raceline)
runninglentgh = 0; runninglentgh = 0;
sprintf(sname, "t%dRB", j); sprintf(sname, "t%dRB", j);
for (i = 0, mseg = Track->seg->next; i < Track->nseg; i++, mseg = mseg->next) { for (i = 0, mseg = Track->seg->next; i < Track->nseg; i++, mseg = mseg->next) {
if ((mseg->rside != NULL) && (mseg->rside->type2 == TR_RBORDER)) { if ((mseg->rside != nullptr) && (mseg->rside->type2 == TR_RBORDER)) {
seg = mseg->rside; seg = mseg->rside;
CHECKDISPLIST(seg->surface->material, sname, i, mseg->lgfromstart); CHECKDISPLIST(seg->surface->material, sname, i, mseg->lgfromstart);
if (!curTexLink) { if (!curTexLink) {
@ -1086,10 +1086,10 @@ InitScene(tTrack *Track, void *TrackHandle, bool bump, bool raceline)
runninglentgh = 0; runninglentgh = 0;
hasBorder = 0; hasBorder = 0;
for (i = 0, mseg = Track->seg->next; i < Track->nseg; i++, mseg = mseg->next) { for (i = 0, mseg = Track->seg->next; i < Track->nseg; i++, mseg = mseg->next) {
if ((mseg->rside != NULL) && if ((mseg->rside != nullptr) &&
((mseg->rside->type2 == TR_RSIDE) || (mseg->rside->rside != NULL))) { ((mseg->rside->type2 == TR_RSIDE) || (mseg->rside->rside != nullptr))) {
seg = mseg->rside; seg = mseg->rside;
if (seg->rside != NULL) { if (seg->rside != nullptr) {
seg = seg->rside; seg = seg->rside;
if (hasBorder == 0) { if (hasBorder == 0) {
startNeeded = 1; startNeeded = 1;
@ -1241,7 +1241,7 @@ InitScene(tTrack *Track, void *TrackHandle, bool bump, bool raceline)
runninglentgh = 0; runninglentgh = 0;
sprintf(sname, "t%dLB", j); sprintf(sname, "t%dLB", j);
for (i = 0, mseg = Track->seg->next; i < Track->nseg; i++, mseg = mseg->next) { for (i = 0, mseg = Track->seg->next; i < Track->nseg; i++, mseg = mseg->next) {
if ((mseg->lside != NULL) && (mseg->lside->type2 == TR_LBORDER)) { if ((mseg->lside != nullptr) && (mseg->lside->type2 == TR_LBORDER)) {
seg = mseg->lside; seg = mseg->lside;
CHECKDISPLIST(seg->surface->material, sname, i, mseg->lgfromstart); CHECKDISPLIST(seg->surface->material, sname, i, mseg->lgfromstart);
if (!curTexLink) { if (!curTexLink) {
@ -1614,8 +1614,8 @@ InitScene(tTrack *Track, void *TrackHandle, bool bump, bool raceline)
runninglentgh = 0; runninglentgh = 0;
hasBorder = 0; hasBorder = 0;
for (i = 0, mseg = Track->seg->next; i < Track->nseg; i++, mseg = mseg->next) { for (i = 0, mseg = Track->seg->next; i < Track->nseg; i++, mseg = mseg->next) {
if ((mseg->lside != NULL) && if ((mseg->lside != nullptr) &&
((mseg->lside->type2 == TR_LSIDE) || (mseg->lside->lside != NULL))) { ((mseg->lside->type2 == TR_LSIDE) || (mseg->lside->lside != nullptr))) {
seg = mseg->lside; seg = mseg->lside;
if (seg->lside) { if (seg->lside) {
seg = seg->lside; seg = seg->lside;
@ -1768,7 +1768,7 @@ InitScene(tTrack *Track, void *TrackHandle, bool bump, bool raceline)
runninglentgh = 0; runninglentgh = 0;
sprintf(sname, "B%dRt", j); sprintf(sname, "B%dRt", j);
for (i = 0, mseg = Track->seg->next; i < Track->nseg; i++, mseg = mseg->next) { for (i = 0, mseg = Track->seg->next; i < Track->nseg; i++, mseg = mseg->next) {
if ((mseg->rside != NULL) && (mseg->rside->raceInfo & TR_PITBUILD)) { if ((mseg->rside != nullptr) && (mseg->rside->raceInfo & TR_PITBUILD)) {
startNeeded = 1; startNeeded = 1;
runninglentgh = 0; runninglentgh = 0;
NEWDISPLIST(0, sname, i); NEWDISPLIST(0, sname, i);
@ -2038,7 +2038,7 @@ InitScene(tTrack *Track, void *TrackHandle, bool bump, bool raceline)
runninglentgh = 0; runninglentgh = 0;
sprintf(sname, "B%dLt", j); sprintf(sname, "B%dLt", j);
for (i = 0, mseg = Track->seg->next; i < Track->nseg; i++, mseg = mseg->next) { for (i = 0, mseg = Track->seg->next; i < Track->nseg; i++, mseg = mseg->next) {
if ((mseg->lside != NULL) && (mseg->lside->raceInfo & TR_PITBUILD)) { if ((mseg->lside != nullptr) && (mseg->lside->raceInfo & TR_PITBUILD)) {
runninglentgh = 0; runninglentgh = 0;
startNeeded = 1; startNeeded = 1;
NEWDISPLIST(0, sname, i); NEWDISPLIST(0, sname, i);
@ -2785,7 +2785,7 @@ SaveMainTrack(FILE *curFd, bool bump, bool raceline)
*/ */
void CalculateTrack(tTrack * Track, void *TrackHandle, bool bump, bool raceline) void CalculateTrack(tTrack * Track, void *TrackHandle, bool bump, bool raceline)
{ {
TrackStep = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_TSTEP, NULL, TrackStep); TrackStep = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_TSTEP, nullptr, TrackStep);
printf("Track step: %.2f ", TrackStep); printf("Track step: %.2f ", TrackStep);
InitScene(Track, TrackHandle, bump, raceline); InitScene(Track, TrackHandle, bump, raceline);
@ -2804,7 +2804,7 @@ void CalculateTrack(tTrack * Track, void *TrackHandle, bool bump, bool raceline)
void void
GenerateTrack(tTrack * Track, void *TrackHandle, const std::string &outFile, FILE *AllFd, bool bump, bool raceline) GenerateTrack(tTrack * Track, void *TrackHandle, const std::string &outFile, FILE *AllFd, bool bump, bool raceline)
{ {
TrackStep = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_TSTEP, NULL, TrackStep); TrackStep = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_TSTEP, nullptr, TrackStep);
printf("Track step: %.2f ", TrackStep); printf("Track step: %.2f ", TrackStep);
InitScene(Track, TrackHandle, bump, raceline); InitScene(Track, TrackHandle, bump, raceline);

View file

@ -225,11 +225,10 @@ float
getBorderAngle(tTrack *Track, void *TrackHandle, float x, float y, float distance, float *xRet, float *yRet, float *zRet ) getBorderAngle(tTrack *Track, void *TrackHandle, float x, float y, float distance, float *xRet, float *yRet, float *zRet )
{ {
float angle=0, dst=100000, shDst=100000; float angle=0, dst=100000, shDst=100000;
int i;
tTrackSeg *seg = Track->seg; tTrackSeg *seg = Track->seg;
tTrkLocPos curPos, closePos, objPos; tTrkLocPos curPos, closePos, objPos;
float x2, y2, x3, y3; float x2, y2, x3, y3;
for(i = 0; i < Track->nseg; i++) for(int i = 0; i < Track->nseg; i++)
{ {
seg=seg->next; seg=seg->next;
curPos.seg=seg; curPos.seg=seg;
@ -300,7 +299,7 @@ getBorderAngle(tTrack *Track, void *TrackHandle, float x, float y, float distanc
curPos.toStart+=0.001; curPos.toStart+=0.001;
RtTrackLocal2Global(&curPos, &x2, &y2, TR_TORIGHT); RtTrackLocal2Global(&curPos, &x2, &y2, TR_TORIGHT);
angle=-90.0-atan2f(x2-x3,y2-y3)*180/PI; angle=-90.0-atan2f(x2-x3,y2-y3)*180/PI;
RtTrackLocal2Global(&objPos, &*xRet, &*yRet, TR_TORIGHT); RtTrackLocal2Global(&objPos, xRet, yRet, TR_TORIGHT);
} }
else else
// left side // left side
@ -310,7 +309,7 @@ getBorderAngle(tTrack *Track, void *TrackHandle, float x, float y, float distanc
curPos.toStart+=0.001; curPos.toStart+=0.001;
RtTrackLocal2Global(&curPos, &x2, &y2, TR_TOLEFT); RtTrackLocal2Global(&curPos, &x2, &y2, TR_TOLEFT);
angle=90.0-atan2f(x2-x3,y2-y3)*180/PI; angle=90.0-atan2f(x2-x3,y2-y3)*180/PI;
RtTrackLocal2Global(&objPos, &*xRet, &*yRet, TR_TOLEFT); RtTrackLocal2Global(&objPos, xRet, yRet, TR_TOLEFT);
} }
*zRet=RtTrackHeightG(seg, *xRet, *yRet); *zRet=RtTrackHeightG(seg, *xRet, *yRet);

View file

@ -45,12 +45,12 @@ class ssgLoaderOptionsEx : public ssgLoaderOptions
virtual void makeModelPath ( char* path, const char *fname ) const virtual void makeModelPath ( char* path, const char *fname ) const
{ {
ulFindFile ( path, model_dir, fname, NULL ) ; ulFindFile ( path, model_dir, fname, nullptr ) ;
} }
virtual void makeTexturePath ( char* path, const char *fname ) const virtual void makeTexturePath ( char* path, const char *fname ) const
{ {
ulFindFile ( path, texture_dir, fname, NULL ) ; ulFindFile ( path, texture_dir, fname, nullptr ) ;
} }
}; };