mirror of https://github.com/aap/librw.git
Added some reference counting.
This commit is contained in:
parent
c0c8271b03
commit
92a3db015c
6
TODO
6
TODO
|
@ -13,7 +13,6 @@ Clump & related:
|
|||
Clump
|
||||
Collision
|
||||
Frame
|
||||
Frame
|
||||
HAnim
|
||||
Atomic
|
||||
Right To Render
|
||||
|
@ -21,10 +20,9 @@ Clump & related:
|
|||
Mat FX
|
||||
Pipeline Set
|
||||
Geometry
|
||||
Mesh
|
||||
Native Data
|
||||
Mesh Extension
|
||||
Night Vertex Colors
|
||||
Breakable
|
||||
Extra Vertex Colors
|
||||
(Morph)
|
||||
Skin
|
||||
(ADC)
|
||||
|
|
70
geometry.cpp
70
geometry.cpp
|
@ -47,8 +47,9 @@ Geometry::Geometry(int32 numVerts, int32 numTris, uint32 flags)
|
|||
m->normals = new float32[3*this->numVertices];
|
||||
}
|
||||
this->numMaterials = 0;
|
||||
materialList = NULL;
|
||||
meshHeader = NULL;
|
||||
this->materialList = NULL;
|
||||
this->meshHeader = NULL;
|
||||
this->refCount = 1;
|
||||
|
||||
this->constructPlugins();
|
||||
}
|
||||
|
@ -60,12 +61,32 @@ Geometry::~Geometry(void)
|
|||
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;
|
||||
|
||||
if(this->meshHeader){
|
||||
for(uint32 i = 0; i < this->meshHeader->numMeshes; i++)
|
||||
delete[] this->meshHeader->mesh[i].indices;
|
||||
delete[] this->meshHeader->mesh;
|
||||
delete this->meshHeader;
|
||||
}
|
||||
|
||||
for(int32 i = 0; i < this->numMaterials; i++)
|
||||
this->materialList[i]->decRef();
|
||||
delete[] this->materialList;
|
||||
}
|
||||
|
||||
void
|
||||
Geometry::decRef(void)
|
||||
{
|
||||
this->refCount--;
|
||||
if(this->refCount)
|
||||
delete this;
|
||||
}
|
||||
|
||||
struct GeoStreamData
|
||||
|
@ -248,9 +269,10 @@ Geometry::addMorphTargets(int32 n)
|
|||
Material::Material(void)
|
||||
{
|
||||
this->texture = NULL;
|
||||
color[0] = color[1] = color[2] = color[3] = 0xFF;
|
||||
memset(this->color, 0xFF, 4);
|
||||
surfaceProps[0] = surfaceProps[1] = surfaceProps[2] = 1.0f;
|
||||
constructPlugins();
|
||||
this->refCount = 1;
|
||||
this->constructPlugins();
|
||||
}
|
||||
|
||||
Material::Material(Material *m)
|
||||
|
@ -262,12 +284,25 @@ Material::Material(Material *m)
|
|||
m->surfaceProps[0] = this->surfaceProps[0];
|
||||
m->surfaceProps[1] = this->surfaceProps[1];
|
||||
m->surfaceProps[2] = this->surfaceProps[2];
|
||||
copyPlugins(m);
|
||||
m->texture = this->texture;
|
||||
if(m->texture)
|
||||
m->texture->refCount++;
|
||||
this->copyPlugins(m);
|
||||
}
|
||||
|
||||
Material::~Material(void)
|
||||
{
|
||||
destructPlugins();
|
||||
this->destructPlugins();
|
||||
if(this->texture)
|
||||
this->texture->decRef();
|
||||
}
|
||||
|
||||
void
|
||||
Material::decRef(void)
|
||||
{
|
||||
this->refCount--;
|
||||
if(this->refCount)
|
||||
delete this;
|
||||
}
|
||||
|
||||
struct MatStreamData
|
||||
|
@ -349,21 +384,22 @@ Texture::Texture(void)
|
|||
{
|
||||
memset(this->name, 0, 32);
|
||||
memset(this->mask, 0, 32);
|
||||
this->filterAddressing = 0;
|
||||
constructPlugins();
|
||||
}
|
||||
|
||||
Texture::Texture(Texture *t)
|
||||
{
|
||||
memcpy(this->name, t->name, 32);
|
||||
memcpy(this->mask, t->name, 32);
|
||||
this->filterAddressing = t->filterAddressing;
|
||||
copyPlugins(t);
|
||||
this->filterAddressing = (WRAP << 12) | (WRAP << 8) | NEAREST;
|
||||
this->refCount = 1;
|
||||
this->constructPlugins();
|
||||
}
|
||||
|
||||
Texture::~Texture(void)
|
||||
{
|
||||
destructPlugins();
|
||||
this->destructPlugins();
|
||||
}
|
||||
|
||||
void
|
||||
Texture::decRef(void)
|
||||
{
|
||||
this->refCount--;
|
||||
if(this->refCount)
|
||||
delete this;
|
||||
}
|
||||
|
||||
Texture*
|
||||
|
|
24
rw.h
24
rw.h
|
@ -8,18 +8,35 @@ struct Object
|
|||
void *parent;
|
||||
};
|
||||
|
||||
// TODO: raster, link into texdict
|
||||
struct Texture : PluginBase<Texture>
|
||||
{
|
||||
char name[32];
|
||||
char mask[32];
|
||||
uint32 filterAddressing;
|
||||
int32 refCount;
|
||||
|
||||
Texture(void);
|
||||
Texture(Texture *t);
|
||||
~Texture(void);
|
||||
void decRef(void);
|
||||
static Texture *streamRead(std::istream &stream);
|
||||
bool streamWrite(std::ostream &stream);
|
||||
uint32 streamGetSize(void);
|
||||
|
||||
enum FilterMode {
|
||||
NEAREST = 1,
|
||||
LINEAR,
|
||||
MIPNEAREST,
|
||||
MIPLINEAR,
|
||||
LINEARMIPNEAREST,
|
||||
LINEARMIPLINEAR
|
||||
};
|
||||
enum Addressing {
|
||||
WRAP = 1,
|
||||
MIRROR,
|
||||
CLAMP,
|
||||
BORDER
|
||||
};
|
||||
};
|
||||
|
||||
struct Material : PluginBase<Material>
|
||||
|
@ -27,9 +44,11 @@ struct Material : PluginBase<Material>
|
|||
Texture *texture;
|
||||
uint8 color[4];
|
||||
float32 surfaceProps[3];
|
||||
int32 refCount;
|
||||
|
||||
Material(void);
|
||||
Material(Material *m);
|
||||
void decRef(void);
|
||||
~Material(void);
|
||||
static Material *streamRead(std::istream &stream);
|
||||
bool streamWrite(std::ostream &stream);
|
||||
|
@ -78,7 +97,10 @@ struct Geometry : PluginBase<Geometry>, Object
|
|||
|
||||
MeshHeader *meshHeader;
|
||||
|
||||
int32 refCount;
|
||||
|
||||
Geometry(int32 numVerts, int32 numTris, uint32 flags);
|
||||
void decRef(void);
|
||||
~Geometry(void);
|
||||
static Geometry *streamRead(std::istream &stream);
|
||||
bool streamWrite(std::ostream &stream);
|
||||
|
|
Loading…
Reference in New Issue