Skip to content

game

Game private

Extends EventEmitter.

The base game class that bootstraps the entire engine. It acts as a service locator by storing constructor references ("types") for every major subsystem and instantiating them during init().

Properties

PropertyTypeDefaultDescription
optionsGAME_OPTIONS{}Configuration options passed to the constructor.
groupnumber0The party / server group the player belongs to.
networkEntityPoolingnumber \| falsefalsePool size for network entities, or false when pooling is disabled.
modelEntityPoolingobject{}Map of model name → pool size for model entity pooling.

Component Type References

These properties hold constructor references that init() uses to create the corresponding subsystem instances. They can be overridden by subclasses before init() is called.

PropertyDefault TypeDescription
assetManagerTypeAssetManagerAsset loading and caching.
networkTypeBinNetworkAdapterBinary WebSocket network adapter.
rendererTypeRendererRendering pipeline.
inputManagerTypeInputManagerKeyboard / mouse input handling.
inputPacketSchedulerTypeInputPacketSchedulerSchedules outgoing input packets.
inputPacketCreatorTypeInputPacketCreatorBuilds input packets from raw input.
platformTypeWebPlatformPlatform abstraction (Web / FBInstant).
worldTypeWorldGame world and entity management.
debugTypeDebugDebug utilities.
metricsTypeMetricsPerformance and network telemetry.
uiTypeUiUser interface root.

Component Instances

Created during init(). Each one corresponds to a type reference above.

PropertyTypeDescription
assetManagerAssetManagerAsset loading and caching instance.
networkBinNetworkAdapterNetwork adapter instance.
rendererRendererRenderer instance.
inputManagerInputManagerInput manager instance.
inputPacketSchedulerInputPacketSchedulerInput packet scheduler instance.
inputPacketCreatorInputPacketCreatorInput packet creator instance.
platformWebPlatform \| FBInstantPlatformPlatform instance.
worldWorldWorld instance.
debugDebugDebug instance.
metricsMetricsMetrics instance.
uiUiUI instance.

Static Properties

PropertyTypeDescription
Game.currentGameGameSingleton reference to the active game instance. Set in the constructor.

Methods

init()

ts
function init(callback: () => void): void

Bootstraps every subsystem by instantiating all component type references, starts the input pipeline and renderer, initialises the world and platform, then invokes callback (bound to the game instance).

INFO

If options.platform is 'FBInstant', the platform type is swapped to FBInstantPlatform and canvas rendering is forced.

start()

ts
function start(firstTime: boolean): void

Starts (or restarts) the renderer.

stop()

ts
function stop(): void

Stops the renderer.

run()

ts
function run(): void

No-op in the base class. Intended to be overridden by subclasses to begin the game loop.

preload()

ts
function preload(): void

Preloads network entities and model entities through the world instance.

getNetworkEntityPooling()

ts
function getNetworkEntityPooling(): number | false

Returns the current network entity pool size, or false if pooling is disabled.

setNetworkEntityPooling()

ts
function setNetworkEntityPooling(poolSize: number): void

Sets the pool size for network entities.

getModelEntityPooling()

ts
function getModelEntityPooling(modelName?: string): boolean | object

When called with a modelName, returns true / false indicating whether that model has pooling enabled. When called without arguments, returns the entire modelEntityPooling map.

setModelEntityPooling()

ts
function setModelEntityPooling(modelName: string, poolSize: number): void

Registers a pool size for the given model name.

setGroup()

ts
function setGroup(group: number): void

Sets the party / server group.

getGroup()

ts
function getGroup(): number

Returns the current party / server group.

Game/Game public

Extends Game. Class is accessible at window.Game. Game instance is accessible at window.game and window.Game.currentGame.

The game-specific subclass that configures zombs.io on top of the base engine. It overrides the world and renderer types with game-specific implementations, disables culling, and sets up entity pooling for projectile models.

Properties

PropertyTypeDescription
optionsGAME_OPTIONSConfiguration options forwarded from the constructor.
worldTypeGame/WorldOverridden to use the game-specific World class.
rendererTypeGame/RendererOverridden to use the game-specific Renderer class.

INFO

options is a dynamic data that is defined by the website. Its structure is documented in Data Interfaces.

Methods

enablePooling()

ts
function enablePooling(): void

Configures object pooling for the game. Sets the network entity pool to 200 and creates pools of 50 for each projectile model:

ModelPool Size
ProjectileArrowModel50
ProjectileBombModel50
ProjectileCannonModel50
ProjectileMageModel50

Calls preload() afterwards to warm the pools.

INFO

enablePooling() is deferred via _.defer() during construction, meaning they execute after the current call stack has cleared.

disableCulling()

ts
function disableCulling(): void

Disables entity culling. Currently a no-op stub.

INFO

Similar to enablePooling,disableCulling() is deferred via _.defer() during construction.

run()

ts
function run(): void

Calls the parent Game.run() implementation. Is called when the website loads.

Data Interfaces

GAME_OPTIONS

ts
interface GAME_OPTIONS {
    stage: string;
    servers: Record<string, SERVER_DATA>;
    userGroup: number;
}

SERVER_DATA

ts
interface SERVER_DATA = {
    id: string;
    region: string;
    name: string;
    hostname: string;
    ipAddress: string;
    port: number;
    fallbackPort: number;
    selected: boolean;
};