Lou Montana/Sandbox – User

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Multiple fixes)
m (Update w/ links)
 
(76 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{SideTOC}}
[[Category: Sandbox]]
{{ Informative | This page is about [[Mission Optimisation]]. For ''scripting'' optimisation, see [[Code Optimisation]]. }}
{{Feature|informative|To go on [[Initialisation Order]].}}
== Introduction ==


This article will try to be a general guide about improving your '''mission's''' performance.<br>
{| class="wikitable sortable align-center align-left-col-1"
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.
|+ Order of Initialisation (use column sorting for respective machine order)
! rowspan="2" class="unsortable" style="text-align: center" | Task
! rowspan="2" | Exec Environment
! rowspan="1" colspan="5" class="unsortable" | Machine
|-
! Single Player
! Dedicated Server
! Hosted Server
! Multiplayer Client
! [[Multiplayer Scripting#Join In Progress|JIP]] MP Client


|-
| [[Arma 3: Functions Library|Functions]] with <syntaxhighlight lang="cpp" inline>recompile</syntaxhighlight> {{Link|Arma 3: Functions Library#Attributes 3|attribute}} are recompiled
| {{n/a}}
| 1 <!-- Single Player -->
| 1 <!-- Dedicated Server -->
| 1 <!-- Hosted Server -->
| 1 <!-- Multiplayer Client -->
| 1 <!-- JIP MP Client -->


== Before anything ==
|-
| [[Arma 3: Functions Library|Functions]] with <syntaxhighlight lang="cpp" inline>preInit</syntaxhighlight> {{Link|Arma 3: Functions Library#Attributes 3|attribute}} are called
| [[Scheduler#Unscheduled Environment|Unscheduled]]
| 2 <!-- Single Player -->
| 2 <!-- Dedicated Server -->
| 2 <!-- Hosted Server -->
| 2 <!-- Multiplayer Client -->
| 2 <!-- JIP MP Client -->


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.
| Object Init Event Handlers are called
** {{arma3}} displays FPS when you go into '''video options'''
| [[Scheduler#Unscheduled Environment|Unscheduled]]
** '''Steam''' allows you to display FPS in a screen corner, in ''Settings &gt; In game &gt; FPS Counter''
| 3 <!-- Single Player -->
* Use (unofficial) Performance Guides to get better performances:
| 3 <!-- Dedicated Server -->
** [https://steamcommunity.com/sharedfiles/filedetails/?id=1731305438      {{arma3}} performance guide]
| 3 <!-- Hosted Server -->
** [https://www.moddb.com/forum/thread/arma-2-ultimate-tweak-thread        {{arma2}} performance guide]
| 3 <!-- Multiplayer Client -->
** [https://forums.bohemia.net/forums/topic/50167-pc-optimization-for-arma/ {{arma}}  performance guide]<!--
| {{Icon|unchecked}} <!-- JIP MP Client -->
** [ {{ofp}}  performance guide]
-->
* 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.
{{ Important | Please note that [[viewDistance]] (among other settings) impacts both GPU and CPU! }}


|-
| Expressions of [[Eden Editor: Configuring Attributes|Eden Editor entity attributes]] are called<ref name="isPlayer"><sqf inline>isPlayer _entity</sqf> does not return [[true]] immediately. Once the entity has become a [[player]], it is transferred to the client.</ref>
| [[Scheduler#Unscheduled Environment|Unscheduled]]
| 4 <!-- Single Player -->
| 4 <!-- Dedicated Server -->
| 4 <!-- Hosted Server -->
| {{Icon|unchecked}} <!-- Multiplayer Client -->
| {{Icon|unchecked}} <!-- JIP MP Client -->


== Creating your mission ==
|-
| Object initialisation fields are called
| [[Scheduler#Unscheduled Environment|Unscheduled]]
| 5 <!-- Single Player -->
| 5 <!-- Dedicated Server -->
| 5 <!-- Hosted Server -->
| 4 <!-- Multiplayer Client -->
| 3 <!-- JIP MP Client -->


* Be sure to create your scripts with the latest available commands and functions.
|- style="background-color: #95F0AD"
** In {{arma3}} use [[remoteExec]]&nbsp;/&nbsp;[[remoteExecCall]] and '''DITCH [[BIS_fnc_MP]] FOR GOOD!''' See [[Arma 3 Remote Execution]] for more information.
| [[Event Scripts#init.sqs|init.sqs]] is executed
** In {{arma2}} network communication is done using the [[Multiplayer framework]].
|
* Use the available frameworks and functions for each topic, unless you replace them by third-party ones:
| 6 <!-- Single Player -->
** [[Arma 3 Respawn]]
| <!-- Dedicated Server -->
** [[Arma 3 Revive]]
| <!-- Hosted Server -->
** [[Arma 3 Task Framework]]
| <!-- Multiplayer Client -->
** [[Arma 3 Animated Briefing]]
| <!-- JIP MP Client -->
** [[Arma 3 Animated Opening]]
** [[Arma 3 Dynamic Groups]]
** [[Arma 3 Key Frame Animation]]
** and most importantly: [[Functions]]


|- style="background-color: #95F0AD"
| [[Event Scripts#init.sqf|init.sqf]] is executed
| [[Scheduler#Scheduled Environment|Scheduled]]<ref name="enginewaits">Note '''in single player''' that while the environment is [[Scheduler#Scheduled Environment|Scheduled]] ([[canSuspend]] returns true), the engine seems to wait until the script is done executing, essentially behaving similarly to an [[Scheduler#Unscheduled Environment|Unscheduled environment]] - infinite loops will freeze the game, [[uiSleep]] may pause the game for up to ~20s (postInit), [[waitUntil]] can cause catastrophic issues, etc.</ref>
| <!-- Single Player -->
| <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->


== Performance impact table ==
|-
{{Informative|
| Expressions of [[Eden Editor: Configuring Attributes|Eden Editor scenario attributes]] are called<ref name="playerCommandNotAvailable">[[player]] is not available immediately.</ref>
{{colorball|red|1.125}}    means a heavy impact on performance<br />
| [[Scheduler#Unscheduled Environment|Unscheduled]]
{{colorball|orange|1.125}} means an average impact<br />
| <!-- Single Player -->
{{colorball|green|1.125}}  means little to no performance impact.
| <!-- Dedicated Server -->
}}
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->


{|class="bikitable"
|- style="background-color: #95DEF0"
! Topic
| Persistent functions are called
! CPU
! GPU
! Net-<br>work
! Solution
|-
|
|
==== AI unit quantity ====
| <!-- Single Player -->
| {{colorball|red}}
| <!-- Dedicated Server -->
| {{colorball|green}}
| <!-- Hosted Server -->
| {{colorball|orange}}
| <!-- Multiplayer Client -->
|
| <!-- JIP MP Client -->
* Use [[createAgent|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.
{{ Important | Most if not all of the mission calculation (objectives, completion distance, etc.) must be done '''server-side'''. Local effects should be calculated '''client-side'''. }}
{{ Informative | If you own more than one average computers, you could consider [[Arma 3 Headless Client|Headless client]] to offload AI from the server. }}
|-
|-
| [[Modules]] are initialised
|
|
==== Object quantity ====
| <!-- Single Player -->
| {{colorball|orange}}
| <!-- Dedicated Server -->
| {{colorball|orange}}
| <!-- Hosted Server -->
| {{colorball|orange}}
| <!-- Multiplayer Client -->
| The less objects, the more FPS you will have.
| {{Icon|unchecked}} <!-- JIP MP Client -->
* Lower the quantity of objects in the mission, such as:
 
** AI units, agents
|- style="background-color: #DEF0AD"
** vehicles, simple objects
| [[Event Scripts#initServer.sqf|initServer.sqf]] is executed
** weapon attachments (their proxies are [[attachedTo]])
| [[Scheduler#Scheduled Environment|Scheduled]]
** headgear, clothing, vests, backpacks
| <!-- Single Player -->
** head-mounted devices (NVGs, etc.)
| <!-- Dedicated Server -->
* Lower [[viewDistance]]
| <!-- Hosted Server -->
* Lower terrain details
| {{n/a}} <!-- Multiplayer Client -->
* Lower the [[Arma 3 Dynamic Simulation|Dynamic Simulation]] treshold
| {{n/a}} <!-- JIP MP Client -->
* Use [[Arma 3 Simple Objects|Simple Objects]]
 
* Use '''Garbage Collection''' in order to automatically delete bodies and wreckages:
|- style="background-color: #DEF0AD"
** {{arma3}}'s Eden-integrated [[Description.ext#Corpse_.26_wreck_management|Garbage Collection]]
| [[Event Scripts#initPlayerLocal.sqf|initPlayerLocal.sqf]] is executed
** {{arma2}}'s [[Garbage Collector]]
| [[Scheduler#Scheduled Environment|Scheduled]]
** {{tkoh}}'s [[BIS_fnc_GC]]
| <!-- Single Player -->
{{ Informative | Only the ''on-screen'' objects will strongly impact GPU. }}
| {{n/a}} <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->
 
|- style="background-color: #DEF0AD"
| [[Event Scripts#initPlayerServer.sqf|initPlayerServer.sqf]] is executed on the server
| [[Scheduler#Scheduled Environment|Scheduled]]
| <!-- Single Player -->
| {{n/a}} <!-- Dedicated Server -->
| ?? <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->
 
|-
|-
|
| [[Arma 3: Functions Library|Functions]] with <syntaxhighlight lang="cpp" inline>postInit</syntaxhighlight> {{Link|Arma 3: Functions Library#Attributes 3|attribute}} are called
==== High-frequency scripts ====
| [[Scheduler#Scheduled Environment|Scheduled]]<ref name="enginewaits"/>
| {{colorball|red}}
| <!-- Single Player -->
| {{colorball|green}}
| <!-- Dedicated Server -->
| {{colorball|green}}
| <!-- Hosted Server -->
|
| <!-- Multiplayer Client -->
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?
| <!-- JIP MP Client -->
* A [[while]]-loop checking without a minimum loop-[[sleep]] time is usually a sign of bad conception.<code>[[while]] { [[true]] } {{codecomment|// already "bad" if you don't know what you are doing}}<br>[[while]] { [[alive]] [[player]] } {{codecomment|// better}}<br>[[while]] { [[sleep]] 1 ; [[alive]] [[player]] } {{codecomment|// perfect}}</code>
 
* [[trigger|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.
|- style="background-color: #95DEF0"
* [[trigger|Triggers]] can be made '''Server-Side only'''.
| [[Event Scripts#init.sqs|init.sqs]] is executed
|-
| [[Scheduler#Scheduled Environment|Scheduled]]
|
| <!-- Single Player -->
==== High-frequency network messages ====
| <!-- Dedicated Server -->
| {{colorball|orange}}
| <!-- Hosted Server -->
| {{colorball|green}}
| <!-- Multiplayer Client -->
| {{colorball|red}}
| <!-- JIP MP Client -->
|
* Use [[publicVariable]] wisely; for specific cases, consider [[publicVariableServer]]&nbsp;/&nbsp;[[publicVariableClient]]
* Creating [[createUnit|units]]/[[createVehicle|vehicles]] globally implies a network synchronisation, keep them to a minimum / at one-point in the mission.
* Keep [[:Category:Commands with global effects|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 [[viewDistance|view distance]] in order to lessen its object position update requests
|}


{{ Informative | [[viewDistance|View distance]] can be separately set for each clients independently from the server's value, through scripting.<br>
|- style="background-color: #95DEF0"
This can make or break performance for the client. }}
| [[Event Scripts#init.sqf|init.sqf]] is executed
| [[Scheduler#Scheduled Environment|Scheduled]]
| <!-- Single Player -->
| <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->


|-
| [[remoteExec]]'s [[Multiplayer Scripting#Join In Progress|JIP]] queue
| {{n/a}}
| {{n/a}} <!-- Single Player -->
| {{n/a}} <!-- Dedicated Server -->
| {{n/a}} <!-- Hosted Server -->
| {{n/a}} <!-- Multiplayer Client -->
| 42 <!-- JIP MP Client -->


== What else? ==
|- style="background-color: #EEE"
| ''Scenario going''
| {{n/a}}
| <!-- Single Player -->
| <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->


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.
| [[Event Scripts#exit.sqf|exit.sqf]]
|
| <!-- Single Player -->
| <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->


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.
|-
| [[Event Scripts#exit.sqs|exit.sqs]]
|
| <!-- Single Player -->
| <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->


|-
| {{Link|Arma 3: Mission Event Handlers#Ended|"Ended" Mission Event Handler}}
|
| <!-- Single Player -->
| <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->


== See also ==
|-
* [[Multiplayer Scripting]]
|  {{Link|Arma 3: Mission Event Handlers#MPEnded|"MPEnded" Mission Event Handler}}
* [[Code Optimisation]]
|
| <!-- Single Player -->
| <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->


|}


[[Category: Scripting Topics]]


== See Also ==


[[Category: Sandbox]]
* [[Arma 3: Functions Library]]<!--
* [[Arma 2: Functions Library]] -->
* [[Arma 3: Remote Execution]], [[BIS_fnc_MP]] <!-- keep? -->
* [[Eden Editor: Configuring Attributes|Eden Editor: Configuring Attributes]]
* [[Event Scripts]]
* [[Scheduler]]

Latest revision as of 00:29, 18 March 2024

Order of Initialisation (use column sorting for respective machine order)
Task Exec Environment Machine
Single Player Dedicated Server Hosted Server Multiplayer Client JIP MP Client
Functions with recompile attribute are recompiled N/A 1 1 1 1 1
Functions with preInit attribute are called Unscheduled 2 2 2 2 2
Object Init Event Handlers are called Unscheduled 3 3 3 3 Unchecked
Expressions of Eden Editor entity attributes are called[1] Unscheduled 4 4 4 Unchecked Unchecked
Object initialisation fields are called Unscheduled 5 5 5 4 3
init.sqs is executed 6
init.sqf is executed Scheduled[2]
Expressions of Eden Editor scenario attributes are called[3] Unscheduled
Persistent functions are called
Modules are initialised Unchecked
initServer.sqf is executed Scheduled N/A N/A
initPlayerLocal.sqf is executed Scheduled N/A
initPlayerServer.sqf is executed on the server Scheduled N/A ??
Functions with postInit attribute are called Scheduled[2]
init.sqs is executed Scheduled
init.sqf is executed Scheduled
remoteExec's JIP queue N/A N/A N/A N/A N/A 42
Scenario going N/A
exit.sqf
exit.sqs
"Ended" Mission Event Handler
"MPEnded" Mission Event Handler


See Also

  1. isPlayer _entity does not return true immediately. Once the entity has become a player, it is transferred to the client.
  2. 2.0 2.1 Note in single player that while the environment is Scheduled (canSuspend returns true), the engine seems to wait until the script is done executing, essentially behaving similarly to an Unscheduled environment - infinite loops will freeze the game, uiSleep may pause the game for up to ~20s (postInit), waitUntil can cause catastrophic issues, etc.
  3. player is not available immediately.