Changeset 917 for code/branches/network/src
- Timestamp:
- Mar 21, 2008, 6:14:31 PM (17 years ago)
- Location:
- code/branches/network/src
- Files:
-
- 2 added
- 3 deleted
- 18 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/Client.h
r888 r917 16 16 #include <string> 17 17 18 #include " orxonox/objects/Tickable.h"18 #include "core/Tickable.h" 19 19 20 20 #include "NetworkPrereqs.h" -
code/branches/network/src/network/Server.cc
r912 r917 13 13 #include <iostream> 14 14 15 #include "util/Sleep.h" 15 16 #include "ConnectionManager.h" 16 17 #include "PacketTypes.h" … … 112 113 processQueue(); 113 114 updateGamestate(); 115 114 116 sleep(1); // TODO remove 115 117 return; -
code/branches/network/src/network/Server.h
r888 r917 16 16 #include <string> 17 17 18 #include " orxonox/objects/Tickable.h"18 #include "core/Tickable.h" 19 19 20 20 #include "PacketManager.h" -
code/branches/network/src/orxonox/Orxonox.cc
r905 r917 44 44 #include <OgreOverlay.h> 45 45 #include <OgreOverlayManager.h> 46 #include <OgreTimer.h> 47 #include <OgreWindowEventUtilities.h> 46 48 47 49 //****** OIS ******* … … 56 58 #include "util/Sleep.h" 57 59 58 // loader and audio 59 //#include "loader/LevelLoader.h" 60 // audio 60 61 #include "audio/AudioManager.h" 61 62 … … 69 70 70 71 // objects 71 #include "objects/Tickable.h"72 72 #include "tools/Timer.h" 73 #include " objects/NPC.h"73 #include "tools/OrxListener.h" 74 74 #include "core/ArgReader.h" 75 #include "core/Debug.h" 75 76 #include "core/Factory.h" 76 #include "core/Debug.h"77 77 #include "core/Loader.h" 78 #include "core/Tickable.h" 78 79 #include "hud/HUD.h" 79 80 #include "objects/weapon/BulletManager.h" … … 84 85 namespace orxonox 85 86 { 86 // put this in a seperate Class or solve the problem in another fashion 87 class OrxListener : public Ogre::FrameListener 88 { 89 public: 90 OrxListener(OIS::Keyboard *keyboard, audio::AudioManager* auMan, gameMode mode) 91 { 92 mKeyboard = keyboard; 93 mode_=mode; 94 auMan_ = auMan; 95 } 96 97 bool frameStarted(const Ogre::FrameEvent& evt) 98 { 99 auMan_->update(); 100 updateAI(); 101 102 // if(mode_ == SERVER) 103 // server_g->tick(evt.timeSinceLastFrame); 104 // else if(mode_ == CLIENT) 105 // client_g->tick(evt.timeSinceLastFrame); 106 107 usleep(10); 108 109 if(mode_!=CLIENT){ 110 mKeyboard->capture(); 111 return !mKeyboard->isKeyDown(OIS::KC_ESCAPE); 112 }else 113 return true; 114 } 115 116 void updateAI() 117 { 118 for(Iterator<NPC> it = ObjectList<NPC>::start(); it; ++it) 119 { 120 it->update(); 121 } 122 } 123 124 private: 125 gameMode mode_; 126 OIS::Keyboard *mKeyboard; 127 audio::AudioManager* auMan_; 128 }; 129 130 // init static singleton reference of Orxonox 87 /// init static singleton reference of Orxonox 131 88 Orxonox* Orxonox::singletonRef_ = NULL; 132 89 … … 138 95 this->ogre_ = new GraphicsEngine(); 139 96 this->dataPath_ = ""; 140 // this->loader_ = 0;141 97 this->auMan_ = 0; 142 98 this->singletonRef_ = 0; … … 146 102 this->frameListener_ = 0; 147 103 this->root_ = 0; 104 // turn frame smoothing on by setting a value different from 0 105 this->frameSmoothingTime_ = 0.0f; 106 this->bAbort_ = false; 148 107 } 149 108 … … 159 118 * initialization of Orxonox object 160 119 * @param argc argument counter 161 * @param argv list of argumen ts120 * @param argv list of argumenst 162 121 * @param path path to config (in home dir or something) 163 122 */ … … 281 240 //TODO: destroy and destruct everything and print nice error msg 282 241 delete this; 242 } 243 244 /** 245 Asks the mainloop nicely to abort. 246 */ 247 void Orxonox::abortRequest() 248 { 249 bAbort_ = true; 283 250 } 284 251 … … 365 332 } 366 333 367 /**368 *369 * @param370 */371 334 void Orxonox::createScene(void) 372 335 { … … 383 346 384 347 Ogre::Overlay* hudOverlay = Ogre::OverlayManager::getSingleton().getByName("Orxonox/HUD1.2"); 385 HUD* orxonoxHud;386 orxonoxH ud= new HUD();387 orxonoxH ud->setEnergyValue(20);388 orxonoxH ud->setEnergyDistr(20,20,60);348 //HUD* orxonoxHud; 349 orxonoxHUD_ = new HUD(); 350 orxonoxHUD_->setEnergyValue(20); 351 orxonoxHUD_->setEnergyDistr(20,20,60); 389 352 hudOverlay->show(); 390 353 … … 398 361 399 362 400 /**401 *402 */403 363 void Orxonox::setupScene() 404 364 { … … 451 411 void Orxonox::createFrameListener() 452 412 { 453 TickFrameListener* TickFL = new TickFrameListener(); 454 ogre_->getRoot()->addFrameListener(TickFL); 455 456 TimerFrameListener* TimerFL = new TimerFrameListener(); 457 ogre_->getRoot()->addFrameListener(TimerFL); 458 459 //if(mode_!=CLIENT) // FIXME just a hack ------- remove this in future 460 frameListener_ = new OrxListener(keyboard_, auMan_, mode_); 461 ogre_->getRoot()->addFrameListener(frameListener_); 413 frameListener_ = new OrxListener(keyboard_, auMan_, mode_); 462 414 } 463 415 … … 477 429 ms.height = height; 478 430 } 479 ogre_->getRoot()->startRendering(); 431 mainLoop(); 432 } 433 434 /** 435 Main loop of the orxonox game. 436 This is a new solution, using the ogre engine instead of beeing used by it. 437 An alternative solution would be to simply use the timer of the Root object, 438 but that implies using Ogre in any case. There would be no way to test 439 our code without the help of the root object. 440 There's even a chance that we can dispose of the root object entirely 441 in server mode. 442 About the loop: The design is almost exactly like the one in ogre, so that 443 if any part of ogre registers a framelisteners, it will still behave 444 correctly. Furthermore I have taken over the time smoothing feature from 445 ogre. If turned on (see orxonox constructor), it will calculate the dt_n by 446 means of the recent most dt_n-1, dt_n-2, etc. 447 */ 448 void Orxonox::mainLoop() 449 { 450 // use the ogre timer class to measure time. 451 Ogre::Timer *timer = new Ogre::Timer(); 452 timer->reset(); 453 454 // Contains the times of recently fired events 455 std::deque<unsigned long> eventTimes[3]; 456 // Clear event times 457 for (int i = 0; i < 3; ++i) 458 eventTimes[i].clear(); 459 460 while (!bAbort_) 461 { 462 // Pump messages in all registered RenderWindows 463 Ogre::WindowEventUtilities::messagePump(); 464 465 // get current time 466 unsigned long now = timer->getMilliseconds(); 467 468 // create an event to pass to the frameStarted method in ogre 469 Ogre::FrameEvent evt; 470 evt.timeSinceLastEvent = calculateEventTime(now, eventTimes[0]); 471 evt.timeSinceLastFrame = calculateEventTime(now, eventTimes[1]); 472 473 // show the current time in the HUD 474 orxonoxHUD_->setTime((int)now, 0); 475 476 // don't forget to call _fireFrameStarted in ogre to make sure 477 // everything goes smoothly 478 if (!ogre_->getRoot()->_fireFrameStarted(evt)) 479 break; 480 481 // Iterate through all Tickables and call their tick(dt) function 482 for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ) 483 (it++)->tick((float)evt.timeSinceLastFrame); 484 485 if (mode_ != SERVER) 486 { 487 // only render in non-server mode 488 ogre_->getRoot()->_updateAllRenderTargets(); 489 } 490 491 // get current time 492 now = timer->getMilliseconds(); 493 494 // create an event to pass to the frameEnded method in ogre 495 evt.timeSinceLastEvent = calculateEventTime(now, eventTimes[0]); 496 evt.timeSinceLastFrame = calculateEventTime(now, eventTimes[2]); 497 498 // again, just to be sure ogre works fine 499 if (!ogre_->getRoot()->_fireFrameEnded(evt)) 500 break; 501 } 502 } 503 504 /** 505 Method for calculating the average time between recently fired events. 506 Code directly taken from OgreRoot.cc 507 @param now The current time in ms. 508 @param type The type of event to be considered. 509 */ 510 float Orxonox::calculateEventTime(unsigned long now, std::deque<unsigned long> ×) 511 { 512 // Calculate the average time passed between events of the given type 513 // during the last mFrameSmoothingTime seconds. 514 515 times.push_back(now); 516 517 if(times.size() == 1) 518 return 0; 519 520 // Times up to mFrameSmoothingTime seconds old should be kept 521 unsigned long discardThreshold = 522 static_cast<unsigned long>(frameSmoothingTime_ * 1000.0f); 523 524 // Find the oldest time to keep 525 std::deque<unsigned long>::iterator it = times.begin(), 526 end = times.end()-2; // We need at least two times 527 while(it != end) 528 { 529 if (now - *it > discardThreshold) 530 ++it; 531 else 532 break; 533 } 534 535 // Remove old times 536 times.erase(times.begin(), it); 537 538 return (float)(times.back() - times.front()) / ((times.size()-1) * 1000); 480 539 } 481 540 } -
code/branches/network/src/orxonox/Orxonox.h
r888 r917 9 9 10 10 #include <string> 11 #include <deque> 11 12 12 13 #include <OgrePrerequisites.h> … … 37 38 // not sure if this should be private 38 39 void die(/* some error code */); 40 void abortRequest(); 39 41 static Orxonox* getSingleton(); 40 42 inline Ogre::SceneManager* getSceneManager() { return ogre_->getSceneManager(); }; … … 65 67 void createFrameListener(); 66 68 void startRenderLoop(); 69 void mainLoop(); 70 void updateTimers(float); 71 float calculateEventTime(unsigned long, std::deque<unsigned long>&); 67 72 68 73 private: … … 78 83 OrxListener* frameListener_; 79 84 Ogre::Root* root_; 85 // TODO: make this a config-value by creating a config class for orxonox 86 float frameSmoothingTime_; 87 // little hack to actually show something dynamic in the HUD 88 HUD* orxonoxHUD_; 89 bool bAbort_; 80 90 81 91 // this is used to identify the mode (server/client/...) we're in -
code/branches/network/src/orxonox/OrxonoxPlatform.h
r790 r917 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" … … 251 262 #endif 252 263 264 265 // Define the english written operators like and, or, xor 266 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC 267 # include <iso646.h> 268 #endif 269 253 270 } /* namespace orxonox */ 254 271 -
code/branches/network/src/orxonox/OrxonoxStableHeaders.h
r871 r917 73 73 //#include "audio/AudioManager.h" 74 74 75 //#include "core/CoreIncludes.h"75 #include "core/CoreIncludes.h" 76 76 #include "core/BaseObject.h" 77 77 //#include "core/ArgReader.h" 78 78 #include "core/Error.h" 79 #include "core/Loader.h" 80 #include "core/XMLPort.h" 81 #include "core/Tickable.h" 79 82 80 83 #include "network/Synchronisable.h" … … 87 90 #include "util/String2Number.h" 88 91 #include "util/Tokenizer.h" 92 #include "util/Multitype.h" 93 #include "util/MultiTypeMath.h" 94 #include "util/MultiTypePrimitive.h" 95 #include "util/MultiTypeString.h" 96 #include "util/substring.h" 97 #include "util/XMLIncludes.h" 98 89 99 #include "util/tinyxml/ticpp.h" 90 100 #include "util/tinyxml/tinyxml.h" … … 106 116 //#include "objects/Skybox.h" 107 117 //#include "objects/SpaceShipSteeringObject.h" 108 #include "objects/Tickable.h"109 118 #include "objects/WorldEntity.h" 110 119 //#include "particle/ParticleInterface.h" -
code/branches/network/src/orxonox/core/Identifier.h
r871 r917 206 206 }; 207 207 208 std::ostream& operator<<(std::ostream& out, const std::list<const Identifier*>& list);208 _CoreExport std::ostream& operator<<(std::ostream& out, const std::list<const Identifier*>& list); 209 209 210 210 -
code/branches/network/src/orxonox/objects/WorldEntity.h
r871 r917 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 -
code/branches/network/src/orxonox/objects/weapon/BulletManager.h
r871 r917 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 { -
code/branches/network/src/orxonox/tools/OrxListener.cc
r916 r917 31 31 #include "objects/NPC.h" 32 32 #include "audio/AudioManager.h" 33 #include "Orxonox.h" 33 34 #include "OrxListener.h" 34 35 35 36 namespace orxonox 36 37 { 37 OrxListener::OrxListener( audio::AudioManager* auMan, gameMode mode)38 OrxListener::OrxListener(OIS::Keyboard *keyboard, audio::AudioManager* auMan, gameMode mode) 38 39 { 40 keyboard_ = keyboard; 39 41 mode_=mode; 40 42 auMan_ = auMan; … … 45 47 auMan_->update(); 46 48 updateAI(); 49 50 keyboard_->capture(); 51 if (keyboard_->isKeyDown(OIS::KC_ESCAPE)) 52 Orxonox::getSingleton()->abortRequest(); 47 53 } 48 54 -
code/branches/network/src/orxonox/tools/OrxListener.h
r916 r917 34 34 #define _OrxListener_H__ 35 35 36 #include <OIS/OISPrereqs.h> 37 36 38 #include "../OrxonoxPrereqs.h" 37 39 #include "audio/AudioPrereqs.h" 38 40 #include "Orxonox.h" 39 #include " objects/Tickable.h"41 #include "core/Tickable.h" 40 42 41 43 namespace orxonox … … 44 46 { 45 47 public: 46 OrxListener( audio::AudioManager* auMan, gameMode mode);48 OrxListener(OIS::Keyboard *keyboard, audio::AudioManager* auMan, gameMode mode); 47 49 48 50 void tick(float dt); … … 52 54 gameMode mode_; 53 55 audio::AudioManager* auMan_; 56 OIS::Keyboard *keyboard_; 54 57 }; 55 58 } -
code/branches/network/src/orxonox/tools/Timer.cc
r871 r917 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Fabian 'x3n' Landau 23 * Co-authors: 24 * ... 25 * 26 */ 27 28 #include "OrxonoxStableHeaders.h" 29 1 30 #include "core/CoreIncludes.h" 2 31 #include "Timer.h" … … 17 46 this->time_ = 0; 18 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 19 73 } -
code/branches/network/src/orxonox/tools/Timer.h
r871 r917 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 -
code/branches/network/src/util/Math.h
r871 r917 147 147 148 148 #endif /* _Math_H__ */ 149 -
code/branches/network/src/util/MultiTypeMath.h
r871 r917 153 153 }; 154 154 155 std::ostream& operator<<(std::ostream& out, MultiTypeMath& mtm);155 _UtilExport std::ostream& operator<<(std::ostream& out, MultiTypeMath& mtm); 156 156 157 157 #endif /* _MultiTypeMath_H__ */ -
code/branches/network/src/util/MultiTypePrimitive.h
r871 r917 175 175 }; 176 176 177 std::ostream& operator<<(std::ostream& out, const MultiTypePrimitive& mtp);177 _UtilExport std::ostream& operator<<(std::ostream& out, const MultiTypePrimitive& mtp); 178 178 179 179 #endif /* _MultiTypePrimitive_H__ */ -
code/branches/network/src/util/MultiTypeString.h
r871 r917 109 109 }; 110 110 111 std::ostream& operator<<(std::ostream& out, MultiTypeString& mts);111 _UtilExport std::ostream& operator<<(std::ostream& out, MultiTypeString& mts); 112 112 113 113 #endif /* _MultiTypeString_H__ */ -
code/branches/network/src/util/Sleep.h
r790 r917 1 // hack for the usleep/Sleep problem 2 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Reto Grieder 23 * Co-authors: 24 * ... 25 * 26 */ 27 28 /** 29 @file Sleep.h 30 @brief Macros for using sleep() and usleep() under windows 31 */ 32 33 #include "OrxonoxPlatform.h" 34 35 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 3 36 # include <windows.h> 4 # define usleep(x) Sleep((x)/1000) 37 # define usleep(x) Sleep((x) / 1000) 38 # define msleep(x) Sleep(x) 39 # define sleep(x) Sleep((x) * 1000) 5 40 #else 6 41 # include <unistd.h> 42 # define msleep(x) uleep((x) * 1000) 7 43 #endif -
code/branches/network/src/util/XMLIncludes.h
r871 r917 1 #include "util/tinyxml/TinyXMLPrereqs.h" 1 //----------------------------------------------------------------------- 2 // Forward declarations 3 //----------------------------------------------------------------------- 4 5 class TiXmlString; 6 class TiXmlOutStream; 7 class TiXmlNode; 8 class TiXmlHandle; 9 class TiXmlDocument; 10 class TiXmlElement; 11 class TiXmlComment; 12 class TiXmlUnknown; 13 class TiXmlAttribute; 14 class TiXmlText; 15 class TiXmlDeclaration; 16 class TiXmlParsingData; 17 18 namespace ticpp 19 { 20 class Document; 21 class Element; 22 class Declaration; 23 class StylesheetReference; 24 class Text; 25 class Comment; 26 class Attribute; 27 } 2 28 3 29 namespace orxonox
Note: See TracChangeset
for help on using the changeset viewer.