Object FluidManager

  • All Implemented Interfaces:

    
    public class FluidManager
    
                        

    Fluid networks are organised into 'segments' which is just a set of connected points. Each segment is created at runtime - they are not persisted. When a point is loaded, we initialise it with its own segment, check whether it's connected to any other points, and if so, join all those connected points (and their connected points, and so on) into one segment.

    Example: Imagine we have A------B------C------D A is loaded first, then C, then D. This means that A and C are on their own segment to start with. Then, D is loaded. D sees that C is connected and loaded, so C and D join together into one segment. Then, B loads, and sees that A and C are connected, so A, B, C, and D join together into one segment.

    This may seem convoluted, but it's the best (and only) way that I could find to deal with the utter chaos that is chunk loading/unloading. Other models usually break when you try to modify a partially unloaded fluid network.

    FUTURE OPTIMISATION POINTS:

    • Use disjoint sets data structure to reduce overhead of connecting/disconnecting and getting connected nodes

    • We currently use round-robin for input and output, this would be more efficient to do first-come- first-serve but would also be much less intuitive so probably not a good idea.

    • Currently not asynchronous, I think parts of this can definitely be made asynchronous