Class SpawnerHost
- Namespace
- FishMMO.Server.Implementation.World.SceneServer.Spawner
- Assembly
- FishMMO.Server.dll
Runs the baked spawners of every world scene instance loaded under one FishNet.Managing.NetworkManager.
public sealed class SpawnerHost
- Inheritance
-
SpawnerHost
- Inherited Members
Remarks
When a scene finishes loading on the server, its SceneSpawnTable is looked up by name and one SpawnerRuntime is created per definition, for that scene instance alone; stacked instances of one scene each get their own. When the scene unloads, its spawners are stopped and dropped.
Started a frame late, on purpose. The scene server's own load handler publishes the instance's difficulty rules — which every NPC reads as it spawns — and unloads scenes whose request has gone away. Both listen to the same FishNet event as this host, in whatever order the systems happened to initialise. Deferring the start to the next update makes the order irrelevant: by then the rules are published, and an orphan is already gone.
And spread over frames. Starting a spawner prewarms its pool and spawns its initial population — instantiation, a ground cast, a NavMesh warp and a network spawn per object — and a scene used to start every spawner it has on one frame: three hundred spawners with three initial spawns each is nine hundred spawns and the prewarm behind them. Starts now draw on StartWorkPerFrame, a budget of objects made per frame, scene after scene in the order they loaded. A scene enters the respawn schedule only once every one of its spawners has started, so a respawn condition naming a sibling never sees that sibling before its initial population exists — which starting them all on one frame used to guarantee by accident.
A plain class rather than a server behaviour so tests and simulations can run it on a bare FishNet server; SpawnerSystem is the production wrapper.
Constructors
SpawnerHost(NetworkManager, SpawnTableCatalogue)
Creates a host. Nothing happens until Start().
public SpawnerHost(NetworkManager networkManager, SpawnTableCatalogue catalogue)
Parameters
networkManagerNetworkManagerThe server's network manager.
catalogueSpawnTableCatalogueEvery world scene's baked spawn table.
Fields
DefaultStartWorkPerFrame
Default for StartWorkPerFrame.
public const int DefaultStartWorkPerFrame = 32
Field Value
Properties
Catalogue
Every world scene's baked spawn table.
public SpawnTableCatalogue Catalogue { get; set; }
Property Value
NetworkManager
The network manager whose scenes this host populates.
public NetworkManager NetworkManager { get; }
Property Value
- NetworkManager
Running
public bool Running { get; }
Property Value
SceneCount
Number of scene instances with running spawners. Diagnostics.
public int SceneCount { get; }
Property Value
Scheduler
The scheduler that drives every spawner this host runs.
public SpawnerScheduler Scheduler { get; }
Property Value
StartWorkPerFrame
Objects spawner starts may make per frame: pooled instances the prewarm creates plus initial spawns, plus one per spawner.
public int StartWorkPerFrame { get; set; }
Property Value
Remarks
A token bucket. Each frame adds this much, up to this much; each start spends what it actually did, which can take the balance below zero — one spawner's start is never cut in half — and the frames after it start nothing until the debt is paid.
It cannot starve a scene. The debt a start can run up is bounded by that one spawner's own prewarm and initial count, the balance recovers by this much every frame, and whenever it is positive the next spawner in load order starts. Every queued spawner therefore starts within a bounded number of frames, and every queued scene enters the schedule. Respawns have their own budget (SpawnsPerFrame), so a run of scene loads cannot hold them up either, nor they the loads. At least 1.
StartingSceneCount
Number of scene instances whose spawners are still being started. Diagnostics and tests.
public int StartingSceneCount { get; }
Property Value
Methods
Start()
Starts following scene loads and unloads.
public void Start()
StartScene(Scene)
Creates and starts the spawners for one loaded scene instance, from its baked table, all at once.
public IReadOnlyList<SpawnerRuntime> StartScene(Scene scene)
Parameters
sceneSceneThe loaded scene instance.
Returns
- IReadOnlyList<SpawnerRuntime>
The spawners started, or an empty list when the scene has none.
Remarks
For tests, simulations and tools that want a scene populated now. A scene the host sees load through FishNet is started over several frames instead; see the class remarks.
StartScene(Scene, SceneSpawnTable)
Creates and starts the spawners of table in one loaded scene instance,
all at once.
public IReadOnlyList<SpawnerRuntime> StartScene(Scene scene, SceneSpawnTable table)
Parameters
sceneSceneThe loaded scene instance.
tableSceneSpawnTableThe spawners to run in it.
Returns
- IReadOnlyList<SpawnerRuntime>
The spawners started.
Stop()
Stops every spawner and stops following scenes.
public void Stop()
StopScene(SceneHandle)
Stops and drops the spawners of one scene instance.
public void StopScene(SceneHandle sceneHandle)
Parameters
sceneHandleSceneHandleThe unloaded scene's handle.
Tick(double)
Picks up newly loaded scenes, advances their starts within the budget, and runs the respawn sweep. Call once per frame.
public void Tick(double now)
Parameters
TryGetScene(SceneHandle, out IReadOnlyList<SpawnerRuntime>)
The spawners running in a scene instance, if any.
public bool TryGetScene(SceneHandle sceneHandle, out IReadOnlyList<SpawnerRuntime> spawners)
Parameters
sceneHandleSceneHandlespawnersIReadOnlyList<SpawnerRuntime>