vivienneanthony

Untitled

Nov 24th, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.21 KB | None | 0 0
  1.  
  2. StrongNodePtr GameAssetFactory::CreateNode2(GameAsset* gameAsset, GameNodeId serversId, Node * node=NULL)
  3. {
  4.     GameNodeId nextGameNodeId = serversId;
  5.     if (nextGameNodeId == INVALID_GAME_NODE_ID)
  6.     {
  7.         nextGameNodeId = GetNextGameNodeId();
  8.     }
  9.  
  10.     StrongNodePtr pGameNode(new Node(context_));
  11.  
  12.     pGameNode->SetID(nextGameNodeId);
  13.  
  14.     // Create root component then create a component type
  15.  
  16.     // Loop through each game asset child element and load the component
  17.     BaseComponent* component = VCreateComponent(gameAsset);
  18.  
  19.     // If component creation failed exit
  20.     if (component)
  21.     {
  22.         // *ITISSCAN* 23.11.2015.
  23.         // Not to good cast from GameAssetType structure to unsigned int...
  24.         // Maybe in future better to make StringHash instead?
  25.         pGameNode->AddComponent(component, component->GetID(), component->GetCreateMode());
  26.     }
  27.     else
  28.     {
  29.         // If an error occurs, we kill the game node and bail. We could keep going, but the game node is will only be
  30.         // partially complete so it's not worth it. Note that the pGameNode instance will be destroyed because it
  31.         // will fall out of scope with nothing else pointing to it.
  32.         return StrongNodePtr();
  33.     }
  34.  
  35.     // Create childs components
  36.     Vector<GameAsset*> childs = gameAsset->GetChilds();
  37.     Vector<GameAsset*>::Iterator it = childs.Begin();
  38.  
  39.     // Loop through each child - Each game asset
  40.     for (Vector<GameAsset*>::Iterator it = childs.Begin(); it != childs.End(); ++it)
  41.     {
  42.         // if it isn't a linked asset
  43.         if((*it)->IsLinkedGameAsset()==false)
  44.         {
  45.             BaseComponent* component = VCreateComponent((*it));
  46.             if (component)
  47.             {
  48.                 // *ITISSCAN* 23.11.2015.
  49.                 // Not to good cast from GameAssetType structure to unsigned int...
  50.                 // Maybe in future better to make StringHash instead?
  51.                 pGameNode->AddComponent(component, (unsigned int)component->VGetGameAssetType(), component->GetCreateMode());
  52.             }
  53.             else
  54.             {
  55.                 // If an error occurs, we kill the game node and bail. We could keep going, but the game node is will only be
  56.                 // partially complete so it's not worth it. Note that the pGameNode instance will be destroyed because it
  57.                 // will fall out of scope with nothing else pointing to it.
  58.                 return StrongNodePtr();
  59.             }
  60.         }
  61.         else
  62.         {
  63.             // Check if a asset manager is set to find linked game asset
  64.             if(m_pGameAssetManager)
  65.             {
  66.                 // If linked game asset is find using the symbol - Asset Manager was found
  67.                 if(GameAsset * m_pLinkedGameAsset =m_pGameAssetManager->FindGameAssetBySymbol((*it)->GetSymbol()))
  68.                 {
  69.                     // Build a new child with components
  70.                     if(CreateNode2(m_pLinkedGameAsset, serversId, pGameNode))
  71.                     {
  72.                         // New node was built for child
  73.                     }
  74.                     else
  75.                     {
  76.                         // Problem occurred creating the child node
  77.                         // Error leave node creation
  78.                         return StrongNodePtr();
  79.                     }
  80.                 }
  81.                 else
  82.                 {
  83.                     // Symbol was not found for linked game asset - Error occurred exit
  84.                     // Error leave node creation
  85.                     return StrongNodePtr();
  86.                 }
  87.             }
  88.             else
  89.             {
  90.                 // The Game Asset Manager was not found so it could not complete building the node
  91.                 // Error leave node creation
  92.                 return StrongNodePtr();
  93.             }
  94.         }
  95.  
  96.         // *ITISSCAN* 23.11.2015.
  97.         // Not the best solution.
  98.         // Send POST INIT event to game assets, in order to finish initialization properly.
  99.         // May be some components depend on others.
  100.         // In future we should to override Urho3D::Node class and implement our GameNode class.
  101.     }
  102.  
  103.     SendEvent("Game_Asset_Factory_Post_Init");
  104.  
  105.     return pGameNode;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment