y_distribute.inc 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. #if defined _INC_y_distribute
  2. #endinput
  3. #endif
  4. #define _INC_y_distribute
  5. /*+
  6. * <library name="y_distribute">
  7. * <section>
  8. * Description
  9. * </section>
  10. * This library simplifies the task of sending data to the new master script
  11. * when one takes over from another.
  12. * <section>
  13. * Version
  14. * </section>
  15. * 0.1
  16. * </library>
  17. *//** *//*
  18. Legal:
  19. Version: MPL 1.1
  20. The contents of this file are subject to the Mozilla Public License Version
  21. 1.1 the "License"; you may not use this file except in compliance with
  22. the License. You may obtain a copy of the License at
  23. http://www.mozilla.org/MPL/
  24. Software distributed under the License is distributed on an "AS IS" basis,
  25. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  26. for the specific language governing rights and limitations under the
  27. License.
  28. The Original Code is the YSI framework.
  29. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  30. Portions created by the Initial Developer are Copyright C 2011
  31. the Initial Developer. All Rights Reserved.
  32. Contributors:
  33. Y_Less
  34. koolk
  35. JoeBullet/Google63
  36. g_aSlice/Slice
  37. Misiur
  38. samphunter
  39. tianmeta
  40. maddinat0r
  41. spacemud
  42. Crayder
  43. Dayvison
  44. Ahmad45123
  45. Zeex
  46. irinel1996
  47. Yiin-
  48. Chaprnks
  49. Konstantinos
  50. Masterchen09
  51. Southclaws
  52. PatchwerkQWER
  53. m0k1
  54. paulommu
  55. udan111
  56. Thanks:
  57. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  58. ZeeX - Very productive conversations.
  59. koolk - IsPlayerinAreaEx code.
  60. TheAlpha - Danish translation.
  61. breadfish - German translation.
  62. Fireburn - Dutch translation.
  63. yom - French translation.
  64. 50p - Polish translation.
  65. Zamaroht - Spanish translation.
  66. Los - Portuguese translation.
  67. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes for
  68. me to strive to better.
  69. Pixels^ - Running XScripters where the idea was born.
  70. Matite - Pestering me to release it and using it.
  71. Very special thanks to:
  72. Thiadmer - PAWN, whose limits continue to amaze me!
  73. Kye/Kalcor - SA:MP.
  74. SA:MP Team past, present and future - SA:MP.
  75. Optional plugins:
  76. Gamer_Z - GPS.
  77. Incognito - Streamer.
  78. Me - sscanf2, fixes2, Whirlpool.
  79. */
  80. #include "y_globaltags"
  81. /*
  82. THIS:
  83. static DISTRIBUTED_SIMPLE YSI_g_sSomeThing;
  84. BECOMES:
  85. static YSI_g_sSomeThing;
  86. static stock YSI_g_sSomeThing_Dist() Distribute_Do("YSI_g_sSomeThing@Dist",_:DIST_SIZE_1:YSI_g_sSomeThing);
  87. forward YSI_g_sSomeThing@Dist(a[], s)
  88. public YSI_g_sSomeThing@Dist(a[], s)<>{}
  89. public YSI_g_sSomeThing@Dist(a[], s)<_YCM:y> Distribute_To(a, s, DIST_SIZE1:YSI_g_sSomeThing);
  90. */
  91. #define __declspec(%0) __declspec_%0
  92. forward _@_y_distribute_@_();
  93. public _@_y_distribute_@_()
  94. {
  95. new
  96. a[1 char];
  97. CallRemoteFunction("", "");
  98. memcpy(a, "", 0, 0);
  99. }
  100. #define DISTRIBUTE(%0) %0_Dist()
  101. #define __declspec_distributed%0; %0;static stock DIST_STRIP:DIST_DO:<%0>;
  102. #define __declspec_dist_tagged%3:%0; %3:%0;static stock DIST_STRIP:DIST_DO:< %0>;
  103. #define __declspec_dist_master%0[%1]%2; %0[%1]%2;static stock DIST_STRIP:DIST_MA:<%0%2>%1|;
  104. #define __declspec_dist_mtagged%3:%0[%1]%2; %3:%0[%1]%2;static stock DIST_STRIP:DIST_MA:< %0%2>%1|;
  105. #define __declspec_dist_special%3:%0; %3:%0;static stock DIST_ST2:DIST_SPEC:< %0>|||;
  106. #define __declspec_dist_mspecial%3:%0; %3:%0;static stock DIST_ST2:DIST_MSPEC:< %0>|||;
  107. #define DIST_DO:<%0>%1; %0_Dist()Distribute_Do(#%0"@Dist",_:%0%1);master_func%0@Dist(a[],s)<y,_YCM:u>Distribute_To(a,s,_:%0%1);
  108. //#define DIST_DO:<%0>%1; %0_Dist()Distribute_Do(#%0"@Dist",true,%0%1);forward%0@Dist(a[],s);public%0@Dist(a[],s)Distribute_To(a,s,%0%1);
  109. // #define Distribute_Do(%0|||%1) Distribute_Do(%0,%1)
  110. // #define Distribute_To(%0|||%1) Distribute_To(%0,%1)
  111. #define DIST_STRIP:%7<%0[%1]%3>%4; DIST_STRIP:%7<%0%3>%4,_:%1;
  112. #define DIST_SPEC:%7<%0<%1>%3>%4|||%9; DIST_DO:%7<%0%3>%4,_:sizeof(%0%9);
  113. #define DIST_MSPEC:%7<%0<%1>%3>%4|||%9; DIST_MA:%7<%0%3>%4,_:sizeof(%0%9);
  114. #define DIST_ST2:%7<%0[%1]%3>%4|||%9; DIST_ST2:%7<%0%3>%4,_:%1|||%9[];
  115. #define DIST_MA:<%0>%8|%1; %0_Dist()for(new i=0;i!=_:%8;++i)Distribute_So(#%0"@Dist",i,YSI_g_sMasterData,_:%0[i]%1);master_func%0@Dist(i,m,a[],s)<y,_YCM:u>YSI_g_sMasterData[i]=Bit:m,Distribute_To(a,s,_:%0[i]%1);
  116. stock Distribute_Do(func[], GLOBAL_TAG_TYPES:...)
  117. {
  118. // Get the data and the sizes.
  119. new
  120. size = 0,
  121. args = numargs(),
  122. curs = 2;
  123. //printf("%d %d", args, curs);
  124. while (curs < args) size = (size + 1) * getarg(--args);
  125. if (size == 0) size = 1;
  126. // Call CallRemoteFunction
  127. //printf("HELLO: %s %d %d", func, size, _MAX_GROUPS_G);
  128. static const
  129. scArgs[] = "ai";
  130. #emit PUSH.ADR size
  131. // Get the actual data pointer.
  132. #emit PUSH.S 16
  133. #emit PUSH.C scArgs
  134. #emit PUSH.S func
  135. #emit PUSH.C 16
  136. #emit SYSREQ.C CallRemoteFunction
  137. #emit STACK 20
  138. }
  139. /*-------------------------------------------------------------------------*//*+
  140. * <param name="func">The name of the receiving function.</param>
  141. * <param name="idx">The index of the data being sent in its array.</param>
  142. * <param name="masters">This data's masters.</param>
  143. * <param name="">The data and array sizes.</param>
  144. * <remarks>
  145. * This function takes the data from a given slot in an array, along with the
  146. * master IDs for that data. If the data is defined in more than the current
  147. * script, then this script is removed and the remainder of the data is sent to
  148. * the new master system.
  149. * </remarks>
  150. *//*------------------------------------------------------------------------**/
  151. stock Distribute_So(func[], idx, Bit:masters[], GLOBAL_TAG_TYPES:...)
  152. {
  153. new
  154. m = _:masters[idx] & ~(1 << Master_ID());
  155. // Only owned by the current script - skip it.
  156. if (m)
  157. {
  158. // Get the data and the sizes.
  159. new
  160. size = 0,
  161. args = numargs(),
  162. curs = 4;
  163. while (curs < args) size = (size + 1) * getarg(--args);
  164. if (size == 0) size = 1;
  165. // Call CallRemoteFunction
  166. static const
  167. scArgs[] = "iiai";
  168. #emit PUSH.ADR size
  169. // Get the actual data pointer.
  170. #emit PUSH.S 24
  171. #emit PUSH.ADR m
  172. #emit PUSH.ADR idx
  173. #emit PUSH.C scArgs
  174. #emit PUSH.S func
  175. #emit PUSH.C 24
  176. #emit SYSREQ.C CallRemoteFunction
  177. #emit STACK 28
  178. }
  179. }
  180. /*-------------------------------------------------------------------------*//*+
  181. * <param name="str">String to get the size of.</param>
  182. * <returns>
  183. * The number of BYTES this string takes up including the NULL.
  184. * </returns>
  185. * <remarks>
  186. * Caters for both packed and unpacked strings.
  187. * </remarks>
  188. *//*------------------------------------------------------------------------**/
  189. stock Distribute_To(from[], ss, GLOBAL_TAG_TYPES:...)
  190. {
  191. // Get the data and the sizes.
  192. new
  193. size = 0,
  194. args = numargs(),
  195. curs = 3;
  196. while (curs < args) size = (size + 1) * getarg(--args);
  197. if (size == 0) size = 1;
  198. // Push the parameters for "memcpy".
  199. ss = min(ss, size);
  200. #emit PUSH.S size
  201. #emit LOAD.S.pri ss
  202. #emit SHL.C.pri 2
  203. #emit PUSH.pri
  204. #emit PUSH.C 0
  205. #emit PUSH.S from
  206. #emit PUSH.S 20
  207. #emit PUSH.C 20
  208. #emit SYSREQ.C memcpy
  209. #emit STACK 24
  210. }