[DEV] update to echrono

This commit is contained in:
Edouard DUPIN 2016-10-14 21:13:39 +02:00
parent 5fbe5f6ebb
commit 3717d0e5d0
7 changed files with 93 additions and 103 deletions

View File

@ -14,6 +14,7 @@
#include <gale/key/Special.hpp>
#include <gale/context/cursor.hpp>
#include <gale/context/clipBoard.hpp>
#include <echrono/Clock.hpp>
namespace gale {
class Context;
@ -211,6 +212,6 @@ namespace gale {
* @brief Call every time a draw is called (not entirely periodic, but faster at we can ...
* @param[in] _time Current time of the call;
*/
virtual void onPeriod(int64_t _time) {};
virtual void onPeriod(const echrono::Clock& _time) {};
};
}

View File

@ -22,6 +22,7 @@
#include <gale/context/Context.hpp>
#include <gale/resource/Manager.hpp>
#include <map>
#include <echrono/Steady.hpp>
/**
@ -174,7 +175,7 @@ gale::Context::Context(gale::Application* _application, int32_t _argc, const cha
m_imulationActive(false),
m_simulationFile("gale.gsim"),
//m_objectManager(*this),
m_previousDisplayTime(0),
m_previousDisplayTime(),
// TODO : m_input(*this),
#if (defined(__TARGET_OS__Android) || defined(__TARGET_OS__IOs))
m_displayFps(true),
@ -255,7 +256,7 @@ gale::Context::Context(gale::Application* _application, int32_t _argc, const cha
GALE_INFO("GALE v:" << gale::getVersion());
// request the init of the application in the main context of openGL ...
if (m_imulationActive == true) {
m_simulationFile.filePuts(etk::to_string(gale::getTime()));
m_simulationFile.filePuts(etk::to_string(echrono::Steady::now()));
m_simulationFile.filePuts(":INIT");
m_simulationFile.filePuts("\n");
}
@ -328,7 +329,7 @@ gale::Context::~Context() {
void gale::Context::requestUpdateSize() {
if (m_imulationActive == true) {
m_simulationFile.filePuts(etk::to_string(gale::getTime()));
m_simulationFile.filePuts(etk::to_string(echrono::Steady::now()));
m_simulationFile.filePuts(":RECALCULATE_SIZE\n");
}
std::unique_lock<std::recursive_mutex> lock(m_mutex);
@ -345,7 +346,7 @@ void gale::Context::OS_Resize(const vec2& _size) {
// TODO : Better in the thread ... ==> but generate some init error ...
gale::Dimension::setPixelWindowsSize(_size);
if (m_imulationActive == true) {
m_simulationFile.filePuts(etk::to_string(gale::getTime()));
m_simulationFile.filePuts(etk::to_string(echrono::Steady::now()));
m_simulationFile.filePuts(":RESIZE:");
m_simulationFile.filePuts(etk::to_string(_size));
m_simulationFile.filePuts("\n");
@ -398,7 +399,7 @@ void gale::Context::OS_SetInput(enum gale::key::type _type,
int32_t _pointerID,
const vec2& _pos) {
if (m_imulationActive == true) {
m_simulationFile.filePuts(etk::to_string(gale::getTime()));
m_simulationFile.filePuts(etk::to_string(echrono::Steady::now()));
m_simulationFile.filePuts(":INPUT:");
m_simulationFile.filePuts(etk::to_string(_type));
m_simulationFile.filePuts(":");
@ -435,7 +436,7 @@ void gale::Context::OS_setKeyboard(const gale::key::Special& _special,
}
}
if (m_imulationActive == true) {
m_simulationFile.filePuts(etk::to_string(gale::getTime()));
m_simulationFile.filePuts(etk::to_string(echrono::Steady::now()));
m_simulationFile.filePuts(":KEYBOARD:");
m_simulationFile.filePuts(etk::to_string(_special));
m_simulationFile.filePuts(":");
@ -461,7 +462,7 @@ void gale::Context::OS_setKeyboard(const gale::key::Special& _special,
void gale::Context::OS_Hide() {
if (m_imulationActive == true) {
m_simulationFile.filePuts(etk::to_string(gale::getTime()));
m_simulationFile.filePuts(etk::to_string(echrono::Steady::now()));
m_simulationFile.filePuts(":VIEW:false\n");
}
std::unique_lock<std::recursive_mutex> lock(m_mutex);
@ -482,7 +483,7 @@ void gale::Context::OS_Hide() {
void gale::Context::OS_Show() {
if (m_imulationActive == true) {
m_simulationFile.filePuts(etk::to_string(gale::getTime()));
m_simulationFile.filePuts(etk::to_string(echrono::Steady::now()));
m_simulationFile.filePuts(":VIEW:true\n");
}
m_msgSystem.post([](gale::Context& _context){
@ -503,7 +504,7 @@ void gale::Context::OS_Show() {
void gale::Context::OS_ClipBoardArrive(enum gale::context::clipBoard::clipboardListe _clipboardID) {
if (m_imulationActive == true) {
m_simulationFile.filePuts(etk::to_string(gale::getTime()));
m_simulationFile.filePuts(etk::to_string(echrono::Steady::now()));
m_simulationFile.filePuts(":CLIPBOARD_ARRIVE:");
m_simulationFile.filePuts(etk::to_string(_clipboardID));
m_simulationFile.filePuts("\n");
@ -528,10 +529,10 @@ void gale::Context::clipBoardSet(enum gale::context::clipBoard::clipboardListe _
bool gale::Context::OS_Draw(bool _displayEveryTime) {
gale::openGL::threadHasContext();
int64_t currentTime = gale::getTime();
echrono::Steady currentTime = echrono::Steady::now();
// this is to prevent the multiple display at the a high frequency ...
#if (!defined(__TARGET_OS__Android) && !defined(__TARGET_OS__Windows))
if(currentTime - m_previousDisplayTime < 1000000/120) {
if(currentTime - m_previousDisplayTime < echrono::seconds(10)) {
std::this_thread::sleep_for(std::chrono::milliseconds(1));
gale::openGL::threadHasNoMoreContext();
return false;
@ -669,7 +670,7 @@ void gale::Context::OS_Suspend() {
// set the curent interface :
lockContext();
GALE_INFO("OS_Suspend...");
m_previousDisplayTime = -1;
m_previousDisplayTime = echrono::Steady();
#if 0
if (m_windowsCurrent != nullptr) {
m_windowsCurrent->onStateSuspend();
@ -683,7 +684,7 @@ void gale::Context::OS_Resume() {
// set the curent interface :
lockContext();
GALE_INFO("OS_Resume...");
m_previousDisplayTime = gale::getTime();
m_previousDisplayTime = echrono::Steady::now();
// TODO : m_objectManager.timeCallResume(m_previousDisplayTime);
#if 0
if (m_windowsCurrent != nullptr) {

View File

@ -20,6 +20,7 @@
#include <gale/orientation.hpp>
#include <gale/context/clipBoard.hpp>
#include <ethread/tools.hpp>
#include <echrono/Steady.hpp>
#define MAX_MANAGE_INPUT (15)
@ -64,7 +65,7 @@ namespace gale {
bool m_imulationActive;
etk::FSNode m_simulationFile;
private:
int64_t m_previousDisplayTime; // this is to limit framerate ... in case...
echrono::Steady m_previousDisplayTime; // this is to limit framerate ... in case...
// TODO : gale::context::InputManager m_input;
etk::Fifo<std::function<void(gale::Context& _context)> > m_msgSystem;
bool m_displayFps;

View File

@ -4,6 +4,8 @@
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include <echrono/Steady.hpp>
#include <echrono/Duration.hpp>
namespace gale {
namespace context {
@ -12,42 +14,39 @@ namespace gale {
* @not_in_doc
*/
class Fps {
// display every second ...
#define DISPLAY_PERIODE_US (1000000)
private:
int64_t startTime;
int64_t nbCallTime;
int64_t nbDisplayTime;
int64_t min;
int64_t avg;
int64_t max;
int64_t min_idle;
int64_t avg_idle;
int64_t max_idle;
int64_t ticTime;
bool display;
bool drwingDone;
echrono::Steady m_startTime;
int64_t m_nbCallTime;
int64_t m_nbDisplayTime;
echrono::Duration m_min;
echrono::Duration m_avg;
echrono::Duration m_max;
echrono::Duration m_min_idle;
echrono::Duration m_avg_idle;
echrono::Duration m_max_idle;
echrono::Steady m_ticTime;
bool m_display;
bool m_drawingDone;
const char * m_displayName;
bool m_displayFPS;
public:
/**
* @brief Constructor
*/
Fps(const char * displayName, bool displayFPS) {
startTime = -1;
nbCallTime = 0;
nbDisplayTime = 0;
min = 99999999999999LL;
avg = 0;
max = 0;
min_idle = 99999999999999LL;
avg_idle = 0;
max_idle = 0;
ticTime = 0;
display = false;
drwingDone = false;
m_displayName = displayName;
m_displayFPS = displayFPS;
Fps(const char* _displayName, bool _displayFPS):
m_nbCallTime(0),
m_nbDisplayTime(0),
m_min(99999999,0),
m_avg(0,0),
m_max(0,0),
m_min_idle(99999999,0),
m_avg_idle(0,0),
m_max_idle(0,0),
m_display(false),
m_drawingDone(false),
m_displayName(_displayName),
m_displayFPS(_displayFPS) {
}
/**
* @brief Destructor
@ -59,75 +58,75 @@ namespace gale {
* @brief this might be call every time a diplay start
*/
void tic() {
int64_t currentTime = gale::getTime();
ticTime = currentTime;
nbCallTime++;
if (startTime<0) {
startTime = currentTime;
echrono::Steady currentTime = echrono::Steady::now();
m_ticTime = currentTime;
m_nbCallTime++;
if (m_startTime == echrono::Steady()) {
m_startTime = currentTime;
}
//GALE_DEBUG("current : " << currentTime << "time diff : " << (currentTime - startTime));
if ( (currentTime - startTime) > DISPLAY_PERIODE_US) {
display = true;
//GALE_DEBUG("current : " << currentTime << "time diff : " << (currentTime - m_startTime));
if ( (currentTime - m_startTime) > echrono::seconds(10)) {
m_display = true;
}
}
/**
* @brief this might be call every time a diplay stop, it do the display every second
* @param[in] displayTime display curent time of the frame.
*/
void toc(bool displayTime = false) {
int64_t currentTime = gale::getTime();
int64_t processTimeLocal = (currentTime - ticTime);
if (displayTime == true) {
GALE_PRINT(m_displayName << " : processTime : " << (float)((float)processTimeLocal / 1000.0) << "ms ");
void toc(bool _displayTime = false) {
echrono::Steady currentTime = echrono::Steady::now();
echrono::Duration processTimeLocal = (currentTime - m_ticTime);
if (_displayTime == true) {
GALE_PRINT(m_displayName << ": processTime: " << processTimeLocal);
}
if (drwingDone) {
min = std::min(min, processTimeLocal);
max = std::max(max, processTimeLocal);
avg += processTimeLocal;
drwingDone = false;
if (m_drawingDone == true) {
m_min = std::min(m_min, processTimeLocal);
m_max = std::max(m_max, processTimeLocal);
m_avg += processTimeLocal;
m_drawingDone = false;
} else {
min_idle = std::min(min_idle, processTimeLocal);
max_idle = std::max(max_idle, processTimeLocal);
avg_idle += processTimeLocal;
m_min_idle = std::min(m_min_idle, processTimeLocal);
m_max_idle = std::max(m_max_idle, processTimeLocal);
m_avg_idle += processTimeLocal;
}
}
/**
* @brief this might be call when a display is really done
*/
void incrementCounter() {
nbDisplayTime++;
drwingDone = true;
m_nbDisplayTime++;
m_drawingDone = true;
}
/**
* @brief draw debug display ...
*/
void draw() {
if (true == display) {
if (nbDisplayTime>0) {
if (m_display == true) {
if (m_nbDisplayTime > 0) {
GALE_PRINT(m_displayName << " : Active : "
<< (float)((float)min / 1000.0) << "ms "
<< (float)((float)avg / (float)nbDisplayTime / 1000.0) << "ms "
<< (float)((float)max / 1000.0) << "ms ");
<< m_min << " "
<< m_avg / m_nbDisplayTime << "ms "
<< m_max << " ");
}
if (nbCallTime-nbDisplayTime>0) {
if (m_nbCallTime-m_nbDisplayTime>0) {
GALE_PRINT(m_displayName << " : idle : "
<< (float)((float)min_idle / 1000.0) << "ms "
<< (float)((float)avg_idle / (float)(nbCallTime-nbDisplayTime) / 1000.0) << "ms "
<< (float)((float)max_idle / 1000.0) << "ms ");
<< m_min_idle << " "
<< m_avg_idle / (m_nbCallTime-m_nbDisplayTime) << "ms "
<< m_max_idle << " ");
}
if (true == m_displayFPS) {
GALE_PRINT("FPS : " << nbDisplayTime << "/" << nbCallTime << "fps");
if (m_displayFPS == true) {
GALE_PRINT("FPS : " << m_nbDisplayTime << "/" << m_nbCallTime << "fps");
}
max = 0;
min = 99999999999999LL;
avg = 0;
max_idle = 0;
min_idle = 99999999999999LL;
avg_idle = 0;
nbCallTime = 0;
nbDisplayTime = 0;
startTime = -1;
display = false;
m_max = echrono::Duration(0);
m_min = echrono::Duration(99999999,0);
m_avg = echrono::Duration(0);
m_max_idle = echrono::Duration(0);
m_min_idle = echrono::Duration(99999999,0);
m_avg_idle = echrono::Duration(0);
m_nbCallTime = 0;
m_nbDisplayTime = 0;
m_startTime = echrono::Steady();
m_display = false;
}
}
};

View File

@ -44,10 +44,3 @@ std::string gale::getVersion() {
return GALE_VERSION;
}
// generic vertion of time: ==> DEPRECATED
int64_t gale::getTime() {
std::chrono::high_resolution_clock::time_point globalTimePoint = std::chrono::high_resolution_clock::now();
std::chrono::microseconds timeSinceEpoch = std::chrono::duration_cast<std::chrono::microseconds>(globalTimePoint.time_since_epoch());
return timeSinceEpoch.count();
}

View File

@ -21,18 +21,12 @@ namespace gale {
* @param[in] _argv Standard argv
* @return normal error int for the application error management
*/
int32_t run(gale::Application* _application, int32_t _argc = 0, const char* _argv[] = NULL);
int32_t run(gale::Application* _application, int32_t _argc = 0, const char* _argv[] = nullptr);
/**
* @brief get GALE version
* @return The string that describe gale version
*/
std::string getVersion();
/**
* @brief get current time in us...
* @return The current time
* @deprecated use std::chrono
*/
int64_t getTime();
/**
* @brief get compilation mode (release/debug)
* @return the string of the mode of commpilation

View File

@ -138,7 +138,8 @@ def configure(target, my_module):
])
my_module.add_depend([
'etk',
'opengl'
'opengl',
'echrono',
])
my_module.add_optionnal_depend('esignal', ["c++", "-DGALE_BUILD_ESIGNAL"])
my_module.add_optionnal_depend('eproperty', ["c++", "-DGALE_BUILD_EPROPERTY"])