forked from pawn-lang/YSI-Includes
/
render.inc
1655 lines (1597 loc) · 52.3 KB
/
render.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Legal:
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 the "License"; you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is the YSI framework.
The Initial Developer of the Original Code is Alex "Y_Less" Cole.
Portions created by the Initial Developer are Copyright C 2011
the Initial Developer. All Rights Reserved.
Contributors:
Y_Less
koolk
JoeBullet/Google63
g_aSlice/Slice
Misiur
samphunter
tianmeta
maddinat0r
spacemud
Crayder
Dayvison
Ahmad45123
Zeex
irinel1996
Yiin-
Chaprnks
Konstantinos
Masterchen09
Southclaws
PatchwerkQWER
m0k1
paulommu
udan111
Thanks:
JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
ZeeX - Very productive conversations.
koolk - IsPlayerinAreaEx code.
TheAlpha - Danish translation.
breadfish - German translation.
Fireburn - Dutch translation.
yom - French translation.
50p - Polish translation.
Zamaroht - Spanish translation.
Los - Portuguese translation.
Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes for
me to strive to better.
Pixels^ - Running XScripters where the idea was born.
Matite - Pestering me to release it and using it.
Very special thanks to:
Thiadmer - PAWN, whose limits continue to amaze me!
Kye/Kalcor - SA:MP.
SA:MP Team past, present and future - SA:MP.
Optional plugins:
Gamer_Z - GPS.
Incognito - Streamer.
Me - sscanf2, fixes2, Whirlpool.
*/
#if !defined FORMAT_FADE_STEP
#define FORMAT_FADE_STEP 2
#endif
#define Y_RENDER_SCM_COLOUR_LEN (8)
//#define Y_RENDER_ONE_ARG
// if ((arg = getarg(curArg++) || TRUE))
// Loops through all possible arguments in lists, functions and singles. See
// "case e_COMPRESS_FORMAT_DATA_CUSTOM:" for more details (an expanded macro
// version can be found there).
#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)
// Make the correct specifier string for the data stored in the compressed
// specifier data.
#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])))
// This makes hex and binary format specifiers display correctly with negative
// numbers in all cases (e.g. %5x etc).
#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)
// Try add a string to the current output. This needs modifying to reset the
// whole function after a string is displayed. "onlyOne" is set in the case
// where any line excess is cut off (e.g. in marquees).
//#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);}
#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;}
#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()}
//#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()}
#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()}
// Helper macros to determine what a character is. This could be modified to
// take in to account unicode letters, but that's hard. I don't know enough
// about unicode, and frankly there are WAY too many characters to be listed
// here. If other people want to modify this to support their language then
// good on them.
#define Y_TEXT_LETTER(%0) ('a'<=(%0)<='z'||'A'<=(%0)<='Z')
#define Y_TEXT_NUMBER(%0) ('0'<=(%0)<='9')
#define Y_RENDER_SCM_COLOUR_LEN (8)
#define e_FORMAT_FLAGS_INDEX (0x00FFFFFF)
#define e_FORMAT_FLAGS_REDO (0x01000000)
#define e_FORMAT_FLAGS_ONE (0x02000000)
#define e_FORMAT_FLAGS_NONE (0x04000000)
static stock
YSI_g_sListSep[4] = ", ",
YSI_g_sFadeRedoTarget,
YSI_g_sFadeLength,
YSI_g_sFadeColour,
bool:YSI_g_sJustOne,
YSI_g_sTempStyle[E_STYLE_DATA],
YSI_g_sTemp3D[E_3D_DATA],
YSI_g_sTempMaster,
Text:YSI_g_sBaseTD = TEXT_DRAW_NO_NEXT,
//YSI_g_sExtraText[MAX_INI_ENTRY_TEXT],
gInitialColour;
/*-------------------------------------------------------------------------*//**
* <transition keep="true" target="y_render_show : y_render_show_scm" />
*//*------------------------------------------------------------------------**/
stock _Text_SetDialogMode()
{
YSI_g_sTempStyle[E_STYLE_DATA_TYPE] = e_STYLE_TYPE_DIALOG;
state y_render_show : y_render_show_scm;
YSI_g_sJustOne = true;
}
stock Format_SetListSeparator(string:lst[])
{
strcpy(YSI_g_sListSep, lst);
}
/*-------------------------------------------------------------------------*//**
* <transition keep="true" target="y_render_show : y_render_show_gt" />
* <transition keep="true" target="y_render_show : y_render_show_scm" />
* <transition keep="true" target="y_render_show : y_render_show_td" />
* <transition keep="true" target="y_render_show : y_render_show_print" />
*//*------------------------------------------------------------------------**/
stock _Format_SetStyleData(master, index, style[E_STYLE_DATA], label[E_3D_DATA])
{
// =========================================================================
//
#pragma unused index
//
// MAJOR WARNING:
//
// "Text_IsLocalOwner" DOES NOT PASS "INDEX" CORRECTLY AS IT DOESN'T KNOW
// WHAT IT SHOULD BE, DON'T FORGET THIS IF YOU EVER USE "index"...
//
// =========================================================================
YSI_g_sTempMaster = master;
YSI_g_sTempStyle = style;
YSI_g_sTemp3D = label;
switch (style[E_STYLE_DATA_TYPE] & e_STYLE_TYPE_MASK)
{
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:
{
state y_render_show : y_render_show_gt;
// Now that we know the style, we can store only the exact style.
YSI_g_sTempStyle[E_STYLE_DATA_TYPE] = ((style[E_STYLE_DATA_TYPE] & e_STYLE_TYPE_MASK) >>> e_STYLE_TYPE_SHIFT) - e_STYLE_TYPE:1;
YSI_g_sJustOne = true;
return 144;
}
case e_STYLE_TYPE_CLIENT:
{
state y_render_show : y_render_show_scm;
YSI_g_sJustOne = false;
return 256;
}
case e_STYLE_TYPE_TD:
{
state y_render_show : y_render_show_td;
YSI_g_sJustOne = true;
// Anything with the ability to be longer than 1024 will require a
// modification to the declaration of variables.
return 1024;
}
}
state y_render_show : y_render_show_print;
return 1023;
}
static stock Format_InsertColour(str[], pos, &rem, &curCol, newCol, step) <y_render_show : y_render_show_scm>
{
// This code doesn't yet deal with colours which are too close to have their
// differences detected by the human eye (especially when there are spaces).
curCol = newCol & 0x00FFFFFF;
if (pos == 0)
{
gInitialColour = curCol;
// Don't add the colour - this is handled in the text display function.
return 0;
}
// Now try add the string version of the colour.
//printf("rem: %d, required: %d", rem, Y_RENDER_SCM_COLOUR_LEN);
if (rem < Y_RENDER_SCM_COLOUR_LEN + step)
{
// Not enough space to add a new colour.
str[pos] = '\0';
return -1;
}
// This may well cut characters off the end of the string, but don't worry,
// well, you can worry because it may mean that some characters are parsed
// multiple times, but there's not a lot you can do about it... This is one
// of the few places where the extra "+ 1" is taken in to account as format
// uses it internally.
format(str[pos], rem + 1, "{%06x}%s", curCol, str[pos]);
rem -= Y_RENDER_SCM_COLOUR_LEN;
return Y_RENDER_SCM_COLOUR_LEN;
}
static stock Format_InsertColour(str[], pos, &rem, &curCol, newCol, step) <>
{
#pragma unused str, pos, rem, step
curCol = newCol;
return 0;
}
static stock Format_InsertColour(str[], pos, &rem, &curCol, newCol, step) <y_render_show : y_render_show_gt, y_render_show : y_render_show_td>
{
// First get the closest GameText colour for the true colour. I wrote a
// function for this a LONG time ago, finally got around to using it!
new
ot = curCol & 0xFF,
oc = curCol >>> 8;
if (ot == 0 || ot == 'x')
{
// Still near the start, allow some of the special start colours.
newCol = Colours_SAMPToGT(newCol & 0x00FFFFFF, oc);
}
else
{
// Can't use the oragey colour used at the start.
newCol = Colours_SAMPToGT(newCol & 0x00FFFFFF, 3);
}
new
nt = newCol & 0xFF,
nc = (newCol >>> 8) * 3;
curCol = newCol;
// Compare them.
static
cs_hTags[] = "~x~~h~~h~~h~~h~~h~%s";
if (nt == ot)
{
ot = nc - (oc * 3);
if (ot == 0)
{
// No change, return 0 if there are enough charaters to show the
// text that should come after this new colour.
return rem >= step ? 0 : -1;
}
else if (ot > 0)
{
if (rem >= ot + step)
{
// Add enough "lighter" tags to change the old colour in to the
// new colour.
format(str[pos], rem + 1, cs_hTags[sizeof (cs_hTags) - 3 - ot], str[pos]);
rem -= ot;
return ot;
}
else
{
return -1;
}
}
}
if (rem < nc + step)
{
return -1;
}
// Subtract six from the size : 3 for "%s\0" and 3 for the extra "~x~"
// needed as placeholder for the colour tag (added on the next line).
format(str[pos], rem + 1, cs_hTags[sizeof (cs_hTags) - 6 - nc], str[pos]);
str[pos + 1] = nt;
rem -= nc + 3;
return nc + 3;
}
static stock Format_AddColour(str[], pos, &rem, &curCol, newCol) <y_render_show : y_render_show_scm>
{
// This code doesn't yet deal with colours which are too close to have their
// differences detected by the human eye (especially when there are spaces).
new
rgb = newCol & 0x00FFFFFF;
// Don't add the colour if there's no change from the last one.
if (rgb == curCol)
{
return 0;
}
if (-0x5 <= ((rgb & 0x0FF) - (curCol & 0xFF)) <= 0x5)
{
if (-0x500 <= ((rgb & 0xFF00) - (curCol & 0xFF00)) <= 0x500)
{
if (-0x50000 <= ((rgb & 0xFF0000) - (curCol & 0xFF0000)) <= 0x50000)
{
// Haven't changed the colour.
return 0;
}
}
}
if (YSI_g_sTempStyle[E_STYLE_DATA_TYPE] != e_STYLE_TYPE_DIALOG && pos == 0)
{
gInitialColour = newCol;
// Don't add the colour - this is handled in the text display function.
curCol = rgb;
return 0;
}
// Now try add the string version of the colour.
if (rem < Y_RENDER_SCM_COLOUR_LEN)
{
// Not enough space to add a new colour.
str[pos] = '\0';
return -1;
}
format(str[pos], rem + 1, "{%06x}", rgb);
rem -= Y_RENDER_SCM_COLOUR_LEN;
curCol = newCol;
return Y_RENDER_SCM_COLOUR_LEN;
}
static stock Format_AddColour(str[], pos, &rem, &curCol, newCol) <>
{
#pragma unused str, pos, rem
curCol = newCol;
return 0;
}
static stock Format_AddColour(str[], pos, &rem, &curCol, newCol) <y_render_show : y_render_show_gt, y_render_show : y_render_show_td>
{
// First get the closest GameText colour for the true colour. I wrote a
// function for this a LONG time ago, finally got around to using it!
new
ot = curCol & 0xFF,
oc = curCol >>> 8;
if (ot == 0 || ot == 'x')
{
// Still near the start, allow some of the special start colours.
newCol = Colours_SAMPToGT(newCol & 0x00FFFFFF, oc);
}
else
{
// Can't use the oragey colour used at the start.
newCol = Colours_SAMPToGT(newCol & 0x00FFFFFF, 3);
}
new
nt = newCol & 0xFF,
nc = (newCol >>> 8) * 3;
curCol = newCol;
// Compare them.
static
cs_hTags[] = "~x~~h~~h~~h~~h~~h~";
if (nt == ot)
{
ot = nc - (oc * 3);
if (ot == 0)
{
return 0;
}
else if (ot > 0)
{
if (rem >= ot)
{
// Add enough "lighter" tags to change the old colour in to the
// new colour.
str[pos] = '\0';
strcat(str[pos], cs_hTags[sizeof (cs_hTags) - 1 - ot], rem + 1);
rem -= ot;
return ot;
}
else
{
return -1;
}
}
}
if (rem < nc)
{
return -1;
}
// Subtract six from the size : 3 for "%s\0" and 3 for the extra "~x~"
// needed as placeholder for the colour tag (added on the next line).
//format(str[pos], rem + 1, cs_hTags[sizeof (cs_hTags) - 6 - nc], str[pos]);
str[pos] = '\0';
strcat(str[pos], cs_hTags[sizeof (cs_hTags) - 4 - nc], rem + 1);
str[pos + 1] = nt;
rem -= nc + 3;
return nc + 3;
}
// str = input and output write array.
// pos = start position of the string to be faded.
// len = total remaining space in the string.
// endColour = target colour.
// gInitialColour = start and current colour.
// step = number of characters for each colour.
// offset = number of characters in the fade not being shown.
static stock Format_AddFade(str[], &pos, &len, endColour, &initialColour, step, offset) //<y_render_display : send_client_message>
{
// Add a fade for a SendClientMessage. This is called if a string is filled
// up during a fade or the end of a fade is reached correctly. In either
// case the current fade will constiture the end of the known current string
// so in actual fact no additionl text after the end of the fade will be
// dropped. This is also where we can save the data to appear in the fade
// on the next line and re-show it.
// Work out how many colours can be inserted at the specified step value
// (i.e. how often a new colour appears) within the length from "pos" to the
// end of "str". This may be more than is required. "len" is from "pos" to
// the end of the string, NOT to the end of the characters requiring the
// fade. The length of the required fade is in "YSI_g_sFadeLength" so that the
// value can be used in the future.
new
parts = (YSI_g_sFadeLength + step - 1) / step + offset,
// We can insert all the colours and their texts in the given space.
// Now we just need to figure out how...
// First get the start and end colours.
start = str[pos + 1] & 0x00FFFFFF; //~(Y_FORMAT_START_FADE | Y_FORMAT_ALWAYS_SET);
// Remove the start and end colour markers.
strdel(str, pos, pos + 2);
// Find the colour components and component deltas.
endColour &= 0x00FFFFFF; //~(Y_FORMAT_START_FADE | Y_FORMAT_ALWAYS_SET);
new
red = start >>> 16 & 0xFF,
dred = ((endColour >>> 16 & 0xFF) - red) / parts,
pred = initialColour >>> 16 & 0xFF,
green = start >>> 8 & 0xFF,
dgreen = ((endColour >>> 8 & 0xFF) - green) / parts,
pgreen = initialColour >>> 8 & 0xFF,
blue = start >>> 0 & 0xFF,
dblue = ((endColour >>> 0 & 0xFF) - blue) / parts,
pblue = initialColour >>> 0 & 0xFF;
// Take old strings in to account.
red += dred * offset;
blue += dblue * offset;
green += dgreen * offset;
//strdel(str, pmax, pmax + 2);
//startColour = gInitialColour;
do
{
// Insert the new colour, if it is sufficiently different from the
// existing colour to warrant being added new.
if (-3 <= red - pred <= 3 && -3 <= blue - pblue <= 3 && -3 <= green - pgreen <= 3)
{
pos += step;
}
else
{
new
upd = Format_InsertColour(str, pos, len, initialColour, red << 16 | green << 8 | blue, step);
if (upd == -1)
{
// Didn't quite finish everything. This is the number of
// characters left to process.
return YSI_g_sFadeLength;
}
//initial += step;
pos += step + upd;
pred = red;
pgreen = green;
pblue = blue;
}
YSI_g_sFadeLength -= step;
len -= step;
red = red + dred & 0xFF;
green = green + dgreen & 0xFF;
blue = blue + dblue & 0xFF;
// Could do something with "len" here if it runs out to signify that
// more text needs to go on the next line of output.
}
while (YSI_g_sFadeLength > 0);
// Correct for any excess characters.
pos += YSI_g_sFadeLength;
// This doesn't add the actual destination colour - that is added by virtue
// of the fact that it is actually just a normal colour, so we can use the
// standard colour code (whatever that may be) to add it in a more generic
// way.
return 0;
}
/*-------------------------------------------------------------------------*//**
* <transition keep="true" target="y_render_fade : y_render_fade_fake" />
*//*------------------------------------------------------------------------**/
static stock Format_DoEndFade(output[], &start, end, &rem, colour, &initial) //<>
{
// If "colour" is 0 this is the end of a string before the close colour is
// reached. This fact is enforced by "Y_FORMAT_ALWAYS_SET", which ensures
// that all colours, including black, are not 0 in the string to avoid PAWN
// treating the colour as a NULL terminator or, as here, a no-colour marker.
if (colour)
{
new
offset = 0;
if (YSI_g_sFadeLength)
{
initial = YSI_g_sFadeColour;
offset = end - start - YSI_g_sFadeLength;
//printf("parts: %d, %d, %d", offset, YSI_g_sFadeLength, end - start);
}
else
{
YSI_g_sFadeLength = end - start;
}
// "rem" will hold the number of characters AFTER the fade string on
// entry, this needs fixing here to exclude them as they're being messed
// with.
rem += YSI_g_sFadeLength;
//printf("length: %d", YSI_g_sFadeLength);
// I wrote this code for the case where too much data has been found and
// we needed a fake render to get the full length, but then found that
// exactly the same code was needed for the default case too...
//printf("Format_DoEndFade: %d %d %x %x %d", YSI_g_sFadeLength, /*YSI_g_sFadeLength +*/ rem, colour, initial, start);
// Default step value is 1 and there is currently no way to change it.
new
ret = Format_AddFade(output, start, /*YSI_g_sFadeLength +*/ rem, colour, initial, FORMAT_FADE_STEP, offset);
//printf("Format_DoEndFade: %d %d %x %x %d", YSI_g_sFadeLength, /*YSI_g_sFadeLength +*/ rem, colour, initial, start);
YSI_g_sFadeColour = initial;
return ret;
}
else
{
//printf("colour: %d", YSI_g_sFadeColour);
// Quite simply, we just change state and return to the calling
// function. This allows this function to be called again when the true
// fade end is reached and the length to be determined. After that some
// re-parsing will need to be done I'm afraid, but that will be handled
// by code dealing with fades which fall over the end of a string, be it
// due to this or to a known length string being pushed over the end due
// to the insertion of the colour codes. Note that this code is display
// method independent - it works for SendClientMessage, GameText and
// others.
state y_render_fade : y_render_fade_fake;
// The return here causes remaining code to continue as normal, but
// makes certain functions just not run.
}
return 0;
}
/*-------------------------------------------------------------------------*//**
* <param name="out">The destination string.</param>
* <param name="in">The data to add.</param>
* <param name="oidx">The index in "out" at which to add data.</param>
* <param name="len">The length of "in".</param>
* <param name="orem">Space remaining in "out".</param>
* <param name="fakePos">Like "oidx", but cumulative over line breaks.</param>
* <returns>
* The amount of data from "in" not added to "out".
* </returns>
* <remarks>
* Takes an input string and adds it to an output string. If the input string
* is too long to fit in the remainder of the output string, what has been
* added already (including part of the input string) is displayed and a new
* string is added. Format_TryShow handles this, including adding formatting
* of colour fades, which may involve fake rendering of more of the string to
* determine how much of the remainder of the string needs processing to get
* the right colour. This will also require a method of winding back the state
* to the point just after the initial input string was added to continue on to
* show the next string including newly determined fade data.
* </remarks>
* <transition keep="true" target="y_render_fade : y_render_fade_real" source="y_render_fade : y_render_fade_redo" />
*//*------------------------------------------------------------------------**/
static stock Format_DoAddString(out[], const in[], &oidx, const len, &orem, &fakepos) <y_render_fade : y_render_fade_fake>
{
#pragma unused out, in, oidx, orem
fakepos += len;
return 0;
}
static stock Format_DoAddString(out[], const in[], &oidx, const len, &orem, &fakepos) <y_render_fade : y_render_fade_redo>
{
new
temp = fakepos + len - YSI_g_sFadeRedoTarget;
if (temp > 0)
{
state y_render_fade : y_render_fade_real;
// This is where the string passes the target point of re-rendering.
new
other = YSI_g_sFadeRedoTarget - fakepos;
fakepos += other;
return Format_DoAddString(out, in[other], oidx, temp, orem, fakepos);
}
else
{
fakepos += len;
return 0;
}
}
static stock Format_DoAddString(out[], const in[], &oidx, const len, &orem, &fakepos) <y_render_fade : y_render_fade_real>
{
P:4("Format_DoAddString <y_render_fade : render_real> called: \"%s\", \"%s\", %i, %i, %i, %i", out, in, oidx, len, orem, fakepos);
// For now don't worry about fades over boundaries - they're just too hard
// to get the code working on to start with, maybe later once this is all
// working they can be added in. It is a shame though as it will mean fades
// don't always work. I can cheat slightly though and have the full fade on
// both halves of the break. Or just warn people about fades like that.
//
// NOTE: This code assumes that orem (output remaining) is always 1 less
// than the true value. This avoids awkward calculations when appending the
// NULL terminator to strings. When we run out of space it simply appends
// it regardless of wether it thinks there is space or not.
//
fakepos += len;
if (len <= orem)
{
P:5("Format_DoStringSCM: p0.");
memcpy(out[oidx], in, 0, len * 4, orem);
orem -= len;
oidx += len;
// The whole string fit in - return true.
return 0;
}
else
{
// Not the end of the string, but the end is required.
// Change state to ignore future inputs.
P:5("Format_DoStringSCM: p1.");
// Copy as much data as possible.
memcpy(out[oidx], in, 0, orem * 4, orem);
//orem -= orem;
//oidx += orem;
// Don't need to adjust this further down as all the characters will be
// added before the recursive call.
oidx += orem;
return len - orem;
}
}
/*-------------------------------------------------------------------------*//**
* <transition keep="true" target="y_render_fade : y_render_fade_real" source="y_render_fade : y_render_fade_redo" />
*//*------------------------------------------------------------------------**/
static stock bool:Format_DoAddChar(out[], const in, &oidx, &orem, &fakepos) <y_render_fade : y_render_fade_fake>
{
#pragma unused out, in, oidx, orem
++fakepos;
return true;
}
static stock bool:Format_DoAddChar(out[], const in, &oidx, &orem, &fakepos) <y_render_fade : y_render_fade_redo>
{
if (fakepos == YSI_g_sFadeRedoTarget)
{
state y_render_fade : y_render_fade_real;
// This should never actually fail...
if (!orem) return false;
--orem;
out[oidx++] = in;
}
++fakepos;
return true;
}
static stock bool:Format_DoAddChar(out[], const in, &oidx, &orem, &fakepos) <y_render_fade : y_render_fade_real>
{
P:4("Format_DoAddChar: %c %d %d", in, oidx, orem);
if (!orem) return false;
--orem;
out[oidx++] = in;
++fakepos;
return true;
}
static stock Format_DoDisplay(playerid, colour, out[]) <y_render_show : y_render_show_scm>
{
P:2("Format_DoDisplay a: %d, %06x, \"%s\"", playerid, colour >>> 8, out);
SendClientMessage(playerid, (colour << 8) | ((YSI_g_sTempStyle[E_STYLE_DATA_COLOUR] & 0x0F) * 0x11), out);
//idx = 0;
//out[0] = '\0';
}
static stock Format_DoDisplay(playerid, colour, out[]) <> //y_render_show : y_render_show_print>
{
P:0("Format_DoDisplay b: %d, %06x, \"%s\"", playerid, colour >>> 8, out);
//idx = 0;
//out[0] = '\0';
}
static stock Format_DoDisplay(playerid, colour, out[]) <y_render_show : y_render_show_gt>
{
#pragma unused colour
P:2("Format_DoDisplay c: %d, %06x, \"%s\"", playerid, colour >>> 8, out);
GameTextForPlayer(playerid, out, YSI_g_sTempStyle[E_STYLE_DATA_TIME], YSI_g_sTempStyle[E_STYLE_DATA_STYLE]);
//SendClientMessage(playerid, (colour << 8) | ((YSI_g_sTempStyle[E_STYLE_DATA_COLOUR] & 0x0F) * 0x11), out);
//GameTextForPlayer(playerid, out,
//SendClientMessage(playerid, colour, out);
//idx = 0;
//out[0] = '\0';
}
static stock Format_DoDisplay(playerid, colour, out[]) <y_render_show : y_render_show_td>
{
#pragma unused colour
P:2("Format_DoDisplay d: %d, %06x, \"%s\"", playerid, colour >>> 8, out);
new
Text:tmp = TD_Display(out, YSI_g_sTempStyle[E_STYLE_DATA_TD_ID]);
out[0] = _:tmp;
out[1] = '\0';
TD_ShowForPlayer(playerid, tmp);
TD_Garbage(tmp);
// Link these TDs together for future manipulations.
if (YSI_g_sBaseTD == TEXT_DRAW_NO_NEXT)
{
YSI_g_sBaseTD = tmp;
}
else
{
TD_Link(YSI_g_sBaseTD, tmp);
}
//SendClientMessage(playerid, (colour << 8) | ((YSI_g_sTempStyle[E_STYLE_DATA_COLOUR] & 0x0F) * 0x11), out);
//GameTextForPlayer(playerid, out,
//SendClientMessage(playerid, colour, out);
//idx = 0;
//out[0] = '\0';
}
/*-------------------------------------------------------------------------*//**
* <param name="playerid">Player to show the text to.</param>
* <param name="out">What the text to show is.</param>
*//*------------------------------------------------------------------------**/
stock Format_JustShow(playerid, out[]) <y_render_show : y_render_show_scm>
{
SendClientMessage(playerid, gInitialColour, out);
}
stock Format_JustShow(playerid, out[]) <y_render_show : y_render_show_print>
{
P:0("Format_DoDisplay: %d, \"%s\"", playerid, out);
}
stock Format_JustShow(playerid, out[]) <y_render_show : y_render_show_gt>
{
GameTextForPlayer(playerid, out, YSI_g_sTempStyle[E_STYLE_DATA_TIME], YSI_g_sTempStyle[E_STYLE_DATA_STYLE]);
}
stock Format_JustShow(playerid, out[]) <y_render_show : y_render_show_td>
{
TD_ShowForPlayer(playerid, Text:out[0]);
}
/*-------------------------------------------------------------------------*//**
* <returns>
* The basic ID linking all displayed elements together where appropriate (for
* example SendClientMessage has no meaningful ID. 3D texts would, but that's
* not implemented. So do game texts, but that's not implemented either, so
* really it's just text draws.
* </returns>
*//*------------------------------------------------------------------------**/
stock Text_GetLastID() <y_render_show : y_render_show_td>
{
return _:YSI_g_sBaseTD;
}
stock Text_GetLastID() <>
{
return -1;
}
/*-------------------------------------------------------------------------*//**
* Generic function to handle rendering for all types of outputs. Other functions
* such as Format_AddColour are specialised for different text styles. The faster
* way to do this would be to store the characters removed from a string when
* adding in fade data, but this is hard to code. The simpler method is to fake
* re-render the string, having previously determined the length of the string
* which will be faded across. Note that this may mean that some parts of the
* string can get rendered many times, but we can just issue a performance warning
* when the player uses fades which go over a line boundary. That is the only time
* in which it is a problem, more specifically it is only a problem when text in a
* fade goes over a line boundardy before the end fade marker has been reached.
* <transition keep="true" target="y_render_fade : y_render_fade_redo" />
* <transition keep="true" target="y_render_fade : y_render_fade_real" />
* <transition keep="true" target="y_render_fade : y_render_fade_fake" />
*//*------------------------------------------------------------------------**/
//stock Format_Render(pid, Language:l, output[], maxlen, idx, target, string[], {Float,_}:...)
stock Format_Render(pid, Language:l, output[], maxlen, idx, target, string[], argCount, GLOBAL_TAG_TYPES:...)
{
P:3("Format_Render called: %i, %i, %s, %i, %i, %i, %s (+%i)", pid, _:l, output, maxlen, idx, target, argCount, numargs() - 8);
gInitialColour = (YSI_g_sTempStyle[E_STYLE_DATA_COLOUR] >>> 4) & 0x00FFFFFF;
new
colour = gInitialColour;
YSI_g_sFadeLength = 0;
YSI_g_sBaseTD = TEXT_DRAW_NO_NEXT;
// Now the (mostly) tail-recursive function call.
Format_Render_start:
static
scFormats[][8] =
{
"%*.*d", // 6 (6)
"%-*.*d", // 7 (13)
"%0*.*d", // 7 (20)
"%0-*.*d" // 8 (28)
},
scSpecifier[8],
// =====================================================================
// UPDATE Y_RENDER_FIX_NEGATIVE MACRO ON CHANGE!!!!!!!
ts[130],
// Max handleable input string length is 128 (hopefully sufficient).
// =====================================================================
func[32],
scNewLineString[] = "~n~",
scDialogLineString[] = "\r\n";
new
ch,
llen = maxlen,
//output[128], // Always 128.
p = 0,
curArg = 8, // Account for additionaly pushed arguments.
numArgs = numargs() + argCount,
//llen = sizeof (output) - 1,
arg,
none = (target & e_FORMAT_FLAGS_NONE),
onlyOne = (target & e_FORMAT_FLAGS_ONE) | none | _:YSI_g_sJustOne,
bool:fade = false,
bool:nlInFade = false,
// flags:
// 1 = Just one output.
// 2 = Newline found in fade.
// 4 = In a fade.
//flags = (target & e_FORMAT_FLAGS_ONE) ? 1 : 0,
fakePos = 0,
// Was only "one" string display used and is this not per-player text?
one = 0,
// Start location of the current fade.
fadeStart,
fadeStartIdx;//,
//fadeStartText;
//#emit LOAD.S.pri string
//#emit STOR.S.pri fadeStartText
if (target & e_FORMAT_FLAGS_REDO)
{
// We need to skip data, ignore everything before "target1".
state y_render_fade : y_render_fade_redo;
}
else
{
state y_render_fade : y_render_fade_real;
}
target &= e_FORMAT_FLAGS_INDEX;
/*new
fadeCurArg,
fadeArg,
fadeIdx;*/
if ((YSI_g_sFadeRedoTarget = target))
{
YSI_g_sFadeRedoTarget &= ~Y_FORMAT_ALWAYS_SET;
state y_render_fade : y_render_fade_redo;
}
else
{
state y_render_fade : y_render_fade_real;
}
/*ch = string[idx];
if (ch > 0)
{
// Copy strings.
++idx;
Y_RENDER_ADD_EX(string, idx, ch - idx)
idx = ch;
}*/
while ((ch = string[idx++]))
{
// TODO: Add {*} and #* format for variable colours.
switch (ch)
{
case '\01':
{
// Null.
break;
}
case '\02':
{
P:6("Text_Render: Format specifier %d", curArg);
if (curArg == numArgs)
{
// Skip.
P:W("Insufficient parameters to YSI format.");
ts = "(null)";
Y_RENDER_ADD(ts)
continue;
}
// Format.
ch = string[idx++];
new
width = (ch & _:e_COMPRESS_FORMAT_DATA_WIDTH),
prec = (ch & _:e_COMPRESS_FORMAT_DATA_PREC) >>> 12;
// Get the true values of the various data bits.
if (width == 0x0800)
{
width = getarg(curArg++);
}
if (prec == 0x0800)
{
prec = getarg(curArg++);
}
else if (prec == 0x0FFF)
{
prec = -1;
}
// Output the correct data type.
switch (ch & 0xF0000000)
{
case e_COMPRESS_FORMAT_DATA_DEC:
{
P:6("Text_Render: Add d");
scSpecifier = Y_RENDER_SPECIFIER(d);
Y_RENDER_ARG
{
//p += Format_AddInt(output[p], llen, arg, width, ch);
format(ts, sizeof (ts), scSpecifier, width, prec, arg);
Y_RENDER_ADD(ts)
}
}
case e_COMPRESS_FORMAT_DATA_HEX:
{
// This completely fixes (I hope) the problems with
// displaying negative numbers as %h/%x numbers.
P:6("Text_Render: Add h");
scSpecifier = Y_RENDER_SPECIFIER(x);
Y_RENDER_ARG
{
if (arg & 0x80000000)
{
Y_RENDER_FIX_NEGATIVE(x:8);
}
else
{
format(ts, sizeof (ts), scSpecifier, width, prec, arg);
}
Y_RENDER_ADD(ts)
}
}
case e_COMPRESS_FORMAT_DATA_BIN:
{
P:6("Text_Render: Add b");
scSpecifier = Y_RENDER_SPECIFIER(b);
Y_RENDER_ARG
{
if (arg & 0x80000000)
{
Y_RENDER_FIX_NEGATIVE(b:32);
}
else
{
format(ts, sizeof (ts), scSpecifier, width, prec, arg);
}
Y_RENDER_ADD(ts)
}
}
case e_COMPRESS_FORMAT_DATA_CHAR:
{
scSpecifier = Y_RENDER_SPECIFIER(c);
Y_RENDER_ARG
{
//p += Format_AddInt(output[p], llen, arg, width, ch);
format(ts, sizeof (ts), scSpecifier, width, prec, arg);
Y_RENDER_ADD(ts)
}
}
case e_COMPRESS_FORMAT_DATA_FLOAT:
{
scSpecifier = Y_RENDER_SPECIFIER(f);
Y_RENDER_ARG
{
//p += Format_AddInt(output[p], llen, arg, width, ch);
format(ts, sizeof (ts), scSpecifier, width, prec, arg);
Y_RENDER_ADD(ts)
}
}
case e_COMPRESS_FORMAT_DATA_IEEE:
{
Y_RENDER_ARG
{
if ((arg & 0x7F800000) == 0x7F800000)
{
scSpecifier = Y_RENDER_SPECIFIER(s);
// One of the special numbers.
if (arg & 0x007FFFFF)