Changeset 1132 for code/branches/network2/src
- Timestamp:
- Apr 22, 2008, 4:25:54 PM (17 years ago)
- Location:
- code/branches/network2/src
- Files:
-
- 2 deleted
- 10 edited
- 16 copied
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network2/src/CMakeLists.txt
r1076 r1132 1 1 INCLUDE_DIRECTORIES(.) 2 2 INCLUDE_DIRECTORIES(orxonox) 3 INCLUDE_DIRECTORIES( util/tolua)3 INCLUDE_DIRECTORIES(tolua) 4 4 5 ADD_SUBDIRECTORY(tolua) 5 6 ADD_SUBDIRECTORY(util) 6 7 ADD_SUBDIRECTORY(core) -
code/branches/network2/src/core/CMakeLists.txt
r1084 r1132 1 #get the created files 2 AUX_SOURCE_DIRECTORY(tolua TOLUA_BIND_FILES) 3 4 SET( CORE_SRC_FILES 1 SET(CORE_SRC_FILES 5 2 OrxonoxClass.cc 6 3 BaseObject.cc … … 29 26 Tickable.cc 30 27 Script.cc 31 ${TOLUA_BIND_FILES}32 28 ) 33 29 34 ADD_LIBRARY( 30 ADD_LIBRARY(core SHARED ${CORE_SRC_FILES}) 35 31 36 TARGET_LINK_LIBRARIES( 32 TARGET_LINK_LIBRARIES(core 37 33 util 34 tolualib 38 35 ${Lua_LIBRARIES} 39 ${Lua_LIBRARY}40 36 ${OIS_LIBRARIES} 41 37 ) -
code/branches/network2/src/core/ConfigFileManager.h
r1064 r1132 63 63 { 64 64 public: 65 virtual ~ConfigFileEntry() {}; 65 66 virtual void setValue(const std::string& value) = 0; 66 67 virtual std::string getValue() const = 0; -
code/branches/network2/src/core/Loader.cc
r1085 r1132 115 115 Script::init(Script::getLuaState()); 116 116 Script::run();*/ 117 //Script* lua = Script::getInstance();118 //lua->loadFile(level->getFile(), true);119 //lua->run();117 Script* lua = Script::getInstance(); 118 lua->loadFile(level->getFile(), true); 119 lua->run(); 120 120 121 121 try … … 124 124 COUT(3) << "Mask: " << Loader::currentMask_s << std::endl; 125 125 126 ticpp::Document xmlfile(level->getFile());127 xmlfile.LoadFile();126 //ticpp::Document xmlfile(level->getFile()); 127 //xmlfile.LoadFile(); 128 128 //ticpp::Element myelement(*Script::getFileString()); 129 //ticpp::Document xmlfile;130 xmlfile.ToDocument();131 //xmlfile.Parse(lua->getLuaOutput(), true);129 ticpp::Document xmlfile; 130 //xmlfile.ToDocument(); 131 xmlfile.Parse(lua->getLuaOutput(), true); 132 132 133 133 ticpp::Element rootElement; -
code/branches/network2/src/core/Script.cc
r1076 r1132 39 39 } 40 40 41 #include "tolua ++.h"41 #include "tolua/tolua++.h" 42 42 #include "tolua/tolua_bind.h" 43 43 … … 102 102 } 103 103 104 #if LUA_VERSION_NUM != 501 105 const char * Script::lua_Chunkreader(lua_State *L, void *data, size_t *size) 106 { 107 LoadS* ls = ((LoadS*)data); 108 if (ls->size == 0) return NULL; 109 *size = ls->size; 110 ls->size = 0; 111 return ls->s; 112 } 113 #endif 104 114 void Script::run() 105 115 { … … 110 120 error = luaL_loadstring(luaState_, init.c_str()); 111 121 #else 112 error = lua_load(luaState_, &orxonox::Script::lua_Chunkreader, (void*)init.c_str(), "init"); 122 LoadS ls; 123 ls.s = init.c_str(); 124 ls.size = init.size(); 125 error = lua_load(luaState_, &orxonox::Script::lua_Chunkreader, &ls, init.c_str()); 113 126 #endif 114 127 if (error == 0) -
code/branches/network2/src/core/Script.h
r1056 r1132 50 50 class _CoreExport Script // tolua_export 51 51 { // tolua_export 52 struct LoadS { 53 const char *s; 54 size_t size; 55 }; 56 52 57 public: 53 58 inline static Script* getInstance() { if (!Script::singletonRef) Script::singletonRef = new Script(); return Script::singletonRef; } // tolua_export … … 61 66 62 67 #if LUA_VERSION_NUM != 501 63 inline static const char * lua_Chunkreader(lua_State *L, void *data, size_t *size) { return NULL;};68 static const char * lua_Chunkreader(lua_State *L, void *data, size_t *size); 64 69 #endif 65 70 -
code/branches/network2/src/orxonox/GraphicsEngine.cc
r1090 r1132 100 100 Ogre::LogManager::getSingleton().getDefaultLog()->removeListener(this); 101 101 Ogre::LogManager::getSingleton().destroyLog(Ogre::LogManager::getSingleton().getDefaultLog()); 102 delete Ogre::LogManager::getSingletonPtr();102 Ogre::LogManager::getSingletonPtr()->~LogManager(); 103 103 } 104 104 COUT(4) << "*** GraphicsEngine: Destroying objects done" << std::endl; -
code/branches/network2/src/orxonox/Orxonox.cc
r1105 r1132 1 1 /* 2 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 3 4 * 4 5 * … … 27 28 28 29 /** 29 @file Orxonox.cc30 @file 30 31 @brief Orxonox Main Class 31 32 */ … … 33 34 // Precompiled Headers 34 35 #include "OrxonoxStableHeaders.h" 36 #include "Orxonox.h" 37 38 //****** STD ******* 39 //#include <iostream> 40 //#include <exception> 41 #include <deque> 35 42 36 43 //****** OGRE ****** … … 39 46 #include <OgreOverlay.h> 40 47 #include <OgreOverlayManager.h> 48 #include <OgreRoot.h> 41 49 #include <OgreTimer.h> 42 50 #include <OgreWindowEventUtilities.h> 43 51 44 //****** STD *******45 //#include <iostream>46 //#include <exception>47 #include <deque>48 49 52 //***** ORXONOX **** 50 // misc53 // util 51 54 //#include "util/Sleep.h" 52 53 // audio 54 #include "audio/AudioManager.h" 55 56 // network 57 #include "network/Server.h" 58 #include "network/Client.h" 59 network::Client *client_g; 60 network::Server *server_g; 61 62 // objects 63 #include "core/ArgReader.h" 55 #include "util/ArgReader.h" 56 #include "util/ExprParser.h" 57 58 // core 59 #include "core/ConfigFileManager.h" 60 #include "core/ConsoleCommand.h" 64 61 #include "core/Debug.h" 65 62 #include "core/Factory.h" 66 63 #include "core/Loader.h" 67 64 #include "core/Tickable.h" 65 #include "core/InputBuffer.h" 66 #include "core/InputManager.h" 67 68 // audio 69 #include "audio/AudioManager.h" 70 71 // network 72 #include "network/Server.h" 73 #include "network/Client.h" 74 75 // objects and tools 76 #include "tools/Timer.h" 68 77 #include "hud/HUD.h" 69 #include "tools/Timer.h" 70 #include "objects/weapon/BulletManager.h" 71 72 #include "InputHandler.h" 73 74 #include "Orxonox.h" 78 79 // FIXME: is this really file scope? 80 // globals for the server or client 81 network::Client *client_g; 82 network::Server *server_g; 75 83 76 84 namespace orxonox 77 85 { 86 ConsoleCommand(Orxonox, exit, AccessLevel::None, true); 87 ConsoleCommand(Orxonox, slomo, AccessLevel::Offline, true).setDefaultValue(0, 1.0); 88 ConsoleCommand(Orxonox, setTimeFactor, AccessLevel::Offline, false).setDefaultValue(0, 1.0); 89 90 class Testconsole : public InputBufferListener 91 { 92 public: 93 Testconsole(InputBuffer* ib) : ib_(ib) {} 94 void listen() const 95 { 96 std::cout << "> " << this->ib_->get() << std::endl; 97 } 98 void execute() const 99 { 100 std::cout << ">> " << this->ib_->get() << std::endl; 101 if (!CommandExecutor::execute(this->ib_->get())) 102 std::cout << "Error" << std::endl; 103 this->ib_->clear(); 104 } 105 void hintandcomplete() const 106 { 107 std::cout << CommandExecutor::hint(this->ib_->get()) << std::endl; 108 this->ib_->set(CommandExecutor::complete(this->ib_->get())); 109 } 110 void clear() const 111 { 112 this->ib_->clear(); 113 } 114 void removeLast() const 115 { 116 this->ib_->removeLast(); 117 } 118 void exit() const 119 { 120 CommandExecutor::execute("setInputMode 2"); 121 } 122 123 private: 124 InputBuffer* ib_; 125 }; 126 127 class Calculator 128 { 129 public: 130 static void calculate(const std::string& calculation) 131 { 132 ExprParser expr(calculation); 133 if (expr.getSuccess()) 134 { 135 if (expr.getResult() == 42.0) 136 std::cout << "Greetings from the restaurant at the end of the universe." << std::endl; 137 // FIXME: insert modifier to display in full precision 138 std::cout << "Result is: " << expr.getResult() << std::endl; 139 if (expr.getRemains() != "") 140 std::cout << "Warning: Expression could not be parsed to the end! Remains: '" 141 << expr.getRemains() << "'" << std::endl; 142 } 143 else 144 std::cout << "Cannot calculate expression: Parse error" << std::endl; 145 } 146 }; 147 ConsoleCommandShortcut(Calculator, calculate, AccessLevel::None); 148 78 149 /** 79 150 @brief Reference to the only instance of the class. … … 86 157 Orxonox::Orxonox() 87 158 { 88 this->ogre_ = new GraphicsEngine();159 this->ogre_ = &GraphicsEngine::getSingleton(); 89 160 this->timer_ = 0; 90 161 this->dataPath_ = ""; 91 162 this->auMan_ = 0; 92 163 this->inputHandler_ = 0; 93 //this->root_ = 0;94 164 // turn on frame smoothing by setting a value different from 0 95 165 this->frameSmoothingTime_ = 0.0f; 96 166 this->bAbort_ = false; 167 this->timefactor_ = 1.0f; 97 168 } 98 169 … … 103 174 { 104 175 // keep in mind: the order of deletion is very important! 105 if (this->bulletMgr_)106 delete this->bulletMgr_;107 176 if (this->orxonoxHUD_) 108 177 delete this->orxonoxHUD_; 109 178 Loader::close(); 110 Input Handler::destroy();179 InputManager::getSingleton().destroy(); 111 180 if (this->auMan_) 112 181 delete this->auMan_; 113 182 if (this->timer_) 114 183 delete this->timer_; 115 if (this->ogre_) 116 delete this->ogre_; 184 GraphicsEngine::getSingleton().destroy(); 117 185 118 186 if (client_g) … … 123 191 124 192 /** 125 * error kills orxonox 126 */ 127 void Orxonox::abortImmediate(/* some error code */) 128 { 129 //TODO: destroy and destruct everything and print nice error msg 193 @brief Immediately deletes the orxonox object. 194 Never use if you can help it while rendering! 195 */ 196 void Orxonox::abortImmediateForce() 197 { 198 COUT(1) << "*** Orxonox Error: Orxonox object was unexpectedly destroyed." << std::endl; 130 199 delete this; 131 200 } … … 136 205 void Orxonox::abortRequest() 137 206 { 207 COUT(3) << "*** Orxonox: Abort requested." << std::endl; 138 208 bAbort_ = true; 139 209 } … … 147 217 singletonRef_s = new Orxonox(); 148 218 return singletonRef_s; 149 //static Orxonox theOnlyInstance;150 //return &theOnlyInstance;151 219 } 152 220 … … 154 222 @brief Destroys the Orxonox singleton. 155 223 */ 156 void Orxonox::destroy ()224 void Orxonox::destroySingleton() 157 225 { 158 226 if (singletonRef_s) … … 174 242 std::string mode; 175 243 176 ArgReader ar = ArgReader(argc, argv);244 ArgReader ar(argc, argv); 177 245 ar.checkArgument("mode", mode, false); 178 246 ar.checkArgument("data", this->dataPath_, false); 179 247 ar.checkArgument("ip", serverIp_, false); 180 if(ar.errorHandling()) abortImmediate ();248 if(ar.errorHandling()) abortImmediateForce(); 181 249 if(mode == std::string("client")) 182 250 { … … 197 265 { 198 266 COUT(2) << "initialising server" << std::endl; 199 267 200 268 ogre_->setConfigPath(path); 201 269 ogre_->setup(); 202 270 //root_ = ogre_->getRoot(); 203 if(!ogre_->load(this->dataPath_)) abortImmediate (/* unable to load */);204 271 if(!ogre_->load(this->dataPath_)) abortImmediateForce(/* unable to load */); 272 205 273 server_g = new network::Server(); 206 274 } … … 209 277 { 210 278 COUT(2) << "initialising client" << std::endl;\ 211 279 212 280 ogre_->setConfigPath(path); 213 281 ogre_->setup(); … … 216 284 else 217 285 client_g = new network::Client(serverIp_, NETWORK_PORT); 218 if(!ogre_->load(this->dataPath_)) abortImmediate (/* unable to load */);219 } 220 286 if(!ogre_->load(this->dataPath_)) abortImmediateForce(/* unable to load */); 287 } 288 221 289 void Orxonox::standaloneInit(std::string path) 222 290 { 223 291 COUT(2) << "initialising standalone mode" << std::endl; 224 292 225 293 ogre_->setConfigPath(path); 226 294 ogre_->setup(); 227 //root_ = ogre_->getRoot(); 228 if(!ogre_->load(this->dataPath_)) abortImmediate(/* unable to load */); 229 } 230 295 if(!ogre_->load(this->dataPath_)) abortImmediateForce(/* unable to load */); 296 } 297 231 298 /** 232 299 * start modules … … 245 312 } 246 313 } 247 314 248 315 void Orxonox::clientStart(){ 249 316 ogre_->initialise(); 317 ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini"); 250 318 Factory::createClassHierarchy(); 251 252 319 320 253 321 auMan_ = new audio::AudioManager(); 254 322 255 bulletMgr_ = new BulletManager();256 257 323 Ogre::Overlay* hudOverlay = Ogre::OverlayManager::getSingleton().getByName("Orxonox/HUD1.2"); 258 orxonoxHUD_ = new HUD(); 259 orxonoxHUD_->setEnergyValue(20); 260 orxonoxHUD_->setEnergyDistr(20,20,60); 324 HUD* orxonoxHud; 325 orxonoxHud = new HUD(); 326 orxonoxHud->setEnergyValue(20); 327 orxonoxHud->setEnergyDistr(20,20,60); 261 328 hudOverlay->show(); 262 263 if( !client_g->establishConnection() ) 264 COUT(1) <<"CLIENT COULD NOT ESTABLISH CONNECTION" << std::endl; 329 330 client_g->establishConnection(); 265 331 client_g->tick(0); 266 267 332 333 268 334 //setupInputSystem(); 269 335 270 336 startRenderLoop(); 271 337 } 272 338 273 339 void Orxonox::serverStart(){ 274 340 //TODO: start modules 275 341 ogre_->initialise(); 276 342 //TODO: run engine 343 ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini"); 277 344 Factory::createClassHierarchy(); 278 345 createScene(); 279 346 setupInputSystem(); 280 347 281 348 server_g->open(); 282 349 283 350 startRenderLoop(); 284 351 } 285 352 286 353 void Orxonox::standaloneStart(){ 287 354 //TODO: start modules 288 355 ogre_->initialise(); 289 356 //TODO: run engine 357 ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini"); 290 358 Factory::createClassHierarchy(); 291 359 createScene(); 292 360 setupInputSystem(); 293 361 294 362 startRenderLoop(); 295 363 } … … 299 367 // Init audio 300 368 auMan_ = new audio::AudioManager(); 301 302 bulletMgr_ = new BulletManager();303 369 304 370 // load this file from config … … 327 393 void Orxonox::setupInputSystem() 328 394 { 329 inputHandler_ = InputHandler::getSingleton();395 inputHandler_ = &InputManager::getSingleton(); 330 396 if (!inputHandler_->initialise(ogre_->getWindowHandle(), 331 397 ogre_->getWindowWidth(), ogre_->getWindowHeight())) 332 abortImmediate(); 398 abortImmediateForce(); 399 inputHandler_->setInputMode(IM_INGAME); 333 400 } 334 401 … … 343 410 About the loop: The design is almost exactly like the one in ogre, so that 344 411 if any part of ogre registers a framelisteners, it will still behave 345 correctly. Furthermore I have taken over the time smoothing feature from346 ogre. If turned on (see orxonox constructor), it will calculate the dt_n by347 means of the recent most dt_n-1, dt_n-2, etc.412 correctly. Furthermore the time smoothing feature from ogre has been 413 implemented too. If turned on (see orxonox constructor), it will calculate 414 the dt_n by means of the recent most dt_n-1, dt_n-2, etc. 348 415 */ 349 416 void Orxonox::startRenderLoop() 350 417 { 418 InputBuffer* ib = new InputBuffer(); 419 InputManager::getSingleton().feedInputBuffer(ib); 420 Testconsole* console = new Testconsole(ib); 421 ib->registerListener(console, &Testconsole::listen, true); 422 ib->registerListener(console, &Testconsole::execute, '\r', false); 423 ib->registerListener(console, &Testconsole::execute, '\n', false); 424 ib->registerListener(console, &Testconsole::hintandcomplete, '\t', true); 425 ib->registerListener(console, &Testconsole::clear, '§', true); 426 ib->registerListener(console, &Testconsole::removeLast, '\b', true); 427 ib->registerListener(console, &Testconsole::exit, (char)0x1B, true); 428 429 // first check whether ogre root object has been created 430 if (Ogre::Root::getSingletonPtr() == 0) 431 { 432 COUT(2) << "*** Orxonox Error: Could not start rendering. No Ogre root object found" << std::endl; 433 return; 434 } 435 Ogre::Root& ogreRoot = Ogre::Root::getSingleton(); 436 437 438 // Contains the times of recently fired events 439 // eventTimes[4] is the list for the times required for the fps counter 440 std::deque<unsigned long> eventTimes[4]; 441 // Clear event times 442 for (int i = 0; i < 4; ++i) 443 eventTimes[i].clear(); 444 // fill the fps time list with zeros 445 for (int i = 0; i < 20; i++) 446 eventTimes[3].push_back(0); 447 351 448 // use the ogre timer class to measure time. 352 449 if (!timer_) … … 354 451 timer_->reset(); 355 452 356 // Contains the times of recently fired events357 std::deque<unsigned long> eventTimes[3];358 // Clear event times359 for (int i = 0; i < 3; ++i)360 eventTimes[i].clear();361 362 453 while (!bAbort_) 363 454 { 364 455 // Pump messages in all registered RenderWindows 456 // This calls the WindowEventListener objects. 365 457 Ogre::WindowEventUtilities::messagePump(); 366 458 367 459 // get current time 368 460 unsigned long now = timer_->getMilliseconds(); 461 eventTimes[3].push_back(now); 462 eventTimes[3].erase(eventTimes[3].begin()); 369 463 370 464 // create an event to pass to the frameStarted method in ogre … … 374 468 375 469 // show the current time in the HUD 376 //orxonoxHUD_->setTime((int)now, 0); 470 orxonoxHUD_->setTime((int)now, 0); 471 if (eventTimes[3].back() - eventTimes[3].front() != 0) 472 orxonoxHUD_->setRocket1((int)(20000.0f/(eventTimes[3].back() - eventTimes[3].front()))); 377 473 378 474 // 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);475 for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it) 476 it->tick((float)evt.timeSinceLastFrame * this->timefactor_); 381 477 382 478 // don't forget to call _fireFrameStarted in ogre to make sure 383 479 // everything goes smoothly 384 ogre_->frameStarted(evt); 385 480 ogreRoot._fireFrameStarted(evt); 481 482 // server still renders at the moment 386 483 //if (mode_ != SERVER) 387 ogre_->renderOneFrame(); // only render in non-server mode484 ogreRoot._updateAllRenderTargets(); // only render in non-server mode 388 485 389 486 // get current time … … 395 492 396 493 // again, just to be sure ogre works fine 397 ogre _->frameEnded(evt);494 ogreRoot._fireFrameEnded(evt); 398 495 } 399 496 } … … 408 505 { 409 506 // Calculate the average time passed between events of the given type 410 // during the last mFrameSmoothingTimeseconds.507 // during the last frameSmoothingTime_ seconds. 411 508 412 509 times.push_back(now); … … 415 512 return 0; 416 513 417 // Times up to mFrameSmoothingTime seconds old should be kept 418 unsigned long discardThreshold = 419 static_cast<unsigned long>(frameSmoothingTime_ * 1000.0f); 514 // Times up to frameSmoothingTime_ seconds old should be kept 515 unsigned long discardThreshold = (unsigned long)(frameSmoothingTime_ * 1000.0f); 420 516 421 517 // 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 518 std::deque<unsigned long>::iterator it = times.begin(); 519 // We need at least two times 520 std::deque<unsigned long>::iterator end = times.end() - 2; 521 424 522 while(it != end) 425 523 { … … 433 531 times.erase(times.begin(), it); 434 532 435 return (float)(times.back() - times.front()) / ((times.size() -1) * 1000);533 return (float)(times.back() - times.front()) / ((times.size() - 1) * 1000); 436 534 } 437 535 -
code/branches/network2/src/util/CMakeLists.txt
r1085 r1132 1 1 AUX_SOURCE_DIRECTORY(tinyxml TINYXML_SRC_FILES) 2 2 3 SET 3 SET(UTIL_SRC_FILES 4 4 ArgReader.cc 5 5 Math.cc … … 7 7 Clipboard.cc 8 8 SubString.cc 9 ExprParser.cc 9 10 MultiTypePrimitive.cc 10 11 MultiTypeString.cc 11 12 MultiTypeMath.cc 12 tolua/tolua_event.c13 tolua/tolua_is.c14 tolua/tolua_map.c15 tolua/tolua_push.c16 tolua/tolua_to.c17 13 ${TINYXML_SRC_FILES} 18 14 ) 19 15 20 ADD_LIBRARY( util SHARED ${UTIL_SRC_FILES})16 ADD_LIBRARY(util SHARED ${UTIL_SRC_FILES}) 21 17 22 18 IF(TESTING_ENABLED) … … 24 20 ENDIF(TESTING_ENABLED) 25 21 26 TARGET_LINK_LIBRARIES( 22 TARGET_LINK_LIBRARIES(util 27 23 ${OGRE_LIBRARIES} 28 ${Lua_LIBRARIES}29 ${Lua_LIBRARY}30 24 ) 31 25 -
code/branches/network2/src/util/String.cc
r1064 r1132 274 274 if (str.size() == 0) 275 275 return str; 276 else if (str.size() == 1) 277 { 278 //TODO: decide whether we need the commented code 279 /*if (str[0] != '\\') 280 return ""; 281 else*/ 282 return str; 283 } 276 284 277 285 std::string output = "";
Note: See TracChangeset
for help on using the changeset viewer.