Skip to content

Commit 8651e2f

Browse files
committed
- optimize & fix broken light pools on emscripten version
1 parent 4e3fdf4 commit 8651e2f

3 files changed

Lines changed: 105 additions & 123 deletions

File tree

src_rebuild/Game/C/debris.c

Lines changed: 98 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -348,14 +348,6 @@ short gRainAlloc[MAX_RAIN_DROPS];
348348

349349
RAIN_TYPE gRain[MAX_RAIN_DROPS];
350350

351-
char PoolPrimData[16] = {
352-
353-
0x0, 0x8, 0x2, 0x9,
354-
0x8, 0x1, 0x9, 0x3,
355-
0x4, 0xA, 0x6, 0xB,
356-
0xA, 0x5, 0xB, 0x7
357-
};
358-
359351
int LightSortCorrect = 0;
360352

361353
TEXTURE_DETAILS smoke_texture;
@@ -420,20 +412,19 @@ void PlacePoolForCar(CAR_DATA *cp, CVECTOR *col, int front, int in_car)
420412
short brightness;
421413
POLY_FT4 *poly;
422414
int i;
423-
SVECTOR s[27];
424-
SVECTOR sout[27];
425-
VECTOR s1[12];
415+
SVECTOR s[12];
416+
SVECTOR s1[12];
426417
VECTOR mid_position;
427418
VECTOR toss;
428-
VECTOR *pos;
419+
VECTOR pos;
429420
CAR_COSMETICS* car_cos;
430421
CVECTOR color;
431422
int Z;
432423
int sub_level;
433424
int car_road_height;
434425
int count;
435426

436-
pos = (VECTOR*)cp->hd.where.t;
427+
pos = *(VECTOR*)cp->hd.where.t;
437428
car_cos = &car_cosmetics[cp->ap.model];
438429

439430
// [A] there was check that prevented in_car lights in game, but it was working in quick replays...
@@ -469,8 +460,6 @@ void PlacePoolForCar(CAR_DATA *cp, CVECTOR *col, int front, int in_car)
469460
s1[11].vz = s1[9].vz;
470461

471462
LightSortCorrect = -800;
472-
473-
sub_level = 3;
474463
}
475464
else
476465
{
@@ -493,13 +482,14 @@ void PlacePoolForCar(CAR_DATA *cp, CVECTOR *col, int front, int in_car)
493482
s1[10].vz = s1[8].vz;
494483
s1[11].vz = s1[3].vz;
495484

496-
sub_level = 3;
497-
498485
if (player[CurrentPlayerView].cameraView == 2 && cp == &car_data[player[CurrentPlayerView].playerCarId])
499486
LightSortCorrect = -320;
500487
else
501488
LightSortCorrect = -200;
502489
}
490+
491+
sub_level = 3;
492+
count = 12;
503493
}
504494
else
505495
{
@@ -513,152 +503,148 @@ void PlacePoolForCar(CAR_DATA *cp, CVECTOR *col, int front, int in_car)
513503
s1[1].vz = s1[3].vz + 204;
514504

515505
sub_level = 0;
506+
count = 4;
516507
}
517508

518509
s1[0].vz = s1[1].vz;
519510
s1[2].vz = s1[3].vz;
520511

521512
SetRotMatrix(&cp->hd.drawCarMat);
513+
SetVec(&mid_position, 0, 0, -500);
522514

523-
mid_position.vx = 0;
524-
mid_position.vy = 0;
525-
mid_position.vz = -500;
526-
527-
_MatrixRotate(&mid_position);
528-
529-
mid_position.vx += pos->vx;
530-
mid_position.vy += pos->vy;
531-
mid_position.vz += pos->vz;
515+
gte_ldlv0(&mid_position);
516+
gte_rtv0();
517+
gte_stlvnl(&mid_position);
518+
VecAdd(&mid_position, &mid_position, &pos);
532519

533520
car_road_height = MapHeight(&mid_position);
534-
535-
if (sub_level == 3)
536-
count = 12;
537-
else
538-
count = 4;
539521

540522
// adjust height and poisition for each vertex
541523
for(i = 0; i < count; i++)
542524
{
543525
int temp_y;
544526

545527
s1[i].vy = 0;
546-
_MatrixRotate(&s1[i]);
547-
548-
toss.vx = s1[i].vx + pos->vx;
549-
toss.vy = s1[i].vy + pos->vy;
550-
toss.vz = s1[i].vz + pos->vz;
551-
552-
s[i].vx = toss.vx - camera_position.vx;
553-
s[i].vz = toss.vz - camera_position.vz;
528+
gte_ldv0(&s1[i]);
529+
gte_rtv0();
530+
gte_stlvnl(&toss);
554531

532+
VecAdd(&toss, &toss, &pos);
533+
toss.vy += 200;
555534
temp_y = MapHeight(&toss);
556535

557536
if (ABS(-temp_y + car_road_height) > 500)
558537
s[i].vy = -car_road_height - camera_position.vy;
559538
else
560539
s[i].vy = -temp_y - camera_position.vy;
540+
s[i].vx = toss.vx - camera_position.vx;
541+
s[i].vz = toss.vz - camera_position.vz;
561542
}
562543

563544
if (FIXEDH(s[0].vy * s[1].vz - s[0].vz * s[1].vy) * s[2].vx +
564545
FIXEDH(s[0].vz * s[1].vx - s[0].vx * s[1].vz) * s[2].vy +
565-
FIXEDH(s[0].vx * s[1].vy - s[0].vy * s[1].vx) * s[2].vz >= 0)
546+
FIXEDH(s[0].vx * s[1].vy - s[0].vy * s[1].vx) * s[2].vz < 0)
566547
{
567-
gte_SetRotMatrix(&inv_camera_matrix);
568-
gte_SetTransVector(&dummy);
548+
return;
549+
}
569550

570-
if (sub_level == 0)
571-
{
572-
gte_ldv3(&s[0], &s[1], &s[2]);
573-
gte_rtpt();
551+
gte_SetRotMatrix(&inv_camera_matrix);
552+
gte_SetTransVector(&dummy);
574553

575-
gte_stszotz(&Z);
554+
if (sub_level == 0)
555+
{
556+
gte_ldv3(&s[0], &s[1], &s[2]);
557+
gte_rtpt();
576558

577-
if (Z > 40)
578-
Z -= 40;
559+
gte_stszotz(&Z);
579560

580-
if (Z > 49)
581-
{
582-
poly = (POLY_FT4 *)current->primptr;
561+
if (Z > 40)
562+
Z -= 40;
583563

584-
// [A] Emit poly only after ot z checked
585-
setPolyFT4(poly);
586-
setSemiTrans(poly, 1);
564+
if (Z > 49)
565+
{
566+
poly = (POLY_FT4 *)current->primptr;
587567

588-
*(ushort*)&poly->u0 = *(ushort*)&light_pool_texture.coords.u0;
589-
*(ushort*)&poly->u1 = *(ushort*)&light_pool_texture.coords.u1;
590-
*(ushort*)&poly->u2 = *(ushort*)&light_pool_texture.coords.u2;
591-
*(ushort*)&poly->u3 = *(ushort*)&light_pool_texture.coords.u3;
568+
gte_stsxy3(&poly->x0, &poly->x1, &poly->x2);
592569

593-
poly->r0 = col->r / 2;
594-
poly->g0 = col->g / 2;
595-
poly->b0 = col->b / 2;
570+
// [A] Emit poly only after ot z checked
571+
setPolyFT4(poly);
572+
setSemiTrans(poly, 1);
596573

597-
gte_stsxy3(&poly->x0, &poly->x1, &poly->x2);
574+
*(ushort*)&poly->u0 = *(ushort*)&light_pool_texture.coords.u0;
575+
*(ushort*)&poly->u1 = *(ushort*)&light_pool_texture.coords.u1;
576+
*(ushort*)&poly->u2 = *(ushort*)&light_pool_texture.coords.u2;
577+
*(ushort*)&poly->u3 = *(ushort*)&light_pool_texture.coords.u3;
598578

599-
poly->tpage = light_pool_texture.tpageid | 0x20;
600-
poly->clut = light_pool_texture.clutid;
579+
poly->r0 = col->r / 2;
580+
poly->g0 = col->g / 2;
581+
poly->b0 = col->b / 2;
582+
poly->tpage = light_pool_texture.tpageid | 0x20;
583+
poly->clut = light_pool_texture.clutid;
601584

602-
gte_ldv0(&s[3]);
603-
gte_rtps();
604-
gte_stsxy(&poly->x3);
585+
gte_ldv0(&s[3]);
586+
gte_rtps();
587+
gte_stsxy(&poly->x3);
605588

606-
addPrim(current->ot + (Z >> 1), poly);
607-
current->primptr += sizeof(POLY_FT4);
608-
}
589+
addPrim(current->ot + (Z >> 1), poly);
590+
current->primptr += sizeof(POLY_FT4);
609591
}
610-
else if (sub_level == 3)
592+
}
593+
else if (sub_level == 3)
594+
{
595+
for(i = 0; i < 12; i++)
611596
{
612-
for(i = 0; i < 12; i++)
613-
{
614-
gte_ldv0(&s[i]);
615-
gte_rtv0tr();
616-
gte_stsv(&sout[i]);
617-
}
597+
gte_ldv0(&s[i]);
598+
gte_rtv0tr();
599+
gte_stsv(&s[i]);
600+
}
618601

619-
// draw front light quads
620-
for(i = 0; i < 4; i++)
621-
{
622-
char* VertIdx;
623-
624-
VertIdx = PoolPrimData + i * 4;
602+
static char PoolPrimData[16] = {
603+
0, 8, 2, 9,
604+
8, 1, 9, 3,
605+
4, 10, 6, 11,
606+
10, 5, 11, 7
607+
};
625608

626-
gte_SetRotMatrix(&identity);
627-
gte_SetTransVector(&dummy);
609+
gte_SetRotMatrix(&identity);
610+
gte_SetTransVector(&dummy);
628611

629-
if (i & 2)
630-
brightness = LeftLight + LeftLight * 4;
631-
else
632-
brightness = RightLight + RightLight * 4;
612+
// draw front light quads
613+
for(i = 0; i < 4; i++)
614+
{
615+
char* VertIdx;
616+
VertIdx = PoolPrimData + i * 4;
633617

634-
if (brightness)
635-
{
636-
int test = col->r * brightness;
618+
if (i & 2)
619+
brightness = LeftLight + LeftLight * 4;
620+
else
621+
brightness = RightLight + RightLight * 4;
637622

638-
color.r = MIN(255, col->r * brightness >> 4);
639-
color.g = MIN(255, col->g * brightness >> 4);
640-
color.b = MIN(255, col->b * brightness >> 4);
623+
if (brightness)
624+
{
625+
color.r = MIN(255, col->r * brightness >> 4);
626+
color.g = MIN(255, col->g * brightness >> 4);
627+
color.b = MIN(255, col->b * brightness >> 4);
641628

642-
if (i & 1)
643-
{
644-
sQuad(sout + VertIdx[0],
645-
sout + VertIdx[2],
646-
sout + VertIdx[3],
647-
sout + VertIdx[1], &color, LightSortCorrect);
648-
}
649-
else
650-
{
651-
sQuad(sout + VertIdx[1],
652-
sout + VertIdx[3],
653-
sout + VertIdx[2],
654-
sout + VertIdx[0], &color, LightSortCorrect);
655-
}
629+
if (i & 1)
630+
{
631+
sQuad(s + VertIdx[0],
632+
s + VertIdx[2],
633+
s + VertIdx[3],
634+
s + VertIdx[1], &color, LightSortCorrect);
635+
}
636+
else
637+
{
638+
sQuad(s + VertIdx[1],
639+
s + VertIdx[3],
640+
s + VertIdx[2],
641+
s + VertIdx[0], &color, LightSortCorrect);
656642
}
657643
}
658644
}
659-
660-
LightSortCorrect = -10;
661645
}
646+
647+
LightSortCorrect = -10;
662648
}
663649

664650
// [D] [T]

src_rebuild/Game/C/shadow.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -827,13 +827,6 @@ void sQuad(SVECTOR *v0, SVECTOR *v1, SVECTOR *v2, SVECTOR *v3, CVECTOR* light_co
827827
else
828828
#endif
829829
{
830-
gte_ldv3(v0, v1, v3);
831-
832-
gte_rtpt();
833-
834-
setPolyG4(poly);
835-
setSemiTrans(poly, 1);
836-
837830
poly->r1 = light_col->r;
838831
poly->g1 = light_col->g;
839832
poly->b1 = light_col->b;
@@ -849,17 +842,20 @@ void sQuad(SVECTOR *v0, SVECTOR *v1, SVECTOR *v2, SVECTOR *v3, CVECTOR* light_co
849842
poly->r3 = 0;
850843
poly->g3 = 0;
851844
poly->b3 = 0;
845+
846+
gte_ldv3(v0, v1, v3);
847+
gte_rtpt();
852848

853-
gte_stsxy3(&poly->x0, &poly->x1, &poly->x2);
849+
setPolyG4(poly);
850+
setSemiTrans(poly, 1);
854851

852+
gte_stsxy3(&poly->x0, &poly->x1, &poly->x2);
855853
gte_stsz3(&z[0], &z[1], &z[2]);
856854

857855
gte_ldv0(v2);
858-
859856
gte_rtps();
860857

861858
gte_stsxy(&poly->x3);
862-
863859
gte_stsz(&z[3]);
864860

865861
z1 = (z[0] + z[1] + z[2] + z[3] >> 2) + LightSortCorrect;

src_rebuild/PsyCross

0 commit comments

Comments
 (0)