reworked the structs and got rid of c++ ctors/dtors

This commit is contained in:
aap 2016-01-11 18:22:59 +01:00
parent efd41771a0
commit 15872ba211
14 changed files with 439 additions and 358 deletions

View File

@ -202,7 +202,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="src\gtaplg.h" /> <ClInclude Include="src\gtaplg.h" />
<ClInclude Include="src\mdl.h" />
<ClInclude Include="src\rwbase.h" /> <ClInclude Include="src\rwbase.h" />
<ClInclude Include="src\rwd3d.h" /> <ClInclude Include="src\rwd3d.h" />
<ClInclude Include="src\rwd3d8.h" /> <ClInclude Include="src\rwd3d8.h" />

View File

@ -19,33 +19,32 @@ using namespace std;
namespace rw { namespace rw {
Frame::Frame(void) Frame*
Frame::create(void)
{ {
this->object.init(0, 0); Frame *f = (Frame*)malloc(PluginBase::s_size);
this->objectList.init(); f->object.init(0, 0);
this->child = NULL; f->objectList.init();
this->next = NULL; f->child = NULL;
this->root = NULL; f->next = NULL;
f->root = NULL;
for(int i = 0; i < 16; i++) for(int i = 0; i < 16; i++)
this->matrix[i] = 0.0f; f->matrix[i] = 0.0f;
this->matrix[0] = 1.0f; f->matrix[0] = 1.0f;
this->matrix[5] = 1.0f; f->matrix[5] = 1.0f;
this->matrix[10] = 1.0f; f->matrix[10] = 1.0f;
this->matrix[15] = 1.0f; f->matrix[15] = 1.0f;
this->matflag = 0; f->matflag = 0;
this->dirty = true; f->dirty = true;
constructPlugins(); f->constructPlugins();
return f;
} }
Frame::Frame(Frame *f) void
Frame::destroy(void)
{ {
// TODO this->destructPlugins();
copyPlugins(f); free(this);
}
Frame::~Frame(void)
{
destructPlugins();
} }
Frame* Frame*
@ -162,29 +161,49 @@ makeFrameList(Frame *frame, Frame **flist)
// Clump // Clump
// //
Clump::Clump(void) Clump*
Clump::create(void)
{ {
this->object.init(2, 0); Clump *clump = (Clump*)malloc(PluginBase::s_size);
this->numAtomics = 0; clump->object.init(2, 0);
this->numLights = 0; clump->atomics.init();
this->numCameras = 0; clump->lights.init();
this->atomicList = NULL; clump->constructPlugins();
this->lightList = NULL; return clump;
this->constructPlugins();
} }
Clump::Clump(Clump *c) Clump*
Clump::clone(void)
{ {
this->numAtomics = c->numAtomics; Clump *clump = Clump::create();
this->numLights = c->numLights; // TODO actually clone
this->numCameras = c->numCameras; clump->copyPlugins(this);
// TODO: atomics and lights return clump;
this->copyPlugins(c);
} }
Clump::~Clump(void) void
Clump::destroy(void)
{ {
this->destructPlugins(); this->destructPlugins();
free(this);
}
int32
Clump::countAtomics(void)
{
int32 n = 0;
FORLIST(l, this->atomics)
n++;
return n;
}
int32
Clump::countLights(void)
{
int32 n = 0;
FORLIST(l, this->lights)
n++;
return n;
} }
Clump* Clump*
@ -194,15 +213,13 @@ Clump::streamRead(Stream *stream)
int32 buf[3]; int32 buf[3];
Clump *clump; Clump *clump;
assert(findChunk(stream, ID_STRUCT, &length, &version)); assert(findChunk(stream, ID_STRUCT, &length, &version));
clump = new Clump; clump = Clump::create();
stream->read(buf, length); stream->read(buf, length);
clump->numAtomics = buf[0]; int32 numAtomics = buf[0];
clump->numLights = 0; int32 numLights = 0;
clump->numCameras = 0; if(version > 0x33000)
if(version > 0x33000){ numLights = buf[1];
clump->numLights = buf[1]; // ignore cameras
clump->numCameras = buf[2];
}
// Frame list // Frame list
Frame **frameList; Frame **frameList;
@ -226,26 +243,21 @@ Clump::streamRead(Stream *stream)
} }
// Atomics // Atomics
if(clump->numAtomics) for(int32 i = 0; i < numAtomics; i++){
clump->atomicList = new Atomic*[clump->numAtomics];
for(int32 i = 0; i < clump->numAtomics; i++){
assert(findChunk(stream, ID_ATOMIC, NULL, NULL)); assert(findChunk(stream, ID_ATOMIC, NULL, NULL));
clump->atomicList[i] = Atomic::streamReadClump(stream, Atomic *a = Atomic::streamReadClump(stream, frameList, geometryList);
frameList, geometryList); clump->addAtomic(a);
clump->atomicList[i]->clump = clump;
} }
// Lights // Lights
if(clump->numLights) for(int32 i = 0; i < numLights; i++){
clump->lightList = new Light*[clump->numLights];
for(int32 i = 0; i < clump->numLights; i++){
int32 frm; int32 frm;
assert(findChunk(stream, ID_STRUCT, NULL, NULL)); assert(findChunk(stream, ID_STRUCT, NULL, NULL));
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); Light *l = Light::streamRead(stream);
clump->lightList[i]->setFrame(frameList[frm]); l->setFrame(frameList[frm]);
clump->lightList[i]->clump = clump; clump->addLight(l);
} }
delete[] frameList; delete[] frameList;
@ -259,7 +271,9 @@ Clump::streamWrite(Stream *stream)
{ {
int size = this->streamGetSize(); int size = this->streamGetSize();
writeChunkHeader(stream, ID_CLUMP, size); writeChunkHeader(stream, ID_CLUMP, size);
int buf[3] = { this->numAtomics, this->numLights, this->numCameras }; int32 numAtomics = this->countAtomics();
int32 numLights = this->countLights();
int buf[3] = { numAtomics, numLights, 0 };
size = version > 0x33000 ? 12 : 4; size = version > 0x33000 ? 12 : 4;
writeChunkHeader(stream, ID_STRUCT, size); writeChunkHeader(stream, ID_STRUCT, size);
stream->write(buf, size); stream->write(buf, size);
@ -272,22 +286,21 @@ Clump::streamWrite(Stream *stream)
if(rw::version >= 0x30400){ if(rw::version >= 0x30400){
size = 12+4; size = 12+4;
for(int32 i = 0; i < this->numAtomics; i++) FORLIST(lnk, this->atomics)
size += 12 + size += 12 + Atomic::fromClump(lnk)->geometry->streamGetSize();
this->atomicList[i]->geometry->streamGetSize();
writeChunkHeader(stream, ID_GEOMETRYLIST, size); writeChunkHeader(stream, ID_GEOMETRYLIST, size);
writeChunkHeader(stream, ID_STRUCT, 4); writeChunkHeader(stream, ID_STRUCT, 4);
stream->writeI32(this->numAtomics); // same as numGeometries stream->writeI32(numAtomics); // same as numGeometries
for(int32 i = 0; i < this->numAtomics; i++) FORLIST(lnk, this->atomics)
this->atomicList[i]->geometry->streamWrite(stream); Atomic::fromClump(lnk)->geometry->streamWrite(stream);
} }
for(int32 i = 0; i < this->numAtomics; i++) FORLIST(lnk, this->atomics)
this->atomicList[i]->streamWriteClump(stream, flist, numFrames); Atomic::fromClump(lnk)->streamWriteClump(stream, flist, numFrames);
for(int32 i = 0; i < this->numLights; i++){ FORLIST(lnk, this->lights){
Light *l = this->lightList[i]; Light *l = Light::fromClump(lnk);
int frm = findPointer((void*)l->object.parent, (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);
@ -326,18 +339,17 @@ Clump::streamGetSize(void)
if(rw::version >= 0x30400){ if(rw::version >= 0x30400){
// geometry list // geometry list
size += 12 + 12 + 4; size += 12 + 12 + 4;
for(int32 i = 0; i < this->numAtomics; i++) FORLIST(lnk, this->atomics)
size += 12 + size += 12 + Atomic::fromClump(lnk)->geometry->streamGetSize();
this->atomicList[i]->geometry->streamGetSize();
} }
// atomics // atomics
for(int32 i = 0; i < this->numAtomics; i++) FORLIST(lnk, this->atomics)
size += 12 + this->atomicList[i]->streamGetSize(); size += 12 + Atomic::fromClump(lnk)->streamGetSize();
// light // light
for(int32 i = 0; i < this->numLights; i++) FORLIST(lnk, this->lights)
size += 16 + 12 + this->lightList[i]->streamGetSize(); size += 16 + 12 + Light::fromClump(lnk)->streamGetSize();
size += 12 + this->streamGetPluginSize(); size += 12 + this->streamGetPluginSize();
return size; return size;
@ -355,7 +367,7 @@ Clump::frameListStreamRead(Stream *stream, Frame ***flp, int32 *nf)
Frame **frameList = new Frame*[numFrames]; Frame **frameList = new Frame*[numFrames];
for(int32 i = 0; i < numFrames; i++){ for(int32 i = 0; i < numFrames; i++){
Frame *f; Frame *f;
frameList[i] = f = new Frame; frameList[i] = f = Frame::create();
stream->read(&buf, sizeof(buf)); stream->read(&buf, sizeof(buf));
f->matrix[0] = buf.mat[0]; f->matrix[0] = buf.mat[0];
f->matrix[1] = buf.mat[1]; f->matrix[1] = buf.mat[1];
@ -424,24 +436,32 @@ Clump::frameListStreamWrite(Stream *stream, Frame **frameList, int32 numFrames)
// Atomic // Atomic
// //
Atomic::Atomic(void) Atomic*
Atomic::create(void)
{ {
this->object.init(1, 0); Atomic *atomic = (Atomic*)malloc(PluginBase::s_size);
this->geometry = NULL; atomic->object.init(1, 0);
this->pipeline = NULL; atomic->geometry = NULL;
constructPlugins(); atomic->pipeline = NULL;
atomic->constructPlugins();
return atomic;
} }
Atomic::Atomic(Atomic *a) Atomic*
Atomic::clone()
{ {
Atomic *atomic = Atomic::create();
//TODO //TODO
copyPlugins(a); atomic->copyPlugins(this);
return atomic;
} }
Atomic::~Atomic(void) void
Atomic::destroy(void)
{ {
//TODO //TODO
destructPlugins(); this->destructPlugins();
free(this);
} }
static uint32 atomicRights[2]; static uint32 atomicRights[2];
@ -454,7 +474,7 @@ Atomic::streamReadClump(Stream *stream,
uint32 version; uint32 version;
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 = Atomic::create();
atomic->setFrame(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));
@ -484,10 +504,12 @@ Atomic::streamWriteClump(Stream *stream, Frame **frameList, int32 numFrames)
stream->write(buf, sizeof(int[3])); stream->write(buf, sizeof(int[3]));
this->geometry->streamWrite(stream); this->geometry->streamWrite(stream);
}else{ }else{
// TODO buf[1] = 0;
for(buf[1] = 0; buf[1] < c->numAtomics; buf[1]++) FORLIST(lnk, c->atomics){
if(c->atomicList[buf[1]]->geometry == this->geometry) if(Atomic::fromClump(lnk)->geometry == this->geometry)
goto foundgeo; goto foundgeo;
buf[1]++;
}
return false; return false;
foundgeo: foundgeo:
stream->write(buf, sizeof(buf)); stream->write(buf, sizeof(buf));
@ -578,30 +600,29 @@ registerAtomicRightsPlugin(void)
// Light // Light
// //
Light::Light(int32 type) Light*
Light::create(int32 type)
{ {
this->object.init(3, type); Light *light = (Light*)malloc(PluginBase::s_size);
this->radius = 0.0f; light->object.init(3, type);
this->color[0] = 1.0f; light->radius = 0.0f;
this->color[1] = 1.0f; light->color[0] = 1.0f;
this->color[2] = 1.0f; light->color[1] = 1.0f;
this->color[3] = 1.0f; light->color[2] = 1.0f;
this->minusCosAngle = 1.0f; light->color[3] = 1.0f;
this->object.privateFlags = 1; light->minusCosAngle = 1.0f;
this->object.flags = 1 | 2; light->object.privateFlags = 1;
Clump *clump; light->object.flags = 1 | 2;
constructPlugins(); light->inClump.init();
light->constructPlugins();
return light;
} }
Light::Light(Light *l) void
Light::destroy(void)
{ {
// TODO this->destructPlugins();
copyPlugins(l); free(this);
}
Light::~Light(void)
{
destructPlugins();
} }
struct LightChunkData struct LightChunkData
@ -619,7 +640,7 @@ Light::streamRead(Stream *stream)
LightChunkData buf; LightChunkData buf;
assert(findChunk(stream, ID_STRUCT, NULL, NULL)); assert(findChunk(stream, ID_STRUCT, NULL, NULL));
stream->read(&buf, sizeof(LightChunkData)); stream->read(&buf, sizeof(LightChunkData));
Light *light = new Light(buf.type); Light *light = Light::create(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;

View File

@ -387,7 +387,7 @@ readNativeTexture(Stream *stream)
{ {
assert(findChunk(stream, ID_STRUCT, NULL, NULL)); assert(findChunk(stream, ID_STRUCT, NULL, NULL));
assert(stream->readU32() == PLATFORM_D3D8); assert(stream->readU32() == PLATFORM_D3D8);
Texture *tex = new Texture; Texture *tex = Texture::create(NULL);
// Texture // Texture
tex->filterAddressing = stream->readU32(); tex->filterAddressing = stream->readU32();
@ -407,10 +407,10 @@ readNativeTexture(Stream *stream)
Raster *raster; Raster *raster;
D3dRaster *ras; D3dRaster *ras;
if(compression){ if(compression){
raster = new Raster(width, height, depth, format | type | 0x80, PLATFORM_D3D8); raster = Raster::create(width, height, depth, format | type | 0x80, PLATFORM_D3D8);
allocateDXT(raster, compression, numLevels, hasAlpha); allocateDXT(raster, compression, numLevels, hasAlpha);
}else }else
raster = new Raster(width, height, depth, format | type, PLATFORM_D3D8); raster = Raster::create(width, height, depth, format | type, PLATFORM_D3D8);
ras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset); ras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset);
tex->raster = raster; tex->raster = raster;

View File

@ -15,79 +15,80 @@ using namespace std;
namespace rw { namespace rw {
Geometry::Geometry(int32 numVerts, int32 numTris, uint32 flags) Geometry*
Geometry::create(int32 numVerts, int32 numTris, uint32 flags)
{ {
this->object.init(8, 0); Geometry *geo = (Geometry*)malloc(PluginBase::s_size);
this->geoflags = flags & 0xFF00FFFF; geo->object.init(8, 0);
this->numTexCoordSets = (flags & 0xFF0000) >> 16; geo->geoflags = flags & 0xFF00FFFF;
if(this->numTexCoordSets == 0) geo->numTexCoordSets = (flags & 0xFF0000) >> 16;
this->numTexCoordSets = (this->geoflags & TEXTURED) ? 1 : if(geo->numTexCoordSets == 0)
(this->geoflags & TEXTURED2) ? 2 : 0; geo->numTexCoordSets = (geo->geoflags & TEXTURED) ? 1 :
this->numTriangles = numTris; (geo->geoflags & TEXTURED2) ? 2 : 0;
this->numVertices = numVerts; geo->numTriangles = numTris;
this->numMorphTargets = 1; geo->numVertices = numVerts;
geo->numMorphTargets = 1;
this->colors = NULL; geo->colors = NULL;
for(int32 i = 0; i < this->numTexCoordSets; i++) for(int32 i = 0; i < geo->numTexCoordSets; i++)
this->texCoords[i] = NULL; geo->texCoords[i] = NULL;
this->triangles = NULL; geo->triangles = NULL;
if(!(this->geoflags & NATIVE) && this->numVertices){ if(!(geo->geoflags & NATIVE) && geo->numVertices){
if(this->geoflags & PRELIT) if(geo->geoflags & PRELIT)
this->colors = new uint8[4*this->numVertices]; geo->colors = new uint8[4*geo->numVertices];
if((this->geoflags & TEXTURED) || (this->geoflags & TEXTURED2)) if((geo->geoflags & TEXTURED) || (geo->geoflags & TEXTURED2))
for(int32 i = 0; i < this->numTexCoordSets; i++) for(int32 i = 0; i < geo->numTexCoordSets; i++)
this->texCoords[i] = geo->texCoords[i] =
new float32[2*this->numVertices]; new float32[2*geo->numVertices];
this->triangles = new uint16[4*this->numTriangles]; geo->triangles = new uint16[4*geo->numTriangles];
} }
this->morphTargets = new MorphTarget[1]; geo->morphTargets = new MorphTarget[1];
MorphTarget *m = this->morphTargets; MorphTarget *m = geo->morphTargets;
m->boundingSphere[0] = 0.0f; m->boundingSphere[0] = 0.0f;
m->boundingSphere[1] = 0.0f; m->boundingSphere[1] = 0.0f;
m->boundingSphere[2] = 0.0f; m->boundingSphere[2] = 0.0f;
m->boundingSphere[3] = 0.0f; m->boundingSphere[3] = 0.0f;
m->vertices = NULL; m->vertices = NULL;
m->normals = NULL; m->normals = NULL;
if(!(this->geoflags & NATIVE) && this->numVertices){ if(!(geo->geoflags & NATIVE) && geo->numVertices){
m->vertices = new float32[3*this->numVertices]; m->vertices = new float32[3*geo->numVertices];
if(this->geoflags & NORMALS) if(geo->geoflags & NORMALS)
m->normals = new float32[3*this->numVertices]; m->normals = new float32[3*geo->numVertices];
} }
this->numMaterials = 0; geo->numMaterials = 0;
this->materialList = NULL; geo->materialList = NULL;
this->meshHeader = NULL; geo->meshHeader = NULL;
this->instData = NULL; geo->instData = NULL;
this->refCount = 1; geo->refCount = 1;
this->constructPlugins(); geo->constructPlugins();
return geo;
} }
Geometry::~Geometry(void)
{
this->destructPlugins();
delete[] this->colors;
for(int32 i = 0; i < this->numTexCoordSets; i++)
delete[] this->texCoords[i];
delete[] this->triangles;
for(int32 i = 0; i < this->numMorphTargets; i++){
MorphTarget *m = &this->morphTargets[i];
delete[] m->vertices;
delete[] m->normals;
}
delete[] this->morphTargets;
delete this->meshHeader;
for(int32 i = 0; i < this->numMaterials; i++)
this->materialList[i]->decRef();
delete[] this->materialList;
}
void void
Geometry::decRef(void) Geometry::destroy(void)
{ {
this->refCount--; this->refCount--;
if(this->refCount == 0) if(this->refCount == 0){
delete this; this->destructPlugins();
delete[] this->colors;
for(int32 i = 0; i < this->numTexCoordSets; i++)
delete[] this->texCoords[i];
delete[] this->triangles;
for(int32 i = 0; i < this->numMorphTargets; i++){
MorphTarget *m = &this->morphTargets[i];
delete[] m->vertices;
delete[] m->normals;
}
delete[] this->morphTargets;
delete this->meshHeader;
for(int32 i = 0; i < this->numMaterials; i++)
this->materialList[i]->destroy();
delete[] this->materialList;
free(this);
}
} }
struct GeoStreamData struct GeoStreamData
@ -105,8 +106,8 @@ Geometry::streamRead(Stream *stream)
GeoStreamData buf; GeoStreamData buf;
assert(findChunk(stream, ID_STRUCT, NULL, &version)); assert(findChunk(stream, ID_STRUCT, NULL, &version));
stream->read(&buf, sizeof(buf)); stream->read(&buf, sizeof(buf));
Geometry *geo = new Geometry(buf.numVertices, Geometry *geo = Geometry::create(buf.numVertices,
buf.numTriangles, buf.flags); buf.numTriangles, buf.flags);
geo->addMorphTargets(buf.numMorphTargets-1); geo->addMorphTargets(buf.numMorphTargets-1);
// skip surface properties // skip surface properties
if(version < 0x34000) if(version < 0x34000)
@ -401,49 +402,48 @@ Geometry::generateTriangles(int8 *adc)
// Material // Material
// //
Material::Material(void) Material*
Material::create(void)
{ {
this->texture = NULL; Material *mat = (Material*)malloc(PluginBase::s_size);
memset(this->color, 0xFF, 4); mat->texture = NULL;
surfaceProps.ambient = 1.0f; memset(mat->color, 0xFF, 4);
surfaceProps.specular = 1.0f; mat->surfaceProps.ambient = 1.0f;
surfaceProps.diffuse = 1.0f; mat->surfaceProps.specular = 1.0f;
this->pipeline = NULL; mat->surfaceProps.diffuse = 1.0f;
this->refCount = 1; mat->pipeline = NULL;
this->constructPlugins(); mat->refCount = 1;
mat->constructPlugins();
return mat;
} }
Material::Material(Material *m) Material*
Material::clone(void)
{ {
this->color[0] = m->color[0]; Material *mat = Material::create();
this->color[1] = m->color[1]; mat->color[0] = this->color[0];
this->color[2] = m->color[2]; mat->color[1] = this->color[1];
this->color[3] = m->color[3]; mat->color[2] = this->color[2];
this->surfaceProps.ambient = m->surfaceProps.ambient; mat->color[3] = this->color[3];
this->surfaceProps.specular = m->surfaceProps.specular; mat->surfaceProps = this->surfaceProps;
this->surfaceProps.diffuse = m->surfaceProps.diffuse; mat->texture = this->texture;
this->texture = m->texture; if(mat->texture)
if(this->texture) mat->texture->refCount++;
this->texture->refCount++; mat->pipeline = this->pipeline;
this->pipeline = m->pipeline; mat->copyPlugins(this);
this->refCount = 1; return mat;
this->constructPlugins();
this->copyPlugins(m);
}
Material::~Material(void)
{
this->destructPlugins();
if(this->texture)
this->texture->decRef();
} }
void void
Material::decRef(void) Material::destroy(void)
{ {
this->refCount--; this->refCount--;
if(this->refCount == 0) if(this->refCount == 0){
delete this; this->destructPlugins();
if(this->texture)
this->texture->destroy();
free(this);
}
} }
struct MatStreamData struct MatStreamData
@ -464,7 +464,7 @@ Material::streamRead(Stream *stream)
assert(findChunk(stream, ID_STRUCT, NULL, &version)); assert(findChunk(stream, ID_STRUCT, NULL, &version));
stream->read(&buf, sizeof(buf)); stream->read(&buf, sizeof(buf));
Material *mat = new Material; Material *mat = Material::create();
mat->color[0] = buf.color[0]; mat->color[0] = buf.color[0];
mat->color[1] = buf.color[1]; mat->color[1] = buf.color[1];
mat->color[2] = buf.color[2]; mat->color[2] = buf.color[2];

View File

@ -21,8 +21,8 @@ namespace rw {
int32 int32
findPlatform(Clump *c) findPlatform(Clump *c)
{ {
for(int32 i = 0; i < c->numAtomics; i++){ FORLIST(lnk, c->atomics){
Geometry *g = c->atomicList[i]->geometry; Geometry *g = Atomic::fromClump(lnk)->geometry;
if(g->instData) if(g->instData)
return g->instData->platform; return g->instData->platform;
} }
@ -32,8 +32,8 @@ findPlatform(Clump *c)
void void
switchPipes(Clump *c, int32 platform) switchPipes(Clump *c, int32 platform)
{ {
for(int32 i = 0; i < c->numAtomics; i++){ FORLIST(lnk, c->atomics){
Atomic *a = c->atomicList[i]; Atomic *a = Atomic::fromClump(lnk);
if(a->pipeline && a->pipeline->platform != platform){ if(a->pipeline && a->pipeline->platform != platform){
uint32 plgid = a->pipeline->pluginID; uint32 plgid = a->pipeline->pluginID;
switch(plgid){ switch(plgid){
@ -527,7 +527,7 @@ destroySpecMat(void *object, int32 offset, int32)
if(*specmat == NULL) if(*specmat == NULL)
return object; return object;
if((*specmat)->texture) if((*specmat)->texture)
(*specmat)->texture->decRef(); (*specmat)->texture->destroy();
delete *specmat; delete *specmat;
*specmat = NULL; *specmat = NULL;
return object; return object;
@ -560,7 +560,7 @@ readSpecMat(Stream *stream, int32, void *object, int32 offset, int32)
*PLUGINOFFSET(SpecMat*, object, offset) = spec; *PLUGINOFFSET(SpecMat*, object, offset) = spec;
stream->read(&buf, sizeof(buf)); stream->read(&buf, sizeof(buf));
spec->specularity = buf.specularity; spec->specularity = buf.specularity;
spec->texture = new Texture; spec->texture = Texture::create(NULL);
strncpy(spec->texture->name, buf.texname, 24); strncpy(spec->texture->name, buf.texname, 24);
} }

View File

@ -29,27 +29,40 @@ namespace rw {
TexDictionary *currentTexDictionary; TexDictionary *currentTexDictionary;
TexDictionary::TexDictionary(void) TexDictionary*
TexDictionary::create(void)
{ {
this->object.init(6, 0); TexDictionary *dict = (TexDictionary*)malloc(PluginBase::s_size);
this->first = NULL; dict->object.init(6, 0);
dict->textures.init();
dict->constructPlugins();
return dict;
} }
void void
TexDictionary::add(Texture *tex) TexDictionary::destroy(void)
{ {
Texture **tp; this->destructPlugins();
for(tp = &this->first; *tp; tp = &(*tp)->next) free(this);
; }
*tp = tex;
int32
TexDictionary::count(void)
{
int32 n = 0;
FORLIST(l, this->textures)
n++;
return n;
} }
Texture* Texture*
TexDictionary::find(const char *name) TexDictionary::find(const char *name)
{ {
for(Texture *tex = this->first; tex; tex = tex->next) FORLIST(lnk, this->textures){
Texture *tex = Texture::fromDict(lnk);
if(strncmp(tex->name, name, 32) == 0) if(strncmp(tex->name, name, 32) == 0)
return tex; return tex;
}
return NULL; return NULL;
} }
@ -60,7 +73,7 @@ TexDictionary::streamRead(Stream *stream)
int32 numTex = stream->readI16(); int32 numTex = stream->readI16();
stream->readI16(); // some platform id (1 = d3d8, 2 = d3d9, 5 = opengl, stream->readI16(); // some platform id (1 = d3d8, 2 = d3d9, 5 = opengl,
// 6 = ps2, 8 = xbox) // 6 = ps2, 8 = xbox)
TexDictionary *txd = new TexDictionary; TexDictionary *txd = TexDictionary::create();
for(int32 i = 0; i < numTex; i++){ for(int32 i = 0; i < numTex; i++){
assert(findChunk(stream, ID_TEXTURENATIVE, NULL, NULL)); assert(findChunk(stream, ID_TEXTURENATIVE, NULL, NULL));
Texture *tex = Texture::streamReadNative(stream); Texture *tex = Texture::streamReadNative(stream);
@ -75,13 +88,11 @@ TexDictionary::streamWrite(Stream *stream)
{ {
writeChunkHeader(stream, ID_TEXDICTIONARY, this->streamGetSize()); writeChunkHeader(stream, ID_TEXDICTIONARY, this->streamGetSize());
writeChunkHeader(stream, ID_STRUCT, 4); writeChunkHeader(stream, ID_STRUCT, 4);
int32 numTex = 0; int32 numTex = this->count();
for(Texture *tex = this->first; tex; tex = tex->next)
numTex++;
stream->writeI16(numTex); stream->writeI16(numTex);
stream->writeI16(0); stream->writeI16(0);
for(Texture *tex = this->first; tex; tex = tex->next) FORLIST(lnk, this->textures)
tex->streamWriteNative(stream); Texture::fromDict(lnk)->streamWriteNative(stream);
this->streamWritePlugins(stream); this->streamWritePlugins(stream);
} }
@ -89,8 +100,8 @@ uint32
TexDictionary::streamGetSize(void) TexDictionary::streamGetSize(void)
{ {
uint32 size = 12 + 4; uint32 size = 12 + 4;
for(Texture *tex = this->first; tex; tex = tex->next) FORLIST(lnk, this->textures)
size += 12 + tex->streamGetSizeNative(); size += 12 + Texture::fromDict(lnk)->streamGetSizeNative();
size += 12 + this->streamGetPluginSize(); size += 12 + this->streamGetPluginSize();
return size; return size;
} }
@ -99,28 +110,29 @@ TexDictionary::streamGetSize(void)
// Texture // Texture
// //
Texture::Texture(void) Texture*
Texture::create(Raster *raster)
{ {
memset(this->name, 0, 32); Texture *tex = (Texture*)malloc(PluginBase::s_size);
memset(this->mask, 0, 32); tex->dict = NULL;
this->filterAddressing = (WRAP << 12) | (WRAP << 8) | NEAREST; tex->inDict.init();
this->raster = NULL; memset(tex->name, 0, 32);
this->refCount = 1; memset(tex->mask, 0, 32);
this->next = NULL; tex->filterAddressing = (WRAP << 12) | (WRAP << 8) | NEAREST;
this->constructPlugins(); tex->raster = raster;
} tex->refCount = 1;
tex->constructPlugins();
Texture::~Texture(void) return tex;
{
this->destructPlugins();
} }
void void
Texture::decRef(void) Texture::destroy(void)
{ {
this->refCount--; this->refCount--;
if(this->refCount == 0) if(this->refCount == 0){
delete this; this->destructPlugins();
free(this);
}
} }
// TODO: do this properly, pretty ugly right now // TODO: do this properly, pretty ugly right now
@ -133,7 +145,7 @@ Texture::read(const char *name, const char *mask)
if(currentTexDictionary && (tex = currentTexDictionary->find(name))) if(currentTexDictionary && (tex = currentTexDictionary->find(name)))
return tex; return tex;
tex = new Texture; tex = Texture::create(NULL);
strncpy(tex->name, name, 32); strncpy(tex->name, name, 32);
strncpy(tex->mask, mask, 32); strncpy(tex->mask, mask, 32);
// char *n = (char*)malloc(strlen(name) + 5); // char *n = (char*)malloc(strlen(name) + 5);
@ -144,9 +156,9 @@ Texture::read(const char *name, const char *mask)
// if(img){ // if(img){
// //raster = Raster::createFromImage(img); // //raster = Raster::createFromImage(img);
// raster = new Raster(0, 0, 0, 0x80); // raster = new Raster(0, 0, 0, 0x80);
// delete img; // img->destroy();
// }else // }else
raster = new Raster(0, 0, 0, 0x80); raster = Raster::create(0, 0, 0, 0x80);
tex->raster = raster; tex->raster = raster;
if(currentTexDictionary /*&& img*/) if(currentTexDictionary /*&& img*/)
currentTexDictionary->add(tex); currentTexDictionary->add(tex);
@ -265,20 +277,25 @@ Texture::streamGetSizeNative(void)
// Image // Image
// //
Image::Image(int32 width, int32 height, int32 depth) Image*
Image::create(int32 width, int32 height, int32 depth)
{ {
this->flags = 0; Image *img = (Image*)malloc(sizeof(*img));
this->width = width; img->flags = 0;
this->height = height; img->width = width;
this->depth = depth; img->height = height;
this->stride = 0; img->depth = depth;
this->pixels = NULL; img->stride = 0;
this->palette = NULL; img->pixels = NULL;
img->palette = NULL;
return img;
} }
Image::~Image(void) void
Image::destroy(void)
{ {
this->free(); this->free();
::free(this);
} }
void void
@ -443,7 +460,7 @@ readTGA(const char *afilename)
assert(depth == 24 || depth == 32); assert(depth == 24 || depth == 32);
} }
image = new Image(header.width, header.height, depth); image = Image::create(header.width, header.height, depth);
image->allocate(); image->allocate();
uint8 *palette = header.colorMapType ? image->palette : NULL; uint8 *palette = header.colorMapType ? image->palette : NULL;
uint8 (*color)[4] = NULL; uint8 (*color)[4] = NULL;
@ -548,29 +565,34 @@ writeTGA(Image *image, const char *filename)
int32 Raster::nativeOffsets[NUM_PLATFORMS]; int32 Raster::nativeOffsets[NUM_PLATFORMS];
Raster::Raster(int32 width, int32 height, int32 depth, int32 format, int32 platform) Raster*
Raster::create(int32 width, int32 height, int32 depth, int32 format, int32 platform)
{ {
this->platform = platform ? platform : rw::platform; Raster *raster = (Raster*)malloc(PluginBase::s_size);
this->type = format & 0x7; raster->platform = platform ? platform : rw::platform;
this->flags = format & 0xF8; raster->type = format & 0x7;
this->format = format & 0xFF00; raster->flags = format & 0xF8;
this->width = width; raster->format = format & 0xFF00;
this->height = height; raster->width = width;
this->depth = depth; raster->height = height;
this->texels = this->palette = NULL; raster->depth = depth;
this->constructPlugins(); raster->texels = raster->palette = NULL;
raster->constructPlugins();
int32 offset = nativeOffsets[this->platform]; int32 offset = nativeOffsets[raster->platform];
assert(offset != 0 && "unimplemented raster platform"); assert(offset != 0 && "unimplemented raster platform");
NativeRaster *nr = PLUGINOFFSET(NativeRaster, this, offset); NativeRaster *nr = PLUGINOFFSET(NativeRaster, raster, offset);
nr->create(this); nr->create(raster);
return raster;
} }
Raster::~Raster(void) void
Raster::destroy(void)
{ {
this->destructPlugins(); this->destructPlugins();
delete[] this->texels; delete[] this->texels;
delete[] this->palette; delete[] this->palette;
free(this);
} }
uint8* uint8*
@ -629,8 +651,8 @@ Raster::createFromImage(Image *image)
format = Raster::PAL4 | Raster::C8888; format = Raster::PAL4 | Raster::C8888;
else else
return NULL; return NULL;
Raster *raster = new Raster(image->width, image->height, Raster *raster = Raster::create(image->width, image->height,
image->depth, format | 4 | 0x80); image->depth, format | 4 | 0x80);
raster->stride = image->stride; raster->stride = image->stride;
raster->texels = new uint8[raster->stride*raster->height]; raster->texels = new uint8[raster->stride*raster->height];

View File

@ -772,19 +772,19 @@ clearMatFX(MatFX *matfx)
switch(matfx->fx[i].type){ switch(matfx->fx[i].type){
case MatFX::BUMPMAP: case MatFX::BUMPMAP:
if(matfx->fx[i].bump.bumpedTex) if(matfx->fx[i].bump.bumpedTex)
matfx->fx[i].bump.bumpedTex->decRef(); matfx->fx[i].bump.bumpedTex->destroy();
if(matfx->fx[i].bump.tex) if(matfx->fx[i].bump.tex)
matfx->fx[i].bump.tex->decRef(); matfx->fx[i].bump.tex->destroy();
break; break;
case MatFX::ENVMAP: case MatFX::ENVMAP:
if(matfx->fx[i].env.tex) if(matfx->fx[i].env.tex)
matfx->fx[i].env.tex->decRef(); matfx->fx[i].env.tex->destroy();
break; break;
case MatFX::DUAL: case MatFX::DUAL:
if(matfx->fx[i].dual.tex) if(matfx->fx[i].dual.tex)
matfx->fx[i].dual.tex->decRef(); matfx->fx[i].dual.tex->destroy();
break; break;
} }
memset(matfx, 0, sizeof(MatFX)); memset(matfx, 0, sizeof(MatFX));

View File

@ -1828,7 +1828,7 @@ readNativeTexture(Stream *stream)
uint32 length, oldversion, version; uint32 length, oldversion, version;
assert(findChunk(stream, ID_STRUCT, NULL, NULL)); assert(findChunk(stream, ID_STRUCT, NULL, NULL));
assert(stream->readU32() == 0x00325350); // 'PS2\0' assert(stream->readU32() == 0x00325350); // 'PS2\0'
Texture *tex = new Texture; Texture *tex = Texture::create(NULL);
// Texture // Texture
tex->filterAddressing = stream->readU32(); tex->filterAddressing = stream->readU32();
@ -1846,9 +1846,9 @@ readNativeTexture(Stream *stream)
Raster *raster; Raster *raster;
noNewStyleRasters = streamExt.type < 2; noNewStyleRasters = streamExt.type < 2;
rw::version = version; rw::version = version;
raster = new Raster(streamExt.width, streamExt.height, raster = Raster::create(streamExt.width, streamExt.height,
streamExt.depth, streamExt.rasterFormat, streamExt.depth, streamExt.rasterFormat,
PLATFORM_PS2); PLATFORM_PS2);
noNewStyleRasters = 0; noNewStyleRasters = 0;
rw::version = oldversion; rw::version = oldversion;
tex->raster = raster; tex->raster = raster;

View File

@ -33,11 +33,22 @@ struct LinkList
this->link.next->prev = link; this->link.next->prev = link;
this->link.next = link; this->link.next = link;
} }
void append(LLLink *link){
link->next = &this->link;
link->prev = this->link.prev;
this->link.prev->next = link;
this->link.prev = link;
}
LLLink *end(void){ LLLink *end(void){
return &this->link; return &this->link;
} }
}; };
#define FORLIST(_link, _list) \
for(LLLink *_link = (_list).link.next; \
(_link) != (_list).end(); \
(_link) = (_link)->next)
struct Object struct Object
{ {
uint8 type; uint8 type;
@ -72,9 +83,10 @@ struct Frame : PluginBase<Frame>
int32 matflag; int32 matflag;
bool dirty; bool dirty;
Frame(void); // MEM create, clonehiearchy, destroy, destroy hierarchy
Frame(Frame *f); static Frame *create(void);
~Frame(void); void destroy(void);
Frame *addChild(Frame *f); Frame *addChild(Frame *f);
Frame *removeChild(void); Frame *removeChild(void);
Frame *forAllChildren(Callback cb, void *data); Frame *forAllChildren(Callback cb, void *data);
@ -145,8 +157,9 @@ struct Image
uint8 *pixels; uint8 *pixels;
uint8 *palette; uint8 *palette;
Image(int32 width, int32 height, int32 depth); // MEM create, destroy
~Image(void); static Image *create(int32 width, int32 height, int32 depth);
void destroy(void);
void allocate(void); void allocate(void);
void free(void); void free(void);
void setPixels(uint8 *pixels); void setPixels(uint8 *pixels);
@ -184,8 +197,9 @@ struct Raster : PluginBase<Raster>
static int32 nativeOffsets[NUM_PLATFORMS]; static int32 nativeOffsets[NUM_PLATFORMS];
Raster(int32 width, int32 height, int32 depth, int32 format, int32 platform = 0); // MEM create, destroy
~Raster(void); static Raster *create(int32 width, int32 height, int32 depth, int32 format, int32 platform = 0);
void destroy(void);
static Raster *createFromImage(Image *image); static Raster *createFromImage(Image *image);
uint8 *lock(int32 level); uint8 *lock(int32 level);
@ -226,22 +240,24 @@ struct NativeRaster
{ assert(IGNORERASTERIMP && "unimplemented"); return 0; }; { assert(IGNORERASTERIMP && "unimplemented"); return 0; };
}; };
// TODO: link into texdict struct TexDictionary;
struct Texture : PluginBase<Texture> struct Texture : PluginBase<Texture>
{ {
Raster *raster; Raster *raster;
// TODO: pointer to txd and link TexDictionary *dict;
LLLink inDict;
char name[32]; char name[32];
char mask[32]; char mask[32];
uint32 filterAddressing; // VVVVUUUU FFFFFFFF uint32 filterAddressing; // VVVVUUUU FFFFFFFF
int32 refCount; int32 refCount;
// temporary - pointer to next tex in dictionary // MEM create, addref, destroy
Texture *next; static Texture *create(Raster *raster);
void destroy(void);
Texture(void); static Texture *fromDict(LLLink *lnk){
~Texture(void); return LLLinkGetData(lnk, Texture, inDict);
void decRef(void); }
static Texture *streamRead(Stream *stream); static Texture *streamRead(Stream *stream);
bool streamWrite(Stream *stream); bool streamWrite(Stream *stream);
uint32 streamGetSize(void); uint32 streamGetSize(void);
@ -281,10 +297,10 @@ struct Material : PluginBase<Material>
Pipeline *pipeline; Pipeline *pipeline;
int32 refCount; int32 refCount;
Material(void); // MEM create, clone, addref, destroy
Material(Material *m); static Material *create(void);
void decRef(void); Material *clone(void);
~Material(void); void destroy(void);
static Material *streamRead(Stream *stream); static Material *streamRead(Stream *stream);
bool streamWrite(Stream *stream); bool streamWrite(Stream *stream);
uint32 streamGetSize(void); uint32 streamGetSize(void);
@ -406,9 +422,9 @@ struct Geometry : PluginBase<Geometry>
int32 refCount; int32 refCount;
Geometry(int32 numVerts, int32 numTris, uint32 flags); // MEM create, addref, destroy
void decRef(void); static Geometry *create(int32 numVerts, int32 numTris, uint32 flags);
~Geometry(void); void destroy(void);
static Geometry *streamRead(Stream *stream); static Geometry *streamRead(Stream *stream);
bool streamWrite(Stream *stream); bool streamWrite(Stream *stream);
uint32 streamGetSize(void); uint32 streamGetSize(void);
@ -472,11 +488,15 @@ struct Light : PluginBase<Light>
// clump link handled by plugin in RW // clump link handled by plugin in RW
Clump *clump; Clump *clump;
LLLink inClump;
Light(int32 type); // MEM create, destroy
Light(Light *l); static Light *create(int32 type);
~Light(void); void destroy(void);
void setFrame(Frame *f) { this->object.setFrame(f); } void setFrame(Frame *f) { this->object.setFrame(f); }
static Light *fromClump(LLLink *lnk){
return LLLinkGetData(lnk, Light, inClump);
}
static Light *streamRead(Stream *stream); static Light *streamRead(Stream *stream);
bool streamWrite(Stream *stream); bool streamWrite(Stream *stream);
uint32 streamGetSize(void); uint32 streamGetSize(void);
@ -487,12 +507,17 @@ struct Atomic : PluginBase<Atomic>
ObjectWithFrame object; ObjectWithFrame object;
Geometry *geometry; Geometry *geometry;
Clump *clump; Clump *clump;
LLLink inClump;
ObjPipeline *pipeline; ObjPipeline *pipeline;
Atomic(void); // MEM create, clone, destroy
Atomic(Atomic *a); static Atomic *create(void);
~Atomic(void); Atomic *clone(void);
void destroy(void);
void setFrame(Frame *f) { this->object.setFrame(f); } void setFrame(Frame *f) { this->object.setFrame(f); }
static Atomic *fromClump(LLLink *lnk){
return LLLinkGetData(lnk, Atomic, inClump);
}
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,
@ -510,31 +535,46 @@ void registerAtomicRightsPlugin(void);
struct Clump : PluginBase<Clump> struct Clump : PluginBase<Clump>
{ {
Object object; Object object;
int32 numAtomics; LinkList atomics;
Atomic **atomicList; LinkList lights;
int32 numLights;
Light **lightList;
int32 numCameras;
// cameras not implemented // cameras not implemented
Clump(void); // MEM create, clone, destroy
Clump(Clump *c); static Clump *create(void);
~Clump(void); Clump *clone(void);
void destroy(void);
int32 countAtomics(void);
void addAtomic(Atomic *a){
a->clump = this;
this->atomics.append(&a->inClump);
}
int32 countLights(void);
void addLight(Light *l){
l->clump = this;
this->lights.append(&l->inClump);
}
static Clump *streamRead(Stream *stream); static Clump *streamRead(Stream *stream);
bool streamWrite(Stream *stream); bool streamWrite(Stream *stream);
uint32 streamGetSize(void); uint32 streamGetSize(void);
void frameListStreamRead(Stream *stream, Frame ***flp, int32 *nf); void frameListStreamRead(Stream *stream, Frame ***flp, int32 *nf);
void frameListStreamWrite(Stream *stream, Frame **flp, int32 nf); void frameListStreamWrite(Stream *stream, Frame **flp, int32 nf);
}; };
struct TexDictionary : PluginBase<TexDictionary> struct TexDictionary : PluginBase<TexDictionary>
{ {
Object object; Object object;
Texture *first; LinkList textures;
TexDictionary(void); // MEM create, destroy
void add(Texture *tex); static TexDictionary *create(void);
void destroy(void);
int32 count(void);
void add(Texture *t){
t->dict = this;
this->textures.append(&t->inDict);
}
Texture *find(const char *name); Texture *find(const char *name);
static TexDictionary *streamRead(Stream *stream); static TexDictionary *streamRead(Stream *stream);
void streamWrite(Stream *stream); void streamWrite(Stream *stream);
@ -599,6 +639,7 @@ struct UVAnimCustomData
struct UVAnimDictionary struct UVAnimDictionary
{ {
// TODO: linked list probably
int32 numAnims; int32 numAnims;
Animation **anims; Animation **anims;

View File

@ -205,15 +205,13 @@ PluginBase<T>::getPluginOffset(uint32 id)
template <typename T> void* template <typename T> void*
PluginBase<T>::operator new(size_t) PluginBase<T>::operator new(size_t)
{ {
void *m = malloc(T::s_size); assert(0);
if(!m) return NULL;
throw std::bad_alloc();
return m;
} }
template <typename T> void template <typename T> void
PluginBase<T>::operator delete(void *p) PluginBase<T>::operator delete(void *p)
{ {
free(p); assert(0);
} }
} }

View File

@ -869,7 +869,7 @@ readNativeTexture(Stream *stream)
assert(findChunk(stream, ID_STRUCT, NULL, &version)); assert(findChunk(stream, ID_STRUCT, NULL, &version));
assert(version >= 0x34001); assert(version >= 0x34001);
assert(stream->readU32() == PLATFORM_XBOX); assert(stream->readU32() == PLATFORM_XBOX);
Texture *tex = new Texture; Texture *tex = Texture::create(NULL);
// Texture // Texture
tex->filterAddressing = stream->readU32(); tex->filterAddressing = stream->readU32();
@ -891,7 +891,7 @@ readNativeTexture(Stream *stream)
assert(unknownFlag == 0); assert(unknownFlag == 0);
Raster *raster; Raster *raster;
if(compression){ if(compression){
raster = new Raster(width, height, depth, format | type | 0x80, PLATFORM_XBOX); raster = Raster::create(width, height, depth, format | type | 0x80, PLATFORM_XBOX);
XboxRaster *ras = PLUGINOFFSET(XboxRaster, raster, nativeRasterOffset); XboxRaster *ras = PLUGINOFFSET(XboxRaster, raster, nativeRasterOffset);
ras->format = compression; ras->format = compression;
ras->hasAlpha = hasAlpha; ras->hasAlpha = hasAlpha;
@ -900,7 +900,7 @@ readNativeTexture(Stream *stream)
ras->format); ras->format);
raster->flags &= ~0x80; raster->flags &= ~0x80;
}else }else
raster = new Raster(width, height, depth, format | type, PLATFORM_XBOX); raster = Raster::create(width, height, depth, format | type, PLATFORM_XBOX);
XboxRaster *ras = PLUGINOFFSET(XboxRaster, raster, nativeRasterOffset); XboxRaster *ras = PLUGINOFFSET(XboxRaster, raster, nativeRasterOffset);
tex->raster = raster; tex->raster = raster;

View File

@ -132,8 +132,8 @@ main(int argc, char *argv[])
} }
if(uninstance) if(uninstance)
for(int32 i = 0; i < c->numAtomics; i++){ FORLIST(lnk, c->atomics){
Atomic *a = c->atomicList[i]; Atomic *a = Atomic::fromClump(lnk);
ObjPipeline *p = a->getPipeline(); ObjPipeline *p = a->getPipeline();
p->uninstance(a); p->uninstance(a);
if(outplatform != PLATFORM_PS2) if(outplatform != PLATFORM_PS2)
@ -144,8 +144,8 @@ main(int argc, char *argv[])
switchPipes(c, rw::platform); switchPipes(c, rw::platform);
if(instance) if(instance)
for(int32 i = 0; i < c->numAtomics; i++){ FORLIST(lnk, c->atomics){
Atomic *a = c->atomicList[i]; Atomic *a = Atomic::fromClump(lnk);
ObjPipeline *p = a->getPipeline(); ObjPipeline *p = a->getPipeline();
p->instance(a); p->instance(a);
if(outplatform != PLATFORM_PS2) if(outplatform != PLATFORM_PS2)
@ -185,7 +185,7 @@ main(int argc, char *argv[])
// out.close(); // out.close();
// delete[] data; // delete[] data;
delete c; c->destroy();
return 0; return 0;
} }

View File

@ -71,7 +71,7 @@ mapID(int32 id)
Frame* Frame*
convertFrame(RslFrame *f) convertFrame(RslFrame *f)
{ {
Frame *rwf = new Frame; Frame *rwf = Frame::create();
rwf->matrix[0] = f->modelling.right.x; rwf->matrix[0] = f->modelling.right.x;
rwf->matrix[1] = f->modelling.right.y; rwf->matrix[1] = f->modelling.right.y;
rwf->matrix[2] = f->modelling.right.z; rwf->matrix[2] = f->modelling.right.z;
@ -123,7 +123,7 @@ Material*
convertMaterial(RslMaterial *m) convertMaterial(RslMaterial *m)
{ {
Material *rwm; Material *rwm;
rwm = new Material; rwm = Material::create();
rwm->color[0] = m->color.red; rwm->color[0] = m->color.red;
rwm->color[1] = m->color.green; rwm->color[1] = m->color.green;
@ -300,9 +300,9 @@ convertMesh(Geometry *rwg, RslGeometry *g, int32 ii)
Atomic* Atomic*
convertAtomic(RslAtomic *atomic) convertAtomic(RslAtomic *atomic)
{ {
Atomic *rwa = new Atomic; Atomic *rwa = Atomic::create();
RslGeometry *g = atomic->geometry; RslGeometry *g = atomic->geometry;
Geometry *rwg = new Geometry(0, 0, 0); Geometry *rwg = Geometry::create(0, 0, 0);
rwa->geometry = rwg; rwa->geometry = rwg;
rwg->numMaterials = g->matList.numMaterials; rwg->numMaterials = g->matList.numMaterials;
@ -396,7 +396,7 @@ convertClump(RslClump *c)
Atomic *rwa; Atomic *rwa;
rslFrameList frameList; rslFrameList frameList;
rwc = new Clump; rwc = Clump::create();
rslFrameListInitialize(&frameList, (RslFrame*)c->object.parent); rslFrameListInitialize(&frameList, (RslFrame*)c->object.parent);
Frame **rwframes = new Frame*[frameList.numFrames]; Frame **rwframes = new Frame*[frameList.numFrames];
for(int32 i = 0; i < frameList.numFrames; i++){ for(int32 i = 0; i < frameList.numFrames; i++){
@ -409,17 +409,15 @@ convertClump(RslClump *c)
} }
rwc->object.parent = rwframes[0]; rwc->object.parent = rwframes[0];
rwc->numAtomics = RslClumpGetNumAtomics(c); int32 numAtomics = RslClumpGetNumAtomics(c);
rwc->atomicList = new Atomic*[rwc->numAtomics]; RslAtomic **alist = new RslAtomic*[numAtomics];
RslAtomic **alist = new RslAtomic*[rwc->numAtomics];
RslAtomic **ap = &alist[0]; RslAtomic **ap = &alist[0];
RslClumpForAllAtomics(c, collectAtomics, &ap); RslClumpForAllAtomics(c, collectAtomics, &ap);
for(int32 i = 0; i < rwc->numAtomics; i++){ for(int32 i = 0; i < numAtomics; i++){
rwa = convertAtomic(alist[i]); rwa = convertAtomic(alist[i]);
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->object.parent = rwframes[fi]; rwa->setFrame(rwframes[fi]);
rwa->clump = rwc; rwc->addAtomic(rwa);
} }
delete[] alist; delete[] alist;
@ -614,14 +612,14 @@ RslTexture *dumpTextureCB(RslTexture *texture, void*)
uint8 *palette = getPalettePS2(texture->raster); uint8 *palette = getPalettePS2(texture->raster);
uint8 *texels = getTexelPS2(texture->raster, 0); uint8 *texels = getTexelPS2(texture->raster, 0);
printf(" %x %x %x %x %x %s\n", w, h, d, mip, swizmask, texture->name); printf(" %x %x %x %x %x %s\n", w, h, d, mip, swizmask, texture->name);
Image *img = new Image(w, h, 32); Image *img = Image::create(w, h, 32);
img->allocate(); img->allocate();
convertTo32(img->pixels, palette, texels, w, h, d, swizmask&1); convertTo32(img->pixels, palette, texels, w, h, d, swizmask&1);
char *name = new char[strlen(texture->name)+5]; char *name = new char[strlen(texture->name)+5];
strcpy(name, texture->name); strcpy(name, texture->name);
strcat(name, ".tga"); strcat(name, ".tga");
writeTGA(img, name); writeTGA(img, name);
delete img; img->destroy();
delete[] name; delete[] name;
return texture; return texture;
} }
@ -630,7 +628,7 @@ RslTexture*
convertTexturePS2(RslTexture *texture, void *pData) convertTexturePS2(RslTexture *texture, void *pData)
{ {
TexDictionary *rwtxd = (TexDictionary*)pData; TexDictionary *rwtxd = (TexDictionary*)pData;
Texture *rwtex = new Texture; Texture *rwtex = Texture::create(NULL);
RslRasterPS2 *ras = &texture->raster->ps2; RslRasterPS2 *ras = &texture->raster->ps2;
strncpy(rwtex->name, texture->name, 32); strncpy(rwtex->name, texture->name, 32);
@ -703,7 +701,7 @@ convertTexturePS2(RslTexture *texture, void *pData)
fprintf(stderr, "unsupported depth %d\n", d); fprintf(stderr, "unsupported depth %d\n", d);
return NULL; return NULL;
} }
Raster *rwras = new Raster(w, h, d == 4 ? 8 : d, format | 4, PLATFORM_D3D8); Raster *rwras = Raster::create(w, h, d == 4 ? 8 : d, format | 4, PLATFORM_D3D8);
d3d::D3dRaster *d3dras = PLUGINOFFSET(d3d::D3dRaster, rwras, d3d::nativeRasterOffset); d3d::D3dRaster *d3dras = PLUGINOFFSET(d3d::D3dRaster, rwras, d3d::nativeRasterOffset);
int32 pallen = d == 4 ? 16 : int32 pallen = d == 4 ? 16 :
@ -744,7 +742,7 @@ convertTexturePS2(RslTexture *texture, void *pData)
TexDictionary* TexDictionary*
convertTXD(RslTexDictionary *txd) convertTXD(RslTexDictionary *txd)
{ {
TexDictionary *rwtxd = new TexDictionary; TexDictionary *rwtxd = TexDictionary::create();
RslTexDictionaryForAllTextures(txd, convertTexturePS2, rwtxd); RslTexDictionaryForAllTextures(txd, convertTexturePS2, rwtxd);
return rwtxd; return rwtxd;
} }

View File

@ -40,8 +40,8 @@ xboxToD3d8(Raster *raster)
int32 format = raster->format; int32 format = raster->format;
// format &= ~Raster::MIPMAP; // format &= ~Raster::MIPMAP;
if(ras->format){ if(ras->format){
newras = new Raster(raster->width, raster->height, raster->depth, newras = Raster::create(raster->width, raster->height, raster->depth,
format | raster->type | 0x80, PLATFORM_D3D8); format | raster->type | 0x80, PLATFORM_D3D8);
int32 dxt = 0; int32 dxt = 0;
switch(ras->format){ switch(ras->format){
case D3DFMT_DXT1: case D3DFMT_DXT1:
@ -57,8 +57,8 @@ xboxToD3d8(Raster *raster)
d3d::allocateDXT(newras, dxt, numLevels, ras->hasAlpha); d3d::allocateDXT(newras, dxt, numLevels, ras->hasAlpha);
}else{ }else{
printf("swizzled!\n"); printf("swizzled!\n");
newras = new Raster(raster->width, raster->height, raster->depth, newras = Raster::create(raster->width, raster->height, raster->depth,
format | raster->type, PLATFORM_D3D8); format | raster->type, PLATFORM_D3D8);
} }
if(raster->format & Raster::PAL4) if(raster->format & Raster::PAL4)
@ -145,8 +145,10 @@ main(int argc, char *argv[])
} }
if(outplatform == PLATFORM_D3D8) if(outplatform == PLATFORM_D3D8)
for(Texture *tex = txd->first; tex; tex = tex->next) FORLIST(lnk, txd->textures){
Texture *tex = Texture::fromDict(lnk);
tex->raster = xboxToD3d8(tex->raster); tex->raster = xboxToD3d8(tex->raster);
}
// for(Texture *tex = txd->first; tex; tex = tex->next) // for(Texture *tex = txd->first; tex; tex = tex->next)
// tex->filterAddressing = (tex->filterAddressing&~0xF) | 0x2; // tex->filterAddressing = (tex->filterAddressing&~0xF) | 0x2;