mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/4jcraft.git
synced 2026-09-23 11:18:07 +00:00
refactor: make AABBList own its values
This commit is contained in:
@@ -3862,12 +3862,6 @@ LevelRenderer::DestroyedTileManager::RecentTile::RecentTile(int x, int y, int z,
|
|||||||
rebuilt = false;
|
rebuilt = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
LevelRenderer::DestroyedTileManager::RecentTile::~RecentTile() {
|
|
||||||
for (AUTO_VAR(it, boxes.begin()); it != boxes.end(); it++) {
|
|
||||||
delete *it;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LevelRenderer::DestroyedTileManager::DestroyedTileManager() {
|
LevelRenderer::DestroyedTileManager::DestroyedTileManager() {
|
||||||
InitializeCriticalSection(&m_csDestroyedTiles);
|
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);
|
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);
|
m_destroyedTiles.push_back(recentTile);
|
||||||
|
|
||||||
LeaveCriticalSection(&m_csDestroyedTiles);
|
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
|
// interested in, add them to the output list, making a temp
|
||||||
// AABB copy so that we can destroy our own copy without
|
// AABB copy so that we can destroy our own copy without
|
||||||
// worrying about the lifespan of the copy we've passed out
|
// worrying about the lifespan of the copy we've passed out
|
||||||
if (m_destroyedTiles[i]->boxes[j]->intersects(*box)) {
|
if (m_destroyedTiles[i]->boxes[j].intersects(*box)) {
|
||||||
AABB bb(m_destroyedTiles[i]->boxes[j]->x0,
|
boxes->push_back({m_destroyedTiles[i]->boxes[j].x0,
|
||||||
m_destroyedTiles[i]->boxes[j]->y0,
|
m_destroyedTiles[i]->boxes[j].y0,
|
||||||
m_destroyedTiles[i]->boxes[j]->z0,
|
m_destroyedTiles[i]->boxes[j].z0,
|
||||||
m_destroyedTiles[i]->boxes[j]->x1,
|
m_destroyedTiles[i]->boxes[j].x1,
|
||||||
m_destroyedTiles[i]->boxes[j]->y1,
|
m_destroyedTiles[i]->boxes[j].y1,
|
||||||
m_destroyedTiles[i]->boxes[j]->z1);
|
m_destroyedTiles[i]->boxes[j].z1});
|
||||||
boxes->push_back(&bb);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ public:
|
|||||||
int timeout_ticks;
|
int timeout_ticks;
|
||||||
bool rebuilt;
|
bool rebuilt;
|
||||||
RecentTile(int x, int y, int z, Level* level);
|
RecentTile(int x, int y, int z, Level* level);
|
||||||
~RecentTile();
|
~RecentTile() = default;
|
||||||
};
|
};
|
||||||
CRITICAL_SECTION m_csDestroyedTiles;
|
CRITICAL_SECTION m_csDestroyedTiles;
|
||||||
std::vector<RecentTile*> m_destroyedTiles;
|
std::vector<RecentTile*> m_destroyedTiles;
|
||||||
|
|||||||
@@ -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,
|
void Tile::addAABBs(Level* level, int x, int y, int z, AABB* box,
|
||||||
AABBList* boxes, std::shared_ptr<Entity> source) {
|
AABBList* boxes, std::shared_ptr<Entity> source) {
|
||||||
AABB* aabb = getAABB(level, x, y, z);
|
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) {
|
AABB* Tile::getAABB(Level* level, int x, int y, int z) {
|
||||||
|
|||||||
@@ -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
|
// But if we don't have the chunk data then all the collision info will
|
||||||
// be incorrect as well
|
// be incorrect as well
|
||||||
for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++)
|
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);
|
*bb = bb->move(0, ya, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -745,7 +745,7 @@ void Entity::move(double xa, double ya, double za,
|
|||||||
|
|
||||||
itEndAABB = aABBs->end();
|
itEndAABB = aABBs->end();
|
||||||
for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++)
|
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);
|
*bb = bb->move(xa, 0, 0);
|
||||||
|
|
||||||
@@ -755,7 +755,7 @@ void Entity::move(double xa, double ya, double za,
|
|||||||
|
|
||||||
itEndAABB = aABBs->end();
|
itEndAABB = aABBs->end();
|
||||||
for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++)
|
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);
|
*bb = bb->move(0, 0, za);
|
||||||
|
|
||||||
if (!slide && zaOrg != 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
|
// all! But if we don't have the chunk data then all the collision
|
||||||
// info will be incorrect as well
|
// info will be incorrect as well
|
||||||
for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++)
|
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);
|
*bb = bb->move(0, ya, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -799,7 +799,7 @@ void Entity::move(double xa, double ya, double za,
|
|||||||
|
|
||||||
itEndAABB = aABBs->end();
|
itEndAABB = aABBs->end();
|
||||||
for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++)
|
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);
|
*bb = bb->move(xa, 0, 0);
|
||||||
|
|
||||||
if (!slide && xaOrg != xa) {
|
if (!slide && xaOrg != xa) {
|
||||||
@@ -808,7 +808,7 @@ void Entity::move(double xa, double ya, double za,
|
|||||||
|
|
||||||
itEndAABB = aABBs->end();
|
itEndAABB = aABBs->end();
|
||||||
for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++)
|
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);
|
*bb = bb->move(0, 0, za);
|
||||||
|
|
||||||
if (!slide && zaOrg != za) {
|
if (!slide && zaOrg != za) {
|
||||||
@@ -822,7 +822,7 @@ void Entity::move(double xa, double ya, double za,
|
|||||||
// LAND FIRST, then x and z
|
// LAND FIRST, then x and z
|
||||||
itEndAABB = aABBs->end();
|
itEndAABB = aABBs->end();
|
||||||
for (AUTO_VAR(it, aABBs->begin()); it != itEndAABB; it++)
|
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);
|
*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;
|
double yTop = 0;
|
||||||
AUTO_VAR(itEnd, collisions->end());
|
AUTO_VAR(itEnd, collisions->end());
|
||||||
for (AUTO_VAR(it, collisions->begin()); it != itEnd; it++) {
|
for (AUTO_VAR(it, collisions->begin()); it != itEnd; it++) {
|
||||||
AABB* ab = *it; // collisions->at(i);
|
if (it->y1 > yTop) yTop = it->y1;
|
||||||
if (ab->y1 > yTop) yTop = ab->y1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
y += yTop - bb->y0;
|
y += yTop - bb->y0;
|
||||||
@@ -1668,7 +1667,7 @@ bool Entity::checkInTile(double x, double y, double z) {
|
|||||||
double yd = y - (yTile);
|
double yd = y - (yTile);
|
||||||
double zd = z - (zTile);
|
double zd = z - (zTile);
|
||||||
|
|
||||||
std::vector<AABB*>* cubes = level->getTileCubes(bb);
|
auto* cubes = level->getTileCubes(bb);
|
||||||
if ((cubes && !cubes->empty()) ||
|
if ((cubes && !cubes->empty()) ||
|
||||||
level->isFullAABBTile(xTile, yTile, zTile)) {
|
level->isFullAABBTile(xTile, yTile, zTile)) {
|
||||||
bool west = !level->isFullAABBTile(xTile - 1, yTile, zTile);
|
bool west = !level->isFullAABBTile(xTile - 1, yTile, zTile);
|
||||||
|
|||||||
@@ -1518,8 +1518,7 @@ void LivingEntity::aiStep() {
|
|||||||
double yTop = 0;
|
double yTop = 0;
|
||||||
AUTO_VAR(itEnd, collisions->end());
|
AUTO_VAR(itEnd, collisions->end());
|
||||||
for (AUTO_VAR(it, collisions->begin()); it != itEnd; it++) {
|
for (AUTO_VAR(it, collisions->begin()); it != itEnd; it++) {
|
||||||
AABB* ab = *it; // collisions->at(i);
|
if (it->y1 > yTop) yTop = it->y1;
|
||||||
if (ab->y1 > yTop) yTop = ab->y1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
yt += yTop - bb->y0;
|
yt += yTop - bb->y0;
|
||||||
|
|||||||
@@ -1805,12 +1805,12 @@ AABBList* Level::getCubes(std::shared_ptr<Entity> source, AABB* box,
|
|||||||
for (AUTO_VAR(it, ee->begin()); it != itEnd; it++) {
|
for (AUTO_VAR(it, ee->begin()); it != itEnd; it++) {
|
||||||
AABB* collideBox = (*it)->getCollideBox();
|
AABB* collideBox = (*it)->getCollideBox();
|
||||||
if (collideBox != NULL && collideBox->intersects(*box)) {
|
if (collideBox != NULL && collideBox->intersects(*box)) {
|
||||||
boxes.push_back(collideBox);
|
boxes.push_back(*collideBox);
|
||||||
}
|
}
|
||||||
|
|
||||||
collideBox = source->getCollideAgainstBox(*it);
|
collideBox = source->getCollideAgainstBox(*it);
|
||||||
if (collideBox != NULL && collideBox->intersects(*box)) {
|
if (collideBox != NULL && collideBox->intersects(*box)) {
|
||||||
boxes.push_back(collideBox);
|
boxes.push_back(*collideBox);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ class AABB;
|
|||||||
class Recipy;
|
class Recipy;
|
||||||
class Object;
|
class Object;
|
||||||
|
|
||||||
typedef std::vector<AABB*> AABBList;
|
typedef std::vector<AABB> AABBList;
|
||||||
typedef std::vector<Recipy*> RecipyList;
|
typedef std::vector<Recipy*> RecipyList;
|
||||||
typedef std::vector<Object*> ObjectList;
|
typedef std::vector<Object*> ObjectList;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user