diff --git a/src/core/Engine.js b/src/core/Engine.js index 7e1567b..a8e5119 100644 --- a/src/core/Engine.js +++ b/src/core/Engine.js @@ -111,6 +111,15 @@ var Engine = {}; timestamp: timestamp }; + /** + * Fired at the start of a tick, before any updates to the engine or timing + * + * @event beforeTick + * @param {} event An event object + * @param {DOMHighResTimeStamp} event.timestamp The timestamp of the current tick + * @param {} event.source The source object of the event + * @param {} event.name The name of the event + */ Events.trigger(engine, 'beforeTick', event); delta = (timestamp - timing.timestamp) || _delta; @@ -140,6 +149,24 @@ var Engine = {}; frameCounter = 0; } + /** + * Fired after engine timing updated, but just before engine state updated + * + * @event tick + * @param {} event An event object + * @param {DOMHighResTimeStamp} event.timestamp The timestamp of the current tick + * @param {} event.source The source object of the event + * @param {} event.name The name of the event + */ + /** + * Fired just before an update + * + * @event beforeUpdate + * @param {} event An event object + * @param {DOMHighResTimeStamp} event.timestamp The timestamp of the current tick + * @param {} event.source The source object of the event + * @param {} event.name The name of the event + */ Events.trigger(engine, 'tick beforeUpdate', event); // update @@ -147,30 +174,96 @@ var Engine = {}; var pairs = engine.pairs; + /** + * Fired after engine update, provides a list of all pairs that have started to collide in the current tick (if any) + * + * @event collisionStart + * @param {} event An event object + * @param {} event.pairs List of affected pairs + * @param {DOMHighResTimeStamp} event.timestamp The timestamp of the current tick + * @param {} event.source The source object of the event + * @param {} event.name The name of the event + */ if (pairs.collisionStart.length > 0) { Events.trigger(engine, 'collisionStart', { pairs: pairs.collisionStart }); } + /** + * Fired after engine update, provides a list of all pairs that are colliding in the current tick (if any) + * + * @event collisionActive + * @param {} event An event object + * @param {} event.pairs List of affected pairs + * @param {DOMHighResTimeStamp} event.timestamp The timestamp of the current tick + * @param {} event.source The source object of the event + * @param {} event.name The name of the event + */ if (pairs.collisionActive.length > 0) { Events.trigger(engine, 'collisionActive', { pairs: pairs.collisionActive }); } + /** + * Fired after engine update, provides a list of all pairs that have ended collision in the current tick (if any) + * + * @event collisionEnd + * @param {} event An event object + * @param {} event.pairs List of affected pairs + * @param {DOMHighResTimeStamp} event.timestamp The timestamp of the current tick + * @param {} event.source The source object of the event + * @param {} event.name The name of the event + */ if (pairs.collisionEnd.length > 0) { Events.trigger(engine, 'collisionEnd', { pairs: pairs.collisionEnd }); } + /** + * Fired after engine update and all collision events + * + * @event afterUpdate + * @param {} event An event object + * @param {DOMHighResTimeStamp} event.timestamp The timestamp of the current tick + * @param {} event.source The source object of the event + * @param {} event.name The name of the event + */ + /** + * Fired just before rendering + * + * @event beforeRender + * @param {} event An event object + * @param {DOMHighResTimeStamp} event.timestamp The timestamp of the current tick + * @param {} event.source The source object of the event + * @param {} event.name The name of the event + */ Events.trigger(engine, 'afterUpdate beforeRender', event); // render if (engine.render.options.enabled) engine.render.controller.world(engine); + /** + * Fired after rendering + * + * @event afterRender + * @param {} event An event object + * @param {DOMHighResTimeStamp} event.timestamp The timestamp of the current tick + * @param {} event.source The source object of the event + * @param {} event.name The name of the event + */ + /** + * Fired after engine update and after rendering + * + * @event afterTick + * @param {} event An event object + * @param {DOMHighResTimeStamp} event.timestamp The timestamp of the current tick + * @param {} event.source The source object of the event + * @param {} event.name The name of the event + */ Events.trigger(engine, 'afterTick afterRender', event); })(); };