02.01.2014, 11:59
Hey,
As you may know, Y_Less once stated that "wait/Sleep is considered harmful" here:
https://sampforum.blast.hk/showthread.php?tid=257660
So anyways, I've been working on a library recently that allows the ability to use "Wait" inside another function without hanging the server. This is achieved by:
The explanation above sounds complex, however the only to achieve this is to dig down into assembly by relying on the "LCTRL" and "SCTRL" instructions.
This will allow code like:
AFAIK, there's also a neat way to do it with y_inline, however the purpose of this is to implement a single-use function that can be used anywhere.
Is this a good idea or not? Thanks!
As you may know, Y_Less once stated that "wait/Sleep is considered harmful" here:
https://sampforum.blast.hk/showthread.php?tid=257660
So anyways, I've been working on a library recently that allows the ability to use "Wait" inside another function without hanging the server. This is achieved by:
- Loading the address and CIP of the current function and saving it somewhere.
- Halting the execution of the current function (at the location Wait was used).
- Setting up a timer for xx milliseconds that will call the saved function.
- When the timer is called, jump to the saved function and CIP + 1.
The explanation above sounds complex, however the only to achieve this is to dig down into assembly by relying on the "LCTRL" and "SCTRL" instructions.
This will allow code like:
pawn Code:
Countdown(playerid)
{
GameTextForPlayer(playerid, "~g~3", 3000, 3);
Wait(1000);
GameTextForPlayer(playerid, "~g~2", 3000, 3);
Wait(1000);
GameTextForPlayer(playerid, "~g~1", 3000, 3);
Wait(1000);
GameTextForPlayer(playerid, "~g~Go!", 3000, 3);
}
Is this a good idea or not? Thanks!