Added destructor code for native data.

This commit is contained in:
Angelo Papenhoff 2014-12-20 20:18:41 +01:00
parent dfdb90369e
commit f173620763
4 changed files with 32 additions and 4 deletions

View File

@ -19,8 +19,8 @@ main(int argc, char *argv[])
// Rw::Build = 0;
registerNodeNamePlugin();
registerMeshPlugin();
registerNativeDataPlugin();
registerMeshPlugin();
Rw::Clump *c;
ifstream in(argv[1], ios::binary);

View File

@ -183,6 +183,17 @@ registerMeshPlugin(void)
// Native Data
static void*
destroyNativeData(void *object, int32 offset, int32 size)
{
Geometry *geometry = (Geometry*)object;
if(geometry->instData == NULL)
return object;
if(geometry->instData->platform == PLATFORM_PS2)
return DestroyNativeDataPS2(object, offset, size);
return object;
}
static void
readNativeData(istream &stream, int32 len, void *object, int32 o, int32 s)
{
@ -236,7 +247,7 @@ getSizeNativeData(void *object, int32 offset, int32 size)
void
registerNativeDataPlugin(void)
{
Rw::Geometry::registerPlugin(0, 0x510, NULL, NULL, NULL);
Rw::Geometry::registerPlugin(0, 0x510, NULL, destroyNativeData, NULL);
Rw::Geometry::registerPluginStream(0x510, (StreamRead)readNativeData,
(StreamWrite)writeNativeData,
(StreamGetSize)getSizeNativeData);

20
ps2.cpp
View File

@ -15,8 +15,22 @@ using namespace std;
namespace Rw {
void*
DestroyNativeDataPS2(void *object, int32, int32)
{
Geometry *geometry = (Geometry*)object;
assert(geometry->instData->platform == PLATFORM_PS2);
PS2InstanceDataHeader *header =
(PS2InstanceDataHeader*)geometry->instData;
for(uint32 i = 0; i < header->numMeshes; i++)
delete[] header->instanceMeshes[i].data;
delete[] header->instanceMeshes;
delete header;
return object;
}
void
ReadNativeDataPS2(istream &stream, int32 len, void *object, int32, int32)
ReadNativeDataPS2(istream &stream, int32, void *object, int32, int32)
{
Geometry *geometry = (Geometry*)object;
assert(FindChunk(stream, ID_STRUCT, NULL, NULL));
@ -43,7 +57,8 @@ WriteNativeDataPS2(ostream &stream, int32 len, void *object, int32, int32)
{
Geometry *geometry = (Geometry*)object;
WriteChunkHeader(stream, ID_STRUCT, len-12);
writeUInt32(4, stream);
assert(geometry->instData->platform == PLATFORM_PS2);
writeUInt32(PLATFORM_PS2, stream);
assert(geometry->instData != NULL);
PS2InstanceDataHeader *header =
(PS2InstanceDataHeader*)geometry->instData;
@ -62,6 +77,7 @@ GetSizeNativeDataPS2(void *object, int32, int32)
{
Geometry *geometry = (Geometry*)object;
int32 size = 16;
assert(geometry->instData->platform == PLATFORM_PS2);
assert(geometry->instData != NULL);
PS2InstanceDataHeader *header =
(PS2InstanceDataHeader*)geometry->instData;

View File

@ -14,6 +14,7 @@ struct PS2InstanceDataHeader : InstanceDataHeader
PS2InstanceData *instanceMeshes;
};
void *DestroyNativeDataPS2(void *object, int32, int32);
void ReadNativeDataPS2(std::istream &stream, int32 len, void *object, int32, int32);
void WriteNativeDataPS2(std::ostream &stream, int32 len, void *object, int32, int32);
int32 GetSizeNativeDataPS2(void *object, int32, int32);