Raised This Month: $ Target: $400
 0% 

client_prethink & posthink - clear explanation on proble


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SubStream
Veteran Member
Join Date: Aug 2005
Location: USA
Old 03-23-2006 , 08:02   client_prethink & posthink - clear explanation on proble
Reply With Quote #1

I dont particularly understand what prethink means... I know its a function but I dont understand what exactly its forward means... the documentation doesn't make sense to me... I am still tryin to understand it.
  • plugin_init - Forward for plugin initialization // obvious... forward for when the plugin initializes

    client_impulse - Forward for impulses. // again.. obvious... impulses are flashlight spray stuff like that

    server_changelevel - Forward for a server's changelevel. // obvious... when you change maps

    register_touch - Registers a touch action to a function. // I think that means when something touches something else?

    client_PostThink - Forward for PostThink() on a player.// what the hell is postthink???

    client_PreThink - Forward for PreThink() on a player. // and prethink???

So you can see why I am confused how/when to use client_prethink because the other stuff is self explanatory.. but this is not really to me.. could someone explain what exactly is happening when postthink and prethink occur? is it before or after an action or something? its kind of confusing without understanding that. A clear and simple response would be something in the form of...
"client_prethink basically is called when .......... happens" or
"client_prethink is triggered every time ....... occurs"

My only guess is that client_prethink means it reads the function and prethink triggers on its own based upon what is in the function but... im not completely sure... please only people who definetly know what they are talking about respond... like v3x or black rose... or brad... somebody with experience please.
SubStream is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 03-23-2006 , 08:31  
Reply With Quote #2

PreThink is called every time before a client renders a frame with physics. This means that if the client's FPS is 50, it will be called 50 times a second, just before each frame is actually rendered. This gives you a fraction of a second to change whatever you need to, before the client actually renders the frame.

PostThink works the same way, except it's a fraction of a second after.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
SubStream
Veteran Member
Join Date: Aug 2005
Location: USA
Old 03-23-2006 , 09:15  
Reply With Quote #3

ty very much that was like the most awesome explanation... now I can actually do stuff I couldn't do before cause I understand that ty
SubStream is offline
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 03-23-2006 , 09:20  
Reply With Quote #4

Just keep in mind that since they are called so frequently, that you want to limit the amount of processing that gets done there.
Brad is offline
organizedKaoS
Senior Member
Join Date: Feb 2006
Old 03-23-2006 , 14:18  
Reply With Quote #5

Quote:
Originally Posted by Hawk552
PreThink is called every time before a client renders a frame with physics. This means that if the client's FPS is 50, it will be called 50 times a second, just before each frame is actually rendered. This gives you a fraction of a second to change whatever you need to, before the client actually renders the frame.

PostThink works the same way, except it's a fraction of a second after.
Is prethink and posthink the only route to go as far as "changing" a clients actions? example is twisted's multijump plugin. Prethink checks if the player is jumping and pressing his jump button again while not on ground. Is pre/posthink the only way of achieving this kind of "client action modification"? Or is there any other possible way? Thanks
organizedKaoS is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 03-23-2006 , 15:45  
Reply With Quote #6

Quote:
Originally Posted by organizedKaoS
Quote:
Originally Posted by Hawk552
PreThink is called every time before a client renders a frame with physics. This means that if the client's FPS is 50, it will be called 50 times a second, just before each frame is actually rendered. This gives you a fraction of a second to change whatever you need to, before the client actually renders the frame.

PostThink works the same way, except it's a fraction of a second after.
Is prethink and posthink the only route to go as far as "changing" a clients actions? example is twisted's multijump plugin. Prethink checks if the player is jumping and pressing his jump button again while not on ground. Is pre/posthink the only way of achieving this kind of "client action modification"? Or is there any other possible way? Thanks
Not really, although it's easily the most effective. There are a number of other ways I can think of.

Code:
register_forward(FM_PlayerPreThink,"my_func") register_forward(FM_PlayerPostThink,"my_func")

Code:
register_think("player","my_func")

Code:
public server_frame() {     //... }

That's pretty much all I can think of. I think client_PreThink and PostThink are still the best though.

If you're going for optimization and can ommit Engine from the plugin, then I would go with the Fakemeta hooks (first example).
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
organizedKaoS
Senior Member
Join Date: Feb 2006
Old 03-23-2006 , 17:09  
Reply With Quote #7

So the fakemeta hooks would be the next step down from pre/postthink? I am asking because I run runemod and it is a big hog of pre/posthink. If I used the fakemeta forwards, say in twisteds multijump, would I just register the forwards, rename the pre/posthink publics, and point the forwards to the newly named publics? Or if not, could you please post an example....Thanks and much appreciated
organizedKaoS is offline
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 03-23-2006 , 17:14  
Reply With Quote #8

The fakemeta hooks are essentially the same as using client_pre/postthink except you don't have to have engine enabled. If you have engine enabled anyway, there's no need to use the fakemeta forwards.

If you did use fakemeta for this, the way you described of implementing it is accurate.
Brad is offline
organizedKaoS
Senior Member
Join Date: Feb 2006
Old 03-23-2006 , 17:29  
Reply With Quote #9

Quote:
Originally Posted by Brad
The fakemeta hooks are essentially the same as using client_pre/postthink except you don't have to have engine enabled. If you have engine enabled anyway, there's no need to use the fakemeta forwards.

If you did use fakemeta for this, the way you described of implementing it is accurate.
Understandable, like I said, Im running runemod and it uses pre/posthink alot. So would using the fakemeta forwards prevent any clashing? The multijump plugin by twisted has caused my server to crash due to the excess use of pre/posthink of runemod. I will try the fakemeta forwards while waiting for ur response...Thanks again
organizedKaoS is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 03-23-2006 , 18:36  
Reply With Quote #10

Quote:
Originally Posted by organizedKaoS
Quote:
Originally Posted by Brad
The fakemeta hooks are essentially the same as using client_pre/postthink except you don't have to have engine enabled. If you have engine enabled anyway, there's no need to use the fakemeta forwards.

If you did use fakemeta for this, the way you described of implementing it is accurate.
Understandable, like I said, Im running runemod and it uses pre/posthink alot. So would using the fakemeta forwards prevent any clashing? The multijump plugin by twisted has caused my server to crash due to the excess use of pre/posthink of runemod. I will try the fakemeta forwards while waiting for ur response...Thanks again
They work the same way. The only difference is that Engine calls Pre/PostThink anyways, even if you didn't initialize a forward. This means that it hogs more CPU. It does this for server_frame, and any other resource consuming hooks in it that I forgot.

Fakemeta however does not do this, which makes it favorable for optimization. The functions for Pre/PostThink are slightly less abstracted though.

As Brad said, if you're running Engine anyways, you'd might as well use it.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
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 16:30.


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