summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2018-03-08 22:16:21 +0100
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2018-03-08 22:16:21 +0100
commite8ae429ac0d4f12ecdad6088605d81de6cf67cce (patch)
treeae96695b6a2c3f7ee52db8a6b8a9075163b6613b
parentMinor RendererSectionData parsing memory optimization (diff)
downloadAltCraft-e8ae429ac0d4f12ecdad6088605d81de6cf67cce.tar
AltCraft-e8ae429ac0d4f12ecdad6088605d81de6cf67cce.tar.gz
AltCraft-e8ae429ac0d4f12ecdad6088605d81de6cf67cce.tar.bz2
AltCraft-e8ae429ac0d4f12ecdad6088605d81de6cf67cce.tar.lz
AltCraft-e8ae429ac0d4f12ecdad6088605d81de6cf67cce.tar.xz
AltCraft-e8ae429ac0d4f12ecdad6088605d81de6cf67cce.tar.zst
AltCraft-e8ae429ac0d4f12ecdad6088605d81de6cf67cce.zip
-rw-r--r--src/AssetManager.cpp7
-rw-r--r--src/AssetManager.hpp2
-rw-r--r--src/RendererSectionData.cpp13
3 files changed, 13 insertions, 9 deletions
diff --git a/src/AssetManager.cpp b/src/AssetManager.cpp
index 0561992..8403700 100644
--- a/src/AssetManager.cpp
+++ b/src/AssetManager.cpp
@@ -69,9 +69,10 @@ void AssetManager::LoadTextureResources() {
LOG(INFO) << "Texture atlas id is " << textureAtlas->texture;
}
-TextureCoordinates AssetManager::GetTextureByAssetName(std::string AssetName) {
- if (assetTextures.find(AssetName) != assetTextures.end())
- return assetTextures[AssetName];
+TextureCoordinates AssetManager::GetTextureByAssetName(const std::string &AssetName) {
+ auto it = assetTextures.find(AssetName);
+ if (it != assetTextures.end())
+ return it->second;
else
return TextureCoordinates{-1, -1, -1, -1};
}
diff --git a/src/AssetManager.hpp b/src/AssetManager.hpp
index b828ee1..37031be 100644
--- a/src/AssetManager.hpp
+++ b/src/AssetManager.hpp
@@ -145,7 +145,7 @@ public:
void LoadTextureResources();
- TextureCoordinates GetTextureByAssetName(std::string AssetName);
+ TextureCoordinates GetTextureByAssetName(const std::string &AssetName);
std::string GetTextureAssetNameByBlockId(BlockTextureId block);
diff --git a/src/RendererSectionData.cpp b/src/RendererSectionData.cpp
index b233522..1ed1099 100644
--- a/src/RendererSectionData.cpp
+++ b/src/RendererSectionData.cpp
@@ -16,7 +16,7 @@ inline const BlockId& GetBlockId(int x, int y, int z, const std::array<BlockId,
return blockIdData[y * 256 + z * 16 + x];
}
-void AddFacesByBlockModel(const std::vector<Vector> &sectionsList, World *world, Vector blockPos, const BlockModel &model, glm::mat4 transform, unsigned char light, unsigned char skyLight, const std::array<unsigned char, 16 * 16 * 16>& visibility, RendererSectionData &data) {
+void AddFacesByBlockModel(const std::vector<Vector> &sectionsList, World *world, Vector blockPos, const BlockModel &model, glm::mat4 transform, unsigned char light, unsigned char skyLight, const std::array<unsigned char, 16 * 16 * 16>& visibility, std::string &textureName, RendererSectionData &data) {
glm::mat4 elementTransform, faceTransform;
for (const auto& element : model.Elements) {
Vector t = element.to - element.from;
@@ -114,11 +114,13 @@ void AddFacesByBlockModel(const std::vector<Vector> &sectionsList, World *world,
break;
}
data.models.push_back(faceTransform);
- std::string textureName = face.second.texture;
+ textureName = face.second.texture;
while (textureName[0] == '#') {
- textureName = model.Textures.find(std::string(textureName.begin() + 1, textureName.end()))->second;
+ textureName.erase(0, 1);
+ textureName = model.Textures.find(textureName)->second;
}
- glm::vec4 texture = AssetManager::Instance().GetTextureByAssetName("minecraft/textures/" + textureName);
+ textureName.insert(0, "minecraft/textures/");
+ glm::vec4 texture = AssetManager::Instance().GetTextureByAssetName(textureName);
if (!(face.second.uv == BlockModel::ElementData::FaceData::Uv{ 0,16,0,16 }) && !(face.second.uv == BlockModel::ElementData::FaceData::Uv{ 0,0,0,0 })
&& !(face.second.uv == BlockModel::ElementData::FaceData::Uv{ 0,0,16,16 })) {
@@ -262,6 +264,7 @@ RendererSectionData ParseSection(World * world, Vector sectionPosition)
std::vector<std::pair<BlockId, const BlockModel *>> idModels;
std::array<BlockId, 4096> blockIdData = SetBlockIdData(world, sectionPosition);
std::array<unsigned char, 4096> blockVisibility = GetBlockVisibilityData(world, sectionPosition, blockIdData, idModels);
+ std::string textureName;
const std::map<BlockTextureId, glm::vec4> &textureAtlas = AssetManager::Instance().GetTextureAtlasIndexes();
const Section &section = world->GetSection(sectionPosition);
@@ -286,7 +289,7 @@ RendererSectionData ParseSection(World * world, Vector sectionPosition)
const BlockModel* model = GetInternalBlockModel(block, idModels);
if (model) {
- AddFacesByBlockModel(sectionsList, world, Vector(x, y, z), *model, transform, section.GetBlockLight(Vector(x, y, z)), section.GetBlockSkyLight(Vector(x, y, z)), blockVisibility, data);
+ AddFacesByBlockModel(sectionsList, world, Vector(x, y, z), *model, transform, section.GetBlockLight(Vector(x, y, z)), section.GetBlockSkyLight(Vector(x, y, z)), blockVisibility, textureName, data);
}
else {
transform = glm::translate(transform, glm::vec3(0, 1, 0));