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()
{
behaviac::EBTStatus status = f8::BtMgr::Instance()->BtExec(this);
#if 0
if (status == behaviac::BT_RUNNING &&
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;
if (status == behaviac::BT_RUNNING) {
CheckCoroutineEvent();
}
#endif
}
void HeroAgent::SetOwner(Creature* owner)
@ -943,8 +934,37 @@ bool HeroAgent::PreEnterCoroutine(int co_id, behaviac::EBTStatus& status)
return true;
}
co->status = co->runing_cb();
if (co->status != behaviac::BT_RUNNING) {
}
status = co->status;
if (co->status != behaviac::BT_RUNNING) {
list_del_init(&co->entry);
coroutines_hash_.erase(itr);
}
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);
behaviac::EBTStatus StartCoroutine(std::shared_ptr<BtCoroutine> coroutine);
bool InternalUseSkill(int skill_id, int& wait_time);
void CheckCoroutineEvent();
private:
Creature* owner_ = nullptr;