#include "nodetimer.h"
#include "modifiedstate.h"
#include "util/numeric.h" // getContainerPos
+#include "settings.h"
class Map;
class NodeMetadataList;
void reallocate()
{
delete[] data;
- u32 datasize = MAP_BLOCKSIZE * MAP_BLOCKSIZE * MAP_BLOCKSIZE;
- data = new MapNode[datasize];
- for (u32 i = 0; i < datasize; i++)
+ data = new MapNode[nodecount];
+ for (u32 i = 0; i < nodecount; i++)
data[i] = MapNode(CONTENT_IGNORE);
raiseModified(MOD_STATE_WRITE_NEEDED, MOD_REASON_REALLOCATE);
inline v3s16 getPosRelative()
{
- return m_pos * MAP_BLOCKSIZE;
+ return m_pos_relative;
}
inline core::aabbox3d<s16> getBox()
if (!*valid_position)
return MapNode(CONTENT_IGNORE);
- return data[z * MAP_BLOCKSIZE * MAP_BLOCKSIZE + y * MAP_BLOCKSIZE + x];
+ return data[z * zstride + y * ystride + x];
}
inline MapNode getNode(v3s16 p, bool *valid_position)
static const u32 ystride = MAP_BLOCKSIZE;
static const u32 zstride = MAP_BLOCKSIZE * MAP_BLOCKSIZE;
+ static const u32 nodecount = MAP_BLOCKSIZE * MAP_BLOCKSIZE * MAP_BLOCKSIZE;
+
private:
/*
Private member variables
// Position in blocks on parent
v3s16 m_pos;
+ /* This is the precalculated m_pos_relative value
+ * This caches the value, improving performance by removing 3 s16 multiplications
+ * at runtime on each getPosRelative call
+ * For a 5 minutes runtime with valgrind this removes 3 * 19M s16 multiplications
+ * The gain can be estimated in Release Build to 3 * 100M multiply operations for 5 mins
+ */
+ v3s16 m_pos_relative;
+
IGameDef *m_gamedef;
/*
inline bool blockpos_over_limit(v3s16 p)
{
- return
- (p.X < -MAP_GENERATION_LIMIT / MAP_BLOCKSIZE
- || p.X > MAP_GENERATION_LIMIT / MAP_BLOCKSIZE
- || p.Y < -MAP_GENERATION_LIMIT / MAP_BLOCKSIZE
- || p.Y > MAP_GENERATION_LIMIT / MAP_BLOCKSIZE
- || p.Z < -MAP_GENERATION_LIMIT / MAP_BLOCKSIZE
- || p.Z > MAP_GENERATION_LIMIT / MAP_BLOCKSIZE);
+ const static u16 map_gen_limit = MYMIN(MAX_MAP_GENERATION_LIMIT,
+ g_settings->getU16("map_generation_limit"));
+ return (p.X < -map_gen_limit / MAP_BLOCKSIZE
+ || p.X > map_gen_limit / MAP_BLOCKSIZE
+ || p.Y < -map_gen_limit / MAP_BLOCKSIZE
+ || p.Y > map_gen_limit / MAP_BLOCKSIZE
+ || p.Z < -map_gen_limit / MAP_BLOCKSIZE
+ || p.Z > map_gen_limit / MAP_BLOCKSIZE);
}
/*
std::string analyze_block(MapBlock *block);
#endif
-