-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameEngine.js.html
590 lines (498 loc) · 29.7 KB
/
GameEngine.js.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>GameEngine.js - Documentation</title>
<link rel="shortcut icon" href="http://lance.gg/favicon.ico">
<link rel="icon" sizes="16x16 32x32 64x64" href="http://lance.gg/favicon.ico">
<link rel="icon" type="image/png" sizes="196x196" href="http://lance.gg/favicon-192.png">
<link rel="icon" type="image/png" sizes="160x160" href="http://lance.gg/favicon-160.png">
<link rel="icon" type="image/png" sizes="96x96" href="http://lance.gg/favicon-96.png">
<link rel="icon" type="image/png" sizes="64x64" href="http://lance.gg/favicon-64.png">
<link rel="icon" type="image/png" sizes="32x32" href="http://lance.gg/favicon-32.png">
<link rel="icon" type="image/png" sizes="16x16" href="http://lance.gg/favicon-16.png">
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link href="https://file.myfontastic.com/DeXq9523CzrFERZkXSzP7D/icons.css" rel="stylesheet">
<link type="text/css" rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
<link rel="stylesheet" href="//cdn.jsdelivr.net/highlight.js/9.8.0/styles/atelier-sulphurpool-light.min.css">
</head>
<body>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav>
<h2 class="home"><a href="index.html">Lance</a></h2><h2>Concepts</h2><ul class="tutorials"><li><span class='category'>Introduction<ul><li><a href="tutorial-introduction.html">Introduction</a></li><li><a href="tutorial-introduction_prologue.html">Prologue</a></li><li><a href="tutorial-introduction_community.html">Community</a></li><li><a href="tutorial-introduction_roadmap.html">Development Roadmap</a></li><li><a href="tutorial-introduction_faq.html">Frequently Asked Questions</a></li></ul></li><li><span class='category'>Overview<ul><li><a href="tutorial-overview_architecture.html">Architecture of a Multiplayer Game</a></li><li><a href="tutorial-choosing_a_physics_engine.html">Choosing a Physics Engine</a></li><li><a href="tutorial-guide_gameengine.html">Game Engine</a></li><li><a href="tutorial-guide_serverengine.html">Server Engine</a></li><li><a href="tutorial-guide_clientengine.html">Client Engine</a></li><li><a href="tutorial-guide_renderer.html">Renderer</a></li><li><a href="tutorial-guide_gameworld.html">Game World and Game Objects</a></li><li><a href="tutorial-guide_serialization.html">Serialization and Communication</a></li></ul></li><li><span class='category'>Synchronization Methods<ul><li><a href="tutorial-guide_syncinterpolation.html">Interpolation</a></li><li><a href="tutorial-guide_syncextrapolation.html">Extrapolation</a></li></ul></li><li><span class='category'>Tutorials<ul><li><a href="tutorial-MyFirstGame.html">My First Game: Pong</a></li><li><a href="tutorial-spaceships.html">Spaaace</a></li></ul></li><li><span class='category'>Extras<ul><li><a href="tutorial-guide_tuningdebugging.html">Fine Tuning and Debugging</a></li><li><a href="tutorial-furtherreading.html">Further Reading</a></li></ul></li></ul><h2>API Reference</h2><h3 class="classes">Classes</h3><ul><li><a href="AFrameRenderer.html">AFrameRenderer</a><ul class='methods'><li data-type='method'><a href="AFrameRenderer.html#draw">draw</a></li><li data-type='method'><a href="AFrameRenderer.html#init">init</a></li></ul></li><li><a href="BaseTypes.html">BaseTypes</a></li><li><a href="CannonPhysicsEngine.html">CannonPhysicsEngine</a></li><li><a href="ClientEngine.html">ClientEngine</a><ul class='methods'><li data-type='method'><a href="ClientEngine.html#connect">connect</a></li><li data-type='method'><a href="ClientEngine.html#disconnect">disconnect</a></li><li data-type='method'><a href="ClientEngine.html#sendInput">sendInput</a></li><li data-type='method'><a href="ClientEngine.html#start">start</a></li></ul></li><li><a href="DynamicObject.html">DynamicObject</a><ul class='methods'><li data-type='method'><a href="DynamicObject.html#bendingToString">bendingToString</a></li><li data-type='method'><a href="DynamicObject.html#toString">toString</a></li></ul></li><li><a href="GameEngine.html">GameEngine</a><ul class='methods'><li data-type='method'><a href="GameEngine.html#addObjectToWorld">addObjectToWorld</a></li><li data-type='method'><a href="GameEngine.html#getPlayerGameOverResult">getPlayerGameOverResult</a></li><li data-type='method'><a href="GameEngine.html#isOwnedByPlayer">isOwnedByPlayer</a></li><li data-type='method'><a href="GameEngine.html#on">on</a></li><li data-type='method'><a href="GameEngine.html#once">once</a></li><li data-type='method'><a href="GameEngine.html#processInput">processInput</a></li><li data-type='method'><a href="GameEngine.html#registerClasses">registerClasses</a></li><li data-type='method'><a href="GameEngine.html#removeListener">removeListener</a></li><li data-type='method'><a href="GameEngine.html#removeObjectFromWorld">removeObjectFromWorld</a></li><li data-type='method'><a href="GameEngine.html#start">start</a></li><li data-type='method'><a href="GameEngine.html#step">step</a></li></ul></li><li><a href="GameObject.html">GameObject</a><ul class='methods'><li data-type='method'><a href="GameObject.html#bendingToString">bendingToString</a></li><li data-type='method'><a href="GameObject.html#hasComponent">hasComponent</a></li><li data-type='method'><a href="GameObject.html#onAddToWorld">onAddToWorld</a></li><li data-type='method'><a href="GameObject.html#onRemoveFromWorld">onRemoveFromWorld</a></li><li data-type='method'><a href="GameObject.html#syncTo">syncTo</a></li><li data-type='method'><a href="GameObject.html#toString">toString</a></li></ul></li><li><a href="GameWorld.html">GameWorld</a><ul class='methods'><li data-type='method'><a href="GameWorld.html#addObject">addObject</a></li><li data-type='method'><a href="GameWorld.html#forEachObject">forEachObject</a></li><li data-type='method'><a href="GameWorld.html#getNewId">getNewId</a></li><li data-type='method'><a href="GameWorld.html#queryObject">queryObject</a></li><li data-type='method'><a href="GameWorld.html#queryObjects">queryObjects</a></li><li data-type='method'><a href="GameWorld.html#removeObject">removeObject</a></li></ul></li><li><a href="KeyboardControls.html">KeyboardControls</a></li><li><a href="PhysicalObject2D.html">PhysicalObject2D</a><ul class='methods'><li data-type='method'><a href="PhysicalObject2D.html#onAddToWorld">onAddToWorld</a></li><li data-type='method'><a href="PhysicalObject2D.html#toString">toString</a></li></ul></li><li><a href="PhysicalObject3D.html">PhysicalObject3D</a><ul class='methods'><li data-type='method'><a href="PhysicalObject3D.html#toString">toString</a></li></ul></li><li><a href="Quaternion.html">Quaternion</a><ul class='methods'><li data-type='method'><a href="Quaternion.html#conjugate">conjugate</a></li><li data-type='method'><a href="Quaternion.html#copy">copy</a></li><li data-type='method'><a href="Quaternion.html#multiply">multiply</a></li><li data-type='method'><a href="Quaternion.html#set">set</a></li><li data-type='method'><a href="Quaternion.html#setFromAxisAngle">setFromAxisAngle</a></li><li data-type='method'><a href="Quaternion.html#slerp">slerp</a></li><li data-type='method'><a href="Quaternion.html#toAxisAngle">toAxisAngle</a></li><li data-type='method'><a href="Quaternion.html#toString">toString</a></li></ul></li><li><a href="Renderer.html">Renderer</a><ul class='methods'><li data-type='method'><a href="Renderer.html#addObject">addObject</a></li><li data-type='method'><a href="Renderer.html#draw">draw</a></li><li data-type='method'><a href="Renderer.html#init">init</a></li><li data-type='method'><a href="Renderer.html#removeObject">removeObject</a></li><li data-type='method'><a href="Renderer.html#runClientStep">runClientStep</a></li><li data-type='method'><a href="Renderer.html#stop">stop</a></li></ul></li><li><a href="Serializer.html">Serializer</a><ul class='methods'><li data-type='method'><a href="Serializer.html#.typeCanAssign">typeCanAssign</a></li><li data-type='method'><a href="Serializer.html#addCustomType">addCustomType</a></li><li data-type='method'><a href="Serializer.html#registerClass">registerClass</a></li></ul></li><li><a href="ServerEngine.html">ServerEngine</a><ul class='methods'><li data-type='method'><a href="ServerEngine.html#gameStatus">gameStatus</a></li></ul></li><li><a href="SimplePhysicsEngine.html">SimplePhysicsEngine</a></li><li><a href="ThreeVector.html">ThreeVector</a><ul class='methods'><li data-type='method'><a href="ThreeVector.html#add">add</a></li><li data-type='method'><a href="ThreeVector.html#clone">clone</a></li><li data-type='method'><a href="ThreeVector.html#copy">copy</a></li><li data-type='method'><a href="ThreeVector.html#getBendingDelta">getBendingDelta</a></li><li data-type='method'><a href="ThreeVector.html#length">length</a></li><li data-type='method'><a href="ThreeVector.html#lerp">lerp</a></li><li data-type='method'><a href="ThreeVector.html#multiplyScalar">multiplyScalar</a></li><li data-type='method'><a href="ThreeVector.html#normalize">normalize</a></li><li data-type='method'><a href="ThreeVector.html#set">set</a></li><li data-type='method'><a href="ThreeVector.html#subtract">subtract</a></li><li data-type='method'><a href="ThreeVector.html#toString">toString</a></li></ul></li><li><a href="Trace.html">Trace</a></li><li><a href="TwoVector.html">TwoVector</a><ul class='methods'><li data-type='method'><a href="TwoVector.html#add">add</a></li><li data-type='method'><a href="TwoVector.html#clone">clone</a></li><li data-type='method'><a href="TwoVector.html#copy">copy</a></li><li data-type='method'><a href="TwoVector.html#getBendingDelta">getBendingDelta</a></li><li data-type='method'><a href="TwoVector.html#length">length</a></li><li data-type='method'><a href="TwoVector.html#lerp">lerp</a></li><li data-type='method'><a href="TwoVector.html#multiplyScalar">multiplyScalar</a></li><li data-type='method'><a href="TwoVector.html#normalize">normalize</a></li><li data-type='method'><a href="TwoVector.html#set">set</a></li><li data-type='method'><a href="TwoVector.html#subtract">subtract</a></li><li data-type='method'><a href="TwoVector.html#toString">toString</a></li></ul></li></ul><h3 class="events">Events</h3><ul><li><a href="GameEngine.html#event:client__postStep">client__postStep</a></li><li><a href="GameEngine.html#event:client__preStep">client__preStep</a></li><li><a href="GameEngine.html#event:client__processInput">client__processInput</a></li><li><a href="GameEngine.html#event:client__slowFrameRate">client__slowFrameRate</a></li><li><a href="GameEngine.html#event:client__stepReset">client__stepReset</a></li><li><a href="GameEngine.html#event:client__syncReceived">client__syncReceived</a></li><li><a href="GameEngine.html#event:objectAdded">objectAdded</a></li><li><a href="GameEngine.html#event:objectDestroyed">objectDestroyed</a></li><li><a href="GameEngine.html#event:playerDisconnected">playerDisconnected</a></li><li><a href="GameEngine.html#event:playerJoined">playerJoined</a></li><li><a href="GameEngine.html#event:postStep">postStep</a></li><li><a href="GameEngine.html#event:preStep">preStep</a></li><li><a href="GameEngine.html#event:processInput">processInput</a></li><li><a href="GameEngine.html#event:server__inputReceived">server__inputReceived</a></li><li><a href="GameEngine.html#event:server__playerDisconnected">server__playerDisconnected</a></li><li><a href="GameEngine.html#event:server__playerJoined">server__playerJoined</a></li><li><a href="GameEngine.html#event:server__postStep">server__postStep</a></li><li><a href="GameEngine.html#event:server__preStep">server__preStep</a></li><li><a href="GameEngine.html#event:server__processInput">server__processInput</a></li><li><a href="GameEngine.html#event:start">start</a></li><li><a href="GameEngine.html#event:syncReceived">syncReceived</a></li></ul>
</nav>
<div id="main">
<h1 class="page-title">GameEngine.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>import GameWorld from './GameWorld';
import EventEmitter from 'eventemitter3';
import Timer from './game/Timer';
import Trace from './lib/Trace';
/**
* The GameEngine contains the game logic. Extend this class
* to implement game mechanics. The GameEngine derived
* instance runs once on the server, where the final decisions
* are always taken, and one instance will run on each client as well,
* where the client emulates what it expects to be happening
* on the server.
*
* The game engine's logic must listen to user inputs and
* act on these inputs to change the game state. For example,
* the game engine listens to controller/keyboard inputs to infer
* movement for the player/ship/first-person. The game engine listens
* to clicks, button-presses to infer firing, etc..
*
* Note that the game engine runs on both the server and on the
* clients - but the server decisions always have the final say,
* and therefore clients must resolve server updates which conflict
* with client-side predictions.
*/
class GameEngine {
/**
* Create a game engine instance. This needs to happen
* once on the server, and once on each client.
*
* @param {Object} options - options object
* @param {Number} options.traceLevel - the trace level from 0 to 5. Lower value traces more.
* @param {Number} options.delayInputCount - client side only. Introduce an artificial delay on the client to better match the time it will occur on the server. This value sets the number of steps the client will wait before applying the input locally
*/
constructor(options) {
// TODO I think we should discuss this whole globals issues
// place the game engine in the LANCE globals
const isServerSide = (typeof window === 'undefined');
const glob = isServerSide ? global : window;
glob.LANCE = { gameEngine: this };
// set options
const defaultOpts = { GameWorld: GameWorld, traceLevel: Trace.TRACE_NONE };
if (!isServerSide) defaultOpts.clientIDSpace = 1000000;
this.options = Object.assign(defaultOpts, options);
/**
* client's player ID, as a string. If running on the client, this is set at runtime by the clientEngine
* @member {String}
*/
this.playerId = NaN;
// set up event emitting and interface
let eventEmitter = new EventEmitter();
/**
* Register a handler for an event
*
* @method on
* @memberof GameEngine
* @instance
* @param {String} eventName - name of the event
* @param {Function} eventHandler - handler function
*/
this.on = eventEmitter.on;
/**
* Register a handler for an event, called just once (if at all)
*
* @method once
* @memberof GameEngine
* @instance
* @param {String} eventName - name of the event
* @param {Function} eventHandler - handler function
*/
this.once = eventEmitter.once;
/**
* Remove a handler
*
* @method removeListener
* @memberof GameEngine
* @instance
* @param {String} eventName - name of the event
* @param {Function} eventHandler - handler function
*/
this.removeListener = eventEmitter.removeListener;
this.emit = eventEmitter.emit;
// set up trace
this.trace = new Trace({ traceLevel: this.options.traceLevel });
}
findLocalShadow(serverObj) {
for (let localId of Object.keys(this.world.objects)) {
if (Number(localId) < this.options.clientIDSpace) continue;
let localObj = this.world.objects[localId];
if (localObj.hasOwnProperty('inputId') && localObj.inputId === serverObj.inputId)
return localObj;
}
return null;
}
initWorld(worldSettings) {
this.world = new GameWorld();
// on the client we have a different ID space
if (this.options.clientIDSpace) {
this.world.idCount = this.options.clientIDSpace;
}
/**
* The worldSettings defines the game world constants, such
* as width, height, depth, etc. such that all other classes
* can reference these values.
* @member {Object} worldSettings
* @memberof GameEngine
*/
this.worldSettings = Object.assign({}, worldSettings);
}
/**
* Start the game. This method runs on both server
* and client. Extending the start method is useful
* for setting up the game's worldSettings attribute,
* and registering methods on the event handler.
*/
start() {
this.trace.info(() => '========== game engine started ==========');
this.initWorld();
// create the default timer
this.timer = new Timer();
this.timer.play();
this.on('postStep', (step, isReenact) => {
if (!isReenact) this.timer.tick();
});
this.emit('start', { timestamp: (new Date()).getTime() });
}
/**
* Single game step.
*
* @param {Boolean} isReenact - is this step a re-enactment of the past.
* @param {Number} t - the current time (optional)
* @param {Number} dt - elapsed time since last step was called. (optional)
* @param {Boolean} physicsOnly - do a physics step only, no game logic
*/
step(isReenact, t, dt, physicsOnly) {
// physics-only step
if (physicsOnly) {
if (dt) dt /= 1000; // physics engines work in seconds
this.physicsEngine.step(dt, objectFilter);
return;
}
// emit preStep event
if (isReenact === undefined)
throw new Error('game engine does not forward argument isReenact to super class');
isReenact = Boolean(isReenact);
let step = ++this.world.stepCount;
let clientIDSpace = this.options.clientIDSpace;
this.emit('preStep', { step, isReenact, dt });
// skip physics for shadow objects during re-enactment
function objectFilter(o) {
return !isReenact || o.id < clientIDSpace;
}
// physics step
if (this.physicsEngine && !this.ignorePhysics) {
if (dt) dt /= 1000; // physics engines work in seconds
this.physicsEngine.step(dt, objectFilter);
}
// for each object
// - apply incremental bending
// - refresh object positions after physics
this.world.forEachObject((id, o) => {
if (typeof o.refreshFromPhysics === 'function')
o.refreshFromPhysics();
this.trace.trace(() => `object[${id}] after ${isReenact ? 'reenact' : 'step'} : ${o.toString()}`);
});
// emit postStep event
this.emit('postStep', { step, isReenact });
}
/**
* Add object to the game world.
* On the client side, the object may not be created, if the server copy
* of this object is already in the game world. This could happen when the client
* is using delayed-input, and the RTT is very low.
*
* @param {Object} object - the object.
* @return {Object} object - the final object.
*/
addObjectToWorld(object) {
// if we are asked to create a local shadow object
// the server copy may already have arrived.
if (Number(object.id) >= this.options.clientIDSpace) {
let serverCopyArrived = false;
this.world.forEachObject((id, o) => {
if (o.hasOwnProperty('inputId') && o.inputId === object.inputId)
serverCopyArrived = true;
});
if (serverCopyArrived) {
this.trace.info(() => `========== shadow object NOT added ${object.toString()} ==========`);
return null;
}
}
this.world.addObject(object);
// tell the object to join the game, by creating
// its corresponding physical entities and renderer entities.
if (typeof object.onAddToWorld === 'function')
object.onAddToWorld(this);
this.emit('objectAdded', object);
this.trace.info(() => `========== object added ${object.toString()} ==========`);
return object;
}
/**
* Override this function to implement input handling.
* This method will be called on the specific client where the
* input was received, and will also be called on the server
* when the input reaches the server. The client does not call this
* method directly, rather the client calls {@link ClientEngine#sendInput}
* so that the input is sent to both server and client, and so that
* the input is delayed artificially if so configured.
*
* The input is described by a short string, and is given an index.
* The index is used internally to keep track of inputs which have already been applied
* on the client during synchronization. The input is also associated with
* the ID of a player.
*
* @param {Object} inputMsg - input descriptor object
* @param {String} inputMsg.input - describe the input (e.g. "up", "down", "fire")
* @param {Number} inputMsg.messageIndex - input identifier
* @param {Number} playerId - the player ID
* @param {Boolean} isServer - indicate if this function is being called on the server side
*/
processInput(inputMsg, playerId, isServer) {
this.trace.info(() => `game engine processing input[${inputMsg.messageIndex}] <${inputMsg.input}> from playerId ${playerId}`);
}
/**
* Remove an object from the game world.
*
* @param {Object|String} objectId - the object or object ID
*/
removeObjectFromWorld(objectId) {
if (typeof objectId === 'object') objectId = objectId.id;
let object = this.world.objects[objectId];
if (!object) {
throw new Error(`Game attempted to remove a game object which doesn't (or never did) exist, id=${objectId}`);
}
this.trace.info(() => `========== destroying object ${object.toString()} ==========`);
if (typeof object.onRemoveFromWorld === 'function')
object.onRemoveFromWorld(this);
this.emit('objectDestroyed', object);
this.world.removeObject(objectId);
}
/**
* Check if a given object is owned by the player on this client
*
* @param {Object} object the game object to check
* @return {Boolean} true if the game object is owned by the player on this client
*/
isOwnedByPlayer(object) {
return (object.playerId == this.playerId);
}
/**
* Register Game Object Classes
*
* @example
* registerClasses(serializer) {
* serializer.registerClass(require('../common/Paddle'));
* serializer.registerClass(require('../common/Ball'));
* }
*
* @param {Serializer} serializer - the serializer
*/
registerClasses(serializer) {
}
/**
* Decide whether the player game is over by returning an Object, need to be implemented
*
* @return {Object} truthful if the game is over for the player and the object is returned as GameOver data
*/
getPlayerGameOverResult() {
return null;
}
}
/**
* EVENTS
*/
/**
* Marks the beginning of a new game step
*
* @event GameEngine#preStep
* @param {Number} stepNumber - the step number
* @param {Boolean} isReenact - is this step a re-enactment
*/
/**
* Marks the end of a game step
*
* @event GameEngine#postStep
* @param {Number} stepNumber - the step number
* @param {Boolean} isReenact - is this step a re-enactment
*/
/**
* An object has been added to the world
*
* @event GameEngine#objectAdded
* @param {Object} obj - the new object
*/
/**
* An object has been removed from the world
*
* @event GameEngine#objectDestroyed
* @param {Object} obj - the object
*/
/**
* A player has joined
*
* @event GameEngine#playerJoined
* @param {Number} joinTime - epoch of join time
* @param {Object} playerDesc - player descriptor
* @param {String} playerDesc.playerId - the player ID
*/
/**
* A player has left
*
* @event GameEngine#playerDisconnected
* @param {Number} joinTime - epoch of join time
* @param {Number} disconnectTime - epoch of disconnect time
* @param {Object} playerDesc - player descriptor
* @param {String} playerDesc.playerId - the player ID
*/
/**
* A player has joined on the server
*
* @event GameEngine#server__playerJoined
* @param {Number} joinTime - epoch of join time
* @param {Object} playerDesc - player descriptor
* @param {String} playerDesc.playerId - the player ID
*/
/**
* A player has left on the server
*
* @event GameEngine#server__playerDisconnected
* @param {Number} joinTime - epoch of join time
* @param {Number} disconnectTime - epoch of disconnect time
* @param {Object} playerDesc - player descriptor
* @param {String} playerDesc.playerId - the player ID
*/
/**
* A synchronization update arrived from the server
*
* @event GameEngine#syncReceived
* @param {Object} sync - the synchronization object
*/
/**
* Marks the beginning of a game step on the client
*
* @event GameEngine#client__preStep
*/
/**
* Marks the end of a game step on the client
*
* @event GameEngine#client__postStep
*/
/**
* An input needs to be handled. Emitted just before the GameEngine
* method processInput is invoked.
*
* @event GameEngine#processInput
* @param {Object} input - input descriptor object
* @param {String} input.input - describe the input (e.g. "up", "down", "fire")
* @param {Number} input.messageIndex - input identifier
* @param {Object} input.options - the object which was passed as SendInput's InputOptions parameter
* @param {Number} input.step - input execution step
* @param {Number} playerId - the player ID
*/
/**
* An input needs to be handled.
* This event is emitted on the server only, just before the
* general processInput event.
*
* @event GameEngine#server__processInput
* @param {Object} input - input descriptor object
* @param {String} input.input - describe the input (e.g. "up", "down", "fire")
* @param {Number} input.messageIndex - input identifier
* @param {Object} input.options - the object which was passed as SendInput's InputOptions parameter
* @param {Number} input.step - input execution step
* @param {Number} playerId - the player ID
*/
/**
* An input needs to be handled.
* This event is emitted on the client only, just before the
* general processInput event.
*
* @event GameEngine#client__processInput
* @param {Object} input - input descriptor object
* @param {String} input.input - describe the input (e.g. "up", "down", "fire")
* @param {Number} input.messageIndex - input identifier
* @param {Object} input.options - the object which was passed as SendInput's InputOptions parameter
* @param {Number} input.step - input execution step
* @param {Number} playerId - the player ID
*/
/**
* Client received a sync from the server
*
* @event GameEngine#client__syncReceived
* @param {Object} sync - sync from the server
* @param {Array} syncEvents - array of events in the sync
* @param {Number} maxStepCount - highest step in the sync
*/
/**
* Client reset the world step
*
* @event GameEngine#client__stepReset
* @param {Object} resetDesc - sync from the server
* @param {Number} oldStep - the old step count
* @param {Number} newStep - the new step count
*/
/**
* Marks the beginning of a game step on the server
*
* @event GameEngine#server__preStep
* @param {Number} stepNumber - the step number
*/
/**
* Marks the end of a game step on the server
*
* @event GameEngine#server__postStep
* @param {Number} stepNumber - the step number
*/
/**
* User input received on the server
*
* @event GameEngine#server__inputReceived
* @param {Object} input - input descriptor
* @param {Object} input.data - input descriptor
* @param {String} input.playerId - player that sent the input
*/
/**
* Report slow frame rate on the browser.
* The browser did not achieve a reasonable frame rate
*
* @event GameEngine#client__slowFrameRate
*/
/**
* server has started
*
* @event GameEngine#start
* @param {Number} timestamp - UTC epoch of start time
*/
// TODO: the declaration "export default" could be done as part of the class
// declaration up above, but the current version of jsdoc doesn't support this.
// when jsdoc is fixed, move this descriptor back to the class declaration,
// in all relevant files (12 files)
// see: https://github.com/jsdoc3/jsdoc/issues/1132
export default GameEngine;
</code></pre>
</article>
</section>
</div>
<br class="clear">
<footer>
Did you find a mistake? Do you have an improvement? <a href="https://github.com/lance-gg/lance/issues">Let us know!</a>
</footer>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-88335360-1', 'auto');
ga('send', 'pageview');
</script>
<script src="https://use.typekit.net/lai1bbe.js"></script>
<script>try{Typekit.load({ async: true });}catch(e){}</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.8.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script src="scripts/linenumber.js"></script>
</body>
</html>