refactor: modernize AABB class

This commit is contained in:
orng
2026-03-27 21:11:11 -05:00
parent da7cbcb4b6
commit 79217ca8e3
53 changed files with 362 additions and 357 deletions
@@ -272,8 +272,9 @@ void PlayerConnection::handleMovePlayer(
*/
float r = 1 / 16.0f;
AABB shrunk = player->bb->shrink(r, r, r);
bool oldOk =
level->getCubes(player, player->bb->copy()->shrink(r, r, r))
level->getCubes(player, &shrunk)
->empty();
if (player->onGround && !packet->onGround && yDist > 0) {
@@ -324,17 +325,19 @@ void PlayerConnection::handleMovePlayer(
}
player->absMoveTo(xt, yt, zt, yRotT, xRotT);
// TODO: check if this can be elided
shrunk = player->bb->shrink(r, r, r);
bool newOk =
level->getCubes(player, player->bb->copy()->shrink(r, r, r))
level->getCubes(player, &shrunk)
->empty();
if (oldOk && (fail || !newOk) && !player->isSleeping()) {
teleport(xLastOk, yLastOk, zLastOk, yRotT, xRotT);
return;
}
AABB* testBox = player->bb->copy()->grow(r, r, r)->expand(0, -0.55, 0);
AABB testBox = (*player->bb).grow(r, r, r).expand(0, -0.55, 0);
// && server.level.getCubes(player, testBox).size() == 0
if (!server->isFlightAllowed() && !player->gameMode->isCreative() &&
!level->containsAnyBlocks(testBox) && !player->isAllowedToFly()) {
!level->containsAnyBlocks(&testBox) && !player->isAllowedToFly()) {
if (oyDist >= (-0.5f / 16.0f)) {
aboveGroundTickCount++;
if (aboveGroundTickCount > 80) {
@@ -163,7 +163,7 @@ void ApplySchematicRuleDefinition::processSchematic(AABB* chunkBox,
m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName);
if (m_locationBox == NULL) updateLocationBox();
if (chunkBox->intersects(m_locationBox)) {
if (chunkBox->intersects(*m_locationBox)) {
m_locationBox->y1 =
std::min((double)Level::maxBuildHeight, m_locationBox->y1);
@@ -207,7 +207,7 @@ void ApplySchematicRuleDefinition::processSchematicLighting(AABB* chunkBox,
m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName);
if (m_locationBox == NULL) updateLocationBox();
if (chunkBox->intersects(m_locationBox)) {
if (chunkBox->intersects(*m_locationBox)) {
m_locationBox->y1 =
std::min((double)Level::maxBuildHeight, m_locationBox->y1);
@@ -464,7 +464,7 @@ void ConsoleSchematicFile::applyTileEntities(LevelChunk* chunk, AABB* chunkBox,
targetZ);
Vec3 pos(targetX, targetY, targetZ);
if (chunkBox->containsIncludingLowerBound(&pos)) {
if (chunkBox->containsIncludingLowerBound(pos)) {
std::shared_ptr<TileEntity> teCopy = chunk->getTileEntity(
(int)targetX & 15, (int)targetY & 15, (int)targetZ & 15);
@@ -511,7 +511,7 @@ void ConsoleSchematicFile::applyTileEntities(LevelChunk* chunk, AABB* chunkBox,
// Add 0.01 as the AABB::contains function returns false if a value is
// <= the lower bound
Vec3 pos(targetX + 0.01, targetY + 0.01, targetZ + 0.01);
if (!chunkBox->containsIncludingLowerBound(&pos)) {
if (!chunkBox->containsIncludingLowerBound(pos)) {
++it;
continue;
}
@@ -25,8 +25,10 @@ AreaConstraint::~AreaConstraint() {
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) {
@@ -40,7 +42,7 @@ 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);
@@ -28,7 +28,7 @@ int AreaHint::tick() {
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)) {
@@ -85,9 +85,11 @@ void ChangeStateConstraint::tick(int iPad) {
break;
}
}
// 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);
@@ -125,7 +127,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);
+2 -2
View File
@@ -509,9 +509,9 @@ void Chunk::rebuild() {
// 4J MGH - added this to take the bound from the value calc'd in the
// tesselator
if (bb) {
bb->set(bounds.boundingBox[0], bounds.boundingBox[1],
*bb = {bounds.boundingBox[0], bounds.boundingBox[1],
bounds.boundingBox[2], bounds.boundingBox[3],
bounds.boundingBox[4], bounds.boundingBox[5]);
bounds.boundingBox[4], bounds.boundingBox[5]};
}
delete tileRenderer;
+9 -8
View File
@@ -309,11 +309,12 @@ void GameRenderer::pick(float a) {
to = to.add(from.x, from.y, from.z);
hovered = nullptr;
float overlap = 1;
std::vector<std::shared_ptr<Entity> >* objects = mc->level->getEntities(
mc->cameraTargetPlayer,
mc->cameraTargetPlayer->bb
->expand(b.x * (range), b.y * (range), b.z * (range))
->grow(overlap, overlap, overlap));
AABB grown = mc->cameraTargetPlayer->bb
->expand(b.x * (range), b.y * (range), b.z * (range))
.grow(overlap, overlap, overlap);
std::vector<std::shared_ptr<Entity> >* objects =
mc->level->getEntities(mc->cameraTargetPlayer, &grown);
double nearest = dist;
AUTO_VAR(itEnd, objects->end());
@@ -322,9 +323,9 @@ void GameRenderer::pick(float a) {
if (!e->isPickable()) continue;
float rr = e->getPickRadius();
AABB* bb = e->bb->grow(rr, rr, rr);
HitResult* p = bb->clip(&from, &to);
if (bb->contains(&from)) {
AABB bb = e->bb->grow(rr, rr, rr);
HitResult* p = bb.clip(from, to);
if (bb.contains(from)) {
if (0 < nearest || nearest == 0) {
hovered = e;
nearest = 0;
+6 -3
View File
@@ -2479,10 +2479,13 @@ void LevelRenderer::renderHitOutline(std::shared_ptr<Player> player,
double xo = player->xOld + (player->x - player->xOld) * a;
double yo = player->yOld + (player->y - player->yOld) * a;
double zo = player->zOld + (player->z - player->zOld) * a;
render(Tile::tiles[tileId]
AABB bb = Tile::tiles[tileId]
->getTileAABB(level[iPad], h->x, h->y, h->z)
->grow(ss, ss, ss)
->cloneMove(-xo, -yo, -zo));
.move(-xo, -yo, -zo);
render(&bb);
}
glDepthMask(true);
glEnable(GL_TEXTURE_2D);
@@ -3974,7 +3977,7 @@ 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)) {
if (m_destroyedTiles[i]->boxes[j]->intersects(*box)) {
boxes->push_back(
AABB::newTemp(m_destroyedTiles[i]->boxes[j]->x0,
m_destroyedTiles[i]->boxes[j]->y0,