Raised This Month: $12 Target: $400
 3% 

Solved trying to decrease "client_preThink" CPU usage


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 02-24-2021 , 23:56   trying to decrease "client_preThink" CPU usage
Reply With Quote #1

Is there any way to decrease CPU load as much as possible?
(bhop as usual)
PHP Code:
public client_PreThink(id
{
    if(
get_pcvar_num(mp_bhop_ban)) {
        if(
gBhop[id] == 1gBhop[id] = 0
    
}
    
    if(
gBhop[id] == 0)
        return 
PLUGIN_HANDLED
    
    entity_set_float
(idEV_FL_fuser20.0)        
    
    if (
entity_get_int(idEV_INT_button) & 2) {    
        new 
flags entity_get_int(idEV_INT_flags)
    
        if (
flags FL_WATERJUMP)
            return 
PLUGIN_CONTINUE
        
if ( entity_get_int(idEV_INT_waterlevel) >= )
            return 
PLUGIN_CONTINUE
        
if ( !(flags FL_ONGROUND) )
            return 
PLUGIN_CONTINUE
                    
        
if (gAutojump[id] == 1) {
            new 
Float:velocity[3]
            
            
entity_get_vector(idEV_VEC_velocityvelocity)
            
            
velocity[2] += 250.0
            
            entity_set_vector
(idEV_VEC_velocityvelocity)
        }
        
        
entity_set_int(idEV_INT_gaitsequence6)
    }
    
    return 
PLUGIN_HANDLED


Last edited by kww; 02-26-2021 at 10:03.
kww is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 02-25-2021 , 06:41   Re: trying to decrease "client_preThink" CPU usage
Reply With Quote #2

You can probably replace client_PreThink with Ham_Player_Jump.
Both are called once per frame but Ham_Player_Jump only if a player has the jump key held

Code:
/**
	 * Players have all the attributes of normal entities, in addition to these.
	 */
	 
	/**
	 * Description:		Typically called every frame when a player has jump held.
	 * Forward params:	function(this)
	 * Return type:		None.
	 * Execute params:	ExecuteHam(Ham_Player_Jump, this);
	 */
	Ham_Player_Jump,
__________________









Last edited by CrazY.; 02-25-2021 at 06:42.
CrazY. is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 02-25-2021 , 06:46   Re: trying to decrease "client_preThink" CPU usage
Reply With Quote #3

Always declare variables in forwards that is being called many times per second using static, change players Boolean variables to bitsum booleans, returning in prethink is ignored so best just to return plugin_continue.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 02-25-2021 , 07:30   Re: trying to decrease "client_preThink" CPU usage
Reply With Quote #4

Quote:
returning in prethink is ignored so best just to return plugin_continue.
If it's ignored, what's the point of returning anything? Just do a blank return.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Natsheh
Veteran Member
Join Date: Sep 2012
Old 02-25-2021 , 08:44   Re: trying to decrease "client_preThink" CPU usage
Reply With Quote #5

Blank return is a plugin continue, but also you're right it should be just return.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 02-25-2021 at 08:52.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
loiraolhosazul
Member
Join Date: May 2020
Old 02-25-2021 , 09:02   Re: trying to decrease "client_preThink" CPU usage
Reply With Quote #6

maybe a check of 0.1 is better, because prethink is according to the player's frames
loiraolhosazul is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 02-25-2021 , 09:37   Re: trying to decrease "client_preThink" CPU usage
Reply With Quote #7

Quote:
Originally Posted by loiraolhosazul View Post
maybe a check of 0.1 is better, because prethink is according to the player's frames
depending on what he's trying to achieve.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 02-25-2021 , 10:03   Re: trying to decrease "client_preThink" CPU usage
Reply With Quote #8

Like CrazY said, using PreThink for auto-bunnyhop is not a 2021 way of making plugins.
Ham_Player_Jump is the right solution.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 02-25-2021 , 11:49   Re: trying to decrease "client_preThink" CPU usage
Reply With Quote #9

Quote:
Originally Posted by OciXCrom View Post
Like CrazY said, using PreThink for auto-bunnyhop is not a 2021 way of making plugins.
Ham_Player_Jump is the right solution.
hamsandwich is pretty hard for me to understand T_T

Last edited by kww; 02-25-2021 at 11:50.
kww is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 02-25-2021 , 13:16   Re: trying to decrease "client_preThink" CPU usage
Reply With Quote #10

It's literally 1 line of code. Understanding PreThink and CPU usage but not HamSandwich doesn't make much sense.

Code:
RegisterHam(Ham_Player_Jump, "player", "OnPlayerJump", 1) public OnPlayerJump(id) {     // your code here... }
__________________

Last edited by OciXCrom; 02-25-2021 at 13:17.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Reply


Thread Tools
Display Modes

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 16:35.


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