ProcessTick
#1

I saw this function in some of the plugins. I'm interesed in how it works and where this function is documented. Can someone explane me that?
Reply
#2

I didn't find a documentation but if you look at the anti cheat plugin or drift counter then u see it's like a timer called every 'process tick', let's say a clock in a process which ticks, every tick it gets executed. It is different per operating system.
Reply
#3

well the processTick function gets called in every frame
when the samp server finishs executing everything in the frame(script, sync ...) it calls the plugin processTick function
lets say the server works with 30 FPS, so the processTick func will be called 30 times per second
so basically, its a plugin frame
Reply
#4

thanks
Reply
#5

Quote:
Originally Posted by Gamer_Z
Посмотреть сообщение
(...)
At my pc it needs 45 seconds to do 10000 empty ticks
(...)
So in fact:
10000/45 = 222,2
(well there is no upscore so I used an underscore - it means infite repeat of the number selected)
ticks per second
Two Hundred Twenty Two Frames Per Seconds .. What a fast process tick frame! :P
Reply
#6

Hi all
Lets say in ProcessTick() I have a condition that would call a callback
Код:
PLUGIN_EXPORT void PLUGIN_CALL ProcessTick()
{
   if(blah == something)
   {
	cell amx_Ret;
	int amx_Idx;

	if(amx_FindPublic(ThatAMX, "OnSnoobIsLost", &amx_Idx) == AMX_ERR_NONE) 
	{
		amx_Exec(ThatAMX,&amx_Ret,amx_Idx);
	}
   }
}
How can one loop thru all the Abstract Machine? (ThatAMX)

Thank you.
Reply
#7

Quote:
Originally Posted by snoob
Посмотреть сообщение
Hi all
Lets say in ProcessTick() I have a condition that would call a callback
Код:
PLUGIN_EXPORT void PLUGIN_CALL ProcessTick()
{
   if(blah == something)
   {
	cell amx_Ret;
	int amx_Idx;

	if(amx_FindPublic(ThatAMX, "OnSnoobIsLost", &amx_Idx) == AMX_ERR_NONE) 
	{
		amx_Exec(ThatAMX,&amx_Ret,amx_Idx);
	}
   }
}
How can one loop thru all the Abstract Machine? (ThatAMX)

Thank you.
You need to use AmxLoad and AmxUnloac to construct a list of all the abstract machines:
pawn Код:
vector          <AMX *>                         amx_list;
PLUGIN_EXPORT int PLUGIN_CALL AmxLoad( AMX *amx )
{
    amx_list.push_back(amx);
    return amx_Register( amx, AMXNatives, -1 );
}

PLUGIN_EXPORT int PLUGIN_CALL AmxUnload( AMX *amx )
{
    std::vector<AMX *>::iterator i = amx_list.begin();
    while (i != amx_list.end())
    {
        i = amx_list.erase(i);
    }
    return AMX_ERR_NONE;
}
//edit: I think I see a bug in my snippet, probably it should be, anyone confirm?:
PLUGIN_EXPORT int PLUGIN_CALL AmxUnload( AMX *amx )
{
    std::vector<AMX *>::iterator i = amx_list.begin();
    while (i != amx_list.end())
    {
        if(amx == amx_list.at(i))amx_list.erase(i);
        ++i;
    }
    return AMX_ERR_NONE;
}
then you can loop them in different ways, I do this like:
pawn Код:
PLUGIN_EXPORT void PLUGIN_CALL
    ProcessTick()
{
    if(g_Ticked == g_TickMax)
    {
        if(!locked.passer)//try another time if locked, won't lagg the server, while(true) {} would
        {
            locked.passer = true;
            if(!PassVector.empty())
            {
                cell amx_addr = NULL;
                cell * amx_physAddr = NULL;
                int ptr;
                for (std::vector<AMX *>::iterator a = amx_list.begin(); a != amx_list.end(); ++a)
                {
                    if (!amx_FindPublic(* a, "GPS_WhenRouteIsCalculated", &ptr) && PassVector.front().script == *a)
                    {
                        amx_Push(* a, PassVector.front().MoveCost);
                        amx_Push(* a, PassVector.front().amount_of_nodes);
                        amx_PushArray(* a, &amx_addr, &amx_physAddr, PassVector.front().Paths, 1792);
                        amx_Push(* a, PassVector.front().extraid);
                        amx_Exec(* a, NULL, ptr);
                        amx_Release(* a,amx_addr);
                    }
                }
                PassVector.pop();
            }
            locked.passer = false;
        }
    }
}
(Code snippet from RouteConnector plugin)
Reply
#8

Quote:

It is different per operating system.

And that's a problem. Never use precise calculation on ProcessTick cause you never know how it's differentiate between each clients.
Reply
#9

Gamer_Z, you better use a simple list for that:
pawn Код:
#include <list>

std::list <AMX *>
    g_pAmx
;
pawn Код:
PLUGIN_EXPORT int PLUGIN_CALL AmxLoad(AMX *pAmx) {
    g_pAmx.push_back(pAmx);
    return amx_Register(pAmx, amx_Natives, -1);
}
pawn Код:
PLUGIN_EXPORT int PLUGIN_CALL AmxUnload(AMX *pAmx) {
    g_pAmx.remove(pAmx);
    return AMX_ERR_NONE;
}
pawn Код:
PLUGIN_EXPORT void PLUGIN_CALL ProcessTick() {
    #define MAX_TICKS (30)

    static int
        s_iTicks,
        s_iIdx
    ;
    if(!(s_iTicks++ % MAX_TICKS)) {
        for(std::list <AMX *>::iterator i = g_pAmx.begin(); i != g_pAmx.end(); ++i) {
            if(!amx_FindPublic(*i, "MyPublic", &s_iIdx)) {
                amx_Push(*i, 5);
                amx_Push(*i, 10);
                amx_Exec(*i, NULL, s_iIdx);
            }
        }
    }
}
Reply
#10

Quote:
Originally Posted by ******
Посмотреть сообщение
What is that "locked.passer" variable doing? Is it set anywhere else? Your comments about "while (true)" seem to indicate a multi-threaded architecture, but there's no protection on the variable read/write.
isn't a bool just setting a bit? I don't know if my (too) simple approach multi-thread to prevent using a vector at the same time truly works, but it didn't let me down yet. However if there is (Or em yes there is.. :P) any better way any suggestion /link/comment is appreciated on how to accomplish it/ I admin it: I don't understand mutexes.

Quote:
Originally Posted by RyDeR`
Посмотреть сообщение
Gamer_Z, you better use a simple list for that:
pawn Код:
#include <list>

std::list <AMX *>
    g_pAmx
;
pawn Код:
PLUGIN_EXPORT int PLUGIN_CALL AmxLoad(AMX *pAmx) {
    g_pAmx.push_back(pAmx);
    return amx_Register(pAmx, amx_Natives, -1);
}
pawn Код:
PLUGIN_EXPORT int PLUGIN_CALL AmxUnload(AMX *pAmx) {
    g_pAmx.remove(pAmx);
    return AMX_ERR_NONE;
}
pawn Код:
PLUGIN_EXPORT void PLUGIN_CALL ProcessTick() {
    #define MAX_TICKS (30)

    static int
        s_iTicks,
        s_iIdx
    ;
    if(!(s_iTicks++ % MAX_TICKS)) {
        for(std::list <AMX *>::iterator i = g_pAmx.begin(); i != g_pAmx.end(); ++i) {
            if(!amx_FindPublic(*i, "MyPublic", &s_iIdx)) {
                amx_Push(*i, 5);
                amx_Push(*i, 10);
                amx_Exec(*i, NULL, s_iIdx);
            }
        }
    }
}
Oh nice one, also possible
Reply
#11

in regard to my question, thank you very much guys, that was very helpful.
Reply
#12

Quote:
Originally Posted by RyDeR`
Посмотреть сообщение
pawn Код:
if(!(s_iTicks++ % MAX_TICKS))

}
Does the % operator get affected by integer / variable overflows?

I mean look at this..
Код:
[16:51:04] 2147483630 1
[16:51:04] 2147483631 0
[16:51:04] 2147483632 0
[16:51:04] 2147483633 0
[16:51:04] 2147483634 0
[16:51:04] 2147483635 0
[16:51:04] 2147483636 0
[16:51:04] 2147483637 0
[16:51:04] 2147483638 0
[16:51:04] 2147483639 0
[16:51:04] 2147483640 1
[16:51:04] 2147483641 0//1
[16:51:04] 2147483642 0//2
[16:51:04] 2147483643 0//...
[16:51:04] 2147483644 0
[16:51:04] 2147483645 0
[16:51:04] 2147483646 0
[16:51:04] 2147483647 0
[16:51:04] -- 0//WTF?
[16:51:04] -2147483647 0
[16:51:04] -2147483646 0
[16:51:04] -2147483645 0
[16:51:04] -2147483644 0
[16:51:04] -2147483643 0
[16:51:04] -2147483642 0
[16:51:04] -2147483641 0//15 instead of 10
[16:51:04] -2147483640 1
[16:51:04] -2147483639 0
[16:51:04] -2147483638 0
[16:51:04] -2147483637 0
[16:51:04] -2147483636 0
[16:51:04] -2147483635 0
[16:51:04] -2147483634 0
[16:51:04] -2147483633 0
[16:51:04] -2147483632 0
[16:51:04] -2147483631 0
[16:51:04] -2147483630 1
[16:51:04] -2147483629 0
[16:51:04] -2147483628 0
[16:51:04] -2147483627 0
[16:51:04] -2147483626 0
[16:51:04] -2147483625 0
[16:51:04] -2147483624 0
[16:51:04] -2147483623 0
[16:51:04] -2147483622 0
[16:51:04] -2147483621 0
[16:51:04] -2147483620 1
[16:51:04] -2147483619 0
[16:51:04] -2147483618 0
[16:51:04] -2147483617 0
[16:51:04] -2147483616 0
[16:51:04] -2147483615 0
[16:51:04] -2147483614 0
[16:51:04] -2147483613 0
[16:51:04] -2147483612 0
[16:51:04] -2147483611 0
[16:51:04] -2147483610 1
[16:51:04] -2147483609 0
[16:51:04] -2147483608 0
[16:51:04] -2147483607 0
[16:51:04] -2147483606 0
[16:51:04] -2147483605 0
[16:51:04] -2147483604 0
[16:51:04] -2147483603 0
[16:51:04] -2147483602 0
[16:51:04] -2147483601 0
[16:51:04] -2147483600 1
[16:51:04] -2147483599 0
[16:51:04] -2147483598 0
[16:51:04] -2147483597 0
[16:51:04] -2147483596 0
[16:51:04] -2147483595 0
[16:51:04] -2147483594 0
[16:51:04] -2147483593 0
[16:51:04] -2147483592 0
[16:51:04] -2147483591 0
[16:51:04] -2147483590 1
[16:51:04] -2147483589 0
[16:51:04] -2147483588 0
[16:51:04] -2147483587 0
[16:51:04] -2147483586 0
[16:51:04] -2147483585 0
[16:51:04] -2147483584 0
[16:51:04] -2147483583 0
[16:51:04] -2147483582 0
[16:51:04] -2147483581 0
[16:51:04] -2147483580 1
[16:51:04] -2147483579 0
[16:51:04] -2147483578 0
[16:51:04] -2147483577 0
[16:51:04] -2147483576 0
[16:51:04] -2147483575 0
[16:51:04] -2147483574 0
[16:51:04] -2147483573 0
[16:51:04] -2147483572 0
[16:51:04] -2147483571 0
[16:51:04] -2147483570 1
[16:51:04] -2147483569 0
[16:51:04] -2147483568 0
[16:51:04] -2147483567 0
with:
pawn Код:
for (new i = 0; i < 100; i++)
        printf("%d %b", 2147483630 + i, ((2147483630 + i) % 10) ==0);
If it affects pawn it does C++ too.. or am I wrong?

Also I think == is faster than %.. (I know it's not really a big deal but anyway..)
Reply
#13

where i == 18 it's interesting, %d just prints a '--',
2147483630+18 = 2147483648 = 2^31 , this is where the overflow happens, any explaination why it's '--' ? ; o
Reply
#14

Quote:
Originally Posted by ******
Посмотреть сообщение
There is a mismatch in signed integers - there are 2147483648 negative numbers, but only 2147483647 positive numbers. The number 0x80000000 is the extra value and has another problem - to convert a negative number to its positive equivalent you do ~n+1:

-1 = 0xFFFFFFFF
~0xFFFFFFFF+1 = 1

If you do that to 0x80000000 you get 0x80000000 (i.e. itself). I don't know if it printing oddly is a bug or intended, but it happens and can be useful.
ah ok I understand that, thanks for the useful info
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)