From e561e652ccae7d7fd214930000892cc24281f96c Mon Sep 17 00:00:00 2001 From: UIS Date: Fri, 14 Aug 2020 01:38:23 +0300 Subject: Use 12+4 bits for BlockId, GetBlockInfo return pointer instead value --- src/AssetManager.cpp | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) (limited to 'src/AssetManager.cpp') diff --git a/src/AssetManager.cpp b/src/AssetManager.cpp index 7bcfaae..e3e0e05 100644 --- a/src/AssetManager.cpp +++ b/src/AssetManager.cpp @@ -27,6 +27,8 @@ std::unique_ptr assetTree; std::unique_ptr atlas; std::map blockIdToBlockFaces; +BlockFaces errorFaces; + void LoadIds(); void LoadAssets(); void LoadTextures(); @@ -68,6 +70,13 @@ void AssetManager::InitAssetManager() void AssetManager::InitPostRml() { LoadScripts(); + + errorFaces.transform = glm::mat4(1.0); + errorFaces.faces = GetAsset("/minecraft/models/block/error")->blockModel.parsedFaces; + errorFaces.isBlock = GetAsset("/minecraft/models/block/error")->blockModel.IsBlock; + for (int i = 0; i < FaceDirection::none; i++) { + errorFaces.faceDirectionVector[i] = FaceDirectionVector[i]; + } } void LoadIds() { @@ -606,35 +615,23 @@ BlockFaces &AssetManager::GetBlockModelByBlockId(BlockId block) { if (it != blockIdToBlockFaces.end()) return it->second; - if (block.id == 7788) { - BlockFaces blockFaces; - blockFaces.transform = glm::mat4(1.0); - blockFaces.faces = GetAsset("/minecraft/models/block/error")->blockModel.parsedFaces; - blockFaces.isBlock = GetAsset("/minecraft/models/block/error")->blockModel.IsBlock; - for (int i = 0; i < FaceDirection::none; i++) { - blockFaces.faceDirectionVector[i] = FaceDirectionVector[i]; - } - blockIdToBlockFaces.insert(std::make_pair(block, blockFaces)); - return blockIdToBlockFaces.find(block)->second; - } - - BlockInfo blockInfo = GetBlockInfo(block); - AssetBlockState *asset = GetAsset("/minecraft/blockstates/" + blockInfo.blockstate); + BlockInfo *blockInfo = GetBlockInfo(block); + AssetBlockState *asset = GetAsset("/minecraft/blockstates/" + blockInfo->blockstate); if (!asset) - return GetBlockModelByBlockId(BlockId{ 7788,0 }); + return errorFaces; BlockState &blockState = asset->blockState; - if (blockState.variants.find(blockInfo.variant) == blockState.variants.end()) - return GetBlockModelByBlockId(BlockId{ 7788,0 }); + if (blockState.variants.find(blockInfo->variant) == blockState.variants.end()) + return errorFaces; - BlockStateVariant &variant = blockState.variants[blockInfo.variant]; + BlockStateVariant &variant = blockState.variants[blockInfo->variant]; if (variant.models.empty()) - return GetBlockModelByBlockId(BlockId{ 7788,0 }); + return errorFaces; BlockStateVariant::Model &model = variant.models[0]; AssetBlockModel *assetModel = GetAsset("/minecraft/models/block/" + model.modelName); if (!assetModel) - return GetBlockModelByBlockId(BlockId{ 7788,0 }); + return errorFaces; BlockFaces blockFaces; blockFaces.transform = glm::mat4(1.0); -- cgit v1.2.3