y_distribute.inc 7.0 KB

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