Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/weapon_system_fw/src/hud/test_overlay.cc @ 823

Last change on this file since 823 was 289, checked in by rgrieder, 17 years ago
  • updated the source files and CMLs
  • adjusted resources.cfg for the new hud overlay
File size: 3.7 KB
Line 
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 modify
8 *   it under the terms of the GNU General Public License as published by
9 *   the Free Software Foundation, either version 3 of the License, or
10 *   (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, see <http://www.gnu.org/licenses/>.
19 *
20 *
21 *   Author:
22 *      HUD design: Yuning Chai
23 *      Implementation: Yuning Chai
24 *   Co-authors:
25 *      Implementation: Reto Grieder
26 *
27 */
28
29//#include "OgreMath.h"
30//#include "OgreVector3.h"
31#include "OgreStringConverter.h"
32#include "OgreOverlayManager.h"
33#include "OgreOverlay.h"
34#include "OgreOverlayElement.h"
35#include "OgreRenderWindow.h"
36#include "OgreRenderTarget.h"
37
38#include "test_overlay.h"
39
40
41namespace orxonox {
42namespace hud {
43  using namespace Ogre;
44
45  TestOverlay::TestOverlay(RenderWindow *window)
46    :window_(window)
47  {
48    //TODO: write safe guard
49    overlay_ = OverlayManager::getSingleton().getByName("Core/DebugOverlay");
50  }
51
52
53  TestOverlay::~TestOverlay()
54  {
55  }
56
57
58  void TestOverlay::show()
59  {
60    //TODO: safe guard
61    overlay_->show();
62  }
63
64
65  void TestOverlay::hide()
66  {
67    //TODO: safe guard
68    overlay_->hide();
69  }
70
71
72  void TestOverlay::setDebugText(Ogre::String &str)
73  {
74    debugText_ = str;
75  }
76
77
78  bool TestOverlay::tick(unsigned long, Ogre::Real)
79  {
80    static String currFps = "Current FPS: ";
81    static String avgFps = "Average FPS: ";
82    static String bestFps = "Best FPS: ";
83    static String worstFps = "Worst FPS: ";
84    static String tris = "Triangle Count: ";
85    static String batches = "Batch Count: ";
86
87    // update stats when necessary
88    try {
89      OverlayElement* guiAvg = OverlayManager::getSingleton()
90        .getOverlayElement("Core/AverageFps");
91      OverlayElement* guiCurr = OverlayManager::getSingleton()
92        .getOverlayElement("Core/CurrFps");
93      OverlayElement* guiBest = OverlayManager::getSingleton()
94        .getOverlayElement("Core/BestFps");
95      OverlayElement* guiWorst = OverlayManager::getSingleton()
96        .getOverlayElement("Core/WorstFps");
97
98      const RenderTarget::FrameStats& stats = window_->getStatistics();
99      guiAvg->setCaption(avgFps + StringConverter::toString(stats.avgFPS));
100      guiCurr->setCaption(currFps + StringConverter::toString(stats.lastFPS));
101      guiBest->setCaption(bestFps + StringConverter::toString(stats.bestFPS)
102        +" "+StringConverter::toString(stats.bestFrameTime)+" ms");
103      guiWorst->setCaption(worstFps + StringConverter::toString(stats.worstFPS)
104        +" "+StringConverter::toString(stats.worstFrameTime)+" ms");
105
106      OverlayElement* guiTris = OverlayManager::getSingleton()
107        .getOverlayElement("Core/NumTris");
108      guiTris->setCaption(tris + StringConverter::toString(stats.triangleCount));
109
110      OverlayElement* guiBatches = OverlayManager::getSingleton()
111        .getOverlayElement("Core/NumBatches");
112      guiBatches->setCaption(batches
113        + StringConverter::toString(stats.batchCount));
114
115      OverlayElement* guiDbg = OverlayManager::getSingleton()
116        .getOverlayElement("Core/DebugText");
117      guiDbg->setCaption(debugText_);
118    }
119    catch(...) { /* ignore */ }
120
121    return true;
122  }
123}
124}
Note: See TracBrowser for help on using the repository browser.