Changeset 929 for code/branches/network/src/orxonox
- Timestamp:
- Mar 26, 2008, 11:39:55 PM (17 years ago)
- Location:
- code/branches/network/src/orxonox
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/orxonox/GraphicsEngine.cc
r926 r929 33 33 34 34 #include <OgreRoot.h> 35 #include <OgreException.h> 35 36 #include <OgreConfigFile.h> 36 37 #include <OgreTextureManager.h> … … 61 62 GraphicsEngine::~GraphicsEngine() 62 63 { 64 if (!this->root_) 65 delete this->root_; 63 66 } 64 67 … … 78 81 root_ = new Root(NULL, configPath_ + "ogre.cfg", configPath_ + "Ogre.log"); 79 82 #endif*/ 80 #if defined(_DEBUG) && defined(WIN32)83 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC && defined(_DEBUG) 81 84 std::string plugin_filename = "plugins_d.cfg"; 82 85 #else … … 110 113 } 111 114 112 void GraphicsEngine:: startRender()115 void GraphicsEngine::initialise() 113 116 { 114 root_->initialise(true, "OrxonoxV2"); 115 this->renderWindow_ = root_->getAutoCreatedWindow(); 117 this->renderWindow_ = root_->initialise(true, "OrxonoxV2"); 116 118 TextureManager::getSingleton().setDefaultNumMipmaps(5); 117 119 //TODO: Do NOT load all the groups, why are we doing that? And do we really do that? initialise != load... -
code/branches/network/src/orxonox/GraphicsEngine.h
r926 r929 10 10 #include <string> 11 11 12 #include <OgrePrerequisites.h> 12 13 #include <OgreRoot.h> 13 14 #include <OgreSceneManager.h> 14 15 15 16 #include "OrxonoxPrereqs.h" 16 #include "core/ BaseObject.h"17 #include "core/OrxonoxClass.h" 17 18 18 19 … … 22 23 * graphics engine manager class 23 24 */ 24 class _OrxonoxExport GraphicsEngine : public BaseObject25 class _OrxonoxExport GraphicsEngine : public OrxonoxClass 25 26 { 26 27 public: … … 28 29 inline void setConfigPath(std::string path) { this->configPath_ = path; }; 29 30 // find a better way for this 30 inline Ogre::Root* getRoot() { return root_; };31 //inline Ogre::Root* getRoot() { return root_; }; 31 32 void setConfigValues(); 32 33 void setup(); … … 34 35 void loadRessourceLocations(std::string path); 35 36 Ogre::SceneManager* getSceneManager(); 36 void startRender();37 void initialise(); 37 38 38 39 // several window properties 40 Ogre::RenderWindow* getRenderWindow() { return this->renderWindow_; } 39 41 size_t getWindowHandle(); 40 42 int getWindowWidth() const; 41 43 int getWindowHeight() const; 42 44 45 // Ogre Root access for Orxonox 46 void frameStarted(Ogre::FrameEvent &evt) 47 { if (root_) root_->_fireFrameStarted(evt); } 48 void frameEnded (Ogre::FrameEvent &evt) 49 { if (root_) root_->_fireFrameEnded(evt); } 50 void renderOneFrame() 51 { if (root_) root_->_updateAllRenderTargets(); } 52 43 53 virtual ~GraphicsEngine(); 54 44 55 private: 45 56 Ogre::Root* root_; //!< Ogre's root -
code/branches/network/src/orxonox/InputHandler.cc
r928 r929 44 44 @brief Constructor only resets the pointer values to 0. 45 45 */ 46 InputHandler::InputHandler() 46 InputHandler::InputHandler() : 47 mouse_(0), keyboard_(0), inputSystem_(0), 48 uninitialized_(true) 47 49 { 48 50 //RegisterObject(InputHandler); 49 this->mouse_ = 0; 50 this->keyboard_ = 0; 51 this->inputSystem_ = 0; 51 } 52 53 /** 54 @brief Destructor only called at the end of the program 55 */ 56 InputHandler::~InputHandler() 57 { 58 this->destroy(); 52 59 } 53 60 … … 71 78 void InputHandler::initialise(size_t windowHnd, int windowWidth, int windowHeight) 72 79 { 73 if ( !inputSystem_)80 if (this->uninitialized_ || !this->inputSystem_) 74 81 { 75 82 // Setup basic variables … … 104 111 this->setWindowExtents(windowWidth, windowHeight); 105 112 } 113 114 uninitialized_ = false; 106 115 } 107 116 … … 120 129 void InputHandler::destroy() 121 130 { 122 this->inputSystem_->destroyInputObject(this->mouse_); 123 this->inputSystem_->destroyInputObject(this->keyboard_); 124 OIS::InputManager::destroyInputSystem(this->inputSystem_); 125 126 //TODO: If the InputHandler has been destroyed, how does it know? 131 if (!this->inputSystem_) 132 { 133 this->inputSystem_->destroyInputObject(this->mouse_); 134 this->inputSystem_->destroyInputObject(this->keyboard_); 135 OIS::InputManager::destroyInputSystem(this->inputSystem_); 136 } 137 138 this->uninitialized_ = true; 127 139 } 128 140 -
code/branches/network/src/orxonox/InputHandler.h
r928 r929 61 61 // don't mess with a Singleton 62 62 InputHandler (); 63 InputHandler (const InputHandler&) { } 64 ~InputHandler() { } 63 InputHandler (const InputHandler&); 64 InputHandler& operator=(const InputHandler& instance); 65 ~InputHandler(); 65 66 66 67 void callListeners(InputEvent &evt); … … 76 77 OIS::Keyboard *keyboard_; //!< OIS mouse 77 78 OIS::Mouse *mouse_; //!< OIS keyboard 79 80 /** 81 @bref Tells whether initialise has been called successfully 82 Also true if destroy() has been called. 83 */ 84 bool uninitialized_; 78 85 79 86 //! denotes the maximum number of different keys there are in OIS. -
code/branches/network/src/orxonox/Orxonox.cc
r928 r929 37 37 //#include <OgreException.h> 38 38 #include <OgreFrameListener.h> 39 #include <OgreRoot.h>40 39 #include <OgreOverlay.h> 41 40 #include <OgreOverlayManager.h> … … 86 85 this->auMan_ = 0; 87 86 this->inputHandler_ = 0; 88 this->root_ = 0;87 //this->root_ = 0; 89 88 // turn on frame smoothing by setting a value different from 0 90 89 this->frameSmoothingTime_ = 0.0f; … … 97 96 Orxonox::~Orxonox() 98 97 { 99 // nothing to delete as for now 100 inputHandler_->destroy(); 98 // keep in mind: the order of deletion is very important! 99 100 if (this->bulletMgr_) 101 delete this->bulletMgr_; 102 if (this->orxonoxHUD_) 103 delete this->orxonoxHUD_; 104 Loader::close(); 105 this->inputHandler_->destroy(); 106 if (this->auMan_) 107 delete this->auMan_; 108 if (this->timer_) 109 delete this->timer_; 110 if (this->ogre_) 111 delete this->ogre_; 112 113 if (client_g) 114 delete client_g; 115 if (server_g) 116 delete server_g; 117 } 118 119 /** 120 * error kills orxonox 121 */ 122 void Orxonox::abortImmediate(/* some error code */) 123 { 124 //TODO: destroy and destruct everything and print nice error msg 125 delete this; 126 } 127 128 /** 129 Asks the mainloop nicely to abort. 130 */ 131 void Orxonox::abortRequest() 132 { 133 bAbort_ = true; 134 } 135 136 /** 137 * @return singleton object 138 */ 139 Orxonox* Orxonox::getSingleton() 140 { 141 static Orxonox theOnlyInstance; 142 return &theOnlyInstance; 101 143 } 102 144 … … 118 160 ar.checkArgument("data", this->dataPath_, false); 119 161 ar.checkArgument("ip", serverIp_, false); 120 if(ar.errorHandling()) die();162 if(ar.errorHandling()) abortImmediate(); 121 163 if(mode == std::string("client")) 122 164 { … … 134 176 } 135 177 178 void Orxonox::serverInit(std::string path) 179 { 180 COUT(2) << "initialising server" << std::endl; 181 182 ogre_->setConfigPath(path); 183 ogre_->setup(); 184 //root_ = ogre_->getRoot(); 185 if(!ogre_->load(this->dataPath_)) abortImmediate(/* unable to load */); 186 187 server_g = new network::Server(); 188 } 189 190 void Orxonox::clientInit(std::string path) 191 { 192 COUT(2) << "initialising client" << std::endl;\ 193 194 ogre_->setConfigPath(path); 195 ogre_->setup(); 196 if(serverIp_.compare("")==0) 197 client_g = new network::Client(); 198 else 199 client_g = new network::Client(serverIp_, NETWORK_PORT); 200 if(!ogre_->load(this->dataPath_)) abortImmediate(/* unable to load */); 201 } 202 203 void Orxonox::standaloneInit(std::string path) 204 { 205 COUT(2) << "initialising standalone mode" << std::endl; 206 207 ogre_->setConfigPath(path); 208 ogre_->setup(); 209 //root_ = ogre_->getRoot(); 210 if(!ogre_->load(this->dataPath_)) abortImmediate(/* unable to load */); 211 } 136 212 137 213 /** … … 153 229 154 230 void Orxonox::clientStart(){ 155 ogre_-> startRender();231 ogre_->initialise(); 156 232 Factory::createClassHierarchy(); 157 233 … … 179 255 void Orxonox::serverStart(){ 180 256 //TODO: start modules 181 ogre_-> startRender();257 ogre_->initialise(); 182 258 //TODO: run engine 183 259 Factory::createClassHierarchy(); … … 192 268 void Orxonox::standaloneStart(){ 193 269 //TODO: start modules 194 ogre_-> startRender();270 ogre_->initialise(); 195 271 //TODO: run engine 196 272 Factory::createClassHierarchy(); … … 199 275 200 276 startRenderLoop(); 201 }202 203 /**204 * @return singleton object205 */206 Orxonox* Orxonox::getSingleton()207 {208 static Orxonox theOnlyInstance;209 return &theOnlyInstance;210 }211 212 /**213 * error kills orxonox214 */215 void Orxonox::die(/* some error code */)216 {217 //TODO: destroy and destruct everything and print nice error msg218 delete this;219 }220 221 /**222 Asks the mainloop nicely to abort.223 */224 void Orxonox::abortRequest()225 {226 bAbort_ = true;227 }228 229 230 void Orxonox::serverInit(std::string path)231 {232 COUT(2) << "initialising server" << std::endl;233 234 ogre_->setConfigPath(path);235 ogre_->setup();236 root_ = ogre_->getRoot();237 if(!ogre_->load(this->dataPath_)) die(/* unable to load */);238 239 server_g = new network::Server();240 }241 242 void Orxonox::clientInit(std::string path)243 {244 COUT(2) << "initialising client" << std::endl;\245 246 ogre_->setConfigPath(path);247 ogre_->setup();248 if(serverIp_.compare("")==0)249 client_g = new network::Client();250 else251 client_g = new network::Client(serverIp_, NETWORK_PORT);252 if(!ogre_->load(this->dataPath_)) die(/* unable to load */);253 }254 255 void Orxonox::standaloneInit(std::string path)256 {257 COUT(2) << "initialising standalone mode" << std::endl;258 259 ogre_->setConfigPath(path);260 ogre_->setup();261 root_ = ogre_->getRoot();262 if(!ogre_->load(this->dataPath_)) die(/* unable to load */);263 277 } 264 278 … … 285 299 auMan_->ambientAdd("a3"); 286 300 //auMan->ambientAdd("ambient1"); 287 auMan_->ambientStart();*/ 301 auMan_->ambientStart(); 302 */ 288 303 } 289 304 … … 316 331 { 317 332 // use the ogre timer class to measure time. 318 Ogre::Timer *timer = new Ogre::Timer(); 319 timer->reset(); 333 if (!timer_) 334 timer_ = new Ogre::Timer(); 335 timer_->reset(); 320 336 321 337 // Contains the times of recently fired events … … 331 347 332 348 // get current time 333 unsigned long now = timer ->getMilliseconds();349 unsigned long now = timer_->getMilliseconds(); 334 350 335 351 // create an event to pass to the frameStarted method in ogre … … 341 357 orxonoxHUD_->setTime((int)now, 0); 342 358 343 // don't forget to call _fireFrameStarted in ogre to make sure344 // everything goes smoothly345 if (!ogre_->getRoot()->_fireFrameStarted(evt))346 break;347 348 359 // Iterate through all Tickables and call their tick(dt) function 349 360 for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ) 350 361 (it++)->tick((float)evt.timeSinceLastFrame); 351 362 363 // don't forget to call _fireFrameStarted in ogre to make sure 364 // everything goes smoothly 365 ogre_->frameStarted(evt); 366 352 367 if (mode_ != SERVER) 353 { 354 // only render in non-server mode 355 ogre_->getRoot()->_updateAllRenderTargets(); 356 } 368 ogre_->renderOneFrame(); // only render in non-server mode 357 369 358 370 // get current time 359 now = timer ->getMilliseconds();371 now = timer_->getMilliseconds(); 360 372 361 373 // create an event to pass to the frameEnded method in ogre … … 364 376 365 377 // again, just to be sure ogre works fine 366 if (!ogre_->getRoot()->_fireFrameEnded(evt)) 367 break; 378 ogre_->frameEnded(evt); 368 379 } 369 380 } … … 406 417 } 407 418 419 /** 420 @brief Test method for the InputHandler. 421 But: Is actually responsible for catching an exit event.. 422 */ 408 423 void Orxonox::eventOccured(InputEvent &evt) 409 424 { -
code/branches/network/src/orxonox/Orxonox.h
r926 r929 36 36 void start(); 37 37 // not sure if this should be private 38 void die(/* some error code */);38 void abortImmediate(/* some error code */); 39 39 void abortRequest(); 40 inline Ogre::SceneManager* getSceneManager() { return ogre_->getSceneManager(); }; 41 inline GraphicsEngine* getOgrePointer() { return ogre_; }; 42 inline audio::AudioManager* getAudioManagerPointer() { return auMan_; }; 43 inline BulletManager* getBulletMgr() { return this->bulletMgr_; } 44 40 45 static Orxonox* getSingleton(); 41 inline Ogre::SceneManager* getSceneManager() { return ogre_->getSceneManager(); };42 inline GraphicsEngine* getOgrePointer() { return ogre_; };43 inline audio::AudioManager* getAudioManagerPointer() { return auMan_; };44 inline BulletManager* getBulletMgr() { return this->bulletMgr_; }45 46 46 private: 47 private: 48 // don't mess with singletons 47 49 Orxonox(); 48 virtual ~Orxonox(); 50 Orxonox(Orxonox& instance); 51 Orxonox& operator=(const Orxonox& instance); 52 ~Orxonox(); 53 49 54 // init functions 50 55 void serverInit(std::string path); 51 56 void clientInit(std::string path); 52 57 void standaloneInit(std::string path); 58 53 59 // run functions 54 60 void serverStart(); … … 56 62 void standaloneStart(); 57 63 58 void createScene( void);64 void createScene(); 59 65 void setupInputSystem(); 60 66 void startRenderLoop(); … … 68 74 audio::AudioManager* auMan_; //!< audio manager 69 75 BulletManager* bulletMgr_; //!< Keeps track of the thrown bullets 70 InputHandler* inputHandler_; 71 Ogre::Root* root_; 76 InputHandler* inputHandler_; //!< Handles input with key bindings 77 Ogre::Root* root_; //!< Holy grail of Ogre 78 Ogre::Timer* timer_; //!< Main loop timer 72 79 // TODO: make this a config-value by creating a config class for orxonox 73 80 float frameSmoothingTime_; -
code/branches/network/src/orxonox/objects/Camera.cc
r790 r929 6 6 #include <OgreSceneManager.h> 7 7 #include <OgreSceneNode.h> 8 #include <OgreRoot.h>9 8 #include <OgreRenderWindow.h> 10 9 #include <OgreViewport.h> … … 69 68 70 69 // FIXME: unused var 71 Ogre::Viewport* vp = orxonox::Orxonox::getSingleton()->getOgrePointer()->getR oot()->getAutoCreatedWindow()->addViewport(cam);70 Ogre::Viewport* vp = orxonox::Orxonox::getSingleton()->getOgrePointer()->getRenderWindow()->addViewport(cam); 72 71 73 72 -
code/branches/network/src/orxonox/objects/Fighter.cc
r919 r929 208 208 209 209 node->attachObject(cam); 210 Orxonox::getSingleton()->getOgrePointer()->getR oot()->getAutoCreatedWindow()->addViewport(cam);210 Orxonox::getSingleton()->getOgrePointer()->getRenderWindow()->addViewport(cam); 211 211 } 212 212 } -
code/branches/network/src/orxonox/objects/SpaceShip.cc
r927 r929 286 286 287 287 this->camNode_->attachObject(cam); 288 Orxonox::getSingleton()->getOgrePointer()->getR oot()->getAutoCreatedWindow()->addViewport(cam);288 Orxonox::getSingleton()->getOgrePointer()->getRenderWindow()->addViewport(cam); 289 289 } 290 290
Note: See TracChangeset
for help on using the changeset viewer.