mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 11:35:20 +02:00
entity server has its own version of actions which simply remember the encoded arguments. Entities with actions don't experience simulateKinematicMotion
This commit is contained in:
parent
6deedd19a3
commit
5381e6e9bb
20 changed files with 317 additions and 61 deletions
38
assignment-client/src/AssignmentAction.cpp
Normal file
38
assignment-client/src/AssignmentAction.cpp
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
//
|
||||||
|
// AssignmentAction.cpp
|
||||||
|
// assignment-client/src/
|
||||||
|
//
|
||||||
|
// Created by Seth Alves 2015-6-19
|
||||||
|
// 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 "EntitySimulation.h"
|
||||||
|
|
||||||
|
#include "AssignmentAction.h"
|
||||||
|
|
||||||
|
AssignmentAction::AssignmentAction(EntityActionType type, QUuid id, EntityItemPointer ownerEntity) :
|
||||||
|
_id(id),
|
||||||
|
_type(type),
|
||||||
|
_data(QByteArray()),
|
||||||
|
_active(false),
|
||||||
|
_ownerEntity(ownerEntity) {
|
||||||
|
}
|
||||||
|
|
||||||
|
AssignmentAction::~AssignmentAction() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssignmentAction::removeFromSimulation(EntitySimulation* simulation) const {
|
||||||
|
simulation->removeAction(_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray AssignmentAction::serialize() {
|
||||||
|
return _data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssignmentAction::deserialize(QByteArray serializedArguments) {
|
||||||
|
qDebug() << "setting data to" << serializedArguments.size() << "bytes";
|
||||||
|
_data = serializedArguments;
|
||||||
|
}
|
64
assignment-client/src/AssignmentAction.h
Normal file
64
assignment-client/src/AssignmentAction.h
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
//
|
||||||
|
// AssignmentAction.h
|
||||||
|
// assignment-client/src/
|
||||||
|
//
|
||||||
|
// Created by Seth Alves 2015-6-19
|
||||||
|
// 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
|
||||||
|
//
|
||||||
|
// http://bulletphysics.org/Bullet/BulletFull/classbtActionInterface.html
|
||||||
|
|
||||||
|
#ifndef hifi_AssignmentAction_h
|
||||||
|
#define hifi_AssignmentAction_h
|
||||||
|
|
||||||
|
#include <QUuid>
|
||||||
|
#include <EntityItem.h>
|
||||||
|
|
||||||
|
#include "EntityActionInterface.h"
|
||||||
|
|
||||||
|
|
||||||
|
class AssignmentAction : public EntityActionInterface {
|
||||||
|
public:
|
||||||
|
AssignmentAction(EntityActionType type, QUuid id, EntityItemPointer ownerEntity);
|
||||||
|
virtual ~AssignmentAction();
|
||||||
|
|
||||||
|
const QUuid& getID() const { return _id; }
|
||||||
|
virtual EntityActionType getType() { return _type; }
|
||||||
|
virtual void removeFromSimulation(EntitySimulation* simulation) const;
|
||||||
|
virtual const EntityItemPointer& getOwnerEntity() const { return _ownerEntity; }
|
||||||
|
virtual void setOwnerEntity(const EntityItemPointer ownerEntity) { _ownerEntity = ownerEntity; }
|
||||||
|
virtual bool updateArguments(QVariantMap arguments) { assert(false); return false; }
|
||||||
|
|
||||||
|
virtual QByteArray serialize();
|
||||||
|
virtual void deserialize(QByteArray serializedArguments);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QUuid _id;
|
||||||
|
EntityActionType _type;
|
||||||
|
// QReadWriteLock _lock;
|
||||||
|
|
||||||
|
QByteArray _data;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// bool tryLockForRead() { return _lock.tryLockForRead(); }
|
||||||
|
// void lockForWrite() { _lock.lockForWrite(); }
|
||||||
|
// bool tryLockForWrite() { return _lock.tryLockForWrite(); }
|
||||||
|
// void unlock() { _lock.unlock(); }
|
||||||
|
|
||||||
|
virtual glm::vec3 getPosition() { assert(false); return glm::vec3(0.0f); }
|
||||||
|
virtual void setPosition(glm::vec3 position) { assert(false); }
|
||||||
|
virtual glm::quat getRotation() { assert(false); return glm::quat(); }
|
||||||
|
virtual void setRotation(glm::quat rotation) { assert(false); }
|
||||||
|
virtual glm::vec3 getLinearVelocity() { assert(false); return glm::vec3(0.0f); }
|
||||||
|
virtual void setLinearVelocity(glm::vec3 linearVelocity) { assert(false); }
|
||||||
|
virtual glm::vec3 getAngularVelocity() { assert(false); return glm::vec3(0.0f); }
|
||||||
|
virtual void setAngularVelocity(glm::vec3 angularVelocity) { assert(false); }
|
||||||
|
|
||||||
|
bool _active;
|
||||||
|
EntityItemPointer _ownerEntity;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // hifi_AssignmentAction_h
|
52
assignment-client/src/AssignmentActionFactory.cpp
Normal file
52
assignment-client/src/AssignmentActionFactory.cpp
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
//
|
||||||
|
// AssignmentActionFactory.cpp
|
||||||
|
// assignment-client/src/
|
||||||
|
//
|
||||||
|
// Created by Seth Alves on 2015-6-19
|
||||||
|
// 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 "AssignmentActionFactory.h"
|
||||||
|
|
||||||
|
|
||||||
|
EntityActionPointer assignmentActionFactory(EntityActionType type, QUuid id, EntityItemPointer ownerEntity) {
|
||||||
|
return (EntityActionPointer) new AssignmentAction(type, id, ownerEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
EntityActionPointer AssignmentActionFactory::factory(EntitySimulation* simulation,
|
||||||
|
EntityActionType type,
|
||||||
|
QUuid id,
|
||||||
|
EntityItemPointer ownerEntity,
|
||||||
|
QVariantMap arguments) {
|
||||||
|
EntityActionPointer action = assignmentActionFactory(type, id, ownerEntity);
|
||||||
|
if (action) {
|
||||||
|
bool ok = action->updateArguments(arguments);
|
||||||
|
if (ok) {
|
||||||
|
ownerEntity->addAction(simulation, action);
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
EntityActionPointer AssignmentActionFactory::factoryBA(EntitySimulation* simulation,
|
||||||
|
EntityItemPointer ownerEntity,
|
||||||
|
QByteArray data) {
|
||||||
|
QDataStream ds(data);
|
||||||
|
EntityActionType type;
|
||||||
|
QUuid id;
|
||||||
|
|
||||||
|
ds >> type;
|
||||||
|
ds >> id;
|
||||||
|
|
||||||
|
EntityActionPointer action = assignmentActionFactory(type, id, ownerEntity);
|
||||||
|
|
||||||
|
action->deserialize(data);
|
||||||
|
ownerEntity->addAction(simulation, action);
|
||||||
|
return action;
|
||||||
|
}
|
32
assignment-client/src/AssignmentActionFactory.h
Normal file
32
assignment-client/src/AssignmentActionFactory.h
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
//
|
||||||
|
// AssignmentActionFactory.cpp
|
||||||
|
// assignment-client/src/
|
||||||
|
//
|
||||||
|
// Created by Seth Alves on 2015-6-19
|
||||||
|
// 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_AssignmentActionFactory_h
|
||||||
|
#define hifi_AssignmentActionFactory_h
|
||||||
|
|
||||||
|
#include "EntityActionFactoryInterface.h"
|
||||||
|
#include "AssignmentAction.h"
|
||||||
|
|
||||||
|
class AssignmentActionFactory : public EntityActionFactoryInterface {
|
||||||
|
public:
|
||||||
|
AssignmentActionFactory() : EntityActionFactoryInterface() { }
|
||||||
|
virtual ~AssignmentActionFactory() { }
|
||||||
|
virtual EntityActionPointer factory(EntitySimulation* simulation,
|
||||||
|
EntityActionType type,
|
||||||
|
QUuid id,
|
||||||
|
EntityItemPointer ownerEntity,
|
||||||
|
QVariantMap arguments);
|
||||||
|
virtual EntityActionPointer factoryBA(EntitySimulation* simulation,
|
||||||
|
EntityItemPointer ownerEntity,
|
||||||
|
QByteArray data);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // hifi_AssignmentActionFactory_h
|
|
@ -32,6 +32,7 @@
|
||||||
#include <SoundCache.h>
|
#include <SoundCache.h>
|
||||||
|
|
||||||
#include "AssignmentFactory.h"
|
#include "AssignmentFactory.h"
|
||||||
|
#include "AssignmentActionFactory.h"
|
||||||
|
|
||||||
#include "AssignmentClient.h"
|
#include "AssignmentClient.h"
|
||||||
|
|
||||||
|
@ -58,6 +59,9 @@ AssignmentClient::AssignmentClient(Assignment::Type requestAssignmentType, QStri
|
||||||
auto avatarHashMap = DependencyManager::set<AvatarHashMap>();
|
auto avatarHashMap = DependencyManager::set<AvatarHashMap>();
|
||||||
auto entityScriptingInterface = DependencyManager::set<EntityScriptingInterface>();
|
auto entityScriptingInterface = DependencyManager::set<EntityScriptingInterface>();
|
||||||
|
|
||||||
|
DependencyManager::registerInheritance<EntityActionFactoryInterface, AssignmentActionFactory>();
|
||||||
|
auto actionFactory = DependencyManager::set<AssignmentActionFactory>();
|
||||||
|
|
||||||
// make up a uuid for this child so the parent can tell us apart. This id will be changed
|
// make up a uuid for this child so the parent can tell us apart. This id will be changed
|
||||||
// when the domain server hands over an assignment.
|
// when the domain server hands over an assignment.
|
||||||
QUuid nodeUUID = QUuid::createUuid();
|
QUuid nodeUUID = QUuid::createUuid();
|
||||||
|
|
|
@ -23,11 +23,11 @@ EntityActionPointer interfaceActionFactory(EntityActionType type, QUuid id, Enti
|
||||||
case ACTION_TYPE_NONE:
|
case ACTION_TYPE_NONE:
|
||||||
return nullptr;
|
return nullptr;
|
||||||
case ACTION_TYPE_OFFSET:
|
case ACTION_TYPE_OFFSET:
|
||||||
return (EntityActionPointer) new ObjectActionOffset(id, ownerEntity);
|
return (EntityActionPointer) new ObjectActionOffset(type, id, ownerEntity);
|
||||||
case ACTION_TYPE_SPRING:
|
case ACTION_TYPE_SPRING:
|
||||||
return (EntityActionPointer) new ObjectActionSpring(id, ownerEntity);
|
return (EntityActionPointer) new ObjectActionSpring(type, id, ownerEntity);
|
||||||
case ACTION_TYPE_HOLD:
|
case ACTION_TYPE_HOLD:
|
||||||
return (EntityActionPointer) new AvatarActionHold(id, ownerEntity);
|
return (EntityActionPointer) new AvatarActionHold(type, id, ownerEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(false);
|
assert(false);
|
||||||
|
@ -64,7 +64,7 @@ EntityActionPointer InterfaceActionFactory::factoryBA(EntitySimulation* simulati
|
||||||
|
|
||||||
EntityActionPointer action = interfaceActionFactory(type, id, ownerEntity);
|
EntityActionPointer action = interfaceActionFactory(type, id, ownerEntity);
|
||||||
|
|
||||||
action->deserializeFromDataStream(ds);
|
action->deserialize(data);
|
||||||
ownerEntity->addAction(simulation, action);
|
ownerEntity->addAction(simulation, action);
|
||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
|
|
||||||
#include "AvatarActionHold.h"
|
#include "AvatarActionHold.h"
|
||||||
|
|
||||||
AvatarActionHold::AvatarActionHold(QUuid id, EntityItemPointer ownerEntity) :
|
AvatarActionHold::AvatarActionHold(EntityActionType type, QUuid id, EntityItemPointer ownerEntity) :
|
||||||
ObjectActionSpring(id, ownerEntity) {
|
ObjectActionSpring(type, id, ownerEntity) {
|
||||||
#if WANT_DEBUG
|
#if WANT_DEBUG
|
||||||
qDebug() << "AvatarActionHold::AvatarActionHold";
|
qDebug() << "AvatarActionHold::AvatarActionHold";
|
||||||
#endif
|
#endif
|
||||||
|
@ -116,15 +116,35 @@ bool AvatarActionHold::updateArguments(QVariantMap arguments) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AvatarActionHold::serializeToDataStream(QDataStream& dataStream) {
|
QByteArray AvatarActionHold::serialize() {
|
||||||
|
QByteArray ba;
|
||||||
|
QDataStream dataStream(&ba, QIODevice::WriteOnly);
|
||||||
|
|
||||||
|
dataStream << getType();
|
||||||
|
dataStream << getID();
|
||||||
|
|
||||||
dataStream << _relativePosition;
|
dataStream << _relativePosition;
|
||||||
dataStream << _relativeRotation;
|
dataStream << _relativeRotation;
|
||||||
dataStream << _hand;
|
dataStream << _hand;
|
||||||
|
|
||||||
|
return ba;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AvatarActionHold::deserializeFromDataStream(QDataStream& dataStream) {
|
void AvatarActionHold::deserialize(QByteArray serializedArguments) {
|
||||||
|
QDataStream dataStream(serializedArguments);
|
||||||
|
|
||||||
|
EntityActionType type;
|
||||||
|
QUuid id;
|
||||||
|
|
||||||
|
dataStream >> type;
|
||||||
|
dataStream >> id;
|
||||||
|
assert(type == getType());
|
||||||
|
assert(id == getID());
|
||||||
|
|
||||||
dataStream >> _relativePosition;
|
dataStream >> _relativePosition;
|
||||||
dataStream >> _relativeRotation;
|
dataStream >> _relativeRotation;
|
||||||
dataStream >> _hand;
|
dataStream >> _hand;
|
||||||
_parametersSet = true;
|
_parametersSet = true;
|
||||||
|
|
||||||
|
_active = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
class AvatarActionHold : public ObjectActionSpring {
|
class AvatarActionHold : public ObjectActionSpring {
|
||||||
public:
|
public:
|
||||||
AvatarActionHold(QUuid id, EntityItemPointer ownerEntity);
|
AvatarActionHold(EntityActionType type, QUuid id, EntityItemPointer ownerEntity);
|
||||||
virtual ~AvatarActionHold();
|
virtual ~AvatarActionHold();
|
||||||
|
|
||||||
virtual EntityActionType getType() { return ACTION_TYPE_HOLD; }
|
virtual EntityActionType getType() { return ACTION_TYPE_HOLD; }
|
||||||
|
@ -27,9 +27,12 @@ public:
|
||||||
virtual bool updateArguments(QVariantMap arguments);
|
virtual bool updateArguments(QVariantMap arguments);
|
||||||
virtual void updateActionWorker(float deltaTimeStep);
|
virtual void updateActionWorker(float deltaTimeStep);
|
||||||
|
|
||||||
|
virtual QByteArray serialize();
|
||||||
|
virtual void deserialize(QByteArray serializedArguments);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void serializeToDataStream(QDataStream& dataStream);
|
// void serializeToDataStream(QDataStream& dataStream);
|
||||||
void deserializeFromDataStream(QDataStream& dataStream);
|
// void deserializeFromDataStream(QDataStream& dataStream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
glm::vec3 _relativePosition;
|
glm::vec3 _relativePosition;
|
||||||
|
|
|
@ -175,25 +175,14 @@ QString EntityActionInterface::extractStringArgument(QString objectName, QVarian
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray EntityActionInterface::serialize() {
|
|
||||||
QByteArray ba;
|
|
||||||
QDataStream ds(&ba, QIODevice::WriteOnly);
|
|
||||||
|
|
||||||
ds << getType();
|
|
||||||
ds << getID();
|
|
||||||
|
|
||||||
serializeToDataStream(ds);
|
|
||||||
return ba;
|
|
||||||
}
|
|
||||||
|
|
||||||
QDataStream& operator<<(QDataStream& stream, const EntityActionType& entityActionType)
|
QDataStream& operator<<(QDataStream& stream, const EntityActionType& entityActionType)
|
||||||
{
|
{
|
||||||
return stream << (quint8)entityActionType;
|
return stream << (quint16)entityActionType;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDataStream& operator>>(QDataStream& stream, EntityActionType& entityActionType)
|
QDataStream& operator>>(QDataStream& stream, EntityActionType& entityActionType)
|
||||||
{
|
{
|
||||||
quint8 v;
|
quint16 v;
|
||||||
stream >> v;
|
stream >> v;
|
||||||
entityActionType = (EntityActionType)v;
|
entityActionType = (EntityActionType)v;
|
||||||
return stream;
|
return stream;
|
||||||
|
|
|
@ -20,10 +20,10 @@ class EntitySimulation;
|
||||||
|
|
||||||
enum EntityActionType {
|
enum EntityActionType {
|
||||||
// keep these synchronized with actionTypeFromString and actionTypeToString
|
// keep these synchronized with actionTypeFromString and actionTypeToString
|
||||||
ACTION_TYPE_NONE,
|
ACTION_TYPE_NONE = 0,
|
||||||
ACTION_TYPE_OFFSET,
|
ACTION_TYPE_OFFSET = 1000,
|
||||||
ACTION_TYPE_SPRING,
|
ACTION_TYPE_SPRING = 2000,
|
||||||
ACTION_TYPE_HOLD
|
ACTION_TYPE_HOLD = 3000
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,9 +39,8 @@ public:
|
||||||
virtual void setOwnerEntity(const EntityItemPointer ownerEntity) = 0;
|
virtual void setOwnerEntity(const EntityItemPointer ownerEntity) = 0;
|
||||||
virtual bool updateArguments(QVariantMap arguments) = 0;
|
virtual bool updateArguments(QVariantMap arguments) = 0;
|
||||||
|
|
||||||
virtual QByteArray serialize();
|
virtual QByteArray serialize() = 0;
|
||||||
virtual void serializeToDataStream(QDataStream& dataStream) = 0;
|
virtual void deserialize(QByteArray serializedArguments) = 0;
|
||||||
virtual void deserializeFromDataStream(QDataStream& dataStream) = 0;
|
|
||||||
|
|
||||||
static EntityActionType actionTypeFromString(QString actionTypeString);
|
static EntityActionType actionTypeFromString(QString actionTypeString);
|
||||||
static QString actionTypeToString(EntityActionType actionType);
|
static QString actionTypeToString(EntityActionType actionType);
|
||||||
|
|
|
@ -761,6 +761,10 @@ void EntityItem::simulate(const quint64& now) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityItem::simulateKinematicMotion(float timeElapsed, bool setFlags) {
|
void EntityItem::simulateKinematicMotion(float timeElapsed, bool setFlags) {
|
||||||
|
if (hasActions()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (hasAngularVelocity()) {
|
if (hasAngularVelocity()) {
|
||||||
// angular damping
|
// angular damping
|
||||||
if (_angularDamping > 0.0f) {
|
if (_angularDamping > 0.0f) {
|
||||||
|
@ -1367,7 +1371,7 @@ bool EntityItem::addAction(EntitySimulation* simulation, EntityActionPointer act
|
||||||
assert(action->getOwnerEntity().get() == this);
|
assert(action->getOwnerEntity().get() == this);
|
||||||
|
|
||||||
simulation->addAction(action);
|
simulation->addAction(action);
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EntityItem::updateAction(EntitySimulation* simulation, const QUuid& actionID, const QVariantMap& arguments) {
|
bool EntityItem::updateAction(EntitySimulation* simulation, const QUuid& actionID, const QVariantMap& arguments) {
|
||||||
|
@ -1404,12 +1408,11 @@ void EntityItem::setActionData(QByteArray actionData) {
|
||||||
if (actionData.size() == 0) {
|
if (actionData.size() == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<QByteArray> serializedActions;
|
QVector<QByteArray> serializedActions;
|
||||||
QDataStream ds(actionData);
|
QDataStream ds(actionData);
|
||||||
ds >> serializedActions;
|
ds >> serializedActions;
|
||||||
|
|
||||||
qDebug() << "EntityItem::setActionData" << actionData.size() << "bytes";
|
|
||||||
|
|
||||||
foreach(QByteArray serializedAction, serializedActions) {
|
foreach(QByteArray serializedAction, serializedActions) {
|
||||||
QDataStream dsForAction(serializedAction);
|
QDataStream dsForAction(serializedAction);
|
||||||
EntityActionType actionType;
|
EntityActionType actionType;
|
||||||
|
@ -1420,7 +1423,7 @@ void EntityItem::setActionData(QByteArray actionData) {
|
||||||
if (_objectActions.contains(actionID)) {
|
if (_objectActions.contains(actionID)) {
|
||||||
EntityActionPointer action = _objectActions[actionID];
|
EntityActionPointer action = _objectActions[actionID];
|
||||||
// XXX make sure types match?
|
// XXX make sure types match?
|
||||||
action->deserializeFromDataStream(dsForAction);
|
action->deserialize(serializedAction);
|
||||||
} else {
|
} else {
|
||||||
auto actionFactory = DependencyManager::get<EntityActionFactoryInterface>();
|
auto actionFactory = DependencyManager::get<EntityActionFactoryInterface>();
|
||||||
|
|
||||||
|
@ -1439,6 +1442,10 @@ void EntityItem::setActionData(QByteArray actionData) {
|
||||||
|
|
||||||
|
|
||||||
const QByteArray EntityItem::getActionData() const {
|
const QByteArray EntityItem::getActionData() const {
|
||||||
|
if (_objectActions.size() == 0) {
|
||||||
|
return QByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
QVector<QByteArray> serializedActions;
|
QVector<QByteArray> serializedActions;
|
||||||
QHash<QUuid, EntityActionPointer>::const_iterator i = _objectActions.begin();
|
QHash<QUuid, EntityActionPointer>::const_iterator i = _objectActions.begin();
|
||||||
while (i != _objectActions.end()) {
|
while (i != _objectActions.end()) {
|
||||||
|
@ -1452,5 +1459,6 @@ const QByteArray EntityItem::getActionData() const {
|
||||||
QByteArray result;
|
QByteArray result;
|
||||||
QDataStream ds(&result, QIODevice::WriteOnly);
|
QDataStream ds(&result, QIODevice::WriteOnly);
|
||||||
ds << serializedActions;
|
ds << serializedActions;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -381,6 +381,7 @@ public:
|
||||||
void clearActions(EntitySimulation* simulation);
|
void clearActions(EntitySimulation* simulation);
|
||||||
void setActionData(QByteArray actionData);
|
void setActionData(QByteArray actionData);
|
||||||
const QByteArray getActionData() const;
|
const QByteArray getActionData() const;
|
||||||
|
bool hasActions() { return !_objectActions.empty(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|
|
@ -181,7 +181,6 @@ QString EntityItemProperties::getAnimationSettings() const {
|
||||||
|
|
||||||
void EntityItemProperties::setCreated(QDateTime &v) {
|
void EntityItemProperties::setCreated(QDateTime &v) {
|
||||||
_created = v.toMSecsSinceEpoch() * 1000; // usec per msec
|
_created = v.toMSecsSinceEpoch() * 1000; // usec per msec
|
||||||
qDebug() << "EntityItemProperties::setCreated QDateTime" << v << _created;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityItemProperties::debugDump() const {
|
void EntityItemProperties::debugDump() const {
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
#include "ObjectAction.h"
|
#include "ObjectAction.h"
|
||||||
|
|
||||||
ObjectAction::ObjectAction(QUuid id, EntityItemPointer ownerEntity) :
|
ObjectAction::ObjectAction(EntityActionType type, QUuid id, EntityItemPointer ownerEntity) :
|
||||||
btActionInterface(),
|
btActionInterface(),
|
||||||
_id(id),
|
_id(id),
|
||||||
_active(false),
|
_active(false),
|
||||||
|
@ -124,3 +124,12 @@ void ObjectAction::setAngularVelocity(glm::vec3 angularVelocity) {
|
||||||
rigidBody->setAngularVelocity(glmToBullet(angularVelocity));
|
rigidBody->setAngularVelocity(glmToBullet(angularVelocity));
|
||||||
rigidBody->activate();
|
rigidBody->activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QByteArray ObjectAction::serialize() {
|
||||||
|
assert(false);
|
||||||
|
return QByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjectAction::deserialize(QByteArray serializedArguments) {
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
class ObjectAction : public btActionInterface, public EntityActionInterface {
|
class ObjectAction : public btActionInterface, public EntityActionInterface {
|
||||||
public:
|
public:
|
||||||
ObjectAction(QUuid id, EntityItemPointer ownerEntity);
|
ObjectAction(EntityActionType type, QUuid id, EntityItemPointer ownerEntity);
|
||||||
virtual ~ObjectAction();
|
virtual ~ObjectAction();
|
||||||
|
|
||||||
const QUuid& getID() const { return _id; }
|
const QUuid& getID() const { return _id; }
|
||||||
|
@ -43,13 +43,14 @@ public:
|
||||||
virtual void updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep);
|
virtual void updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep);
|
||||||
virtual void debugDraw(btIDebugDraw* debugDrawer);
|
virtual void debugDraw(btIDebugDraw* debugDrawer);
|
||||||
|
|
||||||
|
virtual QByteArray serialize();
|
||||||
|
virtual void deserialize(QByteArray serializedArguments);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QUuid _id;
|
QUuid _id;
|
||||||
QReadWriteLock _lock;
|
QReadWriteLock _lock;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void serializeToDataStream(QDataStream& dataStream) = 0;
|
|
||||||
virtual void deserializeFromDataStream(QDataStream& dataStream) = 0;
|
|
||||||
|
|
||||||
virtual btRigidBody* getRigidBody();
|
virtual btRigidBody* getRigidBody();
|
||||||
virtual glm::vec3 getPosition();
|
virtual glm::vec3 getPosition();
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
|
|
||||||
#include "ObjectActionOffset.h"
|
#include "ObjectActionOffset.h"
|
||||||
|
|
||||||
ObjectActionOffset::ObjectActionOffset(QUuid id, EntityItemPointer ownerEntity) :
|
ObjectActionOffset::ObjectActionOffset(EntityActionType type, QUuid id, EntityItemPointer ownerEntity) :
|
||||||
ObjectAction(id, ownerEntity) {
|
ObjectAction(type, id, ownerEntity) {
|
||||||
#if WANT_DEBUG
|
#if WANT_DEBUG
|
||||||
qDebug() << "ObjectActionOffset::ObjectActionOffset";
|
qDebug() << "ObjectActionOffset::ObjectActionOffset";
|
||||||
#endif
|
#endif
|
||||||
|
@ -108,16 +108,35 @@ bool ObjectActionOffset::updateArguments(QVariantMap arguments) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectActionOffset::serializeToDataStream(QDataStream& dataStream) {
|
QByteArray ObjectActionOffset::serialize() {
|
||||||
|
QByteArray ba;
|
||||||
|
QDataStream dataStream(&ba, QIODevice::WriteOnly);
|
||||||
|
dataStream << getType();
|
||||||
|
dataStream << getID();
|
||||||
|
|
||||||
dataStream << _pointToOffsetFrom;
|
dataStream << _pointToOffsetFrom;
|
||||||
dataStream << _linearDistance;
|
dataStream << _linearDistance;
|
||||||
dataStream << _linearTimeScale;
|
dataStream << _linearTimeScale;
|
||||||
dataStream << _positionalTargetSet;
|
dataStream << _positionalTargetSet;
|
||||||
|
|
||||||
|
return ba;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectActionOffset::deserializeFromDataStream(QDataStream& dataStream) {
|
void ObjectActionOffset::deserialize(QByteArray serializedArguments) {
|
||||||
|
QDataStream dataStream(serializedArguments);
|
||||||
|
|
||||||
|
EntityActionType type;
|
||||||
|
QUuid id;
|
||||||
|
|
||||||
|
dataStream >> type;
|
||||||
|
dataStream >> id;
|
||||||
|
assert(type == getType());
|
||||||
|
assert(id == getID());
|
||||||
|
|
||||||
dataStream >> _pointToOffsetFrom;
|
dataStream >> _pointToOffsetFrom;
|
||||||
dataStream >> _linearDistance;
|
dataStream >> _linearDistance;
|
||||||
dataStream >> _linearTimeScale;
|
dataStream >> _linearTimeScale;
|
||||||
dataStream >> _positionalTargetSet;
|
dataStream >> _positionalTargetSet;
|
||||||
|
|
||||||
|
_active = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
class ObjectActionOffset : public ObjectAction {
|
class ObjectActionOffset : public ObjectAction {
|
||||||
public:
|
public:
|
||||||
ObjectActionOffset(QUuid id, EntityItemPointer ownerEntity);
|
ObjectActionOffset(EntityActionType type, QUuid id, EntityItemPointer ownerEntity);
|
||||||
virtual ~ObjectActionOffset();
|
virtual ~ObjectActionOffset();
|
||||||
|
|
||||||
virtual EntityActionType getType() { return ACTION_TYPE_OFFSET; }
|
virtual EntityActionType getType() { return ACTION_TYPE_OFFSET; }
|
||||||
|
@ -27,11 +27,10 @@ public:
|
||||||
virtual bool updateArguments(QVariantMap arguments);
|
virtual bool updateArguments(QVariantMap arguments);
|
||||||
virtual void updateActionWorker(float deltaTimeStep);
|
virtual void updateActionWorker(float deltaTimeStep);
|
||||||
|
|
||||||
protected:
|
virtual QByteArray serialize();
|
||||||
virtual void serializeToDataStream(QDataStream& dataStream);
|
virtual void deserialize(QByteArray serializedArguments);
|
||||||
virtual void deserializeFromDataStream(QDataStream& dataStream);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
glm::vec3 _pointToOffsetFrom;
|
glm::vec3 _pointToOffsetFrom;
|
||||||
float _linearDistance;
|
float _linearDistance;
|
||||||
float _linearTimeScale;
|
float _linearTimeScale;
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
|
|
||||||
#include "ObjectActionSpring.h"
|
#include "ObjectActionSpring.h"
|
||||||
|
|
||||||
ObjectActionSpring::ObjectActionSpring(QUuid id, EntityItemPointer ownerEntity) :
|
ObjectActionSpring::ObjectActionSpring(EntityActionType type, QUuid id, EntityItemPointer ownerEntity) :
|
||||||
ObjectAction(id, ownerEntity) {
|
ObjectAction(type, id, ownerEntity) {
|
||||||
#if WANT_DEBUG
|
#if WANT_DEBUG
|
||||||
qDebug() << "ObjectActionSpring::ObjectActionSpring";
|
qDebug() << "ObjectActionSpring::ObjectActionSpring";
|
||||||
#endif
|
#endif
|
||||||
|
@ -143,8 +143,13 @@ bool ObjectActionSpring::updateArguments(QVariantMap arguments) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QByteArray ObjectActionSpring::serialize() {
|
||||||
|
QByteArray ba;
|
||||||
|
QDataStream dataStream(&ba, QIODevice::WriteOnly);
|
||||||
|
|
||||||
|
dataStream << getType();
|
||||||
|
dataStream << getID();
|
||||||
|
|
||||||
void ObjectActionSpring::serializeToDataStream(QDataStream& dataStream) {
|
|
||||||
dataStream << _positionalTarget;
|
dataStream << _positionalTarget;
|
||||||
dataStream << _linearTimeScale;
|
dataStream << _linearTimeScale;
|
||||||
dataStream << _positionalTargetSet;
|
dataStream << _positionalTargetSet;
|
||||||
|
@ -152,9 +157,21 @@ void ObjectActionSpring::serializeToDataStream(QDataStream& dataStream) {
|
||||||
dataStream << _rotationalTarget;
|
dataStream << _rotationalTarget;
|
||||||
dataStream << _angularTimeScale;
|
dataStream << _angularTimeScale;
|
||||||
dataStream << _rotationalTargetSet;
|
dataStream << _rotationalTargetSet;
|
||||||
|
|
||||||
|
return ba;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectActionSpring::deserializeFromDataStream(QDataStream& dataStream) {
|
void ObjectActionSpring::deserialize(QByteArray serializedArguments) {
|
||||||
|
QDataStream dataStream(serializedArguments);
|
||||||
|
|
||||||
|
EntityActionType type;
|
||||||
|
QUuid id;
|
||||||
|
|
||||||
|
dataStream >> type;
|
||||||
|
dataStream >> id;
|
||||||
|
assert(type == getType());
|
||||||
|
assert(id == getID());
|
||||||
|
|
||||||
dataStream >> _positionalTarget;
|
dataStream >> _positionalTarget;
|
||||||
dataStream >> _linearTimeScale;
|
dataStream >> _linearTimeScale;
|
||||||
dataStream >> _positionalTargetSet;
|
dataStream >> _positionalTargetSet;
|
||||||
|
@ -162,4 +179,6 @@ void ObjectActionSpring::deserializeFromDataStream(QDataStream& dataStream) {
|
||||||
dataStream >> _rotationalTarget;
|
dataStream >> _rotationalTarget;
|
||||||
dataStream >> _angularTimeScale;
|
dataStream >> _angularTimeScale;
|
||||||
dataStream >> _rotationalTargetSet;
|
dataStream >> _rotationalTargetSet;
|
||||||
|
|
||||||
|
_active = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
class ObjectActionSpring : public ObjectAction {
|
class ObjectActionSpring : public ObjectAction {
|
||||||
public:
|
public:
|
||||||
ObjectActionSpring(QUuid id, EntityItemPointer ownerEntity);
|
ObjectActionSpring(EntityActionType type, QUuid id, EntityItemPointer ownerEntity);
|
||||||
virtual ~ObjectActionSpring();
|
virtual ~ObjectActionSpring();
|
||||||
|
|
||||||
virtual EntityActionType getType() { return ACTION_TYPE_SPRING; }
|
virtual EntityActionType getType() { return ACTION_TYPE_SPRING; }
|
||||||
|
@ -27,10 +27,10 @@ public:
|
||||||
virtual bool updateArguments(QVariantMap arguments);
|
virtual bool updateArguments(QVariantMap arguments);
|
||||||
virtual void updateActionWorker(float deltaTimeStep);
|
virtual void updateActionWorker(float deltaTimeStep);
|
||||||
|
|
||||||
protected:
|
virtual QByteArray serialize();
|
||||||
virtual void serializeToDataStream(QDataStream& dataStream);
|
virtual void deserialize(QByteArray serializedArguments);
|
||||||
virtual void deserializeFromDataStream(QDataStream& dataStream);
|
|
||||||
|
|
||||||
|
protected:
|
||||||
glm::vec3 _positionalTarget;
|
glm::vec3 _positionalTarget;
|
||||||
float _linearTimeScale;
|
float _linearTimeScale;
|
||||||
bool _positionalTargetSet;
|
bool _positionalTargetSet;
|
||||||
|
|
Loading…
Reference in a new issue