-
Notifications
You must be signed in to change notification settings - Fork 0
Modules
modules in EEE must inherit from eee.TModule.
TModules define some basic functionalities and default behaviours all modules should have.
let's define a simple Renderer module
in TypeScript
module modules {
export class Renderer extends eee.TModule {
constructor(public canvas: HTMLCanvasElement) {
super([], [CSkin]);
//module initialisation goes here : for example getting the drawing context ...etc
}
public init() {
super.init();
//if you have some code that depend on other modules, you should add it here
//init() is called when all other modules are loaded.
}
public update() {
this.ctx.clearRect(0, 0, this.cWidth, this.cHeight);
var keys = this.entities;
for (var i = 0; i < keys.length; i++) {
var entity = eee.Engine.data.entities.get(keys[i]);
//entity manipulation code goes here
}
}
}
}
there are three important parts when creating an EEE module
Modules constructor must call the superclass constructor witch takes on or two arrays the first array is a list of modules on witch the currend module depends. the second array is a list of components, eatch entity containing all of those components will be registered to module dictionary (this.entities)
suppose that our module Renderer depends on a module Physics, the constructor becomes
in TypeScript
constructor(public canvas: HTMLCanvasElement) {
super([Physics], [CSkin]);
}
the second array determines witch entities will be automatically referenced in the module dictionary (this.entities)
referencing all entities having CSkin component.
super([Physics], [CSkin]);
referencing all entities having both CSkin and CPosition components.
super([Physics], [CSkin, CPosition]);
dont reference any entity
super([Physics]);
the referenced entities are accessible throught this.entities (see update method)
when you instantiate a module, the constructor is called, but sometimes you need to call other modules or need that some other data to be initialised.
the init method is called when the engine starts so you are sure that all attached modules are available.
Note : it's allways possible to create and insert a module after the engine startup, in this case, it's up to you to handle the code execution order.
this method is called each update cycle. the way and frequency of those updates are determined by the Scheduler implementation. usually, an update cycle is run for each frame.