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

View File

@ -20,6 +20,7 @@
#include <gale/orientation.hpp> #include <gale/orientation.hpp>
#include <gale/context/clipBoard.hpp> #include <gale/context/clipBoard.hpp>
#include <ethread/tools.hpp> #include <ethread/tools.hpp>
#include <echrono/Steady.hpp>
#define MAX_MANAGE_INPUT (15) #define MAX_MANAGE_INPUT (15)
@ -64,7 +65,7 @@ namespace gale {
bool m_imulationActive; bool m_imulationActive;
etk::FSNode m_simulationFile; etk::FSNode m_simulationFile;
private: 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; // TODO : gale::context::InputManager m_input;
etk::Fifo<std::function<void(gale::Context& _context)> > m_msgSystem; etk::Fifo<std::function<void(gale::Context& _context)> > m_msgSystem;
bool m_displayFps; bool m_displayFps;

View File

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

View File

@ -44,10 +44,3 @@ std::string gale::getVersion() {
return GALE_VERSION; 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 * @param[in] _argv Standard argv
* @return normal error int for the application error management * @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 * @brief get GALE version
* @return The string that describe gale version * @return The string that describe gale version
*/ */
std::string getVersion(); 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) * @brief get compilation mode (release/debug)
* @return the string of the mode of commpilation * @return the string of the mode of commpilation

View File

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