fix(client): address PR #78 review comments
- Widen world_seed entropy from u32 to full u64 by combining two randi() calls (Hoshe warning #1) - Persist world_seed to save directory and restore on resume_game() so loaded sessions maintain D-010 deterministic replay (Tyre warning #2) - Constrain EntanglementConfig intrigue range based on flat value so mundane_ratio stays within D-029 spec [45,55]% (both reviewers) - Remove dead VIS_PERIPHERAL constant and _grow_bounds() method - Update test_client_p1 peripheral test for forward-only simplification - Fix misleading exp_fade shader comment (filter_nearest = hard step) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -33,16 +33,23 @@ func new_game() -> String:
|
||||
GameState.current_game_id = game_id
|
||||
|
||||
# #175: Generate world_seed for deterministic simulation (D-010, D-029).
|
||||
# Uses randi() (u32) for a seed that maps cleanly to Rust u64 via MessagePack.
|
||||
# 4 billion seeds is sufficient entropy for EntanglementConfig variation (D-029).
|
||||
GameState.world_seed = rng.randi()
|
||||
# Combines two randi() calls (u32 each) into full u64 entropy range.
|
||||
# Without this, upper 32 bits are always zero — halving the seed space.
|
||||
GameState.world_seed = (rng.randi() << 32) | rng.randi()
|
||||
|
||||
# Persist world_seed to save directory so resume_game() can restore it.
|
||||
# Without this, loaded sessions would send seed=0, breaking D-010 determinism.
|
||||
_write_seed_file(save_path, GameState.world_seed)
|
||||
|
||||
return game_id
|
||||
|
||||
|
||||
## Resume an existing game session by setting the active game-id.
|
||||
## Restores world_seed from the save directory for D-010 deterministic replay.
|
||||
func resume_game(game_id: String) -> void:
|
||||
GameState.current_game_id = game_id
|
||||
var save_path := SAVES_DIR + game_id + "/"
|
||||
GameState.world_seed = _read_seed_file(save_path)
|
||||
|
||||
|
||||
## List all game directories under user://saves/ sorted by last-modified (most recent first).
|
||||
@@ -117,6 +124,24 @@ func _cleanup_quit_dialog() -> void:
|
||||
_quit_dialog = null
|
||||
|
||||
|
||||
## Write world_seed to a file in the save directory for session persistence.
|
||||
func _write_seed_file(save_path: String, seed: int) -> void:
|
||||
var file := FileAccess.open(save_path + "world_seed", FileAccess.WRITE)
|
||||
if file == null:
|
||||
push_error("SessionManager: failed to write seed file: %s" % error_string(FileAccess.get_open_error()))
|
||||
return
|
||||
file.store_64(seed)
|
||||
|
||||
|
||||
## Read world_seed from save directory. Returns 0 if file missing (legacy saves).
|
||||
func _read_seed_file(save_path: String) -> int:
|
||||
var file := FileAccess.open(save_path + "world_seed", FileAccess.READ)
|
||||
if file == null:
|
||||
push_warning("SessionManager: no seed file in %s — using seed=0 (legacy save)" % save_path)
|
||||
return 0
|
||||
return file.get_64()
|
||||
|
||||
|
||||
func _find_newest_save(dir_path: String) -> String:
|
||||
var dir := DirAccess.open(dir_path)
|
||||
if dir == null:
|
||||
|
||||
Reference in New Issue
Block a user