mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 14:58:03 +02:00
Merge remote-tracking branch 'upstream/master' into entity_parsing
This commit is contained in:
commit
49a14e3446
22 changed files with 200 additions and 130 deletions
|
@ -13,9 +13,8 @@
|
||||||
|
|
||||||
#include "AssignmentAction.h"
|
#include "AssignmentAction.h"
|
||||||
|
|
||||||
AssignmentAction::AssignmentAction(EntityActionType type, QUuid id, EntityItemPointer ownerEntity) :
|
AssignmentAction::AssignmentAction(EntityActionType type, const QUuid& id, EntityItemPointer ownerEntity) :
|
||||||
_id(id),
|
EntityActionInterface(type, id),
|
||||||
_type(type),
|
|
||||||
_data(QByteArray()),
|
_data(QByteArray()),
|
||||||
_active(false),
|
_active(false),
|
||||||
_ownerEntity(ownerEntity) {
|
_ownerEntity(ownerEntity) {
|
||||||
|
@ -28,7 +27,7 @@ void AssignmentAction::removeFromSimulation(EntitySimulation* simulation) const
|
||||||
simulation->removeAction(_id);
|
simulation->removeAction(_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray AssignmentAction::serialize() {
|
QByteArray AssignmentAction::serialize() const {
|
||||||
return _data;
|
return _data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,23 +21,19 @@
|
||||||
|
|
||||||
class AssignmentAction : public EntityActionInterface {
|
class AssignmentAction : public EntityActionInterface {
|
||||||
public:
|
public:
|
||||||
AssignmentAction(EntityActionType type, QUuid id, EntityItemPointer ownerEntity);
|
AssignmentAction(EntityActionType type, const QUuid& id, EntityItemPointer ownerEntity);
|
||||||
virtual ~AssignmentAction();
|
virtual ~AssignmentAction();
|
||||||
|
|
||||||
const QUuid& getID() const { return _id; }
|
|
||||||
virtual EntityActionType getType() { return _type; }
|
|
||||||
virtual void removeFromSimulation(EntitySimulation* simulation) const;
|
virtual void removeFromSimulation(EntitySimulation* simulation) const;
|
||||||
virtual EntityItemWeakPointer getOwnerEntity() const { return _ownerEntity; }
|
virtual EntityItemWeakPointer getOwnerEntity() const { return _ownerEntity; }
|
||||||
virtual void setOwnerEntity(const EntityItemPointer ownerEntity) { _ownerEntity = ownerEntity; }
|
virtual void setOwnerEntity(const EntityItemPointer ownerEntity) { _ownerEntity = ownerEntity; }
|
||||||
virtual bool updateArguments(QVariantMap arguments);
|
virtual bool updateArguments(QVariantMap arguments);
|
||||||
virtual QVariantMap getArguments();
|
virtual QVariantMap getArguments();
|
||||||
|
|
||||||
virtual QByteArray serialize();
|
virtual QByteArray serialize() const;
|
||||||
virtual void deserialize(QByteArray serializedArguments);
|
virtual void deserialize(QByteArray serializedArguments);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QUuid _id;
|
|
||||||
EntityActionType _type;
|
|
||||||
QByteArray _data;
|
QByteArray _data;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -12,14 +12,14 @@
|
||||||
#include "AssignmentActionFactory.h"
|
#include "AssignmentActionFactory.h"
|
||||||
|
|
||||||
|
|
||||||
EntityActionPointer assignmentActionFactory(EntityActionType type, QUuid id, EntityItemPointer ownerEntity) {
|
EntityActionPointer assignmentActionFactory(EntityActionType type, const QUuid& id, EntityItemPointer ownerEntity) {
|
||||||
return (EntityActionPointer) new AssignmentAction(type, id, ownerEntity);
|
return (EntityActionPointer) new AssignmentAction(type, id, ownerEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
EntityActionPointer AssignmentActionFactory::factory(EntitySimulation* simulation,
|
EntityActionPointer AssignmentActionFactory::factory(EntitySimulation* simulation,
|
||||||
EntityActionType type,
|
EntityActionType type,
|
||||||
QUuid id,
|
const QUuid& id,
|
||||||
EntityItemPointer ownerEntity,
|
EntityItemPointer ownerEntity,
|
||||||
QVariantMap arguments) {
|
QVariantMap arguments) {
|
||||||
EntityActionPointer action = assignmentActionFactory(type, id, ownerEntity);
|
EntityActionPointer action = assignmentActionFactory(type, id, ownerEntity);
|
||||||
|
|
|
@ -21,7 +21,7 @@ public:
|
||||||
virtual ~AssignmentActionFactory() { }
|
virtual ~AssignmentActionFactory() { }
|
||||||
virtual EntityActionPointer factory(EntitySimulation* simulation,
|
virtual EntityActionPointer factory(EntitySimulation* simulation,
|
||||||
EntityActionType type,
|
EntityActionType type,
|
||||||
QUuid id,
|
const QUuid& id,
|
||||||
EntityItemPointer ownerEntity,
|
EntityItemPointer ownerEntity,
|
||||||
QVariantMap arguments);
|
QVariantMap arguments);
|
||||||
virtual EntityActionPointer factoryBA(EntitySimulation* simulation,
|
virtual EntityActionPointer factoryBA(EntitySimulation* simulation,
|
||||||
|
|
|
@ -1014,6 +1014,7 @@ void Application::paintGL() {
|
||||||
|
|
||||||
void Application::runTests() {
|
void Application::runTests() {
|
||||||
runTimingTests();
|
runTimingTests();
|
||||||
|
runUnitTests();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::audioMuteToggled() {
|
void Application::audioMuteToggled() {
|
||||||
|
|
|
@ -18,16 +18,16 @@
|
||||||
#include "InterfaceActionFactory.h"
|
#include "InterfaceActionFactory.h"
|
||||||
|
|
||||||
|
|
||||||
EntityActionPointer interfaceActionFactory(EntityActionType type, QUuid id, EntityItemPointer ownerEntity) {
|
EntityActionPointer interfaceActionFactory(EntityActionType type, const QUuid& id, EntityItemPointer ownerEntity) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ACTION_TYPE_NONE:
|
case ACTION_TYPE_NONE:
|
||||||
return nullptr;
|
return nullptr;
|
||||||
case ACTION_TYPE_OFFSET:
|
case ACTION_TYPE_OFFSET:
|
||||||
return (EntityActionPointer) new ObjectActionOffset(type, id, ownerEntity);
|
return (EntityActionPointer) new ObjectActionOffset(id, ownerEntity);
|
||||||
case ACTION_TYPE_SPRING:
|
case ACTION_TYPE_SPRING:
|
||||||
return (EntityActionPointer) new ObjectActionSpring(type, id, ownerEntity);
|
return (EntityActionPointer) new ObjectActionSpring(id, ownerEntity);
|
||||||
case ACTION_TYPE_HOLD:
|
case ACTION_TYPE_HOLD:
|
||||||
return (EntityActionPointer) new AvatarActionHold(type, id, ownerEntity);
|
return (EntityActionPointer) new AvatarActionHold(id, ownerEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(false);
|
assert(false);
|
||||||
|
@ -37,7 +37,7 @@ EntityActionPointer interfaceActionFactory(EntityActionType type, QUuid id, Enti
|
||||||
|
|
||||||
EntityActionPointer InterfaceActionFactory::factory(EntitySimulation* simulation,
|
EntityActionPointer InterfaceActionFactory::factory(EntitySimulation* simulation,
|
||||||
EntityActionType type,
|
EntityActionType type,
|
||||||
QUuid id,
|
const QUuid& id,
|
||||||
EntityItemPointer ownerEntity,
|
EntityItemPointer ownerEntity,
|
||||||
QVariantMap arguments) {
|
QVariantMap arguments) {
|
||||||
EntityActionPointer action = interfaceActionFactory(type, id, ownerEntity);
|
EntityActionPointer action = interfaceActionFactory(type, id, ownerEntity);
|
||||||
|
|
|
@ -20,7 +20,7 @@ public:
|
||||||
virtual ~InterfaceActionFactory() { }
|
virtual ~InterfaceActionFactory() { }
|
||||||
virtual EntityActionPointer factory(EntitySimulation* simulation,
|
virtual EntityActionPointer factory(EntitySimulation* simulation,
|
||||||
EntityActionType type,
|
EntityActionType type,
|
||||||
QUuid id,
|
const QUuid& id,
|
||||||
EntityItemPointer ownerEntity,
|
EntityItemPointer ownerEntity,
|
||||||
QVariantMap arguments);
|
QVariantMap arguments);
|
||||||
virtual EntityActionPointer factoryBA(EntitySimulation* simulation,
|
virtual EntityActionPointer factoryBA(EntitySimulation* simulation,
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
|
||||||
|
#include <ByteCountCoding.h>
|
||||||
#include <SharedUtil.h>
|
#include <SharedUtil.h>
|
||||||
#include <TextRenderer.h>
|
#include <TextRenderer.h>
|
||||||
|
|
||||||
|
@ -229,6 +230,43 @@ void runTimingTests() {
|
||||||
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
||||||
qCDebug(interfaceapp, "vec3 assign and dot() usecs: %f, last result:%f",
|
qCDebug(interfaceapp, "vec3 assign and dot() usecs: %f, last result:%f",
|
||||||
(double)(elapsedUsecs / numTests), (double)result);
|
(double)(elapsedUsecs / numTests), (double)result);
|
||||||
|
|
||||||
|
|
||||||
|
quint64 BYTE_CODE_MAX_TEST_VALUE = 99999999;
|
||||||
|
quint64 BYTE_CODE_TESTS_SKIP = 999;
|
||||||
|
|
||||||
|
QByteArray extraJunk;
|
||||||
|
const int EXTRA_JUNK_SIZE = 200;
|
||||||
|
extraJunk.append((unsigned char)255);
|
||||||
|
for (int i = 0; i < EXTRA_JUNK_SIZE; i++) {
|
||||||
|
extraJunk.append(QString("junk"));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
startTime.start();
|
||||||
|
quint64 tests = 0;
|
||||||
|
quint64 failed = 0;
|
||||||
|
for (quint64 value = 0; value < BYTE_CODE_MAX_TEST_VALUE; value += BYTE_CODE_TESTS_SKIP) {
|
||||||
|
quint64 valueA = value; // usecTimestampNow();
|
||||||
|
ByteCountCoded<quint64> codedValueA = valueA;
|
||||||
|
QByteArray codedValueABuffer = codedValueA;
|
||||||
|
codedValueABuffer.append(extraJunk);
|
||||||
|
ByteCountCoded<quint64> decodedValueA;
|
||||||
|
decodedValueA.decode(codedValueABuffer);
|
||||||
|
quint64 valueADecoded = decodedValueA;
|
||||||
|
tests++;
|
||||||
|
if (valueA != valueADecoded) {
|
||||||
|
qDebug() << "FAILED! value:" << valueA << "decoded:" << valueADecoded;
|
||||||
|
failed++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
||||||
|
qCDebug(interfaceapp) << "ByteCountCoded<quint64> usecs: " << elapsedUsecs
|
||||||
|
<< "per test:" << (double) (elapsedUsecs / tests)
|
||||||
|
<< "tests:" << tests
|
||||||
|
<< "failed:" << failed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool rayIntersectsSphere(const glm::vec3& rayStarting, const glm::vec3& rayNormalizedDirection,
|
bool rayIntersectsSphere(const glm::vec3& rayStarting, const glm::vec3& rayNormalizedDirection,
|
||||||
|
@ -271,3 +309,39 @@ bool pointInSphere(glm::vec3& point, glm::vec3& sphereCenter, double sphereRadiu
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void runUnitTests() {
|
||||||
|
|
||||||
|
quint64 LAST_TEST = 10;
|
||||||
|
quint64 SKIP_BY = 1;
|
||||||
|
|
||||||
|
for (quint64 value = 0; value <= LAST_TEST; value += SKIP_BY) {
|
||||||
|
qDebug() << "value:" << value;
|
||||||
|
|
||||||
|
ByteCountCoded<quint64> codedValue = value;
|
||||||
|
|
||||||
|
QByteArray codedValueBuffer = codedValue;
|
||||||
|
|
||||||
|
codedValueBuffer.append((unsigned char)255);
|
||||||
|
codedValueBuffer.append(QString("junk"));
|
||||||
|
|
||||||
|
qDebug() << "codedValueBuffer:";
|
||||||
|
outputBufferBits((const unsigned char*)codedValueBuffer.constData(), codedValueBuffer.size());
|
||||||
|
|
||||||
|
ByteCountCoded<quint64> valueDecoder;
|
||||||
|
size_t bytesConsumed = valueDecoder.decode(codedValueBuffer);
|
||||||
|
quint64 valueDecoded = valueDecoder;
|
||||||
|
qDebug() << "valueDecoded:" << valueDecoded;
|
||||||
|
qDebug() << "bytesConsumed:" << bytesConsumed;
|
||||||
|
|
||||||
|
|
||||||
|
if (value == valueDecoded) {
|
||||||
|
qDebug() << "SUCCESS!";
|
||||||
|
} else {
|
||||||
|
qDebug() << "FAILED!";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ void drawText(int x, int y, float scale, float radians, int mono,
|
||||||
void renderCollisionOverlay(int width, int height, float magnitude, float red = 0, float blue = 0, float green = 0);
|
void renderCollisionOverlay(int width, int height, float magnitude, float red = 0, float blue = 0, float green = 0);
|
||||||
|
|
||||||
void runTimingTests();
|
void runTimingTests();
|
||||||
|
void runUnitTests();
|
||||||
|
|
||||||
bool rayIntersectsSphere(const glm::vec3& rayStarting, const glm::vec3& rayNormalizedDirection,
|
bool rayIntersectsSphere(const glm::vec3& rayStarting, const glm::vec3& rayNormalizedDirection,
|
||||||
const glm::vec3& sphereCenter, float sphereRadius, float& distance);
|
const glm::vec3& sphereCenter, float sphereRadius, float& distance);
|
||||||
|
|
|
@ -17,13 +17,14 @@
|
||||||
|
|
||||||
const uint16_t AvatarActionHold::holdVersion = 1;
|
const uint16_t AvatarActionHold::holdVersion = 1;
|
||||||
|
|
||||||
AvatarActionHold::AvatarActionHold(EntityActionType type, QUuid id, EntityItemPointer ownerEntity) :
|
AvatarActionHold::AvatarActionHold(const QUuid& id, EntityItemPointer ownerEntity) :
|
||||||
ObjectActionSpring(type, id, ownerEntity),
|
ObjectActionSpring(id, ownerEntity),
|
||||||
_relativePosition(glm::vec3(0.0f)),
|
_relativePosition(glm::vec3(0.0f)),
|
||||||
_relativeRotation(glm::quat()),
|
_relativeRotation(glm::quat()),
|
||||||
_hand("right"),
|
_hand("right"),
|
||||||
_mine(false)
|
_mine(false)
|
||||||
{
|
{
|
||||||
|
_type = ACTION_TYPE_HOLD;
|
||||||
#if WANT_DEBUG
|
#if WANT_DEBUG
|
||||||
qDebug() << "AvatarActionHold::AvatarActionHold";
|
qDebug() << "AvatarActionHold::AvatarActionHold";
|
||||||
#endif
|
#endif
|
||||||
|
@ -166,8 +167,7 @@ QVariantMap AvatarActionHold::getArguments() {
|
||||||
|
|
||||||
|
|
||||||
void AvatarActionHold::deserialize(QByteArray serializedArguments) {
|
void AvatarActionHold::deserialize(QByteArray serializedArguments) {
|
||||||
if (_mine) {
|
if (!_mine) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
ObjectActionSpring::deserialize(serializedArguments);
|
ObjectActionSpring::deserialize(serializedArguments);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,9 @@
|
||||||
|
|
||||||
class AvatarActionHold : public ObjectActionSpring {
|
class AvatarActionHold : public ObjectActionSpring {
|
||||||
public:
|
public:
|
||||||
AvatarActionHold(EntityActionType type, QUuid id, EntityItemPointer ownerEntity);
|
AvatarActionHold(const QUuid& id, EntityItemPointer ownerEntity);
|
||||||
virtual ~AvatarActionHold();
|
virtual ~AvatarActionHold();
|
||||||
|
|
||||||
virtual EntityActionType getType() { return ACTION_TYPE_HOLD; }
|
|
||||||
|
|
||||||
virtual bool updateArguments(QVariantMap arguments);
|
virtual bool updateArguments(QVariantMap arguments);
|
||||||
virtual QVariantMap getArguments();
|
virtual QVariantMap getArguments();
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ class EntityActionFactoryInterface : public QObject, public Dependency {
|
||||||
virtual ~EntityActionFactoryInterface() { }
|
virtual ~EntityActionFactoryInterface() { }
|
||||||
virtual EntityActionPointer factory(EntitySimulation* simulation,
|
virtual EntityActionPointer factory(EntitySimulation* simulation,
|
||||||
EntityActionType type,
|
EntityActionType type,
|
||||||
QUuid id,
|
const QUuid& id,
|
||||||
EntityItemPointer ownerEntity,
|
EntityItemPointer ownerEntity,
|
||||||
QVariantMap arguments) { assert(false); return nullptr; }
|
QVariantMap arguments) { assert(false); return nullptr; }
|
||||||
virtual EntityActionPointer factoryBA(EntitySimulation* simulation,
|
virtual EntityActionPointer factoryBA(EntitySimulation* simulation,
|
||||||
|
|
|
@ -29,10 +29,10 @@ enum EntityActionType {
|
||||||
|
|
||||||
class EntityActionInterface {
|
class EntityActionInterface {
|
||||||
public:
|
public:
|
||||||
EntityActionInterface() { }
|
EntityActionInterface(EntityActionType type, const QUuid& id) : _id(id), _type(type) { }
|
||||||
virtual ~EntityActionInterface() { }
|
virtual ~EntityActionInterface() { }
|
||||||
virtual const QUuid& getID() const = 0;
|
const QUuid& getID() const { return _id; }
|
||||||
virtual EntityActionType getType() { assert(false); return ACTION_TYPE_NONE; }
|
EntityActionType getType() const { return _type; }
|
||||||
|
|
||||||
virtual void removeFromSimulation(EntitySimulation* simulation) const = 0;
|
virtual void removeFromSimulation(EntitySimulation* simulation) const = 0;
|
||||||
virtual EntityItemWeakPointer getOwnerEntity() const = 0;
|
virtual EntityItemWeakPointer getOwnerEntity() const = 0;
|
||||||
|
@ -40,7 +40,7 @@ public:
|
||||||
virtual bool updateArguments(QVariantMap arguments) = 0;
|
virtual bool updateArguments(QVariantMap arguments) = 0;
|
||||||
virtual QVariantMap getArguments() = 0;
|
virtual QVariantMap getArguments() = 0;
|
||||||
|
|
||||||
virtual QByteArray serialize() = 0;
|
virtual QByteArray serialize() const = 0;
|
||||||
virtual void deserialize(QByteArray serializedArguments) = 0;
|
virtual void deserialize(QByteArray serializedArguments) = 0;
|
||||||
|
|
||||||
static EntityActionType actionTypeFromString(QString actionTypeString);
|
static EntityActionType actionTypeFromString(QString actionTypeString);
|
||||||
|
@ -68,6 +68,8 @@ protected:
|
||||||
static QString extractStringArgument(QString objectName, QVariantMap arguments,
|
static QString extractStringArgument(QString objectName, QVariantMap arguments,
|
||||||
QString argumentName, bool& ok, bool required = true);
|
QString argumentName, bool& ok, bool required = true);
|
||||||
|
|
||||||
|
QUuid _id;
|
||||||
|
EntityActionType _type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,9 +13,9 @@
|
||||||
|
|
||||||
#include "ObjectAction.h"
|
#include "ObjectAction.h"
|
||||||
|
|
||||||
ObjectAction::ObjectAction(EntityActionType type, QUuid id, EntityItemPointer ownerEntity) :
|
ObjectAction::ObjectAction(EntityActionType type, const QUuid& id, EntityItemPointer ownerEntity) :
|
||||||
btActionInterface(),
|
btActionInterface(),
|
||||||
_id(id),
|
EntityActionInterface(type, id),
|
||||||
_active(false),
|
_active(false),
|
||||||
_ownerEntity(ownerEntity) {
|
_ownerEntity(ownerEntity) {
|
||||||
}
|
}
|
||||||
|
@ -24,15 +24,15 @@ ObjectAction::~ObjectAction() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectAction::updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep) {
|
void ObjectAction::updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep) {
|
||||||
if (!_active) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (_ownerEntity.expired()) {
|
if (_ownerEntity.expired()) {
|
||||||
qDebug() << "warning -- action with no entity removing self from btCollisionWorld.";
|
qDebug() << "warning -- action with no entity removing self from btCollisionWorld.";
|
||||||
btDynamicsWorld* dynamicsWorld = static_cast<btDynamicsWorld*>(collisionWorld);
|
btDynamicsWorld* dynamicsWorld = static_cast<btDynamicsWorld*>(collisionWorld);
|
||||||
dynamicsWorld->removeAction(this);
|
dynamicsWorld->removeAction(this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!_active) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
updateActionWorker(deltaTimeStep);
|
updateActionWorker(deltaTimeStep);
|
||||||
}
|
}
|
||||||
|
@ -129,11 +129,3 @@ void ObjectAction::setAngularVelocity(glm::vec3 angularVelocity) {
|
||||||
rigidBody->activate();
|
rigidBody->activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray ObjectAction::serialize() {
|
|
||||||
assert(false);
|
|
||||||
return QByteArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ObjectAction::deserialize(QByteArray serializedArguments) {
|
|
||||||
assert(false);
|
|
||||||
}
|
|
||||||
|
|
|
@ -17,8 +17,6 @@
|
||||||
|
|
||||||
#include <btBulletDynamicsCommon.h>
|
#include <btBulletDynamicsCommon.h>
|
||||||
|
|
||||||
#include <EntityItem.h>
|
|
||||||
|
|
||||||
#include "ObjectMotionState.h"
|
#include "ObjectMotionState.h"
|
||||||
#include "BulletUtil.h"
|
#include "BulletUtil.h"
|
||||||
#include "EntityActionInterface.h"
|
#include "EntityActionInterface.h"
|
||||||
|
@ -26,31 +24,25 @@
|
||||||
|
|
||||||
class ObjectAction : public btActionInterface, public EntityActionInterface {
|
class ObjectAction : public btActionInterface, public EntityActionInterface {
|
||||||
public:
|
public:
|
||||||
ObjectAction(EntityActionType type, QUuid id, EntityItemPointer ownerEntity);
|
ObjectAction(EntityActionType type, const QUuid& id, EntityItemPointer ownerEntity);
|
||||||
virtual ~ObjectAction();
|
virtual ~ObjectAction();
|
||||||
|
|
||||||
const QUuid& getID() const { return _id; }
|
|
||||||
virtual EntityActionType getType() { assert(false); return ACTION_TYPE_NONE; }
|
|
||||||
virtual void removeFromSimulation(EntitySimulation* simulation) const;
|
virtual void removeFromSimulation(EntitySimulation* simulation) const;
|
||||||
virtual EntityItemWeakPointer getOwnerEntity() const { return _ownerEntity; }
|
virtual EntityItemWeakPointer getOwnerEntity() const { return _ownerEntity; }
|
||||||
virtual void setOwnerEntity(const EntityItemPointer ownerEntity) { _ownerEntity = ownerEntity; }
|
virtual void setOwnerEntity(const EntityItemPointer ownerEntity) { _ownerEntity = ownerEntity; }
|
||||||
|
|
||||||
virtual bool updateArguments(QVariantMap arguments) { return false; }
|
virtual bool updateArguments(QVariantMap arguments) = 0;
|
||||||
virtual QVariantMap getArguments() { return QVariantMap(); }
|
virtual QVariantMap getArguments() = 0;
|
||||||
|
|
||||||
// this is called from updateAction and should be overridden by subclasses
|
// this is called from updateAction and should be overridden by subclasses
|
||||||
virtual void updateActionWorker(float deltaTimeStep) {}
|
virtual void updateActionWorker(float deltaTimeStep) = 0;
|
||||||
|
|
||||||
// these are from btActionInterface
|
// these are from btActionInterface
|
||||||
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 QByteArray serialize() const = 0;
|
||||||
virtual void deserialize(QByteArray serializedArguments);
|
virtual void deserialize(QByteArray serializedArguments) = 0;
|
||||||
|
|
||||||
private:
|
|
||||||
QUuid _id;
|
|
||||||
QReadWriteLock _lock;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -70,6 +62,10 @@ protected:
|
||||||
bool tryLockForWrite() { return _lock.tryLockForWrite(); }
|
bool tryLockForWrite() { return _lock.tryLockForWrite(); }
|
||||||
void unlock() { _lock.unlock(); }
|
void unlock() { _lock.unlock(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
QReadWriteLock _lock;
|
||||||
|
|
||||||
|
protected:
|
||||||
bool _active;
|
bool _active;
|
||||||
EntityItemWeakPointer _ownerEntity;
|
EntityItemWeakPointer _ownerEntity;
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
|
|
||||||
const uint16_t ObjectActionOffset::offsetVersion = 1;
|
const uint16_t ObjectActionOffset::offsetVersion = 1;
|
||||||
|
|
||||||
ObjectActionOffset::ObjectActionOffset(EntityActionType type, QUuid id, EntityItemPointer ownerEntity) :
|
ObjectActionOffset::ObjectActionOffset(const QUuid& id, EntityItemPointer ownerEntity) :
|
||||||
ObjectAction(type, id, ownerEntity) {
|
ObjectAction(ACTION_TYPE_OFFSET, id, ownerEntity) {
|
||||||
#if WANT_DEBUG
|
#if WANT_DEBUG
|
||||||
qDebug() << "ObjectActionOffset::ObjectActionOffset";
|
qDebug() << "ObjectActionOffset::ObjectActionOffset";
|
||||||
#endif
|
#endif
|
||||||
|
@ -127,7 +127,7 @@ QVariantMap ObjectActionOffset::getArguments() {
|
||||||
return arguments;
|
return arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray ObjectActionOffset::serialize() {
|
QByteArray ObjectActionOffset::serialize() const {
|
||||||
QByteArray ba;
|
QByteArray ba;
|
||||||
QDataStream dataStream(&ba, QIODevice::WriteOnly);
|
QDataStream dataStream(&ba, QIODevice::WriteOnly);
|
||||||
dataStream << getType();
|
dataStream << getType();
|
||||||
|
@ -146,13 +146,14 @@ void ObjectActionOffset::deserialize(QByteArray serializedArguments) {
|
||||||
QDataStream dataStream(serializedArguments);
|
QDataStream dataStream(serializedArguments);
|
||||||
|
|
||||||
EntityActionType type;
|
EntityActionType type;
|
||||||
QUuid id;
|
|
||||||
uint16_t serializationVersion;
|
|
||||||
|
|
||||||
dataStream >> type;
|
dataStream >> type;
|
||||||
assert(type == getType());
|
assert(type == getType());
|
||||||
|
|
||||||
|
QUuid id;
|
||||||
dataStream >> id;
|
dataStream >> id;
|
||||||
assert(id == getID());
|
assert(id == getID());
|
||||||
|
|
||||||
|
uint16_t serializationVersion;
|
||||||
dataStream >> serializationVersion;
|
dataStream >> serializationVersion;
|
||||||
if (serializationVersion != ObjectActionOffset::offsetVersion) {
|
if (serializationVersion != ObjectActionOffset::offsetVersion) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -19,17 +19,15 @@
|
||||||
|
|
||||||
class ObjectActionOffset : public ObjectAction {
|
class ObjectActionOffset : public ObjectAction {
|
||||||
public:
|
public:
|
||||||
ObjectActionOffset(EntityActionType type, QUuid id, EntityItemPointer ownerEntity);
|
ObjectActionOffset(const QUuid& id, EntityItemPointer ownerEntity);
|
||||||
virtual ~ObjectActionOffset();
|
virtual ~ObjectActionOffset();
|
||||||
|
|
||||||
virtual EntityActionType getType() { return ACTION_TYPE_OFFSET; }
|
|
||||||
|
|
||||||
virtual bool updateArguments(QVariantMap arguments);
|
virtual bool updateArguments(QVariantMap arguments);
|
||||||
virtual QVariantMap getArguments();
|
virtual QVariantMap getArguments();
|
||||||
|
|
||||||
virtual void updateActionWorker(float deltaTimeStep);
|
virtual void updateActionWorker(float deltaTimeStep);
|
||||||
|
|
||||||
virtual QByteArray serialize();
|
virtual QByteArray serialize() const;
|
||||||
virtual void deserialize(QByteArray serializedArguments);
|
virtual void deserialize(QByteArray serializedArguments);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -17,8 +17,8 @@ const float SPRING_MAX_SPEED = 10.0f;
|
||||||
|
|
||||||
const uint16_t ObjectActionSpring::springVersion = 1;
|
const uint16_t ObjectActionSpring::springVersion = 1;
|
||||||
|
|
||||||
ObjectActionSpring::ObjectActionSpring(EntityActionType type, QUuid id, EntityItemPointer ownerEntity) :
|
ObjectActionSpring::ObjectActionSpring(const QUuid& id, EntityItemPointer ownerEntity) :
|
||||||
ObjectAction(type, id, ownerEntity),
|
ObjectAction(ACTION_TYPE_SPRING, id, ownerEntity),
|
||||||
_positionalTarget(glm::vec3(0.0f)),
|
_positionalTarget(glm::vec3(0.0f)),
|
||||||
_linearTimeScale(0.2f),
|
_linearTimeScale(0.2f),
|
||||||
_positionalTargetSet(false),
|
_positionalTargetSet(false),
|
||||||
|
@ -206,7 +206,7 @@ QVariantMap ObjectActionSpring::getArguments() {
|
||||||
return arguments;
|
return arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray ObjectActionSpring::serialize() {
|
QByteArray ObjectActionSpring::serialize() const {
|
||||||
QByteArray serializedActionArguments;
|
QByteArray serializedActionArguments;
|
||||||
QDataStream dataStream(&serializedActionArguments, QIODevice::WriteOnly);
|
QDataStream dataStream(&serializedActionArguments, QIODevice::WriteOnly);
|
||||||
|
|
||||||
|
@ -229,13 +229,14 @@ void ObjectActionSpring::deserialize(QByteArray serializedArguments) {
|
||||||
QDataStream dataStream(serializedArguments);
|
QDataStream dataStream(serializedArguments);
|
||||||
|
|
||||||
EntityActionType type;
|
EntityActionType type;
|
||||||
QUuid id;
|
|
||||||
uint16_t serializationVersion;
|
|
||||||
|
|
||||||
dataStream >> type;
|
dataStream >> type;
|
||||||
assert(type == getType());
|
assert(type == getType());
|
||||||
|
|
||||||
|
QUuid id;
|
||||||
dataStream >> id;
|
dataStream >> id;
|
||||||
assert(id == getID());
|
assert(id == getID());
|
||||||
|
|
||||||
|
uint16_t serializationVersion;
|
||||||
dataStream >> serializationVersion;
|
dataStream >> serializationVersion;
|
||||||
if (serializationVersion != ObjectActionSpring::springVersion) {
|
if (serializationVersion != ObjectActionSpring::springVersion) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -12,24 +12,19 @@
|
||||||
#ifndef hifi_ObjectActionSpring_h
|
#ifndef hifi_ObjectActionSpring_h
|
||||||
#define hifi_ObjectActionSpring_h
|
#define hifi_ObjectActionSpring_h
|
||||||
|
|
||||||
#include <QUuid>
|
|
||||||
|
|
||||||
#include <EntityItem.h>
|
|
||||||
#include "ObjectAction.h"
|
#include "ObjectAction.h"
|
||||||
|
|
||||||
class ObjectActionSpring : public ObjectAction {
|
class ObjectActionSpring : public ObjectAction {
|
||||||
public:
|
public:
|
||||||
ObjectActionSpring(EntityActionType type, QUuid id, EntityItemPointer ownerEntity);
|
ObjectActionSpring(const QUuid& id, EntityItemPointer ownerEntity);
|
||||||
virtual ~ObjectActionSpring();
|
virtual ~ObjectActionSpring();
|
||||||
|
|
||||||
virtual EntityActionType getType() { return ACTION_TYPE_SPRING; }
|
|
||||||
|
|
||||||
virtual bool updateArguments(QVariantMap arguments);
|
virtual bool updateArguments(QVariantMap arguments);
|
||||||
virtual QVariantMap getArguments();
|
virtual QVariantMap getArguments();
|
||||||
|
|
||||||
virtual void updateActionWorker(float deltaTimeStep);
|
virtual void updateActionWorker(float deltaTimeStep);
|
||||||
|
|
||||||
virtual QByteArray serialize();
|
virtual QByteArray serialize() const;
|
||||||
virtual void deserialize(QByteArray serializedArguments);
|
virtual void deserialize(QByteArray serializedArguments);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -21,9 +21,13 @@
|
||||||
#include <climits>
|
#include <climits>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
#include <QBitArray>
|
#include <QBitArray>
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
|
|
||||||
|
#include "SharedUtil.h"
|
||||||
|
|
||||||
#include "NumericalConstants.h"
|
#include "NumericalConstants.h"
|
||||||
|
|
||||||
template<typename T> class ByteCountCoded {
|
template<typename T> class ByteCountCoded {
|
||||||
|
@ -37,7 +41,8 @@ public:
|
||||||
ByteCountCoded(const QByteArray& fromEncoded) : data(0) { decode(fromEncoded); }
|
ByteCountCoded(const QByteArray& fromEncoded) : data(0) { decode(fromEncoded); }
|
||||||
|
|
||||||
QByteArray encode() const;
|
QByteArray encode() const;
|
||||||
void decode(const QByteArray& fromEncoded);
|
size_t decode(const QByteArray& fromEncoded);
|
||||||
|
size_t decode(const char* encodedBuffer, int encodedSize);
|
||||||
|
|
||||||
bool operator==(const ByteCountCoded& other) const { return data == other.data; }
|
bool operator==(const ByteCountCoded& other) const { return data == other.data; }
|
||||||
bool operator!=(const ByteCountCoded& other) const { return data != other.data; }
|
bool operator!=(const ByteCountCoded& other) const { return data != other.data; }
|
||||||
|
@ -110,52 +115,63 @@ template<typename T> inline QByteArray ByteCountCoded<T>::encode() const {
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T> inline void ByteCountCoded<T>::decode(const QByteArray& fromEncodedBytes) {
|
template<typename T> inline size_t ByteCountCoded<T>::decode(const QByteArray& fromEncodedBytes) {
|
||||||
|
return decode(fromEncodedBytes.constData(), fromEncodedBytes.size());
|
||||||
|
}
|
||||||
|
|
||||||
// first convert the ByteArray into a BitArray...
|
template<typename T> inline size_t ByteCountCoded<T>::decode(const char* encodedBuffer, int encodedSize) {
|
||||||
QBitArray encodedBits;
|
data = 0; // reset data
|
||||||
int bitCount = BITS_IN_BYTE * fromEncodedBytes.count();
|
size_t bytesConsumed = 0;
|
||||||
encodedBits.resize(bitCount);
|
int bitCount = BITS_IN_BYTE * encodedSize;
|
||||||
|
|
||||||
for(int byte = 0; byte < fromEncodedBytes.count(); byte++) {
|
int encodedByteCount = 1; // there is at least 1 byte (after the leadBits)
|
||||||
char originalByte = fromEncodedBytes.at(byte);
|
int leadBits = 1; // there is always at least 1 lead bit
|
||||||
|
bool inLeadBits = true;
|
||||||
|
int bitAt = 0;
|
||||||
|
int expectedBitCount; // unknown at this point
|
||||||
|
int lastValueBit;
|
||||||
|
T bitValue = 1;
|
||||||
|
|
||||||
|
for(int byte = 0; byte < encodedSize; byte++) {
|
||||||
|
char originalByte = encodedBuffer[byte];
|
||||||
|
bytesConsumed++;
|
||||||
|
unsigned char maskBit = 128; // LEFT MOST BIT set
|
||||||
for(int bit = 0; bit < BITS_IN_BYTE; bit++) {
|
for(int bit = 0; bit < BITS_IN_BYTE; bit++) {
|
||||||
int shiftBy = BITS_IN_BYTE - (bit + 1);
|
bool bitIsSet = originalByte & maskBit;
|
||||||
char maskBit = ( 1 << shiftBy);
|
|
||||||
bool bitValue = originalByte & maskBit;
|
|
||||||
encodedBits.setBit(byte * BITS_IN_BYTE + bit, bitValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// next, read the leading bits to determine the correct number of bytes to decode (may not match the QByteArray)
|
// Processing of the lead bits
|
||||||
int encodedByteCount = 0;
|
if (inLeadBits) {
|
||||||
int leadBits = 1;
|
if (bitIsSet) {
|
||||||
int bitAt;
|
|
||||||
for (bitAt = 0; bitAt < bitCount; bitAt++) {
|
|
||||||
if (encodedBits.at(bitAt)) {
|
|
||||||
encodedByteCount++;
|
encodedByteCount++;
|
||||||
leadBits++;
|
leadBits++;
|
||||||
} else {
|
} else {
|
||||||
|
inLeadBits = false; // once we hit our first 0, we know we're out of the lead bits
|
||||||
|
expectedBitCount = (encodedByteCount * BITS_IN_BYTE) - leadBits;
|
||||||
|
lastValueBit = expectedBitCount + bitAt;
|
||||||
|
|
||||||
|
// check to see if the remainder of our buffer is sufficient
|
||||||
|
if (expectedBitCount > (bitCount - leadBits)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
encodedByteCount++; // always at least one byte
|
} else {
|
||||||
int expectedBitCount = encodedByteCount * BITS_IN_BYTE;
|
if (bitAt > lastValueBit) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
T value = 0;
|
if(bitIsSet) {
|
||||||
|
data += bitValue;
|
||||||
if (expectedBitCount <= (encodedBits.size() - leadBits)) {
|
|
||||||
// Now, keep reading...
|
|
||||||
int valueStartsAt = bitAt + 1;
|
|
||||||
T bitValue = 1;
|
|
||||||
for (bitAt = valueStartsAt; bitAt < expectedBitCount; bitAt++) {
|
|
||||||
if(encodedBits.at(bitAt)) {
|
|
||||||
value += bitValue;
|
|
||||||
}
|
}
|
||||||
bitValue *= 2;
|
bitValue *= 2;
|
||||||
}
|
}
|
||||||
|
bitAt++;
|
||||||
|
maskBit = maskBit >> 1;
|
||||||
}
|
}
|
||||||
data = value;
|
if (!inLeadBits && bitAt > lastValueBit) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bytesConsumed;
|
||||||
}
|
}
|
||||||
#endif // hifi_ByteCountCoding_h
|
#endif // hifi_ByteCountCoding_h
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ QVariantList glmToQList(const glm::quat& g) {
|
||||||
return QVariantList() << g.x << g.y << g.z << g.w;
|
return QVariantList() << g.x << g.y << g.z << g.w;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantList rgbColorToQList(rgbColor& v) {
|
QVariantList rgbColorToQList(const rgbColor& v) {
|
||||||
return QVariantList() << (int)(v[0]) << (int)(v[1]) << (int)(v[2]);
|
return QVariantList() << (int)(v[0]) << (int)(v[1]) << (int)(v[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,12 +42,12 @@ QVariantMap glmToQMap(const glm::quat& glmQuat) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
glm::vec3 qListToGlmVec3(const QVariant q) {
|
glm::vec3 qListToGlmVec3(const QVariant& q) {
|
||||||
QVariantList qList = q.toList();
|
QVariantList qList = q.toList();
|
||||||
return glm::vec3(qList[RED_INDEX].toFloat(), qList[GREEN_INDEX].toFloat(), qList[BLUE_INDEX].toFloat());
|
return glm::vec3(qList[RED_INDEX].toFloat(), qList[GREEN_INDEX].toFloat(), qList[BLUE_INDEX].toFloat());
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::quat qListToGlmQuat(const QVariant q) {
|
glm::quat qListToGlmQuat(const QVariant& q) {
|
||||||
QVariantList qList = q.toList();
|
QVariantList qList = q.toList();
|
||||||
float x = qList[0].toFloat();
|
float x = qList[0].toFloat();
|
||||||
float y = qList[1].toFloat();
|
float y = qList[1].toFloat();
|
||||||
|
@ -56,7 +56,7 @@ glm::quat qListToGlmQuat(const QVariant q) {
|
||||||
return glm::quat(w, x, y, z);
|
return glm::quat(w, x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
void qListtoRgbColor(const QVariant q, rgbColor returnValue) {
|
void qListtoRgbColor(const QVariant& q, rgbColor& returnValue) {
|
||||||
QVariantList qList = q.toList();
|
QVariantList qList = q.toList();
|
||||||
returnValue[RED_INDEX] = qList[RED_INDEX].toInt();
|
returnValue[RED_INDEX] = qList[RED_INDEX].toInt();
|
||||||
returnValue[GREEN_INDEX] = qList[GREEN_INDEX].toInt();
|
returnValue[GREEN_INDEX] = qList[GREEN_INDEX].toInt();
|
||||||
|
|
|
@ -19,11 +19,11 @@
|
||||||
|
|
||||||
QVariantList glmToQList(const glm::vec3& g);
|
QVariantList glmToQList(const glm::vec3& g);
|
||||||
QVariantList glmToQList(const glm::quat& g);
|
QVariantList glmToQList(const glm::quat& g);
|
||||||
QVariantList rgbColorToQList(rgbColor& v);
|
QVariantList rgbColorToQList(const rgbColor& v);
|
||||||
|
|
||||||
QVariantMap glmToQMap(const glm::vec3& glmVector);
|
QVariantMap glmToQMap(const glm::vec3& glmVector);
|
||||||
QVariantMap glmToQMap(const glm::quat& glmQuat);
|
QVariantMap glmToQMap(const glm::quat& glmQuat);
|
||||||
|
|
||||||
glm::vec3 qListToGlmVec3(const QVariant q);
|
glm::vec3 qListToGlmVec3(const QVariant& q);
|
||||||
glm::quat qListToGlmQuat(const QVariant q);
|
glm::quat qListToGlmQuat(const QVariant& q);
|
||||||
void qListtoRgbColor(const QVariant q, rgbColor returnValue);
|
void qListtoRgbColor(const QVariant& q, rgbColor& returnValue);
|
||||||
|
|
Loading…
Reference in a new issue