One clock for every land: going back to a land catches it up on the time away (like a night's sleep) instead of rewinding to when you left; J3 decided: a server per land with the Valley's as hub, sleep needs everyone in every land

This commit is contained in:
Paul Bailey
2026-11-06 21:57:37 +00:00
parent ad47cd53da
commit b938e045cb
4 changed files with 72 additions and 15 deletions

View File

@@ -446,6 +446,7 @@ func _on_terrain_ready() -> void:
if not state.is_empty():
apply_save(state)
print("[world] loaded '%s'" % Saves.current_id)
catch_up(state.get("catch_up_to", {}))
_arrive(Saves.take_arrival(Saves.current_id))
player.set_physics_process(true)
set_physics_process(true)
@@ -995,6 +996,10 @@ func travel(to: String, arrive: String) -> void:
var there: Dictionary = Saves.load_state(id, to)
if there.is_empty():
there = {"time": here.time} # (a new place: the same day and hour)
else:
# One clock for every land: the one you're going to catches up on the
# time you were away when it loads (catch_up()).
there["catch_up_to"] = here.time
there["player"] = here.player
Saves.save_state(id, there, 0.0, to)
Saves.set_worldlet(id, to, arrive)
@@ -1007,6 +1012,22 @@ func travel(to: String, arrive: String) -> void:
signal travelled(to: String) ## saved and on the way to another worldlet
## Back in a land you've been to before: its clock comes forward to `to`
## ({day, time}, the clock where you've come from), and everything in it
## catches up on the time between, as after a night's sleep (kilns and
## smelters work, fires burn, food goes off, trees and berries grow back).
## Returns the seconds caught up.
func catch_up(to: Dictionary) -> float:
if to.is_empty():
return 0.0
var secs: float = ((int(to.get("day", day_night.day)) - day_night.day) \
+ (float(to.get("time", day_night.time)) - day_night.time)) * day_night.day_length
if secs <= 0.0:
return 0.0
skip_time(secs)
print("[world] %s caught up on %.0f s while you were away" % [worldlet_id(), secs])
return secs
## Just arrived from another worldlet: put you where you came in.
func _arrive(at: String) -> void:
if at.is_empty():