Skip to content

Conversation

@ngokevin
Copy link
Member

@ngokevin ngokevin commented Aug 8, 2017

Description:

There was some messy/dirty/redundant code. Tested with Vive controllers.

Changes proposed:

  • Limit the tracked-controls tick to every 500ms. Before it was every 10ms which does not help much since it usually takes more time to render a single frame. Pretty much, it was getting called on every frame. I don't think this polling needs to be called so often.
  • Don't emit an event and allocate an object every single controller poll. Only emit if the number of controllers change. Before this was emitting every tick, and then possibly handled by 4 controller components at once, for each hand. Save 2 event emissions, 2 object allocations, and 8 event handler calls per tick.
  • Remove getGamepadsByPrefix util. This was only being used in the tracked controls tick, and tracked controls never used the prefix feature. We call the navigator.gamePads now directly in the controls tick. Previously, we were creating a string and array on each tick, and then re-looping over that array and copying it to another array.
  • Clean up axismove event abstraction, removing callbacks, and object/array creations.
  • Don't need to call updateControllersList in the isControllerPresent util. This didn't really do anything since controllers were picked up through the controllersupdate event rather than within here.
  • Various cleanups include removing unused properties (axisLabels), fixing 95-char lengths, and cleaner comments.
this.onButtonUp = function (evt) { self.onButtonEvent(evt.detail.id, 'up'); };
this.onButtonTouchStart = function (evt) { self.onButtonEvent(evt.detail.id, 'touchstart'); };
this.onButtonTouchEnd = function (evt) { self.onButtonEvent(evt.detail.id, 'touchend'); };
this.onButtonDown = function (evt) {
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 keep the one liners. It makes the code harder to parse?

Copy link
Member Author

Choose a reason for hiding this comment

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

Some were going over a character limit causing them to wrap. Want me to revert still?

Copy link
Member

Choose a reason for hiding this comment

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

I think it's ok going over the character limit in same cases to avoid contortions and breaking style consistency

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed it

this.onButtonUp = function (evt) {
self.onButtonEvent(evt.detail.id, 'up');
};
this.onButtonTouchStart = function (evt) {
Copy link
Member

Choose a reason for hiding this comment

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

one liner

self.onButtonEvent(evt.detail.id, 'up');
};
this.onButtonTouchStart = function (evt) {
self.onButtonEvent(evt.detail.id, 'touchstart');
Copy link
Member

Choose a reason for hiding this comment

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

one liner

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah i can catch them all if you just note 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.

though i missed this file xD

this.onButtonTouchStart = function (evt) {
self.onButtonEvent(evt.detail.id, 'touchstart');
};
this.onButtonTouchEnd = function (evt) {
Copy link
Member

Choose a reason for hiding this comment

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

one liner

buttonMeshes.system = controllerObject3D.getObjectByName('HomeButton_HomeButton_Cylinder.005');
buttonMeshes.trackpad = controllerObject3D.getObjectByName('TouchPad_TouchPad_Cylinder.003');
// Offset pivot point
buttonMeshes.menu = controllerObject3D.getObjectByName(
Copy link
Member

Choose a reason for hiding this comment

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

If needed I think it looks better to break the whole expression to the line below instead of just an argument

Copy link
Member Author

Choose a reason for hiding this comment

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

i'll just restore to one liners

@fernandojsg
Copy link
Member

I believe it could be nice to have the tick ms as a parameter, for some applications 500ms it could be way too much

@ngokevin
Copy link
Member Author

ngokevin commented Aug 8, 2017

It just detects new controllers right? Half a second isn't much

@fernandojsg
Copy link
Member

@ngokevin my fault, I was thinking that the tick was in updating the position/rotation, not just on updating the list, I've checked the coded already O:)

@ngokevin
Copy link
Member Author

ngokevin commented Aug 8, 2017

Updated to save another couple object allocations and to skip type check per tracked controls per tick.

@machenmusik
Copy link
Contributor

machenmusik commented Aug 8, 2017

Has this been checked to ensure that controller pose update rate is unaffected in-VR? I know things have changed a lot since we started these... once upon a time, the only way the controller pose was updated was when it was grabbed by tracked-controls system tick, and then utilized by tracked-controls component tick

@machenmusik
Copy link
Contributor

Ok so I think the assumption is that the browser continues to make pose changes to the same controller object, which is still updated unthrottled by tracked-controls component tick, so unless some browser has done wacky things in its implementation, LGTM. Only quirk is if controller goes away, and we won't know it for up to 500ms; need to ensure that dying controller object state doesn't break things before detection.

@ngokevin
Copy link
Member Author

ngokevin commented Aug 8, 2017

Yeah, it'd be pretty noticeable if controllers only moved once every 500ms. The tracked-controls component handles the pose update. The system only handles detection for connected/disconnected so it's fine.

I'll double-check what happens on disconnect.

@dmarcos dmarcos merged commit df50647 into aframevr:master Aug 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

4 participants