feat: simulation speed control with bracket keys
Press [ to slow down, ] to speed up through 6 levels: 0.25x, 0.5x, 1x, 2x, 4x, 10x. Clock delta is multiplied by the current speed, so time_of_day advances proportionally and the visual day-night cycle stays synced. Current speed shown in the village panel header. 10x makes a full day cycle watchable in ~24 seconds. Speed changes are non-destructive to simulation determinism.
This commit is contained in:
@@ -31,6 +31,9 @@ var latest_decisions: Dictionary = {}
|
||||
var action_selector := ActionSelectionSystem.new()
|
||||
var action_executor := ActionExecutionSystem.new()
|
||||
var target_resolver := ActionTargetResolver.new()
|
||||
var speed_index := 2
|
||||
const SPEED_LEVELS := [0.25, 0.5, 1.0, 2.0, 4.0, 10.0]
|
||||
signal speed_changed(multiplier: float)
|
||||
|
||||
var names := ["Amina", "Tarik", "Jasmin", "Elma", "Mirza", "Lejla"]
|
||||
|
||||
@@ -58,11 +61,26 @@ func _ready() -> void:
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
var ticks_due := clock.advance(delta)
|
||||
var ticks_due := clock.advance(delta * SPEED_LEVELS[speed_index])
|
||||
for tick in ticks_due:
|
||||
simulate_tick()
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if not event is InputEventKey or not event.pressed or event.echo:
|
||||
return
|
||||
if event.keycode == KEY_BRACKETLEFT:
|
||||
speed_index = maxi(speed_index - 1, 0)
|
||||
speed_changed.emit(SPEED_LEVELS[speed_index])
|
||||
if debug_logs:
|
||||
print("[SimulationManager] Speed: %.2fx" % SPEED_LEVELS[speed_index])
|
||||
elif event.keycode == KEY_BRACKETRIGHT:
|
||||
speed_index = mini(speed_index + 1, SPEED_LEVELS.size() - 1)
|
||||
speed_changed.emit(SPEED_LEVELS[speed_index])
|
||||
if debug_logs:
|
||||
print("[SimulationManager] Speed: %.2fx" % SPEED_LEVELS[speed_index])
|
||||
|
||||
|
||||
func generate_npcs() -> void:
|
||||
var profession_ids := SimulationDefinitions.get_profession_ids()
|
||||
for i in range(names.size()):
|
||||
@@ -568,6 +586,10 @@ func get_recent_events(max_count: int = 5) -> Array[EconomicEventRecord]:
|
||||
return results
|
||||
|
||||
|
||||
func get_current_speed() -> String:
|
||||
return "%.2fx" % SPEED_LEVELS[speed_index]
|
||||
|
||||
|
||||
func _initialize_storage() -> void:
|
||||
if not storage_states.has(SimulationIds.STORAGE_VILLAGE_PANTRY):
|
||||
storage_states[SimulationIds.STORAGE_VILLAGE_PANTRY] = (StorageStateRecord.create(
|
||||
|
||||
Reference in New Issue
Block a user