⚡ replace polling timers with sorted event queues + action log
Crops, tree seedlings, and tile recovery no longer iterate all entries every frame. Each event stores an absolute gameTime timestamp (growsAt). A sorted priority queue is drained each tick — only due items are touched. WorldState now tracks gameTime (ms); stateManager.advanceTime(delta) increments it each frame. Save version bumped 5→6 with migration. Action log ring buffer (15 entries) added to LocalAdapter; shown in the F3 debug panel under "Last Actions". Closes #36 Closes #37
This commit is contained in:
@@ -46,7 +46,7 @@ export class GameScene extends Phaser.Scene {
|
||||
this.villagerSystem.init(this.resourceSystem, this.farmingSystem)
|
||||
this.treeSeedlingSystem = new TreeSeedlingSystem(this, this.adapter, this.worldSystem)
|
||||
this.foresterZoneSystem = new ForesterZoneSystem(this, this.adapter)
|
||||
this.debugSystem = new DebugSystem(this, this.villagerSystem, this.worldSystem)
|
||||
this.debugSystem = new DebugSystem(this, this.villagerSystem, this.worldSystem, this.adapter)
|
||||
|
||||
this.worldSystem.create()
|
||||
this.renderPersistentObjects()
|
||||
@@ -145,6 +145,9 @@ export class GameScene extends Phaser.Scene {
|
||||
update(_time: number, delta: number): void {
|
||||
if (this.menuOpen) return
|
||||
|
||||
// Advance the in-game clock first so all tick methods see the updated time
|
||||
stateManager.advanceTime(delta)
|
||||
|
||||
this.cameraSystem.update(delta)
|
||||
|
||||
this.resourceSystem.update(delta)
|
||||
@@ -153,8 +156,8 @@ export class GameScene extends Phaser.Scene {
|
||||
this.villagerSystem.update(delta)
|
||||
this.debugSystem.update()
|
||||
|
||||
// Tick tile-recovery timers; refresh canvas for any tiles that reverted to GRASS
|
||||
const recovered = stateManager.tickTileRecovery(delta)
|
||||
// Drain tile-recovery queue; refresh canvas for any tiles that reverted to GRASS
|
||||
const recovered = stateManager.tickTileRecovery()
|
||||
for (const key of recovered) {
|
||||
const [tx, ty] = key.split(',').map(Number)
|
||||
this.worldSystem.refreshTerrainTile(tx, ty, TileType.GRASS)
|
||||
|
||||
Reference in New Issue
Block a user