-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenderAnim.c
More file actions
609 lines (510 loc) · 22.1 KB
/
renderAnim.c
File metadata and controls
609 lines (510 loc) · 22.1 KB
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
#include <sl_def.h>
#include "def.h"
#include "mloader.h"
#include "mymath.h"
#include "render.h"
#include "anorm.h"
animationControl AnimArea[MAX_SIMULTANEOUS_ANIMATED_ENTITIES];
spriteAnimation spriteAnims[MAX_SIMULTANEOUS_SPRITE_ANIMATIONS];
//When an animated texture is assigned to an entity, it is always assigned by index.
//Rather than being indexed from another entity, animated textures are instead indexed into this list.
//The polygon's indexed texture number is entered into this list,
// and what is returned at that point in the list is assigned to that polygon.
// e.g. "attbl[i].texno = animated_texture_list[attbl[i].texno];" - BEFORE being offset by the entity's start texture.
// This happens if "attbl[i].render_data_flags & GV_FLAG_ANIM".
int animated_texture_list[MAX_SIMULTANEOUS_SPRITE_ANIMATIONS];
void clean_sprite_animations(void)
{
//
for(int i = 0; i < MAX_SIMULTANEOUS_SPRITE_ANIMATIONS; i++)
{
if(spriteAnims[i].lifetime < 0)
{
spriteAnims[i].lifetime = 0;
spriteAnims[i].modEnt = NULL;
} else if(spriteAnims[i].lifetime > 0)
{
spriteAnims[i].lifetime -= delta_time;
}
}
}
void operate_texture_animations(void)
{
GVPLY * model;
spriteAnimation * anim;
for(int i = 0; i < MAX_SIMULTANEOUS_SPRITE_ANIMATIONS; i++)
{
anim = &spriteAnims[i];
if(anim->lifetime > 0 && anim->modEnt != NULL)
{
model = anim->modEnt->pol;
anim->curFrm += framerate;
////////////////////////////////////////////////
// This was written after the polygon animation.
// Note that this is much simpler way of handling keyframed animation...
////////////////////////////////////////////////
if(anim->curFrm > anim->arates[anim->curKeyFrm])
{
anim->curKeyFrm++;
anim->curFrm = 0;
}
if(anim->curKeyFrm >= anim->endFrm)
{
anim->curKeyFrm = anim->startFrm;
}
//So to do this, right now, we need to check if the texno is between sprite sheet start/end.
for(unsigned int u = 0; u < model->nbPolygon; u++)
{
if(model->attbl[u].texno >= anim->sprite_sheet_start && model->attbl[u].texno < anim->sprite_sheet_end)
{
model->attbl[u].texno = anim->sprite_sheet_start + anim->curKeyFrm;
model->lumatbl[u] = anim->lumas[anim->curKeyFrm];
}
}
}
}
}
void start_texture_animation(spriteAnimation * anim, entity_t * ent)
{
if(ent->file_done != 1){return;}
//First loop: Check if this texture is already being animated on this entity.
//If it is, stop.
for(int i = 0; i < MAX_SIMULTANEOUS_SPRITE_ANIMATIONS; i++)
{
if(spriteAnims[i].lifetime != 0 &&
spriteAnims[i].sprite_sheet_start == anim->sprite_sheet_start &&
spriteAnims[i].modEnt == ent) return;
}
//Otherwise, try to find a free animation entry to work with.
for(int i = 0; i < MAX_SIMULTANEOUS_SPRITE_ANIMATIONS; i++)
{
if(!spriteAnims[i].lifetime)
{
spriteAnims[i].modEnt = ent;
spriteAnims[i].lifetime = anim->lifetime;
spriteAnims[i].sprite_sheet_start = anim->sprite_sheet_start;
spriteAnims[i].sprite_sheet_end = anim->sprite_sheet_end;
spriteAnims[i].curFrm = 0;
spriteAnims[i].curKeyFrm = 0;
spriteAnims[i].startFrm = anim->startFrm;
spriteAnims[i].endFrm = anim->endFrm;
spriteAnims[i].arates = anim->arates;
spriteAnims[i].lumas = anim->lumas;
break;
}
}
}
void msh2DrawAnimation(animationControl * animCtrl, entity_t * ent, Bool transplant, MATRIX * msMatrix) //Draws animated model via msh2
{
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 FIXED newMtx[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
fxMatrixMul(&msMatrix[0][0][0], ent->prematrix, &newMtx[0]);
static FIXED m0x[4];
static FIXED m1y[4];
static FIXED m2z[4];
//you.pos : Representing the core (initial) translation of the scene; could be avoided?
//ent->prematrix : Position of the object (matrix). Hmm. Isn't quite right.
m0x[3] = newMtx[9];
m1y[3] = newMtx[10];
m2z[3] = newMtx[11];
m0x[0] = newMtx[0];
m0x[1] = newMtx[1];
m0x[2] = newMtx[2];
m1y[0] = newMtx[3];
m1y[1] = newMtx[4];
m1y[2] = newMtx[5];
m2z[0] = newMtx[6];
m2z[1] = newMtx[7];
m2z[2] = newMtx[8];
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;
int cue = 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 curFrm to the AnimArea startFrm<<3
//3. Set uniforn to 0
//4. Set the local arate to 4
//5. Set curKeyFrm 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
int animation_change = (AnimArea[anims].startFrm != animCtrl->startFrm || AnimArea[anims].endFrm != animCtrl->endFrm) ? 1 : 0;
//
// Check to see if the animation matches, or if reset is enabled.
// In these cases, re-load information from the AnimCtrl.
if(animation_change == 1)
{
AnimArea[anims].curFrm = (animCtrl->startFrm<<ANIM_SHIFT);
AnimArea[anims].startFrm = animCtrl->startFrm;
AnimArea[anims].endFrm = animCtrl->endFrm;
}
static unsigned char localArate;
static unsigned char nextKeyFrm;
static int frDelta;
static compVert * curKeyFrame;
static compVert * nextKeyFrame;
/**Sets the animation data**/
///Variable interpolation set
localArate = animCtrl->arate[AnimArea[anims].curKeyFrm];
////
////
AnimArea[anims].curFrm += (localArate * framerate);
AnimArea[anims].curKeyFrm = (AnimArea[anims].curFrm>>ANIM_SHIFT);
// nbg_sprintf(3, 13, "frm(%i)", AnimArea[anims].curFrm);
// nbg_sprintf(3, 14, "kfr(%i)", AnimArea[anims].curKeyFrm);
if (AnimArea[anims].curKeyFrm > (AnimArea[anims].endFrm))
{
AnimArea[anims].curFrm -= ((AnimArea[anims].endFrm+1) - AnimArea[anims].startFrm)<<ANIM_SHIFT;
AnimArea[anims].curKeyFrm = AnimArea[anims].curFrm>>ANIM_SHIFT;
} else if(AnimArea[anims].curKeyFrm < AnimArea[anims].startFrm)
{
AnimArea[anims].curKeyFrm = AnimArea[anims].startFrm;
AnimArea[anims].curFrm += ((AnimArea[anims].endFrm+1)-AnimArea[anims].startFrm)<<ANIM_SHIFT;
}
nextKeyFrm = AnimArea[anims].curKeyFrm+1;
if (nextKeyFrm > (AnimArea[anims].endFrm))
{
nextKeyFrm = AnimArea[anims].startFrm;
} else if (nextKeyFrm <= AnimArea[anims].startFrm)
{
nextKeyFrm = AnimArea[anims].startFrm+1;
}
//For interpolation inside keyframed animation
curKeyFrame = (compVert*)ent->animation[AnimArea[anims].curKeyFrm]->cVert;
nextKeyFrame = (compVert*)ent->animation[nextKeyFrm]->cVert;
///Don't touch this! **absolute** frame delta
frDelta = (AnimArea[anims].curFrm)-(AnimArea[anims].curKeyFrm<<ANIM_SHIFT);
//Animation Data
//volatile Sint32 * dst = model->pntbl[0]; //This pointer is incremented by the animation interpolator.
volatile short * src = curKeyFrame[0];
volatile short * nxt = nextKeyFrame[0];
register int inverseZ = 0;
int near_plane = (ent->z_plane) ? SUPER_NEAR_PLANE : NEAR_PLANE_DISTANCE;
int wp[3];
//Get interpolation set vertex (first vertex)
#pragma GCC push_options
#pragma GCC diagnostic ignored "-Wsequence-point"
wp[X]=( *src + ((( *nxt++ - *src++) * frDelta)>>ANIM_SHIFT))<<8;
wp[Y]=( *src + ((( *nxt++ - *src++) * frDelta)>>ANIM_SHIFT))<<8;
wp[Z]=( *src + ((( *nxt++ - *src++) * frDelta)>>ANIM_SHIFT))<<8;
#pragma GCC pop_options
for(unsigned int i = 0; i < model->nbPoint; i++)
{
//Non-writeback animation interpolation/drawing
//Calcluate Z and start division
msh2VertArea[i].pnt[Z] = trans_pt_by_component(wp, m2z);
msh2VertArea[i].pnt[Z] = (msh2VertArea[i].pnt[Z] > near_plane) ? msh2VertArea[i].pnt[Z] : near_plane;
SetFixDiv(scrn_dist, msh2VertArea[i].pnt[Z]);
//Calculate X and Y while division happens
msh2VertArea[i].pnt[X] = trans_pt_by_component(wp, m0x);
msh2VertArea[i].pnt[Y] = trans_pt_by_component(wp, m1y);
//Get next vertex interpolated (also while division happens)
#pragma GCC push_options
#pragma GCC diagnostic ignored "-Wsequence-point"
wp[X]=( *src + ((( *nxt++ - *src++) * frDelta)>>ANIM_SHIFT))<<8;
wp[Y]=( *src + ((( *nxt++ - *src++) * frDelta)>>ANIM_SHIFT))<<8;
wp[Z]=( *src + ((( *nxt++ - *src++) * frDelta)>>ANIM_SHIFT))<<8;
#pragma GCC pop_options
//Get division result
inverseZ = *DVDNTL;
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;
//For animated models, CPU time is at a premium.
//Simplifying the clipping system specifically for animations might be worth.
clipping(&msh2VertArea[i], ent->useClip);
}
transVerts[0] += model->nbPoint;
volatile Uint8 *src2 = ent->animation[AnimArea[anims].curKeyFrm]->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] = &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 = (ptv[0]->pnt[Z] + ptv[2]->pnt[Z])>>1;
src2 += (i != 0) ? 1 : 0; //Add to compressed normal pointer address only after the first polygon
int offScrn = (ptv[0]->clipFlag & ptv[1]->clipFlag & ptv[2]->clipFlag & ptv[3]->clipFlag);
if((cross0 >= cross1 && (flags & GV_FLAG_SINGLE)) || zDepthTgt < near_plane || zDepthTgt > FAR_PLANE_DISTANCE || offScrn ||
msh2SentPolys[0] >= MAX_MSH2_SENT_POLYS){ continue; }
//Pre-clipping Function
preclipping(ptv, &flip, &pclp);
//New normals in from animation normal table // These are not written back to memory
tNorm[X]=ANORMS[*src2][X];
tNorm[Y]=ANORMS[*src2][Y];
tNorm[Z]=ANORMS[*src2][Z];
//Transform the polygon's normal by light source vector
luma = fxm(-(fxdot(tNorm, 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(tNorm, 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;
depth_cueing(&zDepthTgt, &cue);
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 | cue, pcoTexDefs[model->attbl[i].texno].SIZE, 0, zDepthTgt);
}
transPolys[0] += model->nbPolygon;
anims++; //Increment animation work area pointer
}
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;
int cue = 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 curFrm to the AnimArea startFrm<<3
//3. Set uniforn to 0
//4. Set the local arate to 4
//5. Set curKeyFrm 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
int animation_change = (AnimArea[anims].startFrm != animCtrl->startFrm || AnimArea[anims].endFrm != animCtrl->endFrm) ? 1 : 0;
//
// Check to see if the animation matches, or if reset is enabled.
// In these cases, re-load information from the AnimCtrl.
if(animation_change == 1)
{
AnimArea[anims].curFrm = (animCtrl->startFrm<<ANIM_SHIFT);
AnimArea[anims].startFrm = animCtrl->startFrm;
AnimArea[anims].endFrm = animCtrl->endFrm;
}
static unsigned char localArate;
static unsigned char nextKeyFrm;
static int frDelta;
static compVert * curKeyFrame;
static compVert * nextKeyFrame;
/**Sets the animation data**/
///Variable interpolation set
localArate = animCtrl->arate[AnimArea[anims].curKeyFrm];
////
////
AnimArea[anims].curFrm += (localArate * framerate);
AnimArea[anims].curKeyFrm = (AnimArea[anims].curFrm>>ANIM_SHIFT);
// nbg_sprintf(3, 13, "frm(%i)", AnimArea[anims].curFrm);
// nbg_sprintf(3, 14, "kfr(%i)", AnimArea[anims].curKeyFrm);
if (AnimArea[anims].curKeyFrm > (AnimArea[anims].endFrm))
{
AnimArea[anims].curFrm -= ((AnimArea[anims].endFrm+1) - AnimArea[anims].startFrm)<<ANIM_SHIFT;
AnimArea[anims].curKeyFrm = AnimArea[anims].curFrm>>ANIM_SHIFT;
} else if(AnimArea[anims].curKeyFrm < AnimArea[anims].startFrm)
{
AnimArea[anims].curKeyFrm = AnimArea[anims].startFrm;
AnimArea[anims].curFrm += ((AnimArea[anims].endFrm+1)-AnimArea[anims].startFrm)<<ANIM_SHIFT;
}
nextKeyFrm = AnimArea[anims].curKeyFrm+1;
if (nextKeyFrm > (AnimArea[anims].endFrm))
{
nextKeyFrm = AnimArea[anims].startFrm;
} else if (nextKeyFrm <= AnimArea[anims].startFrm)
{
nextKeyFrm = AnimArea[anims].startFrm+1;
}
//For interpolation inside keyframed animation
curKeyFrame = (compVert*)ent->animation[AnimArea[anims].curKeyFrm]->cVert;
nextKeyFrame = (compVert*)ent->animation[nextKeyFrm]->cVert;
///Don't touch this! **absolute** frame delta
frDelta = (AnimArea[anims].curFrm)-(AnimArea[anims].curKeyFrm<<ANIM_SHIFT);
//Animation Data
//volatile Sint32 * dst = model->pntbl[0]; //This pointer is incremented by the animation interpolator.
volatile short * src = curKeyFrame[0];
volatile short * nxt = nextKeyFrame[0];
register int inverseZ = 0;
int near_plane = (ent->z_plane) ? SUPER_NEAR_PLANE : NEAR_PLANE_DISTANCE;
int wp[3];
//Get interpolation set vertex (first vertex)
#pragma GCC push_options
#pragma GCC diagnostic ignored "-Wsequence-point"
wp[X]=( *src + ((( *nxt++ - *src++) * frDelta)>>ANIM_SHIFT))<<8;
wp[Y]=( *src + ((( *nxt++ - *src++) * frDelta)>>ANIM_SHIFT))<<8;
wp[Z]=( *src + ((( *nxt++ - *src++) * frDelta)>>ANIM_SHIFT))<<8;
#pragma GCC pop_options
for(unsigned int i = 0; i < model->nbPoint; i++)
{
//Non-writeback animation interpolation/drawing
//Calcluate Z and start division
ssh2VertArea[i].pnt[Z] = trans_pt_by_component(wp, m2z);
ssh2VertArea[i].pnt[Z] = (ssh2VertArea[i].pnt[Z] > near_plane) ? ssh2VertArea[i].pnt[Z] : near_plane;
SetFixDiv(scrn_dist, ssh2VertArea[i].pnt[Z]);
//Calculate X and Y while division happens
ssh2VertArea[i].pnt[X] = trans_pt_by_component(wp, m0x);
ssh2VertArea[i].pnt[Y] = trans_pt_by_component(wp, m1y);
//Get next vertex interpolated (also while division happens)
#pragma GCC push_options
#pragma GCC diagnostic ignored "-Wsequence-point"
wp[X]=( *src + ((( *nxt++ - *src++) * frDelta)>>ANIM_SHIFT))<<8;
wp[Y]=( *src + ((( *nxt++ - *src++) * frDelta)>>ANIM_SHIFT))<<8;
wp[Z]=( *src + ((( *nxt++ - *src++) * frDelta)>>ANIM_SHIFT))<<8;
#pragma GCC pop_options
//Get division result
inverseZ = *DVDNTL;
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;
volatile Uint8 *src2 = ent->animation[AnimArea[anims].curKeyFrm]->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);
//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 = (ptv[0]->pnt[Z] + ptv[2]->pnt[Z])>>1;
src2 += (i != 0) ? 1 : 0; //Add to compressed normal pointer address only after the first polygon
int offScrn = (ptv[0]->clipFlag & ptv[1]->clipFlag & ptv[2]->clipFlag & ptv[3]->clipFlag);
if((cross0 >= cross1 && (flags & GV_FLAG_SINGLE)) || zDepthTgt < near_plane || zDepthTgt > FAR_PLANE_DISTANCE || offScrn ||
ssh2SentPolys[0] >= MAX_SSH2_SENT_POLYS){ continue; }
//Pre-clipping Function
preclipping(ptv, &flip, &pclp);
//New normals in from animation normal table // These are not written back to memory
tNorm[X]=ANORMS[*src2][X];
tNorm[Y]=ANORMS[*src2][Y];
tNorm[Z]=ANORMS[*src2][Z];
//Transform the polygon's normal by light source vector
luma = fxm(-(fxdot(tNorm, 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(tNorm, 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;
depth_cueing(&zDepthTgt, &cue);
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 | cue, pcoTexDefs[model->attbl[i].texno].SIZE, 0, zDepthTgt);
}
transPolys[0] += model->nbPolygon;
anims++; //Increment animation work area pointer
}