AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Is it posible to optimize? (https://forums.alliedmods.net/showthread.php?t=105601)

9evill 10-06-2009 07:52

Is it posible to optimize?
 
Hello im trying to optimize some plugins of my server, iam not a scripter but i with your help i hope i will optimize some of the code.
So i instaledd amx profile and looking for plugins having a lot of calls.
One plugin uses big number of calls, here is the code:

public client_PreThink(id)
{
if(norecoil_active[id] == 1)
{
if(get_user_flags(id) & ADMIN_KICK)
{
set_pev(id,pev_punchangle, Float:{0.0, 0.0, 0.0})
}
}
}
How could i optimize this code? Thanks in advice.

9evill 10-06-2009 08:09

Re: Is it posible to optimize?
 
Where is check for norecoil_active[id] == 1? Because norecoil is not for all admin_kick players, but only for those who selected this function.(it some kind of menu with extra function).

fysiks 10-06-2009 18:58

Re: Is it posible to optimize?
 
If you set who is able to have no recoil and set it to norecoil_active[id] then you don't need to use get_user_flags(). If they are not allowed to use the command then don't set their norecoil_active[id].

PHP Code:

public client_PreThink(id)
{
    if(
norecoil_active[id] == 1)
    {
        
set_pev(id,pev_punchangleFloat:{0.00.00.0})
    }



9evill 10-07-2009 02:30

Re: Is it posible to optimize?
 
Quote:

Originally Posted by fysiks (Post 954412)
If you set who is able to have no recoil and set it to norecoil_active[id] then you don't need to use get_user_flags(). If they are not allowed to use the command then don't set their norecoil_active[id].

PHP Code:

public client_PreThink(id)
{
    if(
norecoil_active[id] == 1)
    {
        
set_pev(id,pev_punchangleFloat:{0.00.00.0})
    }



What about caching the norecoil_active value, and check for changes on new round?

vitorrd 10-07-2009 03:18

Re: Is it posible to optimize?
 
As fysiks said, if you have the value only for admins, then checking for admin access is unnecessary. About your question, there's really not much need for caching the value since it is probably set/unset only once, right?
The only possible way to optimize that (and this will still depend on the implementation of the Pawn compiler, therefore this is really low level) is to takethe == 1 off the comparison to simply if(norecoil_active[id]).
You can also make your zero-value Float vector static or global, avoiding creating it every single time PreThink is called.

Arkshine 10-07-2009 03:25

Re: Is it posible to optimize?
 
@9evill: It doesn't make sense what you say. By caching it means you save the original value from a complex code ( in the meaning severals lines or a native ) to a single var. But you have already a single var...

It's possible to not use an array (see below ; using bits sum), but it's a trivial change. You can't really optimize more. If you want to optimise you have to find a way to remove the punchangle without using this forward.

Code:
#define SetEntityBit(%1,%2)     ( %1[ %2 >> 5 ] |=  ( 1 << ( %2 & 31 ) ) ) #define ClearEntityBit(%1,%2)   ( %1[ %2 >> 5 ] &= ~( 1 << ( %2 & 31 ) ) ) #define GetEntityBit(%1,%2)     ( %1[ %2 >> 5 ] &   ( 1 << ( %2 & 31 ) ) )

9evill 10-07-2009 06:21

Re: Is it posible to optimize?
 
http://forums.alliedmods.net/showthread.php?t=87977
In this example MeRcyLeZZ showed how caching improves speed. So i thought is it posible to do the same with my example
Code:

public client_PreThink(id)
{
    if(norecoil_active[id] == 1)
    {
        set_pev(id,pev_punchangle, Float:{0.0, 0.0, 0.0})
    }
}


vitorrd 10-07-2009 12:27

Re: Is it posible to optimize?
 
Caching, for that matter, means storing the variables (CVARS, in his example) in local variables for maximized reading speed. Your code is all localy defined, therefore it is already as fast as his caching example and, as Arkshine said, what you said makes no sense since those are two completely different situations.


All times are GMT -4. The time now is 22:36.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.