From bcbb72013091db29a085d044f200c10d66b7c47a Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Wed, 5 Sep 2012 22:06:35 +0200 Subject: [PATCH] added type description of simple animation --- src/graphics/Animation.cpp | 27 +++++++++++++++++++++++++++ src/graphics/Animation.h | 8 ++++++++ src/graphics/SimpleAnimation.cpp | 32 ++++++++++++++++++++++++++++++++ src/graphics/SimpleAnimation.h | 2 ++ 4 files changed, 69 insertions(+) create mode 100644 src/graphics/Animation.cpp create mode 100644 src/graphics/SimpleAnimation.cpp 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; } -- 2.39.2