From f721ed0e3c6be33670fe330c029a2d4c3353f635 Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Wed, 31 May 2017 19:17:09 +0500 Subject: 2017-05-31 --- src/world/Block.cpp | 2 +- src/world/Block.hpp | 2 +- src/world/Section.cpp | 17 ++++++++++++++--- src/world/Section.hpp | 1 + src/world/World.cpp | 8 +++----- src/world/World.hpp | 2 ++ 6 files changed, 22 insertions(+), 10 deletions(-) (limited to 'src/world') diff --git a/src/world/Block.cpp b/src/world/Block.cpp index 54b7e5e..74423e0 100644 --- a/src/world/Block.cpp +++ b/src/world/Block.cpp @@ -2,7 +2,7 @@ Block::~Block() {} -Block::Block(unsigned short id, unsigned short state, unsigned char light) : id(id), state(state) {} +Block::Block(unsigned short id, unsigned short state) : id(id), state(state) {} Block::Block() : id(0), state(0) {} diff --git a/src/world/Block.hpp b/src/world/Block.hpp index 1a53868..50268f3 100644 --- a/src/world/Block.hpp +++ b/src/world/Block.hpp @@ -3,7 +3,7 @@ struct Block { Block(); - Block(unsigned short id, unsigned short state = 0, unsigned char light = 0); + Block(unsigned short id, unsigned short state); ~Block(); diff --git a/src/world/Section.cpp b/src/world/Section.cpp index 5c42ea5..6147295 100644 --- a/src/world/Section.cpp +++ b/src/world/Section.cpp @@ -36,6 +36,7 @@ Block &Section::GetBlock(Vector pos) { while (m_dataBlocks != nullptr) { parseWaiter.wait(parseLocker); } + LOG(WARNING)<<"Successfully waited for block render!"; } return m_blocks[pos.GetY() * 256 + pos.GetZ() * 16 + pos.GetX()]; } @@ -45,13 +46,13 @@ void Section::Parse() { return; long long *longArray = reinterpret_cast(m_dataBlocks); - for (int i = 0; i < m_dataBlocksLen / 8; i++) + for (size_t i = 0; i < m_dataBlocksLen / 8; i++) endswap(&longArray[i]); std::vector blocks; blocks.reserve(4096); int bitPos = 0; unsigned short t = 0; - for (int i = 0; i < m_dataBlocksLen; i++) { + for (size_t i = 0; i < m_dataBlocksLen; i++) { for (int j = 0; j < 8; j++) { t |= (m_dataBlocks[i] & 0x01) ? 0x80 : 0x00; t >>= 1; @@ -77,7 +78,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, 0, light[i]); + Block block(blockId>>4, blockId>>4 & 0xF); m_blocks.push_back(block); } if ((light.size() + blocks.size()) / 2 != 4096) { @@ -90,7 +91,17 @@ void Section::Parse() { m_dataLight = nullptr; delete[] m_dataSkyLight; m_dataSkyLight = nullptr; + parseWaiter.notify_all(); + /*static std::map totalBlocks; + for (int x=0;x<16;x++) + for (int y=0;y<16;y++) + for (int z=0;z<16;z++) + totalBlocks[GetBlock(Vector(x,y,z))]++; + LOG(ERROR)<<"Logging chunk"; + for (auto& it:totalBlocks){ + LOG(WARNING)< #include #include +#include #include "Block.hpp" #include "../packet/Field.hpp" diff --git a/src/world/World.cpp b/src/world/World.cpp index d13d01d..121b904 100644 --- a/src/world/World.cpp +++ b/src/world/World.cpp @@ -1,5 +1,3 @@ -#include -#include #include "World.hpp" void World::ParseChunkData(Packet packet) { @@ -43,7 +41,7 @@ Section World::ParseSection(byte *data, size_t &dataLen) { data += fBitsPerBlock.GetLength(); dataLen += fBitsPerBlock.GetLength(); - Field fPaletteLength = FieldParser::Parse(VarInt, data); + Field fPaletteLength = FieldParser::Parse(VarIntType, data); int paletteLength = fPaletteLength.GetVarInt(); data += fPaletteLength.GetLength(); dataLen += fPaletteLength.GetLength(); @@ -52,7 +50,7 @@ Section World::ParseSection(byte *data, size_t &dataLen) { if (paletteLength > 0) { for (unsigned char i = 0; i < paletteLength; i++) { endswap(&i); - Field f = FieldParser::Parse(VarInt, data); + Field f = FieldParser::Parse(VarIntType, data); data += f.GetLength(); dataLen += f.GetLength(); palette.push_back(f.GetVarInt()); @@ -60,7 +58,7 @@ Section World::ParseSection(byte *data, size_t &dataLen) { } } - Field fDataLength = FieldParser::Parse(VarInt, data); + Field fDataLength = FieldParser::Parse(VarIntType, data); data += fDataLength.GetLength(); dataLen += fDataLength.GetLength(); diff --git a/src/world/World.hpp b/src/world/World.hpp index cef9eea..b33499c 100644 --- a/src/world/World.hpp +++ b/src/world/World.hpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include "Block.hpp" #include "../packet/Packet.hpp" #include "Section.hpp" -- cgit v1.2.3