slaver0110
Member
- Joined
- Mar 21, 2011
- Messages
- 72
- Reaction score
- 2
- Points
- 6
I have my orbital tug and class-specific MFD working well; without the help of everyone here it would have been impossible.:thumbup:
However, I'm having trouble with where the vessel-cast should take place.
A little background:
The MFD for the Tug is designed to be class-specific, so that a lot of flags in the vessel can be controlled and monitored from the MFD. This requires the including of the 'Tug1.h' file, and then a simple cast:
Of course, there has to be a checking routine to make sure that the current focus-vessel is of the Tug1 class, because my guess would be that if I changed to another vessel, the TugMFD would try to access the non-Tug vessel and crash Orbiter.
So, I use a simple check of the current focus vessel to make sure it's a Tug:
This check works well, and does exactly what I need it to.
The problem is where I currently have the check originating from:
The more experienced coders here will immediately see what the problem is...yes, VesselCheck() is being called from the Update method.
While this works, it also means that while the Tug is the current focus, the cast is happening every frame!!!
And that's where I could use some help.:shrug: I've been trying to think of a way to set this up so that once the Tug is the focus vessel, the cast happens once, and if the focus changes to a different vessel class it doesn't happen.
A little handholding in the right direction would be great here. As I said, the code works as-is, but the idea that it's re-casting every frame is one of those things that would cause me to lose sleep.
Cheers, and thanks in advance!!
However, I'm having trouble with where the vessel-cast should take place.
A little background:
The MFD for the Tug is designed to be class-specific, so that a lot of flags in the vessel can be controlled and monitored from the MFD. This requires the including of the 'Tug1.h' file, and then a simple cast:
Code:
pVessel = static_cast<Tug1*>(v);
Of course, there has to be a checking routine to make sure that the current focus-vessel is of the Tug1 class, because my guess would be that if I changed to another vessel, the TugMFD would try to access the non-Tug vessel and crash Orbiter.
So, I use a simple check of the current focus vessel to make sure it's a Tug:
Code:
bool Tug1MFD::VesselCheck()
{
hVessel = oapiGetFocusObject();
v = oapiGetVesselInterface(hVessel);
sprintf(TestClass, v->GetClassNameA());
switch (strcmp(TestClass, "Tug1"))
{
case 0:
pVessel = static_cast<Tug1*>(v);
return true;
case !0:
return false;
default:
return false;
}
}
The problem is where I currently have the check originating from:
Code:
bool Tug1MFD::Update(oapi::Sketchpad *skp)
{
Title(skp, "Tug1MFD");
skp->SetFont(font);
skp->SetTextColor(0x00FFFF);
switch (VesselCheck())
{
case true:
iPodThrust = (float)pVessel->PodThrust * 100;
len = sprintf_s(buff, TestClass);
skp->Text(100, 100, buff, len);
len = sprintf_s(buff, "PodFlag: %.0f", pVessel->PodFlag);
skp->Text(100, 130, buff, len);
len = sprintf_s(buff, "PodThrust: %2f", iPodThrust);
skp->Text(100, 160, buff, len);
if (CheckTugDock())
{
len = sprintf_s(buff, "DOCKED");
skp->Text(100, 190, buff, len);
}
break;
case false:
len = sprintf_s(buff, "NOT A TUG");
skp->Text(100, 100, buff, len); break;
}
return true;
}
While this works, it also means that while the Tug is the current focus, the cast is happening every frame!!!
And that's where I could use some help.:shrug: I've been trying to think of a way to set this up so that once the Tug is the focus vessel, the cast happens once, and if the focus changes to a different vessel class it doesn't happen.
A little handholding in the right direction would be great here. As I said, the code works as-is, but the idea that it's re-casting every frame is one of those things that would cause me to lose sleep.
Cheers, and thanks in advance!!