diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..70691e6 --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ +SRCDIR=src +BUILDDIR=build +SRC := $(patsubst %.cpp,$(SRCDIR)/%.cpp, rwbase.cpp clump.cpp\ + geometry.cpp plugins.cpp ps2.cpp\ + ogl.cpp) +OBJ := $(patsubst $(SRCDIR)/%.cpp,$(BUILDDIR)/%.o,$(SRC)) +CFLAGS=-Wall -Wextra -g #-Wno-parentheses #-Wconversion + +librw.a: $(OBJ) + ar scr $@ $(OBJ) + +$(BUILDDIR)/%.o: $(SRCDIR)/%.cpp + $(CXX) $(CFLAGS) -c $< -o $@ + +$(BUILDDIR)/%.d: $(SRCDIR)/%.cpp + $(CXX) -MM -MT '$(patsubst $(SRCDIR)/%.cpp,$(BUILDDIR)/%.o,$<)' $(CFLAGS) $< > $@ + +-include $(DEP) diff --git a/main.cpp b/dffwrite.cpp similarity index 92% rename from main.cpp rename to dffwrite.cpp index c3fffe1..091b0ce 100644 --- a/main.cpp +++ b/dffwrite.cpp @@ -6,8 +6,6 @@ #include #include -#include "rwbase.h" -#include "rwplugin.h" #include "rw.h" using namespace std; diff --git a/rw.h b/rw.h index ca025e9..69f96b9 100644 --- a/rw.h +++ b/rw.h @@ -1,213 +1,5 @@ -namespace Rw { - -struct Object -{ - uint8 type; - uint8 subType; - uint8 flags; - void *parent; -}; - -// TODO: raster, link into texdict -struct Texture : PluginBase -{ - char name[32]; - char mask[32]; - uint32 filterAddressing; - int32 refCount; - - Texture(void); - ~Texture(void); - void decRef(void); - static Texture *streamRead(std::istream &stream); - bool streamWrite(std::ostream &stream); - uint32 streamGetSize(void); - - enum FilterMode { - NEAREST = 1, - LINEAR, - MIPNEAREST, - MIPLINEAR, - LINEARMIPNEAREST, - LINEARMIPLINEAR - }; - enum Addressing { - WRAP = 1, - MIRROR, - CLAMP, - BORDER - }; -}; - -struct Material : PluginBase -{ - Texture *texture; - uint8 color[4]; - float32 surfaceProps[3]; - int32 refCount; - - Material(void); - Material(Material *m); - void decRef(void); - ~Material(void); - static Material *streamRead(std::istream &stream); - bool streamWrite(std::ostream &stream); - uint32 streamGetSize(void); -}; - -struct Mesh -{ - uint16 *indices; - uint32 numIndices; - Material *material; -}; - -struct MeshHeader -{ - uint32 flags; - uint16 numMeshes; - // RW has uint16 serialNum here - uint32 totalIndices; - Mesh *mesh; // RW has a byte offset here -}; - -struct MorphTarget -{ - float32 boundingSphere[4]; - float32 *vertices; - float32 *normals; -}; - -struct InstanceDataHeader -{ - uint32 platform; -}; - -struct Geometry : PluginBase, Object -{ - uint32 geoflags; - int32 numTriangles; - int32 numVertices; - int32 numMorphTargets; - int32 numTexCoordSets; - - uint16 *triangles; - uint8 *colors; - float32 *texCoords[8]; - - MorphTarget *morphTargets; - - int32 numMaterials; - Material **materialList; - - MeshHeader *meshHeader; - - InstanceDataHeader *instData; - - int32 refCount; - - Geometry(int32 numVerts, int32 numTris, uint32 flags); - void decRef(void); - ~Geometry(void); - static Geometry *streamRead(std::istream &stream); - bool streamWrite(std::ostream &stream); - uint32 streamGetSize(void); - void addMorphTargets(int32 n); - - enum Flags - { - TRISTRIP = 0x01, - POSITIONS = 0x02, - TEXTURED = 0x04, - PRELIT = 0x08, - NORMALS = 0x10, - LIGHT = 0x20, - MODULATE = 0x40, - TEXTURED2 = 0x80, - NATIVE = 0x01000000, - NATIVEINSTANCE = 0x02000000 - }; -}; - -struct Frame : PluginBase, Object -{ - typedef Frame *(*Callback)(Frame *f, void *data); - float32 matrix[16]; - float32 ltm[16]; - - Frame *child; - Frame *next; - Frame *root; - - // temporary - int32 matflag; - - Frame(void); - Frame(Frame *f); - ~Frame(void); - Frame *addChild(Frame *f); - Frame *removeChild(void); - Frame *forAllChildren(Callback cb, void *data); - int32 count(void); -}; - -struct Clump; - -struct Light : PluginBase, Object -{ - Frame *frame; - float32 radius; - float32 color[4]; - float32 minusCosAngle; - Clump *clump; - - Light(void); - Light(Light *l); - ~Light(void); - static Light *streamRead(std::istream &stream); - bool streamWrite(std::ostream &stream); - uint32 streamGetSize(void); -}; - -struct Atomic : PluginBase, Object -{ - Frame *frame; - Geometry *geometry; - Clump *clump; - - Atomic(void); - Atomic(Atomic *a); - ~Atomic(void); - static Atomic *streamReadClump(std::istream &stream, - Frame **frameList, Geometry **geometryList); - bool streamWriteClump(std::ostream &stream, - Frame **frameList, int32 numFrames); - uint32 streamGetSize(void); -}; - -struct Clump : PluginBase, Object -{ - int32 numAtomics; - Atomic **atomicList; - int32 numLights; - Light **lightList; - int32 numCameras; - // cameras not implemented - - Clump(void); - Clump(Clump *c); - ~Clump(void); - static Clump *streamRead(std::istream &stream); - bool streamWrite(std::ostream &stream); - uint32 streamGetSize(void); - -private: - void frameListStreamRead(std::istream &stream, Frame ***flp, int32 *nf); - void frameListStreamWrite(std::ostream &stream, Frame **flp, int32 nf); -}; - -} - -void registerNodeNamePlugin(void); -void registerMeshPlugin(void); -void registerNativeDataPlugin(void); +#include "src/rwbase.h" +#include "src/rwplugin.h" +#include "src/rwobjects.h" +#include "src/rwps2.h" +#include "src/rwogl.h" diff --git a/clump.cpp b/src/clump.cpp similarity index 99% rename from clump.cpp rename to src/clump.cpp index f5300d4..99bacfd 100644 --- a/clump.cpp +++ b/src/clump.cpp @@ -8,7 +8,7 @@ #include "rwbase.h" #include "rwplugin.h" -#include "rw.h" +#include "rwobjects.h" using namespace std; diff --git a/geometry.cpp b/src/geometry.cpp similarity index 99% rename from geometry.cpp rename to src/geometry.cpp index d2872c9..765749a 100644 --- a/geometry.cpp +++ b/src/geometry.cpp @@ -8,7 +8,7 @@ #include "rwbase.h" #include "rwplugin.h" -#include "rw.h" +#include "rwobjects.h" using namespace std; diff --git a/ogl.cpp b/src/ogl.cpp similarity index 98% rename from ogl.cpp rename to src/ogl.cpp index 7c472b6..ff015b6 100644 --- a/ogl.cpp +++ b/src/ogl.cpp @@ -8,7 +8,7 @@ #include "rwbase.h" #include "rwplugin.h" -#include "rw.h" +#include "rwobjects.h" #include "rwogl.h" using namespace std; diff --git a/plugins.cpp b/src/plugins.cpp similarity index 99% rename from plugins.cpp rename to src/plugins.cpp index c30e26e..5385f5d 100644 --- a/plugins.cpp +++ b/src/plugins.cpp @@ -7,7 +7,7 @@ #include "rwbase.h" #include "rwplugin.h" -#include "rw.h" +#include "rwobjects.h" #include "rwps2.h" #include "rwogl.h" diff --git a/ps2.cpp b/src/ps2.cpp similarity index 99% rename from ps2.cpp rename to src/ps2.cpp index ec398dd..f3617d8 100644 --- a/ps2.cpp +++ b/src/ps2.cpp @@ -8,7 +8,7 @@ #include "rwbase.h" #include "rwplugin.h" -#include "rw.h" +#include "rwobjects.h" #include "rwps2.h" using namespace std; diff --git a/rwbase.cpp b/src/rwbase.cpp similarity index 100% rename from rwbase.cpp rename to src/rwbase.cpp diff --git a/rwbase.h b/src/rwbase.h similarity index 100% rename from rwbase.h rename to src/rwbase.h diff --git a/src/rwobjects.h b/src/rwobjects.h new file mode 100644 index 0000000..ca025e9 --- /dev/null +++ b/src/rwobjects.h @@ -0,0 +1,213 @@ +namespace Rw { + +struct Object +{ + uint8 type; + uint8 subType; + uint8 flags; + void *parent; +}; + +// TODO: raster, link into texdict +struct Texture : PluginBase +{ + char name[32]; + char mask[32]; + uint32 filterAddressing; + int32 refCount; + + Texture(void); + ~Texture(void); + void decRef(void); + static Texture *streamRead(std::istream &stream); + bool streamWrite(std::ostream &stream); + uint32 streamGetSize(void); + + enum FilterMode { + NEAREST = 1, + LINEAR, + MIPNEAREST, + MIPLINEAR, + LINEARMIPNEAREST, + LINEARMIPLINEAR + }; + enum Addressing { + WRAP = 1, + MIRROR, + CLAMP, + BORDER + }; +}; + +struct Material : PluginBase +{ + Texture *texture; + uint8 color[4]; + float32 surfaceProps[3]; + int32 refCount; + + Material(void); + Material(Material *m); + void decRef(void); + ~Material(void); + static Material *streamRead(std::istream &stream); + bool streamWrite(std::ostream &stream); + uint32 streamGetSize(void); +}; + +struct Mesh +{ + uint16 *indices; + uint32 numIndices; + Material *material; +}; + +struct MeshHeader +{ + uint32 flags; + uint16 numMeshes; + // RW has uint16 serialNum here + uint32 totalIndices; + Mesh *mesh; // RW has a byte offset here +}; + +struct MorphTarget +{ + float32 boundingSphere[4]; + float32 *vertices; + float32 *normals; +}; + +struct InstanceDataHeader +{ + uint32 platform; +}; + +struct Geometry : PluginBase, Object +{ + uint32 geoflags; + int32 numTriangles; + int32 numVertices; + int32 numMorphTargets; + int32 numTexCoordSets; + + uint16 *triangles; + uint8 *colors; + float32 *texCoords[8]; + + MorphTarget *morphTargets; + + int32 numMaterials; + Material **materialList; + + MeshHeader *meshHeader; + + InstanceDataHeader *instData; + + int32 refCount; + + Geometry(int32 numVerts, int32 numTris, uint32 flags); + void decRef(void); + ~Geometry(void); + static Geometry *streamRead(std::istream &stream); + bool streamWrite(std::ostream &stream); + uint32 streamGetSize(void); + void addMorphTargets(int32 n); + + enum Flags + { + TRISTRIP = 0x01, + POSITIONS = 0x02, + TEXTURED = 0x04, + PRELIT = 0x08, + NORMALS = 0x10, + LIGHT = 0x20, + MODULATE = 0x40, + TEXTURED2 = 0x80, + NATIVE = 0x01000000, + NATIVEINSTANCE = 0x02000000 + }; +}; + +struct Frame : PluginBase, Object +{ + typedef Frame *(*Callback)(Frame *f, void *data); + float32 matrix[16]; + float32 ltm[16]; + + Frame *child; + Frame *next; + Frame *root; + + // temporary + int32 matflag; + + Frame(void); + Frame(Frame *f); + ~Frame(void); + Frame *addChild(Frame *f); + Frame *removeChild(void); + Frame *forAllChildren(Callback cb, void *data); + int32 count(void); +}; + +struct Clump; + +struct Light : PluginBase, Object +{ + Frame *frame; + float32 radius; + float32 color[4]; + float32 minusCosAngle; + Clump *clump; + + Light(void); + Light(Light *l); + ~Light(void); + static Light *streamRead(std::istream &stream); + bool streamWrite(std::ostream &stream); + uint32 streamGetSize(void); +}; + +struct Atomic : PluginBase, Object +{ + Frame *frame; + Geometry *geometry; + Clump *clump; + + Atomic(void); + Atomic(Atomic *a); + ~Atomic(void); + static Atomic *streamReadClump(std::istream &stream, + Frame **frameList, Geometry **geometryList); + bool streamWriteClump(std::ostream &stream, + Frame **frameList, int32 numFrames); + uint32 streamGetSize(void); +}; + +struct Clump : PluginBase, Object +{ + int32 numAtomics; + Atomic **atomicList; + int32 numLights; + Light **lightList; + int32 numCameras; + // cameras not implemented + + Clump(void); + Clump(Clump *c); + ~Clump(void); + static Clump *streamRead(std::istream &stream); + bool streamWrite(std::ostream &stream); + uint32 streamGetSize(void); + +private: + void frameListStreamRead(std::istream &stream, Frame ***flp, int32 *nf); + void frameListStreamWrite(std::ostream &stream, Frame **flp, int32 nf); +}; + +} + +void registerNodeNamePlugin(void); +void registerMeshPlugin(void); +void registerNativeDataPlugin(void); diff --git a/rwogl.h b/src/rwogl.h similarity index 100% rename from rwogl.h rename to src/rwogl.h diff --git a/rwplugin.h b/src/rwplugin.h similarity index 100% rename from rwplugin.h rename to src/rwplugin.h diff --git a/rwps2.h b/src/rwps2.h similarity index 100% rename from rwps2.h rename to src/rwps2.h