Game Development Community

Need Help With GuiSpeedometerhud

by james burch · in Torque Game Engine · 01/22/2015 (5:13 am) · 4 replies

Hello , again , hope youve been doing well ,

TGE 1.1.2 DEMO
I do not own the source code .

I cant get the needle to display for the GuiSpeedometerHUd .

Im assuming it is handled rather like the health and energy huds in the demo where very little scripting is involved .

Im having no luck at trying to display the needle .

I only want the hud while mounted to the default car , after blahblah::onmount , and deactivated onunmount .

If someone would describe the technique for displaying the needle or hud , I Thank You .
and have a nice day .


EDIT i found this in a search (this time for guispeedometerhud instead of just speedometerhud or speedometer etc...
===============================================================================
===============================================================================

void GuiSpeedometerHud::onRender(Point2I offset, const RectI &updateRect)
{
static char buf[256];

// Must have a connection and player control object
GameConnection* conn = GameConnection::getServerConnection();
if (!conn) {
return;
}
ShapeBase* control = conn->getControlObject();
if (!control || !(control->getType() & PlayerObjectType)) {
return;
}

Player* player = static_cast<Player*>(control);

F32 speed = player->getVelocity().len();

// Background first
if (mShowFill) {
dglDrawRectFill(updateRect, mFillColor);
}

if (mIsMetric) {
F32 displayValue = speed * 3600.0 / 1000.0;
dSprintf(buf, sizeof(buf), "%s%.1f kph", (displayValue < 10.0 ? "0" : ""), displayValue);
}
else {
F32 displayValue = speed * 3600.0 / 1609.3;
dSprintf(buf, sizeof(buf), "%s%.1f mph", (displayValue < 10.0 ? "0" : ""), displayValue);
}

// Center the text
offset.x += (mBounds.extent.x - mProfile->mFont->getStrWidth(buf)) / 2;
offset.y += (mBounds.extent.y - mProfile->mFont->getHeight()) / 2;
dglSetBitmapModulation(mTextColor);
dglDrawText(mProfile->mFont, offset, buf);
dglClearBitmapModulation();

// Border last
if (mShowFrame) {
dglDrawRect(updateRect, mFrameColor);
}
}

==================================================================================
==================================================================================

So... for me as a noobish type , How do I assure
// Must have a connection and player control object
GameConnection* conn = GameConnection::getServerConnection(); //

sorry if i make little sense , also this is the only reference i could find .

About the author

Bare-Bones beginner , 49 yrs old , sooo im setting my sights on becoming an accomplished hobbyist with the patient cooperatin of the kindly knowledge folks . and THANK YOU :)


#1
02/10/2016 (6:58 pm)
Hi , and welcome back , I have not been successful here . Ill demonstrate my analysis skill . Im guessing that the 2 variables that the fuction needs are the control object and speed !? Okay , can anyone tell me what the 2 variable that the guispeedometerhud needs in order to do its thing ?:). My limited understanding of the server client leaves me doing a good bit of guessing that hasnt worked . I seems to me to be all doable on the client side , but I think that i understand it to have need for a connection to the server scripts . I see , if no connection return , but what , I have no connection ? Sry , just dont get it . Any advice appreciated :) Thank You .

BTW It seems like a cool little GUI which could have many implications besides control object velocity , and So i still would like to see it functioning Cooly .
#2
03/06/2016 (12:42 pm)
Hey James,

Are you using the SpedometerGUI in a FPS context (i.e. with a FPS player attached to a mount-point on the vehicle)?

If so, there is a problem in the C code in the version of Torque you are using. The code you've posted above has been updated considerably since 1.1.2 (and 1.5.2).

{Note: It's been a LONG time and I don't have my code handy, so I might be off-base on the details} Basically, look at the top of the function where the code does a dynamic cast to shapebase and then checks to see if the object is a player. The 1.x code does a dynamic cast to *vehicle* and then dumps if the cast fails to produce a valid object. It works fine in the Race demo because in that context the player *is* a vehicle. I can't remember if the routine just dumped or if it failed trying to get a velocity.

I fixed it engine-side and didn't think about it much beyond that. IIRC, my solution was similar to the function you posted above. Unsure if there's a clever way to work around the issue in script or not, but that's probably what you're dealing with.
#3
03/10/2016 (3:58 pm)
Mr. Butler,
Ive at long last got to see that cool little gui thing work . Its everything I imagined :) . Thank you very much , alas I do wish to use it in the FPS context . Im guessing now that there may be no way to compensate for there being no vehicle controlling object ... as , as you say , it appears that it will "cast" to Vehicle in shapebase in engine whenever the speedometer gui is called ... btw I think that that IS your code above . coool tho THX :)
#4
03/11/2016 (1:22 pm)
Well , I can change the control object of the client from the player to the vehicle and it works in the FPS demo .