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. |
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).
|
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:
|
Re: Is it posible to optimize?
Quote:
|
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. |
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:
|
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) |
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.