Skip to content

Commit 14f4cd0

Browse files
committedJun 20, 2015
Small CAO improvements
-> remove the old parent as @kahrl suggested -> use indices no iterator as @kwolekr suggested
1 parent 70da8a9 commit 14f4cd0

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed
 

‎src/content_cao.cpp

+13-12
Original file line numberDiff line numberDiff line change
@@ -728,9 +728,8 @@ scene::IBillboardSceneNode* GenericCAO::getSpriteSceneNode()
728728

729729
void GenericCAO::setChildrenVisible(bool toset)
730730
{
731-
for (std::vector<u16>::iterator ci = m_children.begin();
732-
ci != m_children.end(); ci++) {
733-
GenericCAO *obj = m_env->getGenericCAO(*ci);
731+
for (std::vector<u16>::size_type i = 0; i < m_children.size(); i++) {
732+
GenericCAO *obj = m_env->getGenericCAO(m_children[i]);
734733
if (obj) {
735734
obj->setVisible(toset);
736735
}
@@ -760,11 +759,10 @@ void GenericCAO::removeFromScene(bool permanent)
760759
// Should be true when removing the object permanently and false when refreshing (eg: updating visuals)
761760
if((m_env != NULL) && (permanent))
762761
{
763-
for(std::vector<u16>::iterator ci = m_children.begin();
764-
ci != m_children.end(); ci++)
765-
{
766-
if (m_env->attachement_parent_ids[*ci] == getId()) {
767-
m_env->attachement_parent_ids[*ci] = 0;
762+
for (std::vector<u16>::size_type i = 0; i < m_children.size(); i++) {
763+
u16 ci = m_children[i];
764+
if (m_env->attachement_parent_ids[ci] == getId()) {
765+
m_env->attachement_parent_ids[ci] = 0;
768766
}
769767
}
770768

@@ -1127,11 +1125,9 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
11271125
addToScene(m_smgr, m_gamedef->tsrc(), m_irr);
11281126

11291127
// Attachments, part 2: Now that the parent has been refreshed, put its attachments back
1130-
for(std::vector<u16>::iterator ci = m_children.begin();
1131-
ci != m_children.end(); ci++)
1132-
{
1128+
for (std::vector<u16>::size_type i = 0; i < m_children.size(); i++) {
11331129
// Get the object of the child
1134-
ClientActiveObject *obj = m_env->getActiveObject(*ci);
1130+
ClientActiveObject *obj = m_env->getActiveObject(m_children[i]);
11351131
if (obj)
11361132
obj->setAttachments();
11371133
}
@@ -1670,6 +1666,11 @@ void GenericCAO::processMessage(const std::string &data)
16701666
updateBonePosition();
16711667
} else if (cmd == GENERIC_CMD_ATTACH_TO) {
16721668
u16 parentID = readS16(is);
1669+
u16 oldparent = m_env->attachement_parent_ids[getId()];
1670+
if (oldparent) {
Has a conversation. Original line has a conversation.
1671+
m_children.erase(std::remove(m_children.begin(), m_children.end(),
1672+
getId()), m_children.end());
1673+
}
16731674
m_env->attachement_parent_ids[getId()] = parentID;
16741675
GenericCAO *parentobj = m_env->getGenericCAO(parentID);
16751676

0 commit comments

Comments
 (0)
Please sign in to comment.