H12: Build the next match's island on a worker thread
When a match's results begin, Match starts the next match's Simulation on a WorkerThreadPool task (its seed is fixed by then) and collects it when the lobby opens. The same task plans the island's tide levels (Simulation.plan_tide) and runs a prepare_next hook, which ServerLoop uses to build the bots' NavGrid and BotWorld for the island. All of these read only the new simulation, so the results are the ones the main thread would have made: tests compare the state hash, terrain, solids, props, tide levels and navigation with fresh ones, and the ten-matches test still matches its references. A Match freed while its task runs waits for it. Measured: a 24-bot server paced in real time through the results, lobby, countdown and 3 s of the next drop has a worst tick of 5.4 ms; it was 1.8 s. In the 24-client soak at 2% loss, moving the island alone left a 0.82 s tick (the bots' navigation) and moving that too left 74 ms at the next match's start (planning the tide), which this also moves. The soak hasn't been run again since that last step. Closes #79 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -89,3 +89,28 @@ func test_server_returns_to_the_lobby_and_starts_the_next_match() -> void:
|
||||
assert_eq(loop.bots.size(), 3, "bots are rebuilt for the new match")
|
||||
assert_eq(loop.player_ids, [1, 2, 3] as Array[int])
|
||||
assert_eq(loop.ticks, 5)
|
||||
|
||||
|
||||
## H12: the next island's bot navigation is made on the worker with the island, and
|
||||
## is the same as navigation made on the main thread.
|
||||
func test_the_next_islands_navigation_is_made_in_the_background() -> void:
|
||||
var rules: MatchRules = MatchRules.new()
|
||||
rules.max_players = 2
|
||||
rules.min_players = 0
|
||||
rules.lobby_ticks = 2
|
||||
rules.countdown_ticks = 2
|
||||
rules.results_ticks = 2
|
||||
rules.fill_with_bots = false
|
||||
var loop: ServerLoop = ServerLoop.new(77, 0, 0, rules)
|
||||
var first: NavGrid = loop.nav
|
||||
while loop.match_flow.phase != Match.RESULTS:
|
||||
loop.run_tick()
|
||||
while loop.match_flow.phase != Match.LOBBY:
|
||||
loop.run_tick()
|
||||
assert_true(loop.nav != first, "new navigation for the new island")
|
||||
assert_true(loop.match_flow.prepared.has("nav"), "made by the worker")
|
||||
var fresh: NavGrid = NavGrid.build(loop.match_flow.sim)
|
||||
assert_true(loop.nav.heights == fresh.heights, "the same heights")
|
||||
assert_true(loop.nav.blocked == fresh.blocked, "the same blocked cells")
|
||||
assert_eq(loop.nav.main_region, fresh.main_region)
|
||||
assert_true(loop.world.walkable == BotWorld.build(loop.match_flow.sim, fresh).walkable)
|
||||
|
||||
Reference in New Issue
Block a user