diff options
Diffstat (limited to '')
-rw-r--r-- | src/world/Block.cpp (renamed from Block.cpp) | 0 | ||||
-rw-r--r-- | src/world/Block.hpp (renamed from Block.hpp) | 0 | ||||
-rw-r--r-- | src/world/Section.cpp (renamed from code/Section.cpp) | 5 | ||||
-rw-r--r-- | src/world/Section.hpp (renamed from code/Section.hpp) | 9 | ||||
-rw-r--r-- | src/world/World.cpp (renamed from code/World.cpp) | 16 | ||||
-rw-r--r-- | src/world/World.hpp (renamed from code/World.hpp) | 6 |
6 files changed, 22 insertions, 14 deletions
diff --git a/Block.cpp b/src/world/Block.cpp index 64e5330..64e5330 100644 --- a/Block.cpp +++ b/src/world/Block.cpp diff --git a/Block.hpp b/src/world/Block.hpp index 7c780c1..7c780c1 100644 --- a/Block.hpp +++ b/src/world/Block.hpp diff --git a/code/Section.cpp b/src/world/Section.cpp index 8df5953..f53c987 100644 --- a/code/Section.cpp +++ b/src/world/Section.cpp @@ -19,9 +19,6 @@ Section::Section(byte *dataBlocks, size_t dataBlocksLength, byte *dataLight, byt m_bitsPerBlock = bitsPerBlock; } -Section::Section() { -} - Section::~Section() { delete[] m_dataBlocks; m_dataBlocksLen = 0; @@ -32,7 +29,7 @@ Section::~Section() { m_dataSkyLight = nullptr; } -Block &Section::GetBlock(PositionI pos) { +Block &Section::GetBlock(Vector pos) { if (m_dataBlocks != nullptr) { std::mutex parseMutex; std::unique_lock<std::mutex> parseLocker(parseMutex); diff --git a/code/Section.hpp b/src/world/Section.hpp index 8e1a0d1..3065cbd 100644 --- a/code/Section.hpp +++ b/src/world/Section.hpp @@ -4,7 +4,7 @@ #include <map> #include <condition_variable> #include "Block.hpp" -#include "Field.hpp" +#include "../packet/Field.hpp" const int SECTION_WIDTH = 16; const int SECTION_LENGTH = 16; @@ -19,17 +19,18 @@ class Section { byte m_bitsPerBlock = 0; std::vector<Block> m_blocks; std::condition_variable parseWaiter; + + Section(); + public: void Parse(); Section(byte *dataBlocks, size_t dataBlocksLength, byte *dataLight, byte *dataSky, byte bitsPerBlock, std::vector<unsigned short> palette); - Section(); - ~Section(); - Block &GetBlock(PositionI pos); + Block &GetBlock(Vector pos); Section &operator=(Section other); diff --git a/code/World.cpp b/src/world/World.cpp index c19f88c..adbb3e1 100644 --- a/code/World.cpp +++ b/src/world/World.cpp @@ -21,13 +21,23 @@ void World::ParseChunkData(Packet packet) { for (int i = 0; i < 16; i++) { if (bitmask[i]) { size_t len = 0; - m_sections[PositionI(chunkX, chunkZ, i)] = ParseSection(content, len); - m_sectionToParse.push(m_sections.find(PositionI(chunkX, chunkZ, i))); - m_parseSectionWaiter.notify_one(); + Vector chunkPosition = Vector(chunkX, i, chunkZ); + if (!m_sections.insert(std::make_pair(chunkPosition,ParseSection(content,len))).second) + std::cout<<"Chunk not created: "<<chunkPosition<<std::endl; + auto sectionIter = m_sections.find(chunkPosition); + if (sectionIter==m_sections.end()) + std::cout<<"Created chunk not found: "<<chunkPosition<<std::endl; + else + sectionIter->second.Parse(); + /*m_sections[chunkPosition] = ParseSection(content, len); + m_sections[chunkPosition].Parse();*/ + /*m_sectionToParse.push(m_sections.find(Vector(chunkX, i, chunkZ))); + m_parseSectionWaiter.notify_one();*/ content += len; } } delete[] contentOrigPtr; + //std::cout<<m_sections.size()<<std::endl; } Section World::ParseSection(byte *data, size_t &dataLen) { diff --git a/code/World.hpp b/src/world/World.hpp index 1f35585..7b7ea60 100644 --- a/code/World.hpp +++ b/src/world/World.hpp @@ -6,7 +6,7 @@ #include <condition_variable> #include <queue> #include "Block.hpp" -#include "Packet.hpp" +#include "../packet/Packet.hpp" #include "Section.hpp" class World { @@ -17,7 +17,7 @@ class World { std::mutex m_parseSectionMutex; std::condition_variable m_parseSectionWaiter; std::thread m_sectionParseThread; - std::queue<std::map<PositionI,Section>::iterator> m_sectionToParse; + std::queue<std::map<Vector,Section>::iterator> m_sectionToParse; //utility methods void SectionParsingThread(); //game vars @@ -28,5 +28,5 @@ public: World(); ~World(); void ParseChunkData(Packet packet); - std::map<PositionI, Section> m_sections; + std::map<Vector, Section> m_sections; };
\ No newline at end of file |