started tidying up

This commit is contained in:
aap 2016-06-16 14:08:09 +02:00
parent ee726b90a2
commit 30114667ed
28 changed files with 372 additions and 242 deletions

View File

@ -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)

5
rw.h
View File

@ -2,10 +2,13 @@
#include <cmath>
#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"

View File

@ -4,9 +4,10 @@
#include <cassert>
#include "rwbase.h"
#include "rwplugin.h"
#include "rwplg.h"
#include "rwpipeline.h"
#include "rwobjects.h"
#include "rwplugins.h"
using namespace std;

View File

@ -5,9 +5,10 @@
#include <cmath>
#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;

View File

@ -6,9 +6,10 @@
#include <new>
#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;
}
}

View File

@ -4,7 +4,7 @@
#include <cassert>
#include "rwbase.h"
#include "rwplugin.h"
#include "rwplg.h"
#include "rwpipeline.h"
#include "rwobjects.h"
#include "rwd3d.h"

View File

@ -4,7 +4,7 @@
#include <cassert>
#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
}
}
}

View File

@ -4,7 +4,7 @@
#include <cassert>
#include "rwbase.h"
#include "rwplugin.h"
#include "rwplg.h"
#include "rwpipeline.h"
#include "rwobjects.h"
#include "rwd3d.h"

View File

@ -4,7 +4,7 @@
#include <cassert>
#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
}
}
}

View File

@ -4,7 +4,7 @@
#include <cassert>
#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
}
}
}

49
src/engine.cpp Normal file
View File

@ -0,0 +1,49 @@
#include <cstdio>
#include <assert.h>
#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");
}
}
}

View File

@ -5,7 +5,7 @@
#include <cmath>
#include "rwbase.h"
#include "rwplugin.h"
#include "rwplg.h"
#include "rwpipeline.h"
#include "rwobjects.h"

View File

@ -4,9 +4,10 @@
#include <cassert>
#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);

View File

@ -4,9 +4,10 @@
#include <cassert>
#include "rwbase.h"
#include "rwplugin.h"
#include "rwplg.h"
#include "rwpipeline.h"
#include "rwobjects.h"
#include "rwplugins.h"
#include "rwogl.h"
#ifdef RW_OPENGL

View File

@ -4,10 +4,12 @@
#include <cassert>
#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)
}
}
}
}

View File

@ -4,7 +4,7 @@
#include <cassert>
#include "rwbase.h"
#include "rwplugin.h"
#include "rwplg.h"
#include "rwpipeline.h"
#include "rwobjects.h"
#include "rwps2.h"

View File

@ -4,10 +4,12 @@
#include <cassert>
#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"

View File

@ -4,10 +4,12 @@
#include <cassert>
#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 {

View File

@ -6,9 +6,10 @@
#include <new>
#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)
}
}
}
}

View File

@ -6,9 +6,11 @@
#include <cctype>
#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();

View File

@ -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'

25
src/rwengine.h Normal file
View File

@ -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*);
}
}

View File

@ -132,13 +132,14 @@ struct Frame : PluginBase<Frame>
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<Raster>
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<Texture>
};
};
struct SurfaceProperties
{
float32 ambient;
@ -365,72 +309,6 @@ struct Material : PluginBase<Material>
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<Geometry>
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<Atomic>
@ -580,9 +432,9 @@ struct Atomic : PluginBase<Atomic>
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<Atomic>
static void defaultRenderCB(Atomic *atomic);
};
extern ObjPipeline *defaultPipelines[NUM_PLATFORMS];
void registerAtomicRightsPlugin(void);
struct Light : PluginBase<Light>
@ -616,13 +466,13 @@ struct Light : PluginBase<Light>
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>
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);

165
src/rwplugins.h Normal file
View File

@ -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);
}

View File

@ -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,

22
src/rwps2plg.h Normal file
View File

@ -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*);
}
}

View File

@ -6,9 +6,11 @@
#include <new>
#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*