From e2479261c56c8d1a64b51ad4f084ad3c18505359 Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Sun, 27 Jan 2019 10:10:33 +0500 Subject: GameState double-buffering --- src/World.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/World.cpp') diff --git a/src/World.cpp b/src/World.cpp index ffb657f..928c56a 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -14,7 +14,7 @@ void World::ParseChunkData(std::shared_ptr packet) { for (int i = 0; i < 16; i++) { if (bitmask[i]) { Vector chunkPosition = Vector(packet->ChunkX, i, packet->ChunkZ); - Section section = ParseSection(&chunkData, chunkPosition); + auto section = std::make_shared
(ParseSection(&chunkData, chunkPosition)); if (packet->GroundUpContinuous) { if (!sections.insert(std::make_pair(chunkPosition, section)).second) { @@ -125,7 +125,7 @@ const Section &World::GetSection(Vector sectionPos) { return fallbackSection; } else { - return result->second; + return *result->second; } } @@ -312,7 +312,7 @@ void World::ParseChunkData(std::shared_ptr packet) { } void World::ParseChunkData(std::shared_ptr packet) { - std::vector::iterator> toRemove; + std::vector>::iterator> toRemove; for (auto it = sections.begin(); it != sections.end(); ++it) { if (it->first.x == packet->ChunkX && it->first.z == packet->ChunkZ) toRemove.push_back(it); @@ -345,8 +345,9 @@ void World::SetBlockId(Vector pos, BlockId block) { std::floor(pos.y / 16.0), std::floor(pos.z / 16.0)); Vector blockPos = pos - (sectionPos * 16); - Section* section = GetSectionPtr(sectionPos); + auto section = std::make_shared
(*GetSectionPtr(sectionPos)); section->SetBlockId(blockPos, block); + sections[sectionPos] = section; PUSH_EVENT("ChunkChanged",sectionPos); if (blockPos.x == 0) PUSH_EVENT("ChunkChangedForce", sectionPos + Vector(-1, 0, 0)); @@ -376,7 +377,7 @@ Section *World::GetSectionPtr(Vector position) { if (it == sections.end()) return nullptr; - return &it->second; + return it->second.get(); } Entity* World::GetEntityPtr(unsigned int EntityId) { -- cgit v1.2.3