[612] | 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 | * Benjamin Knecht <beni_at_orxonox.net>, (C) 2007 |
---|
| 23 | * Co-authors: |
---|
| 24 | * ... |
---|
| 25 | * |
---|
| 26 | */ |
---|
| 27 | |
---|
| 28 | /** |
---|
| 29 | @file Orxonox.cc |
---|
| 30 | @brief Orxonox Main Class |
---|
| 31 | */ |
---|
| 32 | |
---|
[784] | 33 | // Precompiled Headers |
---|
[823] | 34 | #include "OrxonoxStableHeaders.h" |
---|
[784] | 35 | |
---|
[612] | 36 | //****** OGRE ****** |
---|
| 37 | #include <OgreException.h> |
---|
| 38 | #include <OgreRoot.h> |
---|
| 39 | #include <OgreFrameListener.h> |
---|
| 40 | #include <OgreRenderWindow.h> |
---|
| 41 | #include <OgreTextureManager.h> |
---|
| 42 | #include <OgreResourceGroupManager.h> |
---|
| 43 | #include <OgreConfigFile.h> |
---|
| 44 | #include <OgreOverlay.h> |
---|
[823] | 45 | #include <OgreOverlayContainer.h> |
---|
[612] | 46 | #include <OgreOverlayManager.h> |
---|
| 47 | |
---|
| 48 | //****** OIS ******* |
---|
| 49 | #include <OIS/OIS.h> |
---|
| 50 | |
---|
| 51 | //****** STD ******* |
---|
| 52 | #include <iostream> |
---|
[673] | 53 | #include <exception> |
---|
[982] | 54 | #include <string.h> |
---|
[612] | 55 | |
---|
| 56 | //***** ORXONOX **** |
---|
[708] | 57 | //misc |
---|
[742] | 58 | #include "util/Sleep.h" |
---|
[708] | 59 | |
---|
[612] | 60 | // loader and audio |
---|
| 61 | #include "loader/LevelLoader.h" |
---|
| 62 | #include "audio/AudioManager.h" |
---|
| 63 | |
---|
| 64 | // network |
---|
| 65 | #include "network/Server.h" |
---|
| 66 | #include "network/Client.h" |
---|
| 67 | #include "network/NetworkFrameListener.h" |
---|
| 68 | |
---|
| 69 | // objects |
---|
| 70 | #include "objects/Tickable.h" |
---|
[748] | 71 | #include "tools/Timer.h" |
---|
[627] | 72 | #include "objects/NPC.h" |
---|
[612] | 73 | #include "core/ArgReader.h" |
---|
| 74 | #include "core/Factory.h" |
---|
| 75 | #include "core/Debug.h" |
---|
| 76 | #include "hud/HUD.h" |
---|
[823] | 77 | #include "hud/Bar.h" |
---|
[768] | 78 | #include "objects/weapon/BulletManager.h" |
---|
[729] | 79 | #include "GraphicsEngine.h" |
---|
[612] | 80 | |
---|
[823] | 81 | #include "Orxonox.h" |
---|
[612] | 82 | |
---|
| 83 | namespace orxonox |
---|
| 84 | { |
---|
| 85 | // put this in a seperate Class or solve the problem in another fashion |
---|
[708] | 86 | class OrxListener : public Ogre::FrameListener |
---|
[612] | 87 | { |
---|
| 88 | public: |
---|
| 89 | OrxListener(OIS::Keyboard *keyboard, audio::AudioManager* auMan, gameMode mode) |
---|
[616] | 90 | { |
---|
[612] | 91 | mKeyboard = keyboard; |
---|
| 92 | mode_=mode; |
---|
| 93 | auMan_ = auMan; |
---|
[616] | 94 | } |
---|
[612] | 95 | |
---|
[708] | 96 | bool frameStarted(const Ogre::FrameEvent& evt) |
---|
[612] | 97 | { |
---|
| 98 | auMan_->update(); |
---|
[627] | 99 | updateAI(); |
---|
[612] | 100 | |
---|
[665] | 101 | if(mode_ == PRESENTATION) |
---|
[612] | 102 | server_g->tick(evt.timeSinceLastFrame); |
---|
[665] | 103 | else if(mode_ == CLIENT) |
---|
[616] | 104 | client_g->tick(evt.timeSinceLastFrame); |
---|
[612] | 105 | |
---|
[616] | 106 | usleep(10); |
---|
[612] | 107 | |
---|
[616] | 108 | mKeyboard->capture(); |
---|
[612] | 109 | return !mKeyboard->isKeyDown(OIS::KC_ESCAPE); |
---|
| 110 | } |
---|
| 111 | |
---|
[627] | 112 | void updateAI() |
---|
| 113 | { |
---|
| 114 | for(Iterator<NPC> it = ObjectList<NPC>::start(); it; ++it) |
---|
| 115 | { |
---|
| 116 | it->update(); |
---|
| 117 | } |
---|
| 118 | } |
---|
| 119 | |
---|
[612] | 120 | private: |
---|
| 121 | gameMode mode_; |
---|
| 122 | OIS::Keyboard *mKeyboard; |
---|
| 123 | audio::AudioManager* auMan_; |
---|
[616] | 124 | }; |
---|
[612] | 125 | |
---|
| 126 | // init static singleton reference of Orxonox |
---|
| 127 | Orxonox* Orxonox::singletonRef_ = NULL; |
---|
| 128 | |
---|
| 129 | /** |
---|
| 130 | * create a new instance of Orxonox |
---|
| 131 | */ |
---|
| 132 | Orxonox::Orxonox() |
---|
| 133 | { |
---|
| 134 | this->ogre_ = new GraphicsEngine(); |
---|
| 135 | this->dataPath_ = ""; |
---|
[616] | 136 | this->loader_ = 0; |
---|
| 137 | this->auMan_ = 0; |
---|
| 138 | this->singletonRef_ = 0; |
---|
| 139 | this->keyboard_ = 0; |
---|
| 140 | this->mouse_ = 0; |
---|
| 141 | this->inputManager_ = 0; |
---|
| 142 | this->frameListener_ = 0; |
---|
| 143 | this->root_ = 0; |
---|
[612] | 144 | } |
---|
| 145 | |
---|
| 146 | /** |
---|
| 147 | * destruct Orxonox |
---|
| 148 | */ |
---|
| 149 | Orxonox::~Orxonox() |
---|
| 150 | { |
---|
| 151 | // nothing to delete as for now |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | /** |
---|
| 155 | * initialization of Orxonox object |
---|
| 156 | * @param argc argument counter |
---|
| 157 | * @param argv list of arguments |
---|
| 158 | * @param path path to config (in home dir or something) |
---|
| 159 | */ |
---|
[715] | 160 | void Orxonox::init(int argc, char **argv, std::string path) |
---|
[612] | 161 | { |
---|
| 162 | //TODO: find config file (assuming executable directory) |
---|
| 163 | //TODO: read config file |
---|
| 164 | //TODO: give config file to Ogre |
---|
[715] | 165 | std::string mode; |
---|
[612] | 166 | // if(argc>=2) |
---|
[715] | 167 | // mode = std::string(argv[1]); |
---|
[612] | 168 | // else |
---|
| 169 | // mode = ""; |
---|
| 170 | ArgReader ar = ArgReader(argc, argv); |
---|
| 171 | ar.checkArgument("mode", mode, false); |
---|
| 172 | ar.checkArgument("data", this->dataPath_, false); |
---|
| 173 | ar.checkArgument("ip", serverIp_, false); |
---|
[637] | 174 | //mode = "presentation"; |
---|
[612] | 175 | if(ar.errorHandling()) die(); |
---|
[715] | 176 | if(mode == std::string("server")) |
---|
[612] | 177 | { |
---|
| 178 | serverInit(path); |
---|
| 179 | mode_ = SERVER; |
---|
| 180 | } |
---|
[715] | 181 | else if(mode == std::string("client")) |
---|
[612] | 182 | { |
---|
| 183 | clientInit(path); |
---|
| 184 | mode_ = CLIENT; |
---|
| 185 | } |
---|
[715] | 186 | else if(mode == std::string("presentation")) |
---|
[612] | 187 | { |
---|
| 188 | serverInit(path); |
---|
| 189 | mode_ = PRESENTATION; |
---|
| 190 | } |
---|
| 191 | else{ |
---|
| 192 | standaloneInit(path); |
---|
| 193 | mode_ = STANDALONE; |
---|
| 194 | } |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | /** |
---|
| 198 | * start modules |
---|
| 199 | */ |
---|
| 200 | void Orxonox::start() |
---|
| 201 | { |
---|
| 202 | //TODO: start modules |
---|
| 203 | ogre_->startRender(); |
---|
| 204 | //TODO: run engine |
---|
[823] | 205 | Factory::createClassHierarchy(); |
---|
[612] | 206 | createScene(); |
---|
| 207 | setupScene(); |
---|
| 208 | setupInputSystem(); |
---|
| 209 | if(mode_!=CLIENT){ // remove this in future ---- presentation hack |
---|
| 210 | } |
---|
| 211 | else |
---|
| 212 | std::cout << "client here" << std::endl; |
---|
| 213 | createFrameListener(); |
---|
| 214 | switch(mode_){ |
---|
| 215 | case PRESENTATION: |
---|
| 216 | //ogre_->getRoot()->addFrameListener(new network::ServerFrameListener()); |
---|
| 217 | //std::cout << "could not add framelistener" << std::endl; |
---|
| 218 | server_g->open(); |
---|
| 219 | break; |
---|
| 220 | case CLIENT: |
---|
| 221 | client_g->establishConnection(); |
---|
| 222 | break; |
---|
| 223 | case SERVER: |
---|
| 224 | case STANDALONE: |
---|
| 225 | default: |
---|
| 226 | break; |
---|
| 227 | } |
---|
| 228 | startRenderLoop(); |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | /** |
---|
| 232 | * @return singleton object |
---|
| 233 | */ |
---|
| 234 | Orxonox* Orxonox::getSingleton() |
---|
| 235 | { |
---|
| 236 | if (!singletonRef_) |
---|
| 237 | singletonRef_ = new Orxonox(); |
---|
| 238 | return singletonRef_; |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | /** |
---|
| 242 | * error kills orxonox |
---|
| 243 | */ |
---|
| 244 | void Orxonox::die(/* some error code */) |
---|
| 245 | { |
---|
| 246 | //TODO: destroy and destruct everything and print nice error msg |
---|
| 247 | delete this; |
---|
| 248 | } |
---|
| 249 | |
---|
[715] | 250 | void Orxonox::standaloneInit(std::string path) |
---|
[612] | 251 | { |
---|
| 252 | ogre_->setConfigPath(path); |
---|
| 253 | ogre_->setup(); |
---|
| 254 | root_ = ogre_->getRoot(); |
---|
| 255 | if(!ogre_->load()) die(/* unable to load */); |
---|
| 256 | |
---|
| 257 | //defineResources(); |
---|
| 258 | //setupRenderSystem(); |
---|
| 259 | //createRenderWindow(); |
---|
| 260 | //initializeResourceGroups(); |
---|
| 261 | /*createScene(); |
---|
| 262 | setupScene(); |
---|
| 263 | setupInputSystem(); |
---|
| 264 | createFrameListener(); |
---|
| 265 | Factory::createClassHierarchy(); |
---|
| 266 | startRenderLoop();*/ |
---|
| 267 | } |
---|
| 268 | |
---|
[715] | 269 | void Orxonox::playableServer(std::string path) |
---|
[612] | 270 | { |
---|
| 271 | ogre_->setConfigPath(path); |
---|
| 272 | ogre_->setup(); |
---|
| 273 | root_ = ogre_->getRoot(); |
---|
| 274 | defineResources(); |
---|
| 275 | setupRenderSystem(); |
---|
| 276 | createRenderWindow(); |
---|
| 277 | initializeResourceGroups(); |
---|
[616] | 278 | setupInputSystem(); |
---|
| 279 | Factory::createClassHierarchy(); |
---|
[612] | 280 | createScene(); |
---|
| 281 | setupScene(); |
---|
| 282 | createFrameListener(); |
---|
| 283 | try{ |
---|
[665] | 284 | server_g = new network::Server(); //!< add port and bindadress |
---|
| 285 | server_g->open(); //!< open server and create listener thread |
---|
[612] | 286 | if(ogre_ && ogre_->getRoot()) |
---|
| 287 | ogre_->getRoot()->addFrameListener(new network::ServerFrameListener()); // adds a framelistener for the server |
---|
| 288 | COUT(3) << "Info: network framelistener added" << std::endl; |
---|
| 289 | } |
---|
[782] | 290 | catch(...) |
---|
[612] | 291 | { |
---|
| 292 | COUT(1) << "Error: There was a problem initialising the server :(" << std::endl; |
---|
| 293 | } |
---|
| 294 | startRenderLoop(); |
---|
| 295 | } |
---|
| 296 | |
---|
| 297 | void Orxonox::standalone(){ |
---|
| 298 | |
---|
| 299 | |
---|
| 300 | |
---|
| 301 | } |
---|
| 302 | |
---|
[715] | 303 | void Orxonox::serverInit(std::string path) |
---|
[612] | 304 | { |
---|
| 305 | COUT(2) << "initialising server" << std::endl; |
---|
| 306 | ogre_->setConfigPath(path); |
---|
| 307 | ogre_->setup(); |
---|
[665] | 308 | server_g = new network::Server(); // FIXME add some settings if wanted |
---|
[612] | 309 | if(!ogre_->load()) die(/* unable to load */); |
---|
[665] | 310 | // FIXME add network framelistener |
---|
[612] | 311 | } |
---|
| 312 | |
---|
[715] | 313 | void Orxonox::clientInit(std::string path) |
---|
[612] | 314 | { |
---|
| 315 | COUT(2) << "initialising client" << std::endl; |
---|
| 316 | ogre_->setConfigPath(path); |
---|
| 317 | ogre_->setup(); |
---|
| 318 | if(serverIp_.compare("")==0) |
---|
| 319 | client_g = new network::Client(); |
---|
| 320 | else |
---|
| 321 | client_g = new network::Client(serverIp_, 55556); |
---|
| 322 | if(!ogre_->load()) die(/* unable to load */); |
---|
| 323 | ogre_->getRoot()->addFrameListener(new network::ClientFrameListener()); |
---|
| 324 | } |
---|
| 325 | |
---|
| 326 | void Orxonox::defineResources() |
---|
| 327 | { |
---|
[715] | 328 | std::string secName, typeName, archName; |
---|
[612] | 329 | Ogre::ConfigFile cf; |
---|
| 330 | #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE |
---|
| 331 | cf.load(macBundlePath() + "/Contents/Resources/resources.cfg"); |
---|
| 332 | #else |
---|
| 333 | cf.load(dataPath_ + "resources.cfg"); |
---|
| 334 | #endif |
---|
| 335 | |
---|
| 336 | Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator(); |
---|
| 337 | while (seci.hasMoreElements()) |
---|
| 338 | { |
---|
| 339 | secName = seci.peekNextKey(); |
---|
| 340 | Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext(); |
---|
| 341 | Ogre::ConfigFile::SettingsMultiMap::iterator i; |
---|
| 342 | for (i = settings->begin(); i != settings->end(); ++i) |
---|
| 343 | { |
---|
| 344 | typeName = i->first; |
---|
| 345 | archName = i->second; |
---|
| 346 | #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE |
---|
[715] | 347 | Ogre::ResourceGroupManager::getSingleton().addResourceLocation( std::string(macBundlePath() + "/" + archName), typeName, secName); |
---|
[612] | 348 | #else |
---|
[708] | 349 | Ogre::ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName); |
---|
[612] | 350 | #endif |
---|
| 351 | } |
---|
| 352 | } |
---|
| 353 | } |
---|
| 354 | |
---|
| 355 | void Orxonox::setupRenderSystem() |
---|
| 356 | { |
---|
| 357 | if (!root_->restoreConfig() && !root_->showConfigDialog()) |
---|
[708] | 358 | throw Ogre::Exception(52, "User canceled the config dialog!", "OrxApplication::setupRenderSystem()"); |
---|
[612] | 359 | } |
---|
| 360 | |
---|
| 361 | void Orxonox::createRenderWindow() |
---|
| 362 | { |
---|
| 363 | root_->initialise(true, "OrxonoxV2"); |
---|
| 364 | } |
---|
| 365 | |
---|
| 366 | void Orxonox::initializeResourceGroups() |
---|
| 367 | { |
---|
[708] | 368 | Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5); |
---|
| 369 | Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); |
---|
[612] | 370 | } |
---|
| 371 | |
---|
| 372 | /** |
---|
| 373 | * |
---|
| 374 | * @param |
---|
| 375 | */ |
---|
| 376 | void Orxonox::createScene(void) |
---|
| 377 | { |
---|
| 378 | // Init audio |
---|
| 379 | auMan_ = new audio::AudioManager(); |
---|
| 380 | |
---|
[637] | 381 | bulletMgr_ = new BulletManager(); |
---|
| 382 | |
---|
[612] | 383 | // load this file from config |
---|
| 384 | loader_ = new loader::LevelLoader("sample.oxw"); |
---|
| 385 | loader_->loadLevel(); |
---|
| 386 | |
---|
[823] | 387 | // Ogre::Overlay* hudOverlay = Ogre::OverlayManager::getSingleton().getByName("Orxonox/HUD1.2"); |
---|
| 388 | // Ogre::OverlayContainer* cont = Ogre::OverlayManager::createOverlayElement("Orxonox/HUD1.2/MyShip", "Orxonox/HUD1.2/shieldLeftTop", false); |
---|
| 389 | // Ogre::OverlayContainer* cont = Ogre::OverlayManager::getSingleton().getByName("Orxonox/HUD1.2/MapBackGround"); |
---|
| 390 | |
---|
| 391 | // hud::Bar* newBar = Ogre::OverlayManager::createOverlayElement("Element", "ElementName"); |
---|
| 392 | //new hud::Bar(1,true,Ogre::ColourValue::Black,"Orxonox/hi"); |
---|
| 393 | // cont->addChild(newBar-> element_); |
---|
| 394 | // hud::Bar* newBar = Ogre::OverlayManager::createOverlayElement("orxonox/bar", "orxonox/newbar", false); |
---|
[982] | 395 | |
---|
[823] | 396 | |
---|
[982] | 397 | // Ogre::OverlayManager& overlayManager = Ogre::OverlayManager::getSingleton(); |
---|
[823] | 398 | |
---|
[982] | 399 | // Ogre::Overlay* hudOverlay = overlayManager.create("orxonoxsuperoverlay"); |
---|
[823] | 400 | |
---|
[982] | 401 | /* Bar* newBar = static_cast<Bar*>(overlayManager.createOverlayElement("Panel", "Bar")); |
---|
[823] | 402 | newBar->setLeft(0); |
---|
| 403 | newBar->setTop(0); |
---|
[982] | 404 | newBar->setWidth(100); |
---|
[823] | 405 | newBar->setHeight(10); |
---|
| 406 | newBar->setMaterialName("Orxonox/Red"); |
---|
[982] | 407 | newBar->setMetricsMode(Ogre::GMM_PIXELS); |
---|
| 408 | newBar->setPercentage(0.5); |
---|
[823] | 409 | newBar->show(); |
---|
[982] | 410 | |
---|
| 411 | */ |
---|
| 412 | /* |
---|
| 413 | Bar* newBar; |
---|
| 414 | newBar = new Bar(0,0,100,10,Bar::LEFT, Bar::RED,"hallo"); |
---|
| 415 | newBar->reset(50); |
---|
[823] | 416 | |
---|
[982] | 417 | Bar* newBar2; |
---|
| 418 | newBar2 = new Bar(0,20,100,10,Bar::UP,Bar::GREEN,"hallo2"); |
---|
| 419 | newBar2->reset(50); |
---|
[823] | 420 | |
---|
[982] | 421 | Bar* newBar3; |
---|
| 422 | newBar3 = new Bar(0,40,100,10,Bar::RIGHT,Bar::RED,"hallo3"); |
---|
| 423 | newBar3->reset(50); |
---|
| 424 | |
---|
| 425 | Bar* newBar4; |
---|
| 426 | newBar4 = new Bar(0,60,100,10,Bar::DOWN,Bar::YELLOW,"hallo4"); |
---|
| 427 | newBar4->reset(50); |
---|
| 428 | newBar4->hide(); |
---|
| 429 | newBar4->show(); |
---|
| 430 | |
---|
| 431 | SmartBar* newBar5; |
---|
| 432 | newBar5 = new SmartBar(0,80,100,10,Bar::DOWN,"hallo5"); |
---|
| 433 | |
---|
| 434 | SmartBar* newBar6; |
---|
| 435 | newBar6 = new SmartBar(50,80,100,10,Bar::DOWN,"hallo6"); |
---|
| 436 | |
---|
| 437 | newBar5->reset(56); |
---|
| 438 | |
---|
| 439 | |
---|
| 440 | */ |
---|
| 441 | /* |
---|
| 442 | Ogre::OverlayElement* element = overlayManager.createOverlayElement("Panel",s); |
---|
| 443 | element->setLeft(0); |
---|
| 444 | element->setTop(0); |
---|
| 445 | element->setWidth(100); |
---|
| 446 | element->setHeight(10); |
---|
| 447 | element->setMaterialName("Orxonox/Red"); |
---|
| 448 | element->setMetricsMode(Ogre::GMM_PIXELS); |
---|
| 449 | */ |
---|
| 450 | /* Ogre::OverlayContainer* panel = static_cast<Ogre::OverlayContainer*> (overlayManager.createOverlayElement("Panel", "PanelName")); |
---|
[823] | 451 | panel->setLeft(10); |
---|
| 452 | panel->setTop(10); |
---|
| 453 | panel->setWidth(100); |
---|
| 454 | panel->setHeight(100); |
---|
[982] | 455 | panel->setMetricsMode(Ogre::GMM_PIXELS); |
---|
[823] | 456 | panel->show(); |
---|
| 457 | |
---|
| 458 | |
---|
[982] | 459 | if(dynamic_cast<Ogre::TextAreaOverlayElement*> (overlayManager.createOverlayElement("TextArea", "hallo7"))!= NULL ){panel->addChild(newBar5->element);} |
---|
[612] | 460 | |
---|
[982] | 461 | Ogre::TextAreaOverlayElement* newEle = dynamic_cast<Ogre::TextAreaOverlayElement*> (overlayManager.createOverlayElement("TextArea", "hallo8")); |
---|
| 462 | newEle->setColour(Ogre::ColourValue::Blue); |
---|
| 463 | newEle->setCaption("hallo"); |
---|
| 464 | newEle->setPosition(0,0); |
---|
| 465 | newEle->setDimensions(0,0); |
---|
| 466 | newEle->setHorizontalAlignment(Ogre::GHA_LEFT); |
---|
| 467 | // newEle->setMaterialName("Orxonox/Red"); |
---|
| 468 | newEle->setCharHeight(18); |
---|
| 469 | newEle->setFontName("BlueHighway"); |
---|
| 470 | // newEle->setMetricsMode(Ogre::GMM_PIXELS); |
---|
[823] | 471 | |
---|
[982] | 472 | |
---|
| 473 | Ogre::OverlayElement* newEle2 =Ogre:: OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/RocketNum1"); |
---|
| 474 | newEle2->setColour(Ogre::ColourValue::Red); |
---|
| 475 | newEle2->setCaption("hallo"); |
---|
| 476 | newEle2->setPosition(-50,0); |
---|
| 477 | newEle2->setDimensions(0,0); |
---|
| 478 | // newEle->setMaterialName("Orxonox/Red"); |
---|
| 479 | // newEle2->setCharHeight(18); |
---|
| 480 | // newEle2->setFontName("BlueHighway"); |
---|
| 481 | // newEle2->setMetricsMode(Ogre::GMM_PIXELS); |
---|
| 482 | |
---|
| 483 | |
---|
| 484 | panel->addChild(newEle2); |
---|
| 485 | |
---|
| 486 | */ |
---|
| 487 | |
---|
| 488 | |
---|
| 489 | // hudOverlay->add2D(panel); |
---|
| 490 | /* panel->addChild(newBar->element); |
---|
| 491 | panel->addChild(newBar2->element); |
---|
| 492 | panel->addChild(newBar3->element); |
---|
| 493 | panel->addChild(newBar4->element); |
---|
| 494 | panel->addChild(newBar5->element); |
---|
| 495 | panel->addChild(newBar6->element); |
---|
| 496 | */// panel->addChild(newEle); |
---|
| 497 | |
---|
| 498 | |
---|
| 499 | |
---|
| 500 | // HUD2* orxonoxHud; |
---|
| 501 | // orxonoxHud = new HUD2(); |
---|
| 502 | // orxonoxHud->setEnergyValue(20); |
---|
| 503 | // orxonoxHud->setEnergyDistr(20,20,60); |
---|
| 504 | // hudOverlay->show(); |
---|
| 505 | |
---|
| 506 | HUD* orxonoxHUD = new HUD(1); |
---|
| 507 | |
---|
| 508 | |
---|
[612] | 509 | /* |
---|
| 510 | auMan_->ambientAdd("a1"); |
---|
| 511 | auMan_->ambientAdd("a2"); |
---|
| 512 | auMan_->ambientAdd("a3"); |
---|
| 513 | //auMan->ambientAdd("ambient1"); |
---|
| 514 | auMan_->ambientStart();*/ |
---|
| 515 | } |
---|
| 516 | |
---|
| 517 | |
---|
| 518 | /** |
---|
| 519 | * |
---|
| 520 | */ |
---|
| 521 | void Orxonox::setupScene() |
---|
| 522 | { |
---|
| 523 | // SceneManager *mgr = ogre_->getSceneManager(); |
---|
| 524 | |
---|
| 525 | |
---|
| 526 | // SceneNode* node = (SceneNode*)mgr->getRootSceneNode()->getChild("OgreHeadNode"); |
---|
| 527 | // SceneNode *node = mgr->getRootSceneNode()->createChildSceneNode("OgreHeadNode", Vector3(0,0,0)); |
---|
| 528 | |
---|
| 529 | |
---|
| 530 | /* |
---|
| 531 | particle::ParticleInterface *e = new particle::ParticleInterface(mgr,"engine","Orxonox/strahl"); |
---|
| 532 | e->particleSystem_->setParameter("local_space","true"); |
---|
| 533 | e->setPositionOfEmitter(0, Vector3(0,-10,0)); |
---|
| 534 | e->setDirection(Vector3(0,0,-1)); |
---|
| 535 | e->addToSceneNode(node); |
---|
| 536 | */ |
---|
| 537 | } |
---|
| 538 | |
---|
| 539 | |
---|
| 540 | void Orxonox::setupInputSystem() |
---|
| 541 | { |
---|
| 542 | size_t windowHnd = 0; |
---|
| 543 | std::ostringstream windowHndStr; |
---|
| 544 | OIS::ParamList pl; |
---|
[663] | 545 | |
---|
| 546 | // fixes auto repeat problem |
---|
| 547 | #if defined OIS_LINUX_PLATFORM |
---|
[715] | 548 | pl.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true"))); |
---|
[663] | 549 | #endif |
---|
| 550 | |
---|
[708] | 551 | Ogre::RenderWindow *win = ogre_->getRoot()->getAutoCreatedWindow(); |
---|
[612] | 552 | win->getCustomAttribute("WINDOW", &windowHnd); |
---|
| 553 | windowHndStr << windowHnd; |
---|
[715] | 554 | pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); |
---|
[612] | 555 | inputManager_ = OIS::InputManager::createInputSystem(pl); |
---|
| 556 | |
---|
| 557 | try |
---|
| 558 | { |
---|
| 559 | keyboard_ = static_cast<OIS::Keyboard*>(inputManager_->createInputObject(OIS::OISKeyboard, false)); |
---|
| 560 | mouse_ = static_cast<OIS::Mouse*>(inputManager_->createInputObject(OIS::OISMouse, true)); |
---|
| 561 | } |
---|
| 562 | catch (const OIS::Exception &e) |
---|
| 563 | { |
---|
| 564 | throw new Ogre::Exception(42, e.eText, "OrxApplication::setupInputSystem"); |
---|
| 565 | } |
---|
| 566 | } |
---|
| 567 | |
---|
[665] | 568 | // FIXME we actually want to do this differently... |
---|
[612] | 569 | void Orxonox::createFrameListener() |
---|
| 570 | { |
---|
| 571 | TickFrameListener* TickFL = new TickFrameListener(); |
---|
| 572 | ogre_->getRoot()->addFrameListener(TickFL); |
---|
| 573 | |
---|
| 574 | TimerFrameListener* TimerFL = new TimerFrameListener(); |
---|
| 575 | ogre_->getRoot()->addFrameListener(TimerFL); |
---|
| 576 | |
---|
[665] | 577 | //if(mode_!=CLIENT) // FIXME just a hack ------- remove this in future |
---|
[612] | 578 | frameListener_ = new OrxListener(keyboard_, auMan_, mode_); |
---|
| 579 | ogre_->getRoot()->addFrameListener(frameListener_); |
---|
| 580 | } |
---|
| 581 | |
---|
| 582 | void Orxonox::startRenderLoop() |
---|
| 583 | { |
---|
[665] | 584 | // FIXME |
---|
[612] | 585 | // this is a hack!!! |
---|
| 586 | // the call to reset the mouse clipping size should probably be somewhere |
---|
| 587 | // else, however this works for the moment. |
---|
| 588 | unsigned int width, height, depth; |
---|
| 589 | int left, top; |
---|
| 590 | ogre_->getRoot()->getAutoCreatedWindow()->getMetrics(width, height, depth, left, top); |
---|
| 591 | |
---|
| 592 | if(mode_!=CLIENT){ |
---|
| 593 | const OIS::MouseState &ms = mouse_->getMouseState(); |
---|
| 594 | ms.width = width; |
---|
| 595 | ms.height = height; |
---|
| 596 | } |
---|
| 597 | ogre_->getRoot()->startRendering(); |
---|
| 598 | } |
---|
| 599 | } |
---|