World Management
BaseWorld
BaseWorld is the container for all GameObject instances in the game. It manages the entity update loop and automatic garbage collection.
import { BaseWorld, GameObject } from '@mavonengine/core'
// Accessed via game.world
const world = game.world
Properties
| Property | Type | Description |
|---|---|---|
entities | Map<string, GameObject> | All entities keyed by their ID |
chunkManager | ChunkManager | Spatial partitioning manager |
Adding entities
world.add({
'player-1': myPlayer,
'enemy-1': myEnemy,
})
Entities are keyed by a string ID. Use stable, meaningful IDs (e.g. player connection IDs for networked entities).
Update loop
BaseWorld.update(delta) is called automatically by BaseGame. It:
- Calls
update(delta)on every entity inentities - Removes any entity with
garbageCollect === true
Garbage collection
To remove an entity, set its garbageCollect flag:
myEntity.garbageCollect = true
// Entity will be removed on the next world update
Or call destroy() directly for immediate cleanup:
myEntity.destroy()
ChunkManager
ChunkManager provides spatial partitioning to efficiently manage a large world. It divides the world into Chunk regions.
// Accessed via world.chunkManager
const chunks = world.chunkManager
Properties
| Property | Type | Description |
|---|---|---|
loadedChunks | Map<string, Chunk> | Currently loaded chunks |
Chunk
Each Chunk represents a spatial region of the world. Chunks are loaded and unloaded as needed based on player proximity (streaming).
ServerWorld
For multiplayer projects, ServerWorld extends BaseWorld with player/client management. See Networking — Server for details.