AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP] Optimizing (https://forums.alliedmods.net/showthread.php?t=167837)

The Inhabitant Of Heavens 09-20-2011 16:31

[HELP] Optimizing
 
How to optimize a code?

CPU 15 ~ % :shock:

PHP Code:

register_forward(FM_AddToFullPack"fm_fullpack"1

PHP Code:

public fm_fullpack(eseenthosthostflagsplayerpSet)
{
    if(!
is_user_connected(host))
    return 
FMRES_IGNORED
    
    
if(!pev_valid(ent))
    return 
FMRES_IGNORED

    
    
static classname[32]
    
pev(entpev_classnameclassname31)
    
    if(!
equal(classname"sprite"))
    return 
FMRES_IGNORED
    
    
static ptr
    
    ptr 
create_tr2()
    static 
Float:start[3], Float:end[3]
    
    
pev(hostpev_originstart)
    
pev(entpev_originend)
    
    
engfunc(EngFunc_TraceLinestartendIGNORE_MONSTERSentptr)
    
    static 
Float:fr
    get_tr2
(ptrTR_flFractionfr)
    if(
fr != 1.0)
    {
        
get_tr2(ptrTR_vecEndPosend)
        
get_tr2(ptrTR_vecPlaneNormalstart)
        
start[0] *= 10.0
        start
[1] *= 10.0
        start
[2] *= 10.0
        
        end
[0] += start[0]
        
end[1] += start[1]
        
end[2] += start[2]
        
        
set_es(esES_Originend)
        static 
Float:distFloat:scale
        
        pev
(entpev_originstart)
        
dist get_distance_f(startend) - 10.0
        
        scale 
500.0 dist

        
if(scale 1.0)
        
scale 1.0
        
        
if(scale 0.3)
        
scale 0.3
        
        set_es
(esES_Scalescale)
        
        
    }
    else
    {
        
set_es(esES_Effectsget_es(esES_Effects) | EF_NODRAW)
    }
    
    
free_tr2(ptr)
    
    return 
FMRES_IGNORED
    
    



Hunter-Digital 09-20-2011 23:43

Re: [HELP] Optimizing
 
Just a few ideeas:

- You could add a skipping system, to skip some "frames" of that function, it will slow down the reactino time of whatever is doing but it will save some resources.
Something like:
Code:

static iSkip

if(++iSkip >= 10) // only 1 of 10 calls gets triggered
    iSkip = 0
else
    return

- I don't think host can't be connected if the function triggers on him, so remove that.
- is_valid_ent() is a bit faster than pev_valid() and I dunno if the function triggers on invalid entities tough...

The rest I'm not really good at :}


All times are GMT -4. The time now is 19:39.

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