rework ScriptValue to act like a stack variable rather than a pointer

This commit is contained in:
Heather Anderson 2021-09-03 01:09:00 -07:00 committed by ksuprynowicz
parent f209c5124d
commit 8581022a53
170 changed files with 2852 additions and 2609 deletions
assignment-client/src
interface/src
libraries
animation/src
audio-client
audio/src
avatars/src
baking/src
controllers/src/controllers
entities-renderer/src
entities/src
graphics-scripting/src/graphics-scripting

View file

@ -505,8 +505,8 @@ void Agent::executeScript() {
scriptEngine->registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCacheScriptingInterface>().data());
scriptEngine->registerGlobalObject("SoundCache", DependencyManager::get<SoundCacheScriptingInterface>().data());
ScriptValuePointer webSocketServerConstructorValue = scriptEngine->newFunction(WebSocketServerClass::constructor);
scriptEngine->globalObject()->setProperty("WebSocketServer", webSocketServerConstructorValue);
ScriptValue webSocketServerConstructorValue = scriptEngine->newFunction(WebSocketServerClass::constructor);
scriptEngine->globalObject().setProperty("WebSocketServer", webSocketServerConstructorValue);
auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();

View file

@ -452,7 +452,7 @@ void EntityScriptServer::resetEntitiesScriptEngine() {
auto newEngine = newManager->engine();
auto webSocketServerConstructorValue = newEngine->newFunction(WebSocketServerClass::constructor);
newEngine->globalObject()->setProperty("WebSocketServer", webSocketServerConstructorValue);
newEngine->globalObject().setProperty("WebSocketServer", webSocketServerConstructorValue);
newEngine->registerGlobalObject("SoundCache", DependencyManager::get<SoundCacheScriptingInterface>().data());
newEngine->registerGlobalObject("AvatarList", DependencyManager::get<AvatarHashMap>().data());

View file

@ -55,7 +55,7 @@ void addAvatarEntities(const QVariantList& avatarEntities) {
const QVariantMap& avatarEntityProperties = avatarEntities.at(index).toMap();
QVariant variantProperties = avatarEntityProperties["properties"];
QVariantMap asMap = variantProperties.toMap();
ScriptValuePointer scriptProperties = variantMapToScriptValue(asMap, *scriptEngine);
ScriptValue scriptProperties = variantMapToScriptValue(asMap, *scriptEngine);
EntityItemProperties entityProperties;
EntityItemPropertiesFromScriptValueIgnoreReadOnly(scriptProperties, entityProperties);
@ -322,8 +322,8 @@ QVariantMap AvatarBookmarks::getAvatarDataToBookmark() {
desiredProperties -= PROP_JOINT_TRANSLATIONS;
EntityItemProperties entityProperties = entity->getProperties(desiredProperties);
ScriptValuePointer scriptProperties = EntityItemPropertiesToScriptValue(scriptEngine.get(), entityProperties);
avatarEntityData["properties"] = scriptProperties->toVariant();
ScriptValue scriptProperties = EntityItemPropertiesToScriptValue(scriptEngine.get(), entityProperties);
avatarEntityData["properties"] = scriptProperties.toVariant();
wearableEntities.append(QVariant(avatarEntityData));
}
}

View file

@ -426,13 +426,13 @@ WorldDetailQuality LODManager::getWorldDetailQuality() const {
return qApp->isHMDMode() ? _hmdWorldDetailQuality : _desktopWorldDetailQuality;
}
ScriptValuePointer worldDetailQualityToScriptValue(ScriptEngine* engine, const WorldDetailQuality& worldDetailQuality) {
ScriptValue worldDetailQualityToScriptValue(ScriptEngine* engine, const WorldDetailQuality& worldDetailQuality) {
return engine->newValue(worldDetailQuality);
}
void worldDetailQualityFromScriptValue(const ScriptValuePointer& object, WorldDetailQuality& worldDetailQuality) {
void worldDetailQualityFromScriptValue(const ScriptValue& object, WorldDetailQuality& worldDetailQuality) {
worldDetailQuality =
static_cast<WorldDetailQuality>(std::min(std::max(object->toInt32(), (int)WORLD_DETAIL_LOW), (int)WORLD_DETAIL_HIGH));
static_cast<WorldDetailQuality>(std::min(std::max(object.toInt32(), (int)WORLD_DETAIL_LOW), (int)WORLD_DETAIL_HIGH));
}
void LODManager::setLODQualityLevel(float quality) {

View file

@ -14,7 +14,6 @@
#define hifi_LODManager_h
#include <mutex>
#include <QtCore/QSharedPointer>
#include <DependencyManager.h>
#include <NumericalConstants.h>
@ -23,10 +22,9 @@
#include <PIDController.h>
#include <SimpleMovingAverage.h>
#include <render/Args.h>
#include <ScriptValue.h>
class ScriptEngine;
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
/*@jsdoc
* <p>The world detail quality rendered.</p>
@ -384,7 +382,7 @@ private:
glm::vec4 _pidOutputs{ 0.0f };
};
ScriptValuePointer worldDetailQualityToScriptValue(ScriptEngine* engine, const WorldDetailQuality& worldDetailQuality);
void worldDetailQualityFromScriptValue(const ScriptValuePointer& object, WorldDetailQuality& worldDetailQuality);
ScriptValue worldDetailQualityToScriptValue(ScriptEngine* engine, const WorldDetailQuality& worldDetailQuality);
void worldDetailQualityFromScriptValue(const ScriptValue& object, WorldDetailQuality& worldDetailQuality);
#endif // hifi_LODManager_h

View file

@ -736,8 +736,8 @@ AvatarSharedPointer AvatarManager::getAvatarBySessionID(const QUuid& sessionID)
}
RayToAvatarIntersectionResult AvatarManager::findRayIntersection(const PickRay& ray,
const ScriptValuePointer& avatarIdsToInclude,
const ScriptValuePointer& avatarIdsToDiscard,
const ScriptValue& avatarIdsToInclude,
const ScriptValue& avatarIdsToDiscard,
bool pickAgainstMesh) {
QVector<EntityItemID> avatarsToInclude = qVectorEntityItemIDFromScriptValue(avatarIdsToInclude);
QVector<EntityItemID> avatarsToDiscard = qVectorEntityItemIDFromScriptValue(avatarIdsToDiscard);
@ -981,10 +981,10 @@ float AvatarManager::getAvatarSortCoefficient(const QString& name) {
}
// HACK
void AvatarManager::setAvatarSortCoefficient(const QString& name, const ScriptValuePointer& value) {
void AvatarManager::setAvatarSortCoefficient(const QString& name, const ScriptValue& value) {
bool somethingChanged = false;
if (value->isNumber()) {
float numericalValue = (float)value->toNumber();
if (value.isNumber()) {
float numericalValue = (float)value.toNumber();
if (name == "size") {
AvatarData::_avatarSortCoefficientSize = numericalValue;
somethingChanged = true;

View file

@ -26,6 +26,7 @@
#include <AudioInjectorManager.h>
#include <workload/Space.h>
#include <EntitySimulation.h> // for SetOfEntities
#include <ScriptValue.h>
#include "AvatarMotionState.h"
#include "DetailedMotionState.h"
@ -33,9 +34,7 @@
#include "OtherAvatar.h"
class ScriptEngine;
class ScriptValue;
using SortedAvatar = std::pair<float, std::shared_ptr<Avatar>>;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
/*@jsdoc
* The <code>AvatarManager</code> API provides information about avatars within the current domain. The avatars available are
@ -187,8 +186,8 @@ public:
* }
*/
Q_INVOKABLE RayToAvatarIntersectionResult findRayIntersection(const PickRay& ray,
const ScriptValuePointer& avatarIdsToInclude = ScriptValuePointer(),
const ScriptValuePointer& avatarIdsToDiscard = ScriptValuePointer(),
const ScriptValue& avatarIdsToInclude = ScriptValue(),
const ScriptValue& avatarIdsToDiscard = ScriptValue(),
bool pickAgainstMesh = true);
/*@jsdoc
* @function AvatarManager.findRayIntersectionVector
@ -231,7 +230,7 @@ public:
* @param {number} value - Value.
* @deprecated This function is deprecated and will be removed.
*/
Q_INVOKABLE void setAvatarSortCoefficient(const QString& name, const ScriptValuePointer& value);
Q_INVOKABLE void setAvatarSortCoefficient(const QString& name, const ScriptValue& value);
/*@jsdoc
* Gets PAL (People Access List) data for one or more avatars. Using this method is faster than iterating over each avatar

View file

@ -440,15 +440,15 @@ void MyAvatar::enableHandTouchForID(const QUuid& entityID) {
}
void MyAvatar::registerMetaTypes(ScriptEnginePointer engine) {
ScriptValuePointer value = engine->newQObject(this, ScriptEngine::QtOwnership);
engine->globalObject()->setProperty("MyAvatar", value);
ScriptValue value = engine->newQObject(this, ScriptEngine::QtOwnership);
engine->globalObject().setProperty("MyAvatar", value);
ScriptValuePointer driveKeys = engine->newObject();
ScriptValue driveKeys = engine->newObject();
auto metaEnum = QMetaEnum::fromType<DriveKeys>();
for (int i = 0; i < MAX_DRIVE_KEYS; ++i) {
driveKeys->setProperty(metaEnum.key(i), metaEnum.value(i));
driveKeys.setProperty(metaEnum.key(i), metaEnum.value(i));
}
engine->globalObject()->setProperty("DriveKeys", driveKeys);
engine->globalObject().setProperty("DriveKeys", driveKeys);
scriptRegisterMetaType(engine.data(), audioListenModeToScriptValue, audioListenModeFromScriptValue);
scriptRegisterMetaType(engine.data(), driveKeysToScriptValue, driveKeysFromScriptValue);
@ -2674,8 +2674,8 @@ QVariantList MyAvatar::getAvatarEntitiesVariant() {
EntityItemProperties entityProperties = entity->getProperties(desiredProperties);
{
std::lock_guard<std::mutex> guard(_scriptEngineLock);
ScriptValuePointer scriptProperties = EntityItemPropertiesToScriptValue(_scriptEngine.data(), entityProperties);
avatarEntityData["properties"] = scriptProperties->toVariant();
ScriptValue scriptProperties = EntityItemPropertiesToScriptValue(_scriptEngine.data(), entityProperties);
avatarEntityData["properties"] = scriptProperties.toVariant();
}
avatarEntitiesData.append(QVariant(avatarEntityData));
}
@ -5704,20 +5704,20 @@ void MyAvatar::setAudioListenerMode(AudioListenerMode audioListenerMode) {
}
}
ScriptValuePointer audioListenModeToScriptValue(ScriptEngine* engine, const AudioListenerMode& audioListenerMode) {
ScriptValue audioListenModeToScriptValue(ScriptEngine* engine, const AudioListenerMode& audioListenerMode) {
return engine->newValue(audioListenerMode);
}
void audioListenModeFromScriptValue(const ScriptValuePointer& object, AudioListenerMode& audioListenerMode) {
audioListenerMode = static_cast<AudioListenerMode>(object->toUInt16());
void audioListenModeFromScriptValue(const ScriptValue& object, AudioListenerMode& audioListenerMode) {
audioListenerMode = static_cast<AudioListenerMode>(object.toUInt16());
}
ScriptValuePointer driveKeysToScriptValue(ScriptEngine* engine, const MyAvatar::DriveKeys& driveKeys) {
ScriptValue driveKeysToScriptValue(ScriptEngine* engine, const MyAvatar::DriveKeys& driveKeys) {
return engine->newValue(driveKeys);
}
void driveKeysFromScriptValue(const ScriptValuePointer& object, MyAvatar::DriveKeys& driveKeys) {
driveKeys = static_cast<MyAvatar::DriveKeys>(object->toUInt16());
void driveKeysFromScriptValue(const ScriptValue& object, MyAvatar::DriveKeys& driveKeys) {
driveKeys = static_cast<MyAvatar::DriveKeys>(object.toUInt16());
}

View file

@ -32,6 +32,7 @@
#include <SettingHandle.h>
#include <Sound.h>
#include <shared/Camera.h>
#include <ScriptValue.h>
#include "AtRestDetector.h"
#include "MyCharacterController.h"
@ -42,8 +43,6 @@ class ModelItemID;
class MyHead;
class DetailedMotionState;
class ScriptEngine;
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
using ScriptEnginePointer = QSharedPointer<ScriptEngine>;
/*@jsdoc
@ -874,7 +873,7 @@ public:
* MyAvatar.removeAnimationStateHandler(handler);
* }, 100);
*/
Q_INVOKABLE ScriptValuePointer addAnimationStateHandler(ScriptValuePointer handler, ScriptValuePointer propertiesList) { return _skeletonModel->getRig().addAnimationStateHandler(handler, propertiesList); }
Q_INVOKABLE ScriptValue addAnimationStateHandler(const ScriptValue& handler, const ScriptValue& propertiesList) { return _skeletonModel->getRig().addAnimationStateHandler(handler, propertiesList); }
/*@jsdoc
* Removes an animation state handler function.
@ -882,7 +881,7 @@ public:
* @param {number} handler - The ID of the animation state handler function to remove.
*/
// Removes a handler previously added by addAnimationStateHandler.
Q_INVOKABLE void removeAnimationStateHandler(ScriptValuePointer handler) { _skeletonModel->getRig().removeAnimationStateHandler(handler); }
Q_INVOKABLE void removeAnimationStateHandler(const ScriptValue& handler) { _skeletonModel->getRig().removeAnimationStateHandler(handler); }
/*@jsdoc
@ -3120,11 +3119,11 @@ private:
QTimer _addAvatarEntitiesToTreeTimer;
};
ScriptValuePointer audioListenModeToScriptValue(ScriptEngine* engine, const AudioListenerMode& audioListenerMode);
void audioListenModeFromScriptValue(const ScriptValuePointer& object, AudioListenerMode& audioListenerMode);
ScriptValue audioListenModeToScriptValue(ScriptEngine* engine, const AudioListenerMode& audioListenerMode);
void audioListenModeFromScriptValue(const ScriptValue& object, AudioListenerMode& audioListenerMode);
ScriptValuePointer driveKeysToScriptValue(ScriptEngine* engine, const MyAvatar::DriveKeys& driveKeys);
void driveKeysFromScriptValue(const ScriptValuePointer& object, MyAvatar::DriveKeys& driveKeys);
ScriptValue driveKeysToScriptValue(ScriptEngine* engine, const MyAvatar::DriveKeys& driveKeys);
void driveKeysFromScriptValue(const ScriptValue& object, MyAvatar::DriveKeys& driveKeys);
bool isWearableEntity(const EntityItemPointer& entity);

View file

@ -14,11 +14,11 @@
#include "PointerScriptingInterface.h"
#include <ScriptValueUtils.h>
void LaserPointerScriptingInterface::setIgnoreItems(unsigned int uid, const ScriptValuePointer& ignoreItems) const {
void LaserPointerScriptingInterface::setIgnoreItems(unsigned int uid, const ScriptValue& ignoreItems) const {
DependencyManager::get<PointerManager>()->setIgnoreItems(uid, qVectorQUuidFromScriptValue(ignoreItems));
}
void LaserPointerScriptingInterface::setIncludeItems(unsigned int uid, const ScriptValuePointer& includeItems) const {
void LaserPointerScriptingInterface::setIncludeItems(unsigned int uid, const ScriptValue& includeItems) const {
DependencyManager::get<PointerManager>()->setIncludeItems(uid, qVectorQUuidFromScriptValue(includeItems));
}

View file

@ -12,13 +12,11 @@
#define hifi_LaserPointerScriptingInterface_h
#include <QtCore/QObject>
#include <QtCore/QSharedPointer>
#include "DependencyManager.h"
#include <PointerManager.h>
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
class LaserPointerScriptingInterface : public QObject, public Dependency {
Q_OBJECT
@ -117,7 +115,7 @@ public:
* @param {number} id - The ID of the pointer.
* @param {Uuid[]} ignoreItems - A list of IDs to ignore.
*/
Q_INVOKABLE void setIgnoreItems(unsigned int uid, const ScriptValuePointer& ignoreEntities) const;
Q_INVOKABLE void setIgnoreItems(unsigned int uid, const ScriptValue& ignoreEntities) const;
/*@jsdoc
* Sets a list of entity and avatar IDs that a pointer should include during intersection, instead of intersecting with
@ -126,7 +124,7 @@ public:
* @param {number} id - The ID of the pointer.
* @param {Uuid[]} includeItems - A list of IDs to include.
*/
Q_INVOKABLE void setIncludeItems(unsigned int uid, const ScriptValuePointer& includeEntities) const;
Q_INVOKABLE void setIncludeItems(unsigned int uid, const ScriptValue& includeEntities) const;
/*@jsdoc

View file

@ -427,11 +427,11 @@ void PickScriptingInterface::setPrecisionPicking(unsigned int uid, bool precisio
DependencyManager::get<PickManager>()->setPrecisionPicking(uid, precisionPicking);
}
void PickScriptingInterface::setIgnoreItems(unsigned int uid, const ScriptValuePointer& ignoreItems) {
void PickScriptingInterface::setIgnoreItems(unsigned int uid, const ScriptValue& ignoreItems) {
DependencyManager::get<PickManager>()->setIgnoreItems(uid, qVectorQUuidFromScriptValue(ignoreItems));
}
void PickScriptingInterface::setIncludeItems(unsigned int uid, const ScriptValuePointer& includeItems) {
void PickScriptingInterface::setIncludeItems(unsigned int uid, const ScriptValue& includeItems) {
DependencyManager::get<PickManager>()->setIncludeItems(uid, qVectorQUuidFromScriptValue(includeItems));
}
@ -447,21 +447,21 @@ bool PickScriptingInterface::isMouse(unsigned int uid) {
return DependencyManager::get<PickManager>()->isMouse(uid);
}
ScriptValuePointer pickTypesToScriptValue(ScriptEngine* engine, const PickQuery::PickType& pickType) {
ScriptValue pickTypesToScriptValue(ScriptEngine* engine, const PickQuery::PickType& pickType) {
return engine->newValue(pickType);
}
void pickTypesFromScriptValue(const ScriptValuePointer& object, PickQuery::PickType& pickType) {
pickType = static_cast<PickQuery::PickType>(object->toUInt16());
void pickTypesFromScriptValue(const ScriptValue& object, PickQuery::PickType& pickType) {
pickType = static_cast<PickQuery::PickType>(object.toUInt16());
}
void PickScriptingInterface::registerMetaTypes(ScriptEngine* engine) {
ScriptValuePointer pickTypes = engine->newObject();
ScriptValue pickTypes = engine->newObject();
auto metaEnum = QMetaEnum::fromType<PickQuery::PickType>();
for (int i = 0; i < PickQuery::PickType::NUM_PICK_TYPES; ++i) {
pickTypes->setProperty(metaEnum.key(i), metaEnum.value(i));
pickTypes.setProperty(metaEnum.key(i), metaEnum.value(i));
}
engine->globalObject()->setProperty("PickType", pickTypes);
engine->globalObject().setProperty("PickType", pickTypes);
scriptRegisterMetaType(engine, pickTypesToScriptValue, pickTypesFromScriptValue);
}

View file

@ -9,7 +9,6 @@
#define hifi_PickScriptingInterface_h
#include <QtCore/QObject>
#include <QtCore/QSharedPointer>
#include <DependencyManager.h>
#include <PhysicsEngine.h>
@ -18,7 +17,6 @@
class ScriptEngine;
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
/*@jsdoc
* The <code>Picks</code> API lets you create and manage objects for repeatedly calculating intersections.
@ -250,7 +248,7 @@ public:
* @param {number} id - The ID of the pick.
* @param {Uuid[]} ignoreItems - The list of IDs to ignore.
*/
Q_INVOKABLE void setIgnoreItems(unsigned int uid, const ScriptValuePointer& ignoreItems);
Q_INVOKABLE void setIgnoreItems(unsigned int uid, const ScriptValue& ignoreItems);
/*@jsdoc
* Sets a list of entity and avatar IDs that a pick should include during intersection, instead of intersecting with
@ -260,7 +258,7 @@ public:
* @param {number} id - The ID of the pick.
* @param {Uuid[]} includeItems - The list of IDs to include.
*/
Q_INVOKABLE void setIncludeItems(unsigned int uid, const ScriptValuePointer& includeItems);
Q_INVOKABLE void setIncludeItems(unsigned int uid, const ScriptValue& includeItems);
/*@jsdoc
* Checks if a pick is associated with the left hand: a ray or parabola pick with <code>joint</code> property set to

View file

@ -25,11 +25,11 @@ static const glm::quat X_ROT_NEG_90{ 0.70710678f, -0.70710678f, 0.0f, 0.0f };
static const glm::vec3 DEFAULT_POSITION_OFFSET{0.0f, 0.0f, -StylusPick::WEB_STYLUS_LENGTH / 2.0f};
static const glm::vec3 DEFAULT_MODEL_DIMENSIONS{0.01f, 0.01f, StylusPick::WEB_STYLUS_LENGTH};
void PointerScriptingInterface::setIgnoreItems(unsigned int uid, const ScriptValuePointer& ignoreItems) const {
void PointerScriptingInterface::setIgnoreItems(unsigned int uid, const ScriptValue& ignoreItems) const {
DependencyManager::get<PointerManager>()->setIgnoreItems(uid, qVectorQUuidFromScriptValue(ignoreItems));
}
void PointerScriptingInterface::setIncludeItems(unsigned int uid, const ScriptValuePointer& includeItems) const {
void PointerScriptingInterface::setIncludeItems(unsigned int uid, const ScriptValue& includeItems) const {
DependencyManager::get<PointerManager>()->setIncludeItems(uid, qVectorQUuidFromScriptValue(includeItems));
}

View file

@ -9,7 +9,6 @@
#define hifi_PointerScriptingInterface_h
#include <QtCore/QObject>
#include <QtCore/QSharedPointer>
#include "DependencyManager.h"
#include "RegisteredMetaTypes.h"
@ -17,7 +16,6 @@
#include <Pick.h>
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
/*@jsdoc
* The <code>Pointers</code> API lets you create, manage, and visually represent objects for repeatedly calculating
@ -369,7 +367,7 @@ public:
* @param {number} id - The ID of the pointer.
* @param {Uuid[]} ignoreItems - A list of IDs to ignore.
*/
Q_INVOKABLE void setIgnoreItems(unsigned int uid, const ScriptValuePointer& ignoreEntities) const;
Q_INVOKABLE void setIgnoreItems(unsigned int uid, const ScriptValue& ignoreEntities) const;
/*@jsdoc
* Sets a list of entity and avatar IDs that a pointer should include during intersection, instead of intersecting with
@ -379,7 +377,7 @@ public:
* @param {number} id - The ID of the pointer.
* @param {Uuid[]} includeItems - A list of IDs to include.
*/
Q_INVOKABLE void setIncludeItems(unsigned int uid, const ScriptValuePointer& includeEntities) const;
Q_INVOKABLE void setIncludeItems(unsigned int uid, const ScriptValue& includeEntities) const;
/*@jsdoc

View file

@ -46,11 +46,11 @@ void RayPickScriptingInterface::setPrecisionPicking(unsigned int uid, bool preci
DependencyManager::get<PickManager>()->setPrecisionPicking(uid, precisionPicking);
}
void RayPickScriptingInterface::setIgnoreItems(unsigned int uid, const ScriptValuePointer& ignoreItems) {
void RayPickScriptingInterface::setIgnoreItems(unsigned int uid, const ScriptValue& ignoreItems) {
DependencyManager::get<PickManager>()->setIgnoreItems(uid, qVectorQUuidFromScriptValue(ignoreItems));
}
void RayPickScriptingInterface::setIncludeItems(unsigned int uid, const ScriptValuePointer& includeItems) {
void RayPickScriptingInterface::setIncludeItems(unsigned int uid, const ScriptValue& includeItems) {
DependencyManager::get<PickManager>()->setIncludeItems(uid, qVectorQUuidFromScriptValue(includeItems));
}

View file

@ -12,7 +12,6 @@
#define hifi_RayPickScriptingInterface_h
#include <QtCore/QObject>
#include <QtCore/QSharedPointer>
#include "RegisteredMetaTypes.h"
#include <DependencyManager.h>
@ -20,7 +19,6 @@
#include "PickScriptingInterface.h"
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
/*@jsdoc
* The <code>RayPick</code> API is a subset of the {@link Picks} API, as used for ray picks.
@ -125,7 +123,7 @@ public:
* @param {number} id - The ID of the ray pick.
* @param {Uuid[]} ignoreItems - The list of IDs to ignore.
*/
Q_INVOKABLE void setIgnoreItems(unsigned int uid, const ScriptValuePointer& ignoreEntities);
Q_INVOKABLE void setIgnoreItems(unsigned int uid, const ScriptValue& ignoreEntities);
/*@jsdoc
* Sets a list of entity and avatar IDs that a ray pick should include during intersection, instead of intersecting with
@ -134,7 +132,7 @@ public:
* @param {number} id - The ID of the ray pick.
* @param {Uuid[]} includeItems - The list of IDs to include.
*/
Q_INVOKABLE void setIncludeItems(unsigned int uid, const ScriptValuePointer& includeEntities);
Q_INVOKABLE void setIncludeItems(unsigned int uid, const ScriptValue& includeEntities);
/*@jsdoc

View file

@ -123,27 +123,27 @@ DownloadInfoResult::DownloadInfoResult() :
* @property {number[]} downloading - The download percentage remaining of each asset currently downloading.
* @property {number} pending - The number of assets pending download.
*/
ScriptValuePointer DownloadInfoResultToScriptValue(ScriptEngine* engine, const DownloadInfoResult& result) {
ScriptValuePointer object = engine->newObject();
ScriptValue DownloadInfoResultToScriptValue(ScriptEngine* engine, const DownloadInfoResult& result) {
ScriptValue object = engine->newObject();
ScriptValuePointer array = engine->newArray(result.downloading.count());
ScriptValue array = engine->newArray(result.downloading.count());
for (int i = 0; i < result.downloading.count(); i += 1) {
array->setProperty(i, result.downloading[i]);
array.setProperty(i, result.downloading[i]);
}
object->setProperty("downloading", array);
object->setProperty("pending", result.pending);
object.setProperty("downloading", array);
object.setProperty("pending", result.pending);
return object;
}
void DownloadInfoResultFromScriptValue(const ScriptValuePointer& object, DownloadInfoResult& result) {
QList<QVariant> downloading = object->property("downloading")->toVariant().toList();
void DownloadInfoResultFromScriptValue(const ScriptValue& object, DownloadInfoResult& result) {
QList<QVariant> downloading = object.property("downloading").toVariant().toList();
result.downloading.clear();
for (int i = 0; i < downloading.count(); i += 1) {
result.downloading.append(downloading[i].toFloat());
}
result.pending = object->property("pending")->toVariant().toFloat();
result.pending = object.property("pending").toVariant().toFloat();
}
DownloadInfoResult AccountServicesScriptingInterface::getDownloadInfo() {

View file

@ -15,14 +15,12 @@
#include <QObject>
#include <QString>
#include <QStringList>
#include <QtCore/QSharedPointer>
#include <AccountManager.h>
#include <DiscoverabilityManager.h>
#include <ScriptValue.h>
class ScriptEngine;
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
class DownloadInfoResult {
public:
@ -33,8 +31,8 @@ public:
Q_DECLARE_METATYPE(DownloadInfoResult)
ScriptValuePointer DownloadInfoResultToScriptValue(ScriptEngine* engine, const DownloadInfoResult& result);
void DownloadInfoResultFromScriptValue(const ScriptValuePointer& object, DownloadInfoResult& result);
ScriptValue DownloadInfoResultToScriptValue(ScriptEngine* engine, const DownloadInfoResult& result);
void DownloadInfoResultFromScriptValue(const ScriptValue& object, DownloadInfoResult& result);
class AccountServicesScriptingInterface : public QObject {
Q_OBJECT

View file

@ -152,7 +152,7 @@ bool HMDScriptingInterface::getAwayStateWhenFocusLostInVREnabled() {
}
ScriptValuePointer HMDScriptingInterface::getHUDLookAtPosition2D(ScriptContext* context, ScriptEngine* engine) {
ScriptValue HMDScriptingInterface::getHUDLookAtPosition2D(ScriptContext* context, ScriptEngine* engine) {
glm::vec3 hudIntersection;
auto instance = DependencyManager::get<HMDScriptingInterface>();
if (instance->getHUDLookAtPosition3D(hudIntersection)) {
@ -162,7 +162,7 @@ ScriptValuePointer HMDScriptingInterface::getHUDLookAtPosition2D(ScriptContext*
return engine->nullValue();
}
ScriptValuePointer HMDScriptingInterface::getHUDLookAtPosition3D(ScriptContext* context, ScriptEngine* engine) {
ScriptValue HMDScriptingInterface::getHUDLookAtPosition3D(ScriptContext* context, ScriptEngine* engine) {
glm::vec3 result;
auto instance = DependencyManager::get<HMDScriptingInterface>();
if (instance->getHUDLookAtPosition3D(result)) {

View file

@ -19,12 +19,10 @@
#include <display-plugins/AbstractHMDScriptingInterface.h>
#include <QReadWriteLock>
#include <QtCore/QSharedPointer>
#include <ScriptValue.h>
class ScriptContext;
class ScriptEngine;
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
/*@jsdoc
* The <code>HMD</code> API provides access to the HMD used in VR display mode.
@ -444,14 +442,14 @@ public:
* @function HMD.getHUDLookAtPosition2D
* @returns {Vec2} The position on the HUD overlay that your HMD is looking at, in pixels.
*/
static ScriptValuePointer getHUDLookAtPosition2D(ScriptContext* context, ScriptEngine* engine);
static ScriptValue getHUDLookAtPosition2D(ScriptContext* context, ScriptEngine* engine);
/*@jsdoc
* Gets the position on the HUD overlay that your HMD is looking at, in world coordinates.
* @function HMD.getHUDLookAtPosition3D
* @returns {Vec3} The position on the HUD overlay the your HMD is looking at, in world coordinates.
*/
static ScriptValuePointer getHUDLookAtPosition3D(ScriptContext* context, ScriptEngine* engine);
static ScriptValue getHUDLookAtPosition3D(ScriptContext* context, ScriptEngine* engine);
bool isMounted() const override;

View file

@ -154,9 +154,9 @@ void TestScriptingInterface::savePhysicsSimulationStats(QString originalPath) {
qApp->saveNextPhysicsStats(path);
}
void TestScriptingInterface::profileRange(const QString& name, ScriptValuePointer fn) {
void TestScriptingInterface::profileRange(const QString& name, const ScriptValue& fn) {
PROFILE_RANGE(script, name);
fn->call();
fn.call();
}
void TestScriptingInterface::clearCaches() {

View file

@ -12,10 +12,7 @@
#include <functional>
#include <QtCore/QObject>
#include <QtCore/QSharedPointer>
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
#include <ScriptValue.h>
class TestScriptingInterface : public QObject {
Q_OBJECT
@ -129,7 +126,7 @@ public slots:
* @param {string} name - Name used to reference the function
* @param {function} function - Function to profile
*/
Q_INVOKABLE void profileRange(const QString& name, ScriptValuePointer function);
Q_INVOKABLE void profileRange(const QString& name, const ScriptValue& function);
/*@jsdoc
* Clear all caches (menu command Reload Content)

View file

@ -76,7 +76,7 @@ WindowScriptingInterface::~WindowScriptingInterface() {
_messageBoxes.clear();
}
ScriptValuePointer WindowScriptingInterface::hasFocus() {
ScriptValue WindowScriptingInterface::hasFocus() {
return engine()->newValue(qApp->hasFocus());
}
@ -96,26 +96,26 @@ void WindowScriptingInterface::raise() {
/// Display an alert box
/// \param const QString& message message to display
/// \return ScriptValuePointer::UndefinedValue
/// \return ScriptValue::UndefinedValue
void WindowScriptingInterface::alert(const QString& message) {
OffscreenUi::asyncWarning("", message, QMessageBox::Ok, QMessageBox::Ok);
}
/// Display a confirmation box with the options 'Yes' and 'No'
/// \param const QString& message message to display
/// \return ScriptValuePointer `true` if 'Yes' was clicked, `false` otherwise
ScriptValuePointer WindowScriptingInterface::confirm(const QString& message) {
/// \return ScriptValue `true` if 'Yes' was clicked, `false` otherwise
ScriptValue WindowScriptingInterface::confirm(const QString& message) {
return engine()->newValue((QMessageBox::Yes == OffscreenUi::question("", message, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes)));
}
/// Display a prompt with a text box
/// \param const QString& message message to display
/// \param const QString& defaultText default text in the text box
/// \return ScriptValuePointer string text value in text box if the dialog was accepted, `null` otherwise.
ScriptValuePointer WindowScriptingInterface::prompt(const QString& message, const QString& defaultText) {
/// \return ScriptValue string text value in text box if the dialog was accepted, `null` otherwise.
ScriptValue WindowScriptingInterface::prompt(const QString& message, const QString& defaultText) {
QString result = OffscreenUi::getText(nullptr, "", message, QLineEdit::Normal, defaultText);
auto sResult = engine()->newValue(result);
if (sResult->equals(engine()->newValue(""))) {
if (sResult.equals(engine()->newValue(""))) {
return engine()->nullValue();
}
return sResult;
@ -218,8 +218,8 @@ void WindowScriptingInterface::ensureReticleVisible() const {
/// working directory.
/// \param const QString& title title of the window
/// \param const QString& directory directory to start the directory browser at
/// \return ScriptValuePointer file path as a string if one was selected, otherwise `ScriptValuePointer::NullValue`
ScriptValuePointer WindowScriptingInterface::browseDir(const QString& title, const QString& directory) {
/// \return ScriptValue file path as a string if one was selected, otherwise `ScriptValue::NullValue`
ScriptValue WindowScriptingInterface::browseDir(const QString& title, const QString& directory) {
ensureReticleVisible();
QString path = directory;
if (path.isEmpty()) {
@ -262,8 +262,8 @@ void WindowScriptingInterface::browseDirAsync(const QString& title, const QStrin
/// \param const QString& title title of the window
/// \param const QString& directory directory to start the file browser at
/// \param const QString& nameFilter filter to filter filenames by - see `QFileDialog`
/// \return ScriptValuePointer file path as a string if one was selected, otherwise `ScriptValuePointer::NullValue`
ScriptValuePointer WindowScriptingInterface::browse(const QString& title, const QString& directory, const QString& nameFilter) {
/// \return ScriptValue file path as a string if one was selected, otherwise `ScriptValue::NullValue`
ScriptValue WindowScriptingInterface::browse(const QString& title, const QString& directory, const QString& nameFilter) {
ensureReticleVisible();
QString path = directory;
if (path.isEmpty()) {
@ -309,8 +309,8 @@ void WindowScriptingInterface::browseAsync(const QString& title, const QString&
/// \param const QString& title title of the window
/// \param const QString& directory directory to start the file browser at
/// \param const QString& nameFilter filter to filter filenames by - see `QFileDialog`
/// \return ScriptValuePointer file path as a string if one was selected, otherwise `ScriptValuePointer::NullValue`
ScriptValuePointer WindowScriptingInterface::save(const QString& title, const QString& directory, const QString& nameFilter) {
/// \return ScriptValue file path as a string if one was selected, otherwise `ScriptValue::NullValue`
ScriptValue WindowScriptingInterface::save(const QString& title, const QString& directory, const QString& nameFilter) {
ensureReticleVisible();
QString path = directory;
if (path.isEmpty()) {
@ -356,8 +356,8 @@ void WindowScriptingInterface::saveAsync(const QString& title, const QString& di
/// \param const QString& title title of the window
/// \param const QString& directory directory to start the asset browser at
/// \param const QString& nameFilter filter to filter asset names by - see `QFileDialog`
/// \return ScriptValuePointer asset path as a string if one was selected, otherwise `ScriptValuePointer::NullValue`
ScriptValuePointer WindowScriptingInterface::browseAssets(const QString& title, const QString& directory, const QString& nameFilter) {
/// \return ScriptValue asset path as a string if one was selected, otherwise `ScriptValue::NullValue`
ScriptValue WindowScriptingInterface::browseAssets(const QString& title, const QString& directory, const QString& nameFilter) {
ensureReticleVisible();
QString path = directory;
if (path.isEmpty()) {

View file

@ -18,15 +18,12 @@
#include <QtCore/QString>
#include <QtQuick/QQuickItem>
#include <QtWidgets/QMessageBox>
#include <QtCore/QSharedPointer>
#include <DependencyManager.h>
#include <Scriptable.h>
#include <ScriptValue.h>
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
/*@jsdoc
* The <code>Window</code> API provides various facilities not covered elsewhere, including: window dimensions, window focus,
* camera view, announcements, user connections, common dialog boxes, snapshots, file import, domain navigation, domain changes,
@ -74,7 +71,7 @@ public slots:
* @function Window.hasFocus
* @returns {boolean} <code>true</code> if the Interface window has focus, <code>false</code> if it doesn't.
*/
ScriptValuePointer hasFocus();
ScriptValue hasFocus();
/*@jsdoc
* Makes the Interface window have focus. On Windows, if Interface doesn't already have focus, the task bar icon flashes to
@ -109,7 +106,7 @@ public slots:
* var answer = Window.confirm("Are you sure?");
* print(answer); // true or false
*/
ScriptValuePointer confirm(const QString& message = "");
ScriptValue confirm(const QString& message = "");
/*@jsdoc
* Prompts the user to enter some text. Displays a modal dialog with a message and a text box, plus "OK" and "Cancel"
@ -126,7 +123,7 @@ public slots:
* print("User answer: " + answer);
* }
*/
ScriptValuePointer prompt(const QString& message, const QString& defaultText);
ScriptValue prompt(const QString& message, const QString& defaultText);
/*@jsdoc
* Prompts the user to enter some text. Displays a non-modal dialog with a message and a text box, plus "OK" and "Cancel"
@ -156,7 +153,7 @@ public slots:
* var directory = Window.browseDir("Select Directory", Paths.resources);
* print("Directory: " + directory);
*/
ScriptValuePointer browseDir(const QString& title = "", const QString& directory = "");
ScriptValue browseDir(const QString& title = "", const QString& directory = "");
/*@jsdoc
* Prompts the user to choose a directory. Displays a non-modal dialog that navigates the directory tree. A
@ -188,7 +185,7 @@ public slots:
* var filename = Window.browse("Select Image File", Paths.resources, "Images (*.png *.jpg *.svg)");
* print("File: " + filename);
*/
ScriptValuePointer browse(const QString& title = "", const QString& directory = "", const QString& nameFilter = "");
ScriptValue browse(const QString& title = "", const QString& directory = "", const QString& nameFilter = "");
/*@jsdoc
* Prompts the user to choose a file. Displays a non-modal dialog that navigates the directory tree. A
@ -224,7 +221,7 @@ public slots:
* var filename = Window.save("Save to JSON file", Paths.resources, "*.json");
* print("File: " + filename);
*/
ScriptValuePointer save(const QString& title = "", const QString& directory = "", const QString& nameFilter = "");
ScriptValue save(const QString& title = "", const QString& directory = "", const QString& nameFilter = "");
/*@jsdoc
* Prompts the user to specify the path and name of a file to save to. Displays a non-modal dialog that navigates the
@ -259,7 +256,7 @@ public slots:
* var asset = Window.browseAssets("Select FBX File", "/", "*.fbx");
* print("FBX file: " + asset);
*/
ScriptValuePointer browseAssets(const QString& title = "", const QString& directory = "", const QString& nameFilter = "");
ScriptValue browseAssets(const QString& title = "", const QString& directory = "", const QString& nameFilter = "");
/*@jsdoc
* Prompts the user to choose an Asset Server item. Displays a non-modal dialog that navigates the tree of assets on the

View file

@ -97,15 +97,13 @@ void registerInteractiveWindowMetaType(ScriptEngine* engine) {
scriptRegisterMetaType(engine, interactiveWindowPointerToScriptValue, interactiveWindowPointerFromScriptValue);
}
ScriptValuePointer interactiveWindowPointerToScriptValue(ScriptEngine* engine, const InteractiveWindowPointer& in) {
ScriptValue interactiveWindowPointerToScriptValue(ScriptEngine* engine, const InteractiveWindowPointer& in) {
return engine->newQObject(in, ScriptEngine::ScriptOwnership);
}
void interactiveWindowPointerFromScriptValue(const ScriptValuePointer& object, InteractiveWindowPointer& out) {
if (!object) {
if (const auto interactiveWindow = qobject_cast<InteractiveWindowPointer>(object->toQObject())) {
out = interactiveWindow;
}
void interactiveWindowPointerFromScriptValue(const ScriptValue& object, InteractiveWindowPointer& out) {
if (const auto interactiveWindow = qobject_cast<InteractiveWindowPointer>(object.toQObject())) {
out = interactiveWindow;
}
}

View file

@ -15,17 +15,15 @@
#define hifi_InteractiveWindow_h
#include <QtCore/QObject>
#include <QtCore/QSharedPointer>
#include <QtCore/QPointer>
#include <QQmlEngine>
#include <ui/QmlWrapper.h>
#include <glm/glm.hpp>
#include <GLMHelpers.h>
#include <ScriptValue.h>
class ScriptEngine;
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
class QmlWindowProxy : public QmlWrapper {
Q_OBJECT
@ -412,8 +410,8 @@ private:
typedef InteractiveWindow* InteractiveWindowPointer;
ScriptValuePointer interactiveWindowPointerToScriptValue(ScriptEngine* engine, const InteractiveWindowPointer& in);
void interactiveWindowPointerFromScriptValue(const ScriptValuePointer& object, InteractiveWindowPointer& out);
ScriptValue interactiveWindowPointerToScriptValue(ScriptEngine* engine, const InteractiveWindowPointer& in);
void interactiveWindowPointerFromScriptValue(const ScriptValue& object, InteractiveWindowPointer& out);
void registerInteractiveWindowMetaType(ScriptEngine* engine);

View file

@ -187,7 +187,7 @@ JSConsole::JSConsole(QWidget* parent, const ScriptManagerPointer& scriptManager)
resizeTextInput();
connect(&_executeWatcher, &QFutureWatcher<ScriptValuePointer>::finished, this, &JSConsole::commandFinished);
connect(&_executeWatcher, &QFutureWatcher<ScriptValue>::finished, this, &JSConsole::commandFinished);
}
void JSConsole::insertCompletion(const QModelIndex& completion) {
@ -351,12 +351,12 @@ void JSConsole::executeCommand(const QString& command) {
QWeakPointer<ScriptManager> weakScriptManager = _scriptManager;
auto consoleFileName = _consoleFileName;
QFuture<ScriptValuePointer> future = QtConcurrent::run([weakScriptManager, consoleFileName, command]() -> ScriptValuePointer {
ScriptValuePointer result;
QFuture<ScriptValue> future = QtConcurrent::run([weakScriptManager, consoleFileName, command]() -> ScriptValue {
ScriptValue result;
auto scriptManager = weakScriptManager.lock();
if (scriptManager) {
BLOCKING_INVOKE_METHOD(scriptManager.data(), "evaluate",
Q_RETURN_ARG(ScriptValuePointer, result),
Q_RETURN_ARG(ScriptValue, result),
Q_ARG(const QString&, command),
Q_ARG(const QString&, consoleFileName));
}
@ -366,7 +366,7 @@ void JSConsole::executeCommand(const QString& command) {
}
void JSConsole::commandFinished() {
ScriptValuePointer result = _executeWatcher.result();
ScriptValue result = _executeWatcher.result();
_ui->promptTextEdit->setDisabled(false);
@ -375,10 +375,10 @@ void JSConsole::commandFinished() {
_ui->promptTextEdit->setFocus();
}
bool error = (_scriptManager->engine()->hasUncaughtException() || (result && result->isError()));
bool error = (_scriptManager->engine()->hasUncaughtException() || result.isError());
QString gutter = error ? GUTTER_ERROR : GUTTER_PREVIOUS_COMMAND;
QString resultColor = error ? RESULT_ERROR_STYLE : RESULT_SUCCESS_STYLE;
QString resultStr = result ? "<span style='" + resultColor + "'>" + result->toString().toHtmlEscaped() + "</span>" : "";
QString resultStr = "<span style='" + resultColor + "'>" + result.toString().toHtmlEscaped() + "</span>";
appendMessage(gutter, resultStr);
resetCurrentCommandHistory();

View file

@ -16,14 +16,13 @@
#include <QObject>
#include <QCompleter>
#include <QtCore/QJsonArray>
#include <ScriptValue.h>
#include "ui_console.h"
class QStandardItemModel;
class ScriptManager;
class ScriptValue;
using ScriptManagerPointer = QSharedPointer<ScriptManager>;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
const QString CONSOLE_TITLE = "Scripting Console";
const float CONSOLE_WINDOW_OPACITY = 0.95f;
@ -71,7 +70,7 @@ private:
QStandardItemModel* getAutoCompleteModel(const QString& memberOf = nullptr);
QFutureWatcher<ScriptValuePointer> _executeWatcher;
QFutureWatcher<ScriptValue> _executeWatcher;
Ui::Console* _ui;
int _currentCommandInHistory;
QString _savedHistoryFilename;

View file

@ -633,7 +633,7 @@ EntityItemProperties Overlays::convertOverlayToEntityProperties(QVariantMap& ove
}
ScriptEnginePointer scriptEngine = newScriptEngine();
ScriptValuePointer props = variantMapToScriptValue(overlayProps, *scriptEngine);
ScriptValue props = variantMapToScriptValue(overlayProps, *scriptEngine);
EntityItemProperties toReturn;
EntityItemPropertiesFromScriptValueHonorReadOnly(props, toReturn);
return toReturn;
@ -641,7 +641,7 @@ EntityItemProperties Overlays::convertOverlayToEntityProperties(QVariantMap& ove
QVariantMap Overlays::convertEntityToOverlayProperties(const EntityItemProperties& properties) {
ScriptEnginePointer scriptEngine = newScriptEngine();
QVariantMap overlayProps = EntityItemPropertiesToScriptValue(scriptEngine.data(), properties)->toVariant().toMap();
QVariantMap overlayProps = EntityItemPropertiesToScriptValue(scriptEngine.data(), properties).toVariant().toMap();
QString type = overlayProps["type"].toString();
overlayProps["type"] = entityToOverlayType(type);
@ -1041,8 +1041,8 @@ QVariantMap Overlays::getOverlaysProperties(const QVariant& propertiesById) {
}
RayToOverlayIntersectionResult Overlays::findRayIntersection(const PickRay& ray, bool precisionPicking,
const ScriptValuePointer& overlayIDsToInclude,
const ScriptValuePointer& overlayIDsToDiscard,
const ScriptValue& overlayIDsToInclude,
const ScriptValue& overlayIDsToDiscard,
bool visibleOnly, bool collidableOnly) {
const QVector<EntityItemID> include = qVectorEntityItemIDFromScriptValue(overlayIDsToInclude);
const QVector<EntityItemID> discard = qVectorEntityItemIDFromScriptValue(overlayIDsToDiscard);
@ -1110,38 +1110,38 @@ ParabolaToOverlayIntersectionResult Overlays::findParabolaIntersectionVector(con
return overlayResult;
}
ScriptValuePointer RayToOverlayIntersectionResultToScriptValue(ScriptEngine* engine, const RayToOverlayIntersectionResult& value) {
ScriptValuePointer obj = engine->newObject();
obj->setProperty("intersects", value.intersects);
ScriptValuePointer overlayIDValue = quuidToScriptValue(engine, value.overlayID);
obj->setProperty("overlayID", overlayIDValue);
obj->setProperty("distance", value.distance);
obj->setProperty("face", boxFaceToString(value.face));
ScriptValue RayToOverlayIntersectionResultToScriptValue(ScriptEngine* engine, const RayToOverlayIntersectionResult& value) {
ScriptValue obj = engine->newObject();
obj.setProperty("intersects", value.intersects);
ScriptValue overlayIDValue = quuidToScriptValue(engine, value.overlayID);
obj.setProperty("overlayID", overlayIDValue);
obj.setProperty("distance", value.distance);
obj.setProperty("face", boxFaceToString(value.face));
ScriptValuePointer intersection = vec3ToScriptValue(engine, value.intersection);
obj->setProperty("intersection", intersection);
ScriptValuePointer surfaceNormal = vec3ToScriptValue(engine, value.surfaceNormal);
obj->setProperty("surfaceNormal", surfaceNormal);
obj->setProperty("extraInfo", engine->toScriptValue(value.extraInfo));
ScriptValue intersection = vec3ToScriptValue(engine, value.intersection);
obj.setProperty("intersection", intersection);
ScriptValue surfaceNormal = vec3ToScriptValue(engine, value.surfaceNormal);
obj.setProperty("surfaceNormal", surfaceNormal);
obj.setProperty("extraInfo", engine->toScriptValue(value.extraInfo));
return obj;
}
void RayToOverlayIntersectionResultFromScriptValue(const ScriptValuePointer& object, RayToOverlayIntersectionResult& value) {
value.intersects = object->property("intersects")->toVariant().toBool();
ScriptValuePointer overlayIDValue = object->property("overlayID");
void RayToOverlayIntersectionResultFromScriptValue(const ScriptValue& object, RayToOverlayIntersectionResult& value) {
value.intersects = object.property("intersects").toVariant().toBool();
ScriptValue overlayIDValue = object.property("overlayID");
quuidFromScriptValue(overlayIDValue, value.overlayID);
value.distance = object->property("distance")->toVariant().toFloat();
value.face = boxFaceFromString(object->property("face")->toVariant().toString());
value.distance = object.property("distance").toVariant().toFloat();
value.face = boxFaceFromString(object.property("face").toVariant().toString());
ScriptValuePointer intersection = object->property("intersection");
if (intersection->isValid()) {
ScriptValue intersection = object.property("intersection");
if (intersection.isValid()) {
vec3FromScriptValue(intersection, value.intersection);
}
ScriptValuePointer surfaceNormal = object->property("surfaceNormal");
if (surfaceNormal->isValid()) {
ScriptValue surfaceNormal = object.property("surfaceNormal");
if (surfaceNormal.isValid()) {
vec3FromScriptValue(surfaceNormal, value.surfaceNormal);
}
value.extraInfo = object->property("extraInfo")->toVariant().toMap();
value.extraInfo = object.property("extraInfo").toVariant().toMap();
}
bool Overlays::isLoaded(const QUuid& id) {

View file

@ -22,7 +22,7 @@
#include <QReadWriteLock>
#include <PointerEvent.h>
#include <QtCore/QSharedPointer>
#include <ScriptValue.h>
#include "Overlay.h"
@ -30,8 +30,6 @@
class PickRay;
class ScriptEngine;
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
/*@jsdoc
* The result of a {@link PickRay} search using {@link Overlays.findRayIntersection|findRayIntersection}.
@ -55,8 +53,8 @@ public:
QVariantMap extraInfo;
};
Q_DECLARE_METATYPE(RayToOverlayIntersectionResult);
ScriptValuePointer RayToOverlayIntersectionResultToScriptValue(ScriptEngine* engine, const RayToOverlayIntersectionResult& value);
void RayToOverlayIntersectionResultFromScriptValue(const ScriptValuePointer& object, RayToOverlayIntersectionResult& value);
ScriptValue RayToOverlayIntersectionResultToScriptValue(ScriptEngine* engine, const RayToOverlayIntersectionResult& value);
void RayToOverlayIntersectionResultFromScriptValue(const ScriptValue& object, RayToOverlayIntersectionResult& value);
class ParabolaToOverlayIntersectionResult {
public:
@ -414,8 +412,8 @@ public slots:
*/
RayToOverlayIntersectionResult findRayIntersection(const PickRay& ray,
bool precisionPicking = false,
const ScriptValuePointer& include = ScriptValuePointer(),
const ScriptValuePointer& discard = ScriptValuePointer(),
const ScriptValue& include = ScriptValue(),
const ScriptValue& discard = ScriptValue(),
bool visibleOnly = false,
bool collidableOnly = false);

View file

@ -18,32 +18,32 @@
const AnimVariant AnimVariant::False = AnimVariant();
ScriptValuePointer AnimVariantMap::animVariantMapToScriptValue(ScriptEngine* engine, const QStringList& names, bool useNames) const {
ScriptValue AnimVariantMap::animVariantMapToScriptValue(ScriptEngine* engine, const QStringList& names, bool useNames) const {
if (QThread::currentThread() != engine->thread()) {
qCWarning(animation) << "Cannot create Javacript object from non-script thread" << QThread::currentThread();
Q_ASSERT(false);
return ScriptValuePointer();
return ScriptValue();
}
ScriptValuePointer target = engine->newObject();
ScriptValue target = engine->newObject();
auto setOne = [&] (const QString& name, const AnimVariant& value) {
switch (value.getType()) {
case AnimVariant::Type::Bool:
target->setProperty(name, value.getBool());
target.setProperty(name, value.getBool());
break;
case AnimVariant::Type::Int:
target->setProperty(name, value.getInt());
target.setProperty(name, value.getInt());
break;
case AnimVariant::Type::Float:
target->setProperty(name, value.getFloat());
target.setProperty(name, value.getFloat());
break;
case AnimVariant::Type::String:
target->setProperty(name, value.getString());
target.setProperty(name, value.getString());
break;
case AnimVariant::Type::Vec3:
target->setProperty(name, vec3ToScriptValue(engine, value.getVec3()));
target.setProperty(name, vec3ToScriptValue(engine, value.getVec3()));
break;
case AnimVariant::Type::Quat:
target->setProperty(name, quatToScriptValue(engine, value.getQuat()));
target.setProperty(name, quatToScriptValue(engine, value.getQuat()));
break;
default:
// Unknown type
@ -56,7 +56,7 @@ ScriptValuePointer AnimVariantMap::animVariantMapToScriptValue(ScriptEngine* eng
if (search != _map.end()) {
setOne(name, search->second);
} else if (_triggers.count(name) == 1) {
target->setProperty(name, true);
target.setProperty(name, true);
} // scripts are allowed to request names that do not exist
}
@ -74,8 +74,8 @@ void AnimVariantMap::copyVariantsFrom(const AnimVariantMap& other) {
}
}
void AnimVariantMap::animVariantMapFromScriptValue(const ScriptValuePointer& source) {
if (QThread::currentThread() != source->engine()->thread()) {
void AnimVariantMap::animVariantMapFromScriptValue(const ScriptValue& source) {
if (QThread::currentThread() != source.engine()->thread()) {
qCWarning(animation) << "Cannot examine Javacript object from non-script thread" << QThread::currentThread();
Q_ASSERT(false);
return;
@ -84,43 +84,43 @@ void AnimVariantMap::animVariantMapFromScriptValue(const ScriptValuePointer& sou
// Whenever we identify a new outbound type in animVariantMapToScriptValue above, or a new inbound type in the code that follows here,
// we would enter it into the dictionary. Then switch on that type here, with the code that follow being executed only if
// the type is not known. One problem with that is that there is no checking that two different script use the same name differently.
ScriptValueIteratorPointer property(source->newIterator());
ScriptValueIteratorPointer property(source.newIterator());
// Note: ScriptValueIterator iterates only over source's own properties. It does not follow the prototype chain.
while (property->hasNext()) {
property->next();
ScriptValuePointer value = property->value();
if (value && value->isBool()) {
set(property->name(), value->toBool());
} else if (value && value->isString()) {
set(property->name(), value->toString());
} else if (value && value->isNumber()) {
int asInteger = value->toInt32();
float asFloat = value->toNumber();
ScriptValue value = property->value();
if (value.isBool()) {
set(property->name(), value.toBool());
} else if (value.isString()) {
set(property->name(), value.toString());
} else if (value.isNumber()) {
int asInteger = value.toInt32();
float asFloat = value.toNumber();
if (asInteger == asFloat) {
set(property->name(), asInteger);
} else {
set(property->name(), asFloat);
}
} else { // Try to get x,y,z and possibly w
if (value && value->isObject()) {
ScriptValuePointer x = value->property("x");
if (x && x->isNumber()) {
ScriptValuePointer y = value->property("y");
if (y && y->isNumber()) {
ScriptValuePointer z = value->property("z");
if (z && z->isNumber()) {
ScriptValuePointer w = value->property("w");
if (w && w->isNumber()) {
set(property->name(), glm::quat(w->toNumber(), x->toNumber(), y->toNumber(), z->toNumber()));
if (value.isObject()) {
ScriptValue x = value.property("x");
if (x.isNumber()) {
ScriptValue y = value.property("y");
if (y.isNumber()) {
ScriptValue z = value.property("z");
if (z.isNumber()) {
ScriptValue w = value.property("w");
if (w.isNumber()) {
set(property->name(), glm::quat(w.toNumber(), x.toNumber(), y.toNumber(), z.toNumber()));
} else {
set(property->name(), glm::vec3(x->toNumber(), y->toNumber(), z->toNumber()));
set(property->name(), glm::vec3(x.toNumber(), y.toNumber(), z.toNumber()));
}
continue; // we got either a vector or quaternion object, so don't fall through to warning
}
}
}
}
qCWarning(animation) << "Ignoring unrecognized data " << (value ? value->toString() : "(undefined)") << " for animation property " << property->name();
qCWarning(animation) << "Ignoring unrecognized data " << value.toString() << " for animation property " << property->name();
Q_ASSERT(false);
}
}

View file

@ -20,11 +20,9 @@
#include <StreamUtils.h>
#include <GLMHelpers.h>
#include "AnimationLogging.h"
#include <QtCore/QSharedPointer>
#include <ScriptValue.h>
class ScriptEngine;
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
class AnimVariant {
public:
@ -233,9 +231,9 @@ public:
}
// Answer a Plain Old Javascript Object (for the given engine) all of our values set as properties.
ScriptValuePointer animVariantMapToScriptValue(ScriptEngine* engine, const QStringList& names, bool useNames) const;
ScriptValue animVariantMapToScriptValue(ScriptEngine* engine, const QStringList& names, bool useNames) const;
// Side-effect us with the value of object's own properties. (No inherited properties.)
void animVariantMapFromScriptValue(const ScriptValuePointer& object);
void animVariantMapFromScriptValue(const ScriptValue& object);
void copyVariantsFrom(const AnimVariantMap& other);
// For stat debugging.
@ -278,7 +276,7 @@ protected:
glm::quat _rigToGeometryRot;
};
typedef std::function<void(ScriptValuePointer)> AnimVariantResultHandler;
typedef std::function<void(ScriptValue)> AnimVariantResultHandler;
Q_DECLARE_METATYPE(AnimVariantResultHandler);
Q_DECLARE_METATYPE(AnimVariantMap)

View file

@ -1586,10 +1586,10 @@ void Rig::computeMotionAnimationState(float deltaTime, const glm::vec3& worldPos
}
// Allow script to add/remove handlers and report results, from within their thread.
ScriptValuePointer Rig::addAnimationStateHandler(ScriptValuePointer handler, ScriptValuePointer propertiesList) { // called in script thread
ScriptValue Rig::addAnimationStateHandler(const ScriptValue& handler, const ScriptValue& propertiesList) { // called in script thread
// validate argument types
if (handler && handler->isFunction() && (isListOfStrings(propertiesList) || propertiesList->isUndefined() || propertiesList->isNull())) {
if (handler.isFunction() && (isListOfStrings(propertiesList) || propertiesList.isUndefined() || propertiesList.isNull())) {
QMutexLocker locker(&_stateMutex);
// Find a safe id, even if there are lots of many scripts add and remove handlers repeatedly.
while (!_nextStateHandlerId || _stateHandlers.contains(_nextStateHandlerId)) { // 0 is unused, and don't reuse existing after wrap.
@ -1597,28 +1597,28 @@ ScriptValuePointer Rig::addAnimationStateHandler(ScriptValuePointer handler, Scr
}
StateHandler& data = _stateHandlers[_nextStateHandlerId];
data.function = handler;
data.useNames = propertiesList->isArray();
data.useNames = propertiesList.isArray();
if (data.useNames) {
data.propertyNames = propertiesList->toVariant().toStringList();
data.propertyNames = propertiesList.toVariant().toStringList();
}
return handler->engine()->newValue(_nextStateHandlerId); // suitable for giving to removeAnimationStateHandler
return handler.engine()->newValue(_nextStateHandlerId); // suitable for giving to removeAnimationStateHandler
} else {
qCWarning(animation) << "Rig::addAnimationStateHandler invalid arguments, expected (function, string[])";
return handler ? handler->engine()->undefinedValue() : ScriptValuePointer();
return handler.engine() ? handler.engine()->undefinedValue() : ScriptValue();
}
}
void Rig::removeAnimationStateHandler(ScriptValuePointer identifier) { // called in script thread
void Rig::removeAnimationStateHandler(const ScriptValue& identifier) { // called in script thread
// validate arguments
if (identifier && identifier->isNumber()) {
if (identifier.isNumber()) {
QMutexLocker locker(&_stateMutex);
_stateHandlers.remove(identifier->toInt32()); // silently continues if handler not present. 0 is unused
_stateHandlers.remove(identifier.toInt32()); // silently continues if handler not present. 0 is unused
} else {
qCWarning(animation) << "Rig::removeAnimationStateHandler invalid argument, expected a number";
}
}
void Rig::animationStateHandlerResult(int identifier, ScriptValuePointer result) { // called synchronously from script
void Rig::animationStateHandlerResult(int identifier, const ScriptValue& result) { // called synchronously from script
QMutexLocker locker(&_stateMutex);
auto found = _stateHandlers.find(identifier);
if (found == _stateHandlers.end()) {
@ -1637,9 +1637,9 @@ void Rig::updateAnimationStateHandlers() { // called on avatar update thread (wh
// call out:
int identifier = data.key();
StateHandler& value = data.value();
ScriptValuePointer& function = value.function;
ScriptValue& function = value.function;
int rigId = _rigId;
auto handleResult = [rigId, identifier](ScriptValuePointer result) { // called in script thread to get the result back to us.
auto handleResult = [rigId, identifier](const ScriptValue& result) { // called in script thread to get the result back to us.
// Hold the rigRegistryMutex to ensure thread-safe access to the rigRegistry, but
// also to prevent the rig from being deleted while this lambda is being executed.
std::lock_guard<std::mutex> guard(rigRegistryMutex);
@ -1658,20 +1658,20 @@ void Rig::updateAnimationStateHandlers() { // called on avatar update thread (wh
// Copies of AnimVariantMap do copy the underlying map, so this will correctly capture
// the state of _animVars and allow continued changes to _animVars in this thread without conflict.
const AnimVariantMap& animVars = _animVars;
ScriptEnginePointer engine = function->engine();
ScriptEnginePointer engine = function.engine();
const QStringList& names = value.propertyNames;
bool useNames = value.useNames;
QMetaObject::invokeMethod(
engine->manager(),
[function, animVars, names, useNames, handleResult, engine] {
ScriptValuePointer javascriptParameters = animVars.animVariantMapToScriptValue(engine.get(), names, useNames);
ScriptValue javascriptParameters = animVars.animVariantMapToScriptValue(engine.get(), names, useNames);
ScriptValueList callingArguments;
callingArguments << javascriptParameters;
ScriptValuePointer result = function->call(ScriptValuePointer(), callingArguments);
ScriptValue result = function.call(ScriptValue(), callingArguments);
// validate result from callback function.
if (result->isValid() && result->isObject()) {
if (result.isValid() && result.isObject()) {
handleResult(result);
} else {
qCWarning(animation) << "Rig::updateAnimationStateHandlers invalid return argument from "

View file

@ -19,7 +19,7 @@
#include <vector>
#include <JointData.h>
#include <QReadWriteLock>
#include <QtCore/QSharedPointer>
#include <ScriptValue.h>
#include "AnimNode.h"
#include "AnimNodeLoader.h"
@ -30,8 +30,6 @@
class Rig;
class AnimInverseKinematics;
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
// Rig instances are reentrant.
// However only specific methods thread-safe. Noted below.
@ -42,7 +40,7 @@ public:
struct StateHandler {
AnimVariantMap results;
QStringList propertyNames;
ScriptValuePointer function;
ScriptValue function;
bool useNames;
};
@ -207,9 +205,9 @@ public:
AnimNode::ConstPointer getAnimNode() const { return _animNode; }
AnimNode::ConstPointer findAnimNodeByName(const QString& name) const;
AnimSkeleton::ConstPointer getAnimSkeleton() const { return _animSkeleton; }
ScriptValuePointer addAnimationStateHandler(ScriptValuePointer handler, ScriptValuePointer propertiesList);
void removeAnimationStateHandler(ScriptValuePointer handler);
void animationStateHandlerResult(int identifier, ScriptValuePointer result);
ScriptValue addAnimationStateHandler(const ScriptValue& handler, const ScriptValue& propertiesList);
void removeAnimationStateHandler(const ScriptValue& handler);
void animationStateHandlerResult(int identifier, const ScriptValue& result);
// rig space
bool getModelRegistrationPoint(glm::vec3& modelRegistrationPointOut) const;

View file

@ -6,6 +6,7 @@ setup_hifi_library(Network Multimedia ${PLATFORM_QT_COMPONENTS})
link_hifi_libraries(audio plugins)
include_hifi_library_headers(shared)
include_hifi_library_headers(networking)
include_hifi_library_headers(script-engine)
if (ANDROID)
else ()

View file

@ -18,8 +18,8 @@
STATIC_SCRIPT_INITIALIZER(+[](ScriptManager* manager) {
auto scriptEngine = manager->engine().data();
ScriptValuePointer audioEffectOptionsConstructorValue = scriptEngine->newFunction(AudioEffectOptions::constructor);
scriptEngine->globalObject()->setProperty("AudioEffectOptions", audioEffectOptionsConstructorValue);
ScriptValue audioEffectOptionsConstructorValue = scriptEngine->newFunction(AudioEffectOptions::constructor);
scriptEngine->globalObject().setProperty("AudioEffectOptions", audioEffectOptionsConstructorValue);
});
static const QString BANDWIDTH_HANDLE = "bandwidth";
@ -66,8 +66,8 @@ static const float LATE_MIX_LEFT_DEFAULT = 90.0f;
static const float LATE_MIX_RIGHT_DEFAULT = 90.0f;
static const float WET_DRY_MIX_DEFAULT = 50.0f;
static void setOption(ScriptValuePointer arguments, const QString name, float defaultValue, float& variable) {
variable = arguments && arguments->property(name)->isNumber() ? (float)arguments->property(name)->toNumber() : defaultValue;
static void setOption(const ScriptValue& arguments, const QString name, float defaultValue, float& variable) {
variable = arguments.property(name).isNumber() ? (float)arguments.property(name).toNumber() : defaultValue;
}
/*@jsdoc
@ -95,7 +95,7 @@ static void setOption(ScriptValuePointer arguments, const QString name, float de
* @property {number} lateMixRight=90 - The apparent distance of the source (percent) in the reverb tail.
* @property {number} wetDryMix=50 - Adjusts the wet/dry ratio, from completely dry (0%) to completely wet (100%).
*/
AudioEffectOptions::AudioEffectOptions(ScriptValuePointer arguments) {
AudioEffectOptions::AudioEffectOptions(const ScriptValue& arguments) {
setOption(arguments, BANDWIDTH_HANDLE, BANDWIDTH_DEFAULT, _bandwidth);
setOption(arguments, PRE_DELAY_HANDLE, PRE_DELAY_DEFAULT, _preDelay);
setOption(arguments, LATE_DELAY_HANDLE, LATE_DELAY_DEFAULT, _lateDelay);
@ -149,6 +149,6 @@ AudioEffectOptions& AudioEffectOptions::operator=(const AudioEffectOptions &othe
return *this;
}
ScriptValuePointer AudioEffectOptions::constructor(ScriptContext* context, ScriptEngine* engine) {
ScriptValue AudioEffectOptions::constructor(ScriptContext* context, ScriptEngine* engine) {
return engine->newQObject(new AudioEffectOptions(context->argument(0)));
}

View file

@ -12,12 +12,10 @@
#define hifi_AudioEffectOptions_h
#include <QObject>
#include <QtCore/QSharedPointer>
#include <ScriptValue.h>
class ScriptContext;
class ScriptEngine;
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
/*@jsdoc
* Audio effect options used by the {@link Audio} API.
@ -82,11 +80,11 @@ class AudioEffectOptions : public QObject {
Q_PROPERTY(float wetDryMix READ getWetDryMix WRITE setWetDryMix)
public:
AudioEffectOptions(ScriptValuePointer arguments = ScriptValuePointer());
AudioEffectOptions(const ScriptValue& arguments = ScriptValue());
AudioEffectOptions(const AudioEffectOptions &other);
AudioEffectOptions& operator=(const AudioEffectOptions &other);
static ScriptValuePointer constructor(ScriptContext* context, ScriptEngine* engine);
static ScriptValue constructor(ScriptContext* context, ScriptEngine* engine);
float getBandwidth() const { return _bandwidth; }
void setBandwidth(float bandwidth) { _bandwidth = bandwidth; }

View file

@ -32,18 +32,18 @@ AudioInjectorOptions::AudioInjectorOptions() :
{
}
ScriptValuePointer injectorOptionsToScriptValue(ScriptEngine* engine, const AudioInjectorOptions& injectorOptions) {
ScriptValuePointer obj = engine->newObject();
ScriptValue injectorOptionsToScriptValue(ScriptEngine* engine, const AudioInjectorOptions& injectorOptions) {
ScriptValue obj = engine->newObject();
if (injectorOptions.positionSet) {
obj->setProperty("position", vec3ToScriptValue(engine, injectorOptions.position));
obj.setProperty("position", vec3ToScriptValue(engine, injectorOptions.position));
}
obj->setProperty("volume", injectorOptions.volume);
obj->setProperty("loop", injectorOptions.loop);
obj->setProperty("orientation", quatToScriptValue(engine, injectorOptions.orientation));
obj->setProperty("ignorePenumbra", injectorOptions.ignorePenumbra);
obj->setProperty("localOnly", injectorOptions.localOnly);
obj->setProperty("secondOffset", injectorOptions.secondOffset);
obj->setProperty("pitch", injectorOptions.pitch);
obj.setProperty("volume", injectorOptions.volume);
obj.setProperty("loop", injectorOptions.loop);
obj.setProperty("orientation", quatToScriptValue(engine, injectorOptions.orientation));
obj.setProperty("ignorePenumbra", injectorOptions.ignorePenumbra);
obj.setProperty("localOnly", injectorOptions.localOnly);
obj.setProperty("secondOffset", injectorOptions.secondOffset);
obj.setProperty("pitch", injectorOptions.pitch);
return obj;
}
@ -66,8 +66,8 @@ ScriptValuePointer injectorOptionsToScriptValue(ScriptEngine* engine, const Audi
* @property {boolean} ignorePenumbra=false - <p class="important">Deprecated: This property is deprecated and will be
* removed.</p>
*/
void injectorOptionsFromScriptValue(const ScriptValuePointer& object, AudioInjectorOptions& injectorOptions) {
if (!object || !object->isObject()) {
void injectorOptionsFromScriptValue(const ScriptValue& object, AudioInjectorOptions& injectorOptions) {
if (!object.isObject()) {
qWarning() << "Audio injector options is not an object.";
return;
}
@ -77,48 +77,48 @@ void injectorOptionsFromScriptValue(const ScriptValuePointer& object, AudioInjec
}
injectorOptions.positionSet = false;
ScriptValueIteratorPointer it(object->newIterator());
ScriptValueIteratorPointer it(object.newIterator());
while (it->hasNext()) {
it->next();
if (it->name() == "position") {
vec3FromScriptValue(object->property("position"), injectorOptions.position);
vec3FromScriptValue(object.property("position"), injectorOptions.position);
injectorOptions.positionSet = true;
} else if (it->name() == "orientation") {
quatFromScriptValue(object->property("orientation"), injectorOptions.orientation);
quatFromScriptValue(object.property("orientation"), injectorOptions.orientation);
} else if (it->name() == "volume") {
if (it->value()->isNumber()) {
injectorOptions.volume = it->value()->toNumber();
if (it->value().isNumber()) {
injectorOptions.volume = it->value().toNumber();
} else {
qCWarning(audio) << "Audio injector options: volume is not a number";
}
} else if (it->name() == "loop") {
if (it->value()->isBool()) {
injectorOptions.loop = it->value()->toBool();
if (it->value().isBool()) {
injectorOptions.loop = it->value().toBool();
} else {
qCWarning(audio) << "Audio injector options: loop is not a boolean";
}
} else if (it->name() == "ignorePenumbra") {
if (it->value()->isBool()) {
injectorOptions.ignorePenumbra = it->value()->toBool();
if (it->value().isBool()) {
injectorOptions.ignorePenumbra = it->value().toBool();
} else {
qCWarning(audio) << "Audio injector options: ignorePenumbra is not a boolean";
}
} else if (it->name() == "localOnly") {
if (it->value()->isBool()) {
injectorOptions.localOnly = it->value()->toBool();
if (it->value().isBool()) {
injectorOptions.localOnly = it->value().toBool();
} else {
qCWarning(audio) << "Audio injector options: localOnly is not a boolean";
}
} else if (it->name() == "secondOffset") {
if (it->value()->isNumber()) {
injectorOptions.secondOffset = it->value()->toNumber();
if (it->value().isNumber()) {
injectorOptions.secondOffset = it->value().toNumber();
} else {
qCWarning(audio) << "Audio injector options: secondOffset is not a number";
}
} else if (it->name() == "pitch") {
if (it->value()->isNumber()) {
injectorOptions.pitch = it->value()->toNumber();
if (it->value().isNumber()) {
injectorOptions.pitch = it->value().toNumber();
} else {
qCWarning(audio) << "Audio injector options: pitch is not a number";
}

View file

@ -14,11 +14,9 @@
#include <glm/glm.hpp>
#include <glm/gtx/quaternion.hpp>
#include <QtCore/QSharedPointer>
#include <ScriptValue.h>
class ScriptEngine;
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
class AudioInjectorOptions {
public:
@ -38,7 +36,7 @@ public:
Q_DECLARE_METATYPE(AudioInjectorOptions);
ScriptValuePointer injectorOptionsToScriptValue(ScriptEngine* engine, const AudioInjectorOptions& injectorOptions);
void injectorOptionsFromScriptValue(const ScriptValuePointer& object, AudioInjectorOptions& injectorOptions);
ScriptValue injectorOptionsToScriptValue(ScriptEngine* engine, const AudioInjectorOptions& injectorOptions);
void injectorOptionsFromScriptValue(const ScriptValue& object, AudioInjectorOptions& injectorOptions);
#endif // hifi_AudioInjectorOptions_h

View file

@ -23,7 +23,7 @@ STATIC_SCRIPT_INITIALIZER(+[](ScriptManager* manager) {
scriptRegisterMetaType(scriptEngine, injectorToScriptValue, injectorFromScriptValue);
});
ScriptValuePointer injectorToScriptValue(ScriptEngine* engine, ScriptAudioInjector* const& in) {
ScriptValue injectorToScriptValue(ScriptEngine* engine, ScriptAudioInjector* const& in) {
// The AudioScriptingInterface::playSound method can return null, so we need to account for that.
if (!in) {
return engine->nullValue();
@ -32,8 +32,8 @@ ScriptValuePointer injectorToScriptValue(ScriptEngine* engine, ScriptAudioInject
return engine->newQObject(in, ScriptEngine::ScriptOwnership);
}
void injectorFromScriptValue(const ScriptValuePointer& object, ScriptAudioInjector*& out) {
out = qobject_cast<ScriptAudioInjector*>(object->toQObject());
void injectorFromScriptValue(const ScriptValue& object, ScriptAudioInjector*& out) {
out = qobject_cast<ScriptAudioInjector*>(object.toQObject());
}
ScriptAudioInjector::ScriptAudioInjector(const AudioInjectorPointer& injector) :

View file

@ -16,13 +16,11 @@
#define hifi_ScriptAudioInjector_h
#include <QtCore/QObject>
#include <QtCore/QSharedPointer>
#include <ScriptValue.h>
#include "AudioInjectorManager.h"
class ScriptEngine;
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
/*@jsdoc
* Plays or "injects" the content of an audio file.
@ -148,13 +146,13 @@ signals:
private:
QWeakPointer<AudioInjector> _injector;
friend ScriptValuePointer injectorToScriptValue(ScriptEngine* engine, ScriptAudioInjector* const& in);
friend ScriptValue injectorToScriptValue(ScriptEngine* engine, ScriptAudioInjector* const& in);
};
Q_DECLARE_METATYPE(ScriptAudioInjector*)
ScriptValuePointer injectorToScriptValue(ScriptEngine* engine, ScriptAudioInjector* const& in);
void injectorFromScriptValue(const ScriptValuePointer& object, ScriptAudioInjector*& out);
ScriptValue injectorToScriptValue(ScriptEngine* engine, ScriptAudioInjector* const& in);
void injectorFromScriptValue(const ScriptValue& object, ScriptAudioInjector*& out);
#endif // hifi_ScriptAudioInjector_h

View file

@ -424,12 +424,12 @@ SoundProcessor::AudioProperties SoundProcessor::interpretAsMP3(const QByteArray&
}
ScriptValuePointer soundSharedPointerToScriptValue(ScriptEngine* engine, const SharedSoundPointer& in) {
ScriptValue soundSharedPointerToScriptValue(ScriptEngine* engine, const SharedSoundPointer& in) {
return engine->newQObject(new SoundScriptingInterface(in), ScriptEngine::ScriptOwnership);
}
void soundSharedPointerFromScriptValue(const ScriptValuePointer& object, SharedSoundPointer& out) {
if (auto soundInterface = qobject_cast<SoundScriptingInterface*>(object->toQObject())) {
void soundSharedPointerFromScriptValue(const ScriptValue& object, SharedSoundPointer& out) {
if (auto soundInterface = qobject_cast<SoundScriptingInterface*>(object.toQObject())) {
out = soundInterface->getSound();
}
}

View file

@ -19,14 +19,13 @@
#include <QtCore/QSharedPointer>
#include <ResourceCache.h>
#include <ScriptValue.h>
#include "AudioConstants.h"
class AudioData;
class ScriptEngine;
class ScriptValue;
using AudioDataPointer = std::shared_ptr<const AudioData>;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
Q_DECLARE_METATYPE(AudioDataPointer);
@ -172,7 +171,7 @@ private:
};
Q_DECLARE_METATYPE(SharedSoundPointer)
ScriptValuePointer soundSharedPointerToScriptValue(ScriptEngine* engine, const SharedSoundPointer& in);
void soundSharedPointerFromScriptValue(const ScriptValuePointer& object, SharedSoundPointer& out);
ScriptValue soundSharedPointerToScriptValue(ScriptEngine* engine, const SharedSoundPointer& in);
void soundSharedPointerFromScriptValue(const ScriptValue& object, SharedSoundPointer& out);
#endif // hifi_Sound_h

View file

@ -3159,40 +3159,40 @@ glm::mat4 AvatarData::getControllerRightHandMatrix() const {
* @property {SubmeshIntersection} extraInfo - Extra information on the mesh intersected if mesh was picked against,
* <code>{}</code> if it wasn't.
*/
ScriptValuePointer RayToAvatarIntersectionResultToScriptValue(ScriptEngine* engine, const RayToAvatarIntersectionResult& value) {
ScriptValuePointer obj = engine->newObject();
obj->setProperty("intersects", value.intersects);
ScriptValuePointer avatarIDValue = quuidToScriptValue(engine, value.avatarID);
obj->setProperty("avatarID", avatarIDValue);
obj->setProperty("distance", value.distance);
obj->setProperty("face", boxFaceToString(value.face));
ScriptValuePointer intersection = vec3ToScriptValue(engine, value.intersection);
ScriptValue RayToAvatarIntersectionResultToScriptValue(ScriptEngine* engine, const RayToAvatarIntersectionResult& value) {
ScriptValue obj = engine->newObject();
obj.setProperty("intersects", value.intersects);
ScriptValue avatarIDValue = quuidToScriptValue(engine, value.avatarID);
obj.setProperty("avatarID", avatarIDValue);
obj.setProperty("distance", value.distance);
obj.setProperty("face", boxFaceToString(value.face));
ScriptValue intersection = vec3ToScriptValue(engine, value.intersection);
obj->setProperty("intersection", intersection);
ScriptValuePointer surfaceNormal = vec3ToScriptValue(engine, value.surfaceNormal);
obj->setProperty("surfaceNormal", surfaceNormal);
obj->setProperty("jointIndex", value.jointIndex);
obj->setProperty("extraInfo", engine->toScriptValue(value.extraInfo));
obj.setProperty("intersection", intersection);
ScriptValue surfaceNormal = vec3ToScriptValue(engine, value.surfaceNormal);
obj.setProperty("surfaceNormal", surfaceNormal);
obj.setProperty("jointIndex", value.jointIndex);
obj.setProperty("extraInfo", engine->toScriptValue(value.extraInfo));
return obj;
}
void RayToAvatarIntersectionResultFromScriptValue(const ScriptValuePointer& object, RayToAvatarIntersectionResult& value) {
value.intersects = object->property("intersects")->toVariant().toBool();
ScriptValuePointer avatarIDValue = object->property("avatarID");
void RayToAvatarIntersectionResultFromScriptValue(const ScriptValue& object, RayToAvatarIntersectionResult& value) {
value.intersects = object.property("intersects").toVariant().toBool();
ScriptValue avatarIDValue = object.property("avatarID");
quuidFromScriptValue(avatarIDValue, value.avatarID);
value.distance = object->property("distance")->toVariant().toFloat();
value.face = boxFaceFromString(object->property("face")->toVariant().toString());
value.distance = object.property("distance").toVariant().toFloat();
value.face = boxFaceFromString(object.property("face").toVariant().toString());
ScriptValuePointer intersection = object->property("intersection");
if (intersection && intersection->isValid()) {
ScriptValue intersection = object.property("intersection");
if (intersection.isValid()) {
vec3FromScriptValue(intersection, value.intersection);
}
ScriptValuePointer surfaceNormal = object->property("surfaceNormal");
if (surfaceNormal && surfaceNormal->isValid()) {
ScriptValue surfaceNormal = object.property("surfaceNormal");
if (surfaceNormal.isValid()) {
vec3FromScriptValue(surfaceNormal, value.surfaceNormal);
}
value.jointIndex = object->property("jointIndex")->toInt32();
value.extraInfo = object->property("extraInfo")->toVariant().toMap();
value.jointIndex = object.property("jointIndex").toInt32();
value.extraInfo = object.property("extraInfo").toVariant().toMap();
}
// these coefficients can be changed via JS for experimental tuning
@ -3205,8 +3205,8 @@ float AvatarData::_avatarSortCoefficientAge { 1.0f };
* An object with the UUIDs of avatar entities as keys and avatar entity properties objects as values.
* @typedef {Object.<Uuid, Entities.EntityProperties>} AvatarEntityMap
*/
ScriptValuePointer AvatarEntityMapToScriptValue(ScriptEngine* engine, const AvatarEntityMap& value) {
ScriptValuePointer obj = engine->newObject();
ScriptValue AvatarEntityMapToScriptValue(ScriptEngine* engine, const AvatarEntityMap& value) {
ScriptValue obj = engine->newObject();
for (auto entityID : value.keys()) {
QByteArray entityProperties = value.value(entityID);
OVERTE_IGNORE_DEPRECATED_BEGIN
@ -3218,22 +3218,22 @@ ScriptValuePointer AvatarEntityMapToScriptValue(ScriptEngine* engine, const Avat
QVariant variantEntityProperties = jsonEntityProperties.toVariant();
QVariantMap entityPropertiesMap = variantEntityProperties.toMap();
ScriptValuePointer scriptEntityProperties = variantMapToScriptValue(entityPropertiesMap, *engine);
ScriptValue scriptEntityProperties = variantMapToScriptValue(entityPropertiesMap, *engine);
QString key = entityID.toString();
obj->setProperty(key, scriptEntityProperties);
obj.setProperty(key, scriptEntityProperties);
}
return obj;
}
void AvatarEntityMapFromScriptValue(const ScriptValuePointer& object, AvatarEntityMap& value) {
ScriptValueIteratorPointer itr(object->newIterator());
void AvatarEntityMapFromScriptValue(const ScriptValue& object, AvatarEntityMap& value) {
ScriptValueIteratorPointer itr(object.newIterator());
while (itr->hasNext()) {
itr->next();
QUuid EntityID = QUuid(itr->name());
ScriptValuePointer scriptEntityProperties = itr->value();
QVariant variantEntityProperties = scriptEntityProperties->toVariant();
ScriptValue scriptEntityProperties = itr->value();
QVariant variantEntityProperties = scriptEntityProperties.toVariant();
QJsonDocument jsonEntityProperties = QJsonDocument::fromVariant(variantEntityProperties);
OVERTE_IGNORE_DEPRECATED_BEGIN
QByteArray binaryEntityProperties = jsonEntityProperties.toBinaryData();

View file

@ -34,7 +34,6 @@
#include <QVariantMap>
#include <QVector>
#include <QReadWriteLock>
#include <QtCore/QSharedPointer>
#include <AvatarConstants.h>
#include <JointData.h>
@ -51,6 +50,7 @@
#include <shared/RateCounter.h>
#include <udt/SequenceNumber.h>
#include "Scriptable.h"
#include <ScriptValue.h>
#include "AABox.h"
#include "AvatarTraits.h"
@ -58,8 +58,6 @@
#include "PathUtils.h"
class ScriptEngine;
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
using AvatarSharedPointer = std::shared_ptr<AvatarData>;
using AvatarWeakPointer = std::weak_ptr<AvatarData>;
@ -1973,8 +1971,8 @@ public:
QVariantMap extraInfo;
};
Q_DECLARE_METATYPE(RayToAvatarIntersectionResult)
ScriptValuePointer RayToAvatarIntersectionResultToScriptValue(ScriptEngine* engine, const RayToAvatarIntersectionResult& results);
void RayToAvatarIntersectionResultFromScriptValue(const ScriptValuePointer& object, RayToAvatarIntersectionResult& results);
ScriptValue RayToAvatarIntersectionResultToScriptValue(ScriptEngine* engine, const RayToAvatarIntersectionResult& results);
void RayToAvatarIntersectionResultFromScriptValue(const ScriptValue& object, RayToAvatarIntersectionResult& results);
// No JSDoc because it's not provided as a type to the script engine.
class ParabolaToAvatarIntersectionResult {
@ -1991,8 +1989,8 @@ public:
Q_DECLARE_METATYPE(AvatarEntityMap)
ScriptValuePointer AvatarEntityMapToScriptValue(ScriptEngine* engine, const AvatarEntityMap& value);
void AvatarEntityMapFromScriptValue(const ScriptValuePointer& object, AvatarEntityMap& value);
ScriptValue AvatarEntityMapToScriptValue(ScriptEngine* engine, const AvatarEntityMap& value);
void AvatarEntityMapFromScriptValue(const ScriptValue& object, AvatarEntityMap& value);
// faux joint indexes (-1 means invalid)
const int NO_JOINT_INDEX = 65535; // -1

View file

@ -14,11 +14,11 @@
#include <ScriptEngineCast.h>
#include <ScriptManager.h>
ScriptValuePointer avatarDataToScriptValue(ScriptEngine* engine, ScriptAvatarData* const& in) {
ScriptValue avatarDataToScriptValue(ScriptEngine* engine, ScriptAvatarData* const& in) {
return engine->newQObject(in, ScriptEngine::ScriptOwnership);
}
void avatarDataFromScriptValue(const ScriptValuePointer& object, ScriptAvatarData*& out) {
void avatarDataFromScriptValue(const ScriptValue& object, ScriptAvatarData*& out) {
// This is not implemented because there are no slots/properties that take an AvatarSharedPointer from a script
assert(false);
out = nullptr;

View file

@ -212,13 +212,13 @@ void MaterialBaker::outputMaterial() {
if (_materialResource->parsedMaterials.networkMaterials.size() == 1) {
auto networkMaterial = _materialResource->parsedMaterials.networkMaterials.begin();
auto scriptableMaterial = scriptable::ScriptableMaterial(networkMaterial->second);
QVariant materialVariant = scriptable::scriptableMaterialToScriptValue(_scriptEngine.data(), scriptableMaterial)->toVariant();
QVariant materialVariant = scriptable::scriptableMaterialToScriptValue(_scriptEngine.data(), scriptableMaterial).toVariant();
json.insert("materials", QJsonDocument::fromVariant(materialVariant).object());
} else {
QJsonArray materialArray;
for (auto networkMaterial : _materialResource->parsedMaterials.networkMaterials) {
auto scriptableMaterial = scriptable::ScriptableMaterial(networkMaterial.second);
QVariant materialVariant = scriptable::scriptableMaterialToScriptValue(_scriptEngine.data(), scriptableMaterial)->toVariant();
QVariant materialVariant = scriptable::scriptableMaterialToScriptValue(_scriptEngine.data(), scriptableMaterial).toVariant();
materialArray.append(QJsonDocument::fromVariant(materialVariant).object());
}
json.insert("materials", materialArray);

View file

@ -40,25 +40,25 @@ namespace controller {
* @property {Vec3} angularVelocity - Angular velocity in rad/s.
* @property {boolean} valid - <code>true</code> if the pose is valid, otherwise <code>false</code>.
*/
ScriptValuePointer Pose::toScriptValue(ScriptEngine* engine, const Pose& pose) {
ScriptValuePointer obj = engine->newObject();
obj->setProperty("translation", vec3ToScriptValue(engine, pose.translation));
obj->setProperty("rotation", quatToScriptValue(engine, pose.rotation));
obj->setProperty("velocity", vec3ToScriptValue(engine, pose.velocity));
obj->setProperty("angularVelocity", vec3ToScriptValue(engine, pose.angularVelocity));
obj->setProperty("valid", pose.valid);
ScriptValue Pose::toScriptValue(ScriptEngine* engine, const Pose& pose) {
ScriptValue obj = engine->newObject();
obj.setProperty("translation", vec3ToScriptValue(engine, pose.translation));
obj.setProperty("rotation", quatToScriptValue(engine, pose.rotation));
obj.setProperty("velocity", vec3ToScriptValue(engine, pose.velocity));
obj.setProperty("angularVelocity", vec3ToScriptValue(engine, pose.angularVelocity));
obj.setProperty("valid", pose.valid);
return obj;
}
void Pose::fromScriptValue(const ScriptValuePointer& object, Pose& pose) {
auto translation = object->property("translation");
auto rotation = object->property("rotation");
auto velocity = object->property("velocity");
auto angularVelocity = object->property("angularVelocity");
if (translation->isValid() &&
rotation->isValid() &&
velocity->isValid() &&
angularVelocity->isValid()) {
void Pose::fromScriptValue(const ScriptValue& object, Pose& pose) {
auto translation = object.property("translation");
auto rotation = object.property("rotation");
auto velocity = object.property("velocity");
auto angularVelocity = object.property("angularVelocity");
if (translation.isValid() &&
rotation.isValid() &&
velocity.isValid() &&
angularVelocity.isValid()) {
vec3FromScriptValue(translation, pose.translation);
quatFromScriptValue(rotation, pose.rotation);
vec3FromScriptValue(velocity, pose.velocity);

View file

@ -10,11 +10,9 @@
#pragma once
#ifndef hifi_controllers_Pose_h
#define hifi_controllers_Pose_h
#include <QtCore/QSharedPointer>
#include <ScriptValue.h>
class ScriptEngine;
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
#include <GLMHelpers.h>
@ -46,8 +44,8 @@ namespace controller {
Pose transform(const glm::mat4& mat) const;
Pose postTransform(const glm::mat4& mat) const;
static ScriptValuePointer toScriptValue(ScriptEngine* engine, const Pose& event);
static void fromScriptValue(const ScriptValuePointer& object, Pose& event);
static ScriptValue toScriptValue(ScriptEngine* engine, const Pose& event);
static void fromScriptValue(const ScriptValue& object, Pose& event);
};
}

View file

@ -33,12 +33,12 @@
Q_DECLARE_METATYPE(controller::InputController*)
//static int inputControllerPointerId = qRegisterMetaType<controller::InputController*>();
ScriptValuePointer inputControllerToScriptValue(ScriptEngine* engine, controller::InputController* const& in) {
ScriptValue inputControllerToScriptValue(ScriptEngine* engine, controller::InputController* const& in) {
return engine->newQObject(in, ScriptEngine::QtOwnership);
}
void inputControllerFromScriptValue(const ScriptValuePointer& object, controller::InputController*& out) {
out = qobject_cast<controller::InputController*>(object->toQObject());
void inputControllerFromScriptValue(const ScriptValue& object, controller::InputController*& out) {
out = qobject_cast<controller::InputController*>(object.toQObject());
}
STATIC_SCRIPT_INITIALIZER(+[](ScriptManager* manager) {

View file

@ -392,58 +392,58 @@ int inputPairMetaTypeId = qRegisterMetaType<Input::NamedPair>();
int poseMetaTypeId = qRegisterMetaType<controller::Pose>("Pose");
int handMetaTypeId = qRegisterMetaType<controller::Hand>();
ScriptValuePointer inputToScriptValue(ScriptEngine* engine, const Input& input);
void inputFromScriptValue(const ScriptValuePointer& object, Input& input);
ScriptValuePointer actionToScriptValue(ScriptEngine* engine, const Action& action);
void actionFromScriptValue(const ScriptValuePointer& object, Action& action);
ScriptValuePointer inputPairToScriptValue(ScriptEngine* engine, const Input::NamedPair& inputPair);
void inputPairFromScriptValue(const ScriptValuePointer& object, Input::NamedPair& inputPair);
ScriptValuePointer handToScriptValue(ScriptEngine* engine, const controller::Hand& hand);
void handFromScriptValue(const ScriptValuePointer& object, controller::Hand& hand);
ScriptValue inputToScriptValue(ScriptEngine* engine, const Input& input);
void inputFromScriptValue(const ScriptValue& object, Input& input);
ScriptValue actionToScriptValue(ScriptEngine* engine, const Action& action);
void actionFromScriptValue(const ScriptValue& object, Action& action);
ScriptValue inputPairToScriptValue(ScriptEngine* engine, const Input::NamedPair& inputPair);
void inputPairFromScriptValue(const ScriptValue& object, Input::NamedPair& inputPair);
ScriptValue handToScriptValue(ScriptEngine* engine, const controller::Hand& hand);
void handFromScriptValue(const ScriptValue& object, controller::Hand& hand);
ScriptValuePointer inputToScriptValue(ScriptEngine* engine, const Input& input) {
ScriptValuePointer obj = engine->newObject();
obj->setProperty("device", input.getDevice());
obj->setProperty("channel", input.getChannel());
obj->setProperty("type", (unsigned short)input.getType());
obj->setProperty("id", input.getID());
ScriptValue inputToScriptValue(ScriptEngine* engine, const Input& input) {
ScriptValue obj = engine->newObject();
obj.setProperty("device", input.getDevice());
obj.setProperty("channel", input.getChannel());
obj.setProperty("type", (unsigned short)input.getType());
obj.setProperty("id", input.getID());
return obj;
}
void inputFromScriptValue(const ScriptValuePointer& object, Input& input) {
input.id = object->property("id")->toInt32();
void inputFromScriptValue(const ScriptValue& object, Input& input) {
input.id = object.property("id").toInt32();
}
ScriptValuePointer actionToScriptValue(ScriptEngine* engine, const Action& action) {
ScriptValuePointer obj = engine->newObject();
ScriptValue actionToScriptValue(ScriptEngine* engine, const Action& action) {
ScriptValue obj = engine->newObject();
auto userInputMapper = DependencyManager::get<UserInputMapper>();
obj->setProperty("action", (int)action);
obj->setProperty("actionName", userInputMapper->getActionName(action));
obj.setProperty("action", (int)action);
obj.setProperty("actionName", userInputMapper->getActionName(action));
return obj;
}
void actionFromScriptValue(const ScriptValuePointer& object, Action& action) {
action = Action(object->property("action")->toVariant().toInt());
void actionFromScriptValue(const ScriptValue& object, Action& action) {
action = Action(object.property("action").toVariant().toInt());
}
ScriptValuePointer inputPairToScriptValue(ScriptEngine* engine, const Input::NamedPair& inputPair) {
ScriptValuePointer obj = engine->newObject();
obj->setProperty("input", inputToScriptValue(engine, inputPair.first));
obj->setProperty("inputName", inputPair.second);
ScriptValue inputPairToScriptValue(ScriptEngine* engine, const Input::NamedPair& inputPair) {
ScriptValue obj = engine->newObject();
obj.setProperty("input", inputToScriptValue(engine, inputPair.first));
obj.setProperty("inputName", inputPair.second);
return obj;
}
void inputPairFromScriptValue(const ScriptValuePointer& object, Input::NamedPair& inputPair) {
inputFromScriptValue(object->property("input"), inputPair.first);
inputPair.second = QString(object->property("inputName")->toVariant().toString());
void inputPairFromScriptValue(const ScriptValue& object, Input::NamedPair& inputPair) {
inputFromScriptValue(object.property("input"), inputPair.first);
inputPair.second = QString(object.property("inputName").toVariant().toString());
}
ScriptValuePointer handToScriptValue(ScriptEngine* engine, const controller::Hand& hand) {
ScriptValue handToScriptValue(ScriptEngine* engine, const controller::Hand& hand) {
return engine->newValue((int)hand);
}
void handFromScriptValue(const ScriptValuePointer& object, controller::Hand& hand) {
hand = Hand(object->toVariant().toInt());
void handFromScriptValue(const ScriptValue& object, controller::Hand& hand) {
hand = Hand(object.toVariant().toInt());
}
void UserInputMapper::registerControllerTypes(ScriptEngine* engine) {
@ -662,21 +662,21 @@ Endpoint::Pointer UserInputMapper::endpointFor(const QJSValue& endpoint) {
return Endpoint::Pointer();
}
Endpoint::Pointer UserInputMapper::endpointFor(const ScriptValuePointer& endpoint) {
if (endpoint->isNumber()) {
return endpointFor(Input(endpoint->toInt32()));
Endpoint::Pointer UserInputMapper::endpointFor(const ScriptValue& endpoint) {
if (endpoint.isNumber()) {
return endpointFor(Input(endpoint.toInt32()));
}
if (endpoint->isFunction()) {
if (endpoint.isFunction()) {
auto result = std::make_shared<ScriptEndpoint>(endpoint);
return result;
}
if (endpoint->isArray()) {
int length = endpoint->property("length")->toInteger();
if (endpoint.isArray()) {
int length = endpoint.property("length").toInteger();
Endpoint::List children;
for (int i = 0; i < length; i++) {
ScriptValuePointer arrayItem = endpoint->property(i);
ScriptValue arrayItem = endpoint.property(i);
Endpoint::Pointer destination = endpointFor(arrayItem);
if (!destination) {
return Endpoint::Pointer();
@ -687,7 +687,7 @@ Endpoint::Pointer UserInputMapper::endpointFor(const ScriptValuePointer& endpoin
}
qWarning() << "Unsupported input type " << endpoint->toString();
qWarning() << "Unsupported input type " << endpoint.toString();
return Endpoint::Pointer();
}
@ -887,12 +887,12 @@ Conditional::Pointer UserInputMapper::conditionalFor(const QJSValue& condition)
return Conditional::Pointer();
}
Conditional::Pointer UserInputMapper::conditionalFor(const ScriptValuePointer& condition) {
if (condition->isArray()) {
int length = condition->property("length")->toInteger();
Conditional::Pointer UserInputMapper::conditionalFor(const ScriptValue& condition) {
if (condition.isArray()) {
int length = condition.property("length").toInteger();
Conditional::List children;
for (int i = 0; i < length; i++) {
Conditional::Pointer destination = conditionalFor(condition->property(i));
Conditional::Pointer destination = conditionalFor(condition.property(i));
if (!destination) {
return Conditional::Pointer();
}
@ -901,15 +901,15 @@ Conditional::Pointer UserInputMapper::conditionalFor(const ScriptValuePointer& c
return std::make_shared<AndConditional>(children);
}
if (condition->isNumber()) {
return conditionalFor(Input(condition->toInt32()));
if (condition.isNumber()) {
return conditionalFor(Input(condition.toInt32()));
}
if (condition->isFunction()) {
if (condition.isFunction()) {
return std::make_shared<ScriptConditional>(condition);
}
qWarning() << "Unsupported conditional type " << condition->toString();
qWarning() << "Unsupported conditional type " << condition.toString();
return Conditional::Pointer();
}

View file

@ -16,7 +16,6 @@
#include <functional>
#include <memory>
#include <mutex>
#include <QtCore/QSharedPointer>
#include <QtQml/QJSValue>
@ -34,7 +33,6 @@
class ScriptEngine;
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
namespace controller {
@ -168,10 +166,10 @@ namespace controller {
void enableMapping(const MappingPointer& mapping);
void disableMapping(const MappingPointer& mapping);
EndpointPointer endpointFor(const QJSValue& endpoint);
EndpointPointer endpointFor(const ScriptValuePointer& endpoint);
EndpointPointer endpointFor(const ScriptValue& endpoint);
EndpointPointer compositeEndpointFor(EndpointPointer first, EndpointPointer second);
ConditionalPointer conditionalFor(const QJSValue& endpoint);
ConditionalPointer conditionalFor(const ScriptValuePointer& endpoint);
ConditionalPointer conditionalFor(const ScriptValue& endpoint);
ConditionalPointer conditionalFor(const Input& endpoint) const;
MappingPointer parseMapping(const QJsonValue& json);

View file

@ -27,8 +27,8 @@ QObject* MappingBuilderProxy::fromQml(const QJSValue& source) {
return from(sourceEndpoint);
}
QObject* MappingBuilderProxy::from(const ScriptValuePointer& source) {
qCDebug(controllers) << "Creating new Route builder proxy from " << source->toString();
QObject* MappingBuilderProxy::from(const ScriptValue& source) {
qCDebug(controllers) << "Creating new Route builder proxy from " << source.toString();
auto sourceEndpoint = _parent.endpointFor(source);
return from(sourceEndpoint);
}
@ -50,7 +50,7 @@ QObject* MappingBuilderProxy::makeAxisQml(const QJSValue& source1, const QJSValu
return from(_parent.compositeEndpointFor(source1Endpoint, source2Endpoint));
}
QObject* MappingBuilderProxy::makeAxis(const ScriptValuePointer& source1, const ScriptValuePointer& source2) {
QObject* MappingBuilderProxy::makeAxis(const ScriptValue& source1, const ScriptValue& source2) {
auto source1Endpoint = _parent.endpointFor(source1);
auto source2Endpoint = _parent.endpointFor(source2);
return from(_parent.compositeEndpointFor(source1Endpoint, source2Endpoint));

View file

@ -11,7 +11,6 @@
#include <QtCore/QObject>
#include <QtCore/QString>
#include <QtCore/QSharedPointer>
#include "Mapping.h"
#include "Endpoint.h"
@ -19,7 +18,6 @@
class QJSValue;
class QJsonValue;
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
namespace controller {
@ -167,7 +165,7 @@ public:
* of the route data. If a function, it must return a number or a {@link Pose} value as the route data.
* @returns {RouteObject} A route ready for mapping to an action or function using {@link RouteObject} methods.
*/
Q_INVOKABLE QObject* from(const ScriptValuePointer& source);
Q_INVOKABLE QObject* from(const ScriptValue& source);
/*@jsdoc
* Creates a new {@link RouteObject} from two numeric {@link Controller.Hardware} outputs, one applied in the negative
@ -189,7 +187,7 @@ public:
* Controller.disableMapping(MAPPING_NAME);
* });
*/
Q_INVOKABLE QObject* makeAxis(const ScriptValuePointer& source1, const ScriptValuePointer& source2);
Q_INVOKABLE QObject* makeAxis(const ScriptValue& source1, const ScriptValue& source2);
/*@jsdoc
* Enables or disables the mapping. When enabled, the routes in the mapping take effect.

View file

@ -44,8 +44,8 @@ void RouteBuilderProxy::toQml(const QJSValue& destination) {
return to(destinationEndpoint);
}
void RouteBuilderProxy::to(const ScriptValuePointer& destination) {
qCDebug(controllers) << "Completing route " << destination->toString();
void RouteBuilderProxy::to(const ScriptValue& destination) {
qCDebug(controllers) << "Completing route " << destination.toString();
auto destinationEndpoint = _parent.endpointFor(destination);
return to(destinationEndpoint);
}
@ -66,7 +66,7 @@ QObject* RouteBuilderProxy::peek(bool enable) {
return this;
}
QObject* RouteBuilderProxy::when(const ScriptValuePointer& expression) {
QObject* RouteBuilderProxy::when(const ScriptValue& expression) {
// FIXME: Support "!" conditional in simple expression and array expression.
// Note that "!" is supported when parsing a JSON file, in UserInputMapper::parseConditional().
auto newConditional = _parent.conditionalFor(expression);

View file

@ -10,7 +10,6 @@
#define hifi_Controllers_Impl_RouteBuilderProxy_h
#include <QtCore/QObject>
#include <QtCore/QSharedPointer>
#include "Filter.h"
#include "Route.h"
@ -21,7 +20,6 @@
class QJSValue;
class QJsonValue;
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
namespace controller {
@ -117,7 +115,7 @@ class RouteBuilderProxy : public QObject {
* Controller.disableMapping(MAPPING_NAME);
* });
*/
Q_INVOKABLE void to(const ScriptValuePointer& destination);
Q_INVOKABLE void to(const ScriptValue& destination);
/*@jsdoc
* Enables or disables writing debug information for a route to the program log.
@ -195,7 +193,7 @@ class RouteBuilderProxy : public QObject {
* Controller.disableMapping(MAPPING_NAME);
* });
*/
Q_INVOKABLE QObject* when(const ScriptValuePointer& expression);
Q_INVOKABLE QObject* when(const ScriptValue& expression);
/*@jsdoc
* Filters numeric route values to lie between two values; values outside this range are not passed on through the

View file

@ -25,5 +25,5 @@ void ScriptConditional::updateValue() {
return;
}
_lastValue = _callable->call()->toBool();
_lastValue = _callable.call().toBool();
}

View file

@ -11,24 +11,21 @@
#define hifi_Controllers_ScriptConditional_h
#include <QtCore/QObject>
#include <QtCore/QSharedPointer>
#include <ScriptValue.h>
#include "../Conditional.h"
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
namespace controller {
class ScriptConditional : public QObject, public Conditional {
Q_OBJECT;
public:
ScriptConditional(const ScriptValuePointer& callable) : _callable(callable) {}
ScriptConditional(const ScriptValue& callable) : _callable(callable) {}
virtual bool satisfied() override;
protected:
Q_INVOKABLE void updateValue();
private:
ScriptValuePointer _callable;
ScriptValue _callable;
bool _lastValue { false };
};

View file

@ -17,14 +17,14 @@
using namespace controller;
QString formatException(const ScriptValuePointer& exception) {
QString formatException(const ScriptValue& exception) {
QString note { "UncaughtException" };
QString result;
const auto message = exception->toString();
const auto fileName = exception->property("fileName")->toString();
const auto lineNumber = exception->property("lineNumber")->toString();
const auto stacktrace = exception->property("stack")->toString();
const auto message = exception.toString();
const auto fileName = exception.property("fileName").toString();
const auto lineNumber = exception.property("lineNumber").toString();
const auto stacktrace = exception.property("stack").toString();
const QString SCRIPT_EXCEPTION_FORMAT = "[%0] %1 in %2:%3";
const QString SCRIPT_BACKTRACE_SEP = "\n ";
@ -47,13 +47,13 @@ void ScriptEndpoint::updateValue() {
return;
}
ScriptValuePointer result = _callable->call();
if (result->isError()) {
ScriptValue result = _callable.call();
if (result.isError()) {
// print JavaScript exception
qCDebug(controllers).noquote() << formatException(result);
_lastValueRead = 0.0f;
} else if (result->isNumber()) {
_lastValueRead = (float)_callable->call()->toNumber();
} else if (result.isNumber()) {
_lastValueRead = (float)_callable.call().toNumber();
} else {
Pose::fromScriptValue(result, _lastPoseRead);
_returnPose = true;
@ -75,10 +75,10 @@ void ScriptEndpoint::internalApply(float value, int sourceID) {
Q_ARG(int, sourceID));
return;
}
ScriptEnginePointer engine = _callable->engine();
ScriptValuePointer result = _callable->call(ScriptValuePointer(),
ScriptEnginePointer engine = _callable.engine();
ScriptValue result = _callable.call(ScriptValue(),
ScriptValueList({ engine->newValue(value), engine->newValue(sourceID) }));
if (result->isError()) {
if (result.isError()) {
// print JavaScript exception
qCDebug(controllers).noquote() << formatException(result);
}
@ -94,8 +94,8 @@ void ScriptEndpoint::updatePose() {
QMetaObject::invokeMethod(this, "updatePose", Qt::QueuedConnection);
return;
}
ScriptValuePointer result = _callable->call();
if (result->isError()) {
ScriptValue result = _callable.call();
if (result.isError()) {
// print JavaScript exception
qCDebug(controllers).noquote() << formatException(result);
}
@ -117,10 +117,10 @@ void ScriptEndpoint::internalApply(const Pose& newPose, int sourceID) {
Q_ARG(int, sourceID));
return;
}
ScriptEnginePointer engine = _callable->engine();
ScriptValuePointer result = _callable->call(ScriptValuePointer(),
ScriptEnginePointer engine = _callable.engine();
ScriptValue result = _callable.call(ScriptValue(),
ScriptValueList({ Pose::toScriptValue(engine.get(), newPose), engine->newValue(sourceID) }));
if (result->isError()) {
if (result.isError()) {
// print JavaScript exception
qCDebug(controllers).noquote() << formatException(result);
}

View file

@ -10,20 +10,17 @@
#ifndef hifi_Controllers_ScriptEndpoint_h
#define hifi_Controllers_ScriptEndpoint_h
#include <QtCore/QSharedPointer>
#include <ScriptValue.h>
#include "../Endpoint.h"
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
namespace controller {
class ScriptEndpoint : public Endpoint {
Q_OBJECT;
public:
using Endpoint::apply;
ScriptEndpoint(const ScriptValuePointer& callable)
ScriptEndpoint(const ScriptValue& callable)
: Endpoint(Input::INVALID_INPUT), _callable(callable) {
}
@ -42,7 +39,7 @@ protected:
Q_INVOKABLE void updatePose();
Q_INVOKABLE virtual void internalApply(const Pose& newValue, int sourceID);
private:
ScriptValuePointer _callable;
ScriptValue _callable;
float _lastValueRead { 0.0f };
AxisValue _lastValueWritten { 0.0f, 0, false };

View file

@ -41,7 +41,7 @@ QString ModelScriptingInterface::meshToOBJ(MeshProxyList in) {
return writeOBJToString(meshes);
}
ScriptValuePointer ModelScriptingInterface::appendMeshes(MeshProxyList in) {
ScriptValue ModelScriptingInterface::appendMeshes(MeshProxyList in) {
// figure out the size of the resulting mesh
size_t totalVertexCount { 0 };
size_t totalColorCount { 0 };
@ -149,13 +149,13 @@ ScriptValuePointer ModelScriptingInterface::appendMeshes(MeshProxyList in) {
return meshToScriptValue(_modelScriptEngine.get(), resultProxy);
}
ScriptValuePointer ModelScriptingInterface::transformMesh(glm::mat4 transform, MeshProxy* meshProxy) {
ScriptValue ModelScriptingInterface::transformMesh(glm::mat4 transform, MeshProxy* meshProxy) {
if (!meshProxy) {
return ScriptValuePointer(false);
return ScriptValue();
}
MeshPointer mesh = meshProxy->getMeshPointer();
if (!mesh) {
return ScriptValuePointer(false);
return ScriptValue();
}
const auto inverseTransposeTransform = glm::inverse(glm::transpose(transform));
@ -167,13 +167,13 @@ ScriptValuePointer ModelScriptingInterface::transformMesh(glm::mat4 transform, M
return meshToScriptValue(_modelScriptEngine.get(), resultProxy);
}
ScriptValuePointer ModelScriptingInterface::getVertexCount(MeshProxy* meshProxy) {
ScriptValue ModelScriptingInterface::getVertexCount(MeshProxy* meshProxy) {
if (!meshProxy) {
return ScriptValuePointer(false);
return ScriptValue();
}
MeshPointer mesh = meshProxy->getMeshPointer();
if (!mesh) {
return ScriptValuePointer(false);
return ScriptValue();
}
gpu::BufferView::Index numVertices = (gpu::BufferView::Index)mesh->getNumVertices();
@ -181,20 +181,20 @@ ScriptValuePointer ModelScriptingInterface::getVertexCount(MeshProxy* meshProxy)
return _modelScriptEngine->newValue(numVertices);
}
ScriptValuePointer ModelScriptingInterface::getVertex(MeshProxy* meshProxy, int vertexIndex) {
ScriptValue ModelScriptingInterface::getVertex(MeshProxy* meshProxy, int vertexIndex) {
if (!meshProxy) {
return ScriptValuePointer(false);
return ScriptValue();
}
MeshPointer mesh = meshProxy->getMeshPointer();
if (!mesh) {
return ScriptValuePointer(false);
return ScriptValue();
}
const gpu::BufferView& vertexBufferView = mesh->getVertexBuffer();
gpu::BufferView::Index numVertices = (gpu::BufferView::Index)mesh->getNumVertices();
if (vertexIndex < 0 || vertexIndex >= numVertices) {
return ScriptValuePointer(false);
return ScriptValue();
}
glm::vec3 pos = vertexBufferView.get<glm::vec3>(vertexIndex);
@ -202,7 +202,7 @@ ScriptValuePointer ModelScriptingInterface::getVertex(MeshProxy* meshProxy, int
}
ScriptValuePointer ModelScriptingInterface::newMesh(const QVector<glm::vec3>& vertices,
ScriptValue ModelScriptingInterface::newMesh(const QVector<glm::vec3>& vertices,
const QVector<glm::vec3>& normals,
const QVector<MeshFace>& faces) {
graphics::MeshPointer mesh(std::make_shared<graphics::Mesh>());

View file

@ -19,11 +19,10 @@
#include <QtCore/QSharedPointer>
#include <RegisteredMetaTypes.h>
#include <ScriptValue.h>
class ScriptEngine;
class ScriptValue;
using ScriptEnginePointer = QSharedPointer<ScriptEngine>;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
/*@jsdoc
* The <code>Model</code> API provides the ability to manipulate meshes. You can get the meshes for an entity using
@ -61,7 +60,7 @@ public:
* @param {MeshProxy[]} meshes - The meshes to combine.
* @returns {MeshProxy} The combined mesh.
*/
Q_INVOKABLE ScriptValuePointer appendMeshes(MeshProxyList in);
Q_INVOKABLE ScriptValue appendMeshes(MeshProxyList in);
/*@jsdoc
* Transforms the vertices in a mesh.
@ -70,7 +69,7 @@ public:
* @param {MeshProxy} mesh - The mesh to apply the transform to.
* @returns {MeshProxy|boolean} The transformed mesh, if valid. <code>false</code> if an error.
*/
Q_INVOKABLE ScriptValuePointer transformMesh(glm::mat4 transform, MeshProxy* meshProxy);
Q_INVOKABLE ScriptValue transformMesh(glm::mat4 transform, MeshProxy* meshProxy);
/*@jsdoc
* Creates a new mesh.
@ -80,7 +79,7 @@ public:
* @param {MeshFace[]} faces - The faces in the mesh.
* @returns {MeshProxy} A new mesh.
*/
Q_INVOKABLE ScriptValuePointer newMesh(const QVector<glm::vec3>& vertices,
Q_INVOKABLE ScriptValue newMesh(const QVector<glm::vec3>& vertices,
const QVector<glm::vec3>& normals,
const QVector<MeshFace>& faces);
@ -90,7 +89,7 @@ public:
* @param {MeshProxy} mesh - The mesh to count the vertices in.
* @returns {number|boolean} The number of vertices in the mesh, if valid. <code>false</code> if an error.
*/
Q_INVOKABLE ScriptValuePointer getVertexCount(MeshProxy* meshProxy);
Q_INVOKABLE ScriptValue getVertexCount(MeshProxy* meshProxy);
/*@jsdoc
* Gets the position of a vertex in a mesh.
@ -99,7 +98,7 @@ public:
* @param {number} index - The index of the vertex to get.
* @returns {Vec3|boolean} The local position of the vertex relative to the mesh, if valid. <code>false</code> if an error.
*/
Q_INVOKABLE ScriptValuePointer getVertex(MeshProxy* meshProxy, int vertexIndex);
Q_INVOKABLE ScriptValue getVertex(MeshProxy* meshProxy, int vertexIndex);
private:
ScriptEnginePointer _modelScriptEngine { nullptr };

View file

@ -19,14 +19,14 @@
const float AmbientLightPropertyGroup::DEFAULT_AMBIENT_LIGHT_INTENSITY = 0.5f;
void AmbientLightPropertyGroup::copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValuePointer& properties,
void AmbientLightPropertyGroup::copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValue& properties,
ScriptEngine* engine, bool skipDefaults, EntityItemProperties& defaultEntityProperties) const {
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_AMBIENT_LIGHT_INTENSITY, AmbientLight, ambientLight, AmbientIntensity, ambientIntensity);
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_AMBIENT_LIGHT_URL, AmbientLight, ambientLight, AmbientURL, ambientURL);
}
void AmbientLightPropertyGroup::copyFromScriptValue(const ScriptValuePointer& object, bool& _defaultSettings) {
void AmbientLightPropertyGroup::copyFromScriptValue(const ScriptValue& object, bool& _defaultSettings) {
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(ambientLight, ambientIntensity, float, setAmbientIntensity);
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(ambientLight, ambientURL, QString, setAmbientURL);

View file

@ -17,7 +17,6 @@
#include <glm/glm.hpp>
#include <QtCore/QSharedPointer>
#include "EntityItemPropertiesMacros.h"
#include "PropertyGroup.h"
@ -28,7 +27,6 @@ class EntityTreeElementExtraEncodeData;
class ReadBitstreamToTreeParams;
class ScriptEngine;
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
/*@jsdoc
* Ambient light is defined by the following properties:
@ -41,10 +39,10 @@ using ScriptValuePointer = QSharedPointer<ScriptValue>;
class AmbientLightPropertyGroup : public PropertyGroup {
public:
// EntityItemProperty related helpers
virtual void copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValuePointer& properties,
virtual void copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValue& properties,
ScriptEngine* engine, bool skipDefaults,
EntityItemProperties& defaultEntityProperties) const override;
virtual void copyFromScriptValue(const ScriptValuePointer& object, bool& _defaultSettings) override;
virtual void copyFromScriptValue(const ScriptValue& object, bool& _defaultSettings) override;
void merge(const AmbientLightPropertyGroup& other);

View file

@ -65,7 +65,7 @@ bool operator!=(const AnimationPropertyGroup& a, const AnimationPropertyGroup& b
* @property {boolean} hold=false - <code>true</code> if the rotations and translations of the last frame played are
* maintained when the animation stops playing, <code>false</code> if they aren't.
*/
void AnimationPropertyGroup::copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValuePointer& properties, ScriptEngine* engine, bool skipDefaults, EntityItemProperties& defaultEntityProperties) const {
void AnimationPropertyGroup::copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValue& properties, ScriptEngine* engine, bool skipDefaults, EntityItemProperties& defaultEntityProperties) const {
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_ANIMATION_URL, Animation, animation, URL, url);
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_ANIMATION_ALLOW_TRANSLATION, Animation, animation, AllowTranslation, allowTranslation);
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_ANIMATION_FPS, Animation, animation, FPS, fps);
@ -78,7 +78,7 @@ void AnimationPropertyGroup::copyToScriptValue(const EntityPropertyFlags& desire
}
void AnimationPropertyGroup::copyFromScriptValue(const ScriptValuePointer& object, bool& _defaultSettings) {
void AnimationPropertyGroup::copyFromScriptValue(const ScriptValue& object, bool& _defaultSettings) {
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(animation, url, QString, setURL);
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(animation, allowTranslation, bool, setAllowTranslation);

View file

@ -17,7 +17,6 @@
#include <glm/glm.hpp>
#include <QtCore/QSharedPointer>
#include "EntityItemPropertiesMacros.h"
#include "PropertyGroup.h"
@ -28,17 +27,16 @@ class EntityTreeElementExtraEncodeData;
class ReadBitstreamToTreeParams;
class ScriptEngine;
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
class AnimationPropertyGroup : public PropertyGroup {
public:
static const float MAXIMUM_POSSIBLE_FRAME;
// EntityItemProperty related helpers
virtual void copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValuePointer& properties,
virtual void copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValue& properties,
ScriptEngine* engine, bool skipDefaults,
EntityItemProperties& defaultEntityProperties) const override;
virtual void copyFromScriptValue(const ScriptValuePointer& object, bool& _defaultSettings) override;
virtual void copyFromScriptValue(const ScriptValue& object, bool& _defaultSettings) override;
void merge(const AnimationPropertyGroup& other);

View file

@ -16,13 +16,13 @@
#include "EntityItemProperties.h"
#include "EntityItemPropertiesMacros.h"
void BloomPropertyGroup::copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValuePointer& properties, ScriptEngine* engine, bool skipDefaults, EntityItemProperties& defaultEntityProperties) const {
void BloomPropertyGroup::copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValue& properties, ScriptEngine* engine, bool skipDefaults, EntityItemProperties& defaultEntityProperties) const {
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_BLOOM_INTENSITY, Bloom, bloom, BloomIntensity, bloomIntensity);
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_BLOOM_THRESHOLD, Bloom, bloom, BloomThreshold, bloomThreshold);
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_BLOOM_SIZE, Bloom, bloom, BloomSize, bloomSize);
}
void BloomPropertyGroup::copyFromScriptValue(const ScriptValuePointer& object, bool& _defaultSettings) {
void BloomPropertyGroup::copyFromScriptValue(const ScriptValue& object, bool& _defaultSettings) {
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(bloom, bloomIntensity, float, setBloomIntensity);
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(bloom, bloomThreshold, float, setBloomThreshold);
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(bloom, bloomSize, float, setBloomSize);

View file

@ -15,8 +15,6 @@
#include <stdint.h>
#include <glm/glm.hpp>
#include <QtCore/QSharedPointer>
#include "PropertyGroup.h"
#include "EntityItemPropertiesMacros.h"
@ -27,7 +25,6 @@ class EntityTreeElementExtraEncodeData;
class ReadBitstreamToTreeParams;
class ScriptEngine;
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
static const float INITIAL_BLOOM_INTENSITY { 0.25f };
static const float INITIAL_BLOOM_THRESHOLD { 0.7f };
@ -43,10 +40,10 @@ static const float INITIAL_BLOOM_SIZE { 0.9f };
class BloomPropertyGroup : public PropertyGroup {
public:
// EntityItemProperty related helpers
virtual void copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValuePointer& properties,
virtual void copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValue& properties,
ScriptEngine* engine, bool skipDefaults,
EntityItemProperties& defaultEntityProperties) const override;
virtual void copyFromScriptValue(const ScriptValuePointer& object, bool& _defaultSettings) override;
virtual void copyFromScriptValue(const ScriptValue& object, bool& _defaultSettings) override;
void merge(const BloomPropertyGroup& other);

View file

@ -79,10 +79,10 @@ bool EntityEditFilters::filter(glm::vec3& position, EntityItemProperties& proper
auto oldProperties = propertiesIn.getDesiredProperties();
auto specifiedProperties = propertiesIn.getChangedProperties();
propertiesIn.setDesiredProperties(specifiedProperties);
ScriptValuePointer inputValues = propertiesIn.copyToScriptValue(filterData.engine, false, true, true);
ScriptValue inputValues = propertiesIn.copyToScriptValue(filterData.engine, false, true, true);
propertiesIn.setDesiredProperties(oldProperties);
auto in = QJsonValue::fromVariant(inputValues->toVariant()); // grab json copy now, because the inputValues might be side effected by the filter.
auto in = QJsonValue::fromVariant(inputValues.toVariant()); // grab json copy now, because the inputValues might be side effected by the filter.
ScriptValueList args;
args << inputValues;
@ -91,7 +91,7 @@ bool EntityEditFilters::filter(glm::vec3& position, EntityItemProperties& proper
// get the current properties for then entity and include them for the filter call
if (existingEntity && filterData.wantsOriginalProperties) {
auto currentProperties = existingEntity->getProperties(filterData.includedOriginalProperties);
ScriptValuePointer currentValues = currentProperties.copyToScriptValue(filterData.engine, false, true, true);
ScriptValue currentValues = currentProperties.copyToScriptValue(filterData.engine, false, true, true);
args << currentValues;
}
@ -101,22 +101,22 @@ bool EntityEditFilters::filter(glm::vec3& position, EntityItemProperties& proper
auto zoneEntity = _tree->findEntityByEntityItemID(id);
if (zoneEntity) {
auto zoneProperties = zoneEntity->getProperties(filterData.includedZoneProperties);
ScriptValuePointer zoneValues = zoneProperties.copyToScriptValue(filterData.engine, false, true, true);
ScriptValue zoneValues = zoneProperties.copyToScriptValue(filterData.engine, false, true, true);
if (filterData.wantsZoneBoundingBox) {
bool success = true;
AABox aaBox = zoneEntity->getAABox(success);
if (success) {
ScriptValuePointer boundingBox = filterData.engine->newObject();
ScriptValuePointer bottomRightNear = vec3ToScriptValue(filterData.engine, aaBox.getCorner());
ScriptValuePointer topFarLeft = vec3ToScriptValue(filterData.engine, aaBox.calcTopFarLeft());
ScriptValuePointer center = vec3ToScriptValue(filterData.engine, aaBox.calcCenter());
ScriptValuePointer boundingBoxDimensions = vec3ToScriptValue(filterData.engine, aaBox.getDimensions());
boundingBox->setProperty("brn", bottomRightNear);
boundingBox->setProperty("tfl", topFarLeft);
boundingBox->setProperty("center", center);
boundingBox->setProperty("dimensions", boundingBoxDimensions);
zoneValues->setProperty("boundingBox", boundingBox);
ScriptValue boundingBox = filterData.engine->newObject();
ScriptValue bottomRightNear = vec3ToScriptValue(filterData.engine, aaBox.getCorner());
ScriptValue topFarLeft = vec3ToScriptValue(filterData.engine, aaBox.calcTopFarLeft());
ScriptValue center = vec3ToScriptValue(filterData.engine, aaBox.calcCenter());
ScriptValue boundingBoxDimensions = vec3ToScriptValue(filterData.engine, aaBox.getDimensions());
boundingBox.setProperty("brn", bottomRightNear);
boundingBox.setProperty("tfl", topFarLeft);
boundingBox.setProperty("center", center);
boundingBox.setProperty("dimensions", boundingBoxDimensions);
zoneValues.setProperty("boundingBox", boundingBox);
}
}
@ -125,32 +125,32 @@ bool EntityEditFilters::filter(glm::vec3& position, EntityItemProperties& proper
// to be the fourth parameter, so we need to pad the args accordingly
int EXPECTED_ARGS = 3;
if (args.length() < EXPECTED_ARGS) {
args << ScriptValuePointer();
args << ScriptValue();
}
assert(args.length() == EXPECTED_ARGS); // we MUST have 3 args by now!
args << zoneValues;
}
}
ScriptValuePointer result = filterData.filterFn->call(_nullObjectForFilter, args);
ScriptValue result = filterData.filterFn.call(_nullObjectForFilter, args);
if (filterData.uncaughtExceptions()) {
return false;
}
if (result->isObject()) {
if (result.isObject()) {
// make propertiesIn reflect the changes, for next filter...
propertiesIn.copyFromScriptValue(result, false);
// and update propertiesOut too. TODO: this could be more efficient...
propertiesOut.copyFromScriptValue(result, false);
// Javascript objects are == only if they are the same object. To compare arbitrary values, we need to use JSON.
auto out = QJsonValue::fromVariant(result->toVariant());
auto out = QJsonValue::fromVariant(result.toVariant());
wasChanged |= (in != out);
} else if (result->isBool()) {
} else if (result.isBool()) {
// if the filter returned false, then it's authoritative
if (!result->toBool()) {
if (!result.toBool()) {
return false;
}
@ -235,7 +235,7 @@ static bool hasCorrectSyntax(const ScriptProgramPointer& program) {
static bool hadUncaughtExceptions(ScriptEngine& engine, const QString& fileName) {
if (engine.hasUncaughtException()) {
const auto backtrace = engine.uncaughtExceptionBacktrace();
const auto exception = engine.uncaughtException()->toString();
const auto exception = engine.uncaughtException().toString();
const auto line = QString::number(engine.uncaughtExceptionLineNumber());
engine.clearExceptions();
@ -267,7 +267,7 @@ void EntityEditFilters::scriptRequestFinished(EntityItemID entityID) {
engine->setProperty("type", "edit_filter");
engine->setProperty("fileName", urlString);
engine->setProperty("entityID", entityID);
engine->globalObject()->setProperty("Script", engine->newQObject(manager.get()));
engine->globalObject().setProperty("Script", engine->newQObject(manager.get()));
DependencyManager::get<ScriptInitializers>()->runScriptInitializers(engine.data());
engine->evaluate(scriptContents, urlString);
if (!hadUncaughtExceptions(*engine, urlString)) {
@ -283,68 +283,68 @@ void EntityEditFilters::scriptRequestFinished(EntityItemID entityID) {
// now get the filter function
auto global = engine->globalObject();
auto entitiesObject = engine->newObject();
entitiesObject->setProperty("ADD_FILTER_TYPE", EntityTree::FilterType::Add);
entitiesObject->setProperty("EDIT_FILTER_TYPE", EntityTree::FilterType::Edit);
entitiesObject->setProperty("PHYSICS_FILTER_TYPE", EntityTree::FilterType::Physics);
entitiesObject->setProperty("DELETE_FILTER_TYPE", EntityTree::FilterType::Delete);
global->setProperty("Entities", entitiesObject);
filterData.filterFn = global->property("filter");
if (!filterData.filterFn->isFunction()) {
entitiesObject.setProperty("ADD_FILTER_TYPE", EntityTree::FilterType::Add);
entitiesObject.setProperty("EDIT_FILTER_TYPE", EntityTree::FilterType::Edit);
entitiesObject.setProperty("PHYSICS_FILTER_TYPE", EntityTree::FilterType::Physics);
entitiesObject.setProperty("DELETE_FILTER_TYPE", EntityTree::FilterType::Delete);
global.setProperty("Entities", entitiesObject);
filterData.filterFn = global.property("filter");
if (!filterData.filterFn.isFunction()) {
qDebug() << "Filter function specified but not found. Will reject all edits for those without lock rights.";
engine.reset();
filterData.rejectAll=true;
}
// if the wantsToFilterEdit is a boolean evaluate as a boolean, otherwise assume true
ScriptValuePointer wantsToFilterAddValue = filterData.filterFn->property("wantsToFilterAdd");
filterData.wantsToFilterAdd = wantsToFilterAddValue->isBool() ? wantsToFilterAddValue->toBool() : true;
ScriptValue wantsToFilterAddValue = filterData.filterFn.property("wantsToFilterAdd");
filterData.wantsToFilterAdd = wantsToFilterAddValue.isBool() ? wantsToFilterAddValue.toBool() : true;
// if the wantsToFilterEdit is a boolean evaluate as a boolean, otherwise assume true
ScriptValuePointer wantsToFilterEditValue = filterData.filterFn->property("wantsToFilterEdit");
filterData.wantsToFilterEdit = wantsToFilterEditValue->isBool() ? wantsToFilterEditValue->toBool() : true;
ScriptValue wantsToFilterEditValue = filterData.filterFn.property("wantsToFilterEdit");
filterData.wantsToFilterEdit = wantsToFilterEditValue.isBool() ? wantsToFilterEditValue.toBool() : true;
// if the wantsToFilterPhysics is a boolean evaluate as a boolean, otherwise assume true
ScriptValuePointer wantsToFilterPhysicsValue = filterData.filterFn->property("wantsToFilterPhysics");
filterData.wantsToFilterPhysics = wantsToFilterPhysicsValue->isBool() ? wantsToFilterPhysicsValue->toBool() : true;
ScriptValue wantsToFilterPhysicsValue = filterData.filterFn.property("wantsToFilterPhysics");
filterData.wantsToFilterPhysics = wantsToFilterPhysicsValue.isBool() ? wantsToFilterPhysicsValue.toBool() : true;
// if the wantsToFilterDelete is a boolean evaluate as a boolean, otherwise assume false
ScriptValuePointer wantsToFilterDeleteValue = filterData.filterFn->property("wantsToFilterDelete");
filterData.wantsToFilterDelete = wantsToFilterDeleteValue->isBool() ? wantsToFilterDeleteValue->toBool() : false;
ScriptValue wantsToFilterDeleteValue = filterData.filterFn.property("wantsToFilterDelete");
filterData.wantsToFilterDelete = wantsToFilterDeleteValue.isBool() ? wantsToFilterDeleteValue.toBool() : false;
// check to see if the filterFn has properties asking for Original props
ScriptValuePointer wantsOriginalPropertiesValue = filterData.filterFn->property("wantsOriginalProperties");
ScriptValue wantsOriginalPropertiesValue = filterData.filterFn.property("wantsOriginalProperties");
// if the wantsOriginalProperties is a boolean, or a string, or list of strings, then evaluate as follows:
// - boolean - true - include all original properties
// false - no properties at all
// - string - empty - no properties at all
// any valid property - include just that property in the Original properties
// - list of strings - include only those properties in the Original properties
if (wantsOriginalPropertiesValue->isBool()) {
filterData.wantsOriginalProperties = wantsOriginalPropertiesValue->toBool();
} else if (wantsOriginalPropertiesValue->isString()) {
auto stringValue = wantsOriginalPropertiesValue->toString();
if (wantsOriginalPropertiesValue.isBool()) {
filterData.wantsOriginalProperties = wantsOriginalPropertiesValue.toBool();
} else if (wantsOriginalPropertiesValue.isString()) {
auto stringValue = wantsOriginalPropertiesValue.toString();
filterData.wantsOriginalProperties = !stringValue.isEmpty();
if (filterData.wantsOriginalProperties) {
EntityPropertyFlagsFromScriptValue(wantsOriginalPropertiesValue, filterData.includedOriginalProperties);
}
} else if (wantsOriginalPropertiesValue->isArray()) {
} else if (wantsOriginalPropertiesValue.isArray()) {
EntityPropertyFlagsFromScriptValue(wantsOriginalPropertiesValue, filterData.includedOriginalProperties);
filterData.wantsOriginalProperties = !filterData.includedOriginalProperties.isEmpty();
}
// check to see if the filterFn has properties asking for Zone props
ScriptValuePointer wantsZonePropertiesValue = filterData.filterFn->property("wantsZoneProperties");
ScriptValue wantsZonePropertiesValue = filterData.filterFn.property("wantsZoneProperties");
// if the wantsZoneProperties is a boolean, or a string, or list of strings, then evaluate as follows:
// - boolean - true - include all Zone properties
// false - no properties at all
// - string - empty - no properties at all
// any valid property - include just that property in the Zone properties
// - list of strings - include only those properties in the Zone properties
if (wantsZonePropertiesValue->isBool()) {
filterData.wantsZoneProperties = wantsZonePropertiesValue->toBool();
if (wantsZonePropertiesValue.isBool()) {
filterData.wantsZoneProperties = wantsZonePropertiesValue.toBool();
filterData.wantsZoneBoundingBox = filterData.wantsZoneProperties; // include this too
} else if (wantsZonePropertiesValue->isString()) {
auto stringValue = wantsZonePropertiesValue->toString();
} else if (wantsZonePropertiesValue.isString()) {
auto stringValue = wantsZonePropertiesValue.toString();
filterData.wantsZoneProperties = !stringValue.isEmpty();
if (filterData.wantsZoneProperties) {
if (stringValue == "boundingBox") {
@ -353,10 +353,10 @@ void EntityEditFilters::scriptRequestFinished(EntityItemID entityID) {
EntityPropertyFlagsFromScriptValue(wantsZonePropertiesValue, filterData.includedZoneProperties);
}
}
} else if (wantsZonePropertiesValue->isArray()) {
auto length = wantsZonePropertiesValue->property("length")->toInteger();
} else if (wantsZonePropertiesValue.isArray()) {
auto length = wantsZonePropertiesValue.property("length").toInteger();
for (int i = 0; i < length; i++) {
auto stringValue = wantsZonePropertiesValue->property(i)->toString();
auto stringValue = wantsZonePropertiesValue.property(i).toString();
if (!stringValue.isEmpty()) {
filterData.wantsZoneProperties = true;

View file

@ -13,7 +13,6 @@
#include <QObject>
#include <QMap>
#include <QtCore/QSharedPointer>
#include <glm/glm.hpp>
#include <functional>
@ -30,7 +29,7 @@ class EntityEditFilters : public QObject, public Dependency {
Q_OBJECT
public:
struct FilterData {
ScriptValuePointer filterFn;
ScriptValue filterFn;
bool wantsOriginalProperties { false };
bool wantsZoneProperties { false };
@ -48,7 +47,7 @@ public:
bool rejectAll;
FilterData(): engine(nullptr), rejectAll(false) {};
bool valid() { return (rejectAll || (engine != nullptr && filterFn->isFunction() && uncaughtExceptions)); }
bool valid() { return (rejectAll || (engine != nullptr && filterFn.isFunction() && uncaughtExceptions)); }
};
EntityEditFilters() {};
@ -71,7 +70,7 @@ private:
EntityTreePointer _tree {};
bool _rejectAll {false};
ScriptValuePointer _nullObjectForFilter{};
ScriptValue _nullObjectForFilter{};
QReadWriteLock _lock;
QMap<EntityItemID, FilterData> _filterDataMap;

View file

@ -1576,14 +1576,14 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const {
* @property {Entities.RingGizmo} ring - The ring gizmo properties.
*/
ScriptValuePointer EntityItemProperties::copyToScriptValue(ScriptEngine* engine, bool skipDefaults, bool allowUnknownCreateTime,
ScriptValue EntityItemProperties::copyToScriptValue(ScriptEngine* engine, bool skipDefaults, bool allowUnknownCreateTime,
bool strictSemantics, EntityPsuedoPropertyFlags psueudoPropertyFlags) const {
// If strictSemantics is true and skipDefaults is false, then all and only those properties are copied for which the property flag
// is included in _desiredProperties, or is one of the specially enumerated ALWAYS properties below.
// (There may be exceptions, but if so, they are bugs.)
// In all other cases, you are welcome to inspect the code and try to figure out what was intended. I wish you luck. -HRS 1/18/17
ScriptValuePointer properties = engine->newObject();
ScriptValue properties = engine->newObject();
EntityItemProperties defaultEntityProperties;
const bool psuedoPropertyFlagsActive = psueudoPropertyFlags.test(EntityPsuedoPropertyFlag::FlagsActive);
@ -1610,7 +1610,7 @@ ScriptValuePointer EntityItemProperties::copyToScriptValue(ScriptEngine* engine,
}
}
if (!psuedoPropertyFlagsActive || psueudoPropertyFlags.test(EntityPsuedoPropertyFlag::LastEdited)) {
properties->setProperty("lastEdited", convertScriptValue(engine, _lastEdited));
properties.setProperty("lastEdited", convertScriptValue(engine, _lastEdited));
}
if (!skipDefaults) {
COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_DIMENSIONS, naturalDimensions); // gettable, but not settable
@ -1927,9 +1927,9 @@ ScriptValuePointer EntityItemProperties::copyToScriptValue(ScriptEngine* engine,
// Handle conversions to old 'textures' property from "imageURL"
if (((!psuedoPropertyFlagsButDesiredEmpty && _desiredProperties.isEmpty()) || _desiredProperties.getHasProperty(PROP_IMAGE_URL)) &&
(!skipDefaults || defaultEntityProperties._imageURL != _imageURL)) {
ScriptValuePointer textures = engine->newObject();
textures->setProperty("tex.picture", _imageURL);
properties->setProperty("textures", textures);
ScriptValue textures = engine->newObject();
textures.setProperty("tex.picture", _imageURL);
properties.setProperty("textures", textures);
}
}
@ -1962,15 +1962,15 @@ ScriptValuePointer EntityItemProperties::copyToScriptValue(ScriptEngine* engine,
(!psuedoPropertyFlagsActive || psueudoPropertyFlags.test(EntityPsuedoPropertyFlag::BoundingBox))) {
AABox aaBox = getAABox();
ScriptValuePointer boundingBox = engine->newObject();
ScriptValuePointer bottomRightNear = vec3ToScriptValue(engine, aaBox.getCorner());
ScriptValuePointer topFarLeft = vec3ToScriptValue(engine, aaBox.calcTopFarLeft());
ScriptValuePointer center = vec3ToScriptValue(engine, aaBox.calcCenter());
ScriptValuePointer boundingBoxDimensions = vec3ToScriptValue(engine, aaBox.getDimensions());
boundingBox->setProperty("brn", bottomRightNear);
boundingBox->setProperty("tfl", topFarLeft);
boundingBox->setProperty("center", center);
boundingBox->setProperty("dimensions", boundingBoxDimensions);
ScriptValue boundingBox = engine->newObject();
ScriptValue bottomRightNear = vec3ToScriptValue(engine, aaBox.getCorner());
ScriptValue topFarLeft = vec3ToScriptValue(engine, aaBox.calcTopFarLeft());
ScriptValue center = vec3ToScriptValue(engine, aaBox.calcCenter());
ScriptValue boundingBoxDimensions = vec3ToScriptValue(engine, aaBox.getDimensions());
boundingBox.setProperty("brn", bottomRightNear);
boundingBox.setProperty("tfl", topFarLeft);
boundingBox.setProperty("center", center);
boundingBox.setProperty("dimensions", boundingBoxDimensions);
COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER_NO_SKIP(boundingBox, boundingBox); // gettable, but not settable
}
@ -1983,7 +1983,7 @@ ScriptValuePointer EntityItemProperties::copyToScriptValue(ScriptEngine* engine,
if (!skipDefaults && !strictSemantics &&
(!psuedoPropertyFlagsActive || psueudoPropertyFlags.test(EntityPsuedoPropertyFlag::RenderInfo))) {
ScriptValuePointer renderInfo = engine->newObject();
ScriptValue renderInfo = engine->newObject();
/*@jsdoc
* Information on how an entity is rendered. Properties are only filled in for <code>Model</code> entities; other
@ -1998,40 +1998,40 @@ ScriptValuePointer EntityItemProperties::copyToScriptValue(ScriptEngine* engine,
*/
// currently only supported by models
if (_type == EntityTypes::Model) {
renderInfo->setProperty("verticesCount", (int)getRenderInfoVertexCount()); // FIXME - theoretically the number of vertex could be > max int
renderInfo->setProperty("texturesSize", (int)getRenderInfoTextureSize()); // FIXME - theoretically the size of textures could be > max int
renderInfo->setProperty("hasTransparent", getRenderInfoHasTransparent());
renderInfo->setProperty("drawCalls", getRenderInfoDrawCalls());
renderInfo->setProperty("texturesCount", getRenderInfoTextureCount());
renderInfo.setProperty("verticesCount", (int)getRenderInfoVertexCount()); // FIXME - theoretically the number of vertex could be > max int
renderInfo.setProperty("texturesSize", (int)getRenderInfoTextureSize()); // FIXME - theoretically the size of textures could be > max int
renderInfo.setProperty("hasTransparent", getRenderInfoHasTransparent());
renderInfo.setProperty("drawCalls", getRenderInfoDrawCalls());
renderInfo.setProperty("texturesCount", getRenderInfoTextureCount());
}
COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER_NO_SKIP(renderInfo, renderInfo); // Gettable but not settable
}
if (!psuedoPropertyFlagsActive || psueudoPropertyFlags.test(EntityPsuedoPropertyFlag::ClientOnly)) {
properties->setProperty("clientOnly", convertScriptValue(engine, getEntityHostType() == entity::HostType::AVATAR));
properties.setProperty("clientOnly", convertScriptValue(engine, getEntityHostType() == entity::HostType::AVATAR));
}
if (!psuedoPropertyFlagsActive || psueudoPropertyFlags.test(EntityPsuedoPropertyFlag::AvatarEntity)) {
properties->setProperty("avatarEntity", convertScriptValue(engine, getEntityHostType() == entity::HostType::AVATAR));
properties.setProperty("avatarEntity", convertScriptValue(engine, getEntityHostType() == entity::HostType::AVATAR));
}
if (!psuedoPropertyFlagsActive || psueudoPropertyFlags.test(EntityPsuedoPropertyFlag::LocalEntity)) {
properties->setProperty("localEntity", convertScriptValue(engine, getEntityHostType() == entity::HostType::LOCAL));
properties.setProperty("localEntity", convertScriptValue(engine, getEntityHostType() == entity::HostType::LOCAL));
}
if (_type != EntityTypes::PolyLine && (!psuedoPropertyFlagsActive || psueudoPropertyFlags.test(EntityPsuedoPropertyFlag::FaceCamera))) {
properties->setProperty("faceCamera", convertScriptValue(engine, getBillboardMode() == BillboardMode::YAW));
properties.setProperty("faceCamera", convertScriptValue(engine, getBillboardMode() == BillboardMode::YAW));
}
if (!psuedoPropertyFlagsActive || psueudoPropertyFlags.test(EntityPsuedoPropertyFlag::IsFacingAvatar)) {
properties->setProperty("isFacingAvatar", convertScriptValue(engine, getBillboardMode() == BillboardMode::FULL));
properties.setProperty("isFacingAvatar", convertScriptValue(engine, getBillboardMode() == BillboardMode::FULL));
}
return properties;
}
void EntityItemProperties::copyFromScriptValue(const ScriptValuePointer& object, bool honorReadOnly) {
ScriptValuePointer typeScriptValue = object->property("type");
if (typeScriptValue->isValid()) {
setType(typeScriptValue->toVariant().toString());
void EntityItemProperties::copyFromScriptValue(const ScriptValue& object, bool honorReadOnly) {
ScriptValue typeScriptValue = object.property("type");
if (typeScriptValue.isValid()) {
setType(typeScriptValue.toVariant().toString());
}
// Core
@ -2284,8 +2284,8 @@ void EntityItemProperties::copyFromScriptValue(const ScriptValuePointer& object,
// Handle conversions from old 'textures' property to "imageURL"
{
ScriptValuePointer V = object->property("textures");
if (_type == EntityTypes::Image && V->isValid() && !object->property("imageURL")->isValid()) {
ScriptValue V = object.property("textures");
if (_type == EntityTypes::Image && V.isValid() && !object.property("imageURL").isValid()) {
bool isValid = false;
QString textures = QString_convertFromScriptValue(V, isValid);
if (isValid) {
@ -2303,9 +2303,9 @@ void EntityItemProperties::copyFromScriptValue(const ScriptValuePointer& object,
// Handle old "faceCamera" and "isFacingAvatar" props
if (_type != EntityTypes::PolyLine) {
ScriptValuePointer P = object->property("faceCamera");
if (P->isValid() && !object->property("billboardMode")->isValid()) {
bool newValue = P->toVariant().toBool();
ScriptValue P = object.property("faceCamera");
if (P.isValid() && !object.property("billboardMode").isValid()) {
bool newValue = P.toVariant().toBool();
bool oldValue = getBillboardMode() == BillboardMode::YAW;
if (_defaultSettings || newValue != oldValue) {
setBillboardMode(newValue ? BillboardMode::YAW : BillboardMode::NONE);
@ -2313,9 +2313,9 @@ void EntityItemProperties::copyFromScriptValue(const ScriptValuePointer& object,
}
}
{
ScriptValuePointer P = object->property("isFacingAvatar");
if (P->isValid() && !object->property("billboardMode")->isValid() && !object->property("faceCamera")->isValid()) {
bool newValue = P->toVariant().toBool();
ScriptValue P = object.property("isFacingAvatar");
if (P.isValid() && !object.property("billboardMode").isValid() && !object.property("faceCamera").isValid()) {
bool newValue = P.toVariant().toBool();
bool oldValue = getBillboardMode() == BillboardMode::FULL;
if (_defaultSettings || newValue != oldValue) {
setBillboardMode(newValue ? BillboardMode::FULL : BillboardMode::NONE);
@ -2332,7 +2332,7 @@ void EntityItemProperties::copyFromJSONString(ScriptEngine& scriptEngine, const
QJsonObject propertiesObj = propertiesDoc.object();
QVariant propertiesVariant(propertiesObj);
QVariantMap propertiesMap = propertiesVariant.toMap();
ScriptValuePointer propertiesScriptValue = variantMapToScriptValue(propertiesMap, scriptEngine);
ScriptValue propertiesScriptValue = variantMapToScriptValue(propertiesMap, scriptEngine);
bool honorReadOnly = true;
copyFromScriptValue(propertiesScriptValue, honorReadOnly);
}
@ -2580,47 +2580,47 @@ void EntityItemProperties::merge(const EntityItemProperties& other) {
_lastEdited = usecTimestampNow();
}
ScriptValuePointer EntityItemPropertiesToScriptValue(ScriptEngine* engine, const EntityItemProperties& properties) {
ScriptValue EntityItemPropertiesToScriptValue(ScriptEngine* engine, const EntityItemProperties& properties) {
return properties.copyToScriptValue(engine, false);
}
ScriptValuePointer EntityItemNonDefaultPropertiesToScriptValue(ScriptEngine* engine, const EntityItemProperties& properties) {
ScriptValue EntityItemNonDefaultPropertiesToScriptValue(ScriptEngine* engine, const EntityItemProperties& properties) {
return properties.copyToScriptValue(engine, true);
}
void EntityItemPropertiesFromScriptValueIgnoreReadOnly(const ScriptValuePointer &object, EntityItemProperties& properties) {
void EntityItemPropertiesFromScriptValueIgnoreReadOnly(const ScriptValue &object, EntityItemProperties& properties) {
properties.copyFromScriptValue(object, false);
}
void EntityItemPropertiesFromScriptValueHonorReadOnly(const ScriptValuePointer &object, EntityItemProperties& properties) {
void EntityItemPropertiesFromScriptValueHonorReadOnly(const ScriptValue &object, EntityItemProperties& properties) {
properties.copyFromScriptValue(object, true);
}
ScriptValuePointer EntityPropertyFlagsToScriptValue(ScriptEngine* engine, const EntityPropertyFlags& flags) {
ScriptValue EntityPropertyFlagsToScriptValue(ScriptEngine* engine, const EntityPropertyFlags& flags) {
return EntityItemProperties::entityPropertyFlagsToScriptValue(engine, flags);
}
void EntityPropertyFlagsFromScriptValue(const ScriptValuePointer& object, EntityPropertyFlags& flags) {
void EntityPropertyFlagsFromScriptValue(const ScriptValue& object, EntityPropertyFlags& flags) {
EntityItemProperties::entityPropertyFlagsFromScriptValue(object, flags);
}
ScriptValuePointer EntityItemProperties::entityPropertyFlagsToScriptValue(ScriptEngine* engine, const EntityPropertyFlags& flags) {
ScriptValuePointer result = engine->newObject();
ScriptValue EntityItemProperties::entityPropertyFlagsToScriptValue(ScriptEngine* engine, const EntityPropertyFlags& flags) {
ScriptValue result = engine->newObject();
return result;
}
void EntityItemProperties::entityPropertyFlagsFromScriptValue(const ScriptValuePointer& object, EntityPropertyFlags& flags) {
if (object->isString()) {
void EntityItemProperties::entityPropertyFlagsFromScriptValue(const ScriptValue& object, EntityPropertyFlags& flags) {
if (object.isString()) {
EntityPropertyInfo propertyInfo;
if (getPropertyInfo(object->toString(), propertyInfo)) {
if (getPropertyInfo(object.toString(), propertyInfo)) {
flags << propertyInfo.propertyEnum;
}
}
else if (object->isArray()) {
quint32 length = object->property("length")->toInt32();
else if (object.isArray()) {
quint32 length = object.property("length").toInt32();
for (quint32 i = 0; i < length; i++) {
QString propertyName = object->property(i)->toString();
QString propertyName = object.property(i).toString();
EntityPropertyInfo propertyInfo;
if (getPropertyInfo(propertyName, propertyInfo)) {
flags << propertyInfo.propertyEnum;
@ -3019,18 +3019,18 @@ bool EntityItemProperties::getPropertyInfo(const QString& propertyName, EntityPr
* @property {string} minimum - The minimum numerical value the property may have, if available, otherwise <code>""</code>.
* @property {string} maximum - The maximum numerical value the property may have, if available, otherwise <code>""</code>.
*/
ScriptValuePointer EntityPropertyInfoToScriptValue(ScriptEngine* engine, const EntityPropertyInfo& propertyInfo) {
ScriptValuePointer obj = engine->newObject();
obj->setProperty("propertyEnum", propertyInfo.propertyEnum);
obj->setProperty("minimum", propertyInfo.minimum.toString());
obj->setProperty("maximum", propertyInfo.maximum.toString());
ScriptValue EntityPropertyInfoToScriptValue(ScriptEngine* engine, const EntityPropertyInfo& propertyInfo) {
ScriptValue obj = engine->newObject();
obj.setProperty("propertyEnum", propertyInfo.propertyEnum);
obj.setProperty("minimum", propertyInfo.minimum.toString());
obj.setProperty("maximum", propertyInfo.maximum.toString());
return obj;
}
void EntityPropertyInfoFromScriptValue(const ScriptValuePointer& object, EntityPropertyInfo& propertyInfo) {
propertyInfo.propertyEnum = (EntityPropertyList)object->property("propertyEnum")->toVariant().toUInt();
propertyInfo.minimum = object->property("minimum")->toVariant();
propertyInfo.maximum = object->property("maximum")->toVariant();
void EntityPropertyInfoFromScriptValue(const ScriptValue& object, EntityPropertyInfo& propertyInfo) {
propertyInfo.propertyEnum = (EntityPropertyList)object.property("propertyEnum").toVariant().toUInt();
propertyInfo.minimum = object.property("minimum").toVariant();
propertyInfo.maximum = object.property("maximum").toVariant();
}
// TODO: Implement support for edit packets that can span an MTU sized buffer. We need to implement a mechanism for the
@ -5205,7 +5205,7 @@ bool EntityItemProperties::blobToProperties(ScriptEngine& scriptEngine, const QB
}
QVariant variant = jsonProperties.toVariant();
QVariantMap variantMap = variant.toMap();
ScriptValuePointer scriptValue = variantMapToScriptValue(variantMap, scriptEngine);
ScriptValue scriptValue = variantMapToScriptValue(variantMap, scriptEngine);
EntityItemPropertiesFromScriptValueIgnoreReadOnly(scriptValue, properties);
// end recipe
return true;
@ -5215,10 +5215,10 @@ void EntityItemProperties::propertiesToBlob(ScriptEngine& scriptEngine, const QU
const EntityItemProperties& properties, QByteArray& blob, bool allProperties) {
// DANGER: this method is NOT efficient.
// begin recipe for extracting unfortunately-formatted-binary-blob from EntityItem
ScriptValuePointer scriptValue = allProperties
ScriptValue scriptValue = allProperties
? EntityItemPropertiesToScriptValue(&scriptEngine, properties)
: EntityItemNonDefaultPropertiesToScriptValue(&scriptEngine, properties);
QVariant variantProperties = scriptValue->toVariant();
QVariant variantProperties = scriptValue.toVariant();
QJsonDocument jsonProperties = QJsonDocument::fromVariant(variantProperties);
// the ID of the parent/avatar changes from session to session. use a special UUID to indicate the avatar
QJsonObject jsonObject = jsonProperties.object();

View file

@ -25,7 +25,6 @@
#include <QVector>
#include <QString>
#include <QDateTime>
#include <QtCore/QSharedPointer>
#include <AACube.h>
#include <NumericalConstants.h>
@ -34,8 +33,9 @@
#include <ShapeInfo.h>
#include <ColorUtils.h>
#include "FontFamilies.h"
#include <ScriptValue.h>
#include "EntityItemID.h"
#include <EntityItemID.h>
#include "EntityItemPropertiesDefaults.h"
#include "EntityItemPropertiesMacros.h"
#include "EntityTypes.h"
@ -70,8 +70,6 @@
#include "TextAlignment.h"
class ScriptEngine;
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
const quint64 UNKNOWN_CREATED_TIME = 0;
@ -100,7 +98,7 @@ EntityPropertyInfo makePropertyInfo(EntityPropertyList p, typename std::enable_i
}
/// A collection of properties of an entity item used in the scripting API. Translates between the actual properties of an
/// entity and a JavaScript style hash/ScriptValuePointer storing a set of properties. Used in scripting to set/get the complete
/// entity and a JavaScript style hash/ScriptValue storing a set of properties. Used in scripting to set/get the complete
/// set of entity item properties via JavaScript hashes/QScriptValues
/// all units for SI units (meter, second, radian, etc)
class EntityItemProperties {
@ -137,13 +135,13 @@ public:
EntityTypes::EntityType getType() const { return _type; }
void setType(EntityTypes::EntityType type) { _type = type; }
virtual ScriptValuePointer copyToScriptValue(ScriptEngine* engine, bool skipDefaults, bool allowUnknownCreateTime = false,
virtual ScriptValue copyToScriptValue(ScriptEngine* engine, bool skipDefaults, bool allowUnknownCreateTime = false,
bool strictSemantics = false, EntityPsuedoPropertyFlags psueudoPropertyFlags = EntityPsuedoPropertyFlags()) const;
virtual void copyFromScriptValue(const ScriptValuePointer& object, bool honorReadOnly);
virtual void copyFromScriptValue(const ScriptValue& object, bool honorReadOnly);
void copyFromJSONString(ScriptEngine& scriptEngine, const QString& jsonString);
static ScriptValuePointer entityPropertyFlagsToScriptValue(ScriptEngine* engine, const EntityPropertyFlags& flags);
static void entityPropertyFlagsFromScriptValue(const ScriptValuePointer& object, EntityPropertyFlags& flags);
static ScriptValue entityPropertyFlagsToScriptValue(ScriptEngine* engine, const EntityPropertyFlags& flags);
static void entityPropertyFlagsFromScriptValue(const ScriptValue& object, EntityPropertyFlags& flags);
static bool getPropertyInfo(const QString& propertyName, EntityPropertyInfo& propertyInfo);
@ -543,18 +541,18 @@ private:
};
Q_DECLARE_METATYPE(EntityItemProperties);
ScriptValuePointer EntityItemPropertiesToScriptValue(ScriptEngine* engine, const EntityItemProperties& properties);
ScriptValuePointer EntityItemNonDefaultPropertiesToScriptValue(ScriptEngine* engine, const EntityItemProperties& properties);
void EntityItemPropertiesFromScriptValueIgnoreReadOnly(const ScriptValuePointer& object, EntityItemProperties& properties);
void EntityItemPropertiesFromScriptValueHonorReadOnly(const ScriptValuePointer& object, EntityItemProperties& properties);
ScriptValue EntityItemPropertiesToScriptValue(ScriptEngine* engine, const EntityItemProperties& properties);
ScriptValue EntityItemNonDefaultPropertiesToScriptValue(ScriptEngine* engine, const EntityItemProperties& properties);
void EntityItemPropertiesFromScriptValueIgnoreReadOnly(const ScriptValue& object, EntityItemProperties& properties);
void EntityItemPropertiesFromScriptValueHonorReadOnly(const ScriptValue& object, EntityItemProperties& properties);
Q_DECLARE_METATYPE(EntityPropertyFlags);
ScriptValuePointer EntityPropertyFlagsToScriptValue(ScriptEngine* engine, const EntityPropertyFlags& flags);
void EntityPropertyFlagsFromScriptValue(const ScriptValuePointer& object, EntityPropertyFlags& flags);
ScriptValue EntityPropertyFlagsToScriptValue(ScriptEngine* engine, const EntityPropertyFlags& flags);
void EntityPropertyFlagsFromScriptValue(const ScriptValue& object, EntityPropertyFlags& flags);
Q_DECLARE_METATYPE(EntityPropertyInfo);
ScriptValuePointer EntityPropertyInfoToScriptValue(ScriptEngine* engine, const EntityPropertyInfo& propertyInfo);
void EntityPropertyInfoFromScriptValue(const ScriptValuePointer& object, EntityPropertyInfo& propertyInfo);
ScriptValue EntityPropertyInfoToScriptValue(ScriptEngine* engine, const EntityPropertyInfo& propertyInfo);
void EntityPropertyInfoFromScriptValue(const ScriptValue& object, EntityPropertyInfo& propertyInfo);
// define these inline here so the macros work
inline void EntityItemProperties::setPosition(const glm::vec3& value)

View file

@ -13,11 +13,11 @@
#ifndef hifi_EntityItemPropertiesMacros_h
#define hifi_EntityItemPropertiesMacros_h
#include "EntityItemID.h"
#include <EntityItemID.h>
#include <RegisteredMetaTypes.h>
#include "ScriptEngine.h"
#include "ScriptValue.h"
#include "ScriptValueUtils.h"
#include <ScriptEngine.h>
#include <ScriptValue.h>
#include <ScriptValueUtils.h>
#define APPEND_ENTITY_PROPERTY(P,V) \
if (requestedProperties.getHasProperty(P)) { \
@ -102,118 +102,118 @@
changedProperties += P; \
}
inline ScriptValuePointer convertScriptValue(ScriptEngine* e, const glm::vec2& v) { return vec2ToScriptValue(e, v); }
inline ScriptValuePointer convertScriptValue(ScriptEngine* e, const glm::vec3& v) { return vec3ToScriptValue(e, v); }
inline ScriptValuePointer vec3Color_convertScriptValue(ScriptEngine* e, const glm::vec3& v) { return vec3ColorToScriptValue(e, v); }
inline ScriptValuePointer convertScriptValue(ScriptEngine* e, const glm::u8vec3& v) { return u8vec3ToScriptValue(e, v); }
inline ScriptValuePointer u8vec3Color_convertScriptValue(ScriptEngine* e, const glm::u8vec3& v) { return u8vec3ColorToScriptValue(e, v); }
inline ScriptValuePointer convertScriptValue(ScriptEngine* e, float v) { return e->newValue(v); }
inline ScriptValuePointer convertScriptValue(ScriptEngine* e, int v) { return e->newValue(v); }
inline ScriptValuePointer convertScriptValue(ScriptEngine* e, bool v) { return e->newValue(v); }
inline ScriptValuePointer convertScriptValue(ScriptEngine* e, quint16 v) { return e->newValue(v); }
inline ScriptValuePointer convertScriptValue(ScriptEngine* e, quint32 v) { return e->newValue(v); }
inline ScriptValuePointer convertScriptValue(ScriptEngine* e, quint64 v) { return e->newValue((double)v); }
inline ScriptValuePointer convertScriptValue(ScriptEngine* e, const QString& v) { return e->newValue(v); }
inline ScriptValue convertScriptValue(ScriptEngine* e, const glm::vec2& v) { return vec2ToScriptValue(e, v); }
inline ScriptValue convertScriptValue(ScriptEngine* e, const glm::vec3& v) { return vec3ToScriptValue(e, v); }
inline ScriptValue vec3Color_convertScriptValue(ScriptEngine* e, const glm::vec3& v) { return vec3ColorToScriptValue(e, v); }
inline ScriptValue convertScriptValue(ScriptEngine* e, const glm::u8vec3& v) { return u8vec3ToScriptValue(e, v); }
inline ScriptValue u8vec3Color_convertScriptValue(ScriptEngine* e, const glm::u8vec3& v) { return u8vec3ColorToScriptValue(e, v); }
inline ScriptValue convertScriptValue(ScriptEngine* e, float v) { return e->newValue(v); }
inline ScriptValue convertScriptValue(ScriptEngine* e, int v) { return e->newValue(v); }
inline ScriptValue convertScriptValue(ScriptEngine* e, bool v) { return e->newValue(v); }
inline ScriptValue convertScriptValue(ScriptEngine* e, quint16 v) { return e->newValue(v); }
inline ScriptValue convertScriptValue(ScriptEngine* e, quint32 v) { return e->newValue(v); }
inline ScriptValue convertScriptValue(ScriptEngine* e, quint64 v) { return e->newValue((double)v); }
inline ScriptValue convertScriptValue(ScriptEngine* e, const QString& v) { return e->newValue(v); }
inline ScriptValuePointer convertScriptValue(ScriptEngine* e, const glm::quat& v) { return quatToScriptValue(e, v); }
inline ScriptValuePointer convertScriptValue(ScriptEngine* e, const ScriptValuePointer& v) { return v; }
inline ScriptValuePointer convertScriptValue(ScriptEngine* e, const QVector<glm::vec3>& v) {return qVectorVec3ToScriptValue(e, v); }
inline ScriptValuePointer qVectorVec3Color_convertScriptValue(ScriptEngine* e, const QVector<glm::vec3>& v) {return qVectorVec3ColorToScriptValue(e, v); }
inline ScriptValuePointer convertScriptValue(ScriptEngine* e, const QVector<glm::quat>& v) {return qVectorQuatToScriptValue(e, v); }
inline ScriptValuePointer convertScriptValue(ScriptEngine* e, const QVector<bool>& v) {return qVectorBoolToScriptValue(e, v); }
inline ScriptValuePointer convertScriptValue(ScriptEngine* e, const QVector<float>& v) { return qVectorFloatToScriptValue(e, v); }
inline ScriptValuePointer convertScriptValue(ScriptEngine* e, const QVector<QUuid>& v) { return qVectorQUuidToScriptValue(e, v); }
inline ScriptValue convertScriptValue(ScriptEngine* e, const glm::quat& v) { return quatToScriptValue(e, v); }
inline ScriptValue convertScriptValue(ScriptEngine* e, const ScriptValue& v) { return v; }
inline ScriptValue convertScriptValue(ScriptEngine* e, const QVector<glm::vec3>& v) {return qVectorVec3ToScriptValue(e, v); }
inline ScriptValue qVectorVec3Color_convertScriptValue(ScriptEngine* e, const QVector<glm::vec3>& v) {return qVectorVec3ColorToScriptValue(e, v); }
inline ScriptValue convertScriptValue(ScriptEngine* e, const QVector<glm::quat>& v) {return qVectorQuatToScriptValue(e, v); }
inline ScriptValue convertScriptValue(ScriptEngine* e, const QVector<bool>& v) {return qVectorBoolToScriptValue(e, v); }
inline ScriptValue convertScriptValue(ScriptEngine* e, const QVector<float>& v) { return qVectorFloatToScriptValue(e, v); }
inline ScriptValue convertScriptValue(ScriptEngine* e, const QVector<QUuid>& v) { return qVectorQUuidToScriptValue(e, v); }
inline ScriptValuePointer convertScriptValue(ScriptEngine* e, const QRect& v) { return qRectToScriptValue(e, v); }
inline ScriptValue convertScriptValue(ScriptEngine* e, const QRect& v) { return qRectToScriptValue(e, v); }
inline ScriptValuePointer convertScriptValue(ScriptEngine* e, const QByteArray& v) {
inline ScriptValue convertScriptValue(ScriptEngine* e, const QByteArray& v) {
QByteArray b64 = v.toBase64();
return e->newValue(QString(b64));
}
inline ScriptValuePointer convertScriptValue(ScriptEngine* e, const EntityItemID& v) { return e->newValue(QUuid(v).toString()); }
inline ScriptValue convertScriptValue(ScriptEngine* e, const EntityItemID& v) { return e->newValue(QUuid(v).toString()); }
inline ScriptValuePointer convertScriptValue(ScriptEngine* e, const AACube& v) { return aaCubeToScriptValue(e, v); }
inline ScriptValue convertScriptValue(ScriptEngine* e, const AACube& v) { return aaCubeToScriptValue(e, v); }
#define COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(X,G,g,P,p) \
if ((desiredProperties.isEmpty() || desiredProperties.getHasProperty(X)) && \
(!skipDefaults || defaultEntityProperties.get##G().get##P() != get##P())) { \
ScriptValuePointer groupProperties = properties->property(#g); \
if (!groupProperties->isValid()) { \
ScriptValue groupProperties = properties.property(#g); \
if (!groupProperties.isValid()) { \
groupProperties = engine->newObject(); \
} \
ScriptValuePointer V = convertScriptValue(engine, get##P()); \
groupProperties->setProperty(#p, V); \
properties->setProperty(#g, groupProperties); \
ScriptValue V = convertScriptValue(engine, get##P()); \
groupProperties.setProperty(#p, V); \
properties.setProperty(#g, groupProperties); \
}
#define COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE_TYPED(X,G,g,P,p,T) \
if ((desiredProperties.isEmpty() || desiredProperties.getHasProperty(X)) && \
(!skipDefaults || defaultEntityProperties.get##G().get##P() != get##P())) { \
ScriptValuePointer groupProperties = properties->property(#g); \
if (!groupProperties->isValid()) { \
ScriptValue groupProperties = properties.property(#g); \
if (!groupProperties.isValid()) { \
groupProperties = engine->newObject(); \
} \
ScriptValuePointer V = T##_convertScriptValue(engine, get##P()); \
groupProperties->setProperty(#p, V); \
properties->setProperty(#g, groupProperties); \
ScriptValue V = T##_convertScriptValue(engine, get##P()); \
groupProperties.setProperty(#p, V); \
properties.setProperty(#g, groupProperties); \
}
#define COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE_GETTER(X,G,g,P,p,M) \
if ((desiredProperties.isEmpty() || desiredProperties.getHasProperty(X)) && \
(!skipDefaults || defaultEntityProperties.get##G().get##P() != get##P())) { \
ScriptValuePointer groupProperties = properties->property(#g); \
if (!groupProperties->isValid()) { \
ScriptValue groupProperties = properties.property(#g); \
if (!groupProperties.isValid()) { \
groupProperties = engine->newObject(); \
} \
ScriptValuePointer V = convertScriptValue(engine, M()); \
groupProperties->setProperty(#p, V); \
properties->setProperty(#g, groupProperties); \
ScriptValue V = convertScriptValue(engine, M()); \
groupProperties.setProperty(#p, V); \
properties.setProperty(#g, groupProperties); \
}
#define COPY_PROPERTY_TO_QSCRIPTVALUE(p,P) \
if (((!psuedoPropertyFlagsButDesiredEmpty && _desiredProperties.isEmpty()) || _desiredProperties.getHasProperty(p)) && \
(!skipDefaults || defaultEntityProperties._##P != _##P)) { \
ScriptValuePointer V = convertScriptValue(engine, _##P); \
properties->setProperty(#P, V); \
ScriptValue V = convertScriptValue(engine, _##P); \
properties.setProperty(#P, V); \
}
#define COPY_PROPERTY_TO_QSCRIPTVALUE_TYPED(p,P,T) \
if ((_desiredProperties.isEmpty() || _desiredProperties.getHasProperty(p)) && \
(!skipDefaults || defaultEntityProperties._##P != _##P)) { \
ScriptValuePointer V = T##_convertScriptValue(engine, _##P); \
properties->setProperty(#P, V); \
ScriptValue V = T##_convertScriptValue(engine, _##P); \
properties.setProperty(#P, V); \
}
#define COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER_NO_SKIP(P, G) \
properties->setProperty(#P, G);
properties.setProperty(#P, G);
#define COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(p, P, G) \
if (((!psuedoPropertyFlagsButDesiredEmpty && _desiredProperties.isEmpty()) || _desiredProperties.getHasProperty(p)) && \
(!skipDefaults || defaultEntityProperties._##P != _##P)) { \
ScriptValuePointer V = convertScriptValue(engine, G); \
properties->setProperty(#P, V); \
ScriptValue V = convertScriptValue(engine, G); \
properties.setProperty(#P, V); \
}
#define COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER_TYPED(p, P, G, T) \
if ((_desiredProperties.isEmpty() || _desiredProperties.getHasProperty(p)) && \
(!skipDefaults || defaultEntityProperties._##P != _##P)) { \
ScriptValuePointer V = T##_convertScriptValue(engine, G); \
properties->setProperty(#P, V); \
ScriptValue V = T##_convertScriptValue(engine, G); \
properties.setProperty(#P, V); \
}
// same as COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER but uses #X instead of #P in the setProperty() step
#define COPY_PROXY_PROPERTY_TO_QSCRIPTVALUE_GETTER(p, P, X, G) \
if (((!psuedoPropertyFlagsButDesiredEmpty && _desiredProperties.isEmpty()) || _desiredProperties.getHasProperty(p)) && \
(!skipDefaults || defaultEntityProperties._##P != _##P)) { \
ScriptValuePointer V = convertScriptValue(engine, G); \
properties->setProperty(#X, V); \
ScriptValue V = convertScriptValue(engine, G); \
properties.setProperty(#X, V); \
}
#define COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER_ALWAYS(P, G) \
if (!skipDefaults || defaultEntityProperties._##P != _##P) { \
ScriptValuePointer V = convertScriptValue(engine, G); \
properties->setProperty(#P, V); \
ScriptValue V = convertScriptValue(engine, G); \
properties.setProperty(#P, V); \
}
typedef QVector<glm::vec3> qVectorVec3;
@ -221,100 +221,100 @@ typedef QVector<glm::quat> qVectorQuat;
typedef QVector<bool> qVectorBool;
typedef QVector<float> qVectorFloat;
typedef QVector<QUuid> qVectorQUuid;
inline float float_convertFromScriptValue(const ScriptValuePointer& v, bool& isValid) { return v->toVariant().toFloat(&isValid); }
inline quint64 quint64_convertFromScriptValue(const ScriptValuePointer& v, bool& isValid) { return v->toVariant().toULongLong(&isValid); }
inline quint32 quint32_convertFromScriptValue(const ScriptValuePointer& v, bool& isValid) {
inline float float_convertFromScriptValue(const ScriptValue& v, bool& isValid) { return v.toVariant().toFloat(&isValid); }
inline quint64 quint64_convertFromScriptValue(const ScriptValue& v, bool& isValid) { return v.toVariant().toULongLong(&isValid); }
inline quint32 quint32_convertFromScriptValue(const ScriptValue& v, bool& isValid) {
// Use QString::toUInt() so that isValid is set to false if the number is outside the quint32 range.
return v->toString().toUInt(&isValid);
return v.toString().toUInt(&isValid);
}
inline quint16 quint16_convertFromScriptValue(const ScriptValuePointer& v, bool& isValid) { return v->toVariant().toInt(&isValid); }
inline uint16_t uint16_t_convertFromScriptValue(const ScriptValuePointer& v, bool& isValid) { return v->toVariant().toInt(&isValid); }
inline uint32_t uint32_t_convertFromScriptValue(const ScriptValuePointer& v, bool& isValid) { return v->toVariant().toInt(&isValid); }
inline int int_convertFromScriptValue(const ScriptValuePointer& v, bool& isValid) { return v->toVariant().toInt(&isValid); }
inline bool bool_convertFromScriptValue(const ScriptValuePointer& v, bool& isValid) { isValid = true; return v->toVariant().toBool(); }
inline uint8_t uint8_t_convertFromScriptValue(const ScriptValuePointer& v, bool& isValid) { isValid = true; return (uint8_t)(0xff & v->toVariant().toInt(&isValid)); }
inline QString QString_convertFromScriptValue(const ScriptValuePointer& v, bool& isValid) { isValid = true; return v->toVariant().toString().trimmed(); }
inline QUuid QUuid_convertFromScriptValue(const ScriptValuePointer& v, bool& isValid) { isValid = true; return v->toVariant().toUuid(); }
inline EntityItemID EntityItemID_convertFromScriptValue(const ScriptValuePointer& v, bool& isValid) { isValid = true; return v->toVariant().toUuid(); }
inline quint16 quint16_convertFromScriptValue(const ScriptValue& v, bool& isValid) { return v.toVariant().toInt(&isValid); }
inline uint16_t uint16_t_convertFromScriptValue(const ScriptValue& v, bool& isValid) { return v.toVariant().toInt(&isValid); }
inline uint32_t uint32_t_convertFromScriptValue(const ScriptValue& v, bool& isValid) { return v.toVariant().toInt(&isValid); }
inline int int_convertFromScriptValue(const ScriptValue& v, bool& isValid) { return v.toVariant().toInt(&isValid); }
inline bool bool_convertFromScriptValue(const ScriptValue& v, bool& isValid) { isValid = true; return v.toVariant().toBool(); }
inline uint8_t uint8_t_convertFromScriptValue(const ScriptValue& v, bool& isValid) { isValid = true; return (uint8_t)(0xff & v.toVariant().toInt(&isValid)); }
inline QString QString_convertFromScriptValue(const ScriptValue& v, bool& isValid) { isValid = true; return v.toVariant().toString().trimmed(); }
inline QUuid QUuid_convertFromScriptValue(const ScriptValue& v, bool& isValid) { isValid = true; return v.toVariant().toUuid(); }
inline EntityItemID EntityItemID_convertFromScriptValue(const ScriptValue& v, bool& isValid) { isValid = true; return v.toVariant().toUuid(); }
inline QByteArray QByteArray_convertFromScriptValue(const ScriptValuePointer& v, bool& isValid) {
inline QByteArray QByteArray_convertFromScriptValue(const ScriptValue& v, bool& isValid) {
isValid = true;
QString b64 = v->toVariant().toString().trimmed();
QString b64 = v.toVariant().toString().trimmed();
return QByteArray::fromBase64(b64.toUtf8());
}
inline glm::vec2 vec2_convertFromScriptValue(const ScriptValuePointer& v, bool& isValid) {
inline glm::vec2 vec2_convertFromScriptValue(const ScriptValue& v, bool& isValid) {
isValid = true;
glm::vec2 vec2;
vec2FromScriptValue(v, vec2);
return vec2;
}
inline glm::vec3 vec3_convertFromScriptValue(const ScriptValuePointer& v, bool& isValid) {
inline glm::vec3 vec3_convertFromScriptValue(const ScriptValue& v, bool& isValid) {
isValid = true;
glm::vec3 vec3;
vec3FromScriptValue(v, vec3);
return vec3;
}
inline glm::vec3 vec3Color_convertFromScriptValue(const ScriptValuePointer& v, bool& isValid) {
inline glm::vec3 vec3Color_convertFromScriptValue(const ScriptValue& v, bool& isValid) {
isValid = true;
glm::vec3 vec3;
vec3FromScriptValue(v, vec3);
return vec3;
}
inline glm::u8vec3 u8vec3Color_convertFromScriptValue(const ScriptValuePointer& v, bool& isValid) {
inline glm::u8vec3 u8vec3Color_convertFromScriptValue(const ScriptValue& v, bool& isValid) {
isValid = true;
glm::u8vec3 vec3;
u8vec3FromScriptValue(v, vec3);
return vec3;
}
inline AACube AACube_convertFromScriptValue(const ScriptValuePointer& v, bool& isValid) {
inline AACube AACube_convertFromScriptValue(const ScriptValue& v, bool& isValid) {
isValid = true;
AACube result;
aaCubeFromScriptValue(v, result);
return result;
}
inline qVectorFloat qVectorFloat_convertFromScriptValue(const ScriptValuePointer& v, bool& isValid) {
inline qVectorFloat qVectorFloat_convertFromScriptValue(const ScriptValue& v, bool& isValid) {
isValid = true;
return qVectorFloatFromScriptValue(v);
}
inline qVectorVec3 qVectorVec3_convertFromScriptValue(const ScriptValuePointer& v, bool& isValid) {
inline qVectorVec3 qVectorVec3_convertFromScriptValue(const ScriptValue& v, bool& isValid) {
isValid = true;
return qVectorVec3FromScriptValue(v);
}
inline qVectorQuat qVectorQuat_convertFromScriptValue(const ScriptValuePointer& v, bool& isValid) {
inline qVectorQuat qVectorQuat_convertFromScriptValue(const ScriptValue& v, bool& isValid) {
isValid = true;
return qVectorQuatFromScriptValue(v);
}
inline qVectorBool qVectorBool_convertFromScriptValue(const ScriptValuePointer& v, bool& isValid) {
inline qVectorBool qVectorBool_convertFromScriptValue(const ScriptValue& v, bool& isValid) {
isValid = true;
return qVectorBoolFromScriptValue(v);
}
inline qVectorQUuid qVectorQUuid_convertFromScriptValue(const ScriptValuePointer& v, bool& isValid) {
inline qVectorQUuid qVectorQUuid_convertFromScriptValue(const ScriptValue& v, bool& isValid) {
isValid = true;
return qVectorQUuidFromScriptValue(v);
}
inline glm::quat quat_convertFromScriptValue(const ScriptValuePointer& v, bool& isValid) {
inline glm::quat quat_convertFromScriptValue(const ScriptValue& v, bool& isValid) {
isValid = false; /// assume it can't be converted
ScriptValuePointer x = v->property("x");
ScriptValuePointer y = v->property("y");
ScriptValuePointer z = v->property("z");
ScriptValuePointer w = v->property("w");
if (x->isValid() && y->isValid() && z->isValid() && w->isValid()) {
ScriptValue x = v.property("x");
ScriptValue y = v.property("y");
ScriptValue z = v.property("z");
ScriptValue w = v.property("w");
if (x.isValid() && y.isValid() && z.isValid() && w.isValid()) {
glm::quat newValue;
newValue.x = x->toVariant().toFloat();
newValue.y = y->toVariant().toFloat();
newValue.z = z->toVariant().toFloat();
newValue.w = w->toVariant().toFloat();
newValue.x = x.toVariant().toFloat();
newValue.y = y.toVariant().toFloat();
newValue.z = z.toVariant().toFloat();
newValue.w = w.toVariant().toFloat();
isValid = !glm::isnan(newValue.x) &&
!glm::isnan(newValue.y) &&
!glm::isnan(newValue.z) &&
@ -326,7 +326,7 @@ inline glm::quat quat_convertFromScriptValue(const ScriptValuePointer& v, bool&
return glm::quat();
}
inline QRect QRect_convertFromScriptValue(const ScriptValuePointer& v, bool& isValid) {
inline QRect QRect_convertFromScriptValue(const ScriptValue& v, bool& isValid) {
isValid = true;
QRect rect;
qRectFromScriptValue(v, rect);
@ -344,8 +344,8 @@ inline QRect QRect_convertFromScriptValue(const ScriptValuePointer& v, bool& isV
#define COPY_PROPERTY_FROM_QSCRIPTVALUE(P, T, S) \
{ \
ScriptValuePointer V = object->property(#P); \
if (V->isValid()) { \
ScriptValue V = object.property(#P); \
if (V.isValid()) { \
bool isValid = false; \
T newValue = T##_convertFromScriptValue(V, isValid); \
if (isValid && (_defaultSettings || newValue != _##P)) { \
@ -356,8 +356,8 @@ inline QRect QRect_convertFromScriptValue(const ScriptValuePointer& v, bool& isV
#define COPY_PROPERTY_FROM_QSCRIPTVALUE_GETTER(P, T, S, G) \
{ \
ScriptValuePointer V = object->property(#P); \
if (V->isValid()) { \
ScriptValue V = object.property(#P); \
if (V.isValid()) { \
bool isValid = false; \
T newValue = T##_convertFromScriptValue(V, isValid); \
if (isValid && (_defaultSettings || newValue != G())) { \
@ -368,8 +368,8 @@ inline QRect QRect_convertFromScriptValue(const ScriptValuePointer& v, bool& isV
#define COPY_PROPERTY_FROM_QSCRIPTVALUE_NOCHECK(P, T, S) \
{ \
ScriptValuePointer V = object->property(#P); \
if (V->isValid()) { \
ScriptValue V = object.property(#P); \
if (V.isValid()) { \
bool isValid = false; \
T newValue = T##_convertFromScriptValue(V, isValid); \
if (isValid && (_defaultSettings)) { \
@ -380,10 +380,10 @@ inline QRect QRect_convertFromScriptValue(const ScriptValuePointer& v, bool& isV
#define COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(G, P, T, S) \
{ \
ScriptValuePointer G = object->property(#G); \
if (G->isValid()) { \
ScriptValuePointer V = G->property(#P); \
if (V->isValid()) { \
ScriptValue G = object.property(#G); \
if (G.isValid()) { \
ScriptValue V = G.property(#P); \
if (V.isValid()) { \
bool isValid = false; \
T newValue = T##_convertFromScriptValue(V, isValid); \
if (isValid && (_defaultSettings || newValue != _##P)) { \
@ -395,9 +395,9 @@ inline QRect QRect_convertFromScriptValue(const ScriptValuePointer& v, bool& isV
#define COPY_PROPERTY_FROM_QSCRIPTVALUE_ENUM(P, S) \
{ \
ScriptValuePointer P = object->property(#P); \
if (P->isValid()) { \
QString newValue = P->toVariant().toString(); \
ScriptValue P = object.property(#P); \
if (P.isValid()) { \
QString newValue = P.toVariant().toString(); \
if (_defaultSettings || newValue != get##S##AsString()) { \
set##S##FromString(newValue); \
} \
@ -406,11 +406,11 @@ inline QRect QRect_convertFromScriptValue(const ScriptValuePointer& v, bool& isV
#define COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE_ENUM(G, P, S) \
{ \
ScriptValuePointer G = object->property(#G); \
if (G->isValid()) { \
ScriptValuePointer P = G->property(#P); \
if (P->isValid()) { \
QString newValue = P->toVariant().toString(); \
ScriptValue G = object.property(#G); \
if (G.isValid()) { \
ScriptValue P = G.property(#P); \
if (P.isValid()) { \
QString newValue = P.toVariant().toString(); \
if (_defaultSettings || newValue != get##S##AsString()) { \
set##S##FromString(newValue); \
} \

View file

@ -846,7 +846,7 @@ struct EntityPropertiesResult {
// Static method to make sure that we have the right script engine.
// Using sender() or QtScriptable::engine() does not work for classes used by multiple threads (script-engines)
ScriptValuePointer EntityScriptingInterface::getMultipleEntityProperties(ScriptContext* context, ScriptEngine* engine) {
ScriptValue EntityScriptingInterface::getMultipleEntityProperties(ScriptContext* context, ScriptEngine* engine) {
const int ARGUMENT_ENTITY_IDS = 0;
const int ARGUMENT_EXTENDED_DESIRED_PROPERTIES = 1;
@ -855,12 +855,12 @@ ScriptValuePointer EntityScriptingInterface::getMultipleEntityProperties(ScriptC
return entityScriptingInterface->getMultipleEntityPropertiesInternal(engine, entityIDs, context->argument(ARGUMENT_EXTENDED_DESIRED_PROPERTIES));
}
ScriptValuePointer EntityScriptingInterface::getMultipleEntityPropertiesInternal(ScriptEngine* engine, QVector<QUuid> entityIDs, const ScriptValuePointer& extendedDesiredProperties) {
ScriptValue EntityScriptingInterface::getMultipleEntityPropertiesInternal(ScriptEngine* engine, QVector<QUuid> entityIDs, const ScriptValue& extendedDesiredProperties) {
PROFILE_RANGE(script_entities, __FUNCTION__);
EntityPsuedoPropertyFlags psuedoPropertyFlags;
const auto readExtendedPropertyStringValue = [&](ScriptValuePointer extendedProperty) {
const auto extendedPropertyString = extendedProperty->toString();
const auto readExtendedPropertyStringValue = [&](ScriptValue extendedProperty) {
const auto extendedPropertyString = extendedProperty.toString();
if (extendedPropertyString == "id") {
psuedoPropertyFlags.set(EntityPsuedoPropertyFlag::ID);
} else if (extendedPropertyString == "type") {
@ -890,13 +890,13 @@ ScriptValuePointer EntityScriptingInterface::getMultipleEntityPropertiesInternal
}
};
if (extendedDesiredProperties->isString()) {
if (extendedDesiredProperties.isString()) {
readExtendedPropertyStringValue(extendedDesiredProperties);
psuedoPropertyFlags.set(EntityPsuedoPropertyFlag::FlagsActive);
} else if (extendedDesiredProperties->isArray()) {
const quint32 length = extendedDesiredProperties->property("length")->toInt32();
} else if (extendedDesiredProperties.isArray()) {
const quint32 length = extendedDesiredProperties.property("length").toInt32();
for (quint32 i = 0; i < length; i++) {
readExtendedPropertyStringValue(extendedDesiredProperties->property(i));
readExtendedPropertyStringValue(extendedDesiredProperties.property(i));
}
psuedoPropertyFlags.set(EntityPsuedoPropertyFlag::FlagsActive);
}
@ -948,18 +948,18 @@ ScriptValuePointer EntityScriptingInterface::getMultipleEntityPropertiesInternal
});
}
}
ScriptValuePointer finalResult = engine->newArray(resultProperties.size());
ScriptValue finalResult = engine->newArray(resultProperties.size());
quint32 i = 0;
if (needsScriptSemantics) {
PROFILE_RANGE(script_entities, "EntityScriptingInterface::getMultipleEntityProperties>Script Semantics");
foreach(const auto& result, resultProperties) {
finalResult->setProperty(i++, convertPropertiesToScriptSemantics(result.properties, result.scalesWithParent)
finalResult.setProperty(i++, convertPropertiesToScriptSemantics(result.properties, result.scalesWithParent)
.copyToScriptValue(engine, false, false, false, psuedoPropertyFlags));
}
} else {
PROFILE_RANGE(script_entities, "EntityScriptingInterface::getMultipleEntityProperties>Skip Script Semantics");
foreach(const auto& result, resultProperties) {
finalResult->setProperty(i++, result.properties.copyToScriptValue(engine, false, false, false, psuedoPropertyFlags));
finalResult.setProperty(i++, result.properties.copyToScriptValue(engine, false, false, false, psuedoPropertyFlags));
}
}
return finalResult;
@ -1432,7 +1432,7 @@ QVector<QUuid> EntityScriptingInterface::findEntitiesByName(const QString entity
}
RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersection(const PickRay& ray, bool precisionPicking,
const ScriptValuePointer& entityIdsToInclude, const ScriptValuePointer& entityIdsToDiscard, bool visibleOnly, bool collidableOnly) const {
const ScriptValue& entityIdsToInclude, const ScriptValue& entityIdsToDiscard, bool visibleOnly, bool collidableOnly) const {
PROFILE_RANGE(script_entities, __FUNCTION__);
QVector<EntityItemID> entitiesToInclude = qVectorEntityItemIDFromScriptValue(entityIdsToInclude);
QVector<EntityItemID> entitiesToDiscard = qVectorEntityItemIDFromScriptValue(entityIdsToDiscard);
@ -1508,13 +1508,13 @@ bool EntityScriptingInterface::reloadServerScripts(const QUuid& entityID) {
return client->reloadServerScript(entityID);
}
bool EntityPropertyMetadataRequest::script(EntityItemID entityID, ScriptValuePointer handler) {
bool EntityPropertyMetadataRequest::script(EntityItemID entityID, const ScriptValue& handler) {
using LocalScriptStatusRequest = QFutureWatcher<QVariant>;
LocalScriptStatusRequest* request = new LocalScriptStatusRequest;
QObject::connect(request, &LocalScriptStatusRequest::finished, _manager, [=]() mutable {
auto details = request->result().toMap();
ScriptValuePointer err, result;
ScriptValue err, result;
if (details.contains("isError")) {
if (!details.contains("message")) {
details["message"] = details["errorInfo"];
@ -1535,14 +1535,14 @@ bool EntityPropertyMetadataRequest::script(EntityItemID entityID, ScriptValuePoi
}, entityID);
if (!request->isStarted()) {
request->deleteLater();
auto engine = handler->engine();
callScopedHandlerObject(handler, engine->makeError(engine->newValue("Entities Scripting Provider unavailable"), "InternalError"), ScriptValuePointer());
auto engine = handler.engine();
callScopedHandlerObject(handler, engine->makeError(engine->newValue("Entities Scripting Provider unavailable"), "InternalError"), ScriptValue());
return false;
}
return true;
}
bool EntityPropertyMetadataRequest::serverScripts(EntityItemID entityID, ScriptValuePointer handler) {
bool EntityPropertyMetadataRequest::serverScripts(EntityItemID entityID, const ScriptValue& handler) {
auto client = DependencyManager::get<EntityScriptClient>();
auto request = client->createScriptStatusRequest(entityID);
QPointer<ScriptManager> manager = _manager;
@ -1558,7 +1558,7 @@ bool EntityPropertyMetadataRequest::serverScripts(EntityItemID entityID, ScriptV
details["status"] = EntityScriptStatus_::valueToKey(request->getStatus()).toLower();
details["errorInfo"] = request->getErrorInfo();
ScriptValuePointer err, result;
ScriptValue err, result;
if (!details["success"].toBool()) {
if (!details.contains("message") && details.contains("errorInfo")) {
details["message"] = details["errorInfo"];
@ -1577,10 +1577,13 @@ bool EntityPropertyMetadataRequest::serverScripts(EntityItemID entityID, ScriptV
return true;
}
bool EntityScriptingInterface::queryPropertyMetadata(const QUuid& entityID, ScriptValuePointer property, ScriptValuePointer scopeOrCallback, ScriptValuePointer methodOrName) {
auto name = property->toString();
bool EntityScriptingInterface::queryPropertyMetadata(const QUuid& entityID,
const ScriptValue& property,
const ScriptValue& scopeOrCallback,
const ScriptValue& methodOrName) {
auto name = property.toString();
auto handler = makeScopedHandlerObject(scopeOrCallback, methodOrName);
QPointer<ScriptManager> manager = handler->engine()->manager();
QPointer<ScriptManager> manager = handler.engine()->manager();
if (!manager) {
qCDebug(entities) << "queryPropertyMetadata without detectable script manager" << entityID << name;
return false;
@ -1591,7 +1594,7 @@ bool EntityScriptingInterface::queryPropertyMetadata(const QUuid& entityID, Scri
qDebug() << "queryPropertyMetadata -- engine destroyed!" << (!engine ? "nullptr" : "engine");
});
#endif
if (!handler->property("callback")->isFunction()) {
if (!handler.property("callback").isFunction()) {
qDebug() << "!handler.callback.isFunction" << manager;
engine->raiseException(engine->makeError(engine->newValue("callback is not a function"), "TypeError"));
return false;
@ -1622,11 +1625,11 @@ bool EntityScriptingInterface::queryPropertyMetadata(const QUuid& entityID, Scri
}
}
bool EntityScriptingInterface::getServerScriptStatus(const QUuid& entityID, ScriptValuePointer callback) {
bool EntityScriptingInterface::getServerScriptStatus(const QUuid& entityID, const ScriptValue& callback) {
auto client = DependencyManager::get<EntityScriptClient>();
auto request = client->createScriptStatusRequest(entityID);
auto engine = callback->engine();
auto engine = callback.engine();
auto manager = engine->manager();
if (!manager) {
engine->raiseException(engine->makeError(engine->newValue("This script does not belong to a ScriptManager")));
@ -1636,9 +1639,9 @@ bool EntityScriptingInterface::getServerScriptStatus(const QUuid& entityID, Scri
connect(request, &GetScriptStatusRequest::finished, manager, [callback](GetScriptStatusRequest* request) mutable {
QString statusString = EntityScriptStatus_::valueToKey(request->getStatus());
auto engine = callback->engine();
auto engine = callback.engine();
ScriptValueList args { engine->newValue(request->getResponseReceived()), engine->newValue(request->getIsRunning()), engine->newValue(statusString.toLower()), engine->newValue(request->getErrorInfo()) };
callback->call(ScriptValuePointer(), args);
callback.call(ScriptValue(), args);
request->deleteLater();
});
request->start();
@ -1669,40 +1672,40 @@ bool EntityScriptingInterface::getDrawZoneBoundaries() const {
return ZoneEntityItem::getDrawZoneBoundaries();
}
ScriptValuePointer RayToEntityIntersectionResultToScriptValue(ScriptEngine* engine, const RayToEntityIntersectionResult& value) {
ScriptValuePointer obj = engine->newObject();
obj->setProperty("intersects", value.intersects);
obj->setProperty("accurate", value.accurate);
ScriptValuePointer entityItemValue = EntityItemIDtoScriptValue(engine, value.entityID);
obj->setProperty("entityID", entityItemValue);
obj->setProperty("distance", value.distance);
obj->setProperty("face", boxFaceToString(value.face));
ScriptValue RayToEntityIntersectionResultToScriptValue(ScriptEngine* engine, const RayToEntityIntersectionResult& value) {
ScriptValue obj = engine->newObject();
obj.setProperty("intersects", value.intersects);
obj.setProperty("accurate", value.accurate);
ScriptValue entityItemValue = EntityItemIDtoScriptValue(engine, value.entityID);
obj.setProperty("entityID", entityItemValue);
obj.setProperty("distance", value.distance);
obj.setProperty("face", boxFaceToString(value.face));
ScriptValuePointer intersection = vec3ToScriptValue(engine, value.intersection);
obj->setProperty("intersection", intersection);
ScriptValuePointer surfaceNormal = vec3ToScriptValue(engine, value.surfaceNormal);
obj->setProperty("surfaceNormal", surfaceNormal);
obj->setProperty("extraInfo", engine->toScriptValue(value.extraInfo));
ScriptValue intersection = vec3ToScriptValue(engine, value.intersection);
obj.setProperty("intersection", intersection);
ScriptValue surfaceNormal = vec3ToScriptValue(engine, value.surfaceNormal);
obj.setProperty("surfaceNormal", surfaceNormal);
obj.setProperty("extraInfo", engine->toScriptValue(value.extraInfo));
return obj;
}
void RayToEntityIntersectionResultFromScriptValue(const ScriptValuePointer& object, RayToEntityIntersectionResult& value) {
value.intersects = object->property("intersects")->toVariant().toBool();
value.accurate = object->property("accurate")->toVariant().toBool();
ScriptValuePointer entityIDValue = object->property("entityID");
void RayToEntityIntersectionResultFromScriptValue(const ScriptValue& object, RayToEntityIntersectionResult& value) {
value.intersects = object.property("intersects").toVariant().toBool();
value.accurate = object.property("accurate").toVariant().toBool();
ScriptValue entityIDValue = object.property("entityID");
quuidFromScriptValue(entityIDValue, value.entityID);
value.distance = object->property("distance")->toVariant().toFloat();
value.face = boxFaceFromString(object->property("face")->toVariant().toString());
value.distance = object.property("distance").toVariant().toFloat();
value.face = boxFaceFromString(object.property("face").toVariant().toString());
ScriptValuePointer intersection = object->property("intersection");
if (intersection->isValid()) {
ScriptValue intersection = object.property("intersection");
if (intersection.isValid()) {
vec3FromScriptValue(intersection, value.intersection);
}
ScriptValuePointer surfaceNormal = object->property("surfaceNormal");
if (surfaceNormal->isValid()) {
ScriptValue surfaceNormal = object.property("surfaceNormal");
if (surfaceNormal.isValid()) {
vec3FromScriptValue(surfaceNormal, value.surfaceNormal);
}
value.extraInfo = object->property("extraInfo")->toVariant().toMap();
value.extraInfo = object.property("extraInfo").toVariant().toMap();
}
bool EntityScriptingInterface::polyVoxWorker(QUuid entityID, std::function<bool(PolyVoxEntityItem&)> actor) {
@ -2423,15 +2426,15 @@ bool EntityScriptingInterface::AABoxIntersectsCapsule(const glm::vec3& low, cons
return aaBox.findCapsulePenetration(start, end, radius, penetration);
}
void EntityScriptingInterface::getMeshes(const QUuid& entityID, ScriptValuePointer callback) {
void EntityScriptingInterface::getMeshes(const QUuid& entityID, const ScriptValue& callback) {
PROFILE_RANGE(script_entities, __FUNCTION__);
auto engine = callback->engine();
auto engine = callback.engine();
EntityItemPointer entity = static_cast<EntityItemPointer>(_entityTree->findEntityByEntityItemID(entityID));
if (!entity) {
qCDebug(entities) << "EntityScriptingInterface::getMeshes no entity with ID" << entityID;
ScriptValueList args { engine->undefinedValue(), false };
callback->call(ScriptValuePointer(), args);
callback.call(ScriptValue(), args);
return;
}
@ -2439,12 +2442,12 @@ void EntityScriptingInterface::getMeshes(const QUuid& entityID, ScriptValuePoint
bool success = entity->getMeshes(result);
if (success) {
ScriptValuePointer resultAsScriptValue = meshesToScriptValue(engine.data(), result);
ScriptValue resultAsScriptValue = meshesToScriptValue(engine.data(), result);
ScriptValueList args{ resultAsScriptValue, engine->newValue(true) };
callback->call(ScriptValuePointer(), args);
callback.call(ScriptValue(), args);
} else {
ScriptValueList args { engine->undefinedValue(), engine->newValue(false) };
callback->call(ScriptValuePointer(), args);
callback.call(ScriptValue(), args);
}
}

View file

@ -29,6 +29,7 @@
#include "PointerEvent.h"
#include <PickFilter.h>
#include <ScriptManager.h>
#include <ScriptValue.h>
#include "PolyVoxEntityItem.h"
#include "LineEntityItem.h"
@ -43,8 +44,6 @@ class EntityTree;
class MeshProxy;
class ScriptContext;
class ScriptEngine;
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
extern const QString GRABBABLE_USER_DATA;
extern const QString NOT_GRABBABLE_USER_DATA;
@ -56,8 +55,8 @@ extern const QString NOT_GRABBABLE_USER_DATA;
class EntityPropertyMetadataRequest {
public:
EntityPropertyMetadataRequest(ScriptManager* manager) : _manager(manager == nullptr ? nullptr : manager){};
bool script(EntityItemID entityID, ScriptValuePointer handler);
bool serverScripts(EntityItemID entityID, ScriptValuePointer handler);
bool script(EntityItemID entityID, const ScriptValue& handler);
bool serverScripts(EntityItemID entityID, const ScriptValue& handler);
private:
QPointer<ScriptManager> _manager;
};
@ -90,8 +89,8 @@ public:
QVariantMap extraInfo;
};
Q_DECLARE_METATYPE(RayToEntityIntersectionResult)
ScriptValuePointer RayToEntityIntersectionResultToScriptValue(ScriptEngine* engine, const RayToEntityIntersectionResult& results);
void RayToEntityIntersectionResultFromScriptValue(const ScriptValuePointer& object, RayToEntityIntersectionResult& results);
ScriptValue RayToEntityIntersectionResultToScriptValue(ScriptEngine* engine, const RayToEntityIntersectionResult& results);
void RayToEntityIntersectionResultFromScriptValue(const ScriptValue& object, RayToEntityIntersectionResult& results);
class ParabolaToEntityIntersectionResult {
public:
@ -213,8 +212,8 @@ public:
* var propertySets = Entities.getMultipleEntityProperties(entityIDs, "name");
* print("Nearby entity names: " + JSON.stringify(propertySets));
*/
static ScriptValuePointer getMultipleEntityProperties(ScriptContext* context, ScriptEngine* engine);
ScriptValuePointer getMultipleEntityPropertiesInternal(ScriptEngine* engine, QVector<QUuid> entityIDs, const ScriptValuePointer& extendedDesiredProperties);
static ScriptValue getMultipleEntityProperties(ScriptContext* context, ScriptEngine* engine);
ScriptValue getMultipleEntityPropertiesInternal(ScriptEngine* engine, QVector<QUuid> entityIDs, const ScriptValue& extendedDesiredProperties);
QUuid addEntityInternal(const EntityItemProperties& properties, entity::HostType entityHostType);
@ -839,7 +838,7 @@ public slots:
/// may be inaccurate if the engine is unable to access the visible entities, in which case result.accurate
/// will be false.
Q_INVOKABLE RayToEntityIntersectionResult findRayIntersection(const PickRay& ray, bool precisionPicking = false,
const ScriptValuePointer& entityIdsToInclude = ScriptValuePointer(), const ScriptValuePointer& entityIdsToDiscard = ScriptValuePointer(),
const ScriptValue& entityIdsToInclude = ScriptValue(), const ScriptValue& entityIdsToDiscard = ScriptValue(),
bool visibleOnly = false, bool collidableOnly = false) const;
/*@jsdoc
@ -868,7 +867,7 @@ public slots:
* @param {string} errorInfo - <code>""</code> if there is a server entity script running, otherwise it may contain extra
* information on the error.
*/
Q_INVOKABLE bool getServerScriptStatus(const QUuid& entityID, ScriptValuePointer callback);
Q_INVOKABLE bool getServerScriptStatus(const QUuid& entityID, const ScriptValue& callback);
/*@jsdoc
* Gets metadata for certain entity properties such as <code>script</code> and <code>serverScripts</code>.
@ -898,8 +897,8 @@ public slots:
* @param {object} result - The metadata for the requested entity property if there was no error, otherwise
* <code>undefined</code>.
*/
Q_INVOKABLE bool queryPropertyMetadata(const QUuid& entityID, ScriptValuePointer property, ScriptValuePointer scopeOrCallback,
ScriptValuePointer methodOrName = ScriptValuePointer());
Q_INVOKABLE bool queryPropertyMetadata(const QUuid& entityID, const ScriptValue& property, const ScriptValue& scopeOrCallback,
const ScriptValue& methodOrName = ScriptValue());
/*@jsdoc
@ -1912,7 +1911,7 @@ public slots:
* {@link Graphics} API instead.
*/
// FIXME move to a renderable entity interface
Q_INVOKABLE void getMeshes(const QUuid& entityID, ScriptValuePointer callback);
Q_INVOKABLE void getMeshes(const QUuid& entityID, const ScriptValue& callback);
/*@jsdoc
* Gets the object to world transform, excluding scale, of an entity.

View file

@ -3089,7 +3089,7 @@ bool EntityTree::readFromMap(QVariantMap& map, const bool isImport) {
// map will have a top-level list keyed as "Entities". This will be extracted
// and iterated over. Each member of this list is converted to a QVariantMap, then
// to a ScriptValuePointer, and then to EntityItemProperties. These properties are used
// to a ScriptValue, and then to EntityItemProperties. These properties are used
// to add the new entity to the EntityTree.
QVariantList entitiesQList = map["Entities"].toList();
ScriptEnginePointer scriptEngine = newScriptEngine();
@ -3103,7 +3103,7 @@ bool EntityTree::readFromMap(QVariantMap& map, const bool isImport) {
bool success = true;
foreach (QVariant entityVariant, entitiesQList) {
// QVariantMap --> ScriptValuePointer --> EntityItemProperties --> Entity
// QVariantMap --> ScriptValue --> EntityItemProperties --> Entity
QVariantMap entityMap = entityVariant.toMap();
// handle parentJointName for wearables
@ -3116,7 +3116,7 @@ bool EntityTree::readFromMap(QVariantMap& map, const bool isImport) {
" mapped it to parentJointIndex " << entityMap["parentJointIndex"].toInt();
}
ScriptValuePointer entityScriptValue = variantMapToScriptValue(entityMap, *scriptEngine);
ScriptValue entityScriptValue = variantMapToScriptValue(entityMap, *scriptEngine);
EntityItemProperties properties;
EntityItemPropertiesFromScriptValueIgnoreReadOnly(entityScriptValue, properties);

View file

@ -16,7 +16,7 @@
#include "EntityItemProperties.h"
#include "EntityItemPropertiesMacros.h"
void GrabPropertyGroup::copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValuePointer& properties,
void GrabPropertyGroup::copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValue& properties,
ScriptEngine* engine, bool skipDefaults,
EntityItemProperties& defaultEntityProperties) const {
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_GRAB_GRABBABLE, Grab, grab, Grabbable, grabbable);
@ -43,7 +43,7 @@ void GrabPropertyGroup::copyToScriptValue(const EntityPropertyFlags& desiredProp
}
void GrabPropertyGroup::copyFromScriptValue(const ScriptValuePointer& object, bool& _defaultSettings) {
void GrabPropertyGroup::copyFromScriptValue(const ScriptValue& object, bool& _defaultSettings) {
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(grab, grabbable, bool, setGrabbable);
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(grab, grabKinematic, bool, setGrabKinematic);
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(grab, grabFollowsController, bool, setGrabFollowsController);

View file

@ -16,8 +16,6 @@
#include <glm/glm.hpp>
#include <QtCore/QSharedPointer>
#include "PropertyGroup.h"
#include "EntityItemPropertiesMacros.h"
@ -26,7 +24,6 @@ class EncodeBitstreamParams;
class OctreePacketData;
class ReadBitstreamToTreeParams;
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
static const bool INITIAL_GRABBABLE { true };
static const bool INITIAL_KINEMATIC { true };
@ -74,10 +71,10 @@ static const glm::vec3 INITIAL_EQUIPPABLE_INDICATOR_OFFSET { glm::vec3(0.0f) };
class GrabPropertyGroup : public PropertyGroup {
public:
// EntityItemProperty related helpers
virtual void copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValuePointer& properties,
virtual void copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValue& properties,
ScriptEngine* engine, bool skipDefaults,
EntityItemProperties& defaultEntityProperties) const override;
virtual void copyFromScriptValue(const ScriptValuePointer& object, bool& _defaultSettings) override;
virtual void copyFromScriptValue(const ScriptValue& object, bool& _defaultSettings) override;
void merge(const GrabPropertyGroup& other);

View file

@ -16,7 +16,7 @@
#include "EntityItemProperties.h"
#include "EntityItemPropertiesMacros.h"
void HazePropertyGroup::copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValuePointer& properties, ScriptEngine* engine, bool skipDefaults, EntityItemProperties& defaultEntityProperties) const {
void HazePropertyGroup::copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValue& properties, ScriptEngine* engine, bool skipDefaults, EntityItemProperties& defaultEntityProperties) const {
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_HAZE_RANGE, Haze, haze, HazeRange, hazeRange);
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE_TYPED(PROP_HAZE_COLOR, Haze, haze, HazeColor, hazeColor, u8vec3Color);
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE_TYPED(PROP_HAZE_GLARE_COLOR, Haze, haze, HazeGlareColor, hazeGlareColor, u8vec3Color);
@ -34,7 +34,7 @@ void HazePropertyGroup::copyToScriptValue(const EntityPropertyFlags& desiredProp
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_HAZE_KEYLIGHT_ALTITUDE, Haze, haze, HazeKeyLightAltitude, hazeKeyLightAltitude);
}
void HazePropertyGroup::copyFromScriptValue(const ScriptValuePointer& object, bool& _defaultSettings) {
void HazePropertyGroup::copyFromScriptValue(const ScriptValue& object, bool& _defaultSettings) {
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(haze, hazeRange, float, setHazeRange);
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(haze, hazeColor, u8vec3Color, setHazeColor);
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(haze, hazeGlareColor, u8vec3Color, setHazeGlareColor);

View file

@ -16,8 +16,6 @@
#include <glm/glm.hpp>
#include <QtCore/QSharedPointer>
#include "PropertyGroup.h"
#include "EntityItemPropertiesMacros.h"
@ -28,7 +26,6 @@ class EntityTreeElementExtraEncodeData;
class ReadBitstreamToTreeParams;
class ScriptEngine;
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
static const float INITIAL_HAZE_RANGE{ 1000.0f };
static const glm::u8vec3 initialHazeGlareColor { 255, 229, 179 };
@ -79,10 +76,10 @@ static const float INITIAL_KEY_LIGHT_ALTITUDE{ 200.0f };
class HazePropertyGroup : public PropertyGroup {
public:
// EntityItemProperty related helpers
virtual void copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValuePointer& properties,
virtual void copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValue& properties,
ScriptEngine* engine, bool skipDefaults,
EntityItemProperties& defaultEntityProperties) const override;
virtual void copyFromScriptValue(const ScriptValuePointer& object, bool& _defaultSettings) override;
virtual void copyFromScriptValue(const ScriptValue& object, bool& _defaultSettings) override;
void merge(const HazePropertyGroup& other);

View file

@ -25,7 +25,7 @@ const bool KeyLightPropertyGroup::DEFAULT_KEYLIGHT_CAST_SHADOWS { false };
const float KeyLightPropertyGroup::DEFAULT_KEYLIGHT_SHADOW_BIAS { 0.5f };
const float KeyLightPropertyGroup::DEFAULT_KEYLIGHT_SHADOW_MAX_DISTANCE { 40.0f };
void KeyLightPropertyGroup::copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValuePointer& properties,
void KeyLightPropertyGroup::copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValue& properties,
ScriptEngine* engine, bool skipDefaults, EntityItemProperties& defaultEntityProperties) const {
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE_TYPED(PROP_KEYLIGHT_COLOR, KeyLight, keyLight, Color, color, u8vec3Color);
@ -36,7 +36,7 @@ void KeyLightPropertyGroup::copyToScriptValue(const EntityPropertyFlags& desired
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_KEYLIGHT_SHADOW_MAX_DISTANCE, KeyLight, keyLight, ShadowMaxDistance, shadowMaxDistance);
}
void KeyLightPropertyGroup::copyFromScriptValue(const ScriptValuePointer& object, bool& _defaultSettings) {
void KeyLightPropertyGroup::copyFromScriptValue(const ScriptValue& object, bool& _defaultSettings) {
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(keyLight, color, u8vec3Color, setColor);
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(keyLight, intensity, float, setIntensity);
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(keyLight, direction, vec3, setDirection);

View file

@ -17,7 +17,6 @@
#include <glm/glm.hpp>
#include <QtCore/QSharedPointer>
#include "EntityItemPropertiesMacros.h"
#include "PropertyGroup.h"
@ -28,7 +27,6 @@ class EntityTreeElementExtraEncodeData;
class ReadBitstreamToTreeParams;
class ScriptEngine;
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
/*@jsdoc
* A key light is defined by the following properties:
@ -48,10 +46,10 @@ using ScriptValuePointer = QSharedPointer<ScriptValue>;
class KeyLightPropertyGroup : public PropertyGroup {
public:
// EntityItemProperty related helpers
virtual void copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValuePointer& properties,
virtual void copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValue& properties,
ScriptEngine* engine, bool skipDefaults,
EntityItemProperties& defaultEntityProperties) const override;
virtual void copyFromScriptValue(const ScriptValuePointer& object, bool& _defaultSettings) override;
virtual void copyFromScriptValue(const ScriptValue& object, bool& _defaultSettings) override;
void merge(const KeyLightPropertyGroup& other);

View file

@ -12,8 +12,6 @@
#ifndef hifi_PropertyGroup_h
#define hifi_PropertyGroup_h
#include <QtCore/QSharedPointer>
#include <OctreeElement.h>
#include "EntityPropertyFlags.h"
@ -26,7 +24,6 @@ class EntityTreeElementExtraEncodeData;
class ReadBitstreamToTreeParams;
class ScriptEngine;
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
using EntityTreeElementExtraEncodeDataPointer = std::shared_ptr<EntityTreeElementExtraEncodeData>;
@ -35,8 +32,8 @@ public:
virtual ~PropertyGroup() = default;
// EntityItemProperty related helpers
virtual void copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValuePointer& properties, ScriptEngine* engine, bool skipDefaults, EntityItemProperties& defaultEntityProperties) const = 0;
virtual void copyFromScriptValue(const ScriptValuePointer& object, bool& _defaultSettings) = 0;
virtual void copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValue& properties, ScriptEngine* engine, bool skipDefaults, EntityItemProperties& defaultEntityProperties) const = 0;
virtual void copyFromScriptValue(const ScriptValue& object, bool& _defaultSettings) = 0;
virtual void debugDump() const { }
virtual void listChangedProperties(QList<QString>& out) { }

View file

@ -57,7 +57,7 @@ void PulsePropertyGroup::setAlphaModeFromString(const QString& pulseMode) {
}
}
void PulsePropertyGroup::copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValuePointer& properties,
void PulsePropertyGroup::copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValue& properties,
ScriptEngine* engine, bool skipDefaults,
EntityItemProperties& defaultEntityProperties) const {
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_PULSE_MIN, Pulse, pulse, Min, min);
@ -67,7 +67,7 @@ void PulsePropertyGroup::copyToScriptValue(const EntityPropertyFlags& desiredPro
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE_GETTER(PROP_PULSE_ALPHA_MODE, Pulse, pulse, AlphaMode, alphaMode, getAlphaModeAsString);
}
void PulsePropertyGroup::copyFromScriptValue(const ScriptValuePointer& object, bool& _defaultSettings) {
void PulsePropertyGroup::copyFromScriptValue(const ScriptValue& object, bool& _defaultSettings) {
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(pulse, min, float, setMin);
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(pulse, max, float, setMax);
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(pulse, period, float, setPeriod);

View file

@ -13,8 +13,6 @@
#include <stdint.h>
#include <QtCore/QSharedPointer>
#include <PulseMode.h>
#include "PropertyGroup.h"
@ -26,7 +24,6 @@ class OctreePacketData;
class ReadBitstreamToTreeParams;
class ScriptEngine;
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
/*@jsdoc
* A color and alpha pulse that an entity may have.
@ -43,10 +40,10 @@ using ScriptValuePointer = QSharedPointer<ScriptValue>;
class PulsePropertyGroup : public PropertyGroup {
public:
// EntityItemProperty related helpers
virtual void copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValuePointer& properties,
virtual void copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValue& properties,
ScriptEngine* engine, bool skipDefaults,
EntityItemProperties& defaultEntityProperties) const override;
virtual void copyFromScriptValue(const ScriptValuePointer& object, bool& _defaultSettings) override;
virtual void copyFromScriptValue(const ScriptValue& object, bool& _defaultSettings) override;
void merge(const PulsePropertyGroup& other);

View file

@ -35,7 +35,7 @@ void RecurseOctreeToJSONOperator::processEntity(const EntityItemPointer& entity)
return; // we weren't able to resolve a parent from _parentID, so don't save this entity.
}
ScriptValuePointer qScriptValues = _skipDefaults
ScriptValue qScriptValues = _skipDefaults
? EntityItemNonDefaultPropertiesToScriptValue(_engine, entity->getProperties())
: EntityItemPropertiesToScriptValue(_engine, entity->getProperties());
@ -46,6 +46,6 @@ void RecurseOctreeToJSONOperator::processEntity(const EntityItemPointer& entity)
_json += "\n ";
// Override default toString():
qScriptValues->setProperty("toString", _toStringMethod);
_json += qScriptValues->toString();
qScriptValues.setProperty("toString", _toStringMethod);
_json += qScriptValues.toString();
}

View file

@ -11,11 +11,9 @@
#include "EntityTree.h"
#include <QtCore/QSharedPointer>
#include <ScriptValue.h>
class ScriptEngine;
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
class RecurseOctreeToJSONOperator : public RecurseOctreeOperator {
public:
@ -30,7 +28,7 @@ private:
void processEntity(const EntityItemPointer& entity);
ScriptEngine* _engine;
ScriptValuePointer _toStringMethod;
ScriptValue _toStringMethod;
QString _json;
const bool _skipDefaults;

View file

@ -57,7 +57,7 @@ bool RecurseOctreeToMapOperator::postRecursion(const OctreeElementPointer& eleme
}
EntityItemProperties properties = entityItem->getProperties();
ScriptValuePointer qScriptValues;
ScriptValue qScriptValues;
if (_skipDefaultValues) {
qScriptValues = EntityItemNonDefaultPropertiesToScriptValue(_engine, properties);
} else {
@ -71,11 +71,11 @@ bool RecurseOctreeToMapOperator::postRecursion(const OctreeElementPointer& eleme
auto jointNames = _myAvatar->getJointNames();
auto parentJointIndex = entityItem->getParentJointIndex();
if (parentJointIndex < jointNames.count()) {
qScriptValues->setProperty("parentJointName", jointNames.at(parentJointIndex));
qScriptValues.setProperty("parentJointName", jointNames.at(parentJointIndex));
}
}
entitiesQList << qScriptValues->toVariant();
entitiesQList << qScriptValues.toVariant();
});
_map["Entities"] = entitiesQList;

View file

@ -20,7 +20,7 @@ const float RingGizmoPropertyGroup::MAX_ALPHA = 1.0f;
const float RingGizmoPropertyGroup::MIN_RADIUS = 0.0f;
const float RingGizmoPropertyGroup::MAX_RADIUS = 0.5f;
void RingGizmoPropertyGroup::copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValuePointer& properties,
void RingGizmoPropertyGroup::copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValue& properties,
ScriptEngine* engine, bool skipDefaults,
EntityItemProperties& defaultEntityProperties) const {
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_START_ANGLE, Ring, ring, StartAngle, startAngle);
@ -46,7 +46,7 @@ void RingGizmoPropertyGroup::copyToScriptValue(const EntityPropertyFlags& desire
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE_TYPED(PROP_MINOR_TICK_MARKS_COLOR, Ring, ring, MinorTickMarksColor, minorTickMarksColor, u8vec3Color);
}
void RingGizmoPropertyGroup::copyFromScriptValue(const ScriptValuePointer& object, bool& _defaultSettings) {
void RingGizmoPropertyGroup::copyFromScriptValue(const ScriptValue& object, bool& _defaultSettings) {
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(ring, startAngle, float, setStartAngle);
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(ring, endAngle, float, setEndAngle);
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(ring, innerRadius, float, setInnerRadius);

View file

@ -11,8 +11,6 @@
#include <stdint.h>
#include <QtCore/QSharedPointer>
#include "PropertyGroup.h"
#include "EntityItemPropertiesMacros.h"
#include "EntityItemPropertiesDefaults.h"
@ -23,7 +21,6 @@ class OctreePacketData;
class ReadBitstreamToTreeParams;
class ScriptEngine;
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
using u8vec3Color = glm::u8vec3;
@ -59,10 +56,10 @@ using u8vec3Color = glm::u8vec3;
class RingGizmoPropertyGroup : public PropertyGroup {
public:
// EntityItemProperty related helpers
virtual void copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValuePointer& properties,
virtual void copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValue& properties,
ScriptEngine* engine, bool skipDefaults,
EntityItemProperties& defaultEntityProperties) const override;
virtual void copyFromScriptValue(const ScriptValuePointer& object, bool& _defaultSettings) override;
virtual void copyFromScriptValue(const ScriptValue& object, bool& _defaultSettings) override;
void merge(const RingGizmoPropertyGroup& other);

View file

@ -18,12 +18,12 @@
const glm::u8vec3 SkyboxPropertyGroup::DEFAULT_COLOR = { 0, 0, 0 };
void SkyboxPropertyGroup::copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValuePointer& properties, ScriptEngine* engine, bool skipDefaults, EntityItemProperties& defaultEntityProperties) const {
void SkyboxPropertyGroup::copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValue& properties, ScriptEngine* engine, bool skipDefaults, EntityItemProperties& defaultEntityProperties) const {
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE_TYPED(PROP_SKYBOX_COLOR, Skybox, skybox, Color, color, u8vec3Color);
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_SKYBOX_URL, Skybox, skybox, URL, url);
}
void SkyboxPropertyGroup::copyFromScriptValue(const ScriptValuePointer& object, bool& _defaultSettings) {
void SkyboxPropertyGroup::copyFromScriptValue(const ScriptValue& object, bool& _defaultSettings) {
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(skybox, color, u8vec3Color, setColor);
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(skybox, url, QString, setURL);
}

View file

@ -16,8 +16,6 @@
#include <glm/glm.hpp>
#include <QtCore/QSharedPointer>
#include <ColorUtils.h>
#include "PropertyGroup.h"
@ -30,7 +28,6 @@ class EntityTreeElementExtraEncodeData;
class ReadBitstreamToTreeParams;
class ScriptEngine;
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
/*@jsdoc
* A skybox is defined by the following properties:
@ -42,10 +39,10 @@ using ScriptValuePointer = QSharedPointer<ScriptValue>;
class SkyboxPropertyGroup : public PropertyGroup {
public:
// EntityItemProperty related helpers
virtual void copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValuePointer& properties,
virtual void copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValue& properties,
ScriptEngine* engine, bool skipDefaults,
EntityItemProperties& defaultEntityProperties) const override;
virtual void copyFromScriptValue(const ScriptValuePointer& object, bool& _defaultSettings) override;
virtual void copyFromScriptValue(const ScriptValue& object, bool& _defaultSettings) override;
void merge(const SkyboxPropertyGroup& other);

View file

@ -319,14 +319,14 @@ namespace scriptable {
scriptRegisterSequenceMetaType<QVector<QPointer<T>>>(engine);
return scriptRegisterMetaType<QPointer<T>>(
engine,
[](ScriptEngine* engine, const QPointer<T>& object) -> ScriptValuePointer {
[](ScriptEngine* engine, const QPointer<T>& object) -> ScriptValue {
if (!object) {
return engine->nullValue();
}
return engine->newQObject(object, ScriptEngine::QtOwnership, ScriptEngine::AutoCreateDynamicProperties);
},
[](const ScriptValuePointer& value, QPointer<T>& out) {
auto obj = value->toQObject();
[](const ScriptValue& value, QPointer<T>& out) {
auto obj = value.toQObject();
#ifdef SCRIPTABLE_MESH_DEBUG
qCInfo(graphics_scripting) << "qpointer_qobject_cast" << obj << value.toString();
#endif
@ -348,11 +348,11 @@ namespace scriptable {
);
}
ScriptValuePointer qVectorScriptableMaterialLayerToScriptValue(ScriptEngine* engine, const QVector<scriptable::ScriptableMaterialLayer>& vector) {
ScriptValue qVectorScriptableMaterialLayerToScriptValue(ScriptEngine* engine, const QVector<scriptable::ScriptableMaterialLayer>& vector) {
return scriptValueFromSequence(engine, vector);
}
void qVectorScriptableMaterialLayerFromScriptValue(const ScriptValuePointer& array, QVector<scriptable::ScriptableMaterialLayer>& result) {
void qVectorScriptableMaterialLayerFromScriptValue(const ScriptValue& array, QVector<scriptable::ScriptableMaterialLayer>& result) {
scriptValueToSequence(array, result);
}
@ -470,197 +470,197 @@ namespace scriptable {
* @property {boolean} defaultFallthrough - <code>true</code> if all properties fall through to the material below unless
* they are set, <code>false</code> if properties respect their individual fall-through settings.
*/
ScriptValuePointer scriptableMaterialToScriptValue(ScriptEngine* engine, const scriptable::ScriptableMaterial &material) {
ScriptValuePointer obj = engine->newObject();
obj->setProperty("name", material.name);
obj->setProperty("model", material.model);
ScriptValue scriptableMaterialToScriptValue(ScriptEngine* engine, const scriptable::ScriptableMaterial &material) {
ScriptValue obj = engine->newObject();
obj.setProperty("name", material.name);
obj.setProperty("model", material.model);
bool hasPropertyFallthroughs = !material.propertyFallthroughs.empty();
const ScriptValuePointer FALLTHROUGH(engine->newValue("fallthrough"));
const ScriptValue FALLTHROUGH(engine->newValue("fallthrough"));
if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::OPACITY_VAL_BIT)) {
obj->setProperty("opacity", FALLTHROUGH);
obj.setProperty("opacity", FALLTHROUGH);
} else if (material.key.isTranslucentFactor()) {
obj->setProperty("opacity", material.opacity);
obj.setProperty("opacity", material.opacity);
}
if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::ALBEDO_VAL_BIT)) {
obj->setProperty("albedo", FALLTHROUGH);
obj.setProperty("albedo", FALLTHROUGH);
} else if (material.key.isAlbedo()) {
obj->setProperty("albedo", vec3ColorToScriptValue(engine, material.albedo));
obj.setProperty("albedo", vec3ColorToScriptValue(engine, material.albedo));
}
if (material.model.toStdString() == graphics::Material::HIFI_PBR) {
if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::OPACITY_CUTOFF_VAL_BIT)) {
obj->setProperty("opacityCutoff", FALLTHROUGH);
obj.setProperty("opacityCutoff", FALLTHROUGH);
} else if (material.key.isOpacityCutoff()) {
obj->setProperty("opacityCutoff", material.opacityCutoff);
obj.setProperty("opacityCutoff", material.opacityCutoff);
}
if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::OPACITY_MAP_MODE_BIT)) {
obj->setProperty("opacityMapMode", FALLTHROUGH);
obj.setProperty("opacityMapMode", FALLTHROUGH);
} else if (material.key.isOpacityMapMode()) {
obj->setProperty("opacityMapMode", material.opacityMapMode);
obj.setProperty("opacityMapMode", material.opacityMapMode);
}
if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::GLOSSY_VAL_BIT)) {
obj->setProperty("roughness", FALLTHROUGH);
obj.setProperty("roughness", FALLTHROUGH);
} else if (material.key.isGlossy()) {
obj->setProperty("roughness", material.roughness);
obj.setProperty("roughness", material.roughness);
}
if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::METALLIC_VAL_BIT)) {
obj->setProperty("metallic", FALLTHROUGH);
obj.setProperty("metallic", FALLTHROUGH);
} else if (material.key.isMetallic()) {
obj->setProperty("metallic", material.metallic);
obj.setProperty("metallic", material.metallic);
}
if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::SCATTERING_VAL_BIT)) {
obj->setProperty("scattering", FALLTHROUGH);
obj.setProperty("scattering", FALLTHROUGH);
} else if (material.key.isScattering()) {
obj->setProperty("scattering", material.scattering);
obj.setProperty("scattering", material.scattering);
}
if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::UNLIT_VAL_BIT)) {
obj->setProperty("unlit", FALLTHROUGH);
obj.setProperty("unlit", FALLTHROUGH);
} else if (material.key.isUnlit()) {
obj->setProperty("unlit", material.unlit);
obj.setProperty("unlit", material.unlit);
}
if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::EMISSIVE_VAL_BIT)) {
obj->setProperty("emissive", FALLTHROUGH);
obj.setProperty("emissive", FALLTHROUGH);
} else if (material.key.isEmissive()) {
obj->setProperty("emissive", vec3ColorToScriptValue(engine, material.emissive));
obj.setProperty("emissive", vec3ColorToScriptValue(engine, material.emissive));
}
if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::EMISSIVE_MAP_BIT)) {
obj->setProperty("emissiveMap", FALLTHROUGH);
obj.setProperty("emissiveMap", FALLTHROUGH);
} else if (!material.emissiveMap.isEmpty()) {
obj->setProperty("emissiveMap", material.emissiveMap);
obj.setProperty("emissiveMap", material.emissiveMap);
}
if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::ALBEDO_MAP_BIT)) {
obj->setProperty("albedoMap", FALLTHROUGH);
obj.setProperty("albedoMap", FALLTHROUGH);
} else if (!material.albedoMap.isEmpty()) {
obj->setProperty("albedoMap", material.albedoMap);
obj.setProperty("albedoMap", material.albedoMap);
}
if (!material.opacityMap.isEmpty()) {
obj->setProperty("opacityMap", material.opacityMap);
obj.setProperty("opacityMap", material.opacityMap);
}
if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::OCCLUSION_MAP_BIT)) {
obj->setProperty("occlusionMap", FALLTHROUGH);
obj.setProperty("occlusionMap", FALLTHROUGH);
} else if (!material.occlusionMap.isEmpty()) {
obj->setProperty("occlusionMap", material.occlusionMap);
obj.setProperty("occlusionMap", material.occlusionMap);
}
if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::LIGHT_MAP_BIT)) {
obj->setProperty("lightMap", FALLTHROUGH);
obj.setProperty("lightMap", FALLTHROUGH);
} else if (!material.lightMap.isEmpty()) {
obj->setProperty("lightMap", material.lightMap);
obj.setProperty("lightMap", material.lightMap);
}
if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::SCATTERING_MAP_BIT)) {
obj->setProperty("scatteringMap", FALLTHROUGH);
obj.setProperty("scatteringMap", FALLTHROUGH);
} else if (!material.scatteringMap.isEmpty()) {
obj->setProperty("scatteringMap", material.scatteringMap);
obj.setProperty("scatteringMap", material.scatteringMap);
}
// Only set one of each of these
if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::METALLIC_MAP_BIT)) {
obj->setProperty("metallicMap", FALLTHROUGH);
obj.setProperty("metallicMap", FALLTHROUGH);
} else if (!material.metallicMap.isEmpty()) {
obj->setProperty("metallicMap", material.metallicMap);
obj.setProperty("metallicMap", material.metallicMap);
} else if (!material.specularMap.isEmpty()) {
obj->setProperty("specularMap", material.specularMap);
obj.setProperty("specularMap", material.specularMap);
}
if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::ROUGHNESS_MAP_BIT)) {
obj->setProperty("roughnessMap", FALLTHROUGH);
obj.setProperty("roughnessMap", FALLTHROUGH);
} else if (!material.roughnessMap.isEmpty()) {
obj->setProperty("roughnessMap", material.roughnessMap);
obj.setProperty("roughnessMap", material.roughnessMap);
} else if (!material.glossMap.isEmpty()) {
obj->setProperty("glossMap", material.glossMap);
obj.setProperty("glossMap", material.glossMap);
}
if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::NORMAL_MAP_BIT)) {
obj->setProperty("normalMap", FALLTHROUGH);
obj.setProperty("normalMap", FALLTHROUGH);
} else if (!material.normalMap.isEmpty()) {
obj->setProperty("normalMap", material.normalMap);
obj.setProperty("normalMap", material.normalMap);
} else if (!material.bumpMap.isEmpty()) {
obj->setProperty("bumpMap", material.bumpMap);
obj.setProperty("bumpMap", material.bumpMap);
}
if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::Material::TEXCOORDTRANSFORM0)) {
obj->setProperty("texCoordTransform0", FALLTHROUGH);
obj.setProperty("texCoordTransform0", FALLTHROUGH);
} else if (material.texCoordTransforms[0] != mat4()) {
obj->setProperty("texCoordTransform0", mat4toScriptValue(engine, material.texCoordTransforms[0]));
obj.setProperty("texCoordTransform0", mat4toScriptValue(engine, material.texCoordTransforms[0]));
}
if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::Material::TEXCOORDTRANSFORM1)) {
obj->setProperty("texCoordTransform1", FALLTHROUGH);
obj.setProperty("texCoordTransform1", FALLTHROUGH);
} else if (material.texCoordTransforms[1] != mat4()) {
obj->setProperty("texCoordTransform1", mat4toScriptValue(engine, material.texCoordTransforms[1]));
obj.setProperty("texCoordTransform1", mat4toScriptValue(engine, material.texCoordTransforms[1]));
}
// These need to be implemented, but set the fallthrough for now
if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::Material::LIGHTMAP_PARAMS)) {
obj->setProperty("lightmapParams", FALLTHROUGH);
obj.setProperty("lightmapParams", FALLTHROUGH);
}
if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::Material::MATERIAL_PARAMS)) {
obj->setProperty("materialParams", FALLTHROUGH);
obj.setProperty("materialParams", FALLTHROUGH);
}
if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::Material::CULL_FACE_MODE)) {
obj->setProperty("cullFaceMode", FALLTHROUGH);
obj.setProperty("cullFaceMode", FALLTHROUGH);
} else if (!material.cullFaceMode.isEmpty()) {
obj->setProperty("cullFaceMode", material.cullFaceMode);
obj.setProperty("cullFaceMode", material.cullFaceMode);
}
} else if (material.model.toStdString() == graphics::Material::HIFI_SHADER_SIMPLE) {
obj->setProperty("procedural", material.procedural);
obj.setProperty("procedural", material.procedural);
}
obj->setProperty("defaultFallthrough", material.defaultFallthrough);
obj.setProperty("defaultFallthrough", material.defaultFallthrough);
return obj;
}
void scriptableMaterialFromScriptValue(const ScriptValuePointer &object, scriptable::ScriptableMaterial& material) {
// No need to convert from ScriptValuePointer to ScriptableMaterial
void scriptableMaterialFromScriptValue(const ScriptValue &object, scriptable::ScriptableMaterial& material) {
// No need to convert from ScriptValue to ScriptableMaterial
}
ScriptValuePointer scriptableMaterialLayerToScriptValue(ScriptEngine* engine, const scriptable::ScriptableMaterialLayer &materialLayer) {
ScriptValuePointer obj = engine->newObject();
obj->setProperty("material", scriptableMaterialToScriptValue(engine, materialLayer.material));
obj->setProperty("priority", materialLayer.priority);
ScriptValue scriptableMaterialLayerToScriptValue(ScriptEngine* engine, const scriptable::ScriptableMaterialLayer &materialLayer) {
ScriptValue obj = engine->newObject();
obj.setProperty("material", scriptableMaterialToScriptValue(engine, materialLayer.material));
obj.setProperty("priority", materialLayer.priority);
return obj;
}
void scriptableMaterialLayerFromScriptValue(const ScriptValuePointer &object, scriptable::ScriptableMaterialLayer& materialLayer) {
// No need to convert from ScriptValuePointer to ScriptableMaterialLayer
void scriptableMaterialLayerFromScriptValue(const ScriptValue &object, scriptable::ScriptableMaterialLayer& materialLayer) {
// No need to convert from ScriptValue to ScriptableMaterialLayer
}
ScriptValuePointer multiMaterialMapToScriptValue(ScriptEngine* engine, const scriptable::MultiMaterialMap& map) {
ScriptValuePointer obj = engine->newObject();
ScriptValue multiMaterialMapToScriptValue(ScriptEngine* engine, const scriptable::MultiMaterialMap& map) {
ScriptValue obj = engine->newObject();
for (auto key : map.keys()) {
obj->setProperty(key, qVectorScriptableMaterialLayerToScriptValue(engine, map[key]));
obj.setProperty(key, qVectorScriptableMaterialLayerToScriptValue(engine, map[key]));
}
return obj;
}
void multiMaterialMapFromScriptValue(const ScriptValuePointer& map, scriptable::MultiMaterialMap& result) {
// No need to convert from ScriptValuePointer to MultiMaterialMap
void multiMaterialMapFromScriptValue(const ScriptValue& map, scriptable::MultiMaterialMap& result) {
// No need to convert from ScriptValue to MultiMaterialMap
}
template <typename T> int registerDebugEnum(ScriptEngine* engine, const DebugEnums<T>& debugEnums) {
static const DebugEnums<T>& instance = debugEnums;
return scriptRegisterMetaType<T>(
engine,
[](ScriptEngine* engine, const T& topology) -> ScriptValuePointer {
[](ScriptEngine* engine, const T& topology) -> ScriptValue {
return engine->newValue(instance.value(topology));
},
[](const ScriptValuePointer& value, T& topology) {
topology = instance.key(value->toString());
[](const ScriptValue& value, T& topology) {
topology = instance.key(value.toString());
}
);
}

View file

@ -11,7 +11,6 @@
#ifndef hifi_GraphicsScriptingInterface_h
#define hifi_GraphicsScriptingInterface_h
#include <QtCore/QSharedPointer>
#include <QtCore/QObject>
#include <QUrl>
@ -19,10 +18,9 @@
#include <DependencyManager.h>
#include "RegisteredMetaTypes.h"
#include <Scriptable.h>
#include <ScriptValue.h>
class ScriptEngine;
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
/*@jsdoc
* The <code>Graphics</code> API enables you to access and manipulate avatar, entity, and overlay models in the rendered scene.
@ -151,7 +149,7 @@ private:
};
namespace scriptable {
ScriptValuePointer scriptableMaterialToScriptValue(ScriptEngine* engine, const scriptable::ScriptableMaterial &material);
ScriptValue scriptableMaterialToScriptValue(ScriptEngine* engine, const scriptable::ScriptableMaterial &material);
};
Q_DECLARE_METATYPE(NestableType)

View file

@ -10,9 +10,9 @@
#include <graphics/BufferViewHelpers.h>
#include <AABox.h>
#include <Extents.h>
#include "ScriptContext.h"
#include "ScriptEngine.h"
#include "ScriptValue.h"
#include <ScriptContext.h>
#include <ScriptEngine.h>
#include <ScriptValue.h>
using buffer_helpers::glmVecToVariant;
@ -78,27 +78,27 @@ QVariant toVariant(const gpu::Element& element) {
};
}
ScriptValuePointer jsBindCallback(ScriptValuePointer value) {
if (value->isObject() && value->property("callback")->isFunction()) {
ScriptValue jsBindCallback(const ScriptValue& value) {
if (value.isObject() && value.property("callback").isFunction()) {
// value is already a bound callback
return value;
}
auto engine = value->engine();
auto engine = value.engine();
auto context = engine ? engine->currentContext() : nullptr;
auto length = context ? context->argumentCount() : 0;
ScriptValuePointer scope = context ? context->thisObject() : engine->nullValue();
ScriptValuePointer method;
ScriptValue scope = context ? context->thisObject() : engine->nullValue();
ScriptValue method;
#ifdef SCRIPTABLE_MESH_DEBUG
qCInfo(graphics_scripting) << "jsBindCallback" << engine << length << scope.toQObject() << method.toString();
#endif
// find position in the incoming JS Function.arguments array (so we can test for the two-argument case)
for (int i = 0; context && i < length; i++) {
if (context->argument(i)->strictlyEquals(value)) {
if (context->argument(i).strictlyEquals(value)) {
method = context->argument(i+1);
}
}
if (method->isFunction() || method->isString()) {
if (method.isFunction() || method.isString()) {
// interpret as `API.func(..., scope, function callback(){})` or `API.func(..., scope, "methodName")`
scope = value;
} else {
@ -114,7 +114,7 @@ ScriptValuePointer jsBindCallback(ScriptValuePointer value) {
template <typename T>
T this_qobject_cast(ScriptEngine* engine) {
auto context = engine ? engine->currentContext() : nullptr;
return scriptvalue_cast<T>(context ? context->thisObject() : ScriptValuePointer::NullValue);
return scriptvalue_cast<T>(context ? context->thisObject() : ScriptValue::NullValue);
}
QString toDebugString(QObject* tmp) {
QString s;

View file

@ -1,17 +1,15 @@
#pragma once
#include <QtCore/QPointer>
#include <QtCore/QSharedPointer>
#include <QtCore/QObject>
#include <QtCore/QLoggingCategory>
#include <QDebug>
#include <memory>
#include <functional>
#include <glm/glm.hpp>
#include <ScriptValue.h>
class ScriptEngine;
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
class Extents;
class AABox;
@ -27,12 +25,12 @@ namespace scriptable {
QVariant toVariant(const glm::mat4& mat4);
// helper that automatically resolves Qt-signal-like scoped callbacks
// ... C++ side: `void MyClass::asyncMethod(..., ScriptValuePointer callback)`
// ... C++ side: `void MyClass::asyncMethod(..., const ScriptValue& callback)`
// ... JS side:
// * `API.asyncMethod(..., function(){})`
// * `API.asyncMethod(..., scope, function(){})`
// * `API.asyncMethod(..., scope, "methodName")`
ScriptValuePointer jsBindCallback(ScriptValuePointer callback);
ScriptValue jsBindCallback(const ScriptValue& callback);
// cast engine->thisObject() => C++ class instance
template <typename T> T this_qobject_cast(ScriptEngine* engine);

View file

@ -7,8 +7,6 @@
#include "ScriptableMesh.h"
#include <ScriptValue.h>
#include <glm/glm.hpp>
#include <glm/gtx/norm.hpp>
#include <glm/gtx/transform.hpp>
@ -266,7 +264,7 @@ bool scriptable::ScriptableMesh::setVertexProperty(glm::uint32 vertexIndex, cons
* @param {number} index - The vertex index.
* @param {object} properties - The properties of the mesh, per {@link GraphicsMesh}.
*/
glm::uint32 scriptable::ScriptableMesh::forEachVertex(ScriptValuePointer _callback) {
glm::uint32 scriptable::ScriptableMesh::forEachVertex(const ScriptValue& _callback) {
auto mesh = getMeshPointer();
if (!mesh) {
return 0;
@ -274,16 +272,16 @@ glm::uint32 scriptable::ScriptableMesh::forEachVertex(ScriptValuePointer _callba
auto scopedHandler = jsBindCallback(_callback);
// destructure so we can still invoke callback scoped, but with a custom signature (obj, i, jsMesh)
auto scope = scopedHandler->property("scope");
auto callback = scopedHandler->property("callback");
auto js = engine() ? engine() : scopedHandler->engine(); // cache value to avoid resolving each iteration
auto scope = scopedHandler.property("scope");
auto callback = scopedHandler.property("callback");
auto js = engine() ? engine() : scopedHandler.engine(); // cache value to avoid resolving each iteration
if (!js) {
return 0;
}
auto meshPart = js ? js->toScriptValue(getSelf()) : js->nullValue();
int numProcessed = 0;
buffer_helpers::mesh::forEachVertex(mesh, [&](glm::uint32 index, const QVariantMap& values) {
auto result = callback->call(scope, { js->toScriptValue(values), js->newValue(index), meshPart });
auto result = callback.call(scope, { js->toScriptValue(values), js->newValue(index), meshPart });
if (js->hasUncaughtException()) {
js->currentContext()->throwValue(js->uncaughtException());
return false;
@ -304,7 +302,7 @@ glm::uint32 scriptable::ScriptableMesh::forEachVertex(ScriptValuePointer _callba
* @returns {Object<Graphics.BufferTypeName, Graphics.BufferType>|boolean} The attribute values to update the vertex with, or
* <code>false</code> to not update the vertex.
*/
glm::uint32 scriptable::ScriptableMesh::updateVertexAttributes(ScriptValuePointer _callback) {
glm::uint32 scriptable::ScriptableMesh::updateVertexAttributes(const ScriptValue& _callback) {
auto mesh = getMeshPointer();
if (!mesh) {
return 0;
@ -312,9 +310,9 @@ glm::uint32 scriptable::ScriptableMesh::updateVertexAttributes(ScriptValuePointe
auto scopedHandler = jsBindCallback(_callback);
// destructure so we can still invoke callback scoped, but with a custom signature (obj, i, jsMesh)
auto scope = scopedHandler->property("scope");
auto callback = scopedHandler->property("callback");
auto js = engine() ? engine() : scopedHandler->engine(); // cache value to avoid resolving each iteration
auto scope = scopedHandler.property("scope");
auto callback = scopedHandler.property("callback");
auto js = engine() ? engine() : scopedHandler.engine(); // cache value to avoid resolving each iteration
if (!js) {
return 0;
}
@ -323,23 +321,23 @@ glm::uint32 scriptable::ScriptableMesh::updateVertexAttributes(ScriptValuePointe
auto attributeViews = buffer_helpers::mesh::getAllBufferViews(mesh);
buffer_helpers::mesh::forEachVertex(mesh, [&](glm::uint32 index, const QVariantMap& values) {
auto obj = js->toScriptValue(values);
auto result = callback->call(scope, { obj, js->newValue(index), meshPart });
auto result = callback.call(scope, { obj, js->newValue(index), meshPart });
if (js->hasUncaughtException()) {
js->currentContext()->throwValue(js->uncaughtException());
return false;
}
if (result->isBool() && !result->toBool()) {
if (result.isBool() && !result.toBool()) {
// bail without modifying data if user explicitly returns false
return true;
}
if (result->isObject() && !result->strictlyEquals(obj)) {
if (result.isObject() && !result.strictlyEquals(obj)) {
// user returned a new object (ie: instead of modifying input properties)
obj = result;
}
for (const auto& a : attributeViews) {
const auto& attribute = obj->property(a.first);
if (attribute->isValid()) {
buffer_helpers::setValue(a.second, index, attribute->toVariant());
const auto& attribute = obj.property(a.first);
if (attribute.isValid()) {
buffer_helpers::setValue(a.second, index, attribute.toVariant());
}
}
numProcessed++;

View file

@ -20,7 +20,6 @@
#include <QtCore/QUuid>
#include <QtCore/QVariant>
#include <QtCore/QVector>
#include <QtCore/QSharedPointer>
#include "GraphicsScriptingUtil.h"
@ -28,7 +27,6 @@
#include <Scriptable.h>
class ScriptValue;
using ScriptValuePointer = QSharedPointer<ScriptValue>;
namespace scriptable {
/*@jsdoc
@ -236,7 +234,7 @@ namespace scriptable {
* @param {GraphicsMesh~updateVertexAttributesCallback} callback - The function to call for each vertex.
* @returns {number} The number of vertices the callback was called for.
*/
glm::uint32 updateVertexAttributes(ScriptValuePointer callback);
glm::uint32 updateVertexAttributes(const ScriptValue& callback);
/*@jsdoc
* Calls a function for each vertex.
@ -244,7 +242,7 @@ namespace scriptable {
* @param {GraphicsMesh~forEachVertexCallback} callback - The function to call for each vertex.
* @returns {number} The number of vertices the callback was called for.
*/
glm::uint32 forEachVertex(ScriptValuePointer callback);
glm::uint32 forEachVertex(const ScriptValue& callback);
/*@jsdoc
* Checks if an index is valid and, optionally, that vertex has a particular attribute.

View file

@ -77,12 +77,12 @@ QVariantList scriptable::ScriptableMeshPart::queryVertexAttributes(QVariant sele
return parentMesh->queryVertexAttributes(selector);
}
glm::uint32 scriptable::ScriptableMeshPart::forEachVertex(ScriptValuePointer _callback) {
glm::uint32 scriptable::ScriptableMeshPart::forEachVertex(const ScriptValue& _callback) {
// TODO: limit to vertices within the part's indexed range?
return isValid() ? parentMesh->forEachVertex(_callback) : 0;
}
glm::uint32 scriptable::ScriptableMeshPart::updateVertexAttributes(ScriptValuePointer _callback) {
glm::uint32 scriptable::ScriptableMeshPart::updateVertexAttributes(const ScriptValue& _callback) {
// TODO: limit to vertices within the part's indexed range?
return isValid() ? parentMesh->updateVertexAttributes(_callback) : 0;
}

Some files were not shown because too many files have changed in this diff Show more