diff --git a/server/robotserver/app.cc b/server/robotserver/app.cc index 257c077c..cc2bd83b 100644 --- a/server/robotserver/app.cc +++ b/server/robotserver/app.cc @@ -18,6 +18,7 @@ #include "app.h" #include "handlermgr.h" #include "httpproxy.h" +#include "playermgr.h" #include "ss_msgid.pb.h" #include "ss_proto.pb.h" @@ -95,7 +96,7 @@ bool App::Init(int argc, char* argv[]) #endif uuid.SetMachineId((node_id - 1) * MAX_NODE_ID + instance_id); HttpProxy::Instance()->Init(); - + PlayerMgr::Instance()->Init(); { int perf_log_time = 1000 * 30; f8::Timer::Instance()->SetInterval @@ -126,6 +127,7 @@ void App::UnInit() { //const char* s2 = GetEnumString(); //int i = static_cast(Test_e::kFlyBuffId); + PlayerMgr::Instance()->UnInit(); HttpProxy::Instance()->UnInit(); f8::BtMgr::Instance()->UnInit(); f8::HttpClientPool::Instance()->UnInit(); diff --git a/server/robotserver/comgr.cc b/server/robotserver/comgr.cc new file mode 100644 index 00000000..64cee3b6 --- /dev/null +++ b/server/robotserver/comgr.cc @@ -0,0 +1,22 @@ +#include "precompile.h" + +#include "comgr.h" +#include "coroutine.h" + +void CoMgr::Init() +{ + INIT_LIST_HEAD(&co_list_); +} + +void CoMgr::UnInit() +{ + +} + +void CoMgr::Update() +{ + Coroutine *co = nullptr, *tmp = nullptr; + list_for_each_entry_safe(co, tmp, &co_list_, entry) { + co->Exec(); + } +} diff --git a/server/robotserver/comgr.h b/server/robotserver/comgr.h new file mode 100644 index 00000000..8bd9d99e --- /dev/null +++ b/server/robotserver/comgr.h @@ -0,0 +1,22 @@ +#pragma once + +#include + +class CoMgr : public a8::Singleton +{ + + private: + CoMgr() {}; + friend class a8::Singleton; + + public: + + void Init(); + void UnInit(); + void Update(); + + private: + + list_head co_list_; + +}; diff --git a/server/robotserver/coroutine.cc b/server/robotserver/coroutine.cc index fbc05807..80eaf034 100644 --- a/server/robotserver/coroutine.cc +++ b/server/robotserver/coroutine.cc @@ -1,16 +1,30 @@ #include "precompile.h" +#include + #include "coroutine.h" Coroutine::Coroutine(std::function cb) { + INIT_LIST_HEAD(&entry); cb_ = cb; source_ = std::make_shared::pull_type> ( [this] (boost::coroutines2::coroutine::push_type& sink) { + CallEnter(sink); cb_(this); + CallExit(sink); }); + while (*source_) { + a8::XPrintf("xxxxx\n", {}); + (*source_)(); + } +} + +void Coroutine::Exec() +{ + } void Coroutine::CoSuspend() @@ -23,6 +37,11 @@ void Coroutine::CoResume() } +void Coroutine::CoYield() +{ + +} + void Coroutine::CoAwait(Awaiter& awaiter) { @@ -32,3 +51,13 @@ void Coroutine::CoAwait(Awaiter* awaiter) { } + +void Coroutine::CallEnter(boost::coroutines2::coroutine::push_type& sink) +{ + sink_ = &sink; +} + +void Coroutine::CallExit(boost::coroutines2::coroutine::push_type& sink) +{ + sink_ = nullptr; +} diff --git a/server/robotserver/coroutine.h b/server/robotserver/coroutine.h index 8da21787..6abf6104 100644 --- a/server/robotserver/coroutine.h +++ b/server/robotserver/coroutine.h @@ -15,15 +15,24 @@ class Promise : public Awaiter class Coroutine : public Awaiter { public: + list_head entry; Coroutine(std::function cb); + void Exec(); void CoSuspend(); void CoResume(); + void CoYield(); void CoAwait(Awaiter& awaiter); void CoAwait(Awaiter* awaiter); + private: + + void CallEnter(boost::coroutines2::coroutine::push_type& sink); + void CallExit(boost::coroutines2::coroutine::push_type& sink); + private: std::shared_ptr::pull_type> source_; std::function cb_; + boost::coroutines2::coroutine::push_type* sink_ = nullptr; }; diff --git a/server/robotserver/playermgr.cc b/server/robotserver/playermgr.cc index 58a6bdcf..d9da884c 100644 --- a/server/robotserver/playermgr.cc +++ b/server/robotserver/playermgr.cc @@ -6,6 +6,7 @@ #include "playermgr.h" #include "player.h" +#include "coroutine.h" #include #include @@ -15,6 +16,12 @@ void PlayerMgr::Init() for (int i = 0; i < 10; i++) { } + Coroutine co + ( + [] (Coroutine* co) + { + + }); } void PlayerMgr::UnInit()