From 981ac2ce7dc9fe3698adefe449fd6ffcb7fc1979 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 2 Jun 2015 13:17:15 -0700 Subject: [PATCH 01/49] quiet-compiler -- remove unused prototype for cleanupMenuItems --- libraries/script-engine/src/ScriptEngine.h | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/script-engine/src/ScriptEngine.h b/libraries/script-engine/src/ScriptEngine.h index 175eff059f..58ecf4adb2 100644 --- a/libraries/script-engine/src/ScriptEngine.h +++ b/libraries/script-engine/src/ScriptEngine.h @@ -54,7 +54,6 @@ public: bool setScriptContents(const QString& scriptContents, const QString& fileNameString = QString("")); const QString& getScriptName() const { return _scriptName; } - void cleanupMenuItems(); QScriptValue registerGlobalObject(const QString& name, QObject* object); /// registers a global object by name void registerGetterSetter(const QString& name, QScriptEngine::FunctionSignature getter, From a6fac2e7805a884a7ac0488efc057fee0604d75f Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 2 Jun 2015 13:17:47 -0700 Subject: [PATCH 02/49] quiet compiler -- remove unused variable --- interface/src/ui/ApplicationOverlay.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 8a64630266..d9d2a1d971 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -507,7 +507,6 @@ QPoint ApplicationOverlay::getPalmClickLocation(const PalmData *palm) const { QPoint rv; auto canvasSize = qApp->getCanvasSize(); if (qApp->isHMDMode()) { - float t; glm::vec2 polar = getPolarCoordinates(*palm); glm::vec2 point = sphericalToScreen(-polar); rv.rx() = point.x; From b24cd82b80a85eaff905c5d8abe790372787713a Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 2 Jun 2015 13:18:49 -0700 Subject: [PATCH 03/49] beginnings of ObjectAction class --- libraries/physics/src/ObjectAction.cpp | 21 +++++++++++++++ libraries/physics/src/ObjectAction.h | 37 ++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 libraries/physics/src/ObjectAction.cpp create mode 100644 libraries/physics/src/ObjectAction.h diff --git a/libraries/physics/src/ObjectAction.cpp b/libraries/physics/src/ObjectAction.cpp new file mode 100644 index 0000000000..635cd7eaf5 --- /dev/null +++ b/libraries/physics/src/ObjectAction.cpp @@ -0,0 +1,21 @@ +// +// ObjectAction.cpp +// libraries/physcis/src +// +// Created by Seth Alves 2015.6.2 +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "ObjectAction.h" + +ObjectAction::ObjectAction(EntityItemPointer ownerEntity) : + btActionInterface(), + _id(QUuid::createUuid()), + _ownerEntity(ownerEntity) { +} + +ObjectAction::~ObjectAction() { +} diff --git a/libraries/physics/src/ObjectAction.h b/libraries/physics/src/ObjectAction.h new file mode 100644 index 0000000000..cbe57a65c8 --- /dev/null +++ b/libraries/physics/src/ObjectAction.h @@ -0,0 +1,37 @@ +// +// ObjectAction.h +// libraries/physcis/src +// +// Created by Seth Alves 2015.6.2 +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_ObjectAction_h +#define hifi_ObjectAction_h + +#include + +#include + +#include + +// http://bulletphysics.org/Bullet/BulletFull/classbtActionInterface.html + +class ObjectAction : public btActionInterface { +public: + ObjectAction(EntityItemPointer ownerEntity); + virtual ~ObjectAction(); + + const QUuid& getID() const { return _id; } + + // virtual void updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep) = 0 + +private: + QUuid _id; + EntityItemPointer _ownerEntity; +}; + +#endif // hifi_ObjectAction_h From 100248c4e83985117e9ed80030bcf997c32bc496 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 2 Jun 2015 13:19:07 -0700 Subject: [PATCH 04/49] beginnings of ObjectAction class --- libraries/physics/src/PhysicsEngine.cpp | 20 ++++++++++++++++++++ libraries/physics/src/PhysicsEngine.h | 6 ++++++ 2 files changed, 26 insertions(+) diff --git a/libraries/physics/src/PhysicsEngine.cpp b/libraries/physics/src/PhysicsEngine.cpp index b622a37136..2e3a612e32 100644 --- a/libraries/physics/src/PhysicsEngine.cpp +++ b/libraries/physics/src/PhysicsEngine.cpp @@ -448,3 +448,23 @@ bool PhysicsEngine::getBodyLocation(void* physicsInfo, glm::vec3& positionReturn return true; } + + +QUuid PhysicsEngine::addAction(ObjectAction* action) { + const QUuid& actionID = action->getID(); + if (_objectActions.contains(actionID)) { + assert(_objectActions[actionID] == action); + return actionID; + } + _objectActions[actionID] = action; + // XXX add to bullet + return actionID; +} + + +void PhysicsEngine::deleteAction(const QUuid actionID) { + if (_objectActions.contains(actionID)) { + // XXX remove from bullet + _objectActions.remove(actionID); + } +} diff --git a/libraries/physics/src/PhysicsEngine.h b/libraries/physics/src/PhysicsEngine.h index 9ff85c9f11..c39a52fd6a 100644 --- a/libraries/physics/src/PhysicsEngine.h +++ b/libraries/physics/src/PhysicsEngine.h @@ -24,6 +24,7 @@ #include "DynamicCharacterController.h" #include "ObjectMotionState.h" #include "ThreadSafeDynamicsWorld.h" +#include "ObjectAction.h" const float HALF_SIMULATION_EXTENT = 512.0f; // meters @@ -94,6 +95,9 @@ public: static bool physicsInfoIsActive(void* physicsInfo); static bool getBodyLocation(void* physicsInfo, glm::vec3& positionReturn, glm::quat& rotationReturn); + QUuid addAction(ObjectAction* action); // PhysicsEngine takes ownership of the pointer + void deleteAction(QUuid actionID); + private: void removeContacts(ObjectMotionState* motionState); @@ -121,6 +125,8 @@ private: QUuid _sessionID; CollisionEvents _collisionEvents; + + QHash _objectActions; }; #endif // hifi_PhysicsEngine_h From d6549948d0b1f93108bb348470d316c10e998c30 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 2 Jun 2015 16:06:27 -0700 Subject: [PATCH 05/49] first pass at entity interface to actions --- .../entities/src/EntityActionInterface.h | 25 ++++++ libraries/entities/src/EntityItem.cpp | 44 +++++++++++ libraries/entities/src/EntityItem.h | 77 +++++++++++-------- libraries/entities/src/EntitySimulation.h | 4 + libraries/entities/src/EntityTree.h | 3 +- libraries/entities/src/EntityTreeElement.h | 1 + libraries/physics/src/ObjectAction.cpp | 21 ++++- libraries/physics/src/ObjectAction.h | 17 ++-- .../physics/src/PhysicalEntitySimulation.cpp | 17 ++++ .../physics/src/PhysicalEntitySimulation.h | 4 + libraries/physics/src/PhysicsEngine.cpp | 24 +++--- libraries/physics/src/PhysicsEngine.h | 5 +- 12 files changed, 189 insertions(+), 53 deletions(-) create mode 100644 libraries/entities/src/EntityActionInterface.h diff --git a/libraries/entities/src/EntityActionInterface.h b/libraries/entities/src/EntityActionInterface.h new file mode 100644 index 0000000000..4250c938c8 --- /dev/null +++ b/libraries/entities/src/EntityActionInterface.h @@ -0,0 +1,25 @@ +// +// EntityItem.h +// libraries/entities/src +// +// Created by Seth Alves on 2015-6-2 +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_EntityActionInterface_h +#define hifi_EntityActionInterface_h + +class EntityActionInterface { + public: + virtual ~EntityActionInterface(); + virtual const QUuid& getID() const = 0; + virtual const EntityItemPointer& getOwnerEntity() const = 0; + virtual void setOwnerEntity(const EntityItemPointer ownerEntity) = 0; + virtual QByteArray serialize() = 0; + static EntityActionInterface* deserialize(EntityItemPointer ownerEntity, QByteArray data); +}; + +#endif // hifi_EntityActionInterface_h diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index cc951ac16b..7edfbf83b9 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -25,6 +25,7 @@ #include "EntityItem.h" #include "EntitiesLogging.h" #include "EntityTree.h" +#include "EntitySimulation.h" bool EntityItem::_sendPhysicsUpdates = true; @@ -84,6 +85,7 @@ EntityItem::EntityItem(const EntityItemID& entityItemID, const EntityItemPropert EntityItem::~EntityItem() { // these pointers MUST be NULL at delete, else we probably have a dangling backpointer // to this EntityItem in the corresponding data structure. + clearActions(); assert(!_simulated); assert(!_element); assert(!_physicsInfo); @@ -1325,3 +1327,45 @@ void EntityItem::updateSimulatorID(const QUuid& value) { _dirtyFlags |= EntityItem::DIRTY_SIMULATOR_ID; } } + +void EntityItem::addAction(EntityActionInterface* action) { + assert(action); + const QUuid& actionID = action->getID(); + assert(!_objectActions.contains(actionID) || _objectActions[actionID] == action); + _objectActions[actionID] = action; + + assert (action->getOwnerEntity() == nullptr); + action->setOwnerEntity(EntityItemPointer(this)); + + const EntityTree* tree = _element->getTree(); + if (tree) { + EntitySimulation* simulation = tree->getSimulation(); + if (simulation) { + simulation->addAction(action); + } + } +} + +void EntityItem::removeAction(const QUuid actionID) { + if (_objectActions.contains(actionID)) { + const EntityActionInterface* action = _objectActions[actionID]; + _objectActions.remove(actionID); + + const EntityTree* tree = _element->getTree(); + if (tree) { + EntitySimulation* simulation = tree->getSimulation(); + if (simulation) { + simulation->removeAction(action->getID()); + } + } + + delete action; + } +} + +void EntityItem::clearActions() { + QHash::iterator i; + for (i = _objectActions.begin(); i != _objectActions.end(); ++i) { + removeAction(i.key()); + } +} diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index 6f9dc54e7a..88c87ed3e2 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -14,6 +14,8 @@ #include +#include + #include #include // for Animation, AnimationCache, and AnimationPointer classes @@ -23,9 +25,10 @@ #include #include -#include "EntityItemID.h" -#include "EntityItemProperties.h" -#include "EntityItemPropertiesDefaults.h" +#include "EntityItemID.h" +#include "EntityItemProperties.h" +#include "EntityItemPropertiesDefaults.h" +#include "EntityActionInterface.h" #include "EntityTypes.h" class EntitySimulation; @@ -88,7 +91,7 @@ public: }; DONT_ALLOW_INSTANTIATION // This class can not be instantiated directly - + EntityItem(const EntityItemID& entityItemID); EntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties); virtual ~EntityItem(); @@ -100,7 +103,7 @@ public: // methods for getting/setting all properties of an entity virtual EntityItemProperties getProperties() const; - + /// returns true if something changed virtual bool setProperties(const EntityItemProperties& properties); @@ -114,7 +117,7 @@ public: /// Last edited time of this entity universal usecs quint64 getLastEdited() const { return _lastEdited; } - void setLastEdited(quint64 lastEdited) + void setLastEdited(quint64 lastEdited) { _lastEdited = _lastUpdated = lastEdited; _changedOnServer = glm::max(lastEdited, _changedOnServer); } float getEditedAgo() const /// Elapsed seconds since this entity was last edited { return (float)(usecTimestampNow() - getLastEdited()) / (float)USECS_PER_SECOND; } @@ -128,26 +131,26 @@ public: // TODO: eventually only include properties changed since the params.lastViewFrustumSent time virtual EntityPropertyFlags getEntityProperties(EncodeBitstreamParams& params) const; - + virtual OctreeElement::AppendState appendEntityData(OctreePacketData* packetData, EncodeBitstreamParams& params, EntityTreeElementExtraEncodeData* entityTreeElementExtraEncodeData) const; - virtual void appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params, + virtual void appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params, EntityTreeElementExtraEncodeData* entityTreeElementExtraEncodeData, EntityPropertyFlags& requestedProperties, EntityPropertyFlags& propertyFlags, EntityPropertyFlags& propertiesDidntFit, - int& propertyCount, + int& propertyCount, OctreeElement::AppendState& appendState) const { /* do nothing*/ }; - static EntityItemID readEntityItemIDFromBuffer(const unsigned char* data, int bytesLeftToRead, + static EntityItemID readEntityItemIDFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args); virtual int readEntityDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args); - virtual int readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead, + virtual int readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args, - EntityPropertyFlags& propertyFlags, bool overwriteLocalData) + EntityPropertyFlags& propertyFlags, bool overwriteLocalData) { return 0; } virtual void render(RenderArgs* args) { } // by default entity items don't know how to render @@ -159,7 +162,7 @@ public: // perform update virtual void update(const quint64& now) { _lastUpdated = now; } quint64 getLastUpdated() const { return _lastUpdated; } - + // perform linear extrapolation for SimpleEntitySimulation void simulate(const quint64& now); void simulateKinematicMotion(float timeElapsed, bool setFlags=true); @@ -167,18 +170,18 @@ public: virtual bool needsToCallUpdate() const { return false; } virtual void debugDump() const; - + virtual bool supportsDetailedRayIntersection() const { return false; } virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, - bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face, + bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face, void** intersectedObject, bool precisionPicking) const { return true; } // attributes applicable to all entity types EntityTypes::EntityType getType() const { return _type; } const glm::vec3& getPosition() const { return _position; } /// get position in meters - - void setPosition(const glm::vec3& value) { - _position = value; + + void setPosition(const glm::vec3& value) { + _position = value; } glm::vec3 getCenter() const; @@ -214,7 +217,7 @@ public: const glm::vec3& getAcceleration() const { return _acceleration; } /// get acceleration in meters/second/second void setAcceleration(const glm::vec3& value) { _acceleration = value; } /// acceleration in meters/second/second bool hasAcceleration() const { return _acceleration != ENTITY_ITEM_ZERO_VEC3; } - + float getDamping() const { return _damping; } void setDamping(float value) { _damping = value; } @@ -233,7 +236,7 @@ public: /// is this entity mortal, in that it has a lifetime set, and will automatically be deleted when that lifetime expires bool isMortal() const { return _lifetime != ENTITY_ITEM_IMMORTAL_LIFETIME; } - + /// age of this entity in seconds float getAge() const { return (float)(usecTimestampNow() - _created) / (float)USECS_PER_SECOND; } bool lifetimeHasExpired() const; @@ -252,7 +255,7 @@ public: const glm::vec3& getRegistrationPoint() const { return _registrationPoint; } /// registration point as ratio of entity /// registration point as ratio of entity - void setRegistrationPoint(const glm::vec3& value) + void setRegistrationPoint(const glm::vec3& value) { _registrationPoint = glm::clamp(value, 0.0f, 1.0f); } const glm::vec3& getAngularVelocity() const { return _angularVelocity; } @@ -280,7 +283,7 @@ public: bool getLocked() const { return _locked; } void setLocked(bool value) { _locked = value; } - + const QString& getUserData() const { return _userData; } void setUserData(const QString& value) { _userData = value; } @@ -288,13 +291,13 @@ public: void setSimulatorID(const QUuid& value); void updateSimulatorID(const QUuid& value); quint64 getSimulatorIDChangedTime() const { return _simulatorIDChangedTime; } - + const QString& getMarketplaceID() const { return _marketplaceID; } void setMarketplaceID(const QString& value) { _marketplaceID = value; } - - // TODO: get rid of users of getRadius()... + + // TODO: get rid of users of getRadius()... float getRadius() const; - + virtual bool contains(const glm::vec3& point) const; virtual bool isReadyToComputeShape() { return true; } @@ -329,11 +332,11 @@ public: uint32_t getDirtyFlags() const { return _dirtyFlags; } void clearDirtyFlags(uint32_t mask = 0xffff) { _dirtyFlags &= ~mask; } - + bool isMoving() const; void* getPhysicsInfo() const { return _physicsInfo; } - + void setPhysicsInfo(void* data) { _physicsInfo = data; } EntityTreeElement* getElement() const { return _element; } @@ -349,12 +352,18 @@ public: void getAllTerseUpdateProperties(EntityItemProperties& properties) const; + void addAction(EntityActionInterface* actionID); + void removeAction(const QUuid actionID); + void clearActions(); + const QList getActionIDs() const { return _objectActions.keys(); } + protected: static bool _sendPhysicsUpdates; EntityTypes::EntityType _type; QUuid _id; - quint64 _lastSimulated; // last time this entity called simulate(), this includes velocity, angular velocity, and physics changes + quint64 _lastSimulated; // last time this entity called simulate(), this includes velocity, angular velocity, + // and physics changes quint64 _lastUpdated; // last time this entity called update(), this includes animations and non-physics changes quint64 _lastEdited; // last official local or remote edit time quint64 _lastBroadcast; // the last time we sent an edit packet about this entity @@ -405,12 +414,12 @@ protected: // // damping = 1 - exp(-1 / timescale) // - - // NOTE: Radius support is obsolete, but these private helper functions are available for this class to + + // NOTE: Radius support is obsolete, but these private helper functions are available for this class to // parse old data streams - + /// set radius in domain scale units (0.0 - 1.0) this will also reset dimensions to be equal for each axis - void setRadius(float value); + void setRadius(float value); // DirtyFlags are set whenever a property changes that the EntitySimulation needs to know about. uint32_t _dirtyFlags; // things that have changed from EXTERNAL changes (via script or packet) but NOT from simulation @@ -419,6 +428,8 @@ protected: EntityTreeElement* _element = nullptr; // set by EntityTreeElement void* _physicsInfo = nullptr; // set by EntitySimulation bool _simulated; // set by EntitySimulation + + QHash _objectActions; }; #endif // hifi_EntityItem_h diff --git a/libraries/entities/src/EntitySimulation.h b/libraries/entities/src/EntitySimulation.h index bce16ba1c2..fc0c6aa7e4 100644 --- a/libraries/entities/src/EntitySimulation.h +++ b/libraries/entities/src/EntitySimulation.h @@ -56,6 +56,10 @@ public: friend class EntityTree; + virtual void addAction(EntityActionInterface* action) {} + virtual void removeAction(const QUuid actionID) {} + virtual void removeActions(QList actionIDsToRemove) {} + protected: // these only called by the EntityTree? /// \param entity pointer to EntityItem to be added /// \sideeffect sets relevant backpointers in entity, but maybe later when appropriate data structures are locked diff --git a/libraries/entities/src/EntityTree.h b/libraries/entities/src/EntityTree.h index 0d99c8e82d..f8c06479ec 100644 --- a/libraries/entities/src/EntityTree.h +++ b/libraries/entities/src/EntityTree.h @@ -158,7 +158,8 @@ public: void emitEntityScriptChanging(const EntityItemID& entityItemID); void setSimulation(EntitySimulation* simulation); - + EntitySimulation* getSimulation() const { return _simulation; } + bool wantEditLogging() const { return _wantEditLogging; } void setWantEditLogging(bool value) { _wantEditLogging = value; } diff --git a/libraries/entities/src/EntityTreeElement.h b/libraries/entities/src/EntityTreeElement.h index 90fb035d7b..4caf996090 100644 --- a/libraries/entities/src/EntityTreeElement.h +++ b/libraries/entities/src/EntityTreeElement.h @@ -152,6 +152,7 @@ public: bool hasEntities() const { return _entityItems ? _entityItems->size() > 0 : false; } void setTree(EntityTree* tree) { _myTree = tree; } + const EntityTree* getTree() const { return _myTree; } bool updateEntity(const EntityItem& entity); void addEntityItem(EntityItemPointer entity); diff --git a/libraries/physics/src/ObjectAction.cpp b/libraries/physics/src/ObjectAction.cpp index 635cd7eaf5..78524c1f14 100644 --- a/libraries/physics/src/ObjectAction.cpp +++ b/libraries/physics/src/ObjectAction.cpp @@ -2,7 +2,7 @@ // ObjectAction.cpp // libraries/physcis/src // -// Created by Seth Alves 2015.6.2 +// Created by Seth Alves 2015-6-2 // Copyright 2015 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. @@ -11,11 +11,26 @@ #include "ObjectAction.h" -ObjectAction::ObjectAction(EntityItemPointer ownerEntity) : +ObjectAction::ObjectAction(QUuid id, EntityItemPointer ownerEntity) : btActionInterface(), - _id(QUuid::createUuid()), + _id(id), _ownerEntity(ownerEntity) { } +ObjectAction::ObjectAction(EntityItemPointer ownerEntity) : + ObjectAction(QUuid::createUuid(), ownerEntity) { +} + ObjectAction::~ObjectAction() { } + +void ObjectAction::updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep) { + qDebug() << "updateAction called"; +} + +EntityActionInterface* ObjectAction::deserialize(EntityItemPointer ownerEntity, QByteArray data) { + return new ObjectAction(ownerEntity); +} + +void ObjectAction::debugDraw(btIDebugDraw* debugDrawer) { +} diff --git a/libraries/physics/src/ObjectAction.h b/libraries/physics/src/ObjectAction.h index cbe57a65c8..d2504a09c2 100644 --- a/libraries/physics/src/ObjectAction.h +++ b/libraries/physics/src/ObjectAction.h @@ -2,12 +2,13 @@ // ObjectAction.h // libraries/physcis/src // -// Created by Seth Alves 2015.6.2 +// Created by Seth Alves 2015-6-2 // Copyright 2015 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +// http://bulletphysics.org/Bullet/BulletFull/classbtActionInterface.html #ifndef hifi_ObjectAction_h #define hifi_ObjectAction_h @@ -18,16 +19,22 @@ #include -// http://bulletphysics.org/Bullet/BulletFull/classbtActionInterface.html - -class ObjectAction : public btActionInterface { +class ObjectAction : public btActionInterface, public EntityActionInterface { public: + ObjectAction(QUuid id, EntityItemPointer ownerEntity); ObjectAction(EntityItemPointer ownerEntity); virtual ~ObjectAction(); const QUuid& getID() const { return _id; } + virtual const EntityItemPointer& getOwnerEntity() const { return _ownerEntity; } + virtual void setOwnerEntity(const EntityItemPointer ownerEntity) { _ownerEntity = ownerEntity; } - // virtual void updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep) = 0 + virtual void updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep); + + virtual QByteArray serialize() { return QByteArray(); } + static EntityActionInterface* deserialize(EntityItemPointer ownerEntity, QByteArray data); + + virtual void debugDraw(btIDebugDraw* debugDrawer); private: QUuid _id; diff --git a/libraries/physics/src/PhysicalEntitySimulation.cpp b/libraries/physics/src/PhysicalEntitySimulation.cpp index b615cf0c77..e5fe5d44a3 100644 --- a/libraries/physics/src/PhysicalEntitySimulation.cpp +++ b/libraries/physics/src/PhysicalEntitySimulation.cpp @@ -232,3 +232,20 @@ void PhysicalEntitySimulation::handleCollisionEvents(CollisionEvents& collisionE } } +void PhysicalEntitySimulation::addAction(EntityActionInterface* action) { + if (_physicsEngine) { + _physicsEngine->addAction(action); + } +} + +void PhysicalEntitySimulation::removeAction(const QUuid actionID) { + if (_physicsEngine) { + _physicsEngine->removeAction(actionID); + } +} + +void PhysicalEntitySimulation::removeActions(QList actionIDsToRemove) { + if (_physicsEngine) { + _physicsEngine->removeActions(actionIDsToRemove); + } +} diff --git a/libraries/physics/src/PhysicalEntitySimulation.h b/libraries/physics/src/PhysicalEntitySimulation.h index 1aae27962a..0c907f078c 100644 --- a/libraries/physics/src/PhysicalEntitySimulation.h +++ b/libraries/physics/src/PhysicalEntitySimulation.h @@ -32,6 +32,10 @@ public: void init(EntityTree* tree, PhysicsEngine* engine, EntityEditPacketSender* packetSender); + virtual void addAction(EntityActionInterface* action); + virtual void removeAction(const QUuid actionID); + virtual void removeActions(QList actionIDsToRemove); + protected: // only called by EntitySimulation // overrides for EntitySimulation virtual void updateEntitiesInternal(const quint64& now); diff --git a/libraries/physics/src/PhysicsEngine.cpp b/libraries/physics/src/PhysicsEngine.cpp index 2e3a612e32..9f843a052c 100644 --- a/libraries/physics/src/PhysicsEngine.cpp +++ b/libraries/physics/src/PhysicsEngine.cpp @@ -449,22 +449,28 @@ bool PhysicsEngine::getBodyLocation(void* physicsInfo, glm::vec3& positionReturn return true; } - -QUuid PhysicsEngine::addAction(ObjectAction* action) { +void PhysicsEngine::addAction(EntityActionInterface* action) { + assert(action); const QUuid& actionID = action->getID(); if (_objectActions.contains(actionID)) { assert(_objectActions[actionID] == action); - return actionID; + return; } - _objectActions[actionID] = action; - // XXX add to bullet - return actionID; + ObjectAction* objectAction = static_cast(action); + _objectActions[actionID] = objectAction; + _dynamicsWorld->addAction(objectAction); } - -void PhysicsEngine::deleteAction(const QUuid actionID) { +void PhysicsEngine::removeAction(const QUuid actionID) { if (_objectActions.contains(actionID)) { - // XXX remove from bullet + ObjectAction* action = _objectActions[actionID]; + _dynamicsWorld->removeAction(action); _objectActions.remove(actionID); } } + +void PhysicsEngine::removeActions(QList actionIDsToRemove) { + foreach(QUuid actionID, actionIDsToRemove) { + removeAction(actionID); + } +} diff --git a/libraries/physics/src/PhysicsEngine.h b/libraries/physics/src/PhysicsEngine.h index c39a52fd6a..085b51d224 100644 --- a/libraries/physics/src/PhysicsEngine.h +++ b/libraries/physics/src/PhysicsEngine.h @@ -95,8 +95,9 @@ public: static bool physicsInfoIsActive(void* physicsInfo); static bool getBodyLocation(void* physicsInfo, glm::vec3& positionReturn, glm::quat& rotationReturn); - QUuid addAction(ObjectAction* action); // PhysicsEngine takes ownership of the pointer - void deleteAction(QUuid actionID); + void addAction(EntityActionInterface* action); + void removeAction(const QUuid actionID); + void removeActions(QList actionIDsToRemove); private: void removeContacts(ObjectMotionState* motionState); From a31a5a155405c3ccce10f6c98f8d5d4b915783bb Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 2 Jun 2015 19:40:20 -0700 Subject: [PATCH 06/49] main actions interface is in EntityItem. changes in actions are queued up and applied before simulation step --- interface/src/Application.cpp | 14 ++++++---- libraries/entities/src/EntityItem.cpp | 2 -- libraries/entities/src/EntitySimulation.h | 3 +- .../physics/src/PhysicalEntitySimulation.cpp | 28 ++++++++++++++----- .../physics/src/PhysicalEntitySimulation.h | 4 +++ libraries/physics/src/PhysicsEngine.cpp | 7 +---- libraries/physics/src/PhysicsEngine.h | 1 - 7 files changed, 37 insertions(+), 22 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 803955f02c..5e059fa2cb 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2461,8 +2461,9 @@ void Application::update(float deltaTime) { updateThreads(deltaTime); // If running non-threaded, then give the threads some time to process... - - DependencyManager::get()->updateOtherAvatars(deltaTime); //loop through all the other avatars and simulate them... + + //loop through all the other avatars and simulate them... + DependencyManager::get()->updateOtherAvatars(deltaTime); updateCamera(deltaTime); // handle various camera tweaks like off axis projection updateDialogs(deltaTime); // update various stats dialogs if present @@ -2476,6 +2477,7 @@ void Application::update(float deltaTime) { _physicsEngine.deleteObjects(_entitySimulation.getObjectsToDelete()); _physicsEngine.addObjects(_entitySimulation.getObjectsToAdd()); _physicsEngine.changeObjects(_entitySimulation.getObjectsToChange()); + _entitySimulation.applyActionChanges(); _entitySimulation.unlock(); AvatarManager* avatarManager = DependencyManager::get().data(); @@ -2498,7 +2500,8 @@ void Application::update(float deltaTime) { if (!_aboutToQuit) { PerformanceTimer perfTimer("entities"); - // Collision events (and their scripts) must not be handled when we're locked, above. (That would risk deadlock.) + // Collision events (and their scripts) must not be handled when we're locked, above. (That would risk + // deadlock.) _entitySimulation.handleCollisionEvents(collisionEvents); // NOTE: the _entities.update() call below will wait for lock // and will simulate entity motion (the EntityTree has been given an EntitySimulation). @@ -2511,11 +2514,12 @@ void Application::update(float deltaTime) { PerformanceTimer perfTimer("overlays"); _overlays.update(deltaTime); } - + { PerformanceTimer perfTimer("myAvatar"); updateMyAvatarLookAtPosition(); - DependencyManager::get()->updateMyAvatar(deltaTime); // Sample hardware, update view frustum if needed, and send avatar data to mixer/nodes + // Sample hardware, update view frustum if needed, and send avatar data to mixer/nodes + DependencyManager::get()->updateMyAvatar(deltaTime); } { diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index cbf8d57723..7887b286f0 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -1369,8 +1369,6 @@ void EntityItem::removeAction(const QUuid actionID) { simulation->removeAction(action->getID()); } } - - delete action; } } diff --git a/libraries/entities/src/EntitySimulation.h b/libraries/entities/src/EntitySimulation.h index fc0c6aa7e4..baf1736d2e 100644 --- a/libraries/entities/src/EntitySimulation.h +++ b/libraries/entities/src/EntitySimulation.h @@ -59,6 +59,7 @@ public: virtual void addAction(EntityActionInterface* action) {} virtual void removeAction(const QUuid actionID) {} virtual void removeActions(QList actionIDsToRemove) {} + virtual void applyActionChanges() {} protected: // these only called by the EntityTree? /// \param entity pointer to EntityItem to be added @@ -116,7 +117,7 @@ protected: SetOfEntities _entitiesToDelete; // entities simulation decided needed to be deleted (EntityTree will actually delete) SetOfEntities _simpleKinematicEntities; // entities undergoing non-colliding kinematic motion -private: + private: void moveSimpleKinematics(); }; diff --git a/libraries/physics/src/PhysicalEntitySimulation.cpp b/libraries/physics/src/PhysicalEntitySimulation.cpp index e5fe5d44a3..8cc9345e67 100644 --- a/libraries/physics/src/PhysicalEntitySimulation.cpp +++ b/libraries/physics/src/PhysicalEntitySimulation.cpp @@ -233,19 +233,33 @@ void PhysicalEntitySimulation::handleCollisionEvents(CollisionEvents& collisionE } void PhysicalEntitySimulation::addAction(EntityActionInterface* action) { - if (_physicsEngine) { - _physicsEngine->addAction(action); - } + // if (_physicsEngine) { + // _physicsEngine->addAction(action); + // } + _actionsToAdd += action; } void PhysicalEntitySimulation::removeAction(const QUuid actionID) { - if (_physicsEngine) { - _physicsEngine->removeAction(actionID); - } + // if (_physicsEngine) { + // _physicsEngine->removeAction(actionID); + // } + _actionsToRemove += actionID; } void PhysicalEntitySimulation::removeActions(QList actionIDsToRemove) { + // if (_physicsEngine) { + // _physicsEngine->removeActions(actionIDsToRemove); + // } + _actionsToRemove += actionIDsToRemove; +} + +void PhysicalEntitySimulation::applyActionChanges() { if (_physicsEngine) { - _physicsEngine->removeActions(actionIDsToRemove); + foreach (EntityActionInterface* actionToAdd, _actionsToAdd) { + _physicsEngine->addAction(actionToAdd); + } + foreach (QUuid actionToRemove, _actionsToRemove) { + _physicsEngine->removeAction(actionToRemove); + } } } diff --git a/libraries/physics/src/PhysicalEntitySimulation.h b/libraries/physics/src/PhysicalEntitySimulation.h index 0c907f078c..e57cd4326b 100644 --- a/libraries/physics/src/PhysicalEntitySimulation.h +++ b/libraries/physics/src/PhysicalEntitySimulation.h @@ -35,6 +35,7 @@ public: virtual void addAction(EntityActionInterface* action); virtual void removeAction(const QUuid actionID); virtual void removeActions(QList actionIDsToRemove); + virtual void applyActionChanges(); protected: // only called by EntitySimulation // overrides for EntitySimulation @@ -68,6 +69,9 @@ private: EntityEditPacketSender* _entityPacketSender = nullptr; uint32_t _lastStepSendPackets = 0; + + QList _actionsToAdd; + QList _actionsToRemove; }; #endif // hifi_PhysicalEntitySimulation_h diff --git a/libraries/physics/src/PhysicsEngine.cpp b/libraries/physics/src/PhysicsEngine.cpp index 9f843a052c..c572121d60 100644 --- a/libraries/physics/src/PhysicsEngine.cpp +++ b/libraries/physics/src/PhysicsEngine.cpp @@ -466,11 +466,6 @@ void PhysicsEngine::removeAction(const QUuid actionID) { ObjectAction* action = _objectActions[actionID]; _dynamicsWorld->removeAction(action); _objectActions.remove(actionID); - } -} - -void PhysicsEngine::removeActions(QList actionIDsToRemove) { - foreach(QUuid actionID, actionIDsToRemove) { - removeAction(actionID); + delete action; } } diff --git a/libraries/physics/src/PhysicsEngine.h b/libraries/physics/src/PhysicsEngine.h index 085b51d224..e009cac60f 100644 --- a/libraries/physics/src/PhysicsEngine.h +++ b/libraries/physics/src/PhysicsEngine.h @@ -97,7 +97,6 @@ public: void addAction(EntityActionInterface* action); void removeAction(const QUuid actionID); - void removeActions(QList actionIDsToRemove); private: void removeContacts(ObjectMotionState* motionState); From 1d0d002222223814caee7d29521e96bdbf2217fc Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 3 Jun 2015 09:10:42 -0700 Subject: [PATCH 07/49] clear out action change lists after applying them --- libraries/physics/src/PhysicalEntitySimulation.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/physics/src/PhysicalEntitySimulation.cpp b/libraries/physics/src/PhysicalEntitySimulation.cpp index 8cc9345e67..35762cbf03 100644 --- a/libraries/physics/src/PhysicalEntitySimulation.cpp +++ b/libraries/physics/src/PhysicalEntitySimulation.cpp @@ -258,8 +258,10 @@ void PhysicalEntitySimulation::applyActionChanges() { foreach (EntityActionInterface* actionToAdd, _actionsToAdd) { _physicsEngine->addAction(actionToAdd); } + _actionsToAdd.clear(); foreach (QUuid actionToRemove, _actionsToRemove) { _physicsEngine->removeAction(actionToRemove); } + _actionsToRemove.clear(); } } From 57c3a14b6ab319bb6ab0658e1f80c7eb65edfd43 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 3 Jun 2015 11:18:38 -0700 Subject: [PATCH 08/49] quiet compiler --- libraries/entities-renderer/src/RenderableLineEntityItem.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp index 1951b2592b..b8e0513d22 100644 --- a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp @@ -26,8 +26,6 @@ EntityItemPointer RenderableLineEntityItem::factory(const EntityItemID& entityID void RenderableLineEntityItem::render(RenderArgs* args) { PerformanceTimer perfTimer("RenderableLineEntityItem::render"); assert(getType() == EntityTypes::Line); - glm::vec3 position = getPosition(); - glm::vec3 dimensions = getDimensions(); glm::quat rotation = getRotation(); glm::vec4 lineColor(toGlm(getXColor()), getLocalRenderAlpha()); glPushMatrix(); From c8ab22c5174a8910d702e1763b71f3f3fd417442 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 3 Jun 2015 11:19:45 -0700 Subject: [PATCH 09/49] hook up entity-scripting-interface to actions --- .../entities/src/EntityActionInterface.h | 12 +++-- .../entities/src/EntityScriptingInterface.cpp | 46 +++++++++++++++---- .../entities/src/EntityScriptingInterface.h | 12 +++-- libraries/entities/src/EntitySimulation.h | 16 +++++-- libraries/physics/src/ObjectAction.cpp | 10 +--- libraries/physics/src/ObjectAction.h | 4 -- .../physics/src/ObjectActionPullToPoint.cpp | 24 ++++++++++ .../physics/src/ObjectActionPullToPoint.h | 31 +++++++++++++ .../physics/src/PhysicalEntitySimulation.cpp | 40 ++++++++-------- .../physics/src/PhysicalEntitySimulation.h | 10 ++-- 10 files changed, 143 insertions(+), 62 deletions(-) create mode 100644 libraries/physics/src/ObjectActionPullToPoint.cpp create mode 100644 libraries/physics/src/ObjectActionPullToPoint.h diff --git a/libraries/entities/src/EntityActionInterface.h b/libraries/entities/src/EntityActionInterface.h index 4250c938c8..d8bb19821c 100644 --- a/libraries/entities/src/EntityActionInterface.h +++ b/libraries/entities/src/EntityActionInterface.h @@ -12,14 +12,20 @@ #ifndef hifi_EntityActionInterface_h #define hifi_EntityActionInterface_h +enum EntityActionType { + ACTION_TYPE_NONE, + ACTION_TYPE_PULL_TO_POINT +}; + + class EntityActionInterface { public: - virtual ~EntityActionInterface(); + virtual ~EntityActionInterface() {}; virtual const QUuid& getID() const = 0; virtual const EntityItemPointer& getOwnerEntity() const = 0; virtual void setOwnerEntity(const EntityItemPointer ownerEntity) = 0; - virtual QByteArray serialize() = 0; - static EntityActionInterface* deserialize(EntityItemPointer ownerEntity, QByteArray data); + // virtual QByteArray serialize() = 0; + // static EntityActionInterface* deserialize(EntityItemPointer ownerEntity, QByteArray data); }; #endif // hifi_EntityActionInterface_h diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 6866505d58..739665194e 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -11,13 +11,14 @@ #include -#include "EntityScriptingInterface.h" #include "EntityTree.h" #include "LightEntityItem.h" #include "ModelEntityItem.h" #include "ZoneEntityItem.h" #include "EntitiesLogging.h" +#include "EntitySimulation.h" +#include "EntityScriptingInterface.h" EntityScriptingInterface::EntityScriptingInterface() : _entityTree(NULL) @@ -83,7 +84,8 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties entity->setLastBroadcast(usecTimestampNow()); // This Node is creating a new object. If it's in motion, set this Node as the simulator. bidForSimulationOwnership(propertiesWithSimID); - entity->setSimulatorID(propertiesWithSimID.getSimulatorID()); // and make note of it now, so we can act on it right away. + // and make note of it now, so we can act on it right away. + entity->setSimulatorID(propertiesWithSimID.getSimulatorID()); } else { qCDebug(entities) << "script failed to add new Entity to local Octree"; success = false; @@ -105,7 +107,7 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identit _entityTree->lockForRead(); EntityItemPointer entity = _entityTree->findEntityByEntityItemID(EntityItemID(identity)); - + if (entity) { results = entity->getProperties(); @@ -124,7 +126,7 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identit } _entityTree->unlock(); } - + return results; } @@ -220,7 +222,7 @@ QVector EntityScriptingInterface::findEntities(const glm::vec3& center, f QVector entities; _entityTree->findEntities(center, radius, entities); _entityTree->unlock(); - + foreach (EntityItemPointer entity, entities) { result << entity->getEntityItemID(); } @@ -236,7 +238,7 @@ QVector EntityScriptingInterface::findEntitiesInBox(const glm::vec3& corn QVector entities; _entityTree->findEntities(box, entities); _entityTree->unlock(); - + foreach (EntityItemPointer entity, entities) { result << entity->getEntityItemID(); } @@ -393,7 +395,6 @@ void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, Ra } } - bool EntityScriptingInterface::setVoxels(QUuid entityID, std::function actor) { if (!_entityTree) { @@ -431,23 +432,48 @@ bool EntityScriptingInterface::setVoxels(QUuid entityID, return true; } - bool EntityScriptingInterface::setVoxelSphere(QUuid entityID, const glm::vec3& center, float radius, int value) { return setVoxels(entityID, [center, radius, value](PolyVoxEntityItem& polyVoxEntity) { polyVoxEntity.setSphere(center, radius, value); }); } - bool EntityScriptingInterface::setVoxel(QUuid entityID, const glm::vec3& position, int value) { return setVoxels(entityID, [position, value](PolyVoxEntityItem& polyVoxEntity) { polyVoxEntity.setVoxelInVolume(position, value); }); } - bool EntityScriptingInterface::setAllVoxels(QUuid entityID, int value) { return setVoxels(entityID, [value](PolyVoxEntityItem& polyVoxEntity) { polyVoxEntity.setAll(value); }); } + +QUuid EntityScriptingInterface::addActionPullToPoint(QUuid entityID, const glm::vec3& target) { + if (!_entityTree) { + return QUuid(); + } + + _entityTree->lockForWrite(); + + EntitySimulation* simulation = _entityTree->getSimulation(); + QUuid actionID = QUuid::createUuid(); + EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID); + if (!entity) { + qDebug() << "addAction -- unknown entity" << entityID; + _entityTree->unlock(); + return QUuid(); + } + + QVariantMap arguments; + QVariantList targetList; + targetList << QVariant(target[0]) << QVariant(target[1]) << QVariant(target[2]); + arguments["target"] = targetList; + EntityActionInterface* action = simulation->actionFactory(ACTION_TYPE_PULL_TO_POINT, actionID, entity, arguments); + entity->addAction(action); + + _entityTree->unlock(); + + return actionID; +} diff --git a/libraries/entities/src/EntityScriptingInterface.h b/libraries/entities/src/EntityScriptingInterface.h index 7761effe2f..df42cb3375 100644 --- a/libraries/entities/src/EntityScriptingInterface.h +++ b/libraries/entities/src/EntityScriptingInterface.h @@ -54,14 +54,14 @@ class EntityScriptingInterface : public OctreeScriptingInterface, public Depende Q_OBJECT public: EntityScriptingInterface(); - + EntityEditPacketSender* getEntityPacketSender() const { return (EntityEditPacketSender*)getPacketSender(); } virtual NodeType_t getServerNodeType() const { return NodeType::EntityServer; } virtual OctreeEditPacketSender* createPacketSender() { return new EntityEditPacketSender(); } void setEntityTree(EntityTree* modelTree); EntityTree* getEntityTree(EntityTree*) { return _entityTree; } - + public slots: // returns true if the DomainServer will allow this Node/Avatar to make changes @@ -88,11 +88,11 @@ public slots: /// 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 Q_INVOKABLE QUuid findClosestEntity(const glm::vec3& center, float radius) const; - + /// 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 Q_INVOKABLE QVector findEntities(const glm::vec3& center, float radius) const; - + /// 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 Q_INVOKABLE QVector findEntitiesInBox(const glm::vec3& corner, const glm::vec3& dimensions) const; @@ -118,13 +118,14 @@ public slots: Q_INVOKABLE void setSendPhysicsUpdates(bool value); Q_INVOKABLE bool getSendPhysicsUpdates() const; - bool setVoxels(QUuid entityID, std::function actor); Q_INVOKABLE bool setVoxelSphere(QUuid entityID, const glm::vec3& center, float radius, int value); Q_INVOKABLE bool setVoxel(QUuid entityID, const glm::vec3& position, int value); Q_INVOKABLE bool setAllVoxels(QUuid entityID, int value); Q_INVOKABLE void dumpTree() const; + Q_INVOKABLE QUuid addActionPullToPoint(QUuid entityID, const glm::vec3& target); + signals: void entityCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision); void collisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision); @@ -152,6 +153,7 @@ signals: void clearingEntities(); private: + bool setVoxels(QUuid entityID, std::function actor); void queueEntityMessage(PacketType packetType, EntityItemID entityID, const EntityItemProperties& properties); /// actually does the work of finding the ray intersection, can be called in locking mode or tryLock mode diff --git a/libraries/entities/src/EntitySimulation.h b/libraries/entities/src/EntitySimulation.h index baf1736d2e..178d5e1358 100644 --- a/libraries/entities/src/EntitySimulation.h +++ b/libraries/entities/src/EntitySimulation.h @@ -56,10 +56,14 @@ public: friend class EntityTree; - virtual void addAction(EntityActionInterface* action) {} - virtual void removeAction(const QUuid actionID) {} - virtual void removeActions(QList actionIDsToRemove) {} - virtual void applyActionChanges() {} + virtual EntityActionInterface* actionFactory(EntityActionType type, + QUuid id, + EntityItemPointer ownerEntity, + QVariantMap arguments) { return nullptr; } + virtual void addAction(EntityActionInterface* action) { _actionsToAdd += action; } + virtual void removeAction(const QUuid actionID) { _actionsToRemove += actionID; } + virtual void removeActions(QList actionIDsToRemove) { _actionsToRemove += actionIDsToRemove; } + virtual void applyActionChanges() { _actionsToAdd.clear(); _actionsToRemove.clear(); } protected: // these only called by the EntityTree? /// \param entity pointer to EntityItem to be added @@ -119,6 +123,10 @@ protected: private: void moveSimpleKinematics(); + + protected: + QList _actionsToAdd; + QList _actionsToRemove; }; #endif // hifi_EntitySimulation_h diff --git a/libraries/physics/src/ObjectAction.cpp b/libraries/physics/src/ObjectAction.cpp index 78524c1f14..cb27f36248 100644 --- a/libraries/physics/src/ObjectAction.cpp +++ b/libraries/physics/src/ObjectAction.cpp @@ -17,19 +17,11 @@ ObjectAction::ObjectAction(QUuid id, EntityItemPointer ownerEntity) : _ownerEntity(ownerEntity) { } -ObjectAction::ObjectAction(EntityItemPointer ownerEntity) : - ObjectAction(QUuid::createUuid(), ownerEntity) { -} - ObjectAction::~ObjectAction() { } void ObjectAction::updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep) { - qDebug() << "updateAction called"; -} - -EntityActionInterface* ObjectAction::deserialize(EntityItemPointer ownerEntity, QByteArray data) { - return new ObjectAction(ownerEntity); + qDebug() << "ObjectAction::updateAction called"; } void ObjectAction::debugDraw(btIDebugDraw* debugDrawer) { diff --git a/libraries/physics/src/ObjectAction.h b/libraries/physics/src/ObjectAction.h index d2504a09c2..8ee4ed4faf 100644 --- a/libraries/physics/src/ObjectAction.h +++ b/libraries/physics/src/ObjectAction.h @@ -22,7 +22,6 @@ class ObjectAction : public btActionInterface, public EntityActionInterface { public: ObjectAction(QUuid id, EntityItemPointer ownerEntity); - ObjectAction(EntityItemPointer ownerEntity); virtual ~ObjectAction(); const QUuid& getID() const { return _id; } @@ -31,9 +30,6 @@ public: virtual void updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep); - virtual QByteArray serialize() { return QByteArray(); } - static EntityActionInterface* deserialize(EntityItemPointer ownerEntity, QByteArray data); - virtual void debugDraw(btIDebugDraw* debugDrawer); private: diff --git a/libraries/physics/src/ObjectActionPullToPoint.cpp b/libraries/physics/src/ObjectActionPullToPoint.cpp new file mode 100644 index 0000000000..eebf5c3608 --- /dev/null +++ b/libraries/physics/src/ObjectActionPullToPoint.cpp @@ -0,0 +1,24 @@ +// +// ObjectActionPullToPoint.cpp +// libraries/physics/src +// +// Created by Seth Alves 2015-6-2 +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "ObjectActionPullToPoint.h" + +ObjectActionPullToPoint::ObjectActionPullToPoint(QUuid id, EntityItemPointer ownerEntity, glm::vec3 target) : + ObjectAction(id, ownerEntity), + _target(target) { +} + +ObjectActionPullToPoint::~ObjectActionPullToPoint() { +} + +void ObjectActionPullToPoint::updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep) { + qDebug() << "ObjectActionPullToPoint::updateAction called"; +} diff --git a/libraries/physics/src/ObjectActionPullToPoint.h b/libraries/physics/src/ObjectActionPullToPoint.h new file mode 100644 index 0000000000..a090a2f134 --- /dev/null +++ b/libraries/physics/src/ObjectActionPullToPoint.h @@ -0,0 +1,31 @@ +// +// ObjectActionPullToPoint.h +// libraries/physics/src +// +// Created by Seth Alves 2015-6-3 +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_ObjectActionPullToPoint_h +#define hifi_ObjectActionPullToPoint_h + +#include + +#include +#include "ObjectAction.h" + +class ObjectActionPullToPoint : public ObjectAction { +public: + ObjectActionPullToPoint(QUuid id, EntityItemPointer ownerEntity, glm::vec3 target); + virtual ~ObjectActionPullToPoint(); + + void updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep); + +private: + glm::vec3 _target; +}; + +#endif // hifi_ObjectActionPullToPoint_h diff --git a/libraries/physics/src/PhysicalEntitySimulation.cpp b/libraries/physics/src/PhysicalEntitySimulation.cpp index 35762cbf03..a75f897c24 100644 --- a/libraries/physics/src/PhysicalEntitySimulation.cpp +++ b/libraries/physics/src/PhysicalEntitySimulation.cpp @@ -9,10 +9,12 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "PhysicalEntitySimulation.h" #include "PhysicsHelpers.h" #include "PhysicsLogging.h" #include "ShapeManager.h" +#include "ObjectActionPullToPoint.h" + +#include "PhysicalEntitySimulation.h" PhysicalEntitySimulation::PhysicalEntitySimulation() { } @@ -232,25 +234,22 @@ void PhysicalEntitySimulation::handleCollisionEvents(CollisionEvents& collisionE } } -void PhysicalEntitySimulation::addAction(EntityActionInterface* action) { - // if (_physicsEngine) { - // _physicsEngine->addAction(action); - // } - _actionsToAdd += action; -} +EntityActionInterface* PhysicalEntitySimulation::actionFactory(EntityActionType type, + QUuid id, + EntityItemPointer ownerEntity, + QVariantMap arguments) { + switch (type) { + case ACTION_TYPE_NONE: + assert(false); + return nullptr; + case ACTION_TYPE_PULL_TO_POINT: + QVariantList target = arguments["target"].toList(); + glm::vec3 glmTarget(target[0].toFloat(), target[1].toFloat(), target[2].toFloat()); + return (EntityActionInterface*) new ObjectActionPullToPoint(id, ownerEntity, glmTarget); + } -void PhysicalEntitySimulation::removeAction(const QUuid actionID) { - // if (_physicsEngine) { - // _physicsEngine->removeAction(actionID); - // } - _actionsToRemove += actionID; -} - -void PhysicalEntitySimulation::removeActions(QList actionIDsToRemove) { - // if (_physicsEngine) { - // _physicsEngine->removeActions(actionIDsToRemove); - // } - _actionsToRemove += actionIDsToRemove; + assert(false); + return nullptr; } void PhysicalEntitySimulation::applyActionChanges() { @@ -258,10 +257,9 @@ void PhysicalEntitySimulation::applyActionChanges() { foreach (EntityActionInterface* actionToAdd, _actionsToAdd) { _physicsEngine->addAction(actionToAdd); } - _actionsToAdd.clear(); foreach (QUuid actionToRemove, _actionsToRemove) { _physicsEngine->removeAction(actionToRemove); } - _actionsToRemove.clear(); } + EntitySimulation::applyActionChanges(); } diff --git a/libraries/physics/src/PhysicalEntitySimulation.h b/libraries/physics/src/PhysicalEntitySimulation.h index e57cd4326b..6195271ce9 100644 --- a/libraries/physics/src/PhysicalEntitySimulation.h +++ b/libraries/physics/src/PhysicalEntitySimulation.h @@ -32,9 +32,10 @@ public: void init(EntityTree* tree, PhysicsEngine* engine, EntityEditPacketSender* packetSender); - virtual void addAction(EntityActionInterface* action); - virtual void removeAction(const QUuid actionID); - virtual void removeActions(QList actionIDsToRemove); + virtual EntityActionInterface* actionFactory(EntityActionType type, + QUuid id, + EntityItemPointer ownerEntity, + QVariantMap arguments); virtual void applyActionChanges(); protected: // only called by EntitySimulation @@ -69,9 +70,6 @@ private: EntityEditPacketSender* _entityPacketSender = nullptr; uint32_t _lastStepSendPackets = 0; - - QList _actionsToAdd; - QList _actionsToRemove; }; #endif // hifi_PhysicalEntitySimulation_h From 9861e8afcc040bd21b7729cf94dc6eb198715030 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 3 Jun 2015 11:47:42 -0700 Subject: [PATCH 10/49] adjust assert --- libraries/entities/src/EntityItem.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 7887b286f0..f953c76d4d 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -1345,8 +1345,9 @@ void EntityItem::addAction(EntityActionInterface* action) { assert(!_objectActions.contains(actionID) || _objectActions[actionID] == action); _objectActions[actionID] = action; - assert (action->getOwnerEntity() == nullptr); - action->setOwnerEntity(EntityItemPointer(this)); + EntityItemPointer thisEntity(this); + assert(action->getOwnerEntity() == nullptr || action->getOwnerEntity() == thisEntity); + action->setOwnerEntity(thisEntity); const EntityTree* tree = _element->getTree(); if (tree) { From d634663bb1715c330aa3d006a12a517d9541870c Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 3 Jun 2015 17:33:55 -0700 Subject: [PATCH 11/49] simple action is working. destructor sequense is still suspicous --- .../entities/src/DeleteEntityOperator.cpp | 1 + .../entities/src/EntityActionInterface.h | 7 ++- libraries/entities/src/EntityItem.cpp | 51 ++++++++++--------- libraries/entities/src/EntityItem.h | 5 +- .../entities/src/EntityScriptingInterface.cpp | 3 +- .../entities/src/EntityScriptingInterface.h | 2 +- libraries/entities/src/EntitySimulation.h | 6 +-- libraries/entities/src/EntityTree.cpp | 2 +- libraries/entities/src/EntityTreeElement.h | 10 ++-- .../src/DynamicCharacterController.cpp | 2 +- libraries/physics/src/ObjectAction.cpp | 10 ++++ libraries/physics/src/ObjectAction.h | 5 ++ .../physics/src/ObjectActionPullToPoint.cpp | 30 +++++++++-- .../physics/src/ObjectActionPullToPoint.h | 3 +- .../physics/src/PhysicalEntitySimulation.cpp | 3 +- 15 files changed, 96 insertions(+), 44 deletions(-) diff --git a/libraries/entities/src/DeleteEntityOperator.cpp b/libraries/entities/src/DeleteEntityOperator.cpp index 051accc732..81230adc0f 100644 --- a/libraries/entities/src/DeleteEntityOperator.cpp +++ b/libraries/entities/src/DeleteEntityOperator.cpp @@ -46,6 +46,7 @@ void DeleteEntityOperator::addEntityIDToDeleteList(const EntityItemID& searchEnt //assert(false); qCDebug(entities) << "that's UNEXPECTED, we got a _containingElement, but couldn't find the oldEntity!"; } else { + details.entity->clearActions(); details.cube = details.containingElement->getAACube(); _entitiesToDelete << details; _lookingCount++; diff --git a/libraries/entities/src/EntityActionInterface.h b/libraries/entities/src/EntityActionInterface.h index d8bb19821c..69c9fda40a 100644 --- a/libraries/entities/src/EntityActionInterface.h +++ b/libraries/entities/src/EntityActionInterface.h @@ -12,6 +12,8 @@ #ifndef hifi_EntityActionInterface_h #define hifi_EntityActionInterface_h +class EntitySimulation; + enum EntityActionType { ACTION_TYPE_NONE, ACTION_TYPE_PULL_TO_POINT @@ -20,8 +22,11 @@ enum EntityActionType { class EntityActionInterface { public: - virtual ~EntityActionInterface() {}; + EntityActionInterface() { qDebug() << "EntityActionInterface::EntityActionInterface"; } + virtual ~EntityActionInterface() { qDebug() << "EntityActionInterface::~EntityActionInterface"; } virtual const QUuid& getID() const = 0; + virtual void setSimulation(EntitySimulation* simulation) = 0; + virtual void removeFromSimulation() const = 0; virtual const EntityItemPointer& getOwnerEntity() const = 0; virtual void setOwnerEntity(const EntityItemPointer ownerEntity) = 0; // virtual QByteArray serialize() = 0; diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index f953c76d4d..0f3da29ed2 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -83,9 +83,10 @@ EntityItem::EntityItem(const EntityItemID& entityItemID, const EntityItemPropert } EntityItem::~EntityItem() { + qDebug() << "EntityItem::~EntityItem" << _objectActions.size() << _name; + clearActions(); // these pointers MUST be NULL at delete, else we probably have a dangling backpointer // to this EntityItem in the corresponding data structure. - clearActions(); assert(!_simulated); assert(!_element); assert(!_physicsInfo); @@ -1339,43 +1340,47 @@ void EntityItem::updateSimulatorID(const QUuid& value) { } } -void EntityItem::addAction(EntityActionInterface* action) { +bool EntityItem::addAction(EntityActionInterface* action) { assert(action); const QUuid& actionID = action->getID(); assert(!_objectActions.contains(actionID) || _objectActions[actionID] == action); + qDebug() << "SETTING" << actionID << "in EntityItem::addAction" << _name; _objectActions[actionID] = action; - EntityItemPointer thisEntity(this); - assert(action->getOwnerEntity() == nullptr || action->getOwnerEntity() == thisEntity); - action->setOwnerEntity(thisEntity); - - const EntityTree* tree = _element->getTree(); - if (tree) { - EntitySimulation* simulation = tree->getSimulation(); - if (simulation) { - simulation->addAction(action); - } - } -} - -void EntityItem::removeAction(const QUuid actionID) { - if (_objectActions.contains(actionID)) { - const EntityActionInterface* action = _objectActions[actionID]; - _objectActions.remove(actionID); + assert(action->getOwnerEntity().get() == this); + if (_element) { const EntityTree* tree = _element->getTree(); if (tree) { EntitySimulation* simulation = tree->getSimulation(); if (simulation) { - simulation->removeAction(action->getID()); + simulation->addAction(action); + return true; } } } + + return false; +} + +void EntityItem::removeAction(const QUuid actionID) { + if (_objectActions.contains(actionID)) { + EntityActionInterface* action = _objectActions[actionID]; + qDebug() << "REMOVING" << actionID << "in EntityItem::removeAction" << _name; + _objectActions.remove(actionID); + action->setOwnerEntity(nullptr); + action->removeFromSimulation(); + } } void EntityItem::clearActions() { - QHash::iterator i; - for (i = _objectActions.begin(); i != _objectActions.end(); ++i) { - removeAction(i.key()); + QHash::iterator i = _objectActions.begin(); + while (i != _objectActions.end()) { + const QUuid id = i.key(); + EntityActionInterface* action = _objectActions[id]; + qDebug() << "ERASING" << id << "in EntityItem::clearActions" << _name; + i = _objectActions.erase(i); + action->setOwnerEntity(nullptr); + action->removeFromSimulation(); } } diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index e1d801a08d..a055060fdf 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -356,10 +356,9 @@ public: void getAllTerseUpdateProperties(EntityItemProperties& properties) const; - void addAction(EntityActionInterface* actionID); + bool addAction(EntityActionInterface* actionID); void removeAction(const QUuid actionID); void clearActions(); - const QList getActionIDs() const { return _objectActions.keys(); } protected: @@ -433,7 +432,7 @@ protected: void* _physicsInfo = nullptr; // set by EntitySimulation bool _simulated; // set by EntitySimulation - QHash _objectActions; + QHash _objectActions; }; #endif // hifi_EntityItem_h diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 739665194e..f14109ee05 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -450,7 +450,7 @@ bool EntityScriptingInterface::setAllVoxels(QUuid entityID, int value) { }); } -QUuid EntityScriptingInterface::addActionPullToPoint(QUuid entityID, const glm::vec3& target) { +QUuid EntityScriptingInterface::addActionPullToPoint(QUuid entityID, const glm::vec3& target, float speed) { if (!_entityTree) { return QUuid(); } @@ -470,6 +470,7 @@ QUuid EntityScriptingInterface::addActionPullToPoint(QUuid entityID, const glm:: QVariantList targetList; targetList << QVariant(target[0]) << QVariant(target[1]) << QVariant(target[2]); arguments["target"] = targetList; + arguments["speed"] = QVariant(speed); EntityActionInterface* action = simulation->actionFactory(ACTION_TYPE_PULL_TO_POINT, actionID, entity, arguments); entity->addAction(action); diff --git a/libraries/entities/src/EntityScriptingInterface.h b/libraries/entities/src/EntityScriptingInterface.h index df42cb3375..555cca14de 100644 --- a/libraries/entities/src/EntityScriptingInterface.h +++ b/libraries/entities/src/EntityScriptingInterface.h @@ -124,7 +124,7 @@ public slots: Q_INVOKABLE void dumpTree() const; - Q_INVOKABLE QUuid addActionPullToPoint(QUuid entityID, const glm::vec3& target); + Q_INVOKABLE QUuid addActionPullToPoint(QUuid entityID, const glm::vec3& target, float velocity); signals: void entityCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision); diff --git a/libraries/entities/src/EntitySimulation.h b/libraries/entities/src/EntitySimulation.h index 178d5e1358..c2d9f15880 100644 --- a/libraries/entities/src/EntitySimulation.h +++ b/libraries/entities/src/EntitySimulation.h @@ -24,9 +24,9 @@ typedef QSet SetOfEntities; typedef QVector VectorOfEntities; -// the EntitySimulation needs to know when these things change on an entity, +// the EntitySimulation needs to know when these things change on an entity, // so it can sort EntityItem or relay its state to the PhysicsEngine. -const int DIRTY_SIMULATION_FLAGS = +const int DIRTY_SIMULATION_FLAGS = EntityItem::DIRTY_POSITION | EntityItem::DIRTY_ROTATION | EntityItem::DIRTY_LINEAR_VELOCITY | @@ -60,7 +60,7 @@ public: QUuid id, EntityItemPointer ownerEntity, QVariantMap arguments) { return nullptr; } - virtual void addAction(EntityActionInterface* action) { _actionsToAdd += action; } + virtual void addAction(EntityActionInterface* action) { action->setSimulation(this); _actionsToAdd += action; } virtual void removeAction(const QUuid actionID) { _actionsToRemove += actionID; } virtual void removeActions(QList actionIDsToRemove) { _actionsToRemove += actionIDsToRemove; } virtual void applyActionChanges() { _actionsToAdd.clear(); _actionsToRemove.clear(); } diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index 937472820e..f50dd59234 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -279,7 +279,7 @@ void EntityTree::setSimulation(EntitySimulation* simulation) { if (simulation) { // assert that the simulation's backpointer has already been properly connected assert(simulation->getEntityTree() == this); - } + } if (_simulation && _simulation != simulation) { // It's important to clearEntities() on the simulation since taht will update each // EntityItem::_simulationState correctly so as to not confuse the next _simulation. diff --git a/libraries/entities/src/EntityTreeElement.h b/libraries/entities/src/EntityTreeElement.h index 4caf996090..589bf4033f 100644 --- a/libraries/entities/src/EntityTreeElement.h +++ b/libraries/entities/src/EntityTreeElement.h @@ -33,7 +33,7 @@ public: _totalItems(0), _movingItems(0) { } - + QList _movingEntities; int _totalElements; int _totalItems; @@ -42,8 +42,8 @@ public: class EntityTreeElementExtraEncodeData { public: - EntityTreeElementExtraEncodeData() : - elementCompleted(false), + EntityTreeElementExtraEncodeData() : + elementCompleted(false), subtreeCompleted(false), entities() { memset(childCompleted, 0, sizeof(childCompleted)); @@ -140,7 +140,7 @@ public: virtual bool canRayIntersect() const { return hasEntities(); } virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, - bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face, + bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face, void** intersectedObject, bool precisionPicking, float distanceToElementCube); virtual bool findSpherePenetration(const glm::vec3& center, float radius, @@ -148,7 +148,7 @@ public: const EntityItems& getEntities() const { return *_entityItems; } EntityItems& getEntities() { return *_entityItems; } - + bool hasEntities() const { return _entityItems ? _entityItems->size() > 0 : false; } void setTree(EntityTree* tree) { _myTree = tree; } diff --git a/libraries/physics/src/DynamicCharacterController.cpp b/libraries/physics/src/DynamicCharacterController.cpp index 5d2a1798f9..8ca27719ca 100644 --- a/libraries/physics/src/DynamicCharacterController.cpp +++ b/libraries/physics/src/DynamicCharacterController.cpp @@ -154,7 +154,7 @@ void DynamicCharacterController::playerStep(btCollisionWorld* dynaWorld, btScala velocityCorrection -= velocityCorrection.dot(_currentUp) * _currentUp; } _rigidBody->setLinearVelocity(actualVelocity + tau * velocityCorrection); - } + } } } diff --git a/libraries/physics/src/ObjectAction.cpp b/libraries/physics/src/ObjectAction.cpp index cb27f36248..705f528ec6 100644 --- a/libraries/physics/src/ObjectAction.cpp +++ b/libraries/physics/src/ObjectAction.cpp @@ -9,15 +9,19 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include "EntitySimulation.h" + #include "ObjectAction.h" ObjectAction::ObjectAction(QUuid id, EntityItemPointer ownerEntity) : btActionInterface(), _id(id), _ownerEntity(ownerEntity) { + qDebug() << "ObjectAction::ObjectAction"; } ObjectAction::~ObjectAction() { + qDebug() << "ObjectAction::~ObjectAction"; } void ObjectAction::updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep) { @@ -26,3 +30,9 @@ void ObjectAction::updateAction(btCollisionWorld* collisionWorld, btScalar delta void ObjectAction::debugDraw(btIDebugDraw* debugDrawer) { } + +void ObjectAction::removeFromSimulation() const { + if (_simulation) { + _simulation->removeAction(_id); + } +} diff --git a/libraries/physics/src/ObjectAction.h b/libraries/physics/src/ObjectAction.h index 8ee4ed4faf..309cf4dd1f 100644 --- a/libraries/physics/src/ObjectAction.h +++ b/libraries/physics/src/ObjectAction.h @@ -25,6 +25,8 @@ public: virtual ~ObjectAction(); const QUuid& getID() const { return _id; } + virtual void setSimulation(EntitySimulation* simulation) { _simulation = simulation; } + virtual void removeFromSimulation() const; virtual const EntityItemPointer& getOwnerEntity() const { return _ownerEntity; } virtual void setOwnerEntity(const EntityItemPointer ownerEntity) { _ownerEntity = ownerEntity; } @@ -34,7 +36,10 @@ public: private: QUuid _id; + +protected: EntityItemPointer _ownerEntity; + EntitySimulation* _simulation; }; #endif // hifi_ObjectAction_h diff --git a/libraries/physics/src/ObjectActionPullToPoint.cpp b/libraries/physics/src/ObjectActionPullToPoint.cpp index eebf5c3608..1772da5dda 100644 --- a/libraries/physics/src/ObjectActionPullToPoint.cpp +++ b/libraries/physics/src/ObjectActionPullToPoint.cpp @@ -9,16 +9,40 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include "ObjectMotionState.h" +#include "BulletUtil.h" + #include "ObjectActionPullToPoint.h" -ObjectActionPullToPoint::ObjectActionPullToPoint(QUuid id, EntityItemPointer ownerEntity, glm::vec3 target) : +ObjectActionPullToPoint::ObjectActionPullToPoint(QUuid id, EntityItemPointer ownerEntity, glm::vec3 target, float speed) : ObjectAction(id, ownerEntity), - _target(target) { + _target(target), + _speed(speed) { + qDebug() << "ObjectActionPullToPoint::ObjectActionPullToPoint"; } ObjectActionPullToPoint::~ObjectActionPullToPoint() { + qDebug() << "ObjectActionPullToPoint::~ObjectActionPullToPoint"; } void ObjectActionPullToPoint::updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep) { - qDebug() << "ObjectActionPullToPoint::updateAction called"; + glm::vec3 offset = _target - _ownerEntity->getPosition(); + + if (glm::length(offset) < IGNORE_POSITION_DELTA) { + offset = glm::vec3(0.0f, 0.0f, 0.0f); + } + + glm::vec3 newVelocity = glm::normalize(offset) * _speed; + + void* physicsInfo = _ownerEntity->getPhysicsInfo(); + if (physicsInfo) { + ObjectMotionState* motionState = static_cast(physicsInfo); + btRigidBody* rigidBody = motionState->getRigidBody(); + if (rigidBody) { + rigidBody->setLinearVelocity(glmToBullet(newVelocity)); + return; + } + } + + _ownerEntity->updateVelocity(newVelocity); } diff --git a/libraries/physics/src/ObjectActionPullToPoint.h b/libraries/physics/src/ObjectActionPullToPoint.h index a090a2f134..49526a8eb4 100644 --- a/libraries/physics/src/ObjectActionPullToPoint.h +++ b/libraries/physics/src/ObjectActionPullToPoint.h @@ -19,13 +19,14 @@ class ObjectActionPullToPoint : public ObjectAction { public: - ObjectActionPullToPoint(QUuid id, EntityItemPointer ownerEntity, glm::vec3 target); + ObjectActionPullToPoint(QUuid id, EntityItemPointer ownerEntity, glm::vec3 target, float speed); virtual ~ObjectActionPullToPoint(); void updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep); private: glm::vec3 _target; + float _speed; }; #endif // hifi_ObjectActionPullToPoint_h diff --git a/libraries/physics/src/PhysicalEntitySimulation.cpp b/libraries/physics/src/PhysicalEntitySimulation.cpp index a75f897c24..0d04c103de 100644 --- a/libraries/physics/src/PhysicalEntitySimulation.cpp +++ b/libraries/physics/src/PhysicalEntitySimulation.cpp @@ -245,7 +245,8 @@ EntityActionInterface* PhysicalEntitySimulation::actionFactory(EntityActionType case ACTION_TYPE_PULL_TO_POINT: QVariantList target = arguments["target"].toList(); glm::vec3 glmTarget(target[0].toFloat(), target[1].toFloat(), target[2].toFloat()); - return (EntityActionInterface*) new ObjectActionPullToPoint(id, ownerEntity, glmTarget); + float speed = arguments["speed"].toFloat(); + return (EntityActionInterface*) new ObjectActionPullToPoint(id, ownerEntity, glmTarget, speed); } assert(false); From 31bc106189b144195b57c0973351d3d99bad143f Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 3 Jun 2015 20:43:11 -0700 Subject: [PATCH 12/49] remove unneeded include --- libraries/entities/src/EntityItem.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index a055060fdf..4791fe38c3 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -14,8 +14,6 @@ #include -#include - #include #include // for Animation, AnimationCache, and AnimationPointer classes From 57d85cece067390a9592db06aa97de09195e2129 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 4 Jun 2015 09:41:32 -0700 Subject: [PATCH 13/49] get rid of simulation back-pointer in actions --- libraries/entities/src/DeleteEntityOperator.cpp | 8 +++++++- libraries/entities/src/EntityActionInterface.h | 3 +-- libraries/entities/src/EntityItem.cpp | 10 ++++------ libraries/entities/src/EntityItem.h | 4 ++-- libraries/entities/src/EntitySimulation.h | 2 +- libraries/physics/src/ObjectAction.cpp | 6 ++---- libraries/physics/src/ObjectAction.h | 4 +--- 7 files changed, 18 insertions(+), 19 deletions(-) diff --git a/libraries/entities/src/DeleteEntityOperator.cpp b/libraries/entities/src/DeleteEntityOperator.cpp index 81230adc0f..55db39c1bc 100644 --- a/libraries/entities/src/DeleteEntityOperator.cpp +++ b/libraries/entities/src/DeleteEntityOperator.cpp @@ -46,7 +46,13 @@ void DeleteEntityOperator::addEntityIDToDeleteList(const EntityItemID& searchEnt //assert(false); qCDebug(entities) << "that's UNEXPECTED, we got a _containingElement, but couldn't find the oldEntity!"; } else { - details.entity->clearActions(); + const EntityTree* tree = details.containingElement->getTree(); + if (tree) { + EntitySimulation* simulation = tree->getSimulation(); + if (simulation) { + details.entity->clearActions(simulation); + } + } details.cube = details.containingElement->getAACube(); _entitiesToDelete << details; _lookingCount++; diff --git a/libraries/entities/src/EntityActionInterface.h b/libraries/entities/src/EntityActionInterface.h index 69c9fda40a..dc80282d78 100644 --- a/libraries/entities/src/EntityActionInterface.h +++ b/libraries/entities/src/EntityActionInterface.h @@ -25,8 +25,7 @@ class EntityActionInterface { EntityActionInterface() { qDebug() << "EntityActionInterface::EntityActionInterface"; } virtual ~EntityActionInterface() { qDebug() << "EntityActionInterface::~EntityActionInterface"; } virtual const QUuid& getID() const = 0; - virtual void setSimulation(EntitySimulation* simulation) = 0; - virtual void removeFromSimulation() const = 0; + virtual void removeFromSimulation(EntitySimulation* simulation) const = 0; virtual const EntityItemPointer& getOwnerEntity() const = 0; virtual void setOwnerEntity(const EntityItemPointer ownerEntity) = 0; // virtual QByteArray serialize() = 0; diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 0f3da29ed2..10954cb4f5 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -83,8 +83,6 @@ EntityItem::EntityItem(const EntityItemID& entityItemID, const EntityItemPropert } EntityItem::~EntityItem() { - qDebug() << "EntityItem::~EntityItem" << _objectActions.size() << _name; - clearActions(); // these pointers MUST be NULL at delete, else we probably have a dangling backpointer // to this EntityItem in the corresponding data structure. assert(!_simulated); @@ -1363,17 +1361,17 @@ bool EntityItem::addAction(EntityActionInterface* action) { return false; } -void EntityItem::removeAction(const QUuid actionID) { +void EntityItem::removeAction(EntitySimulation* simulation, const QUuid actionID) { if (_objectActions.contains(actionID)) { EntityActionInterface* action = _objectActions[actionID]; qDebug() << "REMOVING" << actionID << "in EntityItem::removeAction" << _name; _objectActions.remove(actionID); action->setOwnerEntity(nullptr); - action->removeFromSimulation(); + action->removeFromSimulation(simulation); } } -void EntityItem::clearActions() { +void EntityItem::clearActions(EntitySimulation* simulation) { QHash::iterator i = _objectActions.begin(); while (i != _objectActions.end()) { const QUuid id = i.key(); @@ -1381,6 +1379,6 @@ void EntityItem::clearActions() { qDebug() << "ERASING" << id << "in EntityItem::clearActions" << _name; i = _objectActions.erase(i); action->setOwnerEntity(nullptr); - action->removeFromSimulation(); + action->removeFromSimulation(simulation); } } diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index 4791fe38c3..cf8a1fe584 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -355,8 +355,8 @@ public: void getAllTerseUpdateProperties(EntityItemProperties& properties) const; bool addAction(EntityActionInterface* actionID); - void removeAction(const QUuid actionID); - void clearActions(); + void removeAction(EntitySimulation* simulation, const QUuid actionID); + void clearActions(EntitySimulation* simulation); protected: diff --git a/libraries/entities/src/EntitySimulation.h b/libraries/entities/src/EntitySimulation.h index c2d9f15880..433107fa55 100644 --- a/libraries/entities/src/EntitySimulation.h +++ b/libraries/entities/src/EntitySimulation.h @@ -60,7 +60,7 @@ public: QUuid id, EntityItemPointer ownerEntity, QVariantMap arguments) { return nullptr; } - virtual void addAction(EntityActionInterface* action) { action->setSimulation(this); _actionsToAdd += action; } + virtual void addAction(EntityActionInterface* action) { _actionsToAdd += action; } virtual void removeAction(const QUuid actionID) { _actionsToRemove += actionID; } virtual void removeActions(QList actionIDsToRemove) { _actionsToRemove += actionIDsToRemove; } virtual void applyActionChanges() { _actionsToAdd.clear(); _actionsToRemove.clear(); } diff --git a/libraries/physics/src/ObjectAction.cpp b/libraries/physics/src/ObjectAction.cpp index 705f528ec6..deee870c6a 100644 --- a/libraries/physics/src/ObjectAction.cpp +++ b/libraries/physics/src/ObjectAction.cpp @@ -31,8 +31,6 @@ void ObjectAction::updateAction(btCollisionWorld* collisionWorld, btScalar delta void ObjectAction::debugDraw(btIDebugDraw* debugDrawer) { } -void ObjectAction::removeFromSimulation() const { - if (_simulation) { - _simulation->removeAction(_id); - } +void ObjectAction::removeFromSimulation(EntitySimulation* simulation) const { + simulation->removeAction(_id); } diff --git a/libraries/physics/src/ObjectAction.h b/libraries/physics/src/ObjectAction.h index 309cf4dd1f..e2794d8ca8 100644 --- a/libraries/physics/src/ObjectAction.h +++ b/libraries/physics/src/ObjectAction.h @@ -25,8 +25,7 @@ public: virtual ~ObjectAction(); const QUuid& getID() const { return _id; } - virtual void setSimulation(EntitySimulation* simulation) { _simulation = simulation; } - virtual void removeFromSimulation() const; + virtual void removeFromSimulation(EntitySimulation* simulation) const; virtual const EntityItemPointer& getOwnerEntity() const { return _ownerEntity; } virtual void setOwnerEntity(const EntityItemPointer ownerEntity) { _ownerEntity = ownerEntity; } @@ -39,7 +38,6 @@ private: protected: EntityItemPointer _ownerEntity; - EntitySimulation* _simulation; }; #endif // hifi_ObjectAction_h From 9cae11cc3c958e3beced774c7403027c07e88d12 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 4 Jun 2015 09:55:25 -0700 Subject: [PATCH 14/49] clean up actions when DeleteEntityOperator's list is processed rather than as it's made --- libraries/entities/src/DeleteEntityOperator.cpp | 7 ------- libraries/entities/src/EntityTree.cpp | 1 + 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/libraries/entities/src/DeleteEntityOperator.cpp b/libraries/entities/src/DeleteEntityOperator.cpp index 55db39c1bc..051accc732 100644 --- a/libraries/entities/src/DeleteEntityOperator.cpp +++ b/libraries/entities/src/DeleteEntityOperator.cpp @@ -46,13 +46,6 @@ void DeleteEntityOperator::addEntityIDToDeleteList(const EntityItemID& searchEnt //assert(false); qCDebug(entities) << "that's UNEXPECTED, we got a _containingElement, but couldn't find the oldEntity!"; } else { - const EntityTree* tree = details.containingElement->getTree(); - if (tree) { - EntitySimulation* simulation = tree->getSimulation(); - if (simulation) { - details.entity->clearActions(simulation); - } - } details.cube = details.containingElement->getAACube(); _entitiesToDelete << details; _lookingCount++; diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index f50dd59234..a827d01386 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -381,6 +381,7 @@ void EntityTree::processRemovedEntities(const DeleteEntityOperator& theOperator) } if (_simulation) { + theEntity->clearActions(_simulation); _simulation->removeEntity(theEntity); } } From 14026667f51d37b6b886f82aaee87516e1f06dc8 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 4 Jun 2015 10:55:32 -0700 Subject: [PATCH 15/49] script interface for creating an action now takes an action-type name rather than having a different call for each action --- .../entities/src/EntityActionInterface.cpp | 39 +++++++++++++++++++ .../entities/src/EntityActionInterface.h | 6 +++ libraries/entities/src/EntityItem.cpp | 13 +------ libraries/entities/src/EntityItem.h | 2 +- .../entities/src/EntityScriptingInterface.cpp | 27 ++++++++----- .../entities/src/EntityScriptingInterface.h | 2 +- libraries/entities/src/EntityTree.h | 26 ++++++------- libraries/entities/src/EntityTreeElement.h | 1 - .../physics/src/PhysicalEntitySimulation.cpp | 38 +++++++++++++++--- 9 files changed, 112 insertions(+), 42 deletions(-) create mode 100644 libraries/entities/src/EntityActionInterface.cpp diff --git a/libraries/entities/src/EntityActionInterface.cpp b/libraries/entities/src/EntityActionInterface.cpp new file mode 100644 index 0000000000..8a230f73d6 --- /dev/null +++ b/libraries/entities/src/EntityActionInterface.cpp @@ -0,0 +1,39 @@ +// +// EntityItem.h +// libraries/entities/src +// +// Created by Seth Alves on 2015-6-4 +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "EntityItem.h" + +#include "EntityActionInterface.h" + + +EntityActionType EntityActionInterface::actionTypeFromString(QString actionTypeString) { + QString normalizedActionTypeString = actionTypeString.toLower().remove('-').remove('_'); + if (normalizedActionTypeString == "none") { + return ACTION_TYPE_NONE; + } + if (normalizedActionTypeString == "pulltopoint") { + return ACTION_TYPE_PULL_TO_POINT; + } + + qDebug() << "Warning -- EntityActionInterface::actionTypeFromString got unknown action-type name" << actionTypeString; + return ACTION_TYPE_NONE; +} + +QString EntityActionInterface::actionTypeToString(EntityActionType actionType) { + switch(actionType) { + case ACTION_TYPE_NONE: + return "none"; + case ACTION_TYPE_PULL_TO_POINT: + return "pullToPoint"; + } + assert(false); + return "none"; +} diff --git a/libraries/entities/src/EntityActionInterface.h b/libraries/entities/src/EntityActionInterface.h index dc80282d78..72281fdc1d 100644 --- a/libraries/entities/src/EntityActionInterface.h +++ b/libraries/entities/src/EntityActionInterface.h @@ -12,9 +12,12 @@ #ifndef hifi_EntityActionInterface_h #define hifi_EntityActionInterface_h +#include + class EntitySimulation; enum EntityActionType { + // keep these synchronized with actionTypeFromString and actionTypeToString ACTION_TYPE_NONE, ACTION_TYPE_PULL_TO_POINT }; @@ -30,6 +33,9 @@ class EntityActionInterface { virtual void setOwnerEntity(const EntityItemPointer ownerEntity) = 0; // virtual QByteArray serialize() = 0; // static EntityActionInterface* deserialize(EntityItemPointer ownerEntity, QByteArray data); + + static EntityActionType actionTypeFromString(QString actionTypeString); + static QString actionTypeToString(EntityActionType actionType); }; #endif // hifi_EntityActionInterface_h diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 10954cb4f5..1a4c0fff63 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -1338,7 +1338,7 @@ void EntityItem::updateSimulatorID(const QUuid& value) { } } -bool EntityItem::addAction(EntityActionInterface* action) { +bool EntityItem::addAction(EntitySimulation* simulation, EntityActionInterface* action) { assert(action); const QUuid& actionID = action->getID(); assert(!_objectActions.contains(actionID) || _objectActions[actionID] == action); @@ -1347,16 +1347,7 @@ bool EntityItem::addAction(EntityActionInterface* action) { assert(action->getOwnerEntity().get() == this); - if (_element) { - const EntityTree* tree = _element->getTree(); - if (tree) { - EntitySimulation* simulation = tree->getSimulation(); - if (simulation) { - simulation->addAction(action); - return true; - } - } - } + simulation->addAction(action); return false; } diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index cf8a1fe584..5db3dd3d80 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -354,7 +354,7 @@ public: void getAllTerseUpdateProperties(EntityItemProperties& properties) const; - bool addAction(EntityActionInterface* actionID); + bool addAction(EntitySimulation* simulation, EntityActionInterface* actionID); void removeAction(EntitySimulation* simulation, const QUuid actionID); void clearActions(EntitySimulation* simulation); diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index f14109ee05..22b35b20b4 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -450,7 +450,7 @@ bool EntityScriptingInterface::setAllVoxels(QUuid entityID, int value) { }); } -QUuid EntityScriptingInterface::addActionPullToPoint(QUuid entityID, const glm::vec3& target, float speed) { +QUuid EntityScriptingInterface::addAction(QString actionTypeString, QUuid entityID, QVariantMap arguments) { if (!_entityTree) { return QUuid(); } @@ -466,15 +466,24 @@ QUuid EntityScriptingInterface::addActionPullToPoint(QUuid entityID, const glm:: return QUuid(); } - QVariantMap arguments; - QVariantList targetList; - targetList << QVariant(target[0]) << QVariant(target[1]) << QVariant(target[2]); - arguments["target"] = targetList; - arguments["speed"] = QVariant(speed); - EntityActionInterface* action = simulation->actionFactory(ACTION_TYPE_PULL_TO_POINT, actionID, entity, arguments); - entity->addAction(action); + if (!simulation) { + qDebug() << "addAction -- no simulation" << entityID; + _entityTree->unlock(); + return QUuid(); + } + EntityActionType actionType = EntityActionInterface::actionTypeFromString(actionTypeString); + + if (actionType == ACTION_TYPE_NONE) { + _entityTree->unlock(); + return QUuid(); + } + + EntityActionInterface* action = simulation->actionFactory(actionType, actionID, entity, arguments); _entityTree->unlock(); - return actionID; + if (action) { + return actionID; + } + return QUuid(); } diff --git a/libraries/entities/src/EntityScriptingInterface.h b/libraries/entities/src/EntityScriptingInterface.h index 555cca14de..d5646d8fd0 100644 --- a/libraries/entities/src/EntityScriptingInterface.h +++ b/libraries/entities/src/EntityScriptingInterface.h @@ -124,7 +124,7 @@ public slots: Q_INVOKABLE void dumpTree() const; - Q_INVOKABLE QUuid addActionPullToPoint(QUuid entityID, const glm::vec3& target, float velocity); + Q_INVOKABLE QUuid addAction(QString actionTypeString, QUuid entityID, QVariantMap arguments); signals: void entityCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision); diff --git a/libraries/entities/src/EntityTree.h b/libraries/entities/src/EntityTree.h index f8c06479ec..54a9193074 100644 --- a/libraries/entities/src/EntityTree.h +++ b/libraries/entities/src/EntityTree.h @@ -31,7 +31,7 @@ public: class EntityItemFBXService { public: virtual const FBXGeometry* getGeometryForEntity(EntityItemPointer entityItem) = 0; - virtual const Model* getModelForEntityItem(EntityItemPointer entityItem) = 0; + virtual const Model* getModelForEntityItem(EntityItemPointer entityItem) = 0; virtual const FBXGeometry* getCollisionGeometryForEntity(EntityItemPointer entityItem) = 0; }; @@ -63,23 +63,23 @@ public: // own definition. Implement these to allow your octree based server to support editing virtual bool getWantSVOfileVersions() const { return true; } virtual PacketType expectedDataPacketType() const { return PacketTypeEntityData; } - virtual bool canProcessVersion(PacketVersion thisVersion) const + virtual bool canProcessVersion(PacketVersion thisVersion) const { return thisVersion >= VERSION_ENTITIES_SUPPORT_SPLIT_MTU; } // we support all versions with split mtu virtual bool handlesEditPacketType(PacketType packetType) const; virtual int processEditPacketData(PacketType packetType, const unsigned char* packetData, int packetLength, const unsigned char* editData, int maxLength, const SharedNodePointer& senderNode); virtual bool rootElementHasData() const { return true; } - + // the root at least needs to store the number of entities in the packet/buffer virtual int minimumRequiredRootDataBytes() const { return sizeof(uint16_t); } virtual bool suppressEmptySubtrees() const { return false; } virtual void releaseSceneEncodeData(OctreeElementExtraEncodeData* extraEncodeData) const; virtual bool mustIncludeAllChildData() const { return false; } - virtual bool versionHasSVOfileBreaks(PacketVersion thisVersion) const + virtual bool versionHasSVOfileBreaks(PacketVersion thisVersion) const { return thisVersion >= VERSION_ENTITIES_HAS_FILE_BREAKS; } - + virtual void update(); // The newer API... @@ -111,13 +111,13 @@ public: /// \param foundEntities[out] vector of EntityItemPointer /// \remark Side effect: any initial contents in foundEntities will be lost void findEntities(const glm::vec3& center, float radius, QVector& foundEntities); - + /// finds all entities that touch a cube /// \param cube the query cube in world-frame (meters) /// \param foundEntities[out] vector of non-EntityItemPointer /// \remark Side effect: any initial contents in entities will be lost void findEntities(const AACube& cube, QVector& foundEntities); - + /// finds all entities that touch a box /// \param box the query box in world-frame (meters) /// \param foundEntities[out] vector of non-EntityItemPointer @@ -129,13 +129,13 @@ public: bool hasAnyDeletedEntities() const { return _recentlyDeletedEntityItemIDs.size() > 0; } bool hasEntitiesDeletedSince(quint64 sinceTime); - bool encodeEntitiesDeletedSince(OCTREE_PACKET_SEQUENCE sequenceNumber, quint64& sinceTime, + bool encodeEntitiesDeletedSince(OCTREE_PACKET_SEQUENCE sequenceNumber, quint64& sinceTime, unsigned char* packetData, size_t maxLength, size_t& outputLength); void forgetEntitiesDeletedBefore(quint64 sinceTime); int processEraseMessage(const QByteArray& dataByteArray, const SharedNodePointer& sourceNode); int processEraseMessageDetails(const QByteArray& dataByteArray, const SharedNodePointer& sourceNode); - + EntityItemFBXService* getFBXService() const { return _fbxService; } void setFBXService(EntityItemFBXService* service) { _fbxService = service; } const FBXGeometry* getGeometryForEntity(EntityItemPointer entityItem) { @@ -144,7 +144,7 @@ public: const Model* getModelForEntityItem(EntityItemPointer entityItem) { return _fbxService ? _fbxService->getModelForEntityItem(entityItem) : NULL; } - + EntityTreeElement* getContainingElement(const EntityItemID& entityItemID) /*const*/; void setContainingElement(const EntityItemID& entityItemID, EntityTreeElement* element); void debugDumpMap(); @@ -165,7 +165,7 @@ public: bool writeToMap(QVariantMap& entityDescription, OctreeElement* element, bool skipDefaultValues); bool readFromMap(QVariantMap& entityDescription); - + float getContentsLargestDimension(); signals: @@ -178,7 +178,7 @@ signals: private: void processRemovedEntities(const DeleteEntityOperator& theOperator); - bool updateEntityWithElement(EntityItemPointer entity, const EntityItemProperties& properties, + bool updateEntityWithElement(EntityItemPointer entity, const EntityItemProperties& properties, EntityTreeElement* containingElement, const SharedNodePointer& senderNode = SharedNodePointer(nullptr)); static bool findNearPointOperation(OctreeElement* element, void* extraData); @@ -199,7 +199,7 @@ private: QHash _entityToElementMap; EntitySimulation* _simulation; - + bool _wantEditLogging = false; void maybeNotifyNewCollisionSoundURL(const QString& oldCollisionSoundURL, const QString& newCollisionSoundURL); }; diff --git a/libraries/entities/src/EntityTreeElement.h b/libraries/entities/src/EntityTreeElement.h index 589bf4033f..2504f947bd 100644 --- a/libraries/entities/src/EntityTreeElement.h +++ b/libraries/entities/src/EntityTreeElement.h @@ -152,7 +152,6 @@ public: bool hasEntities() const { return _entityItems ? _entityItems->size() > 0 : false; } void setTree(EntityTree* tree) { _myTree = tree; } - const EntityTree* getTree() const { return _myTree; } bool updateEntity(const EntityItem& entity); void addEntityItem(EntityItemPointer entity); diff --git a/libraries/physics/src/PhysicalEntitySimulation.cpp b/libraries/physics/src/PhysicalEntitySimulation.cpp index 0d04c103de..5ad68ee7ab 100644 --- a/libraries/physics/src/PhysicalEntitySimulation.cpp +++ b/libraries/physics/src/PhysicalEntitySimulation.cpp @@ -238,19 +238,45 @@ EntityActionInterface* PhysicalEntitySimulation::actionFactory(EntityActionType QUuid id, EntityItemPointer ownerEntity, QVariantMap arguments) { + EntityActionInterface* action = nullptr; switch (type) { case ACTION_TYPE_NONE: - assert(false); return nullptr; case ACTION_TYPE_PULL_TO_POINT: - QVariantList target = arguments["target"].toList(); - glm::vec3 glmTarget(target[0].toFloat(), target[1].toFloat(), target[2].toFloat()); + if (!arguments.contains("target")) { + qDebug() << "PullToPoint action requires a `target' argument"; + return nullptr; + } + QVariant targetV = arguments["target"]; + if (targetV.type() != (QVariant::Type) QMetaType::QVariantMap) { + qDebug() << "PullToPoint argument `target' must be a map"; + return nullptr; + } + QVariantMap targetVM = targetV.toMap(); + if (!targetVM.contains("x") || !targetVM.contains("y") || !targetVM.contains("z")) { + qDebug() << "PullToPoint argument `target' must be a map with keys of x, y, z"; + return nullptr; + } + QVariant xV = targetVM["x"]; + QVariant yV = targetVM["y"]; + QVariant zV = targetVM["z"]; + bool xOk = true; + bool yOk = true; + bool zOk = true; + float x = xV.toFloat(&xOk); + float y = yV.toFloat(&yOk); + float z = zV.toFloat(&zOk); + if (!xOk || !yOk || !zOk) { + qDebug() << "PullToPoint argument `target' must be a map with keys of x, y, z and values of type float."; + } + glm::vec3 glmTarget(x, y, z); float speed = arguments["speed"].toFloat(); - return (EntityActionInterface*) new ObjectActionPullToPoint(id, ownerEntity, glmTarget, speed); + action = (EntityActionInterface*) new ObjectActionPullToPoint(id, ownerEntity, glmTarget, speed); } - assert(false); - return nullptr; + assert(action); + ownerEntity->addAction(this, action); + return action; } void PhysicalEntitySimulation::applyActionChanges() { From 8f19bad97d894c41b84db4911d5d99cbeff0e913 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 4 Jun 2015 11:39:15 -0700 Subject: [PATCH 16/49] pull argument extracting code into EntityActionInterface --- .../entities/src/EntityActionInterface.cpp | 62 +++++++++++++++++++ .../entities/src/EntityActionInterface.h | 3 + .../physics/src/PhysicalEntitySimulation.cpp | 39 +++--------- 3 files changed, 74 insertions(+), 30 deletions(-) diff --git a/libraries/entities/src/EntityActionInterface.cpp b/libraries/entities/src/EntityActionInterface.cpp index 8a230f73d6..8d848b356a 100644 --- a/libraries/entities/src/EntityActionInterface.cpp +++ b/libraries/entities/src/EntityActionInterface.cpp @@ -37,3 +37,65 @@ QString EntityActionInterface::actionTypeToString(EntityActionType actionType) { assert(false); return "none"; } + +glm::vec3 EntityActionInterface::extractVec3Argument(QString objectName, QVariantMap arguments, + QString argumentName, bool& ok) { + if (!arguments.contains(argumentName)) { + qDebug() << objectName << "requires argument:" << argumentName; + ok = false; + return vec3(); + } + + QVariant resultV = arguments[argumentName]; + if (resultV.type() != (QVariant::Type) QMetaType::QVariantMap) { + qDebug() << objectName << "argument" << argumentName << "must be a map"; + ok = false; + return vec3(); + } + + QVariantMap resultVM = resultV.toMap(); + if (!resultVM.contains("x") || !resultVM.contains("y") || !resultVM.contains("z")) { + qDebug() << objectName << "argument" << argumentName << "must be a map with keys of x, y, z"; + ok = false; + return vec3(); + } + + QVariant xV = resultVM["x"]; + QVariant yV = resultVM["y"]; + QVariant zV = resultVM["z"]; + + bool xOk = true; + bool yOk = true; + bool zOk = true; + float x = xV.toFloat(&xOk); + float y = yV.toFloat(&yOk); + float z = zV.toFloat(&zOk); + if (!xOk || !yOk || !zOk) { + qDebug() << objectName << "argument" << argumentName << "must be a map with keys of x, y, z and values of type float."; + ok = false; + return vec3(); + } + + return vec3(x, y, z); +} + + +float EntityActionInterface::extractFloatArgument(QString objectName, QVariantMap arguments, + QString argumentName, bool& ok) { + if (!arguments.contains(argumentName)) { + qDebug() << objectName << "requires argument:" << argumentName; + ok = false; + return 0.0f; + } + + QVariant vV = arguments[argumentName]; + bool vOk = true; + float v = vV.toFloat(&vOk); + + if (!vOk) { + ok = false; + return 0.0f; + } + + return v; +} diff --git a/libraries/entities/src/EntityActionInterface.h b/libraries/entities/src/EntityActionInterface.h index 72281fdc1d..6220fc19ed 100644 --- a/libraries/entities/src/EntityActionInterface.h +++ b/libraries/entities/src/EntityActionInterface.h @@ -36,6 +36,9 @@ class EntityActionInterface { static EntityActionType actionTypeFromString(QString actionTypeString); static QString actionTypeToString(EntityActionType actionType); + + static glm::vec3 extractVec3Argument(QString objectName, QVariantMap arguments, QString argumentName, bool& ok); + static float extractFloatArgument(QString objectName, QVariantMap arguments, QString argumentName, bool& ok); }; #endif // hifi_EntityActionInterface_h diff --git a/libraries/physics/src/PhysicalEntitySimulation.cpp b/libraries/physics/src/PhysicalEntitySimulation.cpp index 5ad68ee7ab..3185920337 100644 --- a/libraries/physics/src/PhysicalEntitySimulation.cpp +++ b/libraries/physics/src/PhysicalEntitySimulation.cpp @@ -243,39 +243,18 @@ EntityActionInterface* PhysicalEntitySimulation::actionFactory(EntityActionType case ACTION_TYPE_NONE: return nullptr; case ACTION_TYPE_PULL_TO_POINT: - if (!arguments.contains("target")) { - qDebug() << "PullToPoint action requires a `target' argument"; - return nullptr; + bool ok = true; + glm::vec3 target = EntityActionInterface::extractVec3Argument("pull-to-point action", arguments, "target", ok); + float speed = EntityActionInterface::extractFloatArgument("pull-to-point action", arguments, "speed", ok); + if (ok) { + action = (EntityActionInterface*) new ObjectActionPullToPoint(id, ownerEntity, target, speed); } - QVariant targetV = arguments["target"]; - if (targetV.type() != (QVariant::Type) QMetaType::QVariantMap) { - qDebug() << "PullToPoint argument `target' must be a map"; - return nullptr; - } - QVariantMap targetVM = targetV.toMap(); - if (!targetVM.contains("x") || !targetVM.contains("y") || !targetVM.contains("z")) { - qDebug() << "PullToPoint argument `target' must be a map with keys of x, y, z"; - return nullptr; - } - QVariant xV = targetVM["x"]; - QVariant yV = targetVM["y"]; - QVariant zV = targetVM["z"]; - bool xOk = true; - bool yOk = true; - bool zOk = true; - float x = xV.toFloat(&xOk); - float y = yV.toFloat(&yOk); - float z = zV.toFloat(&zOk); - if (!xOk || !yOk || !zOk) { - qDebug() << "PullToPoint argument `target' must be a map with keys of x, y, z and values of type float."; - } - glm::vec3 glmTarget(x, y, z); - float speed = arguments["speed"].toFloat(); - action = (EntityActionInterface*) new ObjectActionPullToPoint(id, ownerEntity, glmTarget, speed); + break; } - assert(action); - ownerEntity->addAction(this, action); + if (action) { + ownerEntity->addAction(this, action); + } return action; } From 66ab3d455fe094dae38979b95ae67dd1669369e8 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 4 Jun 2015 12:29:05 -0700 Subject: [PATCH 17/49] use shared pointers to keep track of action objects --- libraries/entities/src/EntityActionInterface.h | 4 +++- libraries/entities/src/EntityItem.cpp | 8 ++++---- libraries/entities/src/EntityItem.h | 4 ++-- .../entities/src/EntityScriptingInterface.cpp | 2 +- libraries/entities/src/EntitySimulation.h | 6 +++--- .../physics/src/PhysicalEntitySimulation.cpp | 8 ++++---- libraries/physics/src/PhysicalEntitySimulation.h | 8 ++++---- libraries/physics/src/PhysicsEngine.cpp | 16 ++++++++++------ libraries/physics/src/PhysicsEngine.h | 4 ++-- 9 files changed, 33 insertions(+), 27 deletions(-) diff --git a/libraries/entities/src/EntityActionInterface.h b/libraries/entities/src/EntityActionInterface.h index 6220fc19ed..4d5add6f21 100644 --- a/libraries/entities/src/EntityActionInterface.h +++ b/libraries/entities/src/EntityActionInterface.h @@ -32,7 +32,7 @@ class EntityActionInterface { virtual const EntityItemPointer& getOwnerEntity() const = 0; virtual void setOwnerEntity(const EntityItemPointer ownerEntity) = 0; // virtual QByteArray serialize() = 0; - // static EntityActionInterface* deserialize(EntityItemPointer ownerEntity, QByteArray data); + // static EntityActionPointer deserialize(EntityItemPointer ownerEntity, QByteArray data); static EntityActionType actionTypeFromString(QString actionTypeString); static QString actionTypeToString(EntityActionType actionType); @@ -41,4 +41,6 @@ class EntityActionInterface { static float extractFloatArgument(QString objectName, QVariantMap arguments, QString argumentName, bool& ok); }; +typedef std::shared_ptr EntityActionPointer; + #endif // hifi_EntityActionInterface_h diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 1a4c0fff63..f9e8fdc0da 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -1338,7 +1338,7 @@ void EntityItem::updateSimulatorID(const QUuid& value) { } } -bool EntityItem::addAction(EntitySimulation* simulation, EntityActionInterface* action) { +bool EntityItem::addAction(EntitySimulation* simulation, EntityActionPointer action) { assert(action); const QUuid& actionID = action->getID(); assert(!_objectActions.contains(actionID) || _objectActions[actionID] == action); @@ -1354,7 +1354,7 @@ bool EntityItem::addAction(EntitySimulation* simulation, EntityActionInterface* void EntityItem::removeAction(EntitySimulation* simulation, const QUuid actionID) { if (_objectActions.contains(actionID)) { - EntityActionInterface* action = _objectActions[actionID]; + EntityActionPointer action = _objectActions[actionID]; qDebug() << "REMOVING" << actionID << "in EntityItem::removeAction" << _name; _objectActions.remove(actionID); action->setOwnerEntity(nullptr); @@ -1363,10 +1363,10 @@ void EntityItem::removeAction(EntitySimulation* simulation, const QUuid actionID } void EntityItem::clearActions(EntitySimulation* simulation) { - QHash::iterator i = _objectActions.begin(); + QHash::iterator i = _objectActions.begin(); while (i != _objectActions.end()) { const QUuid id = i.key(); - EntityActionInterface* action = _objectActions[id]; + EntityActionPointer action = _objectActions[id]; qDebug() << "ERASING" << id << "in EntityItem::clearActions" << _name; i = _objectActions.erase(i); action->setOwnerEntity(nullptr); diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index 5db3dd3d80..600074d019 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -354,7 +354,7 @@ public: void getAllTerseUpdateProperties(EntityItemProperties& properties) const; - bool addAction(EntitySimulation* simulation, EntityActionInterface* actionID); + bool addAction(EntitySimulation* simulation, EntityActionPointer actionID); void removeAction(EntitySimulation* simulation, const QUuid actionID); void clearActions(EntitySimulation* simulation); @@ -430,7 +430,7 @@ protected: void* _physicsInfo = nullptr; // set by EntitySimulation bool _simulated; // set by EntitySimulation - QHash _objectActions; + QHash _objectActions; }; #endif // hifi_EntityItem_h diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 22b35b20b4..3c81741b58 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -479,7 +479,7 @@ QUuid EntityScriptingInterface::addAction(QString actionTypeString, QUuid entity return QUuid(); } - EntityActionInterface* action = simulation->actionFactory(actionType, actionID, entity, arguments); + EntityActionPointer action = simulation->actionFactory(actionType, actionID, entity, arguments); _entityTree->unlock(); if (action) { diff --git a/libraries/entities/src/EntitySimulation.h b/libraries/entities/src/EntitySimulation.h index 433107fa55..0c9b3efee6 100644 --- a/libraries/entities/src/EntitySimulation.h +++ b/libraries/entities/src/EntitySimulation.h @@ -56,11 +56,11 @@ public: friend class EntityTree; - virtual EntityActionInterface* actionFactory(EntityActionType type, + virtual EntityActionPointer actionFactory(EntityActionType type, QUuid id, EntityItemPointer ownerEntity, QVariantMap arguments) { return nullptr; } - virtual void addAction(EntityActionInterface* action) { _actionsToAdd += action; } + virtual void addAction(EntityActionPointer action) { _actionsToAdd += action; } virtual void removeAction(const QUuid actionID) { _actionsToRemove += actionID; } virtual void removeActions(QList actionIDsToRemove) { _actionsToRemove += actionIDsToRemove; } virtual void applyActionChanges() { _actionsToAdd.clear(); _actionsToRemove.clear(); } @@ -125,7 +125,7 @@ protected: void moveSimpleKinematics(); protected: - QList _actionsToAdd; + QList _actionsToAdd; QList _actionsToRemove; }; diff --git a/libraries/physics/src/PhysicalEntitySimulation.cpp b/libraries/physics/src/PhysicalEntitySimulation.cpp index 3185920337..da9cd99471 100644 --- a/libraries/physics/src/PhysicalEntitySimulation.cpp +++ b/libraries/physics/src/PhysicalEntitySimulation.cpp @@ -234,11 +234,11 @@ void PhysicalEntitySimulation::handleCollisionEvents(CollisionEvents& collisionE } } -EntityActionInterface* PhysicalEntitySimulation::actionFactory(EntityActionType type, +EntityActionPointer PhysicalEntitySimulation::actionFactory(EntityActionType type, QUuid id, EntityItemPointer ownerEntity, QVariantMap arguments) { - EntityActionInterface* action = nullptr; + EntityActionPointer action = nullptr; switch (type) { case ACTION_TYPE_NONE: return nullptr; @@ -247,7 +247,7 @@ EntityActionInterface* PhysicalEntitySimulation::actionFactory(EntityActionType glm::vec3 target = EntityActionInterface::extractVec3Argument("pull-to-point action", arguments, "target", ok); float speed = EntityActionInterface::extractFloatArgument("pull-to-point action", arguments, "speed", ok); if (ok) { - action = (EntityActionInterface*) new ObjectActionPullToPoint(id, ownerEntity, target, speed); + action = (EntityActionPointer) new ObjectActionPullToPoint(id, ownerEntity, target, speed); } break; } @@ -260,7 +260,7 @@ EntityActionInterface* PhysicalEntitySimulation::actionFactory(EntityActionType void PhysicalEntitySimulation::applyActionChanges() { if (_physicsEngine) { - foreach (EntityActionInterface* actionToAdd, _actionsToAdd) { + foreach (EntityActionPointer actionToAdd, _actionsToAdd) { _physicsEngine->addAction(actionToAdd); } foreach (QUuid actionToRemove, _actionsToRemove) { diff --git a/libraries/physics/src/PhysicalEntitySimulation.h b/libraries/physics/src/PhysicalEntitySimulation.h index 6195271ce9..82b0f8ad51 100644 --- a/libraries/physics/src/PhysicalEntitySimulation.h +++ b/libraries/physics/src/PhysicalEntitySimulation.h @@ -32,10 +32,10 @@ public: void init(EntityTree* tree, PhysicsEngine* engine, EntityEditPacketSender* packetSender); - virtual EntityActionInterface* actionFactory(EntityActionType type, - QUuid id, - EntityItemPointer ownerEntity, - QVariantMap arguments); + virtual EntityActionPointer actionFactory(EntityActionType type, + QUuid id, + EntityItemPointer ownerEntity, + QVariantMap arguments); virtual void applyActionChanges(); protected: // only called by EntitySimulation diff --git a/libraries/physics/src/PhysicsEngine.cpp b/libraries/physics/src/PhysicsEngine.cpp index c572121d60..b708ee868f 100644 --- a/libraries/physics/src/PhysicsEngine.cpp +++ b/libraries/physics/src/PhysicsEngine.cpp @@ -449,23 +449,27 @@ bool PhysicsEngine::getBodyLocation(void* physicsInfo, glm::vec3& positionReturn return true; } -void PhysicsEngine::addAction(EntityActionInterface* action) { +void PhysicsEngine::addAction(EntityActionPointer action) { assert(action); const QUuid& actionID = action->getID(); if (_objectActions.contains(actionID)) { assert(_objectActions[actionID] == action); return; } - ObjectAction* objectAction = static_cast(action); - _objectActions[actionID] = objectAction; + + _objectActions[actionID] = action; + + // bullet needs a pointer to the action, but it doesn't use shared pointers. + // is there a way to bump the reference count? + ObjectAction* objectAction = static_cast(action.get()); _dynamicsWorld->addAction(objectAction); } void PhysicsEngine::removeAction(const QUuid actionID) { if (_objectActions.contains(actionID)) { - ObjectAction* action = _objectActions[actionID]; - _dynamicsWorld->removeAction(action); + EntityActionPointer action = _objectActions[actionID]; + ObjectAction* objectAction = static_cast(action.get()); + _dynamicsWorld->removeAction(objectAction); _objectActions.remove(actionID); - delete action; } } diff --git a/libraries/physics/src/PhysicsEngine.h b/libraries/physics/src/PhysicsEngine.h index e009cac60f..3baeffd57d 100644 --- a/libraries/physics/src/PhysicsEngine.h +++ b/libraries/physics/src/PhysicsEngine.h @@ -95,7 +95,7 @@ public: static bool physicsInfoIsActive(void* physicsInfo); static bool getBodyLocation(void* physicsInfo, glm::vec3& positionReturn, glm::quat& rotationReturn); - void addAction(EntityActionInterface* action); + void addAction(EntityActionPointer action); void removeAction(const QUuid actionID); private: @@ -126,7 +126,7 @@ private: QUuid _sessionID; CollisionEvents _collisionEvents; - QHash _objectActions; + QHash _objectActions; }; #endif // hifi_PhysicsEngine_h From 5f60ad3b51620f99caf1259b9ade1583648089e5 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 4 Jun 2015 12:39:48 -0700 Subject: [PATCH 18/49] put back unused variables as commented out -- there is a comment lower down that talks about them --- libraries/entities-renderer/src/RenderableLineEntityItem.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp index b8e0513d22..dfa819061a 100644 --- a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp @@ -26,6 +26,8 @@ EntityItemPointer RenderableLineEntityItem::factory(const EntityItemID& entityID void RenderableLineEntityItem::render(RenderArgs* args) { PerformanceTimer perfTimer("RenderableLineEntityItem::render"); assert(getType() == EntityTypes::Line); + // glm::vec3 position = getPosition(); + // glm::vec3 dimensions = getDimensions(); glm::quat rotation = getRotation(); glm::vec4 lineColor(toGlm(getXColor()), getLocalRenderAlpha()); glPushMatrix(); @@ -44,6 +46,6 @@ void RenderableLineEntityItem::render(RenderArgs* args) { } geometryCache->renderVertices(gpu::LINE_STRIP, _lineVerticesID); glPopMatrix(); - + RenderableDebugableEntityItem::render(this, args); }; From 5e5bc497d9c59a4509587d7ee2f2d4970c3b2278 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 4 Jun 2015 12:44:08 -0700 Subject: [PATCH 19/49] remove debugging prints --- libraries/entities/src/EntityActionInterface.h | 4 ++-- libraries/entities/src/EntityItem.cpp | 3 --- libraries/physics/src/ObjectAction.cpp | 2 -- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/libraries/entities/src/EntityActionInterface.h b/libraries/entities/src/EntityActionInterface.h index 4d5add6f21..e065fada6c 100644 --- a/libraries/entities/src/EntityActionInterface.h +++ b/libraries/entities/src/EntityActionInterface.h @@ -25,8 +25,8 @@ enum EntityActionType { class EntityActionInterface { public: - EntityActionInterface() { qDebug() << "EntityActionInterface::EntityActionInterface"; } - virtual ~EntityActionInterface() { qDebug() << "EntityActionInterface::~EntityActionInterface"; } + EntityActionInterface() { } + virtual ~EntityActionInterface() { } virtual const QUuid& getID() const = 0; virtual void removeFromSimulation(EntitySimulation* simulation) const = 0; virtual const EntityItemPointer& getOwnerEntity() const = 0; diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index f9e8fdc0da..99afe9bdec 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -1342,7 +1342,6 @@ bool EntityItem::addAction(EntitySimulation* simulation, EntityActionPointer act assert(action); const QUuid& actionID = action->getID(); assert(!_objectActions.contains(actionID) || _objectActions[actionID] == action); - qDebug() << "SETTING" << actionID << "in EntityItem::addAction" << _name; _objectActions[actionID] = action; assert(action->getOwnerEntity().get() == this); @@ -1355,7 +1354,6 @@ bool EntityItem::addAction(EntitySimulation* simulation, EntityActionPointer act void EntityItem::removeAction(EntitySimulation* simulation, const QUuid actionID) { if (_objectActions.contains(actionID)) { EntityActionPointer action = _objectActions[actionID]; - qDebug() << "REMOVING" << actionID << "in EntityItem::removeAction" << _name; _objectActions.remove(actionID); action->setOwnerEntity(nullptr); action->removeFromSimulation(simulation); @@ -1367,7 +1365,6 @@ void EntityItem::clearActions(EntitySimulation* simulation) { while (i != _objectActions.end()) { const QUuid id = i.key(); EntityActionPointer action = _objectActions[id]; - qDebug() << "ERASING" << id << "in EntityItem::clearActions" << _name; i = _objectActions.erase(i); action->setOwnerEntity(nullptr); action->removeFromSimulation(simulation); diff --git a/libraries/physics/src/ObjectAction.cpp b/libraries/physics/src/ObjectAction.cpp index deee870c6a..5a2465bfcd 100644 --- a/libraries/physics/src/ObjectAction.cpp +++ b/libraries/physics/src/ObjectAction.cpp @@ -17,11 +17,9 @@ ObjectAction::ObjectAction(QUuid id, EntityItemPointer ownerEntity) : btActionInterface(), _id(id), _ownerEntity(ownerEntity) { - qDebug() << "ObjectAction::ObjectAction"; } ObjectAction::~ObjectAction() { - qDebug() << "ObjectAction::~ObjectAction"; } void ObjectAction::updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep) { From 2c17274f49334c00305105f571afd1bdaaade13d Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 3 Jun 2015 11:11:31 -0700 Subject: [PATCH 20/49] Rename Dialog.qml to DialogOld.qml --- interface/resources/qml/Browser.qml | 2 +- interface/resources/qml/InfoView.qml | 2 +- interface/resources/qml/LoginDialog.qml | 2 +- interface/resources/qml/MarketplaceDialog.qml | 2 +- interface/resources/qml/MessageDialog.qml | 2 +- interface/resources/qml/TestDialog.qml | 2 +- interface/resources/qml/controls/{Dialog.qml => DialogOld.qml} | 0 7 files changed, 6 insertions(+), 6 deletions(-) rename interface/resources/qml/controls/{Dialog.qml => DialogOld.qml} (100%) diff --git a/interface/resources/qml/Browser.qml b/interface/resources/qml/Browser.qml index 55a0a6a461..3de616e05b 100644 --- a/interface/resources/qml/Browser.qml +++ b/interface/resources/qml/Browser.qml @@ -4,7 +4,7 @@ import QtWebKit 3.0 import "controls" import "styles" -Dialog { +DialogOld { id: root HifiConstants { id: hifi } title: "Browser" diff --git a/interface/resources/qml/InfoView.qml b/interface/resources/qml/InfoView.qml index 6b49e6f0c7..e97ebdeaf3 100644 --- a/interface/resources/qml/InfoView.qml +++ b/interface/resources/qml/InfoView.qml @@ -5,7 +5,7 @@ import QtQuick.Controls.Styles 1.3 import QtWebKit 3.0 import "controls" -Dialog { +DialogOld { id: root width: 800 height: 800 diff --git a/interface/resources/qml/LoginDialog.qml b/interface/resources/qml/LoginDialog.qml index 5653dfc7a1..0c02c0af64 100644 --- a/interface/resources/qml/LoginDialog.qml +++ b/interface/resources/qml/LoginDialog.qml @@ -4,7 +4,7 @@ import QtQuick.Controls.Styles 1.3 import "controls" import "styles" -Dialog { +DialogOld { HifiConstants { id: hifi } title: "Login" objectName: "LoginDialog" diff --git a/interface/resources/qml/MarketplaceDialog.qml b/interface/resources/qml/MarketplaceDialog.qml index 58bb3e6183..4ad3c6515f 100644 --- a/interface/resources/qml/MarketplaceDialog.qml +++ b/interface/resources/qml/MarketplaceDialog.qml @@ -5,7 +5,7 @@ import QtQuick.Controls.Styles 1.3 import QtWebKit 3.0 import "controls" -Dialog { +DialogOld { title: "Test Dlg" id: testDialog objectName: "Browser" diff --git a/interface/resources/qml/MessageDialog.qml b/interface/resources/qml/MessageDialog.qml index dd410b8070..5c699e1f1f 100644 --- a/interface/resources/qml/MessageDialog.qml +++ b/interface/resources/qml/MessageDialog.qml @@ -5,7 +5,7 @@ import QtQuick.Dialogs 1.2 import "controls" import "styles" -Dialog { +DialogOld { id: root HifiConstants { id: hifi } property real spacing: hifi.layout.spacing diff --git a/interface/resources/qml/TestDialog.qml b/interface/resources/qml/TestDialog.qml index 15bd790c22..3ae61fa054 100644 --- a/interface/resources/qml/TestDialog.qml +++ b/interface/resources/qml/TestDialog.qml @@ -3,7 +3,7 @@ import QtQuick.Controls 1.2 import QtQuick.Controls.Styles 1.3 import "controls" -Dialog { +DialogOld { title: "Test Dialog" id: testDialog objectName: "TestDialog" diff --git a/interface/resources/qml/controls/Dialog.qml b/interface/resources/qml/controls/DialogOld.qml similarity index 100% rename from interface/resources/qml/controls/Dialog.qml rename to interface/resources/qml/controls/DialogOld.qml From d33a249b3e795e5a7c8cba3323400da097489aa1 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 3 Jun 2015 13:01:47 -0700 Subject: [PATCH 21/49] Refactor common new dialog functionality into new Dialog.qml --- interface/resources/qml/AddressBarDialog.qml | 62 ++++--------------- interface/resources/qml/ErrorDialog.qml | 50 ++------------- interface/resources/qml/controls/Dialog.qml | 65 ++++++++++++++++++++ 3 files changed, 82 insertions(+), 95 deletions(-) create mode 100644 interface/resources/qml/controls/Dialog.qml diff --git a/interface/resources/qml/AddressBarDialog.qml b/interface/resources/qml/AddressBarDialog.qml index 91e05d020d..b4f1b2b247 100644 --- a/interface/resources/qml/AddressBarDialog.qml +++ b/interface/resources/qml/AddressBarDialog.qml @@ -9,18 +9,16 @@ // import Hifi 1.0 -import QtQuick 2.3 -import QtQuick.Controls 1.2 +import QtQuick 2.4 import "controls" import "styles" -Item { +Dialog { id: root HifiConstants { id: hifi } objectName: "AddressBarDialog" - property int animationDuration: hifi.effects.fadeInDuration property bool destroyOnInvisible: false property real scale: 1.25 // Make this dialog a little larger than normal @@ -101,47 +99,16 @@ Item { } } - // The UI enables an object, rather than manipulating its visibility, so that we can do animations in both directions. - // Because visibility and enabled are booleans, they cannot be animated. So when enabled is changed, we modify a property - // that can be animated, like scale or opacity, and then when the target animation value is reached, we can modify the - // visibility. - enabled: false - opacity: 0.0 - onEnabledChanged: { - opacity = enabled ? 1.0 : 0.0 if (enabled) { addressLine.forceActiveFocus(); } } - Behavior on opacity { - // Animate opacity. - NumberAnimation { - duration: animationDuration - easing.type: Easing.OutCubic - } - } - - onOpacityChanged: { - // Once we're transparent, disable the dialog's visibility. - visible = (opacity != 0.0) - } - onVisibleChanged: { if (!visible) { - reset() - - // Some dialogs should be destroyed when they become invisible. - if (destroyOnInvisible) { - destroy() - } + addressLine.text = "" } - - } - - function reset() { - addressLine.text = "" } function toggleOrGo() { @@ -152,21 +119,18 @@ Item { } } - Keys.onEscapePressed: { - enabled = false - } - Keys.onPressed: { - switch(event.key) { - case Qt.Key_W: - if (event.modifiers == Qt.ControlModifier) { - event.accepted = true - enabled = false - } + switch (event.key) { + case Qt.Key_Escape: + case Qt.Key_Back: + enabled = false; + event.accepted = true + break + case Qt.Key_Enter: + case Qt.Key_Return: + toggleOrGo() + event.accepted = true break } } - - Keys.onReturnPressed: toggleOrGo() - Keys.onEnterPressed: toggleOrGo() } diff --git a/interface/resources/qml/ErrorDialog.qml b/interface/resources/qml/ErrorDialog.qml index c0f8132f14..c3639f5f3c 100644 --- a/interface/resources/qml/ErrorDialog.qml +++ b/interface/resources/qml/ErrorDialog.qml @@ -9,17 +9,14 @@ // import Hifi 1.0 as Hifi -import QtQuick 2.3 -import QtQuick.Controls 1.2 -import QtQuick.Dialogs 1.2 +import QtQuick 2.4 import "controls" import "styles" -Item { +Dialog { id: root HifiConstants { id: hifi } - property int animationDuration: hifi.effects.fadeInDuration property bool destroyOnInvisible: true Component.onCompleted: { @@ -69,7 +66,7 @@ Item { Text { id: messageText - font.pointSize: 10 + font.pixelSize: hifi.fonts.pixelSize * 0.6 font.weight: Font.Bold anchors { @@ -99,47 +96,8 @@ Item { } } - // The UI enables an object, rather than manipulating its visibility, so that we can do animations in both directions. - // Because visibility and enabled are booleans, they cannot be animated. So when enabled is changed, we modify a property - // that can be animated, like scale or opacity, and then when the target animation value is reached, we can modify the - // visibility. - enabled: false - opacity: 0.0 - - onEnabledChanged: { - opacity = enabled ? 1.0 : 0.0 - } - - Behavior on opacity { - // Animate opacity. - NumberAnimation { - duration: animationDuration - easing.type: Easing.OutCubic - } - } - - onOpacityChanged: { - // Once we're transparent, disable the dialog's visibility. - visible = (opacity != 0.0) - } - - onVisibleChanged: { - if (!visible) { - // Some dialogs should be destroyed when they become invisible. - if (destroyOnInvisible) { - destroy() - } - } - } - Keys.onPressed: { - if (event.modifiers === Qt.ControlModifier) - switch (event.key) { - case Qt.Key_W: - event.accepted = true - content.accept() - break - } else switch (event.key) { + switch (event.key) { case Qt.Key_Escape: case Qt.Key_Back: case Qt.Key_Enter: diff --git a/interface/resources/qml/controls/Dialog.qml b/interface/resources/qml/controls/Dialog.qml new file mode 100644 index 0000000000..63430bdae0 --- /dev/null +++ b/interface/resources/qml/controls/Dialog.qml @@ -0,0 +1,65 @@ +// +// Dialog.qml +// +// Created by David Rowe on 3 Jun 2015 +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +import Hifi 1.0 +import QtQuick 2.4 +import "../styles" + +Item { + id: root + + property int animationDuration: hifi.effects.fadeInDuration + + + // The UI enables an object, rather than manipulating its visibility, so that we can do animations in both directions. + // Because visibility and enabled are booleans, they cannot be animated. So when enabled is changed, we modify a property + // that can be animated, like scale or opacity, and then when the target animation value is reached, we can modify the + // visibility. + enabled: false + opacity: 0.0 + + onEnabledChanged: { + opacity = enabled ? 1.0 : 0.0 + } + + Behavior on opacity { + // Animate opacity. + NumberAnimation { + duration: animationDuration + easing.type: Easing.OutCubic + } + } + + onOpacityChanged: { + // Once we're transparent, disable the dialog's visibility. + visible = (opacity != 0.0) + } + + onVisibleChanged: { + if (!visible) { + // Some dialogs should be destroyed when they become invisible. + if (destroyOnInvisible) { + destroy() + } + } + } + + + Keys.onPressed: { + switch(event.key) { + case Qt.Key_W: + if (event.modifiers == Qt.ControlModifier) { + enabled = false + event.accepted = true + } + break + } + } +} From afc2f374e54feafc6386dfe978b17f34ef281d69 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 4 Jun 2015 13:20:48 -0700 Subject: [PATCH 22/49] New login dialog background with circular and rectangular variations Developer menu item toggles between the two. --- interface/resources/images/login-circle.svg | 3 + interface/resources/images/login-close.svg | 55 ++++ .../resources/images/login-rectangle.svg | 3 + interface/resources/qml/ErrorDialog.qml | 5 +- interface/resources/qml/LoginDialog.qml | 253 ++++++------------ interface/src/Menu.cpp | 15 ++ interface/src/Menu.h | 2 + interface/src/ui/DialogsManager.cpp | 4 + interface/src/ui/DialogsManager.h | 4 + interface/src/ui/LoginDialog.cpp | 37 ++- interface/src/ui/LoginDialog.h | 11 + 11 files changed, 219 insertions(+), 173 deletions(-) create mode 100644 interface/resources/images/login-circle.svg create mode 100644 interface/resources/images/login-close.svg create mode 100644 interface/resources/images/login-rectangle.svg diff --git a/interface/resources/images/login-circle.svg b/interface/resources/images/login-circle.svg new file mode 100644 index 0000000000..8a98902e6b --- /dev/null +++ b/interface/resources/images/login-circle.svg @@ -0,0 +1,3 @@ + + +2015-06-02 19:43ZCanvas 1Login Circle diff --git a/interface/resources/images/login-close.svg b/interface/resources/images/login-close.svg new file mode 100644 index 0000000000..88ca90b96f --- /dev/null +++ b/interface/resources/images/login-close.svg @@ -0,0 +1,55 @@ + +image/svg+xml \ No newline at end of file diff --git a/interface/resources/images/login-rectangle.svg b/interface/resources/images/login-rectangle.svg new file mode 100644 index 0000000000..774baf8193 --- /dev/null +++ b/interface/resources/images/login-rectangle.svg @@ -0,0 +1,3 @@ + + +2015-06-02 19:42ZCanvas 1Login2 diff --git a/interface/resources/qml/ErrorDialog.qml b/interface/resources/qml/ErrorDialog.qml index c3639f5f3c..51befb12a7 100644 --- a/interface/resources/qml/ErrorDialog.qml +++ b/interface/resources/qml/ErrorDialog.qml @@ -8,7 +8,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -import Hifi 1.0 as Hifi +import Hifi 1.0 import QtQuick 2.4 import "controls" import "styles" @@ -35,7 +35,7 @@ Dialog { x: parent ? parent.width / 2 - width / 2 : 0 y: parent ? parent.height / 2 - height / 2 : 0 - Hifi.ErrorDialog { + ErrorDialog { id: content implicitWidth: box.width @@ -88,6 +88,7 @@ Dialog { } MouseArea { anchors.fill: parent + cursorShape: "PointingHandCursor" onClicked: { content.accept(); } diff --git a/interface/resources/qml/LoginDialog.qml b/interface/resources/qml/LoginDialog.qml index 0c02c0af64..6db56d21bf 100644 --- a/interface/resources/qml/LoginDialog.qml +++ b/interface/resources/qml/LoginDialog.qml @@ -1,198 +1,119 @@ +// +// LoginDialog.qml +// +// Created by David Rowe on 3 Jun 2015 +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + import Hifi 1.0 -import QtQuick 2.3 -import QtQuick.Controls.Styles 1.3 +import QtQuick 2.4 +import QtQuick.Controls 1.3 // TODO: Needed? import "controls" import "styles" -DialogOld { +Dialog { + id: root HifiConstants { id: hifi } - title: "Login" + objectName: "LoginDialog" - height: 512 - width: 384 - onVisibleChanged: { - if (!visible) { - reset() - } - } + property bool destroyOnInvisible: false - onEnabledChanged: { - if (enabled) { - username.forceActiveFocus(); - } - } + implicitWidth: loginDialog.implicitWidth + implicitHeight: loginDialog.implicitHeight - function reset() { - username.text = "" - password.text = "" - loginDialog.statusText = "" + x: parent ? parent.width / 2 - width / 2 : 0 + y: parent ? parent.height / 2 - height / 2 : 0 + property int maximumX: parent ? parent.width - width : 0 + property int maximumY: parent ? parent.height - height : 0 + + function isCircular() { + return loginDialog.dialogFormat == "circular" } LoginDialog { id: loginDialog - anchors.fill: parent - anchors.margins: parent.margins - anchors.topMargin: parent.topMargin - Column { - anchors.topMargin: 8 - anchors.right: parent.right - anchors.rightMargin: 0 - anchors.left: parent.left - anchors.top: parent.top - spacing: 8 - Image { - height: 64 - anchors.horizontalCenter: parent.horizontalCenter - width: 64 - source: "../images/hifi-logo.svg" + implicitWidth: isCircular() ? circularBackground.width : rectangularBackground.width + implicitHeight: isCircular() ? circularBackground.height : rectangularBackground.height + + Image { + id: circularBackground + visible: isCircular() + + source: "../images/login-circle.svg" + width: 500 + height: 500 + } + + Image { + id: rectangularBackground + visible: !isCircular() + + source: "../images/login-rectangle.svg" + width: 400 + height: 400 + } + + Text { + id: closeText + visible: isCircular() + + text: "Close" + font.pixelSize: hifi.fonts.pixelSize * 0.8 + font.weight: Font.Bold + color: "#175d74" + + anchors { + horizontalCenter: circularBackground.horizontalCenter + bottom: circularBackground.bottom + bottomMargin: hifi.layout.spacing * 4 } - Border { - width: 304 - height: 64 - anchors.horizontalCenter: parent.horizontalCenter - TextInput { - id: username - anchors.fill: parent - helperText: "Username or Email" - anchors.margins: 8 - KeyNavigation.tab: password - KeyNavigation.backtab: password + MouseArea { + anchors.fill: parent + cursorShape: "PointingHandCursor" + onClicked: { + root.enabled = false } } - - Border { - width: 304 - height: 64 - anchors.horizontalCenter: parent.horizontalCenter - TextInput { - id: password - anchors.fill: parent - echoMode: TextInput.Password - helperText: "Password" - anchors.margins: 8 - KeyNavigation.tab: username - KeyNavigation.backtab: username - onFocusChanged: { - if (password.focus) { - password.selectAll() - } - } - } - } - - Text { - anchors.horizontalCenter: parent.horizontalCenter - textFormat: Text.StyledText - width: parent.width - height: 96 - wrapMode: Text.WordWrap - verticalAlignment: Text.AlignVCenter - horizontalAlignment: Text.AlignHCenter - text: loginDialog.statusText - } } - Column { - anchors.bottomMargin: 5 - anchors.right: parent.right - anchors.rightMargin: 0 - anchors.left: parent.left - anchors.bottom: parent.bottom + Image { + id: closeIcon + visible: !isCircular() - Rectangle { - width: 192 - height: 64 - anchors.horizontalCenter: parent.horizontalCenter - color: hifi.colors.hifiBlue - border.width: 0 - radius: 10 - - MouseArea { - anchors.bottom: parent.bottom - anchors.bottomMargin: 0 - anchors.top: parent.top - anchors.right: parent.right - anchors.left: parent.left - onClicked: { - loginDialog.login(username.text, password.text) - } - } - - Row { - anchors.centerIn: parent - anchors.verticalCenter: parent.verticalCenter - spacing: 8 - Image { - id: loginIcon - height: 32 - width: 32 - source: "../images/login.svg" - } - Text { - text: "Login" - color: "white" - width: 64 - height: parent.height - } - } + source: "../images/login-close.svg" + width: 20 + height: 20 + anchors { + top: rectangularBackground.top + right: rectangularBackground.right + topMargin: hifi.layout.spacing * 2 + rightMargin: hifi.layout.spacing * 2 } - Text { - width: parent.width - height: 24 - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - text:"Create Account" - font.pointSize: 12 - font.bold: true - color: hifi.colors.hifiBlue - - MouseArea { - anchors.fill: parent - onClicked: { - loginDialog.openUrl(loginDialog.rootUrl + "/signup") - } - } - } - - Text { - width: parent.width - height: 24 - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - font.pointSize: 12 - text: "Recover Password" - color: hifi.colors.hifiBlue - - MouseArea { - anchors.fill: parent - onClicked: { - loginDialog.openUrl(loginDialog.rootUrl + "/users/password/new") - } + MouseArea { + anchors.fill: parent + cursorShape: "PointingHandCursor" + onClicked: { + root.enabled = false } } } } + Keys.onPressed: { - switch(event.key) { - case Qt.Key_Enter: - case Qt.Key_Return: - if (username.activeFocus) { - event.accepted = true - password.forceActiveFocus() - } else if (password.activeFocus) { - event.accepted = true - if (username.text == "") { - username.forceActiveFocus() - } else { - loginDialog.login(username.text, password.text) - } - } - break; + switch (event.key) { + case Qt.Key_Escape: + case Qt.Key_Back: + enabled = false; + event.accepted = true + break } } } diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 6242318170..b2b9553ea5 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -571,6 +571,21 @@ Menu::Menu() { addCheckableActionToQMenuAndActionHash(physicsOptionsMenu, MenuOption::PhysicsShowOwned); addCheckableActionToQMenuAndActionHash(physicsOptionsMenu, MenuOption::PhysicsShowHulls); + MenuWrapper* loginDialogFormatMenu = developerMenu->addMenu("Login Dialog"); + { + QActionGroup* dialogMenuFormatGroup = new QActionGroup(loginDialogFormatMenu); + + QAction* circularLoginDialog = addCheckableActionToQMenuAndActionHash(loginDialogFormatMenu, + MenuOption::LoginDialogCircular, 0, false, + dialogsManager.data(), SLOT(updateLoginDialogFormat())); + dialogMenuFormatGroup->addAction(circularLoginDialog); + + QAction* rectangularLoginDialog = addCheckableActionToQMenuAndActionHash(loginDialogFormatMenu, + MenuOption::LoginDialogRectangular, 0, true, + dialogsManager.data(), SLOT(updateLoginDialogFormat())); + dialogMenuFormatGroup->addAction(rectangularLoginDialog); + } + MenuWrapper* helpMenu = addMenu("Help"); addActionToQMenuAndActionHash(helpMenu, MenuOption::EditEntitiesHelp, 0, qApp, SLOT(showEditEntitiesHelp())); diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 6107744abc..eb1bd94637 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -209,6 +209,8 @@ namespace MenuOption { const QString LoadRSSDKFile = "Load .rssdk file"; const QString LodTools = "LOD Tools"; const QString Login = "Login"; + const QString LoginDialogCircular = "Circular"; + const QString LoginDialogRectangular = "Rectangular"; const QString Log = "Log"; const QString LowVelocityFilter = "Low Velocity Filter"; const QString Mirror = "Mirror"; diff --git a/interface/src/ui/DialogsManager.cpp b/interface/src/ui/DialogsManager.cpp index 1170e3c3a6..705f55586c 100644 --- a/interface/src/ui/DialogsManager.cpp +++ b/interface/src/ui/DialogsManager.cpp @@ -50,6 +50,10 @@ void DialogsManager::showLoginDialog() { LoginDialog::show(); } +void DialogsManager::updateLoginDialogFormat() { + emit loginDialogFormatChanged(); +} + void DialogsManager::octreeStatsDetails() { if (!_octreeStatsDialog) { _octreeStatsDialog = new OctreeStatsDialog(qApp->getWindow(), qApp->getOcteeSceneStats()); diff --git a/interface/src/ui/DialogsManager.h b/interface/src/ui/DialogsManager.h index fc2dad072b..f7301f5444 100644 --- a/interface/src/ui/DialogsManager.h +++ b/interface/src/ui/DialogsManager.h @@ -47,11 +47,15 @@ public: QPointer getOctreeStatsDialog() const { return _octreeStatsDialog; } QPointer getPreferencesDialog() const { return _preferencesDialog; } +signals: + void loginDialogFormatChanged(); + public slots: void toggleAddressBar(); void toggleDiskCacheEditor(); void toggleLoginDialog(); void showLoginDialog(); + void updateLoginDialogFormat(); void octreeStatsDetails(); void cachesSizeDialog(); void editPreferences(); diff --git a/interface/src/ui/LoginDialog.cpp b/interface/src/ui/LoginDialog.cpp index b452f153f0..4ed338c7db 100644 --- a/interface/src/ui/LoginDialog.cpp +++ b/interface/src/ui/LoginDialog.cpp @@ -1,6 +1,6 @@ // -// // LoginDialog.cpp +// interface/src/ui // // Created by Bradley Austin Davis on 2015/04/14 // Copyright 2015 High Fidelity, Inc. @@ -8,20 +8,28 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // + #include "LoginDialog.h" -#include "DependencyManager.h" -#include "AccountManager.h" -#include "Menu.h" #include +#include "AccountManager.h" +#include "DependencyManager.h" +#include "Menu.h" + HIFI_QML_DEF(LoginDialog) -LoginDialog::LoginDialog(QQuickItem *parent) : OffscreenQmlDialog(parent), _rootUrl(NetworkingConstants::METAVERSE_SERVER_URL.toString()) { +LoginDialog::LoginDialog(QQuickItem *parent) : OffscreenQmlDialog(parent), + _dialogFormat("rectangular"), + _rootUrl(NetworkingConstants::METAVERSE_SERVER_URL.toString()) +{ connect(&AccountManager::getInstance(), &AccountManager::loginComplete, this, &LoginDialog::handleLoginCompleted); connect(&AccountManager::getInstance(), &AccountManager::loginFailed, this, &LoginDialog::handleLoginFailed); + + connect(DependencyManager::get().data(), &DialogsManager::loginDialogFormatChanged, + this, &LoginDialog::updateDialogFormat); } void LoginDialog::toggleAction() { @@ -51,6 +59,25 @@ void LoginDialog::handleLoginFailed() { setStatusText("Invalid username or password.< / font>"); } +void LoginDialog::setDialogFormat(const QString& dialogFormat) { + if (dialogFormat != _dialogFormat) { + _dialogFormat = dialogFormat; + emit dialogFormatChanged(); + } +} + +QString LoginDialog::dialogFormat() const { + return _dialogFormat; +} + +void LoginDialog::updateDialogFormat() { + if (Menu::getInstance()->isOptionChecked(MenuOption::LoginDialogCircular)) { + setDialogFormat("circular"); + } else { + setDialogFormat("rectangular"); + } +} + void LoginDialog::setStatusText(const QString& statusText) { if (statusText != _statusText) { _statusText = statusText; diff --git a/interface/src/ui/LoginDialog.h b/interface/src/ui/LoginDialog.h index e9ae0a1c16..5761914642 100644 --- a/interface/src/ui/LoginDialog.h +++ b/interface/src/ui/LoginDialog.h @@ -1,5 +1,6 @@ // // LoginDialog.h +// interface/src/ui // // Created by Bradley Austin Davis on 2015/04/14 // Copyright 2015 High Fidelity, Inc. @@ -9,9 +10,12 @@ // #pragma once + #ifndef hifi_LoginDialog_h #define hifi_LoginDialog_h +#include "DialogsManager.h" // Need before OffscreenQmlDialog.h in order to get gl.h and glew.h includes in correct order. + #include class LoginDialog : public OffscreenQmlDialog @@ -19,6 +23,7 @@ class LoginDialog : public OffscreenQmlDialog Q_OBJECT HIFI_QML_DECL + Q_PROPERTY(QString dialogFormat READ dialogFormat WRITE setDialogFormat NOTIFY dialogFormatChanged) Q_PROPERTY(QString statusText READ statusText WRITE setStatusText NOTIFY statusTextChanged) Q_PROPERTY(QString rootUrl READ rootUrl) @@ -27,12 +32,17 @@ public: LoginDialog(QQuickItem* parent = nullptr); + void setDialogFormat(const QString& dialogFormat); + QString dialogFormat() const; + void updateDialogFormat(); // protected? + void setStatusText(const QString& statusText); QString statusText() const; QString rootUrl() const; signals: + void dialogFormatChanged(); void statusTextChanged(); protected: @@ -42,6 +52,7 @@ protected: Q_INVOKABLE void login(const QString& username, const QString& password); Q_INVOKABLE void openUrl(const QString& url); private: + QString _dialogFormat; QString _statusText; const QString _rootUrl; }; From ba42b0dcc4cbfd64495db9d2a2226937a3255c37 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 4 Jun 2015 17:51:59 -0700 Subject: [PATCH 23/49] updateAction and deleteAction --- .../entities/src/EntityActionInterface.h | 3 + libraries/entities/src/EntityItem.cpp | 12 +++- libraries/entities/src/EntityItem.h | 5 +- .../entities/src/EntityScriptingInterface.cpp | 59 ++++++++++++++++++- .../entities/src/EntityScriptingInterface.h | 2 + libraries/physics/src/ObjectAction.h | 3 +- .../physics/src/ObjectActionPullToPoint.cpp | 19 ++++-- .../physics/src/ObjectActionPullToPoint.h | 5 +- .../physics/src/PhysicalEntitySimulation.cpp | 13 ++-- 9 files changed, 103 insertions(+), 18 deletions(-) diff --git a/libraries/entities/src/EntityActionInterface.h b/libraries/entities/src/EntityActionInterface.h index e065fada6c..fff8d48fba 100644 --- a/libraries/entities/src/EntityActionInterface.h +++ b/libraries/entities/src/EntityActionInterface.h @@ -31,12 +31,15 @@ class EntityActionInterface { virtual void removeFromSimulation(EntitySimulation* simulation) const = 0; virtual const EntityItemPointer& getOwnerEntity() const = 0; virtual void setOwnerEntity(const EntityItemPointer ownerEntity) = 0; + virtual bool updateArguments(QVariantMap arguments) = 0; // virtual QByteArray serialize() = 0; // static EntityActionPointer deserialize(EntityItemPointer ownerEntity, QByteArray data); static EntityActionType actionTypeFromString(QString actionTypeString); static QString actionTypeToString(EntityActionType actionType); + protected: + static glm::vec3 extractVec3Argument(QString objectName, QVariantMap arguments, QString argumentName, bool& ok); static float extractFloatArgument(QString objectName, QVariantMap arguments, QString argumentName, bool& ok); }; diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 99afe9bdec..247fbee76e 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -1351,13 +1351,23 @@ bool EntityItem::addAction(EntitySimulation* simulation, EntityActionPointer act return false; } -void EntityItem::removeAction(EntitySimulation* simulation, const QUuid actionID) { +bool EntityItem::updateAction(EntitySimulation* simulation, const QUuid actionID, QVariantMap arguments) { + if (!_objectActions.contains(actionID)) { + return false; + } + EntityActionPointer action = _objectActions[actionID]; + return action->updateArguments(arguments); +} + +bool EntityItem::removeAction(EntitySimulation* simulation, const QUuid actionID) { if (_objectActions.contains(actionID)) { EntityActionPointer action = _objectActions[actionID]; _objectActions.remove(actionID); action->setOwnerEntity(nullptr); action->removeFromSimulation(simulation); + return true; } + return false; } void EntityItem::clearActions(EntitySimulation* simulation) { diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index 600074d019..0a8e1c2196 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -354,8 +354,9 @@ public: void getAllTerseUpdateProperties(EntityItemProperties& properties) const; - bool addAction(EntitySimulation* simulation, EntityActionPointer actionID); - void removeAction(EntitySimulation* simulation, const QUuid actionID); + bool addAction(EntitySimulation* simulation, EntityActionPointer action); + bool updateAction(EntitySimulation* simulation, const QUuid actionID, QVariantMap arguments); + bool removeAction(EntitySimulation* simulation, const QUuid actionID); void clearActions(EntitySimulation* simulation); protected: diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 3c81741b58..80f6e1069c 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -450,7 +450,10 @@ bool EntityScriptingInterface::setAllVoxels(QUuid entityID, int value) { }); } + QUuid EntityScriptingInterface::addAction(QString actionTypeString, QUuid entityID, QVariantMap arguments) { + QUuid actionID = QUuid::createUuid(); + if (!_entityTree) { return QUuid(); } @@ -458,7 +461,6 @@ QUuid EntityScriptingInterface::addAction(QString actionTypeString, QUuid entity _entityTree->lockForWrite(); EntitySimulation* simulation = _entityTree->getSimulation(); - QUuid actionID = QUuid::createUuid(); EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID); if (!entity) { qDebug() << "addAction -- unknown entity" << entityID; @@ -487,3 +489,58 @@ QUuid EntityScriptingInterface::addAction(QString actionTypeString, QUuid entity } return QUuid(); } + + +bool EntityScriptingInterface::updateAction(QUuid entityID, QUuid actionID, QVariantMap arguments) { + if (!_entityTree) { + return false; + } + + _entityTree->lockForWrite(); + + EntitySimulation* simulation = _entityTree->getSimulation(); + EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID); + if (!entity) { + qDebug() << "updateAction -- unknown entity" << entityID; + _entityTree->unlock(); + return false; + } + + if (!simulation) { + qDebug() << "updateAction -- no simulation" << entityID; + _entityTree->unlock(); + return false; + } + + bool result = entity->updateAction(simulation, actionID, arguments); + _entityTree->unlock(); + return result; +} + + +bool EntityScriptingInterface::deleteAction(QUuid entityID, QUuid actionID) { + if (!_entityTree) { + return false; + } + + _entityTree->lockForWrite(); + + EntitySimulation* simulation = _entityTree->getSimulation(); + EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID); + if (!entity) { + qDebug() << "updateAction -- unknown entity" << entityID; + _entityTree->unlock(); + return false; + } + + if (!simulation) { + qDebug() << "updateAction -- no simulation" << entityID; + _entityTree->unlock(); + return false; + } + + bool result = entity->removeAction(simulation, actionID); + + _entityTree->unlock(); + return result; +} diff --git a/libraries/entities/src/EntityScriptingInterface.h b/libraries/entities/src/EntityScriptingInterface.h index d5646d8fd0..38cd38c569 100644 --- a/libraries/entities/src/EntityScriptingInterface.h +++ b/libraries/entities/src/EntityScriptingInterface.h @@ -125,6 +125,8 @@ public slots: Q_INVOKABLE void dumpTree() const; Q_INVOKABLE QUuid addAction(QString actionTypeString, QUuid entityID, QVariantMap arguments); + Q_INVOKABLE bool updateAction(QUuid entityID, QUuid actionID, QVariantMap arguments); + Q_INVOKABLE bool deleteAction(QUuid entityID, QUuid actionID); signals: void entityCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision); diff --git a/libraries/physics/src/ObjectAction.h b/libraries/physics/src/ObjectAction.h index e2794d8ca8..b819f25515 100644 --- a/libraries/physics/src/ObjectAction.h +++ b/libraries/physics/src/ObjectAction.h @@ -28,9 +28,10 @@ public: virtual void removeFromSimulation(EntitySimulation* simulation) const; virtual const EntityItemPointer& getOwnerEntity() const { return _ownerEntity; } virtual void setOwnerEntity(const EntityItemPointer ownerEntity) { _ownerEntity = ownerEntity; } + virtual bool updateArguments(QVariantMap arguments) { return false; } + // these are from btActionInterface virtual void updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep); - virtual void debugDraw(btIDebugDraw* debugDrawer); private: diff --git a/libraries/physics/src/ObjectActionPullToPoint.cpp b/libraries/physics/src/ObjectActionPullToPoint.cpp index 1772da5dda..70743904a0 100644 --- a/libraries/physics/src/ObjectActionPullToPoint.cpp +++ b/libraries/physics/src/ObjectActionPullToPoint.cpp @@ -14,10 +14,8 @@ #include "ObjectActionPullToPoint.h" -ObjectActionPullToPoint::ObjectActionPullToPoint(QUuid id, EntityItemPointer ownerEntity, glm::vec3 target, float speed) : - ObjectAction(id, ownerEntity), - _target(target), - _speed(speed) { +ObjectActionPullToPoint::ObjectActionPullToPoint(QUuid id, EntityItemPointer ownerEntity) : + ObjectAction(id, ownerEntity) { qDebug() << "ObjectActionPullToPoint::ObjectActionPullToPoint"; } @@ -46,3 +44,16 @@ void ObjectActionPullToPoint::updateAction(btCollisionWorld* collisionWorld, btS _ownerEntity->updateVelocity(newVelocity); } + + +bool ObjectActionPullToPoint::updateArguments(QVariantMap arguments) { + bool ok = true; + glm::vec3 target = EntityActionInterface::extractVec3Argument("pull-to-point action", arguments, "target", ok); + float speed = EntityActionInterface::extractFloatArgument("pull-to-point action", arguments, "speed", ok); + if (ok) { + _target = target; + _speed = speed; + return true; + } + return false; +} diff --git a/libraries/physics/src/ObjectActionPullToPoint.h b/libraries/physics/src/ObjectActionPullToPoint.h index 49526a8eb4..78005da5bd 100644 --- a/libraries/physics/src/ObjectActionPullToPoint.h +++ b/libraries/physics/src/ObjectActionPullToPoint.h @@ -19,10 +19,11 @@ class ObjectActionPullToPoint : public ObjectAction { public: - ObjectActionPullToPoint(QUuid id, EntityItemPointer ownerEntity, glm::vec3 target, float speed); + ObjectActionPullToPoint(QUuid id, EntityItemPointer ownerEntity); virtual ~ObjectActionPullToPoint(); - void updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep); + virtual bool updateArguments(QVariantMap arguments); + virtual void updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep); private: glm::vec3 _target; diff --git a/libraries/physics/src/PhysicalEntitySimulation.cpp b/libraries/physics/src/PhysicalEntitySimulation.cpp index da9cd99471..1f739fa177 100644 --- a/libraries/physics/src/PhysicalEntitySimulation.cpp +++ b/libraries/physics/src/PhysicalEntitySimulation.cpp @@ -243,18 +243,17 @@ EntityActionPointer PhysicalEntitySimulation::actionFactory(EntityActionType typ case ACTION_TYPE_NONE: return nullptr; case ACTION_TYPE_PULL_TO_POINT: - bool ok = true; - glm::vec3 target = EntityActionInterface::extractVec3Argument("pull-to-point action", arguments, "target", ok); - float speed = EntityActionInterface::extractFloatArgument("pull-to-point action", arguments, "speed", ok); - if (ok) { - action = (EntityActionPointer) new ObjectActionPullToPoint(id, ownerEntity, target, speed); - } + action = (EntityActionPointer) new ObjectActionPullToPoint(id, ownerEntity); break; } - if (action) { + bool ok = action->updateArguments(arguments); + if (ok) { ownerEntity->addAction(this, action); + return action; } + + action = nullptr; return action; } From 3388406984988b2893f8775ed33071263ee55309 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 4 Jun 2015 18:48:21 -0700 Subject: [PATCH 24/49] Add basic username, password, login, and error functionality and styling --- interface/resources/qml/LoginDialog.qml | 180 +++++++++++++++++++----- interface/src/ui/LoginDialog.cpp | 4 +- 2 files changed, 148 insertions(+), 36 deletions(-) diff --git a/interface/resources/qml/LoginDialog.qml b/interface/resources/qml/LoginDialog.qml index 6db56d21bf..75adc30a1c 100644 --- a/interface/resources/qml/LoginDialog.qml +++ b/interface/resources/qml/LoginDialog.qml @@ -10,7 +10,6 @@ import Hifi 1.0 import QtQuick 2.4 -import QtQuick.Controls 1.3 // TODO: Needed? import "controls" import "styles" @@ -40,39 +39,148 @@ Dialog { implicitWidth: isCircular() ? circularBackground.width : rectangularBackground.width implicitHeight: isCircular() ? circularBackground.height : rectangularBackground.height + property int inputWidth: 500 + property int inputHeight: 60 + property int inputSpacing: isCircular() ? 24 : 16 + property int borderWidth: 30 + property int closeMargin: 16 + Image { id: circularBackground visible: isCircular() - source: "../images/login-circle.svg" - width: 500 - height: 500 + width: loginDialog.inputWidth * 1.2 + height: width } Image { id: rectangularBackground visible: !isCircular() - source: "../images/login-rectangle.svg" - width: 400 - height: 400 + width: loginDialog.inputWidth + loginDialog.borderWidth * 2 + height: loginDialog.inputHeight * 6 + } + + Image { + id: closeIcon + visible: !isCircular() + source: "../images/login-close.svg" + width: 20 + height: 20 + anchors { + top: rectangularBackground.top + right: rectangularBackground.right + topMargin: loginDialog.closeMargin + rightMargin: loginDialog.closeMargin + } + + MouseArea { + anchors.fill: parent + cursorShape: "PointingHandCursor" + onClicked: { + root.enabled = false + } + } + } + + Column { + id: mainContent + width: loginDialog.inputWidth + spacing: loginDialog.inputSpacing + anchors { + horizontalCenter: parent.horizontalCenter + verticalCenter: parent.verticalCenter + } + + Rectangle { + width: loginDialog.inputWidth + height: loginDialog.inputHeight + radius: height / 2 + color: "#ebebeb" + + TextInput { + id: username + anchors.fill: parent + anchors.leftMargin: loginDialog.inputHeight / 2 + + helperText: "username or email" + + KeyNavigation.tab: password + KeyNavigation.backtab: password + } + } + + Rectangle { + width: loginDialog.inputWidth + height: loginDialog.inputHeight + radius: height / 2 + color: "#ebebeb" + + TextInput { + id: password + anchors.fill: parent + anchors.leftMargin: loginDialog.inputHeight / 2 + + helperText: "password" + echoMode: TextInput.Password + + KeyNavigation.tab: username + KeyNavigation.backtab: username + onFocusChanged: { + if (password.focus) { + password.selectAll() + } + } + } + } + + Text { + id: messageText + width: loginDialog.inputWidth + height: loginDialog.inputHeight / 2 + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + + text: loginDialog.statusText + } + + Rectangle { + width: loginDialog.inputWidth + height: loginDialog.inputHeight + radius: height / 2 + color: "#353535" + + TextInput { + anchors.fill: parent + text: "Login" + color: "white" + horizontalAlignment: Text.AlignHCenter + } + + MouseArea { + anchors.fill: parent + cursorShape: "PointingHandCursor" + onClicked: { + loginDialog.login(username.text, password.text) + } + } + } } Text { id: closeText visible: isCircular() + anchors { + horizontalCenter: parent.horizontalCenter + top: mainContent.bottom + topMargin: loginDialog.inputSpacing + } text: "Close" font.pixelSize: hifi.fonts.pixelSize * 0.8 font.weight: Font.Bold color: "#175d74" - anchors { - horizontalCenter: circularBackground.horizontalCenter - bottom: circularBackground.bottom - bottomMargin: hifi.layout.spacing * 4 - } - MouseArea { anchors.fill: parent cursorShape: "PointingHandCursor" @@ -81,29 +189,19 @@ Dialog { } } } + } - Image { - id: closeIcon - visible: !isCircular() + onEnabledChanged: { + if (enabled) { + username.forceActiveFocus(); + } + } - source: "../images/login-close.svg" - - width: 20 - height: 20 - anchors { - top: rectangularBackground.top - right: rectangularBackground.right - topMargin: hifi.layout.spacing * 2 - rightMargin: hifi.layout.spacing * 2 - } - - MouseArea { - anchors.fill: parent - cursorShape: "PointingHandCursor" - onClicked: { - root.enabled = false - } - } + onVisibleChanged: { + if (!visible) { + username.text = "" + password.text = "" + loginDialog.statusText = "" } } @@ -114,6 +212,20 @@ Dialog { enabled = false; event.accepted = true break + case Qt.Key_Enter: + case Qt.Key_Return: + if (username.activeFocus) { + event.accepted = true + password.forceActiveFocus() + } else if (password.activeFocus) { + event.accepted = true + if (username.text == "") { + username.forceActiveFocus() + } else { + loginDialog.login(username.text, password.text) + } + } + break; } } } diff --git a/interface/src/ui/LoginDialog.cpp b/interface/src/ui/LoginDialog.cpp index 4ed338c7db..a326d6a6d1 100644 --- a/interface/src/ui/LoginDialog.cpp +++ b/interface/src/ui/LoginDialog.cpp @@ -56,7 +56,7 @@ void LoginDialog::handleLoginCompleted(const QUrl&) { } void LoginDialog::handleLoginFailed() { - setStatusText("Invalid username or password.< / font>"); + setStatusText("Invalid username or password"); } void LoginDialog::setDialogFormat(const QString& dialogFormat) { @@ -95,7 +95,7 @@ QString LoginDialog::rootUrl() const { void LoginDialog::login(const QString& username, const QString& password) { qDebug() << "Attempting to login " << username; - setStatusText("Authenticating..."); + setStatusText("Logging in..."); AccountManager::getInstance().requestAccessToken(username, password); } From 0538eb5756a39944e18158cd4f9c6651f120f036 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 4 Jun 2015 22:27:23 -0700 Subject: [PATCH 25/49] Add remainder of dialog content and polish look --- .../resources/images/hifi-logo-blackish.svg | 123 ++++++++++++++++++ interface/resources/images/login-close.svg | 4 +- interface/resources/images/login-password.svg | 58 +++++++++ interface/resources/images/login-username.svg | 51 ++++++++ interface/resources/qml/LoginDialog.qml | 104 ++++++++++++++- .../resources/qml/styles/HifiConstants.qml | 3 +- 6 files changed, 333 insertions(+), 10 deletions(-) create mode 100644 interface/resources/images/hifi-logo-blackish.svg create mode 100644 interface/resources/images/login-password.svg create mode 100644 interface/resources/images/login-username.svg diff --git a/interface/resources/images/hifi-logo-blackish.svg b/interface/resources/images/hifi-logo-blackish.svg new file mode 100644 index 0000000000..60bfb3d418 --- /dev/null +++ b/interface/resources/images/hifi-logo-blackish.svg @@ -0,0 +1,123 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/interface/resources/images/login-close.svg b/interface/resources/images/login-close.svg index 88ca90b96f..2fb10c241b 100644 --- a/interface/resources/images/login-close.svg +++ b/interface/resources/images/login-close.svg @@ -35,7 +35,7 @@ id="namedview4139" showgrid="false" inkscape:zoom="4.8487496" - inkscape:cx="-11.452085" + inkscape:cx="-41.872299" inkscape:cy="37.53545" inkscape:window-x="77" inkscape:window-y="-8" @@ -48,7 +48,7 @@ d="M 38.400102,87.62655 C 28.705316,86.39839 21.084707,83.18102 13.982682,77.31765 5.5185024,70.329714 -0.09877759,60.244376 -1.7904936,48.998291 -2.1921426,46.328239 -2.2434696,39.677941 -1.8825126,37.07572 0.23131941,21.836625 9.4778634,8.9272213 23.005945,2.3281243 c 9.805646,-4.783264 20.444414,-5.902737 30.964952,-3.25830896 7.357662,1.849413 14.403738,5.75570696 19.976698,11.07495366 7.36697,7.031569 12.03213,16.084669 13.58981,26.37208 0.45133,2.980701 0.44981,9.518147 -0.003,12.481442 -0.72914,4.772737 -2.08456,9.199896 -4.04575,13.214497 -2.40852,4.930297 -4.94684,8.502038 -8.75077,12.313422 -6.78153,6.79482 -14.822805,10.95587 -24.504932,12.68035 -1.787127,0.3183 -3.134188,0.40875 -6.708441,0.45045 -2.459762,0.0287 -4.765789,0.0149 -5.124505,-0.0304 z m -3.02899,-27.869116 7.314939,-7.311007 7.360877,7.35692 7.360872,7.356917 4.983865,-4.982378 4.98386,-4.982378 -7.359111,-7.358686 -7.359105,-7.358687 7.359105,-7.358687 7.359111,-7.358686 -4.98387,-4.982383 -4.983864,-4.982384 -7.407456,7.393329 -7.407456,7.393328 -7.360652,-7.342464 -7.36065,-7.342467 -4.922357,4.916384 -4.922356,4.916381 7.300528,7.417269 7.300528,7.417267 -7.362706,7.362244 -7.362709,7.362244 4.890918,4.889465 c 2.690008,2.689205 4.974582,4.889463 5.076835,4.889463 0.102254,0 3.477639,-3.289951 7.500854,-7.311004 z" id="path4145" inkscape:connector-curvature="0" /> +image/svg+xml \ No newline at end of file diff --git a/interface/resources/images/login-username.svg b/interface/resources/images/login-username.svg new file mode 100644 index 0000000000..a40dd91cf7 --- /dev/null +++ b/interface/resources/images/login-username.svg @@ -0,0 +1,51 @@ + +image/svg+xml \ No newline at end of file diff --git a/interface/resources/qml/LoginDialog.qml b/interface/resources/qml/LoginDialog.qml index 75adc30a1c..f39eb7f5f2 100644 --- a/interface/resources/qml/LoginDialog.qml +++ b/interface/resources/qml/LoginDialog.qml @@ -58,7 +58,7 @@ Dialog { visible: !isCircular() source: "../images/login-rectangle.svg" width: loginDialog.inputWidth + loginDialog.borderWidth * 2 - height: loginDialog.inputHeight * 6 + height: loginDialog.inputHeight * 6 + loginDialog.closeMargin * 2 } Image { @@ -92,18 +92,39 @@ Dialog { verticalCenter: parent.verticalCenter } + Item { + // Offset content down a little + width: loginDialog.inputWidth + height: isCircular() ? loginDialog.inputHeight : loginDialog.closeMargin + } + Rectangle { width: loginDialog.inputWidth height: loginDialog.inputHeight radius: height / 2 color: "#ebebeb" + Image { + source: "../images/login-username.svg" + width: loginDialog.inputHeight * 0.65 + height: width + anchors { + verticalCenter: parent.verticalCenter + left: parent.left + leftMargin: loginDialog.inputHeight / 4 + } + } + TextInput { id: username - anchors.fill: parent - anchors.leftMargin: loginDialog.inputHeight / 2 + anchors { + fill: parent + leftMargin: loginDialog.inputHeight + rightMargin: loginDialog.inputHeight / 2 + } helperText: "username or email" + color: hifi.colors.text KeyNavigation.tab: password KeyNavigation.backtab: password @@ -116,13 +137,28 @@ Dialog { radius: height / 2 color: "#ebebeb" + Image { + source: "../images/login-password.svg" + width: loginDialog.inputHeight * 0.65 + height: width + anchors { + verticalCenter: parent.verticalCenter + left: parent.left + leftMargin: loginDialog.inputHeight / 4 + } + } + TextInput { id: password - anchors.fill: parent - anchors.leftMargin: loginDialog.inputHeight / 2 + anchors { + fill: parent + leftMargin: loginDialog.inputHeight + rightMargin: loginDialog.inputHeight / 2 + } helperText: "password" echoMode: TextInput.Password + color: hifi.colors.text KeyNavigation.tab: username KeyNavigation.backtab: username @@ -142,6 +178,7 @@ Dialog { verticalAlignment: Text.AlignVCenter text: loginDialog.statusText + color: "black" } Rectangle { @@ -165,6 +202,62 @@ Dialog { } } } + + Row { + anchors.horizontalCenter: parent.horizontalCenter + + Text { + text: "Forgot Password?" + font.pixelSize: hifi.fonts.pixelSize * 0.8 + font.underline: true + color: "#e0e0e0" + width: loginDialog.inputHeight * 4 + horizontalAlignment: Text.AlignRight + anchors.verticalCenter: parent.verticalCenter + + MouseArea { + anchors.fill: parent + cursorShape: "PointingHandCursor" + onClicked: { + loginDialog.openUrl(loginDialog.rootUrl + "/users/password/new") + } + } + } + + Item { + width: loginDialog.inputHeight + loginDialog.inputSpacing * 2 + height: loginDialog.inputHeight + + Image { + id: hifiIcon + source: "../images/hifi-logo-blackish.svg" + width: loginDialog.inputHeight + height: width + anchors { + horizontalCenter: parent.horizontalCenter + verticalCenter: parent.verticalCenter + } + } + } + + Text { + text: "Register" + font.pixelSize: hifi.fonts.pixelSize * 0.8 + font.underline: true + color: "#e0e0e0" + width: loginDialog.inputHeight * 4 + horizontalAlignment: Text.AlignLeft + anchors.verticalCenter: parent.verticalCenter + + MouseArea { + anchors.fill: parent + cursorShape: "PointingHandCursor" + onClicked: { + loginDialog.openUrl(loginDialog.rootUrl + "/signup") + } + } + } + } } Text { @@ -178,7 +271,6 @@ Dialog { text: "Close" font.pixelSize: hifi.fonts.pixelSize * 0.8 - font.weight: Font.Bold color: "#175d74" MouseArea { diff --git a/interface/resources/qml/styles/HifiConstants.qml b/interface/resources/qml/styles/HifiConstants.qml index fa556f2083..c232b993d1 100644 --- a/interface/resources/qml/styles/HifiConstants.qml +++ b/interface/resources/qml/styles/HifiConstants.qml @@ -13,10 +13,9 @@ Item { readonly property color hifiBlue: "#0e7077" readonly property color window: sysPalette.window readonly property color dialogBackground: sysPalette.window - //readonly property color dialogBackground: "#00000000" readonly property color inputBackground: "white" readonly property color background: sysPalette.dark - readonly property color text: sysPalette.text + readonly property color text: "#202020" readonly property color disabledText: "gray" readonly property color hintText: "gray" // A bit darker than sysPalette.dark so that it is visible on the DK2 readonly property color light: sysPalette.light From b2db5f7fee76fc064428f0c06ef21c793d092c56 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 5 Jun 2015 07:10:44 -0700 Subject: [PATCH 26/49] update grab.js to use pull-to-point action, various other fixes --- examples/grab.js | 23 +++++++++---- libraries/entities/src/EntityTreeElement.h | 1 + libraries/physics/src/ObjectAction.cpp | 1 + libraries/physics/src/ObjectAction.h | 6 ++++ .../physics/src/ObjectActionPullToPoint.cpp | 34 ++++++++++++------- .../physics/src/ObjectActionPullToPoint.h | 1 + 6 files changed, 47 insertions(+), 19 deletions(-) diff --git a/examples/grab.js b/examples/grab.js index 7ed69e9664..3d95592068 100644 --- a/examples/grab.js +++ b/examples/grab.js @@ -13,6 +13,7 @@ var isGrabbing = false; var grabbedEntity = null; +var actionID = null; var prevMouse = {}; var deltaMouse = { z: 0 @@ -88,6 +89,7 @@ function mousePressEvent(event) { gravity: {x: 0, y: 0, z: 0} }); + Controller.mouseMoveEvent.connect(mouseMoveEvent); } } @@ -110,7 +112,10 @@ function updateDropLine(position) { function mouseReleaseEvent() { if (isGrabbing) { + Controller.mouseMoveEvent.disconnect(mouseMoveEvent); isGrabbing = false; + Entities.deleteAction(grabbedEntity, actionID); + actionID = null; // only restore the original gravity if it's not zero. This is to avoid... // 1. interface A grabs an entity and locally saves off its gravity @@ -228,21 +233,25 @@ function update(deltaTime) { } if (shouldRotate) { angularVelocity = Vec3.subtract(angularVelocity, Vec3.multiply(angularVelocity, ANGULAR_DAMPING_RATE)); + Entities.editEntity(grabbedEntity, { + rotation: currentRotation, + angularVelocity: angularVelocity + }); } else { angularVelocity = entityProps.angularVelocity; } - Entities.editEntity(grabbedEntity, { - position: currentPosition, - rotation: currentRotation, - velocity: newVelocity, - angularVelocity: angularVelocity - }); + var newSpeed = Vec3.length(newVelocity); + if (!actionID) { + actionID = Entities.addAction("pull-to-point", grabbedEntity, {target: targetPosition, speed: newSpeed}); + } else { + Entities.updateAction(grabbedEntity, actionID, {target: targetPosition, speed: newSpeed}); + } + updateDropLine(targetPosition); } } -Controller.mouseMoveEvent.connect(mouseMoveEvent); Controller.mousePressEvent.connect(mousePressEvent); Controller.mouseReleaseEvent.connect(mouseReleaseEvent); Controller.keyPressEvent.connect(keyPressEvent); diff --git a/libraries/entities/src/EntityTreeElement.h b/libraries/entities/src/EntityTreeElement.h index 2504f947bd..05d1904384 100644 --- a/libraries/entities/src/EntityTreeElement.h +++ b/libraries/entities/src/EntityTreeElement.h @@ -152,6 +152,7 @@ public: bool hasEntities() const { return _entityItems ? _entityItems->size() > 0 : false; } void setTree(EntityTree* tree) { _myTree = tree; } + EntityTree* getTree() const { return _myTree; } bool updateEntity(const EntityItem& entity); void addEntityItem(EntityItemPointer entity); diff --git a/libraries/physics/src/ObjectAction.cpp b/libraries/physics/src/ObjectAction.cpp index 5a2465bfcd..6ff4098ba8 100644 --- a/libraries/physics/src/ObjectAction.cpp +++ b/libraries/physics/src/ObjectAction.cpp @@ -16,6 +16,7 @@ ObjectAction::ObjectAction(QUuid id, EntityItemPointer ownerEntity) : btActionInterface(), _id(id), + _active(false), _ownerEntity(ownerEntity) { } diff --git a/libraries/physics/src/ObjectAction.h b/libraries/physics/src/ObjectAction.h index b819f25515..10b086c07d 100644 --- a/libraries/physics/src/ObjectAction.h +++ b/libraries/physics/src/ObjectAction.h @@ -36,8 +36,14 @@ public: private: QUuid _id; + QReadWriteLock _lock; protected: + bool tryLockForRead() { return _lock.tryLockForRead(); } + void lockForWrite() { _lock.lockForWrite(); } + void unlock() { _lock.unlock(); } + + bool _active; EntityItemPointer _ownerEntity; }; diff --git a/libraries/physics/src/ObjectActionPullToPoint.cpp b/libraries/physics/src/ObjectActionPullToPoint.cpp index 70743904a0..85bde3161c 100644 --- a/libraries/physics/src/ObjectActionPullToPoint.cpp +++ b/libraries/physics/src/ObjectActionPullToPoint.cpp @@ -16,33 +16,40 @@ ObjectActionPullToPoint::ObjectActionPullToPoint(QUuid id, EntityItemPointer ownerEntity) : ObjectAction(id, ownerEntity) { + #if WANT_DEBUG qDebug() << "ObjectActionPullToPoint::ObjectActionPullToPoint"; + #endif } ObjectActionPullToPoint::~ObjectActionPullToPoint() { + #if WANT_DEBUG qDebug() << "ObjectActionPullToPoint::~ObjectActionPullToPoint"; + #endif } void ObjectActionPullToPoint::updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep) { - glm::vec3 offset = _target - _ownerEntity->getPosition(); - - if (glm::length(offset) < IGNORE_POSITION_DELTA) { - offset = glm::vec3(0.0f, 0.0f, 0.0f); + if (!tryLockForRead()) { + // don't risk hanging the thread running the physics simulation + return; } - - glm::vec3 newVelocity = glm::normalize(offset) * _speed; - void* physicsInfo = _ownerEntity->getPhysicsInfo(); - if (physicsInfo) { + + if (_active && physicsInfo) { ObjectMotionState* motionState = static_cast(physicsInfo); btRigidBody* rigidBody = motionState->getRigidBody(); if (rigidBody) { - rigidBody->setLinearVelocity(glmToBullet(newVelocity)); - return; + glm::vec3 offset = _target - bulletToGLM(rigidBody->getCenterOfMassPosition()); + float offsetLength = glm::length(offset); + if (offsetLength > IGNORE_POSITION_DELTA) { + glm::vec3 newVelocity = glm::normalize(offset) * _speed; + rigidBody->setLinearVelocity(glmToBullet(newVelocity)); + rigidBody->activate(); // ?? + } else { + rigidBody->setLinearVelocity(glmToBullet(glm::vec3())); + } } } - - _ownerEntity->updateVelocity(newVelocity); + unlock(); } @@ -51,8 +58,11 @@ bool ObjectActionPullToPoint::updateArguments(QVariantMap arguments) { glm::vec3 target = EntityActionInterface::extractVec3Argument("pull-to-point action", arguments, "target", ok); float speed = EntityActionInterface::extractFloatArgument("pull-to-point action", arguments, "speed", ok); if (ok) { + lockForWrite(); _target = target; _speed = speed; + _active = true; + unlock(); return true; } return false; diff --git a/libraries/physics/src/ObjectActionPullToPoint.h b/libraries/physics/src/ObjectActionPullToPoint.h index 78005da5bd..3aca70d640 100644 --- a/libraries/physics/src/ObjectActionPullToPoint.h +++ b/libraries/physics/src/ObjectActionPullToPoint.h @@ -26,6 +26,7 @@ public: virtual void updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep); private: + glm::vec3 _target; float _speed; }; From 3dbf28b7b48bc83f3417ad724fd9eb697d51a0f4 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 5 Jun 2015 07:33:39 -0700 Subject: [PATCH 27/49] use lambdas to remove some repeated code --- .../entities/src/EntityScriptingInterface.cpp | 92 ++++++------------- .../entities/src/EntityScriptingInterface.h | 1 + 2 files changed, 29 insertions(+), 64 deletions(-) diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 80f6e1069c..f6f3b05c4d 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -451,11 +451,9 @@ bool EntityScriptingInterface::setAllVoxels(QUuid entityID, int value) { } -QUuid EntityScriptingInterface::addAction(QString actionTypeString, QUuid entityID, QVariantMap arguments) { - QUuid actionID = QUuid::createUuid(); - +bool EntityScriptingInterface::actionWorker(QUuid entityID, std::function actor) { if (!_entityTree) { - return QUuid(); + return false; } _entityTree->lockForWrite(); @@ -463,28 +461,35 @@ QUuid EntityScriptingInterface::addAction(QString actionTypeString, QUuid entity EntitySimulation* simulation = _entityTree->getSimulation(); EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID); if (!entity) { - qDebug() << "addAction -- unknown entity" << entityID; + qDebug() << "actionWorker -- unknown entity" << entityID; _entityTree->unlock(); - return QUuid(); + return false; } if (!simulation) { - qDebug() << "addAction -- no simulation" << entityID; + qDebug() << "actionWorker -- no simulation" << entityID; _entityTree->unlock(); - return QUuid(); + return false; } - EntityActionType actionType = EntityActionInterface::actionTypeFromString(actionTypeString); - - if (actionType == ACTION_TYPE_NONE) { - _entityTree->unlock(); - return QUuid(); - } - - EntityActionPointer action = simulation->actionFactory(actionType, actionID, entity, arguments); + bool success = actor(simulation, entity); _entityTree->unlock(); + return success; +} - if (action) { + + +QUuid EntityScriptingInterface::addAction(QString actionTypeString, QUuid entityID, QVariantMap arguments) { + QUuid actionID = QUuid::createUuid(); + bool success = actionWorker(entityID, [actionID, actionTypeString, entityID, arguments](EntitySimulation* simulation, + EntityItemPointer entity) { + EntityActionType actionType = EntityActionInterface::actionTypeFromString(actionTypeString); + if (actionType == ACTION_TYPE_NONE) { + return false; + } + return simulation->actionFactory(actionType, actionID, entity, arguments); + }); + if (success) { return actionID; } return QUuid(); @@ -492,55 +497,14 @@ QUuid EntityScriptingInterface::addAction(QString actionTypeString, QUuid entity bool EntityScriptingInterface::updateAction(QUuid entityID, QUuid actionID, QVariantMap arguments) { - if (!_entityTree) { - return false; - } - - _entityTree->lockForWrite(); - - EntitySimulation* simulation = _entityTree->getSimulation(); - EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID); - if (!entity) { - qDebug() << "updateAction -- unknown entity" << entityID; - _entityTree->unlock(); - return false; - } - - if (!simulation) { - qDebug() << "updateAction -- no simulation" << entityID; - _entityTree->unlock(); - return false; - } - - bool result = entity->updateAction(simulation, actionID, arguments); - _entityTree->unlock(); - return result; + return actionWorker(entityID, [entityID, actionID,arguments](EntitySimulation* simulation, EntityItemPointer entity) { + return entity->updateAction(simulation, actionID, arguments); + }); } bool EntityScriptingInterface::deleteAction(QUuid entityID, QUuid actionID) { - if (!_entityTree) { - return false; - } - - _entityTree->lockForWrite(); - - EntitySimulation* simulation = _entityTree->getSimulation(); - EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID); - if (!entity) { - qDebug() << "updateAction -- unknown entity" << entityID; - _entityTree->unlock(); - return false; - } - - if (!simulation) { - qDebug() << "updateAction -- no simulation" << entityID; - _entityTree->unlock(); - return false; - } - - bool result = entity->removeAction(simulation, actionID); - - _entityTree->unlock(); - return result; + return actionWorker(entityID, [entityID, actionID](EntitySimulation* simulation, EntityItemPointer entity) { + return entity->removeAction(simulation, actionID); + }); } diff --git a/libraries/entities/src/EntityScriptingInterface.h b/libraries/entities/src/EntityScriptingInterface.h index 38cd38c569..5c81ab15dd 100644 --- a/libraries/entities/src/EntityScriptingInterface.h +++ b/libraries/entities/src/EntityScriptingInterface.h @@ -155,6 +155,7 @@ signals: void clearingEntities(); private: + bool actionWorker(QUuid entityID, std::function actor); bool setVoxels(QUuid entityID, std::function actor); void queueEntityMessage(PacketType packetType, EntityItemID entityID, const EntityItemProperties& properties); From ce78a95dee84d63d4d0596901af6dbd98cb563f0 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 5 Jun 2015 08:22:36 -0700 Subject: [PATCH 28/49] Make login dialog able to be dragged --- interface/resources/qml/LoginDialog.qml | 82 +++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/interface/resources/qml/LoginDialog.qml b/interface/resources/qml/LoginDialog.qml index f39eb7f5f2..55859cb83d 100644 --- a/interface/resources/qml/LoginDialog.qml +++ b/interface/resources/qml/LoginDialog.qml @@ -44,6 +44,9 @@ Dialog { property int inputSpacing: isCircular() ? 24 : 16 property int borderWidth: 30 property int closeMargin: 16 + property int maximumX: parent ? parent.width - width : 0 + property int maximumY: parent ? parent.height - height : 0 + property real tan30: 0.577 // tan(30°) Image { id: circularBackground @@ -51,6 +54,69 @@ Dialog { source: "../images/login-circle.svg" width: loginDialog.inputWidth * 1.2 height: width + + Item { + // Approximage circle with 3 rectangles that together contain the circle in a hexagon. + anchors.fill: parent + + MouseArea { + width: parent.width + height: parent.width * loginDialog.tan30 + anchors { + horizontalCenter: parent.horizontalCenter + verticalCenter: parent.verticalCenter + } + drag { + target: root + minimumX: -loginDialog.borderWidth + minimumY: -loginDialog.borderWidth + maximumX: root.parent ? root.maximumX + loginDialog.borderWidth : 0 + maximumY: root.parent ? root.maximumY + loginDialog.borderWidth : 0 + } + } + + MouseArea { + width: parent.width + height: parent.width * loginDialog.tan30 + anchors { + horizontalCenter: parent.horizontalCenter + verticalCenter: parent.verticalCenter + } + transform: Rotation { + origin.x: width / 2 + origin.y: width * loginDialog.tan30 / 2 + angle: -60 + } + drag { + target: root + minimumX: -loginDialog.borderWidth + minimumY: -loginDialog.borderWidth + maximumX: root.parent ? root.maximumX + loginDialog.borderWidth : 0 + maximumY: root.parent ? root.maximumY + loginDialog.borderWidth : 0 + } + } + + MouseArea { + width: parent.width + height: parent.width * loginDialog.tan30 + anchors { + horizontalCenter: parent.horizontalCenter + verticalCenter: parent.verticalCenter + } + transform: Rotation { + origin.x: width / 2 + origin.y: width * loginDialog.tan30 / 2 + angle: 60 + } + drag { + target: root + minimumX: -loginDialog.borderWidth + minimumY: -loginDialog.borderWidth + maximumX: root.parent ? root.maximumX + loginDialog.borderWidth : 0 + maximumY: root.parent ? root.maximumY + loginDialog.borderWidth : 0 + } + } + } } Image { @@ -59,6 +125,22 @@ Dialog { source: "../images/login-rectangle.svg" width: loginDialog.inputWidth + loginDialog.borderWidth * 2 height: loginDialog.inputHeight * 6 + loginDialog.closeMargin * 2 + + MouseArea { + width: parent.width + height: parent.height + anchors { + horizontalCenter: parent.horizontalCenter + verticalCenter: parent.verticalCenter + } + drag { + target: root + minimumX: 0 + minimumY: 0 + maximumX: root.parent ? root.maximumX : 0 + maximumY: root.parent ? root.maximumY : 0 + } + } } Image { From 977eae9f86136b029dfedcf93c28ebe1eeb211fe Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 5 Jun 2015 08:42:33 -0700 Subject: [PATCH 29/49] Make login password and register links work --- interface/src/ui/LoginDialog.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/interface/src/ui/LoginDialog.cpp b/interface/src/ui/LoginDialog.cpp index a326d6a6d1..3de8b5adf1 100644 --- a/interface/src/ui/LoginDialog.cpp +++ b/interface/src/ui/LoginDialog.cpp @@ -101,4 +101,5 @@ void LoginDialog::login(const QString& username, const QString& password) { void LoginDialog::openUrl(const QString& url) { qDebug() << url; + Application::getInstance()->openUrl(url); } From 086b9d404afae4d94780f1de4b33fe826d58fdbd Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 5 Jun 2015 08:59:08 -0700 Subject: [PATCH 30/49] fix return-type in lambda --- libraries/entities/src/EntityScriptingInterface.cpp | 5 ++++- libraries/shared/src/SettingInterface.cpp | 12 ++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index f6f3b05c4d..e04bd977a2 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -487,7 +487,10 @@ QUuid EntityScriptingInterface::addAction(QString actionTypeString, QUuid entity if (actionType == ACTION_TYPE_NONE) { return false; } - return simulation->actionFactory(actionType, actionID, entity, arguments); + if (simulation->actionFactory(actionType, actionID, entity, arguments)) { + return true; + } + return false; }); if (success) { return actionID; diff --git a/libraries/shared/src/SettingInterface.cpp b/libraries/shared/src/SettingInterface.cpp index c14fd33565..b27d9089b5 100644 --- a/libraries/shared/src/SettingInterface.cpp +++ b/libraries/shared/src/SettingInterface.cpp @@ -39,12 +39,12 @@ namespace Setting { void init() { // read the ApplicationInfo.ini file for Name/Version/Domain information QSettings::setDefaultFormat(QSettings::IniFormat); - QSettings applicationInfo(PathUtils::resourcesPath() + "info/ApplicationInfo.ini", QSettings::IniFormat); - // set the associated application properties - applicationInfo.beginGroup("INFO"); - QCoreApplication::setApplicationName(applicationInfo.value("name").toString()); - QCoreApplication::setOrganizationName(applicationInfo.value("organizationName").toString()); - QCoreApplication::setOrganizationDomain(applicationInfo.value("organizationDomain").toString()); + // QSettings applicationInfo(PathUtils::resourcesPath() + "info/ApplicationInfo.ini", QSettings::IniFormat); + // // set the associated application properties + // applicationInfo.beginGroup("INFO"); + // QCoreApplication::setApplicationName(applicationInfo.value("name").toString()); + // QCoreApplication::setOrganizationName(applicationInfo.value("organizationName").toString()); + // QCoreApplication::setOrganizationDomain(applicationInfo.value("organizationDomain").toString()); // Let's set up the settings Private instance on its own thread QThread* thread = new QThread(); From 2086a25f931aed76e289bb8008cc36c3c13f634c Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 5 Jun 2015 08:59:19 -0700 Subject: [PATCH 31/49] oops --- libraries/shared/src/SettingInterface.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/shared/src/SettingInterface.cpp b/libraries/shared/src/SettingInterface.cpp index b27d9089b5..c14fd33565 100644 --- a/libraries/shared/src/SettingInterface.cpp +++ b/libraries/shared/src/SettingInterface.cpp @@ -39,12 +39,12 @@ namespace Setting { void init() { // read the ApplicationInfo.ini file for Name/Version/Domain information QSettings::setDefaultFormat(QSettings::IniFormat); - // QSettings applicationInfo(PathUtils::resourcesPath() + "info/ApplicationInfo.ini", QSettings::IniFormat); - // // set the associated application properties - // applicationInfo.beginGroup("INFO"); - // QCoreApplication::setApplicationName(applicationInfo.value("name").toString()); - // QCoreApplication::setOrganizationName(applicationInfo.value("organizationName").toString()); - // QCoreApplication::setOrganizationDomain(applicationInfo.value("organizationDomain").toString()); + QSettings applicationInfo(PathUtils::resourcesPath() + "info/ApplicationInfo.ini", QSettings::IniFormat); + // set the associated application properties + applicationInfo.beginGroup("INFO"); + QCoreApplication::setApplicationName(applicationInfo.value("name").toString()); + QCoreApplication::setOrganizationName(applicationInfo.value("organizationName").toString()); + QCoreApplication::setOrganizationDomain(applicationInfo.value("organizationDomain").toString()); // Let's set up the settings Private instance on its own thread QThread* thread = new QThread(); From 6c7fb7e54cb25393c99988fd0bdf9eb6652f3207 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 5 Jun 2015 09:02:35 -0700 Subject: [PATCH 32/49] Fix setting focus at start-up when not logged in --- interface/resources/qml/LoginDialog.qml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/interface/resources/qml/LoginDialog.qml b/interface/resources/qml/LoginDialog.qml index 55859cb83d..55a4fec34c 100644 --- a/interface/resources/qml/LoginDialog.qml +++ b/interface/resources/qml/LoginDialog.qml @@ -365,9 +365,10 @@ Dialog { } } - onEnabledChanged: { - if (enabled) { - username.forceActiveFocus(); + onOpacityChanged: { + // Set focus once animation is completed so that focus is set at start-up when not logged in + if (opacity == 1.0) { + username.forceActiveFocus() } } From 426fbc662a94794f42e3f8406bf38af87317d5e5 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 5 Jun 2015 09:03:46 -0700 Subject: [PATCH 33/49] White error text instead of black --- interface/resources/qml/LoginDialog.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/resources/qml/LoginDialog.qml b/interface/resources/qml/LoginDialog.qml index 55a4fec34c..b1d488e0cf 100644 --- a/interface/resources/qml/LoginDialog.qml +++ b/interface/resources/qml/LoginDialog.qml @@ -260,7 +260,7 @@ Dialog { verticalAlignment: Text.AlignVCenter text: loginDialog.statusText - color: "black" + color: "white" } Rectangle { From 37aefe73f8a28a7bf08201b7762187c933d2bd6b Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 5 Jun 2015 09:07:07 -0700 Subject: [PATCH 34/49] Remove unnecessary semicolons --- interface/resources/qml/AddressBarDialog.qml | 4 ++-- interface/resources/qml/ErrorDialog.qml | 4 ++-- interface/resources/qml/LoginDialog.qml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/interface/resources/qml/AddressBarDialog.qml b/interface/resources/qml/AddressBarDialog.qml index b4f1b2b247..7fa6bb3481 100644 --- a/interface/resources/qml/AddressBarDialog.qml +++ b/interface/resources/qml/AddressBarDialog.qml @@ -101,7 +101,7 @@ Dialog { onEnabledChanged: { if (enabled) { - addressLine.forceActiveFocus(); + addressLine.forceActiveFocus() } } @@ -123,7 +123,7 @@ Dialog { switch (event.key) { case Qt.Key_Escape: case Qt.Key_Back: - enabled = false; + enabled = false event.accepted = true break case Qt.Key_Enter: diff --git a/interface/resources/qml/ErrorDialog.qml b/interface/resources/qml/ErrorDialog.qml index 51befb12a7..1757aee376 100644 --- a/interface/resources/qml/ErrorDialog.qml +++ b/interface/resources/qml/ErrorDialog.qml @@ -25,7 +25,7 @@ Dialog { onParentChanged: { if (visible && enabled) { - forceActiveFocus(); + forceActiveFocus() } } @@ -90,7 +90,7 @@ Dialog { anchors.fill: parent cursorShape: "PointingHandCursor" onClicked: { - content.accept(); + content.accept() } } } diff --git a/interface/resources/qml/LoginDialog.qml b/interface/resources/qml/LoginDialog.qml index b1d488e0cf..ba8c24f3a7 100644 --- a/interface/resources/qml/LoginDialog.qml +++ b/interface/resources/qml/LoginDialog.qml @@ -384,7 +384,7 @@ Dialog { switch (event.key) { case Qt.Key_Escape: case Qt.Key_Back: - enabled = false; + enabled = false event.accepted = true break case Qt.Key_Enter: @@ -400,7 +400,7 @@ Dialog { loginDialog.login(username.text, password.text) } } - break; + break } } } From 562228e924762c008a73674ac8f4991354d4eafb Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 5 Jun 2015 09:47:34 -0700 Subject: [PATCH 35/49] Change login password recovery link text --- interface/resources/qml/LoginDialog.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/resources/qml/LoginDialog.qml b/interface/resources/qml/LoginDialog.qml index ba8c24f3a7..d75f692827 100644 --- a/interface/resources/qml/LoginDialog.qml +++ b/interface/resources/qml/LoginDialog.qml @@ -289,7 +289,7 @@ Dialog { anchors.horizontalCenter: parent.horizontalCenter Text { - text: "Forgot Password?" + text: "Password?" font.pixelSize: hifi.fonts.pixelSize * 0.8 font.underline: true color: "#e0e0e0" From eb912892dce9757c984b100bf4295277456454e1 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 5 Jun 2015 09:56:34 -0700 Subject: [PATCH 36/49] code review --- libraries/entities/src/EntityActionInterface.cpp | 2 +- libraries/entities/src/EntityActionInterface.h | 6 +++--- libraries/entities/src/EntityItem.cpp | 4 ++-- libraries/entities/src/EntityItem.h | 8 +++----- libraries/entities/src/EntityScriptingInterface.cpp | 9 ++++----- libraries/entities/src/EntityScriptingInterface.h | 2 +- 6 files changed, 14 insertions(+), 17 deletions(-) diff --git a/libraries/entities/src/EntityActionInterface.cpp b/libraries/entities/src/EntityActionInterface.cpp index 8d848b356a..f26dd006ff 100644 --- a/libraries/entities/src/EntityActionInterface.cpp +++ b/libraries/entities/src/EntityActionInterface.cpp @@ -1,5 +1,5 @@ // -// EntityItem.h +// EntityActionInterface.cpp // libraries/entities/src // // Created by Seth Alves on 2015-6-4 diff --git a/libraries/entities/src/EntityActionInterface.h b/libraries/entities/src/EntityActionInterface.h index fff8d48fba..74efae3239 100644 --- a/libraries/entities/src/EntityActionInterface.h +++ b/libraries/entities/src/EntityActionInterface.h @@ -1,5 +1,5 @@ // -// EntityItem.h +// EntityActionInterface.h // libraries/entities/src // // Created by Seth Alves on 2015-6-2 @@ -24,7 +24,7 @@ enum EntityActionType { class EntityActionInterface { - public: +public: EntityActionInterface() { } virtual ~EntityActionInterface() { } virtual const QUuid& getID() const = 0; @@ -38,7 +38,7 @@ class EntityActionInterface { static EntityActionType actionTypeFromString(QString actionTypeString); static QString actionTypeToString(EntityActionType actionType); - protected: +protected: static glm::vec3 extractVec3Argument(QString objectName, QVariantMap arguments, QString argumentName, bool& ok); static float extractFloatArgument(QString objectName, QVariantMap arguments, QString argumentName, bool& ok); diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 247fbee76e..1b36952bdb 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -1351,7 +1351,7 @@ bool EntityItem::addAction(EntitySimulation* simulation, EntityActionPointer act return false; } -bool EntityItem::updateAction(EntitySimulation* simulation, const QUuid actionID, QVariantMap arguments) { +bool EntityItem::updateAction(EntitySimulation* simulation, const QUuid& actionID, QVariantMap& arguments) { if (!_objectActions.contains(actionID)) { return false; } @@ -1359,7 +1359,7 @@ bool EntityItem::updateAction(EntitySimulation* simulation, const QUuid actionID return action->updateArguments(arguments); } -bool EntityItem::removeAction(EntitySimulation* simulation, const QUuid actionID) { +bool EntityItem::removeAction(EntitySimulation* simulation, const QUuid& actionID) { if (_objectActions.contains(actionID)) { EntityActionPointer action = _objectActions[actionID]; _objectActions.remove(actionID); diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index 0a8e1c2196..7538f99d66 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -178,9 +178,7 @@ public: EntityTypes::EntityType getType() const { return _type; } const glm::vec3& getPosition() const { return _position; } /// get position in meters - void setPosition(const glm::vec3& value) { - _position = value; - } + void setPosition(const glm::vec3& value) { _position = value; } glm::vec3 getCenter() const; @@ -355,8 +353,8 @@ public: void getAllTerseUpdateProperties(EntityItemProperties& properties) const; bool addAction(EntitySimulation* simulation, EntityActionPointer action); - bool updateAction(EntitySimulation* simulation, const QUuid actionID, QVariantMap arguments); - bool removeAction(EntitySimulation* simulation, const QUuid actionID); + bool updateAction(EntitySimulation* simulation, const QUuid& actionID, QVariantMap& arguments); + bool removeAction(EntitySimulation* simulation, const QUuid& actionID); void clearActions(EntitySimulation* simulation); protected: diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index e04bd977a2..7ec95c167b 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -451,7 +451,7 @@ bool EntityScriptingInterface::setAllVoxels(QUuid entityID, int value) { } -bool EntityScriptingInterface::actionWorker(QUuid entityID, std::function actor) { +bool EntityScriptingInterface::actionWorker(QUuid& entityID, std::function actor) { if (!_entityTree) { return false; } @@ -478,10 +478,9 @@ bool EntityScriptingInterface::actionWorker(QUuid entityID, std::functionupdateAction(simulation, actionID, arguments); }); } bool EntityScriptingInterface::deleteAction(QUuid entityID, QUuid actionID) { - return actionWorker(entityID, [entityID, actionID](EntitySimulation* simulation, EntityItemPointer entity) { + return actionWorker(entityID, [&](EntitySimulation* simulation, EntityItemPointer entity) { return entity->removeAction(simulation, actionID); }); } diff --git a/libraries/entities/src/EntityScriptingInterface.h b/libraries/entities/src/EntityScriptingInterface.h index 5c81ab15dd..4d1a49ae9f 100644 --- a/libraries/entities/src/EntityScriptingInterface.h +++ b/libraries/entities/src/EntityScriptingInterface.h @@ -155,7 +155,7 @@ signals: void clearingEntities(); private: - bool actionWorker(QUuid entityID, std::function actor); + bool actionWorker(QUuid& entityID, std::function actor); bool setVoxels(QUuid entityID, std::function actor); void queueEntityMessage(PacketType packetType, EntityItemID entityID, const EntityItemProperties& properties); From 51f5730e689064e5978b886daebda6ec68e5fb39 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 5 Jun 2015 10:05:11 -0700 Subject: [PATCH 37/49] formatting --- libraries/entities/src/EntityScriptingInterface.cpp | 3 +-- libraries/physics/src/ObjectActionPullToPoint.cpp | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 7ec95c167b..ce64c62dcf 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -480,8 +480,7 @@ bool EntityScriptingInterface::actionWorker(QUuid& entityID, std::function IGNORE_POSITION_DELTA) { glm::vec3 newVelocity = glm::normalize(offset) * _speed; rigidBody->setLinearVelocity(glmToBullet(newVelocity)); - rigidBody->activate(); // ?? + rigidBody->activate(); } else { rigidBody->setLinearVelocity(glmToBullet(glm::vec3())); } From c8236f867be2537eedd9006614ac8a5c6fcb4b4a Mon Sep 17 00:00:00 2001 From: Niraj Venkat Date: Fri, 5 Jun 2015 10:40:17 -0700 Subject: [PATCH 38/49] Address manager changes to support domain ID --- libraries/networking/src/AddressManager.cpp | 56 ++++++++++++++++++++- libraries/networking/src/AddressManager.h | 2 + 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/libraries/networking/src/AddressManager.cpp b/libraries/networking/src/AddressManager.cpp index 3c6b7bd3f5..0a50cc0793 100644 --- a/libraries/networking/src/AddressManager.cpp +++ b/libraries/networking/src/AddressManager.cpp @@ -123,6 +123,10 @@ bool AddressManager::handleUrl(const QUrl& lookupUrl) { + (lookupUrl.port() == -1 ? "" : ":" + QString::number(lookupUrl.port())))) { // we may have a path that defines a relative viewpoint - if so we should jump to that now handlePath(lookupUrl.path()); + } else if (handleDomainID(lookupUrl.host())){ + // no place name - this is probably a domain ID + // try to look up the domain ID on the metaverse API + attemptDomainIDLookup(lookupUrl.host(), lookupUrl.path()); } else { // wasn't an address - lookup the place name // we may have a path that defines a relative viewpoint - pass that through the lookup so we can go to it after @@ -165,7 +169,11 @@ void AddressManager::handleAPIResponse(QNetworkReply& requestReply) { QJsonObject responseObject = QJsonDocument::fromJson(requestReply.readAll()).object(); QJsonObject dataObject = responseObject["data"].toObject(); - goToAddressFromObject(dataObject.toVariantMap(), requestReply); + if (!dataObject.isEmpty()){ + goToAddressFromObject(dataObject.toVariantMap(), requestReply); + } else { + goToAddressFromObject(responseObject.toVariantMap(), requestReply); + } emit lookupResultsFinished(); } @@ -175,11 +183,14 @@ const char OVERRIDE_PATH_KEY[] = "override_path"; void AddressManager::goToAddressFromObject(const QVariantMap& dataObject, const QNetworkReply& reply) { const QString DATA_OBJECT_PLACE_KEY = "place"; + const QString DATA_OBJECT_DOMAIN_KEY = "domain"; const QString DATA_OBJECT_USER_LOCATION_KEY = "location"; QVariantMap locationMap; if (dataObject.contains(DATA_OBJECT_PLACE_KEY)) { locationMap = dataObject[DATA_OBJECT_PLACE_KEY].toMap(); + } else if (dataObject.contains(DATA_OBJECT_DOMAIN_KEY)) { + locationMap = dataObject; } else { locationMap = dataObject[DATA_OBJECT_USER_LOCATION_KEY].toMap(); } @@ -304,6 +315,24 @@ void AddressManager::attemptPlaceNameLookup(const QString& lookupString, const Q QByteArray(), NULL, requestParams); } +const QString GET_DOMAIN_ID = "/api/v1/domains/%1"; + +void AddressManager::attemptDomainIDLookup(const QString& lookupString, const QString& overridePath) { + // assume this is a domain ID and see if we can get any info on it + QString domainID = QUrl::toPercentEncoding(lookupString); + + QVariantMap requestParams; + if (!overridePath.isEmpty()) { + requestParams.insert(OVERRIDE_PATH_KEY, overridePath); + } + + AccountManager::getInstance().sendRequest(GET_DOMAIN_ID.arg(domainID), + AccountManagerAuth::None, + QNetworkAccessManager::GetOperation, + apiCallbackParameters(), + QByteArray(), NULL, requestParams); +} + bool AddressManager::handleNetworkAddress(const QString& lookupString) { const QString IP_ADDRESS_REGEX_STRING = "^((?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}" "(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))(?::(\\d{1,5}))?$"; @@ -335,7 +364,7 @@ bool AddressManager::handleNetworkAddress(const QString& lookupString) { quint16 domainPort = DEFAULT_DOMAIN_SERVER_PORT; if (!hostnameRegex.cap(2).isEmpty()) { - domainPort = (qint16) hostnameRegex.cap(2).toInt(); + domainPort = (qint16)hostnameRegex.cap(2).toInt(); } emit lookupResultsFinished(); @@ -347,6 +376,29 @@ bool AddressManager::handleNetworkAddress(const QString& lookupString) { return false; } +bool AddressManager::handleDomainID(const QString& host) { + const QString UUID_REGEX_STRING = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"; + + QRegExp domainIDRegex(UUID_REGEX_STRING, Qt::CaseInsensitive); + + if (domainIDRegex.indexIn(host) != -1) { + QString domainID = domainIDRegex.cap(1); + + quint16 domainPort = DEFAULT_DOMAIN_SERVER_PORT; + + if (!domainIDRegex.cap(2).isEmpty()) { + domainPort = (qint16)domainIDRegex.cap(2).toInt(); + } + + emit lookupResultsFinished(); + setDomainInfo(domainID, domainPort); + + return true; + } + + return false; +} + void AddressManager::handlePath(const QString& path) { if (!handleViewpoint(path)) { qCDebug(networking) << "User entered path could not be handled as a viewpoint - " << path << diff --git a/libraries/networking/src/AddressManager.h b/libraries/networking/src/AddressManager.h index 5831d62603..ccbdd4e037 100644 --- a/libraries/networking/src/AddressManager.h +++ b/libraries/networking/src/AddressManager.h @@ -50,6 +50,7 @@ public: void setRootPlaceName(const QString& rootPlaceName); void attemptPlaceNameLookup(const QString& lookupString, const QString& overridePath = QString()); + void attemptDomainIDLookup(const QString& lookupString, const QString& overridePath = QString()); void setPositionGetter(PositionGetter positionGetter) { _positionGetter = positionGetter; } void setOrientationGetter(OrientationGetter orientationGetter) { _orientationGetter = orientationGetter; } @@ -95,6 +96,7 @@ private: void handlePath(const QString& path); bool handleViewpoint(const QString& viewpointString, bool shouldFace = false); bool handleUsername(const QString& lookupString); + bool handleDomainID(const QString& host); QString _rootPlaceName; QUuid _rootPlaceID; From aff582287da88d569b526816303292d53284efe0 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 5 Jun 2015 11:26:54 -0700 Subject: [PATCH 39/49] use const references for arguments in action-related calls --- libraries/entities/src/EntityItem.cpp | 2 +- libraries/entities/src/EntityItem.h | 2 +- libraries/entities/src/EntityScriptingInterface.cpp | 11 +++++++---- libraries/entities/src/EntityScriptingInterface.h | 8 ++++---- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 2536e8aa1e..03ecc6bb68 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -1358,7 +1358,7 @@ bool EntityItem::addAction(EntitySimulation* simulation, EntityActionPointer act return false; } -bool EntityItem::updateAction(EntitySimulation* simulation, const QUuid& actionID, QVariantMap& arguments) { +bool EntityItem::updateAction(EntitySimulation* simulation, const QUuid& actionID, const QVariantMap& arguments) { if (!_objectActions.contains(actionID)) { return false; } diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index 7538f99d66..6c91cc9318 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -353,7 +353,7 @@ public: void getAllTerseUpdateProperties(EntityItemProperties& properties) const; bool addAction(EntitySimulation* simulation, EntityActionPointer action); - bool updateAction(EntitySimulation* simulation, const QUuid& actionID, QVariantMap& arguments); + bool updateAction(EntitySimulation* simulation, const QUuid& actionID, const QVariantMap& arguments); bool removeAction(EntitySimulation* simulation, const QUuid& actionID); void clearActions(EntitySimulation* simulation); diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 0770fbc69e..836e7f5225 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -459,7 +459,8 @@ bool EntityScriptingInterface::setAllVoxels(QUuid entityID, int value) { } -bool EntityScriptingInterface::actionWorker(QUuid& entityID, std::function actor) { +bool EntityScriptingInterface::actionWorker(const QUuid& entityID, + std::function actor) { if (!_entityTree) { return false; } @@ -486,7 +487,9 @@ bool EntityScriptingInterface::actionWorker(QUuid& entityID, std::functionupdateAction(simulation, actionID, arguments); }); } -bool EntityScriptingInterface::deleteAction(QUuid entityID, QUuid actionID) { +bool EntityScriptingInterface::deleteAction(const QUuid& entityID, const QUuid& actionID) { return actionWorker(entityID, [&](EntitySimulation* simulation, EntityItemPointer entity) { return entity->removeAction(simulation, actionID); }); diff --git a/libraries/entities/src/EntityScriptingInterface.h b/libraries/entities/src/EntityScriptingInterface.h index 82e7c18c07..c6bc43c8c6 100644 --- a/libraries/entities/src/EntityScriptingInterface.h +++ b/libraries/entities/src/EntityScriptingInterface.h @@ -124,9 +124,9 @@ public slots: Q_INVOKABLE void dumpTree() const; - Q_INVOKABLE QUuid addAction(QString actionTypeString, QUuid entityID, QVariantMap arguments); - Q_INVOKABLE bool updateAction(QUuid entityID, QUuid actionID, QVariantMap arguments); - Q_INVOKABLE bool deleteAction(QUuid entityID, QUuid actionID); + Q_INVOKABLE QUuid addAction(const QString& actionTypeString, const QUuid& entityID, const QVariantMap& arguments); + Q_INVOKABLE bool updateAction(const QUuid& entityID, const QUuid& actionID, const QVariantMap& arguments); + Q_INVOKABLE bool deleteAction(const QUuid& entityID, const QUuid& actionID); signals: void entityCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision); @@ -155,7 +155,7 @@ signals: void clearingEntities(); private: - bool actionWorker(QUuid& entityID, std::function actor); + bool actionWorker(const QUuid& entityID, std::function actor); bool setVoxels(QUuid entityID, std::function actor); void queueEntityMessage(PacketType packetType, EntityItemID entityID, const EntityItemProperties& properties); From f168385798158c37d9d2d9fb2c075facbfe77e40 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 5 Jun 2015 12:57:40 -0700 Subject: [PATCH 40/49] Add spinner in place of "Logging in..." --- interface/resources/qml/LoginDialog.qml | 69 ++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 6 deletions(-) diff --git a/interface/resources/qml/LoginDialog.qml b/interface/resources/qml/LoginDialog.qml index d75f692827..0fa6ff43cc 100644 --- a/interface/resources/qml/LoginDialog.qml +++ b/interface/resources/qml/LoginDialog.qml @@ -252,15 +252,72 @@ Dialog { } } - Text { - id: messageText + Item { width: loginDialog.inputWidth height: loginDialog.inputHeight / 2 - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - text: loginDialog.statusText - color: "white" + Text { + id: messageText + + visible: loginDialog.statusText != "" && loginDialog.statusText != "Logging in..." + + width: loginDialog.inputWidth + height: loginDialog.inputHeight / 2 + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + + text: loginDialog.statusText + color: "white" + } + + Row { + id: messageSpinner + + visible: loginDialog.statusText == "Logging in..." + onVisibleChanged: visible ? messageSpinnerAnimation.restart() : messageSpinnerAnimation.stop() + + spacing: 24 + anchors { + verticalCenter: parent.verticalCenter + horizontalCenter: parent.horizontalCenter + } + + Rectangle { + id: spinner1 + width: 10 + height: 10 + color: "#ebebeb" + opacity: 0.05 + } + + Rectangle { + id: spinner2 + width: 10 + height: 10 + color: "#ebebeb" + opacity: 0.05 + } + + Rectangle { + id: spinner3 + width: 10 + height: 10 + color: "#ebebeb" + opacity: 0.05 + } + + SequentialAnimation { + id: messageSpinnerAnimation + running: messageSpinner.visible + loops: Animation.Infinite + NumberAnimation { target: spinner1; property: "opacity"; to: 1.0; duration: 1000 } + NumberAnimation { target: spinner2; property: "opacity"; to: 1.0; duration: 1000 } + NumberAnimation { target: spinner3; property: "opacity"; to: 1.0; duration: 1000 } + NumberAnimation { target: spinner1; property: "opacity"; to: 0.05; duration: 0 } + NumberAnimation { target: spinner2; property: "opacity"; to: 0.05; duration: 0 } + NumberAnimation { target: spinner3; property: "opacity"; to: 0.05; duration: 0 } + } + } } Rectangle { From 7e9122e3d13bf1d78f71ad70bc9cbcf2eb310d0b Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 5 Jun 2015 13:15:18 -0700 Subject: [PATCH 41/49] Replace login background SVGs with QML rectangles --- interface/resources/images/login-circle.svg | 3 --- interface/resources/images/login-rectangle.svg | 3 --- interface/resources/qml/LoginDialog.qml | 14 ++++++++++---- 3 files changed, 10 insertions(+), 10 deletions(-) delete mode 100644 interface/resources/images/login-circle.svg delete mode 100644 interface/resources/images/login-rectangle.svg diff --git a/interface/resources/images/login-circle.svg b/interface/resources/images/login-circle.svg deleted file mode 100644 index 8a98902e6b..0000000000 --- a/interface/resources/images/login-circle.svg +++ /dev/null @@ -1,3 +0,0 @@ - - -2015-06-02 19:43ZCanvas 1Login Circle diff --git a/interface/resources/images/login-rectangle.svg b/interface/resources/images/login-rectangle.svg deleted file mode 100644 index 774baf8193..0000000000 --- a/interface/resources/images/login-rectangle.svg +++ /dev/null @@ -1,3 +0,0 @@ - - -2015-06-02 19:42ZCanvas 1Login2 diff --git a/interface/resources/qml/LoginDialog.qml b/interface/resources/qml/LoginDialog.qml index 0fa6ff43cc..aa6cbb162d 100644 --- a/interface/resources/qml/LoginDialog.qml +++ b/interface/resources/qml/LoginDialog.qml @@ -48,12 +48,15 @@ Dialog { property int maximumY: parent ? parent.height - height : 0 property real tan30: 0.577 // tan(30°) - Image { + Rectangle { id: circularBackground visible: isCircular() - source: "../images/login-circle.svg" width: loginDialog.inputWidth * 1.2 height: width + radius: width / 2 + + color: "#2c86b1" + opacity: 0.85 Item { // Approximage circle with 3 rectangles that together contain the circle in a hexagon. @@ -119,12 +122,15 @@ Dialog { } } - Image { + Rectangle { id: rectangularBackground visible: !isCircular() - source: "../images/login-rectangle.svg" width: loginDialog.inputWidth + loginDialog.borderWidth * 2 height: loginDialog.inputHeight * 6 + loginDialog.closeMargin * 2 + radius: loginDialog.closeMargin * 2 + + color: "#2c86b1" + opacity: 0.85 MouseArea { width: parent.width From ee8449712c243114d235d0a5636387af48c1b871 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 5 Jun 2015 13:23:06 -0700 Subject: [PATCH 42/49] Code review and tidying --- interface/resources/qml/ErrorDialog.qml | 2 -- interface/resources/qml/LoginDialog.qml | 10 +++++----- interface/resources/qml/controls/Dialog.qml | 4 ++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/interface/resources/qml/ErrorDialog.qml b/interface/resources/qml/ErrorDialog.qml index 1757aee376..26b18f4ffd 100644 --- a/interface/resources/qml/ErrorDialog.qml +++ b/interface/resources/qml/ErrorDialog.qml @@ -17,8 +17,6 @@ Dialog { id: root HifiConstants { id: hifi } - property bool destroyOnInvisible: true - Component.onCompleted: { enabled = true } diff --git a/interface/resources/qml/LoginDialog.qml b/interface/resources/qml/LoginDialog.qml index aa6cbb162d..3291fed0d0 100644 --- a/interface/resources/qml/LoginDialog.qml +++ b/interface/resources/qml/LoginDialog.qml @@ -39,14 +39,14 @@ Dialog { implicitWidth: isCircular() ? circularBackground.width : rectangularBackground.width implicitHeight: isCircular() ? circularBackground.height : rectangularBackground.height - property int inputWidth: 500 - property int inputHeight: 60 + readonly property int inputWidth: 500 + readonly property int inputHeight: 60 + readonly property int borderWidth: 30 + readonly property int closeMargin: 16 + readonly property real tan30: 0.577 // tan(30°) property int inputSpacing: isCircular() ? 24 : 16 - property int borderWidth: 30 - property int closeMargin: 16 property int maximumX: parent ? parent.width - width : 0 property int maximumY: parent ? parent.height - height : 0 - property real tan30: 0.577 // tan(30°) Rectangle { id: circularBackground diff --git a/interface/resources/qml/controls/Dialog.qml b/interface/resources/qml/controls/Dialog.qml index 63430bdae0..3cada90c3e 100644 --- a/interface/resources/qml/controls/Dialog.qml +++ b/interface/resources/qml/controls/Dialog.qml @@ -15,7 +15,7 @@ import "../styles" Item { id: root - property int animationDuration: hifi.effects.fadeInDuration + property bool destroyOnInvisible: true // The UI enables an object, rather than manipulating its visibility, so that we can do animations in both directions. @@ -32,7 +32,7 @@ Item { Behavior on opacity { // Animate opacity. NumberAnimation { - duration: animationDuration + duration: hifi.effects.fadeInDuration easing.type: Easing.OutCubic } } From a3f19e9d4c0371d95380736bb7e21175388798f4 Mon Sep 17 00:00:00 2001 From: Niraj Venkat Date: Fri, 5 Jun 2015 13:33:14 -0700 Subject: [PATCH 43/49] Fixing title bar update on teleport --- interface/src/Application.cpp | 4 +- libraries/networking/src/AddressManager.cpp | 47 ++++++++------------- libraries/networking/src/AddressManager.h | 10 ++--- 3 files changed, 25 insertions(+), 36 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 2b6ec63d4b..bdc4b83aa6 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -474,7 +474,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : addressManager->setPositionGetter(getPositionForPath); addressManager->setOrientationGetter(getOrientationForPath); - connect(addressManager.data(), &AddressManager::rootPlaceNameChanged, this, &Application::updateWindowTitle); + connect(addressManager.data(), &AddressManager::hostChanged, this, &Application::updateWindowTitle); connect(this, &QCoreApplication::aboutToQuit, addressManager.data(), &AddressManager::storeCurrentAddress); #ifdef _WIN32 @@ -3646,7 +3646,7 @@ void Application::updateWindowTitle(){ QString connectionStatus = nodeList->getDomainHandler().isConnected() ? "" : " (NOT CONNECTED) "; QString username = AccountManager::getInstance().getAccountInfo().getUsername(); - QString currentPlaceName = DependencyManager::get()->getRootPlaceName(); + QString currentPlaceName = DependencyManager::get()->getHost(); if (currentPlaceName.isEmpty()) { currentPlaceName = nodeList->getDomainHandler().getHostname(); diff --git a/libraries/networking/src/AddressManager.cpp b/libraries/networking/src/AddressManager.cpp index 0a50cc0793..e813b214f1 100644 --- a/libraries/networking/src/AddressManager.cpp +++ b/libraries/networking/src/AddressManager.cpp @@ -30,7 +30,7 @@ const QString SETTINGS_CURRENT_ADDRESS_KEY = "address"; Setting::Handle currentAddressHandle(QStringList() << ADDRESS_MANAGER_SETTINGS_GROUP << "address", DEFAULT_HIFI_ADDRESS); AddressManager::AddressManager() : - _rootPlaceName(), + _host(), _rootPlaceID(), _positionGetter(NULL), _orientationGetter(NULL) @@ -45,7 +45,7 @@ const QUrl AddressManager::currentAddress() const { QUrl hifiURL; hifiURL.setScheme(HIFI_URL_SCHEME); - hifiURL.setHost(_rootPlaceName); + hifiURL.setHost(_host); hifiURL.setPath(currentPath()); return hifiURL; @@ -217,6 +217,10 @@ void AddressManager::goToAddressFromObject(const QVariantMap& dataObject, const DependencyManager::get()->flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::HandleAddress); + const QString DOMAIN_ID_KEY = "id"; + QString domainIDString = domainObject[DOMAIN_ID_KEY].toString(); + QUuid domainID(domainIDString); + if (domainObject.contains(DOMAIN_NETWORK_ADDRESS_KEY)) { QString domainHostname = domainObject[DOMAIN_NETWORK_ADDRESS_KEY].toString(); @@ -230,10 +234,6 @@ void AddressManager::goToAddressFromObject(const QVariantMap& dataObject, const } else { QString iceServerAddress = domainObject[DOMAIN_ICE_SERVER_ADDRESS_KEY].toString(); - const QString DOMAIN_ID_KEY = "id"; - QString domainIDString = domainObject[DOMAIN_ID_KEY].toString(); - QUuid domainID(domainIDString); - qCDebug(networking) << "Possible domain change required to connect to domain with ID" << domainID << "via ice-server at" << iceServerAddress; @@ -246,8 +246,12 @@ void AddressManager::goToAddressFromObject(const QVariantMap& dataObject, const // set our current root place name to the name that came back const QString PLACE_NAME_KEY = "name"; - QString newRootPlaceName = rootMap[PLACE_NAME_KEY].toString(); - setRootPlaceName(newRootPlaceName); + QString placeName = rootMap[PLACE_NAME_KEY].toString(); + if (!placeName.isEmpty()) { + setHost(placeName); + } else { + setHost(domainIDString); + } // check if we had a path to override the path returned QString overridePath = reply.property(OVERRIDE_PATH_KEY).toString(); @@ -381,22 +385,7 @@ bool AddressManager::handleDomainID(const QString& host) { QRegExp domainIDRegex(UUID_REGEX_STRING, Qt::CaseInsensitive); - if (domainIDRegex.indexIn(host) != -1) { - QString domainID = domainIDRegex.cap(1); - - quint16 domainPort = DEFAULT_DOMAIN_SERVER_PORT; - - if (!domainIDRegex.cap(2).isEmpty()) { - domainPort = (qint16)domainIDRegex.cap(2).toInt(); - } - - emit lookupResultsFinished(); - setDomainInfo(domainID, domainPort); - - return true; - } - - return false; + return (domainIDRegex.indexIn(host) != -1); } void AddressManager::handlePath(const QString& path) { @@ -474,16 +463,16 @@ bool AddressManager::handleUsername(const QString& lookupString) { return false; } -void AddressManager::setRootPlaceName(const QString& rootPlaceName) { - if (rootPlaceName != _rootPlaceName) { - _rootPlaceName = rootPlaceName; - emit rootPlaceNameChanged(_rootPlaceName); +void AddressManager::setHost(const QString& host) { + if (host != _host) { + _host = host; + emit hostChanged(_host); } } void AddressManager::setDomainInfo(const QString& hostname, quint16 port) { - _rootPlaceName = hostname; + _host = hostname; _rootPlaceID = QUuid(); qCDebug(networking) << "Possible domain change required to connect to domain at" << hostname << "on" << port; diff --git a/libraries/networking/src/AddressManager.h b/libraries/networking/src/AddressManager.h index ccbdd4e037..2b587a9bd7 100644 --- a/libraries/networking/src/AddressManager.h +++ b/libraries/networking/src/AddressManager.h @@ -35,7 +35,7 @@ class AddressManager : public QObject, public Dependency { Q_PROPERTY(bool isConnected READ isConnected) Q_PROPERTY(QUrl href READ currentAddress) Q_PROPERTY(QString protocol READ getProtocol) - Q_PROPERTY(QString hostname READ getRootPlaceName) + Q_PROPERTY(QString hostname READ getHost) Q_PROPERTY(QString pathname READ currentPath) public: bool isConnected(); @@ -46,8 +46,8 @@ public: const QUuid& getRootPlaceID() const { return _rootPlaceID; } - const QString& getRootPlaceName() const { return _rootPlaceName; } - void setRootPlaceName(const QString& rootPlaceName); + const QString& getHost() const { return _host; } + void setHost(const QString& host); void attemptPlaceNameLookup(const QString& lookupString, const QString& overridePath = QString()); void attemptDomainIDLookup(const QString& lookupString, const QString& overridePath = QString()); @@ -79,7 +79,7 @@ signals: bool hasOrientationChange, const glm::quat& newOrientation, bool shouldFaceLocation); void pathChangeRequired(const QString& newPath); - void rootPlaceNameChanged(const QString& newRootPlaceName); + void hostChanged(const QString& newHost); protected: AddressManager(); private slots: @@ -98,7 +98,7 @@ private: bool handleUsername(const QString& lookupString); bool handleDomainID(const QString& host); - QString _rootPlaceName; + QString _host; QUuid _rootPlaceID; PositionGetter _positionGetter; OrientationGetter _orientationGetter; From 037a70b03a8ade08a1315023968a42e42a78ca0c Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 5 Jun 2015 13:47:07 -0700 Subject: [PATCH 44/49] undo unneeded/breaky change in grab.js --- examples/grab.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/grab.js b/examples/grab.js index 3d95592068..593c671506 100644 --- a/examples/grab.js +++ b/examples/grab.js @@ -88,8 +88,6 @@ function mousePressEvent(event) { Entities.editEntity(grabbedEntity, { gravity: {x: 0, y: 0, z: 0} }); - - Controller.mouseMoveEvent.connect(mouseMoveEvent); } } @@ -112,7 +110,7 @@ function updateDropLine(position) { function mouseReleaseEvent() { if (isGrabbing) { - Controller.mouseMoveEvent.disconnect(mouseMoveEvent); + // Controller.mouseMoveEvent.disconnect(mouseMoveEvent); isGrabbing = false; Entities.deleteAction(grabbedEntity, actionID); actionID = null; @@ -254,6 +252,7 @@ function update(deltaTime) { Controller.mousePressEvent.connect(mousePressEvent); Controller.mouseReleaseEvent.connect(mouseReleaseEvent); +Controller.mouseMoveEvent.connect(mouseMoveEvent); Controller.keyPressEvent.connect(keyPressEvent); Controller.keyReleaseEvent.connect(keyReleaseEvent); Script.update.connect(update); From 141ff70a60af68e204fb92e50472e660ba79b846 Mon Sep 17 00:00:00 2001 From: Niraj Venkat Date: Fri, 5 Jun 2015 15:36:42 -0700 Subject: [PATCH 45/49] Some changes to constants --- libraries/networking/src/AddressManager.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libraries/networking/src/AddressManager.cpp b/libraries/networking/src/AddressManager.cpp index e813b214f1..a86ce78655 100644 --- a/libraries/networking/src/AddressManager.cpp +++ b/libraries/networking/src/AddressManager.cpp @@ -165,13 +165,16 @@ void AddressManager::handleLookupString(const QString& lookupString) { } } +const QString DATA_OBJECT_DOMAIN_KEY = "domain"; + + void AddressManager::handleAPIResponse(QNetworkReply& requestReply) { QJsonObject responseObject = QJsonDocument::fromJson(requestReply.readAll()).object(); QJsonObject dataObject = responseObject["data"].toObject(); - if (!dataObject.isEmpty()){ + if (!dataObject.isEmpty()) { goToAddressFromObject(dataObject.toVariantMap(), requestReply); - } else { + } else if (responseObject.contains(DATA_OBJECT_DOMAIN_KEY)) { goToAddressFromObject(responseObject.toVariantMap(), requestReply); } @@ -183,7 +186,6 @@ const char OVERRIDE_PATH_KEY[] = "override_path"; void AddressManager::goToAddressFromObject(const QVariantMap& dataObject, const QNetworkReply& reply) { const QString DATA_OBJECT_PLACE_KEY = "place"; - const QString DATA_OBJECT_DOMAIN_KEY = "domain"; const QString DATA_OBJECT_USER_LOCATION_KEY = "location"; QVariantMap locationMap; From c7c355c19f1435ec8133ea37539d041b71875469 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 5 Jun 2015 15:37:25 -0700 Subject: [PATCH 46/49] Remove circular login dialog variation --- interface/resources/qml/LoginDialog.qml | 116 ++---------------------- interface/src/Menu.cpp | 15 --- interface/src/Menu.h | 2 - interface/src/ui/DialogsManager.cpp | 4 - interface/src/ui/DialogsManager.h | 4 - interface/src/ui/LoginDialog.cpp | 26 +----- interface/src/ui/LoginDialog.h | 9 -- 7 files changed, 9 insertions(+), 167 deletions(-) diff --git a/interface/resources/qml/LoginDialog.qml b/interface/resources/qml/LoginDialog.qml index 3291fed0d0..e552532cbd 100644 --- a/interface/resources/qml/LoginDialog.qml +++ b/interface/resources/qml/LoginDialog.qml @@ -29,102 +29,23 @@ Dialog { property int maximumX: parent ? parent.width - width : 0 property int maximumY: parent ? parent.height - height : 0 - function isCircular() { - return loginDialog.dialogFormat == "circular" - } - LoginDialog { id: loginDialog - implicitWidth: isCircular() ? circularBackground.width : rectangularBackground.width - implicitHeight: isCircular() ? circularBackground.height : rectangularBackground.height + implicitWidth: backgroundRectangle.width + implicitHeight: backgroundRectangle.height readonly property int inputWidth: 500 readonly property int inputHeight: 60 readonly property int borderWidth: 30 readonly property int closeMargin: 16 readonly property real tan30: 0.577 // tan(30°) - property int inputSpacing: isCircular() ? 24 : 16 + readonly property int inputSpacing: 16 property int maximumX: parent ? parent.width - width : 0 property int maximumY: parent ? parent.height - height : 0 Rectangle { - id: circularBackground - visible: isCircular() - width: loginDialog.inputWidth * 1.2 - height: width - radius: width / 2 - - color: "#2c86b1" - opacity: 0.85 - - Item { - // Approximage circle with 3 rectangles that together contain the circle in a hexagon. - anchors.fill: parent - - MouseArea { - width: parent.width - height: parent.width * loginDialog.tan30 - anchors { - horizontalCenter: parent.horizontalCenter - verticalCenter: parent.verticalCenter - } - drag { - target: root - minimumX: -loginDialog.borderWidth - minimumY: -loginDialog.borderWidth - maximumX: root.parent ? root.maximumX + loginDialog.borderWidth : 0 - maximumY: root.parent ? root.maximumY + loginDialog.borderWidth : 0 - } - } - - MouseArea { - width: parent.width - height: parent.width * loginDialog.tan30 - anchors { - horizontalCenter: parent.horizontalCenter - verticalCenter: parent.verticalCenter - } - transform: Rotation { - origin.x: width / 2 - origin.y: width * loginDialog.tan30 / 2 - angle: -60 - } - drag { - target: root - minimumX: -loginDialog.borderWidth - minimumY: -loginDialog.borderWidth - maximumX: root.parent ? root.maximumX + loginDialog.borderWidth : 0 - maximumY: root.parent ? root.maximumY + loginDialog.borderWidth : 0 - } - } - - MouseArea { - width: parent.width - height: parent.width * loginDialog.tan30 - anchors { - horizontalCenter: parent.horizontalCenter - verticalCenter: parent.verticalCenter - } - transform: Rotation { - origin.x: width / 2 - origin.y: width * loginDialog.tan30 / 2 - angle: 60 - } - drag { - target: root - minimumX: -loginDialog.borderWidth - minimumY: -loginDialog.borderWidth - maximumX: root.parent ? root.maximumX + loginDialog.borderWidth : 0 - maximumY: root.parent ? root.maximumY + loginDialog.borderWidth : 0 - } - } - } - } - - Rectangle { - id: rectangularBackground - visible: !isCircular() + id: backgroundRectangle width: loginDialog.inputWidth + loginDialog.borderWidth * 2 height: loginDialog.inputHeight * 6 + loginDialog.closeMargin * 2 radius: loginDialog.closeMargin * 2 @@ -151,13 +72,12 @@ Dialog { Image { id: closeIcon - visible: !isCircular() source: "../images/login-close.svg" width: 20 height: 20 anchors { - top: rectangularBackground.top - right: rectangularBackground.right + top: backgroundRectangle.top + right: backgroundRectangle.right topMargin: loginDialog.closeMargin rightMargin: loginDialog.closeMargin } @@ -183,7 +103,7 @@ Dialog { Item { // Offset content down a little width: loginDialog.inputWidth - height: isCircular() ? loginDialog.inputHeight : loginDialog.closeMargin + height: loginDialog.closeMargin } Rectangle { @@ -404,28 +324,6 @@ Dialog { } } } - - Text { - id: closeText - visible: isCircular() - anchors { - horizontalCenter: parent.horizontalCenter - top: mainContent.bottom - topMargin: loginDialog.inputSpacing - } - - text: "Close" - font.pixelSize: hifi.fonts.pixelSize * 0.8 - color: "#175d74" - - MouseArea { - anchors.fill: parent - cursorShape: "PointingHandCursor" - onClicked: { - root.enabled = false - } - } - } } onOpacityChanged: { diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index b2b9553ea5..6242318170 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -571,21 +571,6 @@ Menu::Menu() { addCheckableActionToQMenuAndActionHash(physicsOptionsMenu, MenuOption::PhysicsShowOwned); addCheckableActionToQMenuAndActionHash(physicsOptionsMenu, MenuOption::PhysicsShowHulls); - MenuWrapper* loginDialogFormatMenu = developerMenu->addMenu("Login Dialog"); - { - QActionGroup* dialogMenuFormatGroup = new QActionGroup(loginDialogFormatMenu); - - QAction* circularLoginDialog = addCheckableActionToQMenuAndActionHash(loginDialogFormatMenu, - MenuOption::LoginDialogCircular, 0, false, - dialogsManager.data(), SLOT(updateLoginDialogFormat())); - dialogMenuFormatGroup->addAction(circularLoginDialog); - - QAction* rectangularLoginDialog = addCheckableActionToQMenuAndActionHash(loginDialogFormatMenu, - MenuOption::LoginDialogRectangular, 0, true, - dialogsManager.data(), SLOT(updateLoginDialogFormat())); - dialogMenuFormatGroup->addAction(rectangularLoginDialog); - } - MenuWrapper* helpMenu = addMenu("Help"); addActionToQMenuAndActionHash(helpMenu, MenuOption::EditEntitiesHelp, 0, qApp, SLOT(showEditEntitiesHelp())); diff --git a/interface/src/Menu.h b/interface/src/Menu.h index eb1bd94637..6107744abc 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -209,8 +209,6 @@ namespace MenuOption { const QString LoadRSSDKFile = "Load .rssdk file"; const QString LodTools = "LOD Tools"; const QString Login = "Login"; - const QString LoginDialogCircular = "Circular"; - const QString LoginDialogRectangular = "Rectangular"; const QString Log = "Log"; const QString LowVelocityFilter = "Low Velocity Filter"; const QString Mirror = "Mirror"; diff --git a/interface/src/ui/DialogsManager.cpp b/interface/src/ui/DialogsManager.cpp index 705f55586c..1170e3c3a6 100644 --- a/interface/src/ui/DialogsManager.cpp +++ b/interface/src/ui/DialogsManager.cpp @@ -50,10 +50,6 @@ void DialogsManager::showLoginDialog() { LoginDialog::show(); } -void DialogsManager::updateLoginDialogFormat() { - emit loginDialogFormatChanged(); -} - void DialogsManager::octreeStatsDetails() { if (!_octreeStatsDialog) { _octreeStatsDialog = new OctreeStatsDialog(qApp->getWindow(), qApp->getOcteeSceneStats()); diff --git a/interface/src/ui/DialogsManager.h b/interface/src/ui/DialogsManager.h index f7301f5444..fc2dad072b 100644 --- a/interface/src/ui/DialogsManager.h +++ b/interface/src/ui/DialogsManager.h @@ -47,15 +47,11 @@ public: QPointer getOctreeStatsDialog() const { return _octreeStatsDialog; } QPointer getPreferencesDialog() const { return _preferencesDialog; } -signals: - void loginDialogFormatChanged(); - public slots: void toggleAddressBar(); void toggleDiskCacheEditor(); void toggleLoginDialog(); void showLoginDialog(); - void updateLoginDialogFormat(); void octreeStatsDetails(); void cachesSizeDialog(); void editPreferences(); diff --git a/interface/src/ui/LoginDialog.cpp b/interface/src/ui/LoginDialog.cpp index 3de8b5adf1..eb6f3c0607 100644 --- a/interface/src/ui/LoginDialog.cpp +++ b/interface/src/ui/LoginDialog.cpp @@ -12,6 +12,7 @@ #include "LoginDialog.h" #include +#include #include "AccountManager.h" #include "DependencyManager.h" @@ -20,16 +21,12 @@ HIFI_QML_DEF(LoginDialog) LoginDialog::LoginDialog(QQuickItem *parent) : OffscreenQmlDialog(parent), - _dialogFormat("rectangular"), _rootUrl(NetworkingConstants::METAVERSE_SERVER_URL.toString()) { connect(&AccountManager::getInstance(), &AccountManager::loginComplete, this, &LoginDialog::handleLoginCompleted); connect(&AccountManager::getInstance(), &AccountManager::loginFailed, this, &LoginDialog::handleLoginFailed); - - connect(DependencyManager::get().data(), &DialogsManager::loginDialogFormatChanged, - this, &LoginDialog::updateDialogFormat); } void LoginDialog::toggleAction() { @@ -59,25 +56,6 @@ void LoginDialog::handleLoginFailed() { setStatusText("Invalid username or password"); } -void LoginDialog::setDialogFormat(const QString& dialogFormat) { - if (dialogFormat != _dialogFormat) { - _dialogFormat = dialogFormat; - emit dialogFormatChanged(); - } -} - -QString LoginDialog::dialogFormat() const { - return _dialogFormat; -} - -void LoginDialog::updateDialogFormat() { - if (Menu::getInstance()->isOptionChecked(MenuOption::LoginDialogCircular)) { - setDialogFormat("circular"); - } else { - setDialogFormat("rectangular"); - } -} - void LoginDialog::setStatusText(const QString& statusText) { if (statusText != _statusText) { _statusText = statusText; @@ -101,5 +79,5 @@ void LoginDialog::login(const QString& username, const QString& password) { void LoginDialog::openUrl(const QString& url) { qDebug() << url; - Application::getInstance()->openUrl(url); + QDesktopServices::openUrl(url); } diff --git a/interface/src/ui/LoginDialog.h b/interface/src/ui/LoginDialog.h index 5761914642..50c820aa07 100644 --- a/interface/src/ui/LoginDialog.h +++ b/interface/src/ui/LoginDialog.h @@ -14,8 +14,6 @@ #ifndef hifi_LoginDialog_h #define hifi_LoginDialog_h -#include "DialogsManager.h" // Need before OffscreenQmlDialog.h in order to get gl.h and glew.h includes in correct order. - #include class LoginDialog : public OffscreenQmlDialog @@ -23,7 +21,6 @@ class LoginDialog : public OffscreenQmlDialog Q_OBJECT HIFI_QML_DECL - Q_PROPERTY(QString dialogFormat READ dialogFormat WRITE setDialogFormat NOTIFY dialogFormatChanged) Q_PROPERTY(QString statusText READ statusText WRITE setStatusText NOTIFY statusTextChanged) Q_PROPERTY(QString rootUrl READ rootUrl) @@ -32,17 +29,12 @@ public: LoginDialog(QQuickItem* parent = nullptr); - void setDialogFormat(const QString& dialogFormat); - QString dialogFormat() const; - void updateDialogFormat(); // protected? - void setStatusText(const QString& statusText); QString statusText() const; QString rootUrl() const; signals: - void dialogFormatChanged(); void statusTextChanged(); protected: @@ -52,7 +44,6 @@ protected: Q_INVOKABLE void login(const QString& username, const QString& password); Q_INVOKABLE void openUrl(const QString& url); private: - QString _dialogFormat; QString _statusText; const QString _rootUrl; }; From 7fb434613ceb7eaf019b3a5a4afff1067a1e61fa Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 5 Jun 2015 15:57:09 -0700 Subject: [PATCH 47/49] Fix #include for Unix --- interface/src/ui/LoginDialog.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interface/src/ui/LoginDialog.cpp b/interface/src/ui/LoginDialog.cpp index eb6f3c0607..196ba5d29e 100644 --- a/interface/src/ui/LoginDialog.cpp +++ b/interface/src/ui/LoginDialog.cpp @@ -11,8 +11,9 @@ #include "LoginDialog.h" +#include + #include -#include #include "AccountManager.h" #include "DependencyManager.h" From bbde36738698eec41e11675d760af6610ac3b6d5 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 6 Jun 2015 10:42:49 -0700 Subject: [PATCH 48/49] Rename new Dialog to DialogContainer --- interface/resources/qml/AddressBarDialog.qml | 2 +- interface/resources/qml/ErrorDialog.qml | 2 +- interface/resources/qml/LoginDialog.qml | 2 +- .../resources/qml/controls/{Dialog.qml => DialogContainer.qml} | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename interface/resources/qml/controls/{Dialog.qml => DialogContainer.qml} (98%) diff --git a/interface/resources/qml/AddressBarDialog.qml b/interface/resources/qml/AddressBarDialog.qml index 7fa6bb3481..3377b20d87 100644 --- a/interface/resources/qml/AddressBarDialog.qml +++ b/interface/resources/qml/AddressBarDialog.qml @@ -13,7 +13,7 @@ import QtQuick 2.4 import "controls" import "styles" -Dialog { +DialogContainer { id: root HifiConstants { id: hifi } diff --git a/interface/resources/qml/ErrorDialog.qml b/interface/resources/qml/ErrorDialog.qml index 26b18f4ffd..76d9111d97 100644 --- a/interface/resources/qml/ErrorDialog.qml +++ b/interface/resources/qml/ErrorDialog.qml @@ -13,7 +13,7 @@ import QtQuick 2.4 import "controls" import "styles" -Dialog { +DialogContainer { id: root HifiConstants { id: hifi } diff --git a/interface/resources/qml/LoginDialog.qml b/interface/resources/qml/LoginDialog.qml index e552532cbd..8d5267f7f8 100644 --- a/interface/resources/qml/LoginDialog.qml +++ b/interface/resources/qml/LoginDialog.qml @@ -13,7 +13,7 @@ import QtQuick 2.4 import "controls" import "styles" -Dialog { +DialogContainer { id: root HifiConstants { id: hifi } diff --git a/interface/resources/qml/controls/Dialog.qml b/interface/resources/qml/controls/DialogContainer.qml similarity index 98% rename from interface/resources/qml/controls/Dialog.qml rename to interface/resources/qml/controls/DialogContainer.qml index 3cada90c3e..4aa4e45d67 100644 --- a/interface/resources/qml/controls/Dialog.qml +++ b/interface/resources/qml/controls/DialogContainer.qml @@ -1,5 +1,5 @@ // -// Dialog.qml +// DialogCommon.qml // // Created by David Rowe on 3 Jun 2015 // Copyright 2015 High Fidelity, Inc. From d7866d99819a93c36ca39feba782817cc4ed1290 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 6 Jun 2015 10:48:07 -0700 Subject: [PATCH 49/49] Rename previous Dialog to VrDialog --- interface/resources/qml/Browser.qml | 2 +- interface/resources/qml/InfoView.qml | 2 +- interface/resources/qml/MarketplaceDialog.qml | 2 +- interface/resources/qml/MessageDialog.qml | 2 +- interface/resources/qml/TestDialog.qml | 2 +- .../resources/qml/controls/{DialogOld.qml => VrDialog.qml} | 0 6 files changed, 5 insertions(+), 5 deletions(-) rename interface/resources/qml/controls/{DialogOld.qml => VrDialog.qml} (100%) diff --git a/interface/resources/qml/Browser.qml b/interface/resources/qml/Browser.qml index 3de616e05b..947bf739fc 100644 --- a/interface/resources/qml/Browser.qml +++ b/interface/resources/qml/Browser.qml @@ -4,7 +4,7 @@ import QtWebKit 3.0 import "controls" import "styles" -DialogOld { +VrDialog { id: root HifiConstants { id: hifi } title: "Browser" diff --git a/interface/resources/qml/InfoView.qml b/interface/resources/qml/InfoView.qml index e97ebdeaf3..012f04f1fd 100644 --- a/interface/resources/qml/InfoView.qml +++ b/interface/resources/qml/InfoView.qml @@ -5,7 +5,7 @@ import QtQuick.Controls.Styles 1.3 import QtWebKit 3.0 import "controls" -DialogOld { +VrDialog { id: root width: 800 height: 800 diff --git a/interface/resources/qml/MarketplaceDialog.qml b/interface/resources/qml/MarketplaceDialog.qml index 4ad3c6515f..946f32e84a 100644 --- a/interface/resources/qml/MarketplaceDialog.qml +++ b/interface/resources/qml/MarketplaceDialog.qml @@ -5,7 +5,7 @@ import QtQuick.Controls.Styles 1.3 import QtWebKit 3.0 import "controls" -DialogOld { +VrDialog { title: "Test Dlg" id: testDialog objectName: "Browser" diff --git a/interface/resources/qml/MessageDialog.qml b/interface/resources/qml/MessageDialog.qml index 5c699e1f1f..e8b01df9d0 100644 --- a/interface/resources/qml/MessageDialog.qml +++ b/interface/resources/qml/MessageDialog.qml @@ -5,7 +5,7 @@ import QtQuick.Dialogs 1.2 import "controls" import "styles" -DialogOld { +VrDialog { id: root HifiConstants { id: hifi } property real spacing: hifi.layout.spacing diff --git a/interface/resources/qml/TestDialog.qml b/interface/resources/qml/TestDialog.qml index 3ae61fa054..e6675b7282 100644 --- a/interface/resources/qml/TestDialog.qml +++ b/interface/resources/qml/TestDialog.qml @@ -3,7 +3,7 @@ import QtQuick.Controls 1.2 import QtQuick.Controls.Styles 1.3 import "controls" -DialogOld { +VrDialog { title: "Test Dialog" id: testDialog objectName: "TestDialog" diff --git a/interface/resources/qml/controls/DialogOld.qml b/interface/resources/qml/controls/VrDialog.qml similarity index 100% rename from interface/resources/qml/controls/DialogOld.qml rename to interface/resources/qml/controls/VrDialog.qml