User Tools

Site Tools


besiege:modding:blocks

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
besiege:modding:blocks [2018/07/10 14:08]
spaar [Guidelines on writing BlockScripts]
besiege:modding:blocks [2018/07/23 11:48] (current)
spaar [Guidelines on writing BlockScripts]
Line 70: Line 70:
  
 When writing for blocks, especially blocks to be used in multiplayer,​ thinking about what should be executed only where physics are simulated, what should be executed everywhere, and what should only be executed where physics are not simulated is very important. When writing for blocks, especially blocks to be used in multiplayer,​ thinking about what should be executed only where physics are simulated, what should be executed everywhere, and what should only be executed where physics are not simulated is very important.
 +
 +In singleplayer,​ there is of course only one game instance that always handles physics. This can be treated as a "​host"​ instance.
 +
 +In multiplayer,​ generally the host simulates physics while all other instances (clients) do not. The only exception is when a client is in local sim. Then, for the purposes of that machine, that client is the host, while the regular host and all other clients act as clients.
  
 As such, ''​BlockScript''​ provides methods to differentiate between updates during building mode and updates during simulation mode. Simulate updates are also differentiated between updates on the instance simulating physics for that block and all other instances in MP, as well as an update method that is called on all instances. This leads to the following methods: As such, ''​BlockScript''​ provides methods to differentiate between updates during building mode and updates during simulation mode. Simulate updates are also differentiated between updates on the instance simulating physics for that block and all other instances in MP, as well as an update method that is called on all instances. This leads to the following methods:
  
   * ''​BuildingUpdate'':​ Called every ''​Update()''​ during build mode, on all instances.   * ''​BuildingUpdate'':​ Called every ''​Update()''​ during build mode, on all instances.
-  * ''​SimulateUpdateLocalPhysics'':​ Called every ''​Update()''​ during simulation mode, on the instance simulating physics for this block. +  * ''​SimulateUpdateHost'':​ Called every ''​Update()''​ during simulation mode, on the instance simulating physics for this block. 
-  * ''​SimulateUpdateRemotePhysics'':​ Called every ''​Update()''​ during simulation mode, on all instances except the one simulating physics for this block.+  * ''​SimulateUpdateClient'':​ Called every ''​Update()''​ during simulation mode, on all instances except the one simulating physics for this block.
   * ''​SimulateUpdateAlways'':​ Called every ''​Update()''​ during simulation mode, on all instances.   * ''​SimulateUpdateAlways'':​ Called every ''​Update()''​ during simulation mode, on all instances.
  
-Or, as a table: +All of these functions also have ''​FixedUpdate''​ and ''​LateUpdate'' ​versions.
- +
-^ Play Mode                       ^ Building ​      ^^ Simulation ​   ^^ +
-^ Physics ​                        ^ Local ^ Remote ^ Local ^ Remote ^ +
-| ''​BuildingUpdate'' ​             |  ✓    |  ✓     ​| ​ X    |  X    | +
-| ''​SimulateUpdateLocalPhysics'' ​ |  X    |  X     ​| ​ ✓    |  X    | +
-| ''​SimulateUpdateRemotePhysics''​ |  X    |  X     ​| ​ X     ​| ​ ✓   | +
-| ''​SimulateUpdateAlways'' ​       |  X    |  X     ​| ​ ✓    |   ​✓ ​  | +
- +
-All of these functions also have ''​FixedUpdate''​ and ''​LateUpdate'' ​overloads. +
- +
-Note: For simplicity, "the instance simulating physics"​ can often be thought of as "the host", and all other instances as "the clients"​. However it is important to keep in mind that this isn't strictly true, mainly because of local simulation. Thinking about it in terms of "local vs. remote physics"​ also automatically handles singleplayer correctly.+
 ===== Skins ===== ===== Skins =====
  
besiege/modding/blocks.txt · Last modified: 2018/07/23 11:48 by spaar