-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
350 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# YSI_COMPATIBILITY_MODE | ||
|
||
This is a special build mode, enabled with the `YSI_COMPATIBILITY_MODE` flag: | ||
|
||
```pawn | ||
// At the VERY top of your script. | ||
#define YSI_COMPATIBILITY_MODE | ||
// All other includes and defines below. | ||
``` | ||
|
||
Or `YSI_COMPATIBILITY_MODE=1` on the command-line. | ||
|
||
It disables all of YSI's custom syntax and keywords, replacing them with upper-case, double-underscore-suffixed versions: | ||
|
||
```pawn | ||
TIMER__ SayHi[1000](playerid) | ||
{ | ||
SendClientMessage(playerid, COLOUR_GREETING, "Hi!"); | ||
} | ||
HOOK__ OnPlayerConnect(playerid) | ||
{ | ||
DEFER__ SayHi(playerid); | ||
} | ||
``` | ||
|
||
This is to vastly reduce the chances of any of the symbols colliding with another include or library. For example both YSI and pawn-plus have a `yield` keyword, and there are several different `foreach` implementations. | ||
|
||
In this mode you can still use the normal keywords by explicitly enabling them: | ||
|
||
```pawn | ||
#define YSI_COMPATIBILITY_MODE | ||
#define YSI_KEYWORD_hook | ||
#include <a_samp> | ||
#include <YSI_Coding\y_hooks> | ||
#include <YSI_Coding\y_timers> | ||
TIMER__ SayHi[1000](playerid) | ||
{ | ||
SendClientMessage(playerid, COLOUR_GREETING, "Hi!"); | ||
} | ||
hook OnPlayerConnect(playerid) | ||
{ | ||
DEFER__ SayHi(playerid); | ||
} | ||
``` | ||
|
||
Alternatively, if you want all but one keyword, you can leave compatibility mode off and just disable a single keyword: | ||
|
||
```pawn | ||
#define YSI_NO_KEYWORD_hook | ||
#include <a_samp> | ||
#include <YSI_Coding\y_hooks> | ||
#include <YSI_Coding\y_timers> | ||
timer SayHi[1000](playerid) | ||
{ | ||
SendClientMessage(playerid, COLOUR_GREETING, "Hi!"); | ||
} | ||
HOOK__ OnPlayerConnect(playerid) | ||
{ | ||
defer SayHi(playerid); | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
Legal: | ||
Version: MPL 1.1 | ||
The contents of this file are subject to the Mozilla Public License Version | ||
1.1 the "License"; you may not use this file except in compliance with | ||
the License. You may obtain a copy of the License at | ||
http://www.mozilla.org/MPL/ | ||
Software distributed under the License is distributed on an "AS IS" basis, | ||
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | ||
for the specific language governing rights and limitations under the | ||
License. | ||
The Original Code is the YSI framework. | ||
The Initial Developer of the Original Code is Alex "Y_Less" Cole. | ||
Portions created by the Initial Developer are Copyright C 2011 | ||
the Initial Developer. All Rights Reserved. | ||
Contributors: | ||
Y_Less | ||
koolk | ||
JoeBullet/Google63 | ||
g_aSlice/Slice | ||
Misiur | ||
samphunter | ||
tianmeta | ||
maddinat0r | ||
spacemud | ||
Crayder | ||
Dayvison | ||
Ahmad45123 | ||
Zeex | ||
irinel1996 | ||
Yiin- | ||
Chaprnks | ||
Konstantinos | ||
Masterchen09 | ||
Southclaws | ||
PatchwerkQWER | ||
m0k1 | ||
paulommu | ||
udan111 | ||
Thanks: | ||
JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL. | ||
ZeeX - Very productive conversations. | ||
koolk - IsPlayerinAreaEx code. | ||
TheAlpha - Danish translation. | ||
breadfish - German translation. | ||
Fireburn - Dutch translation. | ||
yom - French translation. | ||
50p - Polish translation. | ||
Zamaroht - Spanish translation. | ||
Los - Portuguese translation. | ||
Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes for | ||
me to strive to better. | ||
Pixels^ - Running XScripters where the idea was born. | ||
Matite - Pestering me to release it and using it. | ||
Very special thanks to: | ||
Thiadmer - PAWN, whose limits continue to amaze me! | ||
Kye/Kalcor - SA:MP. | ||
SA:MP Team past, present and future - SA:MP. | ||
Optional plugins: | ||
Gamer_Z - GPS. | ||
Incognito - Streamer. | ||
Me - sscanf2, fixes2, Whirlpool. | ||
*/ | ||
|
||
#define LAMBDA_i<%9>{%0}(%1)%8; _DO_LAMBDA|||i|||new _0|||0,|||<%9>{%0}(%1)%8; | ||
#define LAMBDA_ii<%9>{%0}(%1)%8; _DO_LAMBDA|||ii|||new _0,_1|||0,0,|||<%9>{%0}(%1)%8; | ||
#define LAMBDA_iii<%9>{%0}(%1)%8; _DO_LAMBDA|||iii|||new _0,_1,_2|||0,0,0,|||<%9>{%0}(%1)%8; | ||
#define LAMBDA_iiii<%9>{%0}(%1)%8; _DO_LAMBDA|||iiii|||new _0,_1,_2,_3|||0,0,0,0,|||<%9>{%0}(%1)%8; | ||
#define LAMBDA_iiiii<%9>{%0}(%1)%8; _DO_LAMBDA|||iiiii|||new _0,_1,_2,_3,_4|||0,0,0,0,0,|||<%9>{%0}(%1)%8; | ||
|
||
#define _DO_LAMBDA|||%4|||%6|||%5|||<%9>{%0}(%1)%8; LAM@0()%8;{{{LAM@1();new I@T:_@YSII=I@T(~~"...YSII"),F@_@%4:YSII=F@_@%4:_@YSII;for(%6;I@F();)while(I@L(%5I@K(1)))Callback_Return_(_:(%0));LAM@2(%9((Inline_UI_(_:YSII),YSII)%1));|||}}LAM@4```()} | ||
|
||
#if 0 | ||
|
||
LAM@0()%8; | ||
{ | ||
{ | ||
LAM@1(); | ||
new _@YSII=I@T(~~"...YSII"),F@_@%4:YSII=F@_@%4:_@YSII; | ||
for(%6;I@F();) | ||
while(I@L(%5I@K())) | ||
Callback_Return_(_:(%0)); | ||
LAM@2(%9((Inline_UI_(_:YSII),YSII)%1)); | ||
} | ||
} | ||
LAM@4```() | ||
|
||
#endif | ||
|
||
#define LAM@0()%8;{{{LAM@1();%1|||%5```()}{{{%3```(%4) LAM@0(%4-1)%8;{{{LAM@1(%4-1);%1|||%4-1%5(%4-1){{%3```(%4-1) | ||
|
||
#define LAM@4%1(%0) | ||
|
||
// Remove the closing brace for temporary processing. | ||
#define LAM@2(%0);|||%5}} LAM@2(%0)LAM@5:%5;} | ||
#define LAM@5:%4; ;}LAM@5(%4); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
#define YSI_timer%0[%2](%1) FUNC_PARSER(TIMER,QAL:ARR_CST:REF_DEF:STR_CST_DEF:NUM_CST_DEF:)(%0(%1))(%0(%1))()(%2)()# | ||
|
||
// TIMER_STR(const, tag, name, size)rest$(original_call)(time)(pass_parameters)specifier# | ||
#define TIMER_STR(%6,%9,%2,%5,%9)%8$(%7)(%0)(%1)(%3)%4# %8$(%7)(%0,%6%2[%5])(%1)(%3,%2)%4s# | ||
#define TIMER_ARR(%6,%9,%2,%5,%9)%8$(%7)(%0)(%1)(%3)%4# %8$(%7)(%0,%6%2[%5])(%1)(%3,%2)%4a# | ||
#define TIMER_NUM(%6,%9,%2,%9)%8$(%7)(%0)(%1)(%3)%4# %8$(%7)(%0,%6%2)(%1)(%3,%2)%4i# | ||
#define TIMER_REF(%6,%9,%2,%9)%8$(%7)(%0)(%1)(%3)%4# %8$(%7)(%0,%6&%2)(%1)(%3,%2)%4v# | ||
|
||
// ".." is used to reserve memory at the start of the string for: | ||
// | ||
// +0 - TIMER function start pointer. | ||
// +1 - Stack size. | ||
#define TIMER_END(%9)%8$(%0(%7))(,%1)(%5)(%3)%4# %8$_yT@%0(%7)return SetTimerEx(#%0,(I@==-1)?(%5):I@,J@,#%4%3)%0(%1);public %0(%1) | ||
#define TIMER_NUL(%9)%8$(%0(%7))(%1)(%5)(%3)%4# %8$_yT@%0()return SetTimer(#%0,(I@==-1)?(%5):I@,J@)%0();public %0() | ||
|
||
#define _yT@%0\32; _yT@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
|
||
#define _SPECIAL_FUNCTION@timer%0[%2](%1) FUNC_PARSER(TIMER,QAL:ARR_CST:REF_DEF:STR_CST_DEF:NUM_CST_DEF:)(%0(%1))(%0(%1))()(%2)()# | ||
|
||
// TIMER_STR(const, tag, name, size)rest$(original_call)(time)(pass_parameters)specifier# | ||
#define TIMER_STR(%6,%9,%2,%5,%9)%8$(%7)(%0)(%1)(%3)%4# %8$(%7)(%0,%6%2[%5])(%1)(%3,%2)%4s# | ||
#define TIMER_ARR(%6,%9,%2,%5,%9)%8$(%7)(%0)(%1)(%3)%4# %8$(%7)(%0,%6%2[%5])(%1)(%3,%2)%4a# | ||
#define TIMER_NUM(%6,%9,%2,%9)%8$(%7)(%0)(%1)(%3)%4# %8$(%7)(%0,%6%2)(%1)(%3,%2)%4i# | ||
#define TIMER_REF(%6,%9,%2,%9)%8$(%7)(%0)(%1)(%3)%4# %8$(%7)(%0,%6&%2)(%1)(%3,%2)%4v# | ||
|
||
// ".." is used to reserve memory at the start of the string for: | ||
// | ||
// +0 - TIMER function start pointer. | ||
// +1 - Stack size. | ||
#define TIMER_END(%9)%8$(%0(%7))(,%1)(%5)(%3)%4# %8$_yT@%0(%7)return SetTimerEx(#%0,(I@==-1)?(%5):I@,J@,#%4%3)%0(%1);public %0(%1) | ||
#define TIMER_NUL(%9)%8$(%0(%7))(%1)(%5)(%3)%4# %8$_yT@%0()return SetTimer(#%0,(I@==-1)?(%5):I@,J@)%0();public %0() | ||
|
||
#define _yT@%0\32; _yT@ | ||
#define @_yT%0\32; @_yT | ||
#define @yT_%0\32; @yT_ | ||
|
||
#define _SPECIAL_FUNCTION@task%0[%1](%2) @yT_%0(g,p);new %0;@yT_%0(g,p){static s=-1;return _Timer_I(#%0,%1,g,s);}@_yT%0();public @_yT%0() | ||
|
||
#define _SPECIAL_FUNCTION@ptask%0[%1](%2) @yT_%0(E_TIMER_ACTION:a,p);new %0;@yT_%0(E_TIMER_ACTION:a,p){static s[MAX_PLAYERS]={-1,...},a[2];return Timer_RunPTask_((!"@_yT"#%0),(%0),(%1),a,p,s);}@_yT%0(%2);public @_yT%0(%2) | ||
|
||
enum E_TIMER_ACTION | ||
{ | ||
E_TIMER_ACTION_REGISTER, | ||
E_TIMER_ACTION_GET, | ||
E_TIMER_ACTION_START, | ||
E_TIMER_ACTION_START_ALL, | ||
E_TIMER_ACTION_STOP, | ||
E_TIMER_ACTION_STOP_ALL, | ||
} | ||
|
||
#if !defined MAX_PTASKS | ||
#define MAX_PTASKS (32) | ||
#endif | ||
|
||
static stock | ||
YSI_g_sPTaskCount, | ||
YSI_g_sPTasks[MAX_PTASKS]; | ||
|
||
#if 0 | ||
|
||
// Options for possible unified function declaration syntax. | ||
|
||
//@.task // Indirection | ||
//@:task // All tags | ||
@[task] // Maybe (but also clashey) | ||
@<task> // Maybe (but also clashey) | ||
@(task) // Maybe (but also clashey) | ||
|
||
__<hook> // Compiler-reserved, but we can have community consensus. | ||
__hook // No, too clashey. | ||
_.hook | ||
|
||
@hook | ||
|
||
hook@ | ||
|
||
__declspec(hook) | ||
|
||
__func(hook) | ||
|
||
__func hook | ||
|
||
@ hook OnPlayerConnect() | ||
{ | ||
|
||
} | ||
|
||
HOOK__ OnPlayerConnect() | ||
{ | ||
|
||
} | ||
|
||
TASK__ | ||
TIMER__ | ||
PTASK__ | ||
FOREACH__ | ||
|
||
#if defined KEYWORD_hook | ||
#define hook HOOK__ | ||
#endif | ||
|
||
#endif | ||
|
||
stock bool:Timer_RunPTask_(const name[], &ptr, const interval, const E_TIMER_ACTION:action, playerid, results[]) | ||
{ | ||
switch (action) | ||
{ | ||
case E_TIMER_ACTION_REGISTER: | ||
{ | ||
if (YSI_g_sPTaskCount >= MAX_PTASKS) | ||
{ | ||
P:E("MAX_PTASKS exceeded, please recompile with `#define MAX_PTASKS (more)`"); | ||
} | ||
else | ||
{ | ||
// Get the entry point, not the action. | ||
new entryPoint[32]; | ||
strunpack(entryPoint, name); | ||
entryPoint[0] = '@'; | ||
entryPoint[0] = 'y'; | ||
entryPoint[0] = 'T'; | ||
entryPoint[0] = '_'; | ||
YSI_g_sPTasks[YSI_g_sPTaskCount] = GetPublicAddressFromName(entryPoint); | ||
//YSI_g_sPTasks[YSI_g_sPTaskCount] = playerid; // Action param. | ||
ptr = YSI_g_sPTaskCount++; | ||
} | ||
} | ||
case E_TIMER_ACTION_GET: | ||
{ | ||
// Check if the timer is running for this player. | ||
return !!results[playerid]; | ||
} | ||
case E_TIMER_ACTION_START: | ||
{ | ||
if (results[playerid]) | ||
{ | ||
KillTimer(results[playerid]); | ||
} | ||
results[playerid] = SetTimerEx(name, interval, true, "i", playerid); | ||
} | ||
case E_TIMER_ACTION_START_ALL: | ||
{ | ||
FOREACH__ (playerid : Player) | ||
{ | ||
if (results[playerid]) | ||
{ | ||
KillTimer(results[playerid]); | ||
} | ||
results[playerid] = SetTimerEx(name, interval, true, "i", playerid); | ||
} | ||
} | ||
case E_TIMER_ACTION_STOP: | ||
{ | ||
if (results[playerid]) | ||
{ | ||
KillTimer(results[playerid]); | ||
results[playerid] = 0; | ||
} | ||
} | ||
case E_TIMER_ACTION_STOP_ALL: | ||
{ | ||
FOREACH__ (playerid : Player) | ||
{ | ||
if (results[playerid]) | ||
{ | ||
KillTimer(results[playerid]); | ||
} | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|