@@ -14,7 +14,9 @@ using namespace nima;
1414
1515Actor::Actor () :
1616 m_Flags(IsImageDrawOrderDirty|IsVertexDeformDirty),
17+ m_ComponentCount(0 ),
1718 m_NodeCount(0 ),
19+ m_Components(nullptr ),
1820 m_Nodes(nullptr ),
1921 m_Root(nullptr ),
2022 m_MaxTextureIndex(0 ),
@@ -35,10 +37,11 @@ Actor::~Actor()
3537
3638void Actor::dispose ()
3739{
38- for (int i = 0 ; i < m_NodeCount ; i++)
40+ for (int i = 0 ; i < m_ComponentCount ; i++)
3941 {
40- delete m_Nodes [i];
42+ delete m_Components [i];
4143 }
44+ delete [] m_Components;
4245 delete [] m_Nodes;
4346 delete [] m_ImageNodes;
4447 delete [] m_Solvers;
@@ -47,11 +50,13 @@ void Actor::dispose()
4750 delete [] m_Animations;
4851 }
4952
53+ m_ComponentCount = 0 ;
5054 m_NodeCount = 0 ;
5155 m_MaxTextureIndex = 0 ;
5256 m_ImageNodeCount = 0 ;
5357 m_SolverNodeCount = 0 ;
5458 m_AnimationsCount = 0 ;
59+ m_Components = nullptr ;
5560 m_Nodes = nullptr ;
5661 m_ImageNodes = nullptr ;
5762 m_Solvers = nullptr ;
@@ -64,21 +69,21 @@ ActorNode* Actor::root() const
6469 return m_Root;
6570}
6671
67- ActorNode * Actor::node (unsigned int index) const
72+ ActorComponent * Actor::component (unsigned int index) const
6873{
69- return m_Nodes [index];
74+ return m_Components [index];
7075}
7176
72- ActorNode * Actor::node (unsigned short index) const
77+ ActorComponent * Actor::component (unsigned short index) const
7378{
74- return m_Nodes [index];
79+ return m_Components [index];
7580}
7681
77- ActorNode * Actor::node (const std::string& name) const
82+ ActorComponent * Actor::component (const std::string& name) const
7883{
79- for (int i = 0 ; i < m_NodeCount ; i++)
84+ for (int i = 0 ; i < m_ComponentCount ; i++)
8085 {
81- ActorNode * a = m_Nodes [i];
86+ ActorComponent * a = m_Components [i];
8287 if (a->name () == name)
8388 {
8489 return a;
@@ -129,8 +134,8 @@ void Actor::load(unsigned char* bytes, unsigned int length)
129134 {
130135 switch (block->blockType <BlockType>())
131136 {
132- case BlockType::Nodes :
133- readNodesBlock (block);
137+ case BlockType::Components :
138+ readComponentsBlock (block);
134139 break ;
135140 case BlockType::Animations:
136141 readAnimationsBlock (block);
@@ -195,7 +200,7 @@ void Actor::readAnimationsBlock(BlockReader* block)
195200 // Sanity check.
196201 if (animationIndex < m_AnimationsCount)
197202 {
198- m_Animations[animationIndex++].read (animationBlock, m_Nodes );
203+ m_Animations[animationIndex++].read (animationBlock, m_Components );
199204 }
200205 break ;
201206 default :
@@ -211,32 +216,34 @@ ActorImage* Actor::makeImageNode()
211216 return new ActorImage ();
212217}
213218
214- void Actor::readNodesBlock (BlockReader* block)
219+ void Actor::readComponentsBlock (BlockReader* block)
215220{
216- m_NodeCount = block->readUnsignedShort () + 1 ;
217- m_Nodes = new ActorNode*[m_NodeCount];
218- m_Nodes[0 ] = m_Root;
219- BlockReader* nodeBlock = nullptr ;
220- int nodeIndex = 1 ;
221- while ((nodeBlock = block->readNextBlock ()) != nullptr )
221+ m_ComponentCount = block->readUnsignedShort () + 1 ;
222+ m_Components = new ActorComponent*[m_ComponentCount];
223+ m_Components[0 ] = m_Root;
224+
225+ BlockReader* componentBlock = nullptr ;
226+ int componentIndex = 1 ;
227+ m_NodeCount = 1 ;
228+ while ((componentBlock = block->readNextBlock ()) != nullptr )
222229 {
223- ActorNode* node = nullptr ;
224- switch (nodeBlock ->blockType <BlockType>())
230+ ActorComponent* component = nullptr ;
231+ switch (componentBlock ->blockType <BlockType>())
225232 {
226233 case BlockType::ActorNode:
227- node = ActorNode::read (this , nodeBlock );
234+ component = ActorNode::read (this , componentBlock );
228235 break ;
229236 case BlockType::ActorBone:
230- node = ActorBone::read (this , nodeBlock );
237+ component = ActorBone::read (this , componentBlock );
231238 break ;
232239 case BlockType::ActorRootBone:
233- node = ActorRootBone::read (this , nodeBlock );
240+ component = ActorRootBone::read (this , componentBlock );
234241 break ;
235242 case BlockType::ActorImage:
236243 {
237244 m_ImageNodeCount++;
238- node = ActorImage::read (this , nodeBlock , makeImageNode ());
239- ActorImage* imageNode = static_cast <ActorImage*>(node );
245+ component = ActorImage::read (this , componentBlock , makeImageNode ());
246+ ActorImage* imageNode = static_cast <ActorImage*>(component );
240247 if (imageNode->textureIndex () > m_MaxTextureIndex)
241248 {
242249 m_MaxTextureIndex = imageNode->textureIndex ();
@@ -245,42 +252,54 @@ void Actor::readNodesBlock(BlockReader* block)
245252 }
246253 case BlockType::ActorIKTarget:
247254 m_SolverNodeCount++;
248- node = ActorIKTarget::read (this , nodeBlock );
255+ component = ActorIKTarget::read (this , componentBlock );
249256 break ;
250257 default :
251258 // Not handled/expected block.
252259 break ;
253260 }
254- m_Nodes[nodeIndex] = node;
255- nodeIndex++;
261+ if (component != nullptr && component->isNode ())
262+ {
263+ m_NodeCount++;
264+ }
265+ m_Components[componentIndex] = component;
266+ componentIndex++;
256267
257- nodeBlock ->close ();
268+ componentBlock ->close ();
258269 }
259270
271+ m_Nodes = new ActorNode*[m_NodeCount];
260272 m_ImageNodes = new ActorImage*[m_ImageNodeCount];
261273 m_Solvers = new Solver*[m_SolverNodeCount];
274+ m_Nodes[0 ] = m_Root;
262275
263276 // Resolve nodes.
264277 int imdIdx = 0 ;
265278 int slvIdx = 0 ;
266- for (int i = 1 ; i < m_NodeCount; i++)
279+ int ndeIdx = 1 ;
280+ for (int i = 1 ; i < m_ComponentCount; i++)
267281 {
268- ActorNode* n = m_Nodes [i];
269- if (n != nullptr )
282+ ActorComponent* component = m_Components [i];
283+ if (component != nullptr )
270284 {
271- n-> resolveNodeIndices (m_Nodes );
285+ component-> resolveComponentIndices (m_Components );
272286
273- switch (n ->type ())
287+ switch (component ->type ())
274288 {
275- case NodeType ::ActorImage:
276- m_ImageNodes[imdIdx++] = static_cast <ActorImage*>(n );
289+ case ComponentType ::ActorImage:
290+ m_ImageNodes[imdIdx++] = static_cast <ActorImage*>(component );
277291 break ;
278- case NodeType ::ActorIKTarget:
279- m_Solvers[slvIdx++] = static_cast <ActorIKTarget*>(n );
292+ case ComponentType ::ActorIKTarget:
293+ m_Solvers[slvIdx++] = static_cast <ActorIKTarget*>(component );
280294 break ;
281295 default :
282296 break ;
283297 }
298+
299+ if (component->isNode ())
300+ {
301+ m_Nodes[ndeIdx++] = static_cast <ActorNode*>(component);
302+ }
284303 }
285304 }
286305}
@@ -304,9 +323,14 @@ void Actor::copy(const Actor& actor)
304323 m_MaxTextureIndex = actor.m_MaxTextureIndex ;
305324 m_ImageNodeCount = actor.m_ImageNodeCount ;
306325 m_SolverNodeCount = actor.m_SolverNodeCount ;
326+ m_ComponentCount = actor.m_ComponentCount ;
307327 m_NodeCount = actor.m_NodeCount ;
308328 m_BaseFilename = actor.m_BaseFilename ;
309329
330+ if (m_ComponentCount != 0 )
331+ {
332+ m_Components = new ActorComponent*[m_ComponentCount];
333+ }
310334 if (m_NodeCount != 0 )
311335 {
312336 m_Nodes = new ActorNode*[m_NodeCount];
@@ -320,45 +344,51 @@ void Actor::copy(const Actor& actor)
320344 m_Solvers = new Solver*[m_SolverNodeCount];
321345 }
322346
323- if (m_NodeCount > 0 )
347+ if (m_ComponentCount > 0 )
324348 {
325349 int idx = 0 ;
326350 int imgIdx = 0 ;
327351 int slvIdx = 0 ;
352+ int ndeIdx = 0 ;
328353
329- for (int i = 0 ; i < m_NodeCount ; i++)
354+ for (int i = 0 ; i < m_ComponentCount ; i++)
330355 {
331- ActorNode* node = actor.m_Nodes [i];
332- if (node == nullptr )
356+ ActorComponent* component = actor.m_Components [i];
357+ if (component == nullptr )
333358 {
334- m_Nodes [idx++] = nullptr ;
359+ m_Components [idx++] = nullptr ;
335360 continue ;
336361 }
337- ActorNode* instanceNode = node ->makeInstance (this );
338- m_Nodes [idx++] = instanceNode ;
339- switch (instanceNode ->type ())
362+ ActorComponent* instanceComponent = component ->makeInstance (this );
363+ m_Components [idx++] = instanceComponent ;
364+ switch (instanceComponent ->type ())
340365 {
341- case NodeType ::ActorImage:
342- m_ImageNodes[imgIdx++] = static_cast <ActorImage*>(instanceNode );
366+ case ComponentType ::ActorImage:
367+ m_ImageNodes[imgIdx++] = static_cast <ActorImage*>(instanceComponent );
343368 break ;
344- case NodeType ::ActorIKTarget:
345- m_Solvers[slvIdx++] = static_cast <ActorIKTarget*>(instanceNode );
369+ case ComponentType ::ActorIKTarget:
370+ m_Solvers[slvIdx++] = static_cast <ActorIKTarget*>(instanceComponent );
346371 break ;
347372 default :
348373 break ;
349374 }
375+
376+ if (instanceComponent->isNode ())
377+ {
378+ m_Nodes[ndeIdx++] = static_cast <ActorNode*>(instanceComponent);
379+ }
350380 }
351381
352382 // Resolve indices.
353383 m_Root = m_Nodes[0 ];
354- for (int i = 0 ; i < m_NodeCount ; i++)
384+ for (int i = 1 ; i < m_ComponentCount ; i++)
355385 {
356- ActorNode* node = m_Nodes [i];
357- if (m_Root == node || node == nullptr )
386+ ActorComponent* component = m_Components [i];
387+ if (component == nullptr )
358388 {
359389 continue ;
360390 }
361- node-> resolveNodeIndices (m_Nodes );
391+ component-> resolveComponentIndices (m_Components );
362392 }
363393
364394 if (m_Solvers != nullptr )
0 commit comments