mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 21:43:03 +02:00
make EntityItemID a subclass of QUuid
This commit is contained in:
parent
f522334c99
commit
124ff68cee
14 changed files with 45 additions and 84 deletions
|
@ -73,14 +73,6 @@ void Agent::readPendingDatagrams() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (datagramPacketType == PacketTypeEntityAddResponse) {
|
|
||||||
// also give our local entity tree a chance to remap any internal locally created entities
|
|
||||||
_entityViewer.getTree()->handleAddEntityResponse(receivedPacket);
|
|
||||||
|
|
||||||
// Make sure our Node and NodeList knows we've heard from this node.
|
|
||||||
SharedNodePointer sourceNode = nodeList->sendingNodeForPacket(receivedPacket);
|
|
||||||
sourceNode->setLastHeardMicrostamp(usecTimestampNow());
|
|
||||||
|
|
||||||
} else if (datagramPacketType == PacketTypeOctreeStats
|
} else if (datagramPacketType == PacketTypeOctreeStats
|
||||||
|| datagramPacketType == PacketTypeEntityData
|
|| datagramPacketType == PacketTypeEntityData
|
||||||
|| datagramPacketType == PacketTypeEntityErase
|
|| datagramPacketType == PacketTypeEntityErase
|
||||||
|
|
|
@ -60,24 +60,6 @@ void EntityServer::beforeRun() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityServer::entityCreated(const EntityItem& newEntity, const SharedNodePointer& senderNode) {
|
void EntityServer::entityCreated(const EntityItem& newEntity, const SharedNodePointer& senderNode) {
|
||||||
|
|
||||||
unsigned char outputBuffer[MAX_PACKET_SIZE];
|
|
||||||
unsigned char* copyAt = outputBuffer;
|
|
||||||
|
|
||||||
auto nodeList = DependencyManager::get<NodeList>();
|
|
||||||
|
|
||||||
int numBytesPacketHeader = nodeList->populatePacketHeader(reinterpret_cast<char*>(outputBuffer), PacketTypeEntityAddResponse);
|
|
||||||
int packetLength = numBytesPacketHeader;
|
|
||||||
copyAt += numBytesPacketHeader;
|
|
||||||
|
|
||||||
// encode the entity ID
|
|
||||||
QUuid entityID = newEntity.getID();
|
|
||||||
QByteArray encodedID = entityID.toRfc4122();
|
|
||||||
memcpy(copyAt, encodedID.constData(), encodedID.size());
|
|
||||||
copyAt += sizeof(entityID);
|
|
||||||
packetLength += sizeof(entityID);
|
|
||||||
|
|
||||||
nodeList->writeDatagram((char*) outputBuffer, packetLength, senderNode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -82,9 +82,6 @@ void DatagramProcessor::processDatagrams() {
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PacketTypeEntityAddResponse:
|
|
||||||
application->getEntities()->getTree()->handleAddEntityResponse(incomingPacket);
|
|
||||||
break;
|
|
||||||
case PacketTypeEntityData:
|
case PacketTypeEntityData:
|
||||||
case PacketTypeEntityErase:
|
case PacketTypeEntityErase:
|
||||||
case PacketTypeOctreeStats:
|
case PacketTypeOctreeStats:
|
||||||
|
|
|
@ -840,7 +840,7 @@ RayToEntityIntersectionResult EntityTreeRenderer::findRayIntersectionWorker(cons
|
||||||
(void**)&intersectedEntity, lockType, &result.accurate,
|
(void**)&intersectedEntity, lockType, &result.accurate,
|
||||||
precisionPicking);
|
precisionPicking);
|
||||||
if (result.intersects && intersectedEntity) {
|
if (result.intersects && intersectedEntity) {
|
||||||
result.entityID = intersectedEntity->getEntityItemID().id;
|
result.entityID = intersectedEntity->getEntityItemID();
|
||||||
result.properties = intersectedEntity->getProperties();
|
result.properties = intersectedEntity->getProperties();
|
||||||
result.intersection = ray.origin + (ray.direction * result.distance);
|
result.intersection = ray.origin + (ray.direction * result.distance);
|
||||||
result.entity = intersectedEntity;
|
result.entity = intersectedEntity;
|
||||||
|
|
|
@ -30,7 +30,7 @@ bool EntityItem::_sendPhysicsUpdates = true;
|
||||||
|
|
||||||
EntityItem::EntityItem(const EntityItemID& entityItemID) :
|
EntityItem::EntityItem(const EntityItemID& entityItemID) :
|
||||||
_type(EntityTypes::Unknown),
|
_type(EntityTypes::Unknown),
|
||||||
_id(entityItemID.id),
|
_id(entityItemID),
|
||||||
_lastSimulated(0),
|
_lastSimulated(0),
|
||||||
_lastUpdated(0),
|
_lastUpdated(0),
|
||||||
_lastEdited(0),
|
_lastEdited(0),
|
||||||
|
|
|
@ -18,28 +18,26 @@
|
||||||
#include "EntityItemID.h"
|
#include "EntityItemID.h"
|
||||||
|
|
||||||
|
|
||||||
EntityItemID::EntityItemID() :
|
EntityItemID::EntityItemID() : QUuid()
|
||||||
id(UNKNOWN_ENTITY_ID)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
EntityItemID::EntityItemID(const QUuid& id) :
|
|
||||||
id(id)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
EntityItemID::EntityItemID(const EntityItemID& other) : id(other.id)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
EntityItemID::EntityItemID(const QUuid& id) : QUuid(id)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// EntityItemID::EntityItemID(const EntityItemID& other) : QUuid(other)
|
||||||
|
// {
|
||||||
|
// }
|
||||||
|
|
||||||
EntityItemID EntityItemID::readEntityItemIDFromBuffer(const unsigned char* data, int bytesLeftToRead) {
|
EntityItemID EntityItemID::readEntityItemIDFromBuffer(const unsigned char* data, int bytesLeftToRead) {
|
||||||
EntityItemID result;
|
EntityItemID result;
|
||||||
|
|
||||||
if (bytesLeftToRead >= NUM_BYTES_RFC4122_UUID) {
|
if (bytesLeftToRead >= NUM_BYTES_RFC4122_UUID) {
|
||||||
// id
|
// id
|
||||||
QByteArray encodedID((const char*)data, NUM_BYTES_RFC4122_UUID);
|
QByteArray encodedID((const char*)data, NUM_BYTES_RFC4122_UUID);
|
||||||
result.id = QUuid::fromRfc4122(encodedID);
|
result = QUuid::fromRfc4122(encodedID);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -49,9 +47,9 @@ QScriptValue EntityItemID::toScriptValue(QScriptEngine* engine) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
QScriptValue EntityItemIDtoScriptValue(QScriptEngine* engine, const EntityItemID& id) {
|
QScriptValue EntityItemIDtoScriptValue(QScriptEngine* engine, const EntityItemID& id) {
|
||||||
return quuidToScriptValue(engine, id.id);
|
return quuidToScriptValue(engine, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityItemIDfromScriptValue(const QScriptValue &object, EntityItemID& id) {
|
void EntityItemIDfromScriptValue(const QScriptValue &object, EntityItemID& id) {
|
||||||
quuidFromScriptValue(object, id.id);
|
quuidFromScriptValue(object, id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,37 +23,37 @@
|
||||||
const QUuid UNKNOWN_ENTITY_ID; // null uuid
|
const QUuid UNKNOWN_ENTITY_ID; // null uuid
|
||||||
|
|
||||||
/// Abstract ID for editing model items. Used in EntityItem JS API.
|
/// Abstract ID for editing model items. Used in EntityItem JS API.
|
||||||
class EntityItemID {
|
class EntityItemID : public QUuid {
|
||||||
public:
|
public:
|
||||||
EntityItemID();
|
EntityItemID();
|
||||||
EntityItemID(const QUuid& id);
|
EntityItemID(const QUuid& id);
|
||||||
EntityItemID(const EntityItemID& other);
|
// EntityItemID(const EntityItemID& other);
|
||||||
static EntityItemID readEntityItemIDFromBuffer(const unsigned char* data, int bytesLeftToRead);
|
static EntityItemID readEntityItemIDFromBuffer(const unsigned char* data, int bytesLeftToRead);
|
||||||
QScriptValue toScriptValue(QScriptEngine* engine) const;
|
QScriptValue toScriptValue(QScriptEngine* engine) const;
|
||||||
|
|
||||||
bool isInvalidID() const { return id == UNKNOWN_ENTITY_ID; }
|
bool isInvalidID() const { return *this == UNKNOWN_ENTITY_ID; }
|
||||||
|
|
||||||
QUuid id;
|
// QUuid id;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool operator<(const EntityItemID& a, const EntityItemID& b) {
|
// inline bool operator<(const EntityItemID& a, const EntityItemID& b) {
|
||||||
return a.id < b.id;
|
// return a.id < b.id;
|
||||||
}
|
// }
|
||||||
|
|
||||||
inline bool operator==(const EntityItemID& a, const EntityItemID& b) {
|
// inline bool operator==(const EntityItemID& a, const EntityItemID& b) {
|
||||||
return a.id == b.id;
|
// return a.id == b.id;
|
||||||
}
|
// }
|
||||||
|
|
||||||
inline bool operator!=(const EntityItemID& a, const EntityItemID& b) {
|
// inline bool operator!=(const EntityItemID& a, const EntityItemID& b) {
|
||||||
return !(a == b);
|
// return !(a == b);
|
||||||
}
|
// }
|
||||||
|
|
||||||
inline uint qHash(const EntityItemID& a, uint seed) {
|
// inline uint qHash(const EntityItemID& a, uint seed) {
|
||||||
return qHash(a.id, seed);
|
// return qHash(a.id, seed);
|
||||||
}
|
// }
|
||||||
|
|
||||||
inline QDebug operator<<(QDebug debug, const EntityItemID& id) {
|
inline QDebug operator<<(QDebug debug, const EntityItemID& id) {
|
||||||
debug << "[entity-id:" << id.id << "]";
|
debug << "[entity-id:" << id.toString() << "]";
|
||||||
return debug;
|
return debug;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -586,7 +586,7 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem
|
||||||
|
|
||||||
// id
|
// id
|
||||||
// encode our ID as a byte count coded byte stream
|
// encode our ID as a byte count coded byte stream
|
||||||
QByteArray encodedID = id.id.toRfc4122(); // NUM_BYTES_RFC4122_UUID
|
QByteArray encodedID = id.toRfc4122(); // NUM_BYTES_RFC4122_UUID
|
||||||
|
|
||||||
// encode our ID as a byte count coded byte stream
|
// encode our ID as a byte count coded byte stream
|
||||||
ByteCountCoded<quint32> tokenCoder;
|
ByteCountCoded<quint32> tokenCoder;
|
||||||
|
@ -990,7 +990,7 @@ bool EntityItemProperties::encodeEraseEntityMessage(const EntityItemID& entityIt
|
||||||
copyAt += sizeof(numberOfIds);
|
copyAt += sizeof(numberOfIds);
|
||||||
outputLength = sizeof(numberOfIds);
|
outputLength = sizeof(numberOfIds);
|
||||||
|
|
||||||
QUuid entityID = entityItemID.id;
|
QUuid entityID = entityItemID;
|
||||||
QByteArray encodedEntityID = entityID.toRfc4122();
|
QByteArray encodedEntityID = entityID.toRfc4122();
|
||||||
|
|
||||||
memcpy(copyAt, encodedEntityID.constData(), NUM_BYTES_RFC4122_UUID);
|
memcpy(copyAt, encodedEntityID.constData(), NUM_BYTES_RFC4122_UUID);
|
||||||
|
|
|
@ -72,7 +72,7 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties
|
||||||
|
|
||||||
EntityItemProperties propertiesWithSimID = properties;
|
EntityItemProperties propertiesWithSimID = properties;
|
||||||
|
|
||||||
EntityItemID id = EntityItemID(UNKNOWN_ENTITY_ID);
|
EntityItemID id = EntityItemID(QUuid::createUuid());
|
||||||
|
|
||||||
// If we have a local entity tree set, then also update it.
|
// If we have a local entity tree set, then also update it.
|
||||||
bool success = true;
|
bool success = true;
|
||||||
|
@ -95,7 +95,7 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties
|
||||||
queueEntityMessage(PacketTypeEntityAddOrEdit, id, propertiesWithSimID);
|
queueEntityMessage(PacketTypeEntityAddOrEdit, id, propertiesWithSimID);
|
||||||
}
|
}
|
||||||
|
|
||||||
return id.id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identity) {
|
EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identity) {
|
||||||
|
@ -189,7 +189,7 @@ QUuid EntityScriptingInterface::findClosestEntity(const glm::vec3& center, float
|
||||||
result = closestEntity->getEntityItemID();
|
result = closestEntity->getEntityItemID();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result.id;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -210,7 +210,7 @@ QVector<QUuid> EntityScriptingInterface::findEntities(const glm::vec3& center, f
|
||||||
_entityTree->unlock();
|
_entityTree->unlock();
|
||||||
|
|
||||||
foreach (const EntityItem* entity, entities) {
|
foreach (const EntityItem* entity, entities) {
|
||||||
result << entity->getEntityItemID().id;
|
result << entity->getEntityItemID();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -226,7 +226,7 @@ QVector<QUuid> EntityScriptingInterface::findEntitiesInBox(const glm::vec3& corn
|
||||||
_entityTree->unlock();
|
_entityTree->unlock();
|
||||||
|
|
||||||
foreach (const EntityItem* entity, entities) {
|
foreach (const EntityItem* entity, entities) {
|
||||||
result << entity->getEntityItemID().id;
|
result << entity->getEntityItemID();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -253,7 +253,7 @@ RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionWorke
|
||||||
(void**)&intersectedEntity, lockType, &result.accurate,
|
(void**)&intersectedEntity, lockType, &result.accurate,
|
||||||
precisionPicking);
|
precisionPicking);
|
||||||
if (result.intersects && intersectedEntity) {
|
if (result.intersects && intersectedEntity) {
|
||||||
result.entityID = intersectedEntity->getEntityItemID().id;
|
result.entityID = intersectedEntity->getEntityItemID();
|
||||||
result.properties = intersectedEntity->getProperties();
|
result.properties = intersectedEntity->getProperties();
|
||||||
result.intersection = ray.origin + (ray.direction * result.distance);
|
result.intersection = ray.origin + (ray.direction * result.distance);
|
||||||
}
|
}
|
||||||
|
|
|
@ -367,7 +367,7 @@ void EntityTree::processRemovedEntities(const DeleteEntityOperator& theOperator)
|
||||||
// set up the deleted entities ID
|
// set up the deleted entities ID
|
||||||
quint64 deletedAt = usecTimestampNow();
|
quint64 deletedAt = usecTimestampNow();
|
||||||
_recentlyDeletedEntitiesLock.lockForWrite();
|
_recentlyDeletedEntitiesLock.lockForWrite();
|
||||||
_recentlyDeletedEntityItemIDs.insert(deletedAt, theEntity->getEntityItemID().id);
|
_recentlyDeletedEntityItemIDs.insert(deletedAt, theEntity->getEntityItemID());
|
||||||
_recentlyDeletedEntitiesLock.unlock();
|
_recentlyDeletedEntitiesLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -381,14 +381,6 @@ void EntityTree::processRemovedEntities(const DeleteEntityOperator& theOperator)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityTree::handleAddEntityResponse(const QByteArray& packet) {
|
|
||||||
|
|
||||||
if (!getIsClient()) {
|
|
||||||
qCDebug(entities) << "UNEXPECTED!!! EntityTree::handleAddEntityResponse() with !getIsClient() ***";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class FindNearPointArgs {
|
class FindNearPointArgs {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -135,7 +135,6 @@ public:
|
||||||
|
|
||||||
int processEraseMessage(const QByteArray& dataByteArray, const SharedNodePointer& sourceNode);
|
int processEraseMessage(const QByteArray& dataByteArray, const SharedNodePointer& sourceNode);
|
||||||
int processEraseMessageDetails(const QByteArray& dataByteArray, const SharedNodePointer& sourceNode);
|
int processEraseMessageDetails(const QByteArray& dataByteArray, const SharedNodePointer& sourceNode);
|
||||||
void handleAddEntityResponse(const QByteArray& packet);
|
|
||||||
|
|
||||||
EntityItemFBXService* getFBXService() const { return _fbxService; }
|
EntityItemFBXService* getFBXService() const { return _fbxService; }
|
||||||
void setFBXService(EntityItemFBXService* service) { _fbxService = service; }
|
void setFBXService(EntityItemFBXService* service) { _fbxService = service; }
|
||||||
|
|
|
@ -119,7 +119,6 @@ QString nameForPacketType(PacketType packetType) {
|
||||||
PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityData);
|
PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityData);
|
||||||
PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityAddOrEdit);
|
PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityAddOrEdit);
|
||||||
PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityErase);
|
PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityErase);
|
||||||
PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityAddResponse);
|
|
||||||
PACKET_TYPE_NAME_LOOKUP(PacketTypeOctreeDataNack);
|
PACKET_TYPE_NAME_LOOKUP(PacketTypeOctreeDataNack);
|
||||||
PACKET_TYPE_NAME_LOOKUP(PacketTypeStopNode);
|
PACKET_TYPE_NAME_LOOKUP(PacketTypeStopNode);
|
||||||
PACKET_TYPE_NAME_LOOKUP(PacketTypeAudioEnvironment);
|
PACKET_TYPE_NAME_LOOKUP(PacketTypeAudioEnvironment);
|
||||||
|
|
|
@ -70,7 +70,7 @@ enum PacketType {
|
||||||
PacketTypeEntityData,
|
PacketTypeEntityData,
|
||||||
PacketTypeEntityAddOrEdit,
|
PacketTypeEntityAddOrEdit,
|
||||||
PacketTypeEntityErase,
|
PacketTypeEntityErase,
|
||||||
PacketTypeEntityAddResponse,
|
UNUSED_11,
|
||||||
PacketTypeOctreeDataNack, // 45
|
PacketTypeOctreeDataNack, // 45
|
||||||
PacketTypeStopNode,
|
PacketTypeStopNode,
|
||||||
PacketTypeAudioEnvironment,
|
PacketTypeAudioEnvironment,
|
||||||
|
|
|
@ -319,8 +319,10 @@ void ScriptEngine::init() {
|
||||||
registerAudioMetaTypes(this);
|
registerAudioMetaTypes(this);
|
||||||
|
|
||||||
qScriptRegisterMetaType(this, EntityItemPropertiesToScriptValue, EntityItemPropertiesFromScriptValue);
|
qScriptRegisterMetaType(this, EntityItemPropertiesToScriptValue, EntityItemPropertiesFromScriptValue);
|
||||||
|
qScriptRegisterMetaType(this, EntityItemIDtoScriptValue, EntityItemIDfromScriptValue);
|
||||||
qScriptRegisterMetaType(this, RayToEntityIntersectionResultToScriptValue, RayToEntityIntersectionResultFromScriptValue);
|
qScriptRegisterMetaType(this, RayToEntityIntersectionResultToScriptValue, RayToEntityIntersectionResultFromScriptValue);
|
||||||
qScriptRegisterSequenceMetaType<QVector<QUuid> >(this);
|
qScriptRegisterSequenceMetaType<QVector<QUuid>>(this);
|
||||||
|
qScriptRegisterSequenceMetaType<QVector<EntityItemID>>(this);
|
||||||
|
|
||||||
qScriptRegisterSequenceMetaType<QVector<glm::vec2> >(this);
|
qScriptRegisterSequenceMetaType<QVector<glm::vec2> >(this);
|
||||||
qScriptRegisterSequenceMetaType<QVector<glm::quat> >(this);
|
qScriptRegisterSequenceMetaType<QVector<glm::quat> >(this);
|
||||||
|
|
Loading…
Reference in a new issue