mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 11:14:01 +02:00
simple action is working. destructor sequense is still suspicous
This commit is contained in:
parent
9861e8afcc
commit
d634663bb1
15 changed files with 96 additions and 44 deletions
|
@ -46,6 +46,7 @@ void DeleteEntityOperator::addEntityIDToDeleteList(const EntityItemID& searchEnt
|
||||||
//assert(false);
|
//assert(false);
|
||||||
qCDebug(entities) << "that's UNEXPECTED, we got a _containingElement, but couldn't find the oldEntity!";
|
qCDebug(entities) << "that's UNEXPECTED, we got a _containingElement, but couldn't find the oldEntity!";
|
||||||
} else {
|
} else {
|
||||||
|
details.entity->clearActions();
|
||||||
details.cube = details.containingElement->getAACube();
|
details.cube = details.containingElement->getAACube();
|
||||||
_entitiesToDelete << details;
|
_entitiesToDelete << details;
|
||||||
_lookingCount++;
|
_lookingCount++;
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
#ifndef hifi_EntityActionInterface_h
|
#ifndef hifi_EntityActionInterface_h
|
||||||
#define hifi_EntityActionInterface_h
|
#define hifi_EntityActionInterface_h
|
||||||
|
|
||||||
|
class EntitySimulation;
|
||||||
|
|
||||||
enum EntityActionType {
|
enum EntityActionType {
|
||||||
ACTION_TYPE_NONE,
|
ACTION_TYPE_NONE,
|
||||||
ACTION_TYPE_PULL_TO_POINT
|
ACTION_TYPE_PULL_TO_POINT
|
||||||
|
@ -20,8 +22,11 @@ enum EntityActionType {
|
||||||
|
|
||||||
class EntityActionInterface {
|
class EntityActionInterface {
|
||||||
public:
|
public:
|
||||||
virtual ~EntityActionInterface() {};
|
EntityActionInterface() { qDebug() << "EntityActionInterface::EntityActionInterface"; }
|
||||||
|
virtual ~EntityActionInterface() { qDebug() << "EntityActionInterface::~EntityActionInterface"; }
|
||||||
virtual const QUuid& getID() const = 0;
|
virtual const QUuid& getID() const = 0;
|
||||||
|
virtual void setSimulation(EntitySimulation* simulation) = 0;
|
||||||
|
virtual void removeFromSimulation() 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;
|
||||||
|
|
|
@ -83,9 +83,10 @@ EntityItem::EntityItem(const EntityItemID& entityItemID, const EntityItemPropert
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityItem::~EntityItem() {
|
EntityItem::~EntityItem() {
|
||||||
|
qDebug() << "EntityItem::~EntityItem" << _objectActions.size() << _name;
|
||||||
|
clearActions();
|
||||||
// these pointers MUST be NULL at delete, else we probably have a dangling backpointer
|
// these pointers MUST be NULL at delete, else we probably have a dangling backpointer
|
||||||
// to this EntityItem in the corresponding data structure.
|
// to this EntityItem in the corresponding data structure.
|
||||||
clearActions();
|
|
||||||
assert(!_simulated);
|
assert(!_simulated);
|
||||||
assert(!_element);
|
assert(!_element);
|
||||||
assert(!_physicsInfo);
|
assert(!_physicsInfo);
|
||||||
|
@ -1339,43 +1340,47 @@ void EntityItem::updateSimulatorID(const QUuid& value) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityItem::addAction(EntityActionInterface* action) {
|
bool EntityItem::addAction(EntityActionInterface* action) {
|
||||||
assert(action);
|
assert(action);
|
||||||
const QUuid& actionID = action->getID();
|
const QUuid& actionID = action->getID();
|
||||||
assert(!_objectActions.contains(actionID) || _objectActions[actionID] == action);
|
assert(!_objectActions.contains(actionID) || _objectActions[actionID] == action);
|
||||||
|
qDebug() << "SETTING" << actionID << "in EntityItem::addAction" << _name;
|
||||||
_objectActions[actionID] = action;
|
_objectActions[actionID] = action;
|
||||||
|
|
||||||
EntityItemPointer thisEntity(this);
|
assert(action->getOwnerEntity().get() == this);
|
||||||
assert(action->getOwnerEntity() == nullptr || action->getOwnerEntity() == thisEntity);
|
|
||||||
action->setOwnerEntity(thisEntity);
|
|
||||||
|
|
||||||
|
if (_element) {
|
||||||
const EntityTree* tree = _element->getTree();
|
const EntityTree* tree = _element->getTree();
|
||||||
if (tree) {
|
if (tree) {
|
||||||
EntitySimulation* simulation = tree->getSimulation();
|
EntitySimulation* simulation = tree->getSimulation();
|
||||||
if (simulation) {
|
if (simulation) {
|
||||||
simulation->addAction(action);
|
simulation->addAction(action);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityItem::removeAction(const QUuid actionID) {
|
void EntityItem::removeAction(const QUuid actionID) {
|
||||||
if (_objectActions.contains(actionID)) {
|
if (_objectActions.contains(actionID)) {
|
||||||
const EntityActionInterface* action = _objectActions[actionID];
|
EntityActionInterface* action = _objectActions[actionID];
|
||||||
|
qDebug() << "REMOVING" << actionID << "in EntityItem::removeAction" << _name;
|
||||||
_objectActions.remove(actionID);
|
_objectActions.remove(actionID);
|
||||||
|
action->setOwnerEntity(nullptr);
|
||||||
const EntityTree* tree = _element->getTree();
|
action->removeFromSimulation();
|
||||||
if (tree) {
|
|
||||||
EntitySimulation* simulation = tree->getSimulation();
|
|
||||||
if (simulation) {
|
|
||||||
simulation->removeAction(action->getID());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityItem::clearActions() {
|
void EntityItem::clearActions() {
|
||||||
QHash<QUuid, const EntityActionInterface*>::iterator i;
|
QHash<QUuid, EntityActionInterface*>::iterator i = _objectActions.begin();
|
||||||
for (i = _objectActions.begin(); i != _objectActions.end(); ++i) {
|
while (i != _objectActions.end()) {
|
||||||
removeAction(i.key());
|
const QUuid id = i.key();
|
||||||
|
EntityActionInterface* action = _objectActions[id];
|
||||||
|
qDebug() << "ERASING" << id << "in EntityItem::clearActions" << _name;
|
||||||
|
i = _objectActions.erase(i);
|
||||||
|
action->setOwnerEntity(nullptr);
|
||||||
|
action->removeFromSimulation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -356,10 +356,9 @@ public:
|
||||||
|
|
||||||
void getAllTerseUpdateProperties(EntityItemProperties& properties) const;
|
void getAllTerseUpdateProperties(EntityItemProperties& properties) const;
|
||||||
|
|
||||||
void addAction(EntityActionInterface* actionID);
|
bool addAction(EntityActionInterface* actionID);
|
||||||
void removeAction(const QUuid actionID);
|
void removeAction(const QUuid actionID);
|
||||||
void clearActions();
|
void clearActions();
|
||||||
const QList<QUuid> getActionIDs() const { return _objectActions.keys(); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -433,7 +432,7 @@ protected:
|
||||||
void* _physicsInfo = nullptr; // set by EntitySimulation
|
void* _physicsInfo = nullptr; // set by EntitySimulation
|
||||||
bool _simulated; // set by EntitySimulation
|
bool _simulated; // set by EntitySimulation
|
||||||
|
|
||||||
QHash<QUuid, const EntityActionInterface*> _objectActions;
|
QHash<QUuid, EntityActionInterface*> _objectActions;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_EntityItem_h
|
#endif // hifi_EntityItem_h
|
||||||
|
|
|
@ -450,7 +450,7 @@ bool EntityScriptingInterface::setAllVoxels(QUuid entityID, int value) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid EntityScriptingInterface::addActionPullToPoint(QUuid entityID, const glm::vec3& target) {
|
QUuid EntityScriptingInterface::addActionPullToPoint(QUuid entityID, const glm::vec3& target, float speed) {
|
||||||
if (!_entityTree) {
|
if (!_entityTree) {
|
||||||
return QUuid();
|
return QUuid();
|
||||||
}
|
}
|
||||||
|
@ -470,6 +470,7 @@ QUuid EntityScriptingInterface::addActionPullToPoint(QUuid entityID, const glm::
|
||||||
QVariantList targetList;
|
QVariantList targetList;
|
||||||
targetList << QVariant(target[0]) << QVariant(target[1]) << QVariant(target[2]);
|
targetList << QVariant(target[0]) << QVariant(target[1]) << QVariant(target[2]);
|
||||||
arguments["target"] = targetList;
|
arguments["target"] = targetList;
|
||||||
|
arguments["speed"] = QVariant(speed);
|
||||||
EntityActionInterface* action = simulation->actionFactory(ACTION_TYPE_PULL_TO_POINT, actionID, entity, arguments);
|
EntityActionInterface* action = simulation->actionFactory(ACTION_TYPE_PULL_TO_POINT, actionID, entity, arguments);
|
||||||
entity->addAction(action);
|
entity->addAction(action);
|
||||||
|
|
||||||
|
|
|
@ -124,7 +124,7 @@ public slots:
|
||||||
|
|
||||||
Q_INVOKABLE void dumpTree() const;
|
Q_INVOKABLE void dumpTree() const;
|
||||||
|
|
||||||
Q_INVOKABLE QUuid addActionPullToPoint(QUuid entityID, const glm::vec3& target);
|
Q_INVOKABLE QUuid addActionPullToPoint(QUuid entityID, const glm::vec3& target, float velocity);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void entityCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision);
|
void entityCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision);
|
||||||
|
|
|
@ -60,7 +60,7 @@ public:
|
||||||
QUuid id,
|
QUuid id,
|
||||||
EntityItemPointer ownerEntity,
|
EntityItemPointer ownerEntity,
|
||||||
QVariantMap arguments) { return nullptr; }
|
QVariantMap arguments) { return nullptr; }
|
||||||
virtual void addAction(EntityActionInterface* action) { _actionsToAdd += action; }
|
virtual void addAction(EntityActionInterface* action) { action->setSimulation(this); _actionsToAdd += action; }
|
||||||
virtual void removeAction(const QUuid actionID) { _actionsToRemove += actionID; }
|
virtual void removeAction(const QUuid actionID) { _actionsToRemove += actionID; }
|
||||||
virtual void removeActions(QList<QUuid> actionIDsToRemove) { _actionsToRemove += actionIDsToRemove; }
|
virtual void removeActions(QList<QUuid> actionIDsToRemove) { _actionsToRemove += actionIDsToRemove; }
|
||||||
virtual void applyActionChanges() { _actionsToAdd.clear(); _actionsToRemove.clear(); }
|
virtual void applyActionChanges() { _actionsToAdd.clear(); _actionsToRemove.clear(); }
|
||||||
|
|
|
@ -9,15 +9,19 @@
|
||||||
// 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 "EntitySimulation.h"
|
||||||
|
|
||||||
#include "ObjectAction.h"
|
#include "ObjectAction.h"
|
||||||
|
|
||||||
ObjectAction::ObjectAction(QUuid id, EntityItemPointer ownerEntity) :
|
ObjectAction::ObjectAction(QUuid id, EntityItemPointer ownerEntity) :
|
||||||
btActionInterface(),
|
btActionInterface(),
|
||||||
_id(id),
|
_id(id),
|
||||||
_ownerEntity(ownerEntity) {
|
_ownerEntity(ownerEntity) {
|
||||||
|
qDebug() << "ObjectAction::ObjectAction";
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectAction::~ObjectAction() {
|
ObjectAction::~ObjectAction() {
|
||||||
|
qDebug() << "ObjectAction::~ObjectAction";
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectAction::updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep) {
|
void ObjectAction::updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep) {
|
||||||
|
@ -26,3 +30,9 @@ void ObjectAction::updateAction(btCollisionWorld* collisionWorld, btScalar delta
|
||||||
|
|
||||||
void ObjectAction::debugDraw(btIDebugDraw* debugDrawer) {
|
void ObjectAction::debugDraw(btIDebugDraw* debugDrawer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ObjectAction::removeFromSimulation() const {
|
||||||
|
if (_simulation) {
|
||||||
|
_simulation->removeAction(_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -25,6 +25,8 @@ public:
|
||||||
virtual ~ObjectAction();
|
virtual ~ObjectAction();
|
||||||
|
|
||||||
const QUuid& getID() const { return _id; }
|
const QUuid& getID() const { return _id; }
|
||||||
|
virtual void setSimulation(EntitySimulation* simulation) { _simulation = simulation; }
|
||||||
|
virtual void removeFromSimulation() const;
|
||||||
virtual const EntityItemPointer& getOwnerEntity() const { return _ownerEntity; }
|
virtual const EntityItemPointer& getOwnerEntity() const { return _ownerEntity; }
|
||||||
virtual void setOwnerEntity(const EntityItemPointer ownerEntity) { _ownerEntity = ownerEntity; }
|
virtual void setOwnerEntity(const EntityItemPointer ownerEntity) { _ownerEntity = ownerEntity; }
|
||||||
|
|
||||||
|
@ -34,7 +36,10 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QUuid _id;
|
QUuid _id;
|
||||||
|
|
||||||
|
protected:
|
||||||
EntityItemPointer _ownerEntity;
|
EntityItemPointer _ownerEntity;
|
||||||
|
EntitySimulation* _simulation;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_ObjectAction_h
|
#endif // hifi_ObjectAction_h
|
||||||
|
|
|
@ -9,16 +9,40 @@
|
||||||
// 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 "ObjectMotionState.h"
|
||||||
|
#include "BulletUtil.h"
|
||||||
|
|
||||||
#include "ObjectActionPullToPoint.h"
|
#include "ObjectActionPullToPoint.h"
|
||||||
|
|
||||||
ObjectActionPullToPoint::ObjectActionPullToPoint(QUuid id, EntityItemPointer ownerEntity, glm::vec3 target) :
|
ObjectActionPullToPoint::ObjectActionPullToPoint(QUuid id, EntityItemPointer ownerEntity, glm::vec3 target, float speed) :
|
||||||
ObjectAction(id, ownerEntity),
|
ObjectAction(id, ownerEntity),
|
||||||
_target(target) {
|
_target(target),
|
||||||
|
_speed(speed) {
|
||||||
|
qDebug() << "ObjectActionPullToPoint::ObjectActionPullToPoint";
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectActionPullToPoint::~ObjectActionPullToPoint() {
|
ObjectActionPullToPoint::~ObjectActionPullToPoint() {
|
||||||
|
qDebug() << "ObjectActionPullToPoint::~ObjectActionPullToPoint";
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectActionPullToPoint::updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep) {
|
void ObjectActionPullToPoint::updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep) {
|
||||||
qDebug() << "ObjectActionPullToPoint::updateAction called";
|
glm::vec3 offset = _target - _ownerEntity->getPosition();
|
||||||
|
|
||||||
|
if (glm::length(offset) < IGNORE_POSITION_DELTA) {
|
||||||
|
offset = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::vec3 newVelocity = glm::normalize(offset) * _speed;
|
||||||
|
|
||||||
|
void* physicsInfo = _ownerEntity->getPhysicsInfo();
|
||||||
|
if (physicsInfo) {
|
||||||
|
ObjectMotionState* motionState = static_cast<ObjectMotionState*>(physicsInfo);
|
||||||
|
btRigidBody* rigidBody = motionState->getRigidBody();
|
||||||
|
if (rigidBody) {
|
||||||
|
rigidBody->setLinearVelocity(glmToBullet(newVelocity));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_ownerEntity->updateVelocity(newVelocity);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,13 +19,14 @@
|
||||||
|
|
||||||
class ObjectActionPullToPoint : public ObjectAction {
|
class ObjectActionPullToPoint : public ObjectAction {
|
||||||
public:
|
public:
|
||||||
ObjectActionPullToPoint(QUuid id, EntityItemPointer ownerEntity, glm::vec3 target);
|
ObjectActionPullToPoint(QUuid id, EntityItemPointer ownerEntity, glm::vec3 target, float speed);
|
||||||
virtual ~ObjectActionPullToPoint();
|
virtual ~ObjectActionPullToPoint();
|
||||||
|
|
||||||
void updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep);
|
void updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
glm::vec3 _target;
|
glm::vec3 _target;
|
||||||
|
float _speed;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_ObjectActionPullToPoint_h
|
#endif // hifi_ObjectActionPullToPoint_h
|
||||||
|
|
|
@ -245,7 +245,8 @@ EntityActionInterface* PhysicalEntitySimulation::actionFactory(EntityActionType
|
||||||
case ACTION_TYPE_PULL_TO_POINT:
|
case ACTION_TYPE_PULL_TO_POINT:
|
||||||
QVariantList target = arguments["target"].toList();
|
QVariantList target = arguments["target"].toList();
|
||||||
glm::vec3 glmTarget(target[0].toFloat(), target[1].toFloat(), target[2].toFloat());
|
glm::vec3 glmTarget(target[0].toFloat(), target[1].toFloat(), target[2].toFloat());
|
||||||
return (EntityActionInterface*) new ObjectActionPullToPoint(id, ownerEntity, glmTarget);
|
float speed = arguments["speed"].toFloat();
|
||||||
|
return (EntityActionInterface*) new ObjectActionPullToPoint(id, ownerEntity, glmTarget, speed);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(false);
|
assert(false);
|
||||||
|
|
Loading…
Reference in a new issue