Skip to content

Commit

Permalink
libgui|ModelDrawable: Model animator state is serializable
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Dec 7, 2016
1 parent cd2ccff commit fe91c63
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
12 changes: 10 additions & 2 deletions doomsday/sdk/libgui/include/de/graphics/modeldrawable.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ class LIBGUI_PUBLIC ModelDrawable : public AssetGroup
*
* @ingroup gl
*/
class LIBGUI_PUBLIC Animator : public Deletable
class LIBGUI_PUBLIC Animator : public Deletable, public ISerializable
{
public:
/**
* Specialized animators may derive from OngoingSequence to extend the amount of
* data associated with each running animation sequence.
*/
class LIBGUI_PUBLIC OngoingSequence
class LIBGUI_PUBLIC OngoingSequence : public ISerializable
{
public:
enum Flag
Expand Down Expand Up @@ -150,6 +150,10 @@ class LIBGUI_PUBLIC ModelDrawable : public AssetGroup
*/
bool atEnd() const;

// ISerializable.
void operator >> (Writer &to) const override;
void operator << (Reader &from) override;

/**
* Constructs an OngoingSequence instance. This is used by default if no other
* constructor is provided.
Expand Down Expand Up @@ -264,6 +268,10 @@ class LIBGUI_PUBLIC ModelDrawable : public AssetGroup
*/
virtual Vector4f extraRotationForNode(String const &nodeName) const;

// ISerializable.
void operator >> (Writer &to) const override;
void operator << (Reader &from) override;

private:
DENG2_PRIVATE(d)
};
Expand Down
30 changes: 30 additions & 0 deletions doomsday/sdk/libgui/src/graphics/modeldrawable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1889,6 +1889,7 @@ void ModelDrawable::Animator::stop(int index)

void ModelDrawable::Animator::clear()
{
qDeleteAll(d->anims);
d->anims.clear();
}

Expand All @@ -1913,6 +1914,17 @@ Vector4f ModelDrawable::Animator::extraRotationForNode(String const &) const
return Vector4f();
}

void ModelDrawable::Animator::operator >> (Writer &to) const
{
to.writeObjects(d->anims);
}

void ModelDrawable::Animator::operator << (Reader &from)
{
clear();
from.readObjects<OngoingSequence>(d->anims, [this] () { return d->constructor(); });
}

void ModelDrawable::Animator::OngoingSequence::initialize()
{}

Expand All @@ -1921,6 +1933,24 @@ bool ModelDrawable::Animator::OngoingSequence::atEnd() const
return time >= duration;
}

void ModelDrawable::Animator::OngoingSequence::operator >> (Writer &to) const
{
to << animId
<< time
<< duration
<< node
<< duint32(flags);
}

void ModelDrawable::Animator::OngoingSequence::operator << (Reader &from)
{
from >> animId
>> time
>> duration
>> node;
from.readAs<duint32>(flags);
}

ModelDrawable::Animator::OngoingSequence *
ModelDrawable::Animator::OngoingSequence::make() // static
{
Expand Down

0 comments on commit fe91c63

Please sign in to comment.