Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- StrongNodePtr GameAssetFactory::CreateNode2(GameAsset* gameAsset, GameNodeId serversId, Node * node=NULL)
- {
- GameNodeId nextGameNodeId = serversId;
- if (nextGameNodeId == INVALID_GAME_NODE_ID)
- {
- nextGameNodeId = GetNextGameNodeId();
- }
- StrongNodePtr pGameNode(new Node(context_));
- pGameNode->SetID(nextGameNodeId);
- // Create root component then create a component type
- // Loop through each game asset child element and load the component
- BaseComponent* component = VCreateComponent(gameAsset);
- // If component creation failed exit
- if (component)
- {
- // *ITISSCAN* 23.11.2015.
- // Not to good cast from GameAssetType structure to unsigned int...
- // Maybe in future better to make StringHash instead?
- pGameNode->AddComponent(component, component->GetID(), component->GetCreateMode());
- }
- else
- {
- // If an error occurs, we kill the game node and bail. We could keep going, but the game node is will only be
- // partially complete so it's not worth it. Note that the pGameNode instance will be destroyed because it
- // will fall out of scope with nothing else pointing to it.
- return StrongNodePtr();
- }
- // Create childs components
- Vector<GameAsset*> childs = gameAsset->GetChilds();
- Vector<GameAsset*>::Iterator it = childs.Begin();
- // Loop through each child - Each game asset
- for (Vector<GameAsset*>::Iterator it = childs.Begin(); it != childs.End(); ++it)
- {
- // if it isn't a linked asset
- if((*it)->IsLinkedGameAsset()==false)
- {
- BaseComponent* component = VCreateComponent((*it));
- if (component)
- {
- // *ITISSCAN* 23.11.2015.
- // Not to good cast from GameAssetType structure to unsigned int...
- // Maybe in future better to make StringHash instead?
- pGameNode->AddComponent(component, (unsigned int)component->VGetGameAssetType(), component->GetCreateMode());
- }
- else
- {
- // If an error occurs, we kill the game node and bail. We could keep going, but the game node is will only be
- // partially complete so it's not worth it. Note that the pGameNode instance will be destroyed because it
- // will fall out of scope with nothing else pointing to it.
- return StrongNodePtr();
- }
- }
- else
- {
- // Check if a asset manager is set to find linked game asset
- if(m_pGameAssetManager)
- {
- // If linked game asset is find using the symbol - Asset Manager was found
- if(GameAsset * m_pLinkedGameAsset =m_pGameAssetManager->FindGameAssetBySymbol((*it)->GetSymbol()))
- {
- // Build a new child with components
- if(CreateNode2(m_pLinkedGameAsset, serversId, pGameNode))
- {
- // New node was built for child
- }
- else
- {
- // Problem occurred creating the child node
- // Error leave node creation
- return StrongNodePtr();
- }
- }
- else
- {
- // Symbol was not found for linked game asset - Error occurred exit
- // Error leave node creation
- return StrongNodePtr();
- }
- }
- else
- {
- // The Game Asset Manager was not found so it could not complete building the node
- // Error leave node creation
- return StrongNodePtr();
- }
- }
- // *ITISSCAN* 23.11.2015.
- // Not the best solution.
- // Send POST INIT event to game assets, in order to finish initialization properly.
- // May be some components depend on others.
- // In future we should to override Urho3D::Node class and implement our GameNode class.
- }
- SendEvent("Game_Asset_Factory_Post_Init");
- return pGameNode;
- }
Advertisement
Add Comment
Please, Sign In to add comment