This commit is contained in:
aozhiwei 2024-12-21 19:21:22 +08:00
parent 06a74ea172
commit 34f4f1f0cd
10 changed files with 105 additions and 58 deletions

View File

@ -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)

View File

@ -1,6 +1,9 @@
#include "pch.h"
#include <f8/app.h>
int main(int argc, char* argv[])
{
return 0;
f8::App::Instance()->GetZoneId();
return 1;
}

View File

@ -1,4 +1,3 @@
#pragma once
#include <a8/a8.h>
#include <f8/f8.h>

View File

@ -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})

View File

@ -28,14 +28,25 @@ struct Context \
}; \
return std::make_shared<Context>();}()
#define A8_MAKE_SMART_ANON_STRUCT_SHARED(...) \
[] () \
{ \
struct Context : public std::enable_shared_from_this<Context> \
{ \
__VA_ARGS__; \
std::function<void()> _destory_cb; \
std::weak_ptr<Context> GetWp() { return shared_from_this();}; \
~Context() { if (_destory_cb) { _destory_cb(); };}; \
}; \
return std::make_shared<Context>();}()
#define A8_MAKE_SMART_ANON_STRUCT_SHARED(...) \
[] () \
{ \
struct Context : public std::enable_shared_from_this<Context> \
{ \
__VA_ARGS__; \
std::function<void()> _destory_cb; \
std::weak_ptr<Context> GetWp() { return shared_from_this();}; \
~Context() { if (_destory_cb) { _destory_cb(); };}; \
}; \
return std::make_shared<Context>();}()
#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;

View File

@ -29,9 +29,7 @@ namespace a8
~Singleton() {}
private:
static std::shared_ptr<T> instance_;
static inline std::shared_ptr<T> instance_;
};
template<class T> std::shared_ptr<T> Singleton<T>::instance_;
}

View File

@ -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})

View File

@ -17,6 +17,7 @@
#include <f8/httpclientpool.h>
#include <a8/queue.h>
#include <f8/timer.h>
#include <f8/userapp.h>
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<std::mutex> 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<AppImpl>())
{
}
int App::Run(int argc, char* argv[], UserApp* user_app)
{
impl_ = std::make_unique<AppImpl>();
@ -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,

View File

@ -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<App>
{
private:
App() {};
friend class a8::Singleton<App>;
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<class AppImpl> impl_;
std::shared_ptr<class AppImpl> impl_;
};
}

17
third_party/f8/f8/userapp.h vendored Normal file
View File

@ -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;
};
}