Support reading trackdata from GfLocalDir()
This would allow users to extract track data into GfLocalDir(), which is guaranteed to have write permissions, as opposed to GfDataDir().
This commit is contained in:
parent
b76d0cbdbb
commit
e5e83f3921
14 changed files with 160 additions and 112 deletions
|
@ -86,10 +86,8 @@ GfTracks::~GfTracks()
|
||||||
_pPrivate = 0;
|
_pPrivate = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
GfTracks::GfTracks()
|
void GfTracks::list(const std::string &path)
|
||||||
{
|
{
|
||||||
_pPrivate = new GfTracks::Private;
|
|
||||||
|
|
||||||
// Get the list of sub-dirs in the "tracks" folder (the track categories).
|
// Get the list of sub-dirs in the "tracks" folder (the track categories).
|
||||||
tFList* lstCatFolders = GfDirGetList("tracks");
|
tFList* lstCatFolders = GfDirGetList("tracks");
|
||||||
if (!lstCatFolders)
|
if (!lstCatFolders)
|
||||||
|
@ -113,7 +111,7 @@ GfTracks::GfTracks()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Get the list of sub-dirs in the "tracks" folder (the track categories).
|
// Get the list of sub-dirs in the "tracks" folder (the track categories).
|
||||||
std::string strDirName("tracks/");
|
std::string strDirName(path);
|
||||||
strDirName += pszCatId;
|
strDirName += pszCatId;
|
||||||
tFList* lstTrackFolders = GfDirGetList(strDirName.c_str());
|
tFList* lstTrackFolders = GfDirGetList(strDirName.c_str());
|
||||||
if (!lstTrackFolders)
|
if (!lstTrackFolders)
|
||||||
|
@ -143,7 +141,7 @@ GfTracks::GfTracks()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
std::ostringstream ossFileName;
|
std::ostringstream ossFileName;
|
||||||
ossFileName << "tracks/" << pszCatId << '/' << pszTrackId
|
ossFileName << path << pszCatId << '/' << pszTrackId
|
||||||
<< '/' << pszTrackId << '.' << TRKEXT;
|
<< '/' << pszTrackId << '.' << TRKEXT;
|
||||||
const std::string strTrackFileName(ossFileName.str());
|
const std::string strTrackFileName(ossFileName.str());
|
||||||
if (!GfFileExists(strTrackFileName.c_str()))
|
if (!GfFileExists(strTrackFileName.c_str()))
|
||||||
|
@ -155,13 +153,13 @@ GfTracks::GfTracks()
|
||||||
|
|
||||||
// Get 1st level track info (those which don't need to open any file).
|
// Get 1st level track info (those which don't need to open any file).
|
||||||
ossFileName.str("");
|
ossFileName.str("");
|
||||||
ossFileName << "tracks/" << pszCatId << '/' << pszTrackId
|
ossFileName << path << pszCatId << '/' << pszTrackId
|
||||||
<< '/' << pszTrackId << ".jpg";
|
<< '/' << pszTrackId << ".jpg";
|
||||||
std::string strPreviewFileName(ossFileName.str());
|
std::string strPreviewFileName(ossFileName.str());
|
||||||
if (!GfFileExists(strPreviewFileName.c_str()))
|
if (!GfFileExists(strPreviewFileName.c_str()))
|
||||||
{
|
{
|
||||||
ossFileName.str("");
|
ossFileName.str("");
|
||||||
ossFileName << "tracks/" << pszCatId << '/' << pszTrackId
|
ossFileName << path << pszCatId << '/' << pszTrackId
|
||||||
<< '/' << pszTrackId << ".png";
|
<< '/' << pszTrackId << ".png";
|
||||||
strPreviewFileName = ossFileName.str();
|
strPreviewFileName = ossFileName.str();
|
||||||
}
|
}
|
||||||
|
@ -169,7 +167,7 @@ GfTracks::GfTracks()
|
||||||
strPreviewFileName = "data/img/splash-trackselect.jpg";
|
strPreviewFileName = "data/img/splash-trackselect.jpg";
|
||||||
|
|
||||||
ossFileName.str("");
|
ossFileName.str("");
|
||||||
ossFileName << "tracks/" << pszCatId << '/' << pszTrackId << '/' << "outline.png";
|
ossFileName << path << pszCatId << '/' << pszTrackId << '/' << "outline.png";
|
||||||
std::string strOutlineFileName(ossFileName.str());
|
std::string strOutlineFileName(ossFileName.str());
|
||||||
if (!GfFileExists(strOutlineFileName.c_str()))
|
if (!GfFileExists(strOutlineFileName.c_str()))
|
||||||
strOutlineFileName = "data/img/notrackoutline.png";
|
strOutlineFileName = "data/img/notrackoutline.png";
|
||||||
|
@ -201,6 +199,14 @@ GfTracks::GfTracks()
|
||||||
print(false); // No verbose here, otherwise infinite recursion.
|
print(false); // No verbose here, otherwise infinite recursion.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GfTracks::GfTracks()
|
||||||
|
{
|
||||||
|
_pPrivate = new GfTracks::Private;
|
||||||
|
|
||||||
|
list(std::string(GfLocalDir()) + "tracks/");
|
||||||
|
list(std::string(GfDataDir()) + "tracks/");
|
||||||
|
}
|
||||||
|
|
||||||
ITrackLoader* GfTracks::getTrackLoader() const
|
ITrackLoader* GfTracks::getTrackLoader() const
|
||||||
{
|
{
|
||||||
return _pPrivate->piTrackLoader;
|
return _pPrivate->piTrackLoader;
|
||||||
|
@ -226,7 +232,7 @@ const std::vector<std::string>& GfTracks::getCategoryNames() const
|
||||||
{
|
{
|
||||||
std::ostringstream ossFileName;
|
std::ostringstream ossFileName;
|
||||||
ossFileName << "data/tracks/" << *itCatId << '.' << TRKEXT;
|
ossFileName << "data/tracks/" << *itCatId << '.' << TRKEXT;
|
||||||
void* hparmCat = GfParmReadFile(ossFileName.str(), GFPARM_RMODE_STD);
|
void* hparmCat = GfParmReadFileBoth(ossFileName.str(), GFPARM_RMODE_STD);
|
||||||
const char* pszCatName;
|
const char* pszCatName;
|
||||||
if (!hparmCat)
|
if (!hparmCat)
|
||||||
{
|
{
|
||||||
|
@ -624,10 +630,13 @@ bool GfTrack::load() const
|
||||||
std::ostringstream ossFileName;
|
std::ostringstream ossFileName;
|
||||||
ossFileName << "tracks/" << _strCatId << '/' << _strId << '/'
|
ossFileName << "tracks/" << _strCatId << '/' << _strId << '/'
|
||||||
<< (pTrack->graphic.model3d ? pTrack->graphic.model3d : "track.ac");
|
<< (pTrack->graphic.model3d ? pTrack->graphic.model3d : "track.ac");
|
||||||
if (!GfFileExists(ossFileName.str().c_str()))
|
std::string path = ossFileName.str();
|
||||||
|
|
||||||
|
if (!GfFileExists((GfLocalDir() + path).c_str())
|
||||||
|
&& !GfFileExists((GfDataDir() + path).c_str()))
|
||||||
{
|
{
|
||||||
GfLogWarning("Unusable track %s : could not find 3D model %s\n",
|
GfLogWarning("Unusable track %s : could not find 3D model %s\n",
|
||||||
_strId.c_str(), ossFileName.str().c_str());
|
_strId.c_str(), path.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -128,6 +128,8 @@ protected:
|
||||||
GfTracks();
|
GfTracks();
|
||||||
~GfTracks();
|
~GfTracks();
|
||||||
|
|
||||||
|
void list(const std::string &path);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// The singleton itself.
|
// The singleton itself.
|
||||||
|
|
|
@ -530,7 +530,11 @@ int initTrack(tTrack *track)
|
||||||
// TODO: Find a solution to init the graphics first independent of objects.
|
// TODO: Find a solution to init the graphics first independent of objects.
|
||||||
|
|
||||||
// Now, do the real track loading job.
|
// Now, do the real track loading job.
|
||||||
grTrackHandle = GfParmReadFile(track->filename, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT);
|
grTrackHandle = GfParmReadFileBoth(track->filename, GFPARM_RMODE_STD);
|
||||||
|
if (!grTrackHandle) {
|
||||||
|
GfLogError("GfParmReadFileBoth %s failed\n", track->filename);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
//Options = new SDOptions;
|
//Options = new SDOptions;
|
||||||
|
|
||||||
|
@ -538,7 +542,9 @@ int initTrack(tTrack *track)
|
||||||
render = new SDRender;
|
render = new SDRender;
|
||||||
//cam = new SDCamera;
|
//cam = new SDCamera;
|
||||||
|
|
||||||
scenery->LoadScene(track);
|
if (scenery->LoadScene(track))
|
||||||
|
return -1;
|
||||||
|
|
||||||
render->Init(track);
|
render->Init(track);
|
||||||
|
|
||||||
Clouds = track->local.clouds;
|
Clouds = track->local.clouds;
|
||||||
|
|
|
@ -44,13 +44,16 @@ void SDBackground::build(int X, int Y, int Z, const std::string& TrackPath)
|
||||||
{
|
{
|
||||||
osgDB::Registry::instance()->clearObjectCache();
|
osgDB::Registry::instance()->clearObjectCache();
|
||||||
|
|
||||||
std::string LocalPath = GfDataDir();
|
std::string DataPath = GfDataDir(), LocalPath = GfLocalDir();
|
||||||
|
|
||||||
osgDB::FilePathList pathList = osgDB::Registry::instance()->getDataFilePathList();
|
osgDB::FilePathList pathList = osgDB::Registry::instance()->getDataFilePathList();
|
||||||
|
|
||||||
pathList.push_front(LocalPath+"data/objects/");
|
pathList.push_front(DataPath + "data/objects/");
|
||||||
pathList.push_front(LocalPath+"data/textures/");
|
pathList.push_front(DataPath + "data/textures/");
|
||||||
pathList.push_front(TrackPath);
|
pathList.push_front(DataPath + TrackPath);
|
||||||
|
pathList.push_front(LocalPath + "data/objects/");
|
||||||
|
pathList.push_front(LocalPath + "data/textures/");
|
||||||
|
pathList.push_front(LocalPath + TrackPath);
|
||||||
osgDB::Registry::instance()->setDataFilePathList(pathList);
|
osgDB::Registry::instance()->setDataFilePathList(pathList);
|
||||||
|
|
||||||
//osg::ref_ptr<osg::MatrixTransform> _background_transform = new osg::MatrixTransform;
|
//osg::ref_ptr<osg::MatrixTransform> _background_transform = new osg::MatrixTransform;
|
||||||
|
|
|
@ -422,10 +422,16 @@ void SDPit::build(const tTrack *track)
|
||||||
// load pit indicator
|
// load pit indicator
|
||||||
if (bHasPitIndicator)
|
if (bHasPitIndicator)
|
||||||
{
|
{
|
||||||
loader.AddSearchPath(std::string("tracks/") + track->category + "/" + track->internalname);
|
std::string localdir = GfLocalDir(), datadir = GfDataDir();
|
||||||
loader.AddSearchPath("data/objects");
|
loader.AddSearchPath(localdir + "tracks/" + track->category + "/" + track->internalname);
|
||||||
loader.AddSearchPath("data/textures");
|
loader.AddSearchPath(localdir + "data/objects");
|
||||||
loader.AddSearchPath("data/img");
|
loader.AddSearchPath(localdir + "data/textures");
|
||||||
|
loader.AddSearchPath(localdir + "data/img");
|
||||||
|
|
||||||
|
loader.AddSearchPath(datadir + "tracks/" + track->category + "/" + track->internalname);
|
||||||
|
loader.AddSearchPath(datadir + "data/objects");
|
||||||
|
loader.AddSearchPath(datadir + "data/textures");
|
||||||
|
loader.AddSearchPath(datadir + "data/img");
|
||||||
|
|
||||||
std::string filename = pits->pitindicator == 1
|
std::string filename = pits->pitindicator == 1
|
||||||
? "pit_indicator.ac"
|
? "pit_indicator.ac"
|
||||||
|
|
|
@ -69,7 +69,7 @@ SDScenery::~SDScenery(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDScenery::LoadScene(const tTrack *track)
|
int SDScenery::LoadScene(const tTrack *track)
|
||||||
{
|
{
|
||||||
void *hndl = grTrackHandle;
|
void *hndl = grTrackHandle;
|
||||||
const char *acname;
|
const char *acname;
|
||||||
|
@ -118,44 +118,37 @@ void SDScenery::LoadScene(const tTrack *track)
|
||||||
GfLogError("No specified track 3D model file\n");
|
GfLogError("No specified track 3D model file\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string PathTmp = GfDataDir();
|
|
||||||
|
|
||||||
_bgsky = strcmp(GfParmGetStr(grHandle, GR_SCT_GRAPHIC, GR_ATT_DYNAMICSKYDOME, GR_ATT_DYNAMICSKYDOME_DISABLED), GR_ATT_DYNAMICSKYDOME_ENABLED) == 0;
|
_bgsky = strcmp(GfParmGetStr(grHandle, GR_SCT_GRAPHIC, GR_ATT_DYNAMICSKYDOME, GR_ATT_DYNAMICSKYDOME_DISABLED), GR_ATT_DYNAMICSKYDOME_ENABLED) == 0;
|
||||||
if (_bgsky)
|
if (_bgsky)
|
||||||
{
|
{
|
||||||
std::string strPath = PathTmp;
|
snprintf(buf, 256, "tracks/%s/%s/", track->category, track->internalname);
|
||||||
snprintf(buf, 256, "tracks/%s/%s/", SDTrack->category, SDTrack->internalname);
|
m_background->build(grWrldX, grWrldY, grWrldZ, buf);
|
||||||
strPath += buf;
|
|
||||||
m_background->build(grWrldX, grWrldY, grWrldZ, strPath);
|
|
||||||
GfLogDebug("Background loaded\n");
|
GfLogDebug("Background loaded\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string strPath = GfDataDir();
|
snprintf(buf, 256, "tracks/%s/%s/", track->category, track->internalname);
|
||||||
snprintf(buf, 256, "tracks/%s/%s/", SDTrack->category, SDTrack->internalname);
|
|
||||||
|
|
||||||
std::string ext = osgDB::getFileExtension(acname);
|
std::string ext = osgDB::getFileExtension(acname);
|
||||||
|
|
||||||
if (ext == "acc")
|
if (ext == "acc")
|
||||||
{
|
{
|
||||||
GfLogDebug("Load 3D Model Scene ACC\n");
|
GfLogDebug("Load 3D Model Scene ACC\n");
|
||||||
strPath+=buf;
|
if (!LoadTrack(buf, acname))
|
||||||
_strTexturePath = strPath;
|
{
|
||||||
strPath+=acname;
|
GfLogError("LoadTrack %s%s failed\n", buf, acname);
|
||||||
|
return -1;
|
||||||
LoadTrack(strPath);
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strPath+=buf;
|
std::string localdir = GfLocalDir(), datadir = GfDataDir();
|
||||||
|
|
||||||
std::string strTPath = GfDataDir();
|
|
||||||
osgDB::FilePathList pathList = osgDB::Registry::instance()->getDataFilePathList();
|
osgDB::FilePathList pathList = osgDB::Registry::instance()->getDataFilePathList();
|
||||||
pathList.push_back(strPath);
|
pathList.push_back(localdir + buf);
|
||||||
GfLogDebug("Track Path : %s\n", pathList.back().c_str());
|
pathList.push_back(localdir + "data/objects/");
|
||||||
pathList.push_back(strTPath+"data/objects/");
|
pathList.push_back(localdir + "data/textures/");
|
||||||
GfLogDebug("Texture Path : %s\n", pathList.back().c_str());
|
pathList.push_back(datadir + buf);
|
||||||
pathList.push_back(strTPath+"data/textures/");
|
pathList.push_back(datadir + "data/objects/");
|
||||||
GfLogDebug("Texture Path : %s\n", pathList.back().c_str());
|
pathList.push_back(datadir + "data/textures/");
|
||||||
osgDB::Registry::instance()->setDataFilePathList(pathList);
|
osgDB::Registry::instance()->setDataFilePathList(pathList);
|
||||||
osg::ref_ptr<osg::Node> pTrack = osgDB::readNodeFile(acname);
|
osg::ref_ptr<osg::Node> pTrack = osgDB::readNodeFile(acname);
|
||||||
|
|
||||||
|
@ -184,6 +177,7 @@ void SDScenery::LoadScene(const tTrack *track)
|
||||||
|
|
||||||
osgDB::Registry::instance()->setDataFilePathList( osgDB::FilePathList() );
|
osgDB::Registry::instance()->setDataFilePathList( osgDB::FilePathList() );
|
||||||
osgDB::Registry::instance()->clearObjectCache();
|
osgDB::Registry::instance()->clearObjectCache();
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDScenery::LoadSkyOptions()
|
void SDScenery::LoadSkyOptions()
|
||||||
|
@ -219,22 +213,19 @@ void SDScenery::ShutdownScene(void)
|
||||||
_scenery = NULL;
|
_scenery = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SDScenery::LoadTrack(std::string& strTrack)
|
bool SDScenery::LoadTrack(const std::string &dir, const std::string &file)
|
||||||
{
|
{
|
||||||
std::string name;
|
std::string localdir = GfLocalDir();
|
||||||
GfLogDebug("Track Path : %s\n", strTrack.c_str());
|
|
||||||
osgLoader loader;
|
osgLoader loader;
|
||||||
GfLogDebug("Texture Path : %s\n", _strTexturePath.c_str());
|
loader.AddSearchPath(dir);
|
||||||
loader.AddSearchPath(_strTexturePath);
|
loader.AddSearchPath(localdir + "data/textures/");
|
||||||
|
loader.AddSearchPath("data/textures/");
|
||||||
|
|
||||||
std::string strTPath = GfDataDir();
|
std::string path = dir + file;
|
||||||
strTPath += "data/textures/";
|
osg::Node *pTrack;
|
||||||
GfLogDebug("Texture Path : %s\n", strTPath.c_str());
|
|
||||||
loader.AddSearchPath(strTPath);
|
|
||||||
|
|
||||||
osg::Node *pTrack = loader.Load3dFile(strTrack, false, "", name);
|
if ((pTrack = loader.Load3dFile(GfLocalDir() + path))
|
||||||
|
|| (pTrack = loader.Load3dFile(path)))
|
||||||
if (pTrack)
|
|
||||||
{
|
{
|
||||||
pTrack->getOrCreateStateSet()->setRenderBinDetails(TRACKBIN,"RenderBin");
|
pTrack->getOrCreateStateSet()->setRenderBinDetails(TRACKBIN,"RenderBin");
|
||||||
_scenery->addChild(pTrack);
|
_scenery->addChild(pTrack);
|
||||||
|
|
|
@ -104,8 +104,6 @@ private:
|
||||||
|
|
||||||
osg::ref_ptr<osg::Group> _scenery;
|
osg::ref_ptr<osg::Group> _scenery;
|
||||||
|
|
||||||
tTrack *SDTrack;
|
|
||||||
|
|
||||||
int _max_visibility;
|
int _max_visibility;
|
||||||
int _nb_cloudlayer;
|
int _nb_cloudlayer;
|
||||||
int _DynamicSkyDome;
|
int _DynamicSkyDome;
|
||||||
|
@ -116,8 +114,6 @@ private:
|
||||||
bool _speedWay;
|
bool _speedWay;
|
||||||
bool _speedWayLong;
|
bool _speedWayLong;
|
||||||
|
|
||||||
std::string _strTexturePath;
|
|
||||||
|
|
||||||
static double grWrldX;
|
static double grWrldX;
|
||||||
static double grWrldY;
|
static double grWrldY;
|
||||||
static double grWrldZ;
|
static double grWrldZ;
|
||||||
|
@ -126,7 +122,7 @@ private:
|
||||||
void LoadGraphicsOptions();
|
void LoadGraphicsOptions();
|
||||||
void LoadSkyOptions();
|
void LoadSkyOptions();
|
||||||
void CustomizePits(void);
|
void CustomizePits(void);
|
||||||
bool LoadTrack(std::string& strTrack);
|
bool LoadTrack(const std::string &dir, const std::string &file);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/* Constructor */
|
/* Constructor */
|
||||||
|
@ -135,7 +131,7 @@ public:
|
||||||
/* Destructor */
|
/* Destructor */
|
||||||
~SDScenery(void);
|
~SDScenery(void);
|
||||||
|
|
||||||
void LoadScene(const tTrack *track);
|
int LoadScene(const tTrack *track);
|
||||||
void ShutdownScene(void);
|
void ShutdownScene(void);
|
||||||
void reposition(double X, double Y, double Z);
|
void reposition(double X, double Y, double Z);
|
||||||
void update_tracklights(double currentTime, double totTime, int raceType);
|
void update_tracklights(double currentTime, double totTime, int raceType);
|
||||||
|
|
|
@ -502,8 +502,11 @@ grLoadBackground()
|
||||||
|
|
||||||
GfLogDebug("Loading background ...\n");
|
GfLogDebug("Loading background ...\n");
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "tracks/%s/%s;data/img;data/textures;.",
|
std::string trackpath = grTrackPath();
|
||||||
grTrack->category, grTrack->internalname);
|
const char *track = trackpath.c_str();
|
||||||
|
|
||||||
|
snprintf(buf, sizeof(buf), "%s%s;%s;data/img;data/textures;.",
|
||||||
|
GfLocalDir(), track, track);
|
||||||
grSetFilePath(buf);
|
grSetFilePath(buf);
|
||||||
grGammaValue = 1.8;
|
grGammaValue = 1.8;
|
||||||
grMipMap = 0;
|
grMipMap = 0;
|
||||||
|
@ -894,11 +897,13 @@ void grLoadBackgroundSky(void)
|
||||||
char buf2[256];
|
char buf2[256];
|
||||||
const char *bgsky;
|
const char *bgsky;
|
||||||
ssgEntity *desc2;
|
ssgEntity *desc2;
|
||||||
|
std::string trackpath = grTrackPath();
|
||||||
|
const char *track = trackpath.c_str();
|
||||||
|
|
||||||
bgsky = "background-sky.ac";
|
bgsky = "background-sky.ac";
|
||||||
snprintf(buf2, sizeof(buf2), "tracks/%s/%s;data/textures;.", grTrack->category, grTrack->internalname);
|
snprintf(buf2, sizeof(buf2), "%s%s;%s;data/textures;.", GfLocalDir(), track, track);
|
||||||
ssgTexturePath(buf2);
|
ssgTexturePath(buf2);
|
||||||
snprintf(buf2, sizeof(buf2), "tracks/%s/%s;data/objects", grTrack->category, grTrack->internalname);
|
snprintf(buf2, sizeof(buf2), "%s%s;%s;data/objects", GfLocalDir(), track, track);
|
||||||
ssgModelPath(buf2);
|
ssgModelPath(buf2);
|
||||||
|
|
||||||
desc2 = grssgLoadAC3D(bgsky, NULL);
|
desc2 = grssgLoadAC3D(bgsky, NULL);
|
||||||
|
|
|
@ -952,7 +952,12 @@ initTrack(tTrack *track)
|
||||||
grssgSetCurrentOptions(&options);
|
grssgSetCurrentOptions(&options);
|
||||||
|
|
||||||
// Now, do the real track loading job.
|
// Now, do the real track loading job.
|
||||||
grTrackHandle = GfParmReadFile(track->filename, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT);
|
grTrackHandle = GfParmReadFileBoth(track->filename, GFPARM_RMODE_STD);
|
||||||
|
if (!grTrackHandle) {
|
||||||
|
GfLogError("GfParmReadFileBoth %s failed\n", track->filename);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (grNbActiveScreens > 0)
|
if (grNbActiveScreens > 0)
|
||||||
return grLoadScene(track);
|
return grLoadScene(track);
|
||||||
|
|
||||||
|
|
|
@ -77,6 +77,16 @@ ssgBranch *CarlightAnchor = NULL;
|
||||||
ssgBranch *TrackLightAnchor = NULL;
|
ssgBranch *TrackLightAnchor = NULL;
|
||||||
ssgBranch *ThePits = NULL;
|
ssgBranch *ThePits = NULL;
|
||||||
|
|
||||||
|
std::string
|
||||||
|
grTrackPath()
|
||||||
|
{
|
||||||
|
std::string trackpath = "tracks/";
|
||||||
|
trackpath += grTrack->category;
|
||||||
|
trackpath += "/";
|
||||||
|
trackpath += grTrack->internalname;
|
||||||
|
|
||||||
|
return trackpath;
|
||||||
|
}
|
||||||
|
|
||||||
// Must have (Question: What for ?)
|
// Must have (Question: What for ?)
|
||||||
int preScene(ssgEntity *e)
|
int preScene(ssgEntity *e)
|
||||||
|
@ -227,9 +237,11 @@ grLoadScene(tTrack *track)
|
||||||
if ( grSkyDomeDistance > 0 )
|
if ( grSkyDomeDistance > 0 )
|
||||||
grLoadBackgroundSky();
|
grLoadBackgroundSky();
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "tracks/%s/%s;data/textures;data/img;.", grTrack->category, grTrack->internalname);
|
std::string trackpath = grTrackPath();
|
||||||
|
const char *tr = trackpath.c_str();
|
||||||
|
snprintf(buf, sizeof(buf), "%s%s;%s;data/textures;data/img;.", GfLocalDir(), tr, tr);
|
||||||
ssgTexturePath(buf);
|
ssgTexturePath(buf);
|
||||||
snprintf(buf, sizeof(buf), "tracks/%s/%s", grTrack->category, grTrack->internalname);
|
snprintf(buf, sizeof(buf), "%s%s;%s", GfLocalDir(), tr, tr);
|
||||||
ssgModelPath(buf);
|
ssgModelPath(buf);
|
||||||
|
|
||||||
desc = grssgLoadAC3D(acname, NULL);
|
desc = grssgLoadAC3D(acname, NULL);
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include <track.h> //tTrack
|
#include <track.h> //tTrack
|
||||||
#include <raceman.h> // tSituation
|
#include <raceman.h> // tSituation
|
||||||
#include "grmultitexstate.h"
|
#include "grmultitexstate.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace ssggraph {
|
namespace ssggraph {
|
||||||
|
|
||||||
|
@ -67,6 +68,7 @@ extern void grShutdownScene(void);
|
||||||
extern void grCustomizePits(void);
|
extern void grCustomizePits(void);
|
||||||
extern void grLoadPitsIndicator(tdble x,tdble y, tdble z, char *buf, int Pitind);
|
extern void grLoadPitsIndicator(tdble x,tdble y, tdble z, char *buf, int Pitind);
|
||||||
extern void grDrawBackground(class cGrCamera *, class cGrBackgroundCam *bgCam);
|
extern void grDrawBackground(class cGrCamera *, class cGrBackgroundCam *bgCam);
|
||||||
|
std::string grTrackPath();
|
||||||
|
|
||||||
//TODO: Question: What is this??? kilo
|
//TODO: Question: What is this??? kilo
|
||||||
// Possible answer: Some try to lower GPU load by filtering the scene ? JP
|
// Possible answer: Some try to lower GPU load by filtering the scene ? JP
|
||||||
|
|
|
@ -46,12 +46,15 @@ tTrack *
|
||||||
TrackBuildv1(const char *trackfile)
|
TrackBuildv1(const char *trackfile)
|
||||||
{
|
{
|
||||||
TrackShutdown();
|
TrackShutdown();
|
||||||
|
void *h = GfParmReadFileBoth (trackfile, GFPARM_RMODE_STD);
|
||||||
|
|
||||||
|
if (!h)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
theTrack = (tTrack*)calloc(1, sizeof(tTrack));
|
theTrack = (tTrack*)calloc(1, sizeof(tTrack));
|
||||||
theCamList = (tRoadCam*)NULL;
|
theCamList = (tRoadCam*)NULL;
|
||||||
|
|
||||||
theTrack->params = TrackHandle =
|
theTrack->params = TrackHandle = h;
|
||||||
GfParmReadFile (trackfile, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT | GFPARM_RMODE_PRIVATE);
|
|
||||||
|
|
||||||
theTrack->filename = strdup(trackfile);
|
theTrack->filename = strdup(trackfile);
|
||||||
|
|
||||||
|
@ -86,7 +89,7 @@ TrackBuildEx(const char *trackfile)
|
||||||
theTrack = (tTrack*)calloc(1, sizeof(tTrack));
|
theTrack = (tTrack*)calloc(1, sizeof(tTrack));
|
||||||
theCamList = (tRoadCam*)NULL;
|
theCamList = (tRoadCam*)NULL;
|
||||||
|
|
||||||
theTrack->params = TrackHandle = GfParmReadFile (trackfile, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT | GFPARM_RMODE_PRIVATE);
|
theTrack->params = TrackHandle = GfParmReadFileBoth (trackfile, GFPARM_RMODE_STD);
|
||||||
|
|
||||||
theTrack->filename = strdup(trackfile);
|
theTrack->filename = strdup(trackfile);
|
||||||
|
|
||||||
|
|
|
@ -172,7 +172,7 @@ GetTrackName(const char *category, const char *trackName)
|
||||||
std::string name;
|
std::string name;
|
||||||
|
|
||||||
sprintf(buf, "tracks/%s/%s/%s.%s", category, trackName, trackName, TRKEXT);
|
sprintf(buf, "tracks/%s/%s/%s.%s", category, trackName, trackName, TRKEXT);
|
||||||
trackHandle = GfParmReadFile(buf, GFPARM_RMODE_STD);
|
trackHandle = GfParmReadFileBoth(buf, GFPARM_RMODE_STD);
|
||||||
|
|
||||||
if (trackHandle) {
|
if (trackHandle) {
|
||||||
name = GfParmGetStr(trackHandle, TRK_SECT_HDR, TRK_ATT_NAME, trackName);
|
name = GfParmGetStr(trackHandle, TRK_SECT_HDR, TRK_ATT_NAME, trackName);
|
||||||
|
@ -195,37 +195,41 @@ GetTrackName(const char *category, const char *trackName)
|
||||||
static std::string
|
static std::string
|
||||||
GetTrackPreviewFileName(const char *pszCategory, const char *pszTrack)
|
GetTrackPreviewFileName(const char *pszCategory, const char *pszTrack)
|
||||||
{
|
{
|
||||||
char buf[256];
|
static const char *extensions[] = {"jpg", "png"};
|
||||||
|
|
||||||
// Try JPEG first.
|
for (size_t i = 0; i < sizeof extensions / sizeof *extensions; i++)
|
||||||
snprintf(buf, sizeof(buf), "tracks/%s/%s/%s.jpg", pszCategory, pszTrack, pszTrack);
|
|
||||||
buf[255] = 0; /* snprinf manual is not clear about that ... */
|
|
||||||
|
|
||||||
// Then PNG if not found.
|
|
||||||
if (!GfFileExists(buf))
|
|
||||||
{
|
{
|
||||||
snprintf(buf, sizeof(buf), "tracks/%s/%s/%s.png", pszCategory, pszTrack, pszTrack);
|
const char *ext = extensions[i];
|
||||||
buf[255] = 0; /* snprinf manual is not clear about that ... */
|
std::string dirs[] = {GfLocalDir(), GfDataDir()};
|
||||||
|
|
||||||
|
for (size_t i = 0; i < sizeof dirs / sizeof *dirs; i++)
|
||||||
|
{
|
||||||
|
std::string path = dirs[i] + "tracks/" + pszCategory
|
||||||
|
+ "/" + pszTrack + "/" + pszTrack + "." + ext;
|
||||||
|
|
||||||
|
if (GfFileExists(path.c_str()))
|
||||||
|
return path;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then fallback.
|
return "data/img/splash-networkrace.jpg";
|
||||||
if (!GfFileExists(buf))
|
|
||||||
strncpy(buf, "data/img/splash-networkrace.jpg", sizeof(buf));
|
|
||||||
|
|
||||||
return std::string(buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string
|
static std::string
|
||||||
GetTrackOutlineFileName(const char *pszCategory,const char *pszTrack)
|
GetTrackOutlineFileName(const char *pszCategory,const char *pszTrack)
|
||||||
{
|
{
|
||||||
char buf[256];
|
std::string dirs[] = {GfLocalDir(), GfDataDir()};
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "tracks/%s/%s/outline.png", pszCategory, pszTrack);
|
for (size_t i = 0; i < sizeof dirs / sizeof *dirs; i++)
|
||||||
|
{
|
||||||
|
std::string path = dirs[i] + "tracks/" + pszCategory + "/" + pszTrack
|
||||||
|
+ "/outline.png";
|
||||||
|
|
||||||
if (!GfFileExists(buf))
|
if (GfFileExists(path.c_str()))
|
||||||
strncpy(buf, "data/img/transparent.png", sizeof(buf));
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
return std::string(buf);
|
return "data/img/transparent.png";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called by both server and client
|
// Called by both server and client
|
||||||
|
|
|
@ -169,7 +169,7 @@ GetTrackName(const char *category, const char *trackName)
|
||||||
std::string name;
|
std::string name;
|
||||||
|
|
||||||
sprintf(buf, "tracks/%s/%s/%s.%s", category, trackName, trackName, TRKEXT);
|
sprintf(buf, "tracks/%s/%s/%s.%s", category, trackName, trackName, TRKEXT);
|
||||||
trackHandle = GfParmReadFile(buf, GFPARM_RMODE_STD);
|
trackHandle = GfParmReadFileBoth(buf, GFPARM_RMODE_STD);
|
||||||
|
|
||||||
if (trackHandle) {
|
if (trackHandle) {
|
||||||
name = GfParmGetStr(trackHandle, TRK_SECT_HDR, TRK_ATT_NAME, trackName);
|
name = GfParmGetStr(trackHandle, TRK_SECT_HDR, TRK_ATT_NAME, trackName);
|
||||||
|
@ -192,37 +192,41 @@ GetTrackName(const char *category, const char *trackName)
|
||||||
static std::string
|
static std::string
|
||||||
GetTrackPreviewFileName(const char *pszCategory, const char *pszTrack)
|
GetTrackPreviewFileName(const char *pszCategory, const char *pszTrack)
|
||||||
{
|
{
|
||||||
char buf[256];
|
static const char *extensions[] = {"jpg", "png"};
|
||||||
|
|
||||||
// Try JPEG first.
|
for (size_t i = 0; i < sizeof extensions / sizeof *extensions; i++)
|
||||||
snprintf(buf, sizeof(buf), "tracks/%s/%s/%s.jpg", pszCategory, pszTrack, pszTrack);
|
{
|
||||||
buf[255] = 0; /* snprinf manual is not clear about that ... */
|
const char *ext = extensions[i];
|
||||||
|
std::string dirs[] = {GfLocalDir(), GfDataDir()};
|
||||||
|
|
||||||
// Then PNG if not found.
|
for (size_t i = 0; i < sizeof dirs / sizeof *dirs; i++)
|
||||||
if (!GfFileExists(buf))
|
{
|
||||||
{
|
std::string path = dirs[i] + "tracks/" + pszCategory
|
||||||
snprintf(buf, sizeof(buf), "tracks/%s/%s/%s.png", pszCategory, pszTrack, pszTrack);
|
+ "/" + pszTrack + "/" + pszTrack + "." + ext;
|
||||||
buf[255] = 0; /* snprinf manual is not clear about that ... */
|
|
||||||
}
|
|
||||||
|
|
||||||
// Then fallback.
|
if (GfFileExists(path.c_str()))
|
||||||
if (!GfFileExists(buf))
|
return path;
|
||||||
strncpy(buf, "data/img/splash-networkrace.jpg", sizeof(buf));
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return std::string(buf);
|
return "data/img/splash-networkrace.jpg";
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string
|
static std::string
|
||||||
GetTrackOutlineFileName(const char *pszCategory,const char *pszTrack)
|
GetTrackOutlineFileName(const char *pszCategory,const char *pszTrack)
|
||||||
{
|
{
|
||||||
char buf[256];
|
std::string dirs[] = {GfLocalDir(), GfDataDir()};
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "tracks/%s/%s/outline.png", pszCategory, pszTrack);
|
for (size_t i = 0; i < sizeof dirs / sizeof *dirs; i++)
|
||||||
|
{
|
||||||
|
std::string path = dirs[i] + "tracks/" + pszCategory + "/" + pszTrack
|
||||||
|
+ "/outline.png";
|
||||||
|
|
||||||
if (!GfFileExists(buf))
|
if (GfFileExists(path.c_str()))
|
||||||
strncpy(buf, "data/img/transparent.png", sizeof(buf));
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
return std::string(buf);
|
return "data/img/transparent.png";
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Reference in a new issue