-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathSFXLightningShockwave.cpp
123 lines (86 loc) · 2.76 KB
/
SFXLightningShockwave.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
// SFXLightningShockwave.cpp
//
// Lightning Shockwave SFX
#include "PreComp.h"
#if 0
#define IMAGE_TAG CONSTLIT("Image")
#define SPEED_ATTRIB CONSTLIT("speed")
#define LIFETIME_ATTRIB CONSTLIT("lifetime")
class CLightningShockwavePainter : public IEffectPainter
{
public:
CLightningShockwavePainter (CLightningShockwaveEffectCreator *pCreator);
// IEffectPainter virtuals
virtual CEffectCreator *GetCreator (void) { return m_pCreator; }
virtual void GetRect (RECT *retRect) const;
virtual void OnUpdate (SEffectUpdateCtx &Ctx) { m_iRadius += m_pCreator->GetSpeed(); }
virtual void Paint (CG32bitImage &Dest, int x, int y, SViewportPaintCtx &Ctx);
protected:
virtual void OnReadFromStream (SLoadCtx &Ctx);
virtual void OnWriteToStream (IWriteStream *pStream);
private:
CLightningShockwaveEffectCreator *m_pCreator;
int m_iRadius;
};
// CLightningShockwaveEffectCreator object
IEffectPainter *CLightningShockwaveEffectCreator::OnCreatePainter (CCreatePainterCtx &Ctx)
// CreatePainter
//
// Creates a new painter
{
return new CLightningShockwavePainter(this);
}
ALERROR CLightningShockwaveEffectCreator::OnEffectCreateFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc, const CString &sUNID)
// OnEffectCreateFromXML
//
// Initializes from XML
{
ALERROR error;
CXMLElement *pImage = pDesc->GetContentElementByTag(IMAGE_TAG);
if (pImage)
if (error = m_Image.InitFromXML(Ctx, pImage))
return error;
m_iSpeed = pDesc->GetAttributeInteger(SPEED_ATTRIB);
m_iLifetime = pDesc->GetAttributeInteger(LIFETIME_ATTRIB);
return NOERROR;
}
// CLightningShockwavePainter object
CLightningShockwavePainter::CLightningShockwavePainter (CLightningShockwaveEffectCreator *pCreator) : m_pCreator(pCreator),
m_iRadius(1)
// CLightningShockwavePainter constructor
{
}
void CLightningShockwavePainter::GetRect (RECT *retRect) const
// GetRect
//
// Returns the RECT of the effect centered on 0,0
{
retRect->left = -m_iRadius;
retRect->top = -m_iRadius;
retRect->right = m_iRadius + 1;
retRect->bottom = m_iRadius + 1;
}
void CLightningShockwavePainter::OnReadFromStream (SLoadCtx &Ctx)
// OnReadFromStream
//
// Load from stream
{
Ctx.pStream->Read((char *)&m_iRadius, sizeof(DWORD));
}
void CLightningShockwavePainter::OnWriteToStream (IWriteStream *pStream)
// OnWriteToStream
//
// Write to stream
{
pStream->Write((char *)&m_iRadius, sizeof(DWORD));
}
void CLightningShockwavePainter::Paint (CG32bitImage &Dest, int x, int y, SViewportPaintCtx &Ctx)
// Paint
//
// Paint
{
CG32bitImage &Image = m_pCreator->GetRawImage().GetRawImage();
RECT rcImage = m_pCreator->GetRawImage().GetImageRect();
CGDraw::CircleImage(Dest, x, y, m_iRadius, 255, Image, rcImage.left, rcImage.top, RectWidth(rcImage), RectHeight(rcImage));
}
#endif