-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathCObjectEffectList.cpp
230 lines (161 loc) · 5.06 KB
/
CObjectEffectList.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
// CObjectEffectList.cpp
//
// CObjectEffectList class
// Copyright (c) 2014 by George Moromisato. All Rights Reserved.
#include "PreComp.h"
CObjectEffectList::~CObjectEffectList (void)
// CObjectEffectList destructor
{
CleanUp();
}
void CObjectEffectList::AccumulateBounds (CSpaceObject *pObj, const CObjectEffectDesc &Desc, int iRotation, RECT *ioBounds)
// AccumulateBounds
//
// Increases ioBounds to account for effects.
{
int i;
for (i = 0; i < m_FixedEffects.GetCount(); i++)
{
const CObjectEffectDesc::SEffectDesc &EffectDesc = Desc.GetEffectDesc(i);
if (m_FixedEffects[i].pPainter)
{
// Figure out where to paint the effect
int xPainter, yPainter;
EffectDesc.PosCalc.GetCoord(iRotation, &xPainter, &yPainter);
// Get the painter bounds
RECT rcRect;
m_FixedEffects[i].pPainter->GetBounds(&rcRect);
// Offset the painter rect based on position
::OffsetRect(&rcRect, xPainter, yPainter);
// Adjust resulting RECT to include painter rect
::UnionRect(ioBounds, ioBounds, &rcRect);
}
}
}
void CObjectEffectList::CleanUp (void)
// CleanUp
//
// Clean up effects
{
int i;
for (i = 0; i < m_FixedEffects.GetCount(); i++)
if (m_FixedEffects[i].pPainter)
m_FixedEffects[i].pPainter->Delete();
m_FixedEffects.DeleteAll();
}
void CObjectEffectList::Init (const CObjectEffectDesc &Desc, const TArray<IEffectPainter *> &Painters)
// Init
//
// Initialize the effect list
{
int i;
ASSERT(Desc.GetEffectCount() == Painters.GetCount());
CleanUp();
m_FixedEffects.InsertEmpty(Desc.GetEffectCount());
for (i = 0; i < m_FixedEffects.GetCount(); i++)
m_FixedEffects[i].pPainter = Painters[i];
}
void CObjectEffectList::Move (CSpaceObject *pObj, const CVector &vOldPos, bool *retbBoundsChanged)
// Move
//
// Effects move
{
int i;
bool bBoundsChanged = false;
SEffectMoveCtx MoveCtx;
MoveCtx.pObj = pObj;
MoveCtx.vOldPos = vOldPos;
for (i = 0; i < m_FixedEffects.GetCount(); i++)
if (m_FixedEffects[i].pPainter)
{
bool bChanged;
m_FixedEffects[i].pPainter->OnMove(MoveCtx, &bChanged);
if (bChanged)
bBoundsChanged = true;
}
if (retbBoundsChanged)
*retbBoundsChanged = bBoundsChanged;
}
void CObjectEffectList::Paint (SViewportPaintCtx &Ctx, const CObjectEffectDesc &Desc, DWORD dwEffects, CG32bitImage &Dest, int x, int y)
// Paint
//
// Paint the effects in the dwEffects mask
{
int i;
int iObjRotation = Ctx.iRotation;
for (i = 0; i < m_FixedEffects.GetCount(); i++)
{
const CObjectEffectDesc::SEffectDesc &EffectDesc = Desc.GetEffectDesc(i);
// Skip effects that are not in the right plane (in front or behind) OR
// that don't have a painter.
if (m_FixedEffects[i].pPainter == NULL
|| EffectDesc.PosCalc.PaintFirst(Ctx.iVariant) == Ctx.bInFront)
continue;
// Skip maneuvering effects unless we want them
if (!Ctx.fShowManeuverEffects && CObjectEffectDesc::IsManeuverEffect(EffectDesc))
continue;
// Figure out where to paint the effect
int xPainter, yPainter;
EffectDesc.PosCalc.GetCoordFromDir(Ctx.iVariant, &xPainter, &yPainter);
// Compute the rotation (180 for thruster effects)
Ctx.iRotation = AngleMod(iObjRotation + EffectDesc.iRotation + 180);
// Paint
if (dwEffects & EffectDesc.iType)
m_FixedEffects[i].pPainter->Paint(Dest,
x + xPainter,
y + yPainter,
Ctx);
else
m_FixedEffects[i].pPainter->PaintFade(Dest,
x + xPainter,
y + yPainter,
Ctx);
}
Ctx.iRotation = iObjRotation;
}
void CObjectEffectList::PaintAll (SViewportPaintCtx &Ctx, const CObjectEffectDesc &Desc, CG32bitImage &Dest, int x, int y)
// PaintAll
//
// Paint all effects
{
DWORD dwAll = CObjectEffectDesc::effectThrustLeft
| CObjectEffectDesc::effectThrustRight
| CObjectEffectDesc::effectThrustMain;
// Set tick to 1 so we don't blink
int iOldTick = Ctx.iTick;
Ctx.iTick = 1;
// Paint
Paint(Ctx, Desc, dwAll, Dest, x, y);
// Done
Ctx.iTick = iOldTick;
}
void CObjectEffectList::Update (CSpaceObject *pObj, const CObjectEffectDesc &Desc, int iRotation, DWORD dwEffects)
// Update
//
// Update effects
{
DEBUG_TRY
int i;
SEffectUpdateCtx PainterCtx;
PainterCtx.pObj = pObj;
PainterCtx.iTick = g_pUniverse->GetTicks();
for (i = 0; i < m_FixedEffects.GetCount(); i++)
if (m_FixedEffects[i].pPainter)
{
// If bFade is TRUE then it means that we don't emit new particles
// out of particle effects (other effects are hidden).
PainterCtx.bFade = ((dwEffects & Desc.GetEffectDesc(i).iType) == 0);
// Compute the position of the effect (relative to the object center)
// so we can emit at that location. We need this because some effects
// (particle effects) are centered on the object, not the emit position.
int xEmit;
int yEmit;
Desc.GetEffectDesc(i).PosCalc.GetCoord(iRotation, &xEmit, &yEmit);
PainterCtx.vEmitPos = CVector(xEmit * g_KlicksPerPixel, -yEmit * g_KlicksPerPixel);
// Compute the rotation (180 for thruster effects)
PainterCtx.iRotation = AngleMod(iRotation + Desc.GetEffectDesc(i).iRotation + 180);
// Update
m_FixedEffects[i].pPainter->OnUpdate(PainterCtx);
}
DEBUG_CATCH
}