diff options
author | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2017-09-03 17:45:52 +0200 |
---|---|---|
committer | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2018-01-13 03:39:31 +0100 |
commit | 145ba8e157f79db64203db9684af2e6ed33af075 (patch) | |
tree | ec524120eaf2dda746d662297483be51fe626367 /src/World.cpp | |
parent | 2017-08-29 (diff) | |
download | AltCraft-145ba8e157f79db64203db9684af2e6ed33af075.tar AltCraft-145ba8e157f79db64203db9684af2e6ed33af075.tar.gz AltCraft-145ba8e157f79db64203db9684af2e6ed33af075.tar.bz2 AltCraft-145ba8e157f79db64203db9684af2e6ed33af075.tar.lz AltCraft-145ba8e157f79db64203db9684af2e6ed33af075.tar.xz AltCraft-145ba8e157f79db64203db9684af2e6ed33af075.tar.zst AltCraft-145ba8e157f79db64203db9684af2e6ed33af075.zip |
Diffstat (limited to '')
-rw-r--r-- | src/World.cpp | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/src/World.cpp b/src/World.cpp index 8f6bb5c..19eddbf 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -14,6 +14,7 @@ void World::ParseChunkData(std::shared_ptr<PacketChunkData> packet) { if (!sections.insert(std::make_pair(chunkPosition, section)).second) { LOG(ERROR) << "New chunk not created " << chunkPosition << " potential memory leak"; } + UpdateSectionList(); } else { using std::swap; swap(sections.at(chunkPosition), section); @@ -48,6 +49,7 @@ Section World::ParseSection(StreamInput *data, Vector position) { } World::~World() { + DebugInfo::totalSections = 0; } World::World() { @@ -86,7 +88,7 @@ bool World::isPlayerCollides(double X, double Y, double Z) { playerColl.z = Z - PlayerLength / 2.0; playerColl.l = PlayerLength; - const Section §ion = this->GetSection(it); + const Section §ion = *this->GetSection(it); for (int x = 0; x < 16; x++) { for (int y = 0; y < 16; y++) { for (int z = 0; z < 16; z++) { @@ -105,24 +107,18 @@ bool World::isPlayerCollides(double X, double Y, double Z) { return false; } -std::vector<Vector> World::GetSectionsList() { - std::vector<Vector> sectionsList; - for (auto& it : sections) { - if (std::find(sectionsList.begin(), sectionsList.end(), it.first) == sectionsList.end()) - sectionsList.push_back(it.first); - } - return sectionsList; +const std::vector<Vector>& World::GetSectionsList() { + return sectionsList; } static Section fallbackSection; -const Section &World::GetSection(Vector sectionPos) { +const Section* World::GetSection(Vector sectionPos) { auto result = sections.find(sectionPos); if (result == sections.end()) { - LOG(ERROR) << "Accessed not loaded section " << sectionPos; - return fallbackSection; + return nullptr; } else { - return result->second; + return &result->second; } } @@ -226,6 +222,14 @@ void World::ParseChunkData(std::shared_ptr<PacketUnloadChunk> packet) { } for (auto& it : toRemove) { EventAgregator::PushEvent(EventType::ChunkDeleted, ChunkDeletedData{ it->first }); - sections.erase(it); + sections.erase(it); + } + UpdateSectionList(); +} + +void World::UpdateSectionList() { + sectionsList.clear(); + for (auto& it : sections) { + sectionsList.push_back(it.first); } }
\ No newline at end of file |