From 4266a99d786a23e2a32b615a8374a49dfa5005f9 Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Mon, 25 May 2015 11:28:33 -0700 Subject: [PATCH] Put the javascript methods on Script, not Entities, and other minimum-diff cleanup. --- .../entities-renderer/src/EntityTreeRenderer.h | 2 +- .../entities/src/EntityScriptingInterface.cpp | 15 --------------- libraries/entities/src/EntityScriptingInterface.h | 7 ------- libraries/script-engine/src/ScriptEngine.cpp | 4 ++-- libraries/script-engine/src/ScriptEngine.h | 6 +++--- 5 files changed, 6 insertions(+), 28 deletions(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.h b/libraries/entities-renderer/src/EntityTreeRenderer.h index ce40363261..1f03e01e7c 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.h +++ b/libraries/entities-renderer/src/EntityTreeRenderer.h @@ -121,7 +121,7 @@ public slots: void setDisplayModelBounds(bool value) { _displayModelBounds = value; } void setDisplayModelElementProxy(bool value) { _displayModelElementProxy = value; } void setDontDoPrecisionPicking(bool value) { _dontDoPrecisionPicking = value; } - + protected: virtual Octree* createTree() { return new EntityTree(true); } diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 152c1621ef..1460e90a4d 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -17,8 +17,6 @@ #include "ModelEntityItem.h" #include "ZoneEntityItem.h" #include "EntitiesLogging.h" -#include "../../script-engine/src/ScriptEngine.h" // FIXME - EntityScriptingInterface::EntityScriptingInterface() : _entityTree(NULL) @@ -204,19 +202,6 @@ void EntityScriptingInterface::dumpTree() const { } } -void EntityScriptingInterface::addEventHandler(EntityItemID entityID, QString entityEventName, QScriptValue handler) { - ScriptEngine* engine = static_cast(handler.engine()); - if (engine) { // In case it's gone by the time we get the signal - engine->addEntityEventHandler(entityID, entityEventName, handler); - } -} -void EntityScriptingInterface::removeEventHandler(EntityItemID entityID, QString entityEventName, QScriptValue handler) { - ScriptEngine* engine = static_cast(handler.engine()); - if (engine) { - engine->removeEntityEventHandler(entityID, entityEventName, handler); - } -} - QVector EntityScriptingInterface::findEntities(const glm::vec3& center, float radius) const { QVector result; if (_entityTree) { diff --git a/libraries/entities/src/EntityScriptingInterface.h b/libraries/entities/src/EntityScriptingInterface.h index 508a566ed2..ca6e266e98 100644 --- a/libraries/entities/src/EntityScriptingInterface.h +++ b/libraries/entities/src/EntityScriptingInterface.h @@ -119,14 +119,7 @@ public slots: Q_INVOKABLE void dumpTree() const; - // Register a function that will handle the given entityEventName on entityID - Q_INVOKABLE void addEventHandler(EntityItemID entityID, QString entityEventName, QScriptValue handler); - Q_INVOKABLE void removeEventHandler(EntityItemID entityID, QString entityEventName, QScriptValue handler); - signals: - void addEntityEventHandler(EntityItemID entityID, QString entityEventName, QScriptValue handler); - void removeEntityEventHandler(EntityItemID entityID, QString entityEventName, QScriptValue handler); - void entityCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision); void collisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision); diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index e1e920da59..039ab8a19b 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -404,7 +404,7 @@ void ScriptEngine::generalHandler(const EntityItemID& entityID, const QString& e } } // Unregister the handlers for this eventName and entityID. -void ScriptEngine::removeEntityEventHandler(const EntityItemID& entityID, const QString& eventName, QScriptValue handler) { +void ScriptEngine::removeEventHandler(const EntityItemID& entityID, const QString& eventName, QScriptValue handler) { if (!_registeredHandlers.contains(entityID)) return; RegisteredEventHandlers& handlersOnEntity = _registeredHandlers[entityID]; QScriptValueList& handlersForEvent = handlersOnEntity[eventName]; @@ -417,7 +417,7 @@ void ScriptEngine::removeEntityEventHandler(const EntityItemID& entityID, const } } // Register the handler. -void ScriptEngine::addEntityEventHandler(const EntityItemID& entityID, const QString& eventName, QScriptValue handler) { +void ScriptEngine::addEventHandler(const EntityItemID& entityID, const QString& eventName, QScriptValue handler) { if (_registeredHandlers.count() == 0) { // First time any per-entity handler has been added in this script... // Connect up ALL the handlers to the global entities object's signals. // (We could go signal by signal, or even handler by handler, but I don't think the efficiency is worth the complexity.) diff --git a/libraries/script-engine/src/ScriptEngine.h b/libraries/script-engine/src/ScriptEngine.h index 0fd8ed0562..175eff059f 100644 --- a/libraries/script-engine/src/ScriptEngine.h +++ b/libraries/script-engine/src/ScriptEngine.h @@ -23,6 +23,7 @@ #include #include #include +#include #include "AbstractControllerScriptingInterface.h" #include "ArrayBufferClass.h" @@ -31,7 +32,6 @@ #include "ScriptCache.h" #include "ScriptUUID.h" #include "Vec3.h" -#include "../../entities/src/EntityItem.h" // FIXME const QString NO_SCRIPT(""); @@ -101,8 +101,8 @@ public: virtual void scriptContentsAvailable(const QUrl& url, const QString& scriptContents); virtual void errorInLoadingScript(const QUrl& url); - void addEntityEventHandler(const EntityItemID& entityID, const QString& eventName, QScriptValue handler); - void removeEntityEventHandler(const EntityItemID& entityID, const QString& eventName, QScriptValue handler); + Q_INVOKABLE void addEventHandler(const EntityItemID& entityID, const QString& eventName, QScriptValue handler); + Q_INVOKABLE void removeEventHandler(const EntityItemID& entityID, const QString& eventName, QScriptValue handler); public slots: void loadURL(const QUrl& scriptURL);