Exemplo n.º 1
0
void setupOutputLevelFile(XMLNodePtr& mNode)
{
   XMLContextPtr mContext = XMLContextPtr(new XMLContext);
   mNode = XMLNodePtr(new XMLNode(mContext));
   mNode->setName("hi");
   mNode->setType(xml_nt_node);
   XMLNodePtr newNode(new XMLNode(mContext));
   newNode->setName("josh");
   newNode->setType(xml_nt_node);
   mNode->addChild(newNode);
}
Exemplo n.º 2
0
void NowWeCanReallyAddTheLevel(XMLNodePtr& levelNode, XMLContextPtr& context)
{
   std::string temp;
   char namePostFix = 'A';  // a postfix character to add as a name so we can distinguish between different navNodes. -- this is an ugly hack.
   std::cout << "writing out models..." << std::endl;

   

   for(unsigned int i=0;i<modelsInWorld.size();i++)
   {
      XMLNodePtr staticNode(new XMLNode(context));
      XMLNodePtr posNode(new XMLNode(context));
      XMLNodePtr rotNode(new XMLNode(context));
      XMLNodePtr nameNode(new XMLNode(context));
      XMLNodePtr realNameNode(new XMLNode(context));
      
      
      staticNode->setName("static");
      posNode->setName("pos");
      rotNode->setName("rot");
      nameNode->setName("model");

               
      
      staticNode->setType(xml_nt_node);
      posNode->setType(xml_nt_leaf);
      nameNode->setType(xml_nt_node);
      rotNode->setType(xml_nt_leaf);
      realNameNode->setType(xml_nt_cdata);
      
      
      levelNode->addChild(staticNode);
      
      posNode->setAttribute("x", modelsInWorld[i].worldX);
      posNode->setAttribute("y", modelsInWorld[i].worldZ);
      posNode->setAttribute("z", modelsInWorld[i].worldY);
      
      staticNode->addChild(posNode);
      rotNode->setAttribute("x", 0.0f);
      rotNode->setAttribute("y", 0.0f);
      rotNode->setAttribute("z", 0.0f);
      staticNode->addChild(rotNode);

      realNameNode->setCdata(modelsInWorld[i].name);
      nameNode->addChild(realNameNode);
      staticNode->addChild(nameNode);

      if(modelsInWorld[i].name==std::string("turret"))
      {
         std::cout << "adding turret info to xml node" << std::endl;
         staticNode->setName("turret");
         XMLNodePtr turretNameNode(new XMLNode(context));
         XMLNodePtr maxChildNode(new XMLNode(context));
         XMLNodePtr aiLevelNode(new XMLNode(context));
         XMLNodePtr parentNode(new XMLNode(context));
         XMLNodePtr realParentNode(new XMLNode(context));
         XMLNodePtr realTurretNameNode(new XMLNode(context));

         turretNameNode->setType(xml_nt_node);
         realTurretNameNode->setType(xml_nt_cdata);
         parentNode->setType(xml_nt_node);
         realParentNode->setType(xml_nt_cdata);
         aiLevelNode->setType(xml_nt_leaf);
         maxChildNode->setType(xml_nt_leaf);

         turretNameNode->setName("name");
         parentNode->setName("parent");
         aiLevelNode->setName("level");
         maxChildNode->setName("maxChildren");
         
         realParentNode->setCdata("null");
         realTurretNameNode->setCdata("turret");
         
         aiLevelNode->setAttribute("nu", -1);
         maxChildNode->setAttribute("num", 0);
         parentNode->addChild(realParentNode);
         turretNameNode->addChild(realTurretNameNode);

         staticNode->addChild(aiLevelNode);
         staticNode->addChild(parentNode);
         staticNode->addChild(turretNameNode);
         staticNode->addChild(maxChildNode);
      }
      else if(modelsInWorld[i].name==std::string("security_droid"))
      {
         std::cout << "adding droid info to xml node" << std::endl;
         staticNode->setName("security_droid");

         XMLNodePtr droidNameNode(new XMLNode(context));
         XMLNodePtr maxChildNode(new XMLNode(context));
         XMLNodePtr aiLevelNode(new XMLNode(context));
         XMLNodePtr parentNode(new XMLNode(context));
         XMLNodePtr realParentNode(new XMLNode(context));
         XMLNodePtr realDroidNameNode(new XMLNode(context));

         droidNameNode->setType(xml_nt_node);
         realDroidNameNode->setType(xml_nt_cdata);
         parentNode->setType(xml_nt_node);
         realParentNode->setType(xml_nt_cdata);
         aiLevelNode->setType(xml_nt_leaf);
         maxChildNode->setType(xml_nt_leaf);

         droidNameNode->setName("name");
         parentNode->setName("parent");
         aiLevelNode->setName("level");
         maxChildNode->setName("maxChildren");

         realParentNode->setCdata("null");
         realDroidNameNode->setCdata("droid");

         aiLevelNode->setAttribute("nu", -1);
         maxChildNode->setAttribute("num", 0);
         parentNode->addChild(realParentNode);
         droidNameNode->addChild(realDroidNameNode);

         staticNode->addChild(aiLevelNode);
         staticNode->addChild(parentNode);
         staticNode->addChild(droidNameNode);
         staticNode->addChild(maxChildNode);
      }
      
      
   }
   std::cout << "writing out navNodes ..." << std::endl;
   for(std::vector<navNodeId*>::iterator itr=navNodes.begin();itr!=navNodes.end();itr++)
   {
      XMLNodePtr staticNode(new XMLNode(context));
      XMLNodePtr posNode(new XMLNode(context));
      XMLNodePtr rotNode(new XMLNode(context));
      XMLNodePtr nameNode(new XMLNode(context));
      XMLNodePtr realNameNode(new XMLNode(context));
      
      
      staticNode->setName("navNode");
      posNode->setName("pos");
      rotNode->setName("rot");
      nameNode->setName("name");

               
      
      staticNode->setType(xml_nt_node);
      posNode->setType(xml_nt_leaf);
      nameNode->setType(xml_nt_node);
      rotNode->setType(xml_nt_leaf);
      realNameNode->setType(xml_nt_cdata);
      
      
      levelNode->addChild(staticNode);
      
      posNode->setAttribute("x", (*itr)->worldX);
      posNode->setAttribute("y", (*itr)->worldZ);
      posNode->setAttribute("z", (*itr)->worldY);
      
      staticNode->addChild(posNode);
      rotNode->setAttribute("x", 0.0f);
      rotNode->setAttribute("y", 0.0f);
      rotNode->setAttribute("z", 0.0f);
      staticNode->addChild(rotNode);

      
      std::ostringstream s;
      s << (*itr)->id;
      
      realNameNode->setCdata(s.str());
      nameNode->addChild(realNameNode);
      staticNode->addChild(nameNode);
   }

   std::cout << "writing out NavNodeLinks ... " << std::endl;
   for(std::vector<pair>::iterator itr=navNodeLinks.begin();itr!=navNodeLinks.end();itr++)
   {
      XMLNodePtr staticNode(new XMLNode(context));
      staticNode->setName("navNodeLink");
      staticNode->setType(xml_nt_node);
       
      XMLNodePtr navNode1(new XMLNode(context));
      XMLNodePtr navNode2(new XMLNode(context));
      
      navNode1->setType(xml_nt_node);
      navNode2->setType(xml_nt_node);
      
      navNode1->setName("navNode1");
      navNode2->setName("navNode2");

      XMLNodePtr nameNavNode1(new XMLNode(context));
      XMLNodePtr nameNavNode2(new XMLNode(context));

      nameNavNode1->setType(xml_nt_cdata);
      nameNavNode2->setType(xml_nt_cdata);

      std::ostringstream s1, s2;
      s1 << (*itr).model1->id;
      s2 << (*itr).model2->id;
      
      nameNavNode1->setCdata(s1.str());
      nameNavNode2->setCdata(s2.str());

      
      levelNode->addChild(staticNode);
      staticNode->addChild(navNode1);
      staticNode->addChild(navNode2);
      navNode1->addChild(nameNavNode1);
      navNode2->addChild(nameNavNode2);
      
      
   }
}