Implemented Rights to render.

This commit is contained in:
Angelo Papenhoff 2015-01-10 22:13:27 +01:00
parent 2fcd3d1cda
commit 2ff25d928e
5 changed files with 140 additions and 20 deletions

View File

@ -377,6 +377,7 @@ Atomic::Atomic(void)
{
this->frame = NULL;
this->geometry = NULL;
this->pipeline = NULL;
constructPlugins();
}
@ -392,6 +393,8 @@ Atomic::~Atomic(void)
destructPlugins();
}
static uint32 atomicRights[2];
Atomic*
Atomic::streamReadClump(Stream *stream,
Frame **frameList, Geometry **geometryList)
@ -402,7 +405,11 @@ Atomic::streamReadClump(Stream *stream,
Atomic *atomic = new Atomic;
atomic->frame = frameList[buf[0]];
atomic->geometry = geometryList[buf[1]];
atomicRights[0] = 0;
atomic->streamReadPlugins(stream);
if(atomicRights[0])
atomic->assertRights(atomicRights[0], atomicRights[1]);
return atomic;
}
@ -440,13 +447,31 @@ Atomic::streamGetSize(void)
static void
readAtomicRights(Stream *stream, int32, void *, int32, int32)
{
uint32 buffer[2];
uint32 version;
stream->seek(-4);
version = stream->readU32();
stream->read(buffer, 8);
// uint32 version;
//stream->seek(-4);
//version = stream->readU32();
stream->read(atomicRights, 8);
// printf("atomicrights: %s %X %X %X\n", DebugFile, LibraryIDUnpackVersion(version), buffer[0], buffer[1]);
printf("atomicrights: %X %X %X\n", LibraryIDUnpackVersion(version), buffer[0], buffer[1]);
// printf("atomicrights: %X %X %X\n", LibraryIDUnpackVersion(version), buffer[0], buffer[1]);
}
static void
writeAtomicRights(Stream *stream, int32, void *object, int32, int32)
{
Atomic *atomic = (Atomic*)object;
uint32 buffer[2];
buffer[0] = atomic->pipeline->pluginID;
buffer[1] = atomic->pipeline->pluginData;
stream->write(buffer, 8);
}
static int32
getSizeAtomicRights(void *object, int32, int32)
{
Atomic *atomic = (Atomic*)object;
if(atomic->pipeline == NULL || atomic->pipeline->pluginID == 0)
return -1;
return 8;
}
void
@ -454,8 +479,9 @@ RegisterAtomicRightsPlugin(void)
{
Atomic::registerPlugin(0, ID_RIGHTTORENDER, NULL, NULL, NULL);
Atomic::registerPluginStream(ID_RIGHTTORENDER,
(StreamRead)readAtomicRights,
NULL, NULL);
readAtomicRights,
writeAtomicRights,
getSizeAtomicRights);
}

View File

@ -278,6 +278,7 @@ Material::Material(void)
this->texture = NULL;
memset(this->color, 0xFF, 4);
surfaceProps[0] = surfaceProps[1] = surfaceProps[2] = 1.0f;
this->pipeline = NULL;
this->refCount = 1;
this->constructPlugins();
}
@ -321,6 +322,8 @@ struct MatStreamData
float32 surfaceProps[3];
};
static uint32 materialRights[2];
Material*
Material::streamRead(Stream *stream)
{
@ -342,8 +345,10 @@ Material::streamRead(Stream *stream)
mat->texture = Texture::streamRead(stream);
}
materialRights[0] = 0;
mat->streamReadPlugins(stream);
if(materialRights[0])
mat->assertRights(materialRights[0], materialRights[1]);
return mat;
}
@ -390,9 +395,27 @@ Material::streamGetSize(void)
static void
readMaterialRights(Stream *stream, int32, void *, int32, int32)
{
stream->read(materialRights, 8);
// printf("materialrights: %X %X\n", buffer[0], buffer[1]);
}
static void
writeMaterialRights(Stream *stream, int32, void *object, int32, int32)
{
Material *material = (Material*)object;
uint32 buffer[2];
stream->read(buffer, 8);
printf("materialrights: %X %X\n", buffer[0], buffer[1]);
buffer[0] = material->pipeline->pluginID;
buffer[1] = material->pipeline->pluginData;
stream->write(buffer, 8);
}
static int32
getSizeMaterialRights(void *object, int32, int32)
{
Material *material = (Material*)object;
if(material->pipeline == NULL || material->pipeline->pluginID == 0)
return -1;
return 8;
}
void
@ -400,8 +423,9 @@ RegisterMaterialRightsPlugin(void)
{
Material::registerPlugin(0, ID_RIGHTTORENDER, NULL, NULL, NULL);
Material::registerPluginStream(ID_RIGHTTORENDER,
(StreamRead)readMaterialRights,
NULL, NULL);
readMaterialRights,
writeMaterialRights,
getSizeMaterialRights);
}

View File

@ -209,6 +209,8 @@ RegisterNativeDataPlugin(void)
// Skin
SkinGlobals_ SkinGlobals = { 0, NULL };
static void*
createSkin(void *object, int32 offset, int32)
{
@ -418,13 +420,26 @@ getSizeSkin(void *object, int32 offset, int32)
return size;
}
static void
skinRights(void *object, int32, int32, uint32 data)
{
((Atomic*)object)->pipeline = SkinGlobals.pipeline;
}
void
RegisterSkinPlugin(void)
{
Geometry::registerPlugin(sizeof(Skin*), ID_SKIN,
SkinGlobals.pipeline = new Pipeline;
SkinGlobals.pipeline->pluginID = ID_SKIN;
SkinGlobals.pipeline->pluginData = 1;
SkinGlobals.offset = Geometry::registerPlugin(sizeof(Skin*), ID_SKIN,
createSkin, destroySkin, copySkin);
Geometry::registerPluginStream(ID_SKIN,
readSkin, writeSkin, getSizeSkin);
Atomic::registerPlugin(0, ID_SKIN,
NULL, NULL, NULL);
Atomic::setStreamRightsCallback(ID_SKIN, skinRights);
}
// Atomic MatFX
@ -447,13 +462,14 @@ static void
readAtomicMatFX(Stream *stream, int32, void *object, int32 offset, int32)
{
int32 flag;
// uint32 version;
uint32 version;
//stream->seek(-4);
//version = stream->readU32();
stream->read(&flag, 4);
//printf("atomicMatFX: %X %X\n", LibraryIDUnpackVersion(version), flag);
*PLUGINOFFSET(int32, object, offset) = flag;
// TODO: set Pipeline
if(flag)
((Atomic*)object)->pipeline = MatFXGlobals.pipeline;
}
static void
@ -474,6 +490,8 @@ getSizeAtomicMatFX(void *object, int32 offset, int32)
// Material MatFX
MatFXGlobals_ MatFXGlobals = { 0, 0, NULL };
// TODO: Frames and Matrices?
static void
clearMatFX(MatFX *matfx)
@ -735,12 +753,19 @@ getSizeMaterialMatFX(void *object, int32 offset, int32)
void
RegisterMatFXPlugin(void)
{
MatFXGlobals.pipeline = new Pipeline;
MatFXGlobals.pipeline->pluginID = ID_MATFX;
MatFXGlobals.pipeline->pluginData = 0;
MatFXGlobals.atomicOffset =
Atomic::registerPlugin(sizeof(int32), ID_MATFX,
createAtomicMatFX, NULL, copyAtomicMatFX);
Atomic::registerPluginStream(ID_MATFX,
readAtomicMatFX,
writeAtomicMatFX,
getSizeAtomicMatFX);
MatFXGlobals.materialOffset =
Material::registerPlugin(sizeof(MatFX*), ID_MATFX,
createMaterialMatFX, destroyMaterialMatFX,
copyMaterialMatFX);

View File

@ -92,6 +92,7 @@ struct Material : PluginBase<Material>
Texture *texture;
uint8 color[4];
float32 surfaceProps[3];
Pipeline *pipeline;
int32 refCount;
Material(void);
@ -103,6 +104,8 @@ struct Material : PluginBase<Material>
uint32 streamGetSize(void);
};
void RegisterMaterialRightsPlugin(void);
struct MatFX
{
enum Flags {
@ -150,7 +153,13 @@ struct MatFX
int32 getEffectIndex(uint32 type);
};
void RegisterMaterialRightsPlugin(void);
struct MatFXGlobals_
{
int32 atomicOffset;
int32 materialOffset;
Pipeline *pipeline;
};
extern MatFXGlobals_ MatFXGlobals;
void RegisterMatFXPlugin(void);
struct Mesh
@ -227,6 +236,9 @@ struct Geometry : PluginBase<Geometry>, Object
};
};
void RegisterMeshPlugin(void);
void RegisterNativeDataPlugin(void);
struct Skin
{
int32 numBones;
@ -239,8 +251,12 @@ struct Skin
uint8 *data; // only used by delete
};
void RegisterMeshPlugin(void);
void RegisterNativeDataPlugin(void);
struct SkinGlobals_
{
int32 offset;
Pipeline *pipeline;
};
extern SkinGlobals_ SkinGlobals;
void RegisterSkinPlugin(void);
struct Clump;
@ -266,6 +282,7 @@ struct Atomic : PluginBase<Atomic>, Object
Frame *frame;
Geometry *geometry;
Clump *clump;
Pipeline *pipeline;
Atomic(void);
Atomic(Atomic *a);

View File

@ -9,6 +9,7 @@ typedef void *(*CopyConstructor)(void *dst, void *src, int32 offset, int32 size)
typedef void (*StreamRead)(Stream *stream, int32 length, void *object, int32 offset, int32 size);
typedef void (*StreamWrite)(Stream *stream, int32 length, void *object, int32 offset, int32 size);
typedef int32 (*StreamGetSize)(void *object, int32 offset, int32 size);
typedef void (*RightsCallback)(void *object, int32 offset, int32 size, uint32 data);
struct Plugin
{
@ -21,6 +22,7 @@ struct Plugin
StreamRead read;
StreamWrite write;
StreamGetSize getSize;
RightsCallback rightsCallback;
Plugin *next;
};
@ -37,11 +39,13 @@ struct PluginBase
void streamReadPlugins(Stream *stream);
void streamWritePlugins(Stream *stream);
int streamGetPluginSize(void);
void assertRights(uint32 pluginID, uint32 data);
static int registerPlugin(int size, uint id,
Constructor, Destructor, CopyConstructor);
static int registerPluginStream(uint id,
StreamRead, StreamWrite, StreamGetSize);
static int setStreamRightsCallback(uint id, RightsCallback cb);
static int getPluginOffset(uint id);
static void *operator new(size_t size);
static void operator delete(void *p);
@ -125,6 +129,18 @@ PluginBase<T>::streamGetPluginSize(void)
return size;
}
template <typename T> void
PluginBase<T>::assertRights(uint32 pluginID, uint32 data)
{
for(Plugin *p = this->s_plugins; p; p = p->next)
if(p->id == pluginID){
if(p->rightsCallback)
p->rightsCallback(this,
p->offset, p->size, data);
return;
}
}
template <typename T> int
PluginBase<T>::registerPlugin(int size, uint id,
Constructor ctor, Destructor dtor, CopyConstructor cctor)
@ -141,6 +157,7 @@ PluginBase<T>::registerPlugin(int size, uint id,
p->read = NULL;
p->write = NULL;
p->getSize = NULL;
p->rightsCallback = NULL;
p->next = s_plugins;
s_plugins = p;
@ -161,6 +178,17 @@ PluginBase<T>::registerPluginStream(uint id,
return -1;
}
template <typename T> int
PluginBase<T>::setStreamRightsCallback(uint id, RightsCallback cb)
{
for(Plugin *p = PluginBase<T>::s_plugins; p; p = p->next)
if(p->id == id){
p->rightsCallback = cb;
return p->offset;
}
return -1;
}
template <typename T> int
PluginBase<T>::getPluginOffset(uint id)
{