# WE ARE SO FUCKING BACK

This commit is contained in:
Bob 2024-04-04 19:35:03 +02:00
parent 7ab30aa136
commit 3cb6e855a8
2 changed files with 50 additions and 16 deletions

View File

@ -45,10 +45,11 @@ public class Nodespace {
PowerNode node = getNode(world, x, y, z);
if(node != null) {
worlds.get(world).popNode(node);
markNeigbors(world, node);
//markNeigbors(world, node);
}
}
// UNUSED DO NOT TOUCH
/** Grabs all neighbor nodes from the given node's connection points and removes them from the network entirely, forcing a hard reconnect */
private static void markNeigbors(World world, PowerNode node) {
@ -66,21 +67,22 @@ public class Nodespace {
for(Entry<BlockPos, PowerNode> entry : nodes.nodes.entrySet()) {
PowerNode node = entry.getValue();
if(!node.hasValidNet()) {
if(!node.hasValidNet() || node.recentlyChanged) {
checkNodeConnection(world, node);
node.recentlyChanged = false;
}
if(node.hasValidNet()) {
for(BlockPos pos : node.positions) {
/*for(BlockPos pos : node.positions) {
NBTTagCompound data = new NBTTagCompound();
data.setString("type", "marker");
data.setInteger("color", 0x00ff00);
data.setInteger("color", node.net.hashCode() % 0xffffff);
data.setInteger("expires", 250);
data.setDouble("dist", 15D);
data.setString("label", "" + node.net.hashCode());
data.setDouble("dist", 50D);
data.setString("label", "" + node.net.links.size());
PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(data, pos.getX(), pos.getY(), pos.getZ()), new TargetPoint(world.provider.dimensionId, pos.getX(), pos.getY(), pos.getZ(), 50));
}
}*/
}
}
}
@ -115,7 +117,11 @@ public class Nodespace {
private static void connectToNode(PowerNode origin, PowerNode connection) {
if(origin.hasValidNet() && connection.hasValidNet()) { // both nodes have nets, but the nets are different (previous assumption), join networks
origin.net.joinNetworks(connection.net);
if(origin.net.links.size() > connection.net.links.size()) {
origin.net.joinNetworks(connection.net);
} else {
connection.net.joinNetworks(origin.net);
}
} else if(!origin.hasValidNet() && connection.hasValidNet()) { // origin has no net, connection does, have origin join connection's net
connection.net.joinLink(origin);
} else if(origin.hasValidNet() && !connection.hasValidNet()) { // ...and vice versa
@ -158,6 +164,18 @@ public class Nodespace {
public DirPos[] connections;
public PowerNetMK2 net;
public boolean expired = false;
/**
* Okay so here's the deal: The code has shit idiot brain fungus. I don't know why. I re-tested every part involved several times.
* I don't know why. But for some reason, during neighbor checks, on certain arbitrary fucking places, the joining operation just fails.
* Disallowing nodes to create new networks fixed the problem completely, which is hardly surprising since they wouldn't be able to make
* a new net anyway and they will re-check neighbors until a net is found, so the solution is tautological in nature. So I tried limiting
* creation of new networks. Didn't work. So what's there left to do? Hand out a mark to any node that has changed networks, and let those
* recently modified nodes do another re-check. This creates a second layer of redundant operations, and in theory doubles (in practice,
* it might be an extra 20% due to break-off section sizes) the amount of CPU time needed for re-building the networks after joining or
* breaking, but it seems to allow those parts to connect back to their neighbor nets as they are supposed to. I am not proud of this solution,
* this issue shouldn't exist to begin with and I am going fucking insane but it is what it is.
*/
public boolean recentlyChanged = true;
public PowerNode(BlockPos... positions) {
this.positions = positions;
@ -171,5 +189,10 @@ public class Nodespace {
public boolean hasValidNet() {
return this.net != null && this.net.isValid();
}
public void setNet(PowerNetMK2 net) {
this.net = net;
this.recentlyChanged = true;
}
}
}

View File

@ -1,19 +1,21 @@
package api.hbm.energymk2;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import api.hbm.energymk2.Nodespace.PowerNode;
public class PowerNetMK2 {
private boolean valid = true;
private Set<PowerNode> links = new HashSet();
public boolean valid = true;
public Set<PowerNode> links = new HashSet();
/** Maps all active subscribers to a timestamp, handy for handling timeouts. In a good system this shouldn't be necessary, but the previous system taught me to be cautious anyway */
private HashMap<IEnergyReceiverMK2, Long> receiverEntries = new HashMap();
private HashMap<IEnergyProviderMK2, Long> providerEntries = new HashMap();
public HashMap<IEnergyReceiverMK2, Long> receiverEntries = new HashMap();
public HashMap<IEnergyProviderMK2, Long> providerEntries = new HashMap();
public PowerNetMK2() {
Nodespace.activePowerNets.add(this);
@ -52,7 +54,10 @@ public class PowerNetMK2 {
if(network == this) return; //wtf?!
for(PowerNode conductor : network.links) joinLink(conductor);
List<PowerNode> oldNodes = new ArrayList(network.links.size());
oldNodes.addAll(network.links); // might prevent oddities related to joining - nvm it does nothing
for(PowerNode conductor : oldNodes) forceJoinLink(conductor);
network.links.clear();
for(IEnergyReceiverMK2 connector : network.receiverEntries.keySet()) this.addReceiver(connector);
@ -63,13 +68,19 @@ public class PowerNetMK2 {
/** Adds the power node as part of this network's links */
public PowerNetMK2 joinLink(PowerNode node) {
if(node.net != null) node.net.leaveLink(node);
node.net = this;
return forceJoinLink(node);
}
/** Adds the power node as part of this network's links, skips the part about removing it from existing networks */
public PowerNetMK2 forceJoinLink(PowerNode node) {
this.links.add(node);
node.setNet(this);
return this;
}
/** Removes the specified power node */
public void leaveLink(PowerNode node) {
node.net = null;
node.setNet(null);
this.links.remove(node);
}
@ -85,7 +96,7 @@ public class PowerNetMK2 {
public void destroy() {
this.invalidate();
for(PowerNode link : this.links) if(link.net == this) link.net = null;
for(PowerNode link : this.links) if(link.net == this) link.setNet(null);
this.links.clear();
this.receiverEntries.clear();
this.providerEntries.clear();