Help me with TSShapeAlloc, please?
by Tony Richards · in Torque Game Engine Advanced · 08/12/2005 (12:16 am) · 4 replies
I'm trying to use it in a way that it's not meant to be used, and maybe I need to try a completely different approach or something, and I'm willing to do that, but I'm at my wits end as to the correct approach.
I have a series of vertices I'd like to insert into a TSShape. I figured the best way, since it has a TSMesh, was to make one of those. But, digging in the code, I find this TSShapeAlloc. I'm sure it has something to do with making serialization / deserialization go faster, but also clumping data together to facilitate cache hits... ok, this is a good thing. But... how do you use it correctly? I thought I understood the documentation and the examples... here's what I have so far, but I'm getting a crash:
At the crash point, the call stack is this:
TSShapeAlloc::get32()
TSMesh::assemble(skip = true)
TSMesh::assembleMesh(meshType = 0, skip = true)
TSShapeAlloc is corrupted at this point and the nice little buffers that I set with setRead() are pointing in lala land.
Any idea what I'm doing wrong? Or better yet... this looks really hackish to me... what would be a better way of doing it?
I have a series of vertices I'd like to insert into a TSShape. I figured the best way, since it has a TSMesh, was to make one of those. But, digging in the code, I find this TSShapeAlloc. I'm sure it has something to do with making serialization / deserialization go faster, but also clumping data together to facilitate cache hits... ok, this is a good thing. But... how do you use it correctly? I thought I understood the documentation and the examples... here's what I have so far, but I'm getting a crash:
[i]// ... In a function named TSShape::readMDL(Stream* s); ...[/i]
[i]// Assume pVerts[] is a list of vertices, and I copy it into mesh.verts[/i]
Point3F* pVertAddress = new Point3F[pNode->m_usVertexCount];
mesh.verts.set(pVertAddress, pNode->m_usVertexCount);
for(UINT16 x = 0; x < pNode->m_usVertexCount; x++)
{
Point3F& vert = mesh.verts[x];
vert.x = pVerts[x].m_x;
vert.y = pVerts[x].m_y;
vert.z = pVerts[x].m_z;
}
// Now the nastiness starts.
TSShape::alloc.setWrite();
mesh.disassemble();
// Get the buffers and their sizes
S32 bufferSize32 = TSShape::alloc.getBufferSize32();
S32* buffer32 = new S32[bufferSize32];
memcpy(buffer32, TSShape::alloc.getBuffer32(), bufferSize32 * 4);
S32 bufferSize16 = TSShape::alloc.getBufferSize16();
S16* buffer16 = new S16[bufferSize16];
memcpy(buffer16, TSShape::alloc.getBuffer16(), bufferSize16 * 2);
S32 bufferSize8 = TSShape::alloc.getBufferSize8();
S8* buffer8 = new S8[bufferSize8];
memcpy(buffer8, TSShape::alloc.getBuffer8(), bufferSize8);
// Now turn around and do it the other way.
TSShape::alloc.setRead(buffer32, buffer16, buffer8, true);
alloc.setSkipMode(true);
[b]TSMesh::assembleMesh(TSMesh::StandardMeshType, true); <---- crashes here[/b]
S32 buffSize = TSShape::alloc.getSize();
TSShape::alloc.doAlloc();
mMemoryBlock = TSShape::alloc.getBuffer();
TSMesh* pMesh = TSMesh::assembleMesh(TSMesh::StandardMeshType, false);
meshes.set(pMesh, 1);
delete[] buffer32;
delete[] buffer16;
delete[] buffer8;
}
break;At the crash point, the call stack is this:
TSShapeAlloc::get32()
TSMesh::assemble(skip = true)
TSMesh::assembleMesh(meshType = 0, skip = true)
TSShapeAlloc is corrupted at this point and the nice little buffers that I set with setRead() are pointing in lala land.
Any idea what I'm doing wrong? Or better yet... this looks really hackish to me... what would be a better way of doing it?
About the author
I am the founder of IndieZen.org, a website dedicated to the Indie 2.0 Revolution where a number of Indie game development studios and individuals collaborate and share a suite of custom built open source game development tools and middleware.
#2
08/13/2005 (9:17 pm)
Yeah, using the DTS generation SDKs is a very good idea.
#3
Not sure if that's the way you would've done it, but the 3space classes were complicated enough without having to make a way to load different model types.
Also, I have plans of supporting procedural meshes (this would be like particles and other special effects) and my addition of a base GenericMesh will facilitate this.
08/15/2005 (8:35 am)
Thanks... I wound up going a different route. I'm loading MDL models natively in TSE and I created a whole new set of classes (MDLMesh, MDLShape, MDLShapeInstance, MDLShapeBase, MDLShapeBaseData). In the near future I'll create a GenericMesh, GenericShape, etc and derive MDLMesh, DTSMesh etc. Then ShapeBase and ShapeBaseData and other things that rely on TSMesh can use the abstract class instead.Not sure if that's the way you would've done it, but the 3space classes were complicated enough without having to make a way to load different model types.
Also, I have plans of supporting procedural meshes (this would be like particles and other special effects) and my addition of a base GenericMesh will facilitate this.
#4
08/15/2005 (10:59 am)
That's a pretty good idea. I'd love to take a look at your code when you get that implemented; it might be a good modification for TGE at some point.
Torque 3D Owner Phil Carlisle