Refactored parameter updates for use by all machines (wip)
This commit is contained in:
parent
6bf0b4c758
commit
91d5d3850b
2 changed files with 26 additions and 21 deletions
|
@ -24,8 +24,6 @@ public abstract class TileEntityAbstractEnergyCoreOrController extends TileEntit
|
|||
public UUID uuid = null;
|
||||
|
||||
// computed properties
|
||||
private boolean isDirtyParameters = true;
|
||||
private int tickUpdateParameters = 0;
|
||||
private boolean isDirtyGlobalRegion = true;
|
||||
private int tickUpdateGlobalRegion = 0;
|
||||
|
||||
|
@ -45,19 +43,6 @@ public abstract class TileEntityAbstractEnergyCoreOrController extends TileEntit
|
|||
return;
|
||||
}
|
||||
|
||||
// update operational parameters when dirty or periodically to recover whatever may have desynchronized them
|
||||
if (isDirtyParameters) {
|
||||
tickUpdateParameters = 0;
|
||||
}
|
||||
tickUpdateParameters--;
|
||||
if (tickUpdateParameters <= 0) {
|
||||
tickUpdateParameters = WarpDriveConfig.G_PARAMETERS_UPDATE_INTERVAL_TICKS;
|
||||
final boolean isDirty = isDirtyParameters;
|
||||
isDirtyParameters = false;
|
||||
|
||||
doUpdateParameters(isDirty);
|
||||
}
|
||||
|
||||
// update registration upon request or periodically to recover whatever may have desynchronized it
|
||||
if (this instanceof IGlobalRegionProvider) {
|
||||
if (isDirtyGlobalRegion) {
|
||||
|
@ -74,12 +59,6 @@ public abstract class TileEntityAbstractEnergyCoreOrController extends TileEntit
|
|||
}
|
||||
}
|
||||
|
||||
protected void markDirtyParameters() {
|
||||
isDirtyParameters = true;
|
||||
}
|
||||
|
||||
protected abstract void doUpdateParameters(final boolean isDirty);
|
||||
|
||||
protected void markDirtyGlobalRegion() {
|
||||
assert this instanceof IGlobalRegionProvider;
|
||||
isDirtyGlobalRegion = true;
|
||||
|
|
|
@ -36,6 +36,9 @@ public abstract class TileEntityAbstractMachine extends TileEntityAbstractInterf
|
|||
protected boolean isAssemblyValid = true;
|
||||
protected WarpDriveText textValidityIssues = VALIDITY_ISSUES_UNKNOWN;
|
||||
|
||||
private boolean isDirtyParameters = true;
|
||||
private int tickUpdateParameters = 0;
|
||||
|
||||
// allow only one computation at a time
|
||||
protected static final AtomicBoolean isGlobalThreadRunning = new AtomicBoolean(false);
|
||||
// computation is ongoing for this specific tile
|
||||
|
@ -57,6 +60,7 @@ public abstract class TileEntityAbstractMachine extends TileEntityAbstractInterf
|
|||
protected void onFirstUpdateTick() {
|
||||
super.onFirstUpdateTick();
|
||||
doScanAssembly(true);
|
||||
doUpdateParameters(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -79,6 +83,20 @@ public abstract class TileEntityAbstractMachine extends TileEntityAbstractInterf
|
|||
|
||||
doScanAssembly(isDirty);
|
||||
}
|
||||
|
||||
// update operational parameters when dirty or periodically to recover whatever may have desynchronized them
|
||||
if (isDirtyParameters) {
|
||||
tickUpdateParameters = 0;
|
||||
}
|
||||
tickUpdateParameters--;
|
||||
if (tickUpdateParameters <= 0) {
|
||||
tickUpdateParameters = WarpDriveConfig.G_PARAMETERS_UPDATE_INTERVAL_TICKS;
|
||||
final boolean isDirty = isDirtyParameters;
|
||||
isDirtyParameters = false;
|
||||
|
||||
doUpdateParameters(isDirty);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean isDirtyAssembly() {
|
||||
|
@ -109,6 +127,14 @@ public abstract class TileEntityAbstractMachine extends TileEntityAbstractInterf
|
|||
return true;
|
||||
}
|
||||
|
||||
protected void markDirtyParameters() {
|
||||
isDirtyParameters = true;
|
||||
}
|
||||
|
||||
protected void doUpdateParameters(final boolean isDirty) {
|
||||
// no operation
|
||||
}
|
||||
|
||||
@Override
|
||||
public WarpDriveText getStatus() {
|
||||
final WarpDriveText textStatus = super.getStatus();
|
||||
|
|
Loading…
Reference in a new issue