Skip to content

Commit db98ef6

Browse files
CiaranGsapier
authored and
sapier
committedMar 6, 2014
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
1 parent a4e2198 commit db98ef6

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed
 

‎src/environment.cpp

+23-23
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,29 @@ class ABMHandler
719719

720720
ServerMap *map = &m_env->getServerMap();
721721

722+
// Find out how many objects the block contains
723+
u32 active_object_count = block->m_static_objects.m_active.size();
724+
// Find out how many objects this and all the neighbors contain
725+
u32 active_object_count_wider = 0;
726+
u32 wider_unknown_count = 0;
727+
for(s16 x=-1; x<=1; x++)
728+
for(s16 y=-1; y<=1; y++)
729+
for(s16 z=-1; z<=1; z++)
730+
{
731+
MapBlock *block2 = map->getBlockNoCreateNoEx(
732+
block->getPos() + v3s16(x,y,z));
733+
if(block2==NULL){
734+
wider_unknown_count = 0;
735+
continue;
736+
}
737+
active_object_count_wider +=
738+
block2->m_static_objects.m_active.size()
739+
+ block2->m_static_objects.m_stored.size();
740+
}
741+
// Extrapolate
742+
u32 wider_known_count = 3*3*3 - wider_unknown_count;
743+
active_object_count_wider += wider_unknown_count * active_object_count_wider / wider_known_count;
744+
722745
v3s16 p0;
723746
for(p0.X=0; p0.X<MAP_BLOCKSIZE; p0.X++)
724747
for(p0.Y=0; p0.Y<MAP_BLOCKSIZE; p0.Y++)
@@ -762,29 +785,6 @@ class ABMHandler
762785
}
763786
neighbor_found:
764787

765-
// Find out how many objects the block contains
766-
u32 active_object_count = block->m_static_objects.m_active.size();
767-
// Find out how many objects this and all the neighbors contain
768-
u32 active_object_count_wider = 0;
769-
u32 wider_unknown_count = 0;
770-
for(s16 x=-1; x<=1; x++)
771-
for(s16 y=-1; y<=1; y++)
772-
for(s16 z=-1; z<=1; z++)
773-
{
774-
MapBlock *block2 = map->getBlockNoCreateNoEx(
775-
block->getPos() + v3s16(x,y,z));
776-
if(block2==NULL){
777-
wider_unknown_count = 0;
778-
continue;
779-
}
780-
active_object_count_wider +=
781-
block2->m_static_objects.m_active.size()
782-
+ block2->m_static_objects.m_stored.size();
783-
}
784-
// Extrapolate
785-
u32 wider_known_count = 3*3*3 - wider_unknown_count;
786-
active_object_count_wider += wider_unknown_count * active_object_count_wider / wider_known_count;
787-
788788
// Call all the trigger variations
789789
i->abm->trigger(m_env, p, n);
790790
i->abm->trigger(m_env, p, n,

0 commit comments

Comments
 (0)
Please sign in to comment.