diff --git a/src/framework/CMakeLists.txt b/src/framework/CMakeLists.txt index 4316cd1b..e5c18712 100644 --- a/src/framework/CMakeLists.txt +++ b/src/framework/CMakeLists.txt @@ -237,12 +237,14 @@ else() message(STATUS "Crash handler: OFF") endif() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") if(WIN32) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mthreads") set(framework_DEFINITIONS ${framework_DEFINITIONS} -D_WIN32_WINNT=0x0501) set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -Wl,--large-address-aware") # strip all debug information set(SYSTEM_LIBRARIES "") elseif(APPLE) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") set(framework_DEFINITIONS ${framework_DEFINITIONS} -D_REENTRANT) # enable thread safe code set(SYSTEM_LIBRARIES "") else() diff --git a/src/framework/cmake/FindOpenAL.cmake b/src/framework/cmake/FindOpenAL.cmake index e4972173..4b7ed1eb 100644 --- a/src/framework/cmake/FindOpenAL.cmake +++ b/src/framework/cmake/FindOpenAL.cmake @@ -3,13 +3,14 @@ # OPENAL_INCLUDE_DIR - the OPENAL include directory # OPENAL_LIBRARY - the OPENAL library -FIND_PATH(OPENAL_INCLUDE_DIR NAMES AL/al.h) +SET(OPENAL_APPLE_PATHS ~/Library/Frameworks /Library/Frameworks) +FIND_PATH(OPENAL_INCLUDE_DIR NAMES AL/al.h PATHS ${OPENAL_APPLE_PATHS}) SET(_OPENAL_STATIC_LIBS libOpenAL.a libal.a libopenal.a libOpenAL32.a) SET(_OPENAL_SHARED_LIBS libOpenAL.dll.a libal.dll.a libopenal.dll.a libOpenAL32.dll.a OpenAL al openal OpenAL32) IF(USE_STATIC_LIBS) - FIND_LIBRARY(OPENAL_LIBRARY NAMES ${_OPENAL_STATIC_LIBS} ${_OPENAL_SHARED_LIBS}) + FIND_LIBRARY(OPENAL_LIBRARY NAMES ${_OPENAL_STATIC_LIBS} ${_OPENAL_SHARED_LIBS} PATHS ${OPENAL_APPLE_PATHS}) ELSE() - FIND_LIBRARY(OPENAL_LIBRARY NAMES ${_OPENAL_SHARED_LIBS} ${_OPENAL_STATIC_LIBS}) + FIND_LIBRARY(OPENAL_LIBRARY NAMES ${_OPENAL_SHARED_LIBS} ${_OPENAL_STATIC_LIBS} PATHS ${OPENAL_APPLE_PATHS}) ENDIF() INCLUDE(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(OPENAL DEFAULT_MSG OPENAL_LIBRARY OPENAL_INCLUDE_DIR) diff --git a/src/framework/core/eventdispatcher.cpp b/src/framework/core/eventdispatcher.cpp index 10365003..5f7547cb 100644 --- a/src/framework/core/eventdispatcher.cpp +++ b/src/framework/core/eventdispatcher.cpp @@ -75,16 +75,6 @@ void EventDispatcher::poll() } m_pollEventsSize = m_eventList.size(); } - - for(auto it = m_coroutines.begin(); it != m_coroutines.end();) { - stdext::coroutine& coroutine = (*it); - if(coroutine.is_finished()) - it = m_coroutines.erase(it); - else { - coroutine.resume(); - ++it; - } - } } ScheduledEventPtr EventDispatcher::scheduleEvent(const std::function& callback, int delay) @@ -125,7 +115,3 @@ EventPtr EventDispatcher::addEvent(const std::function& callback, bool p return event; } -void EventDispatcher::addCoroutine(const stdext::coroutine& coroutine) -{ - m_coroutines.push_back(coroutine); -} diff --git a/src/framework/core/eventdispatcher.h b/src/framework/core/eventdispatcher.h index 0ae83a19..2b837e12 100644 --- a/src/framework/core/eventdispatcher.h +++ b/src/framework/core/eventdispatcher.h @@ -27,7 +27,6 @@ #include "scheduledevent.h" #include -#include // @bindsingleton g_dispatcher class EventDispatcher @@ -36,7 +35,6 @@ public: void shutdown(); void poll(); - void addCoroutine(const stdext::coroutine& coroutine); EventPtr addEvent(const std::function& callback, bool pushFront = false); ScheduledEventPtr scheduleEvent(const std::function& callback, int delay); ScheduledEventPtr cycleEvent(const std::function& callback, int delay); @@ -46,7 +44,6 @@ private: int m_pollEventsSize; stdext::boolean m_disabled; std::priority_queue, lessScheduledEvent> m_scheduledEventList; - std::list m_coroutines; }; extern EventDispatcher g_dispatcher; diff --git a/src/framework/luaengine/luabinder.h b/src/framework/luaengine/luabinder.h index d58ef085..bb4e5027 100644 --- a/src/framework/luaengine/luabinder.h +++ b/src/framework/luaengine/luabinder.h @@ -205,7 +205,7 @@ namespace luabinder template LuaCppFunction bind_mem_fun(int (C::*f)(LuaInterface*)) { auto mf = std::mem_fn(f); - return [=](LuaInterface* lua) -> int { + return [=](LuaInterface* lua) mutable -> int { auto obj = lua->castValue>(1); lua->remove(1); return mf(obj, lua); diff --git a/src/framework/net/protocol.cpp b/src/framework/net/protocol.cpp index e90b3f0d..ae0c1be1 100644 --- a/src/framework/net/protocol.cpp +++ b/src/framework/net/protocol.cpp @@ -23,6 +23,7 @@ #include "protocol.h" #include "connection.h" #include +#include Protocol::Protocol() { diff --git a/src/framework/stdext/coroutine.h b/src/framework/stdext/coroutine.h deleted file mode 100644 index 61c33701..00000000 --- a/src/framework/stdext/coroutine.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2010-2013 OTClient - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef COROUTINE_H -#define COROUTINE_H - -#include "thread.h" -#include -#include - -namespace stdext { - -class coroutine -{ - struct codata : public stdext::shared_object { - std::unique_ptr thread; - std::condition_variable conditionVar; - std::mutex mutex; - std::function func; - }; - - stdext::shared_object_ptr m; - - void run() { - assert(m->func); - m->func(); - std::lock_guard lock(m->mutex); - m->func = nullptr; - m->conditionVar.notify_all(); - } - -public: - coroutine() : m(stdext::make_shared_object()) { } - coroutine(const coroutine& other) : m(other.m) { } - - coroutine& operator=(const coroutine& other) { m = other.m; return *this; } - - ~coroutine() { - if(m.is_unique()) { - m->conditionVar.notify_all(); - m->thread->join(); - assert(!m->func); - } - } - - void create(const std::function& func) { - assert(!!func && !m->func); - m->func = func; - } - - void yield() const { - std::unique_lock lock(m->mutex); - m->conditionVar.notify_all(); - m->conditionVar.wait(lock); - } - - void resume() { - if(!m->thread) { - std::unique_lock lock(m->mutex); - m->thread.reset(new std::thread(std::bind(&coroutine::run, this))); - m->conditionVar.wait(lock); // wait for the thread to start - } else { - std::unique_lock lock(m->mutex); - assert(m->func); - m->conditionVar.notify_all(); - m->conditionVar.wait(lock); - } - } - - void join() { - while(!is_finished()) - resume(); - } - - bool is_suspended() { return !!m->func; } - bool is_finished() { return !m->func; } -}; - -}; - -#endif diff --git a/src/framework/stdext/types.h b/src/framework/stdext/types.h index a01e4fb6..a6824542 100644 --- a/src/framework/stdext/types.h +++ b/src/framework/stdext/types.h @@ -24,6 +24,7 @@ #define STDEXT_TYPES_H #include +#include typedef unsigned char uchar; typedef unsigned short ushort;