Added support for multiple extras directories. Finally.

ver1_5_1
Chris Laurel 2002-11-16 23:31:31 +00:00
parent 1f4afb98d3
commit 080fd23ac7
3 changed files with 76 additions and 30 deletions

View File

@ -1757,9 +1757,9 @@ bool CelestiaCore::initSimulation()
return false;
}
// First read the solar system files listed individually in the
// config file.
{
// First read the solar system files listed individually in the
// config file.
SolarSystemCatalog* solarSystemCatalog = new SolarSystemCatalog();
universe->setSolarSystemCatalog(solarSystemCatalog);
for (vector<string>::const_iterator iter = config->solarSystemFiles.begin();
@ -1776,6 +1776,7 @@ bool CelestiaCore::initSimulation()
LoadSolarSystemObjects(solarSysFile, *universe);
}
}
}
#if 0
{
@ -1786,21 +1787,28 @@ bool CelestiaCore::initSimulation()
}
#endif
// Next, read all the solar system files in the extras directory
if (config->extrasDir != "")
// Next, read all the solar system files in the extras directories
{
for (vector<string>::const_iterator iter = config->extrasDirs.begin();
iter != config->extrasDirs.end(); iter++)
{
Directory* dir = OpenDirectory(config->extrasDir);
string filename;
while (dir->nextFile(filename))
if (*iter != "")
{
if (DetermineFileType(filename) == Content_CelestiaCatalog)
Directory* dir = OpenDirectory(*iter);
string filename;
while (dir->nextFile(filename))
{
string fullname = config->extrasDir + '/' + filename;
ifstream solarSysFile(fullname.c_str(), ios::in);
if (solarSysFile.good())
LoadSolarSystemObjects(solarSysFile, *universe);
if (DetermineFileType(filename) == Content_CelestiaCatalog)
{
string fullname = *iter + '/' + filename;
ifstream solarSysFile(fullname.c_str(), ios::in);
if (solarSysFile.good())
LoadSolarSystemObjects(solarSysFile, *universe);
}
}
delete dir;
}
}
}
@ -2013,25 +2021,29 @@ bool CelestiaCore::readStars(const CelestiaConfig& cfg)
return false;
}
// Now, read supplemental star files from the extras directory
if (config->extrasDir != "")
// Now, read supplemental star files from the extras directories
for (vector<string>::const_iterator iter = config->extrasDirs.begin();
iter != config->extrasDirs.end(); iter++)
{
Directory* dir = OpenDirectory(config->extrasDir);
string filename;
while (dir->nextFile(filename))
if (*iter != "")
{
if (DetermineFileType(filename) == Content_CelestiaStarCatalog)
Directory* dir = OpenDirectory(*iter);
string filename;
while (dir->nextFile(filename))
{
string fullname = config->extrasDir + '/' + filename;
ifstream starFile(fullname.c_str(), ios::in);
if (starFile.good())
if (DetermineFileType(filename) == Content_CelestiaStarCatalog)
{
bool success = starDB->load(starFile);
if (!success)
string fullname = *iter + '/' + filename;
ifstream starFile(fullname.c_str(), ios::in);
if (starFile.good())
{
DPRINTF(0, "Error reading star file: %s\n",
fullname.c_str());
bool success = starDB->load(starFile);
if (!success)
{
DPRINTF(0, "Error reading star file: %s\n",
fullname.c_str());
}
}
}
}
@ -2211,7 +2223,7 @@ void CelestiaCore::addToHistory()
if (!history.empty() && historyCurrent < history.size() - 1)
{
// truncating history to current position
while (historyCurrent != history.size()-1)
while (historyCurrent != history.size() - 1)
{
history.pop_back();
}

View File

@ -9,6 +9,7 @@
#include <iostream>
#include <fstream>
#include <cassert>
#include <celutil/debug.h>
#include <celengine/celestia.h>
#include <celengine/parser.h>
@ -105,7 +106,40 @@ CelestiaConfig* ReadCelestiaConfig(string filename)
}
}
configParams->getString("ExtrasDirectory", config->extrasDir);
Value* extrasDirsVal = configParams->getValue("ExtrasDirectories");
if (extrasDirsVal != NULL)
{
if (extrasDirsVal->getType() == Value::ArrayType)
{
Array* extrasDirs = extrasDirsVal->getArray();
assert(extrasDirs != NULL);
for (Array::iterator iter = extrasDirs->begin();
iter != extrasDirs->end(); iter++)
{
Value* dirNameVal = *iter;
if (dirNameVal->getType() == Value::StringType)
{
config->extrasDirs.insert(config->extrasDirs.end(),
dirNameVal->getString());
}
else
{
DPRINTF(0, "%s: Extras directory name must be a string.\n",
filename.c_str());
}
}
}
else if (extrasDirsVal->getType() == Value::StringType)
{
config->extrasDirs.insert(config->extrasDirs.end(),
extrasDirsVal->getString());
}
else
{
DPRINTF(0, "%s: ExtrasDirectories must be an array or string.\n", filename.c_str());
}
}
Value* xrefsVal = configParams->getValue("StarCatalogCrossReferences");
if (xrefsVal != NULL)

View File

@ -19,7 +19,7 @@ struct CelestiaConfig
std::string starNamesFile;
std::vector<std::string> catalogXrefFiles;
std::vector<std::string> solarSystemFiles;
std::string extrasDir;
std::vector<std::string> extrasDirs;
std::string galaxyCatalog;
std::vector<std::string> labelledStars;
std::string asterismsFile;