refactor: remove heap-allocated AABBs

This commit is contained in:
orng
2026-03-28 02:58:56 -05:00
parent e48a05bb8f
commit 7101d03c6a
88 changed files with 353 additions and 387 deletions

View File

@@ -10,25 +10,19 @@ AreaConstraint::AreaConstraint(int descriptionId, double x0, double y0,
bool contains /*= true*/,
bool restrictsMovement /*=true*/)
: TutorialConstraint(descriptionId) {
messageArea =
new AABB(x0 + 2, y0 + 2, z0 + 2, x1 - 2, y1 - 2, z1 - 2);
movementArea = new AABB(x0, y0, z0, x1, y1, z1);
messageArea = AABB(x0 + 2, y0 + 2, z0 + 2, x1 - 2, y1 - 2, z1 - 2);
movementArea = AABB(x0, y0, z0, x1, y1, z1);
this->contains = contains;
m_restrictsMovement = restrictsMovement;
}
AreaConstraint::~AreaConstraint() {
delete messageArea;
delete movementArea;
}
bool AreaConstraint::isConstraintSatisfied(int iPad) {
Minecraft* minecraft = Minecraft::GetInstance();
// TODO: check if this can be elided
Vec3 ipad_player = minecraft->localplayers[iPad]->getPos(1);
return messageArea->contains(ipad_player) == contains;
return messageArea.contains(ipad_player) == contains;
}
bool AreaConstraint::isConstraintRestrictive(int iPad) {
@@ -42,12 +36,12 @@ bool AreaConstraint::canMoveToPosition(double xo, double yo, double zo,
Vec3 targetPos(xt, yt, zt);
Minecraft* minecraft = Minecraft::GetInstance();
if (movementArea->contains(targetPos) == contains) {
if (movementArea.contains(targetPos) == contains) {
return true;
}
Vec3 origPos(xo, yo, zo);
double currDist = origPos.distanceTo(movementArea);
double targetDist = targetPos.distanceTo(movementArea);
double currDist = origPos.distanceTo(&movementArea);
double targetDist = targetPos.distanceTo(&movementArea);
return targetDist < currDist;
}