From 39ed0ae6f4c8189a59e0c100ee0c05f68ec0cf39 Mon Sep 17 00:00:00 2001 From: est31 Date: Sun, 31 May 2015 06:23:10 +0200 Subject: [PATCH] Mapblock: nodecount refactor Spare direct multoplication, use constant MapBlock::nodecount instead of local nodecount variables. Also use strides at one place instead of multiplications. --- src/mapblock.cpp | 16 +++++----------- src/mapblock.h | 9 +++++---- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/mapblock.cpp b/src/mapblock.cpp index 7ad67c589..9eb64a76e 100644 --- a/src/mapblock.cpp +++ b/src/mapblock.cpp @@ -132,7 +132,7 @@ MapNode MapBlock::getNodeParent(v3s16 p, bool *is_valid_position) } if (is_valid_position) *is_valid_position = true; - return data[p.Z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + p.Y*MAP_BLOCKSIZE + p.X]; + return data[p.Z * zstride + p.Y * ystride + p.X]; } std::string MapBlock::getModifiedReasonString() @@ -388,7 +388,7 @@ void MapBlock::actuallyUpdateDayNightDiff() /* Check if any lighting value differs */ - for (u32 i = 0; i < MAP_BLOCKSIZE*MAP_BLOCKSIZE*MAP_BLOCKSIZE; i++) { + for (u32 i = 0; i < nodecount; i++) { MapNode &n = data[i]; differs = !n.isLightDayNightEq(nodemgr); @@ -402,7 +402,7 @@ void MapBlock::actuallyUpdateDayNightDiff() */ if (differs) { bool only_air = true; - for (u32 i = 0; i < MAP_BLOCKSIZE*MAP_BLOCKSIZE*MAP_BLOCKSIZE; i++) { + for (u32 i = 0; i < nodecount; i++) { MapNode &n = data[i]; if (n.getContent() != CONTENT_AIR) { only_air = false; @@ -473,8 +473,7 @@ static void getBlockNodeIdMapping(NameIdMapping *nimap, MapNode *nodes, std::set unknown_contents; content_t id_counter = 0; - for(u32 i=0; i unnamed_contents; std::set unallocatable_contents; - for(u32 i=0; igetName(local_id, name); @@ -583,7 +581,6 @@ void MapBlock::serialize(std::ostream &os, u8 version, bool disk) Bulk node data */ NameIdMapping nimap; - u32 nodecount = MAP_BLOCKSIZE*MAP_BLOCKSIZE*MAP_BLOCKSIZE; if(disk) { MapNode *tmp_nodes = new MapNode[nodecount]; @@ -683,7 +680,6 @@ void MapBlock::deSerialize(std::istream &is, u8 version, bool disk) */ TRACESTREAM(<<"MapBlock::deSerialize "<