1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-11-29 03:33:48 +00:00

Remove RenderObject::updateAfterParent; simplify + clarify ParentManaged logic

SkeletalSprite was the only thing using it.
Instead of PM_STATIC it's now added to its Entity as PM_NONE.
PM_NONE is not auto-updated so SkeletalSprite::update() is now called
at the end of Entity::onUpdate()

(There's now a bug that during spirit form the screen stays black,
probably added that in an earlier commit. Will fix.)

(On second tought, maybe ParentManaged should be boolean.
Instead add a noAutoUpdate flag. But i'll save that for another time when i get around
to move all RenderObject bools into a bitmask.)
This commit is contained in:
fgenesis 2022-05-20 03:27:15 +02:00
parent 68b3c61852
commit 5c419efd79
6 changed files with 20 additions and 31 deletions

View file

@ -721,7 +721,7 @@ void Avatar::applyWorldEffects(WorldType type)
skeletalSprite.setFreeze(false); skeletalSprite.setFreeze(false);
if (!skeletalSprite.getParent()) if (!skeletalSprite.getParent())
{ {
addChild(&skeletalSprite, PM_STATIC); addChild(&skeletalSprite, PM_NONE);
} }
skeletalSprite.position = Vector(0,0,0); skeletalSprite.position = Vector(0,0,0);
skeletalSprite.scale = Vector(1,1,1); skeletalSprite.scale = Vector(1,1,1);

View file

@ -237,9 +237,8 @@ Entity::Entity()
skeletalSprite.updateAfterParent = 1;
skeletalSprite.setAnimationKeyNotify(this); skeletalSprite.setAnimationKeyNotify(this);
addChild(&skeletalSprite, PM_STATIC); addChild(&skeletalSprite, PM_NONE);
@ -1471,6 +1470,8 @@ void Entity::onEndOfLife()
dsq->game->entityDied(this); dsq->game->entityDied(this);
calledEntityDied = true; calledEntityDied = true;
} }
skeletalSprite.safeKill();
} }
void Entity::setPoison(float m, float t) void Entity::setPoison(float m, float t)
@ -1692,6 +1693,8 @@ void Entity::onUpdate(float dt)
} }
updateLance(dt); updateLance(dt);
skeletalSprite.update(dt);
} }
void Entity::updateBoneLock() void Entity::updateBoneLock()

View file

@ -98,7 +98,6 @@ RenderObject::RenderObject()
addType(SCO_RENDEROBJECT); addType(SCO_RENDEROBJECT);
useOldDT = false; useOldDT = false;
updateAfterParent = false;
ignoreUpdate = false; ignoreUpdate = false;
overrideRenderPass = OVERRIDE_NONE; overrideRenderPass = OVERRIDE_NONE;
renderPass = 0; renderPass = 0;
@ -146,6 +145,7 @@ RenderObject::RenderObject()
RenderObject::~RenderObject() RenderObject::~RenderObject()
{ {
freeMotionBlur(); freeMotionBlur();
assert(children.empty()); // if this fires some objects were not deleted and will leak
} }
Vector RenderObject::getWorldPosition() const Vector RenderObject::getWorldPosition() const
@ -335,16 +335,9 @@ void RenderObject::destroy()
// must do this first // must do this first
// otherwise child will try to remove THIS // otherwise child will try to remove THIS
(*i)->parent = 0; (*i)->parent = 0;
switch ((*i)->pm) (*i)->destroy();
{ if((*i)->pm == PM_POINTER)
case PM_STATIC:
(*i)->destroy();
break;
case PM_POINTER:
(*i)->destroy();
delete (*i); delete (*i);
break;
}
} }
children.clear(); children.clear();
@ -766,19 +759,7 @@ void RenderObject::update(float dt)
} }
if (!isDead()) if (!isDead())
{ {
onUpdate(dt); onUpdate(dt);
if (isHidden())
return;
for (Children::iterator i = children.begin(); i != children.end(); i++)
{
if ((*i)->updateAfterParent && (((*i)->pm == PM_POINTER) || ((*i)->pm == PM_STATIC)))
{
(*i)->update(dt);
}
}
} }
} }
@ -881,7 +862,7 @@ void RenderObject::onUpdate(float dt)
if (shareColorWithChildren) if (shareColorWithChildren)
(*i)->color = this->color; (*i)->color = this->color;
if (!(*i)->updateAfterParent && (((*i)->pm == PM_POINTER) || ((*i)->pm == PM_STATIC))) if ((*i)->pm != PM_NONE)
{ {
(*i)->update(dt); (*i)->update(dt);
} }
@ -900,7 +881,8 @@ void RenderObject::onUpdate(float dt)
{ {
ro->parent = NULL; ro->parent = NULL;
ro->destroy(); ro->destroy();
delete ro; if(ro->pm == PM_POINTER)
delete ro;
} }
else else
children[w++] = ro; children[w++] = ro;

View file

@ -48,9 +48,9 @@ enum AutoSize
enum ParentManaged enum ParentManaged
{ {
PM_NONE = 0, PM_NONE = 0, // child is destroyed with parent, but not deleted. The childs' update() is NOT called.
PM_POINTER = 1, PM_POINTER = 1, // child is deleted together with parent. update() is called.
PM_STATIC = 2 PM_STATIC = 2 // child is destroyed with parent, but not deleted. update() is called.
}; };
enum ChildOrder enum ChildOrder
@ -237,7 +237,6 @@ public:
// TODO: this should be a bitmask // TODO: this should be a bitmask
bool fadeAlphaWithLife; bool fadeAlphaWithLife;
bool renderBeforeParent; bool renderBeforeParent;
bool updateAfterParent;
bool shareAlphaWithChildren; bool shareAlphaWithChildren;
bool shareColorWithChildren; bool shareColorWithChildren;
bool cull; bool cull;

View file

@ -804,6 +804,9 @@ SkeletalSprite::SkeletalSprite() : RenderObject()
selectedBone = -1; selectedBone = -1;
} }
SkeletalSprite::~SkeletalSprite()
{
}
void SkeletalSprite::setAnimationKeyNotify(RenderObject *r) void SkeletalSprite::setAnimationKeyNotify(RenderObject *r)
{ {

View file

@ -225,6 +225,8 @@ class SkeletalSprite : public RenderObject
public: public:
SkeletalSprite(); SkeletalSprite();
virtual ~SkeletalSprite();
void loadSkeletal(const std::string &fn); void loadSkeletal(const std::string &fn);
bool saveSkeletal(const std::string &fn); bool saveSkeletal(const std::string &fn);
void loadSkin(const std::string &fn); void loadSkin(const std::string &fn);