mirror of https://github.com/aap/librw.git
Started sketching the Instance struct.
This commit is contained in:
parent
92a3db015c
commit
ae682bab47
58
main.cpp
58
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();
|
||||
|
||||
|
|
27
plugins.cpp
27
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++;
|
||||
}
|
||||
}
|
||||
|
|
7
rw.h
7
rw.h
|
@ -78,6 +78,11 @@ struct MorphTarget
|
|||
float32 *normals;
|
||||
};
|
||||
|
||||
struct InstanceDataHeader
|
||||
{
|
||||
uint32 platform;
|
||||
};
|
||||
|
||||
struct Geometry : PluginBase<Geometry>, Object
|
||||
{
|
||||
uint32 geoflags;
|
||||
|
@ -97,6 +102,8 @@ struct Geometry : PluginBase<Geometry>, Object
|
|||
|
||||
MeshHeader *meshHeader;
|
||||
|
||||
InstanceDataHeader *instData;
|
||||
|
||||
int32 refCount;
|
||||
|
||||
Geometry(int32 numVerts, int32 numTris, uint32 flags);
|
||||
|
|
9
rwbase.h
9
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
|
||||
|
|
Loading…
Reference in New Issue