void EntityScriptServer::resetEntitiesScriptEngine() { auto engineName = QString("about:Entities %1").arg(++_entitiesScriptEngineCount); auto newEngine = scriptEngineFactory(ScriptEngine::ENTITY_SERVER_SCRIPT, NO_SCRIPT, engineName); auto webSocketServerConstructorValue = newEngine->newFunction(WebSocketServerClass::constructor); newEngine->globalObject().setProperty("WebSocketServer", webSocketServerConstructorValue); newEngine->registerGlobalObject("SoundCache", DependencyManager::get<SoundCache>().data()); // connect this script engines printedMessage signal to the global ScriptEngines these various messages auto scriptEngines = DependencyManager::get<ScriptEngines>().data(); connect(newEngine.data(), &ScriptEngine::printedMessage, scriptEngines, &ScriptEngines::onPrintedMessage); connect(newEngine.data(), &ScriptEngine::errorMessage, scriptEngines, &ScriptEngines::onErrorMessage); connect(newEngine.data(), &ScriptEngine::warningMessage, scriptEngines, &ScriptEngines::onWarningMessage); connect(newEngine.data(), &ScriptEngine::infoMessage, scriptEngines, &ScriptEngines::onInfoMessage); connect(newEngine.data(), &ScriptEngine::update, this, [this] { _entityViewer.queryOctree(); _entityViewer.getTree()->update(); }); newEngine->runInThread(); auto newEngineSP = qSharedPointerCast<EntitiesScriptEngineProvider>(newEngine); DependencyManager::get<EntityScriptingInterface>()->setEntitiesScriptEngine(newEngineSP); disconnect(_entitiesScriptEngine.data(), &ScriptEngine::entityScriptDetailsUpdated, this, &EntityScriptServer::updateEntityPPS); _entitiesScriptEngine.swap(newEngine); connect(_entitiesScriptEngine.data(), &ScriptEngine::entityScriptDetailsUpdated, this, &EntityScriptServer::updateEntityPPS); }
void ThreadPool::start() { if (!running && numThreads > 0) { work.reset(new boost::asio::io_service::work(ioService)); threads.reserve(numThreads); while (threads.size() < numThreads) { threads.push_back(std::make_shared<std::thread>([this]() { runInThread(); }) ); } running = true; } }
void QueryTester::startInThread(QThread* thread) { this->moveToThread(thread); connect(thread, SIGNAL(started()), this, SLOT(runInThread())); }