]> git.localhorst.tv Git - l2e.git/blob - src/graphics/ComplexAnimation.cpp
renamed namespace geometry -> math
[l2e.git] / src / graphics / ComplexAnimation.cpp
1 #include "ComplexAnimation.h"
2
3 #include "../loader/Interpreter.h"
4 #include "../loader/TypeDescription.h"
5
6 using math::Vector;
7 using loader::FieldDescription;
8 using loader::Interpreter;
9 using loader::TypeDescription;
10
11 namespace graphics {
12
13 ComplexAnimation::ComplexAnimation()
14 : frames(0)
15 , numFrames(0) {
16
17 }
18
19 ComplexAnimation::ComplexAnimation(
20                 const Sprite *sprite,
21                 int frameTime,
22                 bool repeat)
23 : Animation(sprite, frameTime, repeat)
24 , frames(0)
25 , numFrames(0) {
26
27 }
28
29
30 int ComplexAnimation::NumFrames() const {
31         return numFrames;
32 }
33
34 int ComplexAnimation::Col(int frame) const {
35         return frames[frame].col;
36 }
37
38 int ComplexAnimation::Row(int frame) const {
39         return frames[frame].row;
40 }
41
42 Vector<int> ComplexAnimation::Offset(int frame) const {
43         return frames[frame].disposition;
44 }
45
46
47 void ComplexAnimation::CreateTypeDescription() {
48         ComplexAnimation ca;
49         Animation *a(&ca);
50
51         TypeDescription &td(TypeDescription::Create(TYPE_ID, "ComplexAnimation"));
52         td.SetDescription("Complex animation type that supports per-frame disposition and non-linear sprite offset selection.");
53         td.SetConstructor(&Construct);
54         td.SetSize(sizeof(ComplexAnimation));
55         td.AddSupertype(Animation::TYPE_ID, ((char *)a) - ((char *)&ca));
56
57         Animation::AddFields(td, ca, ((char *)a) - ((char *)&ca));
58         td.AddField("frames", FieldDescription(((char *)&ca.frames) - ((char *)&ca), FrameProp::TYPE_ID).SetReferenced().SetAggregate().SetDescription("a variable number of frames"));
59
60
61         FrameProp fp;
62
63         TypeDescription &ftd(TypeDescription::Create(FrameProp::TYPE_ID, "ComplexAnimationFrame"));
64         ftd.SetDescription("Information about how a frame of a complex animation should be rendered.");
65         ftd.SetSize(sizeof(FrameProp));
66
67         ftd.AddField("column", FieldDescription(((char *)&fp.col) - ((char *)&fp), Interpreter::NUMBER_ID).SetDescription("the column of the sprite that will be drawn"));
68         ftd.AddField("row", FieldDescription(((char *)&fp.row) - ((char *)&fp), Interpreter::NUMBER_ID).SetDescription("the row of the sprite that will be drawn"));
69         ftd.AddField("disposition", FieldDescription(((char *)&fp.disposition) - ((char *)&fp), Interpreter::VECTOR_ID).SetDescription("offset from the original drawing position"));
70 }
71
72 void ComplexAnimation::Construct(void *data) {
73         new (data) ComplexAnimation;
74 }
75
76 }