forked from dethrace-labs/dethrace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphics.c
3099 lines (2871 loc) · 109 KB
/
graphics.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
#include "graphics.h"
#include "brender/brender.h"
#include "car.h"
#include "constants.h"
#include "controls.h"
#include "depth.h"
#include "displays.h"
#include "errors.h"
#include "finteray.h"
#include "flicplay.h"
#include "globvars.h"
#include "globvrpb.h"
#include "grafdata.h"
#include "harness/os.h"
#include "harness/trace.h"
#include "init.h"
#include "input.h"
#include "loading.h"
#include "netgame.h"
#include "network.h"
#include "oil.h"
#include "opponent.h"
#include "pd/sys.h"
#include "pedestrn.h"
#include "piping.h"
#include "powerup.h"
#include "pratcam.h"
#include "replay.h"
#include "sound.h"
#include "spark.h"
#include "trig.h"
#include "utility.h"
#include "world.h"
#include <limits.h>
#include <stdlib.h>
#include <math.h>
int gPalette_munged;
int gColourValues[1];
int gNext_transient;
int gCursor_x_offsets[8] = {
6,
8,
16,
36,
6,
8,
16,
36,
};
int gCursor_y_offsets[8] = {
26,
19,
12,
5,
26,
19,
12,
5,
};
int gCursor_gib_x_offsets[8] = {
82,
72,
66,
36,
82,
72,
66,
36,
};
int gCursor_gib_y_offsets[8] = {
74,
86,
93,
106,
74,
86,
93,
106,
};
int gCursor_giblet_sequence0[7] = {
6,
0,
1,
2,
3,
4,
5,
};
int gCursor_giblet_sequence1[5] = {
4,
6,
7,
8,
9,
};
int gCursor_giblet_sequence2[5] = {
4,
10,
11,
12,
13,
};
int gCursor_giblet_sequence3[5] = {
4,
14,
15,
16,
17,
};
int* gCursor_giblet_sequences[4] = {
gCursor_giblet_sequence0,
gCursor_giblet_sequence1,
gCursor_giblet_sequence2,
gCursor_giblet_sequence3,
};
char* gFont_names[21] = {
"TYPEABLE",
"ORANGHED",
"BLUEHEAD",
"GREENHED",
"MEDIUMHD",
"TIMER",
"NEWHITE",
"NEWRED",
"NEWBIGGR",
"GRNDK",
"GRNLIT",
"GRYDK",
"GRYLIT",
"BUTTIN",
"BUTTOUT",
"LITPLAQ",
"DRKPLAQ",
"BUTTIN1",
"BUTTOUT1",
"LITPLAQ1",
"DRKPLAQ1"
};
br_colour gRGB_colours[9] = {
0u,
16777215u,
16711680u,
65280u,
255u,
16776960u,
65535u,
16711935u,
13649666u
};
br_matrix34 gSheer_mat = {
{ { 1.0, 0.0, 0.0 },
{ 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 1.0 },
{ 0.0, 0.0, 0.0 } }
};
br_matrix34 gIdentity34 = {
{ { 1.0, 0.0, 0.0 },
{ 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 1.0 },
{ 0.0, 0.0, 0.0 } }
};
tShadow_level gShadow_level = eShadow_us_only;
br_scalar gShadow_hither_z_move;
br_scalar gShadow_hither_min_move;
/* clang-format off */
// arrows pointing to 180, 202, 224, 246 degrees (step = 90 / 4 = 22(.5) degrees)
int gArrows[2][4][60] =
{
{
// inner arrow (=fill)
{ 10, 0, 0, -1, 0, 1, 0, 0, -1, 0, -2, 0, 1, -1, 1, 1, 1, -2, 2, 2, 2, },
{ 11, 0, 0, -1, 0, 1, 0, 0, -1, 1, -1, 1, -2, -2, 1, -1, 1, 0, 1, 1, 1, 1, 2, },
{ 9, 0, 0, -2, 0, -1, 0, 1, 0, 0, -1, 1, -1, 2, -2, 0, 1, 0, 2, },
{ 11, 0, 0, -1, 0, 1, 0, -2, -1, -1, -1, 0, -1, 1, -1, 2, -1, -1, 1, 0, 1, -1, 2, },
},
{
// outer arrow (=border)
{ 26, 1, -3, 1, -2, 1, -1, 2, -1, 2, 0, 2, 1, 3, 1, 3, 2, 3, 3, 2, 3, 1, 3, 1, 2, 0, 2, -1, 2,
-1, 3, -2, 3, -3, 3, -3, 2, -3, 1, -2, 1, -2, 0, -2, -1, -1, -1, -1, -2, -1, -3, 0, -3, },
{ 22, 0, -3, 1, -3, 2, -3, 2, -2, 2, -1, 2, 0, 2, 1, 2, 2, 2, 3, 1, 3, 0, 3, 0, 2, -1, 2, -2, 2,
-3, 2, -3, 1, -3, 0, -2, 0, -2, -1, -1, -1, -1, -2, 0, -2, },
{ 24, 1, -3, 2, -3, 3, -3, 3, -2, 3, -1, 2, -1, 2, 0, 2, 1, 1, 1, 1, 2, 1, 3, 0, 3, -1, 3, -1, 2,
-1, 1, -2, 1, -3, 1, -3, 0, -3, -1, -2, -1, -1, -1, -1, -2, 0, -2, 1, -2, },
{ 22, -3, -2, -2, -2, -1, -2, 0, -2, 1, -2, 2, -2, 3, -2, 3, -1, 3, 0, 2, 0, 2, 1, 1, 1, 1, 2, 0, 2,
0, 3, -1, 3, -2, 3, -2, 2, -2, 1, -2, 0, -3, 0, -3, -1, },
},
};
/* clang-format on */
float gMap_render_x = 80.f;
float gMap_render_y = 6.f;
float gMap_render_width = 64.f;
float gMap_render_height = 40.f;
int gMouse_started;
int gFaded_palette;
int gAR_fudge_headups;
br_pixelmap* gCurrent_splash;
br_pixelmap* gCurrent_conversion_table;
int gMap_colours[4] = { 4, 0, 52, 132 };
br_vector3 gShadow_points[8];
tConcussion gConcussion;
tClip_details gShadow_clip_planes[8];
br_actor* gLollipops[100];
tWobble_spec gWobble_array[5];
tSaved_table gSaved_shade_tables[100];
tCursor_giblet gCursor_giblets[45];
tTransient_bm gTransient_bitmaps[50];
float gCosine_array[64];
br_pixelmap* gCursors[8];
br_pixelmap* gCursor_giblet_images[18];
br_pixelmap* gEval_1;
br_pixelmap* gEval_2;
br_vector3 gShadow_light_z;
br_vector3 gShadow_light_x;
int gShadow_dim_amount;
int gNumber_of_lollipops;
br_vector3 gShadow_light_ray;
int gFancy_shadow;
br_model* gShadow_model;
br_actor* gShadow_actor;
int gShadow_clip_plane_count;
br_pixelmap* gPalette_conversion_table;
br_material* gShadow_material;
int gSaved_table_count;
int gCurrent_cursor_index;
int gPalette_index;
int gCursor_transient_index;
char* gScratch_pixels;
br_pixelmap* gScratch_palette;
int gLast_palette_change;
br_pixelmap* gOrig_render_palette;
br_pixelmap* gCurrent_palette;
br_pixelmap* gRender_palette;
float gCamera_to_horiz_angle;
int gColours[9];
br_pixelmap* gFlic_palette;
tDR_font gFonts[21];
char* gCurrent_palette_pixels;
int gWidth;
int gMap_render_height_i;
int gScreen_wobble_x;
int gScreen_wobble_y;
br_scalar gCurrent_ambience;
int gY_offset;
int gMap_render_width_i;
int gMouse_in_use;
int gHeight;
int gMouse_last_y_coord;
int gMouse_last_x_coord;
br_scalar gAmbient_adjustment;
int gMap_render_x_i;
int gX_offset;
int gMap_render_y_i;
int gMirror_on__graphics; // suffix added to avoid duplicate symbol
br_scalar gYon_squared;
#define SHADOW_D_IGNORE_FLAG 10000.0
// IDA: void __cdecl TurnOnPaletteConversion()
void TurnOnPaletteConversion() {
LOG_TRACE("()");
gCurrent_conversion_table = gPalette_conversion_table;
}
// IDA: void __cdecl TurnOffPaletteConversion()
void TurnOffPaletteConversion() {
LOG_TRACE("()");
gCurrent_conversion_table = NULL;
}
// IDA: void __cdecl ResetLollipopQueue()
void ResetLollipopQueue() {
LOG_TRACE("()");
gNumber_of_lollipops = 0;
}
// IDA: int __usercall AddToLollipopQueue@<EAX>(br_actor *pActor@<EAX>, int pIndex@<EDX>)
int AddToLollipopQueue(br_actor* pActor, int pIndex) {
LOG_TRACE("(%p, %d)", pActor, pIndex);
if (pIndex >= 0) {
gLollipops[pIndex] = pActor;
} else if (gNumber_of_lollipops >= 100) {
pIndex = -1;
} else {
gLollipops[gNumber_of_lollipops] = pActor;
pIndex = gNumber_of_lollipops;
gNumber_of_lollipops++;
}
return pIndex;
}
// IDA: void __cdecl RenderLollipops()
void RenderLollipops() {
int i;
int must_relink;
br_actor** the_actor;
br_actor* old_parent;
LOG_TRACE("()");
for (i = 0, the_actor = gLollipops; i < gNumber_of_lollipops; i++, the_actor++) {
if ((*the_actor)->render_style == BR_RSTYLE_NONE) {
must_relink = (*the_actor)->parent != gDont_render_actor;
if (must_relink) {
old_parent = (*the_actor)->parent;
BrActorRelink(gDont_render_actor, *the_actor);
}
(*the_actor)->render_style = BR_RSTYLE_FACES;
SetPedMaterialForRender(*the_actor);
BrZbSceneRenderAdd(*the_actor);
(*the_actor)->render_style = BR_RSTYLE_NONE;
if (must_relink) {
BrActorRelink(old_parent, *the_actor);
}
}
}
}
// IDA: void __usercall DRDrawLine(br_pixelmap *pDestn@<EAX>, int pX1@<EDX>, int pY1@<EBX>, int pX2@<ECX>, int pY2, int pColour)
void DRDrawLine(br_pixelmap* pDestn, int pX1, int pY1, int pX2, int pY2, int pColour) {
tU8* d_ptr;
tS32 y_delta;
tS32 x_delta;
tU32 current_y;
tU32 current_x;
int row_bytes;
int x;
int y;
int the_diff;
LOG_TRACE("(%p, %d, %d, %d, %d, %d)", pDestn, pX1, pY1, pX2, pY2, pColour);
BrPixelmapLine(pDestn, pX1, pY1, pX2, pY2, pColour);
}
// IDA: void __usercall DrawDigitAt(br_pixelmap *gImage@<EAX>, int pX@<EDX>, int pY@<EBX>, int pY_pitch@<ECX>, int pValue)
void DrawDigitAt(br_pixelmap* gImage, int pX, int pY, int pY_pitch, int pValue) {
LOG_TRACE("(%p, %d, %d, %d, %d)", gImage, pX, pY, pY_pitch, pValue);
DRPixelmapRectangleMaskedCopy(gBack_screen, pX, pY, gImage, 0, pY_pitch * pValue, gImage->width, pY_pitch);
}
// IDA: void __usercall DrawNumberAt(br_pixelmap *gImage@<EAX>, int pX@<EDX>, int pY@<EBX>, int pX_pitch@<ECX>, int pY_pitch, int pValue, int pDigit_count, int pLeading_zeroes)
void DrawNumberAt(br_pixelmap* gImage, int pX, int pY, int pX_pitch, int pY_pitch, int pValue, int pDigit_count, int pLeading_zeroes) {
int i;
int the_value;
LOG_TRACE("(%p, %d, %d, %d, %d, %d, %d, %d)", gImage, pX, pY, pX_pitch, pY_pitch, pValue, pDigit_count, pLeading_zeroes);
for (i = pDigit_count - 1; i >= 0; i--) {
the_value = pValue % 10;
pValue /= 10;
if (pValue || pLeading_zeroes || pDigit_count - 1 == i) {
DrawDigitAt(gImage, pX + pX_pitch * i, pY, pY_pitch, the_value);
}
}
}
// IDA: void __usercall BuildColourTable(br_pixelmap *pPalette@<EAX>)
void BuildColourTable(br_pixelmap* pPalette) {
int i;
int j;
int nearest_index = 0;
int red;
int green;
int blue;
float nearest_distance;
float distance;
LOG_TRACE("(%p)", pPalette);
#define SQR(i) i* i
for (i = 0; i < COUNT_OF(gRGB_colours); ++i) {
nearest_distance = 0x48400000;
red = (gRGB_colours[i] >> 16) & 0xFF;
green = (gRGB_colours[i] >> 8) & 0xFF;
blue = gRGB_colours[i] & 0xFF;
for (j = 0; j < 256; j++) {
distance = SQR((double)(signed int)(*((br_uint_8*)pPalette->pixels + 4 * j + 2) - red));
distance += SQR((double)(signed int)(*((br_uint_8*)pPalette->pixels + 4 * j) - blue));
distance += SQR((double)(signed int)(*((br_uint_8*)pPalette->pixels + 4 * j + 1) - green));
if (distance < nearest_distance) {
nearest_index = j;
nearest_distance = distance;
}
}
gColours[i] = nearest_index;
}
}
// IDA: void __cdecl ClearConcussion()
void ClearConcussion() {
LOG_TRACE("()");
gConcussion.concussed = 0;
}
// IDA: tS8* __usercall SkipLines@<EAX>(tS8 *pSource@<EAX>, int pCount@<EDX>)
tS8* SkipLines(tS8* pSource, int pCount) {
int i;
int j;
int number_of_chunks;
int chunk_length;
LOG_TRACE("(%p, %d)", pSource, pCount);
for (i = 0; i < pCount; ++i) {
number_of_chunks = *pSource++;
for (j = 0; j < number_of_chunks; j++) {
chunk_length = *pSource++;
if (chunk_length < 0) {
pSource -= chunk_length;
}
}
}
return pSource;
}
// IDA: void __usercall CopyWords(char *pDst@<EAX>, char *pSrc@<EDX>, int pN@<EBX>)
void CopyWords(char* pDst, char* pSrc, int pN) {
tU16* dst;
tU16* src;
LOG_TRACE("(\"%s\", \"%s\", %d)", pDst, pSrc, pN);
NOT_IMPLEMENTED();
}
// IDA: void __usercall Copy8BitStripImageTo16Bit(br_pixelmap *pDest@<EAX>, br_int_16 pDest_x@<EDX>, br_int_16 pOffset_x@<EBX>, br_int_16 pDest_y@<ECX>, br_int_16 pOffset_y, tS8 *pSource, br_int_16 pSource_x, br_int_16 pSource_y, br_uint_16 pWidth, br_uint_16 pHeight)
void Copy8BitStripImageTo16Bit(br_pixelmap* pDest, br_int_16 pDest_x, br_int_16 pOffset_x, br_int_16 pDest_y, br_int_16 pOffset_y, tS8* pSource, br_int_16 pSource_x, br_int_16 pSource_y, br_uint_16 pWidth, br_uint_16 pHeight) {
int i;
int j;
int height;
int number_of_chunks;
int old_x_byte;
int x_byte;
int off_the_left;
int destn_width;
int chunk_length;
char* destn_ptr;
char* destn_ptr2;
LOG_TRACE("(%p, %d, %d, %d, %d, %p, %d, %d, %d, %d)", pDest, pDest_x, pOffset_x, pDest_y, pOffset_y, pSource, pSource_x, pSource_y, pWidth, pHeight);
NOT_IMPLEMENTED();
}
// IDA: void __usercall CopyStripImage(br_pixelmap *pDest@<EAX>, br_int_16 pDest_x@<EDX>, br_int_16 pOffset_x@<EBX>, br_int_16 pDest_y@<ECX>, br_int_16 pOffset_y, tS8 *pSource, br_int_16 pSource_x, br_int_16 pSource_y, br_uint_16 pWidth, br_uint_16 pHeight)
void CopyStripImage(br_pixelmap* pDest, br_int_16 pDest_x, br_int_16 pOffset_x, br_int_16 pDest_y, br_int_16 pOffset_y, tS8* pSource, br_int_16 pSource_x, br_int_16 pSource_y, br_uint_16 pWidth, br_uint_16 pHeight) {
int i;
int j;
int height;
int number_of_chunks;
int old_x_byte;
int x_byte;
int off_the_left;
int destn_width;
int chunk_length;
char* destn_ptr;
char* destn_ptr2;
LOG_TRACE8("(%p, %d, %d, %d, %d, %p, %d, %d, %d, %d)", pDest, pDest_x, pOffset_x, pDest_y, pOffset_y, pSource, pSource_x, pSource_y, pWidth, pHeight);
height = *(uint16_t*)pSource;
pSource = pSource + 2;
if (pDest_y + pOffset_y >= 0) {
destn_ptr = (char*)pDest->pixels + pDest->row_bytes * (pDest_y + pOffset_y);
} else {
pSource = SkipLines(pSource, -pDest_y - pOffset_y);
destn_ptr = (char*)pDest->pixels;
height += pDest_y + pOffset_y;
pOffset_y = 0;
pDest_y = 0;
}
if (height + pDest_y + pOffset_y > pDest->height) {
height = pDest->height - pDest_y - pOffset_y;
}
off_the_left = pDest_x + pOffset_x;
if (off_the_left > 0) {
destn_ptr += off_the_left;
}
for (i = 0; i < height; i++) {
destn_ptr2 = destn_ptr;
number_of_chunks = *pSource;
pSource++;
x_byte = off_the_left;
for (j = 0; j < number_of_chunks; j++) {
chunk_length = *pSource;
pSource++;
if (chunk_length >= 0) {
old_x_byte = x_byte;
x_byte += chunk_length;
if (old_x_byte >= 0) {
destn_ptr2 += chunk_length;
} else if (x_byte > 0) {
destn_ptr2 += chunk_length + old_x_byte;
}
} else {
old_x_byte = x_byte;
x_byte += -chunk_length;
if (old_x_byte >= 0) {
if (pDest->width >= x_byte) {
memcpy(destn_ptr2, pSource, -chunk_length);
destn_ptr2 += -chunk_length;
} else if (old_x_byte < pDest->width) {
memcpy(destn_ptr2, pSource, pDest->width - old_x_byte);
}
} else if (x_byte > 0) {
memcpy(destn_ptr2, &pSource[-old_x_byte], -chunk_length + old_x_byte);
destn_ptr2 += -chunk_length + old_x_byte;
}
pSource += -chunk_length;
}
}
destn_ptr += pDest->row_bytes;
}
}
// IDA: void __usercall SetBRenderScreenAndBuffers(int pX_offset@<EAX>, int pY_offset@<EDX>, int pWidth@<EBX>, int pHeight@<ECX>)
void SetBRenderScreenAndBuffers(int pX_offset, int pY_offset, int pWidth, int pHeight) {
LOG_TRACE("(%d, %d, %d, %d)", pX_offset, pY_offset, pWidth, pHeight);
PDAllocateScreenAndBack();
if (!pWidth) {
pWidth = gBack_screen->width;
}
if (!pHeight) {
pHeight = gBack_screen->height;
}
gRender_screen = DRPixelmapAllocateSub(gBack_screen, pX_offset, pY_offset, pWidth, pHeight);
gWidth = pWidth;
gHeight = pHeight;
gY_offset = pY_offset;
gX_offset = pX_offset;
if (gGraf_specs[gGraf_spec_index].doubled) {
gScreen->base_x = (gGraf_specs[gGraf_spec_index].phys_width - 2 * gGraf_specs[gGraf_spec_index].total_width) / 2;
gScreen->base_y = (gGraf_specs[gGraf_spec_index].phys_height - 2 * gGraf_specs[gGraf_spec_index].total_height) / 2;
} else {
gScreen->base_x = (gGraf_specs[gGraf_spec_index].phys_width - gGraf_specs[gGraf_spec_index].total_width) / 2;
gScreen->base_y = (gGraf_specs[gGraf_spec_index].phys_height - gGraf_specs[gGraf_spec_index].total_height) / 2;
}
gScreen->origin_x = 0;
gScreen->origin_y = 0;
if (gBack_screen == NULL) {
FatalError(kFatalError_AllocateOffScreenBuffer);
}
gDepth_buffer = BrPixelmapMatch(gBack_screen, BR_PMMATCH_DEPTH_16);
if (gDepth_buffer == NULL) {
FatalError(kFatalError_AllocateZBuffer);
}
BrZbBegin(gRender_screen->type, gDepth_buffer->type);
gBrZb_initialized = 1;
}
// IDA: void __cdecl SetIntegerMapRenders()
void SetIntegerMapRenders() {
LOG_TRACE("()");
gMap_render_x_i = ((int)gMap_render_x) & ~3;
gMap_render_y_i = ((int)gMap_render_y) & ~1;
gMap_render_width_i = ((int)gMap_render_width) & ~3;
gMap_render_height_i = ((int)gMap_render_height) & ~1;
if (gReal_graf_data_index != 0) {
gMap_render_x_i = 2 * gMap_render_x_i;
gMap_render_y_i = 2 * gMap_render_y_i + 40;
gMap_render_width_i = 2 * gMap_render_width_i;
gMap_render_height_i = 2 * gMap_render_height_i;
}
}
// IDA: void __cdecl AdjustRenderScreenSize()
void AdjustRenderScreenSize() {
int switched_res;
LOG_TRACE("()");
switched_res = SwitchToRealResolution();
ReinitialiseRenderStuff();
if (gMap_mode) {
gRender_screen->base_x = gMap_render_x_i;
gRender_screen->base_y = gMap_render_y_i;
gRender_screen->width = gMap_render_width_i;
gRender_screen->height = gMap_render_height_i;
} else {
gRender_screen->base_x = gProgram_state.current_render_left;
gRender_screen->base_y = gProgram_state.current_render_top;
gRender_screen->height = gProgram_state.current_render_bottom - gProgram_state.current_render_top;
gRender_screen->width = gProgram_state.current_render_right - gProgram_state.current_render_left;
}
if (gRender_screen->row_bytes == gRender_screen->width) {
gRender_screen->flags |= BR_PMF_ROW_WHOLEPIXELS;
} else {
gRender_screen->flags &= ~BR_PMF_ROW_WHOLEPIXELS;
}
gRender_screen->origin_x = gRender_screen->width / 2;
gRender_screen->origin_y = gRender_screen->height / 2;
gWidth = gRender_screen->width;
gHeight = gRender_screen->height;
ReinitialiseForwardCamera();
if (switched_res) {
SwitchToLoresMode();
}
}
// IDA: void __cdecl ScreenSmaller()
void ScreenSmaller() {
LOG_TRACE("()");
if (!gMap_mode) {
if (gProgram_state.cockpit_on) {
ToggleCockpit();
}
gRender_indent++;
if (gRender_indent > 8) {
gRender_indent = 8;
}
AdjustRenderScreenSize();
}
}
// IDA: void __cdecl ScreenLarger()
void ScreenLarger() {
LOG_TRACE("()");
if (!gMap_mode) {
if (gProgram_state.cockpit_on) {
ToggleCockpit();
}
gRender_indent--;
if (gRender_indent < 0) {
gRender_indent = 0;
}
AdjustRenderScreenSize();
}
}
// IDA: void __usercall DRSetPaletteEntries(br_pixelmap *pPalette@<EAX>, int pFirst_colour@<EDX>, int pCount@<EBX>)
void DRSetPaletteEntries(br_pixelmap* pPalette, int pFirst_colour, int pCount) {
LOG_TRACE("(%p, %d, %d)", pPalette, pFirst_colour, pCount);
if (!pFirst_colour) {
((br_int_32*)pPalette->pixels)[0] = 0;
}
memcpy(gCurrent_palette_pixels + 4 * pFirst_colour, (char*)pPalette->pixels + 4 * pFirst_colour, 4 * pCount);
if (!gFaded_palette) {
PDSetPaletteEntries(pPalette, pFirst_colour, pCount);
}
gPalette_munged = 1;
}
// IDA: void __usercall DRSetPalette3(br_pixelmap *pThe_palette@<EAX>, int pSet_current_palette@<EDX>)
void DRSetPalette3(br_pixelmap* pThe_palette, int pSet_current_palette) {
LOG_TRACE("(%p, %d)", pThe_palette, pSet_current_palette);
if (pSet_current_palette) {
memcpy(gCurrent_palette_pixels, pThe_palette->pixels, 0x400u);
}
if (!gFaded_palette) {
PDSetPalette(pThe_palette);
}
if (pThe_palette != gRender_palette) {
gPalette_munged |= 1u;
}
}
// IDA: void __usercall DRSetPalette2(br_pixelmap *pThe_palette@<EAX>, int pSet_current_palette@<EDX>)
void DRSetPalette2(br_pixelmap* pThe_palette, int pSet_current_palette) {
((br_int_32*)pThe_palette->pixels)[0] = 0;
if (pSet_current_palette) {
memcpy(gCurrent_palette_pixels, pThe_palette->pixels, 0x400u);
}
if (!gFaded_palette) {
PDSetPalette(pThe_palette);
}
if (pThe_palette != gRender_palette) {
gPalette_munged |= 1u;
}
}
// IDA: void __usercall DRSetPalette(br_pixelmap *pThe_palette@<EAX>)
void DRSetPalette(br_pixelmap* pThe_palette) {
DRSetPalette2(pThe_palette, 1);
}
// IDA: void __cdecl InitializePalettes()
void InitializePalettes() {
int j;
gCurrent_palette_pixels = BrMemAllocate(0x400u, kMem_cur_pal_pixels);
gCurrent_palette = DRPixelmapAllocate(BR_PMT_RGBX_888, 1u, 256, gCurrent_palette_pixels, 0);
gRender_palette = BrTableFind("DRRENDER.PAL");
if (gRender_palette == NULL) {
FatalError(kFatalError_RequiredPalette);
}
gOrig_render_palette = BrPixelmapAllocateSub(gRender_palette, 0, 0, gRender_palette->width, gRender_palette->height);
gOrig_render_palette->pixels = BrMemAllocate(0x400u, kMem_render_pal_pixels);
memcpy(gOrig_render_palette->pixels, gRender_palette->pixels, 0x400u);
gFlic_palette = BrTableFind("DRACEFLC.PAL");
if (gFlic_palette == NULL) {
FatalError(kFatalError_RequiredPalette);
}
DRSetPalette(gFlic_palette);
gScratch_pixels = BrMemAllocate(0x400u, kMem_scratch_pal_pixels);
gScratch_palette = DRPixelmapAllocate(BR_PMT_RGBX_888, 1u, 256, gScratch_pixels, 0);
gPalette_conversion_table = BrTableFind("FLC2REND.TAB");
gRender_shade_table = BrTableFind("DRRENDER.TAB");
gEval_1 = LoadPixelmap("Evalu01.PIX");
}
// IDA: void __usercall SwitchToPalette(char *pPal_name@<EAX>)
void SwitchToPalette(char* pPal_name) {
br_pixelmap* the_palette;
LOG_TRACE("(\"%s\")", pPal_name);
NOT_IMPLEMENTED();
}
// IDA: void __cdecl ClearEntireScreen()
void ClearEntireScreen() {
LOG_TRACE("()");
if (gScreen) {
BrPixelmapFill(gScreen, gGraf_specs[gGraf_spec_index].black_value);
}
BrPixelmapFill(gBack_screen, gGraf_specs[gGraf_spec_index].black_value);
PDScreenBufferSwap(0);
}
// IDA: void __cdecl ClearWobbles()
void ClearWobbles() {
int i;
LOG_TRACE("()");
for (i = 0; i < COUNT_OF(gWobble_array); ++i) {
gWobble_array[i].time_started = 0;
}
}
// IDA: void __cdecl InitWobbleStuff()
void InitWobbleStuff() {
int i;
ClearWobbles();
for (i = 0; i < COUNT_OF(gCosine_array); i++) {
gCosine_array[i] = cosf(i / 64.0f * 3.141592653589793f / 2.0f);
}
}
// IDA: void __cdecl NewScreenWobble(double pAmplitude_x, double pAmplitude_y, double pPeriod)
void NewScreenWobble(double pAmplitude_x, double pAmplitude_y, double pPeriod) {
int i;
int oldest_time;
int oldest_index;
LOG_TRACE("(%d, %d, %d)", pAmplitude_x, pAmplitude_y, pPeriod);
oldest_index = -1;
oldest_time = INT_MAX;
for (i = 0; i < COUNT_OF(gWobble_array); i++) {
if (gWobble_array[i].time_started == 0) {
oldest_index = i;
break;
}
if (gWobble_array[i].time_started < oldest_time) {
oldest_time = gWobble_array[i].time_started;
oldest_index = i;
}
}
gWobble_array[oldest_index].time_started = GetTotalTime();
gWobble_array[oldest_index].amplitude_x = pAmplitude_x;
gWobble_array[oldest_index].amplitude_y = pAmplitude_y;
gWobble_array[oldest_index].period = pPeriod;
}
// IDA: void __usercall SetScreenWobble(int pWobble_x@<EAX>, int pWobble_y@<EDX>)
void SetScreenWobble(int pWobble_x, int pWobble_y) {
LOG_TRACE("(%d, %d)", pWobble_x, pWobble_y);
gScreen_wobble_y = pWobble_y;
gScreen_wobble_x = pWobble_x;
}
// IDA: void __cdecl ResetScreenWobble()
void ResetScreenWobble() {
LOG_TRACE("()");
SetScreenWobble(0, 0);
}
// IDA: void __usercall CalculateWobblitude(tU32 pThe_time@<EAX>)
void CalculateWobblitude(tU32 pThe_time) {
int i;
tU32 time_going;
double angle;
double mod_angle;
double cosine_over_angle;
LOG_TRACE("(%d)", pThe_time);
gScreen_wobble_x = 0;
gScreen_wobble_y = 0;
STUB_ONCE();
}
// IDA: void __usercall CalculateConcussion(tU32 pThe_time@<EAX>)
void CalculateConcussion(tU32 pThe_time) {
tU32 time_difference;
int i;
int j;
float the_amplitude;
float angle;
float mod_angle;
float cosine_over_angle;
LOG_TRACE("(%d)", pThe_time);
gConcussion.concussed = 0;
STUB_ONCE();
}
// IDA: void __cdecl SufferFromConcussion(float pSeriousness)
void SufferFromConcussion(float pSeriousness) {
int i;
int j;
LOG_TRACE("(%f)", pSeriousness);
NOT_IMPLEMENTED();
}
// IDA: void __usercall ProcessNonTrackActors(br_pixelmap *pRender_buffer@<EAX>, br_pixelmap *pDepth_buffer@<EDX>, br_actor *pCamera@<EBX>, br_matrix34 *pCamera_to_world@<ECX>, br_matrix34 *pOld_camera_matrix)
void ProcessNonTrackActors(br_pixelmap* pRender_buffer, br_pixelmap* pDepth_buffer, br_actor* pCamera, br_matrix34* pCamera_to_world, br_matrix34* pOld_camera_matrix) {
LOG_TRACE("(%p, %p, %p, %p, %p)", pRender_buffer, pDepth_buffer, pCamera, pCamera_to_world, pOld_camera_matrix);
BrZbSceneRenderAdd(gNon_track_actor);
}
// IDA: int __usercall OppositeColour@<EAX>(int pColour@<EAX>)
int OppositeColour(int pColour) {
int brightness;
LOG_TRACE("(%d)", pColour);
if (pColour < 224) {
if ((pColour & 0x7) < 4) {
brightness = 255;
} else {
brightness = 0;
}
} else {
if ((pColour & 0xf) < 8) {
brightness = 255;
} else {
brightness = 0;
}
}
return brightness;
}
// IDA: void __usercall DrawMapBlip(tCar_spec *pCar@<EAX>, tU32 pTime@<EDX>, br_matrix34 *pTrans@<EBX>, br_vector3 *pPos@<ECX>, int pColour)
void DrawMapBlip(tCar_spec* pCar, tU32 pTime, br_matrix34* pTrans, br_vector3* pPos, int pColour) {
br_vector3 map_pos;
int offset;
int* arrow_ptr;
int point_count;
int colours[2];
int x;
int y;
int colour;
int i;
int j;
int temp;
int from_x;
int from_y;
int to_x;
int to_y;
int arrow_index;
tU32 time_diff;
tU32 period;
br_matrix34 car_in_map_space;
float bearing;
float cos_factor;
float sin_factor;
LOG_TRACE("(%p, %d, %p, %p, %d)", pCar, pTime, pTrans, pPos, pColour);
time_diff = pTime - gMap_mode;
BrMatrix34ApplyP(&map_pos, pPos, &gCurrent_race.map_transformation);
switch (gReal_graf_data_index) {
case 0:
break;
case 1:
map_pos.v[0] = map_pos.v[0] * 2.f;
map_pos.v[1] = map_pos.v[1] * 2.f + 40.f;
break;
default:
TELL_ME_IF_WE_PASS_THIS_WAY();
}
period = 256; // Must be power of 2
colours[0] = pColour;
colours[1] = OppositeColour(pColour);
BrMatrix34Mul(&car_in_map_space, pTrans, &gCurrent_race.map_transformation);
bearing = FastScalarArcTan2(car_in_map_space.m[2][0], car_in_map_space.m[2][1]);
// Calculate in which of the 16 directions, the arrow is pointing to
bearing = (360.f - bearing + 12.25) / 22.5f;
arrow_index = ((int)bearing) % 16;
// The player's blip blinks, others are shown permanently
if (pCar->driver != eDriver_local_human || (period & pTime) != 0) {
for (i = 0; i < COUNT_OF(colours); i++) {
colour = colours[i];
point_count = gArrows[i][arrow_index & 0x3][0];
arrow_ptr = &gArrows[i][arrow_index & 0x3][1];
for (j = 0; j < point_count; j++, arrow_ptr += 2) {
if (arrow_index & 0x8) {
x = -arrow_ptr[0];
y = -arrow_ptr[1];
} else {
x = arrow_ptr[0];
y = arrow_ptr[1];
}
if (arrow_index & 0x4) {
temp = x;
x = -y;
y = temp;
}
BrPixelmapPixelSet(gBack_screen, map_pos.v[0] + x, map_pos.v[1] + y, colour);
}
}
}
// Draw a rectangle around the fox
colour = colours[!!(pTime & period)];
if (gNet_mode != eNet_mode_none && gCurrent_net_game->type == eNet_game_type_foxy && gNet_players[gIt_or_fox].car == pCar) {
from_x = map_pos.v[0] - 8.f;
from_y = map_pos.v[1] - 8.f;
to_x = map_pos.v[0] + 8.f;
to_y = map_pos.v[1] + 8.f;
BrPixelmapLine(gBack_screen, from_x, from_y, to_x, from_y, colour);
BrPixelmapLine(gBack_screen, from_x, to_y, to_x, to_y, colour);
BrPixelmapLine(gBack_screen, from_x, from_y, from_x, to_y, colour);
BrPixelmapLine(gBack_screen, to_x, from_y, to_x, to_y, colour);
}
// To attract the player's attention, draw a rectangle around the player's position that decreases in size,
if (time_diff <= 500 && pCar->driver == eDriver_local_human) {
offset = ((500 - time_diff) * 70) / 500;
from_x = map_pos.v[0] - offset - .5f;
from_y = map_pos.v[1] - offset - .5f;
to_x = map_pos.v[0] + offset + .5f;
to_y = map_pos.v[1] + offset + .5f;
BrPixelmapLine(gBack_screen, from_x, from_y, to_x, from_y, colour);
BrPixelmapLine(gBack_screen, from_x, to_y, to_x, to_y, colour);
BrPixelmapLine(gBack_screen, from_x, from_y, from_x, to_y, colour);
BrPixelmapLine(gBack_screen, to_x, from_y, to_x, to_y, colour);
}
}
// IDA: void __usercall DrawMapSmallBlip(tU32 pTime@<EAX>, br_vector3 *pPos@<EDX>, int pColour@<EBX>)
void DrawMapSmallBlip(tU32 pTime, br_vector3* pPos, int pColour) {
br_vector3 map_pos;
int offset;
tU32 time_diff;
LOG_TRACE("(%d, %p, %d)", pTime, pPos, pColour);
if ((pTime & 0x100) == 0) {
BrMatrix34ApplyP(&map_pos, pPos, &gCurrent_race.map_transformation);
if (gReal_graf_data_index != 0) {
map_pos.v[0] = 2.f * map_pos.v[0];
map_pos.v[1] = 2.f * map_pos.v[1] + 40.f;
}
offset = (int)map_pos.v[0] + gBack_screen->row_bytes * (int)map_pos.v[1];
((br_uint_8*)gBack_screen->pixels)[offset] = pColour;
}
}
// IDA: void __usercall MungeClipPlane(br_vector3 *pLight@<EAX>, tCar_spec *pCar@<EDX>, br_vector3 *p1@<EBX>, br_vector3 *p2@<ECX>, br_scalar pY_offset)
void MungeClipPlane(br_vector3* pLight, tCar_spec* pCar, br_vector3* p1, br_vector3* p2, br_scalar pY_offset) {
br_vector3 v1;
br_vector3 v2;
br_vector3 v3;
br_vector3 v4;
br_scalar length;
br_actor* new_clip;
LOG_TRACE("(%p, %p, %p, %p, %f)", pLight, pCar, p1, p2, pY_offset);
BrMatrix34ApplyP(&v1, p1, &pCar->car_master_actor->t.t.mat);
BrMatrix34ApplyP(&v2, p2, &pCar->car_master_actor->t.t.mat);
BrVector3Sub(&v3, p2, p1);
BrVector3Cross(&v4, &v3, pLight);
if (fabsf(v4.v[0]) >= 0.01f || fabsf(v4.v[1]) >= 0.01f || fabsf(v4.v[2]) >= 0.01f) {
BrVector3Copy(&v3, p1);
v3.v[1] -= pY_offset;
if (BrVector3Dot(&v3, &v4) > 0.f) {
BrVector3Negate(&v4, &v4);
}
BrVector3Normalise(&v3, &v4);
BrMatrix34ApplyV(&v4, &v3, &pCar->car_master_actor->t.t.mat);
length = (v1.v[2] - v2.v[2]) * (v1.v[2] - v2.v[2]) + (v1.v[0] - v2.v[0]) * (v1.v[0] - v2.v[0]);
new_clip = gShadow_clip_planes[gShadow_clip_plane_count].clip;
((br_vector4*)new_clip->type_data)->v[0] = v4.v[0];
((br_vector4*)new_clip->type_data)->v[1] = v4.v[1];
((br_vector4*)new_clip->type_data)->v[2] = v4.v[2];
((br_vector4*)new_clip->type_data)->v[3] = -BrVector3Dot(&v1, &v4);
gShadow_clip_planes[gShadow_clip_plane_count].length = length;
gShadow_clip_plane_count++;
}
}
// IDA: void __usercall TryThisEdge(tCar_spec *pCar@<EAX>, br_vector3 *pLight@<EDX>, int pIndex_1@<EBX>, br_scalar pSign_1, int pIndex_2, br_scalar pSign_2, int pPoint_index_1, int pPoint_index_2, br_scalar pY_offset)
void TryThisEdge(tCar_spec* pCar, br_vector3* pLight, int pIndex_1, br_scalar pSign_1, int pIndex_2, br_scalar pSign_2, int pPoint_index_1, int pPoint_index_2, br_scalar pY_offset) {