From 568178bbb4f9257b8a95627ccb98b5b3de9e0c72 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sat, 18 Feb 2012 23:35:30 +0100 Subject: [PATCH] Some fixes for node script init/cleanup. An Errorneous script could cause a node script instance leaking, preventing the leaked inctances from unloading, and thus locking the whole file, preventing it from re-loading when relaoding the map, until the mod was exited. Also init nodes properly when cloned or changed. --- Aquaria/Path.cpp | 38 +++++++++++--------------------------- Aquaria/SceneEditor.cpp | 11 +++++++++-- 2 files changed, 20 insertions(+), 29 deletions(-) diff --git a/Aquaria/Path.cpp b/Aquaria/Path.cpp index c0e4cf4..41da549 100644 --- a/Aquaria/Path.cpp +++ b/Aquaria/Path.cpp @@ -225,6 +225,7 @@ void Path::destroy() Path::~Path() { + destroy(); } bool Path::hasScript() @@ -288,21 +289,20 @@ void Path::parseWarpNodeData(const std::string &dataString) void Path::refreshScript() { amount = 0; - content.clear(); - label.clear(); + content.clear(); + label.clear(); + + destroy(); - // HACK: clean up - /*+ dsq->game->sceneName + "_"*/ - script = 0; warpMap = warpNode = ""; toFlip = -1; stringToLower(name); - { - SimpleIStringStream is(name.c_str(), SimpleIStringStream::REUSE); - is >> label >> content >> amount; - } + { + SimpleIStringStream is(name.c_str(), SimpleIStringStream::REUSE); + is >> label >> content >> amount; + } std::string scr; if (dsq->mod.isActive()) @@ -423,30 +423,14 @@ void Path::refreshScript() std::string dummy, warpTypeStr; SimpleIStringStream is(name); is >> dummy >> warpMap >> warpTypeStr; - // warpType is just char, which does not automatically skip spaces like strings would - warpType = warpTypeStr.length() ? warpTypeStr[0] : 0; + // warpType is just char, which does not automatically skip spaces like strings would + warpType = warpTypeStr.length() ? warpTypeStr[0] : 0; if (warpMap.find("vedha")!=std::string::npos) { naijaHome = true; } - //debugLog(label + " " + warpMap + " " + warpType); - /* - std::string parse = name; - int pos = 0; - - pos = parse.find('_'); - parse = parse.substr(pos+1, parse.getLength2D()); - - pos = parse.find('_'); - warpMap = parse.substr(0, pos-1); - parse = parse.substr(pos+1, parse.getLength2D()); - - pos = parse.find('_'); - std::string - */ pathType = PATH_WARP; - } else if (label == "se") { diff --git a/Aquaria/SceneEditor.cpp b/Aquaria/SceneEditor.cpp index fc82be9..e207a3b 100644 --- a/Aquaria/SceneEditor.cpp +++ b/Aquaria/SceneEditor.cpp @@ -927,8 +927,14 @@ void SceneEditor::enterName() Path *p = getSelectedPath(); if (p) { - p->name = dsq->getUserInputString("PathName", p->name); - p->refreshScript(); + std::string newname = dsq->getUserInputString("PathName", p->name); + bool changed = newname != p->name; + p->name = newname; + if (changed) + { + p->refreshScript(); + p->init(); + } } } } @@ -3224,6 +3230,7 @@ void SceneEditor::cloneSelectedElement() dsq->game->addPath(newp); selectedIdx = dsq->game->getNumPaths()-1; + newp->init(); } }