y_textrender.inc 53 KB

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