zerk.game.engine Class
Game Engine
The game engine main class
Item Index
Methods
- _getSystemClass
- _log
- _onLoadWorld
- _render
- _startTimer
- _stopTimer
- _tick
- _updateSystems
- addEntity
- addSystem
- clearEntities
- clearSystems
- fireEvent
- getEntitiesByTags
- getEntityById
- getEntitySystemList
- getRegistry
- getSystem
- getTime
- init
- isRunning
- isSystemRegistered
- loadEntities
- loadWorld
- on
- pause
- removeEntity
- removeSystem
- reset
- saveWorld
- start
- startSystems
- stop
- stopSystems
- un
Methods
_getSystemClass
-
name
Returns the class name for given system name
Parameters:
-
name
StringSystem name. Not the class name.
Returns:
_log
-
message
-
severity
Local log method
Parameters:
-
message
StringLog message
-
severity
IntegerLog severity
_onLoadWorld
-
world
-
successHandler
-
errorHandler
Fires when the world definition is laoded
Parameters:
-
world
ObjectWorld definition
-
successHandler
FunctionEvent handler for success
-
errorHandler
FunctionEvent handler for error
_render
()
protected
Game engine render tick
_startTimer
()
protected
Starts the engine timer
_stopTimer
()
protected
Stops the engine timer
_tick
()
protected
Game engine simulation tick
_updateSystems
-
thread
Updates all systems in given thread
Parameters:
-
thread
StringThread name
addEntity
-
config
Creates a new entity instance with given configuration
Parameters:
-
config
config.entityEntity configuration
addSystem
-
name
-
config
Adds a system to the engine
Parameters:
-
name
StringName of the system. Not the class name.
-
config
ObjectInitial config for the system
Returns:
clearEntities
()
Removes all entities from the world
clearSystems
()
Removes all system from the engine
fireEvent
-
event
Fire event
Parameters:
-
event
StringEvent name
Returns:
getEntitiesByTags
-
tags
Returns entites that contain all given tags
Parameters:
-
tags
ArrayArray of tags
Returns:
getEntityById
-
id
Returns entity instance by given id
Parameters:
-
id
StringEntity id
Returns:
getEntitySystemList
-
entity
Returns a list of systems interested in given entity
Parameters:
-
entity
config.entityEntity state
Returns:
getRegistry
()
zerk.game.engine.registry
Returns the game engine registry
Returns:
getSystem
-
name
Returns a system instance
Parameters:
-
name
StringSystem name. Not the class name.
Returns:
getTime
()
Integer
Returns current world time
Returns:
init
-
jsonLoader
-
config
Class constructor
Parameters:
-
jsonLoader
zerk.jsonLoaderA JSON Loader instance
-
config
ObjectGame configuration
isRunning
()
Boolean
Returns true if the game engine is running
Returns:
isSystemRegistered
-
name
Returns true when given system is loaded in the engine
Parameters:
-
name
StringSystem name. Not the class name.
Returns:
loadEntities
-
entities
-
successHandler
-
errorHandler
Loads given entities
Parameters:
-
entities
ArrayAn array of entity resource ids
-
successHandler
FunctionEvent handler for success
-
errorHandler
FunctionEvent handler for error
loadWorld
-
worldClass
-
successHandler
-
errorHandler
Loads a world
Parameters:
-
worldClass
StringResource id of the world to be loaded
-
successHandler
FunctionEvent handler for success
-
errorHandler
FunctionEvent handler for error
on
-
event
-
callback
-
scope
Register event handler
Parameters:
-
event
StringEvent name
-
callback
FunctionCallback function. Return false to cancel event bubble.
-
scope
ObjectScope to be used in callback function
pause
()
Pause game engine
removeEntity
-
Entity
Removes given entity instance from the world
Parameters:
-
Entity
config.entitystate
Returns:
removeSystem
-
name
Removes a system from the engine
Parameters:
-
name
StringName of the system. Not the class name.
Returns:
reset
()
Reset the engine
saveWorld
()
String
Save world state
Returns:
start
()
Start game engine
startSystems
()
Starts all systems
stop
()
Stop game engine
stopSystems
()
Stops all systems
un
-
event
-
callback
Unregister event handler
Parameters:
-
event
StringEvent name
-
callback
FunctionCallback function
Returns:
Properties
_config
Object
protected
Engine configuration
_entities
Array
protected
Entities register
_entityIdMap
Object
protected
Entity id map
_eventListeners
Array
protected
List of event handlers
_lastEntityId
Integer
protected
Last used entity id
Used to generate the next entity id.
_running
Boolean
protected
Indicates that the engine is running
_system
Object
protected
System register
_systemMap
Object
protected
Map of systems by names
_threadMap
Object
protected
Entities grouped by threads for fast access
_time
Integer
protected
Total world runtime
_timer
DOMTimer
protected
World timer
_unloadingWorld
Boolean
deprecated
protected
Indicates that the world is unloading
_worldInterval
Float
protected
World timer interval