Skip to content

Commit b9b662a

Browse files
authored
Merge pull request #30 from wmioch/codex/investigate-timing-issues-affecting-steam-generation
Fix boiler heat decay timing at high game speeds
2 parents 0d0f1c3 + a795dee commit b9b662a

File tree

8 files changed

+47
-35
lines changed

8 files changed

+47
-35
lines changed

core/src/de/dakror/quarry/structure/Boiler.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,16 @@ public void update(double deltaTime, int gameSpeed, Bounds dirtyBounds) {
167167
}
168168

169169
decay -= deltaTime * gameSpeed;
170-
if (decay <= 0) {
171-
heatLevel = Math.max(0, heatLevel - recipe.heatDecay * gameSpeed);
170+
boolean decayed = false;
171+
while (decay <= 0) {
172+
heatLevel = Math.max(0, heatLevel - recipe.heatDecay);
173+
decay += recipe.heatDecayTime;
174+
decayed = true;
175+
}
176+
177+
if (decayed) {
172178
if (clicked) updateUI();
173179
setItemNotifications();
174-
decay = recipe.heatDecayTime;
175180
}
176181
} else {
177182
pauseSfx();

core/src/de/dakror/quarry/structure/DistillationColumn.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public static class DistillationRecipe {
8787
double powerLevel;
8888
boolean noPower;
8989
final WindowedMean powerLevelMean = new WindowedMean(60);
90-
protected int framesPassedWithPower;
90+
protected float powerUptime;
9191

9292
int level;
9393

@@ -239,10 +239,9 @@ private void updateLevel(DistillationColumn level, double deltaTime, int gameSpe
239239
level.noPower = level.powerLevel < recipe.power;
240240
if (!level.noPower) {
241241
level.powerLevel = Math.max(0, level.powerLevel - recipe.power * 60 * deltaTime * gameSpeed);
242-
level.framesPassedWithPower++;
243-
if (level.framesPassedWithPower > 10) level.framesPassedWithPower = 10;
242+
level.powerUptime = Math.min(POWER_RESTORE_GRACE_SECONDS, level.powerUptime + (float) (deltaTime * gameSpeed));
244243
} else {
245-
level.framesPassedWithPower = 0;
244+
level.powerUptime = 0;
246245
}
247246
} else {
248247
level.noPower = false;
@@ -374,17 +373,17 @@ public void drawFrame(SpriteRenderer spriter, ShapeRenderer shaper, SpriterDeleg
374373

375374
if (level == 0) {
376375
if (workingTime > 0) {
377-
if (framesPassedWithPower < 10) {
376+
if (powerUptime < POWER_RESTORE_GRACE_SECONDS) {
378377
float size = Const.STATE_SIZE * (1 + 0.3f * (MathUtils.sin(time * 2 * MathUtils.PI) * 0.5f + 0.5f));
379378
spriter.add(ProducerStructure.nopowerTex, (x + getWidth()) * Const.TILE_SIZE - (size - Const.STATE_SIZE) / 2 - Const.STATE_SIZE * 1.25f * 2,
380379
(y + getHeight()) * Const.TILE_SIZE - (size - Const.STATE_SIZE) / 2 - Const.STATE_SIZE * 1.25f * 2, Const.Z_STATES, size, size);
381380
}
382-
if (level1 != null && level1.framesPassedWithPower < 10) {
381+
if (level1 != null && level1.powerUptime < POWER_RESTORE_GRACE_SECONDS) {
383382
float size = Const.STATE_SIZE * (1 + 0.3f * (MathUtils.sin(time * 2 * MathUtils.PI) * 0.5f + 0.5f));
384383
spriter.add(ProducerStructure.nopowerTex, (level1.x + getWidth()) * Const.TILE_SIZE - (size - Const.STATE_SIZE) / 2 - Const.STATE_SIZE * 1.25f * 3,
385384
(level1.y + getHeight()) * Const.TILE_SIZE - (size - Const.STATE_SIZE) / 2 - Const.STATE_SIZE * 1.25f, Const.Z_STATES, size, size);
386385
}
387-
if (level2 != null && level2.framesPassedWithPower < 10) {
386+
if (level2 != null && level2.powerUptime < POWER_RESTORE_GRACE_SECONDS) {
388387
float size = Const.STATE_SIZE * (1 + 0.3f * (MathUtils.sin(time * 2 * MathUtils.PI) * 0.5f + 0.5f));
389388
spriter.add(ProducerStructure.nopowerTex, (level2.x + getWidth()) * Const.TILE_SIZE - (size - Const.STATE_SIZE) / 2 - Const.STATE_SIZE * 1.25f * 3,
390389
(level2.y + getHeight()) * Const.TILE_SIZE - (size - Const.STATE_SIZE) / 2 - Const.STATE_SIZE * 1.25f, Const.Z_STATES, size, size);

core/src/de/dakror/quarry/structure/Refinery.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public static class RefineryRecipe {
104104
double powerLevel;
105105
private final WindowedMean powerLevelMean = new WindowedMean(60);
106106
boolean noPower;
107-
protected int framesPassedWithPower;
107+
protected float powerUptime;
108108

109109
Table ui;
110110
Container<Table> container;
@@ -242,7 +242,7 @@ public void drawFrame(SpriteRenderer spriter, ShapeRenderer shaper, SpriterDeleg
242242
shaper.rect(x * Const.TILE_SIZE, y * Const.TILE_SIZE + 10, progress * getWidth() * Const.TILE_SIZE, 8);
243243
}
244244

245-
if ((workingTime0 > 0 || workingTime1 > 0) && framesPassedWithPower < 10) {
245+
if ((workingTime0 > 0 || workingTime1 > 0) && powerUptime < POWER_RESTORE_GRACE_SECONDS) {
246246
float size = Const.STATE_SIZE * (1 + 0.3f * (MathUtils.sin(time * 2 * MathUtils.PI) * 0.5f + 0.5f));
247247
spriter.add(ProducerStructure.nopowerTex, (x + getWidth()) * Const.TILE_SIZE - (size - Const.STATE_SIZE) / 2 - Const.STATE_SIZE * 1.25f * 2,
248248
(y + getHeight()) * Const.TILE_SIZE - (size - Const.STATE_SIZE) / 2 - Const.STATE_SIZE * 1.25f * 2, Const.Z_STATES, size, size);
@@ -295,10 +295,9 @@ public void update(double deltaTime, int gameSpeed, Bounds dirtyBounds) {
295295
noPower = powerLevel < recipe.power;
296296
if (!noPower) {
297297
powerLevel = Math.max(0, powerLevel - recipe.power * 60 * deltaTime * gameSpeed);
298-
framesPassedWithPower++;
299-
if (framesPassedWithPower > 10) framesPassedWithPower = 10;
298+
powerUptime = Math.min(POWER_RESTORE_GRACE_SECONDS, powerUptime + (float) (deltaTime * gameSpeed));
300299
} else {
301-
framesPassedWithPower = 0;
300+
powerUptime = 0;
302301
}
303302
} else {
304303
noPower = false;

core/src/de/dakror/quarry/structure/ShaftDrillHead.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import de.dakror.quarry.structure.base.Schema.Flags;
3333
import de.dakror.quarry.structure.base.Structure;
3434
import de.dakror.quarry.structure.base.StructureType;
35+
import de.dakror.quarry.util.Bounds;
3536
import de.dakror.quarry.util.SpriterDelegateBatch;
3637

3738
/**
@@ -41,6 +42,8 @@ public class ShaftDrillHead extends Structure<Schema> {
4142
public static final Schema classSchema = new Schema(0, StructureType.ShaftDrillHead, true, ShaftDrill.classSchema.width, ShaftDrill.classSchema.height, "", new Items(), null)
4243
.flags(Flags.Indestructible, Flags.TextureAlwaysUpright);
4344

45+
private static final float ROTATION_SPEED_DEG_PER_SEC = 7.5f;
46+
4447
static final TextureRegion core = Quarry.Q.atlas.findRegion("structure_shaft_drill_head");
4548
static final TextureRegion corner = Quarry.Q.atlas.findRegion("structure_shaft_drill_head_outer");
4649

@@ -65,11 +68,16 @@ public ShaftDrill getDrill() {
6568
}
6669

6770
@Override
68-
public void drawFrame(SpriteRenderer spriter, ShapeRenderer shaper, SpriterDelegateBatch pfxBatch) {
69-
if (drill.getActiveRecipe() != null && !drill.isSleeping()) {
70-
rotation = (rotation - 0.125f * gameSpeed) % 360;
71+
public void update(double deltaTime, int gameSpeed, Bounds dirtyBounds) {
72+
super.update(deltaTime, gameSpeed, dirtyBounds);
73+
74+
if (drill != null && drill.getActiveRecipe() != null && !drill.isSleeping() && gameSpeed > 0) {
75+
rotation = (rotation - ROTATION_SPEED_DEG_PER_SEC * (float) (deltaTime * gameSpeed)) % 360;
7176
}
77+
}
7278

79+
@Override
80+
public void drawFrame(SpriteRenderer spriter, ShapeRenderer shaper, SpriterDelegateBatch pfxBatch) {
7381
spriter.add(core, x * Const.TILE_SIZE, y * Const.TILE_SIZE, Const.Z_STRUCTURES, Const.TILE_SIZE * 2, Const.TILE_SIZE * 2, Const.TILE_SIZE * 2, Const.TILE_SIZE * 2, 1, 1, rotation);
7482
spriter.add(core, x * Const.TILE_SIZE, y * Const.TILE_SIZE, Const.Z_STRUCTURES, Const.TILE_SIZE * 2, Const.TILE_SIZE * 2, Const.TILE_SIZE * 2, Const.TILE_SIZE * 2, 1, 1, rotation + 90);
7583
spriter.add(core, x * Const.TILE_SIZE, y * Const.TILE_SIZE, Const.Z_STRUCTURES, Const.TILE_SIZE * 2, Const.TILE_SIZE * 2, Const.TILE_SIZE * 2, Const.TILE_SIZE * 2, 1, 1, rotation + 180);

core/src/de/dakror/quarry/structure/base/ProducerStructure.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public Component[] copyComponents(Structure<?> structure) {
106106
protected final WindowedMean powerLevelMean = new WindowedMean(60);
107107

108108
protected boolean noPower;
109-
protected int framesPassedWithPower;
109+
protected float powerUptime;
110110

111111
protected Container<Actor> ui;
112112
protected Label timeLabel;
@@ -435,10 +435,9 @@ public void update(double deltaTime, int gameSpeed, Bounds dirtyBounds) {
435435
noPower = powerLevel < activeRecipe.getPower() / 2;
436436
if (!noPower) {
437437
powerLevel = Math.max(0, powerLevel - activeRecipe.getPower() * 60 * deltaTime * gameSpeed);
438-
framesPassedWithPower++;
439-
if (framesPassedWithPower > 10) framesPassedWithPower = 10;
438+
powerUptime = Math.min(POWER_RESTORE_GRACE_SECONDS, powerUptime + (float) (deltaTime * gameSpeed));
440439
} else {
441-
framesPassedWithPower = 0;
440+
powerUptime = 0;
442441
}
443442
} else noPower = false;
444443

@@ -485,7 +484,7 @@ public void drawFrame(SpriteRenderer spriter, ShapeRenderer shaper, SpriterDeleg
485484

486485
drawRecipeProgress(shaper);
487486

488-
if (activeRecipe != null && activeRecipe.getPower() > 0 && framesPassedWithPower < 10) {
487+
if (activeRecipe != null && activeRecipe.getPower() > 0 && powerUptime < POWER_RESTORE_GRACE_SECONDS) {
489488
float size = Const.STATE_SIZE * (1 + 0.3f * (MathUtils.sin(time * 2 * MathUtils.PI) * 0.5f + 0.5f));
490489
spriter.add(nopowerTex, (x + getWidth()) * Const.TILE_SIZE - (size - Const.STATE_SIZE) / 2 - Const.STATE_SIZE * 1.25f,
491490
(y + getHeight()) * Const.TILE_SIZE - (size - Const.STATE_SIZE) / 2 - Const.STATE_SIZE * 1.25f * 2, Const.Z_STATES, size, size);

core/src/de/dakror/quarry/structure/base/Structure.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public abstract class Structure<T extends Schema> implements Savable, Region {
7272

7373
public static final Color selectionColor = Color.valueOf("#4286f4a0");
7474

75+
protected static final float POWER_RESTORE_GRACE_SECONDS = 10f / 60f;
76+
7577
protected Booster nearbyBooster;
7678

7779
protected PowerNetwork powerNetwork;

core/src/de/dakror/quarry/structure/logistics/ElectricConveyorCore.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ null, new Dock(0, 0, Direction.South, DockType.Power))
7373
double powerUse;
7474
boolean noPower;
7575
final WindowedMean powerLevelMean = new WindowedMean(60);
76-
protected int framesPassedWithPower;
76+
protected float powerUptime;
7777

7878
final HashSet<Integer> tmp = new HashSet<>();
7979
Array<ElectricConveyor> connectedConveyors = new Array<>();
@@ -217,14 +217,14 @@ public void update(double deltaTime, int gameSpeed, Bounds dirtyBounds) {
217217
noPower = powerLevel < powerUse / 2;
218218
if (!noPower) {
219219
powerLevel = Math.max(0, powerLevel - powerUse * 60 * deltaTime * gameSpeed);
220-
if (framesPassedWithPower == 0) {
220+
boolean regainedPower = powerUptime == 0;
221+
powerUptime = Math.min(POWER_RESTORE_GRACE_SECONDS, powerUptime + (float) (deltaTime * gameSpeed));
222+
if (regainedPower) {
221223
// just regained power
222224
notifyNeighbors(true);
223225
}
224-
framesPassedWithPower++;
225-
if (framesPassedWithPower > 10) framesPassedWithPower = 10;
226226
} else {
227-
framesPassedWithPower = 0;
227+
powerUptime = 0;
228228
}
229229
} else noPower = false;
230230

@@ -268,7 +268,7 @@ public void draw(SpriteRenderer spriter) {
268268
public void drawFrame(SpriteRenderer spriter, ShapeRenderer shaper, SpriterDelegateBatch pfxBatch) {
269269
super.drawFrame(spriter, shaper, pfxBatch);
270270

271-
if (framesPassedWithPower < 10) {
271+
if (powerUptime < POWER_RESTORE_GRACE_SECONDS) {
272272
float size = Const.STATE_SIZE * (1 + 0.3f * (MathUtils.sin(time * 2 * MathUtils.PI) * 0.5f + 0.5f));
273273
spriter.add(ProducerStructure.nopowerTex, (x + getWidth()) * Const.TILE_SIZE - (size - Const.STATE_SIZE) / 2 - Const.STATE_SIZE * 1.25f * 2,
274274
(y + getHeight()) * Const.TILE_SIZE - (size - Const.STATE_SIZE) / 2 - Const.STATE_SIZE * 1.25f * 2, Const.Z_STATES, size, size);

core/src/de/dakror/quarry/structure/storage/DigitalStorage.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public void call(Boolean on, Structure<?> data) {
104104
double powerUse;
105105
boolean noPower;
106106
final WindowedMean powerLevelMean = new WindowedMean(60);
107-
protected int framesPassedWithPower;
107+
protected float powerUptime;
108108

109109
public DigitalStorage(int x, int y) {
110110
super(x, y, classSchema);
@@ -192,16 +192,16 @@ public void update(double deltaTime, int gameSpeed, Bounds dirtyBounds) {
192192
if (!noPower) {
193193
playSfx();
194194
powerLevel = Math.max(0, powerLevel - powerUse * 60 * deltaTime * gameSpeed);
195-
if (framesPassedWithPower == 0) {
195+
boolean regainedPower = powerUptime == 0;
196+
powerUptime = Math.min(POWER_RESTORE_GRACE_SECONDS, powerUptime + (float) (deltaTime * gameSpeed));
197+
if (regainedPower) {
196198
// regained power
197199
setItemNotifications();
198200
}
199-
framesPassedWithPower++;
200-
if (framesPassedWithPower > 10) framesPassedWithPower = 10;
201201
pumping = outputs.size > 0;
202202
} else {
203203
pauseSfx();
204-
framesPassedWithPower = 0;
204+
powerUptime = 0;
205205
pumping = false;
206206
}
207207
} else noPower = false;
@@ -213,7 +213,7 @@ public void update(double deltaTime, int gameSpeed, Bounds dirtyBounds) {
213213
public void drawFrame(SpriteRenderer spriter, ShapeRenderer shaper, SpriterDelegateBatch pfxBatch) {
214214
super.drawFrame(spriter, shaper, pfxBatch);
215215

216-
if (framesPassedWithPower < 10) {
216+
if (powerUptime < POWER_RESTORE_GRACE_SECONDS) {
217217
float size = Const.STATE_SIZE * (1 + 0.3f * (MathUtils.sin(time * 2 * MathUtils.PI) * 0.5f + 0.5f));
218218
spriter.add(ProducerStructure.nopowerTex, (x + getWidth()) * Const.TILE_SIZE - (size - Const.STATE_SIZE) / 2 - Const.STATE_SIZE * 1.25f * 2,
219219
(y + getHeight()) * Const.TILE_SIZE - (size - Const.STATE_SIZE) / 2 - Const.STATE_SIZE * 1.25f * 2, Const.Z_STATES, size, size);

0 commit comments

Comments
 (0)