IMS2  Pre-Alpha
An Orbiter add-on to allow on-runtime construction of spacecraft from predefined modules
IMS_Module Class Reference

A physical component of a spacecraft that can be added or removed at runtime. More...

Inheritance diagram for IMS_Module:
EventHandler

Public Member Functions

virtual bool InitModule (IMS_Orbiter_ModuleData *orbiter_data, IMS_General_ModuleData *module_data, IMS2 *mVessel)
 initialises the Module with static data from a config file More...
 
virtual void PostLoad ()
 A callback that is called when all data has been loaded, including data from a scenario state. More...
 
virtual void PreStep (double simdt)
 Called at every clbkPreStep() of the containing vessel. More...
 
virtual void SaveState (FILEHANDLE scn, UINT index)
 called from IMS2::clbkSaveState() to write the module state to scenario file More...
 
virtual bool LoadState (FILEHANDLE scn)
 loads the modules saved state from scenario file More...
 
virtual void RemoveModuleFromVessel ()
 Called when this module is removed from a vessel. More...
 
virtual void AddModuleToVessel (IMS2 *_vessel, bool rotatemesh=false, bool addMesh=true)
 Performs all actions necessary when adding the module to a vessel. More...
 
virtual double GetMass ()
 Returns the combined mass of the module and all its functions/components.
 
MATRIX3 GetRotationMatrix ()
 Returns a rotation matrix to transform from vessel-relative to the module-relative frame.
 
VECTOR3 GetLocalCoordinates ()
 Returns the modules position in orbiter local (vessel relative) coordinates.
 
UINT GetMeshIndex ()
 Returns the index the modules mesh has in the vessel.
 
IMS2 * GetVessel ()
 Returns the vessel containing this module.
 
string getModulePosDescription ()
 Returns a string describing the module by name and position.
 
virtual void RemoveMeshFromVessel ()
 Removes the module's mesh from the vessel.
 
void SpawnNewVesselFromModule (string _name, VECTOR3 velocity)
 Spawns a new vessel that has the same position, orientation and class as this module. More...
 
void RotateMesh ()
 Rotates the module's mesh into the correct position relative to the vessel.
 
void GetRot (VECTOR3 &mRot)
 Fills the passed reference with the module's rotational vector. More...
 
void GetDir (VECTOR3 &mDir)
 Fills the passed reference with the module's directional vector. More...
 
void GetPos (VECTOR3 &mPos)
 Fills the passed reference with the module's position. More...
 
IMS_General_ModuleDataGetGeneralModuleData ()
 Returns a pointer to the module's general static data.
 
void SetRot (VECTOR3 &mRot)
 
void SetDir (VECTOR3 &mDir)
 Sets the vessel-relative direction of the module. More...
 
void SetPos (VECTOR3 &mPos)
 Sets the vessel-relative position of the module. More...
 
void GetAttachmentPoints (vector< IMSATTACHMENTPOINT * > &OUT_points)
 Fills the passed std::vector with the module's list of attachment points. More...
 
void AddAttachmentPointsToList (vector< IMSATTACHMENTPOINT * > &IN_OUT_points)
 Appends this module's attachment points to the passed std::vector. More...
 
IMSATTACHMENTPOINT * GetConnectingAttachmentPoint (VESSEL *_v)
 Returns the attachment point connecting to the passed vessel. More...
 
IMSATTACHMENTPOINT * GetConnectingAttachmentPoint (IMS_Module *module)
 returns the attachment point that connects to the passed module More...
 
int GetAttachmentPointIndex (IMSATTACHMENTPOINT *point)
 Returns the index of an attachment point on this module. More...
 
void UpdateAttachmentPoints (bool redock=false)
 Updates state of attachment points and associated dockports as well as vessels docked to those ports. More...
 
void GetPmi (VECTOR3 &OUT_pmi)
 Returns the modules principle moments of inertia ("inertia" parameter in cfg) in the passed VECTOR3.
 
void CreatePhysicalAttachmentPoints ()
 creates the actual physical attachment points of this vessel (i.e. the orbiter dockports). More...
 
void TransformAttachmentPoints ()
 Transforms attachment points to face the right way and be in the right place.
 
void SetDockPortsToNull ()
 Gets called after assimilating a module, because all DOCKHANDLEs in the module are now invalid. More...
 
void RotateAttachmentPoint (IMSATTACHMENTPOINT *att, double angle)
 rotates an attachment point around its directional axis More...
 
void RemoveAllAttachmentPoints ()
 disconnects attachment points and deletes their docking ports. More...
 
void SetOrientationRelativeTo (IMS_Module *module)
 transforms the module to preserve position and orientation relative to the passed module in its origin state. More...
 
GUIpluginGetGui ()
 Returns the GUIplugin of this module, NULL if it doesn't have a GUI.
 
- Public Member Functions inherited from EventHandler
void ConnectToMyEventGenerator (EventSink *sink, EVENTPIPE pipe)
 connects an EventSink to the EventGenerator of this in the appropriate pipe. More...
 
void ConnectToMyEventSink (EventSink *sink, EVENTPIPE pipe)
 Connects an EventSink on this to the passed event sink. More...
 
void ConnectMySinkToYourNode (EventNode *node, EVENTPIPE pipe)
 Connects an EventSink on this to the passed EventNode, no matter whether generator or another sink. More...
 
EVENTHANDLERTYPE GetEventHandlerType ()
 Returns the EVENTHANDLERTYPE of this event handler.
 
UINT GetUID ()
 Returns the globaly unique identifier of this event handler.
 

Static Public Member Functions

static bool X_ORDER (IMS_Module *a, IMS_Module *b)
 Comparator to sort modules by their position along the X axis.
 
static bool Y_ORDER (IMS_Module *a, IMS_Module *b)
 Comparator to sort modules by their position along the Y axis.
 
static bool Z_ORDER (IMS_Module *a, IMS_Module *b)
 Comparator to sort modules by their position along the Z axis.
 
static bool X_SYMMETRIC_ORDER (IMS_Module *a, IMS_Module *b)
 Comparator to sort modules by their symmetric position along the X axis.
 
static bool Y_SYMMETRIC_ORDER (IMS_Module *a, IMS_Module *b)
 Comparator to sort modules by their symmetric position along the Y axis.
 
static bool Z_SYMMETRIC_ORDER (IMS_Module *a, IMS_Module *b)
 Comparator to sort modules by their symmetric position along the Z axis.
 
static bool ATTACHMENT_POINTS_BY_POS (IMSATTACHMENTPOINT *a, IMSATTACHMENTPOINT *b)
 Comparator to sort attachment points by their overall position. More...
 

Protected Member Functions

void resetAttachmentPoints ()
 Resets attachment points to their original state. More...
 
void SaveBaseAttributes (FILEHANDLE scn)
 Saves attributes common to all modules. More...
 
bool LoadScenarioBaseAttributes (FILEHANDLE scn)
 Loads attributes common to all modules from a scenario file. More...
 
bool AddMeshToVessel (bool rotateMesh=false)
 Adds the module's mesh to the meshes list of the vessel. More...
 
void dockVessel (DOCKEDVESSEL *v, IMSATTACHMENTPOINT *p)
 docks a vessel wraped by a DOCKEDVESSEL struct to the intended attachment point on this module More...
 
virtual bool ProcessEvent (Event_Base *e)
 Receives all events coming through this EventHandler. More...
 
virtual void createGui ()
 creates the module gui. Only called once in the lifetime of a module
 
- Protected Member Functions inherited from EventHandler
EventGeneratorcreateEventGenerator (EVENTPIPE pipe)
 Creates a new EventGenerator for this handler instance. More...
 
EventSinkcreateEventSink (EVENTPIPE pipe)
 creates a new EventSink in this handler instance More...
 
void disconnect (EventHandler *handler, bool bidirectional=true)
 Completely severs connections to and from the passed EventHandler, all sinks, all generators. More...
 
void sendEvents ()
 Tells all event generators in this event handler to advance their event cue. More...
 
void processWaitingQueue ()
 processes all events in the waiting queue. More...
 
void addEvent (Event_Base *_event, EVENTPIPE _pipe=DEFAULT_PIPE)
 Adds an event to the eventcue of an eventpipe. More...
 
void addEventToWaitingQueue (Event_Base *_event)
 Adds an event to this handlers waiting queue. More...
 
void relayEvent (Event_Base *_event, EVENTPIPE _pipe)
 Relays an event to another event pipe. More...
 
EventSinkgetEventSink (EVENTPIPE pipe)
 returns the EventSink on this EventHandler that belongs to the passed event pipe More...
 
EventGeneratorgetEventGenerator (EVENTPIPE pipe)
 Returns the EventGenerator on this EventHandler that belongs to the passed event pipe. More...
 

Protected Attributes

vector< IMS_ModuleFunction_Base * > functions
 A list containing all this module's ModuleFunction objects.
 
IMS2 * vessel
 The vessel containing this module.
 
IMS_Orbiter_ModuleData_orbiter_data
 Orbiter related attributes of this module.
 
IMS_General_ModuleData_module_data
 General attributes of this module.
 
UINT moduleIndex
 Index of the module in the modules list.
 
UINT meshIndex
 Index of the module mesh in the vessel.
 
VECTOR3 pos
 The module's current position in vessel-relative coordinates.
 
VECTOR3 rot
 The module's current orientation ("up"-direction), vessel-relative.
 
VECTOR3 dir
 The module's current directional vector, vessel-relative.
 
MATRIX3 rotationmatrix
 Matrix for transformations into the module-relative frame.
 
vector< IMSATTACHMENTPOINT * > attachmentPoints
 Vector containing all the attachment points of this module.
 
GUIpluginguiplugin = NULL
 pointer to the module's GUI. If NULL, this module doesn't have a GUI
 
- Protected Attributes inherited from EventHandler
EVENTPIPE defaultpipe = DEFAULT_PIPE
 Use this to set the defualt event pipe of this event handler.
 
EVENTHANDLERTYPE eventhandlertype
 An identifier that offers a group identification.
 

Friends

class GUI_Module
 

Detailed Description

A physical component of a spacecraft that can be added or removed at runtime.

The Module class is the heart of IMS2: It manages Attachment points and Mesh placement and transformation, and contains one or several ModuleFunction objects as required to adapt to the demanded functionality. However, while Modules can be added or removed to a vessel at will, a module instance itself is static in terms of capability for the duration of its lifetime, as defined by a config file. A Module is never destroyed, unless the containing vessel is destroyed. If a Module changes ownership, its overall state and the overall state of its functions are unaffected.

A Module is also an EventHandler that provides a throughput eventpipe from the vessel to the modulefunctions. The EventPipe back from a modulefunction however is passed to all other module functions INSIDE THIS MODULE, and are only passed down to the vessel if the module takes action to do so.

Member Function Documentation

void IMS_Module::AddAttachmentPointsToList ( vector< IMSATTACHMENTPOINT * > &  IN_OUT_points)

Appends this module's attachment points to the passed std::vector.

Parameters
IN_OUT_pointsAn std::vector to receive the attachment points. Existing data will not be changed.
Note
use this function instead of GetAttachmentPoints() if you need to collect the attachment points of several modules in the same list, it's much faster.
See also
GetAttachmentPoints()
bool IMS_Module::AddMeshToVessel ( bool  rotateMesh = false)
protected

Adds the module's mesh to the meshes list of the vessel.

Parameters
rotateMeshWhether the mesh needs to be newly transformed
Note
rotateMesh Must only be true if module was a member of another vessel before, otherwise this happens automatically when the visual is created
See also
AddModuleToVessel()
void IMS_Module::AddModuleToVessel ( IMS2 *  _vessel,
bool  rotatemesh = false,
bool  addMesh = true 
)
virtual

Performs all actions necessary when adding the module to a vessel.

Note
The module must at this point be fully initialised, including its ModuleFunctions and its vessel properties!
Parameters
_vesselThe vessel the module is added to
rotatemeshWhether the mesh needs to be newly transformed
addMeshwhether the mesh needs to be added
Note
rotatemesh must only be true if module was a member of another vessel before, otherwise this happens automatically when the visual is created
addmesh must always be true except if this is the first module in a vessel, which has its mesh loaded by orbiter itself
bool IMS_Module::ATTACHMENT_POINTS_BY_POS ( IMSATTACHMENTPOINT *  a,
IMSATTACHMENTPOINT *  b 
)
static

Comparator to sort attachment points by their overall position.

Sorting with this comparator has the effect that overlapping attachment points will be next to each other in the resulting list.

void IMS_Module::CreatePhysicalAttachmentPoints ( )

creates the actual physical attachment points of this vessel (i.e. the orbiter dockports).

Note
This is an initialiser function and only called at very specific places in the code
void IMS_Module::dockVessel ( DOCKEDVESSEL *  v,
IMSATTACHMENTPOINT *  p 
)
protected

docks a vessel wraped by a DOCKEDVESSEL struct to the intended attachment point on this module

Parameters
vThe DOCKEDVESSEL that you want docked
pThe attachment point v needs to dock to
Note
If you already have a DOCKEDVESSEL structure, it means the vessel was docked to this module and has been undocked during the last frame. Re-docking it with this function insures that the vessel will be redocked to the same attachment point on the same module, no matter whether the module still is part of the same vessel or if the attachment point still wraps the same DOCKHANDLE.
int IMS_Module::GetAttachmentPointIndex ( IMSATTACHMENTPOINT *  point)

Returns the index of an attachment point on this module.

Parameters
pointA pointer to the attachment point you need to know the index of
Returns
The index of the attachment point, or -1 if point is not located on this module
Note
The index in the module is the only attribute of an attachment point that's guaranteed to be consistent over sessions!
void IMS_Module::GetAttachmentPoints ( vector< IMSATTACHMENTPOINT * > &  OUT_points)

Fills the passed std::vector with the module's list of attachment points.

Parameters
OUT_pointsReference to std::vector to receive the list. Will be overwritten!
See also
AddAttachmentPointsToList()
IMSATTACHMENTPOINT * IMS_Module::GetConnectingAttachmentPoint ( VESSEL *  _v)

Returns the attachment point connecting to the passed vessel.

Parameters
_vthe vessel for which you need to know to which attachment point on this module it is docked \ return A pointer to an IMSATTACHMENTPOINT object, or NULL if the vessel is not docked to this module
IMSATTACHMENTPOINT * IMS_Module::GetConnectingAttachmentPoint ( IMS_Module module)

returns the attachment point that connects to the passed module

Parameters
moduleThe module for which you need to know to which attachment point on this module it is connected
Returns
e, A pointer to an IMSATTACHMENTPOINT object, or NULL if the module is not docked to this module
void IMS_Module::GetDir ( VECTOR3 &  mDir)

Fills the passed reference with the module's directional vector.

Parameters
mDirReference to receive the direction ("front"-direction)
void IMS_Module::GetPos ( VECTOR3 &  mPos)

Fills the passed reference with the module's position.

Parameters
mPosReference to receive the position
void IMS_Module::GetRot ( VECTOR3 &  mRot)

Fills the passed reference with the module's rotational vector.

Parameters
mRotReference to receive the rotation ("up"-direction)
bool IMS_Module::InitModule ( IMS_Orbiter_ModuleData orbiter_data,
IMS_General_ModuleData module_data,
IMS2 *  mVessel 
)
virtual

initialises the Module with static data from a config file

Parameters
orbiter_dataThe orbiter api specific data for the module (like meshname, size etc)
module_dataThe general data for the module, like mass, module functions etc.
mVesselThe vessel that will initially contain this module
bool IMS_Module::LoadScenarioBaseAttributes ( FILEHANDLE  scn)
protected

Loads attributes common to all modules from a scenario file.

Parameters
scnFILEHANDLE of the scenario file to read from
bool IMS_Module::LoadState ( FILEHANDLE  scn)
virtual

loads the modules saved state from scenario file

Parameters
scnthe FILEHANDLE to the scenario file being loaded
Note
This function interfaces to IMS_ModuleFUnction_Base
See also
IMS_ModuleFUnction_Base::LoadState()
void IMS_Module::PostLoad ( )
virtual

A callback that is called when all data has been loaded, including data from a scenario state.

Note
This function interfaces to IMS_ModuleFunction_Base
See also
IMS_ModuleFunction_Base::PostLoad()
void IMS_Module::PreStep ( double  simdt)
virtual

Called at every clbkPreStep() of the containing vessel.

Parameters
simdtThe time elapsed between this frame and the previous one
Note
This function interfaces to IMS_ModuleFunction_Base
See also
IMS_ModuleFunction_Base::PreStep()
bool IMS_Module::ProcessEvent ( Event_Base e)
protectedvirtual

Receives all events coming through this EventHandler.

Overload to implement event handling in your inheriting class. The function will receive Events one by one as they are coming through your event sinks, regardless of which pipe they belong to. Return true to consume an event, but be sure it was only meant for you when you do that.

Parameters
eThe event coming through the event pipe
Note
Event generators will NOT send events to this function, only sinks.

Implements EventHandler.

void IMS_Module::RemoveAllAttachmentPoints ( )

disconnects attachment points and deletes their docking ports.

This does NOT delete the attachment points themselves, merely their physical representation in Orbiter. it will also remove all DOCKEDVESSEL objects from the vessel without deallocating them. They remain in memory, and the attachment point stays connected to them, and will be redocked this MODULE if UpdateAttachmentPoints() is called with redock true. This enables the transfer of docked vessels from one vessel to another in the event of a split.

void IMS_Module::RemoveModuleFromVessel ( )
virtual

Called when this module is removed from a vessel.

overload for module types that register things or need to modify the base vessel overloaded methods should ALWAYS invoke the base method because of attachment point and mesh handling!

Note
This function interfaces to IMS_ModuleFunction_Base
See also
IMS_ModuleFunction_Base::RemoveFunctionFromVessel()
void IMS_Module::resetAttachmentPoints ( )
protected

Resets attachment points to their original state.

The original state is defined as the state of the attachment point on the newly created, unintegrated module. The state includes position, rotation, direction as well as connection state and dockport state

void IMS_Module::RotateAttachmentPoint ( IMSATTACHMENTPOINT *  att,
double  angle 
)

rotates an attachment point around its directional axis

Parameters
attPointer to the attachment point to be rotated
angleThe rotational angle in radians
void IMS_Module::SaveBaseAttributes ( FILEHANDLE  scn)
protected

Saves attributes common to all modules.

Parameters
scnFILEHNDLE to the open scenario file to write to
void IMS_Module::SaveState ( FILEHANDLE  scn,
UINT  index 
)
virtual

called from IMS2::clbkSaveState() to write the module state to scenario file

Parameters
scnThe FILEHANDLE to the Scenario file being written
indexThe current index of this module in the vessel. This is only needed as an identifier in the Scenario.
Note
This function interfaces to IMS_ModuleFunction_Base
See also
IMS_ModuleFunction_Base::SaveState()
void IMS_Module::SetDir ( VECTOR3 &  mDir)

Sets the vessel-relative direction of the module.

Parameters
mDirThe desired directional vector ("front"-direction)
void IMS_Module::SetDockPortsToNull ( )

Gets called after assimilating a module, because all DOCKHANDLEs in the module are now invalid.

Todo:
with proper event handling, it might be possible to make this function private
void IMS_Module::SetOrientationRelativeTo ( IMS_Module module)

transforms the module to preserve position and orientation relative to the passed module in its origin state.

A module in its origin state means that its position/orientation is 0, 0, 1 / 0, 1, 0. This module is transformed so it has the same position and orientation relative to the passed module that it has now, after the other module is rotated from iuts current orientation to origin. This is used to preserve the relative orientation of modules in a subset of the vessel that is being split off.

Parameters
moduleA pointer to the module this module should keep its relative position and orientation to.
void IMS_Module::SetPos ( VECTOR3 &  mPos)

Sets the vessel-relative position of the module.

Parameters
mPosThe desired position
void IMS_Module::SetRot ( VECTOR3 &  mRot)

Sets the vessel-relative rotation of the module

Parameters
mRotThe desired rotational vector ("up"-direction, normalised)
void IMS_Module::SpawnNewVesselFromModule ( string  _name,
VECTOR3  velocity 
)

Spawns a new vessel that has the same position, orientation and class as this module.

Parameters
_nameThe name for the newly created vessel
velocityDirection and magnitude of velocity relative to separating vessel
void IMS_Module::UpdateAttachmentPoints ( bool  redock = false)

Updates state of attachment points and associated dockports as well as vessels docked to those ports.

Parameters
redockpass true if vessels formerly docked to this attachment point should be redocked instead of unregistered as docked vessels.
Note
vessels are necessarily undocked at events that chenge the structure of the vessel (i.e. adding or removing modules). This is the only situation in which redock sould be true

The documentation for this class was generated from the following files: