1 | /* |
---|
2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
3 | * > www.orxonox.net < |
---|
4 | * |
---|
5 | * |
---|
6 | * License notice: |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the GNU General Public License |
---|
10 | * as published by the Free Software Foundation; either version 2 |
---|
11 | * of the License, or (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
21 | * |
---|
22 | * Author: |
---|
23 | * Reto Grieder |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | #include "OrxonoxStableHeaders.h" |
---|
30 | #include "GSIO.h" |
---|
31 | |
---|
32 | #include <OgreFrameListener.h> |
---|
33 | #include <OgreRoot.h> |
---|
34 | #include <OgreTimer.h> |
---|
35 | |
---|
36 | #include "core/ConsoleCommand.h" |
---|
37 | #include "core/TclThreadManager.h" |
---|
38 | #include "GraphicsEngine.h" |
---|
39 | |
---|
40 | namespace orxonox |
---|
41 | { |
---|
42 | GSIO::GSIO() |
---|
43 | : GameState("io") |
---|
44 | //, timer_(0) |
---|
45 | { |
---|
46 | } |
---|
47 | |
---|
48 | GSIO::~GSIO() |
---|
49 | { |
---|
50 | } |
---|
51 | |
---|
52 | void GSIO::enter() |
---|
53 | { |
---|
54 | } |
---|
55 | |
---|
56 | void GSIO::leave() |
---|
57 | { |
---|
58 | } |
---|
59 | |
---|
60 | void GSIO::ticked(float dt, uint64_t time) |
---|
61 | { |
---|
62 | this->tickChild(dt, time); |
---|
63 | //Ogre::Root& ogreRoot = Ogre::Root::getSingleton(); |
---|
64 | |
---|
65 | //unsigned long frameCount = 0; |
---|
66 | |
---|
67 | //const unsigned long refreshTime = (unsigned long)(debugRefreshTime_ * 1000000.0f); |
---|
68 | //unsigned long refreshStartTime = 0; |
---|
69 | //unsigned long tickTime = 0; |
---|
70 | //unsigned long oldFrameCount = 0; |
---|
71 | |
---|
72 | //unsigned long timeBeforeTick = 0; |
---|
73 | //unsigned long timeBeforeTickOld = 0; |
---|
74 | //unsigned long timeAfterTick = 0; |
---|
75 | |
---|
76 | //// TODO: Update time in seconds every 7 seconds to avoid any overflow (7 secs is very tight) |
---|
77 | |
---|
78 | //COUT(3) << "Orxonox: Starting the main loop." << std::endl; |
---|
79 | |
---|
80 | //try |
---|
81 | //{ |
---|
82 | // timer_->reset(); |
---|
83 | // while (!this->hasScheduledTransition()) |
---|
84 | // { |
---|
85 | // // get current time |
---|
86 | // timeBeforeTickOld = timeBeforeTick; |
---|
87 | // timeBeforeTick = timer_->getMicroseconds(); |
---|
88 | // float dt = (timeBeforeTick - timeBeforeTickOld) / 1000000.0; |
---|
89 | |
---|
90 | // TclThreadManager::getInstance().tick(dt); |
---|
91 | |
---|
92 | // this->tickChild(dt); |
---|
93 | |
---|
94 | // // get current time once again |
---|
95 | // timeAfterTick = timer_->getMicroseconds(); |
---|
96 | |
---|
97 | // tickTime += timeAfterTick - timeBeforeTick; |
---|
98 | // if (timeAfterTick > refreshStartTime + refreshTime) |
---|
99 | // { |
---|
100 | // GraphicsEngine::getInstance().setAverageTickTime( |
---|
101 | // (float)tickTime * 0.001 / (frameCount - oldFrameCount)); |
---|
102 | // float avgFPS = (float)(frameCount - oldFrameCount) / (timeAfterTick - refreshStartTime) * 1000000.0; |
---|
103 | // GraphicsEngine::getInstance().setAverageFramesPerSecond(avgFPS); |
---|
104 | |
---|
105 | // oldFrameCount = frameCount; |
---|
106 | // tickTime = 0; |
---|
107 | // refreshStartTime = timeAfterTick; |
---|
108 | // } |
---|
109 | |
---|
110 | // // don't forget to call _fireFrameStarted in ogre to make sure |
---|
111 | // // everything goes smoothly |
---|
112 | // Ogre::FrameEvent evt; |
---|
113 | // evt.timeSinceLastFrame = dt; |
---|
114 | // evt.timeSinceLastEvent = dt; // note: same time, but shouldn't matter anyway |
---|
115 | // ogreRoot._fireFrameStarted(evt); |
---|
116 | |
---|
117 | // // again, just to be sure ogre works fine |
---|
118 | // ogreRoot._fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted |
---|
119 | |
---|
120 | // ++frameCount; |
---|
121 | // } |
---|
122 | //} |
---|
123 | //catch (std::exception& ex) |
---|
124 | //{ |
---|
125 | // // something went wrong. |
---|
126 | // COUT(1) << ex.what() << std::endl; |
---|
127 | // COUT(1) << "Main loop was stopped by an unhandled exception. Shutting down." << std::endl; |
---|
128 | //} |
---|
129 | } |
---|
130 | } |
---|