perf: creative node verifies its registration instead of trusting it forever
#29 registered the location once. The old per-tick rewrite also repaired the shared TileNode.locations map when another mod cleared or altered it. One lookup and four int compares per tick restore that: generateId runs again as soon as the entry is missing or different. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
1 parent
206d7579ae
commit
0ae97629e3
2 files changed
+55
-1
No files matched your search
@@ -45,12 +45,33 @@ public class TileCreativeNode extends TileVisNode implements INode, IWandable {
|
||||
|
||||
if(!this.hasUpdatedOnce) {
|
||||
this.hasUpdatedOnce = !this.hasUpdatedOnce;
|
||||
} else if(!this.locationRegistered) {
|
||||
} else if(!this.locationRegistered || !this.isRegistrationIntact()) {
|
||||
this.generateId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* True while the shared location map still holds this node's entry unchanged. The old code rewrote the entry every
|
||||
* tick, which also repaired it after another mod cleared or altered the map; checking it is one lookup and four
|
||||
* int compares, and generateId runs again as soon as the entry is missing or different.
|
||||
*/
|
||||
private boolean isRegistrationIntact() {
|
||||
if(this.id == null || TileNode.locations == null || this.worldObj == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
java.util.List entry = (java.util.List)TileNode.locations.get(this.id);
|
||||
if(entry == null || entry.size() != 4) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Integer.valueOf(this.worldObj.provider.dimensionId).equals(entry.get(0))
|
||||
&& Integer.valueOf(this.xCoord).equals(entry.get(1))
|
||||
&& Integer.valueOf(this.yCoord).equals(entry.get(2))
|
||||
&& Integer.valueOf(this.zCoord).equals(entry.get(3));
|
||||
}
|
||||
|
||||
public void invalidate() {
|
||||
this.unregisterLocation();
|
||||
super.invalidate();
|
||||
|
||||
@@ -71,6 +71,39 @@ public class CreativeNodeRegistryTest {
|
||||
assertNotNull(TileNode.locations.get("0:3:70:5"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aClearedMapIsRepairedOnTheNextTick() {
|
||||
this.node.updateEntity();
|
||||
this.node.updateEntity();
|
||||
assertNotNull(TileNode.locations.get("0:3:70:5"));
|
||||
TileNode.locations.clear(); // another mod or TC4 wipes the shared map
|
||||
this.node.updateEntity();
|
||||
assertNotNull(TileNode.locations.get("0:3:70:5"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anAlteredEntryIsRestoredOnTheNextTick() {
|
||||
this.node.updateEntity();
|
||||
this.node.updateEntity();
|
||||
ArrayList wrong = new ArrayList();
|
||||
wrong.add(Integer.valueOf(9));
|
||||
wrong.add(Integer.valueOf(9));
|
||||
wrong.add(Integer.valueOf(9));
|
||||
wrong.add(Integer.valueOf(9));
|
||||
TileNode.locations.put("0:3:70:5", wrong);
|
||||
this.node.updateEntity();
|
||||
assertEquals(Integer.valueOf(3), TileNode.locations.get("0:3:70:5").get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anIntactEntryIsNotRewritten() {
|
||||
this.node.updateEntity();
|
||||
this.node.updateEntity();
|
||||
ArrayList first = TileNode.locations.get("0:3:70:5");
|
||||
this.node.updateEntity();
|
||||
assertSame(first, TileNode.locations.get("0:3:70:5"));
|
||||
}
|
||||
|
||||
public static class FixtureWorld extends WorldServer {
|
||||
|
||||
FixtureWorld() {
|
||||
|
||||
Reference in new issue
Block a user