From abaca40325d7f91e5bc21bfe290bba281c388577 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Thu, 3 Sep 2015 21:10:22 +0200 Subject: [PATCH] [DEV] start work for new model --- gale/Thread.cpp | 14 +++++++--- gale/context/Context.cpp | 60 +++++++++++++++++++++++++++++----------- 2 files changed, 54 insertions(+), 20 deletions(-) diff --git a/gale/Thread.cpp b/gale/Thread.cpp index 4a5f406..e7c5304 100644 --- a/gale/Thread.cpp +++ b/gale/Thread.cpp @@ -17,8 +17,7 @@ gale::Thread::Thread() : } gale::Thread::~Thread() { - delete m_thread; - m_thread = nullptr; + stop(); } void gale::Thread::start() { @@ -35,10 +34,15 @@ void gale::Thread::start() { } void gale::Thread::stop() { - if (m_state != state_running) { + if (m_state == state_stop) { return; } - m_state = state_stopping; + while ( m_state == state_running + || m_state == state_starting) { + // requesting a stop ... + GALE_INFO("wait Thread stopping"); + usleep(500000); + } m_thread->join(); gale::contextUnRegisterThread(m_thread); delete m_thread; @@ -53,7 +57,9 @@ void gale::Thread::threadCall() { continue; } if (onThreadCall() == true) { + m_state = state_stopping; return; } } + m_state = state_stopping; } diff --git a/gale/context/Context.cpp b/gale/context/Context.cpp index d6b7f9d..dc87b5c 100644 --- a/gale/context/Context.cpp +++ b/gale/context/Context.cpp @@ -353,32 +353,60 @@ void gale::Context::OS_Move(const vec2& _pos) { */ } +void gale::Context::OS_SetInput(enum gale::key::type _type, + enum gale::key::status _status, + int32_t _pointerID, + const vec2& _pos ) { + if (m_imulationActive == true) { + m_simulationFile.filePuts(etk::to_string(gale::getTime())); + m_simulationFile.filePuts(":INPUT:";); + m_simulationFile.filePuts(etk::to_string(_type)); + m_simulationFile.filePuts(":"); + m_simulationFile.filePuts(etk::to_string(_status)); + m_simulationFile.filePuts(":"); + m_simulationFile.filePuts(etk::to_string(_pointerID)); + m_simulationFile.filePuts(":"); + m_simulationFile.filePuts(etk::to_string(_pos)); + m_simulationFile.filePuts("\n"); + } + m_msgSystem.post([_type, _status, _pointerID, _pos](gale::Context& _context){ + std::shared_ptr appl = _context.getApplication(); + if (appl == nullptr) { + return; + } + appl->onPointer(_type, + _pointerID, + _pos, + _status); + }); +} + void gale::Context::OS_SetInputMotion(int _pointerID, const vec2& _pos ) { - m_msgSystem.post(std::make_shared(gale::key::type_finger, - gale::key::status_move, - _pointerID, - _pos)); + OS_SetInput(gale::key::type_finger, + gale::key::status_move, + _pointerID, + _pos)); } void gale::Context::OS_SetInputState(int _pointerID, bool _isDown, const vec2& _pos ) { - m_msgSystem.post(std::make_shared(gale::key::type_finger, - (_isDown==true?gale::key::status_down:gale::key::status_up), - _pointerID, - _pos)); + OS_SetInput(gale::key::type_finger, + (_isDown==true?gale::key::status_down:gale::key::status_up), + _pointerID, + _pos)); } void gale::Context::OS_SetMouseMotion(int _pointerID, const vec2& _pos ) { - m_msgSystem.post(std::make_shared(gale::key::type_mouse, - gale::key::status_move, - _pointerID, - _pos)); + OS_SetInput(gale::key::type_mouse, + gale::key::status_move, + _pointerID, + _pos)); } void gale::Context::OS_SetMouseState(int _pointerID, bool _isDown, const vec2& _pos ) { - m_msgSystem.post(std::make_shared(gale::key::type_mouse, - (_isDown==true?gale::key::status_down:gale::key::status_up), - _pointerID, - _pos)); + OS_SetInput(gale::key::type_mouse, + (_isDown==true?gale::key::status_down:gale::key::status_up), + _pointerID, + _pos)); } void gale::Context::OS_SetKeyboard(gale::key::Special& _special,