-
Notifications
You must be signed in to change notification settings - Fork 0
/
tileanim.cpp
98 lines (84 loc) · 2 KB
/
tileanim.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "tileanim.h"
#include "vsp.h"
void TileAnim::Reset(VSP::VSP* vsp)
{
pVsp = vsp;
strand.clear();
strand.resize(vsp->NumTileAnim());
for (u32 i = 0; i<strand.size(); i++)
{
strand[i].flip = false;
strand[i].count = vsp->GetAnim(i).delay;
}
tileidx.resize(vsp->NumTiles());
for (u32 i = 0; i<tileidx.size(); i++)
tileidx[i]=i;
}
namespace
{
void Forward(int& cur, int first, int last)
{
cur++;
if (cur>last) cur = first;
}
void Backward(int& cur, int first, int last)
{
cur--;
if (cur<first) cur = last;
}
void Flip(int& cur, bool& flip, int first, int last)
{
if (flip)
{
cur--;
if (cur<first)
{
flip=!flip;
cur = first;
}
}
else
{
cur++;
if (cur>last)
{
flip=!flip;
cur = last;
}
}
}
void Random(int& cur, int first, int last)
{
cur = rand()%(last-first) + first;
}
};
void TileAnim::Update()
{
for (u32 i = 0; i<strand.size(); i++)
{
strand[i].count--;
if (strand[i].count > 0)
continue;
const VSP::AnimStrand& a = pVsp->GetAnim(i);
strand[i].count = a.delay;
switch (a.mode)
{
case VSP::forward:
for (u32 j = a.first; j<a.last; j++)
Forward(tileidx[j], a.first, a.last);
break;
case VSP::backward:
for (u32 j = a.first; j<a.last; j++)
Backward(tileidx[j], a.first, a.last);
break;
case VSP::flip:
for (u32 j = a.first; j<a.last; j++)
Flip(tileidx[j], strand[i].flip, a.first, a.last);
break;
case VSP::random:
for (u32 j = a.first; j<a.last; j++)
Random(tileidx[j], a.first, a.last);
break;
}
}
}