Game Development Community

GUIClockHud centiseconds and rendering trouble

by Eric Roberts · in Torque Game Engine · 08/16/2005 (6:08 pm) · 4 replies

Hi,

When I was looking at GUIClockHud I decided I wanted to display minutes, seconds AND centiseconds (hundredths of a second). This is for pure aesthetic reasons ;).

However I ran into a little snag.

Here's the code I changed in GuiClockHud::onRender()

//Added by ERIC Aug 15 05
   S32 centiSecs = ( (mTimeOffset + Platform::getVirtualMilliseconds()) / 10 ) % 100;
   //-----------------------
   S32 secs = time % 60;
   S32 mins = (time % 3600) / 60;
   S32 hours = time / 3600;

   // Currently only displays min/sec
   char buf[256];
   //Modified by ERIC Aug 15 05 - added centiseconds
   dSprintf(buf,sizeof(buf), "%02d:%02d:%02d",mins,secs,centiSecs);

A very simple little change. However when I run my game it doesn't render - all of the time. Only sometimes will it render and other times it won't bother rendering at all. To check that it wasn't a string related problem I ran the debugger checking to see if "buf" for whatever reason was null. It wasn't.

So I figure it's a rendering issue. Vertical Sync issues? Maybe I need something in the ways of "dglWaitforVSync()" ?
I know for a fact this is a Torque possibility, Marble Blast did it - didn't they ;) ?

Thanks for your time,

- Eric

#1
08/16/2005 (9:43 pm)
Nah, 3d rendering code never waits for vsync (except to present the next surface in the render chain).

Where's the part where you render things? Is buf still around by then? Is it touched by anything? Have you tried running in the debugger to find out where things are going wrong?
#2
08/17/2005 (6:44 am)
*slaps forehead*

Oh man - now this is really silly. Turns out the GUIClockHud Control itself wasn't large enough to hold the digits width when the digits got "wider" like 88 for example.

A stretch in the horizontal and it works fine...

*slaps head again*

My excuse really is that we're using a custom font where - well, the numbers are much wider...

I really, really, don't like wasting other people's typing molecules and their time.
Sorry for the incovience,

- Eric

P.S. If anyone is googling around for an example on how to add centiseconds to GuiClockHud - there it is, nice and simple. Use and abuse it.
#3
08/17/2005 (10:28 am)
@Eric

Just a thought - you may want to look at the code that Clark Fagot posted at the end of this thread.

I was getting really variable times (10s of seconds and more over 30 minutes) using the ClockHUD as a game countdown timer (and different times on different speed machines in the same game) but with the code from the thread the times are perfect.
#4
08/17/2005 (1:31 pm)
@David

Wow, thanks for pointing me out to that. This will save me a lot of headaches in the future I'm sure.

- Eric