Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

save a couple of function callbacks and array creation on each frame #2937

Merged
merged 1 commit into from Aug 6, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 24 additions & 17 deletions src/core/scene/a-scene.js
Expand Up @@ -55,14 +55,15 @@ module.exports.AScene = registerElement('a-scene', {
this.object3D = new THREE.Scene();
this.render = bind(this.render, this);
this.systems = {};
this.systemNames = [];
this.time = 0;
this.init();
}
},

init: {
value: function () {
this.behaviors = { tick: [], tock: [] };
this.behaviors = {tick: [], tock: []};
this.hasLoaded = false;
this.isPlaying = false;
this.originalHTML = this.innerHTML;
Expand Down Expand Up @@ -141,6 +142,7 @@ module.exports.AScene = registerElement('a-scene', {
value: function (name) {
if (this.systems[name]) { return; }
this.systems[name] = new systems[name](this);
this.systemNames.push(name);
}
},

Expand Down Expand Up @@ -509,20 +511,23 @@ module.exports.AScene = registerElement('a-scene', {
*/
tick: {
value: function (time, timeDelta) {
var i;
var systems = this.systems;

// Animations.
TWEEN.update();

// Components.
this.behaviors.tick.forEach(function (component) {
if (!component.el.isPlaying) { return; }
component.tick(time, timeDelta);
});
for (i = 0; i < this.behaviors.tick.length; i++) {
if (!this.behaviors.tick[i].el.isPlaying) { continue; }
this.behaviors.tick[i].tick(time, timeDelta);
}

// Systems.
Object.keys(systems).forEach(function (key) {
if (!systems[key].tick) { return; }
systems[key].tick(time, timeDelta);
});
for (i = 0; i < this.systemNames.length; i++) {
if (!systems[this.systemNames[i]].tick) { return; }
systems[this.systemNames[i]].tick(time, timeDelta);
}
}
},

Expand All @@ -533,18 +538,20 @@ module.exports.AScene = registerElement('a-scene', {
*/
tock: {
value: function (time, timeDelta) {
var i;
var systems = this.systems;

// Components.
this.behaviors.tock.forEach(function (component) {
if (!component.el.isPlaying) { return; }
component.tock(time, timeDelta);
});
for (i = 0; i < this.behaviors.tock.length; i++) {
if (!this.behaviors.tock[i].el.isPlaying) { continue; }
this.behaviors.tock[i].tock(time, timeDelta);
}

// Systems.
Object.keys(systems).forEach(function (key) {
if (!systems[key].tock) { return; }
systems[key].tock(time, timeDelta);
});
for (i = 0; i < this.systemNames.length; i++) {
if (!systems[this.systemNames[i]].tock) { return; }
systems[this.systemNames[i]].tock(time, timeDelta);
}
}
},

Expand Down