move some global variables into Application::generate function
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@8113 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: e700d76441f7744a8000eee8e8aa0a24e218d5b5 Former-commit-id: 539a263a9443799c4b84d6e3fefa90cec63789b2
This commit is contained in:
parent
73fea8b353
commit
e5e5fb4d3a
11 changed files with 63 additions and 87 deletions
|
@ -38,14 +38,14 @@
|
|||
|
||||
|
||||
FILE *
|
||||
Ac3dOpen(char *filename, int nbObjects)
|
||||
Ac3dOpen(const std::string &filename, int nbObjects)
|
||||
{
|
||||
FILE *save_fd;
|
||||
|
||||
save_fd = fopen(filename, "w"); //save_fd = fopen(filename, "wa");
|
||||
save_fd = fopen(filename.c_str(), "w"); //save_fd = fopen(filename.c_str(), "wa");
|
||||
|
||||
if (save_fd == NULL) {
|
||||
GfOut("Failed to open '%s' for writing (%s)", filename, strerror(errno));
|
||||
GfOut("Failed to open '%s' for writing (%s)", filename.c_str(), strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#ifndef _AC3D_H_
|
||||
#define _AC3D_H_
|
||||
|
||||
extern FILE *Ac3dOpen(char *filename, int nbObjects);
|
||||
extern FILE *Ac3dOpen(const std::string &filename, int nbObjects);
|
||||
extern int Ac3dGroup(FILE *save_fd, const char *name, int nbObjects);
|
||||
extern void Ac3dClose(FILE *save_fd);
|
||||
|
||||
|
|
|
@ -2217,7 +2217,7 @@ GenerateMesh(tTrack *Track, int rightside, int reverse, int exterior)
|
|||
|
||||
|
||||
void
|
||||
GenerateTerrain(tTrack *track, void *TrackHandle, char *outfile, FILE *AllFd, int noElevation)
|
||||
GenerateTerrain(tTrack *track, void *TrackHandle, const std::string &outfile, FILE *AllFd, int noElevation)
|
||||
{
|
||||
const char *FileName;
|
||||
const char *mat;
|
||||
|
@ -2266,7 +2266,7 @@ GenerateTerrain(tTrack *track, void *TrackHandle, char *outfile, FILE *AllFd, in
|
|||
}
|
||||
}
|
||||
|
||||
if (outfile) {
|
||||
if (!outfile.empty()) {
|
||||
// Attempt to fix AC3D (the application) segfault on opening the msh file.
|
||||
//curFd = Ac3dOpen(outfile, 2);
|
||||
curFd = Ac3dOpen(outfile, 1);
|
||||
|
|
|
@ -55,7 +55,7 @@ struct seg
|
|||
|
||||
extern struct seg *segment;
|
||||
|
||||
extern void GenerateTerrain(tTrack *track, void *TrackHandle, char *outfile, FILE *AllFd, int noElevation);
|
||||
extern void GenerateTerrain(tTrack *track, void *TrackHandle, const std::string &outfile, FILE *AllFd, int noElevation);
|
||||
|
||||
extern int Nc;
|
||||
extern int Fl;
|
||||
|
|
|
@ -51,17 +51,17 @@ static int width, height;
|
|||
|
||||
#define MAX_CLR 255.0
|
||||
|
||||
void LoadElevation(tTrack *track, void *TrackHandle, char *imgFile)
|
||||
void LoadElevation(tTrack *track, void *TrackHandle, const std::string &imgFile)
|
||||
{
|
||||
tdble zmin, zmax;
|
||||
tdble xmin, xmax, ymin, ymax;
|
||||
|
||||
ElvImage = GfTexReadImageFromPNG(imgFile, 2.2, &width, &height, 0, 0, false);
|
||||
ElvImage = GfTexReadImageFromPNG(imgFile.c_str(), 2.2, &width, &height, 0, 0, false);
|
||||
if (!ElvImage) {
|
||||
return;
|
||||
}
|
||||
|
||||
printf("Loading Elevation Map %s\n", imgFile);
|
||||
printf("Loading Elevation Map %s\n", imgFile.c_str());
|
||||
|
||||
Margin = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_BMARGIN, NULL, Margin);
|
||||
|
||||
|
@ -101,7 +101,7 @@ tdble GetElevation(tdble x, tdble y, tdble z)
|
|||
}
|
||||
|
||||
|
||||
void SaveElevation(tTrack *track, void *TrackHandle, char *imgFile, char *meshFile, int dispf)
|
||||
void SaveElevation(tTrack *track, void *TrackHandle, const std::string &imgFile, const std::string &meshFile, int dispf)
|
||||
{
|
||||
ssgLoaderOptionsEx options;
|
||||
float zmin, zmax;
|
||||
|
@ -132,7 +132,7 @@ void SaveElevation(tTrack *track, void *TrackHandle, char *imgFile, char *meshFi
|
|||
width = 1024;
|
||||
height = (int)((ymax - ymin) * width / (xmax - xmin));
|
||||
|
||||
printf("Generating Elevation Map %s (%d, %d)\n", imgFile, width, height);
|
||||
printf("Generating Elevation Map %s (%d, %d)\n", imgFile.c_str(), width, height);
|
||||
kX = (xmax - xmin) / width;
|
||||
dX = xmin;
|
||||
kY = (ymax - ymin) / height;
|
||||
|
@ -159,10 +159,10 @@ void SaveElevation(tTrack *track, void *TrackHandle, char *imgFile, char *meshFi
|
|||
ssgTexturePath(buf);
|
||||
sprintf(buf, ".;tracks/%s/%s", track->category, track->internalname);
|
||||
ssgModelPath(buf);
|
||||
root = (ssgRoot*)ssgLoadAC(meshFile);
|
||||
root = (ssgRoot*)ssgLoadAC(meshFile.c_str());
|
||||
|
||||
if (root == NULL) {
|
||||
printf("Could not load %s, ", meshFile);
|
||||
printf("Could not load %s, ", meshFile.c_str());
|
||||
printf("please generate it with \"trackgen -c %s -n %s -a\"\n", track->category, track->internalname);
|
||||
return;
|
||||
}
|
||||
|
@ -212,5 +212,5 @@ void SaveElevation(tTrack *track, void *TrackHandle, char *imgFile, char *meshFi
|
|||
}
|
||||
|
||||
printf("\n");
|
||||
GfTexWriteImageToPNG(ElvImage, imgFile, width, height);
|
||||
GfTexWriteImageToPNG(ElvImage, imgFile.c_str(), width, height);
|
||||
}
|
||||
|
|
|
@ -26,9 +26,9 @@
|
|||
#ifndef _ELEVATION_H_
|
||||
#define _ELEVATION_H_
|
||||
|
||||
extern void LoadElevation(tTrack *track, void *TrackHandle, char *imgFile);
|
||||
extern void LoadElevation(tTrack *track, void *TrackHandle, const std::string &imgFile);
|
||||
extern tdble GetElevation(tdble x, tdble y, tdble z);
|
||||
extern void SaveElevation(tTrack *track, void *TrackHandle, char *imgFile, char *meshFile, int disp);
|
||||
extern void SaveElevation(tTrack *track, void *TrackHandle, const std::string &imgFile, const std::string &meshFile, int disp);
|
||||
|
||||
|
||||
#endif /* _ELEVATION_H_ */
|
||||
|
|
|
@ -70,30 +70,18 @@ int Bump = 0;
|
|||
int Raceline = 0;
|
||||
int UseBorder = 1;
|
||||
|
||||
char *OutputFileName;
|
||||
char *TrackName;
|
||||
char *TrackCategory;
|
||||
|
||||
void *TrackHandle;
|
||||
void *CfgHandle;
|
||||
|
||||
tTrack *Track;
|
||||
ITrackLoader* PiTrackLoader;
|
||||
|
||||
int TrackOnly;
|
||||
int JustCalculate;
|
||||
int MergeAll;
|
||||
int MergeTerrain;
|
||||
|
||||
static char buf[1024];
|
||||
static char buf2[1024];
|
||||
static char trackdef[1024];
|
||||
|
||||
char *OutTrackName;
|
||||
char *OutMeshName;
|
||||
|
||||
int DoSaveElevation;
|
||||
char *ElevationFile;
|
||||
|
||||
class Application : public GfApplication
|
||||
{
|
||||
|
@ -243,9 +231,6 @@ bool Application::parseOptions()
|
|||
|
||||
void Application::generate()
|
||||
{
|
||||
const char *extName;
|
||||
FILE *outfd = NULL;
|
||||
|
||||
// Get the trackgen paramaters.
|
||||
CfgHandle = GfParmReadFile(CFG_FILE, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT);
|
||||
|
||||
|
@ -272,6 +257,7 @@ void Application::generate()
|
|||
}
|
||||
|
||||
// This is the track definition.
|
||||
char trackdef[1024];
|
||||
sprintf(trackdef, "%stracks/%s/%s/%s.xml", GfDataDir(), TrackCategory, TrackName, TrackName);
|
||||
TrackHandle = GfParmReadFile(trackdef, GFPARM_RMODE_STD);
|
||||
if (!TrackHandle) {
|
||||
|
@ -281,43 +267,42 @@ void Application::generate()
|
|||
}
|
||||
|
||||
// Build the track structure with graphic extensions.
|
||||
Track = PiTrackLoader->load(trackdef, true);
|
||||
tTrack *Track = PiTrackLoader->load(trackdef, true);
|
||||
|
||||
if (!JustCalculate) {
|
||||
// Get the output file radix.
|
||||
sprintf(buf2, "%stracks/%s/%s/%s", GfDataDir(), Track->category, Track->internalname, Track->internalname);
|
||||
OutputFileName = strdup(buf2);
|
||||
|
||||
// Number of groups for the complete track.
|
||||
if (TrackOnly) {
|
||||
sprintf(buf2, "%s.ac", OutputFileName);
|
||||
// Track.
|
||||
if (!Bump && !Raceline)
|
||||
outfd = Ac3dOpen(buf2, 1);
|
||||
} else if (MergeAll) {
|
||||
sprintf(buf2, "%s.ac", OutputFileName);
|
||||
// track + terrain + objects.
|
||||
outfd = Ac3dOpen(buf2, 2 + GetObjectsNb(TrackHandle));
|
||||
}
|
||||
|
||||
// Main Track.
|
||||
if (Bump) {
|
||||
extName = "trk-bump";
|
||||
} else if (Raceline) {
|
||||
extName = "trk-raceline";
|
||||
} else {
|
||||
extName = "trk";
|
||||
}
|
||||
|
||||
sprintf(buf2, "%s-%s.ac", OutputFileName, extName);
|
||||
OutTrackName = strdup(buf2);
|
||||
}
|
||||
|
||||
if (JustCalculate){
|
||||
if (JustCalculate) {
|
||||
CalculateTrack(Track, TrackHandle, Bump, Raceline);
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the output file radix.
|
||||
char buf2[1024];
|
||||
sprintf(buf2, "%stracks/%s/%s/%s", GfDataDir(), Track->category, Track->internalname, Track->internalname);
|
||||
std::string OutputFileName(buf2);
|
||||
|
||||
// Number of groups for the complete track.
|
||||
FILE *outfd = NULL;
|
||||
if (TrackOnly) {
|
||||
// Track.
|
||||
if (!Bump && !Raceline)
|
||||
outfd = Ac3dOpen(OutputFileName + ".ac", 1);
|
||||
} else if (MergeAll) {
|
||||
// track + terrain + objects.
|
||||
outfd = Ac3dOpen(OutputFileName + ".ac", 2 + GetObjectsNb(TrackHandle));
|
||||
}
|
||||
|
||||
// Main Track.
|
||||
const char *extName;
|
||||
if (Bump) {
|
||||
extName = "trk-bump";
|
||||
} else if (Raceline) {
|
||||
extName = "trk-raceline";
|
||||
} else {
|
||||
extName = "trk";
|
||||
}
|
||||
|
||||
sprintf(buf2, "%s-%s.ac", OutputFileName.c_str(), extName);
|
||||
std::string OutTrackName(buf2);
|
||||
|
||||
GenerateTrack(Track, TrackHandle, OutTrackName, outfd, Bump, Raceline);
|
||||
|
||||
if (TrackOnly) {
|
||||
|
@ -326,14 +311,11 @@ void Application::generate()
|
|||
|
||||
// Terrain.
|
||||
if (MergeTerrain && !MergeAll) {
|
||||
sprintf(buf2, "%s.ac", OutputFileName);
|
||||
/* terrain + objects */
|
||||
outfd = Ac3dOpen(buf2, 1 + GetObjectsNb(TrackHandle));
|
||||
outfd = Ac3dOpen(OutputFileName + ".ac", 1 + GetObjectsNb(TrackHandle));
|
||||
}
|
||||
|
||||
extName = "msh";
|
||||
sprintf(buf2, "%s-%s.ac", OutputFileName, extName);
|
||||
OutMeshName = strdup(buf2);
|
||||
std::string OutMeshName(OutputFileName + "-msh.ac");
|
||||
|
||||
GenerateTerrain(Track, TrackHandle, OutMeshName, outfd, DoSaveElevation);
|
||||
|
||||
|
@ -344,36 +326,31 @@ void Application::generate()
|
|||
switch (DoSaveElevation) {
|
||||
case 0:
|
||||
case 1:
|
||||
sprintf(buf2, "%s.ac", OutputFileName);
|
||||
sprintf(buf, "%s-elv.png", OutputFileName);
|
||||
SaveElevation(Track, TrackHandle, buf, buf2, 1);
|
||||
SaveElevation(Track, TrackHandle, OutputFileName + "-elv.png", OutputFileName + ".ac", 1);
|
||||
if (DoSaveElevation) {
|
||||
break;
|
||||
}
|
||||
SD_FALLTHROUGH // [[fallthrough]]
|
||||
case 2:
|
||||
sprintf(buf, "%s-elv2.png", OutputFileName);
|
||||
SaveElevation(Track, TrackHandle, buf, OutMeshName, 1);
|
||||
SaveElevation(Track, TrackHandle, OutputFileName + "-elv2.png", OutMeshName, 1);
|
||||
if (DoSaveElevation) {
|
||||
break;
|
||||
}
|
||||
SD_FALLTHROUGH // [[fallthrough]]
|
||||
case 3:
|
||||
sprintf(buf, "%s-elv3.png", OutputFileName);
|
||||
SaveElevation(Track, TrackHandle, buf, OutMeshName, 0);
|
||||
SaveElevation(Track, TrackHandle, OutputFileName + "-elv3.png", OutMeshName, 0);
|
||||
if (DoSaveElevation) {
|
||||
break;
|
||||
}
|
||||
SD_FALLTHROUGH // [[fallthrough]]
|
||||
case 4:
|
||||
sprintf(buf, "%s-elv4.png", OutputFileName);
|
||||
SaveElevation(Track, TrackHandle, buf, OutTrackName, 2);
|
||||
SaveElevation(Track, TrackHandle, OutputFileName + "-elv4.png", OutTrackName, 2);
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
GenerateObjects(Track, TrackHandle, CfgHandle, outfd, OutMeshName);
|
||||
GenerateObjects(Track, TrackHandle, CfgHandle, outfd, OutMeshName, OutputFileName);
|
||||
|
||||
GfParmReleaseHandle(TrackHandle);
|
||||
GfParmReleaseHandle(CfgHandle);
|
||||
|
|
|
@ -523,7 +523,7 @@ Group(tTrack *track, void *TrackHandle, ssgEntity *ent)
|
|||
|
||||
|
||||
void
|
||||
GenerateObjects(tTrack *track, void *TrackHandle, void *CfgHandle, FILE *save_fd, char *meshFile)
|
||||
GenerateObjects(tTrack *track, void *TrackHandle, void *CfgHandle, FILE *save_fd, const std::string &meshFile, const std::string &outputFile)
|
||||
{
|
||||
ssgLoaderOptionsEx options;
|
||||
int i, j;
|
||||
|
@ -543,7 +543,7 @@ GenerateObjects(tTrack *track, void *TrackHandle, void *CfgHandle, FILE *save_fd
|
|||
ssgTexturePath(buf);
|
||||
sprintf(buf, ".;tracks/%s/%s", track->category, track->internalname);
|
||||
ssgModelPath(buf);
|
||||
TrackRoot = (ssgRoot*)ssgLoadAC(meshFile);
|
||||
TrackRoot = (ssgRoot*)ssgLoadAC(meshFile.c_str());
|
||||
|
||||
InitObjects(track, TrackHandle);
|
||||
|
||||
|
@ -601,7 +601,7 @@ GenerateObjects(tTrack *track, void *TrackHandle, void *CfgHandle, FILE *save_fd
|
|||
Group(track, TrackHandle, Root);
|
||||
|
||||
extName = GfParmGetStr(CfgHandle, "Files", "object", "obj");
|
||||
sprintf(buf, "%s-%s-%d.ac", OutputFileName, extName, index);
|
||||
sprintf(buf, "%s-%s-%d.ac", outputFile.c_str(), extName, index);
|
||||
curFd = Ac3dOpen(buf, 1);
|
||||
ssgSaveACInner(GroupRoot, curFd);
|
||||
Ac3dClose(curFd);
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#ifndef _OBJECTS_H_
|
||||
#define _OBJECTS_H_
|
||||
|
||||
extern void GenerateObjects(tTrack *track, void *TrackHandle, void *CfgHandle, FILE *save_fd, char *meshFile);
|
||||
extern void GenerateObjects(tTrack *track, void *TrackHandle, void *CfgHandle, FILE *save_fd, const std::string &meshFile, const std::string &outputFile);
|
||||
extern int GetObjectsNb(void *TrackHandle);
|
||||
|
||||
#endif /* _OBJECTS_H_ */
|
||||
|
|
|
@ -2797,7 +2797,7 @@ void CalculateTrack(tTrack * Track, void *TrackHandle, int bump, int raceline)
|
|||
@return none
|
||||
*/
|
||||
void
|
||||
GenerateTrack(tTrack * Track, void *TrackHandle, char *outFile, FILE *AllFd, int bump, int raceline)
|
||||
GenerateTrack(tTrack * Track, void *TrackHandle, const std::string &outFile, FILE *AllFd, int bump, int raceline)
|
||||
{
|
||||
FILE *curFd;
|
||||
|
||||
|
@ -2806,7 +2806,7 @@ GenerateTrack(tTrack * Track, void *TrackHandle, char *outFile, FILE *AllFd, int
|
|||
|
||||
InitScene(Track, TrackHandle, bump, raceline);
|
||||
|
||||
if (outFile) {
|
||||
if (!outFile.empty()) {
|
||||
curFd = Ac3dOpen(outFile, 1);
|
||||
Ac3dGroup(curFd, "track", ActiveGroups);
|
||||
SaveMainTrack(curFd, bump, raceline);
|
||||
|
|
|
@ -32,12 +32,11 @@
|
|||
#define CFG_FILE "tools/trackgen/trackgen.xml"
|
||||
|
||||
|
||||
extern void GenerateTrack(tTrack * Track, void *TrackHandle, char *outFile, FILE *AllFd, int bump, int raceline);
|
||||
extern void GenerateTrack(tTrack * Track, void *TrackHandle, const std::string &outFile, FILE *AllFd, int bump, int raceline);
|
||||
extern void CalculateTrack(tTrack * Track, void *TrackHandle, int bump, int trackline);
|
||||
extern void generateRaceLine(tTrack* pTrack, const double SideDistExt, const double SideDistInt);
|
||||
extern double getTexureOffset(double length);
|
||||
|
||||
extern char *OutputFileName;
|
||||
extern int HeightSteps;
|
||||
extern int UseBorder;
|
||||
|
||||
|
|
Loading…
Reference in a new issue