Raised This Month: $ Target: $400
 0% 

[HELP] Optimizing


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
The Inhabitant Of Heavens
Member
Join Date: Aug 2011
Old 09-20-2011 , 16:31   [HELP] Optimizing
Reply With Quote #1

How to optimize a code?

CPU 15 ~ %

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
    
    

The Inhabitant Of Heavens is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 09-20-2011 , 23:43   Re: [HELP] Optimizing
Reply With Quote #2

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 :}
__________________
Hunter-Digital 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 19:39.


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