Lou Montana/Sandbox – User

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Add frameworks, table, and mods advice)
m (Update w/ links)
 
(80 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{SideTOC}}
[[Category: Sandbox]]
== Introduction ==
{{Feature|informative|To go on [[Initialisation Order]].}}


This article will try to be a general guide about improving your '''mission's''' code '''and''' its performance.<br>
{| class="wikitable sortable align-center align-left-col-1"
As usual, moderation is the key so do not expect to have thousands of AI magically running 144 FPS. 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)
{{ Informative | This page is about [[Mission Optimisation]]. For ''scripting'' optimisation, see [[Code Optimisation]]. }}
! rowspan="2" class="unsortable" style="text-align: center" | Task
{{ Informative | '''See also [[Multiplayer Scripting]]'''. }}
! 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 ==
|-
| Expressions of [[Eden Editor: Configuring Attributes|Eden Editor scenario attributes]] are called<ref name="playerCommandNotAvailable">[[player]] is not available immediately.</ref>
| [[Scheduler#Unscheduled Environment|Unscheduled]]
| <!-- Single Player -->
| <!-- 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 units quantity ====
| <!-- Single Player -->
| {{colorball|red}}
| <!-- Dedicated Server -->
| {{colorball|green}}
| <!-- Hosted Server -->
| {{colorball|orange}}
| <!-- Multiplayer Client -->
|
| <!-- JIP MP Client -->
* Use [[createAgent|Agents]] whenever possible
 
* 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]] and code accordingly. }}
|-
|-
| [[Modules]] are initialised
|
|
==== Objects 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 mission objects quantity
 
** 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 -->
| A [[while]]-loop checking without a minimum loop-[[sleep]] time is usually a sign of bad conception.<br>
| <!-- Multiplayer Client -->
* <code>[[while]] { [[true]] } {{codecomment|// already "bad" if you don't know what you are doing}}</code>
| <!-- JIP MP Client -->
* [[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 be an issue. Convert them to scripts then.
 
* creating [[createUnit|units]]/[[createVehicle|vehicles]] globally implies a network synchronisation.
|- style="background-color: #95DEF0"
| [[Event Scripts#init.sqs|init.sqs]] is executed
| [[Scheduler#Scheduled Environment|Scheduled]]
| <!-- Single Player -->
| <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->
 
|- style="background-color: #95DEF0"
| [[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
==== High-frequency network messages ====
| {{n/a}}
| {{colorball|orange}}
| {{n/a}} <!-- Single Player -->
| {{colorball|green}}
| {{n/a}} <!-- Dedicated Server -->
| {{colorball|red}}
| {{n/a}} <!-- Hosted Server -->
|
| {{n/a}} <!-- Multiplayer Client -->
* Use [[publicVariable]] wisely; for specific cases, consider [[publicVariableServer]]&nbsp;/&nbsp;[[publicVariableClient]]
| 42 <!-- JIP MP Client -->
* Creating [[createUnit|units]]/[[createVehicle|vehicles]] globally implies a network synchronisation, keep them to a minimum / at one-point in the mission.
* keep the '''*global''' version of commands ([[hideObject]]/[[hideObjectGlobal]], etc) to a minimum
* 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: #EEE"
This can make or break performance for the client. }}
| ''Scenario going''
| {{n/a}}
| <!-- Single Player -->
| <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->


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


== What else? ==
|-
| [[Event Scripts#exit.sqs|exit.sqs]]
|
| <!-- Single Player -->
| <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->


You have applied all these recommendations and yet, your mission still doesn't run well in multiplayer (but does in singleplayer);
|-
an answer to that is that you are using '''mods''', of which some are not well optimised, if at all.
| {{Link|Arma 3: Mission Event Handlers#Ended|"Ended" Mission Event Handler}}
|
| <!-- 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.
|-
|  {{Link|Arma 3: Mission Event Handlers#MPEnded|"MPEnded" Mission Event Handler}}
|
| <!-- 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 01: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.