-
Notifications
You must be signed in to change notification settings - Fork 0
/
render.c
1074 lines (915 loc) · 41 KB
/
render.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 <sl_def.h>
#include "def.h"
#include "mloader.h"
#include "mymath.h"
#include "bounder.h"
#include "render.h"
#include "anorm.h"
int * DVSR = ( int*)0xFFFFFF00;
int * DVDNTH = ( int*)0xFFFFFF10;
int * DVDNTL = ( int*)0xFFFFFF14;
SPRITE * localSprBuf = (SPRITE *)0x060D5B60;
vertex_t ssh2VertArea[MAX_SSH2_ENTITY_VERTICES];
vertex_t msh2VertArea[MAX_MSH2_ENTITY_VERTICES];
animationControl AnimArea[MAX_SIMULTANEOUS_ANIMATED_ENTITIES];
_sprite sprWorkList[MAX_SPRITES];
paletteCode * pcoTexDefs; //Defined with a LWRAM address in lwram.c
point_light light_host[MAX_DYNAMIC_LIGHTS];
point_light * active_lights;
//Just a debug list, not a hard limit.
entity_t * drawn_entity_list[64];
short drawn_entity_count;
int dummy[4];
int * ssh2SentPolys;
int * msh2SentPolys;
int * transVerts;
int * transPolys;
int anims; //Current active animation count; increments animation control data work array.
int scrn_dist; //Distance to projection screen surface
// Software clipping settings.
// Setting user clipping will also set these.
short vert_clip_x = TV_HALF_WIDTH;
short vert_clip_nx = -TV_HALF_WIDTH;
short vert_clip_y = TV_HALF_HEIGHT;
short vert_clip_ny = -TV_HALF_HEIGHT;
int send_draw_stats; //Setting for sending draw stats to screen. 0 = no stats; 1 = send by sprites; 2 = send by NBG text
// Framebuffer Erase Region Settings
unsigned short top_left_erase_pt = 0;
#ifdef USE_HI_RES
int hi_res_switch = 1;
unsigned short btm_rite_erase_pt = ((TV_WIDTH / 16) << 9) | (TV_HALF_HEIGHT);
#else
int hi_res_switch = 0;
unsigned short btm_rite_erase_pt = ((TV_WIDTH / 8) << 9) | (TV_HEIGHT);
#endif
/*
Don't forget:
UV coordinates are possible on Saturn with indexed color draw commands.
The method by which this is possible is to put your texture in color RAM, and use goraud shading as texture coordinates.
The draw command consequently should be untextured, as VDP1 is managing the texel via goraud shading.
The color of the polygon should be .. hmm..
Since goraud is additive, you should be able to locate the texel in color RAM by making the start address of the texel the color.
I plan on experimenting with a 16x16 texture in color RAM so as to use this method.
It seems like this is only possible with a texture width of 32.
The goraud coordinates use red and blue, the first ten bits.
Red and blue each are five bits, ergo, 32.
If you increment blue (or coordinate Y) by 1, you still increment the integer coordinate by 32.
So yes, a 16x16 is not possible. It would have to be 32x8 at the smallest.
*/
int get_screen_distance_from_fov(short desired_horizontal_fov)
{
//Primitive: 90 - ((fov / 2) + 90)
int scrn_half_angle = 8192 - (desired_horizontal_fov >> 1) + 8192;
int scrn_scalar = slTan(scrn_half_angle);
int scrndist = fxm(scrn_scalar, (TV_HALF_WIDTH)<<16);
return scrndist;
}
void init_render_area(short desired_horizontal_fov)
{
for(int i = 0; i < MAX_SPRITES; i++)
{
//Mark the whole sprite list as unused.
sprWorkList[i].type = 'N';
}
scrn_dist = get_screen_distance_from_fov(desired_horizontal_fov);
ssh2SentPolys = (int *)(((unsigned int)&dummy[0])|UNCACHE);
msh2SentPolys = (int *)(((unsigned int)&dummy[1])|UNCACHE);
transVerts = (int *)(((unsigned int)&dummy[2])|UNCACHE);
transPolys = (int *)(((unsigned int)&dummy[3])|UNCACHE);
active_lights = (point_light *)(((unsigned int)&light_host[0])|UNCACHE);
}
void frame_render_prep(void)
{
ssh2SentPolys[0] = 0;
msh2SentPolys[0] = 0;
transVerts[0] = 0;
transPolys[0] = 0;
anims = 0;
drawn_entity_count = 0;
vert_clip_x = TV_HALF_WIDTH;
vert_clip_nx = -TV_HALF_WIDTH;
vert_clip_y = TV_HALF_HEIGHT;
vert_clip_ny = -TV_HALF_HEIGHT;
}
//Note: Set literal screen coordinates.
///Use: Cordon off a region of the screen for drawing static items.
///In this case, the static items do not need to be re-drawn every frame, and save VDP1 on performance.
void setFramebufferEraseRegion(int xtl, int ytl, int xbr, int ybr)
{
if(hi_res_switch){
top_left_erase_pt = ((xtl>>4) << 9) | (ytl>>1);
btm_rite_erase_pt = ((xbr>>4) << 9) | (ybr>>1);
} else {
top_left_erase_pt = ((xtl>>3) << 9) | (ytl);
btm_rite_erase_pt = ((xbr>>3) << 9) | (ybr);
}
}
FIXED trans_pt_by_component(POINT ptx, FIXED * normal)
{
volatile FIXED transPt;
asm(
"clrmac;"
"mov %[ptptr], r0;" //Moves pt ptr to discrete s to prevent the C-level variable from being modified.
"mov %[nmptr], r1;" //Calls the nmptr to a discrete to "encourage" C to refresh the pointer every function call
"mac.l @r0+,@r1+;" //Denoting @r0+ is "data pointed to by data in r0, r0+=(sizeof(instr_depth))"
"mac.l @r0+,@r1+;" //where instr_depth can be byte for mov.b , 2 bytes for mov.w, 4 bytes for mov.l
"mac.l @r0+,@r1+;" //MAC also stands for "multiply and accumulate" - you can probably figure that one out
"sts MACH,r0;" //This, by the way, is representative of matrix[comp] * pt ->
"sts MACL,%[ox];" //e.g. matrix[X][X] * pt[X] + matrix[Y][X] * pt[Y] + matrix[Z][X] * pt[Z] + matrix[pos][X]
"xtrct r0,%[ox];"
"mov.l @r1,r0;" //This last move and add is the matrix component position
"add r0,%[ox];"
: [ox] "=r" (transPt) //OUT
: [ptptr] "r" (ptx) , [nmptr] "r" (normal) //IN
: "r0" , "r1", "mach", "macl" //CLOBBERS
);
return transPt;
}
//Set data in s for division unit.
void SetFixDiv(FIXED dividend, FIXED divisor) //Defined as "dividend / divisor", for fixed points, using division unit
{
/*
SH7604 Manual Information:
The 64-bit dividend is set in dividend s H and L (DVDNTH and DVDNTL).
First set the value in DVDNTH. When a value is written to DVDNTL, the 64-bit ÷ 32-bit operation begins.
After the operation, the 32-bit remainder is written to DVDNTH and the 32-bit quotient is written to DVDNTL.
[ME:]These s can only be accessed via pointers. . . because our compiler is not aware of them.
*/
DVSR[0] = divisor;
DVDNTH[0] = (dividend>>16);
DVDNTL[0] = (dividend<<16);
}
void ssh2SetCommand(FIXED * p1, FIXED * p2, FIXED * p3, FIXED * p4, Uint16 cmdctrl,
Uint16 cmdpmod, Uint16 cmdsrca, Uint16 cmdcolr,
Uint16 cmdsize, Uint16 cmdgrda, FIXED drawPrty) {
SPRITE_T * user_sprite = (SPRITE_T *)&SpriteBuf[ssh2SentPolys[0] + MAX_MSH2_SENT_POLYS];
ssh2SentPolys[0]++;
user_sprite->CTRL = cmdctrl;
user_sprite->LINK = 0x3000;
user_sprite->PMOD = cmdpmod;
user_sprite->SRCA = cmdsrca; //TEXTURE ADDRESS IN VDP1 VRAM
user_sprite->COLR = cmdcolr; //COLOR BANK CODE IN COLOR BANK MODES, DRAW COLOR IN UNTEXTURED MODES, LUT ADDRESS IN CL16LK, IGNORED RGB
user_sprite->SIZE = cmdsize; //VALID FOR TEXTURE DRAW COMMANDS
user_sprite->GRDA = cmdgrda;
user_sprite->XA=p1[X];
user_sprite->YA=p1[Y];
user_sprite->XB=p2[X];
user_sprite->YB=p2[Y];
user_sprite->XC=p3[X];
user_sprite->YC=p3[Y];
user_sprite->XD=p4[X];
user_sprite->YD=p4[Y];
user_sprite->DMMY=(drawPrty>>16);
/**Important : Only the slave CPU is allowed to read/write the z sort buffer**/
//IMPORTANT: We have to use the "far" screen. This is the "128". Why? Someone got angry when I asked why...
//CRITICAL!! You MUST change sl_def to include the SPRITE_T structure. It is the same as SPRITE except with a Uint32 pointer, NEXT.
//You must also change SpriteBuf and SpriteBuf2 to be of SPRITE_T * type.
Uint32 ** Zentry = (Uint32**)(Zbuffer + (128 + ((user_sprite->DMMY>>3)))*4 ); //Get Z distance as entry into Z buffer
user_sprite->NEXT=*Zentry; //Link current polygon to last entry at that Z distance in Zbuffer
*Zentry=(void*)user_sprite; //Make last entry at that Z distance this entry
}
inline void msh2SetCommand(FIXED * p1, FIXED * p2, FIXED * p3, FIXED * p4, Uint16 cmdctrl,
Uint16 cmdpmod, Uint16 cmdsrca, Uint16 cmdcolr,
Uint16 cmdsize, Uint16 cmdgrda, FIXED drawPrty) {
SPRITE_T * user_sprite = (SPRITE_T *)&SpriteBuf[msh2SentPolys[0]];
msh2SentPolys[0]++;
user_sprite->CTRL = cmdctrl;
user_sprite->LINK = 0x3000;
user_sprite->PMOD = cmdpmod;
user_sprite->SRCA = cmdsrca; //TEXTURE ADDRESS IN VDP1 VRAM
user_sprite->COLR = cmdcolr; //COLOR BANK CODE IN COLOR BANK MODES, DRAW COLOR IN UNTEXTURED MODES, LUT ADDRESS IN CL16LK, IGNORED RGB
user_sprite->SIZE = cmdsize; //VALID FOR TEXTURE DRAW COMMANDS
user_sprite->GRDA = cmdgrda;
user_sprite->XA=p1[X];
user_sprite->YA=p1[Y];
user_sprite->XB=p2[X];
user_sprite->YB=p2[Y];
user_sprite->XC=p3[X];
user_sprite->YC=p3[Y];
user_sprite->XD=p4[X];
user_sprite->YD=p4[Y];
user_sprite->DMMY=(drawPrty>>16);
}
void sort_master_polys(void)
{
if(send_draw_stats == 1)
{
unsigned short txt_base = (hi_res_switch) ? 400 : 180;
spr_sprintf(8, txt_base, "Polygons in Scene:(%i)", transPolys[0]);
spr_sprintf(8, txt_base+15, "Sent Commands:(%i)", ssh2SentPolys[0] + msh2SentPolys[0]);
spr_sprintf(8, txt_base+30, "Transformed Verts:(%i)", transVerts[0]);
} else if(send_draw_stats == 2)
{
unsigned short txt_base = (hi_res_switch) ? 1 : 2;
nbg_sprintf(txt_base, 24, "TRPLY:(%i)", transPolys[0]);
nbg_sprintf(txt_base, 25, "SNTPL:(%i)", ssh2SentPolys[0] + msh2SentPolys[0]);
nbg_sprintf(txt_base, 26, "VERTS:(%i)", transVerts[0]);
}
SPRITE_T * user_sprite;
for(int i = 0; i < msh2SentPolys[0]; i++)
{
user_sprite = (SPRITE_T *)&SpriteBuf[i];
/**Important : Only the slave CPU is allowed to read/write the z sort buffer**/
//IMPORTANT: We have to use the "far" screen. This is the "128". Why? Someone got angry when I asked why...
//CRITICAL!! You MUST change sl_def to include the SPRITE_T structure. It is the same as SPRITE except with a Uint32 pointer, NEXT.
//You must also change SpriteBuf and SpriteBuf2 to be of SPRITE_T * type.
Uint32 ** Zentry = (Uint32**)(Zbuffer + (128 + ((user_sprite->DMMY>>3)))*4 ); //Get Z distance as entry into Z buffer
user_sprite->NEXT=*Zentry; //Link current polygon to last entry at that Z distance in Zbuffer [*Zentry is a pointer to the last polygon]
*Zentry=(void*)user_sprite; //Make last entry at that Z distance this entry [*Zentry becomes a pointer to this polygon]
}
}
//If rendering a matrix-centered object (like a gun model or a third-person player model), set "negate coordinates" to Y.
int process_light(VECTOR lightAngle, FIXED * ambient_light, int * brightness_floor, FIXED * prematrix, char model_purpose)
{
//model_purpose .. where 'P' means "PLAYER".
/*
PRE-PROCESSOR
Find the nearest light in the active light list.
The engine expects you to populate the light list with at least 1 light.
It can be a point light, an ambient light, or both.
*/
int nearest_dot = 0;
int active_dot = 0;
VECTOR lightDist = {0, 0, 0};
point_light * light_used = &active_lights[0];
FIXED * wldPos = &prematrix[9];
nearest_dot = JO_ABS(wldPos[X] - light_used->pos[X]) +
JO_ABS(wldPos[Y] - light_used->pos[Y]) +
JO_ABS(wldPos[Z] - light_used->pos[Z]);
for(unsigned int i = 0; i < MAX_DYNAMIC_LIGHTS; i++)
{
if(active_lights[i].pop == 1)
{
// " Manhattan Distance "
if(model_purpose == 'P')
{
active_dot = JO_ABS(wldPos[X] - active_lights[i].pos[X]) +
JO_ABS(wldPos[Y] - active_lights[i].pos[Y]) +
JO_ABS(wldPos[Z] - active_lights[i].pos[Z]);
} else {
active_dot = JO_ABS(wldPos[X] + active_lights[i].pos[X]) +
JO_ABS(wldPos[Y] + active_lights[i].pos[Y]) +
JO_ABS(wldPos[Z] + active_lights[i].pos[Z]);
}
if(active_dot < nearest_dot)
{
light_used = &active_lights[i];
nearest_dot = active_dot;
}
}
}
//Set the ambient light
////////////////////////////////////////////////////
/*
The pre-matrix angle ( " master angle " ) must be passed into the system to rotate the ambient light angle.
The pre-matrix angle is what the object's rotation is BEFORE matrix multiplication. In other words, how the _object_ is rotated.
For some reason, this light angle has to be transformed incorrectly to be correct...
(technical: it uses the transposed matrix)
(e2: this is an "inverse transform", from world space back to the matrix' space, because it is going to be used in matrix space)
*/
ambient_light[X] = fxm(-light_used->ambient_light[X], prematrix[0])
+ fxm(light_used->ambient_light[Y], prematrix[1])
+ fxm(-light_used->ambient_light[Z], prematrix[2]);
ambient_light[Y] = fxm(-light_used->ambient_light[X], prematrix[3])
+ fxm(light_used->ambient_light[Y], prematrix[4])
+ fxm(-light_used->ambient_light[Z], prematrix[5]);
ambient_light[Z] = fxm(-light_used->ambient_light[X], prematrix[6])
+ fxm(light_used->ambient_light[Y], prematrix[7])
+ fxm(-light_used->ambient_light[Z], prematrix[8]);
////////////////////////////////////////////////////
*brightness_floor = (int)(light_used->min_bright);
////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
LIGHT PROCESSING
lightSrc is a point-light.
The function needs to take the entities world position as an argument.
Then get a vector from the world pos to the light pos.
It becomes the light's distance.
We then normalize that distance to get the light angle.
This normalization process is sensitive, so we use the most accurate method we can.
At that point we use the inverse squared law, plus a brightness multiplier, to find the light bright.
If the light is far, the light angle is just considered zero. No light is contributed.
As a result, dynamic point lights are generally quite dim.
*/
if(model_purpose == 'P')
{
lightDist[X] = wldPos[X] - light_used->pos[X];
lightDist[Y] = wldPos[Y] - light_used->pos[Y];
lightDist[Z] = wldPos[Z] - light_used->pos[Z];
} else {
lightDist[X] = wldPos[X] + light_used->pos[X];
lightDist[Y] = wldPos[Y] + light_used->pos[Y];
lightDist[Z] = wldPos[Z] + light_used->pos[Z];
}
int vmag = 0;
if( JO_ABS(lightDist[X]) < (147<<16) && JO_ABS(lightDist[Y]) < (147<<16) && JO_ABS(lightDist[Z]) < (147<<16))
{
vmag = slSquartFX(fxdot(lightDist, lightDist));
vmag = fxdiv(1<<16, vmag);
//Normalize the light vector *properly*
lightAngle[X] = fxm(vmag, lightDist[X]);
lightAngle[Y] = fxm(vmag, lightDist[Y]);
lightAngle[Z] = fxm(vmag, lightDist[Z]);
//Now we have to transform the light angle by the object's orientation
VECTOR tempAngle;
tempAngle[X] = fxm(lightAngle[X], prematrix[0])
+ fxm(lightAngle[Y], prematrix[1])
+ fxm(lightAngle[Z], prematrix[2]);
tempAngle[Y] = fxm(lightAngle[X], prematrix[3])
+ fxm(lightAngle[Y], prematrix[4])
+ fxm(lightAngle[Z], prematrix[5]);
tempAngle[Z] = fxm(lightAngle[X], prematrix[6])
+ fxm(lightAngle[Y], prematrix[7])
+ fxm(lightAngle[Z], prematrix[8]);
if(model_purpose == 'P')
{
lightAngle[X] = -tempAngle[X];
lightAngle[Y] = -tempAngle[Y];
lightAngle[Z] = -tempAngle[Z];
} else {
lightAngle[X] = tempAngle[X];
lightAngle[Y] = tempAngle[Y];
lightAngle[Z] = tempAngle[Z];
}
//Retrieve the inverse square of distance
return fxdiv(1<<16, fxdot(lightDist, lightDist)) * (int)light_used->bright;
/////////////////////////////////////////////////////////////////////////////////
}
return 0;
}
////////////////////////////
// Light shade determinant function
////////////////////////////
inline void determine_colorbank(unsigned short * colorBank, int * luma)
{
//The point of the shades:
// 0: Overbright / Noon, direct sunlight
// 1: Lit / Overcast / Indoor light
// 2: Shaded / Dim light / Twilight
// 3: Full moon / Dark room
// 4: Most lightless shade // Notice this shade cannot be used in hi-res mode (will just be shade #3)
*colorBank = (*luma >= 73726) ? 0x0 : 1;
*colorBank = (*luma < 49152) ? 0x2 : *colorBank;
*colorBank = (*luma < 16384) ? 0x3 : *colorBank;
*colorBank = (*luma < 8196) ? 0x203 : *colorBank; //Make really dark? use MSB shadow
}
inline void preclipping(vertex_t ** ptv, unsigned short * flip, unsigned short * pclp)
{
///////////////////////////////////////////
// *flipping polygon such that vertex 0 is on-screen, or disable pre-clipping
// Costs some CPU time, beware. Improves VDP1 performance, especially important for hi-res mode.
///////////////////////////////////////////
if( (ptv[0]->clipFlag & 12) ){ //Vertical *flip
//Incoming Arrangement:
// 0 - 1 ^
//-------- Edge | Y-
// 3 - 2 |
// ("12" is both Y- and Y+ exit. Why: Dual-plane polygons
ptv[4] = ptv[3]; ptv[3] = ptv[0]; ptv[0] = ptv[4];
ptv[4] = ptv[1]; ptv[1] = ptv[2]; ptv[2] = ptv[4];
*flip ^= 1<<5; //sprite *flip value [v *flip]
//Outgoing Arrangement:
// 3 - 2 ^
//-------- Edge | Y-
// 0 - 1 |
}
if( (ptv[0]->clipFlag & 3) ){//H *flip
//Incoming Arrangement:
// 0 | 1
// 3 | 2
// Edge ---> X+
// ("3" is both X+ and X- screen exit). Why: dual-plane polygons
ptv[4] = ptv[1]; ptv[1]=ptv[0]; ptv[0] = ptv[4];
ptv[4] = ptv[2]; ptv[2]=ptv[3]; ptv[3] = ptv[4];
*flip ^= 1<<4; //sprite *flip value [h *flip]
//Outgoing Arrangement:
// 1 | 0
// 2 | 3
// Edge ---> X+
return;
}
if( !((ptv[0]->clipFlag | ptv[1]->clipFlag | ptv[2]->clipFlag | ptv[3]->clipFlag) & SCRN_CLIP_FLAGS))
{
*pclp = VDP1_PRECLIPPING_DISABLE; //Preclipping Disable
return;
}
/*
//Alternate Clip Handling
// If NO CLIP FLAGS are high, disable preclipping.
// This improves VDP1 performance, at the cost of some CPU time.
ptv[0]->clipFlag |= ptv[1]->clipFlag | ptv[2]->clipFlag | ptv[3]->clipFlag;
if( !(ptv[0]->clipFlag & SCRN_CLIP_FLAGS) )
{
*pclp = 2048; //Preclipping Disable
return;
}
*/
//In case no pre-clipping is NOT disabled, write it as such.
*pclp = 0;
}
////////////////////////////
// Vertex clipping function helper
// This isn't much more complicated than it has to be.
////////////////////////////
inline void clipping(vertex_t * pnt, short useClip)
{
//Screen Clip Flags for on-off screen decimation
//No longer simplified....
pnt->clipFlag = ((pnt->pnt[X]) > vert_clip_x) ? SCRN_CLIP_X : 0;
pnt->clipFlag |= ((pnt->pnt[X]) < vert_clip_nx) ? SCRN_CLIP_NX : pnt->clipFlag;
pnt->clipFlag |= ((pnt->pnt[Y]) > vert_clip_y) ? SCRN_CLIP_Y : pnt->clipFlag;
pnt->clipFlag |= ((pnt->pnt[Y]) < vert_clip_ny) ? SCRN_CLIP_NY : pnt->clipFlag;
pnt->clipFlag ^= (useClip == USER_CLIP_OUTSIDE) ? pnt->clipFlag : 0; //Clip out/in setting
pnt->clipFlag |= ((pnt->pnt[Z]) <= NEAR_PLANE_DISTANCE) ? CLIP_Z : pnt->clipFlag;
}
////////////////////////////
// Setting User CLipping Coordinates
// Note the depth setting. Due to painter's algorithm, you must set the Z of your clipping coordinate *behind* what you want to clip.
// This is so the clipping coordinate will be processed before those polygons are, and thus effective.
// When clipping coordinates are set like this, you should take care to set new clipping coordinates carefully;
// Clipping coordinates shouldn't just be set to the very back; they should be set just behind everything you want to clip.
/*
However, the software does not manage the Z of the clipping region for vertices.
That is dependent on a portal system being implemented which can set vertex clipping by sector.
*/
// For standard resolutions, setting the clipping correctly is important for CPU performance, as it cuts down on commands sent.
// For hi-res mode, setting the clipping coordinates is mostly important for managing VDP1 performance.
// In that case, you can have a high-resolution interface off the side of the screen, and the game raster to a smaller area of it.
////////////////////////////
void setUserClippingAtDepth(int * topLeft, int * btmRight, int zDepthTgt)
{
int tl[2] = {topLeft[X], topLeft[Y]};
int br[2] = {btmRight[X], btmRight[Y]};
//Note: User clipping coordinates do not have to be within the screen, but it's a good idea to make them be.
//They do however need to be inside system clipping.
msh2SetCommand(tl, tl, br, br, 8 /* User Clipping Command Set */, 0 /*All other but Z ignored*/, 0, 0, 0, 0, zDepthTgt);
vert_clip_nx = topLeft[X] - TV_HALF_WIDTH;
vert_clip_x = btmRight[X] - TV_HALF_WIDTH;
vert_clip_ny = topLeft[Y] - TV_HALF_HEIGHT;
vert_clip_y = btmRight[Y] - TV_HALF_HEIGHT;
}
/*Complex Setting, 0: clip in system, 1: clip in user, 2: clip out user*/
//To use user-clipping, be sure to set the clipping area in advance.
void ssh2DrawModel(entity_t * ent) //Primary variable sorting rendering
{
if(ent->file_done != 1){return;}
drawn_entity_list[drawn_entity_count] = ent;
drawn_entity_count++;
//Recommended, for performance, that large entities be placed in HWRAM.
static MATRIX newMtx;
slMultiMatrix((POINT *)ent->prematrix);
slGetMatrix(newMtx);
static FIXED m0x[4];
static FIXED m1y[4];
static FIXED m2z[4];
m0x[0] = newMtx[X][X];
m0x[1] = newMtx[Y][X];
m0x[2] = newMtx[Z][X];
m0x[3] = newMtx[3][X];
m1y[0] = newMtx[X][Y];
m1y[1] = newMtx[Y][Y];
m1y[2] = newMtx[Z][Y];
m1y[3] = newMtx[3][Y];
m2z[0] = newMtx[X][Z];
m2z[1] = newMtx[Y][Z];
m2z[2] = newMtx[Z][Z];
m2z[3] = newMtx[3][Z];
GVPLY * model = ent->pol;
if ( (transVerts[0]+model->nbPoint) >= INTERNAL_MAX_VERTS) return;
if ( (transPolys[0]+model->nbPolygon) >= INTERNAL_MAX_POLY) return;
unsigned short usrClp = SYS_CLIPPING; //The clipping setting added to command table
if(ent->useClip == USER_CLIP_INSIDE)
{
//Clip inside the user clipping setting
usrClp = 0x400;
} else if(ent->useClip == USER_CLIP_OUTSIDE)
{
//Clip outside the user clipping setting
usrClp = 0x600;
}
VECTOR lightAngle = {0, -65535, 0};
VECTOR ambient_light = {0, -65535, 0};
int ambient_bright = 0;
int bright = 0;
if(ent->type != 'F') // 'F' for 'flat', no dynamic lighting applied.
{
bright = process_light(lightAngle, ambient_light, &ambient_bright, ent->prematrix, ent->type);
} else {
ambient_bright = active_lights[0].min_bright;
}
FIXED luma;
unsigned short colorBank;
int inverseZ = 0;
for (unsigned int i = 0; i < model->nbPoint; i++)
{
/**calculate z**/
ssh2VertArea[i].pnt[Z] = trans_pt_by_component(model->pntbl[i], m2z);
ssh2VertArea[i].pnt[Z] = (ssh2VertArea[i].pnt[Z] > NEAR_PLANE_DISTANCE) ? ssh2VertArea[i].pnt[Z] : NEAR_PLANE_DISTANCE;
/**Starts the division**/
SetFixDiv(scrn_dist, ssh2VertArea[i].pnt[Z]);
/**Calculates X and Y while waiting for screenDist/z **/
ssh2VertArea[i].pnt[Y] = trans_pt_by_component(model->pntbl[i], m1y);
ssh2VertArea[i].pnt[X] = trans_pt_by_component(model->pntbl[i], m0x);
/** Retrieves the result of the division **/
inverseZ = *DVDNTL;
/**Transform X and Y to screen space**/
ssh2VertArea[i].pnt[X] = fxm(ssh2VertArea[i].pnt[X], inverseZ)>>SCR_SCALE_X;
ssh2VertArea[i].pnt[Y] = fxm(ssh2VertArea[i].pnt[Y], inverseZ)>>SCR_SCALE_Y;
//Screen Clip Flags for on-off screen decimation
//No longer simplified....
clipping(&ssh2VertArea[i], ent->useClip);
}
transVerts[0] += model->nbPoint;
vertex_t * ptv[5] = {0, 0, 0, 0, 0};
unsigned short flip = 0;
unsigned short flags = 0;
unsigned short pclp = 0;
int zDepthTgt = 0;
/**POLYGON PROCESSING**/
for (unsigned int i = 0; i < model->nbPolygon; i++)
{
ptv[0] = &ssh2VertArea[model->pltbl[i].vertices[0]];
ptv[1] = &ssh2VertArea[model->pltbl[i].vertices[1]];
ptv[2] = &ssh2VertArea[model->pltbl[i].vertices[2]];
ptv[3] = &ssh2VertArea[model->pltbl[i].vertices[3]];
flags = model->attbl[i].render_data_flags;
flip = GET_FLIP_DATA(flags);
zDepthTgt = GET_SORT_DATA(flags);
//Components of screen-space cross-product used for backface culling.
//Vertice order hint:
// 0 - 1
// 3 - 2
//A cross-product can tell us if it's facing the screen. If it is not, we do not want it.
int cross0 = (ptv[1]->pnt[X] - ptv[3]->pnt[X])
* (ptv[0]->pnt[Y] - ptv[2]->pnt[Y]);
int cross1 = (ptv[1]->pnt[Y] - ptv[3]->pnt[Y])
* (ptv[0]->pnt[X] - ptv[2]->pnt[X]);
//Sorting target.
//Uses logic to determine sorting target per polygon. This costs some CPU time.
if( zDepthTgt == GV_SORT_MAX)
{
//Sorting target. Uses max.
zDepthTgt = JO_MAX(
JO_MAX(ptv[0]->pnt[Z], ptv[2]->pnt[Z]),
JO_MAX(ptv[1]->pnt[Z], ptv[3]->pnt[Z]));
} else if( zDepthTgt == GV_SORT_MIN)
{
//Sort Minimum
zDepthTgt = JO_MIN(
JO_MIN(ptv[0]->pnt[Z], ptv[2]->pnt[Z]),
JO_MIN(ptv[1]->pnt[Z], ptv[3]->pnt[Z]));
} else {
//Sorting target. Uses average of top-left and bottom-right.
zDepthTgt = (ptv[0]->pnt[Z] + ptv[2]->pnt[Z])>>1;
}
int offScrn = (ptv[0]->clipFlag & ptv[1]->clipFlag & ptv[2]->clipFlag & ptv[3]->clipFlag);
if((cross0 >= cross1 && (flags & GV_FLAG_SINGLE)) || zDepthTgt < NEAR_PLANE_DISTANCE || zDepthTgt > FAR_PLANE_DISTANCE ||
offScrn || ssh2SentPolys[0] >= MAX_SSH2_SENT_POLYS){ continue; }
//Pre-clipping Function
preclipping(ptv, &flip, &pclp);
//Lighting
luma = fxm(-(fxdot(model->nmtbl[i], lightAngle) + 32768), bright);
//We set the minimum luma as zero so the dynamic light does not corrupt the global light's basis.
luma = (bright < 0) ? ((luma > 0) ? 0 : luma) : ((luma < 0) ? 0 : luma);
luma += fxdot(model->nmtbl[i], ambient_light) + ambient_bright; //In normal "vision" however, bright light would do that..
//Use transformed normal as shade determinant
determine_colorbank(&colorBank, &luma);
//Shift the color bank code to the appropriate bits
colorBank<<=6;
//Added later: In case of a polyline (or really, any untextured command),
// the color for the draw command is defined by the draw command's "texno" or texture number data.
// this texture number data however is inserted in the wrong parts of the draw command to be the color.
// So here, we insert it into the correct place in the command table to be the drawn color.
unsigned short usedCMDCTRL = (flags & GV_FLAG_POLYLINE) ? VDP1_POLYLINE_CMDCTRL : VDP1_BASE_CMDCTRL;
colorBank += (usedCMDCTRL == VDP1_BASE_CMDCTRL) ? 0 : model->attbl[i].texno;
flags = (((flags & GV_FLAG_MESH)>>1) | ((flags & GV_FLAG_DARK)<<4))<<8;
ssh2SetCommand(ptv[0]->pnt, ptv[1]->pnt, ptv[2]->pnt, ptv[3]->pnt,
usedCMDCTRL | (flip), (VDP1_BASE_PMODE | flags | pclp | usrClp),
pcoTexDefs[model->attbl[i].texno].SRCA, colorBank, pcoTexDefs[model->attbl[i].texno].SIZE, 0, zDepthTgt);
} //Sort Max Endif
transPolys[0] += model->nbPolygon;
}
//Master SH2 drawing function (needs to be sorted after by slave)
void msh2DrawModel(entity_t * ent, MATRIX msMatrix, FIXED * lightSrc)
{
if(ent->file_done != 1){return;}
drawn_entity_list[drawn_entity_count] = ent;
drawn_entity_count++;
//Recommended, for performance, that large entities be placed in HWRAM.
/**WARNING: DO NOT USE SGL MATRIX SYSTEM FOR MASTER DRAWING**/
/*
SGL matrix pointer is uncached. Matrix operations will be confused between master/slave
You will have to come up with your own matrix system, it's not too bad ->
You can capture the matrix at the start of the frame instead, before the slave does any matrix ops
MSH2 + SSH2 drawing is not the ideal. In other words, using 1 CPU at full tap and then only if you must spill over to the second.
Diminishing returns might be a better phrase.
But there is no system here to do that. Using MSH2 does help; so perhaps throw a known quantity at it, rather than any dynamic entity list.
*/
static FIXED m0x[4];
static FIXED m1y[4];
static FIXED m2z[4];
m0x[0] = msMatrix[X][X];
m0x[1] = msMatrix[Y][X];
m0x[2] = msMatrix[Z][X];
m0x[3] = msMatrix[3][X];
m1y[0] = msMatrix[X][Y];
m1y[1] = msMatrix[Y][Y];
m1y[2] = msMatrix[Z][Y];
m1y[3] = msMatrix[3][Y];
m2z[0] = msMatrix[X][Z];
m2z[1] = msMatrix[Y][Z];
m2z[2] = msMatrix[Z][Z];
m2z[3] = msMatrix[3][Z];
GVPLY * model = ent->pol;
if ( (transVerts[0]+model->nbPoint) >= INTERNAL_MAX_VERTS) return;
if ( (transPolys[0]+model->nbPolygon) >= INTERNAL_MAX_POLY) return;
unsigned short usrClp = SYS_CLIPPING; //The clipping setting added to command table
if(ent->useClip == USER_CLIP_INSIDE)
{
//Clip inside the user clipping setting
usrClp = 0x400;
} else if(ent->useClip == USER_CLIP_OUTSIDE)
{
//Clip outside the user clipping setting
usrClp = 0x600;
}
FIXED luma;
unsigned short colorBank;
int inverseZ = 0;
for (unsigned int i = 0; i < model->nbPoint; i++)
{
/**calculate z**/
msh2VertArea[i].pnt[Z] = trans_pt_by_component(model->pntbl[i], m2z);
msh2VertArea[i].pnt[Z] = (msh2VertArea[i].pnt[Z] > NEAR_PLANE_DISTANCE) ? msh2VertArea[i].pnt[Z] : NEAR_PLANE_DISTANCE;
/**Starts the division**/
SetFixDiv(scrn_dist, msh2VertArea[i].pnt[Z]);
/**Calculates X and Y while waiting for screenDist/z **/
msh2VertArea[i].pnt[Y] = trans_pt_by_component(model->pntbl[i], m1y);
msh2VertArea[i].pnt[X] = trans_pt_by_component(model->pntbl[i], m0x);
/** Retrieves the result of the division **/
inverseZ = *DVDNTL;
/**Transform X and Y to screen space**/
msh2VertArea[i].pnt[X] = fxm(msh2VertArea[i].pnt[X], inverseZ)>>SCR_SCALE_X;
msh2VertArea[i].pnt[Y] = fxm(msh2VertArea[i].pnt[Y], inverseZ)>>SCR_SCALE_Y;
clipping(&msh2VertArea[i], ent->useClip);
}
transVerts[0] += model->nbPoint;
vertex_t * ptv[5] = {0, 0, 0, 0, 0};
unsigned short flip = 0;
unsigned short flags = 0;
unsigned short pclp = 0;
/**POLYGON PROCESSING**/
for (unsigned int i = 0; i < model->nbPolygon; i++)
{
ptv[0] = &msh2VertArea[model->pltbl[i].vertices[0]];
ptv[1] = &msh2VertArea[model->pltbl[i].vertices[1]];
ptv[2] = &msh2VertArea[model->pltbl[i].vertices[2]];
ptv[3] = &msh2VertArea[model->pltbl[i].vertices[3]];
flags = model->attbl[i].render_data_flags;
flip = GET_FLIP_DATA(flags);
//Components of screen-space cross-product used for backface culling.
//Vertice order hint:
// 0 - 1
// 3 - 2
//A cross-product can tell us if it's facing the screen. If it is not, we do not want it.
int cross0 = (ptv[1]->pnt[X] - ptv[3]->pnt[X])
* (ptv[0]->pnt[Y] - ptv[2]->pnt[Y]);
int cross1 = (ptv[1]->pnt[Y] - ptv[3]->pnt[Y])
* (ptv[0]->pnt[X] - ptv[2]->pnt[X]);
//Sorting target. Uses average of top-left and bottom-right.
//Adding logic to change sorting per-polygon can be done, but costs CPU time.
int zDepthTgt = JO_MAX(
JO_MAX(ptv[0]->pnt[Z], ptv[2]->pnt[Z]),
JO_MAX(ptv[1]->pnt[Z], ptv[3]->pnt[Z]));
int onScrn = (ptv[0]->clipFlag & ptv[1]->clipFlag & ptv[2]->clipFlag & ptv[3]->clipFlag);
if((cross0 >= cross1 && (flags & GV_FLAG_SINGLE)) || zDepthTgt < NEAR_PLANE_DISTANCE || zDepthTgt > FAR_PLANE_DISTANCE ||
onScrn || msh2SentPolys[0] >= MAX_MSH2_SENT_POLYS){ continue; }
//Pre-clipping Function
preclipping(ptv, &flip, &pclp);
//Transform the polygon's normal by light source vector
luma = fxdot(model->nmtbl[i], lightSrc);
//Use transformed normal as shade determinant
determine_colorbank(&colorBank, &luma);
//Shift the color bank code to the appropriate bits
colorBank<<=6;
//Added later: In case of a polyline (or really, any untextured command),
// the color for the draw command is defined by the draw command's "texno" or texture number data.
// this texture number data however is inserted in the wrong parts of the draw command to be the color.
// So here, we insert it into the correct place in the command table to be the drawn color.
unsigned short usedCMDCTRL = (flags & GV_FLAG_POLYLINE) ? VDP1_POLYLINE_CMDCTRL : VDP1_BASE_CMDCTRL;
colorBank += (usedCMDCTRL == VDP1_BASE_CMDCTRL) ? 0 : model->attbl[i].texno;
flags = (((flags & GV_FLAG_MESH)>>1) | ((flags & GV_FLAG_DARK)<<4))<<8;
msh2SetCommand(ptv[0]->pnt, ptv[1]->pnt, ptv[2]->pnt, ptv[3]->pnt,
usedCMDCTRL | (flip), (VDP1_BASE_PMODE | flags | pclp | usrClp),
pcoTexDefs[model->attbl[i].texno].SRCA, colorBank, pcoTexDefs[model->attbl[i].texno].SIZE, 0, zDepthTgt);
}
transPolys[0] += model->nbPolygon;
}
void ssh2DrawAnimation(animationControl * animCtrl, entity_t * ent, Bool transplant) //Draws animated model via SSH2
{
if(ent->file_done != 1){return;}
drawn_entity_list[drawn_entity_count] = ent;
drawn_entity_count++;
//WARNING:
//Once an entity is drawn animated, *all* instances of that entity must be drawn animated, or else they will not reset the pntbl appropriately.
static MATRIX newMtx;
slMultiMatrix((POINT *)ent->prematrix);
slGetMatrix(newMtx);
static FIXED m0x[4];
static FIXED m1y[4];
static FIXED m2z[4];
m0x[0] = newMtx[X][X];
m0x[1] = newMtx[Y][X];
m0x[2] = newMtx[Z][X];
m0x[3] = newMtx[3][X];
m1y[0] = newMtx[X][Y];
m1y[1] = newMtx[Y][Y];
m1y[2] = newMtx[Z][Y];
m1y[3] = newMtx[3][Y];
m2z[0] = newMtx[X][Z];
m2z[1] = newMtx[Y][Z];
m2z[2] = newMtx[Z][Z];
m2z[3] = newMtx[3][Z];
GVPLY * model = ent->pol;
if ( (transVerts[0]+model->nbPoint) >= INTERNAL_MAX_VERTS) return;
if ( (transPolys[0]+model->nbPolygon) >= INTERNAL_MAX_POLY) return;
unsigned short usrClp = SYS_CLIPPING; //The clipping setting added to command table
if(ent->useClip == USER_CLIP_INSIDE)
{
//Clip inside the user clipping setting
usrClp = 0x400;
} else if(ent->useClip == USER_CLIP_OUTSIDE)
{
//Clip outside the user clipping setting
usrClp = 0x600;
}
VECTOR lightAngle = {0, -65535, 0};
VECTOR ambient_light = {0, -65535, 0};
int ambient_bright = 0;
int bright = 0;
if(ent->type != 'F') // 'F' for 'flat', no dynamic lighting applied.
{
bright = process_light(lightAngle, ambient_light, &ambient_bright, ent->prematrix, ent->type);
} else {
ambient_bright = active_lights[0].min_bright;
}
FIXED luma;
unsigned short colorBank;
//Process for static pose change:
//1. Check if both animations are static poses [if arate of startFrm is 0 or if startFrm == endFrm]
//2. Set currentFrm to the AnimArea startFrm<<3
//3. Set uniforn to 0
//4. Set the local arate to 4
//5. Set currentKeyFrm to the AnimArea startFrm
//6. set the nextKeyFrame to the animCtrl startFrm
//7. Interpolate once
//8. Return all control data as if set from the animCtrl pose
Bool animation_change = (AnimArea[anims].startFrm != animCtrl->startFrm && AnimArea[anims].endFrm != animCtrl->endFrm) ? 1 : 0;
//
unsigned char localArate;
unsigned char nextKeyFrm;
int frDelta;
compVert * curKeyFrame;
compVert * nextKeyFrame;
/**Sets the animation data**/
///Variable interpolation set
localArate = animCtrl->arate[AnimArea[anims].currentKeyFrm];
AnimArea[anims].currentFrm += (localArate * framerate)>>1;
AnimArea[anims].currentKeyFrm = (AnimArea[anims].currentFrm>>3);
if (AnimArea[anims].currentKeyFrm >= AnimArea[anims].endFrm) {
AnimArea[anims].currentFrm -= (AnimArea[anims].endFrm - AnimArea[anims].startFrm)<<3;
AnimArea[anims].currentKeyFrm = AnimArea[anims].currentFrm>>3;
} else if(AnimArea[anims].currentKeyFrm < AnimArea[anims].startFrm){
AnimArea[anims].currentKeyFrm = AnimArea[anims].startFrm;
AnimArea[anims].currentFrm += (AnimArea[anims].endFrm-AnimArea[anims].startFrm)<<3;
}
nextKeyFrm = AnimArea[anims].currentKeyFrm+1;
if (nextKeyFrm >= AnimArea[anims].endFrm){
nextKeyFrm = AnimArea[anims].startFrm;
} else if (nextKeyFrm <= AnimArea[anims].startFrm){
nextKeyFrm = AnimArea[anims].startFrm+1;
}
if(animation_change == 1 && transplant != 1)
{
//For single-frame interpolation between poses
curKeyFrame = (compVert*)ent->animation[AnimArea[anims].currentKeyFrm]->cVert;
nextKeyFrame = (compVert*)ent->animation[animCtrl->startFrm]->cVert;
frDelta = 8;
} else {
//For interpolation inside keyframed animation
curKeyFrame = (compVert*)ent->animation[AnimArea[anims].currentKeyFrm]->cVert;
nextKeyFrame = (compVert*)ent->animation[nextKeyFrm]->cVert;
///Don't touch this! **absolute** frame delta
frDelta = (AnimArea[anims].currentFrm)-(AnimArea[anims].currentKeyFrm<<3);
}
//Animation Data
volatile Sint32 * dst = model->pntbl[0]; //This pointer is incremented by the animation interpolator.
short * src = curKeyFrame[0];
short * nxt = nextKeyFrame[0];
int inverseZ = 0;
for (unsigned int i = 0; i < model->nbPoint; i++)
{
/**Uncompress the vertices and apply linear interpolation**/
#pragma GCC push_options
#pragma GCC diagnostic ignored "-Wsequence-point"
*dst++=( *src + ((( *nxt++ - *src++) * frDelta)>>4))<<8;
*dst++=( *src + ((( *nxt++ - *src++) * frDelta)>>4))<<8;
*dst++=( *src + ((( *nxt++ - *src++) * frDelta)>>4))<<8;
#pragma GCC pop_options
/**calculate z**/
ssh2VertArea[i].pnt[Z] = trans_pt_by_component(model->pntbl[i], m2z);
ssh2VertArea[i].pnt[Z] = (ssh2VertArea[i].pnt[Z] > NEAR_PLANE_DISTANCE) ? ssh2VertArea[i].pnt[Z] : NEAR_PLANE_DISTANCE;
/**Starts the division**/
SetFixDiv(scrn_dist, ssh2VertArea[i].pnt[Z]);
/**Calculates X and Y while waiting for screenDist/z **/
ssh2VertArea[i].pnt[Y] = trans_pt_by_component(model->pntbl[i], m1y);
ssh2VertArea[i].pnt[X] = trans_pt_by_component(model->pntbl[i], m0x);
/** Retrieves the result of the division **/
inverseZ = *DVDNTL;
/**Transform X and Y to screen space**/
ssh2VertArea[i].pnt[X] = fxm(ssh2VertArea[i].pnt[X], inverseZ)>>SCR_SCALE_X;
ssh2VertArea[i].pnt[Y] = fxm(ssh2VertArea[i].pnt[Y], inverseZ)>>SCR_SCALE_Y;
//For animated models, CPU time is at a premium.
//Simplifying the clipping system specifically for animations might be worth.
clipping(&ssh2VertArea[i], ent->useClip);
}
transVerts[0] += model->nbPoint;
dst = (Sint32 *)&model->pltbl[0];
volatile Uint8 *src2 = ent->animation[AnimArea[anims].currentKeyFrm]->cNorm; //A new 1-byte src
VECTOR tNorm = {0, 0, 0};
vertex_t * ptv[5] = {0, 0, 0, 0, 0};
unsigned short flip = 0;
unsigned short flags = 0;
unsigned short pclp = 0;
/**POLYGON PROCESSING**/
for (unsigned int i = 0; i < model->nbPolygon; i++)
{
ptv[0] = &ssh2VertArea[model->pltbl[i].vertices[0]];
ptv[1] = &ssh2VertArea[model->pltbl[i].vertices[1]];
ptv[2] = &ssh2VertArea[model->pltbl[i].vertices[2]];
ptv[3] = &ssh2VertArea[model->pltbl[i].vertices[3]];
flags = model->attbl[i].render_data_flags;
flip = GET_FLIP_DATA(flags);