Batch block updates

Linus

Member
Contributor
Currently, the available WorldProvider interfaces only allow blocks to be updated one by one.
The WorldProviderCoreImpl class has two setBlocks functions for batch updates, but these haven't been implemented yet.

Updating blocks one by one led to performance issues with the CA Liquid system. The CA Liquid system commonly updates a large number of blocks in a small area. With the normal setBlock function, Terasology will place a block, recalculate lighting, place another block, recalculate lighting etc.

I solved this issue with a hacky batch block updates that just ignores lighting altogether. This decreased the CA update times by a lot (factor 100 IIRC).

A proper implementation that runs the lighting update once, after all blocks have been placed would of course be preferred, but I ran into a few problems with this.

When a set of block updates is provided to the system:
  • what should happen if one of the updates fails?
    • Just continue with and return failed updates?
    • Stop further updates and return failed + remaining updates?
    • Revert all changes made and return false.
  • how would you tell the lighting system to update a set of blocks/region?
Can anyone help me out with these batch update functions? Also, can we have these in the official dev branch maybe? :D


I also would like to propose general setData functions to accompany the setBlock, setLiquid and setLight functions. These setData functions would take an extra argument to specify to which data layer the data will be written. My guess is that this would make it easier to implement the batch updates for all layers and would also pave a way for additional (mod specific) data layers in the future.
 

Immortius

Lead Software Architect
Contributor
Architecture
GUI
The way I would implement those methods is:
1. Obtain a view of the involved chunks.
2. Lock it.
3. Check whether all changes are valid. If not, abort.
4. Apply changes
5. Run a recalcLighting method for the modified Region3i the wipes existing lighting in that area and recalculates it. This method probably needs to be created.

A complication is the batch updates need to integrate correctly with the Block entity system.
An alternative to those methods would be making a view available for the same purpose.
 
Top