mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 18:36:45 +02:00
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:
parent
ac635336b7
commit
b0d24be58f
6 changed files with 56 additions and 8 deletions
|
@ -66,9 +66,34 @@ std::shared_ptr<Avatar> AvatarActionHold::getTarget(glm::quat& rotation, glm::ve
|
||||||
void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
|
void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
|
||||||
glm::quat rotation;
|
glm::quat rotation;
|
||||||
glm::vec3 position;
|
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([&]{
|
bool gotLock = withTryWriteLock([&]{
|
||||||
_positionalTarget = position;
|
_positionalTarget = position;
|
||||||
_rotationalTarget = rotation;
|
_rotationalTarget = rotation;
|
||||||
|
|
|
@ -12,11 +12,14 @@
|
||||||
#ifndef hifi_EntityActionInterface_h
|
#ifndef hifi_EntityActionInterface_h
|
||||||
#define hifi_EntityActionInterface_h
|
#define hifi_EntityActionInterface_h
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
#include "EntityItem.h"
|
class EntityItem;
|
||||||
|
|
||||||
class EntitySimulation;
|
class EntitySimulation;
|
||||||
|
using EntityItemPointer = std::shared_ptr<EntityItem>;
|
||||||
|
using EntityItemWeakPointer = std::weak_ptr<EntityItem>;
|
||||||
|
|
||||||
enum EntityActionType {
|
enum EntityActionType {
|
||||||
// keep these synchronized with actionTypeFromString and actionTypeToString
|
// keep these synchronized with actionTypeFromString and actionTypeToString
|
||||||
|
@ -34,6 +37,8 @@ public:
|
||||||
const QUuid& getID() const { return _id; }
|
const QUuid& getID() const { return _id; }
|
||||||
EntityActionType getType() const { return _type; }
|
EntityActionType getType() const { return _type; }
|
||||||
|
|
||||||
|
bool isActive() { return _active; }
|
||||||
|
|
||||||
virtual void removeFromSimulation(EntitySimulation* simulation) const = 0;
|
virtual void removeFromSimulation(EntitySimulation* simulation) const = 0;
|
||||||
virtual EntityItemWeakPointer getOwnerEntity() const = 0;
|
virtual EntityItemWeakPointer getOwnerEntity() const = 0;
|
||||||
virtual void setOwnerEntity(const EntityItemPointer ownerEntity) = 0;
|
virtual void setOwnerEntity(const EntityItemPointer ownerEntity) = 0;
|
||||||
|
@ -81,6 +86,7 @@ protected:
|
||||||
|
|
||||||
QUuid _id;
|
QUuid _id;
|
||||||
EntityActionType _type;
|
EntityActionType _type;
|
||||||
|
bool _active { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1844,3 +1844,18 @@ bool EntityItem::shouldSuppressLocationEdits() const {
|
||||||
|
|
||||||
return false;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include "EntityTypes.h"
|
#include "EntityTypes.h"
|
||||||
#include "SimulationOwner.h"
|
#include "SimulationOwner.h"
|
||||||
#include "SimulationFlags.h"
|
#include "SimulationFlags.h"
|
||||||
|
#include "EntityActionInterface.h"
|
||||||
|
|
||||||
class EntitySimulation;
|
class EntitySimulation;
|
||||||
class EntityTreeElement;
|
class EntityTreeElement;
|
||||||
|
@ -419,7 +420,9 @@ public:
|
||||||
|
|
||||||
void setSourceUUID(const QUuid& sourceUUID) { _sourceUUID = sourceUUID; }
|
void setSourceUUID(const QUuid& sourceUUID) { _sourceUUID = sourceUUID; }
|
||||||
const QUuid& getSourceUUID() const { return _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:
|
protected:
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,8 @@
|
||||||
#include <OctreeRenderer.h> // for RenderArgs
|
#include <OctreeRenderer.h> // for RenderArgs
|
||||||
|
|
||||||
class EntityItem;
|
class EntityItem;
|
||||||
typedef std::shared_ptr<EntityItem> EntityItemPointer;
|
using EntityItemPointer = std::shared_ptr<EntityItem>;
|
||||||
typedef std::weak_ptr<EntityItem> EntityItemWeakPointer;
|
using EntityItemWeakPointer = std::weak_ptr<EntityItem>;
|
||||||
|
|
||||||
inline uint qHash(const EntityItemPointer& a, uint seed) {
|
inline uint qHash(const EntityItemPointer& a, uint seed) {
|
||||||
return qHash(a.get(), seed);
|
return qHash(a.get(), seed);
|
||||||
|
|
|
@ -67,7 +67,6 @@ protected:
|
||||||
EntityItemWeakPointer _ownerEntity;
|
EntityItemWeakPointer _ownerEntity;
|
||||||
QString _tag;
|
QString _tag;
|
||||||
quint64 _expires { 0 }; // in seconds since epoch
|
quint64 _expires { 0 }; // in seconds since epoch
|
||||||
bool _active { false };
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int getEntityServerClockSkew() const;
|
int getEntityServerClockSkew() const;
|
||||||
|
|
Loading…
Reference in a new issue