Started sketching the Instance struct.

This commit is contained in:
Angelo Papenhoff 2014-12-20 15:05:34 +01:00
parent 92a3db015c
commit ae682bab47
5 changed files with 56 additions and 62 deletions

View File

@ -12,62 +12,6 @@
using namespace std; 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 int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
@ -83,7 +27,7 @@ main(int argc, char *argv[])
c = Rw::Clump::streamRead(in); c = Rw::Clump::streamRead(in);
in.close(); in.close();
ofstream out("out.dff", ios::binary); ofstream out(argv[2], ios::binary);
c->streamWrite(out); c->streamWrite(out);
out.close(); out.close();

View File

@ -75,6 +75,7 @@ static void
readMesh(istream &stream, Rw::int32, void *object, int32, int32) readMesh(istream &stream, Rw::int32, void *object, int32, int32)
{ {
Geometry *geo = (Geometry*)object; Geometry *geo = (Geometry*)object;
int32 indbuf[256];
uint32 buf[3]; uint32 buf[3];
stream.read((char*)buf, 12); stream.read((char*)buf, 12);
geo->meshHeader = new MeshHeader; geo->meshHeader = new MeshHeader;
@ -93,8 +94,15 @@ readMesh(istream &stream, Rw::int32, void *object, int32, int32)
; ;
else{ else{
mesh->indices = new uint16[mesh->numIndices]; mesh->indices = new uint16[mesh->numIndices];
for(uint32 j = 0; j < mesh->numIndices; j++) uint16 *ind = mesh->indices;
mesh->indices[j] = readUInt32(stream); 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++; mesh++;
} }
@ -104,6 +112,7 @@ static void
writeMesh(ostream &stream, Rw::int32, void *object, int32, int32) writeMesh(ostream &stream, Rw::int32, void *object, int32, int32)
{ {
Geometry *geo = (Geometry*)object; Geometry *geo = (Geometry*)object;
int32 indbuf[256];
uint32 buf[3]; uint32 buf[3];
buf[0] = geo->meshHeader->flags; buf[0] = geo->meshHeader->flags;
buf[1] = geo->meshHeader->numMeshes; buf[1] = geo->meshHeader->numMeshes;
@ -119,9 +128,17 @@ writeMesh(ostream &stream, Rw::int32, void *object, int32, int32)
if(geo->geoflags & Geometry::NATIVE) if(geo->geoflags & Geometry::NATIVE)
// TODO: compressed indices in OpenGL // TODO: compressed indices in OpenGL
; ;
else else{
for(uint32 j = 0; j < mesh->numIndices; j++) uint16 *ind = mesh->indices;
writeUInt32(mesh->indices[j], stream); 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++; mesh++;
} }
} }

7
rw.h
View File

@ -78,6 +78,11 @@ struct MorphTarget
float32 *normals; float32 *normals;
}; };
struct InstanceDataHeader
{
uint32 platform;
};
struct Geometry : PluginBase<Geometry>, Object struct Geometry : PluginBase<Geometry>, Object
{ {
uint32 geoflags; uint32 geoflags;
@ -97,6 +102,8 @@ struct Geometry : PluginBase<Geometry>, Object
MeshHeader *meshHeader; MeshHeader *meshHeader;
InstanceDataHeader *instData;
int32 refCount; int32 refCount;
Geometry(int32 numVerts, int32 numTris, uint32 flags); Geometry(int32 numVerts, int32 numTris, uint32 flags);

View File

@ -27,6 +27,15 @@ int32 readInt32(std::istream &rw);
uint32 readUInt32(std::istream &rw); uint32 readUInt32(std::istream &rw);
float32 readFloat32(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 enum PluginID
{ {
// Core // Core

17
rwps2.h Normal file
View File

@ -0,0 +1,17 @@
namespace Rw {
struct PS2InstanceData
{
uint32 noRefChain;
uint32 dataSize;
uint8 *data;
Material *material;
}
struct PS2InstanceDataHeader : InstanceDataHeader
{
uint32 numMeshes;
PS2InstanceData *instanceMeshes;
};
}