summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2018-08-09 21:09:29 +0200
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2018-08-09 21:09:29 +0200
commitcea95bd7351d66c72832f1688666cd9ef214a23f (patch)
tree770d5d27da7b9f27b973b86f325ea307042831d7
parentWorkaround for liquids (diff)
downloadAltCraft-cea95bd7351d66c72832f1688666cd9ef214a23f.tar
AltCraft-cea95bd7351d66c72832f1688666cd9ef214a23f.tar.gz
AltCraft-cea95bd7351d66c72832f1688666cd9ef214a23f.tar.bz2
AltCraft-cea95bd7351d66c72832f1688666cd9ef214a23f.tar.lz
AltCraft-cea95bd7351d66c72832f1688666cd9ef214a23f.tar.xz
AltCraft-cea95bd7351d66c72832f1688666cd9ef214a23f.tar.zst
AltCraft-cea95bd7351d66c72832f1688666cd9ef214a23f.zip
Diffstat (limited to '')
-rw-r--r--src/AssetManager.cpp42
-rw-r--r--src/AssetManager.hpp36
-rw-r--r--src/RendererSectionData.cpp51
-rw-r--r--src/RendererSectionData.hpp13
4 files changed, 66 insertions, 76 deletions
diff --git a/src/AssetManager.cpp b/src/AssetManager.cpp
index 5fa7990..cca31e8 100644
--- a/src/AssetManager.cpp
+++ b/src/AssetManager.cpp
@@ -227,19 +227,19 @@ void ParseAssetBlockModel(AssetTreeNode &node) {
auto face = faceIt.value();
BlockModel::ElementData::FaceData faceData;
- BlockModel::ElementData::FaceDirection faceDir;
+ FaceDirection faceDir;
if (faceIt.key() == "down")
- faceDir = BlockModel::ElementData::FaceDirection::down;
+ faceDir = FaceDirection::down;
else if (faceIt.key() == "up")
- faceDir = BlockModel::ElementData::FaceDirection::up;
+ faceDir = FaceDirection::up;
else if (faceIt.key() == "north")
- faceDir = BlockModel::ElementData::FaceDirection::north;
+ faceDir = FaceDirection::north;
else if (faceIt.key() == "south")
- faceDir = BlockModel::ElementData::FaceDirection::south;
+ faceDir = FaceDirection::south;
else if (faceIt.key() == "west")
- faceDir = BlockModel::ElementData::FaceDirection::west;
+ faceDir = FaceDirection::west;
else if (faceIt.key() == "east")
- faceDir = BlockModel::ElementData::FaceDirection::east;
+ faceDir = FaceDirection::east;
if (face.find("uv") != face.end()) {
BlockModel::ElementData::FaceData::Uv uv;
@@ -250,20 +250,20 @@ void ParseAssetBlockModel(AssetTreeNode &node) {
faceData.uv = uv;
}
- BlockModel::ElementData::FaceDirection cullface = BlockModel::ElementData::FaceDirection::none;
+ FaceDirection cullface = FaceDirection::none;
if (face.find("cullface") != face.end()) {
if (face["cullface"] == "down")
- cullface = BlockModel::ElementData::FaceDirection::down;
+ cullface = FaceDirection::down;
else if (face["cullface"] == "up")
- cullface = BlockModel::ElementData::FaceDirection::up;
+ cullface = FaceDirection::up;
else if (face["cullface"] == "north")
- cullface = BlockModel::ElementData::FaceDirection::north;
+ cullface = FaceDirection::north;
else if (face["cullface"] == "south")
- cullface = BlockModel::ElementData::FaceDirection::south;
+ cullface = FaceDirection::south;
else if (face["cullface"] == "west")
- cullface = BlockModel::ElementData::FaceDirection::west;
+ cullface = FaceDirection::west;
else if (face["cullface"] == "east")
- cullface = BlockModel::ElementData::FaceDirection::east;
+ cullface = FaceDirection::east;
}
faceData.cullface = cullface;
@@ -404,20 +404,20 @@ void ParseBlockModels() {
elementTransform = glm::scale(elementTransform, elementSize.glm());
for (const auto& face : element.faces) {
- BlockModel::ParsedFace parsedFace;
+ ParsedFace parsedFace;
parsedFace.visibility = face.second.cullface;
glm::mat4 faceTransform;
switch (face.first) {
- case BlockModel::ElementData::FaceDirection::down:
+ case FaceDirection::down:
faceTransform = glm::translate(elementTransform, glm::vec3(0, 0, 0));
faceTransform = glm::rotate(faceTransform, glm::radians(180.0f), glm::vec3(1.0f, 0, 0));
faceTransform = glm::translate(faceTransform, glm::vec3(0, 0, -1));
break;
- case BlockModel::ElementData::FaceDirection::up:
+ case FaceDirection::up:
faceTransform = glm::translate(elementTransform, glm::vec3(0.0f, 1.0f, 0.0f));
break;
- case BlockModel::ElementData::FaceDirection::north:
+ case FaceDirection::north:
faceTransform = glm::translate(elementTransform, glm::vec3(0, 0, 1));
faceTransform = glm::rotate(faceTransform, glm::radians(90.0f), glm::vec3(-1.0f, 0.0f, 0.0f));
faceTransform = glm::rotate(faceTransform, glm::radians(90.0f), glm::vec3(0.0f, -1.0f, 0.0f));
@@ -425,18 +425,18 @@ void ParseBlockModels() {
faceTransform = glm::rotate(faceTransform, glm::radians(180.0f), glm::vec3(1, 0, 0.0f));
faceTransform = glm::translate(faceTransform, glm::vec3(0, 0, -1.0f));
break;
- case BlockModel::ElementData::FaceDirection::south:
+ case FaceDirection::south:
faceTransform = glm::translate(elementTransform, glm::vec3(1, 0, 0));
faceTransform = glm::rotate(faceTransform, glm::radians(90.0f), glm::vec3(-1.0f, 0.0f, 0.0f));
faceTransform = glm::rotate(faceTransform, glm::radians(90.0f), glm::vec3(0.0f, -1.0f, 0.0f));
break;
- case BlockModel::ElementData::FaceDirection::west:
+ case FaceDirection::west:
faceTransform = glm::translate(elementTransform, glm::vec3(1, 0, 0));
faceTransform = glm::rotate(faceTransform, glm::radians(90.0f), glm::vec3(0, 0.0f, 1.0f));
faceTransform = glm::rotate(faceTransform, glm::radians(180.0f), glm::vec3(1.0f, 0.0f, 0.0f));
faceTransform = glm::translate(faceTransform, glm::vec3(0, 0, -1));
break;
- case BlockModel::ElementData::FaceDirection::east:
+ case FaceDirection::east:
faceTransform = glm::translate(elementTransform, glm::vec3(0, 0, 0));
faceTransform = glm::rotate(faceTransform, glm::radians(90.0f), glm::vec3(0, 0.0f, 1.0f));
break;
diff --git a/src/AssetManager.hpp b/src/AssetManager.hpp
index e05ba31..992bd51 100644
--- a/src/AssetManager.hpp
+++ b/src/AssetManager.hpp
@@ -14,6 +14,24 @@
#include "Block.hpp"
#include "TextureAtlas.hpp"
+enum FaceDirection {
+ down,
+ up,
+ north,
+ south,
+ west,
+ east,
+ none,
+};
+
+struct ParsedFace {
+ FaceDirection visibility;
+ glm::mat4 transform;
+ glm::vec4 texture;
+ float layer;
+ glm::vec3 color;
+};
+
struct BlockModel {
bool IsBlock = false;
std::string BlockName;
@@ -56,16 +74,6 @@ struct BlockModel {
bool shade = true;
- enum FaceDirection {
- down,
- up,
- north,
- south,
- west,
- east,
- none,
- };
-
struct FaceData {
struct Uv {
int x1, y1, x2, y2;
@@ -82,14 +90,6 @@ struct BlockModel {
std::vector<ElementData> Elements;
- struct ParsedFace {
- ElementData::FaceDirection visibility;
- glm::mat4 transform;
- glm::vec4 texture;
- float layer;
- glm::vec3 color;
- };
-
std::vector<ParsedFace> parsedFaces;
};
diff --git a/src/RendererSectionData.cpp b/src/RendererSectionData.cpp
index 485636c..5973dd5 100644
--- a/src/RendererSectionData.cpp
+++ b/src/RendererSectionData.cpp
@@ -5,7 +5,6 @@
#include <glm/gtc/matrix_transform.hpp>
#include "World.hpp"
-#include "AssetManager.hpp"
inline const BlockId& GetBlockId(const Vector& pos, const std::array<BlockId, 4096> &blockIdData) {
return blockIdData[pos.y * 256 + pos.z * 16 + pos.x];
@@ -20,42 +19,42 @@ void AddFacesByBlockModel(RendererSectionData &data, const BlockModel &model, co
glm::vec2 lightness;
lightness.x = _max(light.face[0], light.face[1], light.face[2], light.face[3], light.face[4], light.face[5]);
lightness.y = _max(skyLight.face[0], skyLight.face[1], skyLight.face[2], skyLight.face[3], skyLight.face[4], skyLight.face[5]);
- if (face.visibility != BlockModel::ElementData::FaceDirection::none) {
+ if (face.visibility != FaceDirection::none) {
switch (face.visibility) {
- case BlockModel::ElementData::FaceDirection::down: {
+ case FaceDirection::down: {
if (visibility >> 0 & 0x1)
continue;
- lightness = glm::vec2(light.face[BlockDirection::down], skyLight.face[BlockDirection::down]);
+ lightness = glm::vec2(light.face[FaceDirection::down], skyLight.face[FaceDirection::down]);
break;
}
- case BlockModel::ElementData::FaceDirection::up: {
+ case FaceDirection::up: {
if (visibility >> 1 & 0x1)
continue;
- lightness = glm::vec2(light.face[BlockDirection::up], skyLight.face[BlockDirection::up]);
+ lightness = glm::vec2(light.face[FaceDirection::up], skyLight.face[FaceDirection::up]);
break;
}
- case BlockModel::ElementData::FaceDirection::north: {
+ case FaceDirection::north: {
if (visibility >> 2 & 0x1)
continue;
- lightness = glm::vec2(light.face[BlockDirection::north], skyLight.face[BlockDirection::north]);
+ lightness = glm::vec2(light.face[FaceDirection::north], skyLight.face[FaceDirection::north]);
break;
}
- case BlockModel::ElementData::FaceDirection::south: {
+ case FaceDirection::south: {
if (visibility >> 3 & 0x1)
continue;
- lightness = glm::vec2(light.face[BlockDirection::south], skyLight.face[BlockDirection::south]);
+ lightness = glm::vec2(light.face[FaceDirection::south], skyLight.face[FaceDirection::south]);
break;
}
- case BlockModel::ElementData::FaceDirection::west: {
+ case FaceDirection::west: {
if (visibility >> 4 & 0x1)
continue;
- lightness = glm::vec2(light.face[BlockDirection::west], skyLight.face[BlockDirection::west]);
+ lightness = glm::vec2(light.face[FaceDirection::west], skyLight.face[FaceDirection::west]);
break;
}
- case BlockModel::ElementData::FaceDirection::east: {
+ case FaceDirection::east: {
if (visibility >> 5 & 0x1)
continue;
- lightness = glm::vec2(light.face[BlockDirection::east], skyLight.face[BlockDirection::east]);
+ lightness = glm::vec2(light.face[FaceDirection::east], skyLight.face[FaceDirection::east]);
break;
}
}
@@ -247,17 +246,17 @@ BlockLightness SectionsData::GetLight(const Vector &pos) const {
dirValue = _max(self, dirValue);
if (dir == directions[0])
- lightness.face[BlockDirection::west] = dirValue;
+ lightness.face[FaceDirection::west] = dirValue;
if (dir == directions[1])
- lightness.face[BlockDirection::east] = dirValue;
+ lightness.face[FaceDirection::east] = dirValue;
if (dir == directions[2])
- lightness.face[BlockDirection::up] = dirValue;
+ lightness.face[FaceDirection::up] = dirValue;
if (dir == directions[3])
- lightness.face[BlockDirection::down] = dirValue;
+ lightness.face[FaceDirection::down] = dirValue;
if (dir == directions[4])
- lightness.face[BlockDirection::north] = dirValue;
+ lightness.face[FaceDirection::north] = dirValue;
if (dir == directions[5])
- lightness.face[BlockDirection::south] = dirValue;
+ lightness.face[FaceDirection::south] = dirValue;
}
return lightness;
}
@@ -299,17 +298,17 @@ BlockLightness SectionsData::GetSkyLight(const Vector &pos) const {
dirValue = _max(self, dirValue);
if (dir == directions[0])
- lightness.face[BlockDirection::west] = dirValue;
+ lightness.face[FaceDirection::west] = dirValue;
if (dir == directions[1])
- lightness.face[BlockDirection::east] = dirValue;
+ lightness.face[FaceDirection::east] = dirValue;
if (dir == directions[2])
- lightness.face[BlockDirection::up] = dirValue;
+ lightness.face[FaceDirection::up] = dirValue;
if (dir == directions[3])
- lightness.face[BlockDirection::down] = dirValue;
+ lightness.face[FaceDirection::down] = dirValue;
if (dir == directions[4])
- lightness.face[BlockDirection::north] = dirValue;
+ lightness.face[FaceDirection::north] = dirValue;
if (dir == directions[5])
- lightness.face[BlockDirection::south] = dirValue;
+ lightness.face[FaceDirection::south] = dirValue;
}
return lightness;
}
diff --git a/src/RendererSectionData.hpp b/src/RendererSectionData.hpp
index 1250d39..e472e99 100644
--- a/src/RendererSectionData.hpp
+++ b/src/RendererSectionData.hpp
@@ -6,21 +6,12 @@
#include "Vector.hpp"
#include "Section.hpp"
+#include "AssetManager.hpp"
class World;
-enum BlockDirection {
- down, //Y-
- up, //Y+
- north, //Z-
- south, //Z+
- west, //X-
- east, //X+
- none,
-};
-
struct BlockLightness {
- unsigned char face[BlockDirection::none] = { 0,0,0,0,0,0 };
+ unsigned char face[FaceDirection::none] = { 0,0,0,0,0,0 };
};
struct SectionsData {