patterns.inc 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. /*
  2. Legal:
  3. Version: MPL 1.1
  4. The contents of this file are subject to the Mozilla Public License Version
  5. 1.1 the "License"; you may not use this file except in compliance with
  6. the License. You may obtain a copy of the License at
  7. http://www.mozilla.org/MPL/
  8. Software distributed under the License is distributed on an "AS IS" basis,
  9. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  10. for the specific language governing rights and limitations under the
  11. License.
  12. The Original Code is the YSI framework.
  13. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  14. Portions created by the Initial Developer are Copyright C 2011
  15. the Initial Developer. All Rights Reserved.
  16. Contributors:
  17. Y_Less
  18. koolk
  19. JoeBullet/Google63
  20. g_aSlice/Slice
  21. Misiur
  22. samphunter
  23. tianmeta
  24. maddinat0r
  25. spacemud
  26. Crayder
  27. Dayvison
  28. Ahmad45123
  29. Zeex
  30. irinel1996
  31. Yiin-
  32. Chaprnks
  33. Konstantinos
  34. Masterchen09
  35. Southclaws
  36. PatchwerkQWER
  37. m0k1
  38. paulommu
  39. udan111
  40. Thanks:
  41. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  42. ZeeX - Very productive conversations.
  43. koolk - IsPlayerinAreaEx code.
  44. TheAlpha - Danish translation.
  45. breadfish - German translation.
  46. Fireburn - Dutch translation.
  47. yom - French translation.
  48. 50p - Polish translation.
  49. Zamaroht - Spanish translation.
  50. Los - Portuguese translation.
  51. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes for
  52. me to strive to better.
  53. Pixels^ - Running XScripters where the idea was born.
  54. Matite - Pestering me to release it and using it.
  55. Very special thanks to:
  56. Thiadmer - PAWN, whose limits continue to amaze me!
  57. Kye/Kalcor - SA:MP.
  58. SA:MP Team past, present and future - SA:MP.
  59. Optional plugins:
  60. Gamer_Z - GPS.
  61. Incognito - Streamer.
  62. Me - sscanf2, fixes2, Whirlpool.
  63. */
  64. /*#define _PATTERN_FLAGS (0x01010000)
  65. #define _PATTERN_FADE_EDGE (0x01000000)
  66. #define _PATTERN_WIDTH (0xFE000000)
  67. #define _PATTERN_PADDING (0x00FE0000)
  68. #define _PATTERN_MASK (0x0000FFFF)
  69. // Pre-defined patterns.
  70. // ---------
  71. #define PATTERN_SOLID (0b1)
  72. // - - - - -
  73. #define PATTERN_DOTTED (0b10)
  74. // -- -- --
  75. #define PATTERN_DASHED (0b110)
  76. // - -- - --
  77. #define PATTERN_DOT_DASH (0b10110)
  78. // -- -- --
  79. #define PATTERN_WIDE_DASH (0b1100)
  80. // - - -- - - --
  81. #define PATTERN_DOT_DOT_DASH (0b1010110)
  82. // - -- --- --
  83. #define PATTERN_O_A_O_O_A_O_O_O_A_O_O_A (0b101101110110)*/
  84. /*stock const
  85. PATTERN_SOLID = "PATTERN_SOLID",
  86. PATTERN_DOTTED = "PATTERN_DOTTED",
  87. PATTERN_SOLID = "PATTERN_SOLID";*/
  88. /*#define PATTERN(%0) (_:_MK_PAT(0,%0@)&0xFFFF)
  89. #define _MK_PAT(%1,%0) _yPd:_yPD:_yPS:(%1,%0)
  90. // Dot.
  91. #define _yPd:%9(%1,.%0) _MK_PAT((%1)*2|1,%0)
  92. // Space.
  93. #define _yPD:%9(%1,-%0) _MK_PAT((%1)*2,%0)
  94. #define _yPS:%9(%1,) (%1)
  95. //#define _yPN:%9(%1,_%0) _MK_PAT((%1)*2%0)*/
  96. #define PATTERN_MASK_X (256)
  97. #define PATTERN_MASK_Y (256)
  98. stock
  99. // 8Kb
  100. YSI_gBitmapAlpha[PATTERN_MASK_Y][PATTERN_MASK_X char],
  101. YSI_gBitmapAlphaX = 1,
  102. YSI_gBitmapAlphaY = 1;
  103. //BitArray:YSI_gBitmapAlpha[PATTERN_MASK_Y]<PATTERN_MASK_X>;
  104. stock const
  105. YSI_gBitmapBlank[PATTERN_MASK_Y][PATTERN_MASK_X char];// = {Bit:0, ...};
  106. //BitArray:YSI_gBitmapBlank[PATTERN_MASK_Y]<PATTERN_MASK_X>;// = {Bit:0, ...};
  107. //stock Bitmap_ResetPattern()
  108. //{
  109. // YSI_gBitmapAlpha = YSI_gBitmapBlank;
  110. //}
  111. #define _Bitmap_ResetPattern() (YSI_gBitmapAlpha=YSI_gBitmapBlank)
  112. #define PATTERN(%0) (_:_PATTERN:(#%0))
  113. #define _PATTERN:(%0,%1) _PATTERN:(%0"\x2c;"#%1)
  114. stock _Bitmap_MakePattern(const pattern[], const posX, const posY, const offsetX, const offsetY)
  115. {
  116. static
  117. func[32] = "_BMP_PAT@";
  118. new
  119. pos = strfind(pattern, ",");
  120. func[9] = '\0',
  121. strcat(func, pattern);
  122. if (pos == -1)
  123. {
  124. if (funcidx(func) == -1) func = "_BMP_PAT@SOLID";
  125. CallLocalFunction(func, "iiiis", posX, posY, offsetX, offsetY, NULL);
  126. }
  127. else
  128. {
  129. func[pos + 9] = '\0';
  130. if (funcidx(func) == -1) func = "_BMP_PAT@SOLID";
  131. CallLocalFunction(func, "iiiis", posX, posY, offsetX, offsetY, pattern[pos]);
  132. }
  133. }
  134. stock _Bitmap_Param(const str[], const find[])
  135. {
  136. new
  137. pos = strfind(str, find, true),
  138. len = strlen(str),
  139. ch;
  140. if (0 < pos)
  141. {
  142. ch = str[pos - 1];
  143. if (ch == ' ' || ch == ',')
  144. {
  145. new
  146. p = pos;
  147. while (p != len)
  148. {
  149. ch = str[p];
  150. if (ch == '=')
  151. {
  152. return strval(str[++p]);
  153. }
  154. else if (ch == ',')
  155. {
  156. // There, but no value.
  157. return 0;
  158. }
  159. ++p;
  160. }
  161. return 0;
  162. }
  163. }
  164. return cellmin;
  165. }
  166. forward _BMP_PAT@SOLID(const posX, const posY, const offsetX, const offsetY, const flags[]);
  167. public _BMP_PAT@SOLID(const posX, const posY, const offsetX, const offsetY, const flags[])
  168. {
  169. #pragma unused posX, posY, offsetX, offsetY, flags
  170. YSI_gBitmapAlpha[0]{0} = 255,
  171. YSI_gBitmapAlphaX = 1,
  172. YSI_gBitmapAlphaY = 1;
  173. }
  174. forward _BMP_PAT@DIAGONAL(const posX, const posY, const offsetX, const offsetY, const flags[]);
  175. public _BMP_PAT@DIAGONAL(const posX, const posY, const offsetX, const offsetY, const flags[])
  176. {
  177. #pragma unused posX, posY, offsetX, offsetY, flags
  178. new
  179. // Alpha.
  180. stripe1 = _Bitmap_Param(flags, "stripe1"),
  181. stripe2 = _Bitmap_Param(flags, "stripe2"),
  182. left = _Bitmap_Param(flags, "right");
  183. if (stripe1 == cellmin) stripe1 = 8;
  184. if (stripe2 == cellmin) stripe2 = stripe1;
  185. // The stripes are the widths of the lines. Calculate the width of the
  186. // diagonal line horizontally.
  187. new
  188. Float:l1x = stripe1;
  189. l1x = floatsqroot(l1x * l1x / 2.0);
  190. new
  191. // The number of actual pixels across the first line.
  192. Float:l2w = stripe2,
  193. stripes = floatround((l1x + floatsqroot(l2w * l2w / 2.0)) * 2.0);
  194. // For 45 degrees there are only two types of partial pixels.
  195. stripe2 = floatround(l1x, floatround_floor);
  196. // Start pos.
  197. new
  198. pw = stripe2 / 2, // INTEGER division.
  199. mw = floatround(-l1x, floatround_floor),
  200. mp = mw - 1,
  201. pp = pw + 1;
  202. // Get the alpha parts.
  203. l2w = (l1x - stripe2),
  204. stripe2 = floatround(l2w * l2w / 2.0 * 255.0),
  205. l2w = 1.0 - l2w,
  206. stripe1 = floatround((1.0 - l2w * l2w / 2.0) * 255.0);
  207. // stripe2 is now the minor alpha, stripe1 is the major alpha.
  208. for (new y = 0; y != stripes; ++y)
  209. {
  210. for (new x = 0; x != stripes; ++x)
  211. {
  212. new
  213. xp = (x - mp) % stripes + mp;
  214. if (mw < xp < pw)
  215. YSI_gBitmapAlpha[y]{x} = 0xFF;
  216. else if (xp == mw || xp == pw)
  217. YSI_gBitmapAlpha[y]{x} = stripe1;
  218. else if (xp == mp || xp == pp)
  219. YSI_gBitmapAlpha[y]{x} = stripe2;
  220. else
  221. YSI_gBitmapAlpha[y]{x} = 0;
  222. }
  223. if (left)
  224. {
  225. ++pw,
  226. ++mw,
  227. ++mp,
  228. ++pp;
  229. }
  230. else
  231. {
  232. --pw,
  233. --mw,
  234. --mp,
  235. --pp;
  236. }
  237. }
  238. YSI_gBitmapAlphaX = stripes,
  239. YSI_gBitmapAlphaY = stripes;
  240. }
  241. forward _BMP_PAT@STRIPED(const posX, const posY, const offsetX, const offsetY, const flags[]);
  242. public _BMP_PAT@STRIPED(const posX, const posY, const offsetX, const offsetY, const flags[])
  243. {
  244. #pragma unused posX, posY, offsetX, offsetY, flags
  245. // Calculate the colour information.
  246. new
  247. // Alpha.
  248. stripe1 = _Bitmap_Param(flags, "stripe1"),
  249. stripe2 = _Bitmap_Param(flags, "stripe2"),
  250. stripes = _Bitmap_Param(flags, "horizontal");
  251. if (stripe1 == cellmin) stripe1 = 8;
  252. if (stripe2 == cellmin) stripe2 = stripe1;
  253. if (stripes)
  254. {
  255. stripes = stripe1 + stripe2,
  256. stripe2 = 0;
  257. while (stripe2 != stripe1)
  258. {
  259. YSI_gBitmapAlpha[0]{stripe2++} = 255;
  260. }
  261. while (stripe2 != stripes)
  262. {
  263. YSI_gBitmapAlpha[0]{stripe2++} = 0;
  264. }
  265. YSI_gBitmapAlphaX = stripes,
  266. YSI_gBitmapAlphaY = 1;
  267. }
  268. else
  269. {
  270. stripes = stripe1 + stripe2,
  271. stripe2 = 0;
  272. while (stripe2 != stripe1)
  273. {
  274. YSI_gBitmapAlpha[stripe2++]{0} = 255;
  275. }
  276. while (stripe2 != stripes)
  277. {
  278. YSI_gBitmapAlpha[stripe2++]{0} = 0;
  279. }
  280. YSI_gBitmapAlphaX = 1,
  281. YSI_gBitmapAlphaY = stripes;
  282. }
  283. }