Changeset 1621
- Timestamp:
- Jun 23, 2008, 9:12:59 PM (16 years ago)
- Location:
- code/branches/hud
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/hud/src/orxonox/GraphicsEngine.h
r1618 r1621 72 72 int getWindowHeight() const; 73 73 float getWindowAspectRatio() const; 74 float getAverageF PS() const75 { if (renderWindow_) return this->renderWindow_->getAverageFPS(); else return 0.0f; }76 float getAverageRTR() const { return this->renderTimeRatio_; }77 void setAverage RTR(float rtr) { this->renderTimeRatio_ = rtr; }74 float getAverageFramesPerSecond() const { return this->avgFramesPerSecond_; } 75 float getAverageTickTime() const { return this->avgTickTime_; } 76 void setAverageTickTime(float tickTime) { this->avgTickTime_ = tickTime; } 77 void setAverageFramesPerSecond(float fps) { this->avgFramesPerSecond_ = fps; } 78 78 79 79 void setWindowActivity(bool activity) … … 113 113 int ogreLogLevelCritical_; //!< Corresponding Orxonx debug level for LL_CRITICAL 114 114 unsigned int detailLevelParticle_; //!< Detail level of particle effects (0: off, 1: low, 2: normal, 3: high) 115 float renderTimeRatio_; //!< Ratio between time required to render a frame and to tick() it 115 float avgTickTime_; //!< time in ms to tick() one frame 116 float avgFramesPerSecond_; //!< number of frames processed in one second 116 117 }; 117 118 } -
code/branches/hud/src/orxonox/Orxonox.cc
r1618 r1621 103 103 //, auMan_(0) 104 104 , timer_(0) 105 // turn on frame smoothing by setting a value different from 0106 , frameSmoothingTime_(0.0f)107 //orxonoxHUD_(0)108 105 , bAbort_(false) 109 106 , timefactor_(1.0f) … … 438 435 439 436 440 // Contains the times of recently fired events441 // eventTimes[4] is the list for the times required for the fps counter442 std::deque<unsigned long> eventTimes[3];443 // Clear event times444 for (int i = 0; i < 3; ++i)445 eventTimes[i].clear();446 447 437 // use the ogre timer class to measure time. 448 438 if (!timer_) 449 439 timer_ = new Ogre::Timer(); 440 441 unsigned long frameCount = 0; 442 443 const unsigned long refreshTime = 3000000; 444 unsigned long refreshStartTime = 0; 445 unsigned long tickTime = 0; 446 unsigned long oldFrameCount = 0; 447 448 unsigned long timeBeforeTick = 0; 449 unsigned long timeBeforeTickOld = 0; 450 unsigned long timeAfterTick = 0; 451 452 COUT(3) << "Orxonox: Starting the main loop." << std::endl; 453 450 454 timer_->reset(); 451 452 float renderTime = 0.0f;453 float frameTime = 0.0f;454 // clock_t time = 0;455 456 COUT(3) << "Orxonox: Starting the main loop." << std::endl;457 455 while (!bAbort_) 458 456 { 459 457 // get current time 460 unsigned long now = timer_->getMilliseconds(); 461 462 // create an event to pass to the frameStarted method in ogre 463 Ogre::FrameEvent evt; 464 evt.timeSinceLastEvent = calculateEventTime(now, eventTimes[0]); 465 evt.timeSinceLastFrame = calculateEventTime(now, eventTimes[1]); 466 frameTime += evt.timeSinceLastFrame; 467 468 // OverlayGroup::getHUD().setTime(now); 469 if (mode_ != DEDICATED && frameTime > 0.4f) 470 { 471 GraphicsEngine::getSingleton().setAverageRTR(renderTime / frameTime); 472 frameTime = 0.0f; 473 renderTime = 0.0f; 474 } 475 476 // tick the core 477 Core::tick((float)evt.timeSinceLastFrame); 458 timeBeforeTickOld = timeBeforeTick; 459 timeBeforeTick = timer_->getMicroseconds(); 460 float dt = (timeBeforeTick - timeBeforeTickOld) / 1000000.0; 461 462 463 // tick the core (needs real time for input and tcl thread management) 464 Core::tick(dt); 465 478 466 // Call those objects that need the real time 479 467 for (Iterator<TickableReal> it = ObjectList<TickableReal>::start(); it; ++it) 480 it->tick( (float)evt.timeSinceLastFrame);468 it->tick(dt); 481 469 // Call the scene objects 482 470 for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it) 483 it->tick((float)evt.timeSinceLastFrame * this->timefactor_); 484 //AudioManager::tick(); 471 it->tick(dt * this->timefactor_); 472 473 // call server/client with normal dt 485 474 if (client_g) 486 client_g->tick( (float)evt.timeSinceLastFrame);475 client_g->tick(dt * this->timefactor_); 487 476 if (server_g) 488 server_g->tick((float)evt.timeSinceLastFrame); 477 server_g->tick(dt * this->timefactor_); 478 479 480 // get current time once again 481 timeAfterTick = timer_->getMicroseconds(); 482 483 tickTime += timeAfterTick - timeBeforeTick; 484 if (timeAfterTick > refreshStartTime + refreshTime) 485 { 486 GraphicsEngine::getSingleton().setAverageTickTime( 487 (float)tickTime * 0.001 / (frameCount - oldFrameCount)); 488 GraphicsEngine::getSingleton().setAverageFramesPerSecond( 489 (float)(frameCount - oldFrameCount) / (timeAfterTick - refreshStartTime) * 1000000.0); 490 oldFrameCount = frameCount; 491 tickTime = 0; 492 refreshStartTime = timeAfterTick; 493 } 494 489 495 490 496 // don't forget to call _fireFrameStarted in ogre to make sure 491 497 // everything goes smoothly 498 Ogre::FrameEvent evt; 499 evt.timeSinceLastFrame = dt; 500 evt.timeSinceLastEvent = dt; // note: same time, but shouldn't matter anyway 492 501 ogreRoot._fireFrameStarted(evt); 493 494 // get current time495 now = timer_->getMilliseconds();496 calculateEventTime(now, eventTimes[2]);497 502 498 503 if (mode_ != DEDICATED) … … 501 506 // This calls the WindowEventListener objects. 502 507 Ogre::WindowEventUtilities::messagePump(); 508 // make sure the window stays active even when not focused 509 // (probably only necessary on windows) 503 510 GraphicsEngine::getSingleton().setWindowActivity(true); 504 511 … … 507 514 } 508 515 509 // get current time510 now = timer_->getMilliseconds();511 512 // create an event to pass to the frameEnded method in ogre513 evt.timeSinceLastEvent = calculateEventTime(now, eventTimes[0]);514 renderTime += calculateEventTime(now, eventTimes[2]);515 516 516 // again, just to be sure ogre works fine 517 ogreRoot._fireFrameEnded(evt); 518 //msleep(500); 517 ogreRoot._fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted 518 519 ++frameCount; 519 520 } 520 521 … … 526 527 return true; 527 528 } 528 529 /**530 Method for calculating the average time between recently fired events.531 Code directly taken from OgreRoot.cc532 @param now The current time in ms.533 @param type The type of event to be considered.534 */535 float Orxonox::calculateEventTime(unsigned long now, std::deque<unsigned long> ×)536 {537 // Calculate the average time passed between events of the given type538 // during the last frameSmoothingTime_ seconds.539 540 times.push_back(now);541 542 if(times.size() == 1)543 return 0;544 545 // Times up to frameSmoothingTime_ seconds old should be kept546 unsigned long discardThreshold = (unsigned long)(frameSmoothingTime_ * 1000.0f);547 548 // Find the oldest time to keep549 std::deque<unsigned long>::iterator it = times.begin();550 // We need at least two times551 std::deque<unsigned long>::iterator end = times.end() - 2;552 553 while(it != end)554 {555 if (now - *it > discardThreshold)556 ++it;557 else558 break;559 }560 561 // Remove old times562 times.erase(times.begin(), it);563 564 return (float)(times.back() - times.front()) / ((times.size() - 1) * 1000);565 }566 529 } -
code/branches/hud/src/orxonox/Orxonox.h
r1613 r1621 62 62 63 63 void abortRequest(); 64 //inline audio::AudioManager* getAudioManagerPointer() { return auMan_; };65 64 66 65 static Orxonox* getSingleton(); … … 98 97 //audio::AudioManager* auMan_; //!< audio manager 99 98 Ogre::Timer* timer_; //!< Main loop timer 100 // TODO: make this a config-value by creating a config class for orxonox101 float frameSmoothingTime_;102 99 bool bAbort_; //!< aborts the render loop if true 103 100 float timefactor_; //!< A factor to change the gamespeed -
code/branches/hud/src/orxonox/OrxonoxPrereqs.h
r1614 r1621 62 62 namespace orxonox 63 63 { 64 namespace LODParticle 65 { 66 enum LOD 64 namespace LODParticle 67 65 { 68 off = 0, 69 low = 1, 70 normal = 2, 71 high = 3 72 }; 73 } 66 enum LOD 67 { 68 off = 0, 69 low = 1, 70 normal = 2, 71 high = 3 72 }; 73 } 74 74 75 class GraphicsEngine;76 class Orxonox;75 class GraphicsEngine; 76 class Orxonox; 77 77 78 class RadarViewable;79 class Radar;80 class RadarListener;78 class RadarViewable; 79 class Radar; 80 class RadarListener; 81 81 82 // objects83 class Ambient;84 class Backlight;85 class Camera;86 class Fighter;87 class Model;88 class NPC;89 class ParticleSpawner;90 class Skybox;91 class SpaceShip;92 class SpaceShipAI;93 class WorldEntity;82 // objects 83 class Ambient; 84 class Backlight; 85 class Camera; 86 class Fighter; 87 class Model; 88 class NPC; 89 class ParticleSpawner; 90 class Skybox; 91 class SpaceShip; 92 class SpaceShipAI; 93 class WorldEntity; 94 94 95 class Projectile;96 class BillboardProjectile;97 class RotatingProjectile;98 class ParticleProjectile;95 class Projectile; 96 class BillboardProjectile; 97 class RotatingProjectile; 98 class ParticleProjectile; 99 99 100 class AmmunitionDump; 101 class Bullet; 102 class BulletManager; 103 class BaseWeapon; 104 class BarrelGun; 105 class WeaponStation; 100 // tools 101 class BillboardSet; 102 class Light; 103 class Mesh; 104 class ParticleInterface; 105 template <class T> 106 class Timer; 106 107 107 // tools 108 class BillboardSet; 109 class Light; 110 class Mesh; 111 template <class T> 112 class Timer; 113 class TimerBase; 114 115 // particle 116 class ParticleInterface; 117 118 // hud 119 class BarOverlayElement; 120 class BarOverlayElementFactory; 121 class OverlayGroup; 122 class OrxonoxOverlay; 123 class HUDNavigation; 124 class RadarObject; 125 class RadarOverlayElement; 126 class RadarOverlayElementFactory; 127 128 //console 129 class InGameConsole; 108 // overlays 109 class BarColour; 110 class DebugFPSText; 111 class DebugRTRText; 112 class HUDBar; 113 class HUDNavigation; 114 class HUDRadar; 115 class HUDSpeedBar; 116 class InGameConsole; 117 class OrxonoxOverlay; 118 class OverlayGroup; 119 class OverlayText; 130 120 } 131 121 … … 138 128 } 139 129 140 141 130 #endif /* _OrxonoxPrereqs_H__ */ -
code/branches/hud/src/orxonox/overlays/debug/DebugFPSText.cc
r1619 r1621 49 49 void DebugFPSText::tick(float dt) 50 50 { 51 float fps = GraphicsEngine::getSingleton().getAverageF PS();51 float fps = GraphicsEngine::getSingleton().getAverageFramesPerSecond(); 52 52 this->text_->setCaption(this->getCaption() + convertToString(fps)); 53 53 } -
code/branches/hud/src/orxonox/overlays/debug/DebugRTRText.cc
r1619 r1621 49 49 void DebugRTRText::tick(float dt) 50 50 { 51 float rtr = GraphicsEngine::getSingleton().getAverage RTR();51 float rtr = GraphicsEngine::getSingleton().getAverageTickTime(); 52 52 this->text_->setCaption(this->getCaption() + convertToString(rtr)); 53 53 } -
code/branches/hud/src/orxonox/overlays/hud/HUDNavigation.cc
r1616 r1621 101 101 102 102 XMLPortParam(HUDNavigation, "font", setFont, getFont, xmlElement, mode); 103 XMLPortParam(HUDNavigation, "text size", setTextSize, getTextSize, xmlElement, mode);104 XMLPortParam(HUDNavigation, "nav markersize", setNavMarkerSize, getNavMarkerSize, xmlElement, mode);105 XMLPortParam(HUDNavigation, "aim markersize", setAimMarkerSize, getAimMarkerSize, xmlElement, mode);103 XMLPortParam(HUDNavigation, "textSize", setTextSize, getTextSize, xmlElement, mode); 104 XMLPortParam(HUDNavigation, "navMarkerSize", setNavMarkerSize, getNavMarkerSize, xmlElement, mode); 105 XMLPortParam(HUDNavigation, "aimMarkerSize", setAimMarkerSize, getAimMarkerSize, xmlElement, mode); 106 106 107 107 if (mode == XMLPort::LoadObject) -
code/branches/hud/visual_studio/vc8/audio.vcproj
r1024 r1621 82 82 InheritedPropertySheets="$(SolutionDir)base_properties_release.vsprops;..\audio_properties.vsprops" 83 83 CharacterSet="1" 84 WholeProgramOptimization=" 1"84 WholeProgramOptimization="0" 85 85 > 86 86 <Tool -
code/branches/hud/visual_studio/vc8/ois.vcproj
r1567 r1621 24 24 InheritedPropertySheets="..\directory_properties.vsprops" 25 25 CharacterSet="2" 26 WholeProgramOptimization=" 1"26 WholeProgramOptimization="0" 27 27 > 28 28 <Tool -
code/branches/hud/visual_studio/vc8/util.vcproj
r1502 r1621 82 82 InheritedPropertySheets="$(SolutionDir)base_properties_release.vsprops;..\util_properties.vsprops" 83 83 CharacterSet="1" 84 WholeProgramOptimization=" 1"84 WholeProgramOptimization="0" 85 85 > 86 86 <Tool
Note: See TracChangeset
for help on using the changeset viewer.