From 34f4f1f0cd9bc7271d47b8c3a9f280c368ff6ec1 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 21 Dec 2024 19:21:22 +0800 Subject: [PATCH] 1 --- server/mymangosd/CMakeLists.txt | 19 +++---------- server/mymangosd/main.cc | 5 +++- server/mymangosd/pch.h | 1 - third_party/a8/a8/CMakeLists.txt | 7 +++-- third_party/a8/a8/macro.h | 33 +++++++++++++++-------- third_party/a8/a8/singleton.h | 4 +-- third_party/f8/f8/CMakeLists.txt | 10 +++---- third_party/f8/f8/app.cc | 46 ++++++++++++++++++++++++++++++++ third_party/f8/f8/app.h | 21 +++------------ third_party/f8/f8/userapp.h | 17 ++++++++++++ 10 files changed, 105 insertions(+), 58 deletions(-) create mode 100644 third_party/f8/f8/userapp.h diff --git a/server/mymangosd/CMakeLists.txt b/server/mymangosd/CMakeLists.txt index fbd3bc8..14ad6dd 100644 --- a/server/mymangosd/CMakeLists.txt +++ b/server/mymangosd/CMakeLists.txt @@ -20,11 +20,7 @@ include_directories( AFTER ../../third_party/a8 ../../third_party/f8 - /usr/include/mysql - /usr/include/jsoncpp - /usr/include/hiredis /usr/include/glm - ../../third_party ../../third_party/behaviac/inc ../../third_party/recastnavigation/Recast/Include ../../third_party/recastnavigation/Detour/Include @@ -39,14 +35,6 @@ link_directories( /usr/local/lib ) -#aux_source_directory(../../third_party/a8/a8 -# SRC_LIST -#) - -#aux_source_directory(../../third_party/f8/f8 -# SRC_LIST -#) - aux_source_directory(../../third_party/recastnavigation/Recast/Source SRC_LIST ) @@ -73,6 +61,8 @@ add_executable( target_link_libraries( mymangosd + f8 + a8 pthread mysqlclient protobuf @@ -83,7 +73,6 @@ target_link_libraries( ssl jsoncpp curl - hiredis tinyxml2 backtrace ) @@ -103,5 +92,5 @@ else() ) endif() -#ADD_SUBDIRECTORY(../../third_party/a8/a8 a8) -#ADD_SUBDIRECTORY(../../third_party/f8/f8 f8) +ADD_SUBDIRECTORY(../../third_party/a8/a8 a8) +ADD_SUBDIRECTORY(../../third_party/f8/f8 f8) diff --git a/server/mymangosd/main.cc b/server/mymangosd/main.cc index e83f814..d078fc0 100644 --- a/server/mymangosd/main.cc +++ b/server/mymangosd/main.cc @@ -1,6 +1,9 @@ #include "pch.h" +#include + int main(int argc, char* argv[]) { - return 0; + f8::App::Instance()->GetZoneId(); + return 1; } diff --git a/server/mymangosd/pch.h b/server/mymangosd/pch.h index b067f26..e0896a8 100644 --- a/server/mymangosd/pch.h +++ b/server/mymangosd/pch.h @@ -1,4 +1,3 @@ #pragma once -#include #include diff --git a/third_party/a8/a8/CMakeLists.txt b/third_party/a8/a8/CMakeLists.txt index 5ec0642..214a48d 100644 --- a/third_party/a8/a8/CMakeLists.txt +++ b/third_party/a8/a8/CMakeLists.txt @@ -16,17 +16,16 @@ else() set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -std=c++17 -DMYDEBUG ") endif() -# include directories include_directories( AFTER - ../../a8 /usr/include/mysql /usr/include/jsoncpp /usr/include/glm + ../../a8 ) aux_source_directory(. - SRC_LIST + A8_SRC_LIST ) -add_library(a8 STATIC ${SRC_LIST}) +add_library(a8 STATIC ${A8_SRC_LIST}) diff --git a/third_party/a8/a8/macro.h b/third_party/a8/a8/macro.h index 0d01359..4105d01 100644 --- a/third_party/a8/a8/macro.h +++ b/third_party/a8/a8/macro.h @@ -28,14 +28,25 @@ struct Context \ }; \ return std::make_shared();}() -#define A8_MAKE_SMART_ANON_STRUCT_SHARED(...) \ -[] () \ -{ \ -struct Context : public std::enable_shared_from_this \ -{ \ - __VA_ARGS__; \ - std::function _destory_cb; \ - std::weak_ptr GetWp() { return shared_from_this();}; \ - ~Context() { if (_destory_cb) { _destory_cb(); };}; \ -}; \ -return std::make_shared();}() +#define A8_MAKE_SMART_ANON_STRUCT_SHARED(...) \ + [] () \ + { \ + struct Context : public std::enable_shared_from_this \ + { \ + __VA_ARGS__; \ + std::function _destory_cb; \ + std::weak_ptr GetWp() { return shared_from_this();}; \ + ~Context() { if (_destory_cb) { _destory_cb(); };}; \ + }; \ + return std::make_shared();}() + +#define A8_DECLARE_SINGLETON(T) \ + public: static T* Instance() \ + { \ + static T instance; \ + return &instance; \ + } \ + private: \ + T(); \ + T(const T&) = delete; \ + T& operator=(const T&) = delete; diff --git a/third_party/a8/a8/singleton.h b/third_party/a8/a8/singleton.h index 8eb3c25..7cf1ca8 100644 --- a/third_party/a8/a8/singleton.h +++ b/third_party/a8/a8/singleton.h @@ -29,9 +29,7 @@ namespace a8 ~Singleton() {} private: - static std::shared_ptr instance_; + static inline std::shared_ptr instance_; }; - template std::shared_ptr Singleton::instance_; - } diff --git a/third_party/f8/f8/CMakeLists.txt b/third_party/f8/f8/CMakeLists.txt index 4ee7883..fb18b62 100644 --- a/third_party/f8/f8/CMakeLists.txt +++ b/third_party/f8/f8/CMakeLists.txt @@ -16,18 +16,16 @@ else() set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -std=c++17 -DMYDEBUG ") endif() -# include directories include_directories( AFTER + /usr/include/mysql + /usr/include/glm ../../a8 ../../f8 - /usr/include/mysql - /usr/include/jsoncpp - /usr/include/glm ) aux_source_directory(. - SRC_LIST + F8_SRC_LIST ) -add_library(f8 STATIC ${SRC_LIST}) +add_library(f8 STATIC ${F8_SRC_LIST}) diff --git a/third_party/f8/f8/app.cc b/third_party/f8/f8/app.cc index 1d5d567..e98e6c8 100644 --- a/third_party/f8/f8/app.cc +++ b/third_party/f8/f8/app.cc @@ -17,6 +17,7 @@ #include #include #include +#include static const int MAX_ZONE_ID = 100; static const int MAX_NODE_ID = 8; @@ -137,6 +138,11 @@ namespace f8 return flags_.find(flag) != flags_.end(); } + const std::string GetPkgName() + { + return user_app_->GetPkgName(); + } + void NotifyLoopCond() { std::unique_lock lk(*loop_mutex_); @@ -284,6 +290,21 @@ namespace f8 return getpid(); } + int GetZoneId() + { + return zone_id_; + } + + int GetNodeId() + { + return node_id_; + } + + int GetInstanceId() + { + return instance_id_; + } + void InitLog() { std::string filename_fmt = PROJ_LOG_FILENAME_FMT; @@ -319,6 +340,11 @@ namespace f8 }; + App::App():impl_(std::make_shared()) + { + + } + int App::Run(int argc, char* argv[], UserApp* user_app) { impl_ = std::make_unique(); @@ -330,6 +356,11 @@ namespace f8 return impl_->HasFlag(flag); } + const std::string App::GetPkgName() + { + return impl_->GetPkgName(); + } + void App::NotifyLoopCond() { impl_->NotifyLoopCond(); @@ -350,6 +381,21 @@ namespace f8 return impl_->GetPid(); } + int App::GetZoneId() + { + return impl_->GetZoneId(); + } + + int App::GetNodeId() + { + return impl_->GetNodeId(); + } + + int App::GetInstanceId() + { + return impl_->GetInstanceId(); + } + void App::AddSocketMsg(int sockfrom, int sockhandle, long ip_saddr, diff --git a/third_party/f8/f8/app.h b/third_party/f8/f8/app.h index 19b57af..a92a453 100644 --- a/third_party/f8/f8/app.h +++ b/third_party/f8/f8/app.h @@ -3,23 +3,10 @@ namespace f8 { - class UserApp + class UserApp; + class App { - public: - virtual const std::string GetPkgName() = 0; - virtual void Init() = 0; - virtual void UnInit() = 0; - virtual void Update(int delta_time) = 0; - virtual bool HasTask() = 0; - virtual void DispatchSocketMsg(MsgHdr* hdr) = 0; - }; - - class App : public a8::Singleton - { - private: - App() {}; - friend class a8::Singleton; - + A8_DECLARE_SINGLETON(App); public: int Run(int argc, char* argv[], UserApp* user_app); @@ -52,7 +39,7 @@ namespace f8 void ResetMaxRunDelayTime(); private: - std::unique_ptr impl_; + std::shared_ptr impl_; }; } diff --git a/third_party/f8/f8/userapp.h b/third_party/f8/f8/userapp.h new file mode 100644 index 0000000..e41f8f8 --- /dev/null +++ b/third_party/f8/f8/userapp.h @@ -0,0 +1,17 @@ +#pragma once + +namespace f8 +{ + + class UserApp + { + public: + virtual const std::string GetPkgName() = 0; + virtual void Init() = 0; + virtual void UnInit() = 0; + virtual void Update(int delta_time) = 0; + virtual bool HasTask() = 0; + virtual void DispatchSocketMsg(f8::MsgHdr* hdr) = 0; + }; + +}