Mission Optimisation: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(Unscheduled code)
m (Update Unscheduled code)
Line 139: Line 139:
| {{colorball|green}}
| {{colorball|green}}
| {{colorball|green}}
| {{colorball|green}}
| Unscheduled code has a high impact on the framerate. Unscheduled code section must be clear, short, efficient. You should avoid to use loop, complex conditions, long instructions parts, or simply code that doesn't require to be prior over the calculation of the frame. Unscheduled code is used by : trigger, fsm, sqs, event handler, etc.
| [[Scheduler#Unscheduled_Environment|Unscheduled code]] can have a high impact on the framerate, as such code is not subject to the [[Scheduler|scheduler]]'s management (as its name suggests) and will run without limitation. Cyclic unscheduled low-performance code can make the game unplayable, up to freezing it.
* A good pratice to avoid freeze is to switch as fast possible the non prior code to scheduled mode with [[spawn|spawn]]
* As only time-critical scripts should run unscheduled, [[spawn]] any other code from unscheduled environment once you have the required results:<!--
--><code>(...) {{codecomment|// unscheduled code}}<br><!--
-->[_var1, _var2] [[spawn]] TAG_fnc_MyFunction;<br><!--
-->(...) {{codecomment|// other unscheduled code}}</code>
{{ Informative | See also [[Scheduler#Where code starts unscheduled|Where code starts unscheduled]]. }}
|}
|}


{{ Informative | [[viewDistance|View distance]] can be separately set for each clients independently from the server's value, through scripting.<br>
{{ Informative | [[viewDistance|View distance]] can be separately set for each clients independently from the server's value through scripting.<br>
This can make or break performance for the client. }}
This can make or break performance for the client. }}


Line 156: Line 160:


== See also ==
== See also ==
* [[Multiplayer Scripting]]
* [[Multiplayer Scripting]]
* [[Code Optimisation]]
* [[Code Optimisation]]

Revision as of 18:23, 24 July 2019

Template:SideTOC

This page is about Mission Optimisation. For scripting optimisation, see Code Optimisation.

Introduction

This article will try to be a general guide about improving your mission's performance.
As usual, moderation is the key; do not expect to find a magical solution that makes it possible to run thousands of AI at 144 FPS on this page. Everything comes at a cost, the tweaks on this page will simply allow you to calibrate your mission properly.


Before anything

Before optimising anything, make sure you do not have any performance issue running the game itself:

  • Open the editor, place a unit in the area you like and test your computer.
    • You can get current FPS in Arma 3 by going into video options or using diag_fps
    • Steam allows you to display FPS in a screen corner, in Settings > In game > FPS Counter
  • Use (unofficial) Performance Guides to get better performances:
  • Play your mission in singleplayer. If your mission runs fine, its network messages might very well be the issue. See Multiplayer Scripting for good practice tips.
  • Usual bottlenecks:
    • Lower your graphical settings (resolution, textures). If you get way better performances, at least your GPU limits you.
    • If the game keeps having low FPS when running @ 1024×768/low textures then your CPU is most likely the issue. Mission scripts may be performance-hogging too.
Please note that viewDistance (among other settings) impacts both GPU and CPU!


Creating your mission


Performance impact table

Template:colorball means a heavy impact on performance

Template:colorball means an average impact

Template:colorball means little to no performance impact.
Topic CPU GPU Net-
work
Solution

AI unit quantity

Template:colorball Template:colorball Template:colorball
  • Use Agents whenever possible
  • The more units there are, the more network updates there will be - hence the impact on both CPU and network.
  • If a client has a low-end machine, they shouldn't lead a group of many AIs as these would then be locally computed.
  • Arma 3 Dynamic Simulation allows you to freeze AI that are distant from players. Many distance settings should be set according to the mission.
Most if not all of the mission calculation (objectives, completion distance, etc.) must be done server-side. Local effects should be calculated client-side.
If you own more than one average computers, you could consider Headless client to offload AI from the server.

Object quantity

Template:colorball Template:colorball Template:colorball The less objects, the more FPS you will have.
  • Lower the quantity of objects in the mission, such as:
    • AI units, agents
    • vehicles, simple objects
    • weapon attachments (their proxies are attachedTo)
    • headgear, clothing, vests, backpacks
    • head-mounted devices (NVGs, etc.)
  • Lower viewDistance
  • Lower terrain details
  • Lower the Dynamic Simulation treshold
  • Use Simple Objects
  • Use Garbage Collection in order to automatically delete bodies and wreckages:
Only the on-screen objects will strongly impact GPU.

General script mistakes

Template:colorball Template:colorball Template:colorball Having too many scripts running is a cause for severe performance issues and execution delays in singleplayer as well as multiplayer.

High-frequency scripts

Template:colorball Template:colorball Template:colorball Checking a condition too often is usually a source of poor performance. Does your code execution need to be frame-perfect, or can you afford a delay of a few seconds?
  • A while-loop checking without a minimum loop-sleep time is usually a sign of bad conception.while { true } // bad if you don't know what you are doing
    while { alive player } // better
    while { sleep 1 ; alive player } // perfect
  • Triggers check their set condition every 0.5 second (hardcoded value). If a large area is covered or condition code is too complex, this can become an issue; the triggers should then be converted to scripts if possible.
  • Triggers can be made Server-Side only to save clients' resources.

High-frequency network messages

Template:colorball Template:colorball Template:colorball
  • Use publicVariable wisely; for specific cases, consider publicVariableServer / publicVariableClient
  • Creating units/vehicles globally implies a network synchronisation, keep them to a minimum / at one-point in the mission.
  • Keep global effect commands to a minimum: e.g a setPos will synchronise the unit position to every client, a good practice is to use these commands punctually. If you need a frequent "set position" you may want to look at attachTo depending on your usage.
  • Lower client's view distance in order to lessen its object position update requests

Unscheduled code

Template:colorball Template:colorball Template:colorball Unscheduled code can have a high impact on the framerate, as such code is not subject to the scheduler's management (as its name suggests) and will run without limitation. Cyclic unscheduled low-performance code can make the game unplayable, up to freezing it.
  • As only time-critical scripts should run unscheduled, spawn any other code from unscheduled environment once you have the required results:(...) // unscheduled code
    [_var1, _var2] spawn TAG_fnc_MyFunction;
    (...) // other unscheduled code
View distance can be separately set for each clients independently from the server's value through scripting.
This can make or break performance for the client.


What else?

If you have applied all these recommendations and your mission still doesn't run well in multiplayer (but does in singleplayer), it might be caused by mods that you are running which could be badly, or not at all, optimised.

If you want to be sure, run the same mission with and without mods. If you have a big difference in performance, look no further.


See also