From 28c6d28fecec40f573859b87eb0700cd09f17315 Mon Sep 17 00:00:00 2001 From: NickYang <362148418@qq.com> Date: Sat, 10 Mar 2018 16:34:28 +0800 Subject: [PATCH 01/24] add new timer by using std::priority_queue fix error VariantData type add cpp version macros Former-commit-id: 19345d38b6cb2cf7210c1779db181d5bc97dd873 Former-commit-id: d4969f03050fc949da780d22021ac011ca8ca237 --- Frame/Examples/Tutorial1/HelloWorld1.cpp | 15 +- Frame/SDK/Core/Base/AFMacros.hpp | 17 +- Frame/SDK/Core/Base/AFPlatform.hpp | 1 + Frame/SDK/Core/Base/AFTimer.h | 157 +++++++ Frame/SDK/Core/Base/timer.hpp | 482 -------------------- Frame/SDK/Core/Core.vcxproj | 1 + Frame/SDK/Core/Core.vcxproj.filters | 3 + Frame/SDK/KernelPlugin/AFCElementModule.cpp | 2 +- Frame/SDK/Net/AFCNetServer.cpp | 14 +- 9 files changed, 187 insertions(+), 505 deletions(-) create mode 100644 Frame/SDK/Core/Base/AFTimer.h delete mode 100644 Frame/SDK/Core/Base/timer.hpp diff --git a/Frame/Examples/Tutorial1/HelloWorld1.cpp b/Frame/Examples/Tutorial1/HelloWorld1.cpp index f87bb1b3..e1391041 100644 --- a/Frame/Examples/Tutorial1/HelloWorld1.cpp +++ b/Frame/Examples/Tutorial1/HelloWorld1.cpp @@ -19,15 +19,8 @@ */ #include "HelloWorld1.h" -#include "SDK/Core/Base/timer.hpp" #include "SDK/Core/Base/AFMemAlloc.h" -using timer_t = timer >; -timer_t* t = new timer_t(); -timer_t* t2 = new timer_t(); -int32_t time_id_1 = 0; -int32_t time_id_2 = 0; - bool HelloWorld1::Init() { std::cout << typeid(HelloWorld1).name() << std::endl; @@ -42,11 +35,6 @@ bool HelloWorld1::Init() bool HelloWorld1::AfterInit() { std::cout << "Hello, world1, AfterInit" << std::endl; - - // test timer - time_id_1 = t->repeat(1000, 10, [](timerid_t id) { std::cout << "T1 ID = " << id << ", interval=1000ms print timer update" << std::endl; }); - time_id_2 = t2->repeat(1500, 10, [](timerid_t id) { std::cout << "T2 ID = " << id << ", interval=1500ms print timer update" << std::endl; }); - ////////////////////////////////////////////////////////////////////////// //test memory alloc void* ptr1 = ARK_ALLOC(100); @@ -69,8 +57,7 @@ bool HelloWorld1::AfterInit() void HelloWorld1::Update() { - t->update(); - t2->update(); + } bool HelloWorld1::BeforeShut() diff --git a/Frame/SDK/Core/Base/AFMacros.hpp b/Frame/SDK/Core/Base/AFMacros.hpp index 2ce9a0ef..fb8af634 100644 --- a/Frame/SDK/Core/Base/AFMacros.hpp +++ b/Frame/SDK/Core/Base/AFMacros.hpp @@ -143,14 +143,29 @@ # define ARK_SHARE_PTR std::shared_ptr #endif - +//Google Protobuffer use dll #if ARK_PLATFORM == PLATFORM_WIN #if !defined(PROTOBUF_USE_DLLS) #define PROTOBUF_USE_DLLS #endif #endif +//Singleton #define ARK_SINGLETON_INIT(TYPE) template<> TYPE* Singleton::instance_ = 0; + +//cpp version +#if (__cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800)) +#define HAVE_LANG_CXX11 1 +#endif + +#if (__cplusplus >= 201402L || (defined(_MSC_VER) && _MSC_VER >= 1900)) +#define HAVE_LANG_CXX14 1 +#endif + +#if (__cplusplus >= 201703L || (defined(_MSC_VER) && _MSC_VER >= 1910)) +#define HAVE_LANG_CXX17 1 +#endif + /* #if ARK_PLATFORM == PLATFORM_WIN # if defined(ARK_USE_TCMALLOC) diff --git a/Frame/SDK/Core/Base/AFPlatform.hpp b/Frame/SDK/Core/Base/AFPlatform.hpp index 8f20797f..26d1674f 100644 --- a/Frame/SDK/Core/Base/AFPlatform.hpp +++ b/Frame/SDK/Core/Base/AFPlatform.hpp @@ -53,6 +53,7 @@ #include #include #include +#include #define NOMINMAX #if defined(__WIN32__) || defined(WIN32) || defined(_WIN32) || defined(__WIN64__) || defined(WIN64) || defined(_WIN64) diff --git a/Frame/SDK/Core/Base/AFTimer.h b/Frame/SDK/Core/Base/AFTimer.h new file mode 100644 index 00000000..c20cbf74 --- /dev/null +++ b/Frame/SDK/Core/Base/AFTimer.h @@ -0,0 +1,157 @@ +/* +* This source file is part of ArkGameFrame +* For the latest info, see https://github.com/ArkGame +* +* Copyright (c) 2013-2018 ArkGame authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ + +#pragma once + +#include "AFPlatform.hpp" + +class AFTimerManager; + +class AFTimer +{ +public: + using TimerPtr = std::shared_ptr; + using TimerWeakPtr = std::weak_ptr; + using TimerCallback = std::function; + using stready_time_point = std::chrono::steady_clock::time_point; + +public: + AFTimer(stready_time_point start_time, std::chrono::nanoseconds last_time, TimerCallback func) noexcept + : mxStartTime(std::move(start_time)) + , mxLastTime(std::move(last_time)) + , mxCallback(std::move(func)) + , mbActive(true) + { + } + + const stready_time_point& GetStartTime() const + { + return mxStartTime; + } + + const std::chrono::nanoseconds& GetLastTime() const + { + return mxLastTime; + } + + std::chrono::nanoseconds& GetLeftTime() const + { + return GetLastTime() - (std::chrono::steady_clock::now() - GetStartTime()); + } + + void Cancel() + { + mbActive = false; + } + +protected: + void operator() () + { + if (mbActive) + { + mxCallback(); + } + } +private: + bool mbActive; + TimerCallback mxCallback; + const stready_time_point mxStartTime; + std::chrono::nanoseconds mxLastTime; + + //need add count or forever + //need add param + + friend class AFTimerManager; +}; + +class AFTimerManager +{ +public: + using TimerManagerPtr = std::shared_ptr; + + template + AFTimer::TimerWeakPtr AddTimer(std::chrono::nanoseconds timeout, F callback, TArgs&& ... args) + { + auto timer = std::make_shared(std::chrono::steady_clock::now(), + std::chrono::nanoseconds(timeout), + std::bind(std::move(callback), std::forward(args)...)); + mxTimers.push(timer); + return timer; + } + + void Update() + { + while (!mxTimers.empty()) + { + auto tmp = mxTimers.top(); + if (tmp->GetLeftTime() > std::chrono::nanoseconds::zero()) + { + break; + } + + mxTimers.pop(); + (*tmp)(); + } + } + + bool Empty() const + { + return mxTimers.empty(); + } + + std::chrono::nanoseconds GetLeftTime() const + { + if (mxTimers.empty()) + { + return std::chrono::nanoseconds::zero(); + } + + auto result = mxTimers.top()->GetLastTime(); + if (result < std::chrono::nanoseconds::zero()) + { + return std::chrono::nanoseconds::zero(); + } + + return result; + } + + void Clear() + { + while (!mxTimers.empty()) + { + mxTimers.pop(); + } + } + +private: + class CompareTimer + { + public: + bool operator()(const AFTimer::TimerPtr& left, const AFTimer::TimerPtr& right) + { + auto start_diff = left->GetStartTime() - right->GetStartTime(); + auto last_diff = left->GetLastTime() - right->GetLastTime(); + auto diff = start_diff.count() - last_diff.count(); + return (diff > 0); + } + }; + + std::priority_queue, CompareTimer> mxTimers; +}; \ No newline at end of file diff --git a/Frame/SDK/Core/Base/timer.hpp b/Frame/SDK/Core/Base/timer.hpp deleted file mode 100644 index 203b8781..00000000 --- a/Frame/SDK/Core/Base/timer.hpp +++ /dev/null @@ -1,482 +0,0 @@ -/**************************************************************************** - -Git -E-Mail -Copyright (c) 2015-2017 moon -Licensed under the MIT License . - -****************************************************************************/ -#pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -using timerid_t = uint32_t; -template -class timer_context -{ -public: - using timer_handler_t = TimerHandler; - - timer_context(const timer_handler_t& callBack, int32_t duration, bool forever = false) - : removed_(false) - , forever_(forever) - , id_(0) - , repeattimes_(0) - , duration_(duration) - , endtime_(0) - , handler_(callBack) - { - } - - timer_context(timer_handler_t&& callBack, int32_t duration, bool forever = false) - : removed_(false) - , forever_(forever) - , id_(0) - , repeattimes_(0) - , duration_(duration) - , endtime_(0) - , handler_(std::forward(callBack)) - { - } - - void init(timer_handler_t&& callBack, int32_t duration, bool forever = false) - { - removed_ = false; - forever_ = forever; - id_ = 0; - repeattimes_ = 0; - duration_ = duration; - endtime_ = 0; - handler_ = std::forward(callBack); - } - - void id(timerid_t value) - { - id_ = value; - } - - timerid_t id() - { - return id_; - } - - void endtime(int64_t value) - { - endtime_ = value; - } - - int64_t endtime() - { - return endtime_; - } - - int64_t duration() - { - return duration_; - } - - void repeattimes(int32_t value) - { - repeattimes_ = value; - } - - int32_t repeattimes() - { - return repeattimes_; - } - - void expired(timerid_t id) - { - assert(nullptr != handler_); - handler_(id); - } - - void removed(bool value) - { - removed_ = value; - } - - bool removed() - { - return removed_; - } - - bool forever() - { - return forever_; - } -private: - bool removed_; - bool forever_; - timerid_t id_; - int32_t repeattimes_;//重复次数,-1循环 - int32_t duration_; - int64_t endtime_; - timer_handler_t handler_;//调度器回掉 -}; - -template -class timer_wheel -{ -public: - timer_wheel() - : m_head(0) - { - } - - TContainer & operator[](uint8_t pos) - { - assert(pos < TSize); - return m_array[pos]; - } - - TContainer & front() - { - assert(m_head < TSize); - return m_array[m_head]; - } - - void pop_front() - { - auto tmp = ++m_head; - m_head = tmp % TSize; - } - - bool round() - { - return m_head == 0; - } - - uint8_t size() - { - return TSize; - } - - size_t next_slot() - { - return m_head; - } -private: - TContainer m_array[TSize]; - uint32_t m_head; -}; - -inline int64_t millseconds() -{ - return std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); -} - -template -class timer -{ - using timer_handler_t = TimerHandler; - using timer_context_ptr = std::shared_ptr>; - - //every wheel size,max 255 - static const uint8_t WHEEL_SIZE = 255; - //precision ms - static const int32_t PRECISION = 10; - - static const int TIMERID_SHIT = 32; - - static const uint32_t MAX_TIMER_NUM = UINT32_MAX - 1; //max = power(2, 32) - - using timer_wheel_t = timer_wheel, WHEEL_SIZE>; -public: - timer() - : tick_(0) - , prew_tick_(0) - , uuid_(1) - , stop_(false) - { - wheels_.emplace_back(); - wheels_.emplace_back(); - wheels_.emplace_back(); - wheels_.emplace_back(); - } - - ~timer() - { - - } - /** - * 添加一个只执行一次的计时器 - * - * @duration 计时器间隔 ms - * @callBack 回掉函数 - * typedef std::function timer_handler_t; - * 返回计时器ID - */ - timerid_t expired_once(int32_t duration, const timer_handler_t& callBack) - { - if (duration < PRECISION) - duration = PRECISION; - auto pt = std::make_shared>(callBack, duration, false); - pt->repeattimes(1); - return add_new_timer(pt); - } - - timerid_t expired_once(int32_t duration, timer_handler_t&& callBack) - { - if (duration < PRECISION) - duration = PRECISION; - auto pt = std::make_shared>(std::forward(callBack), duration, false); - pt->repeattimes(1); - return add_new_timer(pt); - } - - /** - * 添加重复执行的计时器 - * - * @duration 计时器间隔 ms - * @times 重复次数,(-1 无限循环) - * @callBack 回掉函数 - * typedef std::function timer_handler_t; - * 返回计时器ID - */ - timerid_t repeat(int32_t duration, int32_t times, const timer_handler_t& callBack) - { - if (duration < PRECISION) - { - duration = PRECISION; - } - - auto pt = std::make_shared>(callBack, duration, times < 0); - pt->repeattimes(times); - return add_new_timer(pt); - } - - timerid_t repeat(int32_t duration, int32_t times, timer_handler_t&& callBack) - { - if (duration < PRECISION) - { - duration = PRECISION; - } - - auto pt = std::make_shared>(std::forward(callBack), duration, times < 0); - pt->repeattimes(times); - return add_new_timer(pt); - } - - /** - * 移除一个计时器 - * - * @timerid 计时器 ID - */ - void remove(timerid_t timerid) - { - auto iter = timers_.find(timerid); - if (iter != timers_.end()) - { - iter->second->removed(true); - return; - } - - for (auto& nit : new_timers_) - { - if (nit->id() == timerid) - { - nit->removed(true); - break; - } - } - } - - //逻辑线程需要调用这个函数,驱动计时器 - void update() - { - auto nowTick = millseconds(); - for (auto& it : new_timers_) - { - if (it->removed()) - continue; - add_timer(nowTick, it); - } - new_timers_.clear(); - - if (prew_tick_ == 0) - { - prew_tick_ = nowTick; - } - - tick_ += (nowTick - prew_tick_); - prew_tick_ = nowTick; - - auto& wheels = wheels_; - while (tick_ >= PRECISION) - { - tick_ -= PRECISION; - if (stop_) - continue; - - { - auto& timers = wheels[0].front(); - if (!timers.empty()) - { - expired(timers); - } - wheels[0].pop_front(); - } - - int i = 0; - for (auto wheel = wheels.begin(); wheel != wheels.end(); ++wheel, ++i) - { - auto next_wheel = wheel; - if (wheels.end() == (++next_wheel)) - break; - - if (wheel->round()) - { - auto& timers = next_wheel->front(); - while (!timers.empty()) - { - auto key = timers.front(); - timers.pop_front(); - auto slot = get_slot(key, i); - (*wheel)[slot].push_front(key); - //printf("update timer id %u add to wheel [%d] slot [%d]\r\n", (key>>32), i+1, slot); - } - next_wheel->pop_front(); - } - else - { - break; - } - } - } - } - - void stop_all_timer() - { - stop_ = true; - } - - void start_all_timer() - { - stop_ = false; - } - -private: - //slots: 8bit(notuse) 8bit(wheel3_slot) 8bit(wheel2_slot) 8bit(wheel1_slot) - uint64_t make_key(timerid_t id, uint32_t slots) - { - return ((static_cast(id) << TIMERID_SHIT) | slots); - } - - inline uint8_t get_slot(uint64_t key, int which_queue) - { - return (key >> (which_queue * 8)) & 0xFF; - } - - timerid_t add_new_timer(const timer_context_ptr& t) - { - t->endtime(t->duration() + millseconds()); - if (t->id() == 0) - { - if (uuid_ == 0 || uuid_ == MAX_TIMER_NUM) - { - uuid_ = 1; - } - - auto& timers = timers_; - while (timers.find(uuid_) != timers.end()) - { - ++uuid_; - } - t->id(uuid_); - timers_.emplace(t->id(), t); - } - new_timers_.push_back(t); - return t->id(); - } - - void add_timer(int64_t now, const timer_context_ptr& t) - { - if (t->endtime() > now) - { - auto diff = t->duration(); - auto offset = diff % PRECISION; - //校正 - if (offset > 0) - { - diff += PRECISION; - } - auto slot_count = diff / PRECISION; - slot_count = (slot_count > 0) ? slot_count : 1; - uint64_t key = 0; - do - { - int i = 0; - uint32_t slots = 0; - for (auto it = wheels_.begin(); it != wheels_.end(); it++, i++) - { - auto& wheel = *it; - slot_count += wheel.next_slot(); - uint8_t slot = (slot_count - 1) % (wheel.size()); - slot_count -= slot; - slots |= ( static_cast(slot) << (i * 8)); - key = make_key(t->id(), slots); - //printf("process timer id %u wheel[%d] slot[%d]\r\n", t->id(), i+1, slot); - if (slot_count < wheel.size()) - { - //printf("timer id %u add to wheel [%d] slot [%d]\r\n",t->id(), i + 1, slot); - wheel[slot].push_back(key); - break; - } - slot_count /= wheel.size(); - } - break; - }while (0); - } - else - { - wheels_[0].front().push_back(make_key(t->id(), 0)); - //printf("time out.\r\n"); - } - } - - void expired(std::list& expires) - { - while (!expires.empty()) - { - auto key = expires.front(); - expires.pop_front(); - timerid_t id = static_cast(key >> TIMERID_SHIT); - auto iter = timers_.find(id); - if (iter == timers_.end()) - { - continue; - } - - auto& ctx = iter->second; - if (!ctx->removed()) - { - ctx->expired(id); - ctx->repeattimes(ctx->repeattimes() - 1); - - if (ctx->repeattimes() > 0 || ctx->forever()) - { - add_new_timer(ctx); - continue; - } - } - timers_.erase(iter); - } - } -private: - int64_t tick_; - int64_t prew_tick_; - uint32_t uuid_; - bool stop_; - std::vector wheels_; - std::unordered_map timers_; - std::vector new_timers_; -}; diff --git a/Frame/SDK/Core/Core.vcxproj b/Frame/SDK/Core/Core.vcxproj index c65c72d2..8d19265a 100644 --- a/Frame/SDK/Core/Core.vcxproj +++ b/Frame/SDK/Core/Core.vcxproj @@ -140,6 +140,7 @@ + diff --git a/Frame/SDK/Core/Core.vcxproj.filters b/Frame/SDK/Core/Core.vcxproj.filters index 9b3972ba..9e090b18 100644 --- a/Frame/SDK/Core/Core.vcxproj.filters +++ b/Frame/SDK/Core/Core.vcxproj.filters @@ -141,6 +141,9 @@ Base + + Base + diff --git a/Frame/SDK/KernelPlugin/AFCElementModule.cpp b/Frame/SDK/KernelPlugin/AFCElementModule.cpp index 08cc8d6a..b1056439 100644 --- a/Frame/SDK/KernelPlugin/AFCElementModule.cpp +++ b/Frame/SDK/KernelPlugin/AFCElementModule.cpp @@ -189,7 +189,7 @@ bool AFCElementModule::Load(rapidxml::xml_node<>* attrNode, ARK_SHARE_PTRname.c_str(), __FILE__, __FUNCTION__); } - pTmpNode->value.SetDouble(ARK_LEXICAL_CAST(pstrConfigValue)); + pTmpNode->value.SetFloat(ARK_LEXICAL_CAST(pstrConfigValue)); } break; case DT_DOUBLE: diff --git a/Frame/SDK/Net/AFCNetServer.cpp b/Frame/SDK/Net/AFCNetServer.cpp index b51a0e9e..6deb7377 100644 --- a/Frame/SDK/Net/AFCNetServer.cpp +++ b/Frame/SDK/Net/AFCNetServer.cpp @@ -50,18 +50,18 @@ int AFCNetServer::Start(const unsigned int nMaxClient, const std::string& strAdd mnMaxConnect = (int)nMaxClient; mstrIPPort = strAddrPort; -#if __cplusplus < 201402L - m_pListenThread.reset(new evpp::EventLoopThread); -#else +#if defined(HAVE_LANG_CXX14) || defined(HAVE_LANG_CXX17) m_pListenThread = std::make_unique(); +#else + m_pListenThread.reset(new evpp::EventLoopThread); #endif - m_pListenThread->set_name("LisenThread"); m_pListenThread->Start(true); -#if __cplusplus < 201402L - m_pTcpSrv.reset(new evpp::TCPServer(m_pListenThread->loop(), strAddrPort, "tcp_server", nThreadCount)); -#else + +#if defined(HAVE_LANG_CXX14) || defined(HAVE_LANG_CXX17) m_pTcpSrv = std::make_unique(m_pListenThread->loop(), strAddrPort, "tcp_server", nThreadCount); +#else + m_pTcpSrv.reset(new evpp::TCPServer(m_pListenThread->loop(), strAddrPort, "tcp_server", nThreadCount)); #endif m_pTcpSrv->SetMessageCallback(std::bind(&AFCNetServer::OnMessageInner, this, std::placeholders::_1, std::placeholders::_2)); m_pTcpSrv->SetConnectionCallback(std::bind(&AFCNetServer::OnClientConnectionInner,this, std::placeholders::_1)); From 35004ed70d358dd9ffeb81fe1719228473f3c026 Mon Sep 17 00:00:00 2001 From: NickYang <362148418@qq.com> Date: Sat, 17 Mar 2018 15:27:25 +0800 Subject: [PATCH 02/24] add time-wheel timer add schedule module(unfinished) Former-commit-id: 893298608bba38fa78020d8ffd4a2531efd74935 Former-commit-id: a59c15e97b0f2c60a98aaa86d6535d53cdf9a1c0 --- Frame/Examples/Tutorial1/HelloWorld1.cpp | 35 +- Frame/SDK/Core/Base/AFCData.h | 6 +- Frame/SDK/Core/Base/AFDefine.h | 7 +- Frame/SDK/Core/Base/AFPlatform.hpp | 1 + Frame/SDK/Core/Base/AFTime.hpp | 1 - Frame/SDK/Core/Base/AFTimer.h | 157 ------- Frame/SDK/Core/Base/AFTimer.hpp | 384 ++++++++++++++++++ Frame/SDK/Core/Core.vcxproj | 2 +- Frame/SDK/Core/Core.vcxproj.filters | 2 +- Frame/SDK/Interface/AFILogModule.h | 4 +- Frame/SDK/Interface/AFIScheduleModule.h | 33 ++ Frame/SDK/PluginLoader/AFPluginLoader.cpp | 7 +- Frame/SDK/UtilityPlugin/AFCScheduleModule.cpp | 69 ++++ Frame/SDK/UtilityPlugin/AFCScheduleModule.h | 46 +++ Frame/SDK/UtilityPlugin/UtilityPlugin.vcxproj | 2 + .../UtilityPlugin.vcxproj.filters | 27 +- 16 files changed, 594 insertions(+), 189 deletions(-) delete mode 100644 Frame/SDK/Core/Base/AFTimer.h create mode 100644 Frame/SDK/Core/Base/AFTimer.hpp create mode 100644 Frame/SDK/Interface/AFIScheduleModule.h create mode 100644 Frame/SDK/UtilityPlugin/AFCScheduleModule.cpp create mode 100644 Frame/SDK/UtilityPlugin/AFCScheduleModule.h diff --git a/Frame/Examples/Tutorial1/HelloWorld1.cpp b/Frame/Examples/Tutorial1/HelloWorld1.cpp index e1391041..575f312e 100644 --- a/Frame/Examples/Tutorial1/HelloWorld1.cpp +++ b/Frame/Examples/Tutorial1/HelloWorld1.cpp @@ -20,6 +20,10 @@ #include "HelloWorld1.h" #include "SDK/Core/Base/AFMemAlloc.h" +//#include "SDK/Core/Base/AFTimer.h" +// +//AFTimerManager::TimerManagerPtr gTimerManager; +//AFTimer::TimerWeakPtr timerPtr; bool HelloWorld1::Init() { @@ -28,6 +32,7 @@ bool HelloWorld1::Init() AFMemAlloc::InitPool(); AFMemAlloc::Start(); + //gTimerManager = std::shared_ptr(); return true; } @@ -35,23 +40,34 @@ bool HelloWorld1::Init() bool HelloWorld1::AfterInit() { std::cout << "Hello, world1, AfterInit" << std::endl; + AFCData data1(DT_STRING, "test1"); + AFCData data2(DT_STRING, "test2"); + + data1 = data2; + const char* str1 = data1.GetString(); ////////////////////////////////////////////////////////////////////////// - //test memory alloc - void* ptr1 = ARK_ALLOC(100); - memset(ptr1, 0, 100); + ////test memory alloc + //void* ptr1 = ARK_ALLOC(100); + //memset(ptr1, 0, 100); - void* ptr2 = ARK_ALLOC(10); + //void* ptr2 = ARK_ALLOC(10); - AFMemAlloc::CheckLeak(); + //AFMemAlloc::CheckLeak(); - ARK_FREE(ptr2); + //ARK_FREE(ptr2); - AFMemAlloc::CheckLeak(); + //AFMemAlloc::CheckLeak(); - ARK_FREE(ptr1); - AFMemAlloc::CheckLeak(); + //ARK_FREE(ptr1); + //AFMemAlloc::CheckLeak(); ////////////////////////////////////////////////////////////////////////// + //std::chrono::nanoseconds interval_time = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()) + std::chrono::nanoseconds{ 100000000 }; + //timerPtr = gTimerManager->AddTimer(interval_time, [=]() + //{ + // std::cout << "Run timer" << std::endl; + //}); + return true; } @@ -63,6 +79,7 @@ void HelloWorld1::Update() bool HelloWorld1::BeforeShut() { std::cout << "Hello, world1, BeforeShut-------------" << std::endl; + //timerPtr->Cancel(); return true; } diff --git a/Frame/SDK/Core/Base/AFCData.h b/Frame/SDK/Core/Base/AFCData.h index 9af02ee0..2feb91c3 100644 --- a/Frame/SDK/Core/Base/AFCData.h +++ b/Frame/SDK/Core/Base/AFCData.h @@ -237,9 +237,9 @@ class AFBaseData : public AFIData int tmp_type = this->mnType; int64_t tmp_value = this->mn64Value; uint32_t tmp_alloc_len = this->mnAllocLen; - char tmp_buffer[BUFFER_SIZE]; - bool tmp_use_buffer = (tmp_type == DT_STRING) || (this->mstrValue == this->mBuffer); - if((src.mnType == DT_STRING) || (src.mstrValue == src.mBuffer)) + char tmp_buffer[BUFFER_SIZE] = { 0 }; + bool tmp_use_buffer = (tmp_type == DT_STRING) && (this->mstrValue == this->mBuffer); + if((src.mnType == DT_STRING) && (src.mstrValue == src.mBuffer)) { if(tmp_use_buffer) { diff --git a/Frame/SDK/Core/Base/AFDefine.h b/Frame/SDK/Core/Base/AFDefine.h index 5c39d5bf..d69312b0 100644 --- a/Frame/SDK/Core/Base/AFDefine.h +++ b/Frame/SDK/Core/Base/AFDefine.h @@ -64,6 +64,8 @@ using CLASS_EVENT_FUNCTOR = std::function; //using EVENT_ASYNC_PROCESS_BEGIN_FUNCTOR = std::function; //using EVENT_ASYNC_PROCESS_END_FUNCTOR = std::function; +using TIMER_FUNCTOR = std::function; +using SCHEDULE_FUNCTOR = std::function; using HEART_BEAT_FUNCTOR_PTR = ARK_SHARE_PTR; using MODULE_HEART_BEAT_FUNCTOR_PTR = ARK_SHARE_PTR; @@ -71,6 +73,7 @@ using DATA_NODE_EVENT_FUNCTOR_PTR = ARK_SHARE_PTR; using DATA_TABLE_EVENT_FUNCTOR_PTR = ARK_SHARE_PTR; using CLASS_EVENT_FUNCTOR_PTR = ARK_SHARE_PTR; using EVENT_PROCESS_FUNCTOR_PTR = ARK_SHARE_PTR; - //using EVENT_ASYNC_PROCESS_BEGIN_FUNCTOR_PTR = ARK_SHARE_PTR; -//using EVENT_ASYNC_PROCESS_END_FUNCTOR_PTR = ARK_SHARE_PTR; \ No newline at end of file +//using EVENT_ASYNC_PROCESS_END_FUNCTOR_PTR = ARK_SHARE_PTR; +using TIMER_FUNCTOR_PTR = ARK_SHARE_PTR; +using SCHEDULE_FUNCTOR_PTR = ARK_SHARE_PTR; \ No newline at end of file diff --git a/Frame/SDK/Core/Base/AFPlatform.hpp b/Frame/SDK/Core/Base/AFPlatform.hpp index 26d1674f..f8a38444 100644 --- a/Frame/SDK/Core/Base/AFPlatform.hpp +++ b/Frame/SDK/Core/Base/AFPlatform.hpp @@ -54,6 +54,7 @@ #include #include #include +#include #define NOMINMAX #if defined(__WIN32__) || defined(WIN32) || defined(_WIN32) || defined(__WIN64__) || defined(WIN64) || defined(_WIN64) diff --git a/Frame/SDK/Core/Base/AFTime.hpp b/Frame/SDK/Core/Base/AFTime.hpp index 3f2eb2b2..74756fa3 100644 --- a/Frame/SDK/Core/Base/AFTime.hpp +++ b/Frame/SDK/Core/Base/AFTime.hpp @@ -55,7 +55,6 @@ class AFCTimeBase : return std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); } - //static int64_t GetNowSecondTime(); //单位是秒, 特定时区时间 (尽量少用,特别注意:因为NFTime里用的都是毫秒,如果要将此结果的值转成NFTime,需要 *1000) int64_t GetNowMillisecond() //单位是毫秒, 特定时区时间 { return std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count() + GetTimeZoneMillisecond(); diff --git a/Frame/SDK/Core/Base/AFTimer.h b/Frame/SDK/Core/Base/AFTimer.h deleted file mode 100644 index c20cbf74..00000000 --- a/Frame/SDK/Core/Base/AFTimer.h +++ /dev/null @@ -1,157 +0,0 @@ -/* -* This source file is part of ArkGameFrame -* For the latest info, see https://github.com/ArkGame -* -* Copyright (c) 2013-2018 ArkGame authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* -*/ - -#pragma once - -#include "AFPlatform.hpp" - -class AFTimerManager; - -class AFTimer -{ -public: - using TimerPtr = std::shared_ptr; - using TimerWeakPtr = std::weak_ptr; - using TimerCallback = std::function; - using stready_time_point = std::chrono::steady_clock::time_point; - -public: - AFTimer(stready_time_point start_time, std::chrono::nanoseconds last_time, TimerCallback func) noexcept - : mxStartTime(std::move(start_time)) - , mxLastTime(std::move(last_time)) - , mxCallback(std::move(func)) - , mbActive(true) - { - } - - const stready_time_point& GetStartTime() const - { - return mxStartTime; - } - - const std::chrono::nanoseconds& GetLastTime() const - { - return mxLastTime; - } - - std::chrono::nanoseconds& GetLeftTime() const - { - return GetLastTime() - (std::chrono::steady_clock::now() - GetStartTime()); - } - - void Cancel() - { - mbActive = false; - } - -protected: - void operator() () - { - if (mbActive) - { - mxCallback(); - } - } -private: - bool mbActive; - TimerCallback mxCallback; - const stready_time_point mxStartTime; - std::chrono::nanoseconds mxLastTime; - - //need add count or forever - //need add param - - friend class AFTimerManager; -}; - -class AFTimerManager -{ -public: - using TimerManagerPtr = std::shared_ptr; - - template - AFTimer::TimerWeakPtr AddTimer(std::chrono::nanoseconds timeout, F callback, TArgs&& ... args) - { - auto timer = std::make_shared(std::chrono::steady_clock::now(), - std::chrono::nanoseconds(timeout), - std::bind(std::move(callback), std::forward(args)...)); - mxTimers.push(timer); - return timer; - } - - void Update() - { - while (!mxTimers.empty()) - { - auto tmp = mxTimers.top(); - if (tmp->GetLeftTime() > std::chrono::nanoseconds::zero()) - { - break; - } - - mxTimers.pop(); - (*tmp)(); - } - } - - bool Empty() const - { - return mxTimers.empty(); - } - - std::chrono::nanoseconds GetLeftTime() const - { - if (mxTimers.empty()) - { - return std::chrono::nanoseconds::zero(); - } - - auto result = mxTimers.top()->GetLastTime(); - if (result < std::chrono::nanoseconds::zero()) - { - return std::chrono::nanoseconds::zero(); - } - - return result; - } - - void Clear() - { - while (!mxTimers.empty()) - { - mxTimers.pop(); - } - } - -private: - class CompareTimer - { - public: - bool operator()(const AFTimer::TimerPtr& left, const AFTimer::TimerPtr& right) - { - auto start_diff = left->GetStartTime() - right->GetStartTime(); - auto last_diff = left->GetLastTime() - right->GetLastTime(); - auto diff = start_diff.count() - last_diff.count(); - return (diff > 0); - } - }; - - std::priority_queue, CompareTimer> mxTimers; -}; \ No newline at end of file diff --git a/Frame/SDK/Core/Base/AFTimer.hpp b/Frame/SDK/Core/Base/AFTimer.hpp new file mode 100644 index 00000000..52e1be20 --- /dev/null +++ b/Frame/SDK/Core/Base/AFTimer.hpp @@ -0,0 +1,384 @@ +/* +* This source file is part of ArkGameFrame +* For the latest info, see https://github.com/ArkGame +* +* Copyright (c) 2013-2018 ArkGame authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ + +#pragma once + +#include "AFPlatform.hpp" +#include "AFDefine.h" +#include "AFSingleton.hpp" +#include "AFTime.hpp" + +enum AFTimerEnum +{ + TIMER_TYPE_COUNT_LIMIT = 0, + TIMER_TYPE_FOREVER = 1, + + MAX_SLOT = 1000, + SLOT_TIME = 1, + WHEEL_TIME = MAX_SLOT * SLOT_TIME, +}; + +class AFTimerData +{ +public: + AFTimerData() {} + + std::string name{ "" }; + uint8_t type{ 0 }; + uint16_t count{ 0 }; + uint32_t interval{ 0 }; + uint32_t rotation{ 0 }; + uint16_t slot{ 0 }; + TIMER_FUNCTOR_PTR callback; + + //callback data + AFGUID entity_id{ 0 }; + + AFTimerData* prev; + AFTimerData* next; +}; + +class AFTimerManager : public AFSingleton +{ +public: + AFTimerManager() + { + mnNowSlot = 0; + mnLastUpdateTime = 0; + memset(mxSlots, 0x0, sizeof(mxSlots)); + } + + ~AFTimerManager() + { + + } + + void Init() + { + mnNowSlot = 0; + mnLastUpdateTime = AFCTimeBase::GetInstance().GetNowMillisecond(); + } + + void Update() + { + UpdateTimerReg(); + UpdateTimer(); + } + + void Shut() + { + for (auto iter : mxTimers) + { + for (auto it : iter.second) + { + ARK_DELETE(it.second); + } + } + + mxTimers.clear(); + memset(mxSlots, 0x0, sizeof(mxSlots)); + } + + bool AddForverTimer(const std::string& name, const AFGUID& entity_id, uint32_t interval_time, TIMER_FUNCTOR_PTR callback) + { + auto data = FindTimerData(name, entity_id); + if (data == nullptr) + { + data = (AFTimerData*)ARK_ALLOC(sizeof(AFTimerData)); + memset(data, 0x0, sizeof(data)); + AddTimerData(name, entity_id, data); + } + else + { + RemoveSlotTimer(data); + } + + data->name = name; + data->type = TIMER_TYPE_FOREVER; + data->interval = interval_time; + data->callback = callback; + data->entity_id = entity_id; + mxRegTimers.push_back(data); + return true; + } + + bool AddSingleTimer(const std::string& name, const AFGUID& entity_id, uint32_t interval_time, uint16_t count, TIMER_FUNCTOR_PTR callback) + { + auto data = FindTimerData(name, entity_id); + if (data == nullptr) + { + data = (AFTimerData*)ARK_ALLOC(sizeof(AFTimerData)); + memset(data, 0x0, sizeof(data)); + AddTimerData(name, entity_id, data); + } + else + { + RemoveSlotTimer(data); + } + + data->name = name; + data->type = TIMER_TYPE_FOREVER; + data->count = std::max((uint16_t)1, count); + data->interval = interval_time; + data->callback = callback; + data->entity_id = entity_id; + mxRegTimers.push_back(data); + return true; + } + + bool RemoveTimer(const std::string& name) + { + return RemoveTimerData(name); + } + + bool RemoveTimer(const std::string& name, const AFGUID& entity_id) + { + return RemoveTimerData(name, entity_id); + } + + uint32_t FindLeftTime(const std::string& name, const AFGUID& entity_id) + { + //TODO: + return 0; + } + +protected: + void UpdateTimer() + { + //TODO:需要替换为一个统一的系统时间 + uint64_t now = AFCTimeBase::GetInstance().GetNowMillisecond(); + uint16_t passedSlot = (now - mnLastUpdateTime) / SLOT_TIME; + if (passedSlot == 0) + { + return; + } + + mnLastUpdateTime += passedSlot * SLOT_TIME; + for (uint16_t i = 0; i < passedSlot; ++i) + { + mnNowSlot = (mnNowSlot + 1) % MAX_SLOT; + UpdateSlotTimer(); + } + } + + void UpdateTimerReg() + { + if (mxRegTimers.empty()) + { + return; + } + + for (auto data : mxRegTimers) + { + switch (data->type) + { + case TIMER_TYPE_FOREVER: + AddSlotTimer(data, true); + break; + case TIMER_TYPE_COUNT_LIMIT: + AddSlotTimer(data, false); + break; + default: + ARK_ASSERT_NO_EFFECT(0); + break; + } + } + + mxRegTimers.clear(); + } + + AFTimerData* FindTimerData(const std::string& name, const AFGUID& entity_id) + { + auto iter = mxTimers.find(name); + if (iter == mxTimers.end()) + { + return nullptr; + } + + auto it = iter->second.find(entity_id); + if (it == iter->second.end()) + { + return nullptr; + } + + return it->second; + } + + bool AddTimerData(const std::string& name, const AFGUID& entity_id, AFTimerData* timer_data) + { + auto& iter = mxTimers.find(name); + if (iter == mxTimers.end()) + { + std::map tmp; + iter = mxTimers.insert(std::make_pair(name, tmp)).first; + } + + return iter->second.insert(std::make_pair(entity_id, timer_data)).second; + } + + bool RemoveTimerData(const std::string& name) + { + auto iter = mxTimers.find(name); + if (iter == mxTimers.end()) + { + return false; + } + + for (auto it : iter->second) + { + AFTimerData* data = it.second; + RemoveSlotTimer(data); + ARK_DELETE(data); + } + + iter->second.clear(); + mxTimers.erase(iter); + return true; + } + + bool RemoveTimerData(const std::string& name, const AFGUID& entity_id) + { + auto iter = mxTimers.find(name); + if (iter == mxTimers.end()) + { + return false; + } + + auto it = iter->second.find(entity_id); + if (it == iter->second.end()) + { + return false; + } + + AFTimerData* data = it->second; + RemoveSlotTimer(data); + ARK_DELETE(data); + + iter->second.erase(it); + if (iter->second.empty()) + { + mxTimers.erase(iter); + } + + return true; + } + + void AddSlotTimer(AFTimerData* timer_data, bool first) + { + if (first) + { + timer_data->rotation = 0; + timer_data->slot = (mnNowSlot + 1) % MAX_SLOT; + } + else + { + uint32_t ticks = timer_data->interval / SLOT_TIME; + timer_data->rotation = ticks / MAX_SLOT; + timer_data->slot = ((ticks % MAX_SLOT) + mnNowSlot) % MAX_SLOT; + } + + auto wheelData = mxSlots[timer_data->slot]; + if (wheelData != nullptr) + { + timer_data->next = wheelData; + wheelData->prev = timer_data; + } + + mxSlots[timer_data->slot] = timer_data; + } + + void RemoveSlotTimer(AFTimerData* timer_data) + { + auto prev = timer_data->prev; + if (prev != nullptr) + { + prev->next = timer_data->next; + } + + auto next = timer_data->next; + if (next != nullptr) + { + next->prev = timer_data->prev; + } + + if (timer_data == mxSlots[timer_data->slot]) + { + mxSlots[timer_data->slot] = next; + } + + timer_data->prev = nullptr; + timer_data->next = nullptr; + } + + void UpdateSlotTimer() + { + std::list doneDatas; + auto timerData = mxSlots[mnNowSlot]; + while (timerData != nullptr) + { + if (timerData->rotation > 0) + { + --timerData->rotation; + } + else + { + doneDatas.push_back(timerData); + } + + timerData = timerData->next; + } + + for (auto data : doneDatas) + { + RemoveSlotTimer(data); + + (*(data->callback))(data->name, data->entity_id); + switch (data->type) + { + case TIMER_TYPE_FOREVER: + AddSlotTimer(data, false); + break; + case TIMER_TYPE_COUNT_LIMIT: + { + --data->count; + if (data->count == 0) + { + RemoveTimerData(data->name, data->entity_id); + } + else + { + AddSlotTimer(data, false); + } + } + break; + default: + RemoveTimerData(data->name, data->entity_id); + break; + } + } + } + +private: + uint16_t mnNowSlot; + AFTimerData* mxSlots[MAX_SLOT]; + uint64_t mnLastUpdateTime; + std::map> mxTimers; + std::list mxRegTimers; +}; \ No newline at end of file diff --git a/Frame/SDK/Core/Core.vcxproj b/Frame/SDK/Core/Core.vcxproj index 8d19265a..853845de 100644 --- a/Frame/SDK/Core/Core.vcxproj +++ b/Frame/SDK/Core/Core.vcxproj @@ -140,7 +140,7 @@ - + diff --git a/Frame/SDK/Core/Core.vcxproj.filters b/Frame/SDK/Core/Core.vcxproj.filters index 9e090b18..85a86c49 100644 --- a/Frame/SDK/Core/Core.vcxproj.filters +++ b/Frame/SDK/Core/Core.vcxproj.filters @@ -141,7 +141,7 @@ Base - + Base diff --git a/Frame/SDK/Interface/AFILogModule.h b/Frame/SDK/Interface/AFILogModule.h index 45f49d58..16404324 100644 --- a/Frame/SDK/Interface/AFILogModule.h +++ b/Frame/SDK/Interface/AFILogModule.h @@ -22,10 +22,8 @@ #include "AFIModule.h" -class AFILogModule - : public AFIModule +class AFILogModule : public AFIModule { - public: enum ARK_LOG_LEVEL { diff --git a/Frame/SDK/Interface/AFIScheduleModule.h b/Frame/SDK/Interface/AFIScheduleModule.h new file mode 100644 index 00000000..9b13a2aa --- /dev/null +++ b/Frame/SDK/Interface/AFIScheduleModule.h @@ -0,0 +1,33 @@ +/* +* This source file is part of ArkGameFrame +* For the latest info, see https://github.com/ArkGame +* +* Copyright (c) 2013-2018 ArkGame authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ + +#pragma once + +#include "SDK/Interface/AFIModule.h" + +class AFIScheduleModule : public AFIModule +{ +public: + virtual bool AddSchedule(const std::string& name, const SCHEDULE_FUNCTOR_PTR cb, const int64_t interval_time, const int count) = 0; + virtual bool RemoveSchedule(const std::string& name) = 0; + virtual bool ExistSchedule(const std::string& name) = 0; + + +}; \ No newline at end of file diff --git a/Frame/SDK/PluginLoader/AFPluginLoader.cpp b/Frame/SDK/PluginLoader/AFPluginLoader.cpp index 3b6b11c0..9e8db8aa 100644 --- a/Frame/SDK/PluginLoader/AFPluginLoader.cpp +++ b/Frame/SDK/PluginLoader/AFPluginLoader.cpp @@ -103,7 +103,6 @@ void CreateBackThread() { gThread = std::thread(std::bind(&ThreadFunc)); std::cout << "CreateBackThread, thread ID = " << gThread.get_id() << std::endl; - gThread.join(); } void InitDaemon() @@ -130,7 +129,7 @@ void PrintLogo() std::cout << "********************************************" << std::endl; std::cout << "ARK" << std::endl; - std::cout << "COPYRIGHT 漏 2013-2018 ARK-GAME" << std::endl; + std::cout << "COPYRIGHT (c) 2013-2018 ARK-GAME" << std::endl; std::cout << "All RIGHTS RESERVED." << std::endl; std::cout << "HTTPS://ARKGAME.NET" << std::endl; std::cout << "********************************************" << std::endl; @@ -186,7 +185,7 @@ int main(int argc, char* argv[]) AFCPluginManager::GetInstancePtr()->CheckConfig(); //back thread, for some cmd - //CreateBackThread(); + CreateBackThread(); while(!bExitApp) //DEBUG鐗堟湰宕╂簝锛孯ELEASE涓嶅穿 { @@ -218,6 +217,8 @@ int main(int argc, char* argv[]) AFCPluginManager::GetInstancePtr()->ReleaseInstance(); + gThread.join(); + return 0; } diff --git a/Frame/SDK/UtilityPlugin/AFCScheduleModule.cpp b/Frame/SDK/UtilityPlugin/AFCScheduleModule.cpp new file mode 100644 index 00000000..fb159f2b --- /dev/null +++ b/Frame/SDK/UtilityPlugin/AFCScheduleModule.cpp @@ -0,0 +1,69 @@ +/* +* This source file is part of ArkGameFrame +* For the latest info, see https://github.com/ArkGame +* +* Copyright (c) 2013-2018 ArkGame authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ + +#include "AFCScheduleModule.h" + +AFCScheduleModule::AFCScheduleModule(AFIPluginManager* p) +{ + pPluginManager = p; +} + +bool AFCScheduleModule::Init() +{ + return true; +} + +bool AFCScheduleModule::AfterInit() +{ + return true; +} + +bool AFCScheduleModule::BeforeShut() +{ + return true; +} + +bool AFCScheduleModule::Shut() +{ + return true; +} + +void AFCScheduleModule::Update() +{ + +} + +bool AFCScheduleModule::AddSchedule(const std::string& name, const SCHEDULE_FUNCTOR_PTR cb, const int64_t interval_time, const int count) +{ + //TODO: + return true; +} + +bool AFCScheduleModule::RemoveSchedule(const std::string& name) +{ + //TODO: + return true; +} + +bool AFCScheduleModule::ExistSchedule(const std::string& name) +{ + //TODO: + return true; +} \ No newline at end of file diff --git a/Frame/SDK/UtilityPlugin/AFCScheduleModule.h b/Frame/SDK/UtilityPlugin/AFCScheduleModule.h new file mode 100644 index 00000000..cfdc141d --- /dev/null +++ b/Frame/SDK/UtilityPlugin/AFCScheduleModule.h @@ -0,0 +1,46 @@ +/* +* This source file is part of ArkGameFrame +* For the latest info, see https://github.com/ArkGame +* +* Copyright (c) 2013-2018 ArkGame authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ + +#pragma once + +#include "SDK/Interface/AFIScheduleModule.h" + +class AFCScheduleModule : public AFIScheduleModule +{ +public: + AFCScheduleModule(AFIPluginManager* p); + + virtual ~AFCScheduleModule() {} + + virtual bool Init(); + virtual bool AfterInit(); + + virtual bool BeforeShut(); + virtual bool Shut(); + + virtual void Update(); + + virtual bool AddSchedule(const std::string& name, const SCHEDULE_FUNCTOR_PTR cb, const int64_t interval_time, const int count); + virtual bool RemoveSchedule(const std::string& name); + virtual bool ExistSchedule(const std::string& name); + +private: + +}; \ No newline at end of file diff --git a/Frame/SDK/UtilityPlugin/UtilityPlugin.vcxproj b/Frame/SDK/UtilityPlugin/UtilityPlugin.vcxproj index a457cfd6..9b63c557 100644 --- a/Frame/SDK/UtilityPlugin/UtilityPlugin.vcxproj +++ b/Frame/SDK/UtilityPlugin/UtilityPlugin.vcxproj @@ -12,6 +12,7 @@ + @@ -19,6 +20,7 @@ + diff --git a/Frame/SDK/UtilityPlugin/UtilityPlugin.vcxproj.filters b/Frame/SDK/UtilityPlugin/UtilityPlugin.vcxproj.filters index 6b3bc53d..63fc838a 100644 --- a/Frame/SDK/UtilityPlugin/UtilityPlugin.vcxproj.filters +++ b/Frame/SDK/UtilityPlugin/UtilityPlugin.vcxproj.filters @@ -3,35 +3,44 @@ - AFGUIDModule + GUIDModule - AFLogModule + LogModule Plugin + + ScheduleModule + - AFGUIDModule + GUIDModule - AFLogModule + LogModule Plugin + + ScheduleModule + - + + {dd35784e-5218-4392-b2f9-59ad13b4438f} + + + {d7748549-21cf-41b3-87be-bc3b6775e7f0} + + {90913ee5-a19d-4abe-9140-c81509172c54} - + {c58ba43f-0a44-4368-b6ca-2a0f9401c1a3} - - {dd35784e-5218-4392-b2f9-59ad13b4438f} - \ No newline at end of file From 1efc38e47ac0df08ae63c67499cac5ef0fff1771 Mon Sep 17 00:00:00 2001 From: NickYang <362148418@qq.com> Date: Sat, 17 Mar 2018 15:36:46 +0800 Subject: [PATCH 03/24] fix an error type Former-commit-id: 794e5cf41461dcc925007fa9ef306f6001b501d4 Former-commit-id: ec3ada7dbd4c6bbc7265c599a7f17d456d84cb6b --- Frame/SDK/KernelPlugin/AFCElementModule.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Frame/SDK/KernelPlugin/AFCElementModule.cpp b/Frame/SDK/KernelPlugin/AFCElementModule.cpp index b1056439..361d1975 100644 --- a/Frame/SDK/KernelPlugin/AFCElementModule.cpp +++ b/Frame/SDK/KernelPlugin/AFCElementModule.cpp @@ -166,7 +166,7 @@ bool AFCElementModule::Load(rapidxml::xml_node<>* attrNode, ARK_SHARE_PTRvalue.SetInt(ARK_LEXICAL_CAST(pstrConfigValue)); + pTmpNode->value.SetBool(ARK_LEXICAL_CAST(pstrConfigValue)); } break; case DT_INT: From cb79f809837a57e450b77f07534bf532c61fabb0 Mon Sep 17 00:00:00 2001 From: NickYang <362148418@qq.com> Date: Fri, 23 Mar 2018 11:10:20 +0800 Subject: [PATCH 04/24] use std::is_base_of to check Derived Former-commit-id: 6ea3445d1f8f359e048d94d4e8024ef1c2a0d522 Former-commit-id: 39e456e53dcb9acdc3c80a1e5d915fdce7f5aacb --- Frame/SDK/Interface/AFIModule.h | 20 --------- Frame/SDK/Interface/AFIPlugin.h | 5 +-- Frame/SDK/Interface/AFIPluginManager.h | 61 ++++++++++++-------------- 3 files changed, 29 insertions(+), 57 deletions(-) diff --git a/Frame/SDK/Interface/AFIModule.h b/Frame/SDK/Interface/AFIModule.h index 654964e1..a49c6ca8 100644 --- a/Frame/SDK/Interface/AFIModule.h +++ b/Frame/SDK/Interface/AFIModule.h @@ -28,26 +28,6 @@ #include "SDK/Core/Base/AFVector3.hpp" #include "SDK/Core/AFDataTable.h" -template -class TIsDerived -{ -public: - static int AnyFunction(BaseType* base) - { - return 1; - } - - static char AnyFunction(void* t2) - { - return 0; - } - - enum - { - Result = (sizeof(int) == sizeof(AnyFunction((DerivedType*)NULL))), - }; -}; - class AFIPluginManager; class AFIModule diff --git a/Frame/SDK/Interface/AFIPlugin.h b/Frame/SDK/Interface/AFIPlugin.h index 245a36e1..eecb63c7 100644 --- a/Frame/SDK/Interface/AFIPlugin.h +++ b/Frame/SDK/Interface/AFIPlugin.h @@ -26,10 +26,9 @@ #include "SDK/Interface/AFIPluginManager.h" #include "SDK/Core/Base/AFArrayMap.hpp" -//mxModules defines in AFIPlugin #define REGISTER_MODULE(pManager, classBaseName, className) \ - assert((TIsDerived::Result)); \ - assert((TIsDerived::Result)); \ + assert((std::is_base_of::value)); \ + assert((std::is_base_of::value)); \ AFIModule* pRegisterModule##className = new className(pManager); \ pRegisterModule##className->strName = (#className); \ pManager->AddModule(#classBaseName, pRegisterModule##className); \ diff --git a/Frame/SDK/Interface/AFIPluginManager.h b/Frame/SDK/Interface/AFIPluginManager.h index 19b45064..f9e37cd3 100644 --- a/Frame/SDK/Interface/AFIPluginManager.h +++ b/Frame/SDK/Interface/AFIPluginManager.h @@ -1,34 +1,27 @@ -/***************************************************************************** -// * This source file is part of ArkGameFrame * -// * For the latest info, see https://github.com/ArkGame * -// * * -// * Copyright(c) 2013 - 2017 ArkGame authors. * -// * * -// * Licensed under the Apache License, Version 2.0 (the "License"); * -// * you may not use this file except in compliance with the License. * -// * You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software * -// * distributed under the License is distributed on an "AS IS" BASIS, * -// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* -// * See the License for the specific language governing permissions and * -// * limitations under the License. * -// * * -// * * -// * @file AFIPluginManager.h * -// * @author Ark Game Tech * -// * @date 2015-12-15 * -// * @brief AFIPluginManager * -*****************************************************************************/ +/* +* This source file is part of ArkGameFrame +* For the latest info, see https://github.com/ArkGame +* +* Copyright (c) 2013-2018 ArkGame authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ + #pragma once #include "AFIModule.h" -#define FIND_MODULE(classBaseName, className) \ - assert((TIsDerived::Result)); - class AFIPlugin; class AFIPluginManager : public AFIModule @@ -45,18 +38,19 @@ class AFIPluginManager : public AFIModule AFIModule* pLogicModule = FindModule(typeid(T).name()); if (pLogicModule) { - if (!TIsDerived::Result) + if (!std::is_base_of::value) { - return NULL; + return nullptr; } T* pT = dynamic_cast(pLogicModule); - assert(NULL != pT); + ARK_ASSERT_RET_VAL(pT != nullptr, nullptr); return pT; } - assert(NULL); - return NULL; + + ARK_ASSERT_NO_EFFECT(0); + return nullptr; } virtual void Registered(AFIPlugin* plugin) = 0; @@ -76,5 +70,4 @@ class AFIPluginManager : public AFIModule virtual int64_t GetNowTime() const = 0; virtual const std::string& GetConfigPath() const = 0; virtual void SetConfigName(const std::string& strFileName) = 0; -}; - +}; \ No newline at end of file From b5a90da4ace27db2b99b9ce73ddf281d06c8ec2c Mon Sep 17 00:00:00 2001 From: NickYang <362148418@qq.com> Date: Fri, 23 Mar 2018 18:09:20 +0800 Subject: [PATCH 05/24] add dep build script for vs2017 Former-commit-id: 7b3913e447bdae676e22245ab715e44e9fcdc53d Former-commit-id: d6440c95787f686f0dcbfc8f70352965f8715c79 --- Dep/build_dep_vs2017.bat | 74 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 Dep/build_dep_vs2017.bat diff --git a/Dep/build_dep_vs2017.bat b/Dep/build_dep_vs2017.bat new file mode 100644 index 00000000..4cb0797e --- /dev/null +++ b/Dep/build_dep_vs2017.bat @@ -0,0 +1,74 @@ +@echo off + +echo Building dependencies... + +if exist lib (rd lib /q /s) +md lib +cd lib +md Debug +md Release +cd ../ + +REM If your path is different with blow, please change to your install path +set %VS150COMNTOOLS%=C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\ +echo "%VS150COMNTOOLS%..\IDE\Devenv" + +REM ###################################################################################################### +echo Building protobuf... + +if exist protobuf (rd protobuf /q /s) +git clone -b 3.5.x https://github.com/google/protobuf.git + +cd protobuf/cmake +md build +cd build +cmake -G "Visual Studio 15 Win64" -Dprotobuf_BUILD_SHARED_LIBS=ON -Dprotobuf_BUILD_TESTS=OFF .. +"%VS150COMNTOOLS%..\IDE\Devenv" protobuf.sln /build "Debug|x64" +"%VS150COMNTOOLS%..\IDE\Devenv" protobuf.sln /build "Release|x64" +copy Debug\*.dll ..\..\..\lib\Debug /Y +copy Debug\*.lib ..\..\..\lib\Debug /Y +copy Release\*.dll ..\..\..\lib\Release /Y +copy Release\*.lib ..\..\..\lib\Release /Y + +copy Release\libprotobuf.dll ..\..\..\..\Frame\SDK\Proto\proto-gen /Y +copy Release\libprotoc.dll ..\..\..\..\Frame\SDK\Proto\proto-gen /Y +copy Release\protoc.exe ..\..\..\..\Frame\SDK\Proto\proto-gen /Y + +cd ..\..\..\ +REM ###################################################################################################### +echo Building libevent... + +if exist libevent (rd libevent /q /s) +git clone -b master https://github.com/libevent/libevent.git + +cd libevent +md build +cd build +cmake -G "Visual Studio 15 Win64" -DEVENT__DISABLE_OPENSSL=ON .. +"%VS150COMNTOOLS%..\IDE\Devenv" libevent.sln /build "Debug|x64" /project event_core_static.vcxproj +"%VS150COMNTOOLS%..\IDE\Devenv" libevent.sln /build "Release|x64" /project event_core_static.vcxproj +"%VS150COMNTOOLS%..\IDE\Devenv" libevent.sln /build "Debug|x64" /project event_static.vcxproj +"%VS150COMNTOOLS%..\IDE\Devenv" libevent.sln /build "Release|x64" /project event_static.vcxproj +"%VS150COMNTOOLS%..\IDE\Devenv" libevent.sln /build "Debug|x64" /project event_extra_static.vcxproj +"%VS150COMNTOOLS%..\IDE\Devenv" libevent.sln /build "Release|x64" /project event_extra_static.vcxproj +copy lib\Debug\*.lib ..\..\lib\Debug /Y +copy lib\Release\*.lib ..\..\lib\Release /Y +cd ..\..\ +REM ###################################################################################################### +echo Building evpp... +if exist evpp (rd evpp /q /s) +git clone -b master https://github.com/ArkGame/evpp.git + +cd evpp +md build +cd build +cmake -G "Visual Studio 15 Win64" -DLIBEVENT_DIR=..\libevent -DLIBEVENT_LIB_DIR=..\lib\Release .. +"%VS150COMNTOOLS%..\IDE\Devenv" evpp.sln /build "Debug|x64" /project evpp/evpp_static.vcxproj +"%VS150COMNTOOLS%..\IDE\Devenv" evpp.sln /build "Release|x64" /project evpp/evpp_static.vcxproj +copy lib\Debug\*.lib ..\..\lib\Debug /Y +copy lib\Release\*.lib ..\..\lib\Release /Y + +cd ..\..\ +REM #################################################################################################### +REM back to root dir +cd ..\ \ No newline at end of file From 16666dac85a9ab3c60e314a6888492330a4da0b7 Mon Sep 17 00:00:00 2001 From: NickYang <362148418@qq.com> Date: Fri, 23 Mar 2018 18:12:02 +0800 Subject: [PATCH 06/24] Update build_dep_vs2017.bat Former-commit-id: be5b5c8754982c2ecfbd84ec31e3381d81fe731b Former-commit-id: 04e80786bf98d2aa63cae6f61d864fe5abc5595d --- Dep/build_dep_vs2017.bat | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dep/build_dep_vs2017.bat b/Dep/build_dep_vs2017.bat index 4cb0797e..c4a08519 100644 --- a/Dep/build_dep_vs2017.bat +++ b/Dep/build_dep_vs2017.bat @@ -9,7 +9,7 @@ md Debug md Release cd ../ -REM If your path is different with blow, please change to your install path +REM If your path is different with below, please change to your install path set %VS150COMNTOOLS%=C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\ echo "%VS150COMNTOOLS%..\IDE\Devenv" @@ -71,4 +71,4 @@ copy lib\Release\*.lib ..\..\lib\Release /Y cd ..\..\ REM #################################################################################################### REM back to root dir -cd ..\ \ No newline at end of file +cd ..\ From 4b3dcbb6b0d68a9e5ca6e8b6ff7e8e7c6ee0920a Mon Sep 17 00:00:00 2001 From: NickYang <362148418@qq.com> Date: Sat, 24 Mar 2018 16:06:16 +0800 Subject: [PATCH 07/24] Add TimerModule Former-commit-id: f1a64961cf7f15d9a91c7c9954b005898179faaf Former-commit-id: 3832f53b64769a058c91f80fb6d7aaaadae6aad8 --- Frame/SDK/Interface/AFIScheduleModule.h | 2 - Frame/SDK/Interface/AFITimerModule.h | 48 +++++++++++++ Frame/SDK/UtilityPlugin/AFCTimerModule.cpp | 68 +++++++++++++++++++ Frame/SDK/UtilityPlugin/AFCTimerModule.h | 53 +++++++++++++++ Frame/SDK/UtilityPlugin/UtilityPlugin.vcxproj | 2 + .../UtilityPlugin.vcxproj.filters | 9 +++ Frame/SDK/UtilityPlugin/dllmain.cpp | 4 +- 7 files changed, 182 insertions(+), 4 deletions(-) create mode 100644 Frame/SDK/Interface/AFITimerModule.h create mode 100644 Frame/SDK/UtilityPlugin/AFCTimerModule.cpp create mode 100644 Frame/SDK/UtilityPlugin/AFCTimerModule.h diff --git a/Frame/SDK/Interface/AFIScheduleModule.h b/Frame/SDK/Interface/AFIScheduleModule.h index 9b13a2aa..8715ea7d 100644 --- a/Frame/SDK/Interface/AFIScheduleModule.h +++ b/Frame/SDK/Interface/AFIScheduleModule.h @@ -28,6 +28,4 @@ class AFIScheduleModule : public AFIModule virtual bool AddSchedule(const std::string& name, const SCHEDULE_FUNCTOR_PTR cb, const int64_t interval_time, const int count) = 0; virtual bool RemoveSchedule(const std::string& name) = 0; virtual bool ExistSchedule(const std::string& name) = 0; - - }; \ No newline at end of file diff --git a/Frame/SDK/Interface/AFITimerModule.h b/Frame/SDK/Interface/AFITimerModule.h new file mode 100644 index 00000000..c13d6951 --- /dev/null +++ b/Frame/SDK/Interface/AFITimerModule.h @@ -0,0 +1,48 @@ +/* +* This source file is part of ArkGameFrame +* For the latest info, see https://github.com/ArkGame +* +* Copyright (c) 2013-2018 ArkGame authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ + +#pragma once + +#include "SDK/Interface/AFIModule.h" + +class AFITimerModule : public AFIModule +{ +public: + template + bool AddSingleTimer(const std::string& name, const AFGUID& entity_id, const uint32_t interval_time, const uint32_t count, BaseType* pBase, void (BaseType::*handler)(const std::string&, const AFGUID&)) + { + TIMER_FUNCTOR functor = std::bind(handler, pBase, std::placeholders::_1, std::placeholders::_2); + return AddSingleTimer(name, entity_id, interval_time, count, std::make_shared(functor)); + } + + template + bool AddForeverTimer(const std::string& name, const AFGUID& entity_id, const uint32_t interval_time, void (BaseType::*handler)(const std::string&, const AFGUID&)) + { + TIMER_FUNCTOR functor = std::bind(handler, pBase, std::placeholders::_1, std::placeholders::_2); + return AddForeverTimer(name, entity_id, interval_time, std::make_shared(functor)); + } + + virtual bool RemoveTimer(const std::string& name) = 0; + virtual bool RemoveTimer(const std::string& name, const AFGUID& entity_id) = 0; + +protected: + virtual bool AddSingleTimer(const std::string& name, const AFGUID& entity_id, const uint32_t interval_time, const uint32_t count, TIMER_FUNCTOR_PTR cb) = 0; + virtual bool AddForeverTimer(const std::string& name, const AFGUID& entity_id, const int64_t interval_time, TIMER_FUNCTOR_PTR cb) = 0; +}; \ No newline at end of file diff --git a/Frame/SDK/UtilityPlugin/AFCTimerModule.cpp b/Frame/SDK/UtilityPlugin/AFCTimerModule.cpp new file mode 100644 index 00000000..bb656513 --- /dev/null +++ b/Frame/SDK/UtilityPlugin/AFCTimerModule.cpp @@ -0,0 +1,68 @@ +/* +* This source file is part of ArkGameFrame +* For the latest info, see https://github.com/ArkGame +* +* Copyright (c) 2013-2018 ArkGame authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ + +#include "AFCTimerModule.h" + +bool AFCTimerModule::Init() +{ + mxTimerManager = std::make_shared(); + return true; +} + +bool AFCTimerModule::AfterInit() +{ + return true; +} + +bool AFCTimerModule::BeforeShut() +{ + mxTimerManager->Shut(); + return true; +} + +bool AFCTimerModule::Shut() +{ + return true; +} + +void AFCTimerModule::Update() +{ + mxTimerManager->Update(); +} + +bool AFCTimerModule::RemoveTimer(const std::string& name) +{ + return mxTimerManager->RemoveTimer(name); +} + +bool AFCTimerModule::RemoveTimer(const std::string& name, const AFGUID& entity_id) +{ + return mxTimerManager->RemoveTimer(name, entity_id); +} + +bool AFCTimerModule::AddSingleTimer(const std::string& name, const AFGUID& entity_id, const uint32_t interval_time, const uint32_t count, TIMER_FUNCTOR_PTR cb) +{ + return mxTimerManager->AddSingleTimer(name, entity_id, interval_time, count, cb); +} + +bool AFCTimerModule::AddForeverTimer(const std::string& name, const AFGUID& entity_id, const int64_t interval_time, TIMER_FUNCTOR_PTR cb) +{ + return mxTimerManager->AddForverTimer(name, entity_id, interval_time, cb); +} \ No newline at end of file diff --git a/Frame/SDK/UtilityPlugin/AFCTimerModule.h b/Frame/SDK/UtilityPlugin/AFCTimerModule.h new file mode 100644 index 00000000..b8bd8855 --- /dev/null +++ b/Frame/SDK/UtilityPlugin/AFCTimerModule.h @@ -0,0 +1,53 @@ +/* +* This source file is part of ArkGameFrame +* For the latest info, see https://github.com/ArkGame +* +* Copyright (c) 2013-2018 ArkGame authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ + +#pragma once + +#include "SDK/Interface/AFITimerModule.h" +#include "SDK/Core/Base/AFTimer.hpp" + +class AFCTimerModule : public AFITimerModule +{ +public: + AFCTimerModule(AFIPluginManager* p) + { + pPluginManager = p; + } + + virtual ~AFCTimerModule() {} + + virtual bool Init(); + virtual bool AfterInit(); + + virtual bool BeforeShut(); + virtual bool Shut(); + + virtual void Update(); + + virtual bool RemoveTimer(const std::string& name); + virtual bool RemoveTimer(const std::string& name, const AFGUID& entity_id); + +protected: + virtual bool AddSingleTimer(const std::string& name, const AFGUID& entity_id, const uint32_t interval_time, const uint32_t count, TIMER_FUNCTOR_PTR cb); + virtual bool AddForeverTimer(const std::string& name, const AFGUID& entity_id, const int64_t interval_time, TIMER_FUNCTOR_PTR cb); + +private: + std::shared_ptr mxTimerManager; +}; \ No newline at end of file diff --git a/Frame/SDK/UtilityPlugin/UtilityPlugin.vcxproj b/Frame/SDK/UtilityPlugin/UtilityPlugin.vcxproj index 9b63c557..32c6fcda 100644 --- a/Frame/SDK/UtilityPlugin/UtilityPlugin.vcxproj +++ b/Frame/SDK/UtilityPlugin/UtilityPlugin.vcxproj @@ -13,6 +13,7 @@ + @@ -21,6 +22,7 @@ + diff --git a/Frame/SDK/UtilityPlugin/UtilityPlugin.vcxproj.filters b/Frame/SDK/UtilityPlugin/UtilityPlugin.vcxproj.filters index 63fc838a..9242e10f 100644 --- a/Frame/SDK/UtilityPlugin/UtilityPlugin.vcxproj.filters +++ b/Frame/SDK/UtilityPlugin/UtilityPlugin.vcxproj.filters @@ -14,6 +14,9 @@ ScheduleModule + + TimerModule + @@ -28,6 +31,9 @@ ScheduleModule + + TimerModule + @@ -42,5 +48,8 @@ {c58ba43f-0a44-4368-b6ca-2a0f9401c1a3} + + {d8f35e51-2dd5-4b3b-911d-bad8a174815c} + \ No newline at end of file diff --git a/Frame/SDK/UtilityPlugin/dllmain.cpp b/Frame/SDK/UtilityPlugin/dllmain.cpp index e66820ea..d020530d 100644 --- a/Frame/SDK/UtilityPlugin/dllmain.cpp +++ b/Frame/SDK/UtilityPlugin/dllmain.cpp @@ -24,9 +24,9 @@ #pragma comment( lib, "Dbghelp.lib" ) #if ARK_RUN_MODE == ARK_RUN_MODE_DEBUG -//#pragma comment(lib, "AFCore_d.lib") +#pragma comment(lib, "AFCore_d.lib") #else -//#pragma comment(lib, "AFCore.lib") +#pragma comment(lib, "AFCore.lib") #endif #endif From 6b43f551aa45ddfc825e3b7557a11d5b5d7bff34 Mon Sep 17 00:00:00 2001 From: NickYang <362148418@qq.com> Date: Sat, 24 Mar 2018 16:18:37 +0800 Subject: [PATCH 08/24] fix errors Former-commit-id: b3fb17dace9c4db0854e6f8527ae507795b53ab1 Former-commit-id: 72cc2274f8c505cf25315268cbd614b467051758 --- Frame/SDK/Core/Base/AFTimer.hpp | 2 +- Frame/SDK/Interface/AFITimerModule.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Frame/SDK/Core/Base/AFTimer.hpp b/Frame/SDK/Core/Base/AFTimer.hpp index 52e1be20..7c263793 100644 --- a/Frame/SDK/Core/Base/AFTimer.hpp +++ b/Frame/SDK/Core/Base/AFTimer.hpp @@ -223,7 +223,7 @@ class AFTimerManager : public AFSingleton bool AddTimerData(const std::string& name, const AFGUID& entity_id, AFTimerData* timer_data) { - auto& iter = mxTimers.find(name); + auto iter = mxTimers.find(name); if (iter == mxTimers.end()) { std::map tmp; diff --git a/Frame/SDK/Interface/AFITimerModule.h b/Frame/SDK/Interface/AFITimerModule.h index c13d6951..5c7472e0 100644 --- a/Frame/SDK/Interface/AFITimerModule.h +++ b/Frame/SDK/Interface/AFITimerModule.h @@ -33,7 +33,7 @@ class AFITimerModule : public AFIModule } template - bool AddForeverTimer(const std::string& name, const AFGUID& entity_id, const uint32_t interval_time, void (BaseType::*handler)(const std::string&, const AFGUID&)) + bool AddForeverTimer(const std::string& name, const AFGUID& entity_id, const uint32_t interval_time, BaseType* pBase, void (BaseType::*handler)(const std::string&, const AFGUID&)) { TIMER_FUNCTOR functor = std::bind(handler, pBase, std::placeholders::_1, std::placeholders::_2); return AddForeverTimer(name, entity_id, interval_time, std::make_shared(functor)); From dfb5b959e5a08d0f08c6b6adf61cb35ce04f5b35 Mon Sep 17 00:00:00 2001 From: NickYang <362148418@qq.com> Date: Mon, 26 Mar 2018 14:14:22 +0800 Subject: [PATCH 09/24] fix atomic error in vs2017 Former-commit-id: c1654a1320882313c36f2482b1e138b96bf8d626 Former-commit-id: 8bda5992023dc6bc1cbc52314a82e828469de6c9 --- Frame/SDK/Core/Base/AFMemAlloc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Frame/SDK/Core/Base/AFMemAlloc.cpp b/Frame/SDK/Core/Base/AFMemAlloc.cpp index eb8ce7cb..c151b228 100644 --- a/Frame/SDK/Core/Base/AFMemAlloc.cpp +++ b/Frame/SDK/Core/Base/AFMemAlloc.cpp @@ -261,7 +261,7 @@ void AFMemAlloc::Dump() printf("[Size:%d]:Used:%d / Total:%d (%d bytes) \r\n", g_poolSize[i], g_poolUsed[i], g_poolTotal[i], g_poolSize[i] * g_poolUsed[i]); } - printf("Total: %d bytes used\n", g_totalAlloc); + printf("Total: %d bytes used\n", g_totalAlloc.load()); printf("Memory dump end-----------------------\n"); } From c63dabf16833670cfb00ec55f54517e681b8e3c7 Mon Sep 17 00:00:00 2001 From: Fredida <35677290+Fredida@users.noreply.github.com> Date: Wed, 28 Mar 2018 17:21:50 +0800 Subject: [PATCH 10/24] Update build instructions and notes in README.md Change Linux build instructions to avoid a potential issue. Former-commit-id: b9ebc6b5960d13a26da97033b8281766c69db35a Former-commit-id: 16f49dcc793a9797b11273867797d4ad45000bea --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6c37abc9..4b49c715 100644 --- a/README.md +++ b/README.md @@ -138,9 +138,11 @@ cd Dep cd ../ mkdir build && cd build cmake -G "Unix Makefiles" .. -make -j +make ``` -> Note. If you need build debug, please add `-DCMAKE_BUILD_TYPE="Debug"` in cmake command. +> Note +> - If you need build debug, please add `-DCMAKE_BUILD_TYPE="Debug"` in cmake command. +> - To accelerate building, you can use `make -j` to run multiple complication jobs simultaneously. However, that may exhaust the memory. 3. Run `ARK\Bin\Server\DataConfig\Tool\gen-config.sh` to generate configuration files 4. Run the binary file by `Bin/Server/Debug/rund.sh` From be03cef4851cc8f1edc3966892abddba0a3be049 Mon Sep 17 00:00:00 2001 From: NickYang <362148418@qq.com> Date: Thu, 29 Mar 2018 18:53:05 +0800 Subject: [PATCH 11/24] fix Timer fix Memory Former-commit-id: 9689078bb964f3f373a68a56eb18bffa848f23c3 Former-commit-id: 43fcf59c38c462e44d10df3e75760264b4509f01 --- Frame/Examples/Tutorial1/HelloWorld1.cpp | 45 +- Frame/Examples/Tutorial1/HelloWorld1.h | 4 + Frame/Examples/Tutorial1/Tutorial1Plugin.cpp | 21 +- Frame/Examples/Tutorial2/Tutorial2Plugin.cpp | 11 +- Frame/Examples/Tutorial3/Tutorial3Plugin.cpp | 14 +- Frame/SDK/Core/AFCDataTableManager.cpp | 97 +-- Frame/SDK/Core/Base/AFArrayPod.hpp | 43 +- Frame/SDK/Core/Base/AFCoreDef.hpp | 14 +- Frame/SDK/Core/Base/AFMacros.hpp | 21 +- Frame/SDK/Core/Base/AFMalloc.cpp | 18 + Frame/SDK/Core/Base/AFMalloc.h | 686 ++++++++++++++++++ Frame/SDK/Core/Base/AFMisc.hpp | 29 +- Frame/SDK/Core/Base/AFNoncopyable.hpp | 2 +- Frame/SDK/Core/Base/AFStringPod.hpp | 6 +- Frame/SDK/Core/Base/AFTime.hpp | 3 +- Frame/SDK/Core/Base/AFTimer.hpp | 105 ++- Frame/SDK/Core/Core.vcxproj | 5 +- Frame/SDK/Core/Core.vcxproj.filters | 9 +- Frame/SDK/Interface/AFIPlugin.h | 12 +- Frame/SDK/Interface/AFIPluginManager.h | 17 +- Frame/SDK/KernelPlugin/AFKernelPlugin.cpp | 11 +- Frame/SDK/PluginLoader/AFCPluginManager.cpp | 30 +- Frame/SDK/PluginLoader/AFCPluginManager.h | 2 +- Frame/SDK/PluginLoader/AFPluginLoader.cpp | 10 +- Frame/SDK/UtilityPlugin/AFCTimerModule.cpp | 5 +- Frame/SDK/UtilityPlugin/AFUtilityPlugin.cpp | 22 +- .../GameLogicPlugin/AFGameLogicPlugin.cpp | 15 +- .../AFGameNetClientPlugin.cpp | 11 +- .../AFGameNetServerPlugin.cpp | 13 +- .../LoginLogicPlugin/AFLoginLogicPlugin.cpp | 15 +- .../AFLoginNetClientPlugin.cpp | 11 +- .../AFLoginNetServerPlugin.cpp | 12 +- .../MasterLogicPlugin/AFMasterLogicPlugin.cpp | 15 +- .../AFMasterNetServerPlugin.cpp | 13 +- .../ProxyLogicPlugin/AFProxyLogicPlugin.cpp | 14 +- .../AFProxyNetClientPlugin.cpp | 11 +- .../AFProxyNetServerPlugin.cpp | 13 +- .../WorldLogicPlugin/AFWorldLogicPlugin.cpp | 15 +- .../AFWorldNetClientPlugin.cpp | 11 +- .../AFWorldNetServerPlugin.cpp | 12 +- 40 files changed, 1013 insertions(+), 410 deletions(-) create mode 100644 Frame/SDK/Core/Base/AFMalloc.cpp create mode 100644 Frame/SDK/Core/Base/AFMalloc.h diff --git a/Frame/Examples/Tutorial1/HelloWorld1.cpp b/Frame/Examples/Tutorial1/HelloWorld1.cpp index 575f312e..7b484888 100644 --- a/Frame/Examples/Tutorial1/HelloWorld1.cpp +++ b/Frame/Examples/Tutorial1/HelloWorld1.cpp @@ -19,54 +19,32 @@ */ #include "HelloWorld1.h" -#include "SDK/Core/Base/AFMemAlloc.h" -//#include "SDK/Core/Base/AFTimer.h" -// -//AFTimerManager::TimerManagerPtr gTimerManager; -//AFTimer::TimerWeakPtr timerPtr; +#include "SDK/Core/Base/AFTimer.hpp" bool HelloWorld1::Init() { - std::cout << typeid(HelloWorld1).name() << std::endl; + std::cout << typeid(HelloWorld1).name() << std::endl; std::cout << "Hello, world1, Init" << std::endl; - AFMemAlloc::InitPool(); - AFMemAlloc::Start(); - //gTimerManager = std::shared_ptr(); - return true; } bool HelloWorld1::AfterInit() { + m_pTimerModule = pPluginManager->FindModule(); + + ARK_ASSERT_RET_VAL(m_pTimerModule != nullptr, false); + std::cout << "Hello, world1, AfterInit" << std::endl; AFCData data1(DT_STRING, "test1"); AFCData data2(DT_STRING, "test2"); data1 = data2; const char* str1 = data1.GetString(); - ////////////////////////////////////////////////////////////////////////// - ////test memory alloc - //void* ptr1 = ARK_ALLOC(100); - //memset(ptr1, 0, 100); - - //void* ptr2 = ARK_ALLOC(10); - - //AFMemAlloc::CheckLeak(); - //ARK_FREE(ptr2); + std::cout << pPluginManager->GetNowTime() << std::endl; - //AFMemAlloc::CheckLeak(); - - //ARK_FREE(ptr1); - //AFMemAlloc::CheckLeak(); - ////////////////////////////////////////////////////////////////////////// - - //std::chrono::nanoseconds interval_time = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()) + std::chrono::nanoseconds{ 100000000 }; - //timerPtr = gTimerManager->AddTimer(interval_time, [=]() - //{ - // std::cout << "Run timer" << std::endl; - //}); + m_pTimerModule->AddSingleTimer("test", AFGUID(0, 1), 10 * 1000/*ms*/, 2, this, &HelloWorld1::TestTimer); return true; } @@ -79,7 +57,6 @@ void HelloWorld1::Update() bool HelloWorld1::BeforeShut() { std::cout << "Hello, world1, BeforeShut-------------" << std::endl; - //timerPtr->Cancel(); return true; } @@ -87,4 +64,10 @@ bool HelloWorld1::Shut() { std::cout << "Hello, world1, Shut" << std::endl; return true; +} + +void HelloWorld1::TestTimer(const std::string& name, const AFGUID& entity_id) +{ + std::cout << pPluginManager->GetNowTime() << std::endl; + std::cout << "Test Timer: " << name << " id = " << entity_id.ToString() << std::endl; } \ No newline at end of file diff --git a/Frame/Examples/Tutorial1/HelloWorld1.h b/Frame/Examples/Tutorial1/HelloWorld1.h index 5730a212..f5f7f29c 100644 --- a/Frame/Examples/Tutorial1/HelloWorld1.h +++ b/Frame/Examples/Tutorial1/HelloWorld1.h @@ -22,6 +22,7 @@ #include "SDK/Interface/AFIPlugin.h" #include "SDK/Interface/AFIPluginManager.h" +#include "SDK/Interface/AFITimerModule.h" class HelloWorld1 : public AFIModule @@ -41,5 +42,8 @@ class HelloWorld1 virtual bool Shut(); protected: + void TestTimer(const std::string& name, const AFGUID& entity_id); +protected: + AFITimerModule* m_pTimerModule; }; \ No newline at end of file diff --git a/Frame/Examples/Tutorial1/Tutorial1Plugin.cpp b/Frame/Examples/Tutorial1/Tutorial1Plugin.cpp index cfe016b1..fe09b477 100644 --- a/Frame/Examples/Tutorial1/Tutorial1Plugin.cpp +++ b/Frame/Examples/Tutorial1/Tutorial1Plugin.cpp @@ -23,15 +23,18 @@ #ifdef ARK_DYNAMIC_PLUGIN -ARK_EXPORT void DllStartPlugin(AFIPluginManager* pm) -{ - CREATE_PLUGIN(pm, Tutorial1Plugin) -} - -ARK_EXPORT void DllStopPlugin(AFIPluginManager* pm) -{ - DESTROY_PLUGIN(pm, Tutorial1Plugin) -} +ARK_DLL_PLUGIN_ENTRY(Tutorial1Plugin) +ARK_DLL_PLUGIN_EXIT(Tutorial1Plugin) + +//ARK_EXPORT void DllStartPlugin(AFIPluginManager* pm) +//{ +// CREATE_PLUGIN(pm, Tutorial1Plugin) +//} +// +//ARK_EXPORT void DllStopPlugin(AFIPluginManager* pm) +//{ +// DESTROY_PLUGIN(pm, Tutorial1Plugin) +//} #endif ////////////////////////////////////////////////////////////////////////// diff --git a/Frame/Examples/Tutorial2/Tutorial2Plugin.cpp b/Frame/Examples/Tutorial2/Tutorial2Plugin.cpp index 14e286e7..0f8ae4e8 100644 --- a/Frame/Examples/Tutorial2/Tutorial2Plugin.cpp +++ b/Frame/Examples/Tutorial2/Tutorial2Plugin.cpp @@ -23,15 +23,8 @@ #ifdef ARK_DYNAMIC_PLUGIN -ARK_EXPORT void DllStartPlugin(AFIPluginManager* pm) -{ - CREATE_PLUGIN(pm, Tutorial2Plugin) -} - -ARK_EXPORT void DllStopPlugin(AFIPluginManager* pm) -{ - DESTROY_PLUGIN(pm, Tutorial2Plugin) -} +ARK_DLL_PLUGIN_ENTRY(Tutorial2Plugin) +ARK_DLL_PLUGIN_EXIT(Tutorial2Plugin) #endif ////////////////////////////////////////////////////////////////////////// diff --git a/Frame/Examples/Tutorial3/Tutorial3Plugin.cpp b/Frame/Examples/Tutorial3/Tutorial3Plugin.cpp index 2300294f..c7605f53 100644 --- a/Frame/Examples/Tutorial3/Tutorial3Plugin.cpp +++ b/Frame/Examples/Tutorial3/Tutorial3Plugin.cpp @@ -23,18 +23,8 @@ #ifdef ARK_DYNAMIC_PLUGIN -ARK_EXPORT void DllStartPlugin(AFIPluginManager* pm) -{ -#if ARK_PLATFORM == PLATFORM_WIN - SetConsoleTitle("Tutorial3"); -#endif - CREATE_PLUGIN(pm, Tutorial3Plugin) -} - -ARK_EXPORT void DllStopPlugin(AFIPluginManager* pm) -{ - DESTROY_PLUGIN(pm, Tutorial3Plugin) -} +ARK_DLL_PLUGIN_ENTRY(Tutorial3Plugin) +ARK_DLL_PLUGIN_EXIT(Tutorial3Plugin) #endif ////////////////////////////////////////////////////////////////////////// diff --git a/Frame/SDK/Core/AFCDataTableManager.cpp b/Frame/SDK/Core/AFCDataTableManager.cpp index 6983dc83..f7511a2c 100644 --- a/Frame/SDK/Core/AFCDataTableManager.cpp +++ b/Frame/SDK/Core/AFCDataTableManager.cpp @@ -40,7 +40,7 @@ const AFGUID& AFCDataTableManager::Self() void AFCDataTableManager::ReleaseAll() { - for (size_t i = 0; i < mxTables.GetCount(); ++i) + for(size_t i = 0; i < mxTables.GetCount(); ++i) { delete mxTables[i]; } @@ -62,7 +62,7 @@ bool AFCDataTableManager::Exist(const char* name, size_t& index) const bool AFCDataTableManager::GetTableData(const char* name, const int row, const int col, AFIData& value) { AFDataTable* pTable = GetTable(name); - if (pTable == nullptr) + if(pTable == nullptr) { return NULL; } @@ -72,7 +72,7 @@ bool AFCDataTableManager::GetTableData(const char* name, const int row, const in void AFCDataTableManager::OnEventHandler(const AFGUID& entity_id, const DATA_TABLE_EVENT_DATA& xEventData, const AFCData& oldData, const AFCData& newData) { - for (auto& iter : mxTableCallbacks) + for(auto& iter : mxTableCallbacks) { //TODO:check name from xEventData //xEventData.name @@ -144,20 +144,20 @@ bool AFCDataTableManager::SetTableBool(const char* name, const int row, const in } //callback - do + do { AFCData oldData; - if (!GetTableData(name, row, col, oldData)) + if(!GetTableData(name, row, col, oldData)) { ARK_ASSERT_RET_VAL(0, false); } - if (oldData.GetBool() == value) + if(oldData.GetBool() == value) { return false; } - if (!mxTableCallbacks.empty()) + if(!mxTableCallbacks.empty()) { AFCData newData; newData.SetBool(value); @@ -170,7 +170,8 @@ bool AFCDataTableManager::SetTableBool(const char* name, const int row, const in OnEventHandler(self, xTableEventData, oldData, newData); } - } while (0); + } + while(0); return pTable->SetBool(row, col, value); } @@ -178,7 +179,7 @@ bool AFCDataTableManager::SetTableBool(const char* name, const int row, const in bool AFCDataTableManager::SetTableInt(const char* name, const int row, const int col, const int32_t value) { AFDataTable* pTable = GetTable(name); - if (pTable == nullptr) + if(pTable == nullptr) { return false; } @@ -187,17 +188,17 @@ bool AFCDataTableManager::SetTableInt(const char* name, const int row, const int do { AFCData oldData; - if (!GetTableData(name, row, col, oldData)) + if(!GetTableData(name, row, col, oldData)) { ARK_ASSERT_RET_VAL(0, false); } - if (oldData.GetInt() == value) + if(oldData.GetInt() == value) { return false; } - if (!mxTableCallbacks.empty()) + if(!mxTableCallbacks.empty()) { AFCData newData; newData.SetInt(value); @@ -210,7 +211,8 @@ bool AFCDataTableManager::SetTableInt(const char* name, const int row, const int OnEventHandler(self, xTableEventData, oldData, newData); } - } while (0); + } + while(0); return pTable->SetInt(row, col, value); } @@ -218,7 +220,7 @@ bool AFCDataTableManager::SetTableInt(const char* name, const int row, const int bool AFCDataTableManager::SetTableInt64(const char* name, const int row, const int col, const int64_t value) { AFDataTable* pTable = GetTable(name); - if (pTable == nullptr) + if(pTable == nullptr) { return false; } @@ -227,17 +229,17 @@ bool AFCDataTableManager::SetTableInt64(const char* name, const int row, const i do { AFCData oldData; - if (!GetTableData(name, row, col, oldData)) + if(!GetTableData(name, row, col, oldData)) { ARK_ASSERT_RET_VAL(0, false); } - if (oldData.GetInt64() == value) + if(oldData.GetInt64() == value) { return false; } - if (!mxTableCallbacks.empty()) + if(!mxTableCallbacks.empty()) { AFCData newData; newData.SetInt64(value); @@ -250,7 +252,8 @@ bool AFCDataTableManager::SetTableInt64(const char* name, const int row, const i OnEventHandler(self, xTableEventData, oldData, newData); } - } while (0); + } + while(0); return pTable->SetInt64(row, col, value); } @@ -258,7 +261,7 @@ bool AFCDataTableManager::SetTableInt64(const char* name, const int row, const i bool AFCDataTableManager::SetTableFloat(const char* name, const int row, const int col, const float value) { AFDataTable* pTable = GetTable(name); - if (pTable == nullptr) + if(pTable == nullptr) { return false; } @@ -267,17 +270,17 @@ bool AFCDataTableManager::SetTableFloat(const char* name, const int row, const i do { AFCData oldData; - if (!GetTableData(name, row, col, oldData)) + if(!GetTableData(name, row, col, oldData)) { ARK_ASSERT_RET_VAL(0, false); } - if (AFMisc::IsFloatEqual(oldData.GetFloat(), value)) + if(AFMisc::IsFloatEqual(oldData.GetFloat(), value)) { return false; } - if (!mxTableCallbacks.empty()) + if(!mxTableCallbacks.empty()) { AFCData newData; newData.SetFloat(value); @@ -290,7 +293,8 @@ bool AFCDataTableManager::SetTableFloat(const char* name, const int row, const i OnEventHandler(self, xTableEventData, oldData, newData); } - } while (0); + } + while(0); return pTable->SetFloat(row, col, value); } @@ -298,7 +302,7 @@ bool AFCDataTableManager::SetTableFloat(const char* name, const int row, const i bool AFCDataTableManager::SetTableDouble(const char* name, const int row, const int col, const double value) { AFDataTable* pTable = GetTable(name); - if (pTable == nullptr) + if(pTable == nullptr) { return false; } @@ -307,17 +311,17 @@ bool AFCDataTableManager::SetTableDouble(const char* name, const int row, const do { AFCData oldData; - if (!GetTableData(name, row, col, oldData)) + if(!GetTableData(name, row, col, oldData)) { ARK_ASSERT_RET_VAL(0, false); } - if (AFMisc::IsDoubleEqual(oldData.GetDouble(), value)) + if(AFMisc::IsDoubleEqual(oldData.GetDouble(), value)) { return false; } - if (!mxTableCallbacks.empty()) + if(!mxTableCallbacks.empty()) { AFCData newData; newData.SetDouble(value); @@ -330,7 +334,8 @@ bool AFCDataTableManager::SetTableDouble(const char* name, const int row, const OnEventHandler(self, xTableEventData, oldData, newData); } - } while (0); + } + while(0); return pTable->SetDouble(row, col, value); } @@ -338,7 +343,7 @@ bool AFCDataTableManager::SetTableDouble(const char* name, const int row, const bool AFCDataTableManager::SetTableString(const char* name, const int row, const int col, const char* value) { AFDataTable* pTable = GetTable(name); - if (pTable == nullptr) + if(pTable == nullptr) { return false; } @@ -347,17 +352,17 @@ bool AFCDataTableManager::SetTableString(const char* name, const int row, const do { AFCData oldData; - if (!GetTableData(name, row, col, oldData)) + if(!GetTableData(name, row, col, oldData)) { ARK_ASSERT_RET_VAL(0, false); } - if (ARK_STRICMP(oldData.GetString(), value) == 0) + if(ARK_STRICMP(oldData.GetString(), value) == 0) { return false; } - if (!mxTableCallbacks.empty()) + if(!mxTableCallbacks.empty()) { AFCData newData; newData.SetString(value); @@ -370,7 +375,8 @@ bool AFCDataTableManager::SetTableString(const char* name, const int row, const OnEventHandler(self, xTableEventData, oldData, newData); } - } while (0); + } + while(0); return pTable->SetString(row, col, value); } @@ -378,7 +384,7 @@ bool AFCDataTableManager::SetTableString(const char* name, const int row, const bool AFCDataTableManager::SetTableObject(const char* name, const int row, const int col, const AFGUID& value) { AFDataTable* pTable = GetTable(name); - if (pTable == nullptr) + if(pTable == nullptr) { return false; } @@ -387,17 +393,17 @@ bool AFCDataTableManager::SetTableObject(const char* name, const int row, const do { AFCData oldData; - if (!GetTableData(name, row, col, oldData)) + if(!GetTableData(name, row, col, oldData)) { ARK_ASSERT_RET_VAL(0, false); } - if (oldData.GetObject() == value) + if(oldData.GetObject() == value) { return false; } - if (!mxTableCallbacks.empty()) + if(!mxTableCallbacks.empty()) { AFCData newData; newData.SetObject(value); @@ -410,7 +416,8 @@ bool AFCDataTableManager::SetTableObject(const char* name, const int row, const OnEventHandler(self, xTableEventData, oldData, newData); } - } while (0); + } + while(0); return pTable->SetObject(row, col, value); } @@ -418,7 +425,7 @@ bool AFCDataTableManager::SetTableObject(const char* name, const int row, const bool AFCDataTableManager::GetTableBool(const char* name, const int row, const int col) { AFDataTable* pTable = GetTable(name); - if (pTable == nullptr) + if(pTable == nullptr) { return false; } @@ -429,7 +436,7 @@ bool AFCDataTableManager::GetTableBool(const char* name, const int row, const in int32_t AFCDataTableManager::GetTableInt(const char* name, const int row, const int col) { AFDataTable* pTable = GetTable(name); - if (pTable == nullptr) + if(pTable == nullptr) { return NULL_INT; } @@ -440,7 +447,7 @@ int32_t AFCDataTableManager::GetTableInt(const char* name, const int row, const int64_t AFCDataTableManager::GetTableInt64(const char* name, const int row, const int col) { AFDataTable* pTable = GetTable(name); - if (pTable == nullptr) + if(pTable == nullptr) { return NULL_INT64; } @@ -451,7 +458,7 @@ int64_t AFCDataTableManager::GetTableInt64(const char* name, const int row, cons float AFCDataTableManager::GetTableFloat(const char* name, const int row, const int col) { AFDataTable* pTable = GetTable(name); - if (pTable == nullptr) + if(pTable == nullptr) { return NULL_FLOAT; } @@ -462,7 +469,7 @@ float AFCDataTableManager::GetTableFloat(const char* name, const int row, const double AFCDataTableManager::GetTableDouble(const char* name, const int row, const int col) { AFDataTable* pTable = GetTable(name); - if (pTable == nullptr) + if(pTable == nullptr) { return NULL_DOUBLE; } @@ -473,7 +480,7 @@ double AFCDataTableManager::GetTableDouble(const char* name, const int row, cons const char* AFCDataTableManager::GetTableString(const char* name, const int row, const int col) { AFDataTable* pTable = GetTable(name); - if (pTable == nullptr) + if(pTable == nullptr) { return NULL_STR.c_str(); } @@ -484,7 +491,7 @@ const char* AFCDataTableManager::GetTableString(const char* name, const int row, const AFGUID AFCDataTableManager::GetTableObject(const char* name, const int row, const int col) { AFDataTable* pTable = GetTable(name); - if (pTable == nullptr) + if(pTable == nullptr) { return NULL_GUID; } diff --git a/Frame/SDK/Core/Base/AFArrayPod.hpp b/Frame/SDK/Core/Base/AFArrayPod.hpp index 6a67a2ae..349ba3b2 100644 --- a/Frame/SDK/Core/Base/AFArrayPod.hpp +++ b/Frame/SDK/Core/Base/AFArrayPod.hpp @@ -21,7 +21,8 @@ #pragma once #include "AFPlatform.hpp" -#include "AFMemAlloc.h" +#include "AFMacros.hpp" +#include "AFMalloc.h" class ArrayPodAlloc { @@ -31,12 +32,12 @@ class ArrayPodAlloc void* Alloc(size_t size) { - return ARK_ALLOC(size); + return ARK_MALLOC(ArrayPodAlloc, size); } void Free(void* ptr, size_t size) { - return ARK_FREE(ptr); + return ARK_FREE(ArrayPodAlloc, ptr, size); } void Swap(ArrayPodAlloc& src) @@ -66,7 +67,7 @@ class ArraryPod ArraryPod(const self_t& src) { mnSize = src.mnSize; - if (mnSize <= SIZE) + if(mnSize <= SIZE) { mpData = mxStack; mnCapacity = SIZE; @@ -82,7 +83,7 @@ class ArraryPod ~ArraryPod() { - if (mnCapacity > SIZE) + if(mnCapacity > SIZE) { mxAlloc.Free(mpData, mnCapacity * sizeof(TYPE)); } @@ -102,7 +103,7 @@ class ArraryPod TYPE* tmp_data = src.mpData; TYPE tmp_stack[SIZE]; - if (tmp_capacity <= SIZE) + if(tmp_capacity <= SIZE) { memcpy(tmp_stack, src.mxStack, tmp_size * sizeof(TYPE)); } @@ -110,7 +111,7 @@ class ArraryPod src.mnSize = this->mnSize; src.mnCapacity = this->mnCapacity; - if (this->mnCapacity <= SIZE) + if(this->mnCapacity <= SIZE) { memcpy(src.mxStack, this->mxStack, mnSize * sizeof(TYPE)); src.mpData = src.mxStack; @@ -123,7 +124,7 @@ class ArraryPod this->mnSize = tmp_size; this->mnCapacity = tmp_capacity; - if (tmp_capacity <= SIZE) + if(tmp_capacity <= SIZE) { memcpy(this->mxStack, tmp_stack, tmp_size * sizeof(TYPE)); this->mpData = this->mxStack; @@ -153,13 +154,13 @@ class ArraryPod void push_back(const TYPE& data) { - if (mnSize == mnCapacity) + if(mnSize == mnCapacity) { size_t new_size = mnSize * 2; TYPE* p = (TYPE*)mxAlloc.Alloc(new_size * sizeof(TYPE)); memcpy(p, mpData, mnSize * sizeof(TYPE)); - if (mnCapacity > SIZE) + if(mnCapacity > SIZE) { mxAlloc.Free(mpData, mnCapacity * sizeof(TYPE)); } @@ -204,12 +205,12 @@ class ArraryPod //预分配 void reserve(size_t size) { - if (size > mnCapacity) + if(size > mnCapacity) { TYPE* p = (TYPE*)mxAlloc.Alloc(size * sizeof(TYPE)); memcpy(p, mpData, mnSize * sizeof(TYPE)); - if (mnCapacity > SIZE) + if(mnCapacity > SIZE) { mxAlloc.Free(mpData, mnCapacity * sizeof(TYPE)); } @@ -221,18 +222,18 @@ class ArraryPod void resize(size_t size) { - if (size > mnCapacity) + if(size > mnCapacity) { //申请现有容量的两倍,如果还不够,就按照size来申请 size_t new_size = mnCapacity * 2; - if (new_size < size) + if(new_size < size) { new_size = size; } TYPE* p = (TYPE*)mxAlloc.Alloc(new_size * sizeof(TYPE)); memcpy(p, mpData, mnSize * sizeof(TYPE)); //把原来真正的mnSize数据赋值给新的空间 - if (mnCapacity > SIZE) + if(mnCapacity > SIZE) { mxAlloc.Free(mpData, mnCapacity * sizeof(TYPE)); } @@ -246,18 +247,18 @@ class ArraryPod void resize(size_t size, const TYPE& value) { - if (size > mnCapacity) + if(size > mnCapacity) { //申请现有容量的两倍,如果还不够,就按照size来申请 size_t new_size = mnCapacity * 2; - if (new_size < size) + if(new_size < size) { new_size = size; } TYPE* p = (TYPE*)mxAlloc.Alloc(new_size * sizeof(TYPE)); memcpy(p, mpData, mnSize * sizeof(TYPE)); //把原来真正的mnSize数据赋值给新的空间 - if (mnCapacity > SIZE) + if(mnCapacity > SIZE) { mxAlloc.Free(mpData, mnCapacity * sizeof(TYPE)); } @@ -266,9 +267,9 @@ class ArraryPod mnCapacity = new_size; //容量改成新的 } - if (size > mnSize) + if(size > mnSize) { - for (size_t i = mnSize; i < size; ++i) + for(size_t i = mnSize; i < size; ++i) { mpData[i] = value; } @@ -313,7 +314,7 @@ class ArraryPod size_t get_mem_usage() const { size_t size = sizeof(self_t); - if (mnCapacity > size) + if(mnCapacity > size) { size += mnCapacity * sizeof(TYPE); } diff --git a/Frame/SDK/Core/Base/AFCoreDef.hpp b/Frame/SDK/Core/Base/AFCoreDef.hpp index 7bd944b8..d7b008d5 100644 --- a/Frame/SDK/Core/Base/AFCoreDef.hpp +++ b/Frame/SDK/Core/Base/AFCoreDef.hpp @@ -21,7 +21,8 @@ #pragma once #include "AFPlatform.hpp" -#include "AFMemAlloc.h" +#include "AFMacros.hpp" +#include "AFMalloc.h" //will use memory pool class CoreAlloc @@ -32,12 +33,12 @@ class CoreAlloc void* Alloc(size_t size) { - return ARK_ALLOC(size); + return ARK_MALLOC(CoreAlloc, size); } void Free(void* ptr, size_t size) { - return ARK_FREE(ptr); + return ARK_FREE(CoreAlloc, ptr, size); } void Swap(CoreAlloc& src) @@ -49,7 +50,8 @@ class CoreAlloc // 取哈希值,忽略大小写 inline static unsigned int GetHashValueNoCase(const char* name) { - static unsigned char convert_to_lower[256] = { + static unsigned char convert_to_lower[256] = + { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, @@ -87,7 +89,7 @@ inline static unsigned int GetHashValueNoCase(const char* name) assert(name != nullptr); unsigned int hash = 0; - for (; *name; name++) + for(; *name; name++) { hash = hash * 131 + convert_to_lower[(unsigned char)(*name)]; } @@ -101,7 +103,7 @@ inline unsigned int GetHashValue(const char* name) assert(name != nullptr); unsigned int hash = 0; - for (; *name; name++) + for(; *name; name++) { hash = hash * 131 + *name; } diff --git a/Frame/SDK/Core/Base/AFMacros.hpp b/Frame/SDK/Core/Base/AFMacros.hpp index fb8af634..e2f0c915 100644 --- a/Frame/SDK/Core/Base/AFMacros.hpp +++ b/Frame/SDK/Core/Base/AFMacros.hpp @@ -37,9 +37,6 @@ #define INOUT #endif -#define ARK_NEW new -#define ARK_DELETE delete - #define ARRAY_CLEAR(v) memset((v), 0x0, sizeof((v))) #define MEMORY_CLEAR(v) memset(&(v), 0x0, sizeof((v))) #define MEMORY_CLEAR_POINTER(v) memset((v), 0xx, sizeof(*(v))) @@ -176,5 +173,23 @@ #endif */ +#ifndef ARK_FUNCTION_LINE +#define ARK_FUNCTION_LINE __FUNCTION__, __LINE__ +#endif + +#ifndef ARK_NEW +#define ARK_NEW new +#endif + +#ifndef ARK_DELETE +#define ARK_DELETE(p) if (p!= nullptr) { delete p; p = nullptr; } +#endif + +#ifndef ARK_DELETE_ARRAY +#define ARK_DELETE_ARRAY(p) if (p != nullptr) { delete[] p; p = nullptr; } +#endif + +#define ARK_TO_STRING(value) std::to_string(value) + // clear player data time #define CLEAR_HOUR 5 \ No newline at end of file diff --git a/Frame/SDK/Core/Base/AFMalloc.cpp b/Frame/SDK/Core/Base/AFMalloc.cpp new file mode 100644 index 00000000..3934168a --- /dev/null +++ b/Frame/SDK/Core/Base/AFMalloc.cpp @@ -0,0 +1,18 @@ +锘#include "AFMalloc.h" + +AFMalloc* AFMalloc::m_pMalloc = nullptr; + +void AFMalloc::Initialize(AFMalloc* pMalloc) +{ + if(pMalloc == nullptr) + { + pMalloc = new AFMalloc(); + } + + AFMalloc::m_pMalloc = pMalloc; +} + +AFMalloc* AFMalloc::Instance() +{ + return AFMalloc::m_pMalloc; +} \ No newline at end of file diff --git a/Frame/SDK/Core/Base/AFMalloc.h b/Frame/SDK/Core/Base/AFMalloc.h new file mode 100644 index 00000000..57835e4f --- /dev/null +++ b/Frame/SDK/Core/Base/AFMalloc.h @@ -0,0 +1,686 @@ +锘/* +* This source file is part of ArkGameFrame +* For the latest info, see https://github.com/ArkGame +* +* Copyright (c) 2013-2018 ArkGame authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ + +#pragma once + +#include "AFPlatform.hpp" +#include "AFMacros.hpp" +#include "AFMisc.hpp" + +//object pool +#define ARK_CREATE_OBJECT(name) AFMalloc::Instance()->Create(ARK_FUNCTION_LINE); +#define ARK_CREATE_BATCH_OBJECT(name, batch) AFMalloc::Instance()->Create(ARK_FUNCTION_LINE); +#define ARK_CREATE_OBJECT_WITH_ARG_1(name, batch, param) AFMalloc::Instance()->Create(param, ARK_FUNCTION_LINE); +#define ARK_CREATE_OBJECT_WITH_ARG_2(name, batch, param1, param2) AFMalloc::Instance()->Create(param1, param2, ARK_FUNCTION_LINE); +#define ARK_DELETE_OBJECT(name, object) AFMalloc::Instance()->Delete(object, ARK_FUNCTION_LINE); + +//memory pool +#define ARK_MALLOC(name, size) AFMalloc::Instance()->Malloc(size, 30, ARK_FUNCTION_LINE); +#define ARK_FREE(name, memory, size) AFMalloc::Instance()->Free(memory, size, ARK_FUNCTION_LINE); +/////////////////////////////////////////////////////////////////////////////////////////////////////////////// +class LogData +{ +public: + LogData() {} + + void AddData(uint64_t size, uint64_t totalsize) + { + ++mnCount; + mnUseSize += size; + mnTotalSize = totalsize; + } + + void DecData(uint64_t size) + { + mnCount -= std::min(mnCount, uint32_t(1)); + mnUseSize -= std::min(mnUseSize, size); + } + +public: + uint32_t mnCount = 0; + uint64_t mnUseSize = 0; + uint64_t mnTotalSize = 0; +}; + +class LogBlock +{ +public: + void AddBlock(const std::string& type, uint64_t size, uint64_t total_size) + { + LogData* pData = FindData(type); + pData->AddData(size, total_size); + } + + void DecBlock(const std::string& type, uint64_t size) + { + LogData* pData = FindData(type); + pData->DecData(size); + } + +protected: + LogData* FindData(const std::string& type) + { + auto iter = mxLogDatas.find(type); + if(iter == mxLogDatas.end()) + { + auto logdata = new LogData(); + iter = mxLogDatas.insert(std::make_pair(type, logdata)).first; + } + + return iter->second; + } + +public: + std::map mxLogDatas; +}; + +class AFMemoryLog +{ +public: + AFMemoryLog() + { + mbOpen = true; + } + + ~AFMemoryLog() + { + for(auto iter : mxSTLogBlock.mxLogDatas) + { + delete iter.second; + } + + for(auto iter : mxMTLogBlock.mxLogDatas) + { + delete iter.second; + } + + mxSTLogBlock.mxLogDatas.clear(); + mxMTLogBlock.mxLogDatas.clear();; + } + + void SetOpen(bool open) + { + mbOpen = open; + } + + bool IsOpen() const + { + return mbOpen; + } + + LogBlock GetMTMemory() + { + return mxMTLogBlock; + } + void AddMTMemory(const std::string& type, uint64_t size, uint64_t total_size) + { + if(!mbOpen) + { + return; + } + + mxMTLogBlock.AddBlock(type, size, total_size); + } + + void DecMTMemory(const std::string& type, uint64_t size) + { + if(!mbOpen) + { + return; + } + + mxMTLogBlock.DecBlock(type, size); + } + ////////////////////////////////////////////////////////////////////////// + LogBlock& GetSTMemory() + { + return mxSTLogBlock; + } + + void AddSTMemory(const std::string& type, uint64_t size, uint64_t total_size) + { + if(!mbOpen) + { + return; + } + + mxSTLogBlock.AddBlock(type, size, total_size); + } + + void DecSTMemory(const std::string& type, uint64_t size) + { + if(!mbOpen) + { + return; + } + + mxSTLogBlock.DecBlock(type, size); + } + +private: + //Log switch + bool mbOpen; + + //multi-thread + LogBlock mxMTLogBlock; + + //Single-thread + LogBlock mxSTLogBlock; +}; +////////////////////////////////////////////////////////////////////////// +class BlockMemory +{ +public: + BlockMemory(const char* type, uint32_t block_size, uint32_t block_batch, uint32_t block_alignment) + { + mstrMemType = type; + m_pNextBlock = nullptr; + mnTotalBlockSize = 0; + mnBlockBatch = block_batch; + mnBlockSize = (block_size + block_alignment - 1) & (~(block_alignment - 1)); + } + + ~BlockMemory() + { + + } + + //鍒嗛厤鍐呭瓨 + void* Malloc() + { + //濡傛灉绌轰綑鍐呭瓨娌℃湁鍒欐柊寮杈熶竴鍧楀唴瀛 + if(m_pNextBlock == nullptr) + { + // 纭畾T鍐呭瓨澶у皬,鍐嶆牴鎹唴瀛樺榻愬緱鍑洪渶瑕佺敵璇风殑鍗曚釜T鍐呭瓨鍧楀ぇ灏 + // 鏂板紑涓鎵瑰唴瀛(鐢宠鐨勫唴瀛樻瘮鍘熸湁鍐呭瓨澶15瀛楄妭,鐢ㄤ簬涓嬮潰鐨勫瓧鑺傚榻) + + uint32_t newlength = mnBlockBatch * mnBlockSize + 15; + uint8_t* pnewbatch = new uint8_t[newlength]; + + mnTotalBlockSize += newlength; + mxBlockBatches.push_back(pnewbatch); + + //16瀛楄妭瀵归綈 + uint8_t* paligned = reinterpret_cast(reinterpret_cast((pnewbatch + 15)) & (~15)); + + //灏嗗悇涓厓绱犲彲浠ユ斁缃殑鍦板潃纭畾 + m_pNextBlock = paligned; + + for(uint32_t i = 0; i < mnBlockBatch - 1; ++i) + { + uint8_t* lastblock = paligned + i * mnBlockSize; + uint8_t* nextblock = paligned + (i + 1) * mnBlockSize; + *(reinterpret_cast(lastblock)) = reinterpret_cast(nextblock); + } + + uint8_t* nextblock = paligned + (mnBlockBatch - 1) * mnBlockSize; + *(reinterpret_cast(nextblock)) = static_cast(0); + } + + uint8_t* pblock = m_pNextBlock; + m_pNextBlock = reinterpret_cast(*reinterpret_cast(m_pNextBlock)); + return reinterpret_cast(pblock); + } + + //閲婃斁鍐呭瓨 + void Free(void* pblock) + { + if(pblock == nullptr || m_pNextBlock == nullptr) + { + return; + } + + *(reinterpret_cast(pblock)) = reinterpret_cast(m_pNextBlock); + m_pNextBlock = reinterpret_cast(pblock); + } + +public: + //绫诲瀷 + std::string mstrMemType; + + //鎸囧悜鍐呭瓨鍧楀厓绱犱笅涓涓綅缃殑鎸囬拡 + uint8_t* m_pNextBlock; + + // 绠$悊闆舵暎鐨勫唴瀛樺潡鎸囬拡 + std::vector mxBlockBatches; + + // 姣忎釜鍗曚綋缁撴瀯鐨勫唴瀛樺潡瀛楄妭鏁 + uint32_t mnBlockSize; + + // 姣忔壒鐢宠鐨勫唴瀛樺潡鏁伴噺 + uint32_t mnBlockBatch; + + // 鍏叡鍒嗛厤鐨勫瓧鑺傛暟 + uint64_t mnTotalBlockSize; +}; +////////////////////////////////////////////////////////////////////////// +class BlockStore +{ +public: + BlockStore(const char* type, uint32_t block_size, uint32_t block_batch, uint32_t block_alignment) + { + m_pMutex = ARK_NEW std::mutex(); + m_pBlockMemory = ARK_NEW BlockMemory(type, block_size, block_batch, block_alignment); + } + + virtual ~BlockStore() + { + ARK_DELETE(m_pMutex); + ARK_DELETE(m_pBlockMemory); + } + + void* MallocBlock() + { + std::lock_guard locker(*m_pMutex); + + m_pMemoryLog->AddMTMemory(m_pBlockMemory->mstrMemType, m_pBlockMemory->mnBlockSize, m_pBlockMemory->mnTotalBlockSize); + return m_pBlockMemory->Malloc(); + } + + void FreeBlock(void* pObject) + { + if(pObject == nullptr) + { + return; + } + + std::lock_guard locker(*m_pMutex); + + m_pBlockMemory->Free(pObject); + m_pMemoryLog->DecMTMemory(m_pBlockMemory->mstrMemType, m_pBlockMemory->mnBlockSize); + } + + void SetLogMemory(AFMemoryLog* logmemory) + { + m_pMemoryLog = logmemory; + } + +private: + explicit BlockStore(); + explicit BlockStore(const BlockStore&); + BlockStore& operator = (const BlockStore&); + +protected: + std::mutex* m_pMutex; + BlockMemory* m_pBlockMemory; + AFMemoryLog* m_pMemoryLog; +}; + +class STBlockStore : public BlockStore +{ +public: + STBlockStore(const char* type, uint32_t block_size, uint32_t block_batch, uint32_t block_alignment); +}; + +class MTBlockStore : public BlockStore +{ +public: + MTBlockStore(const char* type, uint32_t block_size, uint32_t block_batch, uint32_t block_alignment); +}; +////////////////////////////////////////////////////////////////////////// +#define Memory_Alignment 4 +#define __USE_MEMORY_POOL__ +#define MILLION_SIZE (1024.0f * 1024.0f) + +class AFMemory +{ +public: + AFMemory() + { + mxObjectMutex = ARK_NEW std::mutex(); + mxMemoryMutex = ARK_NEW std::mutex(); + mxMemoryLog = ARK_NEW AFMemoryLog(); + } + + ~AFMemory() + { + { + std::lock_guard locker(*mxObjectMutex); + for(auto iter : mxMTObjects) + { + ARK_DELETE(iter.second); + } + mxMTObjects.clear(); + mxMTObjectBlocks.clear(); + ARK_DELETE(mxObjectMutex); + } + + { + std::lock_guard locker(*mxMemoryMutex); + for(auto iter : mxMTMemories) + { + ARK_DELETE(iter.second); + } + mxMTMemories.clear(); + mxMTMemoryBlocks.clear(); + + ARK_DELETE(mxMemoryMutex); + } + + ARK_DELETE(mxMemoryLog); + } + + void* Create(const char* name, uint32_t size, uint32_t batch, const char* function, uint32_t line) + { + auto blockstore = CreateObjectBlock(name, size, batch); + auto object = blockstore->MallocBlock(); + if(object != nullptr) + { + std::lock_guard locker(*mxObjectMutex); + mxMTObjectBlocks.insert(std::make_pair(object, blockstore)); + } + else + { + printf("[%s:%u] [%s] Object Malloc Failed!", function, line, name); + } + + return object; + } + + void Delete(void* object, const char* function, uint32_t line) + { + if(object == nullptr) + { + return; + } + + auto blockstore = FindObjectBlock(object); + if(blockstore == nullptr) + { + printf("[%s:%u] Object Free Failed!", function, line); + return; + } + + blockstore->FreeBlock(object); + } + + void* Malloc(uint32_t size, uint32_t batch, const char* function, uint32_t line) + { + auto blockstore = CreateMemoryBlock("char", size, batch); + auto memory = blockstore->MallocBlock(); + if(memory != nullptr) + { + std::lock_guard locker(*mxMemoryMutex); + mxMTMemoryBlocks.insert(std::make_pair(memory, blockstore)); + } + else + { + printf("[%s:%u] [char] Memory Malloc Failed!", function, line); + } + + return memory; + } + + void Free(void* memory, const char* function, uint32_t line) + { + if(memory == nullptr) + { + return; + } + + auto blockstore = FindMemoryBlock(memory); + if(blockstore == nullptr) + { + printf("[%s:%u] Memory Free Failed!", function, line); + return; + } + + blockstore->FreeBlock(memory); + } + + //璁剧疆鏃ュ織寮鍏 + void SetLogOpen(bool open) + { + mxMemoryLog->SetOpen(open); + } + + //鎵撳嵃鍐呭瓨淇℃伅 + void PrintLogMemory() + { + if(!mxMemoryLog->IsOpen()) + { + return; + } + + std::cout << "***********************************Print Memory Start****************************************************\n" << std::endl; + + uint64_t total_use_size = 0; + uint64_t total_malloc_size = 0; + + LogBlock mtlogblock = mxMemoryLog->GetMTMemory(); + for(auto iter = mtlogblock.mxLogDatas.begin(); iter != mtlogblock.mxLogDatas.end(); ++iter) + { + auto logdata = iter->second; + + total_use_size += logdata->mnUseSize; + total_malloc_size += logdata->mnTotalSize; + PrintLogMemory(iter->first.c_str(), logdata->mnCount, logdata->mnUseSize, logdata->mnTotalSize); + } + + double total_muse_size = static_cast(total_use_size / MILLION_SIZE); + double total_mmalloc_size = static_cast(total_malloc_size / MILLION_SIZE); + + std::cout << "******************Print Memory End, Memory[" << total_use_size << "][" << total_muse_size << "]M, Alloc[" << total_mmalloc_size << "]M*************************" << std::endl; + } + +protected: + //鏌ユ壘鍐呭瓨鍒嗛厤鍣 + BlockStore* FindObjectBlock(void* object) + { + std::lock_guard locker(*mxObjectMutex); + auto iter = mxMTObjectBlocks.find(object); + if(iter == mxMTObjectBlocks.end()) + { + return nullptr; + } + + return iter->second; + } + + BlockStore* CreateObjectBlock(const char* name, uint32_t size, uint32_t batch) + { + std::lock_guard locker(*mxObjectMutex); + auto iter = mxMTObjects.find(name); + if(iter == mxMTObjects.end()) + { + auto blockstore = new BlockStore(name, size, batch, Memory_Alignment); + blockstore->SetLogMemory(mxMemoryLog); + iter = mxMTObjects.insert(std::make_pair(name, blockstore)).first; + } + + return iter->second; + } + + BlockStore* FindMemoryBlock(void* memory) + { + std::lock_guard locker(*mxMemoryMutex); + + auto iter = mxMTMemoryBlocks.find(memory); + if(iter == mxMTMemoryBlocks.end()) + { + return nullptr; + } + + return iter->second; + } + + BlockStore* CreateMemoryBlock(const char* name, uint32_t size, uint32_t batch) + { + std::lock_guard locker(*mxMemoryMutex); + + auto iter = mxMTMemories.find(size); + if(iter == mxMTMemories.end()) + { + auto blockstore = new BlockStore(name, size, batch, Memory_Alignment); + blockstore->SetLogMemory(mxMemoryLog); + iter = mxMTMemories.insert(std::make_pair(size, blockstore)).first; + } + + return iter->second; + } + + //鎵撳嵃鍐呭瓨淇℃伅 + void PrintLogMemory(const char* type, uint32_t count, uint64_t use_size, uint64_t total_size) + { + auto strUseSize = ARK_TO_STRING(use_size); + double useSizeMB = static_cast(use_size / MILLION_SIZE); + double totalSizeMB = static_cast(total_size / MILLION_SIZE); + + printf("Count[%u] Memory[%s][%0.2fM] Alloc[%0.2fM] [%s]", count, strUseSize.c_str(), useSizeMB, totalSizeMB, type); + } + +private: + //澶氱嚎绋嬬殑瀵硅薄鍒嗛厤鍣 + std::mutex* mxObjectMutex; + std::map mxMTObjects; + std::map mxMTObjectBlocks; + + //澶氱嚎绋嬬殑鍐呭瓨鍒嗛厤鍣 + std::mutex* mxMemoryMutex; + std::map mxMTMemories; + std::map mxMTMemoryBlocks; + + AFMemoryLog* mxMemoryLog; +}; + +////////////////////////////////////////////////////////////////////////// +class AFMalloc +{ +public: + ~AFMalloc() + { + ARK_DELETE(m_pMemory); + } + + //init + static void Initialize(AFMalloc* pMalloc); + + //real memory pointer + static AFMalloc* Instance(); + + //open log + void SetLogMemoryOpen(bool open) + { + m_pMemory->SetLogOpen(open); + } + + template + T * Create(const char* function, uint32_t line) + { + auto memory = m_pMemory->Create(typeid(T).name(), sizeof(T), batch, function, line); + return new(memory) T(); + } + + template + T * Create(uint32_t param, const char* function, uint32_t line) + { + auto memory = m_pMemory->Create(typeid(T).name(), sizeof(T), batch, function, line); + return new(memory) T(param); + } + + template + T * Create(uint32_t param1, uint32_t param2, const char* function, uint32_t line) + { + auto memory = m_pMemory->Create(typeid(T).name(), sizeof(T), batch, function, line); + return new(memory) T(param1, param2); + } + + template + void Delete(T* object, const char* function, uint32_t line) + { + if(object == nullptr) + { + return; + } + object->~T(); + m_pMemory->Delete(object, function, line); + } + + template + T* Malloc(uint32_t size, uint32_t batch, const char* function, uint32_t line) + { + return reinterpret_cast(MallocMemory(size, batch, function, line)); + } + + template< class T > + void Free(void* memory, uint32_t size, const char* function, uint32_t line) + { + FreeMemory(memory, size, function, line); + } + + //print memory log + void PrintLogMemory() + { + m_pMemory->PrintLogMemory(); + } + +protected: + AFMalloc() + { + m_pMemory = ARK_NEW AFMemory(); + } + //real alloc + static AFMalloc* m_pMalloc; + + //allocation + void* MallocMemory(uint32_t size, uint32_t batch, const char* function, uint32_t line) + { + if(size == 0) + { + return nullptr; + } + + int new_size = AFMisc::GetNearest2N(size); + if(new_size != 0) + { + return m_pMemory->Malloc(new_size, batch, function, line); + } + else + { + printf("[%s:%u] Memory Too Large!", function, line); + return ARK_NEW char[size]; + } + } + + //free + void FreeMemory(void* memory, uint32_t size, const char* function, uint32_t line) + { + if(memory == nullptr || size == 0) + { + return; + } + + int new_size = AFMisc::GetNearest2N(size); + if(new_size != 0) + { + m_pMemory->Free(memory, function, line); + return; + } + else + { + char* p = reinterpret_cast(memory); + ARK_DELETE_ARRAY(p); + } + } + +private: + // 鍐呭瓨鍒嗛厤鍣 + AFMemory* m_pMemory; +}; \ No newline at end of file diff --git a/Frame/SDK/Core/Base/AFMisc.hpp b/Frame/SDK/Core/Base/AFMisc.hpp index 1e7aa8d0..529bbe2c 100644 --- a/Frame/SDK/Core/Base/AFMisc.hpp +++ b/Frame/SDK/Core/Base/AFMisc.hpp @@ -27,19 +27,28 @@ class AFMisc public: static uint32_t GetNearest2N(uint32_t size) { - if (size == 0) + if(size <= 8) + { + return 8; + } + + if(size > (1 << 16)) + { + return 0; + } + + if(size == 0) { return 0; } - if ((size & (size - 1)) == 0) + if((size & (size - 1)) == 0) { - //power(2, n) return size; } int count = 0; - while (size) + while(size) { size = size >> 1; ++count; @@ -76,8 +85,9 @@ class AFMisc nValue = ARK_LEXICAL_CAST(strValue); return true; } - catch (...) + catch(...) { + ARK_ASSERT_NO_EFFECT(0); return false; } @@ -92,7 +102,7 @@ class AFMisc strValue = ARK_LEXICAL_CAST(nValue); return true; } - catch (...) + catch(...) { return false; } @@ -100,17 +110,14 @@ class AFMisc return false; } - - static uint32_t GetSystemTime() + static int64_t GetSystemTime() { #if ARK_PLATFORM == PLATFORM_WIN - return ::GetTickCount(); + return ::GetTickCount64(); #else struct timeval tv; gettimeofday(&tv, NULL); return (tv.tv_sec * 1000) + (tv.tv_usec / 1000); #endif } - - }; \ No newline at end of file diff --git a/Frame/SDK/Core/Base/AFNoncopyable.hpp b/Frame/SDK/Core/Base/AFNoncopyable.hpp index 239a34b1..60d1cffe 100644 --- a/Frame/SDK/Core/Base/AFNoncopyable.hpp +++ b/Frame/SDK/Core/Base/AFNoncopyable.hpp @@ -20,7 +20,7 @@ #pragma once -struct AFNoncopyable +struct AFNoncopyable { protected: AFNoncopyable() {} diff --git a/Frame/SDK/Core/Base/AFStringPod.hpp b/Frame/SDK/Core/Base/AFStringPod.hpp index 82b4f357..c9fdced8 100644 --- a/Frame/SDK/Core/Base/AFStringPod.hpp +++ b/Frame/SDK/Core/Base/AFStringPod.hpp @@ -22,7 +22,7 @@ #include "AFCoreDef.hpp" #include "AFMacros.hpp" -#include "AFMemAlloc.h" +#include "AFMalloc.h" //取hash值时区分大小写 template @@ -86,12 +86,12 @@ class StringPodAlloc void* Alloc(size_t size) { - return ARK_ALLOC(size); + return ARK_MALLOC(StringPodAlloc, size); } void Free(void* ptr, size_t size) { - return ARK_FREE(ptr); + return ARK_FREE(StringPodAlloc, ptr, size); } void Swap(StringPodAlloc& src) diff --git a/Frame/SDK/Core/Base/AFTime.hpp b/Frame/SDK/Core/Base/AFTime.hpp index 74756fa3..be6d0e14 100644 --- a/Frame/SDK/Core/Base/AFTime.hpp +++ b/Frame/SDK/Core/Base/AFTime.hpp @@ -24,8 +24,7 @@ #include "AFSingleton.hpp" #include "AFMisc.hpp" -class AFCTimeBase : - public AFSingleton +class AFCTimeBase : public AFSingleton { public: //各种毫秒 diff --git a/Frame/SDK/Core/Base/AFTimer.hpp b/Frame/SDK/Core/Base/AFTimer.hpp index 7c263793..51902ab7 100644 --- a/Frame/SDK/Core/Base/AFTimer.hpp +++ b/Frame/SDK/Core/Base/AFTimer.hpp @@ -24,6 +24,7 @@ #include "AFDefine.h" #include "AFSingleton.hpp" #include "AFTime.hpp" +#include "AFMalloc.h" enum AFTimerEnum { @@ -40,19 +41,19 @@ class AFTimerData public: AFTimerData() {} - std::string name{ "" }; - uint8_t type{ 0 }; - uint16_t count{ 0 }; - uint32_t interval{ 0 }; - uint32_t rotation{ 0 }; - uint16_t slot{ 0 }; + std::string name = ""; + uint32_t type = 0; + uint32_t count = 0; + uint32_t interval = 0; + uint32_t rotation = 0; + uint32_t slot = 0; TIMER_FUNCTOR_PTR callback; //callback data - AFGUID entity_id{ 0 }; + AFGUID entity_id = 0; - AFTimerData* prev; - AFTimerData* next; + AFTimerData* prev = nullptr; + AFTimerData* next = nullptr; }; class AFTimerManager : public AFSingleton @@ -70,23 +71,23 @@ class AFTimerManager : public AFSingleton } - void Init() + void Init(uint64_t now_time) { mnNowSlot = 0; - mnLastUpdateTime = AFCTimeBase::GetInstance().GetNowMillisecond(); + mnLastUpdateTime = now_time; } - void Update() + void Update(int64_t now_time) { UpdateTimerReg(); - UpdateTimer(); + UpdateTimer(now_time); } void Shut() { - for (auto iter : mxTimers) + for(auto iter : mxTimers) { - for (auto it : iter.second) + for(auto it : iter.second) { ARK_DELETE(it.second); } @@ -99,10 +100,9 @@ class AFTimerManager : public AFSingleton bool AddForverTimer(const std::string& name, const AFGUID& entity_id, uint32_t interval_time, TIMER_FUNCTOR_PTR callback) { auto data = FindTimerData(name, entity_id); - if (data == nullptr) + if(data == nullptr) { - data = (AFTimerData*)ARK_ALLOC(sizeof(AFTimerData)); - memset(data, 0x0, sizeof(data)); + data = ARK_CREATE_OBJECT(AFTimerData); AddTimerData(name, entity_id, data); } else @@ -119,13 +119,12 @@ class AFTimerManager : public AFSingleton return true; } - bool AddSingleTimer(const std::string& name, const AFGUID& entity_id, uint32_t interval_time, uint16_t count, TIMER_FUNCTOR_PTR callback) + bool AddSingleTimer(const std::string& name, const AFGUID& entity_id, uint32_t interval_time, uint32_t count, TIMER_FUNCTOR_PTR callback) { auto data = FindTimerData(name, entity_id); - if (data == nullptr) + if(data == nullptr) { - data = (AFTimerData*)ARK_ALLOC(sizeof(AFTimerData)); - memset(data, 0x0, sizeof(data)); + data = ARK_CREATE_OBJECT(AFTimerData); AddTimerData(name, entity_id, data); } else @@ -134,8 +133,8 @@ class AFTimerManager : public AFSingleton } data->name = name; - data->type = TIMER_TYPE_FOREVER; - data->count = std::max((uint16_t)1, count); + data->type = TIMER_TYPE_COUNT_LIMIT; + data->count = std::max((uint32_t)1, count); data->interval = interval_time; data->callback = callback; data->entity_id = entity_id; @@ -160,18 +159,16 @@ class AFTimerManager : public AFSingleton } protected: - void UpdateTimer() + void UpdateTimer(int64_t now_time) { - //TODO:需要替换为一个统一的系统时间 - uint64_t now = AFCTimeBase::GetInstance().GetNowMillisecond(); - uint16_t passedSlot = (now - mnLastUpdateTime) / SLOT_TIME; - if (passedSlot == 0) + uint64_t passedSlot = (now_time - mnLastUpdateTime) / SLOT_TIME; + if(passedSlot == 0) { return; } mnLastUpdateTime += passedSlot * SLOT_TIME; - for (uint16_t i = 0; i < passedSlot; ++i) + for(uint64_t i = 0; i < passedSlot; ++i) { mnNowSlot = (mnNowSlot + 1) % MAX_SLOT; UpdateSlotTimer(); @@ -180,14 +177,14 @@ class AFTimerManager : public AFSingleton void UpdateTimerReg() { - if (mxRegTimers.empty()) + if(mxRegTimers.empty()) { return; } - for (auto data : mxRegTimers) + for(auto data : mxRegTimers) { - switch (data->type) + switch(data->type) { case TIMER_TYPE_FOREVER: AddSlotTimer(data, true); @@ -207,13 +204,13 @@ class AFTimerManager : public AFSingleton AFTimerData* FindTimerData(const std::string& name, const AFGUID& entity_id) { auto iter = mxTimers.find(name); - if (iter == mxTimers.end()) + if(iter == mxTimers.end()) { return nullptr; } auto it = iter->second.find(entity_id); - if (it == iter->second.end()) + if(it == iter->second.end()) { return nullptr; } @@ -224,7 +221,7 @@ class AFTimerManager : public AFSingleton bool AddTimerData(const std::string& name, const AFGUID& entity_id, AFTimerData* timer_data) { auto iter = mxTimers.find(name); - if (iter == mxTimers.end()) + if(iter == mxTimers.end()) { std::map tmp; iter = mxTimers.insert(std::make_pair(name, tmp)).first; @@ -236,16 +233,16 @@ class AFTimerManager : public AFSingleton bool RemoveTimerData(const std::string& name) { auto iter = mxTimers.find(name); - if (iter == mxTimers.end()) + if(iter == mxTimers.end()) { return false; } - for (auto it : iter->second) + for(auto it : iter->second) { AFTimerData* data = it.second; RemoveSlotTimer(data); - ARK_DELETE(data); + ARK_DELETE_OBJECT(AFTimerData, data); } iter->second.clear(); @@ -256,23 +253,23 @@ class AFTimerManager : public AFSingleton bool RemoveTimerData(const std::string& name, const AFGUID& entity_id) { auto iter = mxTimers.find(name); - if (iter == mxTimers.end()) + if(iter == mxTimers.end()) { return false; } auto it = iter->second.find(entity_id); - if (it == iter->second.end()) + if(it == iter->second.end()) { return false; } AFTimerData* data = it->second; RemoveSlotTimer(data); - ARK_DELETE(data); + ARK_DELETE_OBJECT(AFTimerData, data); iter->second.erase(it); - if (iter->second.empty()) + if(iter->second.empty()) { mxTimers.erase(iter); } @@ -282,7 +279,7 @@ class AFTimerManager : public AFSingleton void AddSlotTimer(AFTimerData* timer_data, bool first) { - if (first) + if(first) { timer_data->rotation = 0; timer_data->slot = (mnNowSlot + 1) % MAX_SLOT; @@ -295,7 +292,7 @@ class AFTimerManager : public AFSingleton } auto wheelData = mxSlots[timer_data->slot]; - if (wheelData != nullptr) + if(wheelData != nullptr) { timer_data->next = wheelData; wheelData->prev = timer_data; @@ -307,18 +304,18 @@ class AFTimerManager : public AFSingleton void RemoveSlotTimer(AFTimerData* timer_data) { auto prev = timer_data->prev; - if (prev != nullptr) + if(prev != nullptr) { prev->next = timer_data->next; } auto next = timer_data->next; - if (next != nullptr) + if(next != nullptr) { next->prev = timer_data->prev; } - if (timer_data == mxSlots[timer_data->slot]) + if(timer_data == mxSlots[timer_data->slot]) { mxSlots[timer_data->slot] = next; } @@ -331,9 +328,9 @@ class AFTimerManager : public AFSingleton { std::list doneDatas; auto timerData = mxSlots[mnNowSlot]; - while (timerData != nullptr) + while(timerData != nullptr) { - if (timerData->rotation > 0) + if(timerData->rotation > 0) { --timerData->rotation; } @@ -345,12 +342,12 @@ class AFTimerManager : public AFSingleton timerData = timerData->next; } - for (auto data : doneDatas) + for(auto data : doneDatas) { RemoveSlotTimer(data); (*(data->callback))(data->name, data->entity_id); - switch (data->type) + switch(data->type) { case TIMER_TYPE_FOREVER: AddSlotTimer(data, false); @@ -358,7 +355,7 @@ class AFTimerManager : public AFSingleton case TIMER_TYPE_COUNT_LIMIT: { --data->count; - if (data->count == 0) + if(data->count == 0) { RemoveTimerData(data->name, data->entity_id); } @@ -376,7 +373,7 @@ class AFTimerManager : public AFSingleton } private: - uint16_t mnNowSlot; + uint32_t mnNowSlot; AFTimerData* mxSlots[MAX_SLOT]; uint64_t mnLastUpdateTime; std::map> mxTimers; diff --git a/Frame/SDK/Core/Core.vcxproj b/Frame/SDK/Core/Core.vcxproj index 853845de..fa69d78e 100644 --- a/Frame/SDK/Core/Core.vcxproj +++ b/Frame/SDK/Core/Core.vcxproj @@ -126,11 +126,10 @@ + - - @@ -150,7 +149,7 @@ - + diff --git a/Frame/SDK/Core/Core.vcxproj.filters b/Frame/SDK/Core/Core.vcxproj.filters index 85a86c49..43d36050 100644 --- a/Frame/SDK/Core/Core.vcxproj.filters +++ b/Frame/SDK/Core/Core.vcxproj.filters @@ -105,9 +105,6 @@ Base - - Base - Base @@ -138,10 +135,10 @@ Base - + Base - + Base @@ -164,7 +161,7 @@ Core - + Base diff --git a/Frame/SDK/Interface/AFIPlugin.h b/Frame/SDK/Interface/AFIPlugin.h index eecb63c7..11fcc3ea 100644 --- a/Frame/SDK/Interface/AFIPlugin.h +++ b/Frame/SDK/Interface/AFIPlugin.h @@ -72,7 +72,7 @@ class AFIPlugin : public AFIModule virtual bool Init() { - for (AFIModule* pModule = mxModules.First(); pModule != nullptr; pModule = mxModules.Next()) + for(AFIModule* pModule = mxModules.First(); pModule != nullptr; pModule = mxModules.Next()) { bool bRet = pModule->Init(); ARK_ASSERT_CONTINUE(bRet); @@ -83,7 +83,7 @@ class AFIPlugin : public AFIModule virtual bool AfterInit() { - for (AFIModule* pModule = mxModules.First(); pModule != nullptr; pModule = mxModules.Next()) + for(AFIModule* pModule = mxModules.First(); pModule != nullptr; pModule = mxModules.Next()) { bool bRet = pModule->AfterInit(); ARK_ASSERT_CONTINUE(bRet); @@ -94,7 +94,7 @@ class AFIPlugin : public AFIModule virtual bool CheckConfig() { - for (AFIModule* pModule = mxModules.First(); pModule != nullptr; pModule = mxModules.Next()) + for(AFIModule* pModule = mxModules.First(); pModule != nullptr; pModule = mxModules.Next()) { bool bRet = pModule->CheckConfig(); ARK_ASSERT_CONTINUE(bRet); @@ -105,7 +105,7 @@ class AFIPlugin : public AFIModule virtual void Update() { - for (AFIModule* pModule = mxModules.First(); pModule != nullptr; pModule = mxModules.Next()) + for(AFIModule* pModule = mxModules.First(); pModule != nullptr; pModule = mxModules.Next()) { pModule->Update(); } @@ -113,7 +113,7 @@ class AFIPlugin : public AFIModule virtual bool BeforeShut() { - for (AFIModule* pModule = mxModules.First(); pModule != nullptr; pModule = mxModules.Next()) + for(AFIModule* pModule = mxModules.First(); pModule != nullptr; pModule = mxModules.Next()) { bool bRet = pModule->BeforeShut(); ARK_ASSERT_CONTINUE(bRet); @@ -124,7 +124,7 @@ class AFIPlugin : public AFIModule virtual bool Shut() { - for (AFIModule* pModule = mxModules.First(); pModule != nullptr; pModule = mxModules.Next()) + for(AFIModule* pModule = mxModules.First(); pModule != nullptr; pModule = mxModules.Next()) { bool bRet = pModule->Shut(); ARK_ASSERT_CONTINUE(bRet); diff --git a/Frame/SDK/Interface/AFIPluginManager.h b/Frame/SDK/Interface/AFIPluginManager.h index f9e37cd3..ef27f59f 100644 --- a/Frame/SDK/Interface/AFIPluginManager.h +++ b/Frame/SDK/Interface/AFIPluginManager.h @@ -24,6 +24,19 @@ class AFIPlugin; +#define ARK_DLL_PLUGIN_ENTRY(plugin_name) \ +ARK_EXPORT void DllStartPlugin(AFIPluginManager* pPluginManager, AFMalloc* pMalloc) \ +{ \ + AFMalloc::Initialize(pMalloc); \ + CREATE_PLUGIN(pPluginManager, plugin_name) \ +} + +#define ARK_DLL_PLUGIN_EXIT(plugin_name) \ +ARK_EXPORT void DllStopPlugin(AFIPluginManager* pPluginManager) \ +{ \ + DESTROY_PLUGIN(pPluginManager, plugin_name) \ +} + class AFIPluginManager : public AFIModule { public: @@ -36,9 +49,9 @@ class AFIPluginManager : public AFIModule T* FindModule() { AFIModule* pLogicModule = FindModule(typeid(T).name()); - if (pLogicModule) + if(pLogicModule) { - if (!std::is_base_of::value) + if(!std::is_base_of::value) { return nullptr; } diff --git a/Frame/SDK/KernelPlugin/AFKernelPlugin.cpp b/Frame/SDK/KernelPlugin/AFKernelPlugin.cpp index da28d092..43adc416 100644 --- a/Frame/SDK/KernelPlugin/AFKernelPlugin.cpp +++ b/Frame/SDK/KernelPlugin/AFKernelPlugin.cpp @@ -26,15 +26,8 @@ #ifdef ARK_DYNAMIC_PLUGIN -ARK_EXPORT void DllStartPlugin(AFIPluginManager* pm) -{ - CREATE_PLUGIN(pm, AFKernelPlugin) -}; - -ARK_EXPORT void DllStopPlugin(AFIPluginManager* pm) -{ - DESTROY_PLUGIN(pm, AFKernelPlugin) -}; +ARK_DLL_PLUGIN_ENTRY(AFKernelPlugin) +ARK_DLL_PLUGIN_EXIT(AFKernelPlugin) #endif diff --git a/Frame/SDK/PluginLoader/AFCPluginManager.cpp b/Frame/SDK/PluginLoader/AFCPluginManager.cpp index 2dca9966..8b98ba20 100644 --- a/Frame/SDK/PluginLoader/AFCPluginManager.cpp +++ b/Frame/SDK/PluginLoader/AFCPluginManager.cpp @@ -25,6 +25,8 @@ #include "RapidXML/rapidxml_utils.hpp" #include "SDK/Interface/AFIPlugin.h" #include "SDK/Core/Base/AFPlatform.hpp" +#include "SDK/Core/Base/AFMalloc.h" +#include "SDK/Core/Base/AFTime.hpp" #if ARK_PLATFORM == PLATFORM_WIN #pragma comment( lib, "ws2_32.lib" ) @@ -33,7 +35,7 @@ AFCPluginManager::AFCPluginManager() : AFIPluginManager() { mnAppID = 0; - mnInitTime = time(NULL); + mnInitTime = AFCTimeBase::GetInstance().GetNowMillisecond(); mnNowTime = mnInitTime; mstrConfigPath = ""; @@ -69,7 +71,7 @@ inline bool AFCPluginManager::Init() #endif } - for (AFIPlugin* pPlugin = mxPluginInstanceMap.First(); pPlugin != nullptr; pPlugin = mxPluginInstanceMap.Next()) + for(AFIPlugin* pPlugin = mxPluginInstanceMap.First(); pPlugin != nullptr; pPlugin = mxPluginInstanceMap.Next()) { pPlugin->Init(); } @@ -148,7 +150,7 @@ bool AFCPluginManager::LoadStaticPlugin(const std::string& strPluginDLLName) void AFCPluginManager::Registered(AFIPlugin* plugin) { std::string strPluginName = plugin->GetPluginName(); - if (!FindPlugin(strPluginName)) + if(!FindPlugin(strPluginName)) { mxPluginInstanceMap.AddElement(strPluginName, plugin); plugin->Install(); @@ -178,8 +180,8 @@ AFIPlugin* AFCPluginManager::FindPlugin(const std::string& strPluginName) void AFCPluginManager::Update() { - mnNowTime = time(NULL); - for (AFIPlugin* pPlugin = mxPluginInstanceMap.First(); pPlugin != nullptr; pPlugin = mxPluginInstanceMap.Next()) + mnNowTime = AFCTimeBase::GetInstance().GetNowMillisecond(); + for(AFIPlugin* pPlugin = mxPluginInstanceMap.First(); pPlugin != nullptr; pPlugin = mxPluginInstanceMap.Next()) { pPlugin->Update(); } @@ -260,7 +262,7 @@ AFIModule* AFCPluginManager::FindModule(const std::string& strModuleName) bool AFCPluginManager::AfterInit() { - for (AFIPlugin* pPlugin = mxPluginInstanceMap.First(); pPlugin != nullptr; pPlugin = mxPluginInstanceMap.Next()) + for(AFIPlugin* pPlugin = mxPluginInstanceMap.First(); pPlugin != nullptr; pPlugin = mxPluginInstanceMap.Next()) { pPlugin->AfterInit(); } @@ -270,7 +272,7 @@ bool AFCPluginManager::AfterInit() bool AFCPluginManager::CheckConfig() { - for (AFIPlugin* pPlugin = mxPluginInstanceMap.First(); pPlugin != nullptr; pPlugin = mxPluginInstanceMap.Next()) + for(AFIPlugin* pPlugin = mxPluginInstanceMap.First(); pPlugin != nullptr; pPlugin = mxPluginInstanceMap.Next()) { pPlugin->CheckConfig(); } @@ -280,7 +282,7 @@ bool AFCPluginManager::CheckConfig() bool AFCPluginManager::BeforeShut() { - for (AFIPlugin* pPlugin = mxPluginInstanceMap.First(); pPlugin != nullptr; pPlugin = mxPluginInstanceMap.Next()) + for(AFIPlugin* pPlugin = mxPluginInstanceMap.First(); pPlugin != nullptr; pPlugin = mxPluginInstanceMap.Next()) { pPlugin->BeforeShut(); } @@ -290,7 +292,7 @@ bool AFCPluginManager::BeforeShut() bool AFCPluginManager::Shut() { - for (AFIPlugin* pPlugin = mxPluginInstanceMap.First(); pPlugin != nullptr; pPlugin = mxPluginInstanceMap.Next()) + for(AFIPlugin* pPlugin = mxPluginInstanceMap.First(); pPlugin != nullptr; pPlugin = mxPluginInstanceMap.Next()) { pPlugin->Shut(); } @@ -312,7 +314,7 @@ bool AFCPluginManager::Shut() bool AFCPluginManager::LoadPluginLibrary(const std::string& strPluginDLLName) { AFCDynLib* pDynLib = mxPluginLibMap.GetElement(strPluginDLLName); - if (pDynLib != nullptr) + if(pDynLib != nullptr) { return false; } @@ -332,7 +334,7 @@ bool AFCPluginManager::LoadPluginLibrary(const std::string& strPluginDLLName) return false; } - pFunc(this); + pFunc(this, AFMalloc::Instance()); return true; } @@ -359,7 +361,7 @@ bool AFCPluginManager::LoadPluginLibrary(const std::string& strPluginDLLName) bool AFCPluginManager::UnLoadPluginLibrary(const std::string& strPluginDLLName) { AFCDynLib* pDynLib = mxPluginLibMap.GetElement(strPluginDLLName); - if (pDynLib == nullptr) + if(pDynLib == nullptr) { return false; } @@ -389,7 +391,7 @@ bool AFCPluginManager::UnLoadStaticPlugin(const std::string & strPluginDLLName) bool AFCPluginManager::StartReLoadState() { AFIModule::StartReLoadState(); - for (AFIPlugin* pPlugin = mxPluginInstanceMap.First(); pPlugin != NULL; pPlugin = mxPluginInstanceMap.Next()) + for(AFIPlugin* pPlugin = mxPluginInstanceMap.First(); pPlugin != NULL; pPlugin = mxPluginInstanceMap.Next()) { pPlugin->StartReLoadState(); } @@ -399,7 +401,7 @@ bool AFCPluginManager::StartReLoadState() bool AFCPluginManager::EndReLoadState() { - for (AFIPlugin* pPlugin = mxPluginInstanceMap.First(); pPlugin != NULL; pPlugin = mxPluginInstanceMap.Next()) + for(AFIPlugin* pPlugin = mxPluginInstanceMap.First(); pPlugin != NULL; pPlugin = mxPluginInstanceMap.Next()) { pPlugin->EndReLoadState(); } diff --git a/Frame/SDK/PluginLoader/AFCPluginManager.h b/Frame/SDK/PluginLoader/AFCPluginManager.h index adef6c02..0d9ab26e 100644 --- a/Frame/SDK/PluginLoader/AFCPluginManager.h +++ b/Frame/SDK/PluginLoader/AFCPluginManager.h @@ -86,7 +86,7 @@ class AFCPluginManager : public AFIPluginManager, public AFSingleton mxPluginNameMap; diff --git a/Frame/SDK/PluginLoader/AFPluginLoader.cpp b/Frame/SDK/PluginLoader/AFPluginLoader.cpp index 9e8db8aa..d9e04fe4 100644 --- a/Frame/SDK/PluginLoader/AFPluginLoader.cpp +++ b/Frame/SDK/PluginLoader/AFPluginLoader.cpp @@ -37,7 +37,13 @@ std::string strPluginName; #if ARK_PLATFORM == PLATFORM_WIN #include -#pragma comment( lib, "DbgHelp" ) +#pragma comment(lib, "DbgHelp") + +#if ARK_RUN_MODE == ARK_RUN_MODE_DEBUG +#pragma comment(lib, "AFCore_d.lib") +#else +#pragma comment(lib, "AFCore.lib") +#endif // 鍒涘缓Dump鏂囦欢 void CreateDumpFile(const std::string& strDumpFilePathName, EXCEPTION_POINTERS* pException) { @@ -92,7 +98,7 @@ void ThreadFunc() std::string s; std::cin >> s; - if (0 == strcmp(s.c_str(), "exit")) + if(0 == strcmp(s.c_str(), "exit")) { bExitApp = true; } diff --git a/Frame/SDK/UtilityPlugin/AFCTimerModule.cpp b/Frame/SDK/UtilityPlugin/AFCTimerModule.cpp index bb656513..d1b378a6 100644 --- a/Frame/SDK/UtilityPlugin/AFCTimerModule.cpp +++ b/Frame/SDK/UtilityPlugin/AFCTimerModule.cpp @@ -19,10 +19,13 @@ */ #include "AFCTimerModule.h" +#include "SDK/Interface/AFIPluginManager.h" bool AFCTimerModule::Init() { mxTimerManager = std::make_shared(); + mxTimerManager->Init(pPluginManager->GetNowTime()); + return true; } @@ -44,7 +47,7 @@ bool AFCTimerModule::Shut() void AFCTimerModule::Update() { - mxTimerManager->Update(); + mxTimerManager->Update(pPluginManager->GetNowTime()); } bool AFCTimerModule::RemoveTimer(const std::string& name) diff --git a/Frame/SDK/UtilityPlugin/AFUtilityPlugin.cpp b/Frame/SDK/UtilityPlugin/AFUtilityPlugin.cpp index 96af29bf..96f93d7d 100644 --- a/Frame/SDK/UtilityPlugin/AFUtilityPlugin.cpp +++ b/Frame/SDK/UtilityPlugin/AFUtilityPlugin.cpp @@ -21,18 +21,22 @@ #include "AFUtilityPlugin.h" #include "AFCGUIDModule.h" #include "AFCLogModule.h" +#include "AFCTimerModule.h" #ifdef ARK_DYNAMIC_PLUGIN -ARK_EXPORT void DllStartPlugin(AFIPluginManager* pm) -{ - CREATE_PLUGIN(pm, AFUtilityPlugin) -} +ARK_DLL_PLUGIN_ENTRY(AFUtilityPlugin) +ARK_DLL_PLUGIN_EXIT(AFUtilityPlugin) -ARK_EXPORT void DllStopPlugin(AFIPluginManager* pm) -{ - DESTROY_PLUGIN(pm, AFUtilityPlugin) -} +//ARK_EXPORT void DllStartPlugin(AFIPluginManager* pm) +//{ +// CREATE_PLUGIN(pm, AFUtilityPlugin) +//} +// +//ARK_EXPORT void DllStopPlugin(AFIPluginManager* pm) +//{ +// DESTROY_PLUGIN(pm, AFUtilityPlugin) +//} #endif @@ -52,10 +56,12 @@ void AFUtilityPlugin::Install() { REGISTER_MODULE(pPluginManager, AFILogModule, AFCLogModule) REGISTER_MODULE(pPluginManager, AFIGUIDModule, AFCGUIDModule) + REGISTER_MODULE(pPluginManager, AFITimerModule, AFCTimerModule) } void AFUtilityPlugin::Uninstall() { + UNREGISTER_MODULE(pPluginManager, AFITimerModule, AFCTimerModule) UNREGISTER_MODULE(pPluginManager, AFIGUIDModule, AFCGUIDModule) UNREGISTER_MODULE(pPluginManager, AFILogModule, AFCLogModule) } \ No newline at end of file diff --git a/Frame/Server/GameServer/GameLogicPlugin/AFGameLogicPlugin.cpp b/Frame/Server/GameServer/GameLogicPlugin/AFGameLogicPlugin.cpp index f9f28644..4f93b72d 100644 --- a/Frame/Server/GameServer/GameLogicPlugin/AFGameLogicPlugin.cpp +++ b/Frame/Server/GameServer/GameLogicPlugin/AFGameLogicPlugin.cpp @@ -28,19 +28,8 @@ #ifdef ARK_DYNAMIC_PLUGIN -ARK_EXPORT void DllStartPlugin(AFIPluginManager* pm) -{ -#if ARK_PLATFORM == PLATFORM_WIN - SetConsoleTitle("GameServer -- ArkGame"); -#endif // ARK_PLATFORM - CREATE_PLUGIN(pm, AFGameLogicPlugin) - -}; - -ARK_EXPORT void DllStopPlugin(AFIPluginManager* pm) -{ - DESTROY_PLUGIN(pm, AFGameLogicPlugin) -}; +ARK_DLL_PLUGIN_ENTRY(AFGameLogicPlugin) +ARK_DLL_PLUGIN_EXIT(AFGameLogicPlugin) #endif ////////////////////////////////////////////////////////////////////////// diff --git a/Frame/Server/GameServer/GameNetClientPlugin/AFGameNetClientPlugin.cpp b/Frame/Server/GameServer/GameNetClientPlugin/AFGameNetClientPlugin.cpp index ecba3788..723719ed 100644 --- a/Frame/Server/GameServer/GameNetClientPlugin/AFGameNetClientPlugin.cpp +++ b/Frame/Server/GameServer/GameNetClientPlugin/AFGameNetClientPlugin.cpp @@ -23,15 +23,8 @@ #ifdef ARK_DYNAMIC_PLUGIN -ARK_EXPORT void DllStartPlugin(AFIPluginManager* pm) -{ - CREATE_PLUGIN(pm, AFGameNetClientPlugin) -} - -ARK_EXPORT void DllStopPlugin(AFIPluginManager* pm) -{ - DESTROY_PLUGIN(pm, AFGameNetClientPlugin) -} +ARK_DLL_PLUGIN_ENTRY(AFGameNetClientPlugin) +ARK_DLL_PLUGIN_EXIT(AFGameNetClientPlugin) #endif diff --git a/Frame/Server/GameServer/GameNetServerPlugin/AFGameNetServerPlugin.cpp b/Frame/Server/GameServer/GameNetServerPlugin/AFGameNetServerPlugin.cpp index 2a8dad03..1d248571 100644 --- a/Frame/Server/GameServer/GameNetServerPlugin/AFGameNetServerPlugin.cpp +++ b/Frame/Server/GameServer/GameNetServerPlugin/AFGameNetServerPlugin.cpp @@ -23,17 +23,8 @@ #ifdef ARK_DYNAMIC_PLUGIN -ARK_EXPORT void DllStartPlugin(AFIPluginManager* pm) -{ - - CREATE_PLUGIN(pm, AFGameNetServerPlugin) - -}; - -ARK_EXPORT void DllStopPlugin(AFIPluginManager* pm) -{ - DESTROY_PLUGIN(pm, AFGameNetServerPlugin) -}; +ARK_DLL_PLUGIN_ENTRY(AFGameNetServerPlugin) +ARK_DLL_PLUGIN_EXIT(AFGameNetServerPlugin) #endif ////////////////////////////////////////////////////////////////////////// diff --git a/Frame/Server/LoginServer/LoginLogicPlugin/AFLoginLogicPlugin.cpp b/Frame/Server/LoginServer/LoginLogicPlugin/AFLoginLogicPlugin.cpp index 4c9d2277..34a3e806 100644 --- a/Frame/Server/LoginServer/LoginLogicPlugin/AFLoginLogicPlugin.cpp +++ b/Frame/Server/LoginServer/LoginLogicPlugin/AFLoginLogicPlugin.cpp @@ -23,19 +23,8 @@ #ifdef ARK_DYNAMIC_PLUGIN -ARK_EXPORT void DllStartPlugin(AFIPluginManager* pm) -{ -#if ARK_PLATFORM == PLATFORM_WIN - SetConsoleTitle("LoginServer -- ArkGame"); -#endif - CREATE_PLUGIN(pm, AFLoginLogicPlugin) - -}; - -ARK_EXPORT void DllStopPlugin(AFIPluginManager* pm) -{ - DESTROY_PLUGIN(pm, AFLoginLogicPlugin) -}; +ARK_DLL_PLUGIN_ENTRY(AFLoginLogicPlugin) +ARK_DLL_PLUGIN_EXIT(AFLoginLogicPlugin) #endif ////////////////////////////////////////////////////////////////////////// diff --git a/Frame/Server/LoginServer/LoginNetClientPlugin/AFLoginNetClientPlugin.cpp b/Frame/Server/LoginServer/LoginNetClientPlugin/AFLoginNetClientPlugin.cpp index 36a907b9..0733bd7b 100644 --- a/Frame/Server/LoginServer/LoginNetClientPlugin/AFLoginNetClientPlugin.cpp +++ b/Frame/Server/LoginServer/LoginNetClientPlugin/AFLoginNetClientPlugin.cpp @@ -23,15 +23,8 @@ #ifdef ARK_DYNAMIC_PLUGIN -ARK_EXPORT void DllStartPlugin(AFIPluginManager* pm) -{ - CREATE_PLUGIN(pm, AFLoginNetClientPlugin) -}; - -ARK_EXPORT void DllStopPlugin(AFIPluginManager* pm) -{ - DESTROY_PLUGIN(pm, AFLoginNetClientPlugin) -}; +ARK_DLL_PLUGIN_ENTRY(AFLoginNetClientPlugin) +ARK_DLL_PLUGIN_EXIT(AFLoginNetClientPlugin) #endif diff --git a/Frame/Server/LoginServer/LoginNetServerPlugin/AFLoginNetServerPlugin.cpp b/Frame/Server/LoginServer/LoginNetServerPlugin/AFLoginNetServerPlugin.cpp index 17f8ec0e..fe596063 100644 --- a/Frame/Server/LoginServer/LoginNetServerPlugin/AFLoginNetServerPlugin.cpp +++ b/Frame/Server/LoginServer/LoginNetServerPlugin/AFLoginNetServerPlugin.cpp @@ -23,16 +23,8 @@ #ifdef ARK_DYNAMIC_PLUGIN -ARK_EXPORT void DllStartPlugin(AFIPluginManager* pm) -{ - CREATE_PLUGIN(pm, AFLoginNetServerPlugin) - -}; - -ARK_EXPORT void DllStopPlugin(AFIPluginManager* pm) -{ - DESTROY_PLUGIN(pm, AFLoginNetServerPlugin) -}; +ARK_DLL_PLUGIN_ENTRY(AFLoginNetServerPlugin) +ARK_DLL_PLUGIN_EXIT(AFLoginNetServerPlugin) #endif diff --git a/Frame/Server/MasterServer/MasterLogicPlugin/AFMasterLogicPlugin.cpp b/Frame/Server/MasterServer/MasterLogicPlugin/AFMasterLogicPlugin.cpp index 3c356d9a..9370473f 100644 --- a/Frame/Server/MasterServer/MasterLogicPlugin/AFMasterLogicPlugin.cpp +++ b/Frame/Server/MasterServer/MasterLogicPlugin/AFMasterLogicPlugin.cpp @@ -23,19 +23,8 @@ #ifdef ARK_DYNAMIC_PLUGIN -ARK_EXPORT void DllStartPlugin(AFIPluginManager* pm) -{ -#if ARK_PLATFORM == PLATFORM_WIN - SetConsoleTitle("MasterServer -- ArkGame"); -#endif - - CREATE_PLUGIN(pm, AFMasterLogicPlugin) -} - -ARK_EXPORT void DllStopPlugin(AFIPluginManager* pm) -{ - DESTROY_PLUGIN(pm, AFMasterLogicPlugin) -} +ARK_DLL_PLUGIN_ENTRY(AFMasterLogicPlugin) +ARK_DLL_PLUGIN_EXIT(AFMasterLogicPlugin) #endif ////////////////////////////////////////////////////////////////////////// diff --git a/Frame/Server/MasterServer/MasterNetServerPlugin/AFMasterNetServerPlugin.cpp b/Frame/Server/MasterServer/MasterNetServerPlugin/AFMasterNetServerPlugin.cpp index c5d6ad92..8142872c 100644 --- a/Frame/Server/MasterServer/MasterNetServerPlugin/AFMasterNetServerPlugin.cpp +++ b/Frame/Server/MasterServer/MasterNetServerPlugin/AFMasterNetServerPlugin.cpp @@ -23,17 +23,8 @@ #ifdef ARK_DYNAMIC_PLUGIN -ARK_EXPORT void DllStartPlugin(AFIPluginManager* pm) -{ - - CREATE_PLUGIN(pm, AFMasterNetServerPlugin) - -}; - -ARK_EXPORT void DllStopPlugin(AFIPluginManager* pm) -{ - DESTROY_PLUGIN(pm, AFMasterNetServerPlugin) -}; +ARK_DLL_PLUGIN_ENTRY(AFMasterNetServerPlugin) +ARK_DLL_PLUGIN_EXIT(AFMasterNetServerPlugin) #endif diff --git a/Frame/Server/ProxyServer/ProxyLogicPlugin/AFProxyLogicPlugin.cpp b/Frame/Server/ProxyServer/ProxyLogicPlugin/AFProxyLogicPlugin.cpp index 3959700c..49a79316 100644 --- a/Frame/Server/ProxyServer/ProxyLogicPlugin/AFProxyLogicPlugin.cpp +++ b/Frame/Server/ProxyServer/ProxyLogicPlugin/AFProxyLogicPlugin.cpp @@ -23,18 +23,8 @@ #ifdef ARK_DYNAMIC_PLUGIN -ARK_EXPORT void DllStartPlugin(AFIPluginManager* pm) -{ -#if ARK_PLATFORM == PLATFORM_WIN - SetConsoleTitle("ProxyServer -- ArkGame"); -#endif - CREATE_PLUGIN(pm, AFProxyLogicPlugin) -} - -ARK_EXPORT void DllStopPlugin(AFIPluginManager* pm) -{ - DESTROY_PLUGIN(pm, AFProxyLogicPlugin) -} +ARK_DLL_PLUGIN_ENTRY(AFProxyLogicPlugin) +ARK_DLL_PLUGIN_EXIT(AFProxyLogicPlugin) #endif ////////////////////////////////////////////////////////////////////////// diff --git a/Frame/Server/ProxyServer/ProxyNetClientPlugin/AFProxyNetClientPlugin.cpp b/Frame/Server/ProxyServer/ProxyNetClientPlugin/AFProxyNetClientPlugin.cpp index 5aacd75e..12131853 100644 --- a/Frame/Server/ProxyServer/ProxyNetClientPlugin/AFProxyNetClientPlugin.cpp +++ b/Frame/Server/ProxyServer/ProxyNetClientPlugin/AFProxyNetClientPlugin.cpp @@ -25,15 +25,8 @@ #ifdef ARK_DYNAMIC_PLUGIN -ARK_EXPORT void DllStartPlugin(AFIPluginManager* pm) -{ - CREATE_PLUGIN(pm, AFProxyNetClientPlugin) -} - -ARK_EXPORT void DllStopPlugin(AFIPluginManager* pm) -{ - DESTROY_PLUGIN(pm, AFProxyNetClientPlugin) -} +ARK_DLL_PLUGIN_ENTRY(AFProxyNetClientPlugin) +ARK_DLL_PLUGIN_EXIT(AFProxyNetClientPlugin) #endif ////////////////////////////////////////////////////////////////////////// diff --git a/Frame/Server/ProxyServer/ProxyNetServerPlugin/AFProxyNetServerPlugin.cpp b/Frame/Server/ProxyServer/ProxyNetServerPlugin/AFProxyNetServerPlugin.cpp index 7421410c..f5e8a004 100644 --- a/Frame/Server/ProxyServer/ProxyNetServerPlugin/AFProxyNetServerPlugin.cpp +++ b/Frame/Server/ProxyServer/ProxyNetServerPlugin/AFProxyNetServerPlugin.cpp @@ -23,17 +23,8 @@ #ifdef ARK_DYNAMIC_PLUGIN -ARK_EXPORT void DllStartPlugin(AFIPluginManager* pm) -{ - - CREATE_PLUGIN(pm, AFProxyNetServerPlugin) - -}; - -ARK_EXPORT void DllStopPlugin(AFIPluginManager* pm) -{ - DESTROY_PLUGIN(pm, AFProxyNetServerPlugin) -}; +ARK_DLL_PLUGIN_ENTRY(AFProxyNetServerPlugin) +ARK_DLL_PLUGIN_EXIT(AFProxyNetServerPlugin) #endif ////////////////////////////////////////////////////////////////////////// diff --git a/Frame/Server/WorldServer/WorldLogicPlugin/AFWorldLogicPlugin.cpp b/Frame/Server/WorldServer/WorldLogicPlugin/AFWorldLogicPlugin.cpp index d5963ee9..745d6054 100644 --- a/Frame/Server/WorldServer/WorldLogicPlugin/AFWorldLogicPlugin.cpp +++ b/Frame/Server/WorldServer/WorldLogicPlugin/AFWorldLogicPlugin.cpp @@ -21,19 +21,12 @@ #include "AFCWorldLogicModule.h" #include "AFWorldLogicPlugin.h" -ARK_EXPORT void DllStartPlugin(AFIPluginManager* pm) -{ -#if ARK_PLATFORM == PLATFORM_WIN - SetConsoleTitle("WorldServer -- ArkGame"); -#endif // ARK_PLATFORM - CREATE_PLUGIN(pm, AFWorldLogicPlugin) -}; +#ifdef ARK_DYNAMIC_PLUGIN -ARK_EXPORT void DllStopPlugin(AFIPluginManager* pm) -{ - DESTROY_PLUGIN(pm, AFWorldLogicPlugin) -}; +ARK_DLL_PLUGIN_ENTRY(AFWorldLogicPlugin) +ARK_DLL_PLUGIN_EXIT(AFWorldLogicPlugin) +#endif ////////////////////////////////////////////////////////////////////////// int AFWorldLogicPlugin::GetPluginVersion() diff --git a/Frame/Server/WorldServer/WorldNetClientPlugin/AFWorldNetClientPlugin.cpp b/Frame/Server/WorldServer/WorldNetClientPlugin/AFWorldNetClientPlugin.cpp index 2d839f27..44cb9bd1 100644 --- a/Frame/Server/WorldServer/WorldNetClientPlugin/AFWorldNetClientPlugin.cpp +++ b/Frame/Server/WorldServer/WorldNetClientPlugin/AFWorldNetClientPlugin.cpp @@ -23,15 +23,8 @@ #ifdef ARK_DYNAMIC_PLUGIN -ARK_EXPORT void DllStartPlugin(AFIPluginManager* pm) -{ - CREATE_PLUGIN(pm, AFWorldNetClientPlugin) -} - -ARK_EXPORT void DllStopPlugin(AFIPluginManager* pm) -{ - DESTROY_PLUGIN(pm, AFWorldNetClientPlugin) -} +ARK_DLL_PLUGIN_ENTRY(AFWorldNetClientPlugin) +ARK_DLL_PLUGIN_EXIT(AFWorldNetClientPlugin) #endif ////////////////////////////////////////////////////////////////////////// diff --git a/Frame/Server/WorldServer/WorldNetServerPlugin/AFWorldNetServerPlugin.cpp b/Frame/Server/WorldServer/WorldNetServerPlugin/AFWorldNetServerPlugin.cpp index 22ef832b..ae7a7740 100644 --- a/Frame/Server/WorldServer/WorldNetServerPlugin/AFWorldNetServerPlugin.cpp +++ b/Frame/Server/WorldServer/WorldNetServerPlugin/AFWorldNetServerPlugin.cpp @@ -23,16 +23,8 @@ #ifdef ARK_DYNAMIC_PLUGIN -ARK_EXPORT void DllStartPlugin(AFIPluginManager* pm) -{ - CREATE_PLUGIN(pm, AFWorldNetServerPlugin) - -}; - -ARK_EXPORT void DllStopPlugin(AFIPluginManager* pm) -{ - DESTROY_PLUGIN(pm, AFWorldNetServerPlugin) -}; +ARK_DLL_PLUGIN_ENTRY(AFWorldNetServerPlugin) +ARK_DLL_PLUGIN_EXIT(AFWorldNetServerPlugin) #endif ////////////////////////////////////////////////////////////////////////// From b97a3bfbc207ad77d2aedace63f53bd89e0f91c7 Mon Sep 17 00:00:00 2001 From: NickYang <362148418@qq.com> Date: Thu, 29 Mar 2018 19:02:39 +0800 Subject: [PATCH 12/24] add SDK/Core/Base dir in cmake Former-commit-id: b822d0a7580151a582325a059647285d57e648fd Former-commit-id: 90c7c5698293e136f269dd11d6fc8baec25b67e0 --- Frame/SDK/Core/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Frame/SDK/Core/CMakeLists.txt b/Frame/SDK/Core/CMakeLists.txt index d34b3a7f..3ff5c171 100644 --- a/Frame/SDK/Core/CMakeLists.txt +++ b/Frame/SDK/Core/CMakeLists.txt @@ -1,4 +1,4 @@ -file(GLOB AFCore_SRC *.h *.hpp *.cpp *.cc *.c) +file(GLOB AFCore_SRC *.h *.hpp *.cpp *.cc *.c Base/*) add_library(AFCore STATIC ${AFCore_SRC}) From ad05c62cb1e3ea20a4e6c7544b15b0fec8841075 Mon Sep 17 00:00:00 2001 From: NickYang <362148418@qq.com> Date: Thu, 29 Mar 2018 19:21:51 +0800 Subject: [PATCH 13/24] fix compiling error in linux Former-commit-id: bcf990f72575acc3ff2370baa20ebd5cac37b1c3 Former-commit-id: ec174075a8a372101e1723a676011266930253b8 --- Frame/SDK/Core/Base/{AFMemAlloc.cpp => AFMemAlloc.cpp.bak} | 2 +- Frame/SDK/Core/Base/{AFMemAlloc.h => AFMemAlloc.h.bak} | 0 Frame/SDK/PluginLoader/CMakeLists.txt | 2 ++ 3 files changed, 3 insertions(+), 1 deletion(-) rename Frame/SDK/Core/Base/{AFMemAlloc.cpp => AFMemAlloc.cpp.bak} (99%) rename Frame/SDK/Core/Base/{AFMemAlloc.h => AFMemAlloc.h.bak} (100%) diff --git a/Frame/SDK/Core/Base/AFMemAlloc.cpp b/Frame/SDK/Core/Base/AFMemAlloc.cpp.bak similarity index 99% rename from Frame/SDK/Core/Base/AFMemAlloc.cpp rename to Frame/SDK/Core/Base/AFMemAlloc.cpp.bak index c151b228..cb1f7daa 100644 --- a/Frame/SDK/Core/Base/AFMemAlloc.cpp +++ b/Frame/SDK/Core/Base/AFMemAlloc.cpp.bak @@ -21,7 +21,7 @@ #include "AFMemAlloc.h" bool g_needRecord = false; -std::atomic_int g_totalAlloc = 0; +std::atomic_int g_totalAlloc(0); std::map g_memMap; std::mutex g_memMapMutex; diff --git a/Frame/SDK/Core/Base/AFMemAlloc.h b/Frame/SDK/Core/Base/AFMemAlloc.h.bak similarity index 100% rename from Frame/SDK/Core/Base/AFMemAlloc.h rename to Frame/SDK/Core/Base/AFMemAlloc.h.bak diff --git a/Frame/SDK/PluginLoader/CMakeLists.txt b/Frame/SDK/PluginLoader/CMakeLists.txt index e6fa432a..166ee235 100644 --- a/Frame/SDK/PluginLoader/CMakeLists.txt +++ b/Frame/SDK/PluginLoader/CMakeLists.txt @@ -3,6 +3,8 @@ file(GLOB PluginLoader_SRC *.h *.hpp *.cpp *.cc *.c) add_definitions(-DELPP_NO_DEFAULT_LOG_FILE) add_executable(PluginLoader ${PluginLoader_SRC}) +add_dependencies(PluginLoader AFCore) + set_target_properties(PluginLoader PROPERTIES OUTPUT_NAME_DEBUG "PluginLoader_d") set_target_properties(PluginLoader PROPERTIES FOLDER "PluginLoader" From 36ec302c5916e5672f7fd3726abc4f713125fb79 Mon Sep 17 00:00:00 2001 From: NickYang <362148418@qq.com> Date: Thu, 29 Mar 2018 19:31:52 +0800 Subject: [PATCH 14/24] change cmake Former-commit-id: cd48279981f47bea16035841964384871d769ff3 Former-commit-id: ba95164794db730addb0b8dd47857c2f5714ee1a --- Frame/SDK/PluginLoader/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/Frame/SDK/PluginLoader/CMakeLists.txt b/Frame/SDK/PluginLoader/CMakeLists.txt index 166ee235..73ff6ce0 100644 --- a/Frame/SDK/PluginLoader/CMakeLists.txt +++ b/Frame/SDK/PluginLoader/CMakeLists.txt @@ -4,6 +4,7 @@ add_definitions(-DELPP_NO_DEFAULT_LOG_FILE) add_executable(PluginLoader ${PluginLoader_SRC}) add_dependencies(PluginLoader AFCore) +link_libraries(AFCore) set_target_properties(PluginLoader PROPERTIES OUTPUT_NAME_DEBUG "PluginLoader_d") set_target_properties(PluginLoader PROPERTIES From 6f7f7a7780c9685e320c85b6a673d2ca95f23e49 Mon Sep 17 00:00:00 2001 From: NickYang <362148418@qq.com> Date: Thu, 29 Mar 2018 19:56:26 +0800 Subject: [PATCH 15/24] fix compiling errors in Linux Former-commit-id: cb08c6bac4a60cc48eddbf5c5eaecda7328fa662 Former-commit-id: c0f09238e2c36db15590fa5c066d0cbcc77a8c33 --- Frame/SDK/PluginLoader/CMakeLists.txt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Frame/SDK/PluginLoader/CMakeLists.txt b/Frame/SDK/PluginLoader/CMakeLists.txt index 73ff6ce0..fc6817d0 100644 --- a/Frame/SDK/PluginLoader/CMakeLists.txt +++ b/Frame/SDK/PluginLoader/CMakeLists.txt @@ -3,8 +3,16 @@ file(GLOB PluginLoader_SRC *.h *.hpp *.cpp *.cc *.c) add_definitions(-DELPP_NO_DEFAULT_LOG_FILE) add_executable(PluginLoader ${PluginLoader_SRC}) -add_dependencies(PluginLoader AFCore) -link_libraries(AFCore) +if(UNIX) + target_link_libraries(PluginLoader AFCore AFNet) +else(UNIX) + target_link_libraries(PluginLoader + debug AFCore_d.lib + debug AFNet_d.lib + + optimized AFCore.lib + optimized AFNet.lib) +endif(UNIX) set_target_properties(PluginLoader PROPERTIES OUTPUT_NAME_DEBUG "PluginLoader_d") set_target_properties(PluginLoader PROPERTIES From b13ff4352595dd0d9e6a6842f20d7a8a4ccc1448 Mon Sep 17 00:00:00 2001 From: NickYang <362148418@qq.com> Date: Fri, 30 Mar 2018 16:54:40 +0800 Subject: [PATCH 16/24] Rename function names; Add launch parameters; Former-commit-id: baba33d4e973ff948559d6397c8f1426a11d42ed Former-commit-id: 5c54707b5be4db4fd99ccd2ed4bfc71c32ccffa0 --- Frame/Examples/Tutorial1/HelloWorld1.cpp | 8 +- Frame/Examples/Tutorial1/HelloWorld1.h | 7 +- Frame/Examples/Tutorial2/HelloWorld2.cpp | 8 +- Frame/Examples/Tutorial2/HelloWorld2.h | 4 +- .../Examples/Tutorial3/HelloWorld3Module.cpp | 8 +- Frame/Examples/Tutorial3/HelloWorld3Module.h | 4 +- Frame/SDK/Core/Base/AFPlatform.hpp | 1 + Frame/SDK/Interface/AFIModule.h | 17 +- Frame/SDK/Interface/AFIPlugin.h | 8 +- Frame/SDK/Interface/AFIPluginManager.h | 1 + Frame/SDK/KernelPlugin/AFCElementModule.cpp | 4 +- Frame/SDK/KernelPlugin/AFCElementModule.h | 4 +- Frame/SDK/KernelPlugin/AFCKernelModule.cpp | 4 +- Frame/SDK/KernelPlugin/AFCKernelModule.h | 4 +- Frame/SDK/KernelPlugin/AFCSceneModule.cpp | 4 +- Frame/SDK/KernelPlugin/AFCSceneModule.h | 4 +- Frame/SDK/PluginLoader/AFCPluginManager.cpp | 13 +- Frame/SDK/PluginLoader/AFCPluginManager.h | 7 +- Frame/SDK/PluginLoader/AFPluginLoader.cpp | 338 ++++++++++++++---- Frame/SDK/UtilityPlugin/AFCGUIDModule.cpp | 4 +- Frame/SDK/UtilityPlugin/AFCGUIDModule.h | 4 +- Frame/SDK/UtilityPlugin/AFCLogModule.cpp | 4 +- Frame/SDK/UtilityPlugin/AFCLogModule.h | 4 +- Frame/SDK/UtilityPlugin/AFCScheduleModule.cpp | 4 +- Frame/SDK/UtilityPlugin/AFCScheduleModule.h | 4 +- Frame/SDK/UtilityPlugin/AFCTimerModule.cpp | 4 +- Frame/SDK/UtilityPlugin/AFCTimerModule.h | 4 +- .../GameLogicPlugin/AFCAccountModule.cpp | 2 +- .../GameLogicPlugin/AFCAccountModule.h | 2 +- .../GameLogicPlugin/AFCGameServerModule.cpp | 4 +- .../GameLogicPlugin/AFCGameServerModule.h | 4 +- .../GameLogicPlugin/AFCLevelModule.cpp | 2 +- .../GameLogicPlugin/AFCLevelModule.h | 2 +- .../AFCPropertyConfigModule.cpp | 2 +- .../GameLogicPlugin/AFCPropertyConfigModule.h | 2 +- .../GameLogicPlugin/AFCPropertyModule.cpp | 2 +- .../GameLogicPlugin/AFCPropertyModule.h | 2 +- .../AFCPropertyTrailModule.cpp | 2 +- .../GameLogicPlugin/AFCPropertyTrailModule.h | 2 +- .../GameLogicPlugin/AFCSceneProcessModule.cpp | 2 +- .../GameLogicPlugin/AFCSceneProcessModule.h | 2 +- .../AFCGameServerToWorldModule.cpp | 2 +- .../AFCGameServerToWorldModule.h | 2 +- .../AFCGameNetServerModule.cpp | 2 +- .../AFCGameNetServerModule.h | 2 +- .../LoginLogicPlugin/AFCLoginLogicModule.cpp | 2 +- .../LoginLogicPlugin/AFCLoginLogicModule.h | 2 +- .../AFCLoginToMasterModule.cpp | 4 +- .../AFCLoginToMasterModule.h | 4 +- .../AFCLoginNetServerModule.cpp | 4 +- .../AFCLoginNetServerModule.h | 4 +- .../AFCMasterNetServerModule.cpp | 2 +- .../AFCMasterNetServerModule.h | 2 +- .../ProxyLogicPlugin/AFCProxyLogicModule.cpp | 2 +- .../ProxyLogicPlugin/AFCProxyLogicModule.h | 2 +- .../AFCProxyServerToGameModule.cpp | 2 +- .../AFCProxyServerToGameModule.h | 2 +- .../AFCProxyServerToWorldModule.cpp | 2 +- .../AFCProxyServerToWorldModule.h | 2 +- .../AFCProxyNetServerModule.cpp | 2 +- .../AFCProxyNetServerModule.h | 2 +- .../WorldLogicPlugin/AFCWorldLogicModule.cpp | 2 +- .../WorldLogicPlugin/AFCWorldLogicModule.h | 2 +- .../AFCWorldToMasterModule.cpp | 4 +- .../AFCWorldToMasterModule.h | 4 +- .../AFCWorldNetServerModule.cpp | 2 +- .../AFCWorldNetServerModule.h | 2 +- 67 files changed, 390 insertions(+), 186 deletions(-) diff --git a/Frame/Examples/Tutorial1/HelloWorld1.cpp b/Frame/Examples/Tutorial1/HelloWorld1.cpp index 7b484888..6c182837 100644 --- a/Frame/Examples/Tutorial1/HelloWorld1.cpp +++ b/Frame/Examples/Tutorial1/HelloWorld1.cpp @@ -29,13 +29,13 @@ bool HelloWorld1::Init() return true; } -bool HelloWorld1::AfterInit() +bool HelloWorld1::PostInit() { m_pTimerModule = pPluginManager->FindModule(); ARK_ASSERT_RET_VAL(m_pTimerModule != nullptr, false); - std::cout << "Hello, world1, AfterInit" << std::endl; + std::cout << "Hello, world1, PostInit" << std::endl; AFCData data1(DT_STRING, "test1"); AFCData data2(DT_STRING, "test2"); @@ -54,9 +54,9 @@ void HelloWorld1::Update() } -bool HelloWorld1::BeforeShut() +bool HelloWorld1::PreShut() { - std::cout << "Hello, world1, BeforeShut-------------" << std::endl; + std::cout << "Hello, world1, PreShut-------------" << std::endl; return true; } diff --git a/Frame/Examples/Tutorial1/HelloWorld1.h b/Frame/Examples/Tutorial1/HelloWorld1.h index f5f7f29c..589c12e2 100644 --- a/Frame/Examples/Tutorial1/HelloWorld1.h +++ b/Frame/Examples/Tutorial1/HelloWorld1.h @@ -24,8 +24,7 @@ #include "SDK/Interface/AFIPluginManager.h" #include "SDK/Interface/AFITimerModule.h" -class HelloWorld1 - : public AFIModule +class HelloWorld1 : public AFIModule { public: HelloWorld1(AFIPluginManager* p) @@ -34,11 +33,11 @@ class HelloWorld1 } virtual bool Init(); - virtual bool AfterInit(); + virtual bool PostInit(); virtual void Update(); - virtual bool BeforeShut(); + virtual bool PreShut(); virtual bool Shut(); protected: diff --git a/Frame/Examples/Tutorial2/HelloWorld2.cpp b/Frame/Examples/Tutorial2/HelloWorld2.cpp index 00fdd879..363ce639 100644 --- a/Frame/Examples/Tutorial2/HelloWorld2.cpp +++ b/Frame/Examples/Tutorial2/HelloWorld2.cpp @@ -37,13 +37,13 @@ int HelloWorld2::OnPropertyCallBackEvent(const AFGUID& self, const std::string& return 0; } -bool HelloWorld2::AfterInit() +bool HelloWorld2::PostInit() { AFCDataList xData; xData.AddInt(111); { - std::cout << "Hello, world2, AfterInit" << std::endl; + std::cout << "Hello, world2, PostInit" << std::endl; //created a object for this test AFIEntity* pEntity = new AFCEntity(AFGUID(0, 1), pPluginManager); @@ -81,9 +81,9 @@ void HelloWorld2::Update() } -bool HelloWorld2::BeforeShut() +bool HelloWorld2::PreShut() { - std::cout << "Hello, world2, BeforeShut" << std::endl; + std::cout << "Hello, world2, PreShut" << std::endl; return true; } diff --git a/Frame/Examples/Tutorial2/HelloWorld2.h b/Frame/Examples/Tutorial2/HelloWorld2.h index 94c20c01..b75ffa35 100644 --- a/Frame/Examples/Tutorial2/HelloWorld2.h +++ b/Frame/Examples/Tutorial2/HelloWorld2.h @@ -33,11 +33,11 @@ class HelloWorld2 } virtual bool Init(); - virtual bool AfterInit(); + virtual bool PostInit(); virtual void Update(); - virtual bool BeforeShut(); + virtual bool PreShut(); virtual bool Shut(); protected: diff --git a/Frame/Examples/Tutorial3/HelloWorld3Module.cpp b/Frame/Examples/Tutorial3/HelloWorld3Module.cpp index 1a0fd3a6..6241231c 100644 --- a/Frame/Examples/Tutorial3/HelloWorld3Module.cpp +++ b/Frame/Examples/Tutorial3/HelloWorld3Module.cpp @@ -92,10 +92,10 @@ int HelloWorld3Module::OnFightHeroTableCB(const AFGUID& self, const DATA_TABLE_E return 0; } -bool HelloWorld3Module::AfterInit() +bool HelloWorld3Module::PostInit() { //初始化完毕 - std::cout << "Hello, world3, AfterInit" << std::endl; + std::cout << "Hello, world3, PostInit" << std::endl; m_pKernelModule = pPluginManager->FindModule(); m_pElementModule = pPluginManager->FindModule(); @@ -147,9 +147,9 @@ void HelloWorld3Module::Update() } -bool HelloWorld3Module::BeforeShut() +bool HelloWorld3Module::PreShut() { - std::cout << "Hello, world3, BeforeShut" << std::endl; + std::cout << "Hello, world3, PreShut" << std::endl; m_pKernelModule->DestroyAll(); return true; diff --git a/Frame/Examples/Tutorial3/HelloWorld3Module.h b/Frame/Examples/Tutorial3/HelloWorld3Module.h index b2d07285..13640927 100644 --- a/Frame/Examples/Tutorial3/HelloWorld3Module.h +++ b/Frame/Examples/Tutorial3/HelloWorld3Module.h @@ -37,11 +37,11 @@ class HelloWorld3Module } virtual bool Init(); - virtual bool AfterInit(); + virtual bool PostInit(); virtual void Update(); - virtual bool BeforeShut(); + virtual bool PreShut(); virtual bool Shut(); protected: diff --git a/Frame/SDK/Core/Base/AFPlatform.hpp b/Frame/SDK/Core/Base/AFPlatform.hpp index f8a38444..49c8dadb 100644 --- a/Frame/SDK/Core/Base/AFPlatform.hpp +++ b/Frame/SDK/Core/Base/AFPlatform.hpp @@ -55,6 +55,7 @@ #include #include #include +#include #define NOMINMAX #if defined(__WIN32__) || defined(WIN32) || defined(_WIN32) || defined(__WIN64__) || defined(WIN64) || defined(_WIN64) diff --git a/Frame/SDK/Interface/AFIModule.h b/Frame/SDK/Interface/AFIModule.h index a49c6ca8..15e98070 100644 --- a/Frame/SDK/Interface/AFIModule.h +++ b/Frame/SDK/Interface/AFIModule.h @@ -46,7 +46,7 @@ class AFIModule return true; } - virtual bool AfterInit() + virtual bool PostInit() { return true; } @@ -56,19 +56,24 @@ class AFIModule return true; } - virtual bool BeforeShut() + virtual bool PreUpdate() { return true; } - virtual bool Shut() + virtual void Update() { - return true; + } - virtual void Update() + virtual bool PreShut() { + return true; + } + virtual bool Shut() + { + return true; } virtual bool StartReLoadState() @@ -99,4 +104,4 @@ class AFIModule protected: AFIPluginManager* pPluginManager; bool mbReloading; -}; +}; \ No newline at end of file diff --git a/Frame/SDK/Interface/AFIPlugin.h b/Frame/SDK/Interface/AFIPlugin.h index 11fcc3ea..c2860ec1 100644 --- a/Frame/SDK/Interface/AFIPlugin.h +++ b/Frame/SDK/Interface/AFIPlugin.h @@ -81,11 +81,11 @@ class AFIPlugin : public AFIModule return true; } - virtual bool AfterInit() + virtual bool PostInit() { for(AFIModule* pModule = mxModules.First(); pModule != nullptr; pModule = mxModules.Next()) { - bool bRet = pModule->AfterInit(); + bool bRet = pModule->PostInit(); ARK_ASSERT_CONTINUE(bRet); } @@ -111,11 +111,11 @@ class AFIPlugin : public AFIModule } } - virtual bool BeforeShut() + virtual bool PreShut() { for(AFIModule* pModule = mxModules.First(); pModule != nullptr; pModule = mxModules.Next()) { - bool bRet = pModule->BeforeShut(); + bool bRet = pModule->PreShut(); ARK_ASSERT_CONTINUE(bRet); } diff --git a/Frame/SDK/Interface/AFIPluginManager.h b/Frame/SDK/Interface/AFIPluginManager.h index ef27f59f..c458e86a 100644 --- a/Frame/SDK/Interface/AFIPluginManager.h +++ b/Frame/SDK/Interface/AFIPluginManager.h @@ -83,4 +83,5 @@ class AFIPluginManager : public AFIModule virtual int64_t GetNowTime() const = 0; virtual const std::string& GetConfigPath() const = 0; virtual void SetConfigName(const std::string& strFileName) = 0; + virtual void SetAppID(const int app_id) = 0; }; \ No newline at end of file diff --git a/Frame/SDK/KernelPlugin/AFCElementModule.cpp b/Frame/SDK/KernelPlugin/AFCElementModule.cpp index 361d1975..27837c33 100644 --- a/Frame/SDK/KernelPlugin/AFCElementModule.cpp +++ b/Frame/SDK/KernelPlugin/AFCElementModule.cpp @@ -378,13 +378,13 @@ bool AFCElementModule::LegalNumber(const char* str) return true; } -bool AFCElementModule::AfterInit() +bool AFCElementModule::PostInit() { return true; } -bool AFCElementModule::BeforeShut() +bool AFCElementModule::PreShut() { return true; diff --git a/Frame/SDK/KernelPlugin/AFCElementModule.h b/Frame/SDK/KernelPlugin/AFCElementModule.h index 84c05fcc..c0a9e738 100644 --- a/Frame/SDK/KernelPlugin/AFCElementModule.h +++ b/Frame/SDK/KernelPlugin/AFCElementModule.h @@ -71,8 +71,8 @@ class AFCElementModule : public AFIElementModule virtual bool Init(); virtual bool Shut(); - virtual bool AfterInit(); - virtual bool BeforeShut(); + virtual bool PostInit(); + virtual bool PreShut(); virtual void Update(); virtual bool Load(); diff --git a/Frame/SDK/KernelPlugin/AFCKernelModule.cpp b/Frame/SDK/KernelPlugin/AFCKernelModule.cpp index cbdd93f3..d134ec76 100644 --- a/Frame/SDK/KernelPlugin/AFCKernelModule.cpp +++ b/Frame/SDK/KernelPlugin/AFCKernelModule.cpp @@ -1261,7 +1261,7 @@ bool AFCKernelModule::LogSelfInfo(const AFGUID& ident) return false; } -bool AFCKernelModule::AfterInit() +bool AFCKernelModule::PostInit() { ARK_SHARE_PTR pClass = m_pClassModule->First(); while(nullptr != pClass) @@ -1296,7 +1296,7 @@ bool AFCKernelModule::DestroyAll() return true; } -bool AFCKernelModule::BeforeShut() +bool AFCKernelModule::PreShut() { return DestroyAll(); } diff --git a/Frame/SDK/KernelPlugin/AFCKernelModule.h b/Frame/SDK/KernelPlugin/AFCKernelModule.h index dcf908f2..37470354 100644 --- a/Frame/SDK/KernelPlugin/AFCKernelModule.h +++ b/Frame/SDK/KernelPlugin/AFCKernelModule.h @@ -44,8 +44,8 @@ class AFCKernelModule virtual bool Init(); virtual bool Shut(); - virtual bool BeforeShut(); - virtual bool AfterInit(); + virtual bool PreShut(); + virtual bool PostInit(); virtual void Update(); diff --git a/Frame/SDK/KernelPlugin/AFCSceneModule.cpp b/Frame/SDK/KernelPlugin/AFCSceneModule.cpp index f81f8975..200c897e 100644 --- a/Frame/SDK/KernelPlugin/AFCSceneModule.cpp +++ b/Frame/SDK/KernelPlugin/AFCSceneModule.cpp @@ -25,12 +25,12 @@ bool AFCSceneModule::Init() return true; } -bool AFCSceneModule::AfterInit() +bool AFCSceneModule::PostInit() { return true; } -bool AFCSceneModule::BeforeShut() +bool AFCSceneModule::PreShut() { return true; } diff --git a/Frame/SDK/KernelPlugin/AFCSceneModule.h b/Frame/SDK/KernelPlugin/AFCSceneModule.h index cb433602..26f72c44 100644 --- a/Frame/SDK/KernelPlugin/AFCSceneModule.h +++ b/Frame/SDK/KernelPlugin/AFCSceneModule.h @@ -38,8 +38,8 @@ class AFCSceneModule } virtual bool Init(); - virtual bool AfterInit(); - virtual bool BeforeShut(); + virtual bool PostInit(); + virtual bool PreShut(); virtual bool Shut(); virtual void Update(); }; \ No newline at end of file diff --git a/Frame/SDK/PluginLoader/AFCPluginManager.cpp b/Frame/SDK/PluginLoader/AFCPluginManager.cpp index 8b98ba20..9d605876 100644 --- a/Frame/SDK/PluginLoader/AFCPluginManager.cpp +++ b/Frame/SDK/PluginLoader/AFCPluginManager.cpp @@ -222,6 +222,11 @@ void AFCPluginManager::SetConfigName(const std::string & strFileName) mstrConfigName = strFileName; } +void AFCPluginManager::SetAppID(const int app_id) +{ + mnAppID = app_id; +} + void AFCPluginManager::AddModule(const std::string& strModuleName, AFIModule* pModule) { ARK_ASSERT_RET_NONE(FindModule(strModuleName) == nullptr); @@ -260,11 +265,11 @@ AFIModule* AFCPluginManager::FindModule(const std::string& strModuleName) return mxModuleInstanceMap.GetElement(strSubModuleName); } -bool AFCPluginManager::AfterInit() +bool AFCPluginManager::PostInit() { for(AFIPlugin* pPlugin = mxPluginInstanceMap.First(); pPlugin != nullptr; pPlugin = mxPluginInstanceMap.Next()) { - pPlugin->AfterInit(); + pPlugin->PostInit(); } return true; @@ -280,11 +285,11 @@ bool AFCPluginManager::CheckConfig() return true; } -bool AFCPluginManager::BeforeShut() +bool AFCPluginManager::PreShut() { for(AFIPlugin* pPlugin = mxPluginInstanceMap.First(); pPlugin != nullptr; pPlugin = mxPluginInstanceMap.Next()) { - pPlugin->BeforeShut(); + pPlugin->PreShut(); } return true; diff --git a/Frame/SDK/PluginLoader/AFCPluginManager.h b/Frame/SDK/PluginLoader/AFCPluginManager.h index 0d9ab26e..363829bb 100644 --- a/Frame/SDK/PluginLoader/AFCPluginManager.h +++ b/Frame/SDK/PluginLoader/AFCPluginManager.h @@ -33,11 +33,11 @@ class AFCPluginManager : public AFIPluginManager, public AFSingleton #if ARK_PLATFORM == PLATFORM_UNIX #include #include #include #include +#include #endif -bool bExitApp = false; -std::thread gThread; -std::string strArgvList; -std::string strPluginName; #if ARK_PLATFORM == PLATFORM_WIN - #include #pragma comment(lib, "DbgHelp") - #if ARK_RUN_MODE == ARK_RUN_MODE_DEBUG #pragma comment(lib, "AFCore_d.lib") #else #pragma comment(lib, "AFCore.lib") #endif + +bool bExitApp = false; +std::thread gBackThread; + // 鍒涘缓Dump鏂囦欢 void CreateDumpFile(const std::string& strDumpFilePathName, EXCEPTION_POINTERS* pException) { @@ -90,35 +88,14 @@ void CloseXButton() #endif } -void ThreadFunc() -{ - while(!bExitApp) - { - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - - std::string s; - std::cin >> s; - if(0 == strcmp(s.c_str(), "exit")) - { - bExitApp = true; - } - } -} - -void CreateBackThread() -{ - gThread = std::thread(std::bind(&ThreadFunc)); - std::cout << "CreateBackThread, thread ID = " << gThread.get_id() << std::endl; -} - void InitDaemon() { #if ARK_PLATFORM == PLATFORM_UNIX daemon(1, 0); // ignore signals - signal(SIGINT, SIG_IGN); - signal(SIGHUP, SIG_IGN); + signal(SIGINT, SIG_IGN); + signal(SIGHUP, SIG_IGN); signal(SIGQUIT, SIG_IGN); signal(SIGPIPE, SIG_IGN); signal(SIGTTOU, SIG_IGN); @@ -127,15 +104,19 @@ void InitDaemon() #endif } -void PrintLogo() +void EchoArkLogo() { #if ARK_PLATFORM == PLATFORM_WIN SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); #endif - std::cout << "********************************************" << std::endl; - std::cout << "ARK" << std::endl; - std::cout << "COPYRIGHT (c) 2013-2018 ARK-GAME" << std::endl; + std::cout << " _ _ ____ _ _ _ " << std::endl; + std::cout << " / \\ _ __| | __ / ___|| |_ _ _ __| (_) ___ " << std::endl; + std::cout << " / _ \\ | '__| |/ / \\___ \\| __| | | |/ _` | |/ _ \\ " << std::endl; + std::cout << " / ___ \\| | | < ___) | |_| |_| | (_| | | (_) |" << std::endl; + std::cout << " /_/ \\_\\_| |_|\\_\\ |____/ \\__|\\__,_|\\__,_|_|\\___/ " << std::endl; + std::cout << std::endl; + std::cout << "COPYRIGHT (c) 2013-2018 Ark Studio" << std::endl; std::cout << "All RIGHTS RESERVED." << std::endl; std::cout << "HTTPS://ARKGAME.NET" << std::endl; std::cout << "********************************************" << std::endl; @@ -145,54 +126,274 @@ void PrintLogo() #endif } -int main(int argc, char* argv[]) +void Usage() { - PrintLogo(); + std::cout << "Ark PluginLoader usage:" << std::endl; + std::cout << "./PluginLoader [options]" << std::endl; + std::cout << "Option:" << std::endl; + std::cout << "\t" << "-d, Run as daemon, just take effect in Linux" << std::endl; + std::cout << "\t" << "-x, Remove close button, just take effect in Windows" << std::endl; + std::cout << "\t" << "cfg=plugin.xml, plugin configuration files" << std::endl; + std::cout << "\t" << "app_id=1, set application's id" << std::endl; + std::cout << "\t" << "app_name=GameServer, set application's name" << std::endl; + std::cout << "i.e. ./PluginLoader -d -x cfg=plugin.xml app_id=1 app_name=my_test" << std::endl; +} - for(int i = 0; i < argc; i++) +void ThreadFunc() +{ + while(!bExitApp) { - strArgvList += " "; - strArgvList += argv[i]; + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + + std::string s; + std::cin >> s; + std::transform(s.begin(), s.end(), s.begin(), ::tolower); + if(s == "exit") + { + bExitApp = true; + } + else if(s == "help") + { + Usage(); + } } +} -#if ARK_PLATFORM == PLATFORM_WIN - SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)ApplicationCrashHandler); - if(strArgvList.find("-x") != string::npos) +void CreateBackThread() +{ + gBackThread = std::thread(std::bind(&ThreadFunc)); + //std::cout << "CreateBackThread, thread ID = " << gThread.get_id() << std::endl; +} + +struct ApplicationConfig +{ + bool deamon = true; //run as deamon, Linux + bool xbutton = true; //close X button in windows + std::string plugin_file = "Plugin.xml"; //config file + int app_id = 0; //app id + std::string app_name = ""; //app name +}; + +#if ARK_PLATFORM == PLATFORM_UNIX +extern char** environ; + +struct environ_guard +{ +public: + ~environ_guard() { - CloseXButton(); + if(env_buf) + { + delete[] env_buf; + env_buf = nullptr; + } + if(environ) + { + delete[] environ; + environ = nullptr; + } } -#elif ARK_PLATFORM == PLATFORM_UNIX - //run it as a daemon process - if(strArgvList.find("-d") != string::npos) + + char* env_buf; + char** environ; +}; + +environ_guard g_new_environ_guard{ nullptr, nullptr }; + +int realloc_environ() +{ + int var_count = 0; + int env_size = 0; { - InitDaemon(); + char** ep = environ; + while(*ep) + { + env_size += std::strlen(*ep) + 1; + ++var_count; + ++ep; + } } - signal(SIGPIPE, SIG_IGN); - signal(SIGCHLD, SIG_IGN); + char* new_env_buf = new char[env_size]; + std::memcpy((void *)new_env_buf, (void *)*environ, env_size); + + char** new_env = new char*[var_count + 1]; + { + int var = 0; + int offset = 0; + char** ep = environ; + while(*ep) + { + new_env[var++] = (new_env_buf + offset); + offset += std::strlen(*ep) + 1; + ++ep; + } + } + new_env[var_count] = 0; + + // RAII to prevent memory leak + g_new_environ_guard = environ_guard{ new_env_buf, new_env }; + + environ = new_env; + + return env_size; +} + +void setproctitle(const char* title, int argc, char** argv) +{ + int argv_size = 0; + for(int i = 0; i < argc; ++i) + { + int len = std::strlen(argv[i]); + std::memset(argv[i], 0, len); + argv_size += len; + } + + int to_be_copied = std::strlen(title); + if(argv_size <= to_be_copied) + { + int env_size = realloc_environ(); + if(env_size < to_be_copied) + { + to_be_copied = env_size; + } + } + + std::strncpy(argv[0], title, to_be_copied); + *(argv[0] + to_be_copied) = 0; +} + #endif - if(strArgvList.find(".xml") != string::npos) +bool ProcArgList(int argc, char* argv[]) +{ + //Echo logo + EchoArkLogo(); + + //Analyse arg list + ApplicationConfig config; + for(int i = 0; i < argc; ++i) { - for(int i = 0; i < argc; i++) + std::string arg = argv[i]; + if(arg == "-d") + { + config.deamon = true; + } + else if(arg == "-x") + { + config.xbutton = true; + } + else if(arg.find("cfg") != std::string::npos) { - strPluginName = argv[i]; - if(strPluginName.find(".xml") != string::npos) + size_t pos = arg.find("="); + if(pos != std::string::npos) { - break; + config.plugin_file = arg.substr(pos + 1, arg.length() - pos - 1); + } + } + else if(arg.find("app_id") != std::string::npos) + { + size_t pos = arg.find("="); + if(pos != std::string::npos) + { + config.app_id = ARK_LEXICAL_CAST(arg.substr(pos + 1, arg.length() - pos - 1)); + } + } + else if(arg.find("app_name") != std::string::npos) + { + size_t pos = arg.find("="); + if(pos != std::string::npos) + { + config.app_name = arg.substr(pos + 1, arg.length() - pos - 1); } } + } - AFCPluginManager::GetInstancePtr()->SetConfigName(strPluginName); + if(config.deamon) + { +#if ARK_PLATFORM == PLATFORM_UNIX + //Run as a daemon process + signal(SIGPIPE, SIG_IGN); + signal(SIGCHLD, SIG_IGN); +#endif } - AFCPluginManager::GetInstancePtr()->Init(); - AFCPluginManager::GetInstancePtr()->AfterInit(); - AFCPluginManager::GetInstancePtr()->CheckConfig(); + if(config.xbutton) + { +#if ARK_PLATFORM == PLATFORM_WIN + SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)ApplicationCrashHandler); + CloseXButton(); +#endif + } + + //鏆傛椂杩樹粠plugin.xml涓幏鍙朼pp id,涓嶅仛寮哄埗瑕佹眰 + //濡傛灉瑕佸仛澶氬紑锛屽垯闇瑕佽嚜宸卞鐞 + //if(config.app_id == 0) + //{ + // std::cout << "parameter app_id is invalid, please check." << std::endl; + // return false; + //} - //back thread, for some cmd + if(config.app_name.empty()) + { + std::cout << "parameter app_name is invalid, please check." << std::endl; + return false; + } + + //Set plugin file + AFCPluginManager::GetInstancePtr()->SetConfigName(config.plugin_file); + AFCPluginManager::GetInstancePtr()->SetAppID(config.app_id); + + std::string process_name = "[" + config.app_name + ":" + ARK_TO_STRING(config.app_id) + "]"; + //Set process name +#if ARK_PLATFORM == PLATFORM_WIN + SetConsoleTitle(process_name.c_str()); +#elif ARK_PLATFORM == PLATFORM_UNIX + setproctitle(process_name, argc, argv); +#endif + + //Create back thread, for some cmd CreateBackThread(); + return true; +} + +void MainLoop() +{ +#if ARK_PLATFORM == PLATFORM_WIN + __try + { + AFCPluginManager::GetInstancePtr()->Update(); + } + __except(ApplicationCrashHandler(GetExceptionInformation())) + { + } +#else + AFCPluginManager::GetInstancePtr()->Update(); +#endif +} + +int main(int argc, char* argv[]) +{ + //arg list + //-d, Run as daemon, just take effect in Linux + //-x, Remove close button, just take effect in Windows + //cfg=plugin.xml, plugin configuration files + //app_id=1, set application's id + //app_name=GameServer, set application's name + if(!ProcArgList(argc, argv)) + { + std::cout << "Application parameter is invalid, please check it..." << std::endl; + Usage(); + + return -1; + } + + AFCPluginManager::GetInstancePtr()->Init(); + AFCPluginManager::GetInstancePtr()->PostInit(); + AFCPluginManager::GetInstancePtr()->CheckConfig(); + AFCPluginManager::GetInstancePtr()->PreUpdate(); + while(!bExitApp) //DEBUG鐗堟湰宕╂簝锛孯ELEASE涓嶅穿 { while(true) @@ -204,27 +405,16 @@ int main(int argc, char* argv[]) break; } -#if ARK_PLATFORM == PLATFORM_WIN - __try - { -#endif - AFCPluginManager::GetInstancePtr()->Update(); -#if ARK_PLATFORM == PLATFORM_WIN - } - __except(ApplicationCrashHandler(GetExceptionInformation())) - { - } -#endif + MainLoop(); } } - AFCPluginManager::GetInstancePtr()->BeforeShut(); + AFCPluginManager::GetInstancePtr()->PreShut(); AFCPluginManager::GetInstancePtr()->Shut(); AFCPluginManager::GetInstancePtr()->ReleaseInstance(); - gThread.join(); + gBackThread.join(); return 0; -} - +} \ No newline at end of file diff --git a/Frame/SDK/UtilityPlugin/AFCGUIDModule.cpp b/Frame/SDK/UtilityPlugin/AFCGUIDModule.cpp index fd67986d..de6f7efb 100644 --- a/Frame/SDK/UtilityPlugin/AFCGUIDModule.cpp +++ b/Frame/SDK/UtilityPlugin/AFCGUIDModule.cpp @@ -141,7 +141,7 @@ bool AFCGUIDModule::Init() return true; } -bool AFCGUIDModule::AfterInit() +bool AFCGUIDModule::PostInit() { return true; } @@ -151,7 +151,7 @@ void AFCGUIDModule::Update() } -bool AFCGUIDModule::BeforeShut() +bool AFCGUIDModule::PreShut() { if(m_pIDWoker != nullptr) { diff --git a/Frame/SDK/UtilityPlugin/AFCGUIDModule.h b/Frame/SDK/UtilityPlugin/AFCGUIDModule.h index 64e36ea4..824e59b3 100644 --- a/Frame/SDK/UtilityPlugin/AFCGUIDModule.h +++ b/Frame/SDK/UtilityPlugin/AFCGUIDModule.h @@ -37,9 +37,9 @@ class AFCGUIDModule virtual ~AFCGUIDModule() {} virtual bool Init(); - virtual bool AfterInit(); + virtual bool PostInit(); virtual void Update(); - virtual bool BeforeShut(); + virtual bool PreShut(); virtual bool Shut(); virtual void SetGUIDMask(uint64_t mask); diff --git a/Frame/SDK/UtilityPlugin/AFCLogModule.cpp b/Frame/SDK/UtilityPlugin/AFCLogModule.cpp index 2338e49d..49ad80f9 100644 --- a/Frame/SDK/UtilityPlugin/AFCLogModule.cpp +++ b/Frame/SDK/UtilityPlugin/AFCLogModule.cpp @@ -99,12 +99,12 @@ bool AFCLogModule::Shut() return true; } -bool AFCLogModule::BeforeShut() +bool AFCLogModule::PreShut() { return true; } -bool AFCLogModule::AfterInit() +bool AFCLogModule::PostInit() { return true; } diff --git a/Frame/SDK/UtilityPlugin/AFCLogModule.h b/Frame/SDK/UtilityPlugin/AFCLogModule.h index 53b745f7..9b5d4bf7 100644 --- a/Frame/SDK/UtilityPlugin/AFCLogModule.h +++ b/Frame/SDK/UtilityPlugin/AFCLogModule.h @@ -33,8 +33,8 @@ class AFCLogModule virtual bool Init(); virtual bool Shut(); - virtual bool BeforeShut(); - virtual bool AfterInit(); + virtual bool PreShut(); + virtual bool PostInit(); virtual void Update(); diff --git a/Frame/SDK/UtilityPlugin/AFCScheduleModule.cpp b/Frame/SDK/UtilityPlugin/AFCScheduleModule.cpp index fb159f2b..6553dc5f 100644 --- a/Frame/SDK/UtilityPlugin/AFCScheduleModule.cpp +++ b/Frame/SDK/UtilityPlugin/AFCScheduleModule.cpp @@ -30,12 +30,12 @@ bool AFCScheduleModule::Init() return true; } -bool AFCScheduleModule::AfterInit() +bool AFCScheduleModule::PostInit() { return true; } -bool AFCScheduleModule::BeforeShut() +bool AFCScheduleModule::PreShut() { return true; } diff --git a/Frame/SDK/UtilityPlugin/AFCScheduleModule.h b/Frame/SDK/UtilityPlugin/AFCScheduleModule.h index cfdc141d..5f9ef5ac 100644 --- a/Frame/SDK/UtilityPlugin/AFCScheduleModule.h +++ b/Frame/SDK/UtilityPlugin/AFCScheduleModule.h @@ -30,9 +30,9 @@ class AFCScheduleModule : public AFIScheduleModule virtual ~AFCScheduleModule() {} virtual bool Init(); - virtual bool AfterInit(); + virtual bool PostInit(); - virtual bool BeforeShut(); + virtual bool PreShut(); virtual bool Shut(); virtual void Update(); diff --git a/Frame/SDK/UtilityPlugin/AFCTimerModule.cpp b/Frame/SDK/UtilityPlugin/AFCTimerModule.cpp index d1b378a6..941f4d3b 100644 --- a/Frame/SDK/UtilityPlugin/AFCTimerModule.cpp +++ b/Frame/SDK/UtilityPlugin/AFCTimerModule.cpp @@ -29,12 +29,12 @@ bool AFCTimerModule::Init() return true; } -bool AFCTimerModule::AfterInit() +bool AFCTimerModule::PostInit() { return true; } -bool AFCTimerModule::BeforeShut() +bool AFCTimerModule::PreShut() { mxTimerManager->Shut(); return true; diff --git a/Frame/SDK/UtilityPlugin/AFCTimerModule.h b/Frame/SDK/UtilityPlugin/AFCTimerModule.h index b8bd8855..f17db4e6 100644 --- a/Frame/SDK/UtilityPlugin/AFCTimerModule.h +++ b/Frame/SDK/UtilityPlugin/AFCTimerModule.h @@ -34,9 +34,9 @@ class AFCTimerModule : public AFITimerModule virtual ~AFCTimerModule() {} virtual bool Init(); - virtual bool AfterInit(); + virtual bool PostInit(); - virtual bool BeforeShut(); + virtual bool PreShut(); virtual bool Shut(); virtual void Update(); diff --git a/Frame/Server/GameServer/GameLogicPlugin/AFCAccountModule.cpp b/Frame/Server/GameServer/GameLogicPlugin/AFCAccountModule.cpp index 89ea8566..1d59b31d 100644 --- a/Frame/Server/GameServer/GameLogicPlugin/AFCAccountModule.cpp +++ b/Frame/Server/GameServer/GameLogicPlugin/AFCAccountModule.cpp @@ -109,7 +109,7 @@ int AFCAccountModule::OnLoadRoleFinalEvent(const AFGUID& object, const int nEven return 0; } -bool AFCAccountModule::AfterInit() +bool AFCAccountModule::PostInit() { //m_pKernelModule->CreateContainer(mnRoleHallContainer, ""); diff --git a/Frame/Server/GameServer/GameLogicPlugin/AFCAccountModule.h b/Frame/Server/GameServer/GameLogicPlugin/AFCAccountModule.h index 1c11be54..87728824 100644 --- a/Frame/Server/GameServer/GameLogicPlugin/AFCAccountModule.h +++ b/Frame/Server/GameServer/GameLogicPlugin/AFCAccountModule.h @@ -40,7 +40,7 @@ class AFCAccountModule : public AFIAccountModule virtual bool Init(); virtual bool Shut(); virtual void Update(const float fLasFrametime, const float fStartedTime); - virtual bool AfterInit(); + virtual bool PostInit(); virtual bool GetRoleList(const std::string& strAccount, AFMsg::AckRoleLiteInfoList& xAckRoleLiteInfoList); virtual bool CreateRole(const std::string& strAccount, AFMsg::AckRoleLiteInfoList& xAckRoleLiteInfoList, const AFIDataList& varList); diff --git a/Frame/Server/GameServer/GameLogicPlugin/AFCGameServerModule.cpp b/Frame/Server/GameServer/GameLogicPlugin/AFCGameServerModule.cpp index d480cf1e..3b09d0ef 100644 --- a/Frame/Server/GameServer/GameLogicPlugin/AFCGameServerModule.cpp +++ b/Frame/Server/GameServer/GameLogicPlugin/AFCGameServerModule.cpp @@ -43,12 +43,12 @@ void AFCGameServerModule::Update() } -bool AFCGameServerModule::AfterInit() +bool AFCGameServerModule::PostInit() { return true; } -bool AFCGameServerModule::BeforeShut() +bool AFCGameServerModule::PreShut() { return true; } \ No newline at end of file diff --git a/Frame/Server/GameServer/GameLogicPlugin/AFCGameServerModule.h b/Frame/Server/GameServer/GameLogicPlugin/AFCGameServerModule.h index 49a3a1ac..08f29b71 100644 --- a/Frame/Server/GameServer/GameLogicPlugin/AFCGameServerModule.h +++ b/Frame/Server/GameServer/GameLogicPlugin/AFCGameServerModule.h @@ -38,8 +38,8 @@ class AFCGameServerModule : public AFIGameServerModule virtual bool Shut(); virtual void Update(); - virtual bool AfterInit(); - virtual bool BeforeShut(); + virtual bool PostInit(); + virtual bool PreShut(); private: AFIGUIDModule* m_pUUIDModule; diff --git a/Frame/Server/GameServer/GameLogicPlugin/AFCLevelModule.cpp b/Frame/Server/GameServer/GameLogicPlugin/AFCLevelModule.cpp index 4f39fe0c..eabd2925 100644 --- a/Frame/Server/GameServer/GameLogicPlugin/AFCLevelModule.cpp +++ b/Frame/Server/GameServer/GameLogicPlugin/AFCLevelModule.cpp @@ -36,7 +36,7 @@ void AFCLevelModule::Update() } -bool AFCLevelModule::AfterInit() +bool AFCLevelModule::PostInit() { m_pKernelModule = pPluginManager->FindModule(); m_pLogModule = pPluginManager->FindModule(); diff --git a/Frame/Server/GameServer/GameLogicPlugin/AFCLevelModule.h b/Frame/Server/GameServer/GameLogicPlugin/AFCLevelModule.h index a3812490..f64388b1 100644 --- a/Frame/Server/GameServer/GameLogicPlugin/AFCLevelModule.h +++ b/Frame/Server/GameServer/GameLogicPlugin/AFCLevelModule.h @@ -41,7 +41,7 @@ class AFCLevelModule : public AFILevelModule virtual bool Init(); virtual bool Shut(); virtual void Update(); - virtual bool AfterInit(); + virtual bool PostInit(); virtual int AddExp(const AFGUID& self, const int nExp); diff --git a/Frame/Server/GameServer/GameLogicPlugin/AFCPropertyConfigModule.cpp b/Frame/Server/GameServer/GameLogicPlugin/AFCPropertyConfigModule.cpp index 0a57bf7a..75d6234d 100644 --- a/Frame/Server/GameServer/GameLogicPlugin/AFCPropertyConfigModule.cpp +++ b/Frame/Server/GameServer/GameLogicPlugin/AFCPropertyConfigModule.cpp @@ -36,7 +36,7 @@ void AFCPropertyConfigModule::Update() } -bool AFCPropertyConfigModule::AfterInit() +bool AFCPropertyConfigModule::PostInit() { m_pClassModule = pPluginManager->FindModule(); m_pElementModule = pPluginManager->FindModule(); diff --git a/Frame/Server/GameServer/GameLogicPlugin/AFCPropertyConfigModule.h b/Frame/Server/GameServer/GameLogicPlugin/AFCPropertyConfigModule.h index 23cb69fe..c6e5514b 100644 --- a/Frame/Server/GameServer/GameLogicPlugin/AFCPropertyConfigModule.h +++ b/Frame/Server/GameServer/GameLogicPlugin/AFCPropertyConfigModule.h @@ -42,7 +42,7 @@ class AFCPropertyConfigModule virtual bool Init(); virtual bool Shut(); virtual void Update(); - virtual bool AfterInit(); + virtual bool PostInit(); virtual int CalculateBaseValue(const int nJob, const int nLevel, const std::string& strProperty); virtual bool LegalLevel(const int nJob, const int nLevel); diff --git a/Frame/Server/GameServer/GameLogicPlugin/AFCPropertyModule.cpp b/Frame/Server/GameServer/GameLogicPlugin/AFCPropertyModule.cpp index d1d5a0b4..b1084943 100644 --- a/Frame/Server/GameServer/GameLogicPlugin/AFCPropertyModule.cpp +++ b/Frame/Server/GameServer/GameLogicPlugin/AFCPropertyModule.cpp @@ -36,7 +36,7 @@ void AFCPropertyModule::Update() } -bool AFCPropertyModule::AfterInit() +bool AFCPropertyModule::PostInit() { m_pKernelModule = pPluginManager->FindModule(); m_pElementModule = pPluginManager->FindModule(); diff --git a/Frame/Server/GameServer/GameLogicPlugin/AFCPropertyModule.h b/Frame/Server/GameServer/GameLogicPlugin/AFCPropertyModule.h index 9b3f932b..0cab8297 100644 --- a/Frame/Server/GameServer/GameLogicPlugin/AFCPropertyModule.h +++ b/Frame/Server/GameServer/GameLogicPlugin/AFCPropertyModule.h @@ -42,7 +42,7 @@ class AFCPropertyModule : public AFIPropertyModule virtual bool Init(); virtual bool Shut(); virtual void Update(); - virtual bool AfterInit(); + virtual bool PostInit(); virtual int RefreshBaseProperty(const AFGUID& self); diff --git a/Frame/Server/GameServer/GameLogicPlugin/AFCPropertyTrailModule.cpp b/Frame/Server/GameServer/GameLogicPlugin/AFCPropertyTrailModule.cpp index c1a19a2f..77ccf551 100644 --- a/Frame/Server/GameServer/GameLogicPlugin/AFCPropertyTrailModule.cpp +++ b/Frame/Server/GameServer/GameLogicPlugin/AFCPropertyTrailModule.cpp @@ -37,7 +37,7 @@ void AFCPropertyTrailModule::Update() } -bool AFCPropertyTrailModule::AfterInit() +bool AFCPropertyTrailModule::PostInit() { m_pKernelModule = pPluginManager->FindModule(); m_pElementModule = pPluginManager->FindModule(); diff --git a/Frame/Server/GameServer/GameLogicPlugin/AFCPropertyTrailModule.h b/Frame/Server/GameServer/GameLogicPlugin/AFCPropertyTrailModule.h index 1bebe971..294c460d 100644 --- a/Frame/Server/GameServer/GameLogicPlugin/AFCPropertyTrailModule.h +++ b/Frame/Server/GameServer/GameLogicPlugin/AFCPropertyTrailModule.h @@ -42,7 +42,7 @@ class AFCPropertyTrailModule : public AFIPropertyTrailModule virtual bool Init(); virtual bool Shut(); virtual void Update(); - virtual bool AfterInit(); + virtual bool PostInit(); virtual void StartTrail(const AFGUID self); virtual void EndTrail(const AFGUID self); diff --git a/Frame/Server/GameServer/GameLogicPlugin/AFCSceneProcessModule.cpp b/Frame/Server/GameServer/GameLogicPlugin/AFCSceneProcessModule.cpp index ad1542ca..b9cbef03 100644 --- a/Frame/Server/GameServer/GameLogicPlugin/AFCSceneProcessModule.cpp +++ b/Frame/Server/GameServer/GameLogicPlugin/AFCSceneProcessModule.cpp @@ -38,7 +38,7 @@ void AFCSceneProcessModule::Update() } -bool AFCSceneProcessModule::AfterInit() +bool AFCSceneProcessModule::PostInit() { m_pKernelModule = pPluginManager->FindModule(); m_pElementModule = pPluginManager->FindModule(); diff --git a/Frame/Server/GameServer/GameLogicPlugin/AFCSceneProcessModule.h b/Frame/Server/GameServer/GameLogicPlugin/AFCSceneProcessModule.h index 0c2d0444..87d8620a 100644 --- a/Frame/Server/GameServer/GameLogicPlugin/AFCSceneProcessModule.h +++ b/Frame/Server/GameServer/GameLogicPlugin/AFCSceneProcessModule.h @@ -49,7 +49,7 @@ class AFCSceneProcessModule : public AFISceneProcessModule virtual bool Init(); virtual bool Shut(); virtual void Update(); - virtual bool AfterInit(); + virtual bool PostInit(); virtual E_SCENE_TYPE GetCloneSceneType(const int nSceneID); virtual bool IsCloneScene(const int nSceneID); diff --git a/Frame/Server/GameServer/GameNetClientPlugin/AFCGameServerToWorldModule.cpp b/Frame/Server/GameServer/GameNetClientPlugin/AFCGameServerToWorldModule.cpp index a4890ba5..16bce503 100644 --- a/Frame/Server/GameServer/GameNetClientPlugin/AFCGameServerToWorldModule.cpp +++ b/Frame/Server/GameServer/GameNetClientPlugin/AFCGameServerToWorldModule.cpp @@ -110,7 +110,7 @@ void AFCGameServerToWorldModule::RefreshWorldInfo() // } } -bool AFCGameServerToWorldModule::AfterInit() +bool AFCGameServerToWorldModule::PostInit() { m_pKernelModule = pPluginManager->FindModule(); m_pClassModule = pPluginManager->FindModule(); diff --git a/Frame/Server/GameServer/GameNetClientPlugin/AFCGameServerToWorldModule.h b/Frame/Server/GameServer/GameNetClientPlugin/AFCGameServerToWorldModule.h index 794e894f..7f6c1c03 100644 --- a/Frame/Server/GameServer/GameNetClientPlugin/AFCGameServerToWorldModule.h +++ b/Frame/Server/GameServer/GameNetClientPlugin/AFCGameServerToWorldModule.h @@ -41,7 +41,7 @@ class AFCGameServerToWorldModule : public AFIGameServerToWorldModule virtual bool Init(); virtual bool Shut(); virtual void Update(); - virtual bool AfterInit(); + virtual bool PostInit(); virtual void SendBySuit(const int& nHashKey, const int nMsgID, const char* msg, const uint32_t nLen); virtual AFINetClientModule* GetClusterClientModule(); diff --git a/Frame/Server/GameServer/GameNetServerPlugin/AFCGameNetServerModule.cpp b/Frame/Server/GameServer/GameNetServerPlugin/AFCGameNetServerModule.cpp index d51db189..1bcbb5d2 100644 --- a/Frame/Server/GameServer/GameNetServerPlugin/AFCGameNetServerModule.cpp +++ b/Frame/Server/GameServer/GameNetServerPlugin/AFCGameNetServerModule.cpp @@ -30,7 +30,7 @@ bool AFCGameNetServerModule::Init() return true; } -bool AFCGameNetServerModule::AfterInit() +bool AFCGameNetServerModule::PostInit() { m_pKernelModule = pPluginManager->FindModule(); m_pClassModule = pPluginManager->FindModule(); diff --git a/Frame/Server/GameServer/GameNetServerPlugin/AFCGameNetServerModule.h b/Frame/Server/GameServer/GameNetServerPlugin/AFCGameNetServerModule.h index 328ee048..62a16b66 100644 --- a/Frame/Server/GameServer/GameNetServerPlugin/AFCGameNetServerModule.h +++ b/Frame/Server/GameServer/GameNetServerPlugin/AFCGameNetServerModule.h @@ -47,7 +47,7 @@ class AFCGameNetServerModule virtual bool Shut(); virtual void Update(); - virtual bool AfterInit(); + virtual bool PostInit(); virtual void LogReceive(const char* str) {} virtual void LogSend(const char* str) {} diff --git a/Frame/Server/LoginServer/LoginLogicPlugin/AFCLoginLogicModule.cpp b/Frame/Server/LoginServer/LoginLogicPlugin/AFCLoginLogicModule.cpp index 8b67429c..009601a2 100644 --- a/Frame/Server/LoginServer/LoginLogicPlugin/AFCLoginLogicModule.cpp +++ b/Frame/Server/LoginServer/LoginLogicPlugin/AFCLoginLogicModule.cpp @@ -41,7 +41,7 @@ void AFCLoginLogicModule::Update() } -bool AFCLoginLogicModule::AfterInit() +bool AFCLoginLogicModule::PostInit() { m_pLoginNet_ServerModule = pPluginManager->FindModule(); diff --git a/Frame/Server/LoginServer/LoginLogicPlugin/AFCLoginLogicModule.h b/Frame/Server/LoginServer/LoginLogicPlugin/AFCLoginLogicModule.h index ac92ebd9..b7a82f57 100644 --- a/Frame/Server/LoginServer/LoginLogicPlugin/AFCLoginLogicModule.h +++ b/Frame/Server/LoginServer/LoginLogicPlugin/AFCLoginLogicModule.h @@ -37,7 +37,7 @@ class AFCLoginLogicModule virtual bool Shut(); virtual void Update(); - virtual bool AfterInit(); + virtual bool PostInit(); virtual int OnLoginProcess(const AFGUID& object, const std::string& strAccount, const std::string& strPwd); diff --git a/Frame/Server/LoginServer/LoginNetClientPlugin/AFCLoginToMasterModule.cpp b/Frame/Server/LoginServer/LoginNetClientPlugin/AFCLoginToMasterModule.cpp index dcf572ce..68ac17bd 100644 --- a/Frame/Server/LoginServer/LoginNetClientPlugin/AFCLoginToMasterModule.cpp +++ b/Frame/Server/LoginServer/LoginNetClientPlugin/AFCLoginToMasterModule.cpp @@ -36,7 +36,7 @@ bool AFCLoginToMasterModule::Shut() return true; } -bool AFCLoginToMasterModule::AfterInit() +bool AFCLoginToMasterModule::PostInit() { m_pKernelModule = pPluginManager->FindModule(); m_pLoginLogicModule = pPluginManager->FindModule(); @@ -83,7 +83,7 @@ bool AFCLoginToMasterModule::AfterInit() return true; } -bool AFCLoginToMasterModule::BeforeShut() +bool AFCLoginToMasterModule::PreShut() { return false; diff --git a/Frame/Server/LoginServer/LoginNetClientPlugin/AFCLoginToMasterModule.h b/Frame/Server/LoginServer/LoginNetClientPlugin/AFCLoginToMasterModule.h index 4c5405c7..ce2ce536 100644 --- a/Frame/Server/LoginServer/LoginNetClientPlugin/AFCLoginToMasterModule.h +++ b/Frame/Server/LoginServer/LoginNetClientPlugin/AFCLoginToMasterModule.h @@ -43,8 +43,8 @@ class AFCLoginToMasterModule virtual bool Shut(); virtual void Update(); - virtual bool AfterInit(); - virtual bool BeforeShut(); + virtual bool PostInit(); + virtual bool PreShut(); virtual void LogReceive(const char* str) {} virtual void LogSend(const char* str) {} diff --git a/Frame/Server/LoginServer/LoginNetServerPlugin/AFCLoginNetServerModule.cpp b/Frame/Server/LoginServer/LoginNetServerPlugin/AFCLoginNetServerModule.cpp index aef26df4..e8795064 100644 --- a/Frame/Server/LoginServer/LoginNetServerPlugin/AFCLoginNetServerModule.cpp +++ b/Frame/Server/LoginServer/LoginNetServerPlugin/AFCLoginNetServerModule.cpp @@ -35,12 +35,12 @@ bool AFCLoginNetServerModule::Shut() return true; } -bool AFCLoginNetServerModule::BeforeShut() +bool AFCLoginNetServerModule::PreShut() { return true; } -bool AFCLoginNetServerModule::AfterInit() +bool AFCLoginNetServerModule::PostInit() { m_pKernelModule = pPluginManager->FindModule(); m_pLoginLogicModule = pPluginManager->FindModule(); diff --git a/Frame/Server/LoginServer/LoginNetServerPlugin/AFCLoginNetServerModule.h b/Frame/Server/LoginServer/LoginNetServerPlugin/AFCLoginNetServerModule.h index a0c202d9..e8383dae 100644 --- a/Frame/Server/LoginServer/LoginNetServerPlugin/AFCLoginNetServerModule.h +++ b/Frame/Server/LoginServer/LoginNetServerPlugin/AFCLoginNetServerModule.h @@ -45,8 +45,8 @@ class AFCLoginNetServerModule virtual void Update(); - virtual bool BeforeShut(); - virtual bool AfterInit(); + virtual bool PreShut(); + virtual bool PostInit(); virtual void LogReceive(const char* str) {} virtual void LogSend(const char* str) {} diff --git a/Frame/Server/MasterServer/MasterNetServerPlugin/AFCMasterNetServerModule.cpp b/Frame/Server/MasterServer/MasterNetServerPlugin/AFCMasterNetServerModule.cpp index 9fcccdbf..93723233 100644 --- a/Frame/Server/MasterServer/MasterNetServerPlugin/AFCMasterNetServerModule.cpp +++ b/Frame/Server/MasterServer/MasterNetServerPlugin/AFCMasterNetServerModule.cpp @@ -229,7 +229,7 @@ void AFCMasterNetServerModule::OnSelectServerResultProcess(const AFIMsgHead& xHe m_pNetModule->SendMsgPB(AFMsg::EGameMsgID::EGMI_ACK_CONNECT_WORLD, xMsg, pServerData->xClient, nPlayerID); } -bool AFCMasterNetServerModule::AfterInit() +bool AFCMasterNetServerModule::PostInit() { m_pKernelModule = pPluginManager->FindModule(); m_pLogModule = pPluginManager->FindModule(); diff --git a/Frame/Server/MasterServer/MasterNetServerPlugin/AFCMasterNetServerModule.h b/Frame/Server/MasterServer/MasterNetServerPlugin/AFCMasterNetServerModule.h index 4198a7e1..9a6ac078 100644 --- a/Frame/Server/MasterServer/MasterNetServerPlugin/AFCMasterNetServerModule.h +++ b/Frame/Server/MasterServer/MasterNetServerPlugin/AFCMasterNetServerModule.h @@ -45,7 +45,7 @@ class AFCMasterNetServerModule : public AFIMasterNetServerModule virtual bool Init(); virtual bool Shut(); - virtual bool AfterInit(); + virtual bool PostInit(); virtual void Update(); virtual void LogReceive(const char* str) {} diff --git a/Frame/Server/ProxyServer/ProxyLogicPlugin/AFCProxyLogicModule.cpp b/Frame/Server/ProxyServer/ProxyLogicPlugin/AFCProxyLogicModule.cpp index 4a90638d..f14664b3 100644 --- a/Frame/Server/ProxyServer/ProxyLogicPlugin/AFCProxyLogicModule.cpp +++ b/Frame/Server/ProxyServer/ProxyLogicPlugin/AFCProxyLogicModule.cpp @@ -36,7 +36,7 @@ void AFCProxyLogicModule::Update() } -bool AFCProxyLogicModule::AfterInit() +bool AFCProxyLogicModule::PostInit() { m_pKernelModule = pPluginManager->FindModule(); m_pClassModule = pPluginManager->FindModule(); diff --git a/Frame/Server/ProxyServer/ProxyLogicPlugin/AFCProxyLogicModule.h b/Frame/Server/ProxyServer/ProxyLogicPlugin/AFCProxyLogicModule.h index 5b30467f..fe738d52 100644 --- a/Frame/Server/ProxyServer/ProxyLogicPlugin/AFCProxyLogicModule.h +++ b/Frame/Server/ProxyServer/ProxyLogicPlugin/AFCProxyLogicModule.h @@ -38,7 +38,7 @@ class AFCProxyLogicModule virtual bool Shut(); virtual void Update(); - virtual bool AfterInit(); + virtual bool PostInit(); private: AFIClassModule* m_pClassModule; diff --git a/Frame/Server/ProxyServer/ProxyNetClientPlugin/AFCProxyServerToGameModule.cpp b/Frame/Server/ProxyServer/ProxyNetClientPlugin/AFCProxyServerToGameModule.cpp index 776887a4..0f22ffe9 100644 --- a/Frame/Server/ProxyServer/ProxyNetClientPlugin/AFCProxyServerToGameModule.cpp +++ b/Frame/Server/ProxyServer/ProxyNetClientPlugin/AFCProxyServerToGameModule.cpp @@ -45,7 +45,7 @@ void AFCProxyServerToGameModule::Update() m_pNetClientModule->Update(); } -bool AFCProxyServerToGameModule::AfterInit() +bool AFCProxyServerToGameModule::PostInit() { m_pProxyLogicModule = pPluginManager->FindModule(); m_pKernelModule = pPluginManager->FindModule(); diff --git a/Frame/Server/ProxyServer/ProxyNetClientPlugin/AFCProxyServerToGameModule.h b/Frame/Server/ProxyServer/ProxyNetClientPlugin/AFCProxyServerToGameModule.h index 2c23ffde..12e1af7b 100644 --- a/Frame/Server/ProxyServer/ProxyNetClientPlugin/AFCProxyServerToGameModule.h +++ b/Frame/Server/ProxyServer/ProxyNetClientPlugin/AFCProxyServerToGameModule.h @@ -46,7 +46,7 @@ class AFCProxyServerToGameModule : public AFIProxyServerToGameModule virtual bool Shut(); virtual void Update(); - virtual bool AfterInit(); + virtual bool PostInit(); virtual AFINetClientModule* GetClusterModule(); protected: diff --git a/Frame/Server/ProxyServer/ProxyNetClientPlugin/AFCProxyServerToWorldModule.cpp b/Frame/Server/ProxyServer/ProxyNetClientPlugin/AFCProxyServerToWorldModule.cpp index d44289e3..d6be1530 100644 --- a/Frame/Server/ProxyServer/ProxyNetClientPlugin/AFCProxyServerToWorldModule.cpp +++ b/Frame/Server/ProxyServer/ProxyNetClientPlugin/AFCProxyServerToWorldModule.cpp @@ -144,7 +144,7 @@ void AFCProxyServerToWorldModule::Register(const int nServerID) } } -bool AFCProxyServerToWorldModule::AfterInit() +bool AFCProxyServerToWorldModule::PostInit() { m_pProxyLogicModule = pPluginManager->FindModule(); m_pKernelModule = pPluginManager->FindModule(); diff --git a/Frame/Server/ProxyServer/ProxyNetClientPlugin/AFCProxyServerToWorldModule.h b/Frame/Server/ProxyServer/ProxyNetClientPlugin/AFCProxyServerToWorldModule.h index ffdb89bf..4368a968 100644 --- a/Frame/Server/ProxyServer/ProxyNetClientPlugin/AFCProxyServerToWorldModule.h +++ b/Frame/Server/ProxyServer/ProxyNetClientPlugin/AFCProxyServerToWorldModule.h @@ -47,7 +47,7 @@ class AFCProxyServerToWorldModule : public AFIProxyServerToWorldModule virtual bool Shut(); virtual void Update(); - virtual bool AfterInit(); + virtual bool PostInit(); virtual void LogReceive(const char* str) {} virtual void LogSend(const char* str) {} diff --git a/Frame/Server/ProxyServer/ProxyNetServerPlugin/AFCProxyNetServerModule.cpp b/Frame/Server/ProxyServer/ProxyNetServerPlugin/AFCProxyNetServerModule.cpp index e144632d..e5089376 100644 --- a/Frame/Server/ProxyServer/ProxyNetServerPlugin/AFCProxyNetServerModule.cpp +++ b/Frame/Server/ProxyServer/ProxyNetServerPlugin/AFCProxyNetServerModule.cpp @@ -28,7 +28,7 @@ bool AFCProxyNetServerModule::Init() return true; } -bool AFCProxyNetServerModule::AfterInit() +bool AFCProxyNetServerModule::PostInit() { m_pKernelModule = pPluginManager->FindModule(); m_pClassModule = pPluginManager->FindModule(); diff --git a/Frame/Server/ProxyServer/ProxyNetServerPlugin/AFCProxyNetServerModule.h b/Frame/Server/ProxyServer/ProxyNetServerPlugin/AFCProxyNetServerModule.h index 8f24df22..4f6d0434 100644 --- a/Frame/Server/ProxyServer/ProxyNetServerPlugin/AFCProxyNetServerModule.h +++ b/Frame/Server/ProxyServer/ProxyNetServerPlugin/AFCProxyNetServerModule.h @@ -45,7 +45,7 @@ class AFCProxyNetServerModule : public AFIProxyNetServerModule virtual bool Shut(); virtual void Update(); - virtual bool AfterInit(); + virtual bool PostInit(); virtual int Transpond(const AFIMsgHead& xHead, const int nMsgID, const char* msg, const uint32_t nLen); virtual int SendToPlayerClient(const int nMsgID, const char* msg, const uint32_t nLen, const AFGUID& nClientID, const AFGUID& nPlayer); diff --git a/Frame/Server/WorldServer/WorldLogicPlugin/AFCWorldLogicModule.cpp b/Frame/Server/WorldServer/WorldLogicPlugin/AFCWorldLogicModule.cpp index aa7d5bc0..8e15d5a2 100644 --- a/Frame/Server/WorldServer/WorldLogicPlugin/AFCWorldLogicModule.cpp +++ b/Frame/Server/WorldServer/WorldLogicPlugin/AFCWorldLogicModule.cpp @@ -37,7 +37,7 @@ void AFCWorldLogicModule::Update() } -bool AFCWorldLogicModule::AfterInit() +bool AFCWorldLogicModule::PostInit() { m_pKernelModule = pPluginManager->FindModule(); diff --git a/Frame/Server/WorldServer/WorldLogicPlugin/AFCWorldLogicModule.h b/Frame/Server/WorldServer/WorldLogicPlugin/AFCWorldLogicModule.h index 8b589f61..31451af8 100644 --- a/Frame/Server/WorldServer/WorldLogicPlugin/AFCWorldLogicModule.h +++ b/Frame/Server/WorldServer/WorldLogicPlugin/AFCWorldLogicModule.h @@ -36,7 +36,7 @@ class AFCWorldLogicModule virtual bool Shut(); virtual void Update(); - virtual bool AfterInit(); + virtual bool PostInit(); protected: diff --git a/Frame/Server/WorldServer/WorldNetClientPlugin/AFCWorldToMasterModule.cpp b/Frame/Server/WorldServer/WorldNetClientPlugin/AFCWorldToMasterModule.cpp index cef79980..a6163d1b 100644 --- a/Frame/Server/WorldServer/WorldNetClientPlugin/AFCWorldToMasterModule.cpp +++ b/Frame/Server/WorldServer/WorldNetClientPlugin/AFCWorldToMasterModule.cpp @@ -38,7 +38,7 @@ bool AFCWorldToMasterModule::Shut() return true; } -bool AFCWorldToMasterModule::AfterInit() +bool AFCWorldToMasterModule::PostInit() { m_pWorldLogicModule = pPluginManager->FindModule(); m_pClassModule = pPluginManager->FindModule(); @@ -213,7 +213,7 @@ void AFCWorldToMasterModule::OnClientConnected(const AFGUID& xClientID) } -bool AFCWorldToMasterModule::BeforeShut() +bool AFCWorldToMasterModule::PreShut() { return true; } diff --git a/Frame/Server/WorldServer/WorldNetClientPlugin/AFCWorldToMasterModule.h b/Frame/Server/WorldServer/WorldNetClientPlugin/AFCWorldToMasterModule.h index e5faca56..6309da73 100644 --- a/Frame/Server/WorldServer/WorldNetClientPlugin/AFCWorldToMasterModule.h +++ b/Frame/Server/WorldServer/WorldNetClientPlugin/AFCWorldToMasterModule.h @@ -40,10 +40,10 @@ class AFCWorldToMasterModule } virtual bool Init(); - virtual bool BeforeShut(); + virtual bool PreShut(); virtual bool Shut(); virtual void Update(); - virtual bool AfterInit(); + virtual bool PostInit(); protected: diff --git a/Frame/Server/WorldServer/WorldNetServerPlugin/AFCWorldNetServerModule.cpp b/Frame/Server/WorldServer/WorldNetServerPlugin/AFCWorldNetServerModule.cpp index dbf81c6f..e957d7cd 100644 --- a/Frame/Server/WorldServer/WorldNetServerPlugin/AFCWorldNetServerModule.cpp +++ b/Frame/Server/WorldServer/WorldNetServerPlugin/AFCWorldNetServerModule.cpp @@ -31,7 +31,7 @@ bool AFCWorldNetServerModule::Init() return true; } -bool AFCWorldNetServerModule::AfterInit() +bool AFCWorldNetServerModule::PostInit() { m_pKernelModule = pPluginManager->FindModule(); m_pWorldLogicModule = pPluginManager->FindModule(); diff --git a/Frame/Server/WorldServer/WorldNetServerPlugin/AFCWorldNetServerModule.h b/Frame/Server/WorldServer/WorldNetServerPlugin/AFCWorldNetServerModule.h index f5378b14..8dc29503 100644 --- a/Frame/Server/WorldServer/WorldNetServerPlugin/AFCWorldNetServerModule.h +++ b/Frame/Server/WorldServer/WorldNetServerPlugin/AFCWorldNetServerModule.h @@ -51,7 +51,7 @@ class AFCWorldNetServerModule virtual bool Shut(); virtual void Update(); - virtual bool AfterInit(); + virtual bool PostInit(); virtual void LogReceive(const char* str) {} virtual void LogSend(const char* str) {} From 7940cdf335844b358e90640d3bb3f4644fba056b Mon Sep 17 00:00:00 2001 From: NickYang <362148418@qq.com> Date: Fri, 30 Mar 2018 16:59:16 +0800 Subject: [PATCH 17/24] Remove parameter check of app_name Former-commit-id: 6aa74d704506076e2eafbe9496468fb1d0479904 Former-commit-id: 8e04e6b1a96221d98516f1479ec1a8af51a62d67 --- Frame/SDK/PluginLoader/AFPluginLoader.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Frame/SDK/PluginLoader/AFPluginLoader.cpp b/Frame/SDK/PluginLoader/AFPluginLoader.cpp index a174e09d..57aed2b6 100644 --- a/Frame/SDK/PluginLoader/AFPluginLoader.cpp +++ b/Frame/SDK/PluginLoader/AFPluginLoader.cpp @@ -333,12 +333,12 @@ bool ProcArgList(int argc, char* argv[]) // std::cout << "parameter app_id is invalid, please check." << std::endl; // return false; //} - - if(config.app_name.empty()) - { - std::cout << "parameter app_name is invalid, please check." << std::endl; - return false; - } + //鏆傛椂app name涔熷彲浠ヤ笉鐢ㄤ紶鍙 + //if(config.app_name.empty()) + //{ + // std::cout << "parameter app_name is invalid, please check." << std::endl; + // return false; + //} //Set plugin file AFCPluginManager::GetInstancePtr()->SetConfigName(config.plugin_file); From c14e99cd79784723015857e9939342ff44add6d9 Mon Sep 17 00:00:00 2001 From: NickYang <362148418@qq.com> Date: Fri, 30 Mar 2018 17:07:10 +0800 Subject: [PATCH 18/24] fix wrong code moving Former-commit-id: 55eabf2e02c7c4a97b73c2e9f309b35f1d3a7fdd Former-commit-id: e22e9cfa1282df7d44377b3df9d279b27abaef53 --- Frame/SDK/PluginLoader/AFPluginLoader.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Frame/SDK/PluginLoader/AFPluginLoader.cpp b/Frame/SDK/PluginLoader/AFPluginLoader.cpp index 57aed2b6..9da1cfd3 100644 --- a/Frame/SDK/PluginLoader/AFPluginLoader.cpp +++ b/Frame/SDK/PluginLoader/AFPluginLoader.cpp @@ -29,6 +29,8 @@ #include #endif +bool bExitApp = false; +std::thread gBackThread; #if ARK_PLATFORM == PLATFORM_WIN #include @@ -39,9 +41,6 @@ #pragma comment(lib, "AFCore.lib") #endif -bool bExitApp = false; -std::thread gBackThread; - // 鍒涘缓Dump鏂囦欢 void CreateDumpFile(const std::string& strDumpFilePathName, EXCEPTION_POINTERS* pException) { From 694fee8d97b461122d4326bdac0a73b28e9282cf Mon Sep 17 00:00:00 2001 From: NickYang <362148418@qq.com> Date: Fri, 30 Mar 2018 17:14:34 +0800 Subject: [PATCH 19/24] fix error arg Former-commit-id: 65d7befd8dc217df07d456d62b96c80d0bac352b Former-commit-id: bd1079189b86175b343bc300c2f3ed1d54095bf9 --- Frame/SDK/PluginLoader/AFPluginLoader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Frame/SDK/PluginLoader/AFPluginLoader.cpp b/Frame/SDK/PluginLoader/AFPluginLoader.cpp index 9da1cfd3..d12492d1 100644 --- a/Frame/SDK/PluginLoader/AFPluginLoader.cpp +++ b/Frame/SDK/PluginLoader/AFPluginLoader.cpp @@ -348,7 +348,7 @@ bool ProcArgList(int argc, char* argv[]) #if ARK_PLATFORM == PLATFORM_WIN SetConsoleTitle(process_name.c_str()); #elif ARK_PLATFORM == PLATFORM_UNIX - setproctitle(process_name, argc, argv); + setproctitle(process_name.c_str(), argc, argv); #endif //Create back thread, for some cmd From 928d7b8f3532451ee8e7373e3375254460a43dbd Mon Sep 17 00:00:00 2001 From: NickYang <362148418@qq.com> Date: Fri, 30 Mar 2018 17:58:51 +0800 Subject: [PATCH 20/24] Forced to use app_id app_name cfg parameters Former-commit-id: c1c19e492175b7bdabecc9fdd144afb4c2ed8348 Former-commit-id: ca2798c5a4d202e8a30389367a5214195fdddedf --- Bin/Server/Debug/killd.sh | 12 +-- Bin/Server/Debug/run.bat | 19 ++--- Bin/Server/Debug/rund.sh | 97 ++++++++++++++--------- Bin/Server/Release/killr.sh | 12 +-- Bin/Server/Release/run.bat | 22 ++--- Bin/Server/Release/runr.sh | 87 ++++++++++++-------- Frame/SDK/PluginLoader/AFPluginLoader.cpp | 25 +++--- 7 files changed, 151 insertions(+), 123 deletions(-) diff --git a/Bin/Server/Debug/killd.sh b/Bin/Server/Debug/killd.sh index 8e5650ba..15210cf0 100644 --- a/Bin/Server/Debug/killd.sh +++ b/Bin/Server/Debug/killd.sh @@ -1,7 +1,7 @@ -kill -9 $(pidof NFMasterServer_d) -kill -9 $(pidof NFWorldServer_d) -kill -9 $(pidof NFLoginServer_d) -kill -9 $(pidof NFGameServer_d) -kill -9 $(pidof NFProxyServer_d) +kill -9 $(pidof MasterServer) +kill -9 $(pidof WorldServer) +kill -9 $(pidof LoginServer) +kill -9 $(pidof GameServer) +kill -9 $(pidof ProxyServer) -ps -A|grep NF +ps ax | grep *Server \ No newline at end of file diff --git a/Bin/Server/Debug/run.bat b/Bin/Server/Debug/run.bat index 09796200..07223be6 100644 --- a/Bin/Server/Debug/run.bat +++ b/Bin/Server/Debug/run.bat @@ -41,38 +41,35 @@ copy ..\\..\\..\\Bin\\Comm\\Debug\\AFWorld*d.dll AFWorldServer\\ /Y copy ..\\..\\..\\Bin\\Comm\\Debug\\AFGame*d.dll AFGameServer\\ /Y cd AFMasterServer - echo Starting AFMasterServer... -start "" "PluginLoader_d.exe" - +start "" "PluginLoader_d.exe -x app_id=3 app_name=MasterServer cfg=Plugin.xml" choice /t 2 /d y /n >nul + cd .. cd AFWorldServer echo Starting AFWorldServer... -start "" "PluginLoader_d.exe" - - +start "" "PluginLoader_d.exe -x app_id=7 app_name=WorldServer cfg=Plugin.xml" choice /t 5 /d y /n >nul cd .. cd AFLoginServer echo Starting AFLoginServer... -start "" "PluginLoader_d.exe" - +start "" "PluginLoader_d.exe -x app_id=4 app_name=LoginServer cfg=Plugin.xml" choice /t 2 /d y /n >nul cd .. cd AFGameServer echo Starting AFGameServer... -start "" "PluginLoader_d.exe" - +start "" "PluginLoader_d.exe -x app_id=6 app_name=GameServer cfg=Plugin.xml" choice /t 4 /d y /n >nul cd .. cd AFProxyServer echo Starting AFProxyServer... -start "" "PluginLoader_d.exe" +start "" "PluginLoader_d.exe -x app_id=5 app_name=ProxyServer cfg=Plugin.xml" + +echo All processes are launching... diff --git a/Bin/Server/Debug/rund.sh b/Bin/Server/Debug/rund.sh index 85538125..d9c72ce5 100644 --- a/Bin/Server/Debug/rund.sh +++ b/Bin/Server/Debug/rund.sh @@ -1,49 +1,68 @@ -cp -a ../../Comm/Debug/NFPluginLoader_d ./NFMasterServer/NFMasterServer_d -cp -a ../../Comm/Debug/NFPluginLoader_d ./NFWorldServer/NFWorldServer_d -cp -a ../../Comm/Debug/NFPluginLoader_d ./NFLoginServer/NFLoginServer_d -cp -a ../../Comm/Debug/NFPluginLoader_d ./NFGameServer1/NFGameServer_d -cp -a ../../Comm/Debug/NFPluginLoader_d ./NFProxyServer1/NFProxyServer_d - -cp -a ../../Comm/Debug/*.so ./NFMasterServer/ -cp -a ../../Comm/Debug/*.so ./NFWorldServer/ -cp -a ../../Comm/Debug/*.so ./NFLoginServer/ -cp -a ../../Comm/Debug/*.so ./NFGameServer1/ -cp -a ../../Comm/Debug/*.so ./NFProxyServer1/ - - +echo Copy common dlls... +cp -a ../../../Bin/Comm/Debug/PluginLoader_d AFLoginServer/ +cp -a ../../../Bin/Comm/Debug/PluginLoader_d AFMasterServer/ +cp -a ../../../Bin/Comm/Debug/PluginLoader_d AFProxyServer/ +cp -a ../../../Bin/Comm/Debug/PluginLoader_d AFWorldServer/ +cp -a ../../../Bin/Comm/Debug/PluginLoader_d AFGameServer/ + +cp -a ../../../Dep/lib/Debug/libproto*d.so AFLoginServer/ +cp -a ../../../Dep/lib/Debug/libproto*d.so AFMasterServer/ +cp -a ../../../Dep/lib/Debug/libproto*d.so AFProxyServer/ +cp -a ../../../Dep/lib/Debug/libproto*d.so AFWorldServer/ +cp -a ../../../Dep/lib/Debug/libproto*d.so AFGameServer/ + +cp -a ../../../Bin/Comm/Debug/AFProto*d.so AFLoginServer/ +cp -a ../../../Bin/Comm/Debug/AFProto*d.so AFMasterServer/ +cp -a ../../../Bin/Comm/Debug/AFProto*d.so AFProxyServer/ +cp -a ../../../Bin/Comm/Debug/AFProto*d.so AFWorldServer/ +cp -a ../../../Bin/Comm/Debug/AFProto*d.so AFGameServer/ + +cp -a ../../../Bin/Comm/Debug/AFKernelPlugin*d.so AFLoginServer/ +cp -a ../../../Bin/Comm/Debug/AFKernelPlugin*d.so AFMasterServer/ +cp -a ../../../Bin/Comm/Debug/AFKernelPlugin*d.so AFProxyServer/ +cp -a ../../../Bin/Comm/Debug/AFKernelPlugin*d.so AFWorldServer/ +cp -a ../../../Bin/Comm/Debug/AFKernelPlugin*d.so AFGameServer/ + +cp -a ../../../Bin/Comm/Debug/AFUtilityPlugin*d.so AFLoginServer/ +cp -a ../../../Bin/Comm/Debug/AFUtilityPlugin*d.so AFMasterServer/ +cp -a ../../../Bin/Comm/Debug/AFUtilityPlugin*d.so AFProxyServer/ +cp -a ../../../Bin/Comm/Debug/AFUtilityPlugin*d.so AFWorldServer/ +cp -a ../../../Bin/Comm/Debug/AFUtilityPlugin*d.so AFGameServer/ + +echo Copy self dlls +cp -a ../../../Bin/Comm/Debug/AFLogin*d.so AFLoginServer/ +cp -a ../../../Bin/Comm/Debug/AFMaster*d.so AFMasterServer/ +cp -a ../../../Bin/Comm/Debug/AFProxy*d.so AFProxyServer/ +cp -a ../../../Bin/Comm/Debug/AFWorld*d.so AFWorldServer/ +cp -a ../../../Bin/Comm/Debug/AFGame*d.so AFGameServer/ export LC_ALL="C" -cd ./NFMasterServer -chmod -R 777 NFMasterServer_d -./NFMasterServer_d -d -cd ../ - -cd ./NFWorldServer -chmod -R 777 NFWorldServer_d -./NFWorldServer_d -d -cd ../ - - -cd ./NFLoginServer -chmod -R 777 NFLoginServer_d -./NFLoginServer_d -d -cd ../ - - +cd AFMasterServer +echo Starting AFMasterServer... +./PluginLoader_d -d app_id=3 app_name=MasterServer cfg=Plugin.xml -cd ./NFGameServer1 -chmod -R 777 NFGameServer_d -./NFGameServer_d -d -cd ../ +cd .. +cd AFWorldServer +echo Starting AFWorldServer... +./PluginLoader_d -d app_id=7 app_name=WorldServer cfg=Plugin.xml -cd ./NFProxyServer1 -chmod -R 777 NFProxyServer_d -./NFProxyServer_d -d -cd ../ +cd .. +cd AFLoginServer +echo Starting AFLoginServer... +./PluginLoader_d -d app_id=4 app_name=LoginServer cfg=Plugin.xml +cd .. +cd AFGameServer +echo Starting AFGameServer... +./PluginLoader_d -d app_id=6 app_name=GameServer cfg=Plugin.xml +cd .. +cd AFProxyServer +echo Starting AFProxyServer... +./PluginLoader_d -d app_id=5 app_name=ProxyServer cfg=Plugin.xml +echo All processes are launching... -ps -A|grep NF +ps ax | grep *Server \ No newline at end of file diff --git a/Bin/Server/Release/killr.sh b/Bin/Server/Release/killr.sh index 1470dbc6..15210cf0 100644 --- a/Bin/Server/Release/killr.sh +++ b/Bin/Server/Release/killr.sh @@ -1,7 +1,7 @@ -kill -9 $(pidof NFMasterServer_r) -kill -9 $(pidof NFWorldServer_r) -kill -9 $(pidof NFLoginServer_r) -kill -9 $(pidof NFGameServer_r) -kill -9 $(pidof NFProxyServer_r) +kill -9 $(pidof MasterServer) +kill -9 $(pidof WorldServer) +kill -9 $(pidof LoginServer) +kill -9 $(pidof GameServer) +kill -9 $(pidof ProxyServer) -ps -A|grep NF +ps ax | grep *Server \ No newline at end of file diff --git a/Bin/Server/Release/run.bat b/Bin/Server/Release/run.bat index a27ccdba..5a201d4b 100644 --- a/Bin/Server/Release/run.bat +++ b/Bin/Server/Release/run.bat @@ -53,40 +53,32 @@ copy ..\\..\\..\\Bin\\Comm\\Release\\AFGame*.dll AFGameServer\\ /Y cd AFMasterServer - echo Starting AFMasterServer... -start "" "PluginLoader.exe" - +start "" "PluginLoader.exe -x app_id=3 app_name=MasterServer cfg=Plugin.xml" choice /t 2 /d y /n >nul + cd .. cd AFWorldServer echo Starting AFWorldServer... -start "" "PluginLoader.exe" - - +start "" "PluginLoader.exe -x app_id=7 app_name=WorldServer cfg=Plugin.xml" choice /t 5 /d y /n >nul cd .. cd AFLoginServer echo Starting AFLoginServer... -start "" "PluginLoader.exe" - +start "" "PluginLoader.exe -x app_id=4 app_name=LoginServer cfg=Plugin.xml" choice /t 2 /d y /n >nul cd .. cd AFGameServer echo Starting AFGameServer... -start "" "PluginLoader.exe" - +start "" "PluginLoader.exe -x app_id=6 app_name=GameServer cfg=Plugin.xml" choice /t 4 /d y /n >nul cd .. cd AFProxyServer echo Starting AFProxyServer... -start "" "PluginLoader.exe" - - - - +start "" "PluginLoader.exe -x app_id=5 app_name=ProxyServer cfg=Plugin.xml" +echo All processes are launching... \ No newline at end of file diff --git a/Bin/Server/Release/runr.sh b/Bin/Server/Release/runr.sh index c1e1b18e..492a6c4f 100644 --- a/Bin/Server/Release/runr.sh +++ b/Bin/Server/Release/runr.sh @@ -1,47 +1,68 @@ -cp -a ../../Comm/Release/NFPluginLoader_r ./NFMasterServer/NFMasterServer_r -cp -a ../../Comm/Release/NFPluginLoader_r ./NFWorldServer/NFWorldServer_r -cp -a ../../Comm/Release/NFPluginLoader_r ./NFLoginServer/NFLoginServer_r -cp -a ../../Comm/Release/NFPluginLoader_r ./NFGameServer1/NFGameServer_r -cp -a ../../Comm/Release/NFPluginLoader_r ./NFProxyServer1/NFProxyServer_r - -cp -a ../../Comm/Debug/*.so ./NFMasterServer/ -cp -a ../../Comm/Debug/*.so ./NFWorldServer/ -cp -a ../../Comm/Debug/*.so ./NFLoginServer/ -cp -a ../../Comm/Debug/*.so ./NFGameServer1/ -cp -a ../../Comm/Debug/*.so ./NFProxyServer1/ +echo Copy common dlls... +cp -a ../../../Bin/Comm/Release/PluginLoader AFLoginServer/ +cp -a ../../../Bin/Comm/Release/PluginLoader AFMasterServer/ +cp -a ../../../Bin/Comm/Release/PluginLoader AFProxyServer/ +cp -a ../../../Bin/Comm/Release/PluginLoader AFWorldServer/ +cp -a ../../../Bin/Comm/Release/PluginLoader AFGameServer/ -export LC_ALL="C" +cp -a ../../../Dep/lib/Release/libproto*.so AFLoginServer/ +cp -a ../../../Dep/lib/Release/libproto*.so AFMasterServer/ +cp -a ../../../Dep/lib/Release/libproto*.so AFProxyServer/ +cp -a ../../../Dep/lib/Release/libproto*.so AFWorldServer/ +cp -a ../../../Dep/lib/Release/libproto*.so AFGameServer/ -cd ./NFMasterServer -chmod -R 777 NFMasterServer_r -./NFMasterServer_r -d -cd ../ +cp -a ../../../Bin/Comm/Release/AFProto*.so AFLoginServer/ +cp -a ../../../Bin/Comm/Release/AFProto*.so AFMasterServer/ +cp -a ../../../Bin/Comm/Release/AFProto*.so AFProxyServer/ +cp -a ../../../Bin/Comm/Release/AFProto*.so AFWorldServer/ +cp -a ../../../Bin/Comm/Release/AFProto*.so AFGameServer/ -cd ./NFWorldServer -chmod -R 777 NFWorldServer_r -./NFWorldServer_r -d -cd ../ +cp -a ../../../Bin/Comm/Release/AFKernelPlugin*.so AFLoginServer/ +cp -a ../../../Bin/Comm/Release/AFKernelPlugin*.so AFMasterServer/ +cp -a ../../../Bin/Comm/Release/AFKernelPlugin*.so AFProxyServer/ +cp -a ../../../Bin/Comm/Release/AFKernelPlugin*.so AFWorldServer/ +cp -a ../../../Bin/Comm/Release/AFKernelPlugin*.so AFGameServer/ +cp -a ../../../Bin/Comm/Release/AFUtilityPlugin*.so AFLoginServer/ +cp -a ../../../Bin/Comm/Release/AFUtilityPlugin*.so AFMasterServer/ +cp -a ../../../Bin/Comm/Release/AFUtilityPlugin*.so AFProxyServer/ +cp -a ../../../Bin/Comm/Release/AFUtilityPlugin*.so AFWorldServer/ +cp -a ../../../Bin/Comm/Release/AFUtilityPlugin*.so AFGameServer/ -cd ./NFLoginServer -chmod -R 777 NFLoginServer_r -./NFLoginServer_r -d -cd ../ +echo Copy self dlls +cp -a ../../../Bin/Comm/Release/AFLogin*.so AFLoginServer/ +cp -a ../../../Bin/Comm/Release/AFMaster*.so AFMasterServer/ +cp -a ../../../Bin/Comm/Release/AFProxy*.so AFProxyServer/ +cp -a ../../../Bin/Comm/Release/AFWorld*.so AFWorldServer/ +cp -a ../../../Bin/Comm/Release/AFGame*.so AFGameServer/ +export LC_ALL="C" +cd AFMasterServer +echo Starting AFMasterServer... +./PluginLoader -d app_id=3 app_name=MasterServer cfg=Plugin.xml -cd ./NFGameServer1 -chmod -R 777 NFGameServer_r -./NFGameServer_r -d -cd ../ +cd .. +cd AFWorldServer +echo Starting AFWorldServer... +./PluginLoader -d app_id=7 app_name=WorldServer cfg=Plugin.xml -cd ./NFProxyServer1 -chmod -R 777 NFProxyServer_r -./NFProxyServer_r -d -cd ../ +cd .. +cd AFLoginServer +echo Starting AFLoginServer... +./PluginLoader -d app_id=4 app_name=LoginServer cfg=Plugin.xml +cd .. +cd AFGameServer +echo Starting AFGameServer... +./PluginLoader -d app_id=6 app_name=GameServer cfg=Plugin.xml +cd .. +cd AFProxyServer +echo Starting AFProxyServer... +./PluginLoader -d app_id=5 app_name=ProxyServer cfg=Plugin.xml +echo All processes are launching... -ps -A|grep NF +ps ax | grep *Server \ No newline at end of file diff --git a/Frame/SDK/PluginLoader/AFPluginLoader.cpp b/Frame/SDK/PluginLoader/AFPluginLoader.cpp index d12492d1..457e6ba7 100644 --- a/Frame/SDK/PluginLoader/AFPluginLoader.cpp +++ b/Frame/SDK/PluginLoader/AFPluginLoader.cpp @@ -325,19 +325,17 @@ bool ProcArgList(int argc, char* argv[]) #endif } - //鏆傛椂杩樹粠plugin.xml涓幏鍙朼pp id,涓嶅仛寮哄埗瑕佹眰 - //濡傛灉瑕佸仛澶氬紑锛屽垯闇瑕佽嚜宸卞鐞 - //if(config.app_id == 0) - //{ - // std::cout << "parameter app_id is invalid, please check." << std::endl; - // return false; - //} - //鏆傛椂app name涔熷彲浠ヤ笉鐢ㄤ紶鍙 - //if(config.app_name.empty()) - //{ - // std::cout << "parameter app_name is invalid, please check." << std::endl; - // return false; - //} + if(config.app_id == 0) + { + std::cout << "parameter app_id is invalid, please check." << std::endl; + return false; + } + + if(config.app_name.empty()) + { + std::cout << "parameter app_name is invalid, please check." << std::endl; + return false; + } //Set plugin file AFCPluginManager::GetInstancePtr()->SetConfigName(config.plugin_file); @@ -385,6 +383,7 @@ int main(int argc, char* argv[]) std::cout << "Application parameter is invalid, please check it..." << std::endl; Usage(); + std::this_thread::sleep_for(std::chrono::seconds(30)); return -1; } From 1230bcd2097106a5b427163a5ca37a39ff98e36e Mon Sep 17 00:00:00 2001 From: NickYang <362148418@qq.com> Date: Fri, 30 Mar 2018 18:34:33 +0800 Subject: [PATCH 21/24] remove APPID which read from xml Former-commit-id: 4197235251014b54d0f8f07eed8b55e7b9355435 Former-commit-id: 75ba1caeaace9c7397eb9aae77ef87be653f3a98 --- Frame/SDK/PluginLoader/AFCPluginManager.cpp | 34 ++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Frame/SDK/PluginLoader/AFCPluginManager.cpp b/Frame/SDK/PluginLoader/AFCPluginManager.cpp index 9d605876..18c8147e 100644 --- a/Frame/SDK/PluginLoader/AFCPluginManager.cpp +++ b/Frame/SDK/PluginLoader/AFCPluginManager.cpp @@ -94,25 +94,25 @@ bool AFCPluginManager::LoadPluginConfig() mxPluginNameMap.insert(std::make_pair(strPluginName, true)); } - rapidxml::xml_node<>* pPluginAppNode = pRoot->first_node("APPID"); - if(!pPluginAppNode) - { - ARK_ASSERT(0, "There are no App ID", __FILE__, __FUNCTION__); - return false; - } + //rapidxml::xml_node<>* pPluginAppNode = pRoot->first_node("APPID"); + //if(!pPluginAppNode) + //{ + // ARK_ASSERT(0, "There are no App ID", __FILE__, __FUNCTION__); + // return false; + //} - const char* strAppID = pPluginAppNode->first_attribute("Name")->value(); - if(!strAppID) - { - ARK_ASSERT(0, "There are no App ID", __FILE__, __FUNCTION__); - return false; - } + //const char* strAppID = pPluginAppNode->first_attribute("Name")->value(); + //if(!strAppID) + //{ + // ARK_ASSERT(0, "There are no App ID", __FILE__, __FUNCTION__); + // return false; + //} - if(!AFMisc::ARK_FROM_STR(strAppID, mnAppID)) - { - ARK_ASSERT(0, "App ID Convert Error", __FILE__, __FUNCTION__); - return false; - } + //if(!AFMisc::ARK_FROM_STR(strAppID, mnAppID)) + //{ + // ARK_ASSERT(0, "App ID Convert Error", __FILE__, __FUNCTION__); + // return false; + //} rapidxml::xml_node<>* pPluginConfigPathNode = pRoot->first_node("ConfigPath"); if(!pPluginConfigPathNode) From a7fb9a42d110913ca139ab1230ea8226fcaf9038 Mon Sep 17 00:00:00 2001 From: NickYang <362148418@qq.com> Date: Fri, 30 Mar 2018 20:04:40 +0800 Subject: [PATCH 22/24] add static_assert Former-commit-id: b75d198aa99d78a68ffacedbb8eb94ff67215bde Former-commit-id: db8071708b77069443576e13f1240d1288f76c15 --- Frame/Examples/Tutorial1/HelloWorld1.cpp | 1 + Frame/SDK/Core/Base/AFMacros.hpp | 26 +++++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Frame/Examples/Tutorial1/HelloWorld1.cpp b/Frame/Examples/Tutorial1/HelloWorld1.cpp index 6c182837..6e39f32b 100644 --- a/Frame/Examples/Tutorial1/HelloWorld1.cpp +++ b/Frame/Examples/Tutorial1/HelloWorld1.cpp @@ -20,6 +20,7 @@ #include "HelloWorld1.h" #include "SDK/Core/Base/AFTimer.hpp" +#include "SDK/Core/Base/AFMacros.hpp" bool HelloWorld1::Init() { diff --git a/Frame/SDK/Core/Base/AFMacros.hpp b/Frame/SDK/Core/Base/AFMacros.hpp index e2f0c915..6438660a 100644 --- a/Frame/SDK/Core/Base/AFMacros.hpp +++ b/Frame/SDK/Core/Base/AFMacros.hpp @@ -91,6 +91,27 @@ #endif +template struct ARK_STATIC_ASSERTION_FAILURE; +template<> struct ARK_STATIC_ASSERTION_FAILURE +{ + enum + { + value = 1 + }; +}; + +template struct ark_static_assert_test {}; + +#if ARK_PLATFORM == PLATFORM_UNIX +#define ARK_UNUSED __attribute__((unused)) +#else +#define ARK_UNUSED +#endif + +#define ARK_STATIC_ASSERT(x) \ + typedef ark_static_assert_test)> \ + __FUNCTION__##__LINE__ ARK_UNUSED + #define ARK_ASSERT_RET_VAL(exp_, val) \ do \ { \ @@ -130,6 +151,7 @@ assert(exp_); \ } while(0) + #if defined(USE_BOOST) # include # define ARK_LEXICAL_CAST boost::lexical_cast @@ -141,11 +163,9 @@ #endif //Google Protobuffer use dll -#if ARK_PLATFORM == PLATFORM_WIN -#if !defined(PROTOBUF_USE_DLLS) +#ifndef PROTOBUF_USE_DLLS #define PROTOBUF_USE_DLLS #endif -#endif //Singleton #define ARK_SINGLETON_INIT(TYPE) template<> TYPE* Singleton::instance_ = 0; From fbd636e967f501e9a8d621ca2b7cdc77ea427e19 Mon Sep 17 00:00:00 2001 From: NickYang <362148418@qq.com> Date: Sat, 31 Mar 2018 11:09:48 +0800 Subject: [PATCH 23/24] Update CONTRIBUTING.md Former-commit-id: 1132a3f68024e10d1f48ad86a9a3b37e9fdeeab1 Former-commit-id: 16ef4c54c82675506778c8b2f9e036e71780295a --- CONTRIBUTING.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 093e01c2..d96e390d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,5 +1,5 @@ # Contributing to ArkGameFrame -Welcome to [report Issues](https://github.com/ArkGame/ArkGameFrame/issues) or [pull requests](https://github.com/ArkGame/ArkGameFrame/pulls). It's recommended to read the following Contributing Guide first before contributing. +Welcome to [report Issues](https://github.com/ArkGame/ARK/issues) or [pull requests](https://github.com/ArkGame/ARK/pulls). It's recommended to read the following Contributing Guide first before contributing. ## Issues We use Github Issues to track public bugs and feature requests. @@ -11,7 +11,7 @@ Please search the existing issues to see if any similar issue or feature request If you open an issue, the more information the better. Such as detailed description, screenshot or video of your problem, logcat or code blocks for your crash. ## Pull Requests -We strongly welcome your pull request to make `ArkGameFrame` better. +We strongly welcome your pull request to make `ARK` better. ### Branch Management There are three main branches here: @@ -48,5 +48,5 @@ Before submitting a pull request, please make sure the followings are done: Try to be similar with the other authers. ## License -By contributing to `ArkGameFrame`, you agree that your contributions will be licensed +By contributing to `ARK`, you agree that your contributions will be licensed under [Apache LICENSE](https://github.com/ArkGame/ArkGameFrame/blob/master/LICENSE) From 8344d43a04fa4c07b1e8b8a288d4f7dadb3f7bb8 Mon Sep 17 00:00:00 2001 From: NickYang <362148418@qq.com> Date: Sat, 31 Mar 2018 11:11:44 +0800 Subject: [PATCH 24/24] Update CONTRIBUTING.md Former-commit-id: d0ca5a612166178f27d869290dc4f67296c54988 Former-commit-id: 79b8ddb3caab06679ef9ed11ae4e641f1147550d --- CONTRIBUTING.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d96e390d..822b1e86 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,4 +1,4 @@ -# Contributing to ArkGameFrame +# Contributing to ARK Welcome to [report Issues](https://github.com/ArkGame/ARK/issues) or [pull requests](https://github.com/ArkGame/ARK/pulls). It's recommended to read the following Contributing Guide first before contributing. ## Issues @@ -24,7 +24,7 @@ There are three main branches here: 2. `develop` branch. - (1).There is a `develop` for `ArkGameFrame` developing version. It is our stable developing branch. After full testing, `develop` branch will be merged to `master` branch for the next release. + (1).There is a `develop` for `ARK` developing version. It is our stable developing branch. After full testing, `develop` branch will be merged to `master` branch for the next release. (2). **You are recommended to submit bugfix or feature PR on `develop` branch.** @@ -49,4 +49,4 @@ Try to be similar with the other authers. ## License By contributing to `ARK`, you agree that your contributions will be licensed -under [Apache LICENSE](https://github.com/ArkGame/ArkGameFrame/blob/master/LICENSE) +under [Apache LICENSE](https://github.com/ArkGame/ARK/blob/master/LICENSE)