added high resolution timer
This commit is contained in:
parent
04a82a7364
commit
c3d5e23518
@ -4,6 +4,7 @@
|
|||||||
#include "glassert.h"
|
#include "glassert.h"
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
#include "module.h"
|
#include "module.h"
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
// main methods
|
// main methods
|
||||||
|
|
||||||
@ -60,7 +61,11 @@ void SparrowRenderer::renderGL()
|
|||||||
for(ModuleNode &m : modules)
|
for(ModuleNode &m : modules)
|
||||||
{
|
{
|
||||||
if(m.isEnabled)
|
if(m.isEnabled)
|
||||||
|
{
|
||||||
|
std::chrono::high_resolution_clock::time_point t = std::chrono::high_resolution_clock::now();
|
||||||
m.module->renderGL(getCamera(), scene);
|
m.module->renderGL(getCamera(), scene);
|
||||||
|
m.seconds = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::high_resolution_clock::now() - t).count();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,6 +74,24 @@ bool SparrowRenderer::isModernOpenGLAvailable()
|
|||||||
return modernOpenglAvailable;
|
return modernOpenglAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// clock methods
|
||||||
|
|
||||||
|
double SparrowRenderer::getFPS()
|
||||||
|
{
|
||||||
|
double totalTime = 0;
|
||||||
|
for(ModuleNode &m : modules)
|
||||||
|
{
|
||||||
|
if(m.isEnabled)
|
||||||
|
totalTime += m.seconds;
|
||||||
|
}
|
||||||
|
return 1./totalTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
double SparrowRenderer::getModuleTime(int moduleId)
|
||||||
|
{
|
||||||
|
return modules[moduleId].seconds;
|
||||||
|
}
|
||||||
|
|
||||||
// module methods
|
// module methods
|
||||||
|
|
||||||
void SparrowRenderer::addModule(Module* myModule, std::string name)
|
void SparrowRenderer::addModule(Module* myModule, std::string name)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef SPARROWRENDERER_H
|
#ifndef SPARROWRENDERER_H
|
||||||
#define SPARROWRENDERER_H
|
#define SPARROWRENDERER_H
|
||||||
|
|
||||||
#include <list>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class Camera;
|
class Camera;
|
||||||
@ -18,6 +18,10 @@ public:
|
|||||||
void renderGL();
|
void renderGL();
|
||||||
static bool isModernOpenGLAvailable();
|
static bool isModernOpenGLAvailable();
|
||||||
|
|
||||||
|
// clock methods
|
||||||
|
double getFPS();
|
||||||
|
double getModuleTime(int moduleId);
|
||||||
|
|
||||||
// modules methods
|
// modules methods
|
||||||
void addModule(Module* myModule, std::string name);
|
void addModule(Module* myModule, std::string name);
|
||||||
int getNbModules();
|
int getNbModules();
|
||||||
@ -35,16 +39,17 @@ protected:
|
|||||||
Module* module;
|
Module* module;
|
||||||
std::string name;
|
std::string name;
|
||||||
bool isEnabled;
|
bool isEnabled;
|
||||||
|
double seconds;
|
||||||
|
|
||||||
s_moduleNode(Module* myModule, const std::string &myName) : module(myModule), name(myName), isEnabled(true) {}
|
s_moduleNode(Module* myModule, const std::string &myName) : module(myModule), name(myName), isEnabled(true) {}
|
||||||
} ModuleNode;
|
} ModuleNode;
|
||||||
|
|
||||||
Camera* camera;
|
Camera* camera;
|
||||||
Scene* scene;
|
Scene* scene;
|
||||||
std::list<ModuleNode> modules;
|
std::vector<ModuleNode> modules;
|
||||||
static bool modernOpenglAvailable;
|
static bool modernOpenglAvailable;
|
||||||
|
|
||||||
std::list<ModuleNode>::iterator getModuleNode(std::string name);
|
std::vector<ModuleNode>::iterator getModuleNode(std::string name);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SPARROWRENDERER_H
|
#endif // SPARROWRENDERER_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user