From: Daniel Karbach Date: Wed, 5 Sep 2012 20:27:02 +0000 (+0200) Subject: added type description of complex animation X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=20e3191911c173d6c9b97dde6b99bd96f5e342cb;p=l2e.git added type description of complex animation --- diff --git a/src/graphics/ComplexAnimation.cpp b/src/graphics/ComplexAnimation.cpp new file mode 100644 index 0000000..b54baf9 --- /dev/null +++ b/src/graphics/ComplexAnimation.cpp @@ -0,0 +1,43 @@ +/* + * ComplexAnimation.cpp + * + * Created on: Sep 5, 2012 + * Author: holy + */ + +#include "ComplexAnimation.h" + +#include "../loader/TypeDescription.h" + +using loader::FieldDescription; +using loader::TypeDescription; + +namespace graphics { + +void ComplexAnimation::CreateTypeDescription() { + ComplexAnimation ca; + Animation *a(&ca); + TypeDescription &td(TypeDescription::CreateOrGet("ComplexAnimation")); + + td.SetSize(sizeof(ComplexAnimation)); + td.AddSupertype(TypeDescription::GetTypeId("Animation"), ((char *)a) - ((char *)&ca)); + + int frameId(TypeDescription::GetTypeId("ComplexAnimationFrame")); + + td.AddField("frames", FieldDescription(((char *)&ca.frames) - ((char *)&ca), frameId, true, true)); + + + FrameProp fp; + TypeDescription &ftd(TypeDescription::CreateOrGet("ComplexAnimationFrame")); + + ftd.SetSize(sizeof(FrameProp)); + + int numberId(TypeDescription::GetTypeId("Number")); + int vectorId(TypeDescription::GetTypeId("Vector")); + + ftd.AddField("column", FieldDescription(((char *)&fp.col) - ((char *)&fp), numberId, false)); + ftd.AddField("row", FieldDescription(((char *)&fp.row) - ((char *)&fp), numberId, false)); + ftd.AddField("disposition", FieldDescription(((char *)&fp.disposition) - ((char *)&fp), vectorId, false)); +} + +} diff --git a/src/graphics/ComplexAnimation.h b/src/graphics/ComplexAnimation.h index 815e9c5..a548cdb 100644 --- a/src/graphics/ComplexAnimation.h +++ b/src/graphics/ComplexAnimation.h @@ -10,27 +10,15 @@ #include "Animation.h" -#include - namespace graphics { class ComplexAnimation : public Animation { public: - ComplexAnimation() { } + ComplexAnimation() : frames(0), numFrames(0) { } ComplexAnimation(const Sprite *sprite, int frameTime, bool repeat = false) - : Animation(sprite, frameTime, repeat) { } - -public: - void AddFrame(int col, int row, const geometry::Vector &disposition = geometry::Vector()) { - frames.push_back(FrameProp(col, row, disposition)); - } - void AddFrames(int col, int row, const geometry::Vector &disposition, int amount) { - for (int i(0); i < amount; ++i) { - AddFrame(col, row, disposition); - } - } + : Animation(sprite, frameTime, repeat), frames(0), numFrames(0) { } public: struct FrameProp { @@ -41,16 +29,19 @@ public: int row; geometry::Vector disposition; }; - void AddFrame(const FrameProp &f) { frames.push_back(f); } + void SetFrames(const FrameProp *f, int num) { frames = f; numFrames = num; } + + static void CreateTypeDescription(); protected: - virtual int NumFrames() const { return frames.size(); }; + virtual int NumFrames() const { return numFrames; }; virtual int Col(int frame) const { return frames[frame].col; } virtual int Row(int frame) const { return frames[frame].row; } virtual geometry::Vector Offset(int frame) const { return frames[frame].disposition; } private: - std::vector frames; + const FrameProp *frames; + int numFrames; };