mirror of
https://github.com/aap/librw.git
synced 2025-02-16 17:26:18 +00:00
worked on rendering and frame ltm synching
This commit is contained in:
parent
80a73f0ac5
commit
0e0cc1156c
120
src/clump.cpp
120
src/clump.cpp
@ -18,6 +18,8 @@ using namespace std;
|
|||||||
|
|
||||||
namespace rw {
|
namespace rw {
|
||||||
|
|
||||||
|
LinkList Frame::dirtyList;
|
||||||
|
|
||||||
Frame*
|
Frame*
|
||||||
Frame::create(void)
|
Frame::create(void)
|
||||||
{
|
{
|
||||||
@ -27,15 +29,13 @@ Frame::create(void)
|
|||||||
f->objectList.init();
|
f->objectList.init();
|
||||||
f->child = NULL;
|
f->child = NULL;
|
||||||
f->next = NULL;
|
f->next = NULL;
|
||||||
f->root = NULL;
|
f->root = f;
|
||||||
for(int i = 0; i < 16; i++)
|
for(int i = 0; i < 16; i++)
|
||||||
f->matrix[i] = 0.0f;
|
f->matrix[i] = 0.0f;
|
||||||
f->matrix[0] = 1.0f;
|
f->matrix[0] = 1.0f;
|
||||||
f->matrix[5] = 1.0f;
|
f->matrix[5] = 1.0f;
|
||||||
f->matrix[10] = 1.0f;
|
f->matrix[10] = 1.0f;
|
||||||
f->matrix[15] = 1.0f;
|
f->matrix[15] = 1.0f;
|
||||||
f->matflag = 0;
|
|
||||||
f->dirty = true;
|
|
||||||
f->constructPlugins();
|
f->constructPlugins();
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
@ -88,13 +88,15 @@ Frame::destroyHierarchy(void)
|
|||||||
Frame*
|
Frame*
|
||||||
Frame::addChild(Frame *child, bool32 append)
|
Frame::addChild(Frame *child, bool32 append)
|
||||||
{
|
{
|
||||||
|
Frame *c;
|
||||||
|
if(child->getParent())
|
||||||
|
child->removeChild();
|
||||||
if(append){
|
if(append){
|
||||||
if(this->child == NULL)
|
if(this->child == NULL)
|
||||||
this->child = child;
|
this->child = child;
|
||||||
else{
|
else{
|
||||||
Frame *f;
|
for(c = this->child; c->next; c = c->next);
|
||||||
for(f = this->child; f->next; f = f->next);
|
c->next = child;
|
||||||
f->next = child;
|
|
||||||
}
|
}
|
||||||
child->next = NULL;
|
child->next = NULL;
|
||||||
}else{
|
}else{
|
||||||
@ -103,6 +105,13 @@ Frame::addChild(Frame *child, bool32 append)
|
|||||||
}
|
}
|
||||||
child->object.parent = this;
|
child->object.parent = this;
|
||||||
child->root = this->root;
|
child->root = this->root;
|
||||||
|
for(c = child->child; c; c = c->next)
|
||||||
|
c->setHierarchyRoot(this);
|
||||||
|
if(child->object.privateFlags & Frame::HIERARCHYSYNC){
|
||||||
|
child->inDirtyList.remove();
|
||||||
|
child->object.privateFlags &= ~Frame::HIERARCHYSYNC;
|
||||||
|
}
|
||||||
|
this->updateObjects();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,19 +119,19 @@ Frame*
|
|||||||
Frame::removeChild(void)
|
Frame::removeChild(void)
|
||||||
{
|
{
|
||||||
Frame *parent = this->getParent();
|
Frame *parent = this->getParent();
|
||||||
if(parent->child == this)
|
Frame *child = parent->child;
|
||||||
|
if(child == this)
|
||||||
parent->child = this->next;
|
parent->child = this->next;
|
||||||
else{
|
else{
|
||||||
Frame *f;
|
while(child->next != this)
|
||||||
for(f = parent->child; f; f = f->next)
|
child = child->next;
|
||||||
if(f->next == this)
|
child->next = this->next;
|
||||||
goto found;
|
|
||||||
// not found
|
|
||||||
found:
|
|
||||||
f->next = f->next->next;
|
|
||||||
}
|
}
|
||||||
this->object.parent = NULL;
|
this->object.parent = this->next = NULL;
|
||||||
this->next = this->root = NULL;
|
this->root = this;
|
||||||
|
for(child = this->child; child; child = child->next)
|
||||||
|
child->setHierarchyRoot(this);
|
||||||
|
this->updateObjects();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,35 +159,53 @@ Frame::count(void)
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
Frame::updateLTM(void)
|
syncRecurse(Frame *frame, uint8 flags)
|
||||||
{
|
{
|
||||||
if(!this->dirty)
|
uint8 flg;
|
||||||
return;
|
for(; frame; frame = frame->next){
|
||||||
Frame *parent = this->getParent();
|
flg = flags | frame->object.privateFlags;
|
||||||
if(parent){
|
if(flg & Frame::SUBTREESYNCLTM){
|
||||||
parent->updateLTM();
|
matrixMult(frame->ltm, frame->getParent()->ltm, frame->matrix);
|
||||||
matrixMult(this->ltm, parent->ltm, this->matrix);
|
frame->object.privateFlags &= ~Frame::SUBTREESYNCLTM;
|
||||||
this->dirty = false;
|
}
|
||||||
}else{
|
syncRecurse(frame->child, flg);
|
||||||
memcpy(this->ltm, this->matrix, 16*4);
|
|
||||||
this->dirty = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Frame*
|
void
|
||||||
dirtyCB(Frame *f, void *)
|
Frame::syncHierarchyLTM(void)
|
||||||
{
|
{
|
||||||
f->dirty = true;
|
Frame *child;
|
||||||
f->forAllChildren(dirtyCB, NULL);
|
uint8 flg;
|
||||||
return f;
|
if(this->object.privateFlags & Frame::SUBTREESYNCLTM)
|
||||||
|
memcpy(this->ltm, this->matrix, 64);
|
||||||
|
for(child = this->child; child; child = child->next){
|
||||||
|
flg = this->object.privateFlags | child->object.privateFlags;
|
||||||
|
if(flg & Frame::SUBTREESYNCLTM){
|
||||||
|
matrixMult(child->ltm, this->ltm, child->matrix);
|
||||||
|
child->object.privateFlags &= ~Frame::SUBTREESYNCLTM;
|
||||||
|
}
|
||||||
|
syncRecurse(child, flg);
|
||||||
|
}
|
||||||
|
this->object.privateFlags &= ~Frame::SYNCLTM;
|
||||||
|
}
|
||||||
|
|
||||||
|
float*
|
||||||
|
Frame::getLTM(void)
|
||||||
|
{
|
||||||
|
if(this->root->object.privateFlags & Frame::HIERARCHYSYNCLTM)
|
||||||
|
this->root->syncHierarchyLTM();
|
||||||
|
return this->ltm;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Frame::setDirty(void)
|
Frame::updateObjects(void)
|
||||||
{
|
{
|
||||||
this->dirty = true;
|
if((this->root->object.privateFlags & HIERARCHYSYNC) == 0)
|
||||||
this->forAllChildren(dirtyCB, NULL);
|
Frame::dirtyList.add(&this->inDirtyList);
|
||||||
|
this->root->object.privateFlags |= HIERARCHYSYNC;
|
||||||
|
this->object.privateFlags |= SUBTREESYNC;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -493,7 +520,7 @@ Clump::frameListStreamRead(Stream *stream, Frame ***flp, int32 *nf)
|
|||||||
f->matrix[13] = buf.pos[1];
|
f->matrix[13] = buf.pos[1];
|
||||||
f->matrix[14] = buf.pos[2];
|
f->matrix[14] = buf.pos[2];
|
||||||
f->matrix[15] = 1.0f;
|
f->matrix[15] = 1.0f;
|
||||||
f->matflag = buf.matflag;
|
//f->matflag = buf.matflag;
|
||||||
if(buf.parent >= 0)
|
if(buf.parent >= 0)
|
||||||
frameList[buf.parent]->addChild(f);
|
frameList[buf.parent]->addChild(f);
|
||||||
}
|
}
|
||||||
@ -533,7 +560,7 @@ Clump::frameListStreamWrite(Stream *stream, Frame **frameList, int32 numFrames)
|
|||||||
buf.pos[2] = f->matrix[14];
|
buf.pos[2] = f->matrix[14];
|
||||||
buf.parent = findPointer(f->getParent(), (void**)frameList,
|
buf.parent = findPointer(f->getParent(), (void**)frameList,
|
||||||
numFrames);
|
numFrames);
|
||||||
buf.matflag = f->matflag;
|
buf.matflag = 0; //f->matflag;
|
||||||
stream->write(&buf, sizeof(buf));
|
stream->write(&buf, sizeof(buf));
|
||||||
}
|
}
|
||||||
for(int32 i = 0; i < numFrames; i++)
|
for(int32 i = 0; i < numFrames; i++)
|
||||||
@ -552,6 +579,7 @@ Atomic::create(void)
|
|||||||
atomic->object.init(Atomic::ID, 0);
|
atomic->object.init(Atomic::ID, 0);
|
||||||
atomic->geometry = NULL;
|
atomic->geometry = NULL;
|
||||||
atomic->pipeline = NULL;
|
atomic->pipeline = NULL;
|
||||||
|
atomic->renderCB = Atomic::defaultRenderCB;
|
||||||
atomic->constructPlugins();
|
atomic->constructPlugins();
|
||||||
|
|
||||||
// flags:
|
// flags:
|
||||||
@ -670,21 +698,9 @@ Atomic::getPipeline(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Atomic::init(void)
|
Atomic::defaultRenderCB(Atomic *atomic)
|
||||||
{
|
{
|
||||||
ObjPipeline *defpipe = new ObjPipeline(PLATFORM_NULL);
|
atomic->getPipeline()->render(atomic);
|
||||||
for(uint i = 0; i < nelem(matFXGlobals.pipelines); i++)
|
|
||||||
defaultPipelines[i] = defpipe;
|
|
||||||
defaultPipelines[PLATFORM_PS2] =
|
|
||||||
ps2::makeDefaultPipeline();
|
|
||||||
defaultPipelines[PLATFORM_OGL] =
|
|
||||||
gl::makeDefaultPipeline();
|
|
||||||
defaultPipelines[PLATFORM_XBOX] =
|
|
||||||
xbox::makeDefaultPipeline();
|
|
||||||
defaultPipelines[PLATFORM_D3D8] =
|
|
||||||
d3d8::makeDefaultPipeline();
|
|
||||||
defaultPipelines[PLATFORM_D3D9] =
|
|
||||||
d3d9::makeDefaultPipeline();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Atomic Rights plugin
|
// Atomic Rights plugin
|
||||||
|
@ -149,7 +149,8 @@ Texture::read(const char *name, const char *mask)
|
|||||||
}
|
}
|
||||||
tex = Texture::create(NULL);
|
tex = Texture::create(NULL);
|
||||||
strncpy(tex->name, name, 32);
|
strncpy(tex->name, name, 32);
|
||||||
strncpy(tex->mask, mask, 32);
|
if(mask)
|
||||||
|
strncpy(tex->mask, mask, 32);
|
||||||
Image *img = NULL;
|
Image *img = NULL;
|
||||||
if(loadTextures){
|
if(loadTextures){
|
||||||
char *n = (char*)malloc(strlen(name) + 5);
|
char *n = (char*)malloc(strlen(name) + 5);
|
||||||
|
@ -16,6 +16,8 @@ using namespace std;
|
|||||||
|
|
||||||
namespace rw {
|
namespace rw {
|
||||||
|
|
||||||
|
void (*defaultRenderCBs[rw::NUM_PLATFORMS])(Atomic*);
|
||||||
|
|
||||||
Pipeline::Pipeline(uint32 platform)
|
Pipeline::Pipeline(uint32 platform)
|
||||||
{
|
{
|
||||||
this->pluginID = 0;
|
this->pluginID = 0;
|
||||||
@ -50,9 +52,10 @@ ObjPipeline::uninstance(Atomic*)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ObjPipeline::render(Atomic*)
|
ObjPipeline::render(Atomic *atomic)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "This pipeline can't render\n");
|
if(defaultRenderCBs[rw::platform])
|
||||||
|
defaultRenderCBs[rw::platform](atomic);
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper functions
|
// helper functions
|
||||||
|
@ -237,9 +237,8 @@ Ps2Raster::create(Raster *raster)
|
|||||||
if(pageWidth*nPagW > raster->width ||
|
if(pageWidth*nPagW > raster->width ||
|
||||||
pageHeight*nPagH > raster->height)
|
pageHeight*nPagH > raster->height)
|
||||||
ras->tex1[0] = (ras->gsSize >> 6) - 4;
|
ras->tex1[0] = (ras->gsSize >> 6) - 4;
|
||||||
else{
|
else
|
||||||
ras->tex1[0] = ras->gsSize >> 6;
|
ras->tex1[0] = ras->gsSize >> 6;
|
||||||
}
|
|
||||||
nPagW = (paletteWidth + palettePagewidth-1)/palettePagewidth;
|
nPagW = (paletteWidth + palettePagewidth-1)/palettePagewidth;
|
||||||
nPagH = (paletteHeight + palettePageheight-1)/palettePageheight;
|
nPagH = (paletteHeight + palettePageheight-1)/palettePageheight;
|
||||||
ras->gsSize += (nPagW*nPagH*0x800)&~0x7FF;
|
ras->gsSize += (nPagW*nPagH*0x800)&~0x7FF;
|
||||||
|
@ -5,6 +5,13 @@
|
|||||||
|
|
||||||
#include "rwbase.h"
|
#include "rwbase.h"
|
||||||
#include "rwplugin.h"
|
#include "rwplugin.h"
|
||||||
|
#include "rwpipeline.h"
|
||||||
|
#include "rwobjects.h"
|
||||||
|
#include "rwps2.h"
|
||||||
|
#include "rwogl.h"
|
||||||
|
#include "rwxbox.h"
|
||||||
|
#include "rwd3d8.h"
|
||||||
|
#include "rwd3d9.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -23,6 +30,27 @@ int32 build = 0xFFFF;
|
|||||||
#endif
|
#endif
|
||||||
char *debugFile = NULL;
|
char *debugFile = NULL;
|
||||||
|
|
||||||
|
void
|
||||||
|
initialize(void)
|
||||||
|
{
|
||||||
|
// Atomic pipelines
|
||||||
|
ObjPipeline *defpipe = new ObjPipeline(PLATFORM_NULL);
|
||||||
|
for(uint i = 0; i < nelem(matFXGlobals.pipelines); i++)
|
||||||
|
defaultPipelines[i] = defpipe;
|
||||||
|
defaultPipelines[PLATFORM_PS2] =
|
||||||
|
ps2::makeDefaultPipeline();
|
||||||
|
defaultPipelines[PLATFORM_OGL] =
|
||||||
|
gl::makeDefaultPipeline();
|
||||||
|
defaultPipelines[PLATFORM_XBOX] =
|
||||||
|
xbox::makeDefaultPipeline();
|
||||||
|
defaultPipelines[PLATFORM_D3D8] =
|
||||||
|
d3d8::makeDefaultPipeline();
|
||||||
|
defaultPipelines[PLATFORM_D3D9] =
|
||||||
|
d3d9::makeDefaultPipeline();
|
||||||
|
|
||||||
|
Frame::dirtyList.init();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
matrixIdentity(float32 *mat)
|
matrixIdentity(float32 *mat)
|
||||||
{
|
{
|
||||||
|
@ -153,6 +153,8 @@ extern int build;
|
|||||||
extern int platform;
|
extern int platform;
|
||||||
extern char *debugFile;
|
extern char *debugFile;
|
||||||
|
|
||||||
|
void initialize(void);
|
||||||
|
|
||||||
void matrixIdentity(float32 *mat);
|
void matrixIdentity(float32 *mat);
|
||||||
int matrixEqual(float32 *m1, float32 *m2);
|
int matrixEqual(float32 *m1, float32 *m2);
|
||||||
int matrixIsIdentity(float32 *mat);
|
int matrixIsIdentity(float32 *mat);
|
||||||
|
@ -115,9 +115,20 @@ struct Object
|
|||||||
struct Frame : PluginBase<Frame>
|
struct Frame : PluginBase<Frame>
|
||||||
{
|
{
|
||||||
typedef Frame *(*Callback)(Frame *f, void *data);
|
typedef Frame *(*Callback)(Frame *f, void *data);
|
||||||
|
|
||||||
enum { ID = 0 };
|
enum { ID = 0 };
|
||||||
|
enum { // private flags
|
||||||
|
HIERARCHYSYNCLTM = 0x01,
|
||||||
|
HIERARCHYSYNCOBJ = 0x02,
|
||||||
|
HIERARCHYSYNC = HIERARCHYSYNCLTM | HIERARCHYSYNCOBJ,
|
||||||
|
SUBTREESYNCLTM = 0x04,
|
||||||
|
SUBTREESYNCOBJ = 0x08,
|
||||||
|
SUBTREESYNC = SUBTREESYNCLTM | SUBTREESYNCOBJ,
|
||||||
|
SYNCLTM = HIERARCHYSYNCLTM | SUBTREESYNCLTM,
|
||||||
|
SYNCOBJ = HIERARCHYSYNCOBJ | SUBTREESYNCOBJ,
|
||||||
|
};
|
||||||
|
|
||||||
Object object;
|
Object object;
|
||||||
|
LLLink inDirtyList;
|
||||||
LinkList objectList;
|
LinkList objectList;
|
||||||
float32 matrix[16];
|
float32 matrix[16];
|
||||||
float32 ltm[16];
|
float32 ltm[16];
|
||||||
@ -126,9 +137,7 @@ struct Frame : PluginBase<Frame>
|
|||||||
Frame *next;
|
Frame *next;
|
||||||
Frame *root;
|
Frame *root;
|
||||||
|
|
||||||
// temporary
|
static LinkList dirtyList;
|
||||||
int32 matflag;
|
|
||||||
bool dirty;
|
|
||||||
|
|
||||||
static Frame *create(void);
|
static Frame *create(void);
|
||||||
Frame *cloneHierarchy(void);
|
Frame *cloneHierarchy(void);
|
||||||
@ -140,9 +149,10 @@ struct Frame : PluginBase<Frame>
|
|||||||
Frame *getParent(void){
|
Frame *getParent(void){
|
||||||
return (Frame*)this->object.parent; }
|
return (Frame*)this->object.parent; }
|
||||||
int32 count(void);
|
int32 count(void);
|
||||||
void updateLTM(void);
|
float *getLTM(void);
|
||||||
void setDirty(void);
|
void updateObjects(void);
|
||||||
|
|
||||||
|
void syncHierarchyLTM(void);
|
||||||
void setHierarchyRoot(Frame *root);
|
void setHierarchyRoot(Frame *root);
|
||||||
Frame *cloneAndLink(Frame *clonedroot);
|
Frame *cloneAndLink(Frame *clonedroot);
|
||||||
void purgeClone(void);
|
void purgeClone(void);
|
||||||
@ -578,12 +588,15 @@ struct Clump;
|
|||||||
|
|
||||||
struct Atomic : PluginBase<Atomic>
|
struct Atomic : PluginBase<Atomic>
|
||||||
{
|
{
|
||||||
|
typedef void (*RenderCB)(Atomic *atomic);
|
||||||
enum { ID = 1 };
|
enum { ID = 1 };
|
||||||
|
|
||||||
ObjectWithFrame object;
|
ObjectWithFrame object;
|
||||||
Geometry *geometry;
|
Geometry *geometry;
|
||||||
Clump *clump;
|
Clump *clump;
|
||||||
LLLink inClump;
|
LLLink inClump;
|
||||||
ObjPipeline *pipeline;
|
ObjPipeline *pipeline;
|
||||||
|
RenderCB renderCB;
|
||||||
|
|
||||||
static Atomic *create(void);
|
static Atomic *create(void);
|
||||||
Atomic *clone(void);
|
Atomic *clone(void);
|
||||||
@ -598,8 +611,9 @@ struct Atomic : PluginBase<Atomic>
|
|||||||
Frame **frameList, int32 numframes);
|
Frame **frameList, int32 numframes);
|
||||||
uint32 streamGetSize(void);
|
uint32 streamGetSize(void);
|
||||||
ObjPipeline *getPipeline(void);
|
ObjPipeline *getPipeline(void);
|
||||||
|
void render(void) { this->renderCB(this); }
|
||||||
|
|
||||||
static void init(void);
|
static void defaultRenderCB(Atomic *atomic);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern ObjPipeline *defaultPipelines[NUM_PLATFORMS];
|
extern ObjPipeline *defaultPipelines[NUM_PLATFORMS];
|
||||||
|
@ -25,11 +25,13 @@ class ObjPipeline : public Pipeline
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ObjPipeline(uint32 platform) : Pipeline(platform) {}
|
ObjPipeline(uint32 platform) : Pipeline(platform) {}
|
||||||
virtual void instance(Atomic *atomic);
|
virtual void instance(Atomic *atomic); // TODO?: make these callbacks instead of virtual
|
||||||
virtual void uninstance(Atomic *atomic);
|
virtual void uninstance(Atomic *atomic); // TODO?: make these callbacks instead of virtual
|
||||||
virtual void render(Atomic *atomic);
|
virtual void render(Atomic *atomic); // TODO?: make these callbacks instead of virtual
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern void (*defaultRenderCBs[rw::NUM_PLATFORMS])(Atomic*);
|
||||||
|
|
||||||
void findMinVertAndNumVertices(uint16 *indices, uint32 numIndices, uint32 *minVert, int32 *numVertices);
|
void findMinVertAndNumVertices(uint16 *indices, uint32 numIndices, uint32 *minVert, int32 *numVertices);
|
||||||
|
|
||||||
// everything xbox, d3d8 and d3d9 may want to use
|
// everything xbox, d3d8 and d3d9 may want to use
|
||||||
|
Loading…
x
Reference in New Issue
Block a user