perf: harden runtime for weaker hardware
This commit is contained in:
@@ -34,9 +34,12 @@ const NIGHT_LIGHT_ENERGY := 0.3
|
||||
const SUNSET_LIGHT_COLOR := Color(1, 0.55, 0.3, 1)
|
||||
const SUNRISE_LIGHT_COLOR := Color(1, 0.6, 0.45, 1)
|
||||
const SUNRISE_SUNSET_ENERGY := 0.8
|
||||
const PRESENTATION_UPDATE_INTERVAL_SECONDS := 0.1
|
||||
|
||||
var elapsed := 0.0
|
||||
var _simulation_node: Node
|
||||
var _presentation_elapsed := 0.0
|
||||
var _last_applied_cycle := -1.0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -47,17 +50,25 @@ func _ready() -> void:
|
||||
_apply_environment(initial_cycle)
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
func _process(delta: float) -> void:
|
||||
_presentation_elapsed += delta
|
||||
if _presentation_elapsed < PRESENTATION_UPDATE_INTERVAL_SECONDS:
|
||||
return
|
||||
var update_delta := _presentation_elapsed
|
||||
_presentation_elapsed = 0.0
|
||||
if _simulation_node == null or not is_instance_valid(_simulation_node):
|
||||
_find_simulation_node()
|
||||
var cycle: float
|
||||
if _simulation_node != null and "clock" in _simulation_node and _simulation_node.clock != null:
|
||||
cycle = _simulation_node.clock.time_of_day()
|
||||
else:
|
||||
elapsed += _delta
|
||||
elapsed += update_delta
|
||||
if elapsed >= cycle_duration_seconds:
|
||||
elapsed = fmod(elapsed, cycle_duration_seconds)
|
||||
cycle = elapsed / cycle_duration_seconds
|
||||
if is_equal_approx(cycle, _last_applied_cycle):
|
||||
return
|
||||
_last_applied_cycle = cycle
|
||||
_apply_light_rotation(cycle)
|
||||
_apply_environment(cycle)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user