Changeset 1021 for code/trunk/src/orxonox
- Timestamp:
- Apr 10, 2008, 5:03:34 PM (17 years ago)
- Location:
- code/trunk/src/orxonox
- Files:
-
- 2 deleted
- 32 edited
- 11 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/CMakeLists.txt
r871 r1021 1 1 SET( ORXONOX_SRC_FILES 2 2 GraphicsEngine.cc 3 InputEventListener.cc 4 InputHandler.cc 3 5 Main.cc 4 6 Orxonox.cc 5 objects/Tickable.cc 6 SpaceshipSteering.cc 7 # SpaceshipSteering.cc 7 8 hud/HUD.cc 8 9 particle/ParticleInterface.cc -
code/trunk/src/orxonox/GraphicsEngine.cc
r790 r1021 33 33 34 34 #include <OgreRoot.h> 35 #include <OgreException.h> 35 36 #include <OgreConfigFile.h> 36 37 #include <OgreTextureManager.h> 38 #include <OgreRenderWindow.h> 37 39 40 #include "core/CoreIncludes.h" 38 41 #include "core/Debug.h" 39 42 #include "GraphicsEngine.h" … … 46 49 GraphicsEngine::GraphicsEngine() 47 50 { 51 RegisterObject(GraphicsEngine); 52 //this->bOverwritePath_ = false; 53 this->setConfigValues(); 48 54 // set to standard values 49 55 this->configPath_ = ""; 50 this->dataPath_ = ""; 51 scene_ = NULL; 56 this->root_ = 0; 57 this->scene_ = 0; 58 this->renderWindow_ = 0; 52 59 } 53 60 … … 55 62 GraphicsEngine::~GraphicsEngine() 56 63 { 64 if (!this->root_) 65 delete this->root_; 66 } 67 68 void GraphicsEngine::setConfigValues() 69 { 70 SetConfigValue(dataPath_, dataPath_).description("relative path to media data"); 71 57 72 } 58 73 … … 66 81 root_ = new Root(NULL, configPath_ + "ogre.cfg", configPath_ + "Ogre.log"); 67 82 #endif*/ 68 #if defined(_DEBUG) && defined(WIN32)83 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC && defined(_DEBUG) 69 84 std::string plugin_filename = "plugins_d.cfg"; 70 85 #else … … 87 102 } 88 103 89 bool GraphicsEngine::load( )104 bool GraphicsEngine::load(std::string dataPath) 90 105 { 106 // temporary overwrite of dataPath, change ini file for permanent change 107 if( dataPath != "" ) 108 dataPath_ = dataPath; 91 109 loadRessourceLocations(this->dataPath_); 92 110 if (!root_->restoreConfig() && !root_->showConfigDialog()) … … 95 113 } 96 114 97 void GraphicsEngine:: startRender()115 void GraphicsEngine::initialise() 98 116 { 99 root_->initialise(true, "OrxonoxV2");117 this->renderWindow_ = root_->initialise(true, "OrxonoxV2"); 100 118 TextureManager::getSingleton().setDefaultNumMipmaps(5); 119 //TODO: Do NOT load all the groups, why are we doing that? And do we really do that? initialise != load... 101 120 ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); 102 121 } … … 131 150 } 132 151 152 /** 153 Returns the window handle of the render window. 154 At least the InputHandler uses this to create the OIS::InputManager 155 @return The window handle of the render window 156 */ 157 size_t GraphicsEngine::getWindowHandle() 158 { 159 if (this->renderWindow_) 160 { 161 Ogre::RenderWindow *renderWindow = this->root_->getAutoCreatedWindow(); 162 size_t windowHnd = 0; 163 renderWindow->getCustomAttribute("WINDOW", &windowHnd); 164 return windowHnd; 165 } 166 else 167 return 0; 168 } 169 170 /** 171 Get the width of the current render window 172 @return The width of the current render window 173 */ 174 int GraphicsEngine::getWindowWidth() const 175 { 176 if (this->renderWindow_) 177 { 178 return this->renderWindow_->getWidth(); 179 } 180 else 181 return 0; 182 } 183 184 /** 185 Get the height of the current render window 186 @return The height of the current render window 187 */ 188 int GraphicsEngine::getWindowHeight() const 189 { 190 if (this->renderWindow_) 191 { 192 return this->renderWindow_->getHeight(); 193 } 194 else 195 return 0; 196 } 133 197 134 198 } -
code/trunk/src/orxonox/GraphicsEngine.h
r790 r1021 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" 17 #include "core/OrxonoxClass.h" 16 18 17 19 … … 21 23 * graphics engine manager class 22 24 */ 23 class _OrxonoxExport GraphicsEngine { 25 class _OrxonoxExport GraphicsEngine : public OrxonoxClass 26 { 24 27 public: 25 28 GraphicsEngine(); 26 29 inline void setConfigPath(std::string path) { this->configPath_ = path; }; 27 30 // find a better way for this 28 inline Ogre::Root* getRoot() { return root_; }; 31 //inline Ogre::Root* getRoot() { return root_; }; 32 void setConfigValues(); 29 33 void setup(); 30 bool load( );34 bool load(std::string path); 31 35 void loadRessourceLocations(std::string path); 32 36 Ogre::SceneManager* getSceneManager(); 33 void startRender(); 37 void initialise(); 38 39 // several window properties 40 Ogre::RenderWindow* getRenderWindow() { return this->renderWindow_; } 41 size_t getWindowHandle(); 42 int getWindowWidth() const; 43 int getWindowHeight() const; 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(); } 34 52 35 53 virtual ~GraphicsEngine(); 54 36 55 private: 37 56 Ogre::Root* root_; //!< Ogre's root … … 39 58 std::string dataPath_; //!< path to data file 40 59 Ogre::SceneManager* scene_; //!< scene manager of the game 60 Ogre::RenderWindow* renderWindow_;//!< the current render window 61 //bool bOverwritePath_; //!< overwrites path 41 62 42 63 }; -
code/trunk/src/orxonox/Main.cc
r790 r1021 27 27 28 28 /** 29 @file Main.cc30 @brief main file handling most of the machine specific code29 @file 30 @brief Entry point of the program. Platform specific code. 31 31 */ 32 32 33 33 #include "OrxonoxStableHeaders.h" 34 34 35 #include <OgrePlatform.h> 36 #include <OgreException.h> 35 #include <exception> 37 36 38 37 #include "OrxonoxPlatform.h" 39 38 #include "core/SignalHandler.h" 40 39 #include "Orxonox.h" 41 40 42 41 using namespace orxonox; 43 #if O GRE_PLATFORM == OGRE_PLATFORM_APPLE42 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_APPLE 44 43 #include <CoreFoundation/CoreFoundation.h> 45 44 … … 72 71 #endif 73 72 74 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 && !defined( __MINGW32__ ) 75 #ifndef WIN32_LEAN_AND_MEAN 76 #define WIN32_LEAN_AND_MEAN 77 #endif 78 #include "windows.h" 79 INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT) 80 { 81 // something like this would be less hacky 82 // maybe one can work with trailing '\0' 83 // or maybe use string based functions 84 // I was unable to test it without working windows version 85 char* cmd = strCmdLine; 86 int argc = 2; 87 int i; 88 int j; 89 for(i = 0; cmd[i] != NULL; i++) 90 { 91 if(cmd[i] == ' ') argc++; 92 } 93 char **argv = new char*[argc]; 94 for (j = 0; j < argc; j++) 95 { 96 argv[j] = new char[i]; 97 } 98 j = 1; 99 int k = 0; 100 for(int i = 0; cmd[i] != NULL; i++) 101 { 102 if(cmd[i] != ' ') { 103 argv[j][k] = cmd[i]; 104 k++; 105 } 106 else { 107 argv[j][k] = '\0'; 108 k = 0; 109 j++; 110 } 111 } 112 argv[j][k] = '\0'; 113 argv[0] = "BeniXonox.exe"; 114 //char *argv[2]; 115 //argv[0] = "asdfProgram"; 116 //argv[1] = strCmdLine; 117 //int argc = 2; 73 int main(int argc, char **argv) 74 { 75 try { 76 SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log"); 77 Orxonox* orx = Orxonox::getSingleton(); 78 79 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_APPLE 80 orx->init(argc, argv, macBundlePath()); 118 81 #else 119 int main(int argc, char **argv) 120 { 121 #endif 122 try { 123 srand(time(0)); //initaialize RNG; TODO check if it works on win 124 SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log"); 125 Orxonox* orx = Orxonox::getSingleton(); 126 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE 127 orx->init(argc, argv, macBundlePath()); 128 orx->start(); 129 #else 130 /* 131 for (int i = 0; i < 500; i++) 132 { 133 int x = rand() % 40000 - 20000; 134 int y = rand() % 40000 - 20000; 135 int z = rand() % 40000 - 20000; 136 137 int scale = rand() % 100 + 20; 138 139 int version = rand() % 6 + 1; 140 141 float rotx = float(rand()) / RAND_MAX; 142 float roty = float(rand()) / RAND_MAX; 143 float rotz = float(rand()) / RAND_MAX; 144 145 int axis = rand() % 3 + 1; 146 147 if (axis == 1) 148 rotx = 0; 149 if (axis == 2) 150 roty = 0; 151 if (axis == 3) 152 rotz = 0; 153 154 int rotation = rand() % 40 + 10; 155 156 // <Model position="1000,1500,0" scale="50" mesh="ast1.mesh" rotationAxis="0,1.25,0" rotationRate="70" /> 157 std::cout << " <Model position=\"" << x << "," << y << "," << z << "\" scale=\"" << scale << "\" mesh=\"ast" << version << ".mesh\" rotationAxis=\"" << rotx << "," << roty << "," << rotz << "\" rotationRate=\"" << rotation << "\" />" << std::endl; 158 159 160 } 161 */ 162 orx->init(argc, argv, ""); 163 orx->start(); 164 #endif 165 } 166 catch (Ogre::Exception& e) { 167 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 && !defined( __MINGW32__ ) 168 MessageBoxA(NULL, e.getFullDescription().c_str(), 169 "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL); 170 #else 171 std::cerr << "Exception:\n"; 172 std::cerr << e.getFullDescription().c_str() << "\n"; 173 #endif 174 return 1; 175 } 176 return 0; 177 } 178 179 #ifdef __cplusplus 180 } 82 orx->init(argc, argv, ""); 181 83 #endif 182 84 183 184 /*int main(int argc, char **argv) 185 { 186 try85 orx->start(); 86 orx->destroy(); 87 } 88 catch (std::exception &ex) 187 89 { 188 SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log"); 189 Orxonox* orx = Orxonox::getSingleton(); 190 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE 191 orx->init(argc, argv, macBundlePath()); 192 orx->start(); 193 #else 194 orx->init(argc, argv, ""); 195 orx->start(); 196 #endif 197 198 } 199 catch(Ogre::Exception& e) 200 { 201 fprintf(stderr, "An exception has occurred: %s\n", 202 e.getFullDescription().c_str()); 90 std::cerr << "Exception:\n"; 91 std::cerr << ex.what() << "\n"; 203 92 return 1; 204 93 } … … 207 96 } 208 97 209 */ 98 #ifdef __cplusplus 99 } 100 #endif -
code/trunk/src/orxonox/Orxonox.cc
r871 r1021 35 35 36 36 //****** OGRE ****** 37 #include <OgreException.h> 38 #include <OgreRoot.h> 37 //#include <OgreException.h> 39 38 #include <OgreFrameListener.h> 40 #include <OgreRenderWindow.h>41 #include <OgreTextureManager.h>42 #include <OgreResourceGroupManager.h>43 #include <OgreConfigFile.h>44 39 #include <OgreOverlay.h> 45 40 #include <OgreOverlayManager.h> 46 47 //****** OIS ******* 48 #include <OIS/OIS.h> 41 #include <OgreTimer.h> 42 #include <OgreWindowEventUtilities.h> 49 43 50 44 //****** STD ******* 51 #include <iostream> 52 #include <exception> 45 //#include <iostream> 46 //#include <exception> 47 #include <deque> 53 48 54 49 //***** ORXONOX **** 55 50 //misc 56 #include "util/Sleep.h" 57 58 // loader and audio 59 //#include "loader/LevelLoader.h" 51 //#include "util/Sleep.h" 52 53 // audio 60 54 #include "audio/AudioManager.h" 61 55 … … 63 57 #include "network/Server.h" 64 58 #include "network/Client.h" 65 #include "network/NetworkFrameListener.h" 59 network::Client *client_g; 60 network::Server *server_g; 66 61 67 62 // objects 68 #include "objects/Tickable.h" 63 #include "core/ArgReader.h" 64 #include "core/Debug.h" 65 #include "core/Factory.h" 66 #include "core/Loader.h" 67 #include "core/Tickable.h" 68 #include "hud/HUD.h" 69 69 #include "tools/Timer.h" 70 #include "objects/NPC.h"71 #include "core/ArgReader.h"72 #include "core/Factory.h"73 #include "core/Debug.h"74 #include "core/Loader.h"75 #include "hud/HUD.h"76 70 #include "objects/weapon/BulletManager.h" 77 #include "GraphicsEngine.h" 71 72 #include "InputHandler.h" 78 73 79 74 #include "Orxonox.h" … … 81 76 namespace orxonox 82 77 { 83 // put this in a seperate Class or solve the problem in another fashion 84 class OrxListener : public Ogre::FrameListener 85 { 86 public: 87 OrxListener(OIS::Keyboard *keyboard, audio::AudioManager* auMan, gameMode mode) 88 { 89 mKeyboard = keyboard; 90 mode_=mode; 91 auMan_ = auMan; 92 } 93 94 bool frameStarted(const Ogre::FrameEvent& evt) 95 { 96 auMan_->update(); 97 updateAI(); 98 99 if(mode_ == PRESENTATION) 100 server_g->tick(evt.timeSinceLastFrame); 101 else if(mode_ == CLIENT) 102 client_g->tick(evt.timeSinceLastFrame); 103 104 usleep(10); 105 106 mKeyboard->capture(); 107 return !mKeyboard->isKeyDown(OIS::KC_ESCAPE); 108 } 109 110 void updateAI() 111 { 112 for(Iterator<NPC> it = ObjectList<NPC>::start(); it; ++it) 113 { 114 it->update(); 115 } 116 } 117 118 private: 119 gameMode mode_; 120 OIS::Keyboard *mKeyboard; 121 audio::AudioManager* auMan_; 122 }; 123 124 // init static singleton reference of Orxonox 125 Orxonox* Orxonox::singletonRef_ = NULL; 78 /** 79 @brief Reference to the only instance of the class. 80 */ 81 Orxonox *Orxonox::singletonRef_s = 0; 126 82 127 83 /** … … 131 87 { 132 88 this->ogre_ = new GraphicsEngine(); 89 this->timer_ = 0; 133 90 this->dataPath_ = ""; 134 // this->loader_ = 0;135 91 this->auMan_ = 0; 136 this->singletonRef_ = 0; 137 this->keyboard_ = 0; 138 this->mouse_ = 0; 139 this->inputManager_ = 0; 140 this->frameListener_ = 0; 141 this->root_ = 0; 92 this->inputHandler_ = 0; 93 //this->root_ = 0; 94 // turn on frame smoothing by setting a value different from 0 95 this->frameSmoothingTime_ = 0.0f; 96 this->bAbort_ = false; 142 97 } 143 98 … … 147 102 Orxonox::~Orxonox() 148 103 { 149 // nothing to delete as for now 104 // keep in mind: the order of deletion is very important! 105 if (this->bulletMgr_) 106 delete this->bulletMgr_; 107 if (this->orxonoxHUD_) 108 delete this->orxonoxHUD_; 109 Loader::close(); 110 InputHandler::destroy(); 111 if (this->auMan_) 112 delete this->auMan_; 113 if (this->timer_) 114 delete this->timer_; 115 if (this->ogre_) 116 delete this->ogre_; 117 118 if (client_g) 119 delete client_g; 120 if (server_g) 121 delete server_g; 122 } 123 124 /** 125 * error kills orxonox 126 */ 127 void Orxonox::abortImmediate(/* some error code */) 128 { 129 //TODO: destroy and destruct everything and print nice error msg 130 delete this; 131 } 132 133 /** 134 Asks the mainloop nicely to abort. 135 */ 136 void Orxonox::abortRequest() 137 { 138 bAbort_ = true; 139 } 140 141 /** 142 * @return singleton object 143 */ 144 Orxonox* Orxonox::getSingleton() 145 { 146 if (!singletonRef_s) 147 singletonRef_s = new Orxonox(); 148 return singletonRef_s; 149 //static Orxonox theOnlyInstance; 150 //return &theOnlyInstance; 151 } 152 153 /** 154 @brief Destroys the Orxonox singleton. 155 */ 156 void Orxonox::destroy() 157 { 158 if (singletonRef_s) 159 delete singletonRef_s; 160 singletonRef_s = 0; 150 161 } 151 162 … … 153 164 * initialization of Orxonox object 154 165 * @param argc argument counter 155 * @param argv list of argumen ts166 * @param argv list of argumenst 156 167 * @param path path to config (in home dir or something) 157 168 */ … … 162 173 //TODO: give config file to Ogre 163 174 std::string mode; 164 // if(argc>=2) 165 // mode = std::string(argv[1]); 166 // else 167 // mode = ""; 175 168 176 ArgReader ar = ArgReader(argc, argv); 169 177 ar.checkArgument("mode", mode, false); 170 178 ar.checkArgument("data", this->dataPath_, false); 171 179 ar.checkArgument("ip", serverIp_, false); 172 //mode = "presentation"; 173 if(ar.errorHandling()) die(); 174 if(mode == std::string("server")) 180 if(ar.errorHandling()) abortImmediate(); 181 if(mode == std::string("client")) 175 182 { 183 mode_ = CLIENT; 184 clientInit(path); 185 } 186 else if(mode== std::string("server")){ 187 mode_ = SERVER; 176 188 serverInit(path); 177 mode_ = SERVER;178 }179 else if(mode == std::string("client"))180 {181 clientInit(path);182 mode_ = CLIENT;183 }184 else if(mode == std::string("presentation"))185 {186 serverInit(path);187 mode_ = PRESENTATION;188 189 } 189 190 else{ 191 mode_ = STANDALONE; 190 192 standaloneInit(path); 191 mode_ = STANDALONE;192 193 } 193 194 } 194 195 195 /** 196 * start modules 197 */ 198 void Orxonox::start() 199 { 200 //TODO: start modules 201 ogre_->startRender(); 202 //TODO: run engine 203 Factory::createClassHierarchy(); 204 createScene(); 205 setupScene(); 206 setupInputSystem(); 207 if(mode_!=CLIENT){ // remove this in future ---- presentation hack 208 } 209 else 210 std::cout << "client here" << std::endl; 211 createFrameListener(); 212 switch(mode_){ 213 case PRESENTATION: 214 //ogre_->getRoot()->addFrameListener(new network::ServerFrameListener()); 215 //std::cout << "could not add framelistener" << std::endl; 216 server_g->open(); 217 break; 218 case CLIENT: 219 client_g->establishConnection(); 220 break; 221 case SERVER: 222 case STANDALONE: 223 default: 224 break; 225 } 226 startRenderLoop(); 227 } 228 229 /** 230 * @return singleton object 231 */ 232 Orxonox* Orxonox::getSingleton() 233 { 234 if (!singletonRef_) 235 singletonRef_ = new Orxonox(); 236 return singletonRef_; 237 } 238 239 /** 240 * error kills orxonox 241 */ 242 void Orxonox::die(/* some error code */) 243 { 244 //TODO: destroy and destruct everything and print nice error msg 245 delete this; 246 } 247 248 void Orxonox::standaloneInit(std::string path) 249 { 196 void Orxonox::serverInit(std::string path) 197 { 198 COUT(2) << "initialising server" << std::endl; 199 250 200 ogre_->setConfigPath(path); 251 201 ogre_->setup(); 252 root_ = ogre_->getRoot(); 253 if(!ogre_->load()) die(/* unable to load */); 254 255 //defineResources(); 256 //setupRenderSystem(); 257 //createRenderWindow(); 258 //initializeResourceGroups(); 259 /*createScene(); 260 setupScene(); 261 setupInputSystem(); 262 createFrameListener(); 263 Factory::createClassHierarchy(); 264 startRenderLoop();*/ 265 } 266 267 void Orxonox::playableServer(std::string path) 268 { 269 ogre_->setConfigPath(path); 270 ogre_->setup(); 271 root_ = ogre_->getRoot(); 272 defineResources(); 273 setupRenderSystem(); 274 createRenderWindow(); 275 initializeResourceGroups(); 276 setupInputSystem(); 277 Factory::createClassHierarchy(); 278 createScene(); 279 setupScene(); 280 createFrameListener(); 281 try{ 282 server_g = new network::Server(); //!< add port and bindadress 283 server_g->open(); //!< open server and create listener thread 284 if(ogre_ && ogre_->getRoot()) 285 ogre_->getRoot()->addFrameListener(new network::ServerFrameListener()); // adds a framelistener for the server 286 COUT(3) << "Info: network framelistener added" << std::endl; 287 } 288 catch(...) 289 { 290 COUT(1) << "Error: There was a problem initialising the server :(" << std::endl; 291 } 292 startRenderLoop(); 293 } 294 295 void Orxonox::standalone(){ 296 297 298 299 } 300 301 void Orxonox::serverInit(std::string path) 302 { 303 COUT(2) << "initialising server" << std::endl; 304 ogre_->setConfigPath(path); 305 ogre_->setup(); 306 server_g = new network::Server(); // FIXME add some settings if wanted 307 if(!ogre_->load()) die(/* unable to load */); 308 // FIXME add network framelistener 202 //root_ = ogre_->getRoot(); 203 if(!ogre_->load(this->dataPath_)) abortImmediate(/* unable to load */); 204 205 server_g = new network::Server(); 309 206 } 310 207 311 208 void Orxonox::clientInit(std::string path) 312 209 { 313 COUT(2) << "initialising client" << std::endl; 210 COUT(2) << "initialising client" << std::endl;\ 211 314 212 ogre_->setConfigPath(path); 315 213 ogre_->setup(); … … 317 215 client_g = new network::Client(); 318 216 else 319 client_g = new network::Client(serverIp_, 55556); 320 if(!ogre_->load()) die(/* unable to load */); 321 ogre_->getRoot()->addFrameListener(new network::ClientFrameListener()); 322 } 323 324 void Orxonox::defineResources() 325 { 326 std::string secName, typeName, archName; 327 Ogre::ConfigFile cf; 328 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE 329 cf.load(macBundlePath() + "/Contents/Resources/resources.cfg"); 330 #else 331 cf.load(dataPath_ + "resources.cfg"); 332 #endif 333 334 Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator(); 335 while (seci.hasMoreElements()) 336 { 337 secName = seci.peekNextKey(); 338 Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext(); 339 Ogre::ConfigFile::SettingsMultiMap::iterator i; 340 for (i = settings->begin(); i != settings->end(); ++i) 341 { 342 typeName = i->first; 343 archName = i->second; 344 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE 345 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( std::string(macBundlePath() + "/" + archName), typeName, secName); 346 #else 347 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName); 348 #endif 349 } 217 client_g = new network::Client(serverIp_, NETWORK_PORT); 218 if(!ogre_->load(this->dataPath_)) abortImmediate(/* unable to load */); 219 } 220 221 void Orxonox::standaloneInit(std::string path) 222 { 223 COUT(2) << "initialising standalone mode" << std::endl; 224 225 ogre_->setConfigPath(path); 226 ogre_->setup(); 227 //root_ = ogre_->getRoot(); 228 if(!ogre_->load(this->dataPath_)) abortImmediate(/* unable to load */); 229 } 230 231 /** 232 * start modules 233 */ 234 void Orxonox::start() 235 { 236 switch(mode_){ 237 case CLIENT: 238 clientStart(); 239 break; 240 case SERVER: 241 serverStart(); 242 break; 243 default: 244 standaloneStart(); 350 245 } 351 246 } 352 353 void Orxonox::setupRenderSystem() 354 { 355 if (!root_->restoreConfig() && !root_->showConfigDialog()) 356 throw Ogre::Exception(52, "User canceled the config dialog!", "OrxApplication::setupRenderSystem()"); 357 } 358 359 void Orxonox::createRenderWindow() 360 { 361 root_->initialise(true, "OrxonoxV2"); 362 } 363 364 void Orxonox::initializeResourceGroups() 365 { 366 Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5); 367 Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); 368 } 369 370 /** 371 * 372 * @param 373 */ 374 void Orxonox::createScene(void) 375 { 376 // Init audio 247 248 void Orxonox::clientStart(){ 249 ogre_->initialise(); 250 Factory::createClassHierarchy(); 251 252 377 253 auMan_ = new audio::AudioManager(); 378 254 379 255 bulletMgr_ = new BulletManager(); 380 381 // load this file from config 382 // loader_ = new loader::LevelLoader("sample.oxw"); 383 // loader_->loadLevel(); 384 Level* startlevel = new Level("levels/sample.oxw"); 385 Loader::open(startlevel); 386 256 387 257 Ogre::Overlay* hudOverlay = Ogre::OverlayManager::getSingleton().getByName("Orxonox/HUD1.2"); 388 258 HUD* orxonoxHud; … … 391 261 orxonoxHud->setEnergyDistr(20,20,60); 392 262 hudOverlay->show(); 263 264 client_g->establishConnection(); 265 client_g->tick(0); 266 267 268 //setupInputSystem(); 269 270 startRenderLoop(); 271 } 272 273 void Orxonox::serverStart(){ 274 //TODO: start modules 275 ogre_->initialise(); 276 //TODO: run engine 277 Factory::createClassHierarchy(); 278 createScene(); 279 setupInputSystem(); 280 281 server_g->open(); 282 283 startRenderLoop(); 284 } 285 286 void Orxonox::standaloneStart(){ 287 //TODO: start modules 288 ogre_->initialise(); 289 //TODO: run engine 290 Factory::createClassHierarchy(); 291 createScene(); 292 setupInputSystem(); 293 294 startRenderLoop(); 295 } 296 297 void Orxonox::createScene(void) 298 { 299 // Init audio 300 auMan_ = new audio::AudioManager(); 301 302 bulletMgr_ = new BulletManager(); 303 304 // load this file from config 305 Level* startlevel = new Level("levels/sample.oxw"); 306 Loader::open(startlevel); 307 308 Ogre::Overlay* hudOverlay = Ogre::OverlayManager::getSingleton().getByName("Orxonox/HUD1.2"); 309 orxonoxHUD_ = new HUD(); 310 orxonoxHUD_->setEnergyValue(20); 311 orxonoxHUD_->setEnergyDistr(20,20,60); 312 hudOverlay->show(); 393 313 394 314 /* … … 396 316 auMan_->ambientAdd("a2"); 397 317 auMan_->ambientAdd("a3"); 398 //auMan->ambientAdd("ambient1"); 399 auMan_->ambientStart();*/ 400 } 401 402 403 /** 404 * 405 */ 406 void Orxonox::setupScene() 407 { 408 // SceneManager *mgr = ogre_->getSceneManager(); 409 410 411 // SceneNode* node = (SceneNode*)mgr->getRootSceneNode()->getChild("OgreHeadNode"); 412 // SceneNode *node = mgr->getRootSceneNode()->createChildSceneNode("OgreHeadNode", Vector3(0,0,0)); 413 414 415 /* 416 particle::ParticleInterface *e = new particle::ParticleInterface(mgr,"engine","Orxonox/strahl"); 417 e->particleSystem_->setParameter("local_space","true"); 418 e->setPositionOfEmitter(0, Vector3(0,-10,0)); 419 e->setDirection(Vector3(0,0,-1)); 420 e->addToSceneNode(node); 421 */ 422 } 423 424 318 //auMan->ambientAdd("ambient1"); 319 auMan_->ambientStart(); 320 */ 321 } 322 323 /** 324 @brief Calls the InputHandler which sets up the input devices. 325 The render window width and height are used to set up the mouse movement. 326 */ 425 327 void Orxonox::setupInputSystem() 426 328 { 427 size_t windowHnd = 0; 428 std::ostringstream windowHndStr; 429 OIS::ParamList pl; 430 431 // fixes auto repeat problem 432 #if defined OIS_LINUX_PLATFORM 433 pl.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true"))); 434 #endif 435 436 Ogre::RenderWindow *win = ogre_->getRoot()->getAutoCreatedWindow(); 437 win->getCustomAttribute("WINDOW", &windowHnd); 438 windowHndStr << windowHnd; 439 pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); 440 inputManager_ = OIS::InputManager::createInputSystem(pl); 441 442 try 329 inputHandler_ = InputHandler::getSingleton(); 330 if (!inputHandler_->initialise(ogre_->getWindowHandle(), 331 ogre_->getWindowWidth(), ogre_->getWindowHeight())) 332 abortImmediate(); 333 } 334 335 /** 336 Main loop of the orxonox game. 337 This is a new solution, using the ogre engine instead of being used by it. 338 An alternative solution would be to simply use the timer of the Root object, 339 but that implies using Ogre in any case. There would be no way to test 340 our code without the help of the root object. 341 There's even a chance that we can dispose of the root object entirely 342 in server mode. 343 About the loop: The design is almost exactly like the one in ogre, so that 344 if any part of ogre registers a framelisteners, it will still behave 345 correctly. Furthermore I have taken over the time smoothing feature from 346 ogre. If turned on (see orxonox constructor), it will calculate the dt_n by 347 means of the recent most dt_n-1, dt_n-2, etc. 348 */ 349 void Orxonox::startRenderLoop() 350 { 351 // use the ogre timer class to measure time. 352 if (!timer_) 353 timer_ = new Ogre::Timer(); 354 timer_->reset(); 355 356 // Contains the times of recently fired events 357 std::deque<unsigned long> eventTimes[3]; 358 // Clear event times 359 for (int i = 0; i < 3; ++i) 360 eventTimes[i].clear(); 361 362 while (!bAbort_) 363 { 364 // Pump messages in all registered RenderWindows 365 Ogre::WindowEventUtilities::messagePump(); 366 367 // get current time 368 unsigned long now = timer_->getMilliseconds(); 369 370 // create an event to pass to the frameStarted method in ogre 371 Ogre::FrameEvent evt; 372 evt.timeSinceLastEvent = calculateEventTime(now, eventTimes[0]); 373 evt.timeSinceLastFrame = calculateEventTime(now, eventTimes[1]); 374 375 // show the current time in the HUD 376 orxonoxHUD_->setTime((int)now, 0); 377 378 // Iterate through all Tickables and call their tick(dt) function 379 for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ) 380 (it++)->tick((float)evt.timeSinceLastFrame); 381 382 // don't forget to call _fireFrameStarted in ogre to make sure 383 // everything goes smoothly 384 ogre_->frameStarted(evt); 385 386 if (mode_ != SERVER) 387 ogre_->renderOneFrame(); // only render in non-server mode 388 389 // get current time 390 now = timer_->getMilliseconds(); 391 392 // create an event to pass to the frameEnded method in ogre 393 evt.timeSinceLastEvent = calculateEventTime(now, eventTimes[0]); 394 evt.timeSinceLastFrame = calculateEventTime(now, eventTimes[2]); 395 396 // again, just to be sure ogre works fine 397 ogre_->frameEnded(evt); 398 } 399 } 400 401 /** 402 Method for calculating the average time between recently fired events. 403 Code directly taken from OgreRoot.cc 404 @param now The current time in ms. 405 @param type The type of event to be considered. 406 */ 407 float Orxonox::calculateEventTime(unsigned long now, std::deque<unsigned long> ×) 408 { 409 // Calculate the average time passed between events of the given type 410 // during the last mFrameSmoothingTime seconds. 411 412 times.push_back(now); 413 414 if(times.size() == 1) 415 return 0; 416 417 // Times up to mFrameSmoothingTime seconds old should be kept 418 unsigned long discardThreshold = 419 static_cast<unsigned long>(frameSmoothingTime_ * 1000.0f); 420 421 // Find the oldest time to keep 422 std::deque<unsigned long>::iterator it = times.begin(), 423 end = times.end()-2; // We need at least two times 424 while(it != end) 443 425 { 444 keyboard_ = static_cast<OIS::Keyboard*>(inputManager_->createInputObject(OIS::OISKeyboard, false)); 445 mouse_ = static_cast<OIS::Mouse*>(inputManager_->createInputObject(OIS::OISMouse, true)); 426 if (now - *it > discardThreshold) 427 ++it; 428 else 429 break; 446 430 } 447 catch (const OIS::Exception &e) 448 { 449 throw new Ogre::Exception(42, e.eText, "OrxApplication::setupInputSystem"); 450 } 451 } 452 453 // FIXME we actually want to do this differently... 454 void Orxonox::createFrameListener() 455 { 456 TickFrameListener* TickFL = new TickFrameListener(); 457 ogre_->getRoot()->addFrameListener(TickFL); 458 459 TimerFrameListener* TimerFL = new TimerFrameListener(); 460 ogre_->getRoot()->addFrameListener(TimerFL); 461 462 //if(mode_!=CLIENT) // FIXME just a hack ------- remove this in future 463 frameListener_ = new OrxListener(keyboard_, auMan_, mode_); 464 ogre_->getRoot()->addFrameListener(frameListener_); 465 } 466 467 void Orxonox::startRenderLoop() 468 { 469 // FIXME 470 // this is a hack!!! 471 // the call to reset the mouse clipping size should probably be somewhere 472 // else, however this works for the moment. 473 unsigned int width, height, depth; 474 int left, top; 475 ogre_->getRoot()->getAutoCreatedWindow()->getMetrics(width, height, depth, left, top); 476 477 if(mode_!=CLIENT){ 478 const OIS::MouseState &ms = mouse_->getMouseState(); 479 ms.width = width; 480 ms.height = height; 481 } 482 ogre_->getRoot()->startRendering(); 431 432 // Remove old times 433 times.erase(times.begin(), it); 434 435 return (float)(times.back() - times.front()) / ((times.size()-1) * 1000); 436 } 437 438 /** 439 @brief Test method for the InputHandler. 440 But: Is actually responsible for catching an exit event.. 441 */ 442 void Orxonox::eventOccured(InputEvent &evt) 443 { 444 if (evt.id == 1) 445 this->abortRequest(); 483 446 } 484 447 } -
code/trunk/src/orxonox/Orxonox.h
r871 r1021 11 11 12 12 #include <OgrePrerequisites.h> 13 #include <OIS/OISPrereqs.h>13 //#include <OIS/OISPrereqs.h> 14 14 15 15 #include "OrxonoxPrereqs.h" 16 //#include "loader/LoaderPrereqs.h"17 16 #include "audio/AudioPrereqs.h" 18 17 19 18 #include "GraphicsEngine.h" 19 #include "InputEventListener.h" 20 20 21 21 … … 25 25 26 26 enum gameMode{ 27 STANDALONE,28 27 SERVER, 29 28 CLIENT, 30 PRESENTATION29 STANDALONE 31 30 }; 32 31 33 class _OrxonoxExport Orxonox 32 class _OrxonoxExport Orxonox : public InputEventListener 34 33 { 35 34 public: … … 37 36 void start(); 38 37 // not sure if this should be private 39 void die(/* some error code */); 38 void abortImmediate(/* some error code */); 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 OIS::Keyboard* getKeyboard() { return this->keyboard_; } 45 inline OIS::Mouse* getMouse() { return this->mouse_; } 46 inline BulletManager* getBulletMgr() { return this->bulletMgr_; } 46 static void destroy(); 47 47 48 private: 48 private: 49 // don't mess with singletons 49 50 Orxonox(); 50 virtual ~Orxonox(); 51 Orxonox(Orxonox& instance); 52 Orxonox& operator=(const Orxonox& instance); 53 ~Orxonox(); 54 51 55 // init functions 52 56 void serverInit(std::string path); 53 57 void clientInit(std::string path); 54 58 void standaloneInit(std::string path); 59 55 60 // run functions 56 void playableServer(std::string path); 57 void standalone(); 58 void defineResources(); 59 void setupRenderSystem(); 60 void createRenderWindow(); 61 void initializeResourceGroups(); 62 void createScene(void); 63 void setupScene(); 61 void serverStart(); 62 void clientStart(); 63 void standaloneStart(); 64 65 void createScene(); 64 66 void setupInputSystem(); 65 void createFrameListener();66 67 void startRenderLoop(); 68 float calculateEventTime(unsigned long, std::deque<unsigned long>&); 69 70 void eventOccured(InputEvent &evt); 67 71 68 72 private: 69 73 GraphicsEngine* ogre_; //!< our dearest graphics engine <3 70 74 std::string dataPath_; //!< path to data 71 // loader::LevelLoader* loader_; //!< level loader builds the scene72 75 audio::AudioManager* auMan_; //!< audio manager 73 76 BulletManager* bulletMgr_; //!< Keeps track of the thrown bullets 74 static Orxonox* singletonRef_; 75 OIS::Keyboard* keyboard_; 76 OIS::Mouse* mouse_; 77 OIS::InputManager* inputManager_; 78 OrxListener* frameListener_; 79 Ogre::Root* root_; 77 InputHandler* inputHandler_; //!< Handles input with key bindings 78 Ogre::Root* root_; //!< Holy grail of Ogre 79 Ogre::Timer* timer_; //!< Main loop timer 80 // TODO: make this a config-value by creating a config class for orxonox 81 float frameSmoothingTime_; 82 // little hack to actually show something dynamic in the HUD 83 HUD* orxonoxHUD_; 84 bool bAbort_; //!< aborts the render loop if true 80 85 81 86 // this is used to identify the mode (server/client/...) we're in 82 87 gameMode mode_; 83 88 std::string serverIp_; 89 90 static Orxonox *singletonRef_s; 84 91 }; 85 92 } -
code/trunk/src/orxonox/OrxonoxPlatform.h
r890 r1021 210 210 //# pragma warning (disable : 4503) 211 211 212 // disable: "conversion from 'double' to 'float', possible loss of data 212 // disable: conversion from 'double' to 'float', possible loss of data 213 // disable: conversion from 'ogg_int64_t' to 'long', possible loss of data 214 // This has been dealt with in base_properties of the solution since the 215 // warning primarily occurs in library header files (which are mostly 216 // included before OrxonoxPlatform.h is) 213 217 //# pragma warning (disable : 4244) 214 218 … … 221 225 // disable: "<type> needs to have dll-interface to be used by clients' 222 226 // Happens on STL member variables which are not public therefore is ok 227 // This has been dealt with in base_properties of the solution since the 228 // warning primarily occurs in library header files (which are mostly 229 // included before OrxonoxPlatform.h is) 223 230 //# pragma warning (disable : 4251) 231 232 // disable: 'MultiTypeString' : multiple assignment operators specified 233 // Used in MultiType and works fine so far 234 # pragma warning (disable : 4522) 224 235 225 236 // disable: "non dll-interface class used as base for dll-interface class" … … 252 263 253 264 254 // Create a logical xor operator265 // Define the english written operators like and, or, xor 255 266 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC 256 # define XOR ^ 257 #elif ORXONOX_COMPILER == ORXONOX_COMPILER_GCC 258 # define XOR xor 259 #else 260 # define XOR ^ 267 # include <iso646.h> 261 268 #endif 262 269 -
code/trunk/src/orxonox/OrxonoxPrereqs.h
r790 r1021 68 68 class Camera; 69 69 class GraphicsEngine; 70 struct InputEvent; 71 class InputEventListener; 72 class InputHandler; 70 73 class Mesh; 71 74 class Model; -
code/trunk/src/orxonox/OrxonoxStableHeaders.h
r890 r1021 41 41 42 42 // not including the entire Ogre.h doesn't exceed the default heap size for pch 43 #ifndef WIN32_LEAN_AND_MEAN 44 // prevent Ogre from including winsock.h that messes with winsock2.h from enet 45 # define WIN32_LEAN_AND_MEAN 46 #endif 43 47 //#include <Ogre.h> 44 48 #include <OgreBillboardSet.h> 45 49 #include <OgreCamera.h> 50 #include <OgreColourValue.h> 46 51 #include <OgreConfigFile.h> 47 52 #include <OgreEntity.h> … … 49 54 #include <OgreFrameListener.h> 50 55 #include <OgreLight.h> 56 #include <OgreMath.h> 57 #include <OgreMatrix3.h> 51 58 #include <OgreOverlay.h> 52 59 #include <OgreOverlayElement.h> … … 56 63 #include <OgrePlatform.h> 57 64 #include <OgrePrerequisites.h> 65 #include <OgreQuaternion.h> 66 #include <OgreResourceGroupManager.h> 58 67 #include <OgreRenderWindow.h> 59 68 #include <OgreRoot.h> … … 62 71 #include <OgreStringConverter.h> 63 72 #include <OgreTextureManager.h> 73 #include <OgreTimer.h> 74 #include <OgreVector2.h> 75 #include <OgreVector3.h> 76 #include <OgreVector3.h> 64 77 #include <OgreViewport.h> 78 #include <OgreWindowEventUtilities.h> 65 79 66 80 #include <OIS/OIS.h> … … 68 82 /** 69 83 * Some of the not so stable header files. 70 * But it's not very useful to include them anyway..84 * It's not very useful to include them anyway.. 71 85 **/ 72 86 73 //#include "audio/AudioManager.h" 74 75 //#include "core/CoreIncludes.h" 87 #include "core/CoreIncludes.h" 76 88 #include "core/BaseObject.h" 77 //#include "core/ArgReader.h"89 #include "core/Tickable.h" 78 90 #include "core/Error.h" 91 #include "core/Loader.h" 92 #include "core/XMLPort.h" 79 93 80 94 #include "network/Synchronisable.h" … … 97 111 #include "util/tinyxml/tinyxml.h" 98 112 99 //#include "hud/HUD.h"100 //#include "loader/LevelLoader.h"101 //#include "objects/weapon/AmmunitionDump.h"102 //#include "objects/weapon/BarrelGun.h"103 //#include "objects/weapon/Bullet.h"104 //#include "objects/weapon/BulletManager.h"105 //#include "objects/weapon/WeaponStation.h"106 //#include "objects/Ambient.h"107 //#include "objects/Camera.h"108 //#include "objects/Explosion.h"109 //#include "objects/Fighter.h"110 113 #include "objects/Model.h" 111 //#include "objects/NPC.h"112 //#include "objects/Projectile.h"113 //#include "objects/Skybox.h"114 //#include "objects/SpaceShipSteeringObject.h"115 #include "objects/Tickable.h"116 114 #include "objects/WorldEntity.h" 117 //#include "particle/ParticleInterface.h"118 //#include "tools/BillboardSet.h"119 //#include "tools/Light.h"120 //#include "tools/Mesh.h"121 //#include "tools/Timer.h"122 //#include "GraphicsEngine.h"123 //#include "InputManager.h"124 //#include "Orxonox.h"125 //#include "SpaceshipSteering.h"126 115 127 116 #endif -
code/trunk/src/orxonox/PrecompiledHeaderFiles.cc
r790 r1021 27 27 28 28 /** 29 @file PrecompiledHeaderFiles.cc29 @file 30 30 @brief This file actually generates the precompiled header file 31 31 */ -
code/trunk/src/orxonox/core/BaseObject.cc
r871 r1021 27 27 28 28 /** 29 @file BaseObject.cc29 @file 30 30 @brief Implementation of the BaseObject class. 31 31 */ -
code/trunk/src/orxonox/core/CMakeLists.txt
r871 r1021 17 17 Executor.cc 18 18 XMLPort.cc 19 Tickable.cc 20 Script.cc 19 21 ) 20 22 … … 24 26 TARGET_LINK_LIBRARIES( core 25 27 util 28 ${Lua_LIBRARIES} 26 29 ) -
code/trunk/src/orxonox/core/ClassTreeMask.cc
r890 r1021 592 592 { 593 593 const Identifier* subclass = it->getClass(); 594 newmask.add(subclass, this->isIncluded(subclass) ||other.isIncluded(subclass), false, false);594 newmask.add(subclass, this->isIncluded(subclass) or other.isIncluded(subclass), false, false); 595 595 } 596 596 … … 599 599 { 600 600 const Identifier* subclass = it->getClass(); 601 newmask.add(subclass, this->isIncluded(subclass) ||other.isIncluded(subclass), false, false);601 newmask.add(subclass, this->isIncluded(subclass) or other.isIncluded(subclass), false, false); 602 602 } 603 603 … … 623 623 { 624 624 const Identifier* subclass = it->getClass(); 625 newmask.add(subclass, this->isIncluded(subclass) &&other.isIncluded(subclass), false, false);625 newmask.add(subclass, this->isIncluded(subclass) and other.isIncluded(subclass), false, false); 626 626 } 627 627 … … 630 630 { 631 631 const Identifier* subclass = it->getClass(); 632 newmask.add(subclass, this->isIncluded(subclass) &&other.isIncluded(subclass), false, false);632 newmask.add(subclass, this->isIncluded(subclass) and other.isIncluded(subclass), false, false); 633 633 } 634 634 … … 737 737 { 738 738 const Identifier* subclass = it->getClass(); 739 newmask.add(subclass, this->isIncluded(subclass) XORother.isIncluded(subclass), false, false);739 newmask.add(subclass, this->isIncluded(subclass) xor other.isIncluded(subclass), false, false); 740 740 } 741 741 … … 744 744 { 745 745 const Identifier* subclass = it->getClass(); 746 newmask.add(subclass, this->isIncluded(subclass) XORother.isIncluded(subclass), false, false);746 newmask.add(subclass, this->isIncluded(subclass) xor other.isIncluded(subclass), false, false); 747 747 } 748 748 -
code/trunk/src/orxonox/core/DebugLevel.cc
r871 r1021 95 95 96 96 // Return a constant value while we're creating the object 97 return 4;97 return 3; 98 98 } 99 99 } -
code/trunk/src/orxonox/core/Loader.cc
r871 r1021 33 33 #include "Debug.h" 34 34 #include "CoreIncludes.h" 35 #include "Script.h" 35 36 36 37 #include "util/tinyxml/ticpp.h" … … 107 108 Loader::currentMask_s = level->getMask() * mask; 108 109 110 // let Lua work this out: 111 //Script* lua; 112 /*Script::loadFile(level->getFile(), true); 113 Script::init(Script::getLuaState()); 114 Script::run();*/ 115 Script* lua = Script::getInstance(); 116 lua->loadFile(level->getFile(), true); 117 lua->run(); 118 109 119 try 110 120 { … … 112 122 COUT(3) << "Mask: " << Loader::currentMask_s << std::endl; 113 123 114 ticpp::Document xmlfile(level->getFile()); 115 xmlfile.LoadFile(); 124 //ticpp::Document xmlfile(level->getFile()); 125 //xmlfile.LoadFile(); 126 //ticpp::Element myelement(*Script::getFileString()); 127 ticpp::Document xmlfile; 128 //xmlfile.ToDocument(); 129 xmlfile.Parse(lua->getLuaOutput(), true); 116 130 117 131 for ( ticpp::Iterator<ticpp::Element> child = xmlfile.FirstChildElement(false); child != child.end(); child++ ) -
code/trunk/src/orxonox/objects/Camera.cc
r790 r1021 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/trunk/src/orxonox/objects/Fighter.cc
r790 r1021 37 37 #include "util/tinyxml/tinyxml.h" 38 38 #include "util/String2Number.h" 39 #include "../core/CoreIncludes.h" 40 #include "../Orxonox.h" 41 #include "../particle/ParticleInterface.h" 39 #include "core/CoreIncludes.h" 40 #include "Orxonox.h" 41 #include "InputHandler.h" 42 #include "particle/ParticleInterface.h" 42 43 #include "weapon/AmmunitionDump.h" 43 44 #include "weapon/BarrelGun.h" … … 207 208 208 209 node->attachObject(cam); 209 Orxonox::getSingleton()->getOgrePointer()->getR oot()->getAutoCreatedWindow()->addViewport(cam);210 Orxonox::getSingleton()->getOgrePointer()->getRenderWindow()->addViewport(cam); 210 211 } 211 212 } … … 254 255 if (!this->setMouseEventCallback_) 255 256 { 256 if ( Orxonox::getSingleton()->getMouse())257 if (InputHandler::getSingleton()->getMouse()) 257 258 { 258 Orxonox::getSingleton()->getMouse()->setEventCallback(this);259 InputHandler::getSingleton()->getMouse()->setEventCallback(this); 259 260 this->setMouseEventCallback_ = true; 260 261 } … … 263 264 WorldEntity::tick(dt); 264 265 265 OIS::Keyboard* mKeyboard = Orxonox::getSingleton()->getKeyboard();266 OIS::Mouse* mMouse = Orxonox::getSingleton()->getMouse();266 OIS::Keyboard* mKeyboard = InputHandler::getSingleton()->getKeyboard(); 267 OIS::Mouse* mMouse = InputHandler::getSingleton()->getMouse(); 267 268 268 269 mKeyboard->capture(); -
code/trunk/src/orxonox/objects/Model.cc
r871 r1021 44 44 { 45 45 RegisterObject(Model); 46 registerAllVariables(); 46 47 } 47 48 … … 63 64 /** 64 65 @brief XML loading and saving. 65 @param xmlelement The XML-element 66 @p 67 aram xmlelement The XML-element 66 68 @param loading Loading (true) or saving (false) 67 69 @return The XML-element … … 82 84 83 85 bool Model::create(){ 86 WorldEntity::create(); 84 87 if(meshSrc_.compare("")!=0){ 85 88 this->mesh_.setMesh(meshSrc_); … … 87 90 COUT(4) << "Loader: Created model" << std::endl; 88 91 } 89 registerAllVariables();90 92 return true; 91 93 } 92 94 93 95 void Model::registerAllVariables(){ 94 // registerVar(&meshSrc_, meshSrc_.length() + 1, network::STRING); 96 WorldEntity::registerAllVariables(); 97 registerVar(&meshSrc_, meshSrc_.length() + 1, network::STRING); 95 98 } 96 99 } -
code/trunk/src/orxonox/objects/Model.h
r871 r1021 22 22 bool create(); 23 23 24 protected: 25 void registerAllVariables(); 26 24 27 private: 25 28 std::string meshSrc_; 26 29 Mesh mesh_; 27 void registerAllVariables();28 30 }; 29 31 } -
code/trunk/src/orxonox/objects/NPC.cc
r790 r1021 85 85 void NPC::tick(float dt) 86 86 { 87 87 update(); 88 88 this->setVelocity(0.995*this->getVelocity() + this->getAcceleration()*dt); 89 89 this->translate(this->getVelocity()*dt); -
code/trunk/src/orxonox/objects/SpaceShip.cc
r978 r1021 39 39 #include "util/String2Number.h" 40 40 #include "util/Math.h" 41 #include "../core/CoreIncludes.h" 42 #include "../core/Debug.h" 43 #include "../Orxonox.h" 44 #include "../particle/ParticleInterface.h" 41 #include "core/CoreIncludes.h" 42 #include "core/Debug.h" 43 #include "Orxonox.h" 44 #include "InputHandler.h" 45 #include "particle/ParticleInterface.h" 45 46 #include "Projectile.h" 46 47 #include "core/XMLPort.h" … … 55 56 { 56 57 RegisterObject(SpaceShip); 58 this->registerAllVariables(); 57 59 58 60 this->setConfigValues(); … … 124 126 this->brakeLoop(loop); 125 127 */ 126 this->init(); 127 128 // this->create(); 129 130 128 131 COUT(3) << "Info: SpaceShip was loaded" << std::endl; 129 132 } … … 135 138 } 136 139 140 bool SpaceShip::create(){ 141 if(Model::create()) 142 this->init(); 143 else 144 return false; 145 return true; 146 } 147 148 void SpaceShip::registerAllVariables(){ 149 Model::registerAllVariables(); 150 151 152 153 } 154 137 155 void SpaceShip::init() 138 156 { … … 202 220 { 203 221 Model::loadParams(xmlElem); 222 this->create(); 204 223 /* 205 224 if (xmlElem->Attribute("forward") && xmlElem->Attribute("rotateupdown") && xmlElem->Attribute("rotaterightleft") && xmlElem->Attribute("looprightleft")) … … 267 286 268 287 this->camNode_->attachObject(cam); 269 Orxonox::getSingleton()->getOgrePointer()->getR oot()->getAutoCreatedWindow()->addViewport(cam);288 Orxonox::getSingleton()->getOgrePointer()->getRenderWindow()->addViewport(cam); 270 289 } 271 290 … … 400 419 if (!this->setMouseEventCallback_) 401 420 { 402 if ( Orxonox::getSingleton()->getMouse())421 if (InputHandler::getSingleton()->getMouse()) 403 422 { 404 Orxonox::getSingleton()->getMouse()->setEventCallback(this);423 InputHandler::getSingleton()->getMouse()->setEventCallback(this); 405 424 this->setMouseEventCallback_ = true; 406 425 } … … 427 446 } 428 447 429 OIS::Keyboard* mKeyboard = Orxonox::getSingleton()->getKeyboard();430 OIS::Mouse* mMouse = Orxonox::getSingleton()->getMouse();448 OIS::Keyboard* mKeyboard = InputHandler::getSingleton()->getKeyboard(); 449 OIS::Mouse* mMouse = InputHandler::getSingleton()->getMouse(); 431 450 432 451 mKeyboard->capture(); -
code/trunk/src/orxonox/objects/SpaceShip.h
r978 r1021 21 21 SpaceShip(); 22 22 ~SpaceShip(); 23 bool create(); 24 void registerAllVariables(); 23 25 void init(); 24 26 void setConfigValues(); -
code/trunk/src/orxonox/objects/WorldEntity.cc
r871 r1021 49 49 RegisterObject(WorldEntity); 50 50 51 if (Orxonox::getSingleton()->getSceneManager()) 52 { 53 std::ostringstream name; 54 name << (WorldEntity::worldEntityCounter_s++); 55 this->setName("WorldEntity" + name.str()); 56 this->node_ = Orxonox::getSingleton()->getSceneManager()->getRootSceneNode()->createChildSceneNode(this->getName()); 57 } 58 else 59 { 60 this->node_ = 0; 61 } 51 //create(); 62 52 63 53 this->bStatic_ = true; … … 67 57 this->rotationRate_ = 0; 68 58 this->momentum_ = 0; 59 60 if (Orxonox::getSingleton()->getSceneManager()) 61 { 62 std::ostringstream name; 63 name << (WorldEntity::worldEntityCounter_s++); 64 this->setName("WorldEntity" + name.str()); 65 this->node_ = Orxonox::getSingleton()->getSceneManager()->getRootSceneNode()->createChildSceneNode(this->getName()); 66 67 registerAllVariables(); 68 } 69 else 70 { 71 this->node_ = 0; 72 } 69 73 } 70 74 … … 89 93 90 94 BaseObject::loadParams(xmlElem); 95 create(); 91 96 /* 92 97 if (xmlElem->Attribute("position")) … … 185 190 } 186 191 187 bool WorldEntity::create(){188 registerAllVariables();189 return true;190 }191 192 192 193 void WorldEntity::registerAllVariables() 193 194 { 194 /*// register coordinates195 // register coordinates 195 196 registerVar( (void*) &(this->getPosition().x), sizeof(this->getPosition().x), network::DATA); 196 197 registerVar( (void*) &(this->getPosition().y), sizeof(this->getPosition().y), network::DATA); … … 200 201 registerVar( (void*) &(this->getOrientation().x), sizeof(this->getOrientation().x), network::DATA); 201 202 registerVar( (void*) &(this->getOrientation().y), sizeof(this->getOrientation().y), network::DATA); 202 registerVar( (void*) &(this->getOrientation().z), sizeof(this->getOrientation().z), network::DATA); */203 registerVar( (void*) &(this->getOrientation().z), sizeof(this->getOrientation().z), network::DATA); 203 204 // not needed at the moment, because we don't have prediction yet 204 / *// register velocity_205 // register velocity_ 205 206 registerVar( (void*) &(this->getVelocity().x), sizeof(this->getVelocity().x), network::DATA); 206 207 registerVar( (void*) &(this->getVelocity().y), sizeof(this->getVelocity().y), network::DATA); … … 210 211 registerVar( (void*) &(this->getRotationAxis().x), sizeof(this->getRotationAxis().x), network::DATA); 211 212 registerVar( (void*) &(this->getRotationAxis().y), sizeof(this->getRotationAxis().y), network::DATA); 212 registerVar( (void*) &(this->getRotationAxis().z), sizeof(this->getRotationAxis().z), network::DATA); */213 registerVar( (void*) &(this->getRotationAxis().z), sizeof(this->getRotationAxis().z), network::DATA); 213 214 } 214 215 -
code/trunk/src/orxonox/objects/WorldEntity.h
r871 r1021 12 12 //#include "util/tinyxml/tinyxml.h" 13 13 #include "core/BaseObject.h" 14 #include " Tickable.h"14 #include "core/Tickable.h" 15 15 #include "../tools/Mesh.h" 16 16 17 17 namespace orxonox 18 18 { 19 class _OrxonoxExport WorldEntity : public BaseObject, public Tickable //, public network::Synchronisable19 class _OrxonoxExport WorldEntity : public BaseObject, public Tickable, public network::Synchronisable 20 20 { 21 21 public: … … 26 26 virtual void loadParams(TiXmlElement* xmlElem); 27 27 virtual void XMLPort(Element& xmlelement, bool loading); 28 bool create();28 inline bool create(){ return true; } 29 29 30 30 void attachWorldEntity(WorldEntity* entity); -
code/trunk/src/orxonox/objects/weapon/AmmunitionDump.cc
r871 r1021 45 45 { 46 46 RegisterObject(AmmunitionDump); 47 registerAllVariables(); 47 48 48 49 for (int i = 0; i < numberOfAmmos_; i++) … … 114 115 return stock_[id]; 115 116 } 117 118 void AmmunitionDump::registerAllVariables(){ 119 registerVar( &numberOfAmmos_, sizeof(int), network::DATA); 120 121 for (int i = 0; i < numberOfAmmos_; i++) 122 { 123 registerVar(&stock_[i], sizeof(int), network::DATA); 124 registerVar(&capacity_[i], sizeof(int), network::DATA); 125 } 126 } 116 127 } -
code/trunk/src/orxonox/objects/weapon/AmmunitionDump.h
r871 r1021 60 60 protected: 61 61 inline bool create() { return true; } 62 void registerAllVariables(); 62 63 63 64 int numberOfAmmos_; -
code/trunk/src/orxonox/objects/weapon/BulletManager.cc
r871 r1021 39 39 { 40 40 RegisterObject(BulletManager); 41 registerAllVariables(); 41 42 bullets_ = new Bullet*[bulletsSize_]; 42 43 } … … 103 104 } 104 105 106 void BulletManager::registerAllVariables(){ 107 registerVar(&bulletsSize_, sizeof(int), network::DATA); 108 registerVar(&bulletsIndex_, sizeof(int), network::DATA); 109 // TODO we got a problem here: 110 // there is no possibility (so far) to synchronise pointers to objects 111 } 112 105 113 } -
code/trunk/src/orxonox/objects/weapon/BulletManager.h
r871 r1021 39 39 #include "util/tinyxml/tinyxml.h" 40 40 #include "core/BaseObject.h" 41 #include " ../Tickable.h"41 #include "core/Tickable.h" 42 42 43 43 namespace orxonox { … … 60 60 protected: 61 61 inline bool create() { return true; } 62 void registerAllVariables(); 62 63 63 64 // Bullet array -
code/trunk/src/orxonox/particle/ParticleInterface.cc
r910 r1021 69 69 { 70 70 //Abgleichen der anderen Emitter an die Variabeln 71 for (int i= 0; i < numberOfEmitters_; i++) {71 for (int i=1; i < numberOfEmitters_; i++) { 72 72 particleSystem_->getEmitter(i)->setColour( colour_ ); 73 73 particleSystem_->getEmitter(i)->setTimeToLive( distance_ ); … … 84 84 } 85 85 86 void ParticleInterface::setRate( float r)86 void ParticleInterface::setRate(int r) 87 87 { 88 88 rate_ = r; … … 127 127 Vector3 ParticleInterface::getPositionOfEmitter ( int emitterNr ) 128 128 { 129 return particleSystem_->getEmitter( emitterNr)->getPosition();129 return particleSystem_->getEmitter(0)->getPosition(); 130 130 } 131 131 -
code/trunk/src/orxonox/particle/ParticleInterface.h
r910 r1021 48 48 void setVelocity( Real v ); 49 49 50 inline float getRate()50 inline int getRate() 51 51 { return rate_; }; 52 void setRate( float r );52 void setRate( int r ); 53 53 54 54 inline Real getDistance() … … 71 71 Real distance_; 72 72 Real velocity_; 73 float rate_;73 int rate_; 74 74 ColourValue colour_; 75 75 int numberOfEmitters_; -
code/trunk/src/orxonox/tools/Timer.cc
r890 r1021 46 46 this->time_ = 0; 47 47 } 48 49 /** 50 @brief Updates the timer before the frames are rendered. 51 */ 52 void TimerBase::tick(float dt) 53 { 54 if (this->bActive_) 55 { 56 // If active: Decrease the timer by the duration of the last frame 57 this->time_ -= dt; 58 59 if (this->time_ <= 0) 60 { 61 // It's time to call the function 62 if (this->bLoop_) 63 // Q: Why '+=' and not '='? A: Think about it. It's more accurate like that. Seriously. 64 this->time_ += this->interval_; 65 else 66 this->stopTimer(); // Stop the timer if we don't want to loop 67 68 this->run(); 69 } 70 } 71 } 72 48 73 } -
code/trunk/src/orxonox/tools/Timer.h
r871 r1021 58 58 #define _Timer_H__ 59 59 60 #include <OgreFrameListener.h>61 60 #include "../OrxonoxPrereqs.h" 61 #include "core/Tickable.h" 62 62 63 63 namespace orxonox 64 64 { 65 65 //! TimerBase is the parent of the Timer class. 66 class _OrxonoxExport TimerBase : public OrxonoxClass66 class _OrxonoxExport TimerBase : public Tickable 67 67 { 68 friend class TimerFrameListener;69 70 68 public: 71 69 TimerBase(); … … 83 81 /** @brief Returns true if the Timer is active (= not stoped, not paused). @return True = Time is active */ 84 82 inline bool isActive() const { return this->bActive_; } 83 84 void tick(float dt); 85 85 86 86 protected: … … 145 145 }; 146 146 147 //! The TimerFrameListener manages all Timers in the game.148 class TimerFrameListener : public Ogre::FrameListener149 {150 private:151 /** @brief Gets called before a frame gets rendered. */152 bool frameStarted(const Ogre::FrameEvent &evt)153 {154 // Iterate through all Timers155 for (Iterator<TimerBase> it = ObjectList<TimerBase>::start(); it; )156 {157 if (it->isActive())158 {159 // If active: Decrease the timer by the duration of the last frame160 it->time_ -= evt.timeSinceLastFrame;161 162 if (it->time_ <= 0)163 {164 // It's time to call the function165 if (it->bLoop_)166 it->time_ += it->interval_; // Q: Why '+=' and not '='? A: Think about it. It's more accurate like that. Seriously.167 else168 it->stopTimer(); // Stop the timer if we don't want to loop169 170 (it++)->run();171 }172 else173 ++it;174 }175 else176 ++it;177 }178 179 return FrameListener::frameStarted(evt);180 }181 };182 147 } 183 148
Note: See TracChangeset
for help on using the changeset viewer.