1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
/// .h
#pragma comment(lib,"winmm.lib")
#include <mmsystem.h>
#include <vector>
using namespace std;
#ifndef FPS_COUNTER_H
#define FPS_COUNTER_H
class FPS_COUNTER
{
public:
FPS_COUNTER() : fps(0.0f), lastTime(0.0f), frames(0), time(0.0f)
{}
~FPS_COUNTER() {}
void Update(void);
float GetFps(void) { return fps; };
vector <float> v_fps;
float fps_moyen;
protected:
float fps;
float lastTime;
int frames;
float time;
};
#endif //FPS_COUNTER_H
//// .cpp
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <mmsystem.h>
#include "FPS_COUNTER.h"
void FPS_COUNTER::Update(void)
{
//keep track of time passed and frame count
time=timeGetTime()*0.001f;
++frames;
//If a second has passed
if(time-lastTime>1.0f)
{
fps=frames/(time-lastTime); //update the number of frames per second
lastTime=time; //set time for the start of the next count
frames=0; //reset fps for this second
v_fps.push_back(fps);
float total = 0;
int i = 0;
int v = v_fps.size();
for ( i=0;i<v;i++) {
total+=v_fps[i];
}
fps_moyen = total / v;
}
} |
Partager