API Question Class or Struct hierarchy for common stages and other elements

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
I'm not really sure how best to describe what I'm trying to do but I'll give it my best shot...

The addon I am working (AAPO) on has a bunch of common spacecraft elements that are shared across multiple VESSEL-derived classes.

At the moment this is accomplished through lots of copying and pasting but what I'd like to do is have a was that I can write the code for a given element once and then have a function along the lines of "AddCommandModule()" or "AddSIVbStage ()" that would add all the of that element's associated thrusters, propellant resources, meshes, functions etc... to the existing vessel. My problem is that I am unsure how best to accomplish this, and could use some input and advice from some of the more experienced coders.

Expressed in pseudo-code i'd like to be able to do something along the lines of the following.

Code:
// --------------------------------------------------------------
// Constructor
// --------------------------------------------------------------
ApolloCSM::ApolloCSM (OBJHANDLE hObj, int fmodel) : VESSEL3 (hObj, fmodel)
{
  cm = AddCommandModule (hObj, fmodel);
  sm = AddServiceModule (hObj, fmodel);
}

or

Code:
SaturnC5::SaturnC5 (OBJHANDLE hObj, int fmodel) : Saturn (hObj, fmodel)
{
  Stage1 = AddStageSIc (hObj, fmodel);
  Stage2 = AddStageSIIc (hObj, fmodel);
  Stage3 = AddStageSIVb (hObj, fmodel);
}

ETA:
Along similar lines I'd also like to be able to...

Code:
ThrusterHandle = AddEngineJ2 (pos, dir, rot, prophandle);

and have it automatically add the appropriate thruster, exhaust/particle streams, mesh, and gimbal animations to the stage.

any assistance will be greatly appreciated. Thank you and :hailprobe:
 
Last edited:

Face

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 18, 2008
Messages
4,403
Reaction score
581
Points
153
Location
Vienna
What about the factory pattern? Make e.g. a VAB class with static functions that create and return module objects of your various components.

Then you could get a pointer to the objects and call all necessary callbacks hierarchically in the root vessel. I'm doing something like this in the AU code.
 

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
What about the factory pattern? Make e.g. a VAB class with static functions that create and return module objects of your various components.

Then you could get a pointer to the objects and call all necessary callbacks hierarchically in the root vessel. I'm doing something like this in the AU code.

Sounds great but I don't actually know how to go about doing that.
 
Top