From 30114667edf910138c5e713ab017441b2110beaf Mon Sep 17 00:00:00 2001 From: aap Date: Thu, 16 Jun 2016 14:08:09 +0200 Subject: [PATCH] started tidying up --- Makefile | 3 +- rw.h | 5 +- src/anim.cpp | 3 +- src/clump.cpp | 45 +++++----- src/d3d.cpp | 7 +- src/d3d8.cpp | 2 +- src/d3d8render.cpp | 4 +- src/d3d9.cpp | 2 +- src/d3d9render.cpp | 4 +- src/d3ddriver.cpp | 4 +- src/engine.cpp | 49 +++++++++++ src/geometry.cpp | 2 +- src/image.cpp | 18 ++-- src/ogl.cpp | 3 +- src/pds.cpp | 6 +- src/pipeline.cpp | 2 +- src/plugins.cpp | 4 +- src/ps2.cpp | 4 +- src/ps2raster.cpp | 7 +- src/rwbase.cpp | 26 ++++-- src/rwbase.h | 10 ++- src/rwengine.h | 25 ++++++ src/rwobjects.h | 170 +++--------------------------------- src/{rwplugin.h => rwplg.h} | 0 src/rwplugins.h | 165 ++++++++++++++++++++++++++++++++++ src/rwps2.h | 16 ---- src/rwps2plg.h | 22 +++++ src/xbox.cpp | 6 +- 28 files changed, 372 insertions(+), 242 deletions(-) create mode 100644 src/engine.cpp create mode 100644 src/rwengine.h rename src/{rwplugin.h => rwplg.h} (100%) create mode 100644 src/rwplugins.h create mode 100644 src/rwps2plg.h diff --git a/Makefile b/Makefile index b026ea3..e496a38 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,8 @@ SRC := $(wildcard $(SRCDIR)/*.cpp) OBJ := $(patsubst $(SRCDIR)/%.cpp,$(BUILDDIR)/%.o,$(SRC)) DEP := $(patsubst $(SRCDIR)/%.cpp,$(BUILDDIR)/%.d,$(SRC)) INC := -I/usr/local/include -CFLAGS=-Wall -Wextra -g $(BUILDDEF) -Wno-parentheses #-Wconversion +CFLAGS=-Wall -Wextra -g $(BUILDDEF) -Wno-parentheses -Wno-invalid-offsetof -fno-diagnostics-show-caret + #-Wconversion LIB=librw-$(BUILD).a $(LIB): $(OBJ) diff --git a/rw.h b/rw.h index 0ac1dcb..ba56c0a 100644 --- a/rw.h +++ b/rw.h @@ -2,10 +2,13 @@ #include #include "src/rwbase.h" -#include "src/rwplugin.h" +#include "src/rwplg.h" #include "src/rwpipeline.h" #include "src/rwobjects.h" +#include "src/rwengine.h" +#include "src/rwplugins.h" #include "src/rwps2.h" +#include "src/rwps2plg.h" #include "src/rwxbox.h" #include "src/rwd3d.h" #include "src/rwd3d8.h" diff --git a/src/anim.cpp b/src/anim.cpp index bd647bb..9406493 100644 --- a/src/anim.cpp +++ b/src/anim.cpp @@ -4,9 +4,10 @@ #include #include "rwbase.h" -#include "rwplugin.h" +#include "rwplg.h" #include "rwpipeline.h" #include "rwobjects.h" +#include "rwplugins.h" using namespace std; diff --git a/src/clump.cpp b/src/clump.cpp index 4bc4917..fac3edd 100644 --- a/src/clump.cpp +++ b/src/clump.cpp @@ -5,9 +5,10 @@ #include #include "rwbase.h" -#include "rwplugin.h" +#include "rwplg.h" #include "rwpipeline.h" #include "rwobjects.h" +#include "rwengine.h" #include "rwps2.h" #include "rwogl.h" #include "rwxbox.h" @@ -492,7 +493,7 @@ Clump::render(void) Atomic *a; FORLIST(lnk, this->atomics){ a = Atomic::fromClump(lnk); - if(a->object.flags & Atomic::RENDER) + if(a->object.object.flags & Atomic::RENDER) a->render(); } } @@ -566,7 +567,7 @@ Atomic::create(void) { Atomic *atomic = (Atomic*)malloc(PluginBase::s_size); assert(atomic != NULL); - atomic->object.init(Atomic::ID, 0); + atomic->object.object.init(Atomic::ID, 0); atomic->geometry = NULL; atomic->worldBoundingSphere.center.set(0.0f, 0.0f, 0.0f); atomic->worldBoundingSphere.radius = 0.0f; @@ -574,7 +575,7 @@ Atomic::create(void) atomic->clump = NULL; atomic->pipeline = NULL; atomic->renderCB = Atomic::defaultRenderCB; - atomic->object.flags = Atomic::COLLISIONTEST | Atomic::RENDER; + atomic->object.object.flags = Atomic::COLLISIONTEST | Atomic::RENDER; atomic->constructPlugins(); return atomic; } @@ -583,8 +584,8 @@ Atomic* Atomic::clone() { Atomic *atomic = Atomic::create(); - atomic->object.copy(&this->object); - atomic->object.privateFlags |= 1; + atomic->object.object.copy(&this->object.object); + atomic->object.object.privateFlags |= 1; if(this->geometry){ atomic->geometry = this->geometry; atomic->geometry->refCount++; @@ -611,14 +612,14 @@ Atomic::getWorldBoundingSphere(void) { Sphere *s = &this->worldBoundingSphere; if(!this->getFrame()->dirty() && - (this->object.privateFlags & WORLDBOUNDDIRTY) == 0) + (this->object.object.privateFlags & WORLDBOUNDDIRTY) == 0) return s; Matrix *ltm = this->getFrame()->getLTM(); // TODO: support scaling // TODO: if we ever support morphing, fix this: s->center = ltm->transPoint(this->geometry->morphTargets[0].boundingSphere.center); s->radius = this->geometry->morphTargets[0].boundingSphere.radius; - this->object.privateFlags &= ~WORLDBOUNDDIRTY; + this->object.object.privateFlags &= ~WORLDBOUNDDIRTY; return s; } @@ -639,7 +640,7 @@ Atomic::streamReadClump(Stream *stream, atomic->geometry = Geometry::streamRead(stream); }else atomic->geometry = geometryList[buf[1]]; - atomic->object.flags = buf[2]; + atomic->object.object.flags = buf[2]; atomicRights[0] = 0; atomic->streamReadPlugins(stream); @@ -660,7 +661,7 @@ Atomic::streamWriteClump(Stream *stream, Frame **frameList, int32 numFrames) buf[0] = findPointer(this->getFrame(), (void**)frameList, numFrames); if(version < 0x30400){ - buf[1] = this->object.flags; + buf[1] = this->object.object.flags; stream->write(buf, sizeof(int[3])); this->geometry->streamWrite(stream); }else{ @@ -672,7 +673,7 @@ Atomic::streamWriteClump(Stream *stream, Frame **frameList, int32 numFrames) } return false; foundgeo: - buf[2] = this->object.flags; + buf[2] = this->object.object.flags; stream->write(buf, sizeof(buf)); } @@ -691,14 +692,12 @@ Atomic::streamGetSize(void) return size; } -ObjPipeline *defaultPipelines[NUM_PLATFORMS]; - ObjPipeline* Atomic::getPipeline(void) { return this->pipeline ? this->pipeline : - defaultPipelines[platform]; + engine[platform].defaultPipeline; } void @@ -754,15 +753,15 @@ Light::create(int32 type) { Light *light = (Light*)malloc(PluginBase::s_size); assert(light != NULL); - light->object.init(Light::ID, type); + light->object.object.init(Light::ID, type); light->radius = 0.0f; light->color.red = 1.0f; light->color.green = 1.0f; light->color.blue = 1.0f; light->color.alpha = 1.0f; light->minusCosAngle = 1.0f; - light->object.privateFlags = 1; - light->object.flags = LIGHTATOMICS | LIGHTWORLD; + light->object.object.privateFlags = 1; + light->object.object.flags = LIGHTATOMICS | LIGHTWORLD; light->clump = NULL; light->inClump.init(); light->constructPlugins(); @@ -796,7 +795,7 @@ Light::setColor(float32 r, float32 g, float32 b) this->color.red = r; this->color.green = g; this->color.blue = b; - this->object.privateFlags = r == g && r == b; + this->object.object.privateFlags = r == g && r == b; } struct LightChunkData @@ -824,7 +823,7 @@ Light::streamRead(Stream *stream) else // tan -> -cos light->minusCosAngle = -1.0f/sqrt(a*a+1.0f); - light->object.flags = (uint8)buf.flags; + light->object.object.flags = (uint8)buf.flags; light->streamReadPlugins(stream); return light; } @@ -843,8 +842,8 @@ Light::streamWrite(Stream *stream) buf.minusCosAngle = this->minusCosAngle; else buf.minusCosAngle = tan(acos(-this->minusCosAngle)); - buf.flags = this->object.flags; - buf.type = this->object.subType; + buf.flags = this->object.object.flags; + buf.type = this->object.object.subType; stream->write(&buf, sizeof(LightChunkData)); this->streamWritePlugins(stream); @@ -865,7 +864,7 @@ Camera* Camera::create(void) { Camera *cam = (Camera*)malloc(PluginBase::s_size); - cam->object.init(Camera::ID, 0); + cam->object.object.init(Camera::ID, 0); cam->viewWindow.set(1.0f, 1.0f); cam->viewOffset.set(0.0f, 0.0f); cam->nearPlane = 0.05f; @@ -882,7 +881,7 @@ Camera* Camera::clone(void) { Camera *cam = Camera::create(); - cam->object.copy(&this->object); + cam->object.object.copy(&this->object.object); cam->setFrame(this->getFrame()); cam->viewWindow = this->viewWindow; cam->viewOffset = this->viewOffset; diff --git a/src/d3d.cpp b/src/d3d.cpp index 157c8c7..91ffa8c 100644 --- a/src/d3d.cpp +++ b/src/d3d.cpp @@ -6,9 +6,10 @@ #include #include "rwbase.h" -#include "rwplugin.h" +#include "rwplg.h" #include "rwpipeline.h" #include "rwobjects.h" +#include "rwengine.h" #include "rwd3d.h" using namespace std; @@ -593,8 +594,8 @@ registerNativeRaster(void) createNativeRaster, destroyNativeRaster, copyNativeRaster); - Raster::nativeOffsets[PLATFORM_D3D8] = nativeRasterOffset; - Raster::nativeOffsets[PLATFORM_D3D9] = nativeRasterOffset; + engine[PLATFORM_D3D8].rasterNativeOffset = nativeRasterOffset; + engine[PLATFORM_D3D9].rasterNativeOffset = nativeRasterOffset; } } diff --git a/src/d3d8.cpp b/src/d3d8.cpp index 9508d45..b3efe89 100644 --- a/src/d3d8.cpp +++ b/src/d3d8.cpp @@ -4,7 +4,7 @@ #include #include "rwbase.h" -#include "rwplugin.h" +#include "rwplg.h" #include "rwpipeline.h" #include "rwobjects.h" #include "rwd3d.h" diff --git a/src/d3d8render.cpp b/src/d3d8render.cpp index 3f566e8..fe191b7 100644 --- a/src/d3d8render.cpp +++ b/src/d3d8render.cpp @@ -4,7 +4,7 @@ #include #include "rwbase.h" -#include "rwplugin.h" +#include "rwplg.h" #include "rwpipeline.h" #include "rwobjects.h" #include "rwd3d.h" @@ -48,4 +48,4 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header) #endif } -} \ No newline at end of file +} diff --git a/src/d3d9.cpp b/src/d3d9.cpp index 5be4ce7..1d19081 100644 --- a/src/d3d9.cpp +++ b/src/d3d9.cpp @@ -4,7 +4,7 @@ #include #include "rwbase.h" -#include "rwplugin.h" +#include "rwplg.h" #include "rwpipeline.h" #include "rwobjects.h" #include "rwd3d.h" diff --git a/src/d3d9render.cpp b/src/d3d9render.cpp index aa8be7d..6c84620 100644 --- a/src/d3d9render.cpp +++ b/src/d3d9render.cpp @@ -4,7 +4,7 @@ #include #include "rwbase.h" -#include "rwplugin.h" +#include "rwplg.h" #include "rwpipeline.h" #include "rwobjects.h" #include "rwd3d.h" @@ -49,4 +49,4 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header) #endif } -} \ No newline at end of file +} diff --git a/src/d3ddriver.cpp b/src/d3ddriver.cpp index 3609e5e..de921c9 100644 --- a/src/d3ddriver.cpp +++ b/src/d3ddriver.cpp @@ -4,7 +4,7 @@ #include #include "rwbase.h" -#include "rwplugin.h" +#include "rwplg.h" #include "rwpipeline.h" #include "rwobjects.h" #include "rwd3d.h" @@ -179,4 +179,4 @@ setMaterial(Material *mat) #endif } -} \ No newline at end of file +} diff --git a/src/engine.cpp b/src/engine.cpp new file mode 100644 index 0000000..ecb7cc2 --- /dev/null +++ b/src/engine.cpp @@ -0,0 +1,49 @@ +#include +#include + +#include "rwbase.h" +#include "rwplg.h" +#include "rwpipeline.h" +#include "rwobjects.h" +#include "rwengine.h" + +namespace rw { + +Engine engines[NUM_PLATFORMS]; + +namespace null { + +void +rasterCreate(Raster*) +{ + assert(0 && "rasterCreate not implemented"); +} + +uint8* +rasterLock(Raster*, int32) +{ + assert(0 && "lockRaster not implemented"); + return NULL; +} + +void +rasterUnlock(Raster*, int32) +{ + assert(0 && "unlockRaster not implemented"); +} + +int32 +rasterNumLevels(Raster*, int32) +{ + assert(0 && "rasterNumLevels not implemented"); + return 0; +} + +void +rasterFromImage(Raster*, Image*) +{ + assert(0 && "rasterFromImage not implemented"); +} + +} +} diff --git a/src/geometry.cpp b/src/geometry.cpp index 9a7428b..cee18a0 100644 --- a/src/geometry.cpp +++ b/src/geometry.cpp @@ -5,7 +5,7 @@ #include #include "rwbase.h" -#include "rwplugin.h" +#include "rwplg.h" #include "rwpipeline.h" #include "rwobjects.h" diff --git a/src/image.cpp b/src/image.cpp index 5362e1d..97e3133 100755 --- a/src/image.cpp +++ b/src/image.cpp @@ -4,9 +4,10 @@ #include #include "rwbase.h" -#include "rwplugin.h" +#include "rwplg.h" #include "rwpipeline.h" #include "rwobjects.h" +#include "rwengine.h" #include "rwps2.h" #include "rwd3d.h" #include "rwxbox.h" @@ -628,8 +629,6 @@ writeTGA(Image *image, const char *filename) // Raster // -int32 Raster::nativeOffsets[NUM_PLATFORMS]; - Raster* Raster::create(int32 width, int32 height, int32 depth, int32 format, int32 platform) { @@ -645,10 +644,13 @@ Raster::create(int32 width, int32 height, int32 depth, int32 format, int32 platf raster->texels = raster->palette = NULL; raster->constructPlugins(); - int32 offset = nativeOffsets[raster->platform]; + int32 offset = engine[raster->platform].rasterNativeOffset; assert(offset != 0 && "unimplemented raster platform"); +printf("%X %d\n", offset, raster->platform); NativeRaster *nr = PLUGINOFFSET(NativeRaster, raster, offset); +printf("%p\n", nr); nr->create(raster); +printf("created\n"); return raster; } @@ -664,7 +666,7 @@ Raster::destroy(void) uint8* Raster::lock(int32 level) { - int32 offset = nativeOffsets[this->platform]; + int32 offset = engine[this->platform].rasterNativeOffset; assert(offset != 0 && "unimplemented raster platform"); NativeRaster *nr = PLUGINOFFSET(NativeRaster, this, offset); return nr->lock(this, level); @@ -673,7 +675,7 @@ Raster::lock(int32 level) void Raster::unlock(int32 level) { - int32 offset = nativeOffsets[this->platform]; + int32 offset = engine[this->platform].rasterNativeOffset; assert(offset != 0 && "unimplemented raster platform"); NativeRaster *nr = PLUGINOFFSET(NativeRaster, this, offset); nr->unlock(this, level); @@ -682,7 +684,7 @@ Raster::unlock(int32 level) int32 Raster::getNumLevels(void) { - int32 offset = nativeOffsets[this->platform]; + int32 offset = engine[this->platform].rasterNativeOffset; assert(offset != 0 && "unimplemented raster platform"); NativeRaster *nr = PLUGINOFFSET(NativeRaster, this, offset); return nr->getNumLevels(this); @@ -703,7 +705,7 @@ Raster::createFromImage(Image *image) { Raster *raster = Raster::create(image->width, image->height, image->depth, 4 | 0x80); - int32 offset = nativeOffsets[raster->platform]; + int32 offset = engine[raster->platform].rasterNativeOffset; assert(offset != 0 && "unimplemented raster platform"); NativeRaster *nr = PLUGINOFFSET(NativeRaster, raster, offset); nr->fromImage(raster, image); diff --git a/src/ogl.cpp b/src/ogl.cpp index ceb5333..b14b7ba 100644 --- a/src/ogl.cpp +++ b/src/ogl.cpp @@ -4,9 +4,10 @@ #include #include "rwbase.h" -#include "rwplugin.h" +#include "rwplg.h" #include "rwpipeline.h" #include "rwobjects.h" +#include "rwplugins.h" #include "rwogl.h" #ifdef RW_OPENGL diff --git a/src/pds.cpp b/src/pds.cpp index ac7d077..13415dd 100644 --- a/src/pds.cpp +++ b/src/pds.cpp @@ -4,10 +4,12 @@ #include #include "rwbase.h" -#include "rwplugin.h" +#include "rwplg.h" #include "rwpipeline.h" #include "rwobjects.h" +#include "rwplugins.h" #include "rwps2.h" +#include "rwps2plg.h" namespace rw { namespace ps2 { @@ -182,4 +184,4 @@ registerPluginPDSPipes(void) } } -} \ No newline at end of file +} diff --git a/src/pipeline.cpp b/src/pipeline.cpp index 94ee501..a9c3284 100644 --- a/src/pipeline.cpp +++ b/src/pipeline.cpp @@ -4,7 +4,7 @@ #include #include "rwbase.h" -#include "rwplugin.h" +#include "rwplg.h" #include "rwpipeline.h" #include "rwobjects.h" #include "rwps2.h" diff --git a/src/plugins.cpp b/src/plugins.cpp index 03227fc..2c0969d 100644 --- a/src/plugins.cpp +++ b/src/plugins.cpp @@ -4,10 +4,12 @@ #include #include "rwbase.h" -#include "rwplugin.h" +#include "rwplg.h" #include "rwpipeline.h" #include "rwobjects.h" +#include "rwplugins.h" #include "rwps2.h" +#include "rwps2plg.h" #include "rwogl.h" #include "rwxbox.h" #include "rwd3d8.h" diff --git a/src/ps2.cpp b/src/ps2.cpp index 986867c..8431c2f 100644 --- a/src/ps2.cpp +++ b/src/ps2.cpp @@ -4,10 +4,12 @@ #include #include "rwbase.h" -#include "rwplugin.h" +#include "rwplg.h" #include "rwpipeline.h" #include "rwobjects.h" +#include "rwplugins.h" #include "rwps2.h" +#include "rwps2plg.h" namespace rw { namespace ps2 { diff --git a/src/ps2raster.cpp b/src/ps2raster.cpp index 7f06f9c..8c05937 100644 --- a/src/ps2raster.cpp +++ b/src/ps2raster.cpp @@ -6,9 +6,10 @@ #include #include "rwbase.h" -#include "rwplugin.h" +#include "rwplg.h" #include "rwpipeline.h" #include "rwobjects.h" +#include "rwengine.h" #include "rwps2.h" #define max(a, b) ((a) > (b) ? (a) : (b)) @@ -480,7 +481,7 @@ registerNativeRaster(void) createNativeRaster, destroyNativeRaster, copyNativeRaster); - Raster::nativeOffsets[PLATFORM_PS2] = nativeRasterOffset; + engine[PLATFORM_PS2].rasterNativeOffset = nativeRasterOffset; Texture::registerPlugin(0, ID_SKYMIPMAP, NULL, NULL, NULL); Texture::registerPluginStream(ID_SKYMIPMAP, readMipmap, writeMipmap, getSizeMipmap); } @@ -632,4 +633,4 @@ getSizeNativeTexture(Texture *tex) } } -} \ No newline at end of file +} diff --git a/src/rwbase.cpp b/src/rwbase.cpp index cd1ebc8..714c449 100644 --- a/src/rwbase.cpp +++ b/src/rwbase.cpp @@ -6,9 +6,11 @@ #include #include "rwbase.h" -#include "rwplugin.h" +#include "rwplg.h" #include "rwpipeline.h" #include "rwobjects.h" +#include "rwplugins.h" +#include "rwengine.h" #include "rwps2.h" #include "rwogl.h" #include "rwxbox.h" @@ -50,19 +52,27 @@ static Matrix3 identMat3 = { void initialize(void) { + for(uint i = 0; i < NUM_PLATFORMS; i++){ + engine[i].rasterCreate = null::rasterCreate; + engine[i].rasterLock = null::rasterLock; + engine[i].rasterUnlock = null::rasterUnlock; + engine[i].rasterNumLevels = null::rasterNumLevels; + engine[i].rasterFromImage = null::rasterFromImage; + } + // Atomic pipelines ObjPipeline *defpipe = new ObjPipeline(PLATFORM_NULL); - for(uint i = 0; i < nelem(matFXGlobals.pipelines); i++) - defaultPipelines[i] = defpipe; - defaultPipelines[PLATFORM_PS2] = + for(uint i = 0; i < NUM_PLATFORMS; i++) + engine[i].defaultPipeline = defpipe; + engine[PLATFORM_PS2].defaultPipeline = ps2::makeDefaultPipeline(); - defaultPipelines[PLATFORM_OGL] = + engine[PLATFORM_OGL].defaultPipeline = gl::makeDefaultPipeline(); - defaultPipelines[PLATFORM_XBOX] = + engine[PLATFORM_XBOX].defaultPipeline = xbox::makeDefaultPipeline(); - defaultPipelines[PLATFORM_D3D8] = + engine[PLATFORM_D3D8].defaultPipeline = d3d8::makeDefaultPipeline(); - defaultPipelines[PLATFORM_D3D9] = + engine[PLATFORM_D3D9].defaultPipeline = d3d9::makeDefaultPipeline(); Frame::dirtyList.init(); diff --git a/src/rwbase.h b/src/rwbase.h index 21782fa..b3d4046 100644 --- a/src/rwbase.h +++ b/src/rwbase.h @@ -160,6 +160,10 @@ struct Sphere float32 radius; }; +/* + * Streams + */ + class Stream { public: @@ -223,7 +227,7 @@ enum Platform { PLATFORM_NULL = 0, // D3D7 - PLATFORM_OGL = 2, + PLATFORM_OGL = 2, // TODO: remove, this is really WarDrum GL // MAC PLATFORM_PS2 = 4, PLATFORM_XBOX = 5, @@ -231,6 +235,10 @@ enum Platform // SOFTRAS PLATFORM_D3D8 = 8, PLATFORM_D3D9 = 9, + + // non stock-RW platforms + + PLATFORM_GL3 = 10, NUM_PLATFORMS, FOURCC_PS2 = 0x00325350 // 'PS2\0' diff --git a/src/rwengine.h b/src/rwengine.h new file mode 100644 index 0000000..9afae03 --- /dev/null +++ b/src/rwengine.h @@ -0,0 +1,25 @@ +namespace rw { + +struct Engine +{ + ObjPipeline *defaultPipeline; + int32 rasterNativeOffset; + + void (*rasterCreate)(Raster*); + uint8 *(*rasterLock)(Raster*, int32 level); + void (*rasterUnlock)(Raster*, int32 level); + int32 (*rasterNumLevels)(Raster*); + void (*rasterFromImage)(Raster*, Image*); +}; + +extern Engine engine[NUM_PLATFORMS]; + +namespace null { + void rasterCreate(Raster*); + uint8 *rasterLock(Raster*, int32 level); + void rasterUnlock(Raster*, int32 level); + int32 rasterNumLevels(Raster*); + void rasterFromImage(Raster*, Image*); +} + +} diff --git a/src/rwobjects.h b/src/rwobjects.h index 8b35900..f35856c 100644 --- a/src/rwobjects.h +++ b/src/rwobjects.h @@ -132,13 +132,14 @@ struct Frame : PluginBase Frame **makeFrameList(Frame *frame, Frame **flist); -struct ObjectWithFrame : Object +struct ObjectWithFrame { + Object object; LLLink inFrame; void setFrame(Frame *f){ - if(this->parent) + if(this->object.parent) this->inFrame.remove(); - this->parent = f; + this->object.parent = f; if(f) f->objectList.add(&this->inFrame); } @@ -147,62 +148,6 @@ struct ObjectWithFrame : Object } }; -struct HAnimKeyFrame -{ - HAnimKeyFrame *prev; - float time; - float q[4]; - float t[3]; -}; - -struct HAnimNodeInfo -{ - int32 id; - int32 index; - int32 flags; - Frame *frame; -}; - -struct HAnimHierarchy -{ - int32 flags; - int32 numNodes; - float *matrices; - float *matricesUnaligned; - HAnimNodeInfo *nodeInfo; - Frame *parentFrame; - HAnimHierarchy *parentHierarchy; // mostly unused - - // temporary - int32 maxInterpKeyFrameSize; - - static HAnimHierarchy *create(int32 numNodes, int32 *nodeFlags, int32 *nodeIDs, int32 flags, int32 maxKeySize); - void destroy(void); - void attachByIndex(int32 id); - void attach(void); - int32 getIndex(int32 id); - - static HAnimHierarchy *get(Frame *f); - static HAnimHierarchy *find(Frame *f); - - enum NodeFlag { - POP = 1, - PUSH - }; -}; - -struct HAnimData -{ - int32 id; - HAnimHierarchy *hierarchy; - - static HAnimData *get(Frame *f); -}; - -extern int32 hAnimOffset; -extern bool32 hAnimDoStream; -void registerHAnimPlugin(void); - struct Image { int32 flags; @@ -250,8 +195,6 @@ struct Raster : PluginBase uint8 *texels; uint8 *palette; - static int32 nativeOffsets[NUM_PLATFORMS]; - static Raster *create(int32 width, int32 height, int32 depth, int32 format, int32 platform = 0); void destroy(void); static Raster *createFromImage(Image *image); @@ -340,6 +283,7 @@ struct Texture : PluginBase }; }; + struct SurfaceProperties { float32 ambient; @@ -365,72 +309,6 @@ struct Material : PluginBase void registerMaterialRightsPlugin(void); -struct MatFX -{ - enum { - NOTHING = 0, - BUMPMAP, - ENVMAP, - BUMPENVMAP, // BUMP | ENV - DUAL, - UVTRANSFORM, - DUALUVTRANSFORM - }; - struct Bump { - Frame *frame; - Texture *bumpedTex; - Texture *tex; - float coefficient; - }; - struct Env { - Frame *frame; - Texture *tex; - float coefficient; - int32 fbAlpha; - }; - struct Dual { - Texture *tex; - int32 srcBlend; - int32 dstBlend; - }; - struct UVtransform { - float *baseTransform; - float *dualTransform; - }; - struct { - uint32 type; - union { - Bump bump; - Env env; - Dual dual; - UVtransform uvtransform; - }; - } fx[2]; - uint32 type; - - void setEffects(uint32 flags); - static uint32 getEffects(Material *m); - uint32 getEffectIndex(uint32 type); - void setBumpTexture(Texture *t); - void setBumpCoefficient(float32 coef); - void setEnvTexture(Texture *t); - void setEnvCoefficient(float32 coef); - void setDualTexture(Texture *t); - void setDualSrcBlend(int32 blend); - void setDualDestBlend(int32 blend); - - static void enableEffects(Atomic *atomic); -}; - -struct MatFXGlobals -{ - int32 atomicOffset; - int32 materialOffset; - ObjPipeline *pipelines[NUM_PLATFORMS]; -}; -extern MatFXGlobals matFXGlobals; -void registerMatFXPlugin(void); - struct Mesh { uint16 *indices; @@ -528,32 +406,6 @@ struct Geometry : PluginBase void registerMeshPlugin(void); void registerNativeDataPlugin(void); -struct Skin -{ - int32 numBones; - int32 numUsedBones; - int32 numWeights; - uint8 *usedBones; - float *inverseMatrices; - uint8 *indices; - float *weights; - uint8 *data; // only used by delete - void *platformData; // a place to store platform specific stuff - - void init(int32 numBones, int32 numUsedBones, int32 numVertices); - void findNumWeights(int32 numVertices); - void findUsedBones(int32 numVertices); - static void setPipeline(Atomic *a, int32 type); -}; - -struct SkinGlobals -{ - int32 offset; - ObjPipeline *pipelines[NUM_PLATFORMS]; -}; -extern SkinGlobals skinGlobals; -void registerSkinPlugin(void); - struct Clump; struct Atomic : PluginBase @@ -580,9 +432,9 @@ struct Atomic : PluginBase void destroy(void); void setFrame(Frame *f) { this->object.setFrame(f); - this->object.privateFlags |= WORLDBOUNDDIRTY; + this->object.object.privateFlags |= WORLDBOUNDDIRTY; } - Frame *getFrame(void) { return (Frame*)this->object.parent; } + Frame *getFrame(void) { return (Frame*)this->object.object.parent; } static Atomic *fromClump(LLLink *lnk){ return LLLinkGetData(lnk, Atomic, inClump); } ObjPipeline *getPipeline(void); @@ -597,8 +449,6 @@ struct Atomic : PluginBase static void defaultRenderCB(Atomic *atomic); }; -extern ObjPipeline *defaultPipelines[NUM_PLATFORMS]; - void registerAtomicRightsPlugin(void); struct Light : PluginBase @@ -616,13 +466,13 @@ struct Light : PluginBase static Light *create(int32 type); void destroy(void); void setFrame(Frame *f) { this->object.setFrame(f); } - Frame *getFrame(void){ return (Frame*)this->object.parent; } + Frame *getFrame(void){ return (Frame*)this->object.object.parent; } static Light *fromClump(LLLink *lnk){ return LLLinkGetData(lnk, Light, inClump); } void setAngle(float32 angle); float32 getAngle(void); void setColor(float32 r, float32 g, float32 b); - int32 getType(void){ return this->object.subType; } + int32 getType(void){ return this->object.object.subType; } static Light *streamRead(Stream *stream); bool streamWrite(Stream *stream); uint32 streamGetSize(void); @@ -660,7 +510,7 @@ struct Camera : PluginBase Camera *clone(void); void destroy(void); void setFrame(Frame *f) { this->object.setFrame(f); } - Frame *getFrame(void){ return (Frame*)this->object.parent; } + Frame *getFrame(void){ return (Frame*)this->object.object.parent; } static Camera *fromClump(LLLink *lnk){ return LLLinkGetData(lnk, Camera, inClump); } static Camera *streamRead(Stream *stream); diff --git a/src/rwplugin.h b/src/rwplg.h similarity index 100% rename from src/rwplugin.h rename to src/rwplg.h diff --git a/src/rwplugins.h b/src/rwplugins.h new file mode 100644 index 0000000..63a9fa5 --- /dev/null +++ b/src/rwplugins.h @@ -0,0 +1,165 @@ +namespace rw { + +/* + * HAnim + */ + +struct HAnimKeyFrame +{ + HAnimKeyFrame *prev; + float time; + float q[4]; + float t[3]; +}; + +struct HAnimNodeInfo +{ + int32 id; + int32 index; + int32 flags; + Frame *frame; +}; + +struct HAnimHierarchy +{ + int32 flags; + int32 numNodes; + float *matrices; + float *matricesUnaligned; + HAnimNodeInfo *nodeInfo; + Frame *parentFrame; + HAnimHierarchy *parentHierarchy; // mostly unused + + // temporary + int32 maxInterpKeyFrameSize; + + static HAnimHierarchy *create(int32 numNodes, int32 *nodeFlags, int32 *nodeIDs, int32 flags, int32 maxKeySize); + void destroy(void); + void attachByIndex(int32 id); + void attach(void); + int32 getIndex(int32 id); + + static HAnimHierarchy *get(Frame *f); + static HAnimHierarchy *find(Frame *f); + + enum NodeFlag { + POP = 1, + PUSH + }; +}; + +struct HAnimData +{ + int32 id; + HAnimHierarchy *hierarchy; + + static HAnimData *get(Frame *f); +}; + +extern int32 hAnimOffset; +extern bool32 hAnimDoStream; +void registerHAnimPlugin(void); + + +/* + * MatFX + */ + +struct MatFX +{ + enum { + NOTHING = 0, + BUMPMAP, + ENVMAP, + BUMPENVMAP, // BUMP | ENV + DUAL, + UVTRANSFORM, + DUALUVTRANSFORM + }; + struct Bump { + Frame *frame; + Texture *bumpedTex; + Texture *tex; + float coefficient; + }; + struct Env { + Frame *frame; + Texture *tex; + float coefficient; + int32 fbAlpha; + }; + struct Dual { + Texture *tex; + int32 srcBlend; + int32 dstBlend; + }; + struct UVtransform { + float *baseTransform; + float *dualTransform; + }; + struct { + uint32 type; + union { + Bump bump; + Env env; + Dual dual; + UVtransform uvtransform; + }; + } fx[2]; + uint32 type; + + void setEffects(uint32 flags); + static uint32 getEffects(Material *m); + uint32 getEffectIndex(uint32 type); + void setBumpTexture(Texture *t); + void setBumpCoefficient(float32 coef); + void setEnvTexture(Texture *t); + void setEnvCoefficient(float32 coef); + void setDualTexture(Texture *t); + void setDualSrcBlend(int32 blend); + void setDualDestBlend(int32 blend); + + static void enableEffects(Atomic *atomic); +}; + +struct MatFXGlobals +{ + int32 atomicOffset; + int32 materialOffset; + ObjPipeline *pipelines[NUM_PLATFORMS]; +}; +extern MatFXGlobals matFXGlobals; +void registerMatFXPlugin(void); + + +/* + * Skin + */ + +struct Skin +{ + int32 numBones; + int32 numUsedBones; + int32 numWeights; + uint8 *usedBones; + float *inverseMatrices; + uint8 *indices; + float *weights; + uint8 *data; // only used by delete + void *platformData; // a place to store platform specific stuff + + void init(int32 numBones, int32 numUsedBones, int32 numVertices); + void findNumWeights(int32 numVertices); + void findUsedBones(int32 numVertices); + static void setPipeline(Atomic *a, int32 type); +}; + +struct SkinGlobals +{ + int32 offset; + ObjPipeline *pipelines[NUM_PLATFORMS]; +}; +extern SkinGlobals skinGlobals; +void registerSkinPlugin(void); + +} diff --git a/src/rwps2.h b/src/rwps2.h index 0055aaf..e357f61 100644 --- a/src/rwps2.h +++ b/src/rwps2.h @@ -141,24 +141,8 @@ void skinInstanceCB(MatPipeline *, Geometry *g, Mesh *m, uint8 **data); //void skinUninstanceCB(MatPipeline*, Geometry *geo, uint32 flags[], Mesh *mesh, uint8 *data[]); ObjPipeline *makeDefaultPipeline(void); -ObjPipeline *makeSkinPipeline(void); -ObjPipeline *makeMatFXPipeline(void); void dumpPipeline(rw::Pipeline *pipe); -// Skin plugin - -void insertVertexSkin(Geometry *geo, int32 i, uint32 mask, Vertex *v); -int32 findVertexSkin(Geometry *g, uint32 flags[], uint32 mask, Vertex *v); - -void readNativeSkin(Stream *stream, int32, void *object, int32 offset); -void writeNativeSkin(Stream *stream, int32 len, void *object, int32 offset); -int32 getSizeNativeSkin(void *object, int32 offset); - -void instanceSkinData(Geometry *g, Mesh *m, Skin *skin, uint32 *data); - -void skinPreCB(MatPipeline*, Geometry*); -void skinPostCB(MatPipeline*, Geometry*); - // ADC plugin // Each element in adcBits corresponds to an index in Mesh->indices, diff --git a/src/rwps2plg.h b/src/rwps2plg.h new file mode 100644 index 0000000..c9f7787 --- /dev/null +++ b/src/rwps2plg.h @@ -0,0 +1,22 @@ +namespace rw { +namespace ps2 { + +ObjPipeline *makeSkinPipeline(void); +ObjPipeline *makeMatFXPipeline(void); + +// Skin plugin + +void insertVertexSkin(Geometry *geo, int32 i, uint32 mask, Vertex *v); +int32 findVertexSkin(Geometry *g, uint32 flags[], uint32 mask, Vertex *v); + +void readNativeSkin(Stream *stream, int32, void *object, int32 offset); +void writeNativeSkin(Stream *stream, int32 len, void *object, int32 offset); +int32 getSizeNativeSkin(void *object, int32 offset); + +void instanceSkinData(Geometry *g, Mesh *m, Skin *skin, uint32 *data); + +void skinPreCB(MatPipeline*, Geometry*); +void skinPostCB(MatPipeline*, Geometry*); + +} +} diff --git a/src/xbox.cpp b/src/xbox.cpp index f594363..70ce773 100644 --- a/src/xbox.cpp +++ b/src/xbox.cpp @@ -6,9 +6,11 @@ #include #include "rwbase.h" -#include "rwplugin.h" +#include "rwplg.h" #include "rwpipeline.h" #include "rwobjects.h" +#include "rwengine.h" +#include "rwplugins.h" #include "rwxbox.h" using namespace std; @@ -867,7 +869,7 @@ registerNativeRaster(void) createNativeRaster, destroyNativeRaster, copyNativeRaster); - Raster::nativeOffsets[PLATFORM_XBOX] = nativeRasterOffset; + engine[PLATFORM_XBOX].rasterNativeOffset = nativeRasterOffset; } Texture*