00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <stdio.h>
00022 #include <graph/FrameTimer.h>
00023 #include <client/ClientChannelManager.h>
00024 #include <graph/OptionsDisplay.h>
00025 #include <GLEXT/GLInfo.h>
00026 #include <GLEXT/GLTexture.h>
00027 #include <lang/LangResource.h>
00028
00029 FrameTimer *FrameTimer::instance_ = 0;
00030
00031 FrameTimer *FrameTimer::instance()
00032 {
00033 if (!instance_)
00034 {
00035 instance_ = new FrameTimer;
00036 }
00037
00038 return instance_;
00039 }
00040
00041 FrameTimer::FrameTimer() :
00042 GameStateI("FrameTimer"),
00043 totalTime_(0.0f), frameCount_(0),
00044 lastStateCount_(0), lastTris_(0), lastTextureSets_(0),
00045 fps_(0.0f)
00046 {
00047
00048 }
00049
00050 FrameTimer::~FrameTimer()
00051 {
00052
00053 }
00054
00055 void FrameTimer::draw(const unsigned state)
00056 {
00057 frameCount_++;
00058
00059 lastStateCount_ = GLState::getStateSwitches();
00060 GLState::resetStateSwitches();
00061
00062 lastTris_ = GLInfo::getNoTriangles();
00063 GLInfo::resetNoTriangles();
00064
00065 lastTextureSets_ = GLTexture::getTextureSets();
00066 GLTexture::resetTextureSets();
00067 }
00068
00069 void FrameTimer::simulate(const unsigned state, float frameTime)
00070 {
00071 totalTime_ += frameTime;
00072 if (totalTime_ > 5.0f)
00073 {
00074 float timeTaken = frameClock_.getTimeDifference();
00075 fps_ = float(frameCount_) / timeTaken;
00076 totalTime_ = 0.0f;
00077 frameCount_ = 0;
00078
00079 if (OptionsDisplay::instance()->getFrameTimer())
00080 {
00081 ChannelText chText("info",
00082 LANG_RESOURCE_1(
00083 "X_FRAMES_PER_SECOND",
00084 "{0} frames per second.",
00085 S3D::formatStringBuffer("%.2f", fps_)));
00086 chText.setFlags(ChannelText::eNoLog | ChannelText::eNoSound);
00087 ClientChannelManager::instance()->showText(chText);
00088 }
00089 }
00090 }