mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/4jcraft.git
synced 2026-07-13 04:58:33 +00:00
refactor: remove heap-allocated AABBs
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ class AABB;
|
||||
|
||||
class AreaConstraint : public TutorialConstraint {
|
||||
private:
|
||||
AABB* movementArea;
|
||||
AABB* messageArea;
|
||||
AABB movementArea;
|
||||
AABB messageArea;
|
||||
bool contains; // If true we must stay in this area, if false must stay out
|
||||
// of this area
|
||||
bool m_restrictsMovement;
|
||||
@@ -18,10 +18,9 @@ public:
|
||||
AreaConstraint(int descriptionId, double x0, double y0, double z0,
|
||||
double x1, double y1, double z1, bool contains = true,
|
||||
bool restrictsMovement = true);
|
||||
~AreaConstraint();
|
||||
|
||||
virtual bool isConstraintSatisfied(int iPad);
|
||||
virtual bool isConstraintRestrictive(int iPad);
|
||||
virtual bool canMoveToPosition(double xo, double yo, double zo, double xt,
|
||||
double yt, double zt);
|
||||
};
|
||||
};
|
||||
|
||||
@@ -12,7 +12,7 @@ AreaHint::AreaHint(eTutorial_Hint id, Tutorial* tutorial,
|
||||
double x1, double y1, double z1, bool allowFade /*= false*/,
|
||||
bool contains /*= true*/)
|
||||
: TutorialHint(id, tutorial, descriptionId, e_Hint_Area, allowFade) {
|
||||
area = new AABB(x0, y0, z0, x1, y1, z1);
|
||||
area = AABB(x0, y0, z0, x1, y1, z1);
|
||||
|
||||
this->contains = contains;
|
||||
|
||||
@@ -20,15 +20,13 @@ AreaHint::AreaHint(eTutorial_Hint id, Tutorial* tutorial,
|
||||
m_completeState = completeState;
|
||||
}
|
||||
|
||||
AreaHint::~AreaHint() { delete area; }
|
||||
|
||||
int AreaHint::tick() {
|
||||
Minecraft* minecraft = Minecraft::GetInstance();
|
||||
Vec3 player_pos = minecraft->player->getPos(1);
|
||||
|
||||
if ((m_displayState == e_Tutorial_State_Any ||
|
||||
m_tutorial->getCurrentState() == m_displayState) &&
|
||||
m_hintNeeded && area->contains(player_pos) == contains) {
|
||||
m_hintNeeded && area.contains(player_pos) == contains) {
|
||||
if (m_completeState == e_Tutorial_State_None) {
|
||||
m_hintNeeded = false;
|
||||
} else if (m_tutorial->isStateCompleted(m_completeState)) {
|
||||
|
||||
@@ -6,7 +6,7 @@ class AABB;
|
||||
|
||||
class AreaHint : public TutorialHint {
|
||||
private:
|
||||
AABB* area;
|
||||
AABB area;
|
||||
bool contains; // If true we must stay in this area, if false must stay out
|
||||
// of this area
|
||||
|
||||
@@ -21,7 +21,6 @@ public:
|
||||
eTutorial_State displayState, eTutorial_State completeState,
|
||||
int descriptionId, double x0, double y0, double z0, double x1,
|
||||
double y1, double z1, bool allowFade = true, bool contains = true);
|
||||
~AreaHint();
|
||||
|
||||
virtual int tick();
|
||||
};
|
||||
};
|
||||
|
||||
@@ -16,7 +16,7 @@ ChangeStateConstraint::ChangeStateConstraint(
|
||||
bool contains /*= true*/, bool changeGameMode /*= false*/,
|
||||
GameType* targetGameMode /*= 0*/)
|
||||
: TutorialConstraint(-1) {
|
||||
movementArea = new AABB(x0, y0, z0, x1, y1, z1);
|
||||
movementArea = AABB(x0, y0, z0, x1, y1, z1);
|
||||
|
||||
this->contains = contains;
|
||||
|
||||
@@ -40,7 +40,6 @@ ChangeStateConstraint::ChangeStateConstraint(
|
||||
}
|
||||
|
||||
ChangeStateConstraint::~ChangeStateConstraint() {
|
||||
delete movementArea;
|
||||
if (m_sourceStatesCount > 0) delete[] m_sourceStates;
|
||||
}
|
||||
|
||||
@@ -89,7 +88,7 @@ void ChangeStateConstraint::tick(int iPad) {
|
||||
// TODO: check if this can be elided
|
||||
Vec3 ipad_player = minecraft->localplayers[iPad]->getPos(1);
|
||||
if (!m_bHasChanged && inASourceState &&
|
||||
movementArea->contains(ipad_player) == contains) {
|
||||
movementArea.contains(ipad_player) == contains) {
|
||||
m_bHasChanged = true;
|
||||
m_changedFromState = m_tutorial->getCurrentState();
|
||||
m_tutorial->changeTutorialState(m_targetState);
|
||||
@@ -127,7 +126,7 @@ void ChangeStateConstraint::tick(int iPad) {
|
||||
}
|
||||
}
|
||||
} else if (m_bHasChanged &&
|
||||
movementArea->contains(ipad_player) != contains) {
|
||||
movementArea.contains(ipad_player) != contains) {
|
||||
m_bHasChanged = false;
|
||||
m_tutorial->changeTutorialState(m_changedFromState);
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ class GameType;
|
||||
|
||||
class ChangeStateConstraint : public TutorialConstraint {
|
||||
private:
|
||||
AABB* movementArea;
|
||||
AABB movementArea;
|
||||
bool contains; // If true we must stay in this area, if false must stay out
|
||||
// of this area
|
||||
bool m_changeGameMode;
|
||||
|
||||
Reference in New Issue
Block a user