Avorion Wiki
Explore
Main Page
All Pages
Interactive Maps
navigation
Main page
Community portal
Recent changes
Random page
Admin noticeboard
Avorion Community
Official forum
Discord
Twitter
Reddit
Facebook
Steam
Gamepedia
Gamepedia support
Report a bad ad
Help Wiki
Contact us
FANDOM
Fan Central
BETA
Games
Anime
Movies
TV
Video
Wikis
Explore Wikis
Community Central
Start a Wiki
Don't have an account?
Register
Sign In
Sign In
Register
Avorion Wiki
356
pages
Explore
Main Page
All Pages
Interactive Maps
navigation
Main page
Community portal
Recent changes
Random page
Admin noticeboard
Avorion Community
Official forum
Discord
Twitter
Reddit
Facebook
Steam
Gamepedia
Gamepedia support
Report a bad ad
Help Wiki
Contact us
Editing
Performance Optimization
(section)
Back to page
Edit
VisualEditor
View history
Talk (0)
Edit Page
Performance Optimization
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Use Predefined Parallel Functions == Avorion provides functionality to have your scripts updated in parallel (instead of one-by-one). This may come in handy, provided your scripts don't have to write-access other entities during their update step. Using these functions * <code>function updateParallelRead(timeStep)</code> * <code>function updateParallelSelf(timeStep)</code> you can have your script be updated in parallel, instead of one after another. '''This only works for the server.''' '''Note:''' See the documentation of these functions in the [[Scripting API]] for more information. The regular execution order for script updates is completely sequential. Scripts can't just be updated in parallel, because of issues like race conditions when accessing other entities. So what Avorion does, is that it call every script update method of every script that needs to be updated one after another, instead of in multiple threads. There are several cases though, where you don't have to access other entities during the update loop (think of a factory script for example, which only needs to access its own entity to read, remove and add cargo). Updates like that could easily be done in parallel. When you define the above functions, Avorion will do additional update steps, where it executes those particular functions in parallel, in 2 phases: # For all entities that have it defined in their scripts, <code>updateParallelRead()</code> is called in parallel. #* Here, all entities have read-access to all entities, but cannot write to themselves or any other entities. This phase is meant for gathering information that can then be used in phase 2. # For all entities that have it defined in their scripts, <code>updateParallelSelf()</code> is called in parallel. #* Here, all entities have read-write-access to themselves, and only themselves. This phase is meant for doing changes to oneself. <source lang="lua"> -- this function is executed one after another for all entities in the sector function MyEntityScript.update(timeStep) ... end -- this function is executed one after another for all entities in the sector function MyEntityScript.updateServer(timeStep) ... end -- this function is executed in parallel together will all other scripts that have it defined -- we have read-only-access to the entire sector function MyEntityScript.updateParallelRead(timeStep) local s = Sector() -- returns nil, we don't have write-access to the sector local s = ReadOnlySector() -- this works local e = Entity() -- returns nil, we don't have write-access to the entity local e = ReadOnlyEntity() -- this works local other = ReadOnlyEntity(someId) -- this also works ... end -- this function is executed in parallel together will all other scripts that have it defined -- we only have access to our own entity, but we have read-write-access function MyEntityScript.updateParallelSelf(timeStep) local s = Sector() -- returns nil, we don't have write- nor read access to the sector local s = ReadOnlySector() -- returns nil, we don't have write- nor read access to the sector local e = Entity() -- this works, we have read-write-access to our own entity local e = ReadOnlyEntity() -- this works as well local other = ReadOnlyEntity(someId) -- returns nil, we don't have any access to any other entities than ourself ... end </source> '''Note:''' Factories are updated like this! Check out the ''data/scripts/entity/merchants/factory.lua'' script for a working example on how this works.
Summary:
Please note that all contributions to the Avorion Wiki are considered to be released under the CC BY-SA 3.0
Cancel
Editing help
(opens in new window)
Follow on IG
TikTok
Join Fan Lab