Previous Blog Next Blog
Prev/Next Blog
by date

Can't be the only one with this problem...?

Can't be the only one with this problem...?
Name:Mads Laumann
Date Posted:Jan 24, 2007
Rating:Not Rated
Public:YES
Comments:YES
RSS Feed:GarageGames Blog feedor Subscribe with .
Profile Page:View profile page for Mads Laumann

Blog post
It's been a while since my last post, but it has been christmas and I have been on vecation to the Domanican Republic for 14 days :)

I have had this problem for some time now, but haven't been able to fix it my self. I have created and posted in different threads, but I still haven't been able to fix the problem... :(

Threads:
- www.garagegames.com/mg/forums/result.thread.php?qt=54975
- garagegames.com/mg/forums/result.thread.php?qt=52682
(I have posted in this thread)

To make a long story short, the problem is that my game runs at different speed, depending on the CPU of the users PC. I have been looking at the TankBuster source code, to get inspired to how to design the game, codewise. Can't find the link to the source code anymore, so i can't give it to you :(
But my current code/scripts is in the first forum link. It's the private forum.

To sum it all up
What I have found out so far is that the my problem started because I was updating all my entities in the 'onUpdateScene' function. Like they do on the TankBuster game.


Code removed


I was then told that I shouldn't update my game here, because this function is called as many times at the users computer can handle. Ok, that was my guess too. Next problem, where do I update my game then? Because I really wanna do it this way by have some kind of "GameLoop", because I am use to do it like this when I make games in C#.
In C# i typically have a "StopWatch" and all my updating logic in a 'if'. If X miliseconds haven't passed since the last time it just skips the if, and then don't update the game.
But to get back to Torque. I couldn't update it on the 'onUpdateScene', so I was told to try doing it with a timer. I thought that sounded like a great idea. I should beable to called a %this.setTimerOn(25); method and a OnTick(%this) (or a name simular to this ;) ) function/event should be fired.
When I tryed this out, I found out the you can't set a timer on a t2dSceneObject.

So what to do now? Im stock here, and need some adwise, hope someone can help me out here. I can't be the only one who wants my game to run at the same speed at different PC's :P

PS: I haven't been working on this game lately, because I been working on a little C# project i wanna use at my work :) blog.laumania.net - Project Timer it is called.

Recent Blog Posts
List:07/29/07 - AstroMania (alpha)
02/20/07 - Web Monitor
02/10/07 - Ninja Nick - Part 1
02/02/07 - MCTS, Torque and C++
01/24/07 - Can't be the only one with this problem...?
12/10/06 - Parachute - Part 1
12/03/06 - Putting the MMORPG on hold for a while...
11/20/06 - Tutorial hunting

Submit ResourceSubmit your own resources!

Phil Carlisle   (Jan 24, 2007 at 21:34 GMT)
What you arent doing, is getting the time since you last updated the game loop. There is a call "getVirtualMilliseconds" in the C++ side of things, so I am sure that is exposed to script.

What I'd recommend, is calling that and storing the value, then every update loop, you check if new time > last time + time step.. (timestep being a value you choose to lock your update rate at), if > then you update all game objects, otherwise you simply return, next time through the loop you check UNTIL you get a value > and it then calls the update.

If your game is running too slow, what you can do is see how much time has elapsed and if > update frequency, you simply update and loop until it isnt.. Basically setting a fixed time step.

One alternative, there are others (like multiplying positions and velocities * time elapsed).

Mads Laumann   (Jan 24, 2007 at 21:44 GMT)
Thanks for your quick answer Phil. That was the idea i had my self, my problem is to get this time in code :)

Chris Labombard   (Jan 25, 2007 at 18:17 GMT)
I update my game logic a bit differently. I set up a function called performGameLogic. The function schedules itself every 100 MS. In the function all of my game objects (stored in an array) check to see if they have any actions to perform. Each object knows how much time needs to elapse before it needs to do something, and it knows when the last time it had a state change was... Doing it this way makes sure everything is kept in perfect sequence. I used to do this differntly. Each object that needed state changes would schedule itself to change states after the state time had elapsed. This lead to things slowly moving out of sequence with each other.

EDIT: Also should you be posting TGB code into a public blog post? I think that's against the EULA
Edited on Jan 25, 2007 18:18 GMT

David Higgins   (Jan 25, 2007 at 18:51 GMT)
@Mads, there is a console method called "GetRealTime()" which gets the current computers time in milliseconds, also for a smaller value to work with, there is a GetSimTime() (might be called something similiar) which gets the time in milliseconds since the engine initialized, so the values will be much smaller then GetRealTime)

You can perform your time logic with that in your onUpdateScene method, or you can schedule an event with a timer using the below block;


new t2dSceneObject(myObject)
{
field1 = 0;
}

myObject.setTimerOn(300);

function myObject::onTimer(%this)
{
%this.field1 = %this.field1 + 1;
echo("myObject.field1 = " @ %this.field1);
}




Mads Laumann   (Jan 25, 2007 at 21:34 GMT)
@Chris. Ok that a way of doing it too, but as Im used to the other one, im trying to aim for that and see if it's doable in Torque.
About the code, didn't thought of that one. I have removed the link for the .zip file with code, so the code is only download able from the private forum. But isn't the EULA only about that you cant show off the source code of the engine?

@David
Thanks, using the code in the code block would force me to set timers for all my object individually... I don't like that :)
But the GetSimTim() looks great, Ill try that out.

Chris Labombard   (Jan 25, 2007 at 21:45 GMT)
Mads - The EULA for TGE says that, but TGB you cant show your script source either. My method and the updateScene method are the exact same... Just use Sim::Time to determine if you need to trigger an even in your objects, and use the elpased tiem since the last call to perform time sensitive activities like physics calculations.

David's method works, but it wont properly sequence events between multiple objects.

Mads Laumann   (Jan 26, 2007 at 12:16 GMT)
@Chris - The code has been removed.
I tryed out the getSimTime() yesterday and it actually seemed to work as it should :) Ofcause it gave me some other problems, but yeah, that's coding! :)

Thanks guys!

You must be a member and be logged in to either append comments or rate this resource.