[DEV] set a real periodic call independent of display (fix wayland stop redraw)
This commit is contained in:
parent
11e7e0f540
commit
ae21bbff96
@ -93,6 +93,10 @@ void gale::Thread::stop() {
|
||||
|
||||
void gale::Thread::threadCall() {
|
||||
GALE_DEBUG("THREAD MAIN [START]");
|
||||
if (m_name != "") {
|
||||
ethread::setName(m_name);
|
||||
m_lastUpdatateName = echrono::Steady::now();
|
||||
}
|
||||
gale::setContext(m_context);
|
||||
while (m_state != state::stopping) {
|
||||
if (m_state == state::starting) {
|
||||
@ -100,6 +104,12 @@ void gale::Thread::threadCall() {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
continue;
|
||||
}
|
||||
if (m_name != "") {
|
||||
if ((echrono::Steady::now()-m_lastUpdatateName) > echrono::seconds(10)) {
|
||||
m_lastUpdatateName = echrono::Steady::now();
|
||||
ethread::setName(m_name);
|
||||
}
|
||||
}
|
||||
if (onThreadCall() == true) {
|
||||
GALE_DEBUG("run std::thread [AUTO STOP]");
|
||||
m_state = state::stopping;
|
||||
@ -107,6 +117,7 @@ void gale::Thread::threadCall() {
|
||||
}
|
||||
}
|
||||
GALE_DEBUG("THREAD MAIN [STOP]");
|
||||
gale::setContext(nullptr);
|
||||
m_state = state::stopping;
|
||||
}
|
||||
|
||||
@ -117,3 +128,7 @@ bool gale::Thread::onThreadCall() {
|
||||
enum gale::Thread::state gale::Thread::getState() {
|
||||
return m_state;
|
||||
}
|
||||
|
||||
void gale::Thread::setName(std::string _name) {
|
||||
m_name = _name;
|
||||
}
|
||||
|
@ -62,6 +62,15 @@ namespace gale {
|
||||
* @brief Stop the Thread (destroy thread here)
|
||||
*/
|
||||
virtual void stop();
|
||||
private:
|
||||
std::string m_name; //!< thread Name
|
||||
echrono::Steady m_lastUpdatateName;
|
||||
public:
|
||||
/**
|
||||
* @brief change name of the thread
|
||||
* @param[in] _name Name of the thread
|
||||
*/
|
||||
void setName(std::string m_name);
|
||||
private:
|
||||
#if defined(__TARGET_OS__Android)
|
||||
static void* threadCallback(void* _userData);
|
||||
|
@ -130,22 +130,6 @@ void gale::contextUnRegisterThread(std::thread* _thread) {
|
||||
g_lockContextMap.unlock();
|
||||
}
|
||||
|
||||
class PeriodicThread : public gale::Thread {
|
||||
public:
|
||||
PeriodicThread() {
|
||||
|
||||
}
|
||||
bool onThreadCall() override {
|
||||
ethread::setName("galeThread 2");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
GALE_INFO("periodicThread");
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
void gale::Context::setInitImage(const std::string& _fileName) {
|
||||
//m_initDisplayImageName = _fileName;
|
||||
}
|
||||
@ -210,6 +194,38 @@ void gale::Context::setArchiveDir(int _mode, const char* _str, const char* _appl
|
||||
}
|
||||
}
|
||||
|
||||
namespace gale {
|
||||
class PeriodicThread : public gale::Thread {
|
||||
private:
|
||||
gale::Context* m_context;
|
||||
public:
|
||||
PeriodicThread(gale::Context* _context):
|
||||
m_context(_context) {
|
||||
setName("GaleThread 2");
|
||||
}
|
||||
bool onThreadCall() override {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
#if 0
|
||||
m_context->lockContext();
|
||||
#else
|
||||
mutexInterface().lock();
|
||||
#endif
|
||||
m_context->processEvents();
|
||||
// call all the application for periodic request (the application manage multiple instance )...
|
||||
if (m_context->m_application != nullptr) {
|
||||
m_context->m_application->onPeriod(echrono::Steady::now());
|
||||
}
|
||||
#if 0
|
||||
m_context->unLockContext();
|
||||
#else
|
||||
mutexInterface().unlock();
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
gale::Context::Context(gale::Application* _application, int32_t _argc, const char* _argv[]) :
|
||||
@ -241,7 +257,7 @@ gale::Context::Context(gale::Application* _application, int32_t _argc, const cha
|
||||
// set the curent interface:
|
||||
lockContext();
|
||||
// create thread to manage real periodic event
|
||||
m_periodicThread = ememory::makeShared<PeriodicThread>();
|
||||
m_periodicThread = ememory::makeShared<PeriodicThread>(this);
|
||||
m_periodicThread->start();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
||||
|
||||
@ -637,11 +653,7 @@ bool gale::Context::OS_Draw(bool _displayEveryTime) {
|
||||
|
||||
*/
|
||||
|
||||
processEvents();
|
||||
// call all the application for periodic request (the application manage multiple instance ...
|
||||
if (m_application != nullptr) {
|
||||
m_application->onPeriod(currentTime);
|
||||
}
|
||||
|
||||
if (m_application != nullptr) {
|
||||
// Redraw all needed elements
|
||||
m_application->onRegenerateDisplay(*this);
|
||||
|
@ -14,7 +14,6 @@
|
||||
#include <gale/Application.hpp>
|
||||
#include <gale/context/clipBoard.hpp>
|
||||
#include <gale/context/commandLine.hpp>
|
||||
// TODO : #include <gale/context/InputManager.hpp>
|
||||
#include <gale/context/Fps.hpp>
|
||||
#include <gale/Thread.hpp>
|
||||
#include <ememory/memory.hpp>
|
||||
@ -27,7 +26,9 @@
|
||||
|
||||
namespace gale {
|
||||
class Thread;
|
||||
class PeriodicThread;
|
||||
class Context {
|
||||
friend class gale::PeriodicThread;
|
||||
protected:
|
||||
std::recursive_mutex m_mutex;
|
||||
ememory::SharedPtr<gale::Thread> m_periodicThread;
|
||||
@ -69,7 +70,6 @@ namespace gale {
|
||||
etk::FSNode m_simulationFile;
|
||||
private:
|
||||
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;
|
||||
gale::context::Fps m_FpsSystemEvent;
|
||||
@ -262,13 +262,6 @@ namespace gale {
|
||||
* @param[in] _status "true" to enable decoration / false otherwise
|
||||
*/
|
||||
virtual void setWindowsDecoration(bool _status) {};
|
||||
/**
|
||||
* @brief get the curent time in micro-second
|
||||
* @note : must be implemented in all system OS implementation
|
||||
* @return The curent time of the process
|
||||
*/
|
||||
// TODO : REMOVE this ... deprecated since c++11
|
||||
static int64_t getTime();
|
||||
private:
|
||||
// TODO : set user argument here ....
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user