Raised This Month: $ Target: $400
 0% 

Is it posible to optimize?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
9evill
Senior Member
Join Date: Apr 2007
Location: Lithuania
Old 10-06-2009 , 07:52   Is it posible to optimize?
Reply With Quote #1

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 is offline
Old 10-06-2009, 08:03
Arkshine
This message has been deleted by Arkshine. Reason: nvm
9evill
Senior Member
Join Date: Apr 2007
Location: Lithuania
Old 10-06-2009 , 08:09   Re: Is it posible to optimize?
Reply With Quote #2

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).
9evill is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-06-2009 , 18:58   Re: Is it posible to optimize?
Reply With Quote #3

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})
    }

__________________
fysiks is offline
9evill
Senior Member
Join Date: Apr 2007
Location: Lithuania
Old 10-07-2009 , 02:30   Re: Is it posible to optimize?
Reply With Quote #4

Quote:
Originally Posted by fysiks View Post
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?
9evill is offline
vitorrd
Senior Member
Join Date: Jul 2009
Old 10-07-2009 , 03:18   Re: Is it posible to optimize?
Reply With Quote #5

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.
vitorrd is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 10-07-2009 , 03:25   Re: Is it posible to optimize?
Reply With Quote #6

@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 ) ) )
__________________

Last edited by Arkshine; 10-07-2009 at 03:29.
Arkshine is offline
9evill
Senior Member
Join Date: Apr 2007
Location: Lithuania
Old 10-07-2009 , 06:21   Re: Is it posible to optimize?
Reply With Quote #7

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}) 
    } 
}
9evill is offline
vitorrd
Senior Member
Join Date: Jul 2009
Old 10-07-2009 , 12:27   Re: Is it posible to optimize?
Reply With Quote #8

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.
vitorrd is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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