diff --git a/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.cpp b/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.cpp index c7b2c0230..b2304fbdd 100644 --- a/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.cpp @@ -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(attributeValue); - if (((int)abs(m_location->x)) % 2 != 0) m_location->x -= 1; + m_location.x = _fromString(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(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(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(attributeValue); - if (((int)abs(m_location->z)) % 2 != 0) m_location->z -= 1; + m_location.z = _fromString(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; }; } diff --git a/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.h b/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.h index e3c5b425f..283c19586 100644 --- a/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.h +++ b/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.h @@ -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(); -}; \ No newline at end of file +}; diff --git a/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.cpp b/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.cpp index b9fec3328..e48113989 100644 --- a/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.cpp @@ -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( - new Vec3(x, y, z), (CompoundTag*)eTag->copy())); + m_entities.push_back(std::pair(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 diff --git a/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.h b/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.h index 1990328a8..adf862a0b 100644 --- a/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.h +++ b/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.h @@ -54,7 +54,7 @@ public: private: int m_xSize, m_ySize, m_zSize; std::vector > m_tileEntities; - std::vector > m_entities; + std::vector > m_entities; public: byteArray m_data; diff --git a/Minecraft.Client/Rendering/GameRenderer.cpp b/Minecraft.Client/Rendering/GameRenderer.cpp index d31ede749..6364b2ba1 100644 --- a/Minecraft.Client/Rendering/GameRenderer.cpp +++ b/Minecraft.Client/Rendering/GameRenderer.cpp @@ -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); diff --git a/Minecraft.Client/Rendering/GameRenderer.h b/Minecraft.Client/Rendering/GameRenderer.h index e3b4c0ca7..c359e45e2 100644 --- a/Minecraft.Client/Rendering/GameRenderer.h +++ b/Minecraft.Client/Rendering/GameRenderer.h @@ -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; diff --git a/Minecraft.Client/Rendering/Polygon.cpp b/Minecraft.Client/Rendering/Polygon.cpp index 6e5dd3d5f..44d65648b 100644 --- a/Minecraft.Client/Rendering/Polygon.cpp +++ b/Minecraft.Client/Rendering/Polygon.cpp @@ -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(); } diff --git a/Minecraft.Client/Rendering/Vertex.cpp b/Minecraft.Client/Rendering/Vertex.cpp index aaf37cc93..7222ed172 100644 --- a/Minecraft.Client/Rendering/Vertex.cpp +++ b/Minecraft.Client/Rendering/Vertex.cpp @@ -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; } diff --git a/Minecraft.Client/Rendering/Vertex.h b/Minecraft.Client/Rendering/Vertex.h index 99166d1ee..7c4492a8d 100644 --- a/Minecraft.Client/Rendering/Vertex.h +++ b/Minecraft.Client/Rendering/Vertex.h @@ -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); -}; \ No newline at end of file +}; diff --git a/Minecraft.World/AI/Navigation/PathNavigation.cpp b/Minecraft.World/AI/Navigation/PathNavigation.cpp index 5b670ec7d..62547c4f0 100644 --- a/Minecraft.World/AI/Navigation/PathNavigation.cpp +++ b/Minecraft.World/AI/Navigation/PathNavigation.cpp @@ -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; } } diff --git a/Minecraft.World/AI/Navigation/PathNavigation.h b/Minecraft.World/AI/Navigation/PathNavigation.h index 25130e1b0..0d5843281 100644 --- a/Minecraft.World/AI/Navigation/PathNavigation.h +++ b/Minecraft.World/AI/Navigation/PathNavigation.h @@ -14,7 +14,7 @@ private: bool avoidSun; int _tick; int lastStuckCheck; - Vec3* lastStuckCheckPos; + Vec3 lastStuckCheckPos; bool _canPassDoors; bool _canOpenDoors; diff --git a/Minecraft.World/AI/Navigation/RandomPos.cpp b/Minecraft.World/AI/Navigation/RandomPos.cpp index 1a804fbb9..4025cc9f3 100644 --- a/Minecraft.World/AI/Navigation/RandomPos.cpp +++ b/Minecraft.World/AI/Navigation/RandomPos.cpp @@ -4,33 +4,36 @@ #include "RandomPos.h" #include -Vec3* RandomPos::tempDir = new Vec3(0, 0, 0); +Vec3 RandomPos::tempDir = Vec3(0, 0, 0); -std::optional RandomPos::getPos(std::shared_ptr mob, int xzDist, - int yDist, int quadrant /*=-1*/) // 4J - added quadrant +std::optional RandomPos::getPos( + std::shared_ptr mob, int xzDist, int yDist, + int quadrant /*=-1*/) // 4J - added quadrant { return generateRandomPos(mob, xzDist, yDist, NULL, quadrant); } -std::optional RandomPos::getPosTowards(std::shared_ptr 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 RandomPos::getPosTowards(std::shared_ptr 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 RandomPos::getPosAvoid(std::shared_ptr 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 RandomPos::getPosAvoid(std::shared_ptr 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 RandomPos::generateRandomPos(std::shared_ptr mob, - int xzDist, int yDist, Vec3* dir, - int quadrant /*=-1*/) // 4J - added quadrant +std::optional RandomPos::generateRandomPos( + std::shared_ptr mob, int xzDist, int yDist, Vec3* dir, + int quadrant /*=-1*/) // 4J - added quadrant { Random* random = mob->getRandom(); bool hasBest = false; diff --git a/Minecraft.World/AI/Navigation/RandomPos.h b/Minecraft.World/AI/Navigation/RandomPos.h index 48e278ad0..b7bd8f394 100644 --- a/Minecraft.World/AI/Navigation/RandomPos.h +++ b/Minecraft.World/AI/Navigation/RandomPos.h @@ -5,17 +5,21 @@ class PathfinderMob; class RandomPos { private: - static Vec3* tempDir; + static Vec3 tempDir; public: - static std::optional getPos(std::shared_ptr mob, int xzDist, - int yDist, int quadrant = -1); // 4J added quadrant - static std::optional getPosTowards(std::shared_ptr mob, int xzDist, - int yDist, Vec3* towardsPos); - static std::optional getPosAvoid(std::shared_ptr mob, int xzDist, - int yDist, Vec3* avoidPos); + static std::optional getPos(std::shared_ptr mob, + int xzDist, int yDist, + int quadrant = -1); // 4J added quadrant + static std::optional getPosTowards(std::shared_ptr mob, + int xzDist, int yDist, + Vec3* towardsPos); + static std::optional getPosAvoid(std::shared_ptr mob, + int xzDist, int yDist, + Vec3* avoidPos); + private: - static std::optional generateRandomPos(std::shared_ptr mob, - int xzDist, int yDist, Vec3* dir, - int quadrant = -1); // 4J added quadrant + static std::optional generateRandomPos( + std::shared_ptr mob, int xzDist, int yDist, Vec3* dir, + int quadrant = -1); // 4J added quadrant };