Changeset 1243 for code/branches/ogre
- Timestamp:
- May 7, 2008, 12:11:25 AM (17 years ago)
- Location:
- code/branches/ogre/src
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ogre/src/core/CoreIncludes.h
r1062 r1243 59 59 if (orxonox::Identifier::isCreatingHierarchy() && this->getParents()) \ 60 60 this->getParents()->insert(this->getParents()->end(), this->getIdentifier()); \ 61 orxonox::ClassManager<ClassName>::getIdentifier()->addObject(this) 61 orxonox::ClassManager<ClassName>::getIdentifier()->addObject(this); \ 62 if (orxonox::Identifier::isCreatingHierarchy()) \ 63 return 62 64 63 65 /** -
code/branches/ogre/src/orxonox/GraphicsEngine.cc
r1220 r1243 44 44 #include "core/ConfigValueIncludes.h" 45 45 #include "core/Debug.h" 46 #include "core/TclBind.h"47 46 48 47 … … 65 64 { 66 65 RegisterObject(GraphicsEngine); 67 //this->bOverwritePath_ = false;68 this->setConfigValues();69 66 // set to standard values 70 67 this->configPath_ = ""; … … 72 69 this->scene_ = 0; 73 70 this->renderWindow_ = 0; 71 this->setConfigValues(); 74 72 COUT(4) << "*** GraphicsEngine: Constructed" << std::endl; 75 73 } … … 113 111 SetConfigValue(ogreLogLevelNormal_ , 4).description("Corresponding orxonox debug level for ogre Normal"); 114 112 SetConfigValue(ogreLogLevelCritical_, 2).description("Corresponding orxonox debug level for ogre Critical"); 115 116 TclBind::getInstance().setDataPath(this->dataPath_);117 113 } 118 114 … … 120 116 @brief Creates the Ogre Root object and sets up the ogre log. 121 117 */ 122 void GraphicsEngine::setup() 123 { 118 bool GraphicsEngine::setup(std::string& dataPath) 119 { 120 // temporary overwrite of dataPath, change ini file for permanent change 121 if (dataPath != "") 122 dataPath_ = dataPath; 123 if (dataPath_ == "") 124 return false; 125 if (dataPath_[dataPath_.size() - 1] != '/') 126 dataPath_ += "/"; 127 124 128 //TODO: Check if file exists (maybe not here) 125 /*#ifndef OGRE_STATIC_LIB126 root_ = new Ogre::Root(configPath_ + "plugins.cfg", configPath_ + "ogre.cfg",127 configPath_ + "Ogre.log");128 #else129 root_ = new Ogre::Root(NULL, configPath_ + "ogre.cfg", configPath_ + "Ogre.log");130 #endif*/131 129 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC && defined(_DEBUG) 132 130 std::string plugin_filename = "plugins_d.cfg"; … … 158 156 root_ = new Ogre::Root(plugin_filename); 159 157 COUT(4) << "*** GraphicsEngine: Creating Ogre Root done" << std::endl; 160 } 161 162 /** 163 * @return scene manager 164 */ 165 Ogre::SceneManager* GraphicsEngine::getSceneManager() 166 { 167 if(!scene_) 168 { 169 scene_ = root_->createSceneManager(Ogre::ST_GENERIC, "Default SceneManager"); 170 COUT(3) << "Info: Created SceneMan: " << scene_ << std::endl; 171 } 172 return scene_; 173 } 174 175 bool GraphicsEngine::load(std::string dataPath) 176 { 177 // temporary overwrite of dataPath, change ini file for permanent change 178 if( dataPath != "" ) 179 dataPath_ = dataPath + "/"; 180 loadRessourceLocations(this->dataPath_); 181 if (!root_->restoreConfig() && !root_->showConfigDialog()) 182 return false; 158 159 // specify where Ogre has to look for resources. This call doesn't parse anything yet! 160 declareRessourceLocations(); 161 183 162 return true; 184 163 } 185 164 186 void GraphicsEngine::initialise() 187 { 188 this->renderWindow_ = root_->initialise(true, "OrxonoxV2"); 189 Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, this); 190 Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5); 191 //TODO: Do NOT load all the groups, why are we doing that? And do we really do that? initialise != load... 192 Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); 193 } 194 195 void GraphicsEngine::loadRessourceLocations(std::string dataPath) 165 void GraphicsEngine::declareRessourceLocations() 196 166 { 197 167 //TODO: Specify layout of data file and maybe use xml-loader … … 199 169 // Load resource paths from data file using configfile ressource type 200 170 Ogre::ConfigFile cf; 201 cf.load(dataPath + "resources.cfg");171 cf.load(dataPath_ + "resources.cfg"); 202 172 203 173 // Go through all sections & settings in the file … … 216 186 217 187 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( 218 std::string(dataPath + archName),188 std::string(dataPath_ + archName), 219 189 typeName, secName); 220 190 } 221 191 } 192 } 193 194 bool GraphicsEngine::loadRenderer() 195 { 196 if (!root_->restoreConfig() && !root_->showConfigDialog()) 197 return false; 198 199 this->renderWindow_ = root_->initialise(true, "OrxonoxV2"); 200 if (!root_->isInitialised()) 201 return false; 202 Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, this); 203 Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5); 204 return true; 205 } 206 207 void GraphicsEngine::initialiseResources() 208 { 209 //TODO: Do NOT load all the groups, why are we doing that? And do we really do that? initialise != load... 210 Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); 211 } 212 213 /** 214 * @brief Creates the SceneManager 215 */ 216 bool GraphicsEngine::createNewScene() 217 { 218 if (scene_) 219 return false; 220 scene_ = root_->createSceneManager(Ogre::ST_GENERIC, "Default SceneManager"); 221 COUT(3) << "Info: Created SceneManager: " << scene_ << std::endl; 222 return true; 222 223 } 223 224 … … 291 292 } 292 293 OutputHandler::getOutStream().setOutputLevel(orxonoxLevel) 293 << " ***Ogre: " << message << std::endl;294 << "Ogre: " << message << std::endl; 294 295 } 295 296 -
code/branches/ogre/src/orxonox/GraphicsEngine.h
r1214 r1243 52 52 @brief Graphics engine manager class 53 53 */ 54 class _OrxonoxExport GraphicsEngine : public Ogre::WindowEventListener, public O rxonoxClass, public Ogre::LogListener54 class _OrxonoxExport GraphicsEngine : public Ogre::WindowEventListener, public Ogre::LogListener, public OrxonoxClass 55 55 { 56 friend class ClassIdentifier<GraphicsEngine>;57 56 public: 58 void setConfigPath(std::string path) { this->configPath_ = path; };59 57 void setConfigValues(); 60 void setup(); 61 bool load(std::string path); 62 void loadRessourceLocations(std::string path); 63 Ogre::SceneManager* getSceneManager(); 64 void initialise(); 58 bool setup(std::string& dataPath); 59 void declareRessourceLocations(); 60 bool loadRenderer(); 61 void initialiseResources(); 62 bool createNewScene(); 63 65 64 void destroy(); 65 66 Ogre::SceneManager* getSceneManager() { return scene_; } 67 std::string& getDataPath() { return dataPath_; } 66 68 67 69 // several window properties … … 71 73 int getWindowHeight() const; 72 74 73 static GraphicsEngine& getSingleton();74 static GraphicsEngine* getSingletonPtr() { return &getSingleton(); }75 76 75 void windowMoved(Ogre::RenderWindow* rw); 77 76 void windowResized(Ogre::RenderWindow* rw); 78 77 void windowFocusChanged(Ogre::RenderWindow* rw); 78 79 static GraphicsEngine& getSingleton(); 80 static GraphicsEngine* getSingletonPtr() { return &getSingleton(); } 79 81 80 82 private: -
code/branches/ogre/src/orxonox/Orxonox.cc
r1219 r1243 65 65 #include "core/InputBuffer.h" 66 66 #include "core/InputManager.h" 67 #include "core/TclBind.h" 67 68 68 69 // audio … … 166 167 this->ogre_ = &GraphicsEngine::getSingleton(); 167 168 this->timer_ = 0; 168 this->dataPath_ = ""; 169 this->auMan_ = 0; 169 //this->auMan_ = 0; 170 170 this->orxonoxHUD_ = 0; 171 171 this->inputHandler_ = 0; … … 186 186 Loader::close(); 187 187 InputManager::destroy(); 188 if (this->auMan_)189 delete this->auMan_;188 //if (this->auMan_) 189 // delete this->auMan_; 190 190 if (this->timer_) 191 191 delete this->timer_; … … 196 196 if (server_g) 197 197 delete server_g; 198 }199 200 /**201 @brief Immediately deletes the orxonox object.202 Never use if you can help it while rendering!203 */204 void Orxonox::abortImmediateForce()205 {206 COUT(1) << "*** Orxonox Error: Orxonox object was unexpectedly destroyed." << std::endl;207 delete this;208 198 } 209 199 … … 243 233 * @param path path to config (in home dir or something) 244 234 */ 245 voidOrxonox::init(int argc, char **argv, std::string path)235 bool Orxonox::init(int argc, char **argv, std::string path) 246 236 { 247 237 //TODO: find config file (assuming executable directory) … … 249 239 //TODO: give config file to Ogre 250 240 std::string mode; 241 std::string dataPath; 251 242 252 243 ArgReader ar(argc, argv); 253 244 ar.checkArgument("mode", mode, false); 254 ar.checkArgument("data", this->dataPath_, false);245 ar.checkArgument("data", dataPath, false); 255 246 ar.checkArgument("ip", serverIp_, false); 256 if(ar.errorHandling()) abortImmediateForce(); 257 if(mode == std::string("client")) 258 { 247 if(ar.errorHandling()) 248 return false; 249 250 if (mode == "client") 259 251 mode_ = CLIENT; 260 clientInit(path); 261 } 262 else if(mode== std::string("server")){ 252 else if (mode == "server") 263 253 mode_ = SERVER; 264 serverInit(path); 265 } 266 else{ 254 else 267 255 mode_ = STANDALONE; 268 standaloneInit(path); 269 } 270 } 271 272 void Orxonox::serverInit(std::string path) 273 { 274 COUT(2) << "initialising server" << std::endl; 275 276 ogre_->setConfigPath(path); 277 ogre_->setup(); 278 //root_ = ogre_->getRoot(); 279 if(!ogre_->load(this->dataPath_)) abortImmediateForce(/* unable to load */); 280 281 server_g = new network::Server(); 282 } 283 284 void Orxonox::clientInit(std::string path) 285 { 286 COUT(2) << "initialising client" << std::endl;\ 287 288 ogre_->setConfigPath(path); 289 ogre_->setup(); 290 if(serverIp_.compare("")==0) 291 client_g = new network::Client(); 292 else 293 client_g = new network::Client(serverIp_, NETWORK_PORT); 294 if(!ogre_->load(this->dataPath_)) abortImmediateForce(/* unable to load */); 295 } 296 297 void Orxonox::standaloneInit(std::string path) 298 { 299 COUT(2) << "initialising standalone mode" << std::endl; 300 301 ogre_->setConfigPath(path); 302 ogre_->setup(); 303 if(!ogre_->load(this->dataPath_)) abortImmediateForce(/* unable to load */); 256 257 //if (mode_ == DEDICATED) 258 // TODO: decide what to do here 259 //else 260 261 // for playable server, client and standalone, the startup 262 // procedure until the GUI is the identical 263 264 TclBind::getInstance().setDataPath(dataPath); 265 ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini"); 266 Factory::createClassHierarchy(); 267 268 if (!ogre_->setup(path)) // creates ogre root and other essentials 269 return false; 270 271 return true; 304 272 } 305 273 … … 307 275 * start modules 308 276 */ 309 void Orxonox::start() 310 { 311 switch(mode_){ 277 bool Orxonox::start() 278 { 279 //if (mode == DEDICATED) 280 // do something else 281 //else 282 283 if (!ogre_->loadRenderer()) // creates the render window 284 return false; 285 286 // Calls the InputHandler which sets up the input devices. 287 // The render window width and height are used to set up the mouse movement. 288 if (!InputManager::initialise(ogre_->getWindowHandle(), 289 ogre_->getWindowWidth(), ogre_->getWindowHeight())) 290 return false; 291 292 // TODO: Spread this so that this call onyl initialises things needed for the GUI 293 ogre_->initialiseResources(); 294 295 // TOOD: load the GUI here 296 // set InputManager to GUI mode 297 InputManager::setInputState(InputManager::IS_GUI); 298 // TODO: run GUI here 299 300 // The following lines depend very much on the GUI, so they're probably misplaced here.. 301 302 InputManager::setInputState(InputManager::IS_NONE); 303 304 if (!loadPlayground()) 305 return false; 306 307 switch (mode_) 308 { 309 case SERVER: 310 if (!serverLoad()) 311 return false; 312 break; 312 313 case CLIENT: 313 clientStart(); 314 break; 315 case SERVER: 316 serverStart(); 314 if (!clientLoad()) 315 return false; 317 316 break; 318 317 default: 319 standaloneStart(); 318 if (!standaloneLoad()) 319 return false; 320 320 } 321 } 322 323 void Orxonox::clientStart(){ 324 ogre_->initialise(); 325 ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini"); 326 Factory::createClassHierarchy(); 327 328 329 auMan_ = new audio::AudioManager(); 330 321 322 InputManager::setInputState(InputManager::IS_NORMAL); 323 324 return startRenderLoop(); 325 } 326 327 bool Orxonox::loadPlayground() 328 { 329 ogre_->createNewScene(); 330 331 // Init audio 332 //auMan_ = new audio::AudioManager(); 333 //auMan_->ambientAdd("a1"); 334 //auMan_->ambientAdd("a2"); 335 //auMan_->ambientAdd("a3"); 336 //auMan->ambientAdd("ambient1"); 337 //auMan_->ambientStart(); 338 339 // Load the HUD 331 340 Ogre::Overlay* hudOverlay = Ogre::OverlayManager::getSingleton().getByName("Orxonox/HUD1.2"); 332 341 orxonoxHUD_ = new HUD(); … … 335 344 hudOverlay->show(); 336 345 337 client_g->establishConnection();338 client_g->tick(0);339 340 341 //setupInputSystem();342 343 startRenderLoop();344 }345 346 void Orxonox::serverStart(){347 //TODO: start modules348 ogre_->initialise();349 //TODO: run engine350 ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini");351 Factory::createClassHierarchy();352 createScene();353 setupInputSystem();354 355 server_g->open();356 357 startRenderLoop();358 }359 360 void Orxonox::standaloneStart(){361 //TODO: start modules362 ogre_->initialise();363 //TODO: run engine364 ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini");365 Factory::createClassHierarchy();366 createScene();367 setupInputSystem();368 369 startRenderLoop();370 }371 372 void Orxonox::createScene(void)373 {374 // Init audio375 auMan_ = new audio::AudioManager();376 377 // load this file from config378 Level* startlevel = new Level("levels/sample.oxw");379 Loader::open(startlevel);380 381 Ogre::Overlay* hudOverlay = Ogre::OverlayManager::getSingleton().getByName("Orxonox/HUD1.2");382 orxonoxHUD_ = new HUD();383 orxonoxHUD_->setEnergyValue(20);384 orxonoxHUD_->setEnergyDistr(20,20,60);385 hudOverlay->show();386 387 /*388 auMan_->ambientAdd("a1");389 auMan_->ambientAdd("a2");390 auMan_->ambientAdd("a3");391 //auMan->ambientAdd("ambient1");392 auMan_->ambientStart();393 */394 }395 396 /**397 @brief Calls the InputHandler which sets up the input devices.398 The render window width and height are used to set up the mouse movement.399 */400 void Orxonox::setupInputSystem()401 {402 if (!InputManager::initialise(ogre_->getWindowHandle(),403 ogre_->getWindowWidth(), ogre_->getWindowHeight()))404 abortImmediateForce();405 InputManager::setInputState(InputManager::IS_NORMAL);406 }407 408 /**409 Main loop of the orxonox game.410 This is a new solution, using the ogre engine instead of being used by it.411 An alternative solution would be to simply use the timer of the Root object,412 but that implies using Ogre in any case. There would be no way to test413 our code without the help of the root object.414 There's even a chance that we can dispose of the root object entirely415 in server mode.416 About the loop: The design is almost exactly like the one in ogre, so that417 if any part of ogre registers a framelisteners, it will still behave418 correctly. Furthermore the time smoothing feature from ogre has been419 implemented too. If turned on (see orxonox constructor), it will calculate420 the dt_n by means of the recent most dt_n-1, dt_n-2, etc.421 */422 void Orxonox::startRenderLoop()423 {424 346 InputBuffer* ib = dynamic_cast<InputBuffer*>(InputManager::getKeyHandler("buffer")); 425 347 /* … … 432 354 ib->registerListener(console, &Testconsole::exit, (char)0x1B, true); 433 355 */ 434 435 356 orxonoxConsole_ = new InGameConsole(ib); 436 357 ib->registerListener(orxonoxConsole_, &InGameConsole::listen, true); … … 441 362 ib->registerListener(orxonoxConsole_, &InGameConsole::exit, (char)0x1B, true); 442 363 364 return true; 365 } 366 367 bool Orxonox::serverLoad() 368 { 369 COUT(2) << "initialising server" << std::endl; 370 371 server_g = new network::Server(); 372 373 if (!loadScene()) 374 return false; 375 376 server_g->open(); 377 378 return true; 379 } 380 381 bool Orxonox::clientLoad() 382 { 383 COUT(2) << "initialising client" << std::endl;\ 384 385 if (serverIp_.compare("") == 0) 386 client_g = new network::Client(); 387 else 388 client_g = new network::Client(serverIp_, NETWORK_PORT); 389 390 client_g->establishConnection(); 391 client_g->tick(0); 392 393 return true; 394 } 395 396 bool Orxonox::standaloneLoad() 397 { 398 COUT(2) << "initialising standalone mode" << std::endl; 399 400 if (!loadScene()) 401 return false; 402 403 return true; 404 } 405 406 bool Orxonox::loadScene() 407 { 408 Level* startlevel = new Level("levels/sample.oxw"); 409 Loader::open(startlevel); 410 411 return true; 412 } 413 414 415 /** 416 Main loop of the orxonox game. 417 About the loop: The design is almost exactly like the one in ogre, so that 418 if any part of ogre registers a framelisteners, it will still behave 419 correctly. Furthermore the time smoothing feature from ogre has been 420 implemented too. If turned on (see orxonox constructor), it will calculate 421 the dt_n by means of the recent most dt_n-1, dt_n-2, etc. 422 */ 423 bool Orxonox::startRenderLoop() 424 { 443 425 // first check whether ogre root object has been created 444 426 if (Ogre::Root::getSingletonPtr() == 0) 445 427 { 446 428 COUT(2) << "*** Orxonox Error: Could not start rendering. No Ogre root object found" << std::endl; 447 return ;429 return false; 448 430 } 449 431 Ogre::Root& ogreRoot = Ogre::Root::getSingleton(); … … 510 492 ogreRoot._fireFrameEnded(evt); 511 493 } 494 495 return true; 512 496 } 513 497 -
code/branches/ogre/src/orxonox/Orxonox.h
r1219 r1243 57 57 { 58 58 public: 59 voidinit(int argc, char **argv, std::string path);60 voidstart();61 void abortImmediateForce(); 59 bool init(int argc, char **argv, std::string path); 60 bool start(); 61 62 62 void abortRequest(); 63 inline audio::AudioManager* getAudioManagerPointer() { return auMan_; };63 //inline audio::AudioManager* getAudioManagerPointer() { return auMan_; }; 64 64 65 65 static Orxonox* getSingleton(); … … 79 79 ~Orxonox(); 80 80 81 // init functions 82 void serverInit(std::string path); 83 void clientInit(std::string path); 84 void standaloneInit(std::string path); 81 bool loadPlayground(); 85 82 86 // run functions 87 void serverStart(); 88 void clientStart(); 89 void standaloneStart(); 83 bool serverLoad(); 84 bool clientLoad(); 85 bool standaloneLoad(); 90 86 91 void createScene(); 92 void setupInputSystem(); 93 void startRenderLoop(); 87 bool loadScene(); 88 89 bool startRenderLoop(); 90 94 91 float calculateEventTime(unsigned long, std::deque<unsigned long>&); 95 92 96 93 private: 97 94 GraphicsEngine* ogre_; //!< our dearest graphics engine <3 98 std::string dataPath_; //!< path to data 99 audio::AudioManager* auMan_; //!< audio manager 95 //audio::AudioManager* auMan_; //!< audio manager 100 96 InputManager* inputHandler_; //!< Handles input with key bindings 101 97 Ogre::Timer* timer_; //!< Main loop timer -
code/branches/ogre/src/orxonox/objects/Explosion.cc
r1056 r1243 47 47 Explosion::Explosion(WorldEntity* owner) 48 48 { 49 RegisterObject(Explosion);50 51 49 this->particle_ = 0; 52 50 this->lifetime_ = 0.4; 51 52 RegisterObject(Explosion); 53 53 54 54 if (owner) -
code/branches/ogre/src/orxonox/objects/SpaceShip.cc
r1219 r1243 64 64 SpaceShip::SpaceShip() 65 65 { 66 RegisterObject(SpaceShip);67 this->registerAllVariables();68 69 66 SpaceShip::instance_s = this; 70 71 this->setConfigValues();72 67 73 68 this->setMouseEventCallback_ = false; … … 139 134 // this->create(); 140 135 136 RegisterObject(SpaceShip); 137 this->registerAllVariables(); 138 this->setConfigValues(); 141 139 142 140 COUT(3) << "Info: SpaceShip was loaded" << std::endl; … … 166 164 void SpaceShip::init() 167 165 { 166 if (!setMouseEventCallback_) 167 { 168 InputManager::addMouseHandler(this, "SpaceShip"); 169 setMouseEventCallback_ = true; 170 } 171 168 172 // START CREATING THRUSTER 169 173 this->tt_ = new ParticleInterface(GraphicsEngine::getSingleton().getSceneManager(),"twinthruster" + this->getName(),"Orxonox/engineglow"); … … 428 432 void SpaceShip::tick(float dt) 429 433 { 430 if (!setMouseEventCallback_)431 {432 InputManager::addMouseHandler(this, "SpaceShip");433 setMouseEventCallback_ = true;434 }435 436 434 if (this->redNode_ && this->greenNode_) 437 435 { -
code/branches/ogre/src/orxonox/objects/WorldEntity.cc
r1209 r1243 47 47 WorldEntity::WorldEntity() 48 48 { 49 RegisterObject(WorldEntity);50 51 //create();52 53 49 this->bStatic_ = true; 54 50 this->velocity_ = Vector3(0, 0, 0); … … 57 53 this->rotationRate_ = 0; 58 54 this->momentum_ = 0; 55 56 RegisterObject(WorldEntity); 59 57 60 58 if (GraphicsEngine::getSingleton().getSceneManager()) -
code/branches/ogre/src/orxonox/tools/Timer.cc
r1063 r1243 68 68 TimerBase::TimerBase() 69 69 { 70 RegisterRootObject(TimerBase);71 72 70 this->executor_ = 0; 73 71 this->interval_ = 0; … … 76 74 77 75 this->time_ = 0; 76 77 RegisterRootObject(TimerBase); 78 78 } 79 79 … … 83 83 TimerBase::~TimerBase() 84 84 { 85 delete this->executor_; 85 if (this->executor_) 86 delete this->executor_; 86 87 } 87 88
Note: See TracChangeset
for help on using the changeset viewer.