This commit is contained in:
aozhiwei 2021-09-22 08:37:19 +00:00
parent e0784dad49
commit 17443b9bcf
2 changed files with 18 additions and 0 deletions

View File

@ -12,6 +12,7 @@ class Global : public a8::Singleton<Global>
static int g_nowtime;
static ColliderComponent* last_collider;
int traversing_cell_creature_count = 0;
};
bool IsValidSlotId(int slot_id);

View File

@ -8,6 +8,7 @@
#include "hero.h"
#include "creature.h"
#include "bullet.h"
#include "global.h"
GridCell::GridCell()
{
@ -32,6 +33,7 @@ void GridCell::TraverseHumanList(std::function<void (Human*, bool&)> func,
int room_idx,
bool& stop)
{
++Global::Instance()->traversing_cell_creature_count;
for (Creature* c : creatures_[room_idx]) {
if (!c->IsHuman()) {
continue;
@ -39,21 +41,26 @@ void GridCell::TraverseHumanList(std::function<void (Human*, bool&)> func,
Human* hum = (Human*)c;
func(hum, stop);
if (stop) {
--Global::Instance()->traversing_cell_creature_count;
return;
}
}
--Global::Instance()->traversing_cell_creature_count;
}
void GridCell::TraverseCreatures(std::function<void (Creature*, bool&)>& func,
int room_idx,
bool& stop)
{
++Global::Instance()->traversing_cell_creature_count;
for (Creature* c : creatures_[room_idx]) {
func(c, stop);
if (stop) {
--Global::Instance()->traversing_cell_creature_count;
return;
}
}
--Global::Instance()->traversing_cell_creature_count;
}
void GridCell::AddPermanentEntity(Entity* entity)
@ -115,11 +122,21 @@ void GridCell::TraverseAllLayerEntityList(std::function<void (Entity*, bool&)>&
void GridCell::AddCreature(Creature* c)
{
#ifdef DEBUG
if (Global::Instance()->traversing_cell_creature_count > 0) {
abort();
}
#endif
creatures_[c->room->GetRoomIdx()].insert(c);
}
void GridCell::RemoveCreature(Creature* c)
{
#ifdef DEBUG
if (Global::Instance()->traversing_cell_creature_count > 0) {
abort();
}
#endif
creatures_[c->room->GetRoomIdx()].erase(c);
}