M1: Match state machine
Match (src/sim/match.gd) runs a server's matches back to back: lobby, countdown, drop, play and results, then a fresh island and the lobby again. It is stepped once per server tick and has no scene-tree or clock dependency. - MatchRules holds max and min players, team size, the lobby, countdown and results timers (defaults in Tuning.MATCH_*) and whether bots fill empty places. - Participants are server-chosen handles. Joining during a match waits for the next; leaving during the drop or play places the leaver as eliminated. - Placements, winners (last team standing) and events for phase changes, joins, leaves, places, match start and end. - Match 0 uses the server's seed; later matches derive their seed from it and their index. The next match's Simulation is built when the lobby opens. - ServerLoop now drives a Match (immediate rules by default, so the smoke match is unchanged: same state hash), rebuilds bots each match, and counts server ticks across matches. The headless server logs match events. Tests: test_match (13) covers every transition, leaving in each phase, an empty lobby, an empty match, teams, late joiners, and ten consecutive matches that each start identical to a freshly built simulation. A ServerLoop test checks the server goes back to the lobby and starts the next match. Closes #24 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -44,6 +44,7 @@ func _ready() -> void:
|
||||
started["engine"] = Engine.get_version_info()["string"]
|
||||
started["tick_rate_hz"] = Tuning.TICK_RATE_HZ
|
||||
started["world_hash"] = loop.sim.island.heightmap_hash()
|
||||
started["match_phase"] = loop.match_flow.phase_name()
|
||||
started["listening"] = false
|
||||
started["note"] = "networking arrives in v0.5; players join as idle slots until then"
|
||||
_log("start", started)
|
||||
@@ -61,10 +62,10 @@ func _process(delta: float) -> void:
|
||||
# Too far behind to catch up: drop the backlog rather than spiral.
|
||||
_accumulator = minf(_accumulator, 1.0 / Tuning.TICK_RATE_HZ)
|
||||
for _index: int in due:
|
||||
if config.ticks > 0 and loop.sim.tick >= config.ticks:
|
||||
if config.ticks > 0 and loop.ticks >= config.ticks:
|
||||
break
|
||||
_tick()
|
||||
if config.ticks > 0 and loop.sim.tick >= config.ticks:
|
||||
if config.ticks > 0 and loop.ticks >= config.ticks:
|
||||
_finish(0)
|
||||
|
||||
|
||||
@@ -75,12 +76,15 @@ func _exit_tree() -> void:
|
||||
|
||||
|
||||
func _tick() -> void:
|
||||
if config.fault == "script-error" and loop.sim.tick == FAULT_TICK:
|
||||
if config.fault == "script-error" and loop.ticks == FAULT_TICK:
|
||||
_deliberate_script_error()
|
||||
loop.run_tick()
|
||||
if config.log_every > 0 and loop.sim.tick % config.log_every == 0:
|
||||
for event: Dictionary in loop.match_flow.events:
|
||||
if event["type"] in ["phase", "match_started", "match_ended"]:
|
||||
_log("match", event)
|
||||
if config.log_every > 0 and loop.ticks % config.log_every == 0:
|
||||
var stats: Dictionary = loop.timing_stats()
|
||||
_log("progress", {"tick": loop.sim.tick, "p95_us": stats["p95_us"], "max_us": stats["max_us"]})
|
||||
_log("progress", {"tick": loop.ticks, "p95_us": stats["p95_us"], "max_us": stats["max_us"]})
|
||||
|
||||
|
||||
func _finish(requested_code: int) -> void:
|
||||
@@ -113,7 +117,7 @@ func _log(event: String, fields: Dictionary) -> void:
|
||||
"seed": config.match_seed,
|
||||
}
|
||||
if loop != null:
|
||||
record["tick"] = loop.sim.tick
|
||||
record["tick"] = loop.ticks
|
||||
record.merge(fields, false)
|
||||
print(JSON.stringify(record))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user