refactor: make AABBList own its values

This commit is contained in:
orng 2026-03-27 22:37:22 -05:00
parent d7d99db4c5
commit 78b5255224
7 changed files with 23 additions and 40 deletions

View file

@ -3862,12 +3862,6 @@ LevelRenderer::DestroyedTileManager::RecentTile::RecentTile(int x, int y, int z,
rebuilt = false;
}
LevelRenderer::DestroyedTileManager::RecentTile::~RecentTile() {
for (AUTO_VAR(it, boxes.begin()); it != boxes.end(); it++) {
delete *it;
}
}
LevelRenderer::DestroyedTileManager::DestroyedTileManager() {
InitializeCriticalSection(&m_csDestroyedTiles);
}
@ -3899,14 +3893,6 @@ void LevelRenderer::DestroyedTileManager::destroyingTileAt(Level* level, int x,
tile->addAABBs(level, x, y, z, &box, &recentTile->boxes, nullptr);
}
// Make these temporary AABBs into permanently allocated AABBs
for (unsigned int i = 0; i < recentTile->boxes.size(); i++) {
recentTile->boxes[i] =
new AABB(recentTile->boxes[i]->x0, recentTile->boxes[i]->y0,
recentTile->boxes[i]->z0, recentTile->boxes[i]->x1,
recentTile->boxes[i]->y1, recentTile->boxes[i]->z1);
}
m_destroyedTiles.push_back(recentTile);
LeaveCriticalSection(&m_csDestroyedTiles);
@ -3977,14 +3963,13 @@ void LevelRenderer::DestroyedTileManager::addAABBs(Level* level, AABB* box,
// interested in, add them to the output list, making a temp
// AABB copy so that we can destroy our own copy without
// worrying about the lifespan of the copy we've passed out
if (m_destroyedTiles[i]->boxes[j]->intersects(*box)) {
AABB bb(m_destroyedTiles[i]->boxes[j]->x0,
m_destroyedTiles[i]->boxes[j]->y0,
m_destroyedTiles[i]->boxes[j]->z0,
m_destroyedTiles[i]->boxes[j]->x1,
m_destroyedTiles[i]->boxes[j]->y1,
m_destroyedTiles[i]->boxes[j]->z1);
boxes->push_back(&bb);
if (m_destroyedTiles[i]->boxes[j].intersects(*box)) {
boxes->push_back({m_destroyedTiles[i]->boxes[j].x0,
m_destroyedTiles[i]->boxes[j].y0,
m_destroyedTiles[i]->boxes[j].z0,
m_destroyedTiles[i]->boxes[j].x1,
m_destroyedTiles[i]->boxes[j].y1,
m_destroyedTiles[i]->boxes[j].z1});
}
}
}

View file

@ -234,7 +234,7 @@ public:
int timeout_ticks;
bool rebuilt;
RecentTile(int x, int y, int z, Level* level);
~RecentTile();
~RecentTile() = default;
};
CRITICAL_SECTION m_csDestroyedTiles;
std::vector<RecentTile*> m_destroyedTiles;

View file

@ -2016,7 +2016,7 @@ AABB* Tile::getTileAABB(Level* level, int x, int y, int z) {
void Tile::addAABBs(Level* level, int x, int y, int z, AABB* box,
AABBList* boxes, std::shared_ptr<Entity> source) {
AABB* aabb = getAABB(level, x, y, z);
if (aabb != NULL && box->intersects(*aabb)) boxes->push_back(aabb);
if (aabb != NULL && box->intersects(*aabb)) boxes->push_back(*aabb);
}
AABB* Tile::getAABB(Level* level, int x, int y, int z) {

View file

@ -733,7 +733,7 @@ void Entity::move(double xa, double ya, double za,
// But if we don't have the chunk data then all the collision info will
// be incorrect as well
for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++)
ya = (*it)->clipYCollide(*bb, ya);
ya = it->clipYCollide(*bb, ya);
*bb = bb->move(0, ya, 0);
}
@ -745,7 +745,7 @@ void Entity::move(double xa, double ya, double za,
itEndAABB = aABBs->end();
for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++)
xa = (*it)->clipXCollide(*bb, xa);
xa = it->clipXCollide(*bb, xa);
*bb = bb->move(xa, 0, 0);
@ -755,7 +755,7 @@ void Entity::move(double xa, double ya, double za,
itEndAABB = aABBs->end();
for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++)
za = (*it)->clipZCollide(*bb, za);
za = it->clipZCollide(*bb, za);
*bb = bb->move(0, 0, za);
if (!slide && zaOrg != za) {
@ -789,7 +789,7 @@ void Entity::move(double xa, double ya, double za,
// all! But if we don't have the chunk data then all the collision
// info will be incorrect as well
for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++)
ya = (*it)->clipYCollide(*bb, ya);
ya = it->clipYCollide(*bb, ya);
*bb = bb->move(0, ya, 0);
}
@ -799,7 +799,7 @@ void Entity::move(double xa, double ya, double za,
itEndAABB = aABBs->end();
for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++)
xa = (*it)->clipXCollide(*bb, xa);
xa = it->clipXCollide(*bb, xa);
*bb = bb->move(xa, 0, 0);
if (!slide && xaOrg != xa) {
@ -808,7 +808,7 @@ void Entity::move(double xa, double ya, double za,
itEndAABB = aABBs->end();
for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++)
za = (*it)->clipZCollide(*bb, za);
za = it->clipZCollide(*bb, za);
*bb = bb->move(0, 0, za);
if (!slide && zaOrg != za) {
@ -822,7 +822,7 @@ void Entity::move(double xa, double ya, double za,
// LAND FIRST, then x and z
itEndAABB = aABBs->end();
for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++)
ya = (*it)->clipYCollide(*bb, ya);
ya = it->clipYCollide(*bb, ya);
*bb = bb->move(0, ya, 0);
}
@ -1526,8 +1526,7 @@ void Entity::lerpTo(double x, double y, double z, float yRot, float xRot,
double yTop = 0;
AUTO_VAR(itEnd, collisions->end());
for (AUTO_VAR(it, collisions->begin()); it != itEnd; it++) {
AABB* ab = *it; // collisions->at(i);
if (ab->y1 > yTop) yTop = ab->y1;
if (it->y1 > yTop) yTop = it->y1;
}
y += yTop - bb->y0;
@ -1668,7 +1667,7 @@ bool Entity::checkInTile(double x, double y, double z) {
double yd = y - (yTile);
double zd = z - (zTile);
std::vector<AABB*>* cubes = level->getTileCubes(bb);
auto* cubes = level->getTileCubes(bb);
if ((cubes && !cubes->empty()) ||
level->isFullAABBTile(xTile, yTile, zTile)) {
bool west = !level->isFullAABBTile(xTile - 1, yTile, zTile);

View file

@ -1518,8 +1518,7 @@ void LivingEntity::aiStep() {
double yTop = 0;
AUTO_VAR(itEnd, collisions->end());
for (AUTO_VAR(it, collisions->begin()); it != itEnd; it++) {
AABB* ab = *it; // collisions->at(i);
if (ab->y1 > yTop) yTop = ab->y1;
if (it->y1 > yTop) yTop = it->y1;
}
yt += yTop - bb->y0;

View file

@ -1805,12 +1805,12 @@ AABBList* Level::getCubes(std::shared_ptr<Entity> source, AABB* box,
for (AUTO_VAR(it, ee->begin()); it != itEnd; it++) {
AABB* collideBox = (*it)->getCollideBox();
if (collideBox != NULL && collideBox->intersects(*box)) {
boxes.push_back(collideBox);
boxes.push_back(*collideBox);
}
collideBox = source->getCollideAgainstBox(*it);
if (collideBox != NULL && collideBox->intersects(*box)) {
boxes.push_back(collideBox);
boxes.push_back(*collideBox);
}
}

View file

@ -4,7 +4,7 @@ class AABB;
class Recipy;
class Object;
typedef std::vector<AABB*> AABBList;
typedef std::vector<AABB> AABBList;
typedef std::vector<Recipy*> RecipyList;
typedef std::vector<Object*> ObjectList;
@ -34,4 +34,4 @@ enum EDefaultSkins {
eDefaultSkins_Skin7,
eDefaultSkins_Count,
};
};