DIRECTOR: XOBJ: Allow multiple SpaceMgr::m_parseText calls

SpaceMgr::m_parseText can be called multiple times, and assume the context
from the previous call exists. For example, ml.dir in The Dark Eye will
call it twice; the first time with a full hierarchy starting with a
SPACECOLLECTION, the second time with a hierarchy starting with a SPACE
and assuming _curSpaceCollection was set by the previous call.

We should be able to reuse the object's global "_cur" values for this,
as the game will override them soon after loading the model with a
SpaceMgr::m_setCurData call.

Fixes loading the scene graph data in The Dark Eye.
This commit is contained in:
Scott Percival 2023-03-02 00:45:38 +08:00 committed by Eugene Sandulenko
parent debb6425d4
commit 6db29a5f23

View File

@ -225,10 +225,15 @@ void SpaceMgr::m_parseText(int nargs) {
SpaceMgrXObject *me = static_cast<SpaceMgrXObject *>(g_lingo->_state->me.u.obj);
Common::String result = *text.u.s;
Common::String curSpaceCollection;
Common::String curSpace;
Common::String curNode;
Common::String curView;
if (debugLevelSet(5)) {
Common::String format = result;
for (int i = 0; i < (int)format.size(); i++) {
if (format[i] == '\r')
format.replace(i, 1, "\n");
}
debugC(5, kDebugXObj, "SpaceMgr::m_parseText:\n%s", format.c_str());
}
Common::StringTokenizer instructions = Common::StringTokenizer(result, "\r");
while (!instructions.empty()) {
@ -236,45 +241,45 @@ void SpaceMgr::m_parseText(int nargs) {
Common::StringTokenizer instruction = Common::StringTokenizer(instructionBody, " ");
Common::String type = instruction.nextToken();
if (type == "SPACECOLLECTION") {
curSpaceCollection = instruction.nextToken();
curSpace = "";
curNode = "";
curView = "";
if (!(me->_spaceCollections.contains(curSpaceCollection) && me->_checkForDups)) {
me->_spaceCollections[curSpaceCollection] = SpaceCollection();
me->_curSpaceCollection = instruction.nextToken();
me->_curSpace = "";
me->_curNode = "";
me->_curView = "";
if (!(me->_spaceCollections.contains(me->_curSpaceCollection) && me->_checkForDups)) {
me->_spaceCollections[me->_curSpaceCollection] = SpaceCollection();
}
} else if (type == "SPACE") {
curSpace = instruction.nextToken();
curNode = "";
curView = "";
SpaceCollection &sc = me->_spaceCollections.getVal(curSpaceCollection);
if (!(sc.spaces.contains(curSpaceCollection) && me->_checkForDups)) {
sc.spaces[curSpace] = Space();
me->_curSpace = instruction.nextToken();
me->_curNode = "";
me->_curView = "";
SpaceCollection &sc = me->_spaceCollections.getVal(me->_curSpaceCollection);
if (!(sc.spaces.contains(me->_curSpaceCollection) && me->_checkForDups)) {
sc.spaces[me->_curSpace] = Space();
}
} else if (type == "NODE") {
curNode = instruction.nextToken();
curView = "";
SpaceCollection &sc = me->_spaceCollections.getVal(curSpaceCollection);
Space &s = sc.spaces.getVal(curSpace);
if (!(s.nodes.contains(curNode) && me->_checkForDups)) {
s.nodes[curNode] = Node();
me->_curNode = instruction.nextToken();
me->_curView = "";
SpaceCollection &sc = me->_spaceCollections.getVal(me->_curSpaceCollection);
Space &s = sc.spaces.getVal(me->_curSpace);
if (!(s.nodes.contains(me->_curNode) && me->_checkForDups)) {
s.nodes[me->_curNode] = Node();
}
} else if (type == "VIEW") {
curView = instruction.nextToken();
SpaceCollection &sc = me->_spaceCollections.getVal(curSpaceCollection);
Space &s = sc.spaces.getVal(curSpace);
Node &n = s.nodes.getVal(curNode);
if (!(n.views.contains(curView) && me->_checkForDups)) {
n.views[curView] = View();
n.views[curView].payload = instruction.nextToken();
me->_curView = instruction.nextToken();
SpaceCollection &sc = me->_spaceCollections.getVal(me->_curSpaceCollection);
Space &s = sc.spaces.getVal(me->_curSpace);
Node &n = s.nodes.getVal(me->_curNode);
if (!(n.views.contains(me->_curView) && me->_checkForDups)) {
n.views[me->_curView] = View();
n.views[me->_curView].payload = instruction.nextToken();
}
} else if (type == "LLINK") {
Common::String target = instruction.nextToken();
Common::String payload = instruction.nextToken();
SpaceCollection &sc = me->_spaceCollections.getVal(curSpaceCollection);
Space &s = sc.spaces.getVal(curSpace);
Node &n = s.nodes.getVal(curNode);
View &v = n.views.getVal(curView);
SpaceCollection &sc = me->_spaceCollections.getVal(me->_curSpaceCollection);
Space &s = sc.spaces.getVal(me->_curSpace);
Node &n = s.nodes.getVal(me->_curNode);
View &v = n.views.getVal(me->_curView);
if (!(v.llinks.contains(target) && me->_checkForDups)) {
v.llinks[target] = LLink();
v.llinks[target].payload = payload;
@ -284,15 +289,6 @@ void SpaceMgr::m_parseText(int nargs) {
}
}
if (debugLevelSet(5)) {
Common::String format = result;
for (int i = 0; i < (int)format.size(); i++) {
if (format[i] == '\r')
format.replace(i, 1, "\n");
}
debugC(5, kDebugXObj, "SpaceMgr::m_parseText: %s", format.c_str());
}
g_lingo->push(Datum(0));
}