Move EntityScriptingInterface instance to DependencyManager

This commit is contained in:
Ryan Huffman 2015-03-02 15:05:31 -08:00
parent 98e0f235cc
commit b370e025c9
6 changed files with 31 additions and 37 deletions

View file

@ -44,7 +44,7 @@ Agent::Agent(const QByteArray& packet) :
// be the parent of the script engine so it gets moved when we do // be the parent of the script engine so it gets moved when we do
_scriptEngine.setParent(this); _scriptEngine.setParent(this);
_scriptEngine.getEntityScriptingInterface()->setPacketSender(&_entityEditSender); DependencyManager::get<EntityScriptingInterface>()->setPacketSender(&_entityEditSender);
DependencyManager::set<ResouceCacheSharedItems>(); DependencyManager::set<ResouceCacheSharedItems>();
DependencyManager::set<SoundCache>(); DependencyManager::set<SoundCache>();
@ -68,8 +68,8 @@ void Agent::readPendingDatagrams() {
// PacketType_JURISDICTION, first byte is the node type... // PacketType_JURISDICTION, first byte is the node type...
switch (receivedPacket[headerBytes]) { switch (receivedPacket[headerBytes]) {
case NodeType::EntityServer: case NodeType::EntityServer:
_scriptEngine.getEntityScriptingInterface()->getJurisdictionListener()-> DependencyManager::get<EntityScriptingInterface>()->getJurisdictionListener()->
queueReceivedPacket(matchedNode, receivedPacket); queueReceivedPacket(matchedNode, receivedPacket);
break; break;
} }
} }
@ -211,10 +211,12 @@ void Agent::run() {
_scriptEngine.registerGlobalObject("SoundCache", DependencyManager::get<SoundCache>().data()); _scriptEngine.registerGlobalObject("SoundCache", DependencyManager::get<SoundCache>().data());
auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
_scriptEngine.registerGlobalObject("EntityViewer", &_entityViewer); _scriptEngine.registerGlobalObject("EntityViewer", &_entityViewer);
_entityViewer.setJurisdictionListener(_scriptEngine.getEntityScriptingInterface()->getJurisdictionListener()); _entityViewer.setJurisdictionListener(entityScriptingInterface->getJurisdictionListener());
_entityViewer.init(); _entityViewer.init();
_scriptEngine.getEntityScriptingInterface()->setEntityTree(_entityViewer.getTree()); entityScriptingInterface->setEntityTree(_entityViewer.getTree());
_scriptEngine.setScriptContents(scriptContents); _scriptEngine.setScriptContents(scriptContents);
_scriptEngine.run(); _scriptEngine.run();

View file

@ -18,6 +18,7 @@
#include <AccountManager.h> #include <AccountManager.h>
#include <AddressManager.h> #include <AddressManager.h>
#include <Assignment.h> #include <Assignment.h>
#include <EntityScriptingInterface.h>
#include <LogHandler.h> #include <LogHandler.h>
#include <LogUtils.h> #include <LogUtils.h>
#include <LimitedNodeList.h> #include <LimitedNodeList.h>
@ -53,6 +54,7 @@ AssignmentClient::AssignmentClient(Assignment::Type requestAssignmentType, QStri
DependencyManager::registerInheritance<LimitedNodeList, NodeList>(); DependencyManager::registerInheritance<LimitedNodeList, NodeList>();
auto addressManager = DependencyManager::set<AddressManager>(); auto addressManager = DependencyManager::set<AddressManager>();
auto nodeList = DependencyManager::set<NodeList>(NodeType::Unassigned); auto nodeList = DependencyManager::set<NodeList>(NodeType::Unassigned);
auto entityScriptingInterface = DependencyManager::set<EntityScriptingInterface>();
// make up a uuid for this child so the parent can tell us apart. This id will be changed // make up a uuid for this child so the parent can tell us apart. This id will be changed
// when the domain server hands over an assignment. // when the domain server hands over an assignment.

View file

@ -241,6 +241,7 @@ bool setupEssentials(int& argc, char** argv) {
auto dialogsManager = DependencyManager::set<DialogsManager>(); auto dialogsManager = DependencyManager::set<DialogsManager>();
auto bandwidthRecorder = DependencyManager::set<BandwidthRecorder>(); auto bandwidthRecorder = DependencyManager::set<BandwidthRecorder>();
auto resouceCacheSharedItems = DependencyManager::set<ResouceCacheSharedItems>(); auto resouceCacheSharedItems = DependencyManager::set<ResouceCacheSharedItems>();
auto entityScriptingInterface = DependencyManager::set<EntityScriptingInterface>();
#if defined(Q_OS_MAC) || defined(Q_OS_WIN) #if defined(Q_OS_MAC) || defined(Q_OS_WIN)
auto speechRecognizer = DependencyManager::set<SpeechRecognizer>(); auto speechRecognizer = DependencyManager::set<SpeechRecognizer>();
#endif #endif
@ -1766,8 +1767,10 @@ void Application::init() {
tree->setSimulation(&_physicsEngine); tree->setSimulation(&_physicsEngine);
_physicsEngine.init(&_entityEditSender); _physicsEngine.init(&_entityEditSender);
auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
connect(&_physicsEngine, &EntitySimulation::entityCollisionWithEntity, connect(&_physicsEngine, &EntitySimulation::entityCollisionWithEntity,
ScriptEngine::getEntityScriptingInterface(), &EntityScriptingInterface::entityCollisionWithEntity); entityScriptingInterface.data(), &EntityScriptingInterface::entityCollisionWithEntity);
// connect the _entityCollisionSystem to our EntityTreeRenderer since that's what handles running entity scripts // connect the _entityCollisionSystem to our EntityTreeRenderer since that's what handles running entity scripts
connect(&_physicsEngine, &EntitySimulation::entityCollisionWithEntity, connect(&_physicsEngine, &EntitySimulation::entityCollisionWithEntity,
@ -1775,7 +1778,7 @@ void Application::init() {
// connect the _entities (EntityTreeRenderer) to our script engine's EntityScriptingInterface for firing // connect the _entities (EntityTreeRenderer) to our script engine's EntityScriptingInterface for firing
// of events related clicking, hovering over, and entering entities // of events related clicking, hovering over, and entering entities
_entities.connectSignalsToSlots(ScriptEngine::getEntityScriptingInterface()); _entities.connectSignalsToSlots(entityScriptingInterface.data());
_entityClipboardRenderer.init(); _entityClipboardRenderer.init();
_entityClipboardRenderer.setViewFrustum(getViewFrustum()); _entityClipboardRenderer.setViewFrustum(getViewFrustum());
@ -3441,8 +3444,9 @@ void joystickFromScriptValue(const QScriptValue &object, Joystick* &out) {
void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scriptEngine) { void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scriptEngine) {
// setup the packet senders and jurisdiction listeners of the script engine's scripting interfaces so // setup the packet senders and jurisdiction listeners of the script engine's scripting interfaces so
// we can use the same ones from the application. // we can use the same ones from the application.
scriptEngine->getEntityScriptingInterface()->setPacketSender(&_entityEditSender); auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
scriptEngine->getEntityScriptingInterface()->setEntityTree(_entities.getTree()); entityScriptingInterface->setPacketSender(&_entityEditSender);
entityScriptingInterface->setEntityTree(_entities.getTree());
// AvatarManager has some custom types // AvatarManager has some custom types
AvatarManager::registerMetaTypes(scriptEngine); AvatarManager::registerMetaTypes(scriptEngine);

View file

@ -17,6 +17,7 @@
#include <QtCore/QObject> #include <QtCore/QObject>
#include <CollisionInfo.h> #include <CollisionInfo.h>
#include <DependencyManager.h>
#include <Octree.h> #include <Octree.h>
#include <OctreeScriptingInterface.h> #include <OctreeScriptingInterface.h>
#include <RegisteredMetaTypes.h> #include <RegisteredMetaTypes.h>
@ -48,7 +49,7 @@ void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, Ra
/// handles scripting of Entity commands from JS passed to assigned clients /// handles scripting of Entity commands from JS passed to assigned clients
class EntityScriptingInterface : public OctreeScriptingInterface { class EntityScriptingInterface : public OctreeScriptingInterface, public Dependency {
Q_OBJECT Q_OBJECT
public: public:
EntityScriptingInterface(); EntityScriptingInterface();

View file

@ -44,8 +44,6 @@
#include "MIDIEvent.h" #include "MIDIEvent.h"
EntityScriptingInterface* ScriptEngine::_entityScriptingInterface;
static QScriptValue debugPrint(QScriptContext* context, QScriptEngine* engine){ static QScriptValue debugPrint(QScriptContext* context, QScriptEngine* engine){
qDebug() << "script:print()<<" << context->argument(0).toString(); qDebug() << "script:print()<<" << context->argument(0).toString();
QString message = context->argument(0).toString() QString message = context->argument(0).toString()
@ -73,13 +71,6 @@ void inputControllerFromScriptValue(const QScriptValue &object, AbstractInputCon
out = qobject_cast<AbstractInputController*>(object.toQObject()); out = qobject_cast<AbstractInputController*>(object.toQObject());
} }
EntityScriptingInterface* ScriptEngine::getEntityScriptingInterface() {
if (!_entityScriptingInterface) {
_entityScriptingInterface = new EntityScriptingInterface();
}
return _entityScriptingInterface;
}
ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNameString, ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNameString,
AbstractControllerScriptingInterface* controllerScriptingInterface) : AbstractControllerScriptingInterface* controllerScriptingInterface) :
@ -104,7 +95,6 @@ ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNam
_isUserLoaded(false), _isUserLoaded(false),
_arrayBufferClass(new ArrayBufferClass(this)) _arrayBufferClass(new ArrayBufferClass(this))
{ {
getEntityScriptingInterface();
_allScriptsMutex.lock(); _allScriptsMutex.lock();
_allKnownScriptEngines.insert(this); _allKnownScriptEngines.insert(this);
_allScriptsMutex.unlock(); _allScriptsMutex.unlock();
@ -322,7 +312,8 @@ void ScriptEngine::init() {
auto sceneScriptingInterface = DependencyManager::set<SceneScriptingInterface>(); auto sceneScriptingInterface = DependencyManager::set<SceneScriptingInterface>();
_entityScriptingInterface->init(); auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
entityScriptingInterface->init();
// register various meta-types // register various meta-types
registerMetaTypes(this); registerMetaTypes(this);
@ -360,7 +351,7 @@ void ScriptEngine::init() {
registerGlobalObject("Script", this); registerGlobalObject("Script", this);
registerGlobalObject("Audio", &AudioScriptingInterface::getInstance()); registerGlobalObject("Audio", &AudioScriptingInterface::getInstance());
registerGlobalObject("Controller", _controllerScriptingInterface); registerGlobalObject("Controller", _controllerScriptingInterface);
registerGlobalObject("Entities", _entityScriptingInterface); registerGlobalObject("Entities", entityScriptingInterface.data());
registerGlobalObject("Quat", &_quatLibrary); registerGlobalObject("Quat", &_quatLibrary);
registerGlobalObject("Vec3", &_vec3Library); registerGlobalObject("Vec3", &_vec3Library);
registerGlobalObject("Uuid", &_uuidLibrary); registerGlobalObject("Uuid", &_uuidLibrary);
@ -478,6 +469,7 @@ void ScriptEngine::run() {
int thisFrame = 0; int thisFrame = 0;
auto nodeList = DependencyManager::get<NodeList>(); auto nodeList = DependencyManager::get<NodeList>();
auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
qint64 lastUpdate = usecTimestampNow(); qint64 lastUpdate = usecTimestampNow();
@ -497,13 +489,13 @@ void ScriptEngine::run() {
break; break;
} }
if (!_isFinished && _entityScriptingInterface->getEntityPacketSender()->serversExist()) { if (!_isFinished && entityScriptingInterface->getEntityPacketSender()->serversExist()) {
// release the queue of edit entity messages. // release the queue of edit entity messages.
_entityScriptingInterface->getEntityPacketSender()->releaseQueuedMessages(); entityScriptingInterface->getEntityPacketSender()->releaseQueuedMessages();
// since we're in non-threaded mode, call process so that the packets are sent // since we're in non-threaded mode, call process so that the packets are sent
if (!_entityScriptingInterface->getEntityPacketSender()->isThreaded()) { if (!entityScriptingInterface->getEntityPacketSender()->isThreaded()) {
_entityScriptingInterface->getEntityPacketSender()->process(); entityScriptingInterface->getEntityPacketSender()->process();
} }
} }
@ -630,13 +622,13 @@ void ScriptEngine::run() {
// kill the avatar identity timer // kill the avatar identity timer
delete _avatarIdentityTimer; delete _avatarIdentityTimer;
if (_entityScriptingInterface->getEntityPacketSender()->serversExist()) { if (entityScriptingInterface->getEntityPacketSender()->serversExist()) {
// release the queue of edit entity messages. // release the queue of edit entity messages.
_entityScriptingInterface->getEntityPacketSender()->releaseQueuedMessages(); entityScriptingInterface->getEntityPacketSender()->releaseQueuedMessages();
// since we're in non-threaded mode, call process so that the packets are sent // since we're in non-threaded mode, call process so that the packets are sent
if (!_entityScriptingInterface->getEntityPacketSender()->isThreaded()) { if (!entityScriptingInterface->getEntityPacketSender()->isThreaded()) {
_entityScriptingInterface->getEntityPacketSender()->process(); entityScriptingInterface->getEntityPacketSender()->process();
} }
} }

View file

@ -31,8 +31,6 @@
#include "ScriptUUID.h" #include "ScriptUUID.h"
#include "Vec3.h" #include "Vec3.h"
class EntityScriptingInterface;
const QString NO_SCRIPT(""); const QString NO_SCRIPT("");
const unsigned int SCRIPT_DATA_CALLBACK_USECS = floor(((1.0 / 60.0f) * 1000 * 1000) + 0.5); const unsigned int SCRIPT_DATA_CALLBACK_USECS = floor(((1.0 / 60.0f) * 1000 * 1000) + 0.5);
@ -46,9 +44,6 @@ public:
~ScriptEngine(); ~ScriptEngine();
/// Access the EntityScriptingInterface in order to initialize it with a custom packet sender and jurisdiction listener
static EntityScriptingInterface* getEntityScriptingInterface();
ArrayBufferClass* getArrayBufferClass() { return _arrayBufferClass; } ArrayBufferClass* getArrayBufferClass() { return _arrayBufferClass; }
/// sets the script contents, will return false if failed, will fail if script is already running /// sets the script contents, will return false if failed, will fail if script is already running
@ -153,8 +148,6 @@ private:
QObject* setupTimerWithInterval(const QScriptValue& function, int intervalMS, bool isSingleShot); QObject* setupTimerWithInterval(const QScriptValue& function, int intervalMS, bool isSingleShot);
void stopTimer(QTimer* timer); void stopTimer(QTimer* timer);
static EntityScriptingInterface* _entityScriptingInterface;
AbstractControllerScriptingInterface* _controllerScriptingInterface; AbstractControllerScriptingInterface* _controllerScriptingInterface;
AvatarData* _avatarData; AvatarData* _avatarData;
QString _scriptName; QString _scriptName;