refactor: remove new Vec3

This commit is contained in:
orng 2026-03-26 14:01:14 -05:00
parent 9fe3315112
commit 87e8078a65
13 changed files with 87 additions and 84 deletions

View file

@ -12,7 +12,7 @@
ApplySchematicRuleDefinition::ApplySchematicRuleDefinition(
LevelGenerationOptions* levelGenOptions) {
m_levelGenOptions = levelGenOptions;
m_location = new Vec3(0, 0, 0);
m_location = Vec3(0, 0, 0);
m_locationBox = NULL;
m_totalBlocksChanged = 0;
m_totalBlocksChangedLighting = 0;
@ -26,7 +26,6 @@ ApplySchematicRuleDefinition::~ApplySchematicRuleDefinition() {
app.DebugPrintf("Deleting ApplySchematicRuleDefinition.\n");
if (!m_completed) m_levelGenOptions->releaseSchematicFile(m_schematicName);
m_schematic = NULL;
delete m_location;
}
void ApplySchematicRuleDefinition::writeAttributes(DataOutputStream* dos,
@ -36,11 +35,11 @@ void ApplySchematicRuleDefinition::writeAttributes(DataOutputStream* dos,
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_filename);
dos->writeUTF(m_schematicName);
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x);
dos->writeUTF(_toString(m_location->x));
dos->writeUTF(_toString(m_location.x));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y);
dos->writeUTF(_toString(m_location->y));
dos->writeUTF(_toString(m_location.y));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z);
dos->writeUTF(_toString(m_location->z));
dos->writeUTF(_toString(m_location.z));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_rot);
switch (m_rotation) {
@ -76,19 +75,19 @@ void ApplySchematicRuleDefinition::addAttribute(
m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName);
}
} else if (attributeName.compare(L"x") == 0) {
m_location->x = _fromString<int>(attributeValue);
if (((int)abs(m_location->x)) % 2 != 0) m_location->x -= 1;
m_location.x = _fromString<int>(attributeValue);
if (((int)abs(m_location.x)) % 2 != 0) m_location.x -= 1;
// app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter
// x=%f\n",m_location->x);
} else if (attributeName.compare(L"y") == 0) {
m_location->y = _fromString<int>(attributeValue);
if (((int)abs(m_location->y)) % 2 != 0) m_location->y -= 1;
if (m_location->y < 0) m_location->y = 0;
m_location.y = _fromString<int>(attributeValue);
if (((int)abs(m_location.y)) % 2 != 0) m_location.y -= 1;
if (m_location.y < 0) m_location.y = 0;
// app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter
// y=%f\n",m_location->y);
} else if (attributeName.compare(L"z") == 0) {
m_location->z = _fromString<int>(attributeValue);
if (((int)abs(m_location->z)) % 2 != 0) m_location->z -= 1;
m_location.z = _fromString<int>(attributeValue);
if (((int)abs(m_location.z)) % 2 != 0) m_location.z -= 1;
// app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter
// z=%f\n",m_location->z);
} else if (attributeName.compare(L"rot") == 0) {
@ -133,23 +132,23 @@ void ApplySchematicRuleDefinition::updateLocationBox() {
m_locationBox = AABB::newPermanent(0, 0, 0, 0, 0, 0);
m_locationBox->x0 = m_location->x;
m_locationBox->y0 = m_location->y;
m_locationBox->z0 = m_location->z;
m_locationBox->x0 = m_location.x;
m_locationBox->y0 = m_location.y;
m_locationBox->z0 = m_location.z;
m_locationBox->y1 = m_location->y + m_schematic->getYSize();
m_locationBox->y1 = m_location.y + m_schematic->getYSize();
switch (m_rotation) {
case ConsoleSchematicFile::eSchematicRot_90:
case ConsoleSchematicFile::eSchematicRot_270:
m_locationBox->x1 = m_location->x + m_schematic->getZSize();
m_locationBox->z1 = m_location->z + m_schematic->getXSize();
m_locationBox->x1 = m_location.x + m_schematic->getZSize();
m_locationBox->z1 = m_location.z + m_schematic->getXSize();
break;
case ConsoleSchematicFile::eSchematicRot_0:
case ConsoleSchematicFile::eSchematicRot_180:
default:
m_locationBox->x1 = m_location->x + m_schematic->getXSize();
m_locationBox->z1 = m_location->z + m_schematic->getZSize();
m_locationBox->x1 = m_location.x + m_schematic->getXSize();
m_locationBox->z1 = m_location.z + m_schematic->getZSize();
break;
};
}

View file

@ -13,7 +13,7 @@ private:
LevelGenerationOptions* m_levelGenOptions;
std::wstring m_schematicName;
ConsoleSchematicFile* m_schematic;
Vec3* m_location;
Vec3 m_location;
AABB* m_locationBox;
ConsoleSchematicFile::ESchematicRotation m_rotation;
int m_dimension;
@ -51,4 +51,4 @@ public:
* Reset any state to how it should be before a new game.
*/
void reset();
};
};

View file

@ -155,8 +155,7 @@ void ConsoleSchematicFile::load(DataInputStream* dis) {
// app.DebugPrintf(1,"Loaded entity type %d at
// (%f,%f,%f)\n",(int)type,x,y,z);
#endif
m_entities.push_back(std::pair<Vec3*, CompoundTag*>(
new Vec3(x, y, z), (CompoundTag*)eTag->copy()));
m_entities.push_back(std::pair<Vec3, CompoundTag*>(Vec3(x, y, z), (CompoundTag*)eTag->copy()));
}
}
delete tag;
@ -500,12 +499,12 @@ void ConsoleSchematicFile::applyTileEntities(LevelChunk* chunk, AABB* chunkBox,
}
}
for (AUTO_VAR(it, m_entities.begin()); it != m_entities.end();) {
Vec3* source = it->first;
Vec3 source = it->first;
double targetX = source->x;
double targetY = source->y + destinationBox->y0;
double targetZ = source->z;
schematicCoordToChunkCoord(destinationBox, source->x, source->z, rot,
double targetX = source.x;
double targetY = source.y + destinationBox->y0;
double targetZ = source.z;
schematicCoordToChunkCoord(destinationBox, source.x, source.z, rot,
targetX, targetZ);
// Add 0.01 as the AABB::contains function returns false if a value is

View file

@ -54,7 +54,7 @@ public:
private:
int m_xSize, m_ySize, m_zSize;
std::vector<std::shared_ptr<TileEntity> > m_tileEntities;
std::vector<std::pair<Vec3*, CompoundTag*> > m_entities;
std::vector<std::pair<Vec3, CompoundTag*> > m_entities;
public:
byteArray m_data;

View file

@ -90,7 +90,7 @@ GameRenderer::GameRenderer(Minecraft* mc) {
tickSmoothYO = 0;
lastTickA = 0;
cameraPos = new Vec3(0.0f, 0.0f, 0.0f);
cameraPos = Vec3(0.0f, 0.0f, 0.0f);
fovOffset = 0;
fovOffsetO = 0;
@ -1370,10 +1370,10 @@ void GameRenderer::renderLevel(float a, int64_t until) {
// Gameplay: Items and mobs not belonging to end world are
// disappearing when Enderdragon is damaged.
Vec3 cameraPosTemp = cameraEntity->getPos(a);
cameraPos->x = cameraPosTemp.x;
cameraPos->y = cameraPosTemp.y;
cameraPos->z = cameraPosTemp.z;
levelRenderer->renderEntities(cameraPos, frustum, a);
cameraPos.x = cameraPosTemp.x;
cameraPos.y = cameraPosTemp.y;
cameraPos.z = cameraPosTemp.z;
levelRenderer->renderEntities(&cameraPos, frustum, a);
#ifdef __PSVITA__
// AP - make sure we're using the Alpha cut out effect for particles
glEnable(GL_ALPHA_TEST);

View file

@ -50,7 +50,7 @@ private:
float thirdTiltO;
float accumulatedSmoothXO, accumulatedSmoothYO;
float tickSmoothXO, tickSmoothYO, lastTickA;
Vec3* cameraPos; // 4J added
Vec3 cameraPos; // 4J added
// fov modification
float fovOffset;

View file

@ -45,8 +45,8 @@ void _Polygon::mirror() {
}
void _Polygon::render(Tesselator* t, float scale) {
Vec3 v0 = vertices[1]->pos->vectorTo(*vertices[0]->pos);
Vec3 v1 = vertices[1]->pos->vectorTo(*vertices[2]->pos);
Vec3 v0 = vertices[1]->pos.vectorTo(vertices[0]->pos);
Vec3 v1 = vertices[1]->pos.vectorTo(vertices[2]->pos);
Vec3 n = v1.cross(v0).normalize();
t->begin();
@ -58,8 +58,8 @@ void _Polygon::render(Tesselator* t, float scale) {
for (int i = 0; i < 4; i++) {
Vertex* v = vertices[i];
t->vertexUV((float)(v->pos->x * scale), (float)(v->pos->y * scale),
(float)(v->pos->z * scale), (float)(v->u), (float)(v->v));
t->vertexUV((float)(v->pos.x * scale), (float)(v->pos.y * scale),
(float)(v->pos.z * scale), (float)(v->u), (float)(v->v));
}
t->end();
}

View file

@ -2,7 +2,7 @@
#include "Vertex.h"
Vertex::Vertex(float x, float y, float z, float u, float v) {
this->pos = new Vec3(x, y, z);
this->pos = Vec3(x, y, z);
this->u = u;
this->v = v;
}
@ -16,7 +16,7 @@ Vertex::Vertex(Vertex* vertex, float u, float v) {
}
Vertex::Vertex(Vec3* pos, float u, float v) {
this->pos = pos;
this->pos = *pos;
this->u = u;
this->v = v;
}

View file

@ -3,7 +3,7 @@
class Vertex {
public:
Vec3* pos;
Vec3 pos;
float u, v;
public:
@ -11,4 +11,4 @@ public:
Vertex* remap(float u, float v);
Vertex(Vertex* vertex, float u, float v);
Vertex(Vec3* pos, float u, float v);
};
};

View file

@ -20,7 +20,7 @@ PathNavigation::PathNavigation(Mob* mob, Level* level) {
avoidSun = false;
_tick = 0;
lastStuckCheck = 0;
lastStuckCheckPos = new Vec3(0, 0, 0);
lastStuckCheckPos = Vec3(0, 0, 0);
_canPassDoors = true;
_canOpenDoors = false;
avoidWater = false;
@ -29,7 +29,6 @@ PathNavigation::PathNavigation(Mob* mob, Level* level) {
PathNavigation::~PathNavigation() {
if (path != NULL) delete path;
delete lastStuckCheckPos;
}
void PathNavigation::setAvoidWater(bool avoidWater) {
@ -112,9 +111,9 @@ bool PathNavigation::moveTo(Path* newPath, double speedModifier) {
this->speedModifier = speedModifier;
Vec3 mobPos = getTempMobPos();
lastStuckCheck = _tick;
lastStuckCheckPos->x = mobPos.x;
lastStuckCheckPos->y = mobPos.y;
lastStuckCheckPos->z = mobPos.z;
lastStuckCheckPos.x = mobPos.x;
lastStuckCheckPos.y = mobPos.y;
lastStuckCheckPos.z = mobPos.z;
return true;
}
@ -161,8 +160,7 @@ void PathNavigation::updatePath() {
int sz = sx;
for (int i = firstElevation - 1; i >= path->getIndex(); --i) {
Vec3 mob_pos = path->getPos(mob->shared_from_this(), i);
if (canMoveDirectly(&mobPos, &mob_pos,
sx, sy, sz)) {
if (canMoveDirectly(&mobPos, &mob_pos, sx, sy, sz)) {
path->setIndex(i);
break;
}
@ -170,11 +168,11 @@ void PathNavigation::updatePath() {
// stuck detection (probably pushed off path)
if (_tick - lastStuckCheck > 100) {
if (mobPos.distanceToSqr(*lastStuckCheckPos) < 1.5 * 1.5) stop();
if (mobPos.distanceToSqr(lastStuckCheckPos) < 1.5 * 1.5) stop();
lastStuckCheck = _tick;
lastStuckCheckPos->x = mobPos.x;
lastStuckCheckPos->y = mobPos.y;
lastStuckCheckPos->z = mobPos.z;
lastStuckCheckPos.x = mobPos.x;
lastStuckCheckPos.y = mobPos.y;
lastStuckCheckPos.z = mobPos.z;
}
}

View file

@ -14,7 +14,7 @@ private:
bool avoidSun;
int _tick;
int lastStuckCheck;
Vec3* lastStuckCheckPos;
Vec3 lastStuckCheckPos;
bool _canPassDoors;
bool _canOpenDoors;

View file

@ -4,33 +4,36 @@
#include "RandomPos.h"
#include <optional>
Vec3* RandomPos::tempDir = new Vec3(0, 0, 0);
Vec3 RandomPos::tempDir = Vec3(0, 0, 0);
std::optional<Vec3> RandomPos::getPos(std::shared_ptr<PathfinderMob> mob, int xzDist,
int yDist, int quadrant /*=-1*/) // 4J - added quadrant
std::optional<Vec3> RandomPos::getPos(
std::shared_ptr<PathfinderMob> mob, int xzDist, int yDist,
int quadrant /*=-1*/) // 4J - added quadrant
{
return generateRandomPos(mob, xzDist, yDist, NULL, quadrant);
}
std::optional<Vec3> RandomPos::getPosTowards(std::shared_ptr<PathfinderMob> mob, int xzDist,
int yDist, Vec3* towardsPos) {
tempDir->x = towardsPos->x - mob->x;
tempDir->y = towardsPos->y - mob->y;
tempDir->z = towardsPos->z - mob->z;
return generateRandomPos(mob, xzDist, yDist, tempDir);
std::optional<Vec3> RandomPos::getPosTowards(std::shared_ptr<PathfinderMob> mob,
int xzDist, int yDist,
Vec3* towardsPos) {
tempDir.x = towardsPos->x - mob->x;
tempDir.y = towardsPos->y - mob->y;
tempDir.z = towardsPos->z - mob->z;
return generateRandomPos(mob, xzDist, yDist, &tempDir);
}
std::optional<Vec3> RandomPos::getPosAvoid(std::shared_ptr<PathfinderMob> mob, int xzDist,
int yDist, Vec3* avoidPos) {
tempDir->x = mob->x - avoidPos->x;
tempDir->y = mob->y - avoidPos->y;
tempDir->z = mob->z - avoidPos->z;
return generateRandomPos(mob, xzDist, yDist, tempDir);
std::optional<Vec3> RandomPos::getPosAvoid(std::shared_ptr<PathfinderMob> mob,
int xzDist, int yDist,
Vec3* avoidPos) {
tempDir.x = mob->x - avoidPos->x;
tempDir.y = mob->y - avoidPos->y;
tempDir.z = mob->z - avoidPos->z;
return generateRandomPos(mob, xzDist, yDist, &tempDir);
}
std::optional<Vec3> RandomPos::generateRandomPos(std::shared_ptr<PathfinderMob> mob,
int xzDist, int yDist, Vec3* dir,
int quadrant /*=-1*/) // 4J - added quadrant
std::optional<Vec3> RandomPos::generateRandomPos(
std::shared_ptr<PathfinderMob> mob, int xzDist, int yDist, Vec3* dir,
int quadrant /*=-1*/) // 4J - added quadrant
{
Random* random = mob->getRandom();
bool hasBest = false;

View file

@ -5,17 +5,21 @@ class PathfinderMob;
class RandomPos {
private:
static Vec3* tempDir;
static Vec3 tempDir;
public:
static std::optional<Vec3> getPos(std::shared_ptr<PathfinderMob> mob, int xzDist,
int yDist, int quadrant = -1); // 4J added quadrant
static std::optional<Vec3> getPosTowards(std::shared_ptr<PathfinderMob> mob, int xzDist,
int yDist, Vec3* towardsPos);
static std::optional<Vec3> getPosAvoid(std::shared_ptr<PathfinderMob> mob, int xzDist,
int yDist, Vec3* avoidPos);
static std::optional<Vec3> getPos(std::shared_ptr<PathfinderMob> mob,
int xzDist, int yDist,
int quadrant = -1); // 4J added quadrant
static std::optional<Vec3> getPosTowards(std::shared_ptr<PathfinderMob> mob,
int xzDist, int yDist,
Vec3* towardsPos);
static std::optional<Vec3> getPosAvoid(std::shared_ptr<PathfinderMob> mob,
int xzDist, int yDist,
Vec3* avoidPos);
private:
static std::optional<Vec3> generateRandomPos(std::shared_ptr<PathfinderMob> mob,
int xzDist, int yDist, Vec3* dir,
int quadrant = -1); // 4J added quadrant
static std::optional<Vec3> generateRandomPos(
std::shared_ptr<PathfinderMob> mob, int xzDist, int yDist, Vec3* dir,
int quadrant = -1); // 4J added quadrant
};