Defer re-init'ing the shape when TSShapeConstructor is loading a shape

This commit is contained in:
James Urquhart 2016-09-03 10:41:25 +01:00
parent 0e717ea707
commit a46779fad6
5 changed files with 143 additions and 71 deletions

View file

@ -435,6 +435,9 @@ bool TSShape::addNode(const String& name, const String& parentName, const Point3
}
}
// Need to make everything editable since node indexes etc will change
makeEditable();
// Insert node at the end of the subshape
S32 subShapeIndex = (parentIndex >= 0) ? getSubShapeForNode(parentIndex) : 0;
S32 nodeIndex = subShapeNumNodes[subShapeIndex];
@ -493,8 +496,7 @@ bool TSShape::addNode(const String& name, const String& parentName, const Point3
}
}
// Re-initialise the shape
init();
initObjects();
return true;
}
@ -548,6 +550,9 @@ bool TSShape::removeNode(const String& name)
((nodeParentIndex >= 0) ? getName(nodes[nodeParentIndex].nameIndex).c_str() : "null"));
}
// Need to make everything editable since node indexes etc will change
makeEditable();
// Update animation sequences
for (S32 iSeq = 0; iSeq < sequences.size(); iSeq++)
{
@ -626,8 +631,7 @@ bool TSShape::removeNode(const String& name)
// Remove the sequence name if it is no longer in use
removeName(name);
// Re-initialise the shape
init();
initObjects();
return true;
}
@ -855,6 +859,9 @@ bool TSShape::removeObject(const String& name)
return false;
}
// Need to make everything editable since node indexes etc will change
makeEditable();
// Destroy all meshes in the object
TSShape::Object& obj = objects[objIndex];
while ( obj.numMeshes )
@ -893,14 +900,7 @@ bool TSShape::removeObject(const String& name)
// Update smallest visible detail
updateSmallestVisibleDL();
// Ensure shape is dirty
if (meshes[0])
{
meshes[0]->makeEditable();
}
// Re-initialise the shape
init();
initObjects();
return true;
}
@ -961,6 +961,9 @@ bool TSShape::addMesh(TSMesh* mesh, const String& meshName)
// Ensure mesh is in editable state
mesh->makeEditable();
// Need to make everything editable since node indexes etc will change
makeEditable();
// Determine the object name and detail size from the mesh name
S32 detailSize = 999;
String objName(String::GetTrailingNumber(meshName, detailSize));
@ -1049,8 +1052,7 @@ bool TSShape::addMesh(TSMesh* mesh, const String& meshName)
}
}
// Re-initialise the shape
init();
initObjects();
return true;
}
@ -1140,6 +1142,9 @@ bool TSShape::setMeshSize(const String& meshName, S32 size)
return false;
}
// Need to make everything editable since node indexes etc will change
makeEditable();
// Remove the mesh from the object, but don't destroy it
TSShape::Object& obj = objects[objIndex];
TSMesh* mesh = meshes[obj.startMeshIndex + meshIndex];
@ -1151,8 +1156,7 @@ bool TSShape::setMeshSize(const String& meshName, S32 size)
// Update smallest visible detail
updateSmallestVisibleDL();
// Re-initialise the shape
init();
initObjects();
return true;
}
@ -1167,6 +1171,9 @@ bool TSShape::removeMesh(const String& meshName)
return false;
}
// Need to make everything editable since node indexes etc will change
makeEditable();
// Destroy and remove the mesh
TSShape::Object& obj = objects[objIndex];
destructInPlace(meshes[obj.startMeshIndex + meshIndex]);
@ -1179,8 +1186,7 @@ bool TSShape::removeMesh(const String& meshName)
// Update smallest visible detail
updateSmallestVisibleDL();
// Re-initialise the shape
init();
initObjects();
return true;
}
@ -1294,8 +1300,8 @@ S32 TSShape::setDetailSize(S32 oldSize, S32 newSize)
// Update smallest visible detail
updateSmallestVisibleDL();
// Re-initialise the shape
init();
// Nothing major, just reint object lists
initObjects();
return newIndex;
}
@ -1310,6 +1316,9 @@ bool TSShape::removeDetail( S32 size )
return false;
}
// Need to make everything editable since node indexes etc will change
makeEditable();
// Destroy and remove each mesh in the detail level
for ( S32 objIndex = objects.size()-1; objIndex >= 0; objIndex-- )
{
@ -1339,17 +1348,10 @@ bool TSShape::removeDetail( S32 size )
billboardDetails.erase( dl );
}
// Ensure shape is dirty
if (meshes[0])
{
meshes[0]->makeEditable();
}
// Update smallest visible detail
updateSmallestVisibleDL();
// Re-initialise the shape
init();
initObjects();
return true;
}
@ -2115,7 +2117,7 @@ bool TSShape::setSequenceGroundSpeed(const String& seqName, const Point3F& trans
// Fixup ground frame indices
seq.numGroundFrames += frameAdjust;
for (S32 i = seqIndex+1; i < sequences.size(); i++)
for (S32 i = seqIndex + 1; i < sequences.size(); i++)
sequences[i].firstGroundFrame += frameAdjust;
// Generate the ground-frames
@ -2140,3 +2142,25 @@ bool TSShape::setSequenceGroundSpeed(const String& seqName, const Point3F& trans
return true;
}
void TSShape::makeEditable()
{
mNeedReinit = true;
if (mShapeVertexData.base == NULL)
return;
for (U32 i = 0; i < meshes.size(); i++)
{
if (meshes[i])
{
meshes[i]->makeEditable();
}
}
mShapeVertexData.set(NULL, 0);
}
bool TSShape::needsReinit()
{
return mVertexSize == 0 || mShapeVertexData.base == NULL || mNeedReinit;
}