From 3cc4ae644d6ad901f88c39a6ee1345dc53405b5f Mon Sep 17 00:00:00 2001 From: Giulio Camuffo Date: Fri, 29 Jul 2011 15:03:28 +0200 Subject: [PATCH] GRIM: Take the cmap from the main model component if there is no parent. Fix #309 --- engines/grim/costume.cpp | 45 ++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/engines/grim/costume.cpp b/engines/grim/costume.cpp index f50fb2e1ed8..3a0764470c8 100644 --- a/engines/grim/costume.cpp +++ b/engines/grim/costume.cpp @@ -162,6 +162,7 @@ protected: ModelNode *_hier; Graphics::Matrix4 _matrix; AnimManager *_animation; + Component *_prevComp; }; class MainModelComponent : public ModelComponent { @@ -341,15 +342,17 @@ ModelComponent::ModelComponent(Costume::Component *p, int parentID, const char * } else { _filename = filename; } - if (prevComponent) { - MainModelComponent *mmc = dynamic_cast(prevComponent); - - if (mmc) - _previousCmap = mmc->getCMap(); - } + _prevComp = prevComponent; } void ModelComponent::init() { + if (_prevComp) { + MainModelComponent *mmc = dynamic_cast(_prevComp); + + if (mmc) { + _previousCmap = mmc->getCMap(); + } + } // Skip loading if it was initialized // by the sharing MainModelComponent // constructor before @@ -919,19 +922,25 @@ void Costume::loadGRIM(TextSplitter &ts, Costume *prevCost) { // A Parent ID of "-1" indicates that the component should // use the properties of the previous costume as a base - if (parentID == -1 && prevCost) { - MainModelComponent *mmc; + if (parentID == -1) { + if (prevCost) { + MainModelComponent *mmc; - // However, only the first item can actually share the - // node hierarchy with the previous costume, so flag - // that component so it knows what to do - if (i == 0) - parentID = -2; - prevComponent = prevCost->_components[0]; - mmc = dynamic_cast(prevComponent); - // Make sure that the component is valid - if (!mmc) - prevComponent = NULL; + // However, only the first item can actually share the + // node hierarchy with the previous costume, so flag + // that component so it knows what to do + if (i == 0) + parentID = -2; + prevComponent = prevCost->_components[0]; + mmc = dynamic_cast(prevComponent); + // Make sure that the component is valid + if (!mmc) + prevComponent = NULL; + } else if (id > 0) { + // Use the MainModelComponent of this costume as prevComponent, + // so that the component can use its colormap. + prevComponent = _components[0]; + } } // Actually load the appropriate component _components[id] = loadComponent(tags[tagID], parentID < 0 ? NULL : _components[parentID], parentID, line + namePos, prevComponent);