Game Development Community

Optimization issue

by Howard Dortch · in Torque 3D Professional · 08/28/2009 (1:31 pm) · 5 replies

I have multiple players, on creation each one calls a function that runs on a schedule

%player.checkMask()

funciton Player::checkMask(%this)
{
%x = foo();
// do something
%this.schedule(3000,"checkMask")
}

function foo()
{
return %foovalue;
}

The question is does calling foo() say from 30 different players at the same time bog the system down? Should I make a new function called Player::foo() ? Which method would be more efficient?

#1
08/28/2009 (1:37 pm)
Just a thought, but if you haven't already, you might want to change the Net::PacketRate in prefs.cs from 16 to 32, to increase performance.
#2
08/28/2009 (5:03 pm)
I'd toy with those schedules to prevent all of them from firing at the same time, spreading them out.
#3
08/28/2009 (5:13 pm)
Packet rate will probably help over all but not the info I was looking for.
I will have no control over when they fire. I could create a global array track the timers and space them out but I am still curious about how scripts treat the foo() call when it's being called multiple times. Seems to be a stack nightmare and I dont want to overload the script decoder.
#4
08/28/2009 (7:05 pm)
There's no simultaneous calls in script. Even if you schedule them to fire at the same time, the calls that were scheduled first will fire first.

Now, you should always get a handle for the schedule:

funciton Player::checkMask(%this)
{
  %x = foo();
  // do something
  cancel(%this.schedules[checkMask]);
  %this.schedules[checkMask] = %this.schedule(3000,"checkMask")
}
This will make sure you will only have a single "checkMask" schedule for each object if you call checkMask() from somewhere else other than the re-schedule itself.
#5
08/28/2009 (8:05 pm)
This schedule has to stay running as long as the player is in the game so I can't cancel it. It is the foo() call within the schedule that concerns me. Even if the checkMask schedule is a bit off from player to player the code will be executing somewhere inside foo() when another schedule fires then the second call to foo() is made or can be made so I would think the code goes into a wait state till the first one finishes. That being the case the speed of execution will degrade. I would like to find out if that is the case.

I can do this
for( %clI = 0; %clI < ClientGroup.getCount(); %clI++ )
{
%cl = ClientGroup.getObject( %clI );
%p = %cl.player;
%x = foo()
do something

and guarantee they all get called and called in a continous execution and eliminate a wait state if indeed it is happeing.