07.09.2011, 19:01
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?
(...)
At my pc it needs 45 seconds to do 10000 empty ticks (...) |
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); } } }
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); } } } Thank you. |
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;
}
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;
}
}
}
It is different per operating system. |
#include <list>
std::list <AMX *>
g_pAmx
;
PLUGIN_EXPORT int PLUGIN_CALL AmxLoad(AMX *pAmx) {
g_pAmx.push_back(pAmx);
return amx_Register(pAmx, amx_Natives, -1);
}
PLUGIN_EXPORT int PLUGIN_CALL AmxUnload(AMX *pAmx) {
g_pAmx.remove(pAmx);
return AMX_ERR_NONE;
}
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);
}
}
}
}
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.
|
Gamer_Z, you better use a simple list for that:
pawn Код:
pawn Код:
pawn Код:
pawn Код:
|
[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
for (new i = 0; i < 100; i++)
printf("%d %b", 2147483630 + i, ((2147483630 + i) % 10) ==0);
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. |