mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 03:03:35 +02:00
provide a way for scripts to get information about what actions an entity has and what the arguments of those actions are
This commit is contained in:
parent
c0c1116c69
commit
0970f010a4
15 changed files with 136 additions and 30 deletions
|
@ -30,6 +30,7 @@ public:
|
|||
virtual const EntityItemWeakPointer getOwnerEntity() const { return _ownerEntity; }
|
||||
virtual void setOwnerEntity(const EntityItemPointer ownerEntity) { _ownerEntity = ownerEntity; }
|
||||
virtual bool updateArguments(QVariantMap arguments) { assert(false); return false; }
|
||||
virtual QVariantMap getArguments() { assert(false); return QVariantMap(); }
|
||||
|
||||
virtual QByteArray serialize();
|
||||
virtual void deserialize(QByteArray serializedArguments);
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include "QVariantGLM.h"
|
||||
#include "avatar/MyAvatar.h"
|
||||
#include "avatar/AvatarManager.h"
|
||||
|
||||
|
@ -118,6 +119,21 @@ bool AvatarActionHold::updateArguments(QVariantMap arguments) {
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
QVariantMap AvatarActionHold::getArguments() {
|
||||
QVariantMap arguments;
|
||||
lockForRead();
|
||||
if (_parametersSet) {
|
||||
arguments["relativePosition"] = glmToQMap(_relativePosition);
|
||||
arguments["relativeRotation"] = glmToQMap(_relativeRotation);
|
||||
arguments["timeScale"] = _linearTimeScale;
|
||||
arguments["hand"] = _hand;
|
||||
}
|
||||
unlock();
|
||||
return arguments;
|
||||
}
|
||||
|
||||
|
||||
QByteArray AvatarActionHold::serialize() {
|
||||
QByteArray ba;
|
||||
QDataStream dataStream(&ba, QIODevice::WriteOnly);
|
||||
|
|
|
@ -25,6 +25,8 @@ public:
|
|||
virtual EntityActionType getType() { return ACTION_TYPE_HOLD; }
|
||||
|
||||
virtual bool updateArguments(QVariantMap arguments);
|
||||
virtual QVariantMap getArguments();
|
||||
|
||||
virtual void updateActionWorker(float deltaTimeStep);
|
||||
|
||||
virtual QByteArray serialize();
|
||||
|
|
|
@ -38,6 +38,7 @@ public:
|
|||
virtual const EntityItemWeakPointer getOwnerEntity() const = 0;
|
||||
virtual void setOwnerEntity(const EntityItemPointer ownerEntity) = 0;
|
||||
virtual bool updateArguments(QVariantMap arguments) = 0;
|
||||
virtual QVariantMap getArguments() = 0;
|
||||
|
||||
virtual QByteArray serialize() = 0;
|
||||
virtual void deserialize(QByteArray serializedArguments) = 0;
|
||||
|
|
|
@ -1492,7 +1492,6 @@ void EntityItem::setActionData(QByteArray actionData) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
bool EntityItem::serializeActionData() {
|
||||
if (_objectActions.size() == 0) {
|
||||
_actionData = QByteArray();
|
||||
|
@ -1521,7 +1520,15 @@ bool EntityItem::serializeActionData() {
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
const QByteArray EntityItem::getActionData() const {
|
||||
return _actionData;
|
||||
}
|
||||
|
||||
QVariantMap EntityItem::getActionArguments(const QUuid& actionID) {
|
||||
QVariantMap result;
|
||||
if (_objectActions.contains(actionID)) {
|
||||
EntityActionPointer action = _objectActions[actionID];
|
||||
result = action->getArguments();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -386,6 +386,8 @@ public:
|
|||
void setActionData(QByteArray actionData);
|
||||
const QByteArray getActionData() const;
|
||||
bool hasActions() { return !_objectActions.empty(); }
|
||||
QList<QUuid> getActionIDs() { return _objectActions.keys(); }
|
||||
QVariantMap getActionArguments(const QUuid& actionID);
|
||||
|
||||
protected:
|
||||
|
||||
|
|
|
@ -509,7 +509,6 @@ bool EntityScriptingInterface::appendPoint(QUuid entityID, const glm::vec3& poin
|
|||
{
|
||||
return lineEntity.appendPoint(point);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -585,9 +584,27 @@ bool EntityScriptingInterface::updateAction(const QUuid& entityID, const QUuid&
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
bool EntityScriptingInterface::deleteAction(const QUuid& entityID, const QUuid& actionID) {
|
||||
return actionWorker(entityID, [&](EntitySimulation* simulation, EntityItemPointer entity) {
|
||||
return entity->removeAction(simulation, actionID);
|
||||
});
|
||||
}
|
||||
|
||||
QVector<QUuid> EntityScriptingInterface::getActionIDs(const QUuid& entityID) {
|
||||
QVector<QUuid> result;
|
||||
actionWorker(entityID, [&](EntitySimulation* simulation, EntityItemPointer entity) {
|
||||
QList<QUuid> actionIDs = entity->getActionIDs();
|
||||
result = QVector<QUuid>::fromList(actionIDs);
|
||||
return true;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
QVariantMap EntityScriptingInterface::getActionArguments(const QUuid& entityID, const QUuid& actionID) {
|
||||
QVariantMap result;
|
||||
actionWorker(entityID, [&](EntitySimulation* simulation, EntityItemPointer entity) {
|
||||
result = entity->getActionArguments(actionID);
|
||||
return true;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -131,6 +131,8 @@ public slots:
|
|||
Q_INVOKABLE QUuid addAction(const QString& actionTypeString, const QUuid& entityID, const QVariantMap& arguments);
|
||||
Q_INVOKABLE bool updateAction(const QUuid& entityID, const QUuid& actionID, const QVariantMap& arguments);
|
||||
Q_INVOKABLE bool deleteAction(const QUuid& entityID, const QUuid& actionID);
|
||||
Q_INVOKABLE QVector<QUuid> getActionIDs(const QUuid& entityID);
|
||||
Q_INVOKABLE QVariantMap getActionArguments(const QUuid& entityID, const QUuid& actionID);
|
||||
|
||||
signals:
|
||||
void entityCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision);
|
||||
|
|
|
@ -34,7 +34,9 @@ public:
|
|||
virtual void removeFromSimulation(EntitySimulation* simulation) const;
|
||||
virtual const EntityItemWeakPointer getOwnerEntity() const { return _ownerEntity; }
|
||||
virtual void setOwnerEntity(const EntityItemPointer ownerEntity) { _ownerEntity = ownerEntity; }
|
||||
|
||||
virtual bool updateArguments(QVariantMap arguments) { return false; }
|
||||
virtual QVariantMap getArguments() { return QVariantMap(); }
|
||||
|
||||
// this is called from updateAction and should be overridden by subclasses
|
||||
virtual void updateActionWorker(float deltaTimeStep) {}
|
||||
|
@ -62,6 +64,7 @@ protected:
|
|||
virtual glm::vec3 getAngularVelocity();
|
||||
virtual void setAngularVelocity(glm::vec3 angularVelocity);
|
||||
|
||||
void lockForRead() { _lock.lockForRead(); }
|
||||
bool tryLockForRead() { return _lock.tryLockForRead(); }
|
||||
void lockForWrite() { _lock.lockForWrite(); }
|
||||
bool tryLockForWrite() { return _lock.tryLockForWrite(); }
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include "QVariantGLM.h"
|
||||
|
||||
#include "ObjectActionOffset.h"
|
||||
|
||||
const uint16_t ObjectActionOffset::offsetVersion = 1;
|
||||
|
@ -115,6 +117,16 @@ bool ObjectActionOffset::updateArguments(QVariantMap arguments) {
|
|||
return true;
|
||||
}
|
||||
|
||||
QVariantMap ObjectActionOffset::getArguments() {
|
||||
QVariantMap arguments;
|
||||
lockForRead();
|
||||
arguments["pointToOffsetFrom"] = glmToQMap(_pointToOffsetFrom);
|
||||
arguments["linearTimeScale"] = _linearTimeScale;
|
||||
arguments["linearDistance"] = _linearDistance;
|
||||
unlock();
|
||||
return arguments;
|
||||
}
|
||||
|
||||
QByteArray ObjectActionOffset::serialize() {
|
||||
QByteArray ba;
|
||||
QDataStream dataStream(&ba, QIODevice::WriteOnly);
|
||||
|
|
|
@ -25,6 +25,8 @@ public:
|
|||
virtual EntityActionType getType() { return ACTION_TYPE_OFFSET; }
|
||||
|
||||
virtual bool updateArguments(QVariantMap arguments);
|
||||
virtual QVariantMap getArguments();
|
||||
|
||||
virtual void updateActionWorker(float deltaTimeStep);
|
||||
|
||||
virtual QByteArray serialize();
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include "QVariantGLM.h"
|
||||
|
||||
#include "ObjectActionSpring.h"
|
||||
|
||||
const uint16_t ObjectActionSpring::springVersion = 1;
|
||||
|
@ -150,6 +152,24 @@ bool ObjectActionSpring::updateArguments(QVariantMap arguments) {
|
|||
return true;
|
||||
}
|
||||
|
||||
QVariantMap ObjectActionSpring::getArguments() {
|
||||
QVariantMap arguments;
|
||||
lockForRead();
|
||||
|
||||
if (_positionalTargetSet) {
|
||||
arguments["linearTimeScale"] = _linearTimeScale;
|
||||
arguments["targetPosition"] = glmToQMap(_positionalTarget);
|
||||
}
|
||||
|
||||
if (_rotationalTargetSet) {
|
||||
arguments["targetRotation"] = glmToQMap(_rotationalTarget);
|
||||
arguments["angularTimeScale"] = _angularTimeScale;
|
||||
}
|
||||
|
||||
unlock();
|
||||
return arguments;
|
||||
}
|
||||
|
||||
QByteArray ObjectActionSpring::serialize() {
|
||||
QByteArray ba;
|
||||
QDataStream dataStream(&ba, QIODevice::WriteOnly);
|
||||
|
|
|
@ -25,6 +25,8 @@ public:
|
|||
virtual EntityActionType getType() { return ACTION_TYPE_SPRING; }
|
||||
|
||||
virtual bool updateArguments(QVariantMap arguments);
|
||||
virtual QVariantMap getArguments();
|
||||
|
||||
virtual void updateActionWorker(float deltaTimeStep);
|
||||
|
||||
virtual QByteArray serialize();
|
||||
|
|
|
@ -24,6 +24,22 @@ QVariantList rgbColorToQList(rgbColor& v) {
|
|||
return QVariantList() << (int)(v[0]) << (int)(v[1]) << (int)(v[2]);
|
||||
}
|
||||
|
||||
QVariantMap glmToQMap(const glm::vec3& g) {
|
||||
QVariantMap p;
|
||||
p["x"] = g.x;
|
||||
p["y"] = g.y;
|
||||
p["z"] = g.z;
|
||||
return p;
|
||||
}
|
||||
|
||||
QVariantMap glmToQMap(const glm::quat& g) {
|
||||
QVariantMap q;
|
||||
q["x"] = g.x;
|
||||
q["y"] = g.y;
|
||||
q["z"] = g.z;
|
||||
q["w"] = g.w;
|
||||
return q;
|
||||
}
|
||||
|
||||
|
||||
glm::vec3 qListToGlmVec3(const QVariant q) {
|
||||
|
|
|
@ -21,6 +21,9 @@ QVariantList glmToQList(const glm::vec3& g);
|
|||
QVariantList glmToQList(const glm::quat& g);
|
||||
QVariantList rgbColorToQList(rgbColor& v);
|
||||
|
||||
QVariantMap glmToQMap(const glm::vec3& g);
|
||||
QVariantMap glmToQMap(const glm::quat& g);
|
||||
|
||||
glm::vec3 qListToGlmVec3(const QVariant q);
|
||||
glm::quat qListToGlmQuat(const QVariant q);
|
||||
void qListtoRgbColor(const QVariant q, rgbColor returnValue);
|
||||
|
|
Loading…
Reference in a new issue