Exemplo n.º 1
0
void CMapPack::init() {
  if (m_bInitialised) {return;}

  Ogre::LogManager::getSingleton().logMessage("Creating map pack for " + m_sMapName);
  Ogre::ResourceGroupManager::getSingleton().createResourceGroup(m_sMapName);
  Ogre::FileInfoListPtr files = Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo("level_user", m_sMapName + ".zip");
  if (files->size() == 0) {
    throw Ogre::Exception(0, "Map zip file not found", __FILE__);
  }
  Ogre::String sZipFile = files->front().archive->getName() + "/" + files->front().filename;
  Ogre::LogManager::getSingleton().logMessage("  adding zip from  " + sZipFile);
#if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID
  Ogre::ResourceGroupManager::getSingleton().addResourceLocation(sZipFile, "APKZip", m_sMapName, true);
#else
  Ogre::ResourceGroupManager::getSingleton().addResourceLocation(sZipFile, "Zip", m_sMapName, true);
#endif
  Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup(m_sMapName);

  m_bInitialised = true;
  
  try {
    loadLanguage();
  }
  catch (const Ogre::Exception& e) {
    Ogre::LogManager::getSingleton().logMessage(Ogre::LML_CRITICAL, e.getFullDescription());
  }

  if (!m_pMapInfo) {
    m_pMapInfo = shared_ptr<CMapInfo>(new CMapInfo(m_sMapName, m_sMapName));
  }
}
Exemplo n.º 2
0
//-------------------------------------------------------------------------------------
void SceneLoader::load(std::string filename, Scene* scene)
{
  try
  {
    Ogre::FileInfoListPtr files = Ogre::ResourceGroupManager::getSingletonPtr()->findResourceFileInfo("Essential", filename);
    if(files->size() < 1) throw NHException("could not find the path to the specified scene");

    std::string filePath = files->front().archive->getName() + "/" + files->front().filename;

    std::ifstream streamfile(filePath);
    rapidxml::xml_document<> doc;

    std::vector<char> buffer((std::istreambuf_iterator<char>(streamfile)), std::istreambuf_iterator<char>());//streamfile)), std::istreambuf_iterator<char>());

    buffer.push_back('\0');//null terminating the buffer

    //std::cout << &buffer[0] << std::endl; //test the buffer

    doc.parse<0>(&buffer[0]);
    rapidxml::xml_node<>* root = doc.first_node(SCENE_STRING);//"scene");

    scene->getSceneGraphicsManager()->setAmbientLight(getXMLColour(root, AMBIENT_RED_STRING, AMBIENT_GREEN_STRING, AMBIENT_BLUE_STRING));

    //description attributes
    //north = boost::lexical_cast<float>(root->first_attribute(NORTH_STRING)->value());

    //Architecture
    rapidxml::xml_node<>* architectureNode = root->first_node(ARCHITECTURE_STRING);//"architecture");
    while(architectureNode != NULL)
    {
      int id = boost::lexical_cast<int>(architectureNode->first_attribute(ID_STRING)->value());
      try
      {
        scene->addArchitecture(id, getXMLPosition(architectureNode), getXMLRotation(architectureNode), getXMLScale(architectureNode));
      }
      catch(NHException e) 
      {
#ifdef _DEBUG
        std::cout << e.what() << std::endl;
#endif
      }
      
      architectureNode = architectureNode->next_sibling(ARCHITECTURE_STRING);
    }

    scene->build();//building static geometry - must do here else we can't use the navigation mesh for creature placement

    //Lights
    rapidxml::xml_node<>* lightNode = root->first_node(LIGHT_STRING);//"light");
    while(lightNode != NULL)
    {
      bool cast_shadows = boost::lexical_cast<bool>(lightNode->first_attribute(CAST_SHADOWS_STRING)->value());
      float range = boost::lexical_cast<float>(lightNode->first_attribute(RANGE_STRING)->value());
      Ogre::ColourValue colour = getXMLColour(lightNode);
      scene->addLight(-1, getXMLPosition(lightNode),cast_shadows,range);//TODO: use actual id rather than -1
      lightNode = lightNode->next_sibling(LIGHT_STRING);
    }

    //Items
    rapidxml::xml_node<>* itemNode = root->first_node(ITEM_STRING);
    while(itemNode != NULL)
    {
      int id = boost::lexical_cast<int>(itemNode->first_attribute(ID_STRING)->value());
      scene->addItem(id, getXMLPosition(itemNode), getXMLRotation(itemNode));
      itemNode = itemNode->next_sibling(ITEM_STRING);
    }

    //Creatures
    rapidxml::xml_node<>* creatureNode = root->first_node(CREATURE_STRING);
    while(creatureNode != NULL)
    {
      int id = boost::lexical_cast<int>(creatureNode->first_attribute(ID_STRING)->value());
      scene->addCreature(id, getXMLPosition(creatureNode));
      creatureNode = creatureNode->next_sibling(CREATURE_STRING);
    }

    //Portals
    rapidxml::xml_node<>* portalNode = root->first_node(PORTAL_STRING);
    while(portalNode != NULL)
    {
      int id = boost::lexical_cast<int>(portalNode->first_attribute(ID_STRING)->value());
      int targetSceneID = boost::lexical_cast<int>(portalNode->first_attribute(TARGET_SCENE_ID_STRING)->value());
      int targetPortalID = boost::lexical_cast<int>(portalNode->first_attribute(TARGET_PORTAL_ID_STRING)->value());
      scene->addPortal(id, getXMLPosition(portalNode), getXMLVector(portalNode, LOOK_AT_X_STRING, LOOK_AT_Y_STRING, LOOK_AT_Z_STRING), Id<Scene>(targetSceneID), Id<Portal>(targetPortalID), Id<Portal>(id));
      portalNode = portalNode->next_sibling(PORTAL_STRING);//"portal");
    }

    //Particles //TODO: change to emitter
    /*
    rapidxml::xml_node<>* particleNode = root->first_node(PARTICLE_STRING);//"particle");
    while(particleNode != NULL)
    {
      scene->addParticles(particleNode->first_attribute(NAME_STRING)->value(), particleNode->first_attribute(TEMPLATE_NAME_STRING)->value(),getXMLPosition(particleNode));
      particleNode = particleNode->next_sibling(PARTICLE_STRING);
    }
    */
  }
  catch (rapidxml::parse_error e)
  {
    std::stringstream ss;
    ss << "could not load the xml scene '" << filename << "': " << e.what() << std::endl;
    throw NHException(ss.str().c_str());
  }
}