This commit is contained in:
aozhiwei 2023-10-14 22:39:05 +08:00
parent e56e22232b
commit 4cd9e474f2
2 changed files with 5 additions and 9 deletions

View File

@ -333,20 +333,14 @@ behaviac::EBTStatus HeroAgent::CoIdle(int min_val, int max_val)
} }
auto context = MAKE_BTCONTEXT auto context = MAKE_BTCONTEXT
( (
a8::XTimerWp timer_ptr; int time = 0;
); );
context->timer_ptr = owner_->room->xtimer.SetTimeoutWpEx context->time = a8::RandEx(min_val, max_val);
(
a8::RandEx(min_val, max_val) / FRAME_RATE_MS,
[] (int event, const a8::Args* args)
{
},
&owner_->xtimer_attacher);
auto co = std::make_shared<BtCoroutine>(context, "CoIdle"); auto co = std::make_shared<BtCoroutine>(context, "CoIdle");
co->runing_cb = co->runing_cb =
[this, context] () [this, context] ()
{ {
if (!context->timer_ptr.expired()) { if (GetRoom()->GetFrameNo() - context->frameno < context->time) {
return behaviac::BT_RUNNING; return behaviac::BT_RUNNING;
} else { } else {
return behaviac::BT_SUCCESS; return behaviac::BT_SUCCESS;

View File

@ -9,10 +9,12 @@ class Context : public BtContext \
{public: \ {public: \
__VA_ARGS__; \ __VA_ARGS__; \
std::function<void()> _destory_cb; \ std::function<void()> _destory_cb; \
long long frameno = 0; \
~Context() { if (_destory_cb) { _destory_cb(); };}; \ ~Context() { if (_destory_cb) { _destory_cb(); };}; \
}; \ }; \
auto context = std::make_shared<Context>(); \ auto context = std::make_shared<Context>(); \
context->SetOwner(owner); \ context->SetOwner(owner); \
context->frameno = owner.Get()->room->GetFrameNo(); \
return context; \ return context; \
}(owner_->GetWeakPtrRef(), this) }(owner_->GetWeakPtrRef(), this)