Game Development Community

dev|Pro Game Development Curriculum

T3D bug, 300 AI's jumping/jerking instead of walk *BUG FIX*

by Vince Gee · 05/11/2012 (9:53 pm) · 5 comments

Anyone notice a bug with the engine that when spawning 300 AI's and they warp around?

Note: Works for both Dedicated Mode and Single Player.

I ran into an interesting issue when we spawned 300 AI in our zone and had them doing a conga dance around the zone following waypoints. When a player was running around them, the mobs would warp. It was horrid, the frame rate was alright (about 60fps in dedicated server mode) but they would warp position to position instead of walking smoothly across the terrain.

(NOTE: The computer I use running a dedicate server and a client is an old Pentium Duo Quad Core with 8 gigs of ram... with an outdated video card)

So I dug up an old resource of mine titled, "Limiting Shapebase ghosting without reducing ViewDistance".

After implementing it, the AI's warped a bit less but we got a significant frame rate increase. I knew I was on the right track, but I couldn't quite put my finger on it. So after reviewing how the server ranks what it ghosts to a player I realized a quick fix could solve the problem.

First, I use the mVisiblePlayers value added by the resource instead of mVisibleDistance in the weight calculation. This alone shot our frame rate well over 80 fps( in dedicated server mode) even with 300 AIs in the zone.

Unfortunately though, the mobs would warp into the FOV instead of gingerly walking into the FOV. Once they were in the FOV they walked normal till they reach the other end of the FOV where once again they warped.

So, I looked into the code a bit more and decided to add 40 degrees to the FOV when calculating whether or not the mob was in front or behind the player (clamped it at 360).

We fired up our build and magically, no more warping! Our AI's now walk across the terrain real pretty like and we were peaking at 133 ( in dedicated server mode) frames per second!

We got about 30 frames per second in single player.

I updated the old resource with the two additional changes, hope you all enjoy!

The resource can be found here: www.garagegames.com/community/resources/view/21471

Vince

P.S.: Don't try to load 300 AIs at home, there is a second resource which has not been posted yet that will explain how to make the engine support 300+ AIs, and relatively unlimited objects in the engine. Well, you would hit the int/unit point at sometime... but that is a different discussion.




#1
05/11/2012 (10:43 pm)
You have to be very careful when tinkering with GameBase::getUpdatePriority() because it's essentially a zero-sum game. Artificially boosting the priority of certain objects will in effect reduce the priority of others. As an example, increasing the 'weight' of Players/AIPlayers may 'fix' the warping issue but cause things like projectiles to update later than they normally would (which will manifest as delayed creation/destruction and warping on the clientside).

The reason you see warping with hundreds (or really even a handful) of AIPlayers is because there's simply too much state data for the server to push out into a single packet (of which the size is determined by $pref::Net::packetSize - in bytes). As of 1.1 each AIPlayer required ~14 bytes to update their state so if you have a default packetSize of 200 bytes you may only 'fit' 10-11 AIPlayers into a single packet.

When this happens getUpdatePriority() kicks in and determines the order in which objects have their state data sent out. Objects that are deemed higher 'priority' have their states updated first and things of lesser importance get sent later. getUpdatePriority() insures every object will eventually be updated but depending on the number of objects it could take several packets to do so (which might translate into several seconds depending on the $pref::Net::packetRateToClient setting).

There are a couple alternatives to tinkering with getUpdatePriority():

1). Reduce the bandwidth requirements of AIPlayer. The old RTSKit used this approach in order to get hundreds of networked units on the screen. I don't know the specifics but I do seem to recall some old .plans by Josh Williams discussing the changes.

2). Change Player::sMinWarpTicks, Player::sMaxWarpTicks and Player::sMaxPredictionTicks. I posted some questions/findings about these a while ago here but never got any response. What I found is increasing sMaxWarpTicks allowed me to have hundreds of AIPlayers (well, AIUnits in my case) on the screen/ghosted while still having a very low packetSize.

I believe these variables are for tweaking the clientside interpolation of Player objects. These variables are also still set to something suitable for Tribes 2, FYI.
#2
05/11/2012 (10:50 pm)
Ahh, but you see I didn't artificially boost AI, I artificially decreased them.

Instead of sending the whole zone, I only send what is in the cull range, (Which is added by the resource) I then decrease their ranking by the cull range instead of the view distance. I then take the square root of the percentage, to make the AI closer to the player send more updates than the ones farther back.

If you read the code, you will see that I am just culling the AIs which are far enough out that they aren't important to the player.

So, it's not a matter of Artificially boosting anything, it's just better culling.....
#3
05/11/2012 (10:58 pm)
This is hot! I cant wait to see the second resource:)
#4
05/11/2012 (11:16 pm)
Just to clarify, I wasn't referring to the vis distance change (which makes sense given the resource) but rather the fov change. You're artificially increasing the player's field-of-view which will essentially boost the update priority of objects that would otherwise be considered 'off screen'. The nature of getUpdatePriority() is that changes like that will solve one problem (namely, warping of Players/AIPlayers that are just out of view) but may create another one as some other object will now be packet-starved.

There's nothing wrong with tweaking the weightings in getUpdatePriority(). The current settings are another holdover from Tribes 2 so they probably -should- be tweaked for each project. I just want folks to be aware of the consequences. :]
#5
05/13/2012 (4:42 am)
Interesting recource!