Skip to content

Conversation

@fernandojsg
Copy link
Member

Introducing a timer to fix the problems with the requestAnimationFrame


var warn = debug('utils:warn');

module.exports.Timer = require('./timer');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could keep this alphabetical

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, I didn't noticed O:)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use THREE.Clock?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmarcos this was my first try, but the current implementation it's quite ugly (https://github.com/mrdoob/three.js/blob/master/src/core/Clock.js) you need to call getElapsedTime() and getDelta() but you'll get different values as it will call performance.now() again. Or you call getDelta() and then access elapsedTime that doesn't seems very coherent.
Also it works with seconds instead of ms, so we need to multiply everything by 1000.
I would better stick for now with our implementation and probably open a PR in three.js but I guess it's widely used so it will break many things if we change the implementation a lot.


this.animationFrameID = effect.requestAnimationFrame(this.render);
effect.render(this.object3D, this.camera);
this.time = time;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd keep the time property on the scene.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Umm do you want it even if it's accesible with this.timer.ellapsedTime?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's documented, might be being used. And if browsers ever fix the behavior, it's possible we might revert?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, good point

var effect = this.effect;
var timeDelta = time - this.time;
this.timer.update();
var time = this.timer.elapsedTime;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need intermediate vars, only used once.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

this.running = true;
},

update: function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unit tests

@fernandojsg fernandojsg force-pushed the timer branch 2 times, most recently from b2c95c1 to 9ed44ce Compare March 8, 2017 23:34
@ngokevin
Copy link
Member

ngokevin commented Mar 8, 2017

r+ from me

@fernandojsg
Copy link
Member Author

Test added, I'm using right now assert.isAbove(scene.time, 0); because of the "bug" we were talking on slack related to mrdoob/three.js#10962.
I'll change that in the future as soon as it will get merged there and we'll upgrade too.

@dmarcos
Copy link
Member

dmarcos commented Mar 9, 2017

Thanks!

@dmarcos
Copy link
Member

dmarcos commented Mar 9, 2017

waiting for tests

@dmarcos dmarcos merged commit 6a4bd10 into aframevr:master Mar 9, 2017
@fernandojsg fernandojsg deleted the timer branch March 9, 2017 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants