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

View File

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

View File

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

View File

@ -92,6 +92,7 @@ struct Material : PluginBase<Material>
Texture *texture; Texture *texture;
uint8 color[4]; uint8 color[4];
float32 surfaceProps[3]; float32 surfaceProps[3];
Pipeline *pipeline;
int32 refCount; int32 refCount;
Material(void); Material(void);
@ -103,6 +104,8 @@ struct Material : PluginBase<Material>
uint32 streamGetSize(void); uint32 streamGetSize(void);
}; };
void RegisterMaterialRightsPlugin(void);
struct MatFX struct MatFX
{ {
enum Flags { enum Flags {
@ -150,7 +153,13 @@ struct MatFX
int32 getEffectIndex(uint32 type); int32 getEffectIndex(uint32 type);
}; };
void RegisterMaterialRightsPlugin(void); struct MatFXGlobals_
{
int32 atomicOffset;
int32 materialOffset;
Pipeline *pipeline;
};
extern MatFXGlobals_ MatFXGlobals;
void RegisterMatFXPlugin(void); void RegisterMatFXPlugin(void);
struct Mesh struct Mesh
@ -227,6 +236,9 @@ struct Geometry : PluginBase<Geometry>, Object
}; };
}; };
void RegisterMeshPlugin(void);
void RegisterNativeDataPlugin(void);
struct Skin struct Skin
{ {
int32 numBones; int32 numBones;
@ -239,8 +251,12 @@ struct Skin
uint8 *data; // only used by delete uint8 *data; // only used by delete
}; };
void RegisterMeshPlugin(void); struct SkinGlobals_
void RegisterNativeDataPlugin(void); {
int32 offset;
Pipeline *pipeline;
};
extern SkinGlobals_ SkinGlobals;
void RegisterSkinPlugin(void); void RegisterSkinPlugin(void);
struct Clump; struct Clump;
@ -266,6 +282,7 @@ struct Atomic : PluginBase<Atomic>, Object
Frame *frame; Frame *frame;
Geometry *geometry; Geometry *geometry;
Clump *clump; Clump *clump;
Pipeline *pipeline;
Atomic(void); Atomic(void);
Atomic(Atomic *a); 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 (*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 void (*StreamWrite)(Stream *stream, int32 length, void *object, int32 offset, int32 size);
typedef int32 (*StreamGetSize)(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 struct Plugin
{ {
@ -21,6 +22,7 @@ struct Plugin
StreamRead read; StreamRead read;
StreamWrite write; StreamWrite write;
StreamGetSize getSize; StreamGetSize getSize;
RightsCallback rightsCallback;
Plugin *next; Plugin *next;
}; };
@ -37,11 +39,13 @@ struct PluginBase
void streamReadPlugins(Stream *stream); void streamReadPlugins(Stream *stream);
void streamWritePlugins(Stream *stream); void streamWritePlugins(Stream *stream);
int streamGetPluginSize(void); int streamGetPluginSize(void);
void assertRights(uint32 pluginID, uint32 data);
static int registerPlugin(int size, uint id, static int registerPlugin(int size, uint id,
Constructor, Destructor, CopyConstructor); Constructor, Destructor, CopyConstructor);
static int registerPluginStream(uint id, static int registerPluginStream(uint id,
StreamRead, StreamWrite, StreamGetSize); StreamRead, StreamWrite, StreamGetSize);
static int setStreamRightsCallback(uint id, RightsCallback cb);
static int getPluginOffset(uint id); static int getPluginOffset(uint id);
static void *operator new(size_t size); static void *operator new(size_t size);
static void operator delete(void *p); static void operator delete(void *p);
@ -125,6 +129,18 @@ PluginBase<T>::streamGetPluginSize(void)
return size; 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 template <typename T> int
PluginBase<T>::registerPlugin(int size, uint id, PluginBase<T>::registerPlugin(int size, uint id,
Constructor ctor, Destructor dtor, CopyConstructor cctor) Constructor ctor, Destructor dtor, CopyConstructor cctor)
@ -141,6 +157,7 @@ PluginBase<T>::registerPlugin(int size, uint id,
p->read = NULL; p->read = NULL;
p->write = NULL; p->write = NULL;
p->getSize = NULL; p->getSize = NULL;
p->rightsCallback = NULL;
p->next = s_plugins; p->next = s_plugins;
s_plugins = p; s_plugins = p;
@ -161,6 +178,17 @@ PluginBase<T>::registerPluginStream(uint id,
return -1; 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 template <typename T> int
PluginBase<T>::getPluginOffset(uint id) PluginBase<T>::getPluginOffset(uint id)
{ {