- Joined
- Apr 14, 2012
- Messages
- 2,585
- Reaction score
- 0
- Points
- 36
So I have studied C++ enough that I can write my own programs, although not quite at a really advanced level just yet. One of the things that puzzles me is how Orbiter works with regards to vessel classes defined in external modules.
As I understood it, polymorphism works something like this:
A very simple definition of two classes, obviously this is missing an incredible number of things, but please bear with me
Then in our int main function, we can do something like
which is simpler than storing lists of every single type of vessel in the sim and updating those individually, because we know that update will need to be called for every object that inherits from Vessel anyways
But... The thing that puzzles me is exactly how Orbiter does this. When Martins compiles Orbiter, he cannot know the exact type name of every vessel type that addon developers will define, like XR2, Energia, Flying_banana, and so on... So when the program loads vessels from a scn file or creates them from the scenario editor, what can the program possibly call when creating that new object?
When developing an Orbiter module, I do know that MSVC++ always spits out a dll, which gets copied to the appropriate orbiter folder. This is perfectly normal as a development strategy, since dynamic link libraries allow for modifying the contents of functions without recompiling a programs original source, only if the program included the original headers. But as we already knew, Orbiter cant have those headers when its source executable is compiled. The one thing I do notice is that Orbiter config files for dlled vessels require a definition of a classname variable or something similar? Its almost as if Orbiter can dynamically load that typename and use it in the program, but how I dont know. I feel as if I am missing something obvious here.
Any help here is appreciated
As I understood it, polymorphism works something like this:
A very simple definition of two classes, obviously this is missing an incredible number of things, but please bear with me
Code:
class Vessel
{ // define some good vessel stuff that the child classes derived from
// Vessel will inherit, like variables and member functions
virtual void callbackFrameUpdate();
};
class DeltaGlider: public Vessel
{ // define some additional good things specific to the vessel, like
// the mesh of the dg and whatever
DeltaGlider(arguments argies);
void callbackFrameUpdate();
};
class ShuttleA: public Vessel
{ // define some additional good things specific to the vessel, like
// the mesh of the dg and whatever
ShuttleA(arguments argies);
void callbackFrameUpdate();
};
Then in our int main function, we can do something like
Code:
int main()
{ Vessel * GL1, * SH2;
GL1 = new DeltaGlider(argieee);
SH2 = new ShuttleA(argier);
// then we stuff those two Vessel pointers into a vector or something
// similar
while(we_aint_done)
{
// we call callbackFrameUpdate(); for every pointer in the vector
}
delete GL1;
delete SH2;
// because someone will howl if I dont do this ;)
return 0;
}
which is simpler than storing lists of every single type of vessel in the sim and updating those individually, because we know that update will need to be called for every object that inherits from Vessel anyways
But... The thing that puzzles me is exactly how Orbiter does this. When Martins compiles Orbiter, he cannot know the exact type name of every vessel type that addon developers will define, like XR2, Energia, Flying_banana, and so on... So when the program loads vessels from a scn file or creates them from the scenario editor, what can the program possibly call when creating that new object?
When developing an Orbiter module, I do know that MSVC++ always spits out a dll, which gets copied to the appropriate orbiter folder. This is perfectly normal as a development strategy, since dynamic link libraries allow for modifying the contents of functions without recompiling a programs original source, only if the program included the original headers. But as we already knew, Orbiter cant have those headers when its source executable is compiled. The one thing I do notice is that Orbiter config files for dlled vessels require a definition of a classname variable or something similar? Its almost as if Orbiter can dynamically load that typename and use it in the program, but how I dont know. I feel as if I am missing something obvious here.
Any help here is appreciated