GuiVelocityHud help
by James Laker (BurNinG) · in Torque Game Engine · 10/16/2007 (9:40 am) · 2 replies
Can anyone see what's wrong with this code? At the moment it's showing the players' velocity and not the targets' velocity. The TargetShapename is correct, I have checked that.
This control has 2 modes... Target and Non-Target. If a Target is selected it should display the Target Velocity, otherwise the Player (my) velocity.
Any help would be appreciated.
This control has 2 modes... Target and Non-Target. If a Target is selected it should display the Target Velocity, otherwise the Player (my) velocity.
void GuiVelocityHud::onRender(Point2I offset, const RectI &updateRect)
{
// Must be in a TS Control
GuiTSCtrl *parent = dynamic_cast<GuiTSCtrl*>(getParent());
if (!parent) return;
// Must have a connection and player control object
GameConnection* conn = GameConnection::getConnectionToServer();
if (!conn)
return;
ShapeBase* control = conn->getControlObject();
if (!control)
return;
// See how much time went by, after last check
S32 timeElapsed = Platform::getVirtualMilliseconds() - mLastUpdated;
if ( ( timeElapsed > 0 ) && ( timeElapsed > mUpdateVar ) )
{
mLastUpdated = Platform::getVirtualMilliseconds();
//If we are in target mode we need to find the ship, then display it's velocity
if (mTargetMode)
{
// All ghosted objects are added to the server connection group,
// so we can find all the shape base objects by iterating through
// our current connection.
for (SimSetIterator itr(conn); *itr; ++itr) {
if ((*itr)->getType() & ShapeBaseObjectType) {
ShapeBase* shape = static_cast<ShapeBase*>(*itr);
if (shape != control && shape->getShapeName()) {
//Check to see if we found the correct Target
if (strcmp(shape->getShapeName(),mTargetShapeName) != 0)
continue;
mValue = shape->getVelocity().len();
break;
}
}
}
}
else
{
//Get the Velocity from the Control
mValue = control->getVelocity().len();
}
..
.Any help would be appreciated.
#2
That quote is how I ripped from other GUI's :)
But tbh, I didn't know that. The thing is, that I can see the Target, and the other GUI's I have does correctly get the Target details. Will try what you said anyway.
I'm sure however that mValue = shape->getVelocity().len(); is somehow screwing up since I am getting a Value... Just not the target velocity.
I wonder if it is because I'm using the gui twice in PlayGui, will check that quickly too.
10/16/2007 (11:05 am)
Kewl.. Thanx for the reply.That quote is how I ripped from other GUI's :)
But tbh, I didn't know that. The thing is, that I can see the Target, and the other GUI's I have does correctly get the Target details. Will try what you said anyway.
I'm sure however that mValue = shape->getVelocity().len(); is somehow screwing up since I am getting a Value... Just not the target velocity.
I wonder if it is because I'm using the gui twice in PlayGui, will check that quickly too.
Associate Orion Elenzil
Real Life Plus
all ghosted objects in network scope for the given client are added to the server connection group.
an object can leave network scope w/r/t a client if it's in a non-visible zone (zone as in portals),
or possibly for some other reasons like being too far away.
try putting a debug print in there in addition to continue.
you might want to try stricmp() instead of strcmp(), for case-insensitivity.
also as a side note, you'll find that everywhere else in the TGE codebase uses the "dFoo()" flavours of most of the stdlib functions, so if you want to be consistent you might use dStricmp().