started implementing linked lists

This commit is contained in:
aap 2016-01-11 11:23:26 +01:00
parent 0aadf8c3c9
commit efd41771a0
10 changed files with 188 additions and 150 deletions

View File

@ -58,6 +58,7 @@ Global
{30552BB0-3B19-49A4-ABF4-87CF68AF9E38}.Release|x64.ActiveCfg = Release|x64 {30552BB0-3B19-49A4-ABF4-87CF68AF9E38}.Release|x64.ActiveCfg = Release|x64
{30552BB0-3B19-49A4-ABF4-87CF68AF9E38}.Release|x64.Build.0 = Release|x64 {30552BB0-3B19-49A4-ABF4-87CF68AF9E38}.Release|x64.Build.0 = Release|x64
{B487F101-0C2B-4F99-A1E0-B0B0C0F3FE7E}.Debug - null|Win32.ActiveCfg = Debug - null|Win32 {B487F101-0C2B-4F99-A1E0-B0B0C0F3FE7E}.Debug - null|Win32.ActiveCfg = Debug - null|Win32
{B487F101-0C2B-4F99-A1E0-B0B0C0F3FE7E}.Debug - null|Win32.Build.0 = Debug - null|Win32
{B487F101-0C2B-4F99-A1E0-B0B0C0F3FE7E}.Debug - null|x64.ActiveCfg = Debug - null|x64 {B487F101-0C2B-4F99-A1E0-B0B0C0F3FE7E}.Debug - null|x64.ActiveCfg = Debug - null|x64
{B487F101-0C2B-4F99-A1E0-B0B0C0F3FE7E}.Debug|Win32.ActiveCfg = Debug|Win32 {B487F101-0C2B-4F99-A1E0-B0B0C0F3FE7E}.Debug|Win32.ActiveCfg = Debug|Win32
{B487F101-0C2B-4F99-A1E0-B0B0C0F3FE7E}.Debug|x64.ActiveCfg = Debug|x64 {B487F101-0C2B-4F99-A1E0-B0B0C0F3FE7E}.Debug|x64.ActiveCfg = Debug|x64
@ -66,6 +67,7 @@ Global
{B487F101-0C2B-4F99-A1E0-B0B0C0F3FE7E}.Release|Win32.Build.0 = Release|Win32 {B487F101-0C2B-4F99-A1E0-B0B0C0F3FE7E}.Release|Win32.Build.0 = Release|Win32
{B487F101-0C2B-4F99-A1E0-B0B0C0F3FE7E}.Release|x64.ActiveCfg = Release|x64 {B487F101-0C2B-4F99-A1E0-B0B0C0F3FE7E}.Release|x64.ActiveCfg = Release|x64
{85F56A7D-6EA2-4B9B-806A-87AF6C577FDF}.Debug - null|Win32.ActiveCfg = Debug - null|Win32 {85F56A7D-6EA2-4B9B-806A-87AF6C577FDF}.Debug - null|Win32.ActiveCfg = Debug - null|Win32
{85F56A7D-6EA2-4B9B-806A-87AF6C577FDF}.Debug - null|Win32.Build.0 = Debug - null|Win32
{85F56A7D-6EA2-4B9B-806A-87AF6C577FDF}.Debug - null|x64.ActiveCfg = Debug - null|x64 {85F56A7D-6EA2-4B9B-806A-87AF6C577FDF}.Debug - null|x64.ActiveCfg = Debug - null|x64
{85F56A7D-6EA2-4B9B-806A-87AF6C577FDF}.Debug|Win32.ActiveCfg = Debug|Win32 {85F56A7D-6EA2-4B9B-806A-87AF6C577FDF}.Debug|Win32.ActiveCfg = Debug|Win32
{85F56A7D-6EA2-4B9B-806A-87AF6C577FDF}.Debug|x64.ActiveCfg = Debug|x64 {85F56A7D-6EA2-4B9B-806A-87AF6C577FDF}.Debug|x64.ActiveCfg = Debug|x64
@ -92,6 +94,7 @@ Global
{E5D477C8-4CAF-43BF-B7E3-6689503D469F}.Release|Win32.Build.0 = Release|Win32 {E5D477C8-4CAF-43BF-B7E3-6689503D469F}.Release|Win32.Build.0 = Release|Win32
{E5D477C8-4CAF-43BF-B7E3-6689503D469F}.Release|x64.ActiveCfg = Release|x64 {E5D477C8-4CAF-43BF-B7E3-6689503D469F}.Release|x64.ActiveCfg = Release|x64
{403C35A9-6D06-4261-B305-9ED000F00136}.Debug - null|Win32.ActiveCfg = Debug - null|Win32 {403C35A9-6D06-4261-B305-9ED000F00136}.Debug - null|Win32.ActiveCfg = Debug - null|Win32
{403C35A9-6D06-4261-B305-9ED000F00136}.Debug - null|Win32.Build.0 = Debug - null|Win32
{403C35A9-6D06-4261-B305-9ED000F00136}.Debug - null|x64.ActiveCfg = Debug - null|x64 {403C35A9-6D06-4261-B305-9ED000F00136}.Debug - null|x64.ActiveCfg = Debug - null|x64
{403C35A9-6D06-4261-B305-9ED000F00136}.Debug|Win32.ActiveCfg = Debug|Win32 {403C35A9-6D06-4261-B305-9ED000F00136}.Debug|Win32.ActiveCfg = Debug|Win32
{403C35A9-6D06-4261-B305-9ED000F00136}.Debug|x64.ActiveCfg = Debug|x64 {403C35A9-6D06-4261-B305-9ED000F00136}.Debug|x64.ActiveCfg = Debug|x64

View File

@ -21,7 +21,8 @@ namespace rw {
Frame::Frame(void) Frame::Frame(void)
{ {
this->parent = NULL; this->object.init(0, 0);
this->objectList.init();
this->child = NULL; this->child = NULL;
this->next = NULL; this->next = NULL;
this->root = NULL; this->root = NULL;
@ -58,7 +59,7 @@ Frame::addChild(Frame *child)
f->next = child; f->next = child;
} }
child->next = NULL; child->next = NULL;
child->parent = this; child->object.parent = this;
child->root = this->root; child->root = this->root;
return this; return this;
} }
@ -66,7 +67,7 @@ Frame::addChild(Frame *child)
Frame* Frame*
Frame::removeChild(void) Frame::removeChild(void)
{ {
Frame *parent = (Frame*)this->parent; Frame *parent = (Frame*)this->object.parent;
if(parent->child == this) if(parent->child == this)
parent->child = this->next; parent->child = this->next;
else{ else{
@ -78,7 +79,7 @@ Frame::removeChild(void)
found: found:
f->next = f->next->next; f->next = f->next->next;
} }
this->parent = NULL; this->object.parent = NULL;
this->next = this->root = NULL; this->next = this->root = NULL;
return this; return this;
} }
@ -112,7 +113,7 @@ Frame::updateLTM(void)
{ {
if(!this->dirty) if(!this->dirty)
return; return;
Frame *parent = (Frame*)this->parent; Frame *parent = (Frame*)this->object.parent;
if(parent){ if(parent){
parent->updateLTM(); parent->updateLTM();
matrixMult(this->ltm, parent->ltm, this->matrix); matrixMult(this->ltm, parent->ltm, this->matrix);
@ -163,6 +164,7 @@ makeFrameList(Frame *frame, Frame **flist)
Clump::Clump(void) Clump::Clump(void)
{ {
this->object.init(2, 0);
this->numAtomics = 0; this->numAtomics = 0;
this->numLights = 0; this->numLights = 0;
this->numCameras = 0; this->numCameras = 0;
@ -206,7 +208,7 @@ Clump::streamRead(Stream *stream)
Frame **frameList; Frame **frameList;
int32 numFrames; int32 numFrames;
clump->frameListStreamRead(stream, &frameList, &numFrames); clump->frameListStreamRead(stream, &frameList, &numFrames);
clump->parent = (void*)frameList[0]; clump->object.parent = (void*)frameList[0];
Geometry **geometryList = 0; Geometry **geometryList = 0;
if(version >= 0x30400){ if(version >= 0x30400){
@ -242,7 +244,7 @@ Clump::streamRead(Stream *stream)
frm = stream->readI32(); frm = stream->readI32();
assert(findChunk(stream, ID_LIGHT, NULL, NULL)); assert(findChunk(stream, ID_LIGHT, NULL, NULL));
clump->lightList[i] = Light::streamRead(stream); clump->lightList[i] = Light::streamRead(stream);
clump->lightList[i]->frame = frameList[frm]; clump->lightList[i]->setFrame(frameList[frm]);
clump->lightList[i]->clump = clump; clump->lightList[i]->clump = clump;
} }
@ -262,9 +264,9 @@ Clump::streamWrite(Stream *stream)
writeChunkHeader(stream, ID_STRUCT, size); writeChunkHeader(stream, ID_STRUCT, size);
stream->write(buf, size); stream->write(buf, size);
int32 numFrames = ((Frame*)this->parent)->count(); int32 numFrames = ((Frame*)this->object.parent)->count();
Frame **flist = new Frame*[numFrames]; Frame **flist = new Frame*[numFrames];
makeFrameList((Frame*)this->parent, flist); makeFrameList((Frame*)this->object.parent, flist);
this->frameListStreamWrite(stream, flist, numFrames); this->frameListStreamWrite(stream, flist, numFrames);
@ -285,7 +287,7 @@ Clump::streamWrite(Stream *stream)
for(int32 i = 0; i < this->numLights; i++){ for(int32 i = 0; i < this->numLights; i++){
Light *l = this->lightList[i]; Light *l = this->lightList[i];
int frm = findPointer((void*)l->frame, (void**)flist,numFrames); int frm = findPointer((void*)l->object.parent, (void**)flist,numFrames);
if(frm < 0) if(frm < 0)
return false; return false;
writeChunkHeader(stream, ID_STRUCT, 4); writeChunkHeader(stream, ID_STRUCT, 4);
@ -317,9 +319,9 @@ Clump::streamGetSize(void)
size += 8; // numLights, numCameras size += 8; // numLights, numCameras
// frame list // frame list
int32 numFrames = ((Frame*)this->parent)->count(); int32 numFrames = ((Frame*)this->object.parent)->count();
size += 12 + 12 + 4 + numFrames*(sizeof(FrameStreamData)+12); size += 12 + 12 + 4 + numFrames*(sizeof(FrameStreamData)+12);
sizeCB((Frame*)this->parent, (void*)&size); sizeCB((Frame*)this->object.parent, (void*)&size);
if(rw::version >= 0x30400){ if(rw::version >= 0x30400){
// geometry list // geometry list
@ -409,7 +411,7 @@ Clump::frameListStreamWrite(Stream *stream, Frame **frameList, int32 numFrames)
buf.pos[0] = f->matrix[12]; buf.pos[0] = f->matrix[12];
buf.pos[1] = f->matrix[13]; buf.pos[1] = f->matrix[13];
buf.pos[2] = f->matrix[14]; buf.pos[2] = f->matrix[14];
buf.parent = findPointer((void*)f->parent, (void**)frameList, buf.parent = findPointer((void*)f->object.parent, (void**)frameList,
numFrames); numFrames);
buf.matflag = f->matflag; buf.matflag = f->matflag;
stream->write(&buf, sizeof(buf)); stream->write(&buf, sizeof(buf));
@ -424,7 +426,7 @@ Clump::frameListStreamWrite(Stream *stream, Frame **frameList, int32 numFrames)
Atomic::Atomic(void) Atomic::Atomic(void)
{ {
this->frame = NULL; this->object.init(1, 0);
this->geometry = NULL; this->geometry = NULL;
this->pipeline = NULL; this->pipeline = NULL;
constructPlugins(); constructPlugins();
@ -453,7 +455,7 @@ Atomic::streamReadClump(Stream *stream,
assert(findChunk(stream, ID_STRUCT, NULL, &version)); assert(findChunk(stream, ID_STRUCT, NULL, &version));
stream->read(buf, version < 0x30400 ? 12 : 16); stream->read(buf, version < 0x30400 ? 12 : 16);
Atomic *atomic = new Atomic; Atomic *atomic = new Atomic;
atomic->frame = frameList[buf[0]]; atomic->setFrame(frameList[buf[0]]);
if(version < 0x30400){ if(version < 0x30400){
assert(findChunk(stream, ID_GEOMETRY, NULL, NULL)); assert(findChunk(stream, ID_GEOMETRY, NULL, NULL));
atomic->geometry = Geometry::streamRead(stream); atomic->geometry = Geometry::streamRead(stream);
@ -476,7 +478,7 @@ Atomic::streamWriteClump(Stream *stream, Frame **frameList, int32 numFrames)
return false; return false;
writeChunkHeader(stream, ID_ATOMIC, this->streamGetSize()); writeChunkHeader(stream, ID_ATOMIC, this->streamGetSize());
writeChunkHeader(stream, ID_STRUCT, rw::version < 0x30400 ? 12 : 16); writeChunkHeader(stream, ID_STRUCT, rw::version < 0x30400 ? 12 : 16);
buf[0] = findPointer((void*)this->frame, (void**)frameList, numFrames); buf[0] = findPointer((void*)this->object.parent, (void**)frameList, numFrames);
if(version < 0x30400){ if(version < 0x30400){
stream->write(buf, sizeof(int[3])); stream->write(buf, sizeof(int[3]));
@ -576,9 +578,18 @@ registerAtomicRightsPlugin(void)
// Light // Light
// //
Light::Light(void) Light::Light(int32 type)
{ {
this->frame = NULL; this->object.init(3, type);
this->radius = 0.0f;
this->color[0] = 1.0f;
this->color[1] = 1.0f;
this->color[2] = 1.0f;
this->color[3] = 1.0f;
this->minusCosAngle = 1.0f;
this->object.privateFlags = 1;
this->object.flags = 1 | 2;
Clump *clump;
constructPlugins(); constructPlugins();
} }
@ -607,16 +618,15 @@ Light::streamRead(Stream *stream)
{ {
LightChunkData buf; LightChunkData buf;
assert(findChunk(stream, ID_STRUCT, NULL, NULL)); assert(findChunk(stream, ID_STRUCT, NULL, NULL));
Light *light = new Light;
stream->read(&buf, sizeof(LightChunkData)); stream->read(&buf, sizeof(LightChunkData));
Light *light = new Light(buf.type);
light->radius = buf.radius; light->radius = buf.radius;
light->color[0] = buf.red; light->color[0] = buf.red;
light->color[1] = buf.green; light->color[1] = buf.green;
light->color[2] = buf.blue; light->color[2] = buf.blue;
light->color[3] = 1.0f; light->color[3] = 1.0f;
light->minusCosAngle = buf.minusCosAngle; light->minusCosAngle = buf.minusCosAngle;
light->flags = (uint8)buf.flags; light->object.flags = (uint8)buf.flags;
light->subType = (uint8)buf.type;
light->streamReadPlugins(stream); light->streamReadPlugins(stream);
return light; return light;
@ -633,8 +643,8 @@ Light::streamWrite(Stream *stream)
buf.green = this->color[1]; buf.green = this->color[1];
buf.blue = this->color[2]; buf.blue = this->color[2];
buf.minusCosAngle = this->minusCosAngle; buf.minusCosAngle = this->minusCosAngle;
buf.flags = this->flags; buf.flags = this->object.flags;
buf.type = this->subType; buf.type = this->object.subType;
stream->write(&buf, sizeof(LightChunkData)); stream->write(&buf, sizeof(LightChunkData));
this->streamWritePlugins(stream); this->streamWritePlugins(stream);

View File

@ -17,6 +17,7 @@ namespace rw {
Geometry::Geometry(int32 numVerts, int32 numTris, uint32 flags) Geometry::Geometry(int32 numVerts, int32 numTris, uint32 flags)
{ {
this->object.init(8, 0);
this->geoflags = flags & 0xFF00FFFF; this->geoflags = flags & 0xFF00FFFF;
this->numTexCoordSets = (flags & 0xFF0000) >> 16; this->numTexCoordSets = (flags & 0xFF0000) >> 16;
if(this->numTexCoordSets == 0) if(this->numTexCoordSets == 0)

View File

@ -31,6 +31,7 @@ TexDictionary *currentTexDictionary;
TexDictionary::TexDictionary(void) TexDictionary::TexDictionary(void)
{ {
this->object.init(6, 0);
this->first = NULL; this->first = NULL;
} }

View File

@ -1,17 +1,66 @@
namespace rw { namespace rw {
struct LLLink
{
LLLink *next;
LLLink *prev;
void init(void){
this->next = NULL;
this->prev = NULL;
}
void remove(void){
this->prev->next = this->next;
this->next->prev = this->prev;
}
};
#define LLLinkGetData(linkvar,type,entry) \
((type*)(((uint8*)(linkvar))-offsetof(type,entry)))
struct LinkList
{
LLLink link;
void init(void){
this->link.next = &this->link;
this->link.prev = &this->link;
}
bool32 isEmpty(void){
return this->link.next == &this->link;
}
void add(LLLink *link){
link->next = this->link.next;
link->prev = &this->link;
this->link.next->prev = link;
this->link.next = link;
}
LLLink *end(void){
return &this->link;
}
};
struct Object struct Object
{ {
uint8 type; uint8 type;
uint8 subType; uint8 subType;
uint8 flags; uint8 flags;
uint8 privateFlags;
void *parent; void *parent;
void init(uint8 type, uint8 subType){
this->type = type;
this->subType = subType;
this->flags = 0;
this->privateFlags = 0;
this->parent = NULL;
}
}; };
// TODO: missing: list of attached objects struct Frame : PluginBase<Frame>
struct Frame : PluginBase<Frame>, Object
{ {
typedef Frame *(*Callback)(Frame *f, void *data); typedef Frame *(*Callback)(Frame *f, void *data);
Object object;
LinkList objectList;
float32 matrix[16]; float32 matrix[16];
float32 ltm[16]; float32 ltm[16];
@ -36,6 +85,18 @@ struct Frame : PluginBase<Frame>, Object
Frame **makeFrameList(Frame *frame, Frame **flist); Frame **makeFrameList(Frame *frame, Frame **flist);
struct ObjectWithFrame : Object
{
LLLink inFrame;
void setFrame(Frame *f){
if(this->parent)
this->inFrame.remove();
this->parent = f;
if(f)
f->objectList.add(&this->inFrame);
}
};
struct HAnimKeyFrame struct HAnimKeyFrame
{ {
HAnimKeyFrame *prev; HAnimKeyFrame *prev;
@ -168,10 +229,11 @@ struct NativeRaster
// TODO: link into texdict // TODO: link into texdict
struct Texture : PluginBase<Texture> struct Texture : PluginBase<Texture>
{ {
Raster *raster;
// TODO: pointer to txd and link
char name[32]; char name[32];
char mask[32]; char mask[32];
uint32 filterAddressing; // VVVVUUUU FFFFFFFF uint32 filterAddressing; // VVVVUUUU FFFFFFFF
Raster *raster;
int32 refCount; int32 refCount;
// temporary - pointer to next tex in dictionary // temporary - pointer to next tex in dictionary
@ -319,9 +381,10 @@ struct InstanceDataHeader
uint32 platform; uint32 platform;
}; };
struct Geometry : PluginBase<Geometry>, Object struct Geometry : PluginBase<Geometry>
{ {
uint32 geoflags; Object object;
uint32 geoflags; // TODO: rename
int32 numTriangles; int32 numTriangles;
int32 numVertices; int32 numVertices;
int32 numMorphTargets; int32 numMorphTargets;
@ -333,6 +396,7 @@ struct Geometry : PluginBase<Geometry>, Object
MorphTarget *morphTargets; MorphTarget *morphTargets;
// TODO: struct
int32 numMaterials; int32 numMaterials;
Material **materialList; Material **materialList;
@ -399,25 +463,28 @@ void registerSkinPlugin(void);
struct Clump; struct Clump;
struct Light : PluginBase<Light>, Object struct Light : PluginBase<Light>
{ {
Frame *frame; ObjectWithFrame object;
float32 radius; float32 radius;
float32 color[4]; float32 color[4];
float32 minusCosAngle; float32 minusCosAngle;
// clump link handled by plugin in RW
Clump *clump; Clump *clump;
Light(void); Light(int32 type);
Light(Light *l); Light(Light *l);
~Light(void); ~Light(void);
void setFrame(Frame *f) { this->object.setFrame(f); }
static Light *streamRead(Stream *stream); static Light *streamRead(Stream *stream);
bool streamWrite(Stream *stream); bool streamWrite(Stream *stream);
uint32 streamGetSize(void); uint32 streamGetSize(void);
}; };
struct Atomic : PluginBase<Atomic>, Object struct Atomic : PluginBase<Atomic>
{ {
Frame *frame; ObjectWithFrame object;
Geometry *geometry; Geometry *geometry;
Clump *clump; Clump *clump;
ObjPipeline *pipeline; ObjPipeline *pipeline;
@ -425,10 +492,11 @@ struct Atomic : PluginBase<Atomic>, Object
Atomic(void); Atomic(void);
Atomic(Atomic *a); Atomic(Atomic *a);
~Atomic(void); ~Atomic(void);
void setFrame(Frame *f) { this->object.setFrame(f); }
static Atomic *streamReadClump(Stream *stream, static Atomic *streamReadClump(Stream *stream,
Frame **frameList, Geometry **geometryList); Frame **frameList, Geometry **geometryList);
bool streamWriteClump(Stream *stream, bool streamWriteClump(Stream *stream,
Frame **frameList, int32 numFrames); Frame **frameList, int32 numFrames);
uint32 streamGetSize(void); uint32 streamGetSize(void);
ObjPipeline *getPipeline(void); ObjPipeline *getPipeline(void);
@ -439,8 +507,9 @@ extern ObjPipeline *defaultPipelines[NUM_PLATFORMS];
void registerAtomicRightsPlugin(void); void registerAtomicRightsPlugin(void);
struct Clump : PluginBase<Clump>, Object struct Clump : PluginBase<Clump>
{ {
Object object;
int32 numAtomics; int32 numAtomics;
Atomic **atomicList; Atomic **atomicList;
int32 numLights; int32 numLights;
@ -461,6 +530,7 @@ struct Clump : PluginBase<Clump>, Object
struct TexDictionary : PluginBase<TexDictionary> struct TexDictionary : PluginBase<TexDictionary>
{ {
Object object;
Texture *first; Texture *first;
TexDictionary(void); TexDictionary(void);

View File

@ -11,37 +11,6 @@
using namespace std; using namespace std;
using namespace rw; using namespace rw;
Frame*
findHierCB(Frame *f, void *p)
{
HAnimData *hanim = PLUGINOFFSET(HAnimData, f, hAnimOffset);
if(hanim->hierarchy){
*(HAnimHierarchy**)p = hanim->hierarchy;
return NULL;
}
f->forAllChildren(findHierCB, p);
return f;
}
HAnimHierarchy*
getHierarchy(Clump *c)
{
HAnimHierarchy *hier = NULL;
findHierCB((Frame*)c->parent, &hier);
return hier;
}
void
fixLcsHier(HAnimHierarchy *hier)
{
hier->maxInterpKeyFrameSize = findAnimInterpolatorInfo(1)->keyFrameSize;
for(int32 i = 0; i < hier->numNodes; i++){
int32 id = hier->nodeInfo[i].id;
if(id == 255) hier->nodeInfo[i].id = -1;
else if(id > 0x80) hier->nodeInfo[i].id |= 0x1300;
}
}
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
@ -54,10 +23,6 @@ main(int argc, char *argv[])
rw::platform = PLATFORM_D3D8; rw::platform = PLATFORM_D3D8;
// rw::version = 0x30200; // rw::version = 0x30200;
int lcs = 1;
matFXGlobals.hack = lcs;
skinGlobals.forceSkipUsedBones = lcs;
gta::attachPlugins(); gta::attachPlugins();
rw::Clump *c; rw::Clump *c;
@ -104,25 +69,10 @@ main(int argc, char *argv[])
readChunkHeaderInfo(&in, &header); readChunkHeaderInfo(&in, &header);
} }
assert(header.type == ID_CLUMP); assert(header.type == ID_CLUMP);
if(lcs) c = Clump::streamRead(&in);
c = clumpStreamReadRsl(&in);
else
c = Clump::streamRead(&in);
assert(c != NULL); assert(c != NULL);
} }
if(lcs){
HAnimHierarchy *hier = getHierarchy(c);
if(hier)
fixLcsHier(hier);
for(int32 i = 0; i < c->numAtomics; i++){
Skin *skin = *PLUGINOFFSET(Skin*, c->atomicList[i]->geometry, skinGlobals.offset);
convertRslGeometry(c->atomicList[i]->geometry);
if(skin)
c->atomicList[i]->pipeline = skinGlobals.pipelines[rw::platform];
}
}
if(rw::version == 0){ if(rw::version == 0){
rw::version = header.version; rw::version = header.version;
rw::build = header.build; rw::build = header.build;
@ -159,10 +109,7 @@ main(int argc, char *argv[])
out.open(argv[2], "wb"); out.open(argv[2], "wb");
else else
out.open("out.dff", "wb"); out.open("out.dff", "wb");
// if(lcs) c->streamWrite(&out);
// clumpStreamWriteRsl(&out, c);
// else
c->streamWrite(&out);
out.close(); out.close();
} }

View File

@ -142,6 +142,7 @@
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile> </ClCompile>
<Link> <Link>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>

View File

@ -28,17 +28,11 @@ RslMatrixSetIdentity(RslMatrix *matrix)
void void
rslObjectHasFrameSetFrame(RslObjectHasFrame *object, RslFrame *f) rslObjectHasFrameSetFrame(RslObjectHasFrame *object, RslFrame *f)
{ {
if(object->object.parent){ if(object->object.parent)
object->lFrame.prev->next = object->lFrame.next; rslLinkListRemoveLLLink(&object->lFrame);
object->lFrame.next->prev = object->lFrame.prev; rslObjectSetParent(object, f);
}
object->object.parent = f;
if(f){ if(f){
object->lFrame.prev = &f->objectList.link; rslLinkListAddLLLink(&f->objectList, &object->lFrame);
object->lFrame.next = f->objectList.link.next;
f->objectList.link.next->prev = &object->lFrame;
f->objectList.link.next = &object->lFrame;
f->root->object.privateFlags |= 1; f->root->object.privateFlags |= 1;
f->object.privateFlags |= 2; f->object.privateFlags |= 2;
} }
@ -49,8 +43,7 @@ RslFrameCreate(void)
{ {
RslFrame *f = new RslFrame; RslFrame *f = new RslFrame;
rslObjectInitialize(&f->object, 0, 0); rslObjectInitialize(&f->object, 0, 0);
f->objectList.link.prev = &f->objectList.link; rslLinkListInitialize(&f->objectList);
f->objectList.link.next = &f->objectList.link;
RslMatrixSetIdentity(&f->modelling); RslMatrixSetIdentity(&f->modelling);
RslMatrixSetIdentity(&f->ltm); RslMatrixSetIdentity(&f->ltm);
f->child = NULL; f->child = NULL;
@ -327,8 +320,7 @@ RslClumpCreate(void)
{ {
RslClump *clump = new RslClump; RslClump *clump = new RslClump;
rslObjectInitialize(&clump->object, 2, 0); rslObjectInitialize(&clump->object, 2, 0);
clump->atomicList.link.prev = &clump->atomicList.link; rslLinkListInitialize(&clump->atomicList);
clump->atomicList.link.next = &clump->atomicList.link;
return clump; return clump;
} }
@ -373,10 +365,7 @@ RslClumpStreamRead(Stream *stream)
RslClump* RslClump*
RslClumpAddAtomic(RslClump *clump, RslAtomic *a) RslClumpAddAtomic(RslClump *clump, RslAtomic *a)
{ {
a->inClumpLink.prev = &clump->atomicList.link; rslLinkListAddLLLink(&clump->atomicList, &a->inClumpLink);
a->inClumpLink.next = clump->atomicList.link.next;
clump->atomicList.link.next->prev = &a->inClumpLink;
clump->atomicList.link.next = &a->inClumpLink;
a->clump = clump; a->clump = clump;
return clump; return clump;
} }
@ -387,7 +376,7 @@ RslClumpForAllAtomics(RslClump *clump, RslAtomicCallBack callback, void *pData)
RslAtomic *a; RslAtomic *a;
RslLLLink *link; RslLLLink *link;
for(link = rslLLLinkGetNext(&clump->atomicList.link); for(link = rslLLLinkGetNext(&clump->atomicList.link);
link != &clump->atomicList.link; link != rslLinkListGetTerminator(&clump->atomicList);
link = link->next){ link = link->next){
a = rslLLLinkGetData(link, RslAtomic, inClumpLink); a = rslLLLinkGetData(link, RslAtomic, inClumpLink);
if(callback(a, pData) == NULL) if(callback(a, pData) == NULL)
@ -402,7 +391,7 @@ RslClumpGetNumAtomics(RslClump *clump)
int32 n = 0; int32 n = 0;
RslLLLink *link; RslLLLink *link;
for(link = rslLLLinkGetNext(&clump->atomicList.link); for(link = rslLLLinkGetNext(&clump->atomicList.link);
link != &clump->atomicList.link; link != rslLinkListGetTerminator(&clump->atomicList);
link = link->next) link = link->next)
n++; n++;
return n; return n;
@ -561,23 +550,17 @@ RslTexDictionaryCreate(void)
RslTexDictionary *dict = new RslTexDictionary; RslTexDictionary *dict = new RslTexDictionary;
memset(dict, 0, sizeof(RslTexDictionary)); memset(dict, 0, sizeof(RslTexDictionary));
rslObjectInitialize(&dict->object, 6, 0); rslObjectInitialize(&dict->object, 6, 0);
dict->texturesInDict.link.prev = &dict->texturesInDict.link; rslLinkListInitialize(&dict->texturesInDict);
dict->texturesInDict.link.next = &dict->texturesInDict.link;
return dict; return dict;
} }
RslTexture* RslTexture*
RslTexDictionaryAddTexture(RslTexDictionary *dict, RslTexture *tex) RslTexDictionaryAddTexture(RslTexDictionary *dict, RslTexture *tex)
{ {
if(tex->dict){ if(tex->dict)
tex->lInDictionary.prev->next = tex->lInDictionary.next; rslLinkListRemoveLLLink(&tex->lInDictionary);
tex->lInDictionary.next->prev = tex->lInDictionary.prev;
}
tex->dict = dict; tex->dict = dict;
tex->lInDictionary.prev = &dict->texturesInDict.link; rslLinkListAddLLLink(&dict->texturesInDict, &tex->lInDictionary);
tex->lInDictionary.next = dict->texturesInDict.link.next;
dict->texturesInDict.link.next->prev = &tex->lInDictionary;
dict->texturesInDict.link.next = &tex->lInDictionary;
return tex; return tex;
} }
@ -587,7 +570,7 @@ RslTexDictionaryForAllTextures(RslTexDictionary *dict, RslTextureCallBack fpCall
RslTexture *t; RslTexture *t;
RslLLLink *link; RslLLLink *link;
for(link = rslLLLinkGetNext(&dict->texturesInDict.link); for(link = rslLLLinkGetNext(&dict->texturesInDict.link);
link != &dict->texturesInDict.link; link != rslLinkListGetTerminator(&dict->texturesInDict);
link = link->next){ link = link->next){
t = rslLLLinkGetData(link, RslTexture, lInDictionary); t = rslLLLinkGetData(link, RslTexture, lInDictionary);
if(fpCallBack(t, pData) == NULL) if(fpCallBack(t, pData) == NULL)

View File

@ -75,26 +75,43 @@ struct RslLLLink
RslLLLink *prev; RslLLLink *prev;
}; };
#define rslLLLinkGetData(linkvar,type,entry) \
((type*)(((uint8*)(linkvar))-offsetof(type,entry)))
#define rslLLLinkGetNext(linkvar) \
((linkvar)->next)
#define rslLLLinkGetPrevious(linkvar) \
((linkvar)->prev)
#define rslLLLinkInitialize(linkvar) \
((linkvar)->prev = (RslLLLink*)NULL, \
(linkvar)->next = (RslLLLink*)NULL)
#define rslLLLinkAttached(linkvar) \
((linkvar)->next)
struct RslLinkList struct RslLinkList
{ {
RslLLLink link; RslLLLink link;
}; };
#define rslLLLinkGetData(linkvar,type,entry) \ #define rslLinkListInitialize(list) \
((type *)(((uint8 *)(linkvar))-offsetof(type,entry))) ((list)->link.next = ((RslLLLink*)(list)), \
(list)->link.prev = ((RslLLLink*)(list)))
#define rslLinkListEmpty(list) \
(((list)->link.next) == (&(list)->link))
#define rslLinkListAddLLLink(list, linkvar) \
((linkvar)->next = (list)->link.next, \
(linkvar)->prev = (&(list)->link), \
((list)->link.next)->prev = (linkvar), \
(list)->link.next = (linkvar) )
#define rslLinkListRemoveLLLink(linkvar) \
(((linkvar)->prev)->next = (linkvar)->next, \
((linkvar)->next)->prev = (linkvar)->prev)
#define rslLinkListGetFirstLLLink(list) \
((list)->link.next)
#define rslLinkListGetLastLLLink(list) \
((list)->link.prev)
#define rslLinkListGetTerminator(list) \
(&((list)->link))
#define rslLLLinkGetNext(linkvar) \
((linkvar)->next)
#define rslLLLinkGetPrevious(linkvar) \
((linkvar)->prev)
#define rslLLLinkInitialize(linkvar) \
( (linkvar)->prev = (RslLLLink *)NULL, \
(linkvar)->next = (RslLLLink *)NULL )
#define rslLLLinkAttached(linkvar) \
((linkvar)->next)
struct RslObject { struct RslObject {
uint8 type; uint8 type;

View File

@ -407,7 +407,7 @@ convertClump(RslClump *c)
if(parent >= 0) if(parent >= 0)
rwframes[parent]->addChild(rwf); rwframes[parent]->addChild(rwf);
} }
rwc->parent = rwframes[0]; rwc->object.parent = rwframes[0];
rwc->numAtomics = RslClumpGetNumAtomics(c); rwc->numAtomics = RslClumpGetNumAtomics(c);
rwc->atomicList = new Atomic*[rwc->numAtomics]; rwc->atomicList = new Atomic*[rwc->numAtomics];
@ -418,7 +418,7 @@ convertClump(RslClump *c)
rwa = convertAtomic(alist[i]); rwa = convertAtomic(alist[i]);
rwc->atomicList[i] = rwa; rwc->atomicList[i] = rwa;
int32 fi = findPointer(alist[i]->object.object.parent, (void**)frameList.frames, frameList.numFrames); int32 fi = findPointer(alist[i]->object.object.parent, (void**)frameList.frames, frameList.numFrames);
rwa->frame = rwframes[fi]; rwa->object.parent = rwframes[fi];
rwa->clump = rwc; rwa->clump = rwc;
} }
@ -823,14 +823,14 @@ main(int argc, char *argv[])
rslstr->relocate(); rslstr->relocate();
bool32 largefile; bool32 largefile;
largefile = rslstr->dataSize > 0x100000; largefile = rslstr->dataSize > 0x1000000;
if(rslstr->ident == WRLD_IDENT && largefile){ // hack if(rslstr->ident == WRLD_IDENT && largefile){ // hack
world = (World*)rslstr->data; world = (World*)rslstr->data;
int len = strlen(argv[1])+1; int len = strlen(argv[0])+1;
char filename[1024]; char filename[1024];
strncpy(filename, argv[1], len); strncpy(filename, argv[0], len);
filename[len-3] = 'i'; filename[len-3] = 'i';
filename[len-2] = 'm'; filename[len-2] = 'm';
filename[len-1] = 'g'; filename[len-1] = 'g';
@ -874,16 +874,21 @@ main(int argc, char *argv[])
stream.close(); stream.close();
}else if(rslstr->ident == WRLD_IDENT){ // sector }else if(rslstr->ident == WRLD_IDENT){ // sector
sector = (Sector*)rslstr->data; sector = (Sector*)rslstr->data;
printf("resources\n"); fprintf(stderr, "%d\n",sector->unk1);
for(uint32 i = 0; i < sector->numResources; i++){ //printf("resources\n");
OverlayResource *r = &sector->resources[i]; //for(uint32 i = 0; i < sector->numResources; i++){
printf(" %d %p\n", r->id, r->raw); // OverlayResource *r = &sector->resources[i];
} // printf(" %d %p\n", r->id, r->raw);
printf("placement\n"); //}
//printf("placement\n");
if(sector->unk1 == 0)
return 0;
Placement *p; Placement *p;
for(p = sector->sectionA; p < sector->sectionEnd; p++){ //for(p = sector->sectionA; p < sector->sectionEnd; p++){
printf(" %d, %d, %f %f %f\n", p->id &0x7FFF, p->resId, p->matrix[12], p->matrix[13], p->matrix[14]); // printf(" %d, %d, %f %f %f\n", p->id &0x7FFF, p->resId, p->matrix[12], p->matrix[13], p->matrix[14]);
} //}
for(p = sector->sectionA; p < sector->sectionEnd; p++)
printf("%f %f %f\n", p->matrix[12], p->matrix[13], p->matrix[14]);
}else if(rslstr->ident == MDL_IDENT){ }else if(rslstr->ident == MDL_IDENT){
uint8 *p; uint8 *p;
p = *rslstr->hashTab; p = *rslstr->hashTab;