Jump to content
Sign in to follow this  
Horner

How many AI, are too many AI

Recommended Posts

So.... I've got a question for all you more experienced mission makers.

How many AI is too many? At what point does arma itself start to break down and make the game run slower (not speaking of overall machine abilities, but the engine abilities)?

Share this post


Link to post
Share on other sites

My favourite field of research. :) This - of course - depends on lot of things and your CPU (single core) power cannot be disregarded.

The AI are basically scripts. More AI means more scripts, more commands. Firefights mean a lot more commands. Not only AI throws commands at the engine, but basically everything that is happening in your mission.

The other factor is that you need to draw every single frame. These are commands too and cannot be separated from AI behaviour (you need to know on each frame where the units are and what they are doing, where the bullets are, etc. right?).

Now, Your CPU speed will give you how many commands can be executed per second. (All the above must be run on one core). A fast CPU will be able to run more commands per second. A 4core CPU can take some other work to other cores to ease this a bit. So your question cannot be answered as is. There is no engine ability alone.

You have two types of slowdown: delayed script execution and FPS drop.

Delayed script execution means that the scheduler can execute the commands one after the other. Think of it as an airport. Too much commands at a time causes bottleneck. Too much commands coming when there is a bottleneck causes an even bigger bottleneck. This will lead to FPS drops too, because you'll need to show the whole thing on frames in the end.

So back to the original question: you can kill the engine with 2 AIs too (an uncontrolled while cycle is enough), and you can operate well with lots of AIs, even more if not all of them are fighting.

To give you numbers: according to my tests on my 3,4 Ghz 2Core CPU, playable FPS can be achieved with around 100 AI, with some pretty serious script system running parallel. Of course firefights are baad, but soliders die easily, which helps with the numbers quickly. Using caching and stuff you can achieve a lot by 100 AIs.

All the above is about singleplayer. A dedicated server and MP is another story.

Edited by zapat

Share this post


Link to post
Share on other sites

The question is : what is the AI doing ? If standing still, you can put a hell lot of AI, but while pathfinding, that's another story.

Share this post


Link to post
Share on other sites

It also seems to depend on where those AI are. The closer they are to each other, the more lag caused.

As a rule of thumb, I never go above 150 in SP, and 250-300 on a dedi (last mission I made produced about 400 of them, and the AI reactions were pretty poor. Although a caching system and a HC should help solve that).

Just to be stupid, I used DAC to populate Lingor with between 600 and 700 dudes (and I had quite a lot of mods running at the time, plus ALICE civies). Was still totally playable, even though the AI reactions were not really good at all times. On the other hand, the script delay was pretty fat, and sometime the "uncaching" of groups would be delayed to the point I'd see the units reappear.

Share this post


Link to post
Share on other sites

I have a script that sets ai to enableSimulation false (idea from qbt) if they are over 2km away, that seems to help out a lot. And the headless client feature seems to be like a great idea that will revolutionize ai in the arma franchise.

Thanks for the information guys :)

Share this post


Link to post
Share on other sites

I've been curious about that thing for a while now: What do you check the distance to? I mean, in case of SP, it's pretty easy, but when you get multiple players, do you check that distance for every player?

Share this post


Link to post
Share on other sites

It runs client side, as enableSimulation is a client side command, I'll upload the code in a second.

EDIT:

http://pastebin.com/eutVgtdg

Like I said, I got the method from a guy named qbt, so this is his method I just coded it to work for me.

Edited by Horner
Added code link

Share this post


Link to post
Share on other sites

You should try using spawn scripts or stuff like DAC, then you can have a great number of AI as long as everything is not supposed to happen at the same time.

There's videos of 1500 AI but it's in SP.

Share this post


Link to post
Share on other sites

Another thing to consider is that the AI are still rendered or active to a point even when their dead, so dead bodies, destroyed vehicles and such

all effect the performance of a mission as also noted the performance will be different for everyone based on their computer setup.

So as a suggestion you can implement a script the deletes dead bodies, and destroyed vehicles.

One I use all the time:

Delete Dead bodies and destroyed vehicles script

http://forums.bistudio.com/showthread.php?124600-delete-dead-vehicles&p=2016996#post2016996

Also note there is a caching script that can be used too.

Having a single core cpu myself, i have limitations but with this:

cB AI Unit Caching

http://www.armaholic.com/page.php?id=10102

I was able to play with more AI, alot more AI!

theres also

RMM Reducer

http://www.armaholic.com/page.php?id=8544

Share this post


Link to post
Share on other sites

Thanks for the links, Gunter, I'll definately check those out, I already have an allDead script running to delete dead Units, however, the Unit Caching script looks fantastic though! Currently with the way I have it set up with the enableSimulation false command for units at greater distances than 2km, I usually only take a 10fps hit when I have 100 ai spawned (this is hosting locally, i.e. acting as the client and the server) instead of a higher 20-25 fps hit when not running the script so it's doing wonders.

Share this post


Link to post
Share on other sites

Also note there is a caching script that can be used too.

Having a single core cpu myself, i have limitations but with this:

cB AI Unit Caching

http://www.armaholic.com/page.php?id=10102

I was able to play with more AI, alot more AI!

That script seems to work fine as long as you leave the ai unscripted with just basic waypoint cycles. I tried to add conditions to the ai and it runs into problems in combi with that script. See my unanswered question here in this forum section.

Share this post


Link to post
Share on other sites
Another thing to consider is that the AI are still rendered or active to a point even when their dead, so dead bodies, destroyed vehicles and such

all effect the performance of a mission as also noted the performance will be different for everyone based on their computer setup.

I have also read about these affecting performance, but I haven't been able to measure this. I put thousands of dead bodies on the map and framerate didn't drop at all. The same amount of AI could be used.

This is true for wrecks, spawned objects, destroyed cities, and even triggers (but that is a bit different story). Sure they cost something, but I needed ten-thousands to have something that can be called performance hit.

Naturally some checking commands will struggle more with more objects/dead bodies, OR/AND you can have a hit becasue of effects multiplying (I mean you can have things that don't cause performance hit, when run alone, but running them together can have a serious hit.)

I came to the conclusion that if the engine can handle 10000 of something well, 500 won't cause anything bad.

My other observation was that turning off simulation on AIs don't have THAT much effect either. You end up better if you delete like 10 units instead of diabling simulation for 100. So it doesn't really worth checking, turning off and on all the time. Caching DOES worth though! you will hardly see an infantry unit 2kms away, so I don't see any reasons to keep him in the gameworld.

I may not be right with all these, but I have put hours to test performance for my dynamic mission I am working on. And I am talking about SP only on a weak CPU.

Edited by zapat

Share this post


Link to post
Share on other sites
I tried to add conditions to the ai and it runs into problems in combi with that script. See my unanswered question here in this forum section.

When i had my gameserver earlier this year I had this very caching script running in a large mission I built.

Feeling the mission didn't have enough enemies, as my buddy and I were like taking them down, we'd be out running for a bit before we'd run into a patrol,

so I reedited my mission and added maybe 25 more AI, tested it before I added the caching script, and i was getting a slowdown, enough lag to make a custom

menu respawn i use sometimes not work properly or delay, well i implemented the script into the mission, and tested again, and no lag whatsoever!

This mission was also being played with CoWarMod too. Sxcript works fine for me, i normally dont play with alot of AI but if I do i add the script.

you will hardly see an infantry unit 2kms away, so I don't see any reasons to keep him in the gameworld.

Right, when i use the caching script i usually set the cache distance at 500-800m, al depends on the map too, default is a 1000.

Share this post


Link to post
Share on other sites

run Battlezone and adjust the ai numbers that will give you a idea on what you can run and you will see where it starts to lag

ai numbers are as they say , depends on how the sctipts are written

more loops less ai. but if you let the arma engine do most of the work you can run more ai

again the more spacing between ai the more you can run ,

a crewed vehicle and a single ai soldier seem to take up the same cpu power , depending on the script

Share this post


Link to post
Share on other sites

I was pressing arma's limits again today and came up with some other unrelated information.

Whether it's just my CPU or not, it seems as though with strings (and I'm guessing with arrays aswell), when you're handling variables with data sizes up into several MB (i.e. a string with millions of characters) this is when things start to break down. And I'm talking 2-3 fps break down and almost unable to exit the game. Not sure if this is the game itself breaking down or my own personal computer. Anyone else got some documentation on this?

EDIT:

Alright, either something about the operators in arma is odd at higher numbers or my function is broken, I'm using this function to convert higher numbers into a readable format

ext_math_fnc_addCommas =
{
private["_number","_modNumber","_skip","_str","_ret"];
_number = _this select 0;
_modNumber = _number;
_skip = 0;
_str = "";

if (_number > 0) then
{
	while {_modNumber > 0} do
	{
		if (_modNumber > 0 && _skip > 0 && (_skip mod 3) == 0) then
		{
			_str = "," + _str;
		};

		_str =  (str (_modNumber mod 10)) + _str;
		_skip = _skip + 1;
		_modNumber = floor (_modNumber / 10);
	};

	if (_number < 0) then
	{
		_str = "-" + _str;
	};
} else {
	_str = "0";
};

_ret = _str;
_ret
};

And I'm using this code to calculate the numbers.

num = 1000000;
mod = 10;

while {true} do
{
hintSilent ([num] call ext_math_fnc_addCommas);
diag_log ([num] call ext_math_fnc_addCommas);
num = num * mod;
sleep 1;
};

And with this code it spits this out in the rpt

"1,000,000"
"10,000,000"
"100,000,000"
"1,000,000,000"
"10,000,000,000"
"100,000,000,002"
"1,000,000,000,024"
"10,000,000,000,248"
"100,000,000,002,482"
"1,000,000,000,024,824"
"10,000,002,684,404,084"
"100,000,026,844,040,844"
"1,000,000,268,440,408,440"
"10,000,002,684,404,084,402"
"100,000,026,844,040,844,022"
"1,000,000,268,440,408,440,220"
"9,999,998,426,022,400,246,466"
"99,999,984,260,224,002,464,660"
"999,999,842,602,240,024,646,608"
"10,000,002,684,404,028,828,040,248"
"100,000,026,844,040,288,280,402,486"
"1,000,000,268,440,402,882,804,024,862"
"10,000,002,684,404,028,828,040,248,620"
"100,000,026,844,040,288,280,402,486,204"
"1,000,000,268,440,402,882,804,024,862,040"
"10,000,002,684,404,028,828,040,248,620,406"
"100,000,026,844,040,288,280,402,486,204,044"
"1,000,000,268,440,402,882,804,024,862,040,442"

As you can see, all of a sudden at 100 billion it turns a 0 into a 2, is there something wrong with the math in my function that is causing this or is it the way math is handled in arma? I'm pretty sure it's the function I'm using but I fail to see why it works with lower numbers but not with higher numbers.

---------- Post added at 08:12 PM ---------- Previous post was at 07:20 PM ----------

And, problem found.

The "Mod" command in arma may be sort of bugged.

It seems it breaks at 100 billion because.

num = 10000000000; // 10 Billion
hintSilent (str (num mod 10));

Prints out 0, but

num = 100000000000; // 100 Billion
hintSilent (str (num mod 10));

Prints out 2. the "mod" command must be broken for higher numbers.

EDIT:

Okay, I came up with a way to properly format numbers with commas without using "mod", this method will be introduced in the next update of the Extended Functions Library.

Edited by Horner

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×