add a way to get a list of all actions of a certain type from an entity. hold actions average their positional targets.

This commit is contained in:
Seth Alves 2015-11-13 16:02:39 -08:00
parent ac635336b7
commit b0d24be58f
6 changed files with 56 additions and 8 deletions

View file

@ -66,9 +66,34 @@ std::shared_ptr<Avatar> AvatarActionHold::getTarget(glm::quat& rotation, glm::ve
void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
glm::quat rotation;
glm::vec3 position;
std::shared_ptr<Avatar> holdingAvatar = getTarget(rotation, position);
bool valid = false;
int holdCount = 0;
auto ownerEntity = _ownerEntity.lock();
if (!ownerEntity) {
return;
}
QList<EntityActionPointer> holdActions = ownerEntity->getActionsOfType(ACTION_TYPE_HOLD);
foreach (EntityActionPointer action, holdActions) {
std::shared_ptr<AvatarActionHold> holdAction = std::static_pointer_cast<AvatarActionHold>(action);
glm::quat rotationForAction;
glm::vec3 positionForAction;
std::shared_ptr<Avatar> holdingAvatar = holdAction->getTarget(rotationForAction, positionForAction);
if (holdingAvatar) {
holdCount ++;
if (holdAction.get() == this) {
// only use the rotation for this action
valid = true;
rotation = rotationForAction;
}
position += positionForAction;
}
}
if (valid && holdCount > 0) {
position /= holdCount;
if (holdingAvatar) {
bool gotLock = withTryWriteLock([&]{
_positionalTarget = position;
_rotationalTarget = rotation;

View file

@ -12,11 +12,14 @@
#ifndef hifi_EntityActionInterface_h
#define hifi_EntityActionInterface_h
#include <memory>
#include <QUuid>
#include <glm/glm.hpp>
#include "EntityItem.h"
class EntityItem;
class EntitySimulation;
using EntityItemPointer = std::shared_ptr<EntityItem>;
using EntityItemWeakPointer = std::weak_ptr<EntityItem>;
enum EntityActionType {
// keep these synchronized with actionTypeFromString and actionTypeToString
@ -34,6 +37,8 @@ public:
const QUuid& getID() const { return _id; }
EntityActionType getType() const { return _type; }
bool isActive() { return _active; }
virtual void removeFromSimulation(EntitySimulation* simulation) const = 0;
virtual EntityItemWeakPointer getOwnerEntity() const = 0;
virtual void setOwnerEntity(const EntityItemPointer ownerEntity) = 0;
@ -81,6 +86,7 @@ protected:
QUuid _id;
EntityActionType _type;
bool _active { false };
};

View file

@ -1844,3 +1844,18 @@ bool EntityItem::shouldSuppressLocationEdits() const {
return false;
}
QList<EntityActionPointer> EntityItem::getActionsOfType(EntityActionType typeToGet) {
QList<EntityActionPointer> result;
QHash<QUuid, EntityActionPointer>::const_iterator i = _objectActions.begin();
while (i != _objectActions.end()) {
EntityActionPointer action = i.value();
if (action->getType() == typeToGet && action->isActive()) {
result += action;
}
i++;
}
return result;
}

View file

@ -30,6 +30,7 @@
#include "EntityTypes.h"
#include "SimulationOwner.h"
#include "SimulationFlags.h"
#include "EntityActionInterface.h"
class EntitySimulation;
class EntityTreeElement;
@ -419,7 +420,9 @@ public:
void setSourceUUID(const QUuid& sourceUUID) { _sourceUUID = sourceUUID; }
const QUuid& getSourceUUID() const { return _sourceUUID; }
bool matchesSourceUUID(const QUuid& sourceUUID) const { return _sourceUUID == sourceUUID; }
bool matchesSourceUUID(const QUuid& sourceUUID) const { return _sourceUUID == sourceUUID; }
QList<EntityActionPointer> getActionsOfType(EntityActionType typeToGet);
protected:

View file

@ -20,8 +20,8 @@
#include <OctreeRenderer.h> // for RenderArgs
class EntityItem;
typedef std::shared_ptr<EntityItem> EntityItemPointer;
typedef std::weak_ptr<EntityItem> EntityItemWeakPointer;
using EntityItemPointer = std::shared_ptr<EntityItem>;
using EntityItemWeakPointer = std::weak_ptr<EntityItem>;
inline uint qHash(const EntityItemPointer& a, uint seed) {
return qHash(a.get(), seed);

View file

@ -67,7 +67,6 @@ protected:
EntityItemWeakPointer _ownerEntity;
QString _tag;
quint64 _expires { 0 }; // in seconds since epoch
bool _active { false };
private:
int getEntityServerClockSkew() const;