Skip to content

Commit 62e65ac

Browse files
feat: add excludeStandaloneWagons to optimize performance (TeamOpenIndustry#1576)
1 parent f7d91a2 commit 62e65ac

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

src/main/java/cam72cam/immersiverailroading/Config.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ public static class ConfigDebug {
257257
@Comment("Keep rolling stock loaded even when it is not moving")
258258
public static boolean keepStockLoaded = true;
259259

260+
@Comment("Exclude unattached wagons from chunk loading when keepStockLoaded is true")
261+
public static boolean excludeStandaloneWagons = false;
262+
260263
@Comment( "Print extra chunk loading info" )
261264
public static boolean debugLog = false;
262265

src/main/java/cam72cam/immersiverailroading/entity/EntityCoupleableRollingStock.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public String toString() {
100100
@TagSync
101101
@TagField("hasElectricalPower")
102102
private boolean hasElectricalPower;
103+
private boolean linkedToLocomotive;
103104
private boolean hadElectricalPower = false;
104105
private int gotElectricalPowerTick = -1;
105106

@@ -186,17 +187,23 @@ public void onTick() {
186187

187188
if (this.getTickCount() % 5 == 0) {
188189
hasElectricalPower = false;
189-
this.mapTrain(this, false, stock ->
190-
hasElectricalPower = hasElectricalPower ||
191-
stock instanceof Locomotive && ((Locomotive) stock).providesElectricalPower()
190+
linkedToLocomotive = false;
191+
this.mapTrain(this, false, stock -> {
192+
hasElectricalPower = hasElectricalPower ||
193+
stock instanceof Locomotive && ((Locomotive) stock).providesElectricalPower();
194+
linkedToLocomotive = linkedToLocomotive || stock instanceof Locomotive;
195+
}
192196
);
193197
}
194198

195199
hadElectricalPower = hasElectricalPower();
196200

197201
if (this.getCurrentState() != null && !this.getCurrentState().atRest || ConfigDebug.keepStockLoaded) {
198-
keepLoaded();
199-
}
202+
//Then exclude stocks not linked to any locomotive
203+
if (!ConfigDebug.excludeStandaloneWagons || this.linkedToLocomotive) {
204+
keepLoaded();
205+
}
206+
}
200207

201208
slackFrontPercent = 0;
202209
slackRearPercent = 0;

0 commit comments

Comments
 (0)