1 | "use strict";
|
2 |
|
3 | var ECS = require("entity-component-system").EntityComponentSystem;
|
4 | var EntityPool = require("entity-component-system").EntityPool;
|
5 | var gameLoop = require("./game-loop");
|
6 |
|
7 | function Scene() {
|
8 | this.simulation = new ECS();
|
9 | this.renderer = new ECS();
|
10 | this.entities = new EntityPool();
|
11 | this.simulationStepTime = 5;
|
12 | }
|
13 | Scene.prototype.start = function(context) {
|
14 | if (this._stop) {
|
15 | return;
|
16 | }
|
17 | if (typeof this.onEnter === "function") {
|
18 | this._stop = function() {};
|
19 | this.onEnter();
|
20 | if (this._stop === undefined) {
|
21 | return;
|
22 | }
|
23 | }
|
24 | this._stop = gameLoop(this.entities, this.simulation, this.simulationStepTime, this.renderer, context);
|
25 | };
|
26 | Scene.prototype.stop = function() {
|
27 | if (!this._stop) {
|
28 | return;
|
29 | }
|
30 | this._stop();
|
31 | delete this._stop;
|
32 |
|
33 | if (typeof this.onExit === "function") {
|
34 | this.onExit();
|
35 | }
|
36 | };
|
37 |
|
38 | module.exports = Scene;
|