"initialize" section in Flowchart
Posted: 29.12.2005, 18:52
December 29, 2005, Rev. 4
An unofficial flowchart for Celestia is being developed, and the box
called "initialize" is being explained in this forum thread. In a
different thread, the "update" box was discussed, so that some
familiarity would be gained with the C++ open source software.
http://www.celestiaproject.net/forum/viewtopic.php?t=8522
This has involved reading the source code. A future, second style
for familiarization will be to use a compiler IDE to single-step through
programs. That is an integrated development environment where
class views are really pretty.
Here is the flowchart where the "initialize" box resides :
Refresh your browser to see the latest version.
The initialization takes place on one of three types of operating systems:
Apple OS X, Linux class, and Microsoft Windows. For my PC system,
the first program is called winmain.cpp . Here is the sequence of
events to initialize :
INITIALIZE
Step 1 Declare prototypes, templates, structures, operators, variables
Step 2 Instantiate classes as objects (here are examples) :
static CelestiaCore* appCore = NULL;
static SolarSystemBrowser* solarSystemBrowser = NULL;
HWND CreateOpenGLWindow(int x, int y, int widt ...
{HWND hwnd = CreateWindow(AppName, ...
return hwnd;}
implement "default setting" classes
Step 3 Start executing main function !!!!!!!!!!!!!!!!!!!!!!!
int APIENTRY WinMain(HINSTANCE hInstance,
Step 4 Check if a celestia.exe is already running
Step 5 Specify some default values in case registry keys are not found.
Step 6 appCore = new CelestiaCore();
Step 7 appCore->setAlerter(new WinAlerter());
Step 8,9 if (!appCore->initSimulation(altConfig, &extrasDirectories))
{
return 1;
}
The step above calls celestiacore.cpp initSimulation (See below the line)
Step 10 UpdateWindow(mainWindow);
This draws the screen before the loop starts.
Step 11 // Set values saved in registry: renderFlags, visualMagnitude, labelMode and timezone bias.
appCore->getSimulation()->setFaintestVisible(prefs.visualMagnitude)...etc.
Step 12 appCore->getSimulation()->getActiveObserver()->setDisplayedSurface(prefs.altSurfaceName);
appCore->getRenderer()->setResolution(prefs.textureResolution);
Step 13 appCore->start((double) time(NULL) / 86400.0 +
(double) astro::Date(1970, 1, 1));
Step 14 MSG msg;
PeekMessage(&msg, NULL, 0U, 0U, PM_NOREMOVE);
End of initialization in winmain.cpp
_______________________________________________________
Step 15 Begin celestiacore.cpp initialization description
CelestiaCore::CelestiaCore() : config(NULL),...
{
/* Get a renderer here so it may be queried for capabilities of the
underlying engine even before rendering is enabled. Its initRenderer()
routine will be called much later. */
renderer = new Renderer();
timer = CreateTimer();
execEnv = new CoreExecutionEnvironment(*this);
Step 16 initSimulation calls SolarSystemLoader and other loaders
bool CelestiaCore::initSimulation(const string* configFileName,
const vector<string>* extrasDirs)
{...
universe = new Universe();
sim = new Simulation(universe); ...}
...
// 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();
iter != config->solarSystemFiles.end();
iter++)
{
ifstream solarSysFile(iter->c_str(), ios::in);
if (!solarSysFile.good())
{
warning(_("Error opening solar system catalog.\n"));
}
else
{
LoadSolarSystemObjects(solarSysFile, *universe, "");
}
}
}
// 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++)
{
if (*iter != "")
{
Directory* dir = OpenDirectory(*iter);
SolarSystemLoader loader(universe);
loader.pushDir(*iter);
dir->enumFiles(loader, true);
...
// We'll first read a very large DSO catalog from a bundled file:
if (config->deepSkyCatalog != "")
{
ifstream dsoFile(config->deepSkyCatalog.c_str(), ios::in);
// Next, read all the deep sky files in the extras directories
// Load asterisms: (still in initSimulation)
class SolarSystemLoader : public EnumFilesHandler
{
public:
Universe* universe;
SolarSystemLoader(Universe* u) : universe(u) {};
bool process(const string& filename)
{
if (DetermineFileType(filename) == Content_CelestiaCatalog)
{
string fullname = getPath() + '/' + filename;
clog << _("Loading solar system catalog: ") << fullname << '\n';
...}
It is loading the catalog. I traced what called that, but not where the catalog is used.
void CelestiaCore::start(double t)
{
if (config->initScriptFile != "")
{
// using the KdeAlerter in runScript would create an infinite loop,
// break it here by resetting config->initScriptFile:
string filename = config->initScriptFile;
config->initScriptFile = "";
runScript(filename);
}
// Set the simulation starting time to the current system time
sim->setTime(t);
sim->update(0.0);
___________________________________________
Conclusion : please make corrections and improvements to
the flowchart and to the explanations of the software.
This will help people to become familiar with the open source
software. In particular, point out the branches and loops that
are not described in the text, so a flowchart can be drawn.
There must be loops to initialize various types of similar
objects. Some branching may occur, but it usually leads into
"the frame rate loop" of the top level flowchart.
An unofficial flowchart for Celestia is being developed, and the box
called "initialize" is being explained in this forum thread. In a
different thread, the "update" box was discussed, so that some
familiarity would be gained with the C++ open source software.
http://www.celestiaproject.net/forum/viewtopic.php?t=8522
This has involved reading the source code. A future, second style
for familiarization will be to use a compiler IDE to single-step through
programs. That is an integrated development environment where
class views are really pretty.
Here is the flowchart where the "initialize" box resides :
Refresh your browser to see the latest version.
The initialization takes place on one of three types of operating systems:
Apple OS X, Linux class, and Microsoft Windows. For my PC system,
the first program is called winmain.cpp . Here is the sequence of
events to initialize :
INITIALIZE
Step 1 Declare prototypes, templates, structures, operators, variables
Step 2 Instantiate classes as objects (here are examples) :
static CelestiaCore* appCore = NULL;
static SolarSystemBrowser* solarSystemBrowser = NULL;
HWND CreateOpenGLWindow(int x, int y, int widt ...
{HWND hwnd = CreateWindow(AppName, ...
return hwnd;}
implement "default setting" classes
Step 3 Start executing main function !!!!!!!!!!!!!!!!!!!!!!!
int APIENTRY WinMain(HINSTANCE hInstance,
Step 4 Check if a celestia.exe is already running
Step 5 Specify some default values in case registry keys are not found.
Step 6 appCore = new CelestiaCore();
Step 7 appCore->setAlerter(new WinAlerter());
Step 8,9 if (!appCore->initSimulation(altConfig, &extrasDirectories))
{
return 1;
}
The step above calls celestiacore.cpp initSimulation (See below the line)
Step 10 UpdateWindow(mainWindow);
This draws the screen before the loop starts.
Step 11 // Set values saved in registry: renderFlags, visualMagnitude, labelMode and timezone bias.
appCore->getSimulation()->setFaintestVisible(prefs.visualMagnitude)...etc.
Step 12 appCore->getSimulation()->getActiveObserver()->setDisplayedSurface(prefs.altSurfaceName);
appCore->getRenderer()->setResolution(prefs.textureResolution);
Step 13 appCore->start((double) time(NULL) / 86400.0 +
(double) astro::Date(1970, 1, 1));
Step 14 MSG msg;
PeekMessage(&msg, NULL, 0U, 0U, PM_NOREMOVE);
End of initialization in winmain.cpp
_______________________________________________________
Step 15 Begin celestiacore.cpp initialization description
CelestiaCore::CelestiaCore() : config(NULL),...
{
/* Get a renderer here so it may be queried for capabilities of the
underlying engine even before rendering is enabled. Its initRenderer()
routine will be called much later. */
renderer = new Renderer();
timer = CreateTimer();
execEnv = new CoreExecutionEnvironment(*this);
Step 16 initSimulation calls SolarSystemLoader and other loaders
bool CelestiaCore::initSimulation(const string* configFileName,
const vector<string>* extrasDirs)
{...
universe = new Universe();
sim = new Simulation(universe); ...}
...
// 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();
iter != config->solarSystemFiles.end();
iter++)
{
ifstream solarSysFile(iter->c_str(), ios::in);
if (!solarSysFile.good())
{
warning(_("Error opening solar system catalog.\n"));
}
else
{
LoadSolarSystemObjects(solarSysFile, *universe, "");
}
}
}
// 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++)
{
if (*iter != "")
{
Directory* dir = OpenDirectory(*iter);
SolarSystemLoader loader(universe);
loader.pushDir(*iter);
dir->enumFiles(loader, true);
...
// We'll first read a very large DSO catalog from a bundled file:
if (config->deepSkyCatalog != "")
{
ifstream dsoFile(config->deepSkyCatalog.c_str(), ios::in);
// Next, read all the deep sky files in the extras directories
// Load asterisms: (still in initSimulation)
class SolarSystemLoader : public EnumFilesHandler
{
public:
Universe* universe;
SolarSystemLoader(Universe* u) : universe(u) {};
bool process(const string& filename)
{
if (DetermineFileType(filename) == Content_CelestiaCatalog)
{
string fullname = getPath() + '/' + filename;
clog << _("Loading solar system catalog: ") << fullname << '\n';
...}
It is loading the catalog. I traced what called that, but not where the catalog is used.
void CelestiaCore::start(double t)
{
if (config->initScriptFile != "")
{
// using the KdeAlerter in runScript would create an infinite loop,
// break it here by resetting config->initScriptFile:
string filename = config->initScriptFile;
config->initScriptFile = "";
runScript(filename);
}
// Set the simulation starting time to the current system time
sim->setTime(t);
sim->update(0.0);
___________________________________________
Conclusion : please make corrections and improvements to
the flowchart and to the explanations of the software.
This will help people to become familiar with the open source
software. In particular, point out the branches and loops that
are not described in the text, so a flowchart can be drawn.
There must be loops to initialize various types of similar
objects. Some branching may occur, but it usually leads into
"the frame rate loop" of the top level flowchart.