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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final class
FluidManager.FluidSupplyInfo
-
Field Summary
Fields Modifier and Type Field Description public final static FluidManager
INSTANCE
-
Method Summary
Modifier and Type Method Description final static VirtualFluidPoint
getById(UUID uuid)
final static Unit
add(VirtualFluidPoint point)
Call when creating a new connection point, or when one has been loaded final static Unit
remove(VirtualFluidPoint point)
Call when removing a connection point. final static Unit
unload(VirtualFluidPoint point)
Removes a connection point from the cache, but keeps its connection information intact. final static Unit
setFluidPerSecond(UUID segment, Double fluidPerSecond)
Sets the flow rate per tick for a segment. final static Double
getFluidPerSecond(UUID segment)
final static Unit
setFluidPredicate(UUID segment, Predicate<PylonFluid> predicate)
Sets the fluid predicate for a segment. final static Predicate<PylonFluid>
getFluidPredicate(UUID segment)
final static Unit
connect(VirtualFluidPoint point1, VirtualFluidPoint point2)
Connects two points - and all their connected points - into one segment. final static Unit
disconnect(VirtualFluidPoint point1, VirtualFluidPoint point2)
Disconnects two points, potentially splitting them into two segments if there is no other link between them. final static Set<VirtualFluidPoint>
getAllConnected(VirtualFluidPoint point)
Recursively gets all the points connected to another point that are loaded final static List<VirtualFluidPoint>
getPoints(UUID segment, FluidPointType type)
final static Map<PylonFluid, FluidManager.FluidSupplyInfo>
getSuppliedFluids(UUID segment, Double deltaSeconds)
final Pair<Map<PylonFluidBlock, Double>, Double>
getRequestedFluids(UUID segment, PylonFluid fluid, Double deltaSeconds)
Find how much of the fluid each input point on the block is requesting Ignore input points requesting zero or effectively zero of the fluid -
-
Method Detail
-
getById
final static VirtualFluidPoint getById(UUID uuid)
-
add
final static Unit add(VirtualFluidPoint point)
Call when creating a new connection point, or when one has been loaded
-
remove
final static Unit remove(VirtualFluidPoint point)
Call when removing a connection point. Use unload for when a connection point is unloaded.
-
unload
final static Unit unload(VirtualFluidPoint point)
Removes a connection point from the cache, but keeps its connection information intact.
-
setFluidPerSecond
final static Unit setFluidPerSecond(UUID segment, Double fluidPerSecond)
Sets the flow rate per tick for a segment. The segment will not transfer more fluid than the flow rate per tick.
Preserved across disconnects and connects (when connecting two points, one of the two points being connected is selected, and its segment's flow rate is copied to the new segment).
-
getFluidPerSecond
final static Double getFluidPerSecond(UUID segment)
-
setFluidPredicate
final static Unit setFluidPredicate(UUID segment, Predicate<PylonFluid> predicate)
Sets the fluid predicate for a segment. The segment will only transfer fluids that match the predicate.
Preserved across disconnects and connects (when connecting two points, one of the two points being connected is selected, and its segment's predicate is copied to the new segment).
-
getFluidPredicate
final static Predicate<PylonFluid> getFluidPredicate(UUID segment)
-
connect
final static Unit connect(VirtualFluidPoint point1, VirtualFluidPoint point2)
Connects two points - and all their connected points - into one segment. Preserves the flow rate and predicate of the first point's segment.
-
disconnect
final static Unit disconnect(VirtualFluidPoint point1, VirtualFluidPoint point2)
Disconnects two points, potentially splitting them into two segments if there is no other link between them.
-
getAllConnected
final static Set<VirtualFluidPoint> getAllConnected(VirtualFluidPoint point)
Recursively gets all the points connected to another point that are loaded
-
getPoints
final static List<VirtualFluidPoint> getPoints(UUID segment, FluidPointType type)
-
getSuppliedFluids
final static Map<PylonFluid, FluidManager.FluidSupplyInfo> getSuppliedFluids(UUID segment, Double deltaSeconds)
-
getRequestedFluids
final Pair<Map<PylonFluidBlock, Double>, Double> getRequestedFluids(UUID segment, PylonFluid fluid, Double deltaSeconds)
Find how much of the fluid each input point on the block is requesting Ignore input points requesting zero or effectively zero of the fluid
-
-
-
-