This commit is contained in:
aozhiwei 2023-06-23 19:37:25 +08:00
parent 53d0553d40
commit 07e56b7e59
4 changed files with 17 additions and 11 deletions

View File

@ -109,7 +109,7 @@ behaviac::EBTStatus BaseAgent::StartCoroutine(std::shared_ptr<BtCoroutine> corou
#ifdef DEBUG #ifdef DEBUG
last_status_ = behaviac::BT_INVALID; last_status_ = behaviac::BT_INVALID;
status_frameno_ = GetOwner()->room->GetFrameNo(); status_frameno_ = GetOwner()->room->GetFrameNo();
status_name_ = coroutine_->name; status_name_ = coroutine_->GetName();
#endif #endif
status_ = behaviac::BT_RUNNING; status_ = behaviac::BT_RUNNING;
return status_; return status_;

View File

@ -27,7 +27,7 @@ namespace a8
} }
} }
struct BtCoroutine; class BtCoroutine;
class Creature; class Creature;
class BaseAgent : public behaviac::Agent class BaseAgent : public behaviac::Agent
{ {

View File

@ -9,8 +9,8 @@
bool BtCoroutine::HasEvent() bool BtCoroutine::HasEvent()
{ {
if (!context->events.empty()) { if (!context_->events.empty()) {
auto event = context->events.at(context->events.size() - 1); auto event = context_->events.at(context_->events.size() - 1);
return event->HasEvent(); return event->HasEvent();
} }
return false; return false;
@ -18,8 +18,8 @@ bool BtCoroutine::HasEvent()
void BtCoroutine::FireEvent(BaseAgent* agent) void BtCoroutine::FireEvent(BaseAgent* agent)
{ {
if (!context->events.empty()) { if (!context_->events.empty()) {
auto event = context->events.at(context->events.size() - 1); auto event = context_->events.at(context_->events.size() - 1);
if (event->HasEvent()) { if (event->HasEvent()) {
event->FireEvent(agent); event->FireEvent(agent);
} }

View File

@ -5,20 +5,26 @@
struct BtContext; struct BtContext;
class BaseAgent; class BaseAgent;
struct BtCoroutine class BtCoroutine
{ {
std::shared_ptr<BtContext> context; public:
const char* name = nullptr;
std::function<behaviac::EBTStatus()> runing_cb; std::function<behaviac::EBTStatus()> runing_cb;
long long sleep_end_frameno = 0; long long sleep_end_frameno = 0;
int sleep_time = 0; int sleep_time = 0;
BtCoroutine(std::shared_ptr<BtContext> context, const char* name) BtCoroutine(std::shared_ptr<BtContext> context, const char* name)
{ {
this->context = context; this->context_ = context;
this->name = name; this->name_ = name;
} }
bool HasEvent(); bool HasEvent();
void FireEvent(BaseAgent* agent); void FireEvent(BaseAgent* agent);
const char* GetName() const { return name_; }
private:
std::shared_ptr<BtContext> context_;
const char* name_ = nullptr;
}; };