mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
convert script engine variables from QSharedPointer to std::shared_ptr
This commit is contained in:
parent
82535cab90
commit
70fbe76341
49 changed files with 194 additions and 164 deletions
|
@ -606,7 +606,7 @@ void Agent::setIsAvatar(bool isAvatar) {
|
|||
// start the timer
|
||||
_avatarQueryTimer->start(AVATAR_VIEW_PACKET_SEND_INTERVAL_MSECS);
|
||||
|
||||
connect(_scriptManager.data(), &ScriptManager::update,
|
||||
connect(_scriptManager.get(), &ScriptManager::update,
|
||||
scriptableAvatar.data(), &ScriptableAvatar::update, Qt::QueuedConnection);
|
||||
|
||||
// tell the avatarAudioTimer to start ticking
|
||||
|
@ -642,7 +642,7 @@ void Agent::setIsAvatar(bool isAvatar) {
|
|||
nodeList->sendPacket(std::move(packet), *node);
|
||||
});
|
||||
|
||||
disconnect(_scriptManager.data(), &ScriptManager::update,
|
||||
disconnect(_scriptManager.get(), &ScriptManager::update,
|
||||
scriptableAvatar.data(), &ScriptableAvatar::update);
|
||||
|
||||
QMetaObject::invokeMethod(&_avatarAudioTimer, "stop");
|
||||
|
@ -879,7 +879,7 @@ void Agent::aboutToFinish() {
|
|||
|
||||
// drop our shared pointer to the script engine, then ask ScriptEngines to shutdown scripting
|
||||
// this ensures that the ScriptEngine goes down before ScriptEngines
|
||||
_scriptManager.clear();
|
||||
_scriptManager.reset();
|
||||
|
||||
{
|
||||
DependencyManager::get<ScriptEngines>()->shutdownScripting();
|
||||
|
|
|
@ -37,8 +37,8 @@
|
|||
|
||||
class ScriptEngine;
|
||||
class ScriptManager;
|
||||
using ScriptEnginePointer = QSharedPointer<ScriptEngine>;
|
||||
using ScriptManagerPointer = QSharedPointer<ScriptManager>;
|
||||
using ScriptEnginePointer = std::shared_ptr<ScriptEngine>;
|
||||
using ScriptManagerPointer = std::shared_ptr<ScriptManager>;
|
||||
|
||||
class Agent : public ThreadedAssignment {
|
||||
Q_OBJECT
|
||||
|
|
|
@ -459,12 +459,12 @@ void EntityScriptServer::resetEntitiesScriptEngine() {
|
|||
|
||||
// connect this script engines printedMessage signal to the global ScriptEngines these various messages
|
||||
auto scriptEngines = DependencyManager::get<ScriptEngines>().data();
|
||||
connect(newManager.data(), &ScriptManager::printedMessage, scriptEngines, &ScriptEngines::onPrintedMessage);
|
||||
connect(newManager.data(), &ScriptManager::errorMessage, scriptEngines, &ScriptEngines::onErrorMessage);
|
||||
connect(newManager.data(), &ScriptManager::warningMessage, scriptEngines, &ScriptEngines::onWarningMessage);
|
||||
connect(newManager.data(), &ScriptManager::infoMessage, scriptEngines, &ScriptEngines::onInfoMessage);
|
||||
connect(newManager.get(), &ScriptManager::printedMessage, scriptEngines, &ScriptEngines::onPrintedMessage);
|
||||
connect(newManager.get(), &ScriptManager::errorMessage, scriptEngines, &ScriptEngines::onErrorMessage);
|
||||
connect(newManager.get(), &ScriptManager::warningMessage, scriptEngines, &ScriptEngines::onWarningMessage);
|
||||
connect(newManager.get(), &ScriptManager::infoMessage, scriptEngines, &ScriptEngines::onInfoMessage);
|
||||
|
||||
connect(newManager.data(), &ScriptManager::update, this, [this] {
|
||||
connect(newManager.get(), &ScriptManager::update, this, [this] {
|
||||
_entityViewer.queryOctree();
|
||||
_entityViewer.getTree()->preUpdate();
|
||||
_entityViewer.getTree()->update();
|
||||
|
@ -472,18 +472,18 @@ void EntityScriptServer::resetEntitiesScriptEngine() {
|
|||
|
||||
scriptEngines->runScriptInitializers(newManager);
|
||||
newManager->runInThread();
|
||||
auto newEngineSP = qSharedPointerCast<EntitiesScriptEngineProvider>(newManager);
|
||||
std::shared_ptr<EntitiesScriptEngineProvider> newEngineSP = newManager;
|
||||
// On the entity script server, these are the same
|
||||
DependencyManager::get<EntityScriptingInterface>()->setPersistentEntitiesScriptEngine(newEngineSP);
|
||||
DependencyManager::get<EntityScriptingInterface>()->setNonPersistentEntitiesScriptEngine(newEngineSP);
|
||||
|
||||
if (_entitiesScriptManager) {
|
||||
disconnect(_entitiesScriptManager.data(), &ScriptManager::entityScriptDetailsUpdated,
|
||||
disconnect(_entitiesScriptManager.get(), &ScriptManager::entityScriptDetailsUpdated,
|
||||
this, &EntityScriptServer::updateEntityPPS);
|
||||
}
|
||||
|
||||
_entitiesScriptManager.swap(newManager);
|
||||
connect(_entitiesScriptManager.data(), &ScriptManager::entityScriptDetailsUpdated,
|
||||
connect(_entitiesScriptManager.get(), &ScriptManager::entityScriptDetailsUpdated,
|
||||
this, &EntityScriptServer::updateEntityPPS);
|
||||
}
|
||||
|
||||
|
@ -516,7 +516,7 @@ void EntityScriptServer::shutdownScriptEngine() {
|
|||
auto scriptEngines = DependencyManager::get<ScriptEngines>();
|
||||
scriptEngines->shutdownScripting();
|
||||
|
||||
_entitiesScriptManager.clear();
|
||||
_entitiesScriptManager.reset();
|
||||
|
||||
auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
|
||||
// our entity tree is going to go away so tell that to the EntityScriptingInterface
|
||||
|
|
|
@ -7476,10 +7476,10 @@ void Application::registerScriptEngineWithApplicationServices(const ScriptManage
|
|||
|
||||
ClipboardScriptingInterface* clipboardScriptable = new ClipboardScriptingInterface();
|
||||
scriptEngine->registerGlobalObject("Clipboard", clipboardScriptable);
|
||||
connect(scriptManager.data(), &ScriptManager::finished, clipboardScriptable, &ClipboardScriptingInterface::deleteLater);
|
||||
connect(scriptManager.get(), &ScriptManager::finished, clipboardScriptable, &ClipboardScriptingInterface::deleteLater);
|
||||
|
||||
scriptEngine->registerGlobalObject("Overlays", &_overlays);
|
||||
scriptRegisterMetaType(scriptEngine.data(), RayToOverlayIntersectionResultToScriptValue,
|
||||
scriptRegisterMetaType(scriptEngine.get(), RayToOverlayIntersectionResultToScriptValue,
|
||||
RayToOverlayIntersectionResultFromScriptValue);
|
||||
|
||||
bool clientScript = scriptManager->isClientScript();
|
||||
|
@ -7497,13 +7497,13 @@ void Application::registerScriptEngineWithApplicationServices(const ScriptManage
|
|||
}
|
||||
#endif
|
||||
|
||||
scriptRegisterMetaType(scriptEngine.data(), wrapperToScriptValue<ToolbarProxy>, wrapperFromScriptValue<ToolbarProxy>);
|
||||
scriptRegisterMetaType(scriptEngine.data(),
|
||||
scriptRegisterMetaType(scriptEngine.get(), wrapperToScriptValue<ToolbarProxy>, wrapperFromScriptValue<ToolbarProxy>);
|
||||
scriptRegisterMetaType(scriptEngine.get(),
|
||||
wrapperToScriptValue<ToolbarButtonProxy>, wrapperFromScriptValue<ToolbarButtonProxy>);
|
||||
scriptEngine->registerGlobalObject("Toolbars", DependencyManager::get<ToolbarScriptingInterface>().data());
|
||||
|
||||
scriptRegisterMetaType(scriptEngine.data(), wrapperToScriptValue<TabletProxy>, wrapperFromScriptValue<TabletProxy>);
|
||||
scriptRegisterMetaType(scriptEngine.data(),
|
||||
scriptRegisterMetaType(scriptEngine.get(), wrapperToScriptValue<TabletProxy>, wrapperFromScriptValue<TabletProxy>);
|
||||
scriptRegisterMetaType(scriptEngine.get(),
|
||||
wrapperToScriptValue<TabletButtonProxy>, wrapperFromScriptValue<TabletButtonProxy>);
|
||||
scriptEngine->registerGlobalObject("Tablet", DependencyManager::get<TabletScriptingInterface>().data());
|
||||
// FIXME remove these deprecated names for the tablet scripting interface
|
||||
|
@ -7554,12 +7554,12 @@ void Application::registerScriptEngineWithApplicationServices(const ScriptManage
|
|||
scriptEngine->registerGlobalObject("Account", AccountServicesScriptingInterface::getInstance()); // DEPRECATED - TO BE REMOVED
|
||||
scriptEngine->registerGlobalObject("GlobalServices", AccountServicesScriptingInterface::getInstance()); // DEPRECATED - TO BE REMOVED
|
||||
scriptEngine->registerGlobalObject("AccountServices", AccountServicesScriptingInterface::getInstance());
|
||||
scriptRegisterMetaType(scriptEngine.data(), DownloadInfoResultToScriptValue, DownloadInfoResultFromScriptValue);
|
||||
scriptRegisterMetaType(scriptEngine.get(), DownloadInfoResultToScriptValue, DownloadInfoResultFromScriptValue);
|
||||
|
||||
scriptEngine->registerGlobalObject("AvatarManager", DependencyManager::get<AvatarManager>().data());
|
||||
|
||||
scriptEngine->registerGlobalObject("LODManager", DependencyManager::get<LODManager>().data());
|
||||
scriptRegisterMetaType(scriptEngine.data(), worldDetailQualityToScriptValue, worldDetailQualityFromScriptValue);
|
||||
scriptRegisterMetaType(scriptEngine.get(), worldDetailQualityToScriptValue, worldDetailQualityFromScriptValue);
|
||||
|
||||
scriptEngine->registerGlobalObject("Keyboard", DependencyManager::get<KeyboardScriptingInterface>().data());
|
||||
scriptEngine->registerGlobalObject("Performance", new PerformanceScriptingInterface());
|
||||
|
@ -7574,7 +7574,7 @@ void Application::registerScriptEngineWithApplicationServices(const ScriptManage
|
|||
scriptEngine->registerGlobalObject("Render", RenderScriptingInterface::getInstance());
|
||||
scriptEngine->registerGlobalObject("Workload", _gameWorkload._engine->getConfiguration().get());
|
||||
|
||||
GraphicsScriptingInterface::registerMetaTypes(scriptEngine.data());
|
||||
GraphicsScriptingInterface::registerMetaTypes(scriptEngine.get());
|
||||
scriptEngine->registerGlobalObject("Graphics", DependencyManager::get<GraphicsScriptingInterface>().data());
|
||||
|
||||
scriptEngine->registerGlobalObject("ScriptDiscoveryService", DependencyManager::get<ScriptEngines>().data());
|
||||
|
@ -7586,11 +7586,11 @@ void Application::registerScriptEngineWithApplicationServices(const ScriptManage
|
|||
scriptEngine->registerGlobalObject("GooglePoly", DependencyManager::get<GooglePolyScriptingInterface>().data());
|
||||
|
||||
if (auto steamClient = PluginManager::getInstance()->getSteamClientPlugin()) {
|
||||
scriptEngine->registerGlobalObject("Steam", new SteamScriptingInterface(scriptManager.data(), steamClient.get()));
|
||||
scriptEngine->registerGlobalObject("Steam", new SteamScriptingInterface(scriptManager.get(), steamClient.get()));
|
||||
}
|
||||
auto scriptingInterface = DependencyManager::get<controller::ScriptingInterface>();
|
||||
scriptEngine->registerGlobalObject("Controller", scriptingInterface.data());
|
||||
UserInputMapper::registerControllerTypes(scriptEngine.data());
|
||||
UserInputMapper::registerControllerTypes(scriptEngine.get());
|
||||
|
||||
auto recordingInterface = DependencyManager::get<RecordingScriptingInterface>();
|
||||
scriptEngine->registerGlobalObject("Recording", recordingInterface.data());
|
||||
|
@ -7606,18 +7606,18 @@ void Application::registerScriptEngineWithApplicationServices(const ScriptManage
|
|||
scriptEngine->registerGlobalObject("HifiAbout", AboutUtil::getInstance()); // Deprecated.
|
||||
scriptEngine->registerGlobalObject("ResourceRequestObserver", DependencyManager::get<ResourceRequestObserver>().data());
|
||||
|
||||
registerInteractiveWindowMetaType(scriptEngine.data());
|
||||
registerInteractiveWindowMetaType(scriptEngine.get());
|
||||
|
||||
auto pickScriptingInterface = DependencyManager::get<PickScriptingInterface>();
|
||||
pickScriptingInterface->registerMetaTypes(scriptEngine.data());
|
||||
pickScriptingInterface->registerMetaTypes(scriptEngine.get());
|
||||
|
||||
// connect this script engines printedMessage signal to the global ScriptEngines these various messages
|
||||
auto scriptEngines = DependencyManager::get<ScriptEngines>().data();
|
||||
connect(scriptManager.data(), &ScriptManager::printedMessage, scriptEngines, &ScriptEngines::onPrintedMessage);
|
||||
connect(scriptManager.data(), &ScriptManager::errorMessage, scriptEngines, &ScriptEngines::onErrorMessage);
|
||||
connect(scriptManager.data(), &ScriptManager::warningMessage, scriptEngines, &ScriptEngines::onWarningMessage);
|
||||
connect(scriptManager.data(), &ScriptManager::infoMessage, scriptEngines, &ScriptEngines::onInfoMessage);
|
||||
connect(scriptManager.data(), &ScriptManager::clearDebugWindow, scriptEngines, &ScriptEngines::onClearDebugWindow);
|
||||
connect(scriptManager.get(), &ScriptManager::printedMessage, scriptEngines, &ScriptEngines::onPrintedMessage);
|
||||
connect(scriptManager.get(), &ScriptManager::errorMessage, scriptEngines, &ScriptEngines::onErrorMessage);
|
||||
connect(scriptManager.get(), &ScriptManager::warningMessage, scriptEngines, &ScriptEngines::onWarningMessage);
|
||||
connect(scriptManager.get(), &ScriptManager::infoMessage, scriptEngines, &ScriptEngines::onInfoMessage);
|
||||
connect(scriptManager.get(), &ScriptManager::clearDebugWindow, scriptEngines, &ScriptEngines::onClearDebugWindow);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#define hifi_Application_h
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
#include <QtCore/QCommandLineParser>
|
||||
#include <QtCore/QHash>
|
||||
|
@ -93,7 +94,7 @@ class AssetUpload;
|
|||
class CompositorHelper;
|
||||
class AudioInjector;
|
||||
class ScriptEngine;
|
||||
using ScriptEnginePointer = QSharedPointer<ScriptEngine>;
|
||||
using ScriptEnginePointer = std::shared_ptr<ScriptEngine>;
|
||||
|
||||
namespace controller {
|
||||
class StateController;
|
||||
|
|
|
@ -449,8 +449,8 @@ void MyAvatar::registerMetaTypes(ScriptEnginePointer engine) {
|
|||
}
|
||||
engine->globalObject().setProperty("DriveKeys", driveKeys);
|
||||
|
||||
scriptRegisterMetaType(engine.data(), audioListenModeToScriptValue, audioListenModeFromScriptValue);
|
||||
scriptRegisterMetaType(engine.data(), driveKeysToScriptValue, driveKeysFromScriptValue);
|
||||
scriptRegisterMetaType(engine.get(), audioListenModeToScriptValue, audioListenModeFromScriptValue);
|
||||
scriptRegisterMetaType(engine.get(), driveKeysToScriptValue, driveKeysFromScriptValue);
|
||||
}
|
||||
|
||||
void MyAvatar::setOrientationVar(const QVariant& newOrientationVar) {
|
||||
|
@ -2673,7 +2673,7 @@ QVariantList MyAvatar::getAvatarEntitiesVariant() {
|
|||
EntityItemProperties entityProperties = entity->getProperties(desiredProperties);
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(_scriptEngineLock);
|
||||
ScriptValue scriptProperties = EntityItemPropertiesToScriptValue(_scriptEngine.data(), entityProperties);
|
||||
ScriptValue scriptProperties = EntityItemPropertiesToScriptValue(_scriptEngine.get(), entityProperties);
|
||||
avatarEntityData["properties"] = scriptProperties.toVariant();
|
||||
}
|
||||
avatarEntitiesData.append(QVariant(avatarEntityData));
|
||||
|
|
|
@ -15,11 +15,11 @@
|
|||
#define hifi_MyAvatar_h
|
||||
|
||||
#include <bitset>
|
||||
#include <memory>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include <QUuid>
|
||||
#include <QtCore/QSharedPointer>
|
||||
|
||||
#include <AvatarConstants.h>
|
||||
#include <avatars-renderer/Avatar.h>
|
||||
|
@ -43,7 +43,7 @@ class ModelItemID;
|
|||
class MyHead;
|
||||
class DetailedMotionState;
|
||||
class ScriptEngine;
|
||||
using ScriptEnginePointer = QSharedPointer<ScriptEngine>;
|
||||
using ScriptEnginePointer = std::shared_ptr<ScriptEngine>;
|
||||
|
||||
/*@jsdoc
|
||||
* <p>Locomotion control types.</p>
|
||||
|
|
|
@ -374,7 +374,7 @@ bool QmlCommerce::installApp(const QString& itemHref, const bool& alsoOpenImmedi
|
|||
// Don't try to re-load (install) a script if it's already running
|
||||
QStringList runningScripts = DependencyManager::get<ScriptEngines>()->getRunningScripts();
|
||||
if (!runningScripts.contains(scriptUrl)) {
|
||||
if ((DependencyManager::get<ScriptEngines>()->loadScript(scriptUrl.trimmed())).isNull()) {
|
||||
if (!(DependencyManager::get<ScriptEngines>()->loadScript(scriptUrl.trimmed()))) {
|
||||
qCDebug(commerce) << "Couldn't load script.";
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -308,7 +308,7 @@ void JSConsole::highlightedCompletion(const QModelIndex& completion) {
|
|||
|
||||
JSConsole::~JSConsole() {
|
||||
if (_scriptManager) {
|
||||
disconnect(_scriptManager.data(), nullptr, this, nullptr);
|
||||
disconnect(_scriptManager.get(), nullptr, this, nullptr);
|
||||
_scriptManager.reset();
|
||||
}
|
||||
delete _ui;
|
||||
|
@ -319,21 +319,21 @@ void JSConsole::setScriptManager(const ScriptManagerPointer& scriptManager) {
|
|||
return;
|
||||
}
|
||||
if (scriptManager != nullptr) {
|
||||
disconnect(_scriptManager.data(), nullptr, this, nullptr);
|
||||
disconnect(_scriptManager.get(), nullptr, this, nullptr);
|
||||
_scriptManager.reset();
|
||||
}
|
||||
|
||||
// if scriptEngine is nullptr then create one and keep track of it using _ownScriptEngine
|
||||
if (scriptManager.isNull()) {
|
||||
if (!scriptManager) {
|
||||
_scriptManager = DependencyManager::get<ScriptEngines>()->loadScript(_consoleFileName, false);
|
||||
} else {
|
||||
_scriptManager = scriptManager;
|
||||
}
|
||||
|
||||
connect(_scriptManager.data(), &ScriptManager::printedMessage, this, &JSConsole::handlePrint);
|
||||
connect(_scriptManager.data(), &ScriptManager::infoMessage, this, &JSConsole::handleInfo);
|
||||
connect(_scriptManager.data(), &ScriptManager::warningMessage, this, &JSConsole::handleWarning);
|
||||
connect(_scriptManager.data(), &ScriptManager::errorMessage, this, &JSConsole::handleError);
|
||||
connect(_scriptManager.get(), &ScriptManager::printedMessage, this, &JSConsole::handlePrint);
|
||||
connect(_scriptManager.get(), &ScriptManager::infoMessage, this, &JSConsole::handleInfo);
|
||||
connect(_scriptManager.get(), &ScriptManager::warningMessage, this, &JSConsole::handleWarning);
|
||||
connect(_scriptManager.get(), &ScriptManager::errorMessage, this, &JSConsole::handleError);
|
||||
}
|
||||
|
||||
void JSConsole::executeCommand(const QString& command) {
|
||||
|
@ -349,13 +349,13 @@ void JSConsole::executeCommand(const QString& command) {
|
|||
|
||||
appendMessage(">", "<span style='" + COMMAND_STYLE + "'>" + command.toHtmlEscaped() + "</span>");
|
||||
|
||||
QWeakPointer<ScriptManager> weakScriptManager = _scriptManager;
|
||||
std::weak_ptr<ScriptManager> weakScriptManager = _scriptManager;
|
||||
auto consoleFileName = _consoleFileName;
|
||||
QFuture<ScriptValue> future = QtConcurrent::run([weakScriptManager, consoleFileName, command]() -> ScriptValue {
|
||||
ScriptValue result;
|
||||
auto scriptManager = weakScriptManager.lock();
|
||||
if (scriptManager) {
|
||||
BLOCKING_INVOKE_METHOD(scriptManager.data(), "evaluate",
|
||||
BLOCKING_INVOKE_METHOD(scriptManager.get(), "evaluate",
|
||||
Q_RETURN_ARG(ScriptValue, result),
|
||||
Q_ARG(const QString&, command),
|
||||
Q_ARG(const QString&, consoleFileName));
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
#ifndef hifi_JSConsole_h
|
||||
#define hifi_JSConsole_h
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QFutureWatcher>
|
||||
#include <QObject>
|
||||
#include <QCompleter>
|
||||
|
@ -22,7 +24,7 @@
|
|||
|
||||
class QStandardItemModel;
|
||||
class ScriptManager;
|
||||
using ScriptManagerPointer = QSharedPointer<ScriptManager>;
|
||||
using ScriptManagerPointer = std::shared_ptr<ScriptManager>;
|
||||
|
||||
const QString CONSOLE_TITLE = "Scripting Console";
|
||||
const float CONSOLE_WINDOW_OPACITY = 0.95f;
|
||||
|
|
|
@ -26,7 +26,7 @@ TestingDialog::TestingDialog(QWidget* parent) :
|
|||
|
||||
_manager = DependencyManager::get<ScriptEngines>()->loadScript(qApp->applicationDirPath() + testRunnerRelativePath);
|
||||
_console->setScriptManager(_manager);
|
||||
connect(_manager.data(), &ScriptManager::finished, this, &TestingDialog::onTestingFinished);
|
||||
connect(_manager.get(), &ScriptManager::finished, this, &TestingDialog::onTestingFinished);
|
||||
}
|
||||
|
||||
void TestingDialog::onTestingFinished(const QString& scriptPath) {
|
||||
|
|
|
@ -12,12 +12,13 @@
|
|||
#ifndef hifi_TestingDialog_h
|
||||
#define hifi_TestingDialog_h
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QDialog>
|
||||
#include <QtCore/QSharedPointer>
|
||||
#include "JSConsole.h"
|
||||
|
||||
class ScriptManager;
|
||||
using ScriptManagerPointer = QSharedPointer<ScriptManager>;
|
||||
using ScriptManagerPointer = std::shared_ptr<ScriptManager>;
|
||||
|
||||
const QString windowLabel = "Client Script Tests";
|
||||
const QString testRunnerRelativePath = "/scripts/developer/tests/unit_tests/testRunner.js";
|
||||
|
|
|
@ -641,7 +641,7 @@ EntityItemProperties Overlays::convertOverlayToEntityProperties(QVariantMap& ove
|
|||
|
||||
QVariantMap Overlays::convertEntityToOverlayProperties(const EntityItemProperties& properties) {
|
||||
ScriptEnginePointer scriptEngine = newScriptEngine();
|
||||
QVariantMap overlayProps = EntityItemPropertiesToScriptValue(scriptEngine.data(), properties).toVariant().toMap();
|
||||
QVariantMap overlayProps = EntityItemPropertiesToScriptValue(scriptEngine.get(), properties).toVariant().toMap();
|
||||
|
||||
QString type = overlayProps["type"].toString();
|
||||
overlayProps["type"] = entityToOverlayType(type);
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "AnimationCache.h"
|
||||
|
||||
STATIC_SCRIPT_INITIALIZER(+[](ScriptManager* manager) {
|
||||
registerAnimationTypes(manager->engine().data());
|
||||
registerAnimationTypes(manager->engine().get());
|
||||
});
|
||||
|
||||
QStringList AnimationObject::getJointNames() const {
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#include <ScriptValue.h>
|
||||
|
||||
STATIC_SCRIPT_INITIALIZER(+[](ScriptManager* manager) {
|
||||
auto scriptEngine = manager->engine().data();
|
||||
auto scriptEngine = manager->engine();
|
||||
|
||||
ScriptValue audioEffectOptionsConstructorValue = scriptEngine->newFunction(AudioEffectOptions::constructor);
|
||||
scriptEngine->globalObject().setProperty("AudioEffectOptions", audioEffectOptionsConstructorValue);
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
|
||||
STATIC_SCRIPT_INITIALIZER(+[](ScriptManager* manager){
|
||||
auto scriptEngine = manager->engine().data();
|
||||
auto scriptEngine = manager->engine().get();
|
||||
|
||||
registerAudioMetaTypes(scriptEngine);
|
||||
scriptEngine->registerGlobalObject("Audio", DependencyManager::get<AudioScriptingInterface>().data());
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include <ScriptValue.h>
|
||||
|
||||
STATIC_SCRIPT_INITIALIZER(+[](ScriptManager* manager) {
|
||||
auto scriptEngine = manager->engine().data();
|
||||
auto scriptEngine = manager->engine().get();
|
||||
|
||||
scriptRegisterMetaType(scriptEngine, injectorToScriptValue, injectorFromScriptValue);
|
||||
});
|
||||
|
|
|
@ -69,7 +69,7 @@ static const float DEFAULT_AVATAR_DENSITY = 1000.0f; // density of water
|
|||
#define ASSERT(COND) do { if (!(COND)) { abort(); } } while(0)
|
||||
|
||||
STATIC_SCRIPT_INITIALIZER(+[](ScriptManager* manager) {
|
||||
auto scriptEngine = manager->engine().data();
|
||||
auto scriptEngine = manager->engine().get();
|
||||
|
||||
registerAvatarTypes(scriptEngine);
|
||||
scriptRegisterMetaType(scriptEngine, RayToAvatarIntersectionResultToScriptValue, RayToAvatarIntersectionResultFromScriptValue);
|
||||
|
|
|
@ -25,7 +25,7 @@ void avatarDataFromScriptValue(const ScriptValue& object, ScriptAvatarData*& out
|
|||
}
|
||||
|
||||
STATIC_SCRIPT_INITIALIZER(+[](ScriptManager* manager) {
|
||||
auto scriptEngine = manager->engine().data();
|
||||
auto scriptEngine = manager->engine().get();
|
||||
|
||||
scriptRegisterMetaType(scriptEngine, avatarDataToScriptValue, avatarDataFromScriptValue);
|
||||
});
|
||||
|
|
|
@ -212,13 +212,15 @@ void MaterialBaker::outputMaterial() {
|
|||
if (_materialResource->parsedMaterials.networkMaterials.size() == 1) {
|
||||
auto networkMaterial = _materialResource->parsedMaterials.networkMaterials.begin();
|
||||
auto scriptableMaterial = scriptable::ScriptableMaterial(networkMaterial->second);
|
||||
QVariant materialVariant = scriptable::scriptableMaterialToScriptValue(_scriptEngine.data(), scriptableMaterial).toVariant();
|
||||
QVariant materialVariant =
|
||||
scriptable::scriptableMaterialToScriptValue(_scriptEngine.get(), scriptableMaterial).toVariant();
|
||||
json.insert("materials", QJsonDocument::fromVariant(materialVariant).object());
|
||||
} else {
|
||||
QJsonArray materialArray;
|
||||
for (auto networkMaterial : _materialResource->parsedMaterials.networkMaterials) {
|
||||
auto scriptableMaterial = scriptable::ScriptableMaterial(networkMaterial.second);
|
||||
QVariant materialVariant = scriptable::scriptableMaterialToScriptValue(_scriptEngine.data(), scriptableMaterial).toVariant();
|
||||
QVariant materialVariant =
|
||||
scriptable::scriptableMaterialToScriptValue(_scriptEngine.get(), scriptableMaterial).toVariant();
|
||||
materialArray.append(QJsonDocument::fromVariant(materialVariant).object());
|
||||
}
|
||||
json.insert("materials", materialArray);
|
||||
|
|
|
@ -42,7 +42,7 @@ void inputControllerFromScriptValue(const ScriptValue& object, controller::Input
|
|||
}
|
||||
|
||||
STATIC_SCRIPT_INITIALIZER(+[](ScriptManager* manager) {
|
||||
auto scriptEngine = manager->engine().data();
|
||||
auto scriptEngine = manager->engine().get();
|
||||
|
||||
scriptRegisterMetaType(scriptEngine, inputControllerToScriptValue, inputControllerFromScriptValue);
|
||||
});
|
||||
|
|
|
@ -161,42 +161,52 @@ int EntityTreeRenderer::_entitiesScriptEngineCount = 0;
|
|||
void EntityTreeRenderer::setupEntityScriptEngineSignals(const ScriptManagerPointer& scriptManager) {
|
||||
auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
|
||||
|
||||
connect(entityScriptingInterface.data(), &EntityScriptingInterface::mousePressOnEntity, scriptManager.data(), [&](const EntityItemID& entityID, const PointerEvent& event) {
|
||||
connect(entityScriptingInterface.data(), &EntityScriptingInterface::mousePressOnEntity, scriptManager.get(),
|
||||
[&](const EntityItemID& entityID, const PointerEvent& event) {
|
||||
scriptManager->callEntityScriptMethod(entityID, "mousePressOnEntity", event);
|
||||
});
|
||||
connect(entityScriptingInterface.data(), &EntityScriptingInterface::mouseDoublePressOnEntity, scriptManager.data(), [&](const EntityItemID& entityID, const PointerEvent& event) {
|
||||
connect(entityScriptingInterface.data(), &EntityScriptingInterface::mouseDoublePressOnEntity, scriptManager.get(),
|
||||
[&](const EntityItemID& entityID, const PointerEvent& event) {
|
||||
scriptManager->callEntityScriptMethod(entityID, "mouseDoublePressOnEntity", event);
|
||||
});
|
||||
connect(entityScriptingInterface.data(), &EntityScriptingInterface::mouseMoveOnEntity, scriptManager.data(), [&](const EntityItemID& entityID, const PointerEvent& event) {
|
||||
connect(entityScriptingInterface.data(), &EntityScriptingInterface::mouseMoveOnEntity, scriptManager.get(),
|
||||
[&](const EntityItemID& entityID, const PointerEvent& event) {
|
||||
scriptManager->callEntityScriptMethod(entityID, "mouseMoveOnEntity", event);
|
||||
// FIXME: this is a duplicate of mouseMoveOnEntity, but it seems like some scripts might use this naming
|
||||
scriptManager->callEntityScriptMethod(entityID, "mouseMoveEvent", event);
|
||||
});
|
||||
connect(entityScriptingInterface.data(), &EntityScriptingInterface::mouseReleaseOnEntity, scriptManager.data(), [&](const EntityItemID& entityID, const PointerEvent& event) {
|
||||
connect(entityScriptingInterface.data(), &EntityScriptingInterface::mouseReleaseOnEntity, scriptManager.get(),
|
||||
[&](const EntityItemID& entityID, const PointerEvent& event) {
|
||||
scriptManager->callEntityScriptMethod(entityID, "mouseReleaseOnEntity", event);
|
||||
});
|
||||
|
||||
connect(entityScriptingInterface.data(), &EntityScriptingInterface::clickDownOnEntity, scriptManager.data(), [&](const EntityItemID& entityID, const PointerEvent& event) {
|
||||
connect(entityScriptingInterface.data(), &EntityScriptingInterface::clickDownOnEntity, scriptManager.get(),
|
||||
[&](const EntityItemID& entityID, const PointerEvent& event) {
|
||||
scriptManager->callEntityScriptMethod(entityID, "clickDownOnEntity", event);
|
||||
});
|
||||
connect(entityScriptingInterface.data(), &EntityScriptingInterface::holdingClickOnEntity, scriptManager.data(), [&](const EntityItemID& entityID, const PointerEvent& event) {
|
||||
connect(entityScriptingInterface.data(), &EntityScriptingInterface::holdingClickOnEntity, scriptManager.get(),
|
||||
[&](const EntityItemID& entityID, const PointerEvent& event) {
|
||||
scriptManager->callEntityScriptMethod(entityID, "holdingClickOnEntity", event);
|
||||
});
|
||||
connect(entityScriptingInterface.data(), &EntityScriptingInterface::clickReleaseOnEntity, scriptManager.data(), [&](const EntityItemID& entityID, const PointerEvent& event) {
|
||||
connect(entityScriptingInterface.data(), &EntityScriptingInterface::clickReleaseOnEntity, scriptManager.get(),
|
||||
[&](const EntityItemID& entityID, const PointerEvent& event) {
|
||||
scriptManager->callEntityScriptMethod(entityID, "clickReleaseOnEntity", event);
|
||||
});
|
||||
|
||||
connect(entityScriptingInterface.data(), &EntityScriptingInterface::hoverEnterEntity, scriptManager.data(), [&](const EntityItemID& entityID, const PointerEvent& event) {
|
||||
connect(entityScriptingInterface.data(), &EntityScriptingInterface::hoverEnterEntity, scriptManager.get(),
|
||||
[&](const EntityItemID& entityID, const PointerEvent& event) {
|
||||
scriptManager->callEntityScriptMethod(entityID, "hoverEnterEntity", event);
|
||||
});
|
||||
connect(entityScriptingInterface.data(), &EntityScriptingInterface::hoverOverEntity, scriptManager.data(), [&](const EntityItemID& entityID, const PointerEvent& event) {
|
||||
connect(entityScriptingInterface.data(), &EntityScriptingInterface::hoverOverEntity, scriptManager.get(),
|
||||
[&](const EntityItemID& entityID, const PointerEvent& event) {
|
||||
scriptManager->callEntityScriptMethod(entityID, "hoverOverEntity", event);
|
||||
});
|
||||
connect(entityScriptingInterface.data(), &EntityScriptingInterface::hoverLeaveEntity, scriptManager.data(), [&](const EntityItemID& entityID, const PointerEvent& event) {
|
||||
connect(entityScriptingInterface.data(), &EntityScriptingInterface::hoverLeaveEntity, scriptManager.get(),
|
||||
[&](const EntityItemID& entityID, const PointerEvent& event) {
|
||||
scriptManager->callEntityScriptMethod(entityID, "hoverLeaveEntity", event);
|
||||
});
|
||||
|
||||
connect(scriptManager.data(), &ScriptManager::entityScriptPreloadFinished, [&](const EntityItemID& entityID) {
|
||||
connect(scriptManager.get(), &ScriptManager::entityScriptPreloadFinished, [&](const EntityItemID& entityID) {
|
||||
EntityItemPointer entity = getTree()->findEntityByID(entityID);
|
||||
if (entity) {
|
||||
entity->setScriptHasFinishedPreload(true);
|
||||
|
@ -215,7 +225,7 @@ void EntityTreeRenderer::resetPersistentEntitiesScriptEngine() {
|
|||
QString("about:Entities %1").arg(++_entitiesScriptEngineCount));
|
||||
DependencyManager::get<ScriptEngines>()->runScriptInitializers(_persistentEntitiesScriptManager);
|
||||
_persistentEntitiesScriptManager->runInThread();
|
||||
auto entitiesScriptEngineProvider = qSharedPointerCast<EntitiesScriptEngineProvider>(_persistentEntitiesScriptManager);
|
||||
std::shared_ptr<EntitiesScriptEngineProvider> entitiesScriptEngineProvider = _persistentEntitiesScriptManager;
|
||||
auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
|
||||
entityScriptingInterface->setPersistentEntitiesScriptEngine(entitiesScriptEngineProvider);
|
||||
|
||||
|
@ -233,7 +243,7 @@ void EntityTreeRenderer::resetNonPersistentEntitiesScriptEngine() {
|
|||
QString("about:Entities %1").arg(++_entitiesScriptEngineCount));
|
||||
DependencyManager::get<ScriptEngines>()->runScriptInitializers(_nonPersistentEntitiesScriptManager);
|
||||
_nonPersistentEntitiesScriptManager->runInThread();
|
||||
auto entitiesScriptEngineProvider = qSharedPointerCast<EntitiesScriptEngineProvider>(_nonPersistentEntitiesScriptManager);
|
||||
std::shared_ptr<EntitiesScriptEngineProvider> entitiesScriptEngineProvider = _nonPersistentEntitiesScriptManager;
|
||||
DependencyManager::get<EntityScriptingInterface>()->setNonPersistentEntitiesScriptEngine(entitiesScriptEngineProvider);
|
||||
|
||||
setupEntityScriptEngineSignals(_nonPersistentEntitiesScriptManager);
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
#ifndef hifi_EntityTreeRenderer_h
|
||||
#define hifi_EntityTreeRenderer_h
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QtCore/QSet>
|
||||
#include <QtCore/QStack>
|
||||
#include <QtGui/QMouseEvent>
|
||||
|
@ -35,8 +37,8 @@ class ZoneEntityItem;
|
|||
class EntityItem;
|
||||
class ScriptEngine;
|
||||
class ScriptManager;
|
||||
using ScriptEnginePointer = QSharedPointer<ScriptEngine>;
|
||||
using ScriptManagerPointer = QSharedPointer<ScriptManager>;
|
||||
using ScriptEnginePointer = std::shared_ptr<ScriptEngine>;
|
||||
using ScriptManagerPointer = std::shared_ptr<ScriptManager>;
|
||||
|
||||
namespace render { namespace entities {
|
||||
class EntityRenderer;
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include <OBJWriter.h>
|
||||
|
||||
STATIC_SCRIPT_INITIALIZER(+[](ScriptManager* manager) {
|
||||
auto scriptEngine = manager->engine().data();
|
||||
auto scriptEngine = manager->engine();
|
||||
|
||||
scriptEngine->registerGlobalObject("Model", new ModelScriptingInterface(manager));
|
||||
});
|
||||
|
|
|
@ -15,14 +15,15 @@
|
|||
#ifndef hifi_ModelScriptingInterface_h
|
||||
#define hifi_ModelScriptingInterface_h
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QSharedPointer>
|
||||
|
||||
#include <RegisteredMetaTypes.h>
|
||||
#include <ScriptValue.h>
|
||||
|
||||
class ScriptEngine;
|
||||
using ScriptEnginePointer = QSharedPointer<ScriptEngine>;
|
||||
using ScriptEnginePointer = std::shared_ptr<ScriptEngine>;
|
||||
|
||||
/*@jsdoc
|
||||
* The <code>Model</code> API provides the ability to manipulate meshes. You can get the meshes for an entity using
|
||||
|
@ -101,7 +102,7 @@ public:
|
|||
Q_INVOKABLE ScriptValue getVertex(MeshProxy* meshProxy, int vertexIndex);
|
||||
|
||||
private:
|
||||
ScriptEnginePointer _modelScriptEngine { nullptr };
|
||||
ScriptEnginePointer _modelScriptEngine;
|
||||
};
|
||||
|
||||
#endif // hifi_ModelScriptingInterface_h
|
||||
|
|
|
@ -264,7 +264,7 @@ void EntityEditFilters::scriptRequestFinished(EntityItemID entityID) {
|
|||
engine->setProperty("fileName", urlString);
|
||||
engine->setProperty("entityID", entityID);
|
||||
engine->globalObject().setProperty("Script", engine->newQObject(manager.get()));
|
||||
DependencyManager::get<ScriptInitializers>()->runScriptInitializers(engine.data());
|
||||
DependencyManager::get<ScriptInitializers>()->runScriptInitializers(engine.get());
|
||||
engine->evaluate(scriptContents, urlString);
|
||||
if (!hadUncaughtExceptions(*engine, urlString)) {
|
||||
// put the engine in the engine map (so we don't leak them, etc...)
|
||||
|
|
|
@ -49,7 +49,7 @@ const QString GRABBABLE_USER_DATA = "{\"grabbableKey\":{\"grabbable\":true}}";
|
|||
const QString NOT_GRABBABLE_USER_DATA = "{\"grabbableKey\":{\"grabbable\":false}}";
|
||||
|
||||
void staticEntityScriptInitializer(ScriptManager* manager) {
|
||||
auto scriptEngine = manager->engine().data();
|
||||
auto scriptEngine = manager->engine().get();
|
||||
|
||||
auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
|
||||
entityScriptingInterface->init();
|
||||
|
@ -145,7 +145,8 @@ void EntityScriptingInterface::attachDefaultEventHandlers(ScriptManager* manager
|
|||
using SingleEntityHandler = std::function<void(const EntityItemID&)>;
|
||||
auto makeSingleEntityHandler = [manager](QString eventName) -> SingleEntityHandler {
|
||||
return [manager, eventName](const EntityItemID& entityItemID) {
|
||||
manager->forwardHandlerCall(entityItemID, eventName, { EntityItemIDtoScriptValue(manager->engine().data(), entityItemID) });
|
||||
manager->forwardHandlerCall(entityItemID, eventName,
|
||||
{ EntityItemIDtoScriptValue(manager->engine().get(), entityItemID) });
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -159,7 +160,7 @@ void EntityScriptingInterface::attachDefaultEventHandlers(ScriptManager* manager
|
|||
auto makePointerHandler = [manager](QString eventName) -> PointerHandler {
|
||||
return [manager, eventName](const EntityItemID& entityItemID, const PointerEvent& event) {
|
||||
if (!EntityTree::areEntityClicksCaptured()) {
|
||||
ScriptEngine* engine = manager->engine().data();
|
||||
ScriptEngine* engine = manager->engine().get();
|
||||
manager->forwardHandlerCall(entityItemID, eventName,
|
||||
{ EntityItemIDtoScriptValue(engine, entityItemID), event.toScriptValue(engine) });
|
||||
}
|
||||
|
@ -176,7 +177,7 @@ void EntityScriptingInterface::attachDefaultEventHandlers(ScriptManager* manager
|
|||
using CollisionHandler = std::function<void(const EntityItemID&, const EntityItemID&, const Collision&)>;
|
||||
auto makeCollisionHandler = [manager](QString eventName) -> CollisionHandler {
|
||||
return [manager, eventName](const EntityItemID& idA, const EntityItemID& idB, const Collision& collision) {
|
||||
ScriptEngine* engine = manager->engine().data();
|
||||
ScriptEngine* engine = manager->engine().get();
|
||||
manager->forwardHandlerCall(idA, eventName,
|
||||
{ EntityItemIDtoScriptValue(engine, idA),
|
||||
EntityItemIDtoScriptValue(engine, idB),
|
||||
|
@ -1234,12 +1235,12 @@ QSizeF EntityScriptingInterface::textSize(const QUuid& id, const QString& text)
|
|||
return EntityTree::textSize(id, text);
|
||||
}
|
||||
|
||||
void EntityScriptingInterface::setPersistentEntitiesScriptEngine(QSharedPointer<EntitiesScriptEngineProvider> manager) {
|
||||
void EntityScriptingInterface::setPersistentEntitiesScriptEngine(std::shared_ptr<EntitiesScriptEngineProvider> manager) {
|
||||
std::lock_guard<std::recursive_mutex> lock(_entitiesScriptEngineLock);
|
||||
_persistentEntitiesScriptManager = manager;
|
||||
}
|
||||
|
||||
void EntityScriptingInterface::setNonPersistentEntitiesScriptEngine(QSharedPointer<EntitiesScriptEngineProvider> manager) {
|
||||
void EntityScriptingInterface::setNonPersistentEntitiesScriptEngine(std::shared_ptr<EntitiesScriptEngineProvider> manager) {
|
||||
std::lock_guard<std::recursive_mutex> lock(_entitiesScriptEngineLock);
|
||||
_nonPersistentEntitiesScriptManager = manager;
|
||||
}
|
||||
|
@ -1528,7 +1529,7 @@ bool EntityPropertyMetadataRequest::script(EntityItemID entityID, const ScriptVa
|
|||
request->deleteLater();
|
||||
});
|
||||
auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
|
||||
entityScriptingInterface->withEntitiesScriptEngine([&](QSharedPointer<EntitiesScriptEngineProvider> entitiesScriptEngine) {
|
||||
entityScriptingInterface->withEntitiesScriptEngine([&](std::shared_ptr<EntitiesScriptEngineProvider> entitiesScriptEngine) {
|
||||
if (entitiesScriptEngine) {
|
||||
request->setFuture(entitiesScriptEngine->getLocalEntityScriptDetails(entityID));
|
||||
}
|
||||
|
@ -2442,7 +2443,7 @@ void EntityScriptingInterface::getMeshes(const QUuid& entityID, const ScriptValu
|
|||
bool success = entity->getMeshes(result);
|
||||
|
||||
if (success) {
|
||||
ScriptValue resultAsScriptValue = meshesToScriptValue(engine.data(), result);
|
||||
ScriptValue resultAsScriptValue = meshesToScriptValue(engine.get(), result);
|
||||
ScriptValueList args{ resultAsScriptValue, engine->newValue(true) };
|
||||
callback.call(ScriptValue(), args);
|
||||
} else {
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
#ifndef hifi_EntityScriptingInterface_h
|
||||
#define hifi_EntityScriptingInterface_h
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QSharedPointer>
|
||||
|
@ -185,8 +187,8 @@ public:
|
|||
|
||||
void setEntityTree(EntityTreePointer modelTree);
|
||||
EntityTreePointer getEntityTree() { return _entityTree; }
|
||||
void setPersistentEntitiesScriptEngine(QSharedPointer<EntitiesScriptEngineProvider> manager);
|
||||
void setNonPersistentEntitiesScriptEngine(QSharedPointer<EntitiesScriptEngineProvider> manager);
|
||||
void setPersistentEntitiesScriptEngine(std::shared_ptr<EntitiesScriptEngineProvider> manager);
|
||||
void setNonPersistentEntitiesScriptEngine(std::shared_ptr<EntitiesScriptEngineProvider> manager);
|
||||
|
||||
void resetActivityTracking();
|
||||
ActivityTracking getActivityTracking() const { return _activityTracking; }
|
||||
|
@ -2532,7 +2534,7 @@ signals:
|
|||
void webEventReceived(const EntityItemID& entityItemID, const QVariant& message);
|
||||
|
||||
protected:
|
||||
void withEntitiesScriptEngine(std::function<void(QSharedPointer<EntitiesScriptEngineProvider>)> function, const EntityItemID& id) {
|
||||
void withEntitiesScriptEngine(std::function<void(std::shared_ptr<EntitiesScriptEngineProvider>)> function, const EntityItemID& id) {
|
||||
auto entity = getEntityTree()->findEntityByEntityItemID(id);
|
||||
if (entity) {
|
||||
std::lock_guard<std::recursive_mutex> lock(_entitiesScriptEngineLock);
|
||||
|
@ -2573,8 +2575,8 @@ private:
|
|||
EntityTreePointer _entityTree;
|
||||
|
||||
std::recursive_mutex _entitiesScriptEngineLock;
|
||||
QSharedPointer<EntitiesScriptEngineProvider> _persistentEntitiesScriptManager;
|
||||
QSharedPointer<EntitiesScriptEngineProvider> _nonPersistentEntitiesScriptManager;
|
||||
std::shared_ptr<EntitiesScriptEngineProvider> _persistentEntitiesScriptManager;
|
||||
std::shared_ptr<EntitiesScriptEngineProvider> _nonPersistentEntitiesScriptManager;
|
||||
|
||||
bool _bidOnSimulationOwnership { false };
|
||||
|
||||
|
|
|
@ -2943,7 +2943,7 @@ bool EntityTree::writeToMap(QVariantMap& entityDescription, OctreeElementPointer
|
|||
entityDescription["DataVersion"] = _persistDataVersion;
|
||||
entityDescription["Id"] = _persistID;
|
||||
ScriptEnginePointer engine = newScriptEngine();
|
||||
RecurseOctreeToMapOperator theOperator(entityDescription, element, engine.data(), skipDefaultValues,
|
||||
RecurseOctreeToMapOperator theOperator(entityDescription, element, engine.get(), skipDefaultValues,
|
||||
skipThoseWithBadParents, _myAvatar);
|
||||
withReadLock([&] {
|
||||
recurseTreeWithOperator(&theOperator);
|
||||
|
@ -3268,7 +3268,7 @@ bool EntityTree::readFromMap(QVariantMap& map, const bool isImport) {
|
|||
|
||||
bool EntityTree::writeToJSON(QString& jsonString, const OctreeElementPointer& element) {
|
||||
ScriptEnginePointer engine = newScriptEngine();
|
||||
RecurseOctreeToJSONOperator theOperator(element, engine.data(), jsonString);
|
||||
RecurseOctreeToJSONOperator theOperator(element, engine.get(), jsonString);
|
||||
withReadLock([&] {
|
||||
recurseTreeWithOperator(&theOperator);
|
||||
});
|
||||
|
|
|
@ -135,7 +135,7 @@ void CALLBACK MidiInProc(HMIDIIN hMidiIn, UINT wMsg, DWORD_PTR dwInstance, DWORD
|
|||
}
|
||||
|
||||
STATIC_SCRIPT_INITIALIZER(+[](ScriptManager* manager) {
|
||||
auto scriptEngine = manager->engine().data();
|
||||
auto scriptEngine = manager->engine();
|
||||
|
||||
scriptEngine->registerGlobalObject("Midi", DependencyManager::get<Midi>().data());
|
||||
});
|
||||
|
|
|
@ -15,10 +15,10 @@
|
|||
#ifndef hifi_AbstractScriptingServicesInterface_h
|
||||
#define hifi_AbstractScriptingServicesInterface_h
|
||||
|
||||
#include <QtCore/QSharedPointer>
|
||||
#include <memory>
|
||||
|
||||
class ScriptManager;
|
||||
using ScriptManagerPointer = QSharedPointer<ScriptManager>;
|
||||
using ScriptManagerPointer = std::shared_ptr<ScriptManager>;
|
||||
|
||||
/// Interface provided by Application to other objects that need access to scripting services of the application
|
||||
class AbstractScriptingServicesInterface {
|
||||
|
|
|
@ -15,7 +15,8 @@
|
|||
#ifndef hifi_ScriptContext_h
|
||||
#define hifi_ScriptContext_h
|
||||
|
||||
#include <QtCore/QSharedPointer>
|
||||
#include <memory>
|
||||
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QStringList>
|
||||
|
||||
|
@ -24,9 +25,9 @@
|
|||
class ScriptContext;
|
||||
class ScriptEngine;
|
||||
class ScriptFunctionContext;
|
||||
using ScriptContextPointer = QSharedPointer<ScriptContext>;
|
||||
using ScriptFunctionContextPointer = QSharedPointer<ScriptFunctionContext>;
|
||||
using ScriptEnginePointer = QSharedPointer<ScriptEngine>;
|
||||
using ScriptContextPointer = std::shared_ptr<ScriptContext>;
|
||||
using ScriptFunctionContextPointer = std::shared_ptr<ScriptFunctionContext>;
|
||||
using ScriptEnginePointer = std::shared_ptr<ScriptEngine>;
|
||||
|
||||
/// [ScriptInterface] Provides an engine-independent interface for QScriptContextInfo
|
||||
class ScriptFunctionContext {
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include "qtscript/ScriptEngineQtScript.h"
|
||||
|
||||
ScriptEnginePointer newScriptEngine(ScriptManager* manager) {
|
||||
return QSharedPointer<ScriptEngineQtScript>(new ScriptEngineQtScript(manager));
|
||||
return std::make_shared<ScriptEngineQtScript>(manager);
|
||||
}
|
||||
|
||||
ScriptValue makeScopedHandlerObject(const ScriptValue& scopeOrCallback, const ScriptValue& methodOrName) {
|
||||
|
|
|
@ -16,9 +16,10 @@
|
|||
#ifndef hifi_ScriptEngine_h
|
||||
#define hifi_ScriptEngine_h
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QtCore/QFlags>
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QSharedPointer>
|
||||
|
||||
#include "ScriptValue.h"
|
||||
|
||||
|
@ -31,8 +32,8 @@ class ScriptContext;
|
|||
class ScriptEngine;
|
||||
class ScriptManager;
|
||||
class ScriptProgram;
|
||||
using ScriptEnginePointer = QSharedPointer<ScriptEngine>;
|
||||
using ScriptProgramPointer = QSharedPointer<ScriptProgram>;
|
||||
using ScriptEnginePointer = std::shared_ptr<ScriptEngine>;
|
||||
using ScriptProgramPointer = std::shared_ptr<ScriptProgram>;
|
||||
|
||||
Q_DECLARE_METATYPE(ScriptEnginePointer);
|
||||
|
||||
|
|
|
@ -422,7 +422,7 @@ void ScriptEngines::stopAllScripts(bool restart) {
|
|||
_isReloading = true;
|
||||
ScriptManager::Type type = scriptManager->getType();
|
||||
|
||||
connect(scriptManager.data(), &ScriptManager::finished, this, [this, type, isOverrideScript](QString scriptName) {
|
||||
connect(scriptManager.get(), &ScriptManager::finished, this, [this, type, isOverrideScript](QString scriptName) {
|
||||
reloadScript(scriptName, !isOverrideScript)->setType(type);
|
||||
});
|
||||
}
|
||||
|
@ -458,7 +458,7 @@ bool ScriptEngines::stopScript(const QString& rawScriptURL, bool restart) {
|
|||
scriptCache->deleteScript(scriptURL);
|
||||
|
||||
if (!scriptManager->isStopping()) {
|
||||
connect(scriptManager.data(), &ScriptManager::finished,
|
||||
connect(scriptManager.get(), &ScriptManager::finished,
|
||||
this, [this, isUserLoaded, type](QString scriptName, ScriptManagerPointer manager) {
|
||||
reloadScript(scriptName, isUserLoaded)->setType(type);
|
||||
});
|
||||
|
@ -523,12 +523,12 @@ ScriptManagerPointer ScriptEngines::loadScript(const QUrl& scriptFilename, bool
|
|||
launchScriptEngine(scriptManager);
|
||||
} else {
|
||||
// connect to the appropriate signals of this script engine
|
||||
connect(scriptManager.data(), &ScriptManager::scriptLoaded, this, &ScriptEngines::onScriptEngineLoaded);
|
||||
connect(scriptManager.data(), &ScriptManager::errorLoadingScript, this, &ScriptEngines::onScriptEngineError);
|
||||
connect(scriptManager.get(), &ScriptManager::scriptLoaded, this, &ScriptEngines::onScriptEngineLoaded);
|
||||
connect(scriptManager.get(), &ScriptManager::errorLoadingScript, this, &ScriptEngines::onScriptEngineError);
|
||||
|
||||
// Shutdown Interface when script finishes, if requested
|
||||
if (quitWhenFinished) {
|
||||
connect(scriptManager.data(), &ScriptManager::finished, this, &ScriptEngines::quitWhenFinished);
|
||||
connect(scriptManager.get(), &ScriptManager::finished, this, &ScriptEngines::quitWhenFinished);
|
||||
}
|
||||
|
||||
// get the script engine object to load the script at the designated script URL
|
||||
|
@ -554,7 +554,7 @@ ScriptManagerPointer ScriptEngines::getScriptEngine(const QUrl& rawScriptURL) {
|
|||
// FIXME - change to new version of ScriptCache loading notification
|
||||
void ScriptEngines::onScriptEngineLoaded(const QString& rawScriptURL) {
|
||||
UserActivityLogger::getInstance().loadedScript(rawScriptURL);
|
||||
ScriptManagerPointer scriptEngine = qobject_cast<ScriptManager*>(sender())->sharedFromThis();
|
||||
ScriptManagerPointer scriptEngine = qobject_cast<ScriptManager*>(sender())->shared_from_this();
|
||||
|
||||
launchScriptEngine(scriptEngine);
|
||||
|
||||
|
@ -575,16 +575,18 @@ void ScriptEngines::quitWhenFinished() {
|
|||
}
|
||||
|
||||
int ScriptEngines::runScriptInitializers(ScriptManagerPointer scriptManager) {
|
||||
auto nativeCount = DependencyManager::get<ScriptInitializers>()->runScriptInitializers(scriptManager->engine().data());
|
||||
auto nativeCount = DependencyManager::get<ScriptInitializers>()->runScriptInitializers(scriptManager->engine().get());
|
||||
return nativeCount + ScriptInitializerMixin<ScriptManagerPointer>::runScriptInitializers(scriptManager);
|
||||
}
|
||||
|
||||
void ScriptEngines::launchScriptEngine(ScriptManagerPointer scriptManager) {
|
||||
connect(scriptManager.data(), &ScriptManager::finished, this, &ScriptEngines::onScriptFinished, Qt::DirectConnection);
|
||||
connect(scriptManager.data(), &ScriptManager::loadScript, [this](const QString& scriptName, bool userLoaded) {
|
||||
connect(scriptManager.get(), &ScriptManager::finished, this, &ScriptEngines::onScriptFinished, Qt::DirectConnection);
|
||||
connect(scriptManager.get(), &ScriptManager::loadScript,
|
||||
[this](const QString& scriptName, bool userLoaded) {
|
||||
loadScript(scriptName, userLoaded);
|
||||
});
|
||||
connect(scriptManager.data(), &ScriptManager::reloadScript, [this](const QString& scriptName, bool userLoaded) {
|
||||
connect(scriptManager.get(), &ScriptManager::reloadScript,
|
||||
[this](const QString& scriptName, bool userLoaded) {
|
||||
loadScript(scriptName, userLoaded, false, false, true);
|
||||
});
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include <QtCore/QObject>
|
||||
#include <QtCore/QMutex>
|
||||
#include <QtCore/QReadWriteLock>
|
||||
#include <QtCore/QSharedPointer>
|
||||
#include <QtCore/QUrl>
|
||||
|
||||
#include <SettingHandle.h>
|
||||
|
|
|
@ -133,7 +133,7 @@ static ScriptValue debugPrint(ScriptContext* context, ScriptEngine* engine) {
|
|||
ScriptContextPointer parentContext; // using this variable to maintain parent variable lifespan
|
||||
while (userContext && userContext->functionContext()->functionType() == ScriptFunctionContext::NativeFunction) {
|
||||
parentContext = userContext->parentContext();
|
||||
userContext = parentContext.data();
|
||||
userContext = parentContext.get();
|
||||
}
|
||||
QString location;
|
||||
if (userContext) {
|
||||
|
@ -211,7 +211,8 @@ ScriptManagerPointer scriptManagerFactory(ScriptManager::Context context,
|
|||
ScriptManagerPointer newScriptManager(ScriptManager::Context context,
|
||||
const QString& scriptContents,
|
||||
const QString& fileNameString) {
|
||||
ScriptManagerPointer manager(new ScriptManager(context, scriptContents, fileNameString), &QObject::deleteLater);
|
||||
ScriptManagerPointer manager(new ScriptManager(context, scriptContents, fileNameString),
|
||||
[](ScriptManager* obj) { obj->deleteLater(); });
|
||||
ScriptEnginePointer engine = newScriptEngine(manager.get());
|
||||
manager->_engine = engine;
|
||||
return manager;
|
||||
|
@ -559,7 +560,7 @@ static ScriptValue createScriptableResourcePrototype(ScriptManagerPointer manage
|
|||
auto prototype = engine->newObject();
|
||||
|
||||
// Expose enum State to JS/QML via properties
|
||||
QObject* state = new QObject(manager.data());
|
||||
QObject* state = new QObject(manager.get());
|
||||
state->setObjectName("ResourceState");
|
||||
auto metaEnum = QMetaEnum::fromType<ScriptableResource::State>();
|
||||
for (int i = 0; i < metaEnum.keyCount(); ++i) {
|
||||
|
@ -623,7 +624,7 @@ void ScriptManager::init() {
|
|||
_isInitialized = true;
|
||||
runStaticInitializers(this);
|
||||
|
||||
auto scriptEngine = _engine.data();
|
||||
auto scriptEngine = _engine.get();
|
||||
|
||||
// register various meta-types
|
||||
registerMIDIMetaTypes(scriptEngine);
|
||||
|
@ -693,7 +694,7 @@ void ScriptManager::init() {
|
|||
scriptEngine->registerFunction("console", "groupEnd", ConsoleScriptingInterface::groupEnd, 0);
|
||||
|
||||
// Scriptable cache access
|
||||
auto resourcePrototype = createScriptableResourcePrototype(qSharedPointerCast<ScriptManager>(sharedFromThis()));
|
||||
auto resourcePrototype = createScriptableResourcePrototype(shared_from_this());
|
||||
scriptEngine->globalObject().setProperty("Resource", resourcePrototype);
|
||||
scriptEngine->setDefaultPrototype(qMetaTypeId<ScriptableResource*>(), resourcePrototype);
|
||||
scriptRegisterMetaType(scriptEngine, scriptableResourceToScriptValue, scriptableResourceFromScriptValue);
|
||||
|
@ -960,7 +961,7 @@ void ScriptManager::run() {
|
|||
|
||||
emit releaseEntityPacketSenderMessages(true);
|
||||
|
||||
emit finished(_fileNameString, qSharedPointerCast<ScriptManager>(sharedFromThis()));
|
||||
emit finished(_fileNameString, shared_from_this());
|
||||
|
||||
// Don't leave our local-file-access flag laying around, reset it to false when the scriptengine
|
||||
// thread is finished
|
||||
|
@ -1117,7 +1118,7 @@ QUrl ScriptManager::resolvePath(const QString& include) const {
|
|||
auto contextInfo = context->functionContext();
|
||||
parentURL = QUrl(contextInfo->fileName());
|
||||
parentContext = context->parentContext();
|
||||
context = parentContext.data();
|
||||
context = parentContext.get();
|
||||
} while (parentURL.isRelative() && context);
|
||||
|
||||
if (parentURL.isRelative()) {
|
||||
|
@ -1258,7 +1259,8 @@ ScriptValue ScriptManager::currentModule() {
|
|||
auto cache = jsRequire.property("cache");
|
||||
ScriptValue candidate;
|
||||
ScriptContextPointer parentContext; // using this variable to maintain parent variable lifespan
|
||||
for (auto context = _engine->currentContext(); context && !candidate.isObject(); parentContext = context->parentContext(), context = parentContext.data()) {
|
||||
for (auto context = _engine->currentContext(); context && !candidate.isObject();
|
||||
parentContext = context->parentContext(), context = parentContext.get()) {
|
||||
auto contextInfo = context->functionContext();
|
||||
candidate = cache.property(contextInfo->fileName());
|
||||
}
|
||||
|
@ -1808,10 +1810,10 @@ void ScriptManager::loadEntityScript(const EntityItemID& entityID, const QString
|
|||
|
||||
auto scriptCache = DependencyManager::get<ScriptCache>();
|
||||
// note: see EntityTreeRenderer.cpp for shared pointer lifecycle management
|
||||
QWeakPointer<ScriptManager> weakRef(sharedFromThis());
|
||||
std::weak_ptr<ScriptManager> weakRef(shared_from_this());
|
||||
scriptCache->getScriptContents(entityScript,
|
||||
[this, weakRef, entityScript, entityID](const QString& url, const QString& contents, bool isURL, bool success, const QString& status) {
|
||||
QSharedPointer<ScriptManager> strongRef(weakRef);
|
||||
std::shared_ptr<ScriptManager> strongRef(weakRef);
|
||||
if (!strongRef) {
|
||||
qCWarning(scriptengine) << "loadEntityScript.contentAvailable -- ScriptManager was deleted during getScriptContents!!";
|
||||
return;
|
||||
|
@ -1929,7 +1931,7 @@ void ScriptManager::entityScriptContentAvailable(const EntityItemID& entityID, c
|
|||
return;
|
||||
}
|
||||
auto program = _engine->newProgram( contents, fileName );
|
||||
if (program.isNull()) {
|
||||
if (!program) {
|
||||
setError("Bad program (isNull)", EntityScriptStatus::ERROR_RUNNING_SCRIPT);
|
||||
emit unhandledException(_engine->makeError(_engine->newValue("program.isNull")));
|
||||
return; // done processing script
|
||||
|
@ -2337,7 +2339,7 @@ void ScriptManager::callEntityScriptMethod(const EntityItemID& entityID, const Q
|
|||
}
|
||||
|
||||
if (callAllowed && entityScript.property(methodName).isFunction()) {
|
||||
auto scriptEngine = engine().data();
|
||||
auto scriptEngine = engine().get();
|
||||
|
||||
ScriptValueList args;
|
||||
args << EntityItemIDtoScriptValue(scriptEngine, entityID);
|
||||
|
@ -2380,7 +2382,7 @@ void ScriptManager::callEntityScriptMethod(const EntityItemID& entityID, const Q
|
|||
}
|
||||
ScriptValue entityScript = details.scriptObject; // previously loaded
|
||||
if (entityScript.property(methodName).isFunction()) {
|
||||
auto scriptEngine = engine().data();
|
||||
auto scriptEngine = engine().get();
|
||||
|
||||
ScriptValueList args;
|
||||
args << EntityItemIDtoScriptValue(scriptEngine, entityID);
|
||||
|
@ -2420,7 +2422,7 @@ void ScriptManager::callEntityScriptMethod(const EntityItemID& entityID, const Q
|
|||
}
|
||||
ScriptValue entityScript = details.scriptObject; // previously loaded
|
||||
if (entityScript.property(methodName).isFunction()) {
|
||||
auto scriptEngine = engine().data();
|
||||
auto scriptEngine = engine().get();
|
||||
|
||||
ScriptValueList args;
|
||||
args << EntityItemIDtoScriptValue(scriptEngine, entityID);
|
||||
|
|
|
@ -16,10 +16,10 @@
|
|||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <mutex>
|
||||
|
||||
#include <QtCore/QEnableSharedFromThis>
|
||||
#include <QtCore/QFuture>
|
||||
#include <QtCore/QHash>
|
||||
#include <QtCore/QObject>
|
||||
|
@ -54,8 +54,8 @@ static const int DEFAULT_ENTITY_PPS_PER_SCRIPT = 900;
|
|||
class ScriptEngine;
|
||||
class ScriptEngines;
|
||||
class ScriptManager;
|
||||
using ScriptEnginePointer = QSharedPointer<ScriptEngine>;
|
||||
using ScriptManagerPointer = QSharedPointer<ScriptManager>;
|
||||
using ScriptEnginePointer = std::shared_ptr<ScriptEngine>;
|
||||
using ScriptManagerPointer = std::shared_ptr<ScriptManager>;
|
||||
using ScriptValueList = QList<ScriptValue>;
|
||||
|
||||
Q_DECLARE_METATYPE(ScriptManagerPointer)
|
||||
|
@ -137,7 +137,7 @@ public:
|
|||
* <em>Read-only.</em>
|
||||
* @property {Script.ResourceBuckets} ExternalPaths - External resource buckets.
|
||||
*/
|
||||
class ScriptManager : public QObject, public EntitiesScriptEngineProvider, public QEnableSharedFromThis<ScriptManager> {
|
||||
class ScriptManager : public QObject, public EntitiesScriptEngineProvider, public std::enable_shared_from_this<ScriptManager> {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString context READ getContext)
|
||||
Q_PROPERTY(QString type READ getTypeAsString)
|
||||
|
|
|
@ -15,12 +15,12 @@
|
|||
#ifndef hifi_ScriptProgram_h
|
||||
#define hifi_ScriptProgram_h
|
||||
|
||||
#include <QtCore/QSharedPointer>
|
||||
#include <memory>
|
||||
|
||||
class ScriptProgram;
|
||||
class ScriptSyntaxCheckResult;
|
||||
using ScriptProgramPointer = QSharedPointer<ScriptProgram>;
|
||||
using ScriptSyntaxCheckResultPointer = QSharedPointer<ScriptSyntaxCheckResult>;
|
||||
using ScriptProgramPointer = std::shared_ptr<ScriptProgram>;
|
||||
using ScriptSyntaxCheckResultPointer = std::shared_ptr<ScriptSyntaxCheckResult>;
|
||||
|
||||
/// [ScriptInterface] Provides an engine-independent interface for QScriptProgram
|
||||
class ScriptProgram {
|
||||
|
|
|
@ -15,10 +15,11 @@
|
|||
#ifndef hifi_ScriptValue_h
|
||||
#define hifi_ScriptValue_h
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QFlags>
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QSharedPointer>
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QVariant>
|
||||
|
||||
|
@ -26,9 +27,9 @@ class ScriptEngine;
|
|||
class ScriptValue;
|
||||
class ScriptValueIterator;
|
||||
class ScriptValueProxy;
|
||||
using ScriptEnginePointer = QSharedPointer<ScriptEngine>;
|
||||
using ScriptEnginePointer = std::shared_ptr<ScriptEngine>;
|
||||
using ScriptValueList = QList<ScriptValue>;
|
||||
using ScriptValueIteratorPointer = QSharedPointer<ScriptValueIterator>;
|
||||
using ScriptValueIteratorPointer = std::shared_ptr<ScriptValueIterator>;
|
||||
|
||||
/// [ScriptInterface] Provides an engine-independent interface for QScriptValue
|
||||
class ScriptValue {
|
||||
|
|
|
@ -15,13 +15,14 @@
|
|||
#ifndef hifi_ScriptValueIterator_h
|
||||
#define hifi_ScriptValueIterator_h
|
||||
|
||||
#include <QtCore/QSharedPointer>
|
||||
#include <memory>
|
||||
|
||||
#include <QtCore/QString>
|
||||
|
||||
#include "ScriptValue.h"
|
||||
|
||||
class ScriptValueIterator;
|
||||
using ScriptValueIteratorPointer = QSharedPointer<ScriptValueIterator>;
|
||||
using ScriptValueIteratorPointer = std::shared_ptr<ScriptValueIterator>;
|
||||
|
||||
/// [ScriptInterface] Provides an engine-independent interface for QScriptValueIterator
|
||||
class ScriptValueIterator {
|
||||
|
|
|
@ -15,13 +15,13 @@
|
|||
#ifndef hifi_Scriptable_h
|
||||
#define hifi_Scriptable_h
|
||||
|
||||
#include <QtCore/QSharedPointer>
|
||||
#include <memory>
|
||||
|
||||
#include "ScriptContext.h"
|
||||
#include "ScriptValue.h"
|
||||
|
||||
class ScriptEngine;
|
||||
using ScriptEnginePointer = QSharedPointer<ScriptEngine>;
|
||||
using ScriptEnginePointer = std::shared_ptr<ScriptEngine>;
|
||||
|
||||
/// [ScriptInterface] Provides an engine-independent interface for QScriptable
|
||||
class Scriptable {
|
||||
|
|
|
@ -21,7 +21,7 @@ void ScriptContextQtAgent::contextPop() {
|
|||
if (_prevAgent) {
|
||||
_prevAgent->contextPop();
|
||||
}
|
||||
if (_engine->currentContext() == _currContext) {
|
||||
if (_engine->currentContext() == _currContext.get()) {
|
||||
_currContext.reset();
|
||||
if (!_contextActive && !_contextStack.empty()) {
|
||||
_currContext = _contextStack.back();
|
||||
|
@ -50,7 +50,7 @@ void ScriptContextQtAgent::functionEntry(qint64 scriptId) {
|
|||
return;
|
||||
}
|
||||
if (!_currContext) {
|
||||
_currContext = ScriptContextQtPointer(new ScriptContextQtWrapper(_engine, static_cast<QScriptEngine*>(_engine)->currentContext()));
|
||||
_currContext = std::make_shared<ScriptContextQtWrapper>(_engine, static_cast<QScriptEngine*>(_engine)->currentContext());
|
||||
}
|
||||
Scriptable::setContext(_currContext.get());
|
||||
_contextActive = true;
|
||||
|
|
|
@ -12,8 +12,9 @@
|
|||
#ifndef hifi_ScriptContextQtAgent_h
|
||||
#define hifi_ScriptContextQtAgent_h
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QSharedPointer>
|
||||
#include <QtScript/QScriptEngineAgent>
|
||||
|
||||
#include "ScriptEngineQtScript.h"
|
||||
|
@ -22,7 +23,7 @@ class QScriptContext;
|
|||
class QScriptValue;
|
||||
class ScriptContextQtWrapper;
|
||||
class ScriptEngineQtScript;
|
||||
using ScriptContextQtPointer = QSharedPointer<ScriptContextQtWrapper>;
|
||||
using ScriptContextQtPointer = std::shared_ptr<ScriptContextQtWrapper>;
|
||||
|
||||
class ScriptContextQtAgent final : public QScriptEngineAgent {
|
||||
public: // construction
|
||||
|
|
|
@ -43,16 +43,16 @@ ScriptValue ScriptContextQtWrapper::callee() const {
|
|||
}
|
||||
|
||||
ScriptEnginePointer ScriptContextQtWrapper::engine() const {
|
||||
return _engine->sharedFromThis();
|
||||
return _engine->shared_from_this();
|
||||
}
|
||||
|
||||
ScriptFunctionContextPointer ScriptContextQtWrapper::functionContext() const {
|
||||
return ScriptFunctionContextPointer(new ScriptFunctionContextQtWrapper(_context));
|
||||
return std::make_shared<ScriptFunctionContextQtWrapper>(_context);
|
||||
}
|
||||
|
||||
ScriptContextPointer ScriptContextQtWrapper::parentContext() const {
|
||||
QScriptContext* result = _context->parentContext();
|
||||
return result ? ScriptContextPointer(new ScriptContextQtWrapper(_engine, result)) : ScriptContextPointer();
|
||||
return result ? std::make_shared<ScriptContextQtWrapper>(_engine, result) : ScriptContextPointer();
|
||||
}
|
||||
|
||||
ScriptValue ScriptContextQtWrapper::thisObject() const {
|
||||
|
|
|
@ -777,7 +777,7 @@ ScriptValue ScriptEngineQtScript::newObject() {
|
|||
|
||||
ScriptProgramPointer ScriptEngineQtScript::newProgram(const QString& sourceCode, const QString& fileName) {
|
||||
QScriptProgram result(sourceCode, fileName);
|
||||
return ScriptProgramPointer(new ScriptProgramQtWrapper(this, result));
|
||||
return std::make_shared<ScriptProgramQtWrapper>(this, result);
|
||||
}
|
||||
|
||||
ScriptValue ScriptEngineQtScript::newQObject(QObject* object,
|
||||
|
@ -857,7 +857,7 @@ ScriptContext* ScriptEngineQtScript::currentContext() const {
|
|||
return nullptr;
|
||||
}
|
||||
if (!_currContext || _currContext->toQtValue() != localCtx) {
|
||||
_currContext = ScriptContextQtPointer(new ScriptContextQtWrapper(const_cast<ScriptEngineQtScript*>(this), localCtx));
|
||||
_currContext = std::make_shared<ScriptContextQtWrapper>(const_cast<ScriptEngineQtScript*>(this), localCtx);
|
||||
}
|
||||
return _currContext.get();
|
||||
}
|
||||
|
|
|
@ -16,12 +16,12 @@
|
|||
#ifndef hifi_ScriptEngineQtScript_h
|
||||
#define hifi_ScriptEngineQtScript_h
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QtCore/QByteArray>
|
||||
#include <QtCore/QEnableSharedFromThis>
|
||||
#include <QtCore/QMetaEnum>
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QPointer>
|
||||
#include <QtCore/QSharedPointer>
|
||||
#include <QtCore/QString>
|
||||
|
||||
#include <QtScript/QScriptEngine>
|
||||
|
@ -35,15 +35,15 @@ class ScriptContextQtWrapper;
|
|||
class ScriptContextQtAgent;
|
||||
class ScriptEngineQtScript;
|
||||
class ScriptManager;
|
||||
using ScriptEngineQtScriptPointer = QSharedPointer<ScriptEngineQtScript>;
|
||||
using ScriptContextQtPointer = QSharedPointer<ScriptContextQtWrapper>;
|
||||
using ScriptEngineQtScriptPointer = std::shared_ptr<ScriptEngineQtScript>;
|
||||
using ScriptContextQtPointer = std::shared_ptr<ScriptContextQtWrapper>;
|
||||
|
||||
Q_DECLARE_METATYPE(ScriptEngineQtScriptPointer);
|
||||
|
||||
/// [QtScript] Implements ScriptEngine for QtScript and translates calls for QScriptEngine
|
||||
class ScriptEngineQtScript final : public QScriptEngine,
|
||||
public ScriptEngine,
|
||||
public QEnableSharedFromThis<ScriptEngineQtScript> {
|
||||
public std::enable_shared_from_this<ScriptEngineQtScript> {
|
||||
Q_OBJECT
|
||||
|
||||
public: // construction
|
||||
|
|
|
@ -26,7 +26,7 @@ ScriptProgramQtWrapper* ScriptProgramQtWrapper::unwrap(ScriptProgramPointer val)
|
|||
|
||||
ScriptSyntaxCheckResultPointer ScriptProgramQtWrapper::checkSyntax() const {
|
||||
QScriptSyntaxCheckResult result = _engine->checkSyntax(_value.sourceCode());
|
||||
return ScriptSyntaxCheckResultPointer(new ScriptSyntaxCheckResultQtWrapper(std::move(result)));
|
||||
return std::make_shared<ScriptSyntaxCheckResultQtWrapper>(std::move(result));
|
||||
}
|
||||
|
||||
QString ScriptProgramQtWrapper::fileName() const {
|
||||
|
|
|
@ -84,11 +84,11 @@ ScriptEnginePointer ScriptValueQtWrapper::engine() const {
|
|||
if (!_engine) {
|
||||
return ScriptEnginePointer();
|
||||
}
|
||||
return _engine->sharedFromThis();
|
||||
return _engine->shared_from_this();
|
||||
}
|
||||
|
||||
ScriptValueIteratorPointer ScriptValueQtWrapper::newIterator() const {
|
||||
return ScriptValueIteratorPointer(new ScriptValueIteratorQtWrapper(_engine, _value));
|
||||
return std::make_shared<ScriptValueIteratorQtWrapper>(_engine, _value);
|
||||
}
|
||||
|
||||
ScriptValue ScriptValueQtWrapper::property(const QString& name, const ScriptValue::ResolveFlags& mode) const {
|
||||
|
|
Loading…
Reference in a new issue