mirror of
https://github.com/aap/librw.git
synced 2025-04-30 21:43:45 +01:00
implemented many create/clone/destroy functions
This commit is contained in:
parent
15872ba211
commit
02c809625a
104
src/clump.cpp
104
src/clump.cpp
@ -40,9 +40,47 @@ Frame::create(void)
|
|||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Frame*
|
||||||
|
Frame::cloneHierarchy(void)
|
||||||
|
{
|
||||||
|
Frame *frame = this->cloneAndLink(NULL);
|
||||||
|
frame->purgeClone();
|
||||||
|
return frame;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Frame::destroy(void)
|
Frame::destroy(void)
|
||||||
{
|
{
|
||||||
|
this->destructPlugins();
|
||||||
|
Frame *parent = this->getParent();
|
||||||
|
Frame *child;
|
||||||
|
if(parent){
|
||||||
|
// remove from child list
|
||||||
|
child = parent->child;
|
||||||
|
if(child == this)
|
||||||
|
parent->child = this->next;
|
||||||
|
else{
|
||||||
|
for(child = child->next; child != this; child = child->next)
|
||||||
|
;
|
||||||
|
child->next = this->next;
|
||||||
|
}
|
||||||
|
this->object.parent = NULL;
|
||||||
|
// Doesn't seem to make much sense, blame criterion.
|
||||||
|
this->setHierarchyRoot(this);
|
||||||
|
}
|
||||||
|
for(Frame *f = this->child; f; f = f->next)
|
||||||
|
f->object.parent = NULL;
|
||||||
|
free(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Frame::destroyHierarchy(void)
|
||||||
|
{
|
||||||
|
Frame *next;
|
||||||
|
for(Frame *child = this->child; child; child = next){
|
||||||
|
next = child->next;
|
||||||
|
child->destroyHierarchy();
|
||||||
|
}
|
||||||
this->destructPlugins();
|
this->destructPlugins();
|
||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
@ -138,6 +176,43 @@ Frame::setDirty(void)
|
|||||||
this->forAllChildren(dirtyCB, NULL);
|
this->forAllChildren(dirtyCB, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Frame::setHierarchyRoot(Frame *root)
|
||||||
|
{
|
||||||
|
this->root = root;
|
||||||
|
for(Frame *child = this->child; child; child = child->next)
|
||||||
|
child->setHierarchyRoot(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clone a frame hierarchy. Link cloned frames into Frame::root of the originals.
|
||||||
|
Frame*
|
||||||
|
Frame::cloneAndLink(Frame *clonedroot)
|
||||||
|
{
|
||||||
|
Frame *frame = Frame::create();
|
||||||
|
if(clonedroot == NULL)
|
||||||
|
clonedroot = frame;
|
||||||
|
frame->object.copy(&this->object);
|
||||||
|
memcpy(frame->matrix, this->matrix, sizeof(this->matrix));
|
||||||
|
frame->root = clonedroot;
|
||||||
|
this->root = frame; // Remember cloned frame
|
||||||
|
for(Frame *child = this->child; child; child = child->next){
|
||||||
|
Frame *clonedchild = child->cloneAndLink(clonedroot);
|
||||||
|
clonedchild->next = frame->child;
|
||||||
|
frame->child = clonedchild;
|
||||||
|
clonedchild->object.parent = frame;
|
||||||
|
}
|
||||||
|
frame->copyPlugins(this);
|
||||||
|
return frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove links to cloned frames from hierarchy.
|
||||||
|
void
|
||||||
|
Frame::purgeClone(void)
|
||||||
|
{
|
||||||
|
Frame *parent = this->getParent();
|
||||||
|
this->setHierarchyRoot(parent ? parent->root : this);
|
||||||
|
}
|
||||||
|
|
||||||
static Frame*
|
static Frame*
|
||||||
sizeCB(Frame *f, void *size)
|
sizeCB(Frame *f, void *size)
|
||||||
{
|
{
|
||||||
@ -176,7 +251,15 @@ Clump*
|
|||||||
Clump::clone(void)
|
Clump::clone(void)
|
||||||
{
|
{
|
||||||
Clump *clump = Clump::create();
|
Clump *clump = Clump::create();
|
||||||
// TODO actually clone
|
Frame *root = this->getFrame()->cloneHierarchy();
|
||||||
|
clump->setFrame(root);
|
||||||
|
FORLIST(lnk, this->atomics){
|
||||||
|
Atomic *a = Atomic::fromClump(lnk);
|
||||||
|
Atomic *atomic = a->clone();
|
||||||
|
atomic->setFrame(a->getFrame()->root);
|
||||||
|
clump->addAtomic(atomic);
|
||||||
|
}
|
||||||
|
root->purgeClone();
|
||||||
clump->copyPlugins(this);
|
clump->copyPlugins(this);
|
||||||
return clump;
|
return clump;
|
||||||
}
|
}
|
||||||
@ -184,7 +267,14 @@ Clump::clone(void)
|
|||||||
void
|
void
|
||||||
Clump::destroy(void)
|
Clump::destroy(void)
|
||||||
{
|
{
|
||||||
|
Frame *f;
|
||||||
this->destructPlugins();
|
this->destructPlugins();
|
||||||
|
FORLIST(lnk, this->atomics)
|
||||||
|
Atomic::fromClump(lnk)->destroy();
|
||||||
|
FORLIST(lnk, this->lights)
|
||||||
|
Light::fromClump(lnk)->destroy();
|
||||||
|
if(f = this->getFrame())
|
||||||
|
f->destroyHierarchy();
|
||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -451,7 +541,13 @@ Atomic*
|
|||||||
Atomic::clone()
|
Atomic::clone()
|
||||||
{
|
{
|
||||||
Atomic *atomic = Atomic::create();
|
Atomic *atomic = Atomic::create();
|
||||||
//TODO
|
atomic->object.copy(&this->object);
|
||||||
|
atomic->object.privateFlags |= 1;
|
||||||
|
if(this->geometry){
|
||||||
|
atomic->geometry = this->geometry;
|
||||||
|
atomic->geometry->refCount++;
|
||||||
|
}
|
||||||
|
atomic->pipeline = this->pipeline;
|
||||||
atomic->copyPlugins(this);
|
atomic->copyPlugins(this);
|
||||||
return atomic;
|
return atomic;
|
||||||
}
|
}
|
||||||
@ -459,8 +555,10 @@ Atomic::clone()
|
|||||||
void
|
void
|
||||||
Atomic::destroy(void)
|
Atomic::destroy(void)
|
||||||
{
|
{
|
||||||
//TODO
|
|
||||||
this->destructPlugins();
|
this->destructPlugins();
|
||||||
|
if(this->geometry)
|
||||||
|
this->geometry->destroy();
|
||||||
|
this->setFrame(NULL);
|
||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,6 +64,13 @@ struct Object
|
|||||||
this->privateFlags = 0;
|
this->privateFlags = 0;
|
||||||
this->parent = NULL;
|
this->parent = NULL;
|
||||||
}
|
}
|
||||||
|
void copy(Object *o){
|
||||||
|
this->type = o->type;
|
||||||
|
this->subType = o->subType;
|
||||||
|
this->flags = o->flags;
|
||||||
|
this->privateFlags = o->privateFlags;
|
||||||
|
this->parent = NULL;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Frame : PluginBase<Frame>
|
struct Frame : PluginBase<Frame>
|
||||||
@ -85,14 +92,22 @@ struct Frame : PluginBase<Frame>
|
|||||||
|
|
||||||
// MEM create, clonehiearchy, destroy, destroy hierarchy
|
// MEM create, clonehiearchy, destroy, destroy hierarchy
|
||||||
static Frame *create(void);
|
static Frame *create(void);
|
||||||
|
Frame *cloneHierarchy(void);
|
||||||
void destroy(void);
|
void destroy(void);
|
||||||
|
void destroyHierarchy(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);
|
||||||
|
Frame *getParent(void){
|
||||||
|
return (Frame*)this->object.parent;
|
||||||
|
}
|
||||||
int32 count(void);
|
int32 count(void);
|
||||||
void updateLTM(void);
|
void updateLTM(void);
|
||||||
void setDirty(void);
|
void setDirty(void);
|
||||||
|
|
||||||
|
void setHierarchyRoot(Frame *root);
|
||||||
|
Frame *cloneAndLink(Frame *clonedroot);
|
||||||
|
void purgeClone(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
Frame **makeFrameList(Frame *frame, Frame **flist);
|
Frame **makeFrameList(Frame *frame, Frame **flist);
|
||||||
@ -515,6 +530,7 @@ struct Atomic : PluginBase<Atomic>
|
|||||||
Atomic *clone(void);
|
Atomic *clone(void);
|
||||||
void destroy(void);
|
void destroy(void);
|
||||||
void setFrame(Frame *f) { this->object.setFrame(f); }
|
void setFrame(Frame *f) { this->object.setFrame(f); }
|
||||||
|
Frame *getFrame(void) { return (Frame*)this->object.parent; }
|
||||||
static Atomic *fromClump(LLLink *lnk){
|
static Atomic *fromClump(LLLink *lnk){
|
||||||
return LLLinkGetData(lnk, Atomic, inClump);
|
return LLLinkGetData(lnk, Atomic, inClump);
|
||||||
}
|
}
|
||||||
@ -553,6 +569,12 @@ struct Clump : PluginBase<Clump>
|
|||||||
l->clump = this;
|
l->clump = this;
|
||||||
this->lights.append(&l->inClump);
|
this->lights.append(&l->inClump);
|
||||||
}
|
}
|
||||||
|
void setFrame(Frame *f){
|
||||||
|
this->object.parent = f;
|
||||||
|
}
|
||||||
|
Frame *getFrame(void){
|
||||||
|
return (Frame*)this->object.parent;
|
||||||
|
}
|
||||||
static Clump *streamRead(Stream *stream);
|
static Clump *streamRead(Stream *stream);
|
||||||
bool streamWrite(Stream *stream);
|
bool streamWrite(Stream *stream);
|
||||||
uint32 streamGetSize(void);
|
uint32 streamGetSize(void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user