diff options
author | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2018-03-08 22:16:21 +0100 |
---|---|---|
committer | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2018-03-08 22:16:21 +0100 |
commit | e8ae429ac0d4f12ecdad6088605d81de6cf67cce (patch) | |
tree | ae96695b6a2c3f7ee52db8a6b8a9075163b6613b /src/RendererSectionData.cpp | |
parent | Minor RendererSectionData parsing memory optimization (diff) | |
download | AltCraft-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 |
Diffstat (limited to '')
-rw-r--r-- | src/RendererSectionData.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
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> §ionsList, 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> §ionsList, 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> §ionsList, 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 §ion = 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)); |