Changeset 1263
- Timestamp:
- May 13, 2008, 3:45:19 PM (17 years ago)
- Location:
- code/branches/merge/src
- Files:
-
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/merge/src/core/BaseObject.cc
r1209 r1263 45 45 @brief Constructor: Registers the object in the BaseObject-list. 46 46 */ 47 BaseObject::BaseObject() 47 BaseObject::BaseObject() : 48 bActive_(true), 49 bVisible_(true), 50 level_(0), 51 namespace_(0) 48 52 { 49 53 RegisterRootObject(BaseObject); 50 51 this->bActive_ = true;52 this->bVisible_ = true;53 this->level_ = 0;54 this->namespace_ = 0;55 54 } 56 55 -
code/branches/merge/src/core/CoreIncludes.h
r1062 r1263 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/merge/src/core/Debug.h
r1219 r1263 273 273 #define CCOUT_EXEC(x) \ 274 274 orxonox::OutputHandler::getOutStream().setOutputLevel(x) \ 275 << "*** " <<this->getIdentifier()->getName() << ": "275 << this->getIdentifier()->getName() << ": " 276 276 277 277 #ifndef CCOUT -
code/branches/merge/src/core/Error.cc
r1062 r1263 37 37 namespace orxonox 38 38 { 39 Error::Error()40 {41 Error(0,"");42 }43 44 39 Error::Error(std::string errorMsg, int errorCode) 45 {46 Error(errorCode, errorMsg);47 }48 49 Error::Error(int errorCode, std::string errorMsg)50 40 { 51 41 COUT(1) << "############################ "<< std::endl -
code/branches/merge/src/core/Error.h
r1062 r1263 44 44 { 45 45 public: 46 Error(); 47 Error(std::string errorMsg, int errorCode = 0); 48 Error(int errorCode, std::string errorMsg = ""); 46 Error(std::string errorMsg = "", int errorCode = 0); 49 47 private: 50 48 -
code/branches/merge/src/core/Namespace.cc
r1062 r1263 37 37 CreateFactory(Namespace); 38 38 39 Namespace::Namespace() 39 Namespace::Namespace() : 40 bAutogeneratedFileRootNamespace_(false), 41 bRoot_(false), 42 operator_("or") 40 43 { 41 44 RegisterObject(Namespace); 42 43 this->bAutogeneratedFileRootNamespace_ = false;44 this->bRoot_ = false;45 this->operator_ = "or";46 45 } 47 46 -
code/branches/merge/src/core/OrxonoxClass.cc
r1056 r1263 37 37 { 38 38 /** @brief Constructor: Sets the default values. */ 39 OrxonoxClass::OrxonoxClass() 39 OrxonoxClass::OrxonoxClass() : 40 identifier_(0), 41 parents_(0) 40 42 { 41 43 this->setConfigValues(); 42 43 this->identifier_ = 0;44 this->parents_ = 0;45 44 } 46 45 -
code/branches/merge/src/orxonox/GraphicsEngine.cc
r1220 r1263 44 44 #include "core/ConfigValueIncludes.h" 45 45 #include "core/Debug.h" 46 #include "core/ TclBind.h"46 #include "core/CommandExecutor.h" 47 47 48 48 … … 53 53 @return The only instance of GraphicsEngine. 54 54 */ 55 GraphicsEngine& GraphicsEngine::getSingleton()55 /*static*/ GraphicsEngine& GraphicsEngine::getSingleton() 56 56 { 57 57 static GraphicsEngine theOnlyInstance; … … 62 62 @brief Only use constructor to initialise variables and pointers! 63 63 */ 64 GraphicsEngine::GraphicsEngine() 64 GraphicsEngine::GraphicsEngine() : 65 root_(0), 66 scene_(0), 67 renderWindow_(0), 68 //configPath_(""), 69 dataPath_(""), 70 ogreLogfile_("") 65 71 { 66 72 RegisterObject(GraphicsEngine); 67 //this->bOverwritePath_ = false; 73 68 74 this->setConfigValues(); 69 // set to standard values 70 this->configPath_ = ""; 71 this->root_ = 0; 72 this->scene_ = 0; 73 this->renderWindow_ = 0; 74 COUT(4) << "*** GraphicsEngine: Constructed" << std::endl; 75 CCOUT(4) << "Constructed" << std::endl; 76 } 77 78 void GraphicsEngine::setConfigValues() 79 { 80 SetConfigValue(dataPath_, "../../Media/").description("relative path to media data"); 81 SetConfigValue(ogreLogfile_, "ogre.log").description("Logfile for messages from Ogre. Use \"\" to suppress log file creation."); 82 SetConfigValue(ogreLogLevelTrivial_ , 5).description("Corresponding orxonox debug level for ogre Trivial"); 83 SetConfigValue(ogreLogLevelNormal_ , 4).description("Corresponding orxonox debug level for ogre Normal"); 84 SetConfigValue(ogreLogLevelCritical_, 2).description("Corresponding orxonox debug level for ogre Critical"); 75 85 } 76 86 … … 89 99 void GraphicsEngine::destroy() 90 100 { 91 COUT(4) << " *** GraphicsEngine:Destroying objects..." << std::endl;101 COUT(4) << "Destroying objects..." << std::endl; 92 102 Ogre::WindowEventUtilities::removeWindowEventListener(this->renderWindow_, this); 93 103 if (this->root_) … … 103 113 delete Ogre::LogManager::getSingletonPtr(); 104 114 } 105 COUT(4) << "*** GraphicsEngine: Destroying objects done" << std::endl; 106 } 107 108 void GraphicsEngine::setConfigValues() 109 { 110 SetConfigValue(dataPath_, "../../Media/").description("relative path to media data"); 111 SetConfigValue(ogreLogfile_, "ogre.log").description("Logfile for messages from Ogre. Use \"\" to suppress log file creation."); 112 SetConfigValue(ogreLogLevelTrivial_ , 5).description("Corresponding orxonox debug level for ogre Trivial"); 113 SetConfigValue(ogreLogLevelNormal_ , 4).description("Corresponding orxonox debug level for ogre Normal"); 114 SetConfigValue(ogreLogLevelCritical_, 2).description("Corresponding orxonox debug level for ogre Critical"); 115 116 TclBind::getInstance().setDataPath(this->dataPath_); 115 COUT(4) << "Destroying objects done" << std::endl; 117 116 } 118 117 … … 120 119 @brief Creates the Ogre Root object and sets up the ogre log. 121 120 */ 122 void GraphicsEngine::setup() 123 { 121 bool GraphicsEngine::setup(std::string& dataPath) 122 { 123 CCOUT(3) << "Setting up..." << std::endl; 124 // temporary overwrite of dataPath, change ini file for permanent change 125 if (dataPath != "") 126 dataPath_ = dataPath; 127 if (dataPath_ == "") 128 return false; 129 if (dataPath_[dataPath_.size() - 1] != '/') 130 dataPath_ += "/"; 131 124 132 //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 133 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC && defined(_DEBUG) 132 134 std::string plugin_filename = "plugins_d.cfg"; … … 137 139 // create a logManager 138 140 Ogre::LogManager *logger; 139 140 141 if (Ogre::LogManager::getSingletonPtr() == 0) 142 logger = new Ogre::LogManager(); 141 143 else 142 144 logger = Ogre::LogManager::getSingletonPtr(); 143 C OUT(4) << "*** GraphicsEngine:Ogre LogManager created/assigned" << std::endl;145 CCOUT(4) << "Ogre LogManager created/assigned" << std::endl; 144 146 145 147 // create our own log that we can listen to … … 155 157 156 158 // Root will detect that we've already created a Log 157 C OUT(4) << "*** GraphicsEngine:Creating Ogre Root..." << std::endl;159 CCOUT(4) << "Creating Ogre Root..." << std::endl; 158 160 root_ = new Ogre::Root(plugin_filename); 159 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; 161 CCOUT(4) << "Creating Ogre Root done" << std::endl; 162 163 // specify where Ogre has to look for resources. This call doesn't parse anything yet! 164 declareRessourceLocations(); 165 166 CCOUT(3) << "Set up done." << std::endl; 183 167 return true; 184 168 } 185 169 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) 196 { 170 void GraphicsEngine::declareRessourceLocations() 171 { 172 CCOUT(4) << "Declaring Resources" << std::endl; 197 173 //TODO: Specify layout of data file and maybe use xml-loader 198 174 //TODO: Work with ressource groups (should be generated by a special loader) 199 175 // Load resource paths from data file using configfile ressource type 200 176 Ogre::ConfigFile cf; 201 cf.load(dataPath + "resources.cfg");177 cf.load(dataPath_ + "resources.cfg"); 202 178 203 179 // Go through all sections & settings in the file … … 216 192 217 193 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( 218 std::string(dataPath + archName),194 std::string(dataPath_ + archName), 219 195 typeName, secName); 220 196 } 221 197 } 198 } 199 200 bool GraphicsEngine::loadRenderer() 201 { 202 CCOUT(4) << "Configuring Renderer" << std::endl; 203 if (!root_->restoreConfig() && !root_->showConfigDialog()) 204 return false; 205 206 CCOUT(4) << "Creating render window" << std::endl; 207 this->renderWindow_ = root_->initialise(true, "OrxonoxV2"); 208 if (!root_->isInitialised()) 209 { 210 CCOUT(2) << "Error: Creating Ogre root object failed" << std::endl; 211 return false; 212 } 213 Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, this); 214 Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5); 215 return true; 216 } 217 218 bool GraphicsEngine::initialiseResources() 219 { 220 CCOUT(4) << "Initialising resources" << std::endl; 221 //TODO: Do NOT load all the groups, why are we doing that? And do we really do that? initialise != load... 222 try 223 { 224 Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); 225 /*Ogre::StringVector str = Ogre::ResourceGroupManager::getSingleton().getResourceGroups(); 226 for (unsigned int i = 0; i < str.size(); i++) 227 { 228 Ogre::ResourceGroupManager::getSingleton().loadResourceGroup(str[i]); 229 }*/ 230 } 231 catch (Ogre::Exception e) 232 { 233 CCOUT(2) << "Error: There was an Error when initialising the resources." << std::endl; 234 CCOUT(2) << "ErrorMessage: " << e.getFullDescription() << std::endl; 235 return false; 236 } 237 return true; 238 } 239 240 /** 241 * @brief Creates the SceneManager 242 */ 243 bool GraphicsEngine::createNewScene() 244 { 245 CCOUT(4) << "Creating new SceneManager" << std::endl; 246 if (scene_) 247 { 248 CCOUT(2) << "SceneManager already exists! Skipping." << std::endl; 249 return false; 250 } 251 scene_ = root_->createSceneManager(Ogre::ST_GENERIC, "Default SceneManager"); 252 CCOUT(3) << "Created SceneManager: " << scene_ << std::endl; 253 return true; 222 254 } 223 255 … … 291 323 } 292 324 OutputHandler::getOutStream().setOutputLevel(orxonoxLevel) 293 << "*** Ogre: " << message << std::endl; 294 } 295 296 void GraphicsEngine::windowMoved(Ogre::RenderWindow *rw){ 297 int w = rw->getWidth(); 298 int h = rw->getHeight(); 299 InputManager::setWindowExtents(w, h); 300 } 301 302 void GraphicsEngine::windowResized(Ogre::RenderWindow *rw){ 303 int w = rw->getWidth(); 304 int h = rw->getHeight(); 305 InputManager::setWindowExtents(w, h); 306 } 307 308 void GraphicsEngine::windowFocusChanged(Ogre::RenderWindow *rw){ 309 int w = rw->getWidth(); 310 int h = rw->getHeight(); 311 InputManager::setWindowExtents(w, h); 312 } 325 << "Ogre: " << message << std::endl; 326 } 327 328 /** 329 * Window has resized. 330 * @param rw The render window it occured in 331 */ 332 void GraphicsEngine::windowMoved(Ogre::RenderWindow *rw) 333 { 334 // note: this doesn't change the window extents 335 } 336 337 /** 338 * Window has resized. 339 * @param rw The render window it occured in 340 * @note GraphicsEngine has a render window stored itself. This is the same 341 * as rw. But we have to be careful when using multiple render windows! 342 */ 343 void GraphicsEngine::windowResized(Ogre::RenderWindow *rw) 344 { 345 // change the mouse clipping size for absolute mouse movements 346 int w = rw->getWidth(); 347 int h = rw->getHeight(); 348 InputManager::setWindowExtents(w, h); 349 } 350 351 /** 352 * Window has resized. 353 * @param rw The render window it occured in 354 */ 355 void GraphicsEngine::windowFocusChanged(Ogre::RenderWindow *rw) 356 { 357 // note: this doesn't change the window extents 358 } 359 360 /** 361 * Window has resized. 362 * @param rw The render window it occured in 363 */ 364 void GraphicsEngine::windowClosed(Ogre::RenderWindow *rw) 365 { 366 // using CommandExecutor in order to avoid depending on Orxonox class. 367 CommandExecutor::execute("exit", false); 368 } 313 369 } -
code/branches/merge/src/orxonox/GraphicsEngine.h
r1214 r1263 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 bool 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 75 void windowMoved (Ogre::RenderWindow* rw); 76 void windowResized (Ogre::RenderWindow* rw); 77 void windowFocusChanged(Ogre::RenderWindow* rw); 78 void windowClosed (Ogre::RenderWindow* rw); 79 73 80 static GraphicsEngine& getSingleton(); 74 81 static GraphicsEngine* getSingletonPtr() { return &getSingleton(); } 75 76 void windowMoved(Ogre::RenderWindow* rw);77 void windowResized(Ogre::RenderWindow* rw);78 void windowFocusChanged(Ogre::RenderWindow* rw);79 82 80 83 private: … … 92 95 Ogre::RenderWindow* renderWindow_;//!< the current render window 93 96 //bool bOverwritePath_; //!< overwrites path 94 std::string configPath_; //!< path to config file97 //std::string configPath_; //!< path to config file 95 98 std::string dataPath_; //!< path to data file 96 99 std::string ogreLogfile_; //!< log file name for Ogre log messages -
code/branches/merge/src/orxonox/Main.cc
r1214 r1263 78 78 Orxonox* orx = Orxonox::getSingleton(); 79 79 80 bool res = false; 80 81 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_APPLE 81 orx->init(argc, argv, macBundlePath());82 res = orx->init(argc, argv, macBundlePath()); 82 83 #else 83 orx->init(argc, argv, "");84 res = orx->init(argc, argv, ""); 84 85 #endif 85 86 86 orx->start(); 87 if (res) 88 orx->start(); 87 89 orx->destroySingleton(); 88 90 /*} -
code/branches/merge/src/orxonox/Orxonox.cc
r1219 r1263 37 37 38 38 //****** STD ******* 39 //#include <iostream>40 //#include <exception>41 39 #include <deque> 42 40 43 41 //****** OGRE ****** 44 //#include <OgreException.h>45 42 #include <OgreFrameListener.h> 46 43 #include <OgreOverlay.h> … … 65 62 #include "core/InputBuffer.h" 66 63 #include "core/InputManager.h" 64 #include "core/TclBind.h" 67 65 68 66 // audio … … 158 156 159 157 /** 160 * create a new instance of Orxonox 161 */ 162 Orxonox::Orxonox() 163 { 164 this->mode_ = STANDALONE; 165 this->serverIp_ = ""; 166 this->ogre_ = &GraphicsEngine::getSingleton(); 167 this->timer_ = 0; 168 this->dataPath_ = ""; 169 this->auMan_ = 0; 170 this->orxonoxHUD_ = 0; 171 this->inputHandler_ = 0; 158 * Create a new instance of Orxonox. Avoid doing any actual work here. 159 */ 160 Orxonox::Orxonox() : 161 ogre_(&GraphicsEngine::getSingleton()), 162 //auMan_(0), 163 timer_(0), 172 164 // turn on frame smoothing by setting a value different from 0 173 this->frameSmoothingTime_ = 0.0f; 174 this->bAbort_ = false; 175 this->timefactor_ = 1.0f; 176 } 177 178 /** 179 * destruct Orxonox 165 frameSmoothingTime_(0.0f), 166 orxonoxConsole_(0), 167 orxonoxHUD_(0), 168 bAbort_(false), 169 timefactor_(1.0f), 170 mode_(STANDALONE), 171 serverIp_("") 172 { 173 } 174 175 /** 176 * Destruct Orxonox. 180 177 */ 181 178 Orxonox::~Orxonox() … … 186 183 Loader::close(); 187 184 InputManager::destroy(); 188 if (this->auMan_)189 delete this->auMan_;185 //if (this->auMan_) 186 // delete this->auMan_; 190 187 if (this->timer_) 191 188 delete this->timer_; … … 199 196 200 197 /** 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 }209 210 /**211 198 Asks the mainloop nicely to abort. 212 199 */ … … 218 205 219 206 /** 220 * @return singleton object207 * @return singleton reference 221 208 */ 222 209 Orxonox* Orxonox::getSingleton() … … 243 230 * @param path path to config (in home dir or something) 244 231 */ 245 voidOrxonox::init(int argc, char **argv, std::string path)232 bool Orxonox::init(int argc, char **argv, std::string path) 246 233 { 247 234 //TODO: find config file (assuming executable directory) … … 249 236 //TODO: give config file to Ogre 250 237 std::string mode; 238 std::string dataPath; 251 239 252 240 ArgReader ar(argc, argv); 253 241 ar.checkArgument("mode", mode, false); 254 ar.checkArgument("data", this->dataPath_, false);242 ar.checkArgument("data", dataPath, false); 255 243 ar.checkArgument("ip", serverIp_, false); 256 if(ar.errorHandling()) abortImmediateForce(); 257 if(mode == std::string("client")) 244 if(ar.errorHandling()) 245 return false; 246 247 COUT(3) << "*** Orxonox: Mode is " << mode << "." << std::endl; 248 if (mode == "client") 249 mode_ = CLIENT; 250 else if (mode == "server") 251 mode_ = SERVER; 252 else 253 mode_ = STANDALONE; 254 255 //if (mode_ == DEDICATED) 256 // TODO: decide what to do here 257 //else 258 259 // for playable server, client and standalone, the startup 260 // procedure until the GUI is identical 261 262 TclBind::getInstance().setDataPath(dataPath); 263 ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini"); 264 Factory::createClassHierarchy(); 265 266 if (!ogre_->setup(path)) // creates ogre root and other essentials 267 return false; 268 269 return true; 270 } 271 272 /** 273 * start modules 274 */ 275 bool Orxonox::start() 276 { 277 //if (mode == DEDICATED) 278 // do something else 279 //else 280 281 if (!ogre_->loadRenderer()) // creates the render window 282 return false; 283 284 // Calls the InputManager which sets up the input devices. 285 // The render window width and height are used to set up the mouse movement. 286 if (!InputManager::initialise(ogre_->getWindowHandle(), 287 ogre_->getWindowWidth(), ogre_->getWindowHeight())) 288 return false; 289 290 // TODO: Spread this so that this call only initialises things needed for the GUI 291 if (!ogre_->initialiseResources()) 292 return false; 293 294 // TOOD: load the GUI here 295 // set InputManager to GUI mode 296 InputManager::setInputState(InputManager::IS_GUI); 297 // TODO: run GUI here 298 299 // The following lines depend very much on the GUI output, so they're probably misplaced here.. 300 301 InputManager::setInputState(InputManager::IS_NONE); 302 303 if (!loadPlayground()) 304 return false; 305 306 switch (mode_) 258 307 { 259 mode_ = CLIENT; 260 clientInit(path); 261 } 262 else if(mode== std::string("server")){ 263 mode_ = SERVER; 264 serverInit(path); 265 } 266 else{ 267 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 */); 304 } 305 306 /** 307 * start modules 308 */ 309 void Orxonox::start() 310 { 311 switch(mode_){ 308 case SERVER: 309 if (!serverLoad()) 310 return false; 311 break; 312 312 case CLIENT: 313 clientStart(); 314 break; 315 case SERVER: 316 serverStart(); 313 if (!clientLoad()) 314 return false; 317 315 break; 318 316 default: 319 standaloneStart(); 317 if (!standaloneLoad()) 318 return false; 320 319 } 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 320 321 InputManager::setInputState(InputManager::IS_NORMAL); 322 323 return startRenderLoop(); 324 } 325 326 /** 327 * Loads everything in the scene except for the actual objects. 328 * This includes HUD, Console.. 329 */ 330 bool Orxonox::loadPlayground() 331 { 332 ogre_->createNewScene(); 333 334 // Init audio 335 //auMan_ = new audio::AudioManager(); 336 //auMan_->ambientAdd("a1"); 337 //auMan_->ambientAdd("a2"); 338 //auMan_->ambientAdd("a3"); 339 //auMan->ambientAdd("ambient1"); 340 //auMan_->ambientStart(); 341 342 // Load the HUD 343 COUT(3) << "*** Orxonox: Loading HUD..." << std::endl; 331 344 Ogre::Overlay* hudOverlay = Ogre::OverlayManager::getSingleton().getByName("Orxonox/HUD1.2"); 332 345 orxonoxHUD_ = new HUD(); … … 335 348 hudOverlay->show(); 336 349 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 modules 348 ogre_->initialise(); 349 //TODO: run engine 350 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 modules 362 ogre_->initialise(); 363 //TODO: run engine 364 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 audio 375 auMan_ = new audio::AudioManager(); 376 377 // load this file from config 378 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 test 413 our code without the help of the root object. 414 There's even a chance that we can dispose of the root object entirely 415 in server mode. 416 About the loop: The design is almost exactly like the one in ogre, so that 417 if any part of ogre registers a framelisteners, it will still behave 418 correctly. Furthermore the time smoothing feature from ogre has been 419 implemented too. If turned on (see orxonox constructor), it will calculate 420 the dt_n by means of the recent most dt_n-1, dt_n-2, etc. 421 */ 422 void Orxonox::startRenderLoop() 423 { 350 COUT(3) << "*** Orxonox: Loading Console..." << std::endl; 424 351 InputBuffer* ib = dynamic_cast<InputBuffer*>(InputManager::getKeyHandler("buffer")); 425 352 /* … … 432 359 ib->registerListener(console, &Testconsole::exit, (char)0x1B, true); 433 360 */ 434 435 361 orxonoxConsole_ = new InGameConsole(ib); 436 362 ib->registerListener(orxonoxConsole_, &InGameConsole::listen, true); … … 441 367 ib->registerListener(orxonoxConsole_, &InGameConsole::exit, (char)0x1B, true); 442 368 369 return true; 370 } 371 372 /** 373 * Level loading method for server mode. 374 */ 375 bool Orxonox::serverLoad() 376 { 377 COUT(2) << "Loading level in server mode" << std::endl; 378 379 server_g = new network::Server(); 380 381 if (!loadScene()) 382 return false; 383 384 server_g->open(); 385 386 return true; 387 } 388 389 /** 390 * Level loading method for client mode. 391 */ 392 bool Orxonox::clientLoad() 393 { 394 COUT(2) << "Loading level in client mode" << std::endl;\ 395 396 if (serverIp_.compare("") == 0) 397 client_g = new network::Client(); 398 else 399 client_g = new network::Client(serverIp_, NETWORK_PORT); 400 401 client_g->establishConnection(); 402 client_g->tick(0); 403 404 return true; 405 } 406 407 /** 408 * Level loading method for standalone mode. 409 */ 410 bool Orxonox::standaloneLoad() 411 { 412 COUT(2) << "Loading level in standalone mode" << std::endl; 413 414 if (!loadScene()) 415 return false; 416 417 return true; 418 } 419 420 /** 421 * Helper method to load a level. 422 */ 423 bool Orxonox::loadScene() 424 { 425 Level* startlevel = new Level("levels/sample.oxw"); 426 Loader::open(startlevel); 427 428 return true; 429 } 430 431 432 /** 433 Main loop of the orxonox game. 434 About the loop: The design is almost exactly like the one in ogre, so that 435 if any part of ogre registers a framelisteners, it will still behave 436 correctly. Furthermore the time smoothing feature from ogre has been 437 implemented too. If turned on (see orxonox constructor), it will calculate 438 the dt_n by means of the recent most dt_n-1, dt_n-2, etc. 439 */ 440 bool Orxonox::startRenderLoop() 441 { 443 442 // first check whether ogre root object has been created 444 443 if (Ogre::Root::getSingletonPtr() == 0) 445 444 { 446 445 COUT(2) << "*** Orxonox Error: Could not start rendering. No Ogre root object found" << std::endl; 447 return ;446 return false; 448 447 } 449 448 Ogre::Root& ogreRoot = Ogre::Root::getSingleton(); … … 465 464 timer_->reset(); 466 465 466 COUT(3) << "*** Orxonox: Starting the main loop." << std::endl; 467 467 while (!bAbort_) 468 468 { … … 510 510 ogreRoot._fireFrameEnded(evt); 511 511 } 512 513 return true; 512 514 } 513 515 … … 550 552 } 551 553 554 /** 555 * Static function that shows the console in game mode. 556 */ 552 557 void Orxonox::activateConsole() 553 558 { 559 // currently, the console shows itself when feeded with input. 554 560 InputManager::setInputState(InputManager::IS_CONSOLE); 555 561 } -
code/branches/merge/src/orxonox/Orxonox.h
r1219 r1263 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 100 InputManager* inputHandler_; //!< Handles input with key bindings 95 //audio::AudioManager* auMan_; //!< audio manager 101 96 Ogre::Timer* timer_; //!< Main loop timer 102 97 // TODO: make this a config-value by creating a config class for orxonox -
code/branches/merge/src/orxonox/OrxonoxPlatform.h
r1064 r1263 21 21 * 22 22 * Author: 23 * An unknown man from the Ogre development crew23 * ... 24 24 * Co-authors: 25 25 * Reto Grieder -
code/branches/merge/src/orxonox/console/InGameConsole.cc
r1223 r1263 54 54 const float BLINK = 0.25; 55 55 56 InGameConsole::InGameConsole(InputBuffer* ib){ 56 InGameConsole::InGameConsole(InputBuffer* ib) : 57 windowW(0), windowH(0), 58 scroll(0), scrollTimer(0.0f), 59 cursor(0.0f), 60 active(false), 61 ib_(ib), 62 om(0), 63 consoleOverlay(0), 64 consoleOverlayContainer(0), 65 consoleOverlayNoise(0), 66 consoleOverlayBorder(0), 67 consoleOverlayTextAreas(0) 68 { 57 69 //RegisterObject(InGameConsole); 58 ib_ = ib;59 active = false;60 cursor = 0.0;61 70 init(); 62 71 } -
code/branches/merge/src/orxonox/objects/Explosion.cc
r1056 r1263 45 45 CreateFactory(Explosion); 46 46 47 Explosion::Explosion(WorldEntity* owner) 47 Explosion::Explosion(WorldEntity* owner) : 48 particle_(0), 49 lifetime_(0.4) 48 50 { 49 51 RegisterObject(Explosion); 50 51 this->particle_ = 0;52 this->lifetime_ = 0.4;53 52 54 53 if (owner) -
code/branches/merge/src/orxonox/objects/Model.cc
r1209 r1263 49 49 } 50 50 51 void Model::loadParams(TiXmlElement* xmlElem)52 {53 WorldEntity::loadParams(xmlElem);54 55 if (xmlElem->Attribute("mesh"))56 {57 meshSrc_ = xmlElem->Attribute("mesh");58 }59 create();60 }61 62 51 /** 63 52 @brief XML loading and saving. -
code/branches/merge/src/orxonox/objects/Model.h
r1056 r1263 43 43 Model(); 44 44 virtual ~Model(); 45 virtual void loadParams(TiXmlElement* xmlElem);46 45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 46 void setMesh(const std::string& meshname); -
code/branches/merge/src/orxonox/objects/NPC.cc
r1056 r1263 36 36 CreateFactory(NPC); 37 37 38 NPC::NPC() 38 NPC::NPC() : 39 movable_(true) 39 40 { 40 41 RegisterObject(NPC); 41 movable_ = true;42 42 } 43 43 -
code/branches/merge/src/orxonox/objects/Projectile.cc
r1056 r1263 42 42 CreateFactory(Projectile); 43 43 44 Projectile::Projectile(SpaceShip* owner) 44 Projectile::Projectile(SpaceShip* owner) : 45 owner_(owner) 45 46 { 46 47 RegisterObject(Projectile); 47 48 48 49 this->setConfigValues(); 49 50 this->owner_ = owner;51 50 52 51 this->billboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 1.0, 0.5), 1); -
code/branches/merge/src/orxonox/objects/SpaceShip.cc
r1219 r1263 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/merge/src/orxonox/objects/WorldEntity.cc
r1209 r1263 45 45 unsigned int WorldEntity::worldEntityCounter_s = 0; 46 46 47 WorldEntity::WorldEntity() 47 WorldEntity::WorldEntity() : 48 velocity_ (0, 0, 0), 49 acceleration_(0, 0, 0), 50 rotationAxis_(0, 1, 0), 51 rotationRate_(0), 52 momentum_ (0), 53 node_ (0), 54 bStatic_ (true) 48 55 { 49 56 RegisterObject(WorldEntity); 50 51 //create();52 53 this->bStatic_ = true;54 this->velocity_ = Vector3(0, 0, 0);55 this->acceleration_ = Vector3(0, 0, 0);56 this->rotationAxis_ = Vector3(0, 1, 0);57 this->rotationRate_ = 0;58 this->momentum_ = 0;59 57 60 58 if (GraphicsEngine::getSingleton().getSceneManager()) … … 66 64 67 65 registerAllVariables(); 68 }69 else70 {71 this->node_ = 0;72 66 } 73 67 } … … 94 88 BaseObject::loadParams(xmlElem); 95 89 create(); 96 /*97 if (xmlElem->Attribute("position"))98 {99 std::vector<std::string> pos = tokenize(xmlElem->Attribute("position"),",");100 float x, y, z;101 String2Number<float>(x, pos[0]);102 String2Number<float>(y, pos[1]);103 String2Number<float>(z, pos[2]);104 this->setPosition(x, y, z);105 }106 107 if (xmlElem->Attribute("direction"))108 {109 std::vector<std::string> pos = tokenize(xmlElem->Attribute("direction"),",");110 float x, y, z;111 String2Number<float>(x, pos[0]);112 String2Number<float>(y, pos[1]);113 String2Number<float>(z, pos[2]);114 this->setDirection(x, y, z);115 }116 117 if (xmlElem->Attribute("yaw") || xmlElem->Attribute("pitch") || xmlElem->Attribute("roll"))118 {119 float yaw = 0.0, pitch = 0.0, roll = 0.0;120 if (xmlElem->Attribute("yaw"))121 String2Number<float>(yaw,xmlElem->Attribute("yaw"));122 123 if (xmlElem->Attribute("pitch"))124 String2Number<float>(pitch,xmlElem->Attribute("pitch"));125 126 if (xmlElem->Attribute("roll"))127 String2Number<float>(roll,xmlElem->Attribute("roll"));128 129 this->yaw(Degree(yaw));130 this->pitch(Degree(pitch));131 this->roll(Degree(roll));132 }133 134 if (xmlElem->Attribute("scale"))135 {136 std::string scaleStr = xmlElem->Attribute("scale");137 float scale;138 String2Number<float>(scale, scaleStr);139 this->setScale(scale);140 }141 142 if (xmlElem->Attribute("rotationAxis"))143 {144 std::vector<std::string> pos = tokenize(xmlElem->Attribute("rotationAxis"),",");145 float x, y, z;146 String2Number<float>(x, pos[0]);147 String2Number<float>(y, pos[1]);148 String2Number<float>(z, pos[2]);149 this->setRotationAxis(x, y, z);150 }151 152 if (xmlElem->Attribute("rotationRate"))153 {154 float rotationRate;155 String2Number<float>(rotationRate, xmlElem->Attribute("rotationRate"));156 this->setRotationRate(Degree(rotationRate));157 if (rotationRate != 0)158 this->setStatic(false);159 }160 161 create();162 */163 90 } 164 91 -
code/branches/merge/src/orxonox/tools/Timer.cc
r1063 r1263 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.