AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   General (https://forums.alliedmods.net/forumdisplay.php?f=7)
-   -   Avoid forwards (thinks, cmd) (https://forums.alliedmods.net/showthread.php?t=316415)

SomewhereLost 05-21-2019 20:15

Avoid forwards (thinks, cmd)
 
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 ?

gabuch2 05-21-2019 21:14

Re: Avoid forwards (thinks, cmd)
 
I don't think getting buttons is an expensive operation compared to string operations for example.

Bugsy 05-21-2019 22:41

Re: Avoid forwards (thinks, cmd)
 
@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.

SomewhereLost 05-22-2019 00:06

Re: Avoid forwards (thinks, cmd)
 
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.

HamletEagle 05-22-2019 10:13

Re: Avoid forwards (thinks, cmd)
 
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?

SomewhereLost 05-22-2019 11:19

Re: Avoid forwards (thinks, cmd)
 
Quote:

Originally Posted by HamletEagle (Post 2652661)
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?

E1_531G 05-22-2019 12:12

Re: Avoid forwards (thinks, cmd)
 
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.

SomewhereLost 05-22-2019 12:45

Re: Avoid forwards (thinks, cmd)
 
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.

HamletEagle 05-22-2019 13:49

Re: Avoid forwards (thinks, cmd)
 
Quote:

Originally Posted by SomewhereLost (Post 2652672)
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.

SomewhereLost 05-22-2019 15:29

Re: Avoid forwards (thinks, cmd)
 
Quote:

Originally Posted by HamletEagle (Post 2652705)
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?


All times are GMT -4. The time now is 17:23.

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