refactor(whip): applyDamage itera getActors() en lloc de getEntities()
This commit is contained in:
1 parent
881e0ea1f6
commit
6f8ab74d6b
1 file changed
+14
-7
@@ -299,19 +299,22 @@ namespace {
|
||||
// Tracta una mòmia candidata: si és whippable i la seua caja solapa
|
||||
// amb `damage_rect`, la posa a HURT i la marca al set. Extret per
|
||||
// acotar la complexitat cognitiva d'`applyDamage` (clang-tidy llindar).
|
||||
// Rep un `DynamicHazard*` (l'iterador d'`applyDamage` ja filtra el
|
||||
// sac d'actors); només cal el dynamic_cast a Mummy per descartar
|
||||
// altres hermanes (RollingRock i futurs DynamicHazards no whippables).
|
||||
void hitMummyIfApplicable(
|
||||
Entity* e,
|
||||
DynamicHazard* actor,
|
||||
const SDL_FRect& damage_rect,
|
||||
WhipAttack::Direction dir,
|
||||
std::unordered_set<void*>& already_hit) {
|
||||
if (e == nullptr || e->isDead()) { return; }
|
||||
if (already_hit.contains(static_cast<void*>(e))) { return; }
|
||||
auto* mummy = dynamic_cast<Mummy*>(e);
|
||||
if (actor == nullptr || actor->isDead()) { return; }
|
||||
if (already_hit.contains(static_cast<void*>(actor))) { return; }
|
||||
auto* mummy = dynamic_cast<Mummy*>(actor);
|
||||
if (mummy == nullptr || !mummy->isWhippable()) { return; }
|
||||
const auto BOX = mummy->getCollisionRect();
|
||||
if (!SDL_HasRectIntersectionFloat(&damage_rect, &BOX)) { return; }
|
||||
mummy->enterHurt(whipDirToMummyDir(dir));
|
||||
already_hit.insert(static_cast<void*>(e));
|
||||
already_hit.insert(static_cast<void*>(actor));
|
||||
}
|
||||
|
||||
void hitPlayerIfApplicable(
|
||||
@@ -336,8 +339,12 @@ namespace {
|
||||
|
||||
void WhipAttack::applyDamage() {
|
||||
if (entity_manager_ != nullptr) {
|
||||
for (auto* e : entity_manager_->getEntities()) {
|
||||
hitMummyIfApplicable(e, damage_rect_, direction_, already_hit_);
|
||||
// Només els actors poden rebre el fuetejo (decoracions, sarcs,
|
||||
// forats... no són hits del whip). Iterem el sac `actors_`
|
||||
// directament — sense recórrer tot el mapa per descartar-ne la
|
||||
// major part.
|
||||
for (auto* actor : entity_manager_->getActors()) {
|
||||
hitMummyIfApplicable(actor, damage_rect_, direction_, already_hit_);
|
||||
}
|
||||
}
|
||||
if (players_ != nullptr) {
|
||||
|
||||
Reference in new issue
Block a user