From 0df5dc6b4c885e899b713e982e69dae1e2f6b994 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 31 Oct 2023 14:53:08 +0800 Subject: [PATCH] 1 --- server/gameserver/base_agent.cc | 16 +++++----- server/gameserver/btcoroutine.h | 2 +- server/gameserver/hero_agent.cc | 55 ++++++++++++++++++++++++++------- 3 files changed, 54 insertions(+), 19 deletions(-) diff --git a/server/gameserver/base_agent.cc b/server/gameserver/base_agent.cc index 4eddfdd4..5887ebfc 100644 --- a/server/gameserver/base_agent.cc +++ b/server/gameserver/base_agent.cc @@ -76,14 +76,10 @@ bool BaseAgent::PreEnterCoroutine(int co_id, behaviac::EBTStatus& status) return false; } auto& co = itr->second; - if (co->IsAbort()) { - status = behaviac::BT_FAILURE; - return true; - } if (co->status != behaviac::BT_RUNNING) { abort(); } - co->status = co->runing_cb(); + co->status = co->runing_cb(co.get()); status = co->status; if (co->status != behaviac::BT_RUNNING) { list_del_init(&co->entry); @@ -137,8 +133,11 @@ behaviac::EBTStatus BaseAgent::CoTest1(int time) context->time = time; auto co = std::make_shared(context, co_id, "CoTest1"); co->runing_cb = - [this, context] () + [this, context] (BtCoroutine* co) { + if (co->IsAbort()) { + return behaviac::BT_FAILURE; + } if ((GetRoom()->GetFrameNo() - context->frameno) * FRAME_RATE_MS < context->time) { return behaviac::BT_RUNNING; @@ -159,8 +158,11 @@ behaviac::EBTStatus BaseAgent::CoTest(int time) context->time = time; auto co = std::make_shared(context, co_id, "CoTest"); co->runing_cb = - [this, context] () + [this, context] (BtCoroutine* co) { + if (co->IsAbort()) { + return behaviac::BT_FAILURE; + } if ((GetRoom()->GetFrameNo() - context->frameno) * FRAME_RATE_MS < context->time) { return behaviac::BT_RUNNING; diff --git a/server/gameserver/btcoroutine.h b/server/gameserver/btcoroutine.h index 37fcc336..1e2d2cbf 100644 --- a/server/gameserver/btcoroutine.h +++ b/server/gameserver/btcoroutine.h @@ -9,7 +9,7 @@ class BtCoroutine { public: - std::function runing_cb; + std::function runing_cb; long long sleep_end_frameno = 0; int sleep_time = 0; list_head entry; diff --git a/server/gameserver/hero_agent.cc b/server/gameserver/hero_agent.cc index fff4fbfa..fc664ecb 100644 --- a/server/gameserver/hero_agent.cc +++ b/server/gameserver/hero_agent.cc @@ -255,8 +255,11 @@ behaviac::EBTStatus HeroAgent::RandomSafeZonePoint(int try_count, int step_len) ); auto co = std::make_shared(context, co_id, "RandomSafeZonePoint"); co->runing_cb = - [this, context, try_count, step_len] () + [this, context, try_count, step_len] (BtCoroutine* co) { + if (co->IsAbort()) { + return behaviac::BT_FAILURE; + } if (owner_->dead) { return behaviac::BT_FAILURE; } @@ -406,8 +409,11 @@ behaviac::EBTStatus HeroAgent::CoIdle(int min_val, int max_val) context->time = a8::RandEx(min_val, max_val); auto co = std::make_shared(context, co_id, "CoIdle"); co->runing_cb = - [this, context] () + [this, context] (BtCoroutine* co) { + if (co->IsAbort()) { + return behaviac::BT_FAILURE; + } if ((GetRoom()->GetFrameNo() - context->frameno) * FRAME_RATE_MS < context->time) { return behaviac::BT_RUNNING; @@ -426,8 +432,11 @@ behaviac::EBTStatus HeroAgent::CoMoveCurrentTargetRaycast() ); auto co = std::make_shared(context, co_id, "CoMoveCurrentTargetRaycast"); co->runing_cb = - [this, context] () + [this, context] (BtCoroutine* co) { + if (co->IsAbort()) { + return behaviac::BT_FAILURE; + } if (!current_target_agent->IsValid()) { return behaviac::BT_FAILURE; } @@ -450,8 +459,11 @@ behaviac::EBTStatus HeroAgent::CoShotCurrentTargetRaycast() ); auto co = std::make_shared(context, co_id, "CoShotCurrentTargetRaycast"); co->runing_cb = - [this, context] () + [this, context] (BtCoroutine* co) { + if (co->IsAbort()) { + return behaviac::BT_FAILURE; + } if (!current_target_agent->IsValid()) { return behaviac::BT_FAILURE; } @@ -482,8 +494,11 @@ behaviac::EBTStatus HeroAgent::CoMoveMasterRaycast() &owner_->xtimer_attacher); auto co = std::make_shared(context, co_id, "CoMoveMasterRaycast"); co->runing_cb = - [this, context] () + [this, context] (BtCoroutine* co) { + if (co->IsAbort()) { + return behaviac::BT_FAILURE; + } if (!context->timer_ptr.expired()) { return behaviac::BT_RUNNING; } else { @@ -504,8 +519,11 @@ behaviac::EBTStatus HeroAgent::CoFindPath(const glm::vec3& pos) context->target_pos = pos; auto co = std::make_shared(context, co_id, "CoFindPath"); co->runing_cb = - [this, context, pos] () + [this, context, pos] (BtCoroutine* co) { + if (co->IsAbort()) { + return behaviac::BT_FAILURE; + } if (owner_->dead) { return behaviac::BT_FAILURE; } @@ -538,8 +556,11 @@ behaviac::EBTStatus HeroAgent::CoFindPathEx(const glm::vec3& pos, float distance context->target_pos = pos; auto co = std::make_shared(context, co_id, "CoFindPathEx"); co->runing_cb = - [this, context, distance] () + [this, context, distance] (BtCoroutine* co) { + if (co->IsAbort()) { + return behaviac::BT_FAILURE; + } if (owner_->dead) { return behaviac::BT_FAILURE; } @@ -570,8 +591,11 @@ behaviac::EBTStatus HeroAgent::CoStartMove(int min_val, int max_val) ); auto co = std::make_shared(context, co_id, "CoStartMove"); co->runing_cb = - [this, context, distance] () + [this, context, distance] (BtCoroutine* co) { + if (co->IsAbort()) { + return behaviac::BT_FAILURE; + } if (!owner_->dead) { owner_->GetMovement()->CalcTargetPos(distance); } @@ -596,8 +620,11 @@ behaviac::EBTStatus HeroAgent::CoSleep(int time) &owner_->xtimer_attacher); auto co = std::make_shared(context, co_id, "CoSleep"); co->runing_cb = - [this, context] () + [this, context] (BtCoroutine* co) { + if (co->IsAbort()) { + return behaviac::BT_FAILURE; + } if (!context->timer_ptr.expired()) { return behaviac::BT_RUNNING; } else { @@ -652,8 +679,11 @@ behaviac::EBTStatus HeroAgent::CoMoveForward(int min_val, int max_val) owner_->GetMovement()->CalcTargetPos(distance); auto co = std::make_shared(context, co_id, "CoMoveForward"); co->runing_cb = - [this, context] () + [this, context] (BtCoroutine* co) { + if (co->IsAbort()) { + return behaviac::BT_FAILURE; + } if (owner_->GetMovement()->GetPathSize() <= 0) { return behaviac::BT_SUCCESS; } else { @@ -945,8 +975,11 @@ behaviac::EBTStatus HeroAgent::CoGetRunAwayPoint() ); auto co = std::make_shared(context, co_id, "CoGetRunAwayPoint"); co->runing_cb = - [this, context] () + [this, context] (BtCoroutine* co) { + if (co->IsAbort()) { + return behaviac::BT_FAILURE; + } if (owner_->dead) { return behaviac::BT_FAILURE; }