aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCiaran Gultnieks <ciaran@ciarang.com>2014-03-03 18:43:53 +0000
committersapier <Sapier at GMX dot net>2014-03-06 19:18:36 +0100
commitdb98ef6b4553e7b7cb99589740dc219902a90fbc (patch)
treeb4ad2c4fbedea7c5be61522dbff69c485c73c572
parenta4e2198e4102f1dabc8f8720c2ace9c2fca8d999 (diff)
downloadminetest-db98ef6b4553e7b7cb99589740dc219902a90fbc.tar.gz
minetest-db98ef6b4553e7b7cb99589740dc219902a90fbc.tar.bz2
minetest-db98ef6b4553e7b7cb99589740dc219902a90fbc.zip
Stop wasting time in abm - performance improvement
Unless I'm mistaken, the chunk of code I'm moving there is potentially executed hundreds of times inside the loop to get the exact same result every time
-rw-r--r--src/environment.cpp46
1 files changed, 23 insertions, 23 deletions
diff --git a/src/environment.cpp b/src/environment.cpp
index 0e7830a26..9f7207b8d 100644
--- a/src/environment.cpp
+++ b/src/environment.cpp
@@ -719,6 +719,29 @@ public:
ServerMap *map = &m_env->getServerMap();
+ // Find out how many objects the block contains
+ u32 active_object_count = block->m_static_objects.m_active.size();
+ // Find out how many objects this and all the neighbors contain
+ u32 active_object_count_wider = 0;
+ u32 wider_unknown_count = 0;
+ for(s16 x=-1; x<=1; x++)
+ for(s16 y=-1; y<=1; y++)
+ for(s16 z=-1; z<=1; z++)
+ {
+ MapBlock *block2 = map->getBlockNoCreateNoEx(
+ block->getPos() + v3s16(x,y,z));
+ if(block2==NULL){
+ wider_unknown_count = 0;
+ continue;
+ }
+ active_object_count_wider +=
+ block2->m_static_objects.m_active.size()
+ + block2->m_static_objects.m_stored.size();
+ }
+ // Extrapolate
+ u32 wider_known_count = 3*3*3 - wider_unknown_count;
+ active_object_count_wider += wider_unknown_count * active_object_count_wider / wider_known_count;
+
v3s16 p0;
for(p0.X=0; p0.X<MAP_BLOCKSIZE; p0.X++)
for(p0.Y=0; p0.Y<MAP_BLOCKSIZE; p0.Y++)
@@ -762,29 +785,6 @@ public:
}
neighbor_found:
- // Find out how many objects the block contains
- u32 active_object_count = block->m_static_objects.m_active.size();
- // Find out how many objects this and all the neighbors contain
- u32 active_object_count_wider = 0;
- u32 wider_unknown_count = 0;
- for(s16 x=-1; x<=1; x++)
- for(s16 y=-1; y<=1; y++)
- for(s16 z=-1; z<=1; z++)
- {
- MapBlock *block2 = map->getBlockNoCreateNoEx(
- block->getPos() + v3s16(x,y,z));
- if(block2==NULL){
- wider_unknown_count = 0;
- continue;
- }
- active_object_count_wider +=
- block2->m_static_objects.m_active.size()
- + block2->m_static_objects.m_stored.size();
- }
- // Extrapolate
- u32 wider_known_count = 3*3*3 - wider_unknown_count;
- active_object_count_wider += wider_unknown_count * active_object_count_wider / wider_known_count;
-
// Call all the trigger variations
i->abm->trigger(m_env, p, n);
i->abm->trigger(m_env, p, n,