Merge pull request #1995 from ZappoMan/scriptfixes

Fix crash on shutdown with multiple scripts and other scripting improvements
This commit is contained in:
Philip Rosedale 2014-02-13 21:28:05 -08:00
commit 04cda4c2b6
6 changed files with 46 additions and 4 deletions

View file

@ -3984,6 +3984,32 @@ void Application::saveScripts() {
settings->endArray();
}
void Application::stopAllScripts() {
// stops all current running scripts
QList<QAction*> scriptActions = Menu::getInstance()->getActiveScriptsMenu()->actions();
foreach (QAction* scriptAction, scriptActions) {
scriptAction->activate(QAction::Trigger);
qDebug() << "stopping script..." << scriptAction->text();
}
_activeScripts.clear();
}
void Application::reloadAllScripts() {
// remember all the current scripts so we can reload them
QStringList reloadList = _activeScripts;
// reloads all current running scripts
QList<QAction*> scriptActions = Menu::getInstance()->getActiveScriptsMenu()->actions();
foreach (QAction* scriptAction, scriptActions) {
scriptAction->activate(QAction::Trigger);
qDebug() << "stopping script..." << scriptAction->text();
}
_activeScripts.clear();
foreach (QString scriptName, reloadList){
qDebug() << "reloading script..." << scriptName;
loadScript(scriptName);
}
}
void Application::removeScriptName(const QString& fileNameString) {
_activeScripts.removeOne(fileNameString);
}

View file

@ -231,6 +231,8 @@ public slots:
void loadDialog();
void toggleLogDialog();
void initAvatarAndViewFrustum();
void stopAllScripts();
void reloadAllScripts();
private slots:
void timer();

View file

@ -93,6 +93,8 @@ Menu::Menu() :
addDisabledActionAndSeparator(fileMenu, "Scripts");
addActionToQMenuAndActionHash(fileMenu, MenuOption::LoadScript, Qt::CTRL | Qt::Key_O, appInstance, SLOT(loadDialog()));
addActionToQMenuAndActionHash(fileMenu, MenuOption::StopAllScripts, 0, appInstance, SLOT(stopAllScripts()));
addActionToQMenuAndActionHash(fileMenu, MenuOption::ReloadAllScripts, 0, appInstance, SLOT(reloadAllScripts()));
_activeScriptsMenu = fileMenu->addMenu("Running Scripts");
addDisabledActionAndSeparator(fileMenu, "Voxels");

View file

@ -243,8 +243,10 @@ namespace MenuOption {
const QString PasteVoxels = "Paste";
const QString PasteToVoxel = "Paste to Voxel...";
const QString PipelineWarnings = "Show Render Pipeline Warnings";
const QString PlaySlaps = "Play Slaps";
const QString Preferences = "Preferences...";
const QString RandomizeVoxelColors = "Randomize Voxel TRUE Colors";
const QString ReloadAllScripts = "Reload All Scripts";
const QString ResetAvatarSize = "Reset Avatar Size";
const QString ResetSwatchColors = "Reset Swatch Colors";
const QString RunTimingTests = "Run Timing Tests";
@ -253,11 +255,10 @@ namespace MenuOption {
const QString SettingsExport = "Export Settings";
const QString ShowAllLocalVoxels = "Show All Local Voxels";
const QString ShowTrueColors = "Show TRUE Colors";
const QString VoxelDrumming = "Voxel Drumming";
const QString PlaySlaps = "Play Slaps";
const QString SuppressShortTimings = "Suppress Timings Less than 10ms";
const QString Stars = "Stars";
const QString Stats = "Stats";
const QString StopAllScripts = "Stop All Scripts";
const QString TestPing = "Test Ping";
const QString TreeStats = "Calculate Tree Stats";
const QString TransmitterDrive = "Transmitter Drive";
@ -268,6 +269,7 @@ namespace MenuOption {
const QString VoxelAddMode = "Add Voxel Mode";
const QString VoxelColorMode = "Color Voxel Mode";
const QString VoxelDeleteMode = "Delete Voxel Mode";
const QString VoxelDrumming = "Voxel Drumming";
const QString VoxelGetColorMode = "Get Color Mode";
const QString VoxelMode = "Cycle Voxel Mode";
const QString VoxelPaintColor = "Voxel Paint Color";

View file

@ -11,13 +11,19 @@
#include "OctreeScriptingInterface.h"
OctreeScriptingInterface::OctreeScriptingInterface(OctreeEditPacketSender* packetSender,
JurisdictionListener* jurisdictionListener)
JurisdictionListener* jurisdictionListener) :
_packetSender(NULL),
_jurisdictionListener(NULL),
_managedPacketSender(false),
_managedJurisdictionListener(false),
_initialized(false)
{
setPacketSender(packetSender);
setJurisdictionListener(jurisdictionListener);
}
OctreeScriptingInterface::~OctreeScriptingInterface() {
qDebug() << "OctreeScriptingInterface::~OctreeScriptingInterface() this=" << this;
cleanupManagedObjects();
}
@ -45,6 +51,9 @@ void OctreeScriptingInterface::setJurisdictionListener(JurisdictionListener* jur
}
void OctreeScriptingInterface::init() {
if (_initialized) {
return;
}
if (_jurisdictionListener) {
_managedJurisdictionListener = false;
} else {
@ -64,5 +73,5 @@ void OctreeScriptingInterface::init() {
if (QCoreApplication::instance()) {
connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()), this, SLOT(cleanupManagedObjects()));
}
_initialized = true;
}

View file

@ -93,6 +93,7 @@ protected:
JurisdictionListener* _jurisdictionListener;
bool _managedPacketSender;
bool _managedJurisdictionListener;
bool _initialized;
};
#endif /* defined(__hifi__OctreeScriptingInterface__) */