Core Concepts

World Management

BaseWorld and ChunkManager manage entities and spatial partitioning.

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

PropertyTypeDescription
entitiesMap<string, GameObject>All entities keyed by their ID
chunkManagerChunkManagerSpatial 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:

  1. Calls update(delta) on every entity in entities
  2. 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

PropertyTypeDescription
loadedChunksMap<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.