Merged the new frame rate system into dev-char

This commit is contained in:
Kayne Ruse
2013-06-23 15:11:24 +10:00
4 changed files with 34 additions and 27 deletions
+7
View File
@@ -34,6 +34,7 @@ InWorld::InWorld() {
cout << "entering InWorld" << endl; cout << "entering InWorld" << endl;
#endif #endif
cout << "Client Index: " << infoMgr->GetClientIndex() << endl; cout << "Client Index: " << infoMgr->GetClientIndex() << endl;
font.SetSurface(surfaceMgr->Get("font"));
pc.GetSprite()->SetSurface(surfaceMgr->Get("elliot"), 32, 48); pc.GetSprite()->SetSurface(surfaceMgr->Get("elliot"), 32, 48);
} }
@@ -61,7 +62,13 @@ void InWorld::FrameEnd() {
} }
void InWorld::Render(SDL_Surface* const screen) { void InWorld::Render(SDL_Surface* const screen) {
ClockFrameRate();
pc.DrawTo(screen); pc.DrawTo(screen);
//since we're using this twice, make a tmp var
string fps = itos(GetFrameRate());
font.DrawStringTo(fps, screen, screen->w - fps.size() * font.GetCharW(), 0);
} }
//------------------------- //-------------------------
+2
View File
@@ -35,6 +35,7 @@
#include "udp_network_utility.hpp" #include "udp_network_utility.hpp"
#include "button.hpp" #include "button.hpp"
#include "raster_font.hpp" #include "raster_font.hpp"
#include "frame_rate.hpp"
//debugging //debugging
#include "player_character.hpp" #include "player_character.hpp"
@@ -73,6 +74,7 @@ protected:
InformationManager* infoMgr = ServiceLocator<InformationManager>::Get(); InformationManager* infoMgr = ServiceLocator<InformationManager>::Get();
//members //members
RasterFont font;
PlayerCharacter pc; PlayerCharacter pc;
}; };
+21 -3
View File
@@ -21,6 +21,24 @@
*/ */
#include "frame_rate.hpp" #include "frame_rate.hpp"
int FrameRate::frameCount = 0; #include <chrono>
int FrameRate::lastFrameRate = 0;
FrameRate::Clock::time_point FrameRate::tick = FrameRate::Clock::now(); typedef std::chrono::high_resolution_clock Clock;
static int frameCount = 0;
static int lastFrameRate = 0;
static Clock::time_point tick = Clock::now();
int ClockFrameRate() {
frameCount++;
if (Clock::now() - tick >= std::chrono::duration<int>(1)) {
lastFrameRate = frameCount;
frameCount = 0;
tick = Clock::now();
}
return lastFrameRate;
}
int GetFrameRate() {
return lastFrameRate;
}
+2 -22
View File
@@ -22,27 +22,7 @@
#ifndef FRAMERATE_HPP_ #ifndef FRAMERATE_HPP_
#define FRAMERATE_HPP_ #define FRAMERATE_HPP_
#include <chrono> int ClockFrameRate();
int GetFrameRate();
class FrameRate {
public:
typedef std::chrono::high_resolution_clock Clock;
FrameRate() = delete;
static int Calculate() {
frameCount++;
if (Clock::now() - tick >= std::chrono::duration<int>(1)) {
lastFrameRate = frameCount;
frameCount = 0;
tick = Clock::now();
}
return lastFrameRate;
}
static int GetFrameRate() { return lastFrameRate; }
private:
static int frameCount;
static int lastFrameRate;
static Clock::time_point tick;
};
#endif #endif