aiPlayer Lag?
by Sean Burgoon · in Torque Game Engine Advanced · 02/02/2009 (1:00 am) · 2 replies
Hey Everyone,
I'm having a weird problem with aiPlayers. I have an NPCManager (basically a modified AIManager) setup to spawn a new tank every few seconds if there are less than a preset number (currently I'm just testing this out, so it's very simple). Oddly, once 5-6 little tanks get on screen (they are aiPlayer objects), I start to get very jerky motion from them despite getting around 50 fps. Stranger still, if I go into the world editor and select one, its rendered shape will move very jerkily, but the bounding box is perfectly smooth. It seems to get worse the more that are spawned, and once I get up to around 10 it even seems to interfere with normal game operation (IE my camera panning suddenly stops working).
I guess my question is, is the aiplayer class so heavy that you can't have more than a few of them spawned at once? If so, should I be creating my own lightweight npc class? If not, any idea why things would start to lag so bad? Any help would be appreciated.
-Sean
I'm having a weird problem with aiPlayers. I have an NPCManager (basically a modified AIManager) setup to spawn a new tank every few seconds if there are less than a preset number (currently I'm just testing this out, so it's very simple). Oddly, once 5-6 little tanks get on screen (they are aiPlayer objects), I start to get very jerky motion from them despite getting around 50 fps. Stranger still, if I go into the world editor and select one, its rendered shape will move very jerkily, but the bounding box is perfectly smooth. It seems to get worse the more that are spawned, and once I get up to around 10 it even seems to interfere with normal game operation (IE my camera panning suddenly stops working).
I guess my question is, is the aiplayer class so heavy that you can't have more than a few of them spawned at once? If so, should I be creating my own lightweight npc class? If not, any idea why things would start to lag so bad? Any help would be appreciated.
-Sean
#2
02/02/2009 (9:44 am)
Adding the clamp function fixed it. Thanks for the quick reply. It sounds like it might still be worth writing a lightweight npc class (these guys are going to be cannon fodder, so don't need to keep track of much), just for network performance reasons, but now I can put that off. Thanks again :)
Torque Owner Jason "fireVein" Culwell
It really is just a minor annoyance, and nothing really serious. I can easily drop 100 or more bots into my game, PrototypeB. I get bigger performance hits from them all bumping into each other(collision detection) than anything.
To fix it, go to aiPlayer.cpp and look for the function: bool AIPlayer::getAIMove(Move *movePtr)
Add..
movePtr->clamp();
right before "return true;" at the bottom of that function. I am actually surprised that this has not already been added in. I have had to add it to every project that I have prototyped thus far with TGE/A.
Alternatively, or in conjunction, you can try increasing the packet sizes and frequency:
$pref::Net::PacketRateToClient = "32";
$pref::Net::PacketRateToServer = "32";
$pref::Net::PacketSize = "450";
(note: these values are maximum)
Careful with those, however, as it is very easy to alienate dial-up players and keep them from being able to play online. Increasing these values will also reduce the client-side delay of projectiles being added to the scene. Useful if you have a large amount of projectiles and they aren't moving very fast.
If you are making a single player game, then those values should be maxed.