From 7074f35e4ba831e358117842b99ee35b87f85ae5 Mon Sep 17 00:00:00 2001 From: void_17 Date: Mon, 2 Mar 2026 15:58:20 +0700 Subject: shared_ptr -> std::shared_ptr This is one of the first commits in a plan to remove all `using namespace std;` lines in the entire codebase as it is considered anti-pattern today. --- Minecraft.World/Village.cpp | 46 ++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'Minecraft.World/Village.cpp') diff --git a/Minecraft.World/Village.cpp b/Minecraft.World/Village.cpp index aef38066..51e89c25 100644 --- a/Minecraft.World/Village.cpp +++ b/Minecraft.World/Village.cpp @@ -8,7 +8,7 @@ #include "BasicTypeContainers.h" #include "Village.h" -Village::Aggressor::Aggressor(shared_ptr mob, int timeStamp) +Village::Aggressor::Aggressor(std::shared_ptr mob, int timeStamp) { this->mob = mob; this->timeStamp = timeStamp; @@ -71,7 +71,7 @@ void Village::tick(int tick) Vec3 *spawnPos = findRandomSpawnPos(center->x, center->y, center->z, 2, 4, 2); if (spawnPos != NULL) { - shared_ptr vg = shared_ptr( new VillagerGolem(level) ); + std::shared_ptr vg = std::shared_ptr( new VillagerGolem(level) ); vg->setPos(spawnPos->x, spawnPos->y, spawnPos->z); level->addEntity(vg); ++golemCount; @@ -123,14 +123,14 @@ bool Village::canSpawnAt(int x, int y, int z, int sx, int sy, int sz) void Village::countGolem() { // Fix - let bots report themselves? - vector > *golems = level->getEntitiesOfClass(typeid(VillagerGolem), AABB::newTemp(center->x - radius, center->y - 4, center->z - radius, center->x + radius, center->y + 4, center->z + radius)); + vector > *golems = level->getEntitiesOfClass(typeid(VillagerGolem), AABB::newTemp(center->x - radius, center->y - 4, center->z - radius, center->x + radius, center->y + 4, center->z + radius)); golemCount = golems->size(); delete golems; } void Village::countPopulation() { - vector > *villagers = level->getEntitiesOfClass(typeid(Villager), AABB::newTemp(center->x - radius, center->y - 4, center->z - radius, center->x + radius, center->y + 4, center->z + radius)); + vector > *villagers = level->getEntitiesOfClass(typeid(Villager), AABB::newTemp(center->x - radius, center->y - 4, center->z - radius, center->x + radius, center->y + 4, center->z + radius)); populationSize = villagers->size(); delete villagers; @@ -171,19 +171,19 @@ bool Village::isInside(int xx, int yy, int zz) return center->distSqr(xx, yy, zz) < radius * radius; } -vector > *Village::getDoorInfos() +vector > *Village::getDoorInfos() { return &doorInfos; } -shared_ptr Village::getClosestDoorInfo(int x, int y, int z) +std::shared_ptr Village::getClosestDoorInfo(int x, int y, int z) { - shared_ptr closest = nullptr; + std::shared_ptr closest = nullptr; int closestDistSqr = Integer::MAX_VALUE; //for (DoorInfo dm : doorInfos) for(AUTO_VAR(it, doorInfos.begin()); it != doorInfos.end(); ++it) { - shared_ptr dm = *it; + std::shared_ptr dm = *it; int distSqr = dm->distanceToSqr(x, y, z); if (distSqr < closestDistSqr) { @@ -194,14 +194,14 @@ shared_ptr Village::getClosestDoorInfo(int x, int y, int z) return closest; } -shared_ptrVillage::getBestDoorInfo(int x, int y, int z) +std::shared_ptrVillage::getBestDoorInfo(int x, int y, int z) { - shared_ptr closest = nullptr; + std::shared_ptr closest = nullptr; int closestDist = Integer::MAX_VALUE; //for (DoorInfo dm : doorInfos) for(AUTO_VAR(it, doorInfos.begin()); it != doorInfos.end(); ++it) { - shared_ptrdm = *it; + std::shared_ptrdm = *it; int distSqr = dm->distanceToSqr(x, y, z); if (distSqr > 16 * 16) distSqr *= 1000; @@ -221,19 +221,19 @@ bool Village::hasDoorInfo(int x, int y, int z) return getDoorInfo(x, y, z) != NULL; } -shared_ptrVillage::getDoorInfo(int x, int y, int z) +std::shared_ptrVillage::getDoorInfo(int x, int y, int z) { if (center->distSqr(x, y, z) > radius * radius) return nullptr; //for (DoorInfo di : doorInfos) for(AUTO_VAR(it, doorInfos.begin()); it != doorInfos.end(); ++it) { - shared_ptr di = *it; + std::shared_ptr di = *it; if (di->x == x && di->z == z && abs(di->y - y) <= 1) return di; } return nullptr; } -void Village::addDoorInfo(shared_ptr di) +void Village::addDoorInfo(std::shared_ptr di) { doorInfos.push_back(di); accCenter->x += di->x; @@ -248,7 +248,7 @@ bool Village::canRemove() return doorInfos.empty(); } -void Village::addAggressor(shared_ptr mob) +void Village::addAggressor(std::shared_ptr mob) { //for (Aggressor a : aggressors) for(AUTO_VAR(it, aggressors.begin()); it != aggressors.end(); ++it) @@ -263,7 +263,7 @@ void Village::addAggressor(shared_ptr mob) aggressors.push_back(new Aggressor(mob, _tick)); } -shared_ptr Village::getClosestAggressor(shared_ptr from) +std::shared_ptr Village::getClosestAggressor(std::shared_ptr from) { double closestSqr = Double::MAX_VALUE; Aggressor *closest = NULL; @@ -279,10 +279,10 @@ shared_ptr Village::getClosestAggressor(shared_ptr from) return closest != NULL ? closest->mob : nullptr; } -shared_ptr Village::getClosestBadStandingPlayer(shared_ptr from) // 4J Stu - Should be LivingEntity when we add that +std::shared_ptr Village::getClosestBadStandingPlayer(std::shared_ptr from) // 4J Stu - Should be LivingEntity when we add that { double closestSqr = Double::MAX_VALUE; - shared_ptr closest = nullptr; + std::shared_ptr closest = nullptr; //for (String player : playerStanding.keySet()) for(AUTO_VAR(it,playerStanding.begin()); it != playerStanding.end(); ++it) @@ -290,7 +290,7 @@ shared_ptr Village::getClosestBadStandingPlayer(shared_ptr from) // wstring player = it->first; if (isVeryBadStanding(player)) { - shared_ptr mob = level->getPlayerByName(player); + std::shared_ptr mob = level->getPlayerByName(player); if (mob != NULL) { double distSqr = mob->distanceToSqr(from); @@ -330,7 +330,7 @@ void Village::updateDoors() //for (Iterator it = doorInfos.iterator(); it.hasNext();) for(AUTO_VAR(it, doorInfos.begin()); it != doorInfos.end();) { - shared_ptr dm = *it; //it.next(); + std::shared_ptr dm = *it; //it.next(); if (resetBookings) dm->resetBookingCount(); if (!isDoor(dm->x, dm->y, dm->z) || abs(_tick - dm->timeStamp) > 1200) { @@ -373,7 +373,7 @@ void Village::calcInfo() //for (DoorInfo dm : doorInfos) for(AUTO_VAR(it, doorInfos.begin()); it != doorInfos.end(); ++it) { - shared_ptr dm = *it; + std::shared_ptr dm = *it; maxRadiusSqr = max(dm->distanceToSqr(center->x, center->y, center->z), maxRadiusSqr); } int doorDist= Villages::MaxDoorDist; // Take into local int for PS4 as max takes a reference to the const int there and then needs the value to exist for the linker @@ -433,7 +433,7 @@ void Village::readAdditionalSaveData(CompoundTag *tag) { CompoundTag *dTag = doorTags->get(i); - shared_ptr door = shared_ptr(new DoorInfo(dTag->getInt(L"X"), dTag->getInt(L"Y"), dTag->getInt(L"Z"), dTag->getInt(L"IDX"), dTag->getInt(L"IDZ"), dTag->getInt(L"TS"))); + std::shared_ptr door = std::shared_ptr(new DoorInfo(dTag->getInt(L"X"), dTag->getInt(L"Y"), dTag->getInt(L"Z"), dTag->getInt(L"IDX"), dTag->getInt(L"IDZ"), dTag->getInt(L"TS"))); doorInfos.push_back(door); } @@ -464,7 +464,7 @@ void Village::addAdditonalSaveData(CompoundTag *tag) //for (DoorInfo dm : doorInfos) for(AUTO_VAR(it,doorInfos.begin()); it != doorInfos.end(); ++it) { - shared_ptr dm = *it; + std::shared_ptr dm = *it; CompoundTag *doorTag = new CompoundTag(L"Door"); doorTag->putInt(L"X", dm->x); doorTag->putInt(L"Y", dm->y); -- cgit v1.2.3