diff --git a/gale/Thread.cpp b/gale/Thread.cpp index bc34c29..139b0fb 100644 --- a/gale/Thread.cpp +++ b/gale/Thread.cpp @@ -10,10 +10,8 @@ #include #include - - #if defined(__TARGET_OS__Android) - static void* threadCallback(void* _userData) { + void* gale::Thread::threadCallback(void* _userData) { gale::Thread* threadHandle = static_cast(_userData); if (threadHandle != nullptr) { threadHandle->threadCall(); @@ -44,9 +42,9 @@ void gale::Thread::start() { m_state = state_starting; m_context = &gale::getContext(); #if defined(__TARGET_OS__Android) - pthread_create(&m_thread, nullptr, &threadCallback, this); + pthread_create(&m_thread, nullptr, &gale::Thread::threadCallback, this); #else - m_thread = new std11::thread(&gale::Thread::threadCall, this);//, &gale::getContext()); + m_thread = std11::make_shared(&gale::Thread::threadCall, this); if (m_thread == nullptr) { GALE_ERROR("Can not create thread ..."); return; @@ -78,17 +76,17 @@ void gale::Thread::stop() { } GALE_DEBUG("stop std11::thread [START]"); #if defined(__TARGET_OS__Android) - //m_thread.join(); + void* ret = nullptr; + int val = pthread_join(m_thread, &ret); #else m_thread->join(); #endif //gale::contextUnRegisterThread(m_thread); GALE_DEBUG("stop std11::thread [delete]"); #if defined(__TARGET_OS__Android) - + #else - delete m_thread; - m_thread = nullptr; + m_thread.reset(); #endif GALE_DEBUG("stop std11::thread [set state]"); m_state = state_stop; diff --git a/gale/Thread.h b/gale/Thread.h index 967ef3e..cb003c1 100644 --- a/gale/Thread.h +++ b/gale/Thread.h @@ -36,7 +36,7 @@ namespace gale { #if defined(__TARGET_OS__Android) pthread_t m_thread; #else - std11::thread* m_thread; + std11::shared_ptr m_thread; #endif gale::Context* m_context; public: @@ -50,7 +50,10 @@ namespace gale { virtual ~Thread(); void start(); void stop(); - public: + private: + #if defined(__TARGET_OS__Android) + static void* threadCallback(void* _userData); + #endif void threadCall(); protected: virtual bool onThreadCall() { return true; }; diff --git a/gale/context/Android/Context.cpp b/gale/context/Android/Context.cpp index 7a065bb..bf95065 100644 --- a/gale/context/Android/Context.cpp +++ b/gale/context/Android/Context.cpp @@ -435,32 +435,32 @@ class AndroidContext : public gale::Context { enum gale::key::status _status, int32_t _pointerID, const vec2& _pos) { - GALE_DEBUG("OS_SetInput [BEGIN]"); + GALE_VERBOSE("OS_SetInput [BEGIN]"); gale::Context::OS_SetInput(_type, _status, _pointerID, vec2(_pos.x(),m_currentHeight-_pos.y())); - GALE_DEBUG("OS_SetInput [END]"); + GALE_VERBOSE("OS_SetInput [END]"); } void ANDROID_SetKeyboard(char32_t _myChar, bool _isDown, bool _isARepeateKey=false) { - GALE_DEBUG("ANDROID_SetKeyboard [BEGIN]"); + GALE_VERBOSE("ANDROID_SetKeyboard [BEGIN]"); OS_setKeyboard(m_guiKeyBoardSpecialKeyMode, gale::key::keyboard_char, (_isDown==true?gale::key::status_down:gale::key::status_up), _isARepeateKey, _myChar); - GALE_DEBUG("ANDROID_SetKeyboard [END]"); + GALE_VERBOSE("ANDROID_SetKeyboard [END]"); } bool ANDROID_systemKeyboradEvent(enum gale::key::keyboard _key, bool _isDown) { - GALE_DEBUG("ANDROID_systemKeyboradEvent [BEGIN]"); + GALE_VERBOSE("ANDROID_systemKeyboradEvent [BEGIN]"); OS_setKeyboard(m_guiKeyBoardSpecialKeyMode, _key, (_isDown==true?gale::key::status_down:gale::key::status_up)); - GALE_DEBUG("ANDROID_systemKeyboradEvent [END]"); + GALE_VERBOSE("ANDROID_systemKeyboradEvent [END]"); return false; } void ANDROID_SetKeyboardMove(int _move, bool _isDown, bool _isARepeateKey=false) { - GALE_DEBUG("ANDROID_SetKeyboardMove [BEGIN]"); + GALE_VERBOSE("ANDROID_SetKeyboardMove [BEGIN]"); // direct wrapping : enum gale::key::keyboard move = (enum gale::key::keyboard)_move; m_guiKeyBoardSpecialKeyMode.update(move, _isDown); @@ -468,14 +468,14 @@ class AndroidContext : public gale::Context { move, (_isDown==true?gale::key::status_down:gale::key::status_up), _isARepeateKey); - GALE_DEBUG("ANDROID_SetKeyboardMove [END]"); + GALE_VERBOSE("ANDROID_SetKeyboardMove [END]"); } void OS_Resize(const vec2& _size) { - GALE_DEBUG("OS_Resize [BEGIN]"); + GALE_VERBOSE("OS_Resize [BEGIN]"); m_currentHeight = _size.y(); gale::Context::OS_Resize(_size); - GALE_DEBUG("OS_Resize [END]"); + GALE_VERBOSE("OS_Resize [END]"); } }; @@ -888,7 +888,7 @@ extern "C" { jobject _thiz, jint _id) { std::unique_lock lock(g_interfaceMutex); - GALE_DEBUG("Java_org_gale_Gale_EWrenderInit [BEGIN]"); + GALE_VERBOSE("Java_org_gale_Gale_EWrenderInit [BEGIN]"); if( _id >= (int32_t)s_listInstance.size() || _id<0 || nullptr == s_listInstance[_id] ) { @@ -896,7 +896,7 @@ extern "C" { // TODO : generate error in java to stop the current instance return; } - GALE_DEBUG("Java_org_gale_Gale_EWrenderInit [END]"); + GALE_VERBOSE("Java_org_gale_Gale_EWrenderInit [END]"); } void Java_org_gale_Gale_EWrenderResize(JNIEnv* _env, @@ -905,7 +905,7 @@ extern "C" { jint _w, jint _h) { std::unique_lock lock(g_interfaceMutex); - GALE_DEBUG("Java_org_gale_Gale_EWrenderResize [BEGIN]"); + GALE_VERBOSE("Java_org_gale_Gale_EWrenderResize [BEGIN]"); if( _id >= (int32_t)s_listInstance.size() || _id<0 || nullptr == s_listInstance[_id] ) { @@ -914,7 +914,7 @@ extern "C" { return; } s_listInstance[_id]->OS_Resize(vec2(_w, _h)); - GALE_DEBUG("Java_org_gale_Gale_EWrenderResize [END]"); + GALE_VERBOSE("Java_org_gale_Gale_EWrenderResize [END]"); } // TODO : Return true or false to not redraw when the under draw has not be done (processing gain of time) @@ -922,7 +922,7 @@ extern "C" { jobject _thiz, jint _id) { std::unique_lock lock(g_interfaceMutex); - GALE_DEBUG("Java_org_gale_Gale_EWrenderDraw [BEGIN]"); + GALE_VERBOSE("Java_org_gale_Gale_EWrenderDraw [BEGIN]"); if( _id >= (int32_t)s_listInstance.size() || _id<0 || nullptr == s_listInstance[_id] ) { @@ -931,7 +931,7 @@ extern "C" { return; } s_listInstance[_id]->OS_Draw(true); - GALE_DEBUG("Java_org_gale_Gale_EWrenderDraw [END]"); + GALE_VERBOSE("Java_org_gale_Gale_EWrenderDraw [END]"); } }; diff --git a/gale/context/Context.cpp b/gale/context/Context.cpp index 77a1f94..801ceb9 100644 --- a/gale/context/Context.cpp +++ b/gale/context/Context.cpp @@ -65,7 +65,7 @@ gale::Context& gale::getContext() { void gale::setContext(gale::Context* _context) { std::map& list = getContextList(); - GALE_ERROR("Set context : " << std11::this_thread::get_id() << " context pointer : " << uint64_t(_context)); + //GALE_ERROR("Set context : " << std11::this_thread::get_id() << " context pointer : " << uint64_t(_context)); g_lockContextMap.lock(); std::map::iterator it = list.find(std11::this_thread::get_id()); if (it == list.end()) { @@ -82,7 +82,7 @@ void gale::contextRegisterThread(std11::thread* _thread) { } gale::Context* context = &gale::getContext(); std::map& list = getContextList(); - GALE_ERROR("REGISTER Thread : " << _thread->get_id() << " context pointer : " << uint64_t(context)); + //GALE_ERROR("REGISTER Thread : " << _thread->get_id() << " context pointer : " << uint64_t(context)); g_lockContextMap.lock(); std::map::iterator it = list.find(_thread->get_id()); if (it == list.end()) { @@ -506,7 +506,6 @@ void gale::Context::clipBoardSet(enum gale::context::clipBoard::clipboardListe _ } bool gale::Context::OS_Draw(bool _displayEveryTime) { - GALE_INFO("plop 10"); gale::openGL::threadHasContext(); int64_t currentTime = gale::getTime(); // this is to prevent the multiple display at the a high frequency ... @@ -518,13 +517,11 @@ bool gale::Context::OS_Draw(bool _displayEveryTime) { } #endif m_previousDisplayTime = currentTime; - GALE_INFO("plop 20"); // process the events if (m_displayFps == true) { m_FpsSystemEvent.tic(); } - GALE_INFO("plop 30"); bool needRedraw = false; //! Event management section ... { @@ -547,7 +544,6 @@ bool gale::Context::OS_Draw(bool _displayEveryTime) { // release the curent interface : unLockContext(); } - GALE_INFO("plop 40"); bool hasDisplayDone = false; //! drawing section: { @@ -556,7 +552,6 @@ bool gale::Context::OS_Draw(bool _displayEveryTime) { if (m_displayFps == true) { m_FpsSystemContext.tic(); } - GALE_INFO("plop 41"); if( needRedraw == true || _displayEveryTime == true) { lockContext(); @@ -566,12 +561,10 @@ bool gale::Context::OS_Draw(bool _displayEveryTime) { m_FpsSystemContext.incrementCounter(); } } - GALE_INFO("plop 42"); if (m_displayFps == true) { m_FpsSystemContext.toc(); m_FpsSystem.tic(); } - GALE_INFO("plop 43"); if (m_application != nullptr) { if( true == needRedraw || true == _displayEveryTime) { @@ -583,35 +576,28 @@ bool gale::Context::OS_Draw(bool _displayEveryTime) { hasDisplayDone = true; } } - GALE_INFO("plop 44"); if (m_displayFps == true) { m_FpsSystem.toc(); m_FpsFlush.tic(); } - GALE_INFO("plop 45"); if (hasDisplayDone == true) { if (m_displayFps == true) { m_FpsFlush.incrementCounter(); } gale::openGL::flush(); } - GALE_INFO("plop 46"); if (m_displayFps == true) { m_FpsFlush.toc(); } - GALE_INFO("plop 47"); // release open GL Context gale::openGL::unLock(); - GALE_INFO("plop 48"); } - GALE_INFO("plop 50"); if (m_displayFps == true) { m_FpsSystemEvent.draw(); m_FpsSystemContext.draw(); m_FpsSystem.draw(); m_FpsFlush.draw(); } - GALE_INFO("plop 60"); { // set the curent interface : lockContext(); @@ -626,9 +612,7 @@ bool gale::Context::OS_Draw(bool _displayEveryTime) { // release the curent interface : unLockContext(); } - GALE_INFO("plop 70"); gale::openGL::threadHasNoMoreContext(); - GALE_INFO("plop 80"); return hasDisplayDone; }