render.inc 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647
  1. /**--------------------------------------------------------------------------**\
  2. =================================
  3. y_textrender - Show text.
  4. =================================
  5. Description:
  6. Part of the y_text system. Handles formatting loaded text in the correct
  7. manner for display in the currently selected style.
  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 utils 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. 25/02/12:
  46. First version.
  47. Functions:
  48. Stock:
  49. -
  50. Inline:
  51. -
  52. Variables:
  53. Global:
  54. -
  55. </remarks>
  56. \**--------------------------------------------------------------------------**/
  57. #if !defined FORMAT_FADE_STEP
  58. #define FORMAT_FADE_STEP 2
  59. #endif
  60. #define Y_RENDER_SCM_COLOUR_LEN (8)
  61. //#define Y_RENDER_ONE_ARG
  62. // if ((arg = getarg(curArg++) || TRUE))
  63. // Loops through all possible arguments in lists, functions and singles. See
  64. // "case e_COMPRESS_FORMAT_DATA_CUSTOM:" for more details (an expanded macro
  65. // version can be found there).
  66. #define Y_RENDER_ARG for(new i,j,b=4;i!=2;++i)if(!i){if(ch&_:e_COMPRESS_FORMAT_DATA_FUNC){b=1,func="@yR_",va_getstring(func[4],curArg);if(funcidx(func)<0)func[b=2]='r';}else if(ch&_:e_COMPRESS_FORMAT_DATA_LIST)b=3;}else for(;(arg=b==1?W@(func,"iii",pid,(_:l),j):b==2?W@(func,"ii",(_:l),j):b==3?getarg(curArg,j++):getarg(curArg)),arg!=cellmin&&b||++curArg&0;b&=~4,++j)
  67. // Make the correct specifier string for the data stored in the compressed
  68. // specifier data.
  69. #define Y_RENDER_SPECIFIER(%0) ((ch&_:e_COMPRESS_FORMAT_DATA_ZERO)?((ch&_:e_COMPRESS_FORMAT_DATA_LEFT)?(scFormats[3][6]='%0',scFormats[3]):(scFormats[2][5]='%0',scFormats[2])):((ch&_:e_COMPRESS_FORMAT_DATA_LEFT)?(scFormats[1][5]='%0',scFormats[1]):(scFormats[0][4]='%0',scFormats[0])))
  70. // This makes hex and binary format specifiers display correctly with negative
  71. // numbers in all cases (e.g. %5x etc).
  72. #define Y_RENDER_FIX_NEGATIVE(%0:%1) if(width>%1)arg=(ch&_:e_COMPRESS_FORMAT_DATA_LEFT)?((ch&_:e_COMPRESS_FORMAT_DATA_ZERO)?format(ts,130,"%"#%0"%0-*"#%0,arg>>>32/%1,width-(%1-1),arg&(1<<32/%1)-1):format(ts,130,"%"#%0"%-*"#%0,arg>>>32/%1,width-(%1-1),arg&(1<<32/%1)-1)):(ch&_:e_COMPRESS_FORMAT_DATA_ZERO)?format(ts,130,"%0*"#%0"%"#%0,width-1,arg>>>32/%1,arg&(1<<32/%1)-1):format(ts,130,"%*"#%0"%"#%0,width-1,arg>>>32/%1,arg&(1<<32/%1)-1);else format(ts,130,"%"#%0"%"#%0,arg>>>32/%1,arg&(1<<32/%1)-1)
  73. // Try add a string to the current output. This needs modifying to reset the
  74. // whole function after a string is displayed. "onlyOne" is set in the case
  75. // where any line excess is cut off (e.g. in marquees).
  76. //#define Y_RENDER_ADD(%1) switch(Format_DoAddString(pid,output,%1,p,maxlen,llen,strlen(%1),fakepos,fade)){case 1:++one;case 2:Format_DoTryShow(output,fade);}
  77. #define Y_RENDER_DO_DISPLAY() {output[p]='\0';if(!none)Format_DoDisplay(pid,gInitialColour,output);if(onlyOne)return one;output[0]=p=0;llen=maxlen;++one;}
  78. #define Y_RENDER_ADD(%1) for(new __added,__len=strlen((%1)),__done;(__added=Format_DoAddString(output,%1[__done],p,__len,llen,fakePos));__done+=__added,__len-=__added){if(fade)state y_render_fade:y_render_fade_fake;else Y_RENDER_DO_DISPLAY()}
  79. //#define Y_RENDER_ADD_EX(%1,%2,%3) for(new __added,__len=(%3),__done=%2;(__added=Format_DoAddString(output,%1[__done],p,__len,llen,fakePos));__done+=__added,__len-=__added){if(fade)state y_render_fade:y_render_fade_fake;else Y_RENDER_DO_DISPLAY()}
  80. #define Y_RENDER_CHAR(%1) while(!Format_DoAddChar(output,(%1),p,llen,fakePos)){if(fade)state y_render_fade:y_render_fade_fake;else Y_RENDER_DO_DISPLAY()}
  81. // Helper macros to determine what a character is. This could be modified to
  82. // take in to account unicode letters, but that's hard. I don't know enough
  83. // about unicode, and frankly there are WAY too many characters to be listed
  84. // here. If other people want to modify this to support their language then
  85. // good on them.
  86. #define Y_TEXT_LETTER(%0) ('a'<=(%0)<='z'||'A'<=(%0)<='Z')
  87. #define Y_TEXT_NUMBER(%0) ('0'<=(%0)<='9')
  88. #define Y_RENDER_SCM_COLOUR_LEN (8)
  89. #define e_FORMAT_FLAGS_INDEX (0x00FFFFFF)
  90. #define e_FORMAT_FLAGS_REDO (0x01000000)
  91. #define e_FORMAT_FLAGS_ONE (0x02000000)
  92. #define e_FORMAT_FLAGS_NONE (0x04000000)
  93. static stock
  94. YSI_g_sListSep[4] = ", ",
  95. YSI_g_sFadeRedoTarget,
  96. YSI_g_sFadeLength,
  97. YSI_g_sFadeColour,
  98. bool:YSI_g_sJustOne,
  99. YSI_g_sTempStyle[E_STYLE_DATA],
  100. YSI_g_sTemp3D[E_3D_DATA],
  101. YSI_g_sTempMaster,
  102. Text:YSI_g_sBaseTD = TEXT_DRAW_NO_NEXT,
  103. //YSI_g_sExtraText[MAX_INI_ENTRY_TEXT],
  104. gInitialColour;
  105. stock _Text_SetDialogMode()
  106. {
  107. YSI_g_sTempStyle[E_STYLE_DATA_TYPE] = e_STYLE_TYPE_DIALOG;
  108. state y_render_show : y_render_show_scm;
  109. YSI_g_sJustOne = true;
  110. }
  111. stock Format_SetListSeparator(string:lst[])
  112. {
  113. strcpy(YSI_g_sListSep, lst);
  114. }
  115. stock _Format_SetStyleData(master, index, style[E_STYLE_DATA], label[E_3D_DATA])
  116. {
  117. // =========================================================================
  118. //
  119. #pragma unused index
  120. //
  121. // MAJOR WARNING:
  122. //
  123. // "Text_IsLocalOwner" DOES NOT PASS "INDEX" CORRECTLY AS IT DOESN'T KNOW
  124. // WHAT IT SHOULD BE, DON'T FORGET THIS IF YOU EVER USE "index"...
  125. //
  126. // =========================================================================
  127. YSI_g_sTempMaster = master;
  128. YSI_g_sTempStyle = style;
  129. YSI_g_sTemp3D = label;
  130. switch (style[E_STYLE_DATA_TYPE] & e_STYLE_TYPE_MASK)
  131. {
  132. case e_STYLE_TYPE_GT_0, e_STYLE_TYPE_GT_1, e_STYLE_TYPE_GT_2, e_STYLE_TYPE_GT_3, e_STYLE_TYPE_GT_4, e_STYLE_TYPE_GT_5, e_STYLE_TYPE_GT_6:
  133. {
  134. state y_render_show : y_render_show_gt;
  135. // Now that we know the style, we can store only the exact style.
  136. YSI_g_sTempStyle[E_STYLE_DATA_TYPE] = ((style[E_STYLE_DATA_TYPE] & e_STYLE_TYPE_MASK) >>> e_STYLE_TYPE_SHIFT) - e_STYLE_TYPE:1;
  137. YSI_g_sJustOne = true;
  138. return 144;
  139. }
  140. case e_STYLE_TYPE_CLIENT:
  141. {
  142. state y_render_show : y_render_show_scm;
  143. YSI_g_sJustOne = false;
  144. return 256;
  145. }
  146. case e_STYLE_TYPE_TD:
  147. {
  148. state y_render_show : y_render_show_td;
  149. YSI_g_sJustOne = true;
  150. // Anything with the ability to be longer than 1024 will require a
  151. // modification to the declaration of variables.
  152. return 1024;
  153. }
  154. }
  155. state y_render_show : y_render_show_print;
  156. return 1023;
  157. }
  158. static stock Format_InsertColour(str[], pos, &rem, &curCol, newCol, step) <y_render_show : y_render_show_scm>
  159. {
  160. // This code doesn't yet deal with colours which are too close to have their
  161. // differences detected by the human eye (especially when there are spaces).
  162. curCol = newCol & 0x00FFFFFF;
  163. if (pos == 0)
  164. {
  165. gInitialColour = curCol;
  166. // Don't add the colour - this is handled in the text display function.
  167. return 0;
  168. }
  169. // Now try add the string version of the colour.
  170. //printf("rem: %d, required: %d", rem, Y_RENDER_SCM_COLOUR_LEN);
  171. if (rem < Y_RENDER_SCM_COLOUR_LEN + step)
  172. {
  173. // Not enough space to add a new colour.
  174. str[pos] = '\0';
  175. return -1;
  176. }
  177. // This may well cut characters off the end of the string, but don't worry,
  178. // well, you can worry because it may mean that some characters are parsed
  179. // multiple times, but there's not a lot you can do about it... This is one
  180. // of the few places where the extra "+ 1" is taken in to account as format
  181. // uses it internally.
  182. format(str[pos], rem + 1, "{%06x}%s", curCol, str[pos]);
  183. rem -= Y_RENDER_SCM_COLOUR_LEN;
  184. return Y_RENDER_SCM_COLOUR_LEN;
  185. }
  186. static stock Format_InsertColour(str[], pos, &rem, &curCol, newCol, step) <>
  187. {
  188. #pragma unused str, pos, rem, step
  189. curCol = newCol;
  190. return 0;
  191. }
  192. static stock Format_InsertColour(str[], pos, &rem, &curCol, newCol, step) <y_render_show : y_render_show_gt, y_render_show : y_render_show_td>
  193. {
  194. // First get the closest GameText colour for the true colour. I wrote a
  195. // function for this a LONG time ago, finally got around to using it!
  196. new
  197. ot = curCol & 0xFF,
  198. oc = curCol >>> 8;
  199. if (ot == 0 || ot == 'x')
  200. {
  201. // Still near the start, allow some of the special start colours.
  202. newCol = Colours_SAMPToGT(newCol & 0x00FFFFFF, oc);
  203. }
  204. else
  205. {
  206. // Can't use the oragey colour used at the start.
  207. newCol = Colours_SAMPToGT(newCol & 0x00FFFFFF, 3);
  208. }
  209. new
  210. nt = newCol & 0xFF,
  211. nc = (newCol >>> 8) * 3;
  212. curCol = newCol;
  213. // Compare them.
  214. static
  215. cs_hTags[] = "~x~~h~~h~~h~~h~~h~%s";
  216. if (nt == ot)
  217. {
  218. ot = nc - (oc * 3);
  219. if (ot == 0)
  220. {
  221. // No change, return 0 if there are enough charaters to show the
  222. // text that should come after this new colour.
  223. return rem >= step ? 0 : -1;
  224. }
  225. else if (ot > 0)
  226. {
  227. if (rem >= ot + step)
  228. {
  229. // Add enough "lighter" tags to change the old colour in to the
  230. // new colour.
  231. format(str[pos], rem + 1, cs_hTags[sizeof (cs_hTags) - 3 - ot], str[pos]);
  232. rem -= ot;
  233. return ot;
  234. }
  235. else
  236. {
  237. return -1;
  238. }
  239. }
  240. }
  241. if (rem < nc + step)
  242. {
  243. return -1;
  244. }
  245. // Subtract six from the size : 3 for "%s\0" and 3 for the extra "~x~"
  246. // needed as placeholder for the colour tag (added on the next line).
  247. format(str[pos], rem + 1, cs_hTags[sizeof (cs_hTags) - 6 - nc], str[pos]);
  248. str[pos + 1] = nt;
  249. rem -= nc + 3;
  250. return nc + 3;
  251. }
  252. static stock Format_AddColour(str[], pos, &rem, &curCol, newCol) <y_render_show : y_render_show_scm>
  253. {
  254. // This code doesn't yet deal with colours which are too close to have their
  255. // differences detected by the human eye (especially when there are spaces).
  256. new
  257. rgb = newCol & 0x00FFFFFF;
  258. // Don't add the colour if there's no change from the last one.
  259. if (rgb == curCol)
  260. {
  261. return 0;
  262. }
  263. if (-0x5 <= ((rgb & 0x0FF) - (curCol & 0xFF)) <= 0x5)
  264. {
  265. if (-0x500 <= ((rgb & 0xFF00) - (curCol & 0xFF00)) <= 0x500)
  266. {
  267. if (-0x50000 <= ((rgb & 0xFF0000) - (curCol & 0xFF0000)) <= 0x50000)
  268. {
  269. // Haven't changed the colour.
  270. return 0;
  271. }
  272. }
  273. }
  274. if (YSI_g_sTempStyle[E_STYLE_DATA_TYPE] != e_STYLE_TYPE_DIALOG && pos == 0)
  275. {
  276. gInitialColour = curCol;
  277. // Don't add the colour - this is handled in the text display function.
  278. curCol = rgb;
  279. return 0;
  280. }
  281. // Now try add the string version of the colour.
  282. if (rem < Y_RENDER_SCM_COLOUR_LEN)
  283. {
  284. // Not enough space to add a new colour.
  285. str[pos] = '\0';
  286. return -1;
  287. }
  288. format(str[pos], rem + 1, "{%06x}", rgb);
  289. rem -= Y_RENDER_SCM_COLOUR_LEN;
  290. curCol = newCol;
  291. return Y_RENDER_SCM_COLOUR_LEN;
  292. }
  293. static stock Format_AddColour(str[], pos, &rem, &curCol, newCol) <>
  294. {
  295. #pragma unused str, pos, rem
  296. curCol = newCol;
  297. return 0;
  298. }
  299. static stock Format_AddColour(str[], pos, &rem, &curCol, newCol) <y_render_show : y_render_show_gt, y_render_show : y_render_show_td>
  300. {
  301. // First get the closest GameText colour for the true colour. I wrote a
  302. // function for this a LONG time ago, finally got around to using it!
  303. new
  304. ot = curCol & 0xFF,
  305. oc = curCol >>> 8;
  306. if (ot == 0 || ot == 'x')
  307. {
  308. // Still near the start, allow some of the special start colours.
  309. newCol = Colours_SAMPToGT(newCol & 0x00FFFFFF, oc);
  310. }
  311. else
  312. {
  313. // Can't use the oragey colour used at the start.
  314. newCol = Colours_SAMPToGT(newCol & 0x00FFFFFF, 3);
  315. }
  316. new
  317. nt = newCol & 0xFF,
  318. nc = (newCol >>> 8) * 3;
  319. curCol = newCol;
  320. // Compare them.
  321. static
  322. cs_hTags[] = "~x~~h~~h~~h~~h~~h~";
  323. if (nt == ot)
  324. {
  325. ot = nc - (oc * 3);
  326. if (ot == 0)
  327. {
  328. return 0;
  329. }
  330. else if (ot > 0)
  331. {
  332. if (rem >= ot)
  333. {
  334. // Add enough "lighter" tags to change the old colour in to the
  335. // new colour.
  336. str[pos] = '\0';
  337. strcat(str[pos], cs_hTags[sizeof (cs_hTags) - 1 - ot], rem + 1);
  338. rem -= ot;
  339. return ot;
  340. }
  341. else
  342. {
  343. return -1;
  344. }
  345. }
  346. }
  347. if (rem < nc)
  348. {
  349. return -1;
  350. }
  351. // Subtract six from the size : 3 for "%s\0" and 3 for the extra "~x~"
  352. // needed as placeholder for the colour tag (added on the next line).
  353. //format(str[pos], rem + 1, cs_hTags[sizeof (cs_hTags) - 6 - nc], str[pos]);
  354. str[pos] = '\0';
  355. strcat(str[pos], cs_hTags[sizeof (cs_hTags) - 4 - nc], rem + 1);
  356. str[pos + 1] = nt;
  357. rem -= nc + 3;
  358. return nc + 3;
  359. }
  360. // str = input and output write array.
  361. // pos = start position of the string to be faded.
  362. // len = total remaining space in the string.
  363. // endColour = target colour.
  364. // gInitialColour = start and current colour.
  365. // step = number of characters for each colour.
  366. // offset = number of characters in the fade not being shown.
  367. static stock Format_AddFade(str[], &pos, &len, endColour, &initialColour, step, offset) //<y_render_display : send_client_message>
  368. {
  369. // Add a fade for a SendClientMessage. This is called if a string is filled
  370. // up during a fade or the end of a fade is reached correctly. In either
  371. // case the current fade will constiture the end of the known current string
  372. // so in actual fact no additionl text after the end of the fade will be
  373. // dropped. This is also where we can save the data to appear in the fade
  374. // on the next line and re-show it.
  375. // Work out how many colours can be inserted at the specified step value
  376. // (i.e. how often a new colour appears) within the length from "pos" to the
  377. // end of "str". This may be more than is required. "len" is from "pos" to
  378. // the end of the string, NOT to the end of the characters requiring the
  379. // fade. The length of the required fade is in "YSI_g_sFadeLength" so that the
  380. // value can be used in the future.
  381. new
  382. parts = (YSI_g_sFadeLength + step - 1) / step + offset,
  383. // We can insert all the colours and their texts in the given space.
  384. // Now we just need to figure out how...
  385. // First get the start and end colours.
  386. start = str[pos + 1] & 0x00FFFFFF; //~(Y_FORMAT_START_FADE | Y_FORMAT_ALWAYS_SET);
  387. // Remove the start and end colour markers.
  388. strdel(str, pos, pos + 2);
  389. // Find the colour components and component deltas.
  390. endColour &= 0x00FFFFFF; //~(Y_FORMAT_START_FADE | Y_FORMAT_ALWAYS_SET);
  391. new
  392. red = start >>> 16 & 0xFF,
  393. dred = ((endColour >>> 16 & 0xFF) - red) / parts,
  394. pred = initialColour >>> 16 & 0xFF,
  395. green = start >>> 8 & 0xFF,
  396. dgreen = ((endColour >>> 8 & 0xFF) - green) / parts,
  397. pgreen = initialColour >>> 8 & 0xFF,
  398. blue = start >>> 0 & 0xFF,
  399. dblue = ((endColour >>> 0 & 0xFF) - blue) / parts,
  400. pblue = initialColour >>> 0 & 0xFF;
  401. // Take old strings in to account.
  402. red += dred * offset;
  403. blue += dblue * offset;
  404. green += dgreen * offset;
  405. //strdel(str, pmax, pmax + 2);
  406. //startColour = gInitialColour;
  407. do
  408. {
  409. // Insert the new colour, if it is sufficiently different from the
  410. // existing colour to warrant being added new.
  411. if (-3 <= red - pred <= 3 && -3 <= blue - pblue <= 3 && -3 <= green - pgreen <= 3)
  412. {
  413. pos += step;
  414. }
  415. else
  416. {
  417. new
  418. upd = Format_InsertColour(str, pos, len, initialColour, red << 16 | green << 8 | blue, step);
  419. if (upd == -1)
  420. {
  421. // Didn't quite finish everything. This is the number of
  422. // characters left to process.
  423. return YSI_g_sFadeLength;
  424. }
  425. //initial += step;
  426. pos += step + upd;
  427. pred = red;
  428. pgreen = green;
  429. pblue = blue;
  430. }
  431. YSI_g_sFadeLength -= step;
  432. len -= step;
  433. red = red + dred & 0xFF;
  434. green = green + dgreen & 0xFF;
  435. blue = blue + dblue & 0xFF;
  436. // Could do something with "len" here if it runs out to signify that
  437. // more text needs to go on the next line of output.
  438. }
  439. while (YSI_g_sFadeLength > 0);
  440. // Correct for any excess characters.
  441. pos += YSI_g_sFadeLength;
  442. // This doesn't add the actual destination colour - that is added by virtue
  443. // of the fact that it is actually just a normal colour, so we can use the
  444. // standard colour code (whatever that may be) to add it in a more generic
  445. // way.
  446. return 0;
  447. }
  448. static stock Format_DoEndFade(output[], &start, end, &rem, colour, &initial) //<>
  449. {
  450. // If "colour" is 0 this is the end of a string before the close colour is
  451. // reached. This fact is enforced by "Y_FORMAT_ALWAYS_SET", which ensures
  452. // that all colours, including black, are not 0 in the string to avoid PAWN
  453. // treating the colour as a NULL terminator or, as here, a no-colour marker.
  454. if (colour)
  455. {
  456. new
  457. offset = 0;
  458. if (YSI_g_sFadeLength)
  459. {
  460. initial = YSI_g_sFadeColour;
  461. offset = end - start - YSI_g_sFadeLength;
  462. //printf("parts: %d, %d, %d", offset, YSI_g_sFadeLength, end - start);
  463. }
  464. else
  465. {
  466. YSI_g_sFadeLength = end - start;
  467. }
  468. // "rem" will hold the number of characters AFTER the fade string on
  469. // entry, this needs fixing here to exclude them as they're being messed
  470. // with.
  471. rem += YSI_g_sFadeLength;
  472. //printf("length: %d", YSI_g_sFadeLength);
  473. // I wrote this code for the case where too much data has been found and
  474. // we needed a fake render to get the full length, but then found that
  475. // exactly the same code was needed for the default case too...
  476. //printf("Format_DoEndFade: %d %d %x %x %d", YSI_g_sFadeLength, /*YSI_g_sFadeLength +*/ rem, colour, initial, start);
  477. // Default step value is 1 and there is currently no way to change it.
  478. new
  479. ret = Format_AddFade(output, start, /*YSI_g_sFadeLength +*/ rem, colour, initial, FORMAT_FADE_STEP, offset);
  480. //printf("Format_DoEndFade: %d %d %x %x %d", YSI_g_sFadeLength, /*YSI_g_sFadeLength +*/ rem, colour, initial, start);
  481. YSI_g_sFadeColour = initial;
  482. return ret;
  483. }
  484. else
  485. {
  486. //printf("colour: %d", YSI_g_sFadeColour);
  487. // Quite simply, we just change state and return to the calling
  488. // function. This allows this function to be called again when the true
  489. // fade end is reached and the length to be determined. After that some
  490. // re-parsing will need to be done I'm afraid, but that will be handled
  491. // by code dealing with fades which fall over the end of a string, be it
  492. // due to this or to a known length string being pushed over the end due
  493. // to the insertion of the colour codes. Note that this code is display
  494. // method independent - it works for SendClientMessage, GameText and
  495. // others.
  496. state y_render_fade : y_render_fade_fake;
  497. // The return here causes remaining code to continue as normal, but
  498. // makes certain functions just not run.
  499. }
  500. return 0;
  501. }
  502. /**--------------------------------------------------------------------------**\
  503. <summary>Format_DoAddString</summary>
  504. <param name="out[]">The destination string.</param>
  505. <param name="in[]">The data to add.</param>
  506. <param name="&oidx">The index in "out" at which to add data.</param>
  507. <param name="len">The length of "in".</param>
  508. <param name="&orem">Space remaining in "out".</param>
  509. <param name="&fakePos">Like "oidx", but cumulative over line breaks.</param>
  510. <returns>
  511. The amount of data from "in" not added to "out".
  512. </returns>
  513. <remarks>
  514. Takes an input string and adds it to an output string. If the input string
  515. is too long to fit in the remainder of the output string, what has been
  516. added already (including part of the input string) is displayed and a new
  517. string is added. Format_TryShow handles this, including adding formatting
  518. of colour fades, which may involve fake rendering of more of the string to
  519. determine how much of the remainder of the string needs processing to get
  520. the right colour. This will also require a method of winding back the state
  521. to the point just after the initial input string was added to continue on to
  522. show the next string including newly determined fade data.
  523. </remarks>
  524. \**--------------------------------------------------------------------------**/
  525. static stock Format_DoAddString(out[], const in[], &oidx, const len, &orem, &fakepos) <y_render_fade : y_render_fade_fake>
  526. {
  527. #pragma unused out, in, oidx, orem
  528. fakepos += len;
  529. return 0;
  530. }
  531. static stock Format_DoAddString(out[], const in[], &oidx, const len, &orem, &fakepos) <y_render_fade : y_render_fade_redo>
  532. {
  533. new
  534. temp = fakepos + len - YSI_g_sFadeRedoTarget;
  535. if (temp > 0)
  536. {
  537. state y_render_fade : y_render_fade_real;
  538. // This is where the string passes the target point of re-rendering.
  539. new
  540. other = YSI_g_sFadeRedoTarget - fakepos;
  541. fakepos += other;
  542. return Format_DoAddString(out, in[other], oidx, temp, orem, fakepos);
  543. }
  544. else
  545. {
  546. fakepos += len;
  547. return 0;
  548. }
  549. }
  550. static stock Format_DoAddString(out[], const in[], &oidx, const len, &orem, &fakepos) <y_render_fade : y_render_fade_real>
  551. {
  552. P:4("Format_DoAddString <y_render_fade : render_real> called: \"%s\", \"%s\", %i, %i, %i, %i", out, in, oidx, len, orem, fakepos);
  553. // For now don't worry about fades over boundaries - they're just too hard
  554. // to get the code working on to start with, maybe later once this is all
  555. // working they can be added in. It is a shame though as it will mean fades
  556. // don't always work. I can cheat slightly though and have the full fade on
  557. // both halves of the break. Or just warn people about fades like that.
  558. //
  559. // NOTE: This code assumes that orem (output remaining) is always 1 less
  560. // than the true value. This avoids awkward calculations when appending the
  561. // NULL terminator to strings. When we run out of space it simply appends
  562. // it regardless of wether it thinks there is space or not.
  563. //
  564. fakepos += len;
  565. if (len <= orem)
  566. {
  567. P:5("Format_DoStringSCM: p0.");
  568. memcpy(out[oidx], in, 0, len * 4, orem);
  569. orem -= len;
  570. oidx += len;
  571. // The whole string fit in - return true.
  572. return 0;
  573. }
  574. else
  575. {
  576. // Not the end of the string, but the end is required.
  577. // Change state to ignore future inputs.
  578. P:5("Format_DoStringSCM: p1.");
  579. // Copy as much data as possible.
  580. memcpy(out[oidx], in, 0, orem * 4, orem);
  581. //orem -= orem;
  582. //oidx += orem;
  583. // Don't need to adjust this further down as all the characters will be
  584. // added before the recursive call.
  585. oidx += orem;
  586. return len - orem;
  587. }
  588. }
  589. static stock bool:Format_DoAddChar(out[], const in, &oidx, &orem, &fakepos) <y_render_fade : y_render_fade_fake>
  590. {
  591. #pragma unused out, in, oidx, orem
  592. ++fakepos;
  593. return true;
  594. }
  595. static stock bool:Format_DoAddChar(out[], const in, &oidx, &orem, &fakepos) <y_render_fade : y_render_fade_redo>
  596. {
  597. if (fakepos == YSI_g_sFadeRedoTarget)
  598. {
  599. state y_render_fade : y_render_fade_real;
  600. // This should never actually fail...
  601. if (!orem) return false;
  602. --orem;
  603. out[oidx++] = in;
  604. }
  605. ++fakepos;
  606. return true;
  607. }
  608. static stock bool:Format_DoAddChar(out[], const in, &oidx, &orem, &fakepos) <y_render_fade : y_render_fade_real>
  609. {
  610. P:4("Format_DoAddChar: %c %d %d", in, oidx, orem);
  611. if (!orem) return false;
  612. --orem;
  613. out[oidx++] = in;
  614. ++fakepos;
  615. return true;
  616. }
  617. static stock Format_DoDisplay(playerid, colour, out[]) <y_render_show : y_render_show_scm>
  618. {
  619. P:2("Format_DoDisplay a: %d, %06x, \"%s\"", playerid, colour >>> 8, out);
  620. SendClientMessage(playerid, (colour << 8) | ((YSI_g_sTempStyle[E_STYLE_DATA_COLOUR] & 0x0F) * 0x11), out);
  621. //idx = 0;
  622. //out[0] = '\0';
  623. }
  624. static stock Format_DoDisplay(playerid, colour, out[]) <> //y_render_show : y_render_show_print>
  625. {
  626. P:0("Format_DoDisplay b: %d, %06x, \"%s\"", playerid, colour >>> 8, out);
  627. //idx = 0;
  628. //out[0] = '\0';
  629. }
  630. static stock Format_DoDisplay(playerid, colour, out[]) <y_render_show : y_render_show_gt>
  631. {
  632. #pragma unused colour
  633. P:2("Format_DoDisplay c: %d, %06x, \"%s\"", playerid, colour >>> 8, out);
  634. GameTextForPlayer(playerid, out, YSI_g_sTempStyle[E_STYLE_DATA_TIME], YSI_g_sTempStyle[E_STYLE_DATA_STYLE]);
  635. //SendClientMessage(playerid, (colour << 8) | ((YSI_g_sTempStyle[E_STYLE_DATA_COLOUR] & 0x0F) * 0x11), out);
  636. //GameTextForPlayer(playerid, out,
  637. //SendClientMessage(playerid, colour, out);
  638. //idx = 0;
  639. //out[0] = '\0';
  640. }
  641. static stock Format_DoDisplay(playerid, colour, out[]) <y_render_show : y_render_show_td>
  642. {
  643. #pragma unused colour
  644. P:2("Format_DoDisplay d: %d, %06x, \"%s\"", playerid, colour >>> 8, out);
  645. new
  646. Text:tmp = TD_Display(out, YSI_g_sTempStyle[E_STYLE_DATA_TD_ID]);
  647. out[0] = _:tmp;
  648. out[1] = '\0';
  649. TD_ShowForPlayer(playerid, tmp);
  650. TD_Garbage(tmp);
  651. // Link these TDs together for future manipulations.
  652. if (YSI_g_sBaseTD == TEXT_DRAW_NO_NEXT)
  653. {
  654. YSI_g_sBaseTD = tmp;
  655. }
  656. else
  657. {
  658. TD_Link(YSI_g_sBaseTD, tmp);
  659. }
  660. //SendClientMessage(playerid, (colour << 8) | ((YSI_g_sTempStyle[E_STYLE_DATA_COLOUR] & 0x0F) * 0x11), out);
  661. //GameTextForPlayer(playerid, out,
  662. //SendClientMessage(playerid, colour, out);
  663. //idx = 0;
  664. //out[0] = '\0';
  665. }
  666. /**--------------------------------------------------------------------------**\
  667. <summary>Format_JustShow</summary>
  668. <param name="playerid">Player to show the text to.</param>
  669. <param name="out[]">What the text to show is.</param>
  670. <returns>
  671. -
  672. </returns>
  673. <remarks>
  674. -
  675. </remarks>
  676. \**--------------------------------------------------------------------------**/
  677. stock Format_JustShow(playerid, out[]) <y_render_show : y_render_show_scm>
  678. {
  679. SendClientMessage(playerid, gInitialColour, out);
  680. }
  681. stock Format_JustShow(playerid, out[]) <y_render_show : y_render_show_print>
  682. {
  683. P:0("Format_DoDisplay: %d, \"%s\"", playerid, out);
  684. }
  685. stock Format_JustShow(playerid, out[]) <y_render_show : y_render_show_gt>
  686. {
  687. GameTextForPlayer(playerid, out, YSI_g_sTempStyle[E_STYLE_DATA_TIME], YSI_g_sTempStyle[E_STYLE_DATA_STYLE]);
  688. }
  689. stock Format_JustShow(playerid, out[]) <y_render_show : y_render_show_td>
  690. {
  691. TD_ShowForPlayer(playerid, Text:out[0]);
  692. }
  693. /**--------------------------------------------------------------------------**\
  694. <summary>Text_GetLastID</summary>
  695. <returns>
  696. The basic ID linking all displayed elements together where appropriate (for
  697. example SendClientMessage has no meaningful ID. 3D texts would, but that's
  698. not implemented. So do game texts, but that's not implemented either, so
  699. really it's just text draws.
  700. </returns>
  701. <remarks>
  702. -
  703. </remarks>
  704. \**--------------------------------------------------------------------------**/
  705. stock Text_GetLastID() <y_render_show : y_render_show_td>
  706. {
  707. return _:YSI_g_sBaseTD;
  708. }
  709. stock Text_GetLastID() <>
  710. {
  711. return -1;
  712. }
  713. /**--------------------------------------------------------------------------**\
  714. <summary>-</summary>
  715. <returns>
  716. -
  717. </returns>
  718. <remarks>
  719. -
  720. </remarks>
  721. \**--------------------------------------------------------------------------**/
  722. // Generic function to handle rendering for all types of outputs. Other
  723. // functions such as Format_AddColour are specialised for different text styles.
  724. // The faster way to do this would be to store the characters removed from a
  725. // string when adding in fade data, but this is hard to code. The simpler
  726. // method is to fake re-render the string, having previously determined the
  727. // length of the string which will be faded across. Note that this may mean
  728. // that some parts of the string can get rendered many times, but we can just
  729. // issue a performance warning when the player uses fades which go over a line
  730. // boundary. That is the only time in which it is a problem, more specifically
  731. // it is only a problem when text in a fade goes over a line boundardy before
  732. // the end fade marker has been reached.
  733. //stock Format_Render(pid, Language:l, output[], maxlen, idx, target, string[], {Float,_}:...)
  734. stock Format_Render(pid, Language:l, output[], maxlen, idx, target, string[], argCount, GLOBAL_TAG_TYPES:...)
  735. {
  736. P:3("Format_Render called: %i, %i, %s, %i, %i, %i, %s (+%i)", pid, _:l, output, maxlen, idx, target, argCount, numargs() - 8);
  737. //state y_text_colour_fade:full_render;
  738. gInitialColour = (YSI_g_sTempStyle[E_STYLE_DATA_COLOUR] >>> 4) & 0x00FFFFFF;
  739. new
  740. colour = gInitialColour;
  741. YSI_g_sFadeLength = 0;
  742. YSI_g_sBaseTD = TEXT_DRAW_NO_NEXT;
  743. // Now the (mostly) tail-recursive function call.
  744. Format_Render_start:
  745. static
  746. scFormats[][8] =
  747. {
  748. "%*.*d", // 6 (6)
  749. "%-*.*d", // 7 (13)
  750. "%0*.*d", // 7 (20)
  751. "%0-*.*d" // 8 (28)
  752. },
  753. scSpecifier[8],
  754. // =====================================================================
  755. // UPDATE Y_RENDER_FIX_NEGATIVE MACRO ON CHANGE!!!!!!!
  756. ts[130],
  757. // Max handleable input string length is 128 (hopefully sufficient).
  758. // =====================================================================
  759. func[32],
  760. scNewLineString[] = "~n~",
  761. scDialogLineString[] = "\r\n";
  762. new
  763. ch,
  764. llen = maxlen,
  765. //output[128], // Always 128.
  766. p = 0,
  767. curArg = 8, // Account for additionaly pushed arguments.
  768. numArgs = numargs() + argCount,
  769. //llen = sizeof (output) - 1,
  770. arg,
  771. none = (target & e_FORMAT_FLAGS_NONE),
  772. onlyOne = (target & e_FORMAT_FLAGS_ONE) | none | _:YSI_g_sJustOne,
  773. bool:fade = false,
  774. bool:nlInFade = false,
  775. // flags:
  776. // 1 = Just one output.
  777. // 2 = Newline found in fade.
  778. // 4 = In a fade.
  779. //flags = (target & e_FORMAT_FLAGS_ONE) ? 1 : 0,
  780. fakePos = 0,
  781. // Was only "one" string display used and is this not per-player text?
  782. one = 0,
  783. // Start location of the current fade.
  784. fadeStart,
  785. fadeStartIdx;//,
  786. //fadeStartText;
  787. //#emit LOAD.S.pri string
  788. //#emit STOR.S.pri fadeStartText
  789. if (target & e_FORMAT_FLAGS_REDO)
  790. {
  791. // We need to skip data, ignore everything before "target1".
  792. state y_render_fade : y_render_fade_redo;
  793. }
  794. else
  795. {
  796. state y_render_fade : y_render_fade_real;
  797. }
  798. target &= e_FORMAT_FLAGS_INDEX;
  799. /*new
  800. fadeCurArg,
  801. fadeArg,
  802. fadeIdx;*/
  803. if ((YSI_g_sFadeRedoTarget = target))
  804. {
  805. YSI_g_sFadeRedoTarget &= ~Y_FORMAT_ALWAYS_SET;
  806. state y_render_fade : y_render_fade_redo;
  807. }
  808. else
  809. {
  810. state y_render_fade : y_render_fade_real;
  811. }
  812. /*ch = string[idx];
  813. if (ch > 0)
  814. {
  815. // Copy strings.
  816. ++idx;
  817. Y_RENDER_ADD_EX(string, idx, ch - idx)
  818. idx = ch;
  819. }*/
  820. while ((ch = string[idx++]))
  821. {
  822. // TODO: Add {*} and #* format for variable colours.
  823. switch (ch)
  824. {
  825. case '\01':
  826. {
  827. // Null.
  828. break;
  829. }
  830. case '\02':
  831. {
  832. P:6("Text_Render: Format specifier %d", curArg);
  833. if (curArg == numArgs)
  834. {
  835. // Skip.
  836. P:W("Insufficient parameters to YSI format.");
  837. ts = "(null)";
  838. Y_RENDER_ADD(ts)
  839. continue;
  840. }
  841. // Format.
  842. ch = string[idx++];
  843. new
  844. width = (ch & _:e_COMPRESS_FORMAT_DATA_WIDTH),
  845. prec = (ch & _:e_COMPRESS_FORMAT_DATA_PREC) >>> 12;
  846. // Get the true values of the various data bits.
  847. if (width == 0x0800)
  848. {
  849. width = getarg(curArg++);
  850. }
  851. if (prec == 0x0800)
  852. {
  853. prec = getarg(curArg++);
  854. }
  855. else if (prec == 0x0FFF)
  856. {
  857. prec = -1;
  858. }
  859. // Output the correct data type.
  860. switch (ch & 0xF0000000)
  861. {
  862. case e_COMPRESS_FORMAT_DATA_DEC:
  863. {
  864. P:6("Text_Render: Add d");
  865. scSpecifier = Y_RENDER_SPECIFIER(d);
  866. Y_RENDER_ARG
  867. {
  868. //p += Format_AddInt(output[p], llen, arg, width, ch);
  869. format(ts, sizeof (ts), scSpecifier, width, prec, arg);
  870. Y_RENDER_ADD(ts)
  871. }
  872. }
  873. case e_COMPRESS_FORMAT_DATA_HEX:
  874. {
  875. // This completely fixes (I hope) the problems with
  876. // displaying negative numbers as %h/%x numbers.
  877. P:6("Text_Render: Add h");
  878. scSpecifier = Y_RENDER_SPECIFIER(x);
  879. Y_RENDER_ARG
  880. {
  881. if (arg & 0x80000000)
  882. {
  883. Y_RENDER_FIX_NEGATIVE(x:8);
  884. }
  885. else
  886. {
  887. format(ts, sizeof (ts), scSpecifier, width, prec, arg);
  888. }
  889. Y_RENDER_ADD(ts)
  890. }
  891. }
  892. case e_COMPRESS_FORMAT_DATA_BIN:
  893. {
  894. P:6("Text_Render: Add b");
  895. scSpecifier = Y_RENDER_SPECIFIER(b);
  896. Y_RENDER_ARG
  897. {
  898. if (arg & 0x80000000)
  899. {
  900. Y_RENDER_FIX_NEGATIVE(b:32);
  901. }
  902. else
  903. {
  904. format(ts, sizeof (ts), scSpecifier, width, prec, arg);
  905. }
  906. Y_RENDER_ADD(ts)
  907. }
  908. }
  909. case e_COMPRESS_FORMAT_DATA_CHAR:
  910. {
  911. scSpecifier = Y_RENDER_SPECIFIER(c);
  912. Y_RENDER_ARG
  913. {
  914. //p += Format_AddInt(output[p], llen, arg, width, ch);
  915. format(ts, sizeof (ts), scSpecifier, width, prec, arg);
  916. Y_RENDER_ADD(ts)
  917. }
  918. }
  919. case e_COMPRESS_FORMAT_DATA_FLOAT:
  920. {
  921. scSpecifier = Y_RENDER_SPECIFIER(f);
  922. Y_RENDER_ARG
  923. {
  924. //p += Format_AddInt(output[p], llen, arg, width, ch);
  925. format(ts, sizeof (ts), scSpecifier, width, prec, arg);
  926. Y_RENDER_ADD(ts)
  927. }
  928. }
  929. case e_COMPRESS_FORMAT_DATA_IEEE:
  930. {
  931. Y_RENDER_ARG
  932. {
  933. if ((arg & 0x7F800000) == 0x7F800000)
  934. {
  935. scSpecifier = Y_RENDER_SPECIFIER(s);
  936. // One of the special numbers.
  937. if (arg & 0x007FFFFF)
  938. {
  939. // NAN.
  940. if (arg & 0x00400000)
  941. {
  942. // QNAN
  943. format(ts, sizeof (ts), scSpecifier, width, cellmax, "QNAN");
  944. Y_RENDER_ADD(ts)
  945. }
  946. else
  947. {
  948. // SNAN
  949. format(ts, sizeof (ts), scSpecifier, width, cellmax, "SNAN");
  950. Y_RENDER_ADD(ts)
  951. }
  952. }
  953. else
  954. {
  955. if (arg & 0x80000000)
  956. {
  957. // -INFINITY
  958. format(ts, sizeof (ts), scSpecifier, width, cellmax, "-INFINITY");
  959. Y_RENDER_ADD(ts)
  960. }
  961. else
  962. {
  963. // INFINITY
  964. format(ts, sizeof (ts), scSpecifier, width, cellmax, "INFINITY");
  965. Y_RENDER_ADD(ts)
  966. }
  967. }
  968. }
  969. else
  970. {
  971. scSpecifier = Y_RENDER_SPECIFIER(f);
  972. format(ts, sizeof (ts), scSpecifier, width, prec, arg);
  973. Y_RENDER_ADD(ts)
  974. }
  975. }
  976. }
  977. case e_COMPRESS_FORMAT_DATA_STRING:
  978. {
  979. scSpecifier = Y_RENDER_SPECIFIER(s);
  980. if (ch & _:e_COMPRESS_FORMAT_DATA_FUNC)
  981. {
  982. func = "@yR_";
  983. // Get the function name.
  984. for (new _k = 4; _k != 32; ++_k)
  985. {
  986. if (!(func[_k] = getarg(curArg, _k - 4)))
  987. {
  988. break;
  989. }
  990. }
  991. if (funcidx(func) == -1)
  992. {
  993. // Normal version. This is ended by a null.
  994. // Other functions get the count in advance when
  995. // an index of -1 is passed.
  996. func[2] = 'r';
  997. // This code mimicks much of the internal
  998. // y_master code because wrapping this in a
  999. // macro is a) pointless and b) hard. This code
  1000. // is ALWAYS like this because of the nature of
  1001. // it.
  1002. new
  1003. lst = setproperty(8, YSIM_CALLER),
  1004. _j = 0;
  1005. setproperty(8, YSIM_CALLER, _@);
  1006. for ( ; ; )
  1007. {
  1008. CallRemoteFunction(func, "ii", _:l, _j);
  1009. // Resolve the string.
  1010. getproperty(8, "", YSIM_STRING, Q@);
  1011. strunpack(Q@, Q@);
  1012. if (Q@[0])
  1013. {
  1014. if (_j)
  1015. {
  1016. // Separate the strings - hard coded
  1017. // list format currently I'm afraid.
  1018. //ts = ", ";
  1019. //Y_RENDER_ADD(ts)
  1020. Y_RENDER_ADD(YSI_g_sListSep)
  1021. }
  1022. format(ts, sizeof (ts), scSpecifier, width, prec, Q@);
  1023. Y_RENDER_ADD(ts)
  1024. }
  1025. else
  1026. {
  1027. break;
  1028. }
  1029. ++_j;
  1030. }
  1031. setproperty(8, YSIM_CALLER, lst);
  1032. }
  1033. else
  1034. {
  1035. // Player specific version.
  1036. // Normal version. This is ended by a null.
  1037. // Other functions get the count in advance when
  1038. // an index of -1 is passed.
  1039. //func[2] = 'r';
  1040. // This code mimicks much of the internal
  1041. // y_master code because wrapping this in a
  1042. // macro is a) pointless and b) hard. This code
  1043. // is ALWAYS like this because of the nature of
  1044. // it.
  1045. new
  1046. lst = setproperty(8, YSIM_CALLER),
  1047. _j = 0;
  1048. setproperty(8, YSIM_CALLER, _@);
  1049. for ( ; ; )
  1050. {
  1051. CallRemoteFunction(func, "iii", pid, _:l, _j);
  1052. // Resolve the string.
  1053. getproperty(8, "", YSIM_STRING, Q@);
  1054. strunpack(Q@, Q@);
  1055. if (Q@[0])
  1056. {
  1057. if (_j)
  1058. {
  1059. // Separate the strings - hard coded
  1060. // list format currently I'm afraid.
  1061. //ts = ", ";
  1062. //Y_RENDER_ADD(ts)
  1063. Y_RENDER_ADD(YSI_g_sListSep)
  1064. }
  1065. // Could do with configuring this to not
  1066. // need to call "Y_RENDER_SPECIFIER" every
  1067. // time.
  1068. format(ts, sizeof (ts), scSpecifier, width, prec, Q@);
  1069. Y_RENDER_ADD(ts)
  1070. }
  1071. else
  1072. {
  1073. break;
  1074. }
  1075. ++_j;
  1076. }
  1077. setproperty(8, YSIM_CALLER, lst);
  1078. // Force the string to be rebuilt every time.
  1079. ++one;
  1080. }
  1081. }
  1082. else
  1083. {
  1084. // Single parameter. Can do this FAR better by just
  1085. // using #emit to re-push the parameter directly.
  1086. for (new _k = 0; _k != sizeof (ts); ++_k)
  1087. {
  1088. if (!(ts[_k] = getarg(curArg, _k)))
  1089. {
  1090. break;
  1091. }
  1092. }
  1093. format(ts, sizeof (ts), scSpecifier, width, prec, ts);
  1094. Y_RENDER_ADD(ts)
  1095. }
  1096. ++curArg;
  1097. }
  1098. /*case e_COMPRESS_FORMAT_DATA_OCT:
  1099. {
  1100. Y_RENDER_ARG
  1101. {
  1102. //p += Format_AddInt(output[p], llen, arg, width, ch);
  1103. //format(ts, sizeof (ts), Y_RENDER_SPECIFIER(f), width, prec, arg);
  1104. ts[Format_AddOct(ts, sizeof (ts) - 1, arg, width, ch)] = '\0';
  1105. Y_RENDER_ADD(ts)
  1106. }
  1107. }*/
  1108. case e_COMPRESS_FORMAT_DATA_COMM:
  1109. {
  1110. scSpecifier = Y_RENDER_SPECIFIER(s);
  1111. // Show a command.
  1112. /*for(new _i=0,_b=4;_i!=2;++_i)
  1113. if(_i==0)
  1114. {
  1115. if(ch&_:e_COMPRESS_FORMAT_DATA_FUNC)
  1116. {
  1117. _b=1,func="@yR_";
  1118. for(new _k=4;_k!=32;++_k)
  1119. if(!(func[_k]=getarg(curArg,_k-4)))
  1120. break;
  1121. if(funcidx(func)==-1)func[2]='r',_b=2;
  1122. }
  1123. else if(ch&_:e_COMPRESS_FORMAT_DATA_LIST)
  1124. _b=3;
  1125. }
  1126. else
  1127. for(new _j=0;(arg=_b==1?W@(func,"iii",pid,(_:l),_j):_b==2?W@(func,"ii",(_:l),_j):_b==3?getarg(curArg,_j++):getarg(curArg)),(_j!=-1&&_b)?TRUE:++curArg&&FALSE;_b=_b==4?0:_b)*/
  1128. Y_RENDER_ARG
  1129. {
  1130. //p += Format_AddInt(output[p], llen, arg, width, ch);
  1131. //format(ts, sizeof (ts), Y_RENDER_SPECIFIER(f), width, prec, arg);
  1132. // "arg" has the ID of the command, not the NAME of
  1133. // the command which may change for different people
  1134. // (need to find a way to return a single name for a
  1135. // player which gets to the specified command).
  1136. #if defined _inc_y_commands
  1137. strcpy(ts, Command_GetDisplay(arg, pid));
  1138. if (ts[0])
  1139. {
  1140. format(ts, sizeof (ts), scSpecifier, width, prec, ts);
  1141. Y_RENDER_ADD(ts)
  1142. }
  1143. #endif
  1144. //ts[Format_AddOct(ts, sizeof (ts) - 1, arg, width, ch)] = '\0';
  1145. //Y_RENDER_ADD(ts)
  1146. }
  1147. }
  1148. /*case e_COMPRESS_FORMAT_DATA_SUFFIX:
  1149. {
  1150. scSpecifier = Y_RENDER_SPECIFIER(s);
  1151. // TODO: Add language to this.
  1152. //p += Format_AddSuffix(output[p], llen, getarg(curArg++), l);
  1153. Y_RENDER_ARG
  1154. {
  1155. format(ts, sizeof (ts), scSpecifier, width, cellmax, Format_AddSuffix(arg, l));
  1156. Y_RENDER_ADD(ts)
  1157. }
  1158. }
  1159. case e_COMPRESS_FORMAT_DATA_UNSIGNED:
  1160. {
  1161. if (prec < 0) prec = 10;
  1162. Y_RENDER_ARG
  1163. {
  1164. //p += Format_AddInt(output[p], llen, arg, width, ch);
  1165. //format(ts, sizeof (ts), Y_RENDER_SPECIFIER(f), width, prec, arg);
  1166. //ts[Format_AddOct(ts, sizeof (ts) - 1, arg, width, ch)] = '\0';
  1167. ts[Format_AddNum(ts, sizeof (ts) - 1, arg, width, ch, prec, false)] = '\0';
  1168. Y_RENDER_ADD(ts)
  1169. }
  1170. }
  1171. case e_COMPRESS_FORMAT_DATA_SIGNED:
  1172. {
  1173. if (prec < 0) prec = 10;
  1174. Y_RENDER_ARG
  1175. {
  1176. //p += Format_AddInt(output[p], llen, arg, width, ch);
  1177. //format(ts, sizeof (ts), Y_RENDER_SPECIFIER(f), width, prec, arg);
  1178. ts[Format_AddNum(ts, sizeof (ts) - 1, arg, width, ch, prec, true)] = '\0';
  1179. Y_RENDER_ADD(ts)
  1180. }
  1181. }*/
  1182. case e_COMPRESS_FORMAT_DATA_PLAYER:
  1183. {
  1184. Y_RENDER_ARG
  1185. {
  1186. //p += Format_AddInt(output[p], llen, arg, width, ch);
  1187. GetPlayerName(arg, ts, sizeof (ts));
  1188. format(ts, sizeof (ts), scSpecifier, width, prec, ts);
  1189. Y_RENDER_ADD(ts)
  1190. }
  1191. }
  1192. case e_COMPRESS_FORMAT_DATA_LOGICAL:
  1193. {
  1194. scSpecifier = Y_RENDER_SPECIFIER(s);
  1195. Y_RENDER_ARG
  1196. {
  1197. //p += Format_AddInt(output[p], llen, arg, width, ch);
  1198. format(ts, sizeof (ts), scSpecifier, width, prec, arg ? ("true") : ("false"));
  1199. Y_RENDER_ADD(ts)
  1200. }
  1201. }
  1202. case e_COMPRESS_FORMAT_DATA_CUSTOM:
  1203. {
  1204. // Get the function we will be calling to do the format.
  1205. // Slice caches these, but we don't because of the
  1206. // extended versions (%k<DATE>) etc.
  1207. new
  1208. ffake[4 char],
  1209. fidx;
  1210. ffake[0] = string[idx];
  1211. if (ffake{1} == '@')
  1212. {
  1213. if (!AMX_GetPublicPointer(0, fidx, ffake))
  1214. {
  1215. continue;
  1216. }
  1217. ++idx;
  1218. }
  1219. else
  1220. {
  1221. static
  1222. sFunc2[32] = "F";
  1223. strunpack(sFunc2[1], string[idx], sizeof (sFunc2) - 1);
  1224. // Limit the function name to the function length.
  1225. sFunc2[sFunc2[1]] = '\0';
  1226. idx += ceildiv(sFunc2[1], 4);
  1227. sFunc2[1] = '@';
  1228. if (!AMX_GetPublicPointer(0, fidx, sFunc2))
  1229. {
  1230. continue;
  1231. }
  1232. }
  1233. //
  1234. // "b":
  1235. //
  1236. // "b" is the source type. "1" = function, "2" = per-
  1237. // player function, "3" = list, "4" = variable. "0" is
  1238. // a special case meaning "processed variable" and tells
  1239. // the system to stop "j != -1 && b".
  1240. //
  1241. // "i":
  1242. //
  1243. // "i" is the current processing stage - there are two.
  1244. // The first looks at all the arguments and collects the
  1245. // function or list data (if any). The second loops
  1246. // over all the passed arguments and does the format.
  1247. // This is where the "b" check comes in, to only do that
  1248. // inner loop once. It is done this way simply to allow
  1249. // us to use braces around the code to do the format.
  1250. //
  1251. // "j":
  1252. //
  1253. // "j" is the main loop variable for the inner loop and
  1254. // tracks which parameter part we are currently doing in
  1255. // the case of function or list inputs.
  1256. //
  1257. for (new i, j, b = 4; i != 2; ++i)
  1258. {
  1259. if (!i)
  1260. {
  1261. if (ch & _:e_COMPRESS_FORMAT_DATA_FUNC)
  1262. {
  1263. b = 1;
  1264. func = "@yR_";
  1265. va_getstring(func[4], curArg);
  1266. if (funcidx(func) == -1)
  1267. {
  1268. b = 2;
  1269. func[2] = 'r';
  1270. }
  1271. }
  1272. else if (ch & _:e_COMPRESS_FORMAT_DATA_LIST)
  1273. {
  1274. b = 3;
  1275. }
  1276. ch &= FORMAT_FLAG_LEFT | FORMAT_FLAG_ZERO;
  1277. }
  1278. else
  1279. {
  1280. for (;
  1281. // These lines ALWAYS get run because
  1282. // they come before a comma in the "for"
  1283. // conditional, but their result is
  1284. // ignored.
  1285. (arg = (b == 1)
  1286. ? W@(func, "iii", pid, (_:l), j)
  1287. : (b == 2)
  1288. ? W@(func, "ii", (_:l), j)
  1289. : (b == 3)
  1290. ? getarg(curArg, j++)
  1291. : getarg(curArg)
  1292. ),
  1293. // This is the true condition. If the
  1294. // first half fails then "curArg" is
  1295. // incremented and the whole check
  1296. // fails, otherwise, thanks to short-
  1297. // circuiting, "curArg" is NOT
  1298. // incremented.
  1299. (arg != cellmin && b) || (++curArg & 0);
  1300. // Only run the loop once when "b = 4".
  1301. b &= ~4, ++j
  1302. )
  1303. {
  1304. // Standard format code goes here.
  1305. #emit PUSH.S prec
  1306. #emit PUSH.S width
  1307. #emit PUSH.S ch
  1308. // Get the source (assume constant for now,
  1309. // i.e. no functions or lists yet).
  1310. #emit PUSH.S arg
  1311. // Get a string if there is one.
  1312. if (b == 1 || b == 2)
  1313. {
  1314. getproperty(8, "", YSIM_STRING, Q@);
  1315. strunpack(Q@, Q@);
  1316. if (isnull(Q@))
  1317. {
  1318. ++curArg;
  1319. // Fix the stack.
  1320. #emit POP.pri
  1321. #emit POP.pri
  1322. #emit POP.pri
  1323. #emit POP.pri
  1324. break;
  1325. }
  1326. #emit PUSH.C Q@
  1327. }
  1328. else
  1329. {
  1330. #emit LCTRL 5
  1331. #emit LOAD.S.alt curArg
  1332. #emit SHL.C.alt 2
  1333. #emit ADD
  1334. #emit LOAD.I
  1335. #emit PUSH.pri
  1336. }
  1337. #emit PUSH.C ts
  1338. // Far more parameters that Slice's.
  1339. #emit PUSH.C 24 // 4 * 6.
  1340. // This code is almost common now!
  1341. #emit LCTRL 6
  1342. #emit ADD.C 28
  1343. #emit PUSH.pri
  1344. #emit LOAD.S.pri fidx
  1345. #emit SCTRL 6
  1346. // Now we have returned from the custom
  1347. // function.
  1348. Y_RENDER_ADD(ts)
  1349. }
  1350. }
  1351. }
  1352. }
  1353. /*case e_COMPRESS_FORMAT_DATA_DATE:
  1354. {
  1355. // Hard one - needs more interaction.
  1356. }*/
  1357. }
  1358. }
  1359. case '\03', -1:
  1360. {
  1361. P:6("Text_Render: Colour %d %d %d %d %d %06x %s", p, llen, fadeStart, fakePos, idx, colour & 0xFFFFFF, string);
  1362. if (fade) //flags & 4)
  1363. {
  1364. p = fadeStart;
  1365. new
  1366. rem = Format_DoEndFade(output, p, fakePos, llen, string[idx], colour);
  1367. if (rem || nlInFade) //(flags & 2))
  1368. {
  1369. // "rem" is the number of characters not processed.
  1370. YSI_g_sFadeColour = colour;
  1371. Y_RENDER_DO_DISPLAY()
  1372. P:6("Format_Render: one stage: \"%s\"", output);
  1373. // Subtract 2 to get the index in to the fade where the
  1374. // letters start. This is not as easy as it used to be
  1375. // as we need to manipulate the stack to push the extra
  1376. // parameters somehow. Now changed to a fake tail-
  1377. // recursive call so that we don't need to worry about
  1378. // the stack. This also explains why labels generate
  1379. // extra stack manipulation code (to reset locals).
  1380. //return Format_Render(pid, l, output, maxlen, fadeStartIdx, fakePos - fadeStart - rem | e_FORMAT_FLAGS_REDO, string);
  1381. //#emit LOAD.S.pri fadeStartText
  1382. //#emit STOR.S.pri string
  1383. idx = fadeStartIdx;
  1384. target = (fakePos - fadeStart - rem) | e_FORMAT_FLAGS_REDO;
  1385. gInitialColour = colour;
  1386. //YSI_g_sTempStyle[E_STYLE_DATA_COLOUR] = (YSI_g_sTempStyle[E_STYLE_DATA_COLOUR] & 0xF000000F) | (gInitialColour << 4);
  1387. goto Format_Render_start;
  1388. // We don't need these as they are only set when you
  1389. // want less than 2 displays, and as to get to this
  1390. // point you need to have shown at least noe item there
  1391. // is no possible way they can be set the second time.
  1392. //| (onlyOne ? e_FORMAT_FLAGS_ONE : 0) | (none ? e_FORMAT_FLAGS_NONE : 0);
  1393. }
  1394. //flags &= ~4;
  1395. fade = false;
  1396. fakePos += p - fadeStart;
  1397. }
  1398. if (string[idx] & Y_FORMAT_CLOSE_CURR)
  1399. {
  1400. // Get the initial display colour.
  1401. //string[idx] |= (YSI_g_sTempStyle[E_STYLE_DATA_COLOUR] >>> 4) & 0x00FFFFFF;
  1402. string[idx] = (string[idx] & 0xFF000000) | ((YSI_g_sTempStyle[E_STYLE_DATA_COLOUR] >>> 4) & 0x00FFFFFF);
  1403. }
  1404. if (string[idx] & Y_FORMAT_START_FADE)
  1405. {
  1406. //flags |= 4;
  1407. fade = true;
  1408. fadeStart = p;
  1409. fadeStartIdx = idx - 1;
  1410. string[fadeStartIdx] = -1;
  1411. //#emit LOAD.S.pri string
  1412. //#emit STOR.S.pri fadeStartText
  1413. if (p < maxlen - 1)
  1414. {
  1415. output[p++] = '\03';
  1416. output[p++] = string[idx++];
  1417. }
  1418. }
  1419. else
  1420. {
  1421. // Just add the colour here normally.
  1422. arg = Format_AddColour(output, p, llen, colour, string[idx++]); //& ~(Y_FORMAT_START_FADE | Y_FORMAT_ALWAYS_SET));
  1423. switch (arg)
  1424. {
  1425. case -1:
  1426. {
  1427. Y_RENDER_DO_DISPLAY()
  1428. }
  1429. case 0:
  1430. {
  1431. // Do nothing.
  1432. }
  1433. default:
  1434. {
  1435. p += arg;
  1436. fakePos += arg;
  1437. }
  1438. }
  1439. /*else
  1440. {
  1441. p += arg;
  1442. }
  1443. currentColour = string[idx++];
  1444. if (maxlen - pos > Y_RENDER_SCM_COLOUR_LEN)
  1445. {
  1446. format(output[pos], maxlen - pos, "{%06x}", currentColour & ~(Y_FORMAT_START_FADE | Y_FORMAT_ALWAYS_SET));
  1447. pos += Y_RENDER_SCM_COLOUR_LEN;
  1448. }
  1449. else
  1450. {
  1451. output[pos] = '\0';
  1452. printf("some stage: \"%s\"", output);
  1453. output[0] = '\0';
  1454. pos = 0;
  1455. }*/
  1456. //++idx;
  1457. }
  1458. }
  1459. case '\04':
  1460. {
  1461. P:6("Text_Render: Key");
  1462. ++idx;
  1463. }
  1464. case '\05':
  1465. {
  1466. // String extension.
  1467. P:6("Text_Render: Extension %d %d %d", YSI_g_sTempMaster, string[idx], string[idx - 1]);
  1468. // TODO!
  1469. // This should change the current input to a new one. May
  1470. // require some more advanced hacking to support fades over
  1471. // these boundaries (or just ban them)... Actually, I don't
  1472. // think it will require extra work...
  1473. // Just use the text directly.
  1474. idx = _Text_GetPointer(YSI_g_sTempMaster, string[idx]);
  1475. #emit LOAD.S.pri idx
  1476. #emit STOR.S.pri string
  1477. idx = 0;
  1478. }
  1479. case '\n':
  1480. {
  1481. P:6("Text_Render: NL");
  1482. // Check for 2 character new lines (\n\r).
  1483. if (string[idx] == '\r') ++idx;
  1484. // Output the last string.
  1485. if (fade) //flags & 4)
  1486. {
  1487. //flags |= 2;
  1488. nlInFade = true;
  1489. state y_render_fade : y_render_fade_fake;
  1490. }
  1491. else if ((YSI_g_sTempStyle[E_STYLE_DATA_TYPE] & e_STYLE_TYPE_MASK) < e_STYLE_TYPE_CLIENT)
  1492. {
  1493. // This works even for GTs which are always 0 by this point.
  1494. Y_RENDER_ADD(scNewLineString)
  1495. }
  1496. else if (YSI_g_sTempStyle[E_STYLE_DATA_TYPE] == e_STYLE_TYPE_DIALOG)
  1497. {
  1498. //printf("NL 1");
  1499. // This works even for GTs which are always 0 by this point.
  1500. Y_RENDER_ADD(scDialogLineString)
  1501. //printf("NL 2");
  1502. }
  1503. else
  1504. {
  1505. Y_RENDER_DO_DISPLAY()
  1506. gInitialColour = colour;
  1507. }
  1508. }
  1509. case '\r':
  1510. {
  1511. P:6("Text_Render: NL");
  1512. // Check for 2 character new lines (\r\n).
  1513. if (string[idx] == '\n') ++idx;
  1514. // Output the last string.
  1515. if (fade) //flags & 4)
  1516. {
  1517. //flags |= 2;
  1518. nlInFade = true;
  1519. state y_render_fade : y_render_fade_fake;
  1520. }
  1521. else if ((YSI_g_sTempStyle[E_STYLE_DATA_TYPE] & e_STYLE_TYPE_MASK) < e_STYLE_TYPE_CLIENT)
  1522. {
  1523. // This works even for GTs which are always 0 by this point.
  1524. Y_RENDER_ADD(scNewLineString)
  1525. }
  1526. else if (YSI_g_sTempStyle[E_STYLE_DATA_TYPE] == e_STYLE_TYPE_DIALOG)
  1527. {
  1528. // This works even for GTs which are always 0 by this point.
  1529. //printf("NL 3");
  1530. Y_RENDER_ADD(scDialogLineString)
  1531. //printf("NL 4");
  1532. }
  1533. else
  1534. {
  1535. Y_RENDER_DO_DISPLAY()
  1536. }
  1537. }
  1538. case '\t':
  1539. {
  1540. // Somehow display a tab. Maybe keep track of characters
  1541. // displayed and show "n % 4" spaces.
  1542. arg = 4 - (p & 0x03); // The number of spaces to add.
  1543. static
  1544. sTabs[] = " ";
  1545. for (new __added; (__added = Format_DoAddString(output, sTabs[4 - arg], p, arg, llen, fakePos)); arg -= __added)
  1546. {
  1547. if (fade) //flags & 4)
  1548. {
  1549. state y_render_fade : y_render_fade_fake;
  1550. }
  1551. else
  1552. {
  1553. Y_RENDER_DO_DISPLAY()
  1554. }
  1555. }
  1556. }
  1557. case '\06' .. '\08', '\11', '\12', '\14' .. '\32':
  1558. {
  1559. // Whitespace. Just show a space, not the fancy character, no
  1560. // idea what it could do. Note that this range includes spaces.
  1561. P:6("Text_Render: Space");
  1562. Y_RENDER_CHAR(' ')
  1563. }
  1564. default:
  1565. {
  1566. P:6("Text_Render: Char");
  1567. Y_RENDER_CHAR(ch)
  1568. }
  1569. }
  1570. /*if (!(ch = string[idx]))
  1571. {
  1572. break;
  1573. }
  1574. // Copy strings.
  1575. ++idx;
  1576. Y_RENDER_ADD_EX(string, idx, ch - idx)
  1577. idx = ch;*/
  1578. P:6("Text_Render: Loop: p = %d, llen = %d, output = \"%s\"", p, llen, (output[p] = '\0', output));
  1579. }
  1580. P:5("Text_Render: Final render?");
  1581. if (p)
  1582. {
  1583. P:5("Text_Render: Yes!");
  1584. output[p] = '\0';
  1585. if (!none) Format_DoDisplay(pid, gInitialColour, output);
  1586. ++one;
  1587. }
  1588. P:5("Text_Render: p = %d, output = \"%s\"", p, output);
  1589. P:C(idx=0;while ((ch = output[idx++]))printf("%04x%04x = %c", ch >>> 16, ch & 0xFFFF, ch););
  1590. P:5("Text_Render end");
  1591. return one;
  1592. }