2016-10-24 13:04:41 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
|
|
|
|
#include "mozilla/HoldDropJSObjects.h"
|
|
|
|
#include "mozilla/dom/GamepadPoseBinding.h"
|
|
|
|
#include "mozilla/dom/GamepadPose.h"
|
|
|
|
|
2020-11-04 20:04:01 +03:00
|
|
|
namespace mozilla::dom {
|
2016-10-24 13:04:41 +03:00
|
|
|
|
|
|
|
GamepadPose::GamepadPose(nsISupports* aParent, const GamepadPoseState& aState)
|
|
|
|
: Pose(aParent), mPoseState(aState) {
|
|
|
|
mozilla::HoldJSObjects(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
GamepadPose::GamepadPose(nsISupports* aParent) : Pose(aParent) {
|
|
|
|
mozilla::HoldJSObjects(this);
|
|
|
|
mPoseState.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
GamepadPose::~GamepadPose() { mozilla::DropJSObjects(this); }
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* virtual */
|
|
|
|
JSObject* GamepadPose::WrapObject(JSContext* aJSContext,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return GamepadPose_Binding::Wrap(aJSContext, this, aGivenProto);
|
2016-10-24 13:04:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GamepadPose::HasOrientation() const {
|
2018-08-30 01:09:48 +03:00
|
|
|
return bool(mPoseState.flags & GamepadCapabilityFlags::Cap_Orientation);
|
2016-10-24 13:04:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GamepadPose::HasPosition() const {
|
2020-04-21 14:17:34 +03:00
|
|
|
return bool(mPoseState.flags & GamepadCapabilityFlags::Cap_Position) ||
|
|
|
|
bool(mPoseState.flags & GamepadCapabilityFlags::Cap_PositionEmulated);
|
2016-10-24 13:04:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void GamepadPose::GetPosition(JSContext* aJSContext,
|
|
|
|
JS::MutableHandle<JSObject*> aRetval,
|
|
|
|
ErrorResult& aRv) {
|
2019-08-20 21:34:24 +03:00
|
|
|
const bool valid =
|
|
|
|
mPoseState.isPositionValid &&
|
2020-04-21 14:17:34 +03:00
|
|
|
(bool(mPoseState.flags & GamepadCapabilityFlags::Cap_Position) ||
|
|
|
|
bool(mPoseState.flags & GamepadCapabilityFlags::Cap_PositionEmulated));
|
2019-07-30 03:23:38 +03:00
|
|
|
SetFloat32Array(aJSContext, this, aRetval, mPosition,
|
2019-08-20 21:34:24 +03:00
|
|
|
valid ? mPoseState.position : nullptr, 3, aRv);
|
2016-10-24 13:04:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void GamepadPose::GetLinearVelocity(JSContext* aJSContext,
|
|
|
|
JS::MutableHandle<JSObject*> aRetval,
|
|
|
|
ErrorResult& aRv) {
|
2019-08-20 21:34:24 +03:00
|
|
|
const bool valid =
|
|
|
|
mPoseState.isPositionValid &&
|
2020-04-21 14:17:34 +03:00
|
|
|
(bool(mPoseState.flags & GamepadCapabilityFlags::Cap_Position) ||
|
|
|
|
bool(mPoseState.flags & GamepadCapabilityFlags::Cap_PositionEmulated));
|
2019-08-20 21:34:24 +03:00
|
|
|
SetFloat32Array(aJSContext, this, aRetval, mLinearVelocity,
|
|
|
|
valid ? mPoseState.linearVelocity : nullptr, 3, aRv);
|
2016-10-24 13:04:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void GamepadPose::GetLinearAcceleration(JSContext* aJSContext,
|
|
|
|
JS::MutableHandle<JSObject*> aRetval,
|
|
|
|
ErrorResult& aRv) {
|
2019-08-20 21:34:24 +03:00
|
|
|
const bool valid =
|
|
|
|
mPoseState.isPositionValid &&
|
|
|
|
bool(mPoseState.flags & GamepadCapabilityFlags::Cap_LinearAcceleration);
|
|
|
|
SetFloat32Array(aJSContext, this, aRetval, mLinearAcceleration,
|
|
|
|
valid ? mPoseState.linearAcceleration : nullptr, 3, aRv);
|
2016-10-24 13:04:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void GamepadPose::GetOrientation(JSContext* aJSContext,
|
|
|
|
JS::MutableHandle<JSObject*> aRetval,
|
|
|
|
ErrorResult& aRv) {
|
2019-08-20 21:34:24 +03:00
|
|
|
const bool valid =
|
|
|
|
mPoseState.isOrientationValid &&
|
|
|
|
bool(mPoseState.flags & GamepadCapabilityFlags::Cap_Orientation);
|
|
|
|
SetFloat32Array(aJSContext, this, aRetval, mOrientation,
|
|
|
|
valid ? mPoseState.orientation : nullptr, 4, aRv);
|
2016-10-24 13:04:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void GamepadPose::GetAngularVelocity(JSContext* aJSContext,
|
|
|
|
JS::MutableHandle<JSObject*> aRetval,
|
|
|
|
ErrorResult& aRv) {
|
2019-08-20 21:34:24 +03:00
|
|
|
const bool valid =
|
|
|
|
mPoseState.isOrientationValid &&
|
|
|
|
bool(mPoseState.flags & GamepadCapabilityFlags::Cap_Orientation);
|
|
|
|
SetFloat32Array(aJSContext, this, aRetval, mAngularVelocity,
|
|
|
|
valid ? mPoseState.angularVelocity : nullptr, 3, aRv);
|
2016-10-24 13:04:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void GamepadPose::GetAngularAcceleration(JSContext* aJSContext,
|
|
|
|
JS::MutableHandle<JSObject*> aRetval,
|
|
|
|
ErrorResult& aRv) {
|
2019-08-20 21:34:24 +03:00
|
|
|
const bool valid =
|
|
|
|
mPoseState.isOrientationValid &&
|
|
|
|
bool(mPoseState.flags & GamepadCapabilityFlags::Cap_AngularAcceleration);
|
|
|
|
SetFloat32Array(aJSContext, this, aRetval, mAngularAcceleration,
|
|
|
|
valid ? mPoseState.angularAcceleration : nullptr, 3, aRv);
|
2016-10-24 13:04:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void GamepadPose::SetPoseState(const GamepadPoseState& aPose) {
|
|
|
|
mPoseState = aPose;
|
|
|
|
}
|
|
|
|
|
|
|
|
const GamepadPoseState& GamepadPose::GetPoseState() { return mPoseState; }
|
|
|
|
|
2020-11-04 20:04:01 +03:00
|
|
|
} // namespace mozilla::dom
|