Author Topic: Is there any way to optimize this better?  (Read 1656 times)

Code: [Select]
function doExplosion(%position,%radius)
{

serverPlay3d(explosionSound,%position);

for(%i=0;%i<%radius;%i++)
{

InitContainerRadiusSearch(%position,%radius,$TypeMasks::FXBrickObjectType);

while((%targetObject = containerSearchNext()) !$= 0)
{

%targetPos = getWord(%targetObject.getPosition(),2);

if(!%targetObject.invincible)
{

checkMiningBlock(%targetObject.getPosition());
if(getSimTime() - %targetObject.lastOwnerTime >= 7500)
{

%targetObject.delete();

}

if(%targetObject.type $= "Dormant Bomb")
{

%targetObject.delete();

}

}

}

}

}
When %radius is under 10 it's fine, but once it's over 10 it begins lagging the server.
Is there a better way to go about doing this?

pretty sure you can use a radius explosion (from an actual bomb)

and anything the projectiles it shoots out touches you can break

not positive though

What's the for loop for? There's no point to it.

What's the for loop for? There's no point to it.
So it's a sphere and not a tunnel. I tried removing it and yeah.

So it's a sphere and not a tunnel. I tried removing it and yeah.

Why would it be a tunnel? You're using a radius search function.

Why would it be a tunnel? You're using a radius search function.

Try storing a reference to every dirt block. It will only take up a few MBs of memory for a few hundred thousand bricks.

Try storing a reference to every dirt block. It will only take up a few MBs of memory for a few hundred thousand bricks.
There's already a reference to each block though.

Code: [Select]
%brick = new fxDTSBrick()
{
properties stuff here
};

$Mining::Block[%position] = %brick;
in the function that places bricks.

Unless I'm thinking of the wrong reference

function doExplosion(%position,%radius)
{

   serverPlay3d(explosionSound,%position);

//Remove the for loop, if it isn't a sphere it's the fault of something else you're doing wrong

      InitContainerRadiusSearch(%position,%radius,$TypeMasks::FXBrickObjectType);

      while((%targetObject = containerSearchNext()) !$= 0)
//Change !$= to just !=
      {

         %targetPos = getWord(%targetObject.getPosition(),2);
//Why is this line even here? You never use the variable %targetpos, you might as well just define %targetPos as %targetObject.getPosition() and use that in all the other places you call getPosition()

         if(!%targetObject.invincible)
         {

            checkMiningBlock(%targetObject.getPosition());
Like here
            if(getSimTime() - %targetObject.lastOwnerTime >= 7500)
            {

               %targetObject.delete();

            }

            if(%targetObject.type $= "Dormant Bomb")
Why is this here? You're deleting the brick in both conditions. Wouldn't the brick be deleted twice if it were a dormant bomb?
            {

               %targetObject.delete();

            }

         }


   }

}

The main problem here is that you're somehow misdirecting a radius search to give you something other than a sphere. Is this all the code being tested in that picture?

The main problem here is that you're somehow misdirecting a radius search to give you something other than a sphere. Is this all the code being tested in that picture?

checkMiningBlock is being used in there as well
Code: [Select]
function checkMiningBlock(%position,%spawn)
{

%xpos = getWord(%position,0);
%ypos = getWord(%position,1);
%zpos = getWord(%position,2);

//left and right blocks
%position[0] = %xpos + 2 SPC %ypos SPC %zpos;
%position[1] = %xpos - 2 SPC %ypos SPC %zpos;
//front and behind blocks
%position[2] = %xpos SPC %ypos + 2 SPC %zpos;
%position[3] = %xpos SPC %ypos - 2 SPC %zpos;
//above and below blocks
%position[4] = %xpos SPC %ypos SPC %zpos + 2;
%position[5] = %xpos SPC %ypos SPC %zpos - 2;

for(%i=0;%i<6;%i++)
{

if(!$Mining::Block[%position[%i]])
{

if(%zpos <= 50000)
{

if(getRandom(0,mCeil(%zpos/180)+4) == 5) { %type = 5; }

}

if(getRandom(1,12) == 3) { %type = 2; } else if(%type != 5) { %type = 1; }
if(getRandom(0,1850) == 5) { %type = 6; }
if(getRandom(0,2250) == 5) { %type = 8; }

if(!%spawn) { placeMiningBlock(%position[%i],%type); } else { placeMiningBlock(%position[%i],1); }

}

}

}