sort out script interface changes

This commit is contained in:
Seth Alves 2015-05-20 12:30:06 -07:00
parent a769cfdaf2
commit f522334c99
7 changed files with 37 additions and 43 deletions

View file

@ -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(); result.entityID = intersectedEntity->getEntityItemID().id;
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;

View file

@ -99,7 +99,7 @@ void RenderableWebEntityItem::render(RenderArgs* args) {
return; return;
} }
if (intersection.entityID.id == getID()) { if (intersection.entityID == getID()) {
if (event->button() == Qt::MouseButton::RightButton) { if (event->button() == Qt::MouseButton::RightButton) {
if (event->type() == QEvent::MouseButtonRelease) { if (event->type() == QEvent::MouseButtonRelease) {
AbstractViewStateInterface::instance()->postLambdaEvent([this] { AbstractViewStateInterface::instance()->postLambdaEvent([this] {

View file

@ -20,13 +20,7 @@
#include <QScriptEngine> #include <QScriptEngine>
#include <QUuid> #include <QUuid>
// const uint32_t UNKNOWN_ENTITY_TOKEN = 0xFFFFFFFF; const QUuid UNKNOWN_ENTITY_ID; // null uuid
// const uint32_t NEW_ENTITY = 0xFFFFFFFF;
// const uint32_t UNKNOWN_ENTITY_ID = 0xFFFFFFFF;
const QUuid NEW_ENTITY;
const QUuid UNKNOWN_ENTITY_ID;
/// 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 {
@ -43,7 +37,7 @@ public:
}; };
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) {

View file

@ -68,11 +68,11 @@ void bidForSimulationOwnership(EntityItemProperties& properties) {
EntityItemID EntityScriptingInterface::addEntity(const EntityItemProperties& properties) { QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties) {
EntityItemProperties propertiesWithSimID = properties; EntityItemProperties propertiesWithSimID = properties;
EntityItemID id = EntityItemID(QUuid::createUuid()); EntityItemID id = EntityItemID(UNKNOWN_ENTITY_ID);
// 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,10 +95,10 @@ EntityItemID EntityScriptingInterface::addEntity(const EntityItemProperties& pro
queueEntityMessage(PacketTypeEntityAddOrEdit, id, propertiesWithSimID); queueEntityMessage(PacketTypeEntityAddOrEdit, id, propertiesWithSimID);
} }
return id; return id.id;
} }
EntityItemProperties EntityScriptingInterface::getEntityProperties(EntityItemID identity) { EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identity) {
EntityItemProperties results; EntityItemProperties results;
if (_entityTree) { if (_entityTree) {
_entityTree->lockForRead(); _entityTree->lockForRead();
@ -126,7 +126,7 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(EntityItemID
return results; return results;
} }
EntityItemID EntityScriptingInterface::editEntity(EntityItemID id, const EntityItemProperties& properties) { QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& properties) {
EntityItemID entityID(id); EntityItemID entityID(id);
// If we have a local entity tree set, then also update it. // If we have a local entity tree set, then also update it.
if (_entityTree) { if (_entityTree) {
@ -153,7 +153,7 @@ EntityItemID EntityScriptingInterface::editEntity(EntityItemID id, const EntityI
return id; return id;
} }
void EntityScriptingInterface::deleteEntity(EntityItemID id) { void EntityScriptingInterface::deleteEntity(QUuid id) {
EntityItemID entityID(id); EntityItemID entityID(id);
bool shouldDelete = true; bool shouldDelete = true;
@ -179,17 +179,17 @@ void EntityScriptingInterface::deleteEntity(EntityItemID id) {
} }
} }
EntityItemID EntityScriptingInterface::findClosestEntity(const glm::vec3& center, float radius) const { QUuid EntityScriptingInterface::findClosestEntity(const glm::vec3& center, float radius) const {
QUuid result; EntityItemID result;
if (_entityTree) { if (_entityTree) {
_entityTree->lockForRead(); _entityTree->lockForRead();
const EntityItem* closestEntity = _entityTree->findClosestEntity(center, radius); const EntityItem* closestEntity = _entityTree->findClosestEntity(center, radius);
_entityTree->unlock(); _entityTree->unlock();
if (closestEntity) { if (closestEntity) {
result = closestEntity->getEntityItemID().id; result = closestEntity->getEntityItemID();
} }
} }
return result; return result.id;
} }
@ -201,8 +201,8 @@ void EntityScriptingInterface::dumpTree() const {
} }
} }
QVector<EntityItemID> EntityScriptingInterface::findEntities(const glm::vec3& center, float radius) const { QVector<QUuid> EntityScriptingInterface::findEntities(const glm::vec3& center, float radius) const {
QVector<EntityItemID> result; QVector<QUuid> result;
if (_entityTree) { if (_entityTree) {
_entityTree->lockForRead(); _entityTree->lockForRead();
QVector<const EntityItem*> entities; QVector<const EntityItem*> entities;
@ -210,14 +210,14 @@ QVector<EntityItemID> EntityScriptingInterface::findEntities(const glm::vec3& ce
_entityTree->unlock(); _entityTree->unlock();
foreach (const EntityItem* entity, entities) { foreach (const EntityItem* entity, entities) {
result << entity->getEntityItemID(); result << entity->getEntityItemID().id;
} }
} }
return result; return result;
} }
QVector<EntityItemID> EntityScriptingInterface::findEntitiesInBox(const glm::vec3& corner, const glm::vec3& dimensions) const { QVector<QUuid> EntityScriptingInterface::findEntitiesInBox(const glm::vec3& corner, const glm::vec3& dimensions) const {
QVector<EntityItemID> result; QVector<QUuid> result;
if (_entityTree) { if (_entityTree) {
_entityTree->lockForRead(); _entityTree->lockForRead();
AABox box(corner, dimensions); AABox box(corner, dimensions);
@ -226,7 +226,7 @@ QVector<EntityItemID> EntityScriptingInterface::findEntitiesInBox(const glm::vec
_entityTree->unlock(); _entityTree->unlock();
foreach (const EntityItem* entity, entities) { foreach (const EntityItem* entity, entities) {
result << entity->getEntityItemID(); result << entity->getEntityItemID().id;
} }
} }
return result; return result;
@ -353,7 +353,8 @@ void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, Ra
value.intersects = object.property("intersects").toVariant().toBool(); value.intersects = object.property("intersects").toVariant().toBool();
value.accurate = object.property("accurate").toVariant().toBool(); value.accurate = object.property("accurate").toVariant().toBool();
QScriptValue entityIDValue = object.property("entityID"); QScriptValue entityIDValue = object.property("entityID");
EntityItemIDfromScriptValue(entityIDValue, value.entityID); // EntityItemIDfromScriptValue(entityIDValue, value.entityID);
quuidFromScriptValue(entityIDValue, value.entityID);
QScriptValue entityPropertiesValue = object.property("properties"); QScriptValue entityPropertiesValue = object.property("properties");
if (entityPropertiesValue.isValid()) { if (entityPropertiesValue.isValid()) {
EntityItemPropertiesFromScriptValue(entityPropertiesValue, value.properties); EntityItemPropertiesFromScriptValue(entityPropertiesValue, value.properties);

View file

@ -34,7 +34,7 @@ public:
RayToEntityIntersectionResult(); RayToEntityIntersectionResult();
bool intersects; bool intersects;
bool accurate; bool accurate;
EntityItemID entityID; QUuid entityID;
EntityItemProperties properties; EntityItemProperties properties;
float distance; float distance;
BoxFace face; BoxFace face;
@ -70,31 +70,31 @@ public slots:
Q_INVOKABLE bool canRez(); Q_INVOKABLE bool canRez();
/// adds a model with the specific properties /// adds a model with the specific properties
Q_INVOKABLE EntityItemID addEntity(const EntityItemProperties& properties); Q_INVOKABLE QUuid addEntity(const EntityItemProperties& properties);
/// gets the current model properties for a specific model /// gets the current model properties for a specific model
/// this function will not find return results in script engine contexts which don't have access to models /// this function will not find return results in script engine contexts which don't have access to models
Q_INVOKABLE EntityItemProperties getEntityProperties(EntityItemID entityID); Q_INVOKABLE EntityItemProperties getEntityProperties(QUuid entityID);
/// edits a model updating only the included properties, will return the identified EntityItemID in case of /// edits a model updating only the included properties, will return the identified EntityItemID in case of
/// successful edit, if the input entityID is for an unknown model this function will have no effect /// successful edit, if the input entityID is for an unknown model this function will have no effect
Q_INVOKABLE EntityItemID editEntity(EntityItemID entityID, const EntityItemProperties& properties); Q_INVOKABLE QUuid editEntity(QUuid entityID, const EntityItemProperties& properties);
/// deletes a model /// deletes a model
Q_INVOKABLE void deleteEntity(EntityItemID entityID); Q_INVOKABLE void deleteEntity(QUuid entityID);
/// finds the closest model to the center point, within the radius /// finds the closest model to the center point, within the radius
/// will return a EntityItemID.isKnownID = false if no models are in the radius /// will return a EntityItemID.isKnownID = false if no models are in the radius
/// this function will not find any models in script engine contexts which don't have access to models /// this function will not find any models in script engine contexts which don't have access to models
Q_INVOKABLE EntityItemID findClosestEntity(const glm::vec3& center, float radius) const; Q_INVOKABLE QUuid findClosestEntity(const glm::vec3& center, float radius) const;
/// finds models within the search sphere specified by the center point and radius /// finds models within the search sphere specified by the center point and radius
/// this function will not find any models in script engine contexts which don't have access to models /// this function will not find any models in script engine contexts which don't have access to models
Q_INVOKABLE QVector<EntityItemID> findEntities(const glm::vec3& center, float radius) const; Q_INVOKABLE QVector<QUuid> findEntities(const glm::vec3& center, float radius) const;
/// finds models within the search sphere specified by the center point and radius /// finds models within the search sphere specified by the center point and radius
/// this function will not find any models in script engine contexts which don't have access to models /// this function will not find any models in script engine contexts which don't have access to models
Q_INVOKABLE QVector<EntityItemID> findEntitiesInBox(const glm::vec3& corner, const glm::vec3& dimensions) const; Q_INVOKABLE QVector<QUuid> findEntitiesInBox(const glm::vec3& corner, const glm::vec3& dimensions) const;
/// If the scripting context has visible entities, this will determine a ray intersection, the results /// If the scripting context has visible entities, this will determine a ray intersection, the results
/// may be inaccurate if the engine is unable to access the visible entities, in which case result.accurate /// may be inaccurate if the engine is unable to access the visible entities, in which case result.accurate
@ -142,7 +142,6 @@ signals:
void deletingEntity(const EntityItemID& entityID); void deletingEntity(const EntityItemID& entityID);
void addingEntity(const EntityItemID& entityID); void addingEntity(const EntityItemID& entityID);
void changingEntityID(const EntityItemID& oldEntityID, const EntityItemID& newEntityID);
void clearingEntities(); void clearingEntities();
private: private:

View file

@ -1062,7 +1062,7 @@ bool EntityTree::readFromMap(QVariantMap& map) {
EntityItem* entity = addEntity(entityItemID, properties); EntityItem* entity = addEntity(entityItemID, properties);
if (!entity) { if (!entity) {
qCDebug(entities) << "adding Entity failed:" << entityItemID << entity->getType(); qCDebug(entities) << "adding Entity failed:" << entityItemID << properties.getType();
} }
} }

View file

@ -51,7 +51,7 @@ MovingEntitiesOperator::~MovingEntitiesOperator() {
void MovingEntitiesOperator::addEntityToMoveList(EntityItem* entity, const AACube& newCube) { void MovingEntitiesOperator::addEntityToMoveList(EntityItem* entity, const AACube& newCube) {
EntityTreeElement* oldContainingElement = _tree->getContainingElement(entity->getID()); EntityTreeElement* oldContainingElement = _tree->getContainingElement(entity->getEntityItemID());
AABox newCubeClamped = newCube.clamp(0.0f, (float)TREE_SCALE); AABox newCubeClamped = newCube.clamp(0.0f, (float)TREE_SCALE);
if (_wantDebug) { if (_wantDebug) {
@ -68,7 +68,7 @@ void MovingEntitiesOperator::addEntityToMoveList(EntityItem* entity, const AACub
} }
if (!oldContainingElement) { if (!oldContainingElement) {
qCDebug(entities) << "UNEXPECTED!!!! attempting to move entity "<< entity->getID() qCDebug(entities) << "UNEXPECTED!!!! attempting to move entity "<< entity->getEntityItemID()
<< "that has no containing element. "; << "that has no containing element. ";
return; // bail without adding. return; // bail without adding.
} }
@ -90,7 +90,7 @@ void MovingEntitiesOperator::addEntityToMoveList(EntityItem* entity, const AACub
if (_wantDebug) { if (_wantDebug) {
qCDebug(entities) << "MovingEntitiesOperator::addEntityToMoveList() -----------------------------"; qCDebug(entities) << "MovingEntitiesOperator::addEntityToMoveList() -----------------------------";
qCDebug(entities) << " details.entity:" << details.entity->getID(); qCDebug(entities) << " details.entity:" << details.entity->getEntityItemID();
qCDebug(entities) << " details.oldContainingElementCube:" << details.oldContainingElementCube; qCDebug(entities) << " details.oldContainingElementCube:" << details.oldContainingElementCube;
qCDebug(entities) << " details.newCube:" << details.newCube; qCDebug(entities) << " details.newCube:" << details.newCube;
qCDebug(entities) << " details.newCubeClamped:" << details.newCubeClamped; qCDebug(entities) << " details.newCubeClamped:" << details.newCubeClamped;
@ -122,7 +122,7 @@ bool MovingEntitiesOperator::shouldRecurseSubTree(OctreeElement* element) {
if (_wantDebug) { if (_wantDebug) {
qCDebug(entities) << "MovingEntitiesOperator::shouldRecurseSubTree() details["<< detailIndex <<"]-----------------------------"; qCDebug(entities) << "MovingEntitiesOperator::shouldRecurseSubTree() details["<< detailIndex <<"]-----------------------------";
qCDebug(entities) << " element:" << element->getAACube(); qCDebug(entities) << " element:" << element->getAACube();
qCDebug(entities) << " details.entity:" << details.entity->getID(); qCDebug(entities) << " details.entity:" << details.entity->getEntityItemID();
qCDebug(entities) << " details.oldContainingElementCube:" << details.oldContainingElementCube; qCDebug(entities) << " details.oldContainingElementCube:" << details.oldContainingElementCube;
qCDebug(entities) << " details.newCube:" << details.newCube; qCDebug(entities) << " details.newCube:" << details.newCube;
qCDebug(entities) << " details.newCubeClamped:" << details.newCubeClamped; qCDebug(entities) << " details.newCubeClamped:" << details.newCubeClamped;
@ -167,7 +167,7 @@ bool MovingEntitiesOperator::preRecursion(OctreeElement* element) {
qCDebug(entities) << "MovingEntitiesOperator::preRecursion() details["<< detailIndex <<"]-----------------------------"; qCDebug(entities) << "MovingEntitiesOperator::preRecursion() details["<< detailIndex <<"]-----------------------------";
qCDebug(entities) << " entityTreeElement:" << entityTreeElement->getAACube(); qCDebug(entities) << " entityTreeElement:" << entityTreeElement->getAACube();
qCDebug(entities) << " entityTreeElement->bestFitBounds(details.newCube):" << entityTreeElement->bestFitBounds(details.newCube); qCDebug(entities) << " entityTreeElement->bestFitBounds(details.newCube):" << entityTreeElement->bestFitBounds(details.newCube);
qCDebug(entities) << " details.entity:" << details.entity->getID(); qCDebug(entities) << " details.entity:" << details.entity->getEntityItemID();
qCDebug(entities) << " details.oldContainingElementCube:" << details.oldContainingElementCube; qCDebug(entities) << " details.oldContainingElementCube:" << details.oldContainingElementCube;
qCDebug(entities) << " entityTreeElement:" << entityTreeElement; qCDebug(entities) << " entityTreeElement:" << entityTreeElement;
qCDebug(entities) << " details.newCube:" << details.newCube; qCDebug(entities) << " details.newCube:" << details.newCube;
@ -193,7 +193,7 @@ bool MovingEntitiesOperator::preRecursion(OctreeElement* element) {
// If this element is the best fit for the new bounds of this entity then add the entity to the element // If this element is the best fit for the new bounds of this entity then add the entity to the element
if (!details.newFound && entityTreeElement->bestFitBounds(details.newCube)) { if (!details.newFound && entityTreeElement->bestFitBounds(details.newCube)) {
QUuid entityItemID = details.entity->getID(); EntityItemID entityItemID = details.entity->getEntityItemID();
// remove from the old before adding // remove from the old before adding
EntityTreeElement* oldElement = details.entity->getElement(); EntityTreeElement* oldElement = details.entity->getElement();
if (oldElement != entityTreeElement) { if (oldElement != entityTreeElement) {