From 710547a014c377165588a78b0412dad77a75c6fb Mon Sep 17 00:00:00 2001 From: ionut Date: Wed, 29 Apr 2026 21:58:43 +0300 Subject: [PATCH] todo: stuff --- TODO.md | 32 +++++++++++++++++++ .../neocomputers/block/DeviceBlock.kt | 5 +++ .../neocomputers/entity/CableEntity.kt | 3 ++ 3 files changed, 40 insertions(+) diff --git a/TODO.md b/TODO.md index 042b6ef..daa6a19 100644 --- a/TODO.md +++ b/TODO.md @@ -1,3 +1,35 @@ +# Networking +> All that is left is optimization + +## ERADICATE DIRECT + +We only need NONE, SOME and NETWORK. + +## Optimize compute and memory +> OC does this too + +Optimize both *time* and *memory* using graph theory. + +### Requirements + +It obviously must be fast and memory-efficient, and respect the current semantics. + +The current idea is to make NETWORK style nodes the only ones with a cache, +and to instead appoint a connection that is also a NETWORK node, if any, as +the one source of truth, or steal the source. This means only one node +in a local network gets to actually compute the graph layout. +Complications can happen when merges happen, the idea is to pick one source of truth +then as well. + +Also, `onNodeAdded` and `onNodeRemoved` should also be called when a reachable node is added/removed. +This is for perf. We only care about nodes being added/removed then. +This can be done by broadcasting to all of their *connections*, to circumvent the NONE/SOME/NETWORK asymmetric reachability sets. + +## Optimize power balancing + +Use a smarter algorithm to prevent N storage nodes from iterating N^2 nodes each tick +to balance power. + # Computation > Pretty important for a computer mod diff --git a/src/main/kotlin/org/neoflock/neocomputers/block/DeviceBlock.kt b/src/main/kotlin/org/neoflock/neocomputers/block/DeviceBlock.kt index 86c54b4..227d6fd 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/block/DeviceBlock.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/block/DeviceBlock.kt @@ -33,6 +33,7 @@ abstract class DeviceBlockEntity(type: BlockEntityType<*>, pos: BlockPos, state: val connetionsInDir = MutableList(Direction.entries.size) { null } var alreadySetup = false var receivedServerState = false + var connectionsAreDirty = false abstract fun getDeviceNodes(): List @@ -93,6 +94,10 @@ abstract class DeviceBlockEntity(type: BlockEntityType<*>, pos: BlockPos, state: if(!alreadySetup) { initNetworking() } + if(connectionsAreDirty) { + connectionsAreDirty = false + Direction.entries.forEach { handleConnectionsFor(it) } + } } open fun sendCommitsToClient(level: Level) { diff --git a/src/main/kotlin/org/neoflock/neocomputers/entity/CableEntity.kt b/src/main/kotlin/org/neoflock/neocomputers/entity/CableEntity.kt index 53e5c84..3cd4959 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/entity/CableEntity.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/entity/CableEntity.kt @@ -38,6 +38,9 @@ class CableEntity(pos: BlockPos, state: BlockState) : SingleDeviceBlockEntity(Bl for (dir in Direction.entries) { val ent = level!!.getBlockEntity(blockPos.relative(dir)) level!!.setBlockAndUpdate(blockPos, blockState.setValue(getPropByDirection(dir), CableBlock.shouldConnect(blockPos, blockPos.relative(dir), level!!))) + if(ent is CableEntity) { + ent.connectionsAreDirty = true + } } } } \ No newline at end of file