Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 7, 2008, 5:01:44 PM (16 years ago)
Author:
nicolasc
Message:

merged FICN back into trunk
awaiting release.

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

    • Property svn:ignore set to
      dependencies
  • code/trunk/src/loader/LevelLoader.cc

    r164 r790  
    1 #include <string.h>
    2 #include <iostream>
     1/*
     2*   ORXONOX - the hottest 3D action shooter ever to exist
     3*
     4*
     5*   License notice:
     6*
     7*   This program is free software; you can redistribute it and/or
     8*   modify it under the terms of the GNU General Public License
     9*   as published by the Free Software Foundation; either version 2
     10*   of the License, or (at your option) any later version.
     11*
     12*   This program is distributed in the hope that it will be useful,
     13*   but WITHOUT ANY WARRANTY; without even the implied warranty of
     14*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15*   GNU General Public License for more details.
     16*
     17*   You should have received a copy of the GNU General Public License
     18*   along with this program; if not, write to the Free Software
     19*   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     20*
     21*   Author:
     22*     Nicolas Perrenoud <nicolape@ee.ethz.ch>
     23*   Co-authors:
     24*      ...
     25*
     26*/
     27
     28#include "OrxonoxStableHeaders.h"
     29
     30#include <OgreOverlay.h>
     31#include <OgreOverlayManager.h>
     32
     33#include "core/Error.h"
     34#include "core/Debug.h"
     35#include "core/CoreIncludes.h"
     36
     37#include "audio/AudioManager.h"
     38#include "core/BaseObject.h"
     39#include "orxonox/Orxonox.h"
    340
    441#include "LevelLoader.h"
    5 #include "../xml/xmlParser.h"
    6 
    7 using namespace std;
    842
    943namespace loader
    1044{
    1145
    12 LevelLoader::LevelLoader(string file, string dir)
    13 {
    14         // Load XML level file
    15         dir.append("/");
    16         dir.append(file);       
    17         rootNode = XMLNode::openFileHelper(dir.c_str(),"WorldDataFile");
    18         // TODO: Error handling
    19 
    20         // Assing general level infos to class variables
    21         this->name_ = rootNode.getChildNode("name").getText();
    22         this->description_ = rootNode.getChildNode("description").getText();
    23         this->image_ = rootNode.getChildNode("image").getText();
    24  
    25         this->loadingScreen();
    26  
    27   // Assign sub-nodes
    28   if (rootNode.nChildNode("LightManager")==1)
     46  LevelLoader::LevelLoader(std::string file, std::string path)
    2947  {
    30         // Init Luightmanager...
     48    valid_ = false;
     49
     50    // Load XML level file
     51    path.append("/");
     52    path.append(file);
     53
     54    // Open xml file
     55    doc_.LoadFile(path.c_str());
     56
     57    // Check if file was loaded
     58    if (doc_.LoadFile())
     59    {
     60      TiXmlHandle hDoc(&doc_);
     61      TiXmlHandle hRoot(0);
     62      TiXmlElement* pElem;
     63
     64      // Check for root element
     65      pElem = hDoc.FirstChildElement("orxonoxworld").Element();
     66      if (pElem)
     67      {
     68        // Set root element
     69        hRoot = TiXmlHandle(pElem);
     70        rootElement_ = hRoot.Element();
     71
     72        // Set level description
     73        pElem = hRoot.FirstChild("description").Element();
     74        if (pElem)
     75        {
     76          description_ = pElem->GetText();
     77        }
     78
     79        // Set level name
     80        name_ = rootElement_->Attribute("name");
     81        image_ = rootElement_->Attribute("image");
     82
     83        valid_ = true;
     84      }
     85      else
     86      {
     87        orxonox::Error("Level file has no valid root node");
     88      }
     89    }
     90    else
     91    {
     92      orxonox::Error("Could not load level file ");
     93    }
    3194  }
    32  
    33   /*
    34  
    35         worldNode = rootNode.getChildNode("WorldEntities");
    36         scriptNode = rootNode.getChildNode("ScriptManager");
    37         cameraNode = rootNode.getChildNode("CameraMan");
    38         lightNode = rootNode.getChildNode("LightManager");
    39 */
     95
     96  void LevelLoader::loadLevel()
     97  {
     98    if (valid_)
     99    {
     100      TiXmlElement* loadElem;
     101      TiXmlElement* audioElem;
     102      TiXmlElement* worldElem;
     103      TiXmlElement* tElem;
     104      TiXmlNode* tNode;
     105
     106      Ogre::OverlayManager& omgr = Ogre::OverlayManager::getSingleton();
     107      Ogre::Overlay* mLoadOverlay; // FIXME: may be uninitialized
     108
     109      // Set loading screen
     110      loadElem = rootElement_->FirstChildElement("loading");
     111      if (loadElem)
     112      {
     113        // Set background
     114        tElem = loadElem->FirstChildElement("background");
     115        if (tElem)
     116        {
     117          loadingBackgroundColor_ = tElem->Attribute("color");
     118          loadingBackgroundImage_ = tElem->Attribute("image");
     119        }
     120        // Set bar
     121        tElem = loadElem->FirstChildElement("bar");
     122        if (tElem)
     123        {
     124          loadingBarImage_ = tElem->Attribute("image");;
     125          loadingBarTop_ = tElem->Attribute("top");
     126          loadingBarLeft_ = tElem->Attribute("left");
     127          loadingBarWidth_ = tElem->Attribute("width");
     128          loadingBarHeight_ = tElem->Attribute("height");
     129        }
     130
     131
     132        mLoadOverlay = (Ogre::Overlay*)omgr.getByName("Orxonox/LoadingScreenSample");
     133        mLoadOverlay->show();
     134
     135        COUT(0) << "This is Orxonox" << std::endl;
     136        COUT(0) << "the hottest 3D action shooter ever to exist" << std::endl;
     137        COUT(0) << "Level: " << name() << std::endl << "Description:" << description() << std::endl << "Image:" << image() << std::endl;
     138        COUT(4) << "Backgroundcolor: " << loadingBackgroundColor_ << std::endl << "Backgroundimage:" << loadingBackgroundImage_ << std::endl;
     139
     140      }
     141
     142      // Load audio
     143      audio::AudioManager* auMan = orxonox::Orxonox::getSingleton()->getAudioManagerPointer();
     144      audioElem = rootElement_->FirstChildElement("audio");
     145
     146      if (audioElem)
     147      {
     148        audioElem = audioElem->FirstChildElement("ambient");
     149        if (audioElem)
     150        {
     151          tNode = 0;
     152          //FIXME something is wrong, probably missing ==
     153          while( tNode = audioElem->IterateChildren( tNode ) )
     154          {
     155            if (tNode->Type() == TiXmlNode::ELEMENT)
     156            {
     157
     158              tElem = tNode->ToElement();
     159              std::string elemVal = tElem->Value();
     160              if (elemVal == "ogg")
     161              {
     162                COUT(3) << "Adding sound "<< tElem->Attribute("src") << std::endl;
     163
     164                auMan->ambientAdd(tElem->Attribute("src"));
     165              }
     166            }
     167          }
     168          auMan->ambientStart();
     169        }
     170      }
     171
     172      // Load world
     173      worldElem = rootElement_->FirstChildElement("world");
     174      if (worldElem)
     175      {
     176        tNode = 0;
     177        //FIXME something is wrong, probably missing ==
     178        while (tNode = worldElem->IterateChildren(tNode))
     179        {
     180          if (tNode->Type() == TiXmlNode::ELEMENT)
     181          {
     182            tElem = tNode->ToElement();
     183            orxonox::Identifier* id = ID(tElem->Value());
     184            if (id)
     185            {
     186              orxonox::BaseObject* obj = id->fabricate();
     187              obj->loadParams(tElem);
     188            }
     189            else
     190            {
     191              COUT(2) << "Warning: '"<< tElem->Value() <<"' is not a valid classname." << std::endl;
     192            }
     193          }
     194        }
     195      }
     196
     197      if (loadElem)
     198      {
     199        // FIXME: check for potential initialisation of mLoadOverlay
     200        mLoadOverlay->hide();
     201      }
     202
     203
     204      COUT(0) << "Loading finished!" << std::endl << std::endl;
     205    }
     206  }
     207
     208  LevelLoader::~LevelLoader()
     209  {
     210
     211  }
    40212
    41213}
    42 
    43 LevelLoader::~LevelLoader()
    44 {
    45 
    46 
    47 }
    48 
    49 
    50 string LevelLoader::name()
    51 {
    52         return this->name_;
    53 }
    54 
    55 string LevelLoader::description()
    56 {
    57         return this->description_;
    58 }
    59 
    60 string LevelLoader::image()
    61 {
    62         return this->image_;
    63 }
    64 
    65 void LevelLoader::loadingScreen()
    66 {
    67         cout << "\n\n\nThis is Orxonox\nthe hottest 3D action shooter ever to exist\n\n\n";
    68         cout << "Level: " << name() << "\nDescription:" << description() << "\nImage:"<<image()<<"\n\n\n";
    69 }
    70 
    71 /*
    72 
    73 
    74 void LevelLoader::loadWorld(WorldManager* wm)
    75 {
    76         if (!worldNode.getChildNode("lights").isEmpty())
    77         {
    78                
    79                
    80         }
    81 }
    82 
    83 
    84 void LevelLoader::loadLights(LightManager* lm)
    85 {
    86         if (!lightNode.getChildNode("lights").isEmpty())
    87         {
    88                 int nLights = lightNode.getChildNode("lights").nChildNode("light");
    89                 for (int i=0; i<nLights;i++)
    90                 {
    91                         XMLNode t = lightNode.getChildNode("lights").getChildNode("light",i);
    92                         const char* diffuse = t.getAttribute("diffuse-color");
    93                         const char* coor = t.getAttribute("abs-coor");
    94                         lm->addLight(diffuse,coor);     
    95                 }
    96         }
    97         lm->setAmbient(lightNode.getChildNode("ambient").getAttribute("color"));       
    98 }
    99 
    100 void LevelLoader::loadCameras(CameraManager* cm)
    101 {
    102         if (!cameraNode.getChildNode("cameras").isEmpty())
    103         {
    104                 int nCameras = cameraNode.getChildNode("cameras").nChildNode("camera");
    105                 for (int i=0; i<nCameras;i++)
    106                 {
    107                         XMLNode t = cameraNode.getChildNode("cameras").getChildNode("camera",i);
    108                        
    109                        
    110                         cm->addCamera();
    111                 }
    112         }
    113 }
    114 
    115 
    116 void LevelLoader::loadScripts(ScriptManager* sm)
    117 {
    118         if (!scriptNode.getChildNode("scripts").isEmpty())
    119         {
    120                 int nScripts = scriptNode.getChildNode("scripts").nChildNode("script");
    121                 for (int i=0; i<nScripts;i++)
    122                 {
    123                         XMLNode t = scriptNode.getChildNode("scripts").getChildNode("script",i);
    124                         sm->addScript(t.getAttribute("file"));
    125                 }
    126        
    127         }
    128 }
    129 */
    130 
    131 
    132 }
    133 
Note: See TracChangeset for help on using the changeset viewer.