@@ -723,52 +723,29 @@ void GenericCAO::setAttachments()
723
723
ClientActiveObject* GenericCAO::getParent ()
724
724
{
725
725
ClientActiveObject *obj = NULL ;
726
- for (std::vector<core::vector2d<int > >::const_iterator cii = m_env->attachment_list .begin (); cii != m_env->attachment_list .end (); cii++)
727
- {
728
- if (cii->X == getId ()) // This ID is our child
729
- {
730
- if (cii->Y > 0 ) // A parent ID exists for our child
731
- {
732
- if (cii->X != cii->Y ) // The parent and child ID are not the same
733
- {
734
- obj = m_env->getActiveObject (cii->Y );
735
- }
736
- }
737
- break ;
738
- }
726
+
727
+ u16 attached_id = m_env->m_attachements [getId ()];
728
+
729
+ if ((attached_id != 0 ) &&
730
+ (attached_id != getId ())) {
731
+ obj = m_env->getActiveObject (attached_id);
739
732
}
740
- if (obj)
741
- return obj;
742
- return NULL ;
733
+ return obj;
743
734
}
744
735
745
736
void GenericCAO::removeFromScene (bool permanent)
746
737
{
747
738
if (permanent) // Should be true when removing the object permanently and false when refreshing (eg: updating visuals)
748
739
{
749
- // Detach this object's children
750
- for (std::vector<core::vector2d<int > >::iterator ii = m_env->attachment_list .begin ();
751
- ii != m_env->attachment_list .end (); ii++)
752
- {
753
- if (ii->Y == getId ()) // Is a child of our object
754
- {
755
- ii->Y = 0 ;
756
- // Get the object of the child
757
- ClientActiveObject *obj = m_env->getActiveObject (ii->X );
758
- if (obj)
759
- obj->setAttachments ();
760
- }
761
- }
762
- // Delete this object from the attachments list
763
- for (std::vector<core::vector2d<int > >::iterator ii = m_env->attachment_list .begin ();
764
- ii != m_env->attachment_list .end (); ii++)
740
+ for (std::vector<u16>::iterator ci = m_children.begin ();
741
+ ci != m_children.end (); ci++)
765
742
{
766
- if (ii->X == getId ()) // Is our object
767
- {
768
- m_env->attachment_list .erase (ii);
769
- break ;
743
+ if (m_env->m_attachements [*ci] == getId ()) {
744
+ m_env->m_attachements [*ci] = 0 ;
770
745
}
771
746
}
747
+
748
+ m_env->m_attachements [getId ()] = 0 ;
772
749
}
773
750
774
751
if (m_meshnode)
@@ -1098,45 +1075,43 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
1098
1075
1099
1076
// Attachments, part 1: All attached objects must be unparented first,
1100
1077
// or Irrlicht causes a segmentation fault
1101
- for (std::vector<core::vector2d< int > > ::iterator ii = m_env-> attachment_list .begin ();
1102
- ii != m_env-> attachment_list .end (); ii++ )
1078
+ for (std::vector<u16> ::iterator ci = m_children .begin ();
1079
+ ci != m_children .end ();)
1103
1080
{
1104
- if (ii->Y == getId ()) // This is a child of our parent
1081
+ if (m_env->m_attachements [*ci] != getId ()) {
1082
+ ci = m_children.erase (ci);
1083
+ continue ;
1084
+ }
1085
+ ClientActiveObject *obj = m_env->getActiveObject (*ci);
1086
+ if (obj)
1105
1087
{
1106
- // Get the object of the child
1107
- ClientActiveObject *obj = m_env->getActiveObject (ii->X );
1108
- if (obj)
1109
- {
1110
- scene::IMeshSceneNode *m_child_meshnode
1111
- = obj->getMeshSceneNode ();
1112
- scene::IAnimatedMeshSceneNode *m_child_animated_meshnode
1113
- = obj->getAnimatedMeshSceneNode ();
1114
- scene::IBillboardSceneNode *m_child_spritenode
1115
- = obj->getSpriteSceneNode ();
1116
- if (m_child_meshnode)
1117
- m_child_meshnode->setParent (m_smgr->getRootSceneNode ());
1118
- if (m_child_animated_meshnode)
1119
- m_child_animated_meshnode->setParent (m_smgr->getRootSceneNode ());
1120
- if (m_child_spritenode)
1121
- m_child_spritenode->setParent (m_smgr->getRootSceneNode ());
1122
- }
1088
+ scene::IMeshSceneNode *m_child_meshnode
1089
+ = obj->getMeshSceneNode ();
1090
+ scene::IAnimatedMeshSceneNode *m_child_animated_meshnode
1091
+ = obj->getAnimatedMeshSceneNode ();
1092
+ scene::IBillboardSceneNode *m_child_spritenode
1093
+ = obj->getSpriteSceneNode ();
1094
+ if (m_child_meshnode)
1095
+ m_child_meshnode->setParent (m_smgr->getRootSceneNode ());
1096
+ if (m_child_animated_meshnode)
1097
+ m_child_animated_meshnode->setParent (m_smgr->getRootSceneNode ());
1098
+ if (m_child_spritenode)
1099
+ m_child_spritenode->setParent (m_smgr->getRootSceneNode ());
1123
1100
}
1101
+ ++ci;
1124
1102
}
1125
1103
1126
1104
removeFromScene (false );
1127
1105
addToScene (m_smgr, m_gamedef->tsrc (), m_irr);
1128
1106
1129
1107
// Attachments, part 2: Now that the parent has been refreshed, put its attachments back
1130
- for (std::vector<core::vector2d< int > > ::iterator ii = m_env-> attachment_list .begin ();
1131
- ii != m_env-> attachment_list .end (); ii ++)
1108
+ for (std::vector<u16> ::iterator ci = m_children .begin ();
1109
+ ci != m_children .end (); ci ++)
1132
1110
{
1133
- if (ii->Y == getId ()) // This is a child of our parent
1134
- {
1135
1111
// Get the object of the child
1136
- ClientActiveObject *obj = m_env->getActiveObject (ii-> X );
1112
+ ClientActiveObject *obj = m_env->getActiveObject (*ci );
1137
1113
if (obj)
1138
1114
obj->setAttachments ();
1139
- }
1140
1115
}
1141
1116
}
1142
1117
@@ -1803,16 +1778,8 @@ void GenericCAO::processMessage(const std::string &data)
1803
1778
updateBonePosition ();
1804
1779
}
1805
1780
else if (cmd == GENERIC_CMD_SET_ATTACHMENT) {
1806
- // If an entry already exists for this object, delete it first to avoid duplicates
1807
- for (std::vector<core::vector2d<int > >::iterator ii = m_env->attachment_list .begin (); ii != m_env->attachment_list .end (); ii++)
1808
- {
1809
- if (ii->X == getId ()) // This is the ID of our object
1810
- {
1811
- m_env->attachment_list .erase (ii);
1812
- break ;
1813
- }
1814
- }
1815
- m_env->attachment_list .push_back (core::vector2d<int >(getId (), readS16 (is)));
1781
+ m_env->m_attachements [getId ()] = readS16 (is);
1782
+ m_children.push_back (m_env->m_attachements [getId ()]);
1816
1783
m_attachment_bone = deSerializeString (is);
1817
1784
m_attachment_position = readV3F1000 (is);
1818
1785
m_attachment_rotation = readV3F1000 (is);
0 commit comments