This commit is contained in:
aozhiwei 2022-10-28 15:11:55 +08:00
parent 090cea717b
commit 8ff4411274

View File

@ -3330,9 +3330,11 @@ void Creature::AutoNavigation(a8::Vec2 target_pos, float speed,
{ {
float distance = GetPos().Distance(target_pos); float distance = GetPos().Distance(target_pos);
if (distance < 0.001f) { if (distance < 0.001f) {
cb(this);
return; return;
} }
if (speed < 0.001f) { if (speed < 0.001f) {
cb(this);
return; return;
} }
@ -3345,6 +3347,7 @@ void Creature::AutoNavigation(a8::Vec2 target_pos, float speed,
int exec_frameno = 0; int exec_frameno = 0;
float speed = 0.0f; float speed = 0.0f;
float distance = 0.0f; float distance = 0.0f;
std::function<void (Creature*)> cb;
}; };
NavContext* context = new NavContext(); NavContext* context = new NavContext();
context->c = GetWeakPtrRef(); context->c = GetWeakPtrRef();
@ -3354,6 +3357,7 @@ void Creature::AutoNavigation(a8::Vec2 target_pos, float speed,
context->dir.Normalize(); context->dir.Normalize();
context->speed = speed; context->speed = speed;
context->distance = distance; context->distance = distance;
context->cb = cb;
IncDisableMoveTimes(); IncDisableMoveTimes();
room->xtimer.AddRepeatTimerAndAttach room->xtimer.AddRepeatTimerAndAttach
@ -3397,6 +3401,7 @@ void Creature::AutoNavigation(a8::Vec2 target_pos, float speed,
} }
if (ok || c->dead) { if (ok || c->dead) {
context->cb(c);
c->DecDisableMoveTimes(); c->DecDisableMoveTimes();
delete context; delete context;
room->xtimer.DeleteTimer(room->xtimer.GetRunningTimer()); room->xtimer.DeleteTimer(room->xtimer.GetRunningTimer());