]> git.localhorst.tv Git - l2e.git/commitdiff
added type description of complex animation
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 5 Sep 2012 20:27:02 +0000 (22:27 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 5 Sep 2012 20:57:05 +0000 (22:57 +0200)
src/graphics/ComplexAnimation.cpp [new file with mode: 0644]
src/graphics/ComplexAnimation.h

diff --git a/src/graphics/ComplexAnimation.cpp b/src/graphics/ComplexAnimation.cpp
new file mode 100644 (file)
index 0000000..b54baf9
--- /dev/null
@@ -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));
+}
+
+}
index 815e9c5a6e4183c88de7225e4721b67a4521033c..a548cdbb9931b92d6be76388be0713765f0b1497 100644 (file)
 
 #include "Animation.h"
 
-#include <vector>
-
 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<int> &disposition = geometry::Vector<int>()) {
-               frames.push_back(FrameProp(col, row, disposition));
-       }
-       void AddFrames(int col, int row, const geometry::Vector<int> &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<int> 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<int> Offset(int frame) const { return frames[frame].disposition; }
 
 private:
-       std::vector<FrameProp> frames;
+       const FrameProp *frames;
+       int numFrames;
 
 };