-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathCObjectEffectDesc.cpp
150 lines (111 loc) · 3.13 KB
/
CObjectEffectDesc.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
// CObjectEffectDesc.cpp
//
// CObjectEffectDesc class
// Copyright (c) 2014 by George Moromisato. All Rights Reserved.
#include "PreComp.h"
#define EFFECT_ATTRIB CONSTLIT("effect")
#define ROTATION_ATTRIB CONSTLIT("rotation")
#define TYPE_ATTRIB CONSTLIT("type")
#define EFFECT_ROTATE_LEFT CONSTLIT("rotateLeft")
#define EFFECT_ROTATE_RIGHT CONSTLIT("rotateRight")
#define EFFECT_THRUST_MAIN CONSTLIT("thrustMain")
ALERROR CObjectEffectDesc::Bind (SDesignLoadCtx &Ctx, const CObjectImageArray &Image)
// Bind
//
// Bind design
{
ALERROR error;
int i;
for (i = 0; i < m_Effects.GetCount(); i++)
{
// Finish initialization
m_Effects[i].PosCalc.InitComplete(Image.GetRotationCount(), Image.GetImageViewportSize(), m_Effects[i].iRotation);
// Default effect
if (m_Effects[i].pEffect.IsEmpty())
{
switch (m_Effects[i].iType)
{
case effectThrustLeft:
case effectThrustRight:
m_Effects[i].pEffect.SetUNID(UNID_MANEUVERING_THRUSTER);
break;
case effectThrustMain:
m_Effects[i].pEffect.SetUNID(UNID_MAIN_THRUSTER);
break;
}
}
// Bind
if (error = m_Effects[i].pEffect.Bind(Ctx))
return error;
}
return NOERROR;
}
CEffectCreator *CObjectEffectDesc::FindEffectCreator (const CString &sUNID) const
// FindEffectCreator
//
// Returns the effect creator
{
return NULL;
}
int CObjectEffectDesc::GetEffectCount (DWORD dwEffects) const
// GetEffectCount
//
// Returns the number of effects that match the given mask
{
int i;
int iCount = 0;
for (i = 0; i < m_Effects.GetCount(); i++)
if (dwEffects & m_Effects[i].iType)
iCount++;
return iCount;
}
ALERROR CObjectEffectDesc::InitFromXML (SDesignLoadCtx &Ctx, const CString &sUNID, CXMLElement *pDesc)
// InitFromXML
//
// Initializes
{
ALERROR error;
int i;
// Loop over all effects and add them to the list
for (i = 0; i < pDesc->GetContentElementCount(); i++)
{
CXMLElement *pEffectXML = pDesc->GetContentElement(i);
SEffectDesc *pEntry = m_Effects.Insert();
CString sType = pEffectXML->GetAttribute(TYPE_ATTRIB);
if (strEquals(sType, EFFECT_ROTATE_LEFT))
pEntry->iType = effectThrustLeft;
else if (strEquals(sType, EFFECT_ROTATE_RIGHT))
pEntry->iType = effectThrustRight;
else if (strEquals(sType, EFFECT_THRUST_MAIN))
pEntry->iType = effectThrustMain;
else
{
Ctx.sError = strPatternSubst(CONSTLIT("Invalid effect type: %s."), sType);
return ERR_FAIL;
}
// Load the direction
pEntry->iRotation = pEffectXML->GetAttributeInteger(ROTATION_ATTRIB);
// Load the position
if (error = pEntry->PosCalc.Init(pEffectXML))
{
Ctx.sError = strPatternSubst(CONSTLIT("Invalid effect position."));
return ERR_FAIL;
}
// Load the effect
if (error = pEntry->pEffect.LoadEffect(Ctx,
strPatternSubst(CONSTLIT("%s:%d"), sUNID, i),
(pEffectXML->GetContentElementCount() > 0 ? pEffectXML : NULL),
pEffectXML->GetAttribute(EFFECT_ATTRIB)))
return error;
}
return NOERROR;
}
void CObjectEffectDesc::MarkImages (void)
// MarkImages
//
// Mark images
{
int i;
for (i = 0; i < m_Effects.GetCount(); i++)
m_Effects[i].pEffect->MarkImages();
}