mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:24:00 +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"
|
||||
|
||||
AssignmentAction::AssignmentAction(EntityActionType type, QUuid id, EntityItemPointer ownerEntity) :
|
||||
_id(id),
|
||||
_type(type),
|
||||
AssignmentAction::AssignmentAction(EntityActionType type, const QUuid& id, EntityItemPointer ownerEntity) :
|
||||
EntityActionInterface(type, id),
|
||||
_data(QByteArray()),
|
||||
_active(false),
|
||||
_ownerEntity(ownerEntity) {
|
||||
|
@ -28,7 +27,7 @@ void AssignmentAction::removeFromSimulation(EntitySimulation* simulation) const
|
|||
simulation->removeAction(_id);
|
||||
}
|
||||
|
||||
QByteArray AssignmentAction::serialize() {
|
||||
QByteArray AssignmentAction::serialize() const {
|
||||
return _data;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,23 +21,19 @@
|
|||
|
||||
class AssignmentAction : public EntityActionInterface {
|
||||
public:
|
||||
AssignmentAction(EntityActionType type, QUuid id, EntityItemPointer ownerEntity);
|
||||
AssignmentAction(EntityActionType type, const QUuid& id, EntityItemPointer ownerEntity);
|
||||
virtual ~AssignmentAction();
|
||||
|
||||
const QUuid& getID() const { return _id; }
|
||||
virtual EntityActionType getType() { return _type; }
|
||||
virtual void removeFromSimulation(EntitySimulation* simulation) const;
|
||||
virtual EntityItemWeakPointer getOwnerEntity() const { return _ownerEntity; }
|
||||
virtual void setOwnerEntity(const EntityItemPointer ownerEntity) { _ownerEntity = ownerEntity; }
|
||||
virtual bool updateArguments(QVariantMap arguments);
|
||||
virtual QVariantMap getArguments();
|
||||
|
||||
virtual QByteArray serialize();
|
||||
virtual QByteArray serialize() const;
|
||||
virtual void deserialize(QByteArray serializedArguments);
|
||||
|
||||
private:
|
||||
QUuid _id;
|
||||
EntityActionType _type;
|
||||
QByteArray _data;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -12,14 +12,14 @@
|
|||
#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);
|
||||
}
|
||||
|
||||
|
||||
EntityActionPointer AssignmentActionFactory::factory(EntitySimulation* simulation,
|
||||
EntityActionType type,
|
||||
QUuid id,
|
||||
const QUuid& id,
|
||||
EntityItemPointer ownerEntity,
|
||||
QVariantMap arguments) {
|
||||
EntityActionPointer action = assignmentActionFactory(type, id, ownerEntity);
|
||||
|
|
|
@ -21,7 +21,7 @@ public:
|
|||
virtual ~AssignmentActionFactory() { }
|
||||
virtual EntityActionPointer factory(EntitySimulation* simulation,
|
||||
EntityActionType type,
|
||||
QUuid id,
|
||||
const QUuid& id,
|
||||
EntityItemPointer ownerEntity,
|
||||
QVariantMap arguments);
|
||||
virtual EntityActionPointer factoryBA(EntitySimulation* simulation,
|
||||
|
|
|
@ -1014,6 +1014,7 @@ void Application::paintGL() {
|
|||
|
||||
void Application::runTests() {
|
||||
runTimingTests();
|
||||
runUnitTests();
|
||||
}
|
||||
|
||||
void Application::audioMuteToggled() {
|
||||
|
|
|
@ -18,16 +18,16 @@
|
|||
#include "InterfaceActionFactory.h"
|
||||
|
||||
|
||||
EntityActionPointer interfaceActionFactory(EntityActionType type, QUuid id, EntityItemPointer ownerEntity) {
|
||||
EntityActionPointer interfaceActionFactory(EntityActionType type, const QUuid& id, EntityItemPointer ownerEntity) {
|
||||
switch (type) {
|
||||
case ACTION_TYPE_NONE:
|
||||
return nullptr;
|
||||
case ACTION_TYPE_OFFSET:
|
||||
return (EntityActionPointer) new ObjectActionOffset(type, id, ownerEntity);
|
||||
return (EntityActionPointer) new ObjectActionOffset(id, ownerEntity);
|
||||
case ACTION_TYPE_SPRING:
|
||||
return (EntityActionPointer) new ObjectActionSpring(type, id, ownerEntity);
|
||||
return (EntityActionPointer) new ObjectActionSpring(id, ownerEntity);
|
||||
case ACTION_TYPE_HOLD:
|
||||
return (EntityActionPointer) new AvatarActionHold(type, id, ownerEntity);
|
||||
return (EntityActionPointer) new AvatarActionHold(id, ownerEntity);
|
||||
}
|
||||
|
||||
assert(false);
|
||||
|
@ -37,7 +37,7 @@ EntityActionPointer interfaceActionFactory(EntityActionType type, QUuid id, Enti
|
|||
|
||||
EntityActionPointer InterfaceActionFactory::factory(EntitySimulation* simulation,
|
||||
EntityActionType type,
|
||||
QUuid id,
|
||||
const QUuid& id,
|
||||
EntityItemPointer ownerEntity,
|
||||
QVariantMap arguments) {
|
||||
EntityActionPointer action = interfaceActionFactory(type, id, ownerEntity);
|
||||
|
|
|
@ -20,7 +20,7 @@ public:
|
|||
virtual ~InterfaceActionFactory() { }
|
||||
virtual EntityActionPointer factory(EntitySimulation* simulation,
|
||||
EntityActionType type,
|
||||
QUuid id,
|
||||
const QUuid& id,
|
||||
EntityItemPointer ownerEntity,
|
||||
QVariantMap arguments);
|
||||
virtual EntityActionPointer factoryBA(EntitySimulation* simulation,
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include <QThread>
|
||||
|
||||
#include <ByteCountCoding.h>
|
||||
#include <SharedUtil.h>
|
||||
#include <TextRenderer.h>
|
||||
|
||||
|
@ -229,6 +230,43 @@ void runTimingTests() {
|
|||
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
||||
qCDebug(interfaceapp, "vec3 assign and dot() usecs: %f, last result:%f",
|
||||
(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,
|
||||
|
@ -271,3 +309,39 @@ bool pointInSphere(glm::vec3& point, glm::vec3& sphereCenter, double sphereRadiu
|
|||
}
|
||||
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 runTimingTests();
|
||||
void runUnitTests();
|
||||
|
||||
bool rayIntersectsSphere(const glm::vec3& rayStarting, const glm::vec3& rayNormalizedDirection,
|
||||
const glm::vec3& sphereCenter, float sphereRadius, float& distance);
|
||||
|
|
|
@ -17,13 +17,14 @@
|
|||
|
||||
const uint16_t AvatarActionHold::holdVersion = 1;
|
||||
|
||||
AvatarActionHold::AvatarActionHold(EntityActionType type, QUuid id, EntityItemPointer ownerEntity) :
|
||||
ObjectActionSpring(type, id, ownerEntity),
|
||||
AvatarActionHold::AvatarActionHold(const QUuid& id, EntityItemPointer ownerEntity) :
|
||||
ObjectActionSpring(id, ownerEntity),
|
||||
_relativePosition(glm::vec3(0.0f)),
|
||||
_relativeRotation(glm::quat()),
|
||||
_hand("right"),
|
||||
_mine(false)
|
||||
{
|
||||
_type = ACTION_TYPE_HOLD;
|
||||
#if WANT_DEBUG
|
||||
qDebug() << "AvatarActionHold::AvatarActionHold";
|
||||
#endif
|
||||
|
@ -166,8 +167,7 @@ QVariantMap AvatarActionHold::getArguments() {
|
|||
|
||||
|
||||
void AvatarActionHold::deserialize(QByteArray serializedArguments) {
|
||||
if (_mine) {
|
||||
return;
|
||||
if (!_mine) {
|
||||
ObjectActionSpring::deserialize(serializedArguments);
|
||||
}
|
||||
ObjectActionSpring::deserialize(serializedArguments);
|
||||
}
|
||||
|
|
|
@ -19,11 +19,9 @@
|
|||
|
||||
class AvatarActionHold : public ObjectActionSpring {
|
||||
public:
|
||||
AvatarActionHold(EntityActionType type, QUuid id, EntityItemPointer ownerEntity);
|
||||
AvatarActionHold(const QUuid& id, EntityItemPointer ownerEntity);
|
||||
virtual ~AvatarActionHold();
|
||||
|
||||
virtual EntityActionType getType() { return ACTION_TYPE_HOLD; }
|
||||
|
||||
virtual bool updateArguments(QVariantMap arguments);
|
||||
virtual QVariantMap getArguments();
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ class EntityActionFactoryInterface : public QObject, public Dependency {
|
|||
virtual ~EntityActionFactoryInterface() { }
|
||||
virtual EntityActionPointer factory(EntitySimulation* simulation,
|
||||
EntityActionType type,
|
||||
QUuid id,
|
||||
const QUuid& id,
|
||||
EntityItemPointer ownerEntity,
|
||||
QVariantMap arguments) { assert(false); return nullptr; }
|
||||
virtual EntityActionPointer factoryBA(EntitySimulation* simulation,
|
||||
|
|
|
@ -29,10 +29,10 @@ enum EntityActionType {
|
|||
|
||||
class EntityActionInterface {
|
||||
public:
|
||||
EntityActionInterface() { }
|
||||
EntityActionInterface(EntityActionType type, const QUuid& id) : _id(id), _type(type) { }
|
||||
virtual ~EntityActionInterface() { }
|
||||
virtual const QUuid& getID() const = 0;
|
||||
virtual EntityActionType getType() { assert(false); return ACTION_TYPE_NONE; }
|
||||
const QUuid& getID() const { return _id; }
|
||||
EntityActionType getType() const { return _type; }
|
||||
|
||||
virtual void removeFromSimulation(EntitySimulation* simulation) const = 0;
|
||||
virtual EntityItemWeakPointer getOwnerEntity() const = 0;
|
||||
|
@ -40,7 +40,7 @@ public:
|
|||
virtual bool updateArguments(QVariantMap arguments) = 0;
|
||||
virtual QVariantMap getArguments() = 0;
|
||||
|
||||
virtual QByteArray serialize() = 0;
|
||||
virtual QByteArray serialize() const = 0;
|
||||
virtual void deserialize(QByteArray serializedArguments) = 0;
|
||||
|
||||
static EntityActionType actionTypeFromString(QString actionTypeString);
|
||||
|
@ -68,6 +68,8 @@ protected:
|
|||
static QString extractStringArgument(QString objectName, QVariantMap arguments,
|
||||
QString argumentName, bool& ok, bool required = true);
|
||||
|
||||
QUuid _id;
|
||||
EntityActionType _type;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -13,9 +13,9 @@
|
|||
|
||||
#include "ObjectAction.h"
|
||||
|
||||
ObjectAction::ObjectAction(EntityActionType type, QUuid id, EntityItemPointer ownerEntity) :
|
||||
ObjectAction::ObjectAction(EntityActionType type, const QUuid& id, EntityItemPointer ownerEntity) :
|
||||
btActionInterface(),
|
||||
_id(id),
|
||||
EntityActionInterface(type, id),
|
||||
_active(false),
|
||||
_ownerEntity(ownerEntity) {
|
||||
}
|
||||
|
@ -24,15 +24,15 @@ ObjectAction::~ObjectAction() {
|
|||
}
|
||||
|
||||
void ObjectAction::updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep) {
|
||||
if (!_active) {
|
||||
return;
|
||||
}
|
||||
if (_ownerEntity.expired()) {
|
||||
qDebug() << "warning -- action with no entity removing self from btCollisionWorld.";
|
||||
btDynamicsWorld* dynamicsWorld = static_cast<btDynamicsWorld*>(collisionWorld);
|
||||
dynamicsWorld->removeAction(this);
|
||||
return;
|
||||
}
|
||||
if (!_active) {
|
||||
return;
|
||||
}
|
||||
|
||||
updateActionWorker(deltaTimeStep);
|
||||
}
|
||||
|
@ -129,11 +129,3 @@ void ObjectAction::setAngularVelocity(glm::vec3 angularVelocity) {
|
|||
rigidBody->activate();
|
||||
}
|
||||
|
||||
QByteArray ObjectAction::serialize() {
|
||||
assert(false);
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
void ObjectAction::deserialize(QByteArray serializedArguments) {
|
||||
assert(false);
|
||||
}
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
|
||||
#include <btBulletDynamicsCommon.h>
|
||||
|
||||
#include <EntityItem.h>
|
||||
|
||||
#include "ObjectMotionState.h"
|
||||
#include "BulletUtil.h"
|
||||
#include "EntityActionInterface.h"
|
||||
|
@ -26,31 +24,25 @@
|
|||
|
||||
class ObjectAction : public btActionInterface, public EntityActionInterface {
|
||||
public:
|
||||
ObjectAction(EntityActionType type, QUuid id, EntityItemPointer ownerEntity);
|
||||
ObjectAction(EntityActionType type, const QUuid& id, EntityItemPointer ownerEntity);
|
||||
virtual ~ObjectAction();
|
||||
|
||||
const QUuid& getID() const { return _id; }
|
||||
virtual EntityActionType getType() { assert(false); return ACTION_TYPE_NONE; }
|
||||
virtual void removeFromSimulation(EntitySimulation* simulation) const;
|
||||
virtual EntityItemWeakPointer getOwnerEntity() const { return _ownerEntity; }
|
||||
virtual void setOwnerEntity(const EntityItemPointer ownerEntity) { _ownerEntity = ownerEntity; }
|
||||
|
||||
virtual bool updateArguments(QVariantMap arguments) { return false; }
|
||||
virtual QVariantMap getArguments() { return QVariantMap(); }
|
||||
virtual bool updateArguments(QVariantMap arguments) = 0;
|
||||
virtual QVariantMap getArguments() = 0;
|
||||
|
||||
// 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
|
||||
virtual void updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep);
|
||||
virtual void debugDraw(btIDebugDraw* debugDrawer);
|
||||
|
||||
virtual QByteArray serialize();
|
||||
virtual void deserialize(QByteArray serializedArguments);
|
||||
|
||||
private:
|
||||
QUuid _id;
|
||||
QReadWriteLock _lock;
|
||||
virtual QByteArray serialize() const = 0;
|
||||
virtual void deserialize(QByteArray serializedArguments) = 0;
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -70,6 +62,10 @@ protected:
|
|||
bool tryLockForWrite() { return _lock.tryLockForWrite(); }
|
||||
void unlock() { _lock.unlock(); }
|
||||
|
||||
private:
|
||||
QReadWriteLock _lock;
|
||||
|
||||
protected:
|
||||
bool _active;
|
||||
EntityItemWeakPointer _ownerEntity;
|
||||
};
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
|
||||
const uint16_t ObjectActionOffset::offsetVersion = 1;
|
||||
|
||||
ObjectActionOffset::ObjectActionOffset(EntityActionType type, QUuid id, EntityItemPointer ownerEntity) :
|
||||
ObjectAction(type, id, ownerEntity) {
|
||||
ObjectActionOffset::ObjectActionOffset(const QUuid& id, EntityItemPointer ownerEntity) :
|
||||
ObjectAction(ACTION_TYPE_OFFSET, id, ownerEntity) {
|
||||
#if WANT_DEBUG
|
||||
qDebug() << "ObjectActionOffset::ObjectActionOffset";
|
||||
#endif
|
||||
|
@ -127,7 +127,7 @@ QVariantMap ObjectActionOffset::getArguments() {
|
|||
return arguments;
|
||||
}
|
||||
|
||||
QByteArray ObjectActionOffset::serialize() {
|
||||
QByteArray ObjectActionOffset::serialize() const {
|
||||
QByteArray ba;
|
||||
QDataStream dataStream(&ba, QIODevice::WriteOnly);
|
||||
dataStream << getType();
|
||||
|
@ -146,13 +146,14 @@ void ObjectActionOffset::deserialize(QByteArray serializedArguments) {
|
|||
QDataStream dataStream(serializedArguments);
|
||||
|
||||
EntityActionType type;
|
||||
QUuid id;
|
||||
uint16_t serializationVersion;
|
||||
|
||||
dataStream >> type;
|
||||
assert(type == getType());
|
||||
|
||||
QUuid id;
|
||||
dataStream >> id;
|
||||
assert(id == getID());
|
||||
|
||||
uint16_t serializationVersion;
|
||||
dataStream >> serializationVersion;
|
||||
if (serializationVersion != ObjectActionOffset::offsetVersion) {
|
||||
return;
|
||||
|
|
|
@ -19,17 +19,15 @@
|
|||
|
||||
class ObjectActionOffset : public ObjectAction {
|
||||
public:
|
||||
ObjectActionOffset(EntityActionType type, QUuid id, EntityItemPointer ownerEntity);
|
||||
ObjectActionOffset(const QUuid& id, EntityItemPointer ownerEntity);
|
||||
virtual ~ObjectActionOffset();
|
||||
|
||||
virtual EntityActionType getType() { return ACTION_TYPE_OFFSET; }
|
||||
|
||||
virtual bool updateArguments(QVariantMap arguments);
|
||||
virtual QVariantMap getArguments();
|
||||
|
||||
virtual void updateActionWorker(float deltaTimeStep);
|
||||
|
||||
virtual QByteArray serialize();
|
||||
virtual QByteArray serialize() const;
|
||||
virtual void deserialize(QByteArray serializedArguments);
|
||||
|
||||
private:
|
||||
|
|
|
@ -17,8 +17,8 @@ const float SPRING_MAX_SPEED = 10.0f;
|
|||
|
||||
const uint16_t ObjectActionSpring::springVersion = 1;
|
||||
|
||||
ObjectActionSpring::ObjectActionSpring(EntityActionType type, QUuid id, EntityItemPointer ownerEntity) :
|
||||
ObjectAction(type, id, ownerEntity),
|
||||
ObjectActionSpring::ObjectActionSpring(const QUuid& id, EntityItemPointer ownerEntity) :
|
||||
ObjectAction(ACTION_TYPE_SPRING, id, ownerEntity),
|
||||
_positionalTarget(glm::vec3(0.0f)),
|
||||
_linearTimeScale(0.2f),
|
||||
_positionalTargetSet(false),
|
||||
|
@ -206,7 +206,7 @@ QVariantMap ObjectActionSpring::getArguments() {
|
|||
return arguments;
|
||||
}
|
||||
|
||||
QByteArray ObjectActionSpring::serialize() {
|
||||
QByteArray ObjectActionSpring::serialize() const {
|
||||
QByteArray serializedActionArguments;
|
||||
QDataStream dataStream(&serializedActionArguments, QIODevice::WriteOnly);
|
||||
|
||||
|
@ -229,13 +229,14 @@ void ObjectActionSpring::deserialize(QByteArray serializedArguments) {
|
|||
QDataStream dataStream(serializedArguments);
|
||||
|
||||
EntityActionType type;
|
||||
QUuid id;
|
||||
uint16_t serializationVersion;
|
||||
|
||||
dataStream >> type;
|
||||
assert(type == getType());
|
||||
|
||||
QUuid id;
|
||||
dataStream >> id;
|
||||
assert(id == getID());
|
||||
|
||||
uint16_t serializationVersion;
|
||||
dataStream >> serializationVersion;
|
||||
if (serializationVersion != ObjectActionSpring::springVersion) {
|
||||
return;
|
||||
|
|
|
@ -12,24 +12,19 @@
|
|||
#ifndef hifi_ObjectActionSpring_h
|
||||
#define hifi_ObjectActionSpring_h
|
||||
|
||||
#include <QUuid>
|
||||
|
||||
#include <EntityItem.h>
|
||||
#include "ObjectAction.h"
|
||||
|
||||
class ObjectActionSpring : public ObjectAction {
|
||||
public:
|
||||
ObjectActionSpring(EntityActionType type, QUuid id, EntityItemPointer ownerEntity);
|
||||
ObjectActionSpring(const QUuid& id, EntityItemPointer ownerEntity);
|
||||
virtual ~ObjectActionSpring();
|
||||
|
||||
virtual EntityActionType getType() { return ACTION_TYPE_SPRING; }
|
||||
|
||||
virtual bool updateArguments(QVariantMap arguments);
|
||||
virtual QVariantMap getArguments();
|
||||
|
||||
virtual void updateActionWorker(float deltaTimeStep);
|
||||
|
||||
virtual QByteArray serialize();
|
||||
virtual QByteArray serialize() const;
|
||||
virtual void deserialize(QByteArray serializedArguments);
|
||||
|
||||
protected:
|
||||
|
|
|
@ -21,9 +21,13 @@
|
|||
#include <climits>
|
||||
#include <limits>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include <QBitArray>
|
||||
#include <QByteArray>
|
||||
|
||||
#include "SharedUtil.h"
|
||||
|
||||
#include "NumericalConstants.h"
|
||||
|
||||
template<typename T> class ByteCountCoded {
|
||||
|
@ -37,7 +41,8 @@ public:
|
|||
ByteCountCoded(const QByteArray& fromEncoded) : data(0) { decode(fromEncoded); }
|
||||
|
||||
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; }
|
||||
|
@ -110,52 +115,63 @@ template<typename T> inline QByteArray ByteCountCoded<T>::encode() const {
|
|||
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...
|
||||
QBitArray encodedBits;
|
||||
int bitCount = BITS_IN_BYTE * fromEncodedBytes.count();
|
||||
encodedBits.resize(bitCount);
|
||||
template<typename T> inline size_t ByteCountCoded<T>::decode(const char* encodedBuffer, int encodedSize) {
|
||||
data = 0; // reset data
|
||||
size_t bytesConsumed = 0;
|
||||
int bitCount = BITS_IN_BYTE * encodedSize;
|
||||
|
||||
int encodedByteCount = 1; // there is at least 1 byte (after the leadBits)
|
||||
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 < fromEncodedBytes.count(); byte++) {
|
||||
char originalByte = fromEncodedBytes.at(byte);
|
||||
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++) {
|
||||
int shiftBy = BITS_IN_BYTE - (bit + 1);
|
||||
char maskBit = ( 1 << shiftBy);
|
||||
bool bitValue = originalByte & maskBit;
|
||||
encodedBits.setBit(byte * BITS_IN_BYTE + bit, bitValue);
|
||||
bool bitIsSet = originalByte & maskBit;
|
||||
|
||||
// Processing of the lead bits
|
||||
if (inLeadBits) {
|
||||
if (bitIsSet) {
|
||||
encodedByteCount++;
|
||||
leadBits++;
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (bitAt > lastValueBit) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(bitIsSet) {
|
||||
data += bitValue;
|
||||
}
|
||||
bitValue *= 2;
|
||||
}
|
||||
bitAt++;
|
||||
maskBit = maskBit >> 1;
|
||||
}
|
||||
}
|
||||
|
||||
// next, read the leading bits to determine the correct number of bytes to decode (may not match the QByteArray)
|
||||
int encodedByteCount = 0;
|
||||
int leadBits = 1;
|
||||
int bitAt;
|
||||
for (bitAt = 0; bitAt < bitCount; bitAt++) {
|
||||
if (encodedBits.at(bitAt)) {
|
||||
encodedByteCount++;
|
||||
leadBits++;
|
||||
} else {
|
||||
if (!inLeadBits && bitAt > lastValueBit) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
encodedByteCount++; // always at least one byte
|
||||
int expectedBitCount = encodedByteCount * BITS_IN_BYTE;
|
||||
|
||||
T value = 0;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
data = value;
|
||||
return bytesConsumed;
|
||||
}
|
||||
#endif // hifi_ByteCountCoding_h
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ QVariantList glmToQList(const glm::quat& g) {
|
|||
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]);
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
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();
|
||||
float x = qList[0].toFloat();
|
||||
float y = qList[1].toFloat();
|
||||
|
@ -56,7 +56,7 @@ glm::quat qListToGlmQuat(const QVariant q) {
|
|||
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();
|
||||
returnValue[RED_INDEX] = qList[RED_INDEX].toInt();
|
||||
returnValue[GREEN_INDEX] = qList[GREEN_INDEX].toInt();
|
||||
|
|
|
@ -19,11 +19,11 @@
|
|||
|
||||
QVariantList glmToQList(const glm::vec3& 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::quat& glmQuat);
|
||||
|
||||
glm::vec3 qListToGlmVec3(const QVariant q);
|
||||
glm::quat qListToGlmQuat(const QVariant q);
|
||||
void qListtoRgbColor(const QVariant q, rgbColor returnValue);
|
||||
glm::vec3 qListToGlmVec3(const QVariant& q);
|
||||
glm::quat qListToGlmQuat(const QVariant& q);
|
||||
void qListtoRgbColor(const QVariant& q, rgbColor& returnValue);
|
||||
|
|
Loading…
Reference in a new issue