]> git.localhorst.tv Git - l2e.git/blob - src/graphics/ComplexAnimation.cpp
initialize objects after loading
[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 ComplexAnimation::ComplexAnimation(loader::noinit_t n)
30 : Animation(n) {
31
32 }
33
34
35 int ComplexAnimation::NumFrames() const {
36         return numFrames;
37 }
38
39 int ComplexAnimation::Col(int frame) const {
40         return frames[frame].col;
41 }
42
43 int ComplexAnimation::Row(int frame) const {
44         return frames[frame].row;
45 }
46
47 Vector<int> ComplexAnimation::Offset(int frame) const {
48         return frames[frame].disposition;
49 }
50
51
52 void ComplexAnimation::CreateTypeDescription() {
53         ComplexAnimation ca;
54         Animation *a(&ca);
55
56         TypeDescription &td(TypeDescription::Create(TYPE_ID, "ComplexAnimation"));
57         td.SetDescription("Complex animation type that supports per-frame disposition and non-linear sprite offset selection.");
58         td.SetConstructor(&Construct);
59         td.SetInitializer(&Initialize);
60         td.SetSize(sizeof(ComplexAnimation));
61         td.AddSupertype(Animation::TYPE_ID, ((char *)a) - ((char *)&ca));
62
63         Animation::AddFields(td, ca, ((char *)a) - ((char *)&ca));
64         td.AddField("frames", FieldDescription(((char *)&ca.frames) - ((char *)&ca), FrameProp::TYPE_ID).SetAggregate().SetDescription("a variable number of frames"));
65
66
67         FrameProp fp;
68
69         TypeDescription &ftd(TypeDescription::Create(FrameProp::TYPE_ID, "ComplexAnimationFrame"));
70         ftd.SetDescription("Information about how a frame of a complex animation should be rendered.");
71         ftd.SetSize(sizeof(FrameProp));
72
73         ftd.AddField("column", FieldDescription(((char *)&fp.col) - ((char *)&fp), Interpreter::NUMBER_ID).SetDescription("the column of the sprite that will be drawn"));
74         ftd.AddField("row", FieldDescription(((char *)&fp.row) - ((char *)&fp), Interpreter::NUMBER_ID).SetDescription("the row of the sprite that will be drawn"));
75         ftd.AddField("disposition", FieldDescription(((char *)&fp.disposition) - ((char *)&fp), Interpreter::VECTOR_ID).SetDescription("offset from the original drawing position"));
76 }
77
78 void ComplexAnimation::Construct(void *data) {
79         new (data) ComplexAnimation;
80 }
81
82 void ComplexAnimation::Initialize(void *data) {
83         new (data) ComplexAnimation(loader::noinit);
84 }
85
86 }