From: Daniel Karbach Date: Wed, 5 Sep 2012 20:06:35 +0000 (+0200) Subject: added type description of simple animation X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=bcbb72013091db29a085d044f200c10d66b7c47a;p=l2e.git added type description of simple animation --- diff --git a/src/graphics/Animation.cpp b/src/graphics/Animation.cpp new file mode 100644 index 0000000..caffb50 --- /dev/null +++ b/src/graphics/Animation.cpp @@ -0,0 +1,27 @@ +/* + * Animation.cpp + * + * Created on: Sep 5, 2012 + * Author: holy + */ + +#include "Animation.h" + +#include "../loader/TypeDescription.h" + +using loader::FieldDescription; +using loader::TypeDescription; + +namespace graphics { + +void AddFields(TypeDescription &td, const Animation &a, std::ptrdiff_t offset) { + int boolId(TypeDescription::GetTypeId("Boolean")); + int numberId(TypeDescription::GetTypeId("Number")); + int spriteId(TypeDescription::GetTypeId("Sprite")); + + td.AddField("sprite", FieldDescription(((char *)&a.sprite) - ((char *)&a) - offset, spriteId, true)); + td.AddField("frametime", FieldDescription(((char *)&a.frameTime) - ((char *)&a) - offset, numberId, false)); + td.AddField("repeat", FieldDescription(((char *)&a.repeat) - ((char *)&a) - offset, boolId, false)); +} + +} diff --git a/src/graphics/Animation.h b/src/graphics/Animation.h index 2696694..ee62493 100644 --- a/src/graphics/Animation.h +++ b/src/graphics/Animation.h @@ -14,8 +14,13 @@ #include "../app/Timer.h" #include "../geometry/Vector.h" +#include #include +namespace loader { + class TypeDescription; +} + namespace graphics { class Animation { @@ -43,6 +48,9 @@ public: virtual int Row(int frame) const = 0; virtual geometry::Vector Offset(int frame) const { return geometry::Vector(); } +protected: + static void AddFields(loader::TypeDescription &, const Animation &, std::ptrdiff_t offset); + private: const Sprite *sprite; int frameTime; diff --git a/src/graphics/SimpleAnimation.cpp b/src/graphics/SimpleAnimation.cpp new file mode 100644 index 0000000..4e16b81 --- /dev/null +++ b/src/graphics/SimpleAnimation.cpp @@ -0,0 +1,32 @@ +/* + * SimpleAnimation.cpp + * + * Created on: Sep 5, 2012 + * Author: holy + */ + +#include "SimpleAnimation.h" + +#include "../loader/TypeDescription.h" + +using loader::FieldDescription; +using loader::TypeDescription; + +namespace graphics { + +void SimpleAnimation::CreateTypeDescription() { + SimpleAnimation sa; + Animation *a(&sa); + TypeDescription &td(TypeDescription::CreateOrGet("SimpleAnimation")); + + td.SetSize(sizeof(SimpleAnimation)); + td.AddSupertype(TypeDescription::GetTypeId("Animation"), ((char *)a) - ((char *)&sa)); + + int numberId(TypeDescription::GetTypeId("Number")); + + td.AddField("framecount", FieldDescription(((char *)&sa.numFrames) - ((char *)&sa), numberId, false)); + td.AddField("col", FieldDescription(((char *)&sa.col) - ((char *)&sa), numberId, false)); + td.AddField("row", FieldDescription(((char *)&sa.row) - ((char *)&sa), numberId, false)); +} + +} diff --git a/src/graphics/SimpleAnimation.h b/src/graphics/SimpleAnimation.h index 003a031..81d6244 100644 --- a/src/graphics/SimpleAnimation.h +++ b/src/graphics/SimpleAnimation.h @@ -26,6 +26,8 @@ public: void SetCol(int c) { col = c; } void SetRow(int r) { row = r; } + static void CreateTypeDescription(); + protected: virtual int NumFrames() const { return numFrames; }; virtual int Col(int frame) const { return col; }