AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   [INFO] Think workflow (https://forums.alliedmods.net/showthread.php?t=110634)

joropito 12-01-2009 09:52

[INFO] Think workflow
 
I posting this here because I think I'm right with my conclussions.
Anyway, I can fix any error i've made.

Because I didn't knew exactly how the things go inside the engine, I've read hlsdk to understand it.
Here's the flow of calls in PreThink and PostThink (see the attach)

So, as I understand, every call to PreThink implies (in order) calling PlayerPreThink, ItemPreFrame and UpdateClientData and after that, PreThink will return.

I only show that calls who can be used with hamsandwitch but there some other calls that we can't use in an amxx plugin (but yes for modules).

I think this is usefull to people who doesn't know the order of each call and when it's used.

If anyone know that I'm missing something or I'm wrong, please let me know.
Thanks

EDIT:

Here's the updated workflow (made by Connor, updated by me)

Code:

SV_Frame
{
        looped SV_ExecuteClientMessage ->     
        {
                pfnCmdStart (FM_CmdStart)
                pfnPlayerPreThink (client_PreThink , FM_PlayerPreThink)
                pfnThink (pfnThink, FM_Think)
                pfnPM_Move
                pfnPlayerPostThink (client_PostThink, FM_PlayerPostThink)
                pfnCmdEnd (FM_CmdEnt)
        }
 
        SV_Physics
        {
                pfnStartFrame (server_frame, FM_StartFrame)
                loop for each entity ->
                {
                        if movetype ->
                        {
                                SV_Physics_*
                                if touch => pfnTouch (pfnTouch, FM_Touch)
                        }
                        pfnThink (pfnThink, FM_Think) // entities only
                }
        }
 
        SV_SendClientMessages (looping)
        {
                SV_WriteClientdataToMessage -> gEntityInterface.pfnUpdateClientData (FM_UpdateClientData)
                SV_WriteEntitiesToClient -> gEntityInterface.pfnAddToFullPack (FM_AddToFullPack)
        }
}


Javivi 12-01-2009 10:41

Re: [INFO] Think Flow
 
Interesting

ConnorMcLeod 12-06-2009 06:34

Re: [INFO] Think workflow
 
I think you are wrong with PreThink() (Ham_Think) called from PlayerPreThink (Ham_Player_PreThink)

Reading HLSDK it seems to be :

PlayerPreThink (from client.cpp) I don't know if it's engine forward client_PreThink and fakemeta FM_PlayerPreThink but it sounds like it is correct.
Code:
/* ================ PlayerPreThink Called every frame before physics are run ================ */ void PlayerPreThink( edict_t *pEntity ) {     entvars_t *pev = &pEntity->v;     CBasePlayer *pPlayer = (CBasePlayer *)GET_PRIVATE(pEntity);     if (pPlayer)
        pPlayer->PreThink( );
}

Then CBasePlayer::PreThink from player.cpp (Ham_Player_PreThink)
Code:
void CBasePlayer::PreThink(void) {     int buttonsChanged = (m_afButtonLast ^ pev->button);    // These buttons have changed this frame         // Debounced button codes for pressed/released     // UNDONE: Do we need auto-repeat?     m_afButtonPressed =  buttonsChanged & pev->button;    // The changed ones still down are "pressed"     m_afButtonReleased = buttonsChanged & (~pev->button);   // The ones not down are "released"
    g_pGameRules->PlayerThink( this );
    if ( g_fGameOver )         return;         // intermission or finale     UTIL_MakeVectors(pev->v_angle);             // is this still used?    
    ItemPreFrame( );
    WaterMove();     if ( g_pGameRules && g_pGameRules->FAllowFlashlight() )         m_iHideHUD &= ~HIDEHUD_FLASHLIGHT;     else         m_iHideHUD |= HIDEHUD_FLASHLIGHT;     // JOHN: checks if new client data (for HUD and view control) needs to be sent to the client
    UpdateClientData();

And from that one are called
* g_pGameRules->PlayerThink (CHalfLifeMultiplay :: PlayerThink in multiplayer that is hookable with orpheu module)
* ItemPreFrame
* UpdateClientData


Also, ItemPreFrame is not Ham_Item_PreFrame, it's CBasePlayer::ItemPreFrame (not hookable with hamsandwich) from where m_pActiveItem->ItemPreFrame( ); (Ham_Item_PreFrame) is called.

Code:

void CBasePlayer::ItemPreFrame()
{
#if defined( CLIENT_WEAPONS )
    if ( m_flNextAttack > 0 )
#else
    if ( gpGlobals->time < m_flNextAttack )
#endif
        {
                return;
        }

        if (!m_pActiveItem)
                return;

        m_pActiveItem->ItemPreFrame( );
}


joropito 12-06-2009 07:41

Re: [INFO] Think workflow
 
That's what I saw.

I don't mean each Ham_* where called directly but the sequence it's right.

I'm trying to understand (and show) the order in which each function is called.

I can put conditionals in the graphics to understand the difference you are talking about.

ConnorMcLeod 12-06-2009 08:56

Re: [INFO] Think workflow
 
You also forgot one thing for postthink, i guess it is like that :

Code:

PlayerPostThink (client_PreThink/FM_PlayerPostThink)
|
->    CBasePlayer::PostThink (Ham_Player_PostThink)
      |
      ->    CBasePlayer::ItemPostFrame (should be avaible with orpheu module)
            |
            ->    CBasePlayer::ImpulseCommands (Ham_Player_ImpulseCommands)
            ->    CBasePlayerWeapon::ItemPostFrame (Ham_Item_PostFrame)


joropito 05-25-2013 12:23

Re: [INFO] Think workflow
 
Just to keep track how things are called I post this here (credits to Connor)

Code:

SV_Frame
{
        looped SV_ExecuteClientMessage ->     
        {
                pfnCmdStart (FM_CmdStart)
                pfnPlayerPreThink (client_PreThink , FM_PlayerPreThink)
                pfnThink (pfnThink, FM_Think)
                pfnPM_Move
                pfnPlayerPostThink (client_PostThink, FM_PlayerPostThink)
                pfnCmdEnd (FM_CmdEnt)
        }
 
        SV_Physics
        {
                pfnStartFrame (server_frame, FM_StartFrame)
                loop for each entity ->
                {
                        if movetype ->
                        {
                                SV_Physics_*
                                if touch => pfnTouch (pfnTouch, FM_Touch)
                        }
                        pfnThink (pfnThink, FM_Think) // entities only
                }
        }
 
        SV_SendClientMessages (looping)
        {
                SV_WriteClientdataToMessage -> gEntityInterface.pfnUpdateClientData (FM_UpdateClientData)
                SV_WriteEntitiesToClient -> gEntityInterface.pfnAddToFullPack (FM_AddToFullPack)
        }
}


ConnorMcLeod 05-25-2013 12:58

Re: [INFO] Think workflow
 
I wanted to post it and completly forgot.
Everybody will notice that server_frame is called in the middle of the routine, can have its importance.

joropito 07-31-2013 08:05

Re: [INFO] Think workflow
 
Small update in SV_Physics and moved updated workflow to first post

ConnorMcLeod 07-31-2013 08:11

Re: [INFO] Think workflow
 
What have you updated ?

joropito 07-31-2013 08:18

Re: [INFO] Think workflow
 
Quote:

Originally Posted by ConnorMcLeod (Post 2002781)
What have you updated ?

SV_Physics

Code:

loop for each entity ->
{
        if movetype ->
        {
                SV_Physics_*
                if touch => pfnTouch (pfnTouch, FM_Touch)
        }
        pfnThink (pfnThink, FM_Think) // entities only
}



All times are GMT -4. The time now is 22:19.

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