ClientEngine

ClientEngine

The client engine is the singleton which manages the client-side process, starting the game engine, listening to network messages, starting client steps, and handling world updates which arrive from the server. Normally, a game will implement its own sub-class of ClientEngine, and may override the constructor ClientEngine#constructor and the methods ClientEngine#start and ClientEngine#connect

Constructor

new ClientEngine(gameEngine, inputOptions, Renderer)

Create a client engine instance.

Parameters:
Name Type Description
gameEngine GameEngine

a game engine

inputOptions Object

options object

Properties
Name Type Description
verbose Boolean

print logs to console

autoConnect Boolean

if true, the client will automatically attempt connect to server.

standaloneMode Boolean

if true, the client will never try to connect to a server

delayInputCount Number

if set, inputs will be delayed by this many steps before they are actually applied on the client.

healthCheckInterval Number

health check message interval (millisec). Default is 1000.

healthCheckRTTSample Number

health check RTT calculation sample size. Default is 10.

scheduler String

When set to "render-schedule" the game step scheduling is controlled by the renderer and step time is variable. When set to "fixed" the game step is run independently with a fixed step time. Default is "render-schedule".

syncOptions Object

an object describing the synchronization method. If not set, will be set to extrapolate, with local object bending set to 0.0 and remote object bending set to 0.6. If the query-string parameter "sync" is defined, then that value is passed to this object's sync attribute.

Properties
Name Type Description
sync String

chosen sync option, can be "interpolate", "extrapolate", or "frameSync"

localObjBending Number

amount (0 to 1.0) of bending towards original client position, after each sync, for local objects

remoteObjBending Number

amount (0 to 1.0) of bending towards original client position, after each sync, for remote objects

serverURL String

Socket server url

Renderer Renderer

the Renderer class constructor

Source:

Members

gameEngine :GameEngine

reference to game engine

Source:

serializer :Serializer

reference to serializer

Source:

Methods

connect(optionsopt) → {Promise}

Makes a connection to the game server. Extend this method if you want to add additional logic on every connection. Call the super-class connect first, and return a promise which executes when the super-class promise completes.

Parameters:
Name Type Attributes Description
options Object <optional>

additional socket.io options

Source:
Returns:

Resolved when the connection is made to the server

Type
Promise

disconnect()

Disconnect from game server

Source:

sendInput(input, inputOptions)

This function should be called by the client whenever a user input occurs. This function will emit the input event, forward the input to the client's game engine (with a delay if so configured) and will transmit the input to the server as well.

This function can be called by the extended client engine class, typically at the beginning of client-side step processing {@see GameEngine#client__preStep}.

Parameters:
Name Type Description
input String

string representing the input

inputOptions Object

options for the input

Source:

start() → {Promise}

Start the client engine, setting up the game loop, rendering loop and renderer.

Source:
Returns:

Resolves once the Renderer has been initialized, and the game is ready to connect

Type
Promise