mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Mapblock: nodecount refactor
Spare direct multoplication, use constant MapBlock::nodecount instead of local nodecount variables. Also use strides at one place instead of multiplications.
This commit is contained in:
parent
b4dfaa3a7a
commit
06a2eee692
2 changed files with 10 additions and 15 deletions
|
@ -145,9 +145,8 @@ public:
|
|||
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);
|
||||
|
@ -294,7 +293,7 @@ public:
|
|||
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)
|
||||
|
@ -553,6 +552,8 @@ public:
|
|||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue