Class WorldRuntime
Composes world data, editing rules, persistence hooks, and advanced tooling support behind a single gameplay-facing facade.
public sealed class WorldRuntime
- Inheritance
-
WorldRuntime
- Inherited Members
Remarks
Prefer this type as the stable entry point for gameplay code, editor tooling, and hosts. Lower-level runtime services are kept internal so external callers do not accidentally couple themselves to transient engine plumbing.
Constructors
WorldRuntime(WorldData, ContentRegistry)
Creates an in-memory world runtime without persistence options.
public WorldRuntime(WorldData worldData, ContentRegistry contentRegistry)
Parameters
worldDataWorldDataThe world data to own and mutate.
contentRegistryContentRegistryThe content registry used to resolve tile definitions.
WorldRuntime(WorldData, ContentRegistry, WorldRuntimeOptions)
Creates a world runtime with optional persistence and auto-save behavior.
public WorldRuntime(WorldData worldData, ContentRegistry contentRegistry, WorldRuntimeOptions options)
Parameters
worldDataWorldDataThe world data to own and mutate.
contentRegistryContentRegistryThe content registry used to resolve tile definitions.
optionsWorldRuntimeOptionsOptional persistence and auto-save configuration.
Properties
ContentRegistry
Gets the content registry used to resolve tile definitions referenced by the runtime.
public ContentRegistry ContentRegistry { get; }
Property Value
IsPersistenceEnabled
Gets a value indicating whether this runtime is currently backed by persistent world storage.
public bool IsPersistenceEnabled { get; }
Property Value
Options
Gets the runtime options that control persistence and auto-save behavior.
public WorldRuntimeOptions Options { get; }
Property Value
Storage
Gets the storage backend when persistence is enabled.
public WorldStorage Storage { get; }
Property Value
Remarks
This property is available for hosting and diagnostics scenarios. Gameplay code should usually prefer higher-level methods such as SaveWorld() and EnsureChunkLoaded(ChunkCoord).
WorldData
Gets the mutable world data owned by this runtime.
public WorldData WorldData { get; }
Property Value
Methods
BreakTile(WorldTileCoord, TileBreakContext)
Breaks the foreground tile at the supplied coordinate using break semantics and validation rules.
public TileEditResult BreakTile(WorldTileCoord coord, TileBreakContext context)
Parameters
coordWorldTileCoordThe target world-tile coordinate.
contextTileBreakContextBreak metadata and behavior flags.
Returns
- TileEditResult
The outcome of the break attempt.
CanPlaceObject(WorldTileCoord, int, ObjectPlacementContext)
Evaluates whether an object placement would currently succeed.
public bool CanPlaceObject(WorldTileCoord anchorCoord, int objectDefId, ObjectPlacementContext context)
Parameters
anchorCoordWorldTileCoordThe logical object anchor coordinate.
objectDefIdintThe object definition identifier to place.
contextObjectPlacementContextPlacement metadata and behavior flags.
Returns
EnsureActiveAround(WorldTileCoord)
Ensures the active chunk set around the supplied world-tile coordinate.
public void EnsureActiveAround(WorldTileCoord center)
Parameters
centerWorldTileCoordThe world-tile coordinate that should remain centered in the active set.
EnsureChunkLoaded(ChunkCoord)
Ensures that the chunk at the supplied coordinate is available in memory.
public Chunk EnsureChunkLoaded(ChunkCoord coord)
Parameters
coordChunkCoordThe chunk coordinate to load or create.
Returns
- Chunk
The loaded or newly created chunk.
Remarks
This method is intended for hosts, tooling, and controlled world bootstrap flows. Gameplay logic should usually access world state via tile-level APIs such as GetCell(WorldTileCoord, QueryOptions), PlaceTile(WorldTileCoord, ushort, TilePlacementContext), and BreakTile(WorldTileCoord, TileBreakContext).
EnumerateEntities()
Enumerates all active prototype entities.
public IEnumerable<Entity> EnumerateEntities()
Returns
- IEnumerable<Entity>
The active entities.
GetActiveChunks()
Enumerates the currently active chunk coordinates.
public IEnumerable<ChunkCoord> GetActiveChunks()
Returns
- IEnumerable<ChunkCoord>
The active chunk coordinates.
GetCell(WorldTileCoord, QueryOptions)
Resolves a cell at the supplied world-tile coordinate.
public TileCell GetCell(WorldTileCoord coord, QueryOptions options = null)
Parameters
coordWorldTileCoordThe world-tile coordinate to inspect.
optionsQueryOptionsOptional query behavior overrides.
Returns
GetObject(int)
Resolves an object instance by identifier.
public ObjectInstance GetObject(int objectInstanceId)
Parameters
objectInstanceIdintThe object instance identifier to resolve.
Returns
- ObjectInstance
The resolved object instance.
HasBackgroundWall(WorldTileCoord)
Returns whether the supplied coordinate contains a background wall.
public bool HasBackgroundWall(WorldTileCoord coord)
Parameters
coordWorldTileCoordThe world-tile coordinate to inspect.
Returns
Initialize()
Transitions the runtime into the initialized state.
public void Initialize()
IsSolid(WorldTileCoord)
Returns whether the foreground tile at the supplied coordinate is solid.
public bool IsSolid(WorldTileCoord coord)
Parameters
coordWorldTileCoordThe world-tile coordinate to inspect.
Returns
LoadChunk(ChunkCoord)
Loads or creates a chunk and returns detailed source information.
public ChunkLoadResult LoadChunk(ChunkCoord coord)
Parameters
coordChunkCoordThe chunk coordinate to load or create.
Returns
- ChunkLoadResult
The detailed chunk load result.
PlaceObject(WorldTileCoord, int, ObjectPlacementContext)
Places an object instance into the world.
public ObjectPlacementResult PlaceObject(WorldTileCoord anchorCoord, int objectDefId, ObjectPlacementContext context)
Parameters
anchorCoordWorldTileCoordThe logical object anchor coordinate.
objectDefIdintThe object definition identifier to place.
contextObjectPlacementContextPlacement metadata and behavior flags.
Returns
- ObjectPlacementResult
The outcome of the placement attempt.
PlaceTile(WorldTileCoord, ushort, TilePlacementContext)
Places a foreground tile using placement semantics and validation rules.
public TileEditResult PlaceTile(WorldTileCoord coord, ushort tileId, TilePlacementContext context)
Parameters
coordWorldTileCoordThe target world-tile coordinate.
tileIdushortThe non-air tile identifier to place.
contextTilePlacementContextPlacement metadata and behavior flags.
Returns
- TileEditResult
The outcome of the placement attempt.
RemoveBackgroundWall(WorldTileCoord)
Removes the background wall at the supplied coordinate.
public bool RemoveBackgroundWall(WorldTileCoord coord)
Parameters
coordWorldTileCoordThe target world-tile coordinate.
Returns
RemoveForegroundTile(WorldTileCoord)
Removes the foreground tile at the supplied coordinate without break validation.
public TileEditResult RemoveForegroundTile(WorldTileCoord coord)
Parameters
coordWorldTileCoordThe target world-tile coordinate.
Returns
- TileEditResult
The outcome of the removal operation.
RemoveObject(int, bool)
Removes an object instance from the world.
public bool RemoveObject(int objectInstanceId, bool destroyed = true)
Parameters
objectInstanceIdintThe object instance identifier to remove.
destroyedboolWhether the removal should be treated as destruction.
Returns
SaveWorld()
Persists metadata and all save-dirty chunks for the current world.
public int SaveWorld()
Returns
- int
The number of chunk payloads written to storage.
SetBackgroundWall(WorldTileCoord, ushort)
Writes a background wall directly to the world.
public bool SetBackgroundWall(WorldTileCoord coord, ushort wallId)
Parameters
coordWorldTileCoordThe target world-tile coordinate.
wallIdushortThe non-empty wall identifier to write.
Returns
SetForegroundTile(WorldTileCoord, ushort)
Writes a non-air foreground tile directly to the world without placement validation.
public TileEditResult SetForegroundTile(WorldTileCoord coord, ushort tileId)
Parameters
coordWorldTileCoordThe target world-tile coordinate.
tileIdushortThe non-air tile identifier to write.
Returns
- TileEditResult
The outcome of the write operation.
SetPlayerInput(int, float, bool)
Applies movement input to a player entity for the next update.
public void SetPlayerInput(int entityId, float moveAxis, bool jumpRequested)
Parameters
entityIdintThe target player entity identifier.
moveAxisfloatThe horizontal movement axis in the range [-1, 1].
jumpRequestedboolWhether a jump should be attempted.
Shutdown()
Shuts down the runtime and performs final persistence when enabled.
public void Shutdown()
SpawnPlayer(Float2)
Spawns a controllable player prototype at the supplied world position in tile units.
public int SpawnPlayer(Float2 position)
Parameters
positionFloat2The player spawn position in world tile units.
Returns
- int
The created player entity identifier.
Subscribe<TEvent>(Action<TEvent>)
Subscribes to a runtime event stream.
public void Subscribe<TEvent>(Action<TEvent> handler)
Parameters
handlerAction<TEvent>The handler that should receive published events.
Type Parameters
TEventThe event payload type to observe.
TryGetCell(WorldTileCoord, out TileCell, QueryOptions)
Attempts to resolve a cell at the supplied world-tile coordinate.
public bool TryGetCell(WorldTileCoord coord, out TileCell cell, QueryOptions options = null)
Parameters
coordWorldTileCoordThe world-tile coordinate to inspect.
cellTileCellThe resolved cell when available.
optionsQueryOptionsOptional query behavior overrides.
Returns
TryGetEntity(int, out Entity)
Attempts to resolve an entity by identifier.
public bool TryGetEntity(int entityId, out Entity entity)
Parameters
Returns
TryGetLoadedChunk(ChunkCoord, out Chunk)
Attempts to resolve a chunk that is already loaded in memory.
public bool TryGetLoadedChunk(ChunkCoord coord, out Chunk chunk)
Parameters
coordChunkCoordThe chunk coordinate to inspect.
chunkChunkThe loaded chunk when present.
Returns
TryGetObject(int, out ObjectInstance)
Attempts to resolve an object instance by identifier.
public bool TryGetObject(int objectInstanceId, out ObjectInstance instance)
Parameters
objectInstanceIdintThe object instance identifier to resolve.
instanceObjectInstanceThe resolved object instance when present.
Returns
TryGetObjectAt(WorldTileCoord, out ObjectInstance)
Attempts to resolve an object instance occupying a world-tile coordinate.
public bool TryGetObjectAt(WorldTileCoord coord, out ObjectInstance instance)
Parameters
coordWorldTileCoordThe world-tile coordinate to inspect.
instanceObjectInstanceThe resolved object instance when present.
Returns
Unsubscribe<TEvent>(Action<TEvent>)
Unsubscribes a previously registered runtime event handler.
public void Unsubscribe<TEvent>(Action<TEvent> handler)
Parameters
handlerAction<TEvent>The handler to remove.
Type Parameters
TEventThe event payload type to stop observing.
Update(FrameTime)
Advances runtime bookkeeping for the current frame, including auto-save checks.
public void Update(FrameTime frameTime)
Parameters
frameTimeFrameTimeThe frame timing snapshot supplied by the active host.