mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-26 07:18:46 +02:00
hook up entity-scripting-interface to actions
This commit is contained in:
parent
57c3a14b6a
commit
c8ab22c517
10 changed files with 143 additions and 62 deletions
|
@ -12,14 +12,20 @@
|
||||||
#ifndef hifi_EntityActionInterface_h
|
#ifndef hifi_EntityActionInterface_h
|
||||||
#define hifi_EntityActionInterface_h
|
#define hifi_EntityActionInterface_h
|
||||||
|
|
||||||
|
enum EntityActionType {
|
||||||
|
ACTION_TYPE_NONE,
|
||||||
|
ACTION_TYPE_PULL_TO_POINT
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class EntityActionInterface {
|
class EntityActionInterface {
|
||||||
public:
|
public:
|
||||||
virtual ~EntityActionInterface();
|
virtual ~EntityActionInterface() {};
|
||||||
virtual const QUuid& getID() const = 0;
|
virtual const QUuid& getID() const = 0;
|
||||||
virtual const EntityItemPointer& getOwnerEntity() const = 0;
|
virtual const EntityItemPointer& getOwnerEntity() const = 0;
|
||||||
virtual void setOwnerEntity(const EntityItemPointer ownerEntity) = 0;
|
virtual void setOwnerEntity(const EntityItemPointer ownerEntity) = 0;
|
||||||
virtual QByteArray serialize() = 0;
|
// virtual QByteArray serialize() = 0;
|
||||||
static EntityActionInterface* deserialize(EntityItemPointer ownerEntity, QByteArray data);
|
// static EntityActionInterface* deserialize(EntityItemPointer ownerEntity, QByteArray data);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_EntityActionInterface_h
|
#endif // hifi_EntityActionInterface_h
|
||||||
|
|
|
@ -11,13 +11,14 @@
|
||||||
|
|
||||||
#include <VariantMapToScriptValue.h>
|
#include <VariantMapToScriptValue.h>
|
||||||
|
|
||||||
#include "EntityScriptingInterface.h"
|
|
||||||
#include "EntityTree.h"
|
#include "EntityTree.h"
|
||||||
#include "LightEntityItem.h"
|
#include "LightEntityItem.h"
|
||||||
#include "ModelEntityItem.h"
|
#include "ModelEntityItem.h"
|
||||||
#include "ZoneEntityItem.h"
|
#include "ZoneEntityItem.h"
|
||||||
#include "EntitiesLogging.h"
|
#include "EntitiesLogging.h"
|
||||||
|
#include "EntitySimulation.h"
|
||||||
|
|
||||||
|
#include "EntityScriptingInterface.h"
|
||||||
|
|
||||||
EntityScriptingInterface::EntityScriptingInterface() :
|
EntityScriptingInterface::EntityScriptingInterface() :
|
||||||
_entityTree(NULL)
|
_entityTree(NULL)
|
||||||
|
@ -83,7 +84,8 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties
|
||||||
entity->setLastBroadcast(usecTimestampNow());
|
entity->setLastBroadcast(usecTimestampNow());
|
||||||
// This Node is creating a new object. If it's in motion, set this Node as the simulator.
|
// This Node is creating a new object. If it's in motion, set this Node as the simulator.
|
||||||
bidForSimulationOwnership(propertiesWithSimID);
|
bidForSimulationOwnership(propertiesWithSimID);
|
||||||
entity->setSimulatorID(propertiesWithSimID.getSimulatorID()); // and make note of it now, so we can act on it right away.
|
// and make note of it now, so we can act on it right away.
|
||||||
|
entity->setSimulatorID(propertiesWithSimID.getSimulatorID());
|
||||||
} else {
|
} else {
|
||||||
qCDebug(entities) << "script failed to add new Entity to local Octree";
|
qCDebug(entities) << "script failed to add new Entity to local Octree";
|
||||||
success = false;
|
success = false;
|
||||||
|
@ -393,7 +395,6 @@ void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, Ra
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool EntityScriptingInterface::setVoxels(QUuid entityID,
|
bool EntityScriptingInterface::setVoxels(QUuid entityID,
|
||||||
std::function<void(PolyVoxEntityItem&)> actor) {
|
std::function<void(PolyVoxEntityItem&)> actor) {
|
||||||
if (!_entityTree) {
|
if (!_entityTree) {
|
||||||
|
@ -431,23 +432,48 @@ bool EntityScriptingInterface::setVoxels(QUuid entityID,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool EntityScriptingInterface::setVoxelSphere(QUuid entityID, const glm::vec3& center, float radius, int value) {
|
bool EntityScriptingInterface::setVoxelSphere(QUuid entityID, const glm::vec3& center, float radius, int value) {
|
||||||
return setVoxels(entityID, [center, radius, value](PolyVoxEntityItem& polyVoxEntity) {
|
return setVoxels(entityID, [center, radius, value](PolyVoxEntityItem& polyVoxEntity) {
|
||||||
polyVoxEntity.setSphere(center, radius, value);
|
polyVoxEntity.setSphere(center, radius, value);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool EntityScriptingInterface::setVoxel(QUuid entityID, const glm::vec3& position, int value) {
|
bool EntityScriptingInterface::setVoxel(QUuid entityID, const glm::vec3& position, int value) {
|
||||||
return setVoxels(entityID, [position, value](PolyVoxEntityItem& polyVoxEntity) {
|
return setVoxels(entityID, [position, value](PolyVoxEntityItem& polyVoxEntity) {
|
||||||
polyVoxEntity.setVoxelInVolume(position, value);
|
polyVoxEntity.setVoxelInVolume(position, value);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool EntityScriptingInterface::setAllVoxels(QUuid entityID, int value) {
|
bool EntityScriptingInterface::setAllVoxels(QUuid entityID, int value) {
|
||||||
return setVoxels(entityID, [value](PolyVoxEntityItem& polyVoxEntity) {
|
return setVoxels(entityID, [value](PolyVoxEntityItem& polyVoxEntity) {
|
||||||
polyVoxEntity.setAll(value);
|
polyVoxEntity.setAll(value);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QUuid EntityScriptingInterface::addActionPullToPoint(QUuid entityID, const glm::vec3& target) {
|
||||||
|
if (!_entityTree) {
|
||||||
|
return QUuid();
|
||||||
|
}
|
||||||
|
|
||||||
|
_entityTree->lockForWrite();
|
||||||
|
|
||||||
|
EntitySimulation* simulation = _entityTree->getSimulation();
|
||||||
|
QUuid actionID = QUuid::createUuid();
|
||||||
|
EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID);
|
||||||
|
if (!entity) {
|
||||||
|
qDebug() << "addAction -- unknown entity" << entityID;
|
||||||
|
_entityTree->unlock();
|
||||||
|
return QUuid();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariantMap arguments;
|
||||||
|
QVariantList targetList;
|
||||||
|
targetList << QVariant(target[0]) << QVariant(target[1]) << QVariant(target[2]);
|
||||||
|
arguments["target"] = targetList;
|
||||||
|
EntityActionInterface* action = simulation->actionFactory(ACTION_TYPE_PULL_TO_POINT, actionID, entity, arguments);
|
||||||
|
entity->addAction(action);
|
||||||
|
|
||||||
|
_entityTree->unlock();
|
||||||
|
|
||||||
|
return actionID;
|
||||||
|
}
|
||||||
|
|
|
@ -118,13 +118,14 @@ public slots:
|
||||||
Q_INVOKABLE void setSendPhysicsUpdates(bool value);
|
Q_INVOKABLE void setSendPhysicsUpdates(bool value);
|
||||||
Q_INVOKABLE bool getSendPhysicsUpdates() const;
|
Q_INVOKABLE bool getSendPhysicsUpdates() const;
|
||||||
|
|
||||||
bool setVoxels(QUuid entityID, std::function<void(PolyVoxEntityItem&)> actor);
|
|
||||||
Q_INVOKABLE bool setVoxelSphere(QUuid entityID, const glm::vec3& center, float radius, int value);
|
Q_INVOKABLE bool setVoxelSphere(QUuid entityID, const glm::vec3& center, float radius, int value);
|
||||||
Q_INVOKABLE bool setVoxel(QUuid entityID, const glm::vec3& position, int value);
|
Q_INVOKABLE bool setVoxel(QUuid entityID, const glm::vec3& position, int value);
|
||||||
Q_INVOKABLE bool setAllVoxels(QUuid entityID, int value);
|
Q_INVOKABLE bool setAllVoxels(QUuid entityID, int value);
|
||||||
|
|
||||||
Q_INVOKABLE void dumpTree() const;
|
Q_INVOKABLE void dumpTree() const;
|
||||||
|
|
||||||
|
Q_INVOKABLE QUuid addActionPullToPoint(QUuid entityID, const glm::vec3& target);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void entityCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision);
|
void entityCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision);
|
||||||
void collisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision);
|
void collisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision);
|
||||||
|
@ -152,6 +153,7 @@ signals:
|
||||||
void clearingEntities();
|
void clearingEntities();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool setVoxels(QUuid entityID, std::function<void(PolyVoxEntityItem&)> actor);
|
||||||
void queueEntityMessage(PacketType packetType, EntityItemID entityID, const EntityItemProperties& properties);
|
void queueEntityMessage(PacketType packetType, EntityItemID entityID, const EntityItemProperties& properties);
|
||||||
|
|
||||||
/// actually does the work of finding the ray intersection, can be called in locking mode or tryLock mode
|
/// actually does the work of finding the ray intersection, can be called in locking mode or tryLock mode
|
||||||
|
|
|
@ -56,10 +56,14 @@ public:
|
||||||
|
|
||||||
friend class EntityTree;
|
friend class EntityTree;
|
||||||
|
|
||||||
virtual void addAction(EntityActionInterface* action) {}
|
virtual EntityActionInterface* actionFactory(EntityActionType type,
|
||||||
virtual void removeAction(const QUuid actionID) {}
|
QUuid id,
|
||||||
virtual void removeActions(QList<QUuid> actionIDsToRemove) {}
|
EntityItemPointer ownerEntity,
|
||||||
virtual void applyActionChanges() {}
|
QVariantMap arguments) { return nullptr; }
|
||||||
|
virtual void addAction(EntityActionInterface* action) { _actionsToAdd += action; }
|
||||||
|
virtual void removeAction(const QUuid actionID) { _actionsToRemove += actionID; }
|
||||||
|
virtual void removeActions(QList<QUuid> actionIDsToRemove) { _actionsToRemove += actionIDsToRemove; }
|
||||||
|
virtual void applyActionChanges() { _actionsToAdd.clear(); _actionsToRemove.clear(); }
|
||||||
|
|
||||||
protected: // these only called by the EntityTree?
|
protected: // these only called by the EntityTree?
|
||||||
/// \param entity pointer to EntityItem to be added
|
/// \param entity pointer to EntityItem to be added
|
||||||
|
@ -119,6 +123,10 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void moveSimpleKinematics();
|
void moveSimpleKinematics();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QList<EntityActionInterface*> _actionsToAdd;
|
||||||
|
QList<QUuid> _actionsToRemove;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_EntitySimulation_h
|
#endif // hifi_EntitySimulation_h
|
||||||
|
|
|
@ -17,19 +17,11 @@ ObjectAction::ObjectAction(QUuid id, EntityItemPointer ownerEntity) :
|
||||||
_ownerEntity(ownerEntity) {
|
_ownerEntity(ownerEntity) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectAction::ObjectAction(EntityItemPointer ownerEntity) :
|
|
||||||
ObjectAction(QUuid::createUuid(), ownerEntity) {
|
|
||||||
}
|
|
||||||
|
|
||||||
ObjectAction::~ObjectAction() {
|
ObjectAction::~ObjectAction() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectAction::updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep) {
|
void ObjectAction::updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep) {
|
||||||
qDebug() << "updateAction called";
|
qDebug() << "ObjectAction::updateAction called";
|
||||||
}
|
|
||||||
|
|
||||||
EntityActionInterface* ObjectAction::deserialize(EntityItemPointer ownerEntity, QByteArray data) {
|
|
||||||
return new ObjectAction(ownerEntity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectAction::debugDraw(btIDebugDraw* debugDrawer) {
|
void ObjectAction::debugDraw(btIDebugDraw* debugDrawer) {
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
class ObjectAction : public btActionInterface, public EntityActionInterface {
|
class ObjectAction : public btActionInterface, public EntityActionInterface {
|
||||||
public:
|
public:
|
||||||
ObjectAction(QUuid id, EntityItemPointer ownerEntity);
|
ObjectAction(QUuid id, EntityItemPointer ownerEntity);
|
||||||
ObjectAction(EntityItemPointer ownerEntity);
|
|
||||||
virtual ~ObjectAction();
|
virtual ~ObjectAction();
|
||||||
|
|
||||||
const QUuid& getID() const { return _id; }
|
const QUuid& getID() const { return _id; }
|
||||||
|
@ -31,9 +30,6 @@ public:
|
||||||
|
|
||||||
virtual void updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep);
|
virtual void updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep);
|
||||||
|
|
||||||
virtual QByteArray serialize() { return QByteArray(); }
|
|
||||||
static EntityActionInterface* deserialize(EntityItemPointer ownerEntity, QByteArray data);
|
|
||||||
|
|
||||||
virtual void debugDraw(btIDebugDraw* debugDrawer);
|
virtual void debugDraw(btIDebugDraw* debugDrawer);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
24
libraries/physics/src/ObjectActionPullToPoint.cpp
Normal file
24
libraries/physics/src/ObjectActionPullToPoint.cpp
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
//
|
||||||
|
// ObjectActionPullToPoint.cpp
|
||||||
|
// libraries/physics/src
|
||||||
|
//
|
||||||
|
// Created by Seth Alves 2015-6-2
|
||||||
|
// Copyright 2015 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "ObjectActionPullToPoint.h"
|
||||||
|
|
||||||
|
ObjectActionPullToPoint::ObjectActionPullToPoint(QUuid id, EntityItemPointer ownerEntity, glm::vec3 target) :
|
||||||
|
ObjectAction(id, ownerEntity),
|
||||||
|
_target(target) {
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjectActionPullToPoint::~ObjectActionPullToPoint() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjectActionPullToPoint::updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep) {
|
||||||
|
qDebug() << "ObjectActionPullToPoint::updateAction called";
|
||||||
|
}
|
31
libraries/physics/src/ObjectActionPullToPoint.h
Normal file
31
libraries/physics/src/ObjectActionPullToPoint.h
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
//
|
||||||
|
// ObjectActionPullToPoint.h
|
||||||
|
// libraries/physics/src
|
||||||
|
//
|
||||||
|
// Created by Seth Alves 2015-6-3
|
||||||
|
// Copyright 2015 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef hifi_ObjectActionPullToPoint_h
|
||||||
|
#define hifi_ObjectActionPullToPoint_h
|
||||||
|
|
||||||
|
#include <QUuid>
|
||||||
|
|
||||||
|
#include <EntityItem.h>
|
||||||
|
#include "ObjectAction.h"
|
||||||
|
|
||||||
|
class ObjectActionPullToPoint : public ObjectAction {
|
||||||
|
public:
|
||||||
|
ObjectActionPullToPoint(QUuid id, EntityItemPointer ownerEntity, glm::vec3 target);
|
||||||
|
virtual ~ObjectActionPullToPoint();
|
||||||
|
|
||||||
|
void updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep);
|
||||||
|
|
||||||
|
private:
|
||||||
|
glm::vec3 _target;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // hifi_ObjectActionPullToPoint_h
|
|
@ -9,10 +9,12 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "PhysicalEntitySimulation.h"
|
|
||||||
#include "PhysicsHelpers.h"
|
#include "PhysicsHelpers.h"
|
||||||
#include "PhysicsLogging.h"
|
#include "PhysicsLogging.h"
|
||||||
#include "ShapeManager.h"
|
#include "ShapeManager.h"
|
||||||
|
#include "ObjectActionPullToPoint.h"
|
||||||
|
|
||||||
|
#include "PhysicalEntitySimulation.h"
|
||||||
|
|
||||||
PhysicalEntitySimulation::PhysicalEntitySimulation() {
|
PhysicalEntitySimulation::PhysicalEntitySimulation() {
|
||||||
}
|
}
|
||||||
|
@ -232,25 +234,22 @@ void PhysicalEntitySimulation::handleCollisionEvents(CollisionEvents& collisionE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicalEntitySimulation::addAction(EntityActionInterface* action) {
|
EntityActionInterface* PhysicalEntitySimulation::actionFactory(EntityActionType type,
|
||||||
// if (_physicsEngine) {
|
QUuid id,
|
||||||
// _physicsEngine->addAction(action);
|
EntityItemPointer ownerEntity,
|
||||||
// }
|
QVariantMap arguments) {
|
||||||
_actionsToAdd += action;
|
switch (type) {
|
||||||
}
|
case ACTION_TYPE_NONE:
|
||||||
|
assert(false);
|
||||||
|
return nullptr;
|
||||||
|
case ACTION_TYPE_PULL_TO_POINT:
|
||||||
|
QVariantList target = arguments["target"].toList();
|
||||||
|
glm::vec3 glmTarget(target[0].toFloat(), target[1].toFloat(), target[2].toFloat());
|
||||||
|
return (EntityActionInterface*) new ObjectActionPullToPoint(id, ownerEntity, glmTarget);
|
||||||
|
}
|
||||||
|
|
||||||
void PhysicalEntitySimulation::removeAction(const QUuid actionID) {
|
assert(false);
|
||||||
// if (_physicsEngine) {
|
return nullptr;
|
||||||
// _physicsEngine->removeAction(actionID);
|
|
||||||
// }
|
|
||||||
_actionsToRemove += actionID;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PhysicalEntitySimulation::removeActions(QList<QUuid> actionIDsToRemove) {
|
|
||||||
// if (_physicsEngine) {
|
|
||||||
// _physicsEngine->removeActions(actionIDsToRemove);
|
|
||||||
// }
|
|
||||||
_actionsToRemove += actionIDsToRemove;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicalEntitySimulation::applyActionChanges() {
|
void PhysicalEntitySimulation::applyActionChanges() {
|
||||||
|
@ -258,10 +257,9 @@ void PhysicalEntitySimulation::applyActionChanges() {
|
||||||
foreach (EntityActionInterface* actionToAdd, _actionsToAdd) {
|
foreach (EntityActionInterface* actionToAdd, _actionsToAdd) {
|
||||||
_physicsEngine->addAction(actionToAdd);
|
_physicsEngine->addAction(actionToAdd);
|
||||||
}
|
}
|
||||||
_actionsToAdd.clear();
|
|
||||||
foreach (QUuid actionToRemove, _actionsToRemove) {
|
foreach (QUuid actionToRemove, _actionsToRemove) {
|
||||||
_physicsEngine->removeAction(actionToRemove);
|
_physicsEngine->removeAction(actionToRemove);
|
||||||
}
|
}
|
||||||
_actionsToRemove.clear();
|
|
||||||
}
|
}
|
||||||
|
EntitySimulation::applyActionChanges();
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,9 +32,10 @@ public:
|
||||||
|
|
||||||
void init(EntityTree* tree, PhysicsEngine* engine, EntityEditPacketSender* packetSender);
|
void init(EntityTree* tree, PhysicsEngine* engine, EntityEditPacketSender* packetSender);
|
||||||
|
|
||||||
virtual void addAction(EntityActionInterface* action);
|
virtual EntityActionInterface* actionFactory(EntityActionType type,
|
||||||
virtual void removeAction(const QUuid actionID);
|
QUuid id,
|
||||||
virtual void removeActions(QList<QUuid> actionIDsToRemove);
|
EntityItemPointer ownerEntity,
|
||||||
|
QVariantMap arguments);
|
||||||
virtual void applyActionChanges();
|
virtual void applyActionChanges();
|
||||||
|
|
||||||
protected: // only called by EntitySimulation
|
protected: // only called by EntitySimulation
|
||||||
|
@ -69,9 +70,6 @@ private:
|
||||||
EntityEditPacketSender* _entityPacketSender = nullptr;
|
EntityEditPacketSender* _entityPacketSender = nullptr;
|
||||||
|
|
||||||
uint32_t _lastStepSendPackets = 0;
|
uint32_t _lastStepSendPackets = 0;
|
||||||
|
|
||||||
QList<EntityActionInterface*> _actionsToAdd;
|
|
||||||
QList<QUuid> _actionsToRemove;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_PhysicalEntitySimulation_h
|
#endif // hifi_PhysicalEntitySimulation_h
|
||||||
|
|
Loading…
Reference in a new issue