Raised This Month: $32 Target: $400
 8% 

Avoid forwards (thinks, cmd)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SomewhereLost
AlliedModders Donor
Join Date: Mar 2014
Location: Tomorrowland
Old 05-21-2019 , 20:15   Avoid forwards (thinks, cmd)
Reply With Quote #1

Hello,

A simple question. Fakemeta or Engine (also Ham) forwards such as pre/post thinks, cmd start/end etc. are said that they take loads of CPU usage. As for example I am using around 6 pre/post thinks (or cmdstart) in different plugins, lets say to get the button press (IN_JUMP, IN_ATTACK etc), is there any other known efficient way to avoid these forwards ?
__________________
SomewhereLost is offline
Send a message via Skype™ to SomewhereLost
gabuch2
AlliedModders Donor
Join Date: Mar 2011
Location: Chile
Old 05-21-2019 , 21:14   Re: Avoid forwards (thinks, cmd)
Reply With Quote #2

I don't think getting buttons is an expensive operation compared to string operations for example.
__________________
gabuch2 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-21-2019 , 22:41   Re: Avoid forwards (thinks, cmd)
Reply With Quote #3

@Gabe Iggy - Getting the buttons itself is not bad, it's what you need to do to continuously check if the player is pressing a button that the OP is asking (cmd start, prethink). You basically need to constantly check every frame to see if they are pressing/holding/released a button.

You can improve some things by hooking attack using a hamsandwich, which will be more efficient. Detecting when a player presses a button like attack or jump, you really have no other choice that I know of.

In my opinion, it is always ideal to code as efficiently as possible, but this game is now 20 years old? Computers of today can handle games that are exponentially more advanced and CPU intensive. My recommendation would be to look at your CPU usage and see if you need to bother changing these plugins.
__________________
Bugsy is online now
SomewhereLost
AlliedModders Donor
Join Date: Mar 2014
Location: Tomorrowland
Old 05-22-2019 , 00:06   Re: Avoid forwards (thinks, cmd)
Reply With Quote #4

The only thing I have changed so far is, when detecting the E button (+use) instead of using prethink I used Ham_ObjectCaps.

Quote:
You can improve some things by hooking attack using a hamsandwich
I did this change too, instead of cmdstart (to detect if the player is in attack1) I hooked Ham_Primaryattack.

The only issue is, if I would use prethink and those for lets say 2 times that would be just fine. But Im using around 80 plugins, some of them are advanced and are in need of using thinks such as detecting player's fps.

But mostly I need an improvement for getting the buttons as at least 3 plugins are using prethinks for simple plugins as is Afk manager.

Quote:
I don't think getting buttons is an expensive operation compared to string operations for example.
It is not indeed, but if you use it constantly for detecting 1 thing from multiple plugins, then it gets messier.
__________________

Last edited by SomewhereLost; 05-22-2019 at 00:07.
SomewhereLost is offline
Send a message via Skype™ to SomewhereLost
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 05-22-2019 , 10:13   Re: Avoid forwards (thinks, cmd)
Reply With Quote #5

Why does it matter if one plugin hooks prethink and does one trivial task or if 10 plugins hook prethink and do one trivial task?
__________________
HamletEagle is offline
SomewhereLost
AlliedModders Donor
Join Date: Mar 2014
Location: Tomorrowland
Old 05-22-2019 , 11:19   Re: Avoid forwards (thinks, cmd)
Reply With Quote #6

Quote:
Originally Posted by HamletEagle View Post
one plugin hooks prethink and does one trivial task or if 10 plugins hook prethink and do one trivial task
So youre saying theres no performance difference in this case?
__________________

Last edited by SomewhereLost; 05-22-2019 at 11:21.
SomewhereLost is offline
Send a message via Skype™ to SomewhereLost
E1_531G
Senior Member
Join Date: Dec 2017
Old 05-22-2019 , 12:12   Re: Avoid forwards (thinks, cmd)
Reply With Quote #7

For example, take a look at the https://forums.alliedmods.net/showthread.php?t=141586 , but keep in mind it runs on servers with 32 players.
And everything is/was good.
__________________
My English is A0
E1_531G is offline
SomewhereLost
AlliedModders Donor
Join Date: Mar 2014
Location: Tomorrowland
Old 05-22-2019 , 12:45   Re: Avoid forwards (thinks, cmd)
Reply With Quote #8

I do use it as well, runs well but the server is experiencing lag spikes (happens not really often, 1 to 2 seconds red dots appear on net_graph) I dont really want to disable 80 plugins one by one, then test one by one on a full server. Only thing I can do is look up all of the plugins and remove unneccessary stuff or improve them (starting from the most CPU usageable stuff as the thread title says)

In that particular plugin, there's loads of stuff, thinks, server_frames so on which I have removed and you know what? I did notice an improvement.
__________________

Last edited by SomewhereLost; 05-22-2019 at 12:48.
SomewhereLost is offline
Send a message via Skype™ to SomewhereLost
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 05-22-2019 , 13:49   Re: Avoid forwards (thinks, cmd)
Reply With Quote #9

Quote:
Originally Posted by SomewhereLost View Post
So youre saying theres no performance difference in this case?
It will be 10 * O(trivial task) which is still O(trivial task)(a.k.a not a big deal). Notice I said trivial task, if you are doing expensive stuff in expensive forwards what I said doesn't necessarily hold.
__________________

Last edited by HamletEagle; 05-22-2019 at 13:49.
HamletEagle is offline
SomewhereLost
AlliedModders Donor
Join Date: Mar 2014
Location: Tomorrowland
Old 05-22-2019 , 15:29   Re: Avoid forwards (thinks, cmd)
Reply With Quote #10

Quote:
Originally Posted by HamletEagle View Post
It will be 10 * O(trivial task) which is still O(trivial task)(a.k.a not a big deal). Notice I said trivial task, if you are doing expensive stuff in expensive forwards what I said doesn't necessarily hold.
I'd hook it once (even tho if its a trivial task) and do something with it rather than 10 times.

So there are no other ways to detect the buttons?

Btw, I also use prethink to get the user aiming, catch the statusvalue+statustext and change the default text messages (Enemy : NAME, Friend : NAME). Its a poor way I know but any ideas on this one?
__________________

Last edited by SomewhereLost; 05-22-2019 at 15:44.
SomewhereLost is offline
Send a message via Skype™ to SomewhereLost
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 13:32.


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