Tweaking Block Networks

Marcin Sciesinski

Code ALL the Ages!
Contributor
World
Architecture
Name: BlockNetwork
Summary: Library mod allowing to easily add new mechanisms (mods) that require connecting multiple blocks into structures that need to track which block belong to which networks and how far away are they from other blocks in the same network
Scope: Engine
Current Goal: Provide fast and memory efficient way of tracking networks of blocks, while providing utility methods that allow access to networks' data
Phase: Implementation
Curator: MarcinSc
GitHub Repository: https://github.com/Terasology/BlockNetwork

Details:
Mod operates on two different types of network nodes:
- networking nodes - the back-bone of a network, connects with other neighboring nodes of both types,
- leaf nodes - the purpose the network is created for, connects only to neighboring networking nodes (exception: network can contain exactly two leaf nodes and no networking nodes, if so it is considered to be "degenerated network").

Both networking and leaf nodes define on which side it is connecting to other nodes using byte type. The mapping between directions and the byte value is provided by DirectionsUtil class.

Only one networking node can be defined per block. Any number of leaf nodes can be defined per block, as long as they do not share connecting sides (i.e. leaf node with connection to Top, and another one connecting to Left and Right are allowed in the same block).

Use instructions:
If you wish to create a network of blocks in your mod (electricity, steam in pipes, etc) you should create an instance of BlockNetwork class in your mod. Add/update/remove blocks to it when your blocks are placed, modified or removed. You can register a NetworkTopologyListener class that will notify you of all changes done to your network so you can track any required updates in your mod's internal data.

To do:
  1. Improve removal of networking node in BlockNetwork to check if a network split is required and perform a more efficient split, based on all nodes that are connected to the networking node being removed.
  2. Improve the update of networking and leaf nodes in BlockNetwork, at the moment the implementation uses a naive approach of remove+add.
Planned features:
  1. New type of nodes - satellite nodes - allowing connecting without actually being a neighbor to a block. For example - wireless transfer. The connectivity will be tracked based on connection id, this kind of block will be considered "neighbor" to any block with the same connection id.
 
Last edited by a moderator:
Top