diff --git a/src/hanim.cpp b/src/hanim.cpp index d576c36..2eab62b 100644 --- a/src/hanim.cpp +++ b/src/hanim.cpp @@ -78,11 +78,23 @@ findById(Frame *f, int32 id) return findById(f->child, id); } +static Frame* +findUnattachedById(HAnimHierarchy *hier, Frame *f, int32 id) +{ + if(f == nil) return nil; + HAnimData *hanim = HAnimData::get(f); + if(hanim->id >= 0 && hanim->id == id && hier->getIndex(f) == -1) return f; + Frame *ff = findUnattachedById(hier, f->next, id); + if(ff) return ff; + return findUnattachedById(hier, f->child, id); +} + void HAnimHierarchy::attachByIndex(int32 idx) { int32 id = this->nodeInfo[idx].id; - Frame *f = findById(this->parentFrame, id); +// Frame *f = findById(this->parentFrame, id); + Frame *f = findUnattachedById(this, this->parentFrame, id); this->nodeInfo[idx].frame = f; } @@ -102,6 +114,15 @@ HAnimHierarchy::getIndex(int32 id) return -1; } +int32 +HAnimHierarchy::getIndex(Frame *f) +{ + for(int32 i = 0; i < this->numNodes; i++) + if(this->nodeInfo[i].frame == f) + return i; + return -1; +} + HAnimHierarchy* HAnimHierarchy::get(Frame *f) { diff --git a/src/rwplugins.h b/src/rwplugins.h index 86075e1..440d94f 100755 --- a/src/rwplugins.h +++ b/src/rwplugins.h @@ -45,6 +45,7 @@ struct HAnimHierarchy void attachByIndex(int32 id); void attach(void); int32 getIndex(int32 id); + int32 getIndex(Frame *f); void updateMatrices(void); static HAnimHierarchy *get(Frame *f);