1.
What is the problem with just storing your own variable that counts up with using the DT from the FrameListener as you are saying?
The update code should just be like this then:
Code: Select all
m_timer += dt;
if(m_timer >= 1.0f)
{
m_timer -= 1.0f; // Important to not set to 0, otherwise it will not be exactly once per second over a long period of time
// Do your once per second stuff here
}
2.
Draw calls (batches) are stored in the camera, as well as the triangle count. Note however that you would really need to loop through all cameras and not just your main one, since multiple cameras can be used in one render (from compositors and such as well):
Code: Select all
unsigned int totalAmountOfBatches = 0;
unsigned int totalAmountOfFaces = 0;
const Ogre::SceneManager::CameraList& tmpCameras = sceneManager->getCameras();
for (Ogre::SceneManager::CameraList::const_iterator it = tmpCameras.begin(); it != tmpCameras.end(); it++)
{
Camera* camera = (*it).second;
unsigned int count = camera->_getNumRenderedBatches();
totalAmountOfBatches += count;
camera->_notifyRenderedBatches(0); // This resets the count to the next frame
count = camera->_getNumRenderedFaces();
totalAmountOfFaces += count;
camera->_notifyRenderedFaces(0); // This resets the count to the next frame
}
But this is how it is done in the Ogre source code example, which also gets you the FPS (however, I calculate my FPS myself instead, since DT is not really a good indicator of that since you may want to not render a frame if you use a max-FPS option in your game):
Code: Select all
unsigned long currentTime = mTimer->getMilliseconds();
if (areFrameStatsVisible() && currentTime - mLastStatUpdateTime >= FRAME_UPDATE_DELAY)
{
Ogre::RenderTarget::FrameStats stats = mWindow->getStatistics();
mLastStatUpdateTime = currentTime;
Ogre::String s("FPS: ");
s += Ogre::StringConverter::toString((int)stats.lastFPS);
mFpsLabel->setCaption(s);
if (mStatsPanel->getOverlayElement()->isVisible())
{
Ogre::StringVector values;
Ogre::StringStream oss;
oss.str("");
oss << std::fixed << std::setprecision(1) << stats.avgFPS;
Ogre::String str = oss.str();
values.push_back(str);
oss.str("");
oss << std::fixed << std::setprecision(1) << stats.bestFPS;
str = oss.str();
values.push_back(str);
oss.str("");
oss << std::fixed << std::setprecision(1) << stats.worstFPS;
str = oss.str();
values.push_back(str);
str = Ogre::StringConverter::toString(stats.triangleCount);
values.push_back(str);
str = Ogre::StringConverter::toString(stats.batchCount);
values.push_back(str);
mStatsPanel->setAllParamValues(values);
}
}
3.
I do not know the way to make a very fast and simple code to display UI.
I use a more advanced UI to have full control over it with as few batches as possible (using Gorilla at the core level though: https://github.com/betajaen/gorilla).