From d93c2073896e63aca5a859fe7182ba24dbe84cd3 Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Sun, 28 May 2017 19:16:05 +0500 Subject: 2017-05-28 --- src/world/Block.cpp | 4 +--- src/world/Block.hpp | 4 +--- src/world/Section.cpp | 2 +- src/world/World.cpp | 20 +------------------- src/world/World.hpp | 18 +++++++++--------- 5 files changed, 13 insertions(+), 35 deletions(-) (limited to 'src/world') diff --git a/src/world/Block.cpp b/src/world/Block.cpp index 3cf09db..54b7e5e 100644 --- a/src/world/Block.cpp +++ b/src/world/Block.cpp @@ -2,9 +2,7 @@ Block::~Block() {} -Block::Block(unsigned short idAndState, unsigned char light) : id(idAndState >> 4), state(idAndState & 0x0F) {} - -Block::Block(unsigned short id, unsigned char state, unsigned char light) : id(id), state(state) {} +Block::Block(unsigned short id, unsigned short state, unsigned char light) : id(id), state(state) {} Block::Block() : id(0), state(0) {} diff --git a/src/world/Block.hpp b/src/world/Block.hpp index ae952c9..1a53868 100644 --- a/src/world/Block.hpp +++ b/src/world/Block.hpp @@ -3,9 +3,7 @@ struct Block { Block(); - Block(unsigned short idAndState, unsigned char light); - - Block(unsigned short id, unsigned char state, unsigned char light); + Block(unsigned short id, unsigned short state = 0, unsigned char light = 0); ~Block(); diff --git a/src/world/Section.cpp b/src/world/Section.cpp index ac34fba..5c42ea5 100644 --- a/src/world/Section.cpp +++ b/src/world/Section.cpp @@ -77,7 +77,7 @@ void Section::Parse() { } for (int i = 0; i < 4096; i++) { unsigned short blockId = m_palette.size() > 0 ? m_palette[blocks[i]] : blocks[i]; - Block block(blockId, light[i]); + Block block(blockId, 0, light[i]); m_blocks.push_back(block); } if ((light.size() + blocks.size()) / 2 != 4096) { diff --git a/src/world/World.cpp b/src/world/World.cpp index af76fd5..d13d01d 100644 --- a/src/world/World.cpp +++ b/src/world/World.cpp @@ -84,27 +84,9 @@ Section World::ParseSection(byte *data, size_t &dataLen) { } World::~World() { - isContinue = false; - m_parseSectionWaiter.notify_all(); - m_sectionParseThread.join(); -} - -void World::SectionParsingThread() { - while (isContinue) { - std::unique_lock sectionParseLocker(m_parseSectionMutex); - m_parseSectionWaiter.wait(sectionParseLocker); - while (m_sectionToParse.size() == 0 && isContinue) { - m_parseSectionWaiter.wait(sectionParseLocker); - } - while (m_sectionToParse.size() > 0) { - auto it = m_sectionToParse.front(); - m_sectionToParse.pop(); - it->second.Parse(); - } - } } World::World() { - m_sectionParseThread = std::thread(&World::SectionParsingThread, this); + } diff --git a/src/world/World.hpp b/src/world/World.hpp index 7b7ea60..cef9eea 100644 --- a/src/world/World.hpp +++ b/src/world/World.hpp @@ -11,22 +11,22 @@ class World { //utility vars - World(const World& other); - World&operator=(const World &other); - bool isContinue=true; - std::mutex m_parseSectionMutex; - std::condition_variable m_parseSectionWaiter; - std::thread m_sectionParseThread; - std::queue::iterator> m_sectionToParse; - //utility methods - void SectionParsingThread(); + World(const World &other); + + World &operator=(const World &other); + //game vars int m_dimension = 0; + //game methods Section ParseSection(byte *data, size_t &dataLen); + public: World(); + ~World(); + void ParseChunkData(Packet packet); + std::map m_sections; }; \ No newline at end of file -- cgit v1.2.3