I Want to Make an Active Timer!

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Frazz1080
Posts: 41
Joined: Fri Nov 18, 2005 3:09 am

I Want to Make an Active Timer!

Post by Frazz1080 »

I'm at a new roadblock in my racer project, making an active timer. I'm using the coding from the tutorial on how to make Fonts appear(got that problem solved the other day), but now I want a timer in the corner, like in Wipeout or Diddy Kong Racing, or anything of that sort.
So far I've tried putting in a value, i.e. int Time and placing it in parens in the text, but the compiler says "is not an L-value", the program doesn't run, or it only prints the value, not the time.
How would one make actively changing text for time?

ITimer* Timer = device->getTimer();
u32 lastTime = Timer->getRealTime();
u32 timeSinceLastFrame = 0;

while(device->run() && driver)
{
if (device->isWindowActive())
{
u32 time = device->getTimer()->getTime(); //get time
driver->beginScene(true, true, 0);

smgr->drawAll();

//draw some text
if (Time)
Time->draw(L"Time: ",
core::rect<s32>(500,75, 600,75),
video::SColor(255,255,255,255));

driver->endScene();
}
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Code: Select all

	ITimer* Timer = device->getTimer(); 
	u32 lastTime = Timer->getRealTime();

	wchar_t msg[64];

	while( device->run() && driver)
	{
		u32 currTime = Timer->getRealTime();

		driver->beginScene(true, true, 0);
		smgr->drawAll();

		wsprintf(msg, "Time: %f", (currTime - lastTime) / 1000.f);
		// assumes you have a font pointer and the position to render the message...
		Font->drawText(msg, position); 

		driver->endScene();
	}
Frazz1080
Posts: 41
Joined: Fri Nov 18, 2005 3:09 am

Post by Frazz1080 »

Thanks for the answer. I've almost got the app compiled except for one thing, that "wsprintf" function. My Dev-CPP compiler says, "wsprintf undeclared(first use of this function)". I have the wchar #include file in my project, what's going wrong?
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

You are missing a declaration for the function.
Frazz1080
Posts: 41
Joined: Fri Nov 18, 2005 3:09 am

Post by Frazz1080 »

how would I declare it?
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

either by #including the appropriate file for your system, forward declaring the appropriate function yourself, or by using google to find an alternative answer. Teach a man to fish...
Last edited by vitek on Tue Jan 31, 2006 11:49 pm, edited 1 time in total.
Baal Cadar
Posts: 377
Joined: Fri Oct 28, 2005 10:28 am
Contact:

Post by Baal Cadar »

wsprintf is defined in the include file wchar.h. You say, you have it "in your project", does it also mean that you included it in the cpp file, the function declaration is reported to be missing? If not, then include it there, if you already did, then I have no clue.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

I should also point out that http://msdn.microsoft.com is a good place to go for questions specific to windows.
Frazz1080
Posts: 41
Joined: Fri Nov 18, 2005 3:09 am

Post by Frazz1080 »

Found the typo, it was wprintf, not wsprintf; that's what got me confused. Thanks for the formula.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

I think you had better mean swprintf. wprintf formats output to the console, but we want it to format the output into a string. If you did use swprintf, that is okay, unfortunately the signature for swprintf on windows systems is not in compliance with the C language standard... That isn't really a big problem, until you start porting to another platform.
Post Reply