This commit is contained in:
aozhiwei 2023-10-21 12:39:56 +08:00
parent a75eabe884
commit eef2cd1972
2 changed files with 34 additions and 13 deletions

View File

@ -61,18 +61,9 @@ HeroAgent::~HeroAgent()
void HeroAgent::Exec() void HeroAgent::Exec()
{ {
behaviac::EBTStatus status = f8::BtMgr::Instance()->BtExec(this); behaviac::EBTStatus status = f8::BtMgr::Instance()->BtExec(this);
#if 0 if (status == behaviac::BT_RUNNING) {
if (status == behaviac::BT_RUNNING && CheckCoroutineEvent();
coroutine_ &&
coroutine_->GetContext()->HasEvent()) {
status_= behaviac::BT_INVALID;
auto old_coroutine = coroutine_;
coroutine_ = nullptr;
owner_->shot_hold = false;
old_coroutine->GetContext()->FireEvent(this);
old_coroutine = nullptr;
} }
#endif
} }
void HeroAgent::SetOwner(Creature* owner) void HeroAgent::SetOwner(Creature* owner)
@ -943,8 +934,37 @@ bool HeroAgent::PreEnterCoroutine(int co_id, behaviac::EBTStatus& status)
return true; return true;
} }
co->status = co->runing_cb(); co->status = co->runing_cb();
if (co->status != behaviac::BT_RUNNING) {
}
status = co->status; status = co->status;
if (co->status != behaviac::BT_RUNNING) {
list_del_init(&co->entry);
coroutines_hash_.erase(itr);
}
return true; return true;
} }
void HeroAgent::CheckCoroutineEvent()
{
int co_id = -1;
{
list_head* pos = nullptr;
list_head* next = nullptr;
list_head* head = &coroutines_list_;
list_for_each_safe(pos, next, head) {
BtCoroutine* co = list_entry(pos, BtCoroutine, entry);
if (co->GetContext()->HasEvent()) {
co_id = co->GetId();
break;
}
}
}
if (co_id >= 0) {
auto itr = coroutines_hash_.find(co_id);
if (itr == coroutines_hash_.end()) {
abort();
}
auto co = itr->second;
coroutines_hash_.clear();
INIT_LIST_HEAD(&coroutines_list_);
co->GetContext()->FireEvent(this);
}
}

View File

@ -143,6 +143,7 @@ protected:
bool PreEnterCoroutine(int co_id, behaviac::EBTStatus& status); bool PreEnterCoroutine(int co_id, behaviac::EBTStatus& status);
behaviac::EBTStatus StartCoroutine(std::shared_ptr<BtCoroutine> coroutine); behaviac::EBTStatus StartCoroutine(std::shared_ptr<BtCoroutine> coroutine);
bool InternalUseSkill(int skill_id, int& wait_time); bool InternalUseSkill(int skill_id, int& wait_time);
void CheckCoroutineEvent();
private: private:
Creature* owner_ = nullptr; Creature* owner_ = nullptr;