summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2018-03-28 16:21:50 +0200
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2018-03-28 16:21:50 +0200
commitb30f16d7c9a832ed09b5cd03d73f343f933ca872 (patch)
treefda125d7857add52b32bc1d77dc74451c7437fa4
parentMoved model parsing to startup stage and implemented model rotation (diff)
downloadAltCraft-b30f16d7c9a832ed09b5cd03d73f343f933ca872.tar
AltCraft-b30f16d7c9a832ed09b5cd03d73f343f933ca872.tar.gz
AltCraft-b30f16d7c9a832ed09b5cd03d73f343f933ca872.tar.bz2
AltCraft-b30f16d7c9a832ed09b5cd03d73f343f933ca872.tar.lz
AltCraft-b30f16d7c9a832ed09b5cd03d73f343f933ca872.tar.xz
AltCraft-b30f16d7c9a832ed09b5cd03d73f343f933ca872.tar.zst
AltCraft-b30f16d7c9a832ed09b5cd03d73f343f933ca872.zip
-rw-r--r--src/RendererSectionData.cpp4
-rw-r--r--src/Section.cpp29
-rw-r--r--src/Section.hpp6
-rw-r--r--src/World.cpp4
4 files changed, 16 insertions, 27 deletions
diff --git a/src/RendererSectionData.cpp b/src/RendererSectionData.cpp
index 96d78e0..6554d16 100644
--- a/src/RendererSectionData.cpp
+++ b/src/RendererSectionData.cpp
@@ -213,7 +213,7 @@ RendererSectionData ParseSection(const SectionsData &sections)
}
unsigned char SectionsData::GetLight(const Vector & pos) const {
- const Vector directions[] = {
+ static const Vector directions[] = {
Vector(0,0,0),
Vector(1,0,0),
Vector(-1,0,0),
@@ -252,7 +252,7 @@ unsigned char SectionsData::GetLight(const Vector & pos) const {
}
unsigned char SectionsData::GetSkyLight(const Vector & pos) const {
- const Vector directions[] = {
+ static const Vector directions[] = {
Vector(0,0,0),
Vector(1,0,0),
Vector(-1,0,0),
diff --git a/src/Section.cpp b/src/Section.cpp
index 1f60471..c8c67dc 100644
--- a/src/Section.cpp
+++ b/src/Section.cpp
@@ -13,17 +13,12 @@ void Section::CalculateHash() const {
size_t offset = 0;
std::vector<unsigned char> rawData;
- rawData.resize(block.size() * sizeof(long long) + light.size() + sky.size());
+ rawData.resize(block.size() * sizeof(long long) + 4096);
- std::memcpy(rawData.data() + offset, block.data(), block.size() * sizeof(BlockId));
- offset += block.size() * sizeof(BlockId);
-
- std::memcpy(rawData.data() + offset, light.data(), light.size() * sizeof(unsigned char));
- offset += light.size() * sizeof(unsigned char);
-
- if (!sky.empty())
- std::memcpy(rawData.data() + offset, sky.data(), sky.size() * sizeof(unsigned char));
-
+ std::memcpy(rawData.data(), light, 2048);
+ std::memcpy(rawData.data() + 2048, sky, 2048);
+ std::memcpy(rawData.data() + 4096, block.data(), block.size() * sizeof(long long));
+
for (auto& it : overrideList) {
rawData.push_back(*reinterpret_cast<const unsigned short*> (&it.second) & 0xF);
rawData.push_back(*reinterpret_cast<const unsigned short*> (&it.second) >> 0xF);
@@ -36,7 +31,7 @@ void Section::CalculateHash() const {
hash = std::hash<std::string>{}(str);
}
-Section::Section(Vector pos, unsigned char bitsPerBlock, std::vector<unsigned short> palette, std::vector<long long> blockData, std::vector<unsigned char> lightData, std::vector<unsigned char> skyData) {
+Section::Section(Vector pos, unsigned char bitsPerBlock, std::vector<unsigned short> palette, std::vector<long long> blockData, const std::vector<unsigned char> &lightData, const std::vector<unsigned char> &skyData) {
if (bitsPerBlock < 4)
bitsPerBlock = 4;
if (bitsPerBlock > 8)
@@ -46,8 +41,8 @@ Section::Section(Vector pos, unsigned char bitsPerBlock, std::vector<unsigned sh
this->worldPosition = pos;
this->block = std::move(blockData);
this->palette = std::move(palette);
- this->light = std::move(lightData);
- this->sky = std::move(skyData);
+ std::copy(lightData.begin(), lightData.end(), light);
+ std::copy(skyData.begin(), skyData.end(), sky);
hash = -1;
}
@@ -99,9 +94,6 @@ BlockId Section::GetBlockId(Vector pos) const {
unsigned char Section::GetBlockLight(Vector pos) const
{
- if (light.empty())
- return 0;
-
int blockNumber = pos.y * 256 + pos.z * 16 + pos.x;
unsigned char lightValue = this->light[blockNumber / 2];
return (blockNumber % 2 == 0) ? (lightValue & 0xF) : (lightValue >> 4);
@@ -109,10 +101,7 @@ unsigned char Section::GetBlockLight(Vector pos) const
unsigned char Section::GetBlockSkyLight(Vector pos) const
{
- if (sky.empty())
- return 0;
-
- int blockNumber = pos.y * 256 + pos.z * 16 + pos.x;
+ int blockNumber = pos.y * 256 + pos.z * 16 + pos.x;
unsigned char skyValue = this->sky[blockNumber / 2];
return (blockNumber % 2 == 0) ? (skyValue & 0xF) : (skyValue >> 4);
}
diff --git a/src/Section.hpp b/src/Section.hpp
index bc8b70b..b85eb43 100644
--- a/src/Section.hpp
+++ b/src/Section.hpp
@@ -8,8 +8,8 @@
class Section {
std::vector<long long> block;
- std::vector<unsigned char> light;
- std::vector<unsigned char> sky;
+ unsigned char light[2048] = {};
+ unsigned char sky[2048] = {};
unsigned char bitsPerBlock = 0;
std::vector<unsigned short> palette;
@@ -20,7 +20,7 @@ class Section {
std::map<Vector, BlockId> overrideList;
public:
- Section(Vector pos, unsigned char bitsPerBlock, std::vector<unsigned short> palette, std::vector<long long> blockData, std::vector<unsigned char> lightData, std::vector<unsigned char> skyData);
+ Section(Vector pos, unsigned char bitsPerBlock, std::vector<unsigned short> palette, std::vector<long long> blockData, const std::vector<unsigned char> &lightData, const std::vector<unsigned char> &skyData);
Section() = default;
diff --git a/src/World.cpp b/src/World.cpp
index f9eb560..76598e3 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -421,7 +421,7 @@ unsigned char World::GetBlockLight(Vector pos)
unsigned char World::GetBlockLight(const Vector &blockPos, const Section *section, const Section *xp, const Section *xn, const Section *yp, const Section *yn, const Section *zp, const Section *zn)
{
- const Vector directions[] = {
+ static const Vector directions[] = {
Vector(0,0,0),
Vector(1,0,0),
Vector(-1,0,0),
@@ -482,7 +482,7 @@ unsigned char World::GetBlockSkyLight(Vector pos)
unsigned char World::GetBlockSkyLight(const Vector &blockPos, const Section *section, const Section *xp, const Section *xn, const Section *yp, const Section *yn, const Section *zp, const Section *zn)
{
- const Vector directions[] = {
+ static const Vector directions[] = {
Vector(0,0,0),
Vector(1,0,0),
Vector(-1,0,0),