From ae682bab47686d6266a9ab8c9f7b1c89d43660b8 Mon Sep 17 00:00:00 2001 From: Angelo Papenhoff Date: Sat, 20 Dec 2014 15:05:34 +0100 Subject: [PATCH] Started sketching the Instance struct. --- main.cpp | 58 +---------------------------------------------------- plugins.cpp | 27 ++++++++++++++++++++----- rw.h | 7 +++++++ rwbase.h | 9 +++++++++ rwps2.h | 17 ++++++++++++++++ 5 files changed, 56 insertions(+), 62 deletions(-) create mode 100644 rwps2.h diff --git a/main.cpp b/main.cpp index e8e3a82..05a24d1 100644 --- a/main.cpp +++ b/main.cpp @@ -12,62 +12,6 @@ using namespace std; -// -// X - Plugin of Clump -// -struct X -{ - Rw::int32 a; - Rw::int32 b; -}; - -void* -ctorX(void *object, int offset, int) -{ - X *x = PLUGINOFFSET(X, object, offset); - x->a = 123; - x->b = 789; - return object; -} - -void* -dtorX(void *object, int, int) -{ - return object; -} - -void* -cctorX(void *dst, void *src, int offset, int) -{ - X *srcx = PLUGINOFFSET(X, src, offset); - X *dstx = PLUGINOFFSET(X, dst, offset); - dstx->a = srcx->a; - dstx->b = srcx->b; - return dst; -} - -Rw::int32 -getSizeX(void *, int, int) -{ - return 8; -} - -void -writeX(ostream &stream, Rw::int32, void *object, int offset, int) -{ - X *x = PLUGINOFFSET(X, object, offset); - Rw::writeInt32(x->a, stream); - Rw::writeInt32(x->b, stream); -} - -void -readX(istream &stream, Rw::int32, void *object, int offset, int) -{ - X *x = PLUGINOFFSET(X, object, offset); - x->a = Rw::readInt32(stream); - x->b = Rw::readInt32(stream); -} - int main(int argc, char *argv[]) { @@ -83,7 +27,7 @@ main(int argc, char *argv[]) c = Rw::Clump::streamRead(in); in.close(); - ofstream out("out.dff", ios::binary); + ofstream out(argv[2], ios::binary); c->streamWrite(out); out.close(); diff --git a/plugins.cpp b/plugins.cpp index 8b13a2b..8c5a246 100644 --- a/plugins.cpp +++ b/plugins.cpp @@ -75,6 +75,7 @@ static void readMesh(istream &stream, Rw::int32, void *object, int32, int32) { Geometry *geo = (Geometry*)object; + int32 indbuf[256]; uint32 buf[3]; stream.read((char*)buf, 12); geo->meshHeader = new MeshHeader; @@ -93,8 +94,15 @@ readMesh(istream &stream, Rw::int32, void *object, int32, int32) ; else{ mesh->indices = new uint16[mesh->numIndices]; - for(uint32 j = 0; j < mesh->numIndices; j++) - mesh->indices[j] = readUInt32(stream); + uint16 *ind = mesh->indices; + int32 numIndices = mesh->numIndices; + for(; numIndices > 0; numIndices -= 256){ + int32 n = numIndices < 256 ? numIndices : 256; + stream.read((char*)indbuf, n*4); + for(int32 j = 0; j < n; j++) + ind[j] = indbuf[j]; + ind += n; + } } mesh++; } @@ -104,6 +112,7 @@ static void writeMesh(ostream &stream, Rw::int32, void *object, int32, int32) { Geometry *geo = (Geometry*)object; + int32 indbuf[256]; uint32 buf[3]; buf[0] = geo->meshHeader->flags; buf[1] = geo->meshHeader->numMeshes; @@ -119,9 +128,17 @@ writeMesh(ostream &stream, Rw::int32, void *object, int32, int32) if(geo->geoflags & Geometry::NATIVE) // TODO: compressed indices in OpenGL ; - else - for(uint32 j = 0; j < mesh->numIndices; j++) - writeUInt32(mesh->indices[j], stream); + else{ + uint16 *ind = mesh->indices; + int32 numIndices = mesh->numIndices; + for(; numIndices > 0; numIndices -= 256){ + int32 n = numIndices < 256 ? numIndices : 256; + for(int32 j = 0; j < n; j++) + indbuf[j] = ind[j]; + stream.write((char*)indbuf, n*4); + ind += n; + } + } mesh++; } } diff --git a/rw.h b/rw.h index 7569956..4c575a5 100644 --- a/rw.h +++ b/rw.h @@ -78,6 +78,11 @@ struct MorphTarget float32 *normals; }; +struct InstanceDataHeader +{ + uint32 platform; +}; + struct Geometry : PluginBase, Object { uint32 geoflags; @@ -97,6 +102,8 @@ struct Geometry : PluginBase, Object MeshHeader *meshHeader; + InstanceDataHeader *instData; + int32 refCount; Geometry(int32 numVerts, int32 numTris, uint32 flags); diff --git a/rwbase.h b/rwbase.h index 8ca59f7..6928905 100644 --- a/rwbase.h +++ b/rwbase.h @@ -27,6 +27,15 @@ int32 readInt32(std::istream &rw); uint32 readUInt32(std::istream &rw); float32 readFloat32(std::istream &rw); +enum Platform +{ + PLATFORM_OGL = 2, + PLATFORM_PS2 = 4, + PLATFORM_XBOX = 5, + PLATFORM_D3D8 = 8, + PLATFORM_D3D9 = 9 +}; + enum PluginID { // Core diff --git a/rwps2.h b/rwps2.h new file mode 100644 index 0000000..0ba80e1 --- /dev/null +++ b/rwps2.h @@ -0,0 +1,17 @@ +namespace Rw { + +struct PS2InstanceData +{ + uint32 noRefChain; + uint32 dataSize; + uint8 *data; + Material *material; +} + +struct PS2InstanceDataHeader : InstanceDataHeader +{ + uint32 numMeshes; + PS2InstanceData *instanceMeshes; +}; + +}