forked from aburch/simutrans
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimgraph.c
1721 lines (1346 loc) · 34.1 KB
/
simgraph.c
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
/*
* Copyright (c) 2001 Hansjörg Malthaner
*
* This file is part of the Simugraph engine and may not be used
* in other projects without written permission of the author.
*
* Usage for Iso-Angband is granted.
*/
/* simgraph.c
*
* Versuch einer Graphic fuer Simulationsspiele
* Hj. Malthaner, Aug. 1997
*
*
* 3D, isometrische Darstellung
*
*
*
* 18.11.97 lineare Speicherung fuer Images -> hoehere Performance
* 22.03.00 run längen Speicherung fuer Images -> hoehere Performance
* 15.08.00 dirty tile verwaltung fuer effizientere updates
*/
//#define DEBUG 1
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include "simgraph.h"
#include "simsys.h"
#include "simmem.h"
#include "simdebug.h"
#include "utils/writepcx.h"
#ifdef _MSC_VER
#include <io.h>
#else
#include <unistd.h>
#endif
// since 0.80.pre1 Simutrans can read all config files
// from a directory:
// this is set from simgraph_init()
static const char * configdir = 0;
// do we need a mouse pointer emulation ?
// assume yes by default, but the system wrapper
// is inquired during initialisation
static int use_softpointer = 1;
static int softpointer = 261;
static int old_my = -1; // die icon leiste muss neu gezeichnet werden wenn der
// Mauszeiger darueber schwebt
static unsigned char dr_fonttab[2048]; /* Unser Zeichensatz sitzt hier */
static unsigned char npr_fonttab[3072]; // Niels: npr are my initials
static unsigned char dr_4x7font[7*256];
/*
* pixel value type, colormap index
*/
typedef unsigned char PIXVAL;
struct imd {
signed char x;
signed char w;
signed char y;
signed char h;
int len;
PIXVAL * data;
};
static int anz_images = 0;
static int disp_width = 640;
static int disp_height = 480;
static struct imd *images = NULL;
static PIXVAL *textur = NULL;
static struct clip_dimension clip_rect;
// dirty tile management strcutures
#define DIRTY_TILE_SIZE 16
#define DIRTY_TILE_SHIFT 4
static char *tile_dirty = NULL;
static char *tile_dirty_old = NULL;
static int tiles_per_line = 0;
static int tile_lines = 0;
// colormap management structures
static unsigned char day_pal[256*3];
static unsigned char night_pal[256*3];
static unsigned char base_pal[256*3];
static int light_level = 0;
static int color_level = 1;
// tile raster width
static int tile_raster_width = 64;
int get_tile_raster_width()
{
return tile_raster_width;
}
void set_tile_raster_width(int rw)
{
tile_raster_width = rw
}
// ------------ procedure like defines --------------------
#define mark_tile_dirty(x,y) tile_dirty[(x) + (y)*tiles_per_line] = 1
#define mark_tiles_dirty(x1, x2, y) {const int line = (y) * tiles_per_line; int x; for(x=(x1); x<=(x2); x++) { tile_dirty[x + line] = 1; } };
#define is_tile_dirty(x,y) ((tile_dirty[(x) + (y)*tiles_per_line]) || (tile_dirty_old[(x) + (y)*tiles_per_line]))
// ----------------- procedures ---------------------------
/**
* Markiert ein Tile as schmutzig, ohne Clipping
* @author Hj. Malthaner
*/
static void mark_rect_dirty_nc(int x1, int y1, int x2, int y2)
{
int y;
// floor to tile size
x1 >>= DIRTY_TILE_SHIFT;
y1 >>= DIRTY_TILE_SHIFT;
x2 >>= DIRTY_TILE_SHIFT;
y2 >>= DIRTY_TILE_SHIFT;
assert(x1 >= 0);
assert(x1 < tiles_per_line);
assert(y1 >= 0);
assert(y1 < tile_lines);
assert(x2 >= 0);
assert(x2 < tiles_per_line);
assert(y2 >= 0);
assert(y2 < tile_lines);
for(y=y1; y<=y2; y++) {
mark_tiles_dirty(x1, x2, y);
}
}
/**
* Markiert ein Tile as schmutzig, mit Clipping
* @author Hj. Malthaner
*/
void mark_rect_dirty_wc(int x1, int y1, int x2, int y2)
{
if(x1 < 0) x1 = 0;
if(y1 < 0) y1 = 0;
if(x2 < 0) x2 = 0;
if(y2 < 0) y2 = 0;
if(x1 >= disp_width) {
x2 = x1 = disp_width-1;
} else if(x2 >= disp_width) {
x2 = disp_width-1;
}
if(y1 >= disp_height) {
y2 = y1 = disp_height-1;
} else if(y2 >= disp_height) {
y2 = disp_height-1;
}
mark_rect_dirty_nc(x1, y1, x2, y2);
}
/**
* Clipped einen Wert in Intervall
* @author Hj. Malthaner
*/
static int clip(int w, int u, int o)
{
return w < u ? u : w > o ? o : w;
}
/**
* Laedt den Font
* @author Hj. Malthaner
*/
static void init_font()
{
FILE *f = NULL;
// suche in ./draw.fnt
if(f==NULL ) {
f=fopen("./draw.fnt","rb");
}
if(f==NULL) {
printf("Error: Cannot open draw.fnt!\n");
exit(1);
} else {
int i;
for(i=0;i<2048;i++) dr_fonttab[i]=getc(f);
fclose(f);
}
// also, read font.dat
{
int i,r;
f = fopen("prop.fnt","rb");
if (f==NULL) {
printf("Error: Cannot open prop.fnt!\n");
exit(1);
}
for (i=0;i<3072;i++) {
npr_fonttab[i] = r = getc(f);
}
if (r==EOF) {
printf("Error: prop.fnt too short\n");
exit(1);
}
if (getc(f)!=EOF) {
printf("Error: prop.fnt too long\n");
exit(1);
}
fclose(f);
}
}
/**
* Laedt die Palette
* @author Hj. Malthaner
*/
static int
load_palette(const char *filename, unsigned char *palette)
{
char fname[256];
FILE *file;
strcpy(fname, configdir);
strcat(fname, filename);
file = fopen(fname,"rb");
if(file) {
int x;
int anzahl=256;
int r,g,b;
fscanf(file, "%d", &anzahl);
for(x=0; x<anzahl; x++) {
fscanf(file,"%d %d %d", &r, &g, &b);
palette[x*3+0] = r;
palette[x*3+1] = g;
palette[x*3+2] = b;
}
dr_setRGB8multi(0, anzahl, palette);
fclose(file);
} else {
fprintf(stderr, "Error: can't open file '%s' for reading\n", fname);
}
return file != NULL;
}
static int nibble(char c)
{
if(c > '9') {
return 10 + (c - 'A');
} else {
return c - '0';
}
}
static void load_4x7_font()
{
FILE *file = fopen("4x7.hex", "rb");
int fh = 7;
if(file) {
char buf [80];
int n, line;
char *p;
while(fgets(buf, 79, file) != NULL) {
sscanf(buf, "%4x", &n);
p = buf+5;
for(line=0; line<fh; line ++) {
int val = nibble(p[0])*16 + nibble(p[1]);
dr_4x7font[n*fh + line] = val;
p += 2;
// printf("%02X", val);
}
// printf("\n");
}
} else {
fprintf(stderr, "Error: can't open file '%s' for reading\n", "4x7.hex");
}
}
int display_get_width()
{
return disp_width;
}
int display_get_height()
{
return disp_height;
}
/**
* Holt Helligkeitseinstellungen
* @author Hj. Malthaner
*/
int display_get_light()
{
return light_level;
}
/**
* Setzt Helligkeitseinstellungen
* @author Hj. Malthaner
*/
void display_set_light(int new_light_level)
{
unsigned char palette[256*3];
const double ll = 1.0 - light_level/20.0;
int i;
light_level = new_light_level;
for(i=0; i<256; i++) {
const int n = i*3;
palette[n+0] = clip((int)(pow(base_pal[n+0]/255.0, ll)*255.0), 0, 255);
palette[n+1] = clip((int)(pow(base_pal[n+1]/255.0, ll)*255.0), 0, 255);
palette[n+2] = clip((int)(pow(base_pal[n+2]/255.0, ll)*255.0), 0, 255);
}
dr_setRGB8multi(0, 256, palette);
}
/**
* Holt Farbeinstellungen
* @author Hj. Malthaner
*/
int display_get_color()
{
return color_level;
}
/**
* Setzt Farbeinstellungen
* @author Hj. Malthaner
*/
void display_set_color(int new_color_level)
{
color_level = new_color_level;
if(color_level < 0) {
color_level = 0;
}
if(color_level > 3) {
color_level = 3;
}
switch(color_level) {
case 0:
load_palette("simud70.pal", day_pal);
load_palette("simun70.pal", night_pal);
break;
case 1:
load_palette("simud80.pal", day_pal);
load_palette("simun80.pal", night_pal);
break;
case 2:
load_palette("simud90.pal", day_pal);
load_palette("simun90.pal", night_pal);
break;
case 3:
load_palette("simud100.pal", day_pal);
load_palette("simun100.pal", night_pal);
break;
}
memcpy(base_pal, day_pal, 256*3);
display_set_light(display_get_light());
}
static int night_shift = -1;
static void calc_base_pal_from_night_shift(const int night)
{
const int day = 4 - night;
int i;
for(i=0; i<256; i++) {
base_pal[i*3+0] = (day_pal[i*3+0] * day + night_pal[i*3+0] * night) >> 2;
base_pal[i*3+1] = (day_pal[i*3+1] * day + night_pal[i*3+1] * night) >> 2;
base_pal[i*3+2] = (day_pal[i*3+2] * day + night_pal[i*3+2] * night) >> 2;
}
}
void display_day_night_shift(int night)
{
if(night != night_shift) {
night_shift = night;
calc_base_pal_from_night_shift(night);
display_set_light(light_level);
mark_rect_dirty_nc(0,0, disp_width-1, disp_height-1);
}
}
/**
* Setzt Farbeintrag
* @author Hj. Malthaner
*/
void display_set_player_colors(const unsigned char *day, const unsigned char *night)
{
memcpy(day_pal, day, 12);
memcpy(night_pal, night, 12);
calc_base_pal_from_night_shift(night_shift);
display_set_light(light_level);
mark_rect_dirty_nc(0,0, disp_width-1, disp_height-1);
}
/**
* Liest 32Bit wert Plattfromunabhängig
* @author Hj. Malthaner
*/
static int fread_int(FILE *f)
{
int i = 0;
i += fgetc(f);
i += fgetc(f) << 8;
i += fgetc(f) << 16;
i += fgetc(f) << 24;
return i;
}
/**
* Laedt daten.pak
* @author Hj. Malthaner
*/
static void init_images(const char *filename)
{
FILE *f = fopen(filename, "rb");
if( f ) {
int i;
anz_images = fread_int(f);
// aligned on 8 byte doesn't hurt as it seems?!
images = (struct imd *) guarded_malloc(sizeof(struct imd)*anz_images);
for(i=0; i<anz_images; i++) {
images[i].x = fgetc(f);
images[i].w = fgetc(f);
images[i].y = fgetc(f);
images[i].h = fgetc(f);
images[i].len = fread_int(f);
if(images[i].h > 0) {
images[i].data = malloc(images[i].len*sizeof(PIXVAL));
fread(images[i].data, images[i].len*sizeof(PIXVAL), 1, f);
} else {
images[i].data = NULL;
}
}
fclose(f);
} else {
printf("Error: can't read daten pak file '%s', aborting.\n",
filename);
exit(1);
}
}
/**
* Holt Maus X-Position
* @author Hj. Malthaner
*/
int gib_maus_x()
{
return sys_event.mx;
}
/**
* Holt Maus y-Position
* @author Hj. Malthaner
*/
int gib_maus_y()
{
return sys_event.my;
}
/**
* this sets width < 0 if the range is out of bounds
* so check the value after calling and before displaying
* @author Hj. Malthaner
*/
static int clip_wh(int *x, int *width, const int min_width, const int max_width)
{
// doesnt check "wider than image" case
if(*x < min_width) {
const int xoff = min_width - (*x);
*width += *x-min_width;
*x = min_width;
if(*x + *width >= max_width) {
*width = max_width - *x;
}
return xoff;
} else if(*x + *width >= max_width) {
*width = max_width - *x;
}
return 0;
}
/**
* places x and w within bounds left and right
* if nothing to show, returns FALSE
* @author Niels Roest
**/
static int clip_lr(int *x, int *w, int left, int right)
{
int l = *x; // leftmost pixel
int r = *x+*w-1; // rightmost pixel
if (l > right) { *w = 0; return FALSE; }
if (r < left) { *w = 0; return FALSE; }
// there is something to show.
if (l < left) { *w -= left - l; *x = l = left; }
if (r > right) { *w -= r - right; /* r = right */ }
return TRUE;
}
/**
* Ermittelt Clipping Rechteck
* @author Hj. Malthaner
*/
struct clip_dimension display_gib_clip_wh(void)
{
return clip_rect;
}
/**
* Setzt Clipping Rechteck
* @author Hj. Malthaner
*/
void display_setze_clip_wh(int x, int y, int w, int h)
{
clip_wh(&x, &w, 0, disp_width);
clip_wh(&y, &h, 0, disp_height);
clip_rect.x = x;
clip_rect.y = y;
clip_rect.w = w;
clip_rect.h = h;
clip_rect.xx = x+w-1;
clip_rect.yy = y+h-1;
}
// ----------------- basic painting procedures ----------------
/**
* Kopiert Pixel von src nach dest
* @author Hj. Malthaner
*/
#ifdef USE_C
static void pixcopy(PIXVAL *dest,
const PIXVAL *src,
int len)
{
*dest;
switch(len & 3) {
case 3: *dest++ = *src++;
case 2: *((short *)dest)++ = *((short *)src)++;
break;
case 1: *dest++ = *src++;
}
len >>= 2;
while(len) {
len --;
*((long*)dest)++ = *((long*)src)++;
}
}
/**
* Kopiert Pixel, ersetzt Spielerfarben
* @author Hj. Malthaner
*/
static void colorpixcpy(PIXVAL *dest, const PIXVAL *src,
const PIXVAL * const end,
const PIXVAL color)
{
unsigned char c;
while(src < end) {
c = *src++;
*dest++ = (c > (unsigned char)3) ? c : c | color;
}
}
#else
extern void pixcopy(unsigned char *dest,
const unsigned char *src,
int len);
extern void colorpixcpy(unsigned char *dest, const unsigned char *src,
const unsigned char * const end, const unsigned char color);
extern void
decode_img(unsigned char *tp, const unsigned char *sp,
int h, const int disp_width);
#endif
/**
* Zeichnet Bild mit Clipping
* @author Hj. Malthaner
*/
static void
display_img_wc(const int n, const int xp, const int yp)
{
if(n >= 0 && n < anz_images) {
int h = images[n].h;
int y = yp + images[n].y;
int yoff = clip_wh(&y, &h, clip_rect.y, clip_rect.yy);
if(h > 0) {
const PIXVAL *sp = images[n].data;
PIXVAL *tp = textur + y*disp_width;
// oben clippen
while(yoff) {
yoff --;
do {
if(*(++sp)) {
sp += *sp + 1;
}
} while(*sp);
sp ++;
}
do { // zeilen dekodieren
int xpos = xp;
// bild darstellen
int runlen = *sp++;
do {
// wir starten mit einem clear run
xpos += runlen;
// jetzt kommen farbige pixel
runlen = *sp++;
if(runlen) {
if(xpos >= clip_rect.x && runlen+xpos <= clip_rect.xx) {
pixcopy(tp+xpos, sp, runlen);
} else if(xpos < clip_rect.x) {
if(runlen+xpos >= clip_rect.x) {
pixcopy(tp+clip_rect.x, sp+(clip_rect.x-xpos), runlen-(clip_rect.x-xpos));
}
} else if(clip_rect.xx >= xpos) {
pixcopy(tp+xpos, sp, clip_rect.xx-xpos+1);
}
sp += runlen;
xpos += runlen;
runlen = *sp ++;
}
} while(runlen);
tp += disp_width;
} while(--h);
}
}
}
/**
* Zeichnet Bild ohne Clipping
* @author Hj. Malthaner
*/
static void
display_img_nc(const int n, const int xp, const int yp)
{
if(n >= 0 && n < anz_images) {
signed char h = images[n].h;
if(h > 0) {
const PIXVAL *sp = images[n].data;
PIXVAL *tp = textur + xp + (yp + images[n].y)*disp_width;
#ifdef USE_C
// bild darstellen
do { // zeilen dekodieren
unsigned char runlen = *sp++;
// eine Zeile dekodieren
do {
// wir starten mit einem clear run
tp += runlen;
// jetzt kommen farbige pixel
runlen = *sp++;
if(runlen) {
pixcopy(tp, sp, runlen);
sp += runlen;
tp += runlen;
runlen = *sp++;
}
} while(runlen);
tp += (disp_width-tile_raster_width);
} while(--h);
#else
decode_img(tp, sp, h, disp_width);
#endif
}
}
}
/**
* Zeichnet Bild
* @author Hj. Malthaner
*/
void
display_img(const int n, const int xp, const int yp, const int dirty)
{
if(dirty && n>=0 && n<anz_images) {
mark_rect_dirty_wc(xp+images[n].x,
yp+images[n].y,
xp+images[n].x+images[n].w-1,
yp+images[n].y+images[n].h-1);
}
if(xp>=clip_rect.x &&
yp>=clip_rect.y &&
xp < clip_rect.xx-tile_raster_width &&
yp < clip_rect.yy-tile_raster_width) {
display_img_nc(n, xp, yp);
} else if(xp>clip_rect.x-tile_raster_width &&
yp>clip_rect.y-tile_raster_width &&
xp < clip_rect.xx &&
yp < clip_rect.yy) {
display_img_wc(n, xp, yp);
}
}
/**
* Zeichnet Bild, ersetzt Spielerfarben
* @author Hj. Malthaner
*/
static void
display_color_img_aux(const int n, const int xp, const int yp, const int color)
{
if(n >= 0 && n < anz_images) {
int h = images[n].h;
int y = yp + images[n].y;
int yoff = clip_wh(&y, &h, clip_rect.y, clip_rect.yy);
if(h > 0) {
const PIXVAL *sp = images[n].data;
PIXVAL *tp = textur + y*disp_width;
// oben clippen
while(yoff) {
yoff --;
do {
if(*(++sp)) {
sp += *sp + 1;
}
} while(*sp);
sp ++;
}
do { // zeilen dekodieren
int xpos = xp;
// bild darstellen
do {
// wir starten mit einem clear run
xpos += *sp ++;
// jetzt kommen farbige pixel
if(*sp) {
const int runlen = *sp++;
if(xpos >= clip_rect.x && runlen+xpos <= clip_rect.xx) {
colorpixcpy(tp+xpos, sp, sp+runlen, (unsigned char)color);
} else if(xpos < clip_rect.x) {
if(runlen+xpos >= clip_rect.x) {
colorpixcpy(tp+clip_rect.x, sp+(clip_rect.x-xpos), sp+runlen, (unsigned char)color);
}
} else if(clip_rect.xx >= xpos) {
colorpixcpy(tp+xpos, sp, sp+clip_rect.xx-xpos+1, (unsigned char)color);
}
sp += runlen;
xpos += runlen;
}
} while(*sp);
tp += disp_width;
sp ++;
} while(--h);
}
}
}
/**
* Zeichnet Bild, ersetzt Spielerfarben
* @author Hj. Malthaner
*/
void
display_color_img(const int n, const int xp, const int yp, const int color, const int dirty)
{
if(dirty && n>=0 && n<anz_images) {
mark_rect_dirty_wc(xp+images[n].x-8,
yp+images[n].y-4,
xp+images[n].x+images[n].w+8-1,
yp+images[n].y+images[n].h+4-1);
}
// since the colors for player 0 are already right,
// only use the expensive replacement routine for colored images
// of other players
if(color) {
display_color_img_aux(n, xp, yp, color);
} else {
display_img_wc(n, xp, yp);
}
}
/**
* Zeichnet ein Pixel
* @author Hj. Malthaner
*/
void
display_pixel(int x, int y, const int color)
{
if(x >= clip_rect.x && x<=clip_rect.xx &&
y >= clip_rect.y && y<=clip_rect.yy) {
PIXVAL * const p = textur + x + y*disp_width;
*p = color;
mark_tile_dirty(x >> DIRTY_TILE_SHIFT, y >> DIRTY_TILE_SHIFT);
}
}
/**
* Zeichnet einen Text, lowlevel Funktion
* @author Hj. Malthaner
*/
static void
dr_textur_text(PIXVAL *textur,
const unsigned char *fontdata,
int fw, int fh,
int x,int y,
const char *txt,
const int chars,
const int fgpen,
const int dirty)
{
if(y >= clip_rect.y && y+fh <= clip_rect.yy) {
int screen_pos = y*disp_width + x;
int p;
if(dirty) {
mark_rect_dirty_wc(x, y, x+chars*fw-1, y+fh-1);
}
for(p=0; p<chars; p++) { /* Zeichen fuer Zeichen ausgeben */
int base=((unsigned char *)txt)[p] * fh; /* 8 Byte je Zeichen */
const int end = base+fh;
do {
const int c=fontdata[base++]; /* Eine Zeile des Zeichens */
int b;
for(b=0; b<fw; b++) {