I'm not really sure how best to describe what I'm trying to do this but I will give it my best shot.
So apollo space craft have a lot of switches. In orbiter terms each of the switchs have some common variables that need to be saved/manipulated by the user. To facilitate this (and kepp my cockpit manager class somewhat manageable, I have created a structure called VCSWITCHSPEC.
I then have a "createVCswitch ()" function in my cockpit manager class that returns a VCSWITCHSPEC based on the arguments entered. This has made basic coding a lot easier as my original LM's cockpit code was an unmanageable mess. The problem is that I still end up with a lot of redundant and copy/pastaed code like the following in the body of my vessel's code.
What i'd like to do is have an list or array containing all the switches that have been added to the cockpit thus far so that in clbkMouseEvent and other similar functions I can simply write a function to "check the list" rather than having to ensure that each switch has been properly added to the cockpit in 4 seperate places. (clbkMouseEvent, redrawevent, register active areas, and constructor/destructor)
In psuedo-code I imagine it would look something like ...
I also imagine that the simples way to do this would be to have a line in the the create and deleteswitch functions that says "add/remove this switch to/from list"
I just don't know what such a function or list would actually look like and I'm not sure of the proper vocabulary needed to search or ask.
So apollo space craft have a lot of switches. In orbiter terms each of the switchs have some common variables that need to be saved/manipulated by the user. To facilitate this (and kepp my cockpit manager class somewhat manageable, I have created a structure called VCSWITCHSPEC.
Code:
// --------------------------------------------------------------
// Individual VC switch specification
// --------------------------------------------------------------
typedef struct
{
int aid; // VC active area id
int nstate; // number of valid switch positions;
switchstate state; // current switch position
double size; // switch size (radius of clickable area in VC)
VECTOR3 pos; // switch position in VC
int sound_id; // sound to play when clicked on
UINT anim; // associated animation
// ??? **function pointer thingy goes here once I figure out how to make it work** // Associated function
} VCSWITCHSPEC;
I then have a "createVCswitch ()" function in my cockpit manager class that returns a VCSWITCHSPEC based on the arguments entered. This has made basic coding a lot easier as my original LM's cockpit code was an unmanageable mess. The problem is that I still end up with a lot of redundant and copy/pastaed code like the following in the body of my vessel's code.
Code:
// --------------------------------------------------------------
// Process cockpit mouse event notifications
// --------------------------------------------------------------
bool LM_Cockpit::clbkMouseEvent (int id, int event, VECTOR3 &p)
{
if (P1_AID) return ActivateSwitch (&p1_switch[id - P1_SWITCH_AID], event);
else if (P2_AID) return ActivateSwitch (&p2_switch[id - P2_SWITCH_AID], event);
else if (P3_AID) return ActivateSwitch (&p3_switch[id - P3_SWITCH_AID], event);
etc, etc, etc...
What i'd like to do is have an list or array containing all the switches that have been added to the cockpit thus far so that in clbkMouseEvent and other similar functions I can simply write a function to "check the list" rather than having to ensure that each switch has been properly added to the cockpit in 4 seperate places. (clbkMouseEvent, redrawevent, register active areas, and constructor/destructor)
In psuedo-code I imagine it would look something like ...
Code:
bool LM_Cockpit::clbkMouseEvent (int id, int event, VECTOR3 &p)
{
CheckVCSwitchList ();
if (MatchFound) ActivateSwitch (switch_id, event);
else return false;
}
I also imagine that the simples way to do this would be to have a line in the the create and deleteswitch functions that says "add/remove this switch to/from list"
I just don't know what such a function or list would actually look like and I'm not sure of the proper vocabulary needed to search or ask.
