Skip to content

Commit ca63f7f

Browse files
committedJul 29, 2015
Precalculate mapblock relative size. This permit to remove many s16 calculs on runtime
1 parent 88a6b9f commit ca63f7f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed
 

Diff for: ‎src/mapblock.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ static const char *modified_reason_strings[] = {
6969
MapBlock::MapBlock(Map *parent, v3s16 pos, IGameDef *gamedef, bool dummy):
7070
m_parent(parent),
7171
m_pos(pos),
72+
m_pos_relative(pos * MAP_BLOCKSIZE),
7273
m_gamedef(gamedef),
7374
m_modified(MOD_STATE_WRITE_NEEDED),
7475
m_modified_reason(MOD_REASON_INITIAL),

Diff for: ‎src/mapblock.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ class MapBlock /*: public NodeContainer*/
258258

259259
inline v3s16 getPosRelative()
260260
{
261-
return m_pos * MAP_BLOCKSIZE;
261+
return m_pos_relative;
262262
}
263263

264264
inline core::aabbox3d<s16> getBox()
@@ -564,6 +564,14 @@ class MapBlock /*: public NodeContainer*/
564564
// Position in blocks on parent
565565
v3s16 m_pos;
566566

567+
/* This is the precalculated m_pos_relative value
568+
* This caches the value, improving performance by removing 3 s16 multiplications
569+
* at runtime on each getPosRelative call
570+
* For a 5 minutes runtime with valgrind this removes 3 * 19M s16 multiplications
571+
* The gain can be estimated in Release Build to 3 * 100M multiply operations for 5 mins
572+
*/
573+
v3s16 m_pos_relative;
574+
567575
IGameDef *m_gamedef;
568576

569577
/*

0 commit comments

Comments
 (0)
Please sign in to comment.