Merge pull request #51 from SoapyMan/develop-SoapyMan

Develop soapy man
This commit is contained in:
Ilya 2020-10-29 19:58:16 +06:00 committed by GitHub
commit a4bcdf43ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 167 additions and 163 deletions

View File

@ -1414,19 +1414,19 @@ VECTOR* ApplyRotMatrixLV(VECTOR* v0, VECTOR* v1)
gte_rtir();
if (tmpLO.vx < 0)
tmpLO.vx = tmpLO.vx * 8;
tmpLO.vx *= 8;
else
tmpLO.vx = tmpLO.vx << 3;
tmpLO.vx <<= 3;
if (tmpLO.vy < 0)
tmpLO.vy = tmpLO.vy * 8;
tmpLO.vy *= 8;
else
tmpLO.vy = tmpLO.vy << 3;
tmpLO.vy <<= 3;
if (tmpLO.vz < 0)
tmpLO.vz = tmpLO.vz * 8;
tmpLO.vz *= 8;
else
tmpLO.vz = tmpLO.vz << 3;
tmpLO.vz <<= 3;
gte_stlvnl(&tmpHI);
@ -1474,6 +1474,7 @@ VECTOR* ApplyMatrixLV(MATRIX* m, VECTOR* v0, VECTOR* v1)
MATRIX* RotMatrix(struct SVECTOR* r, MATRIX* m)
{
// correct Psy-Q implementation
int c0, c1, c2;
int s0, s1, s2;
int s2p0, s2m0, c2p0, c2m0;
@ -1509,80 +1510,40 @@ MATRIX* RotMatrix(struct SVECTOR* r, MATRIX* m)
MATRIX* RotMatrixYXZ(struct SVECTOR* r, MATRIX* m)
{
int iVar1;
int iVar2;
short sVar3;
int uVar4;
int iVar5;
int iVar6;
int iVar7;
int iVar8;
// correct Psy-Q implementation
int c0, c1, c2;
int s0, s1, s2;
uVar4 = (r->vx);
c0 = rcos(r->vx);
c1 = rcos(r->vy);
c2 = rcos(r->vz);
s0 = rsin(r->vx);
s1 = rsin(r->vy);
s2 = rsin(r->vz);
if (uVar4 < 0)
{
iVar6 = *(int*)(rcossin_tbl + (-uVar4 & 0xfff) * 2);
sVar3 = iVar6;
iVar5 = -sVar3;
}
else
{
iVar6 = *(int*)(rcossin_tbl + (uVar4 & 0xfff) * 2);
iVar5 = iVar6;
sVar3 = -iVar6;
}
// Y-axis
m->m[1][0] = FIXED(s2 * c0);
m->m[1][1] = FIXED(c2 * c0);
m->m[1][2] = -s0;
iVar6 = iVar6 >> 0x10;
uVar4 = (r->vy);
// X-axis
int x0 = FIXED(s1 * s0);
m->m[0][0] = FIXED(c1 * c2) + FIXED(x0 * s2);
m->m[0][1] = FIXED(x0 * c2) - FIXED(c1 * s2);
m->m[0][2] = FIXED(s1 * c0);
if (uVar4 < 0)
{
iVar7 = *(int*)(rcossin_tbl + (-uVar4 & 0xfff) * 2);
iVar1 = -iVar7;
}
else
{
iVar7 = *(int*)(rcossin_tbl + (uVar4 & 0xfff) * 2);
iVar1 = iVar7;
}
iVar7 = iVar7 >> 0x10;
uVar4 = (r->vz);
m->m[1][2] = sVar3;
m->m[0][2] = FIXED(iVar1 * iVar6);
sVar3 = FIXED(iVar7 * iVar6);
if (uVar4 < 0)
{
m->m[2][2] = sVar3;
iVar8 = *(int*)(rcossin_tbl + (-uVar4 & 0xfff) * 2);
iVar2 = -iVar8;
}
else
{
m->m[2][2] = sVar3;
iVar8 = *(int*)(rcossin_tbl + (uVar4 & 0xfff) * 2);
iVar2 = iVar8;
}
iVar8 = iVar8 >> 0x10;
m->m[1][0] = FIXED(iVar2 * iVar6);
m->m[1][1] = FIXED(iVar8 * iVar6);
iVar6 = FIXED(iVar1 * iVar5);
m->m[0][0] = FIXED(iVar7 * iVar8) + FIXED(iVar6 * iVar2);
m->m[0][1] = FIXED(iVar6 * iVar8) - FIXED(iVar7 * iVar2);
iVar5 = FIXED(iVar7 * iVar5);
m->m[2][1] = FIXED(iVar1 * iVar2) + FIXED(iVar5 * iVar8);
m->m[2][0] = FIXED(iVar5 * iVar2) - FIXED(iVar1 * iVar8);
// Z-axis
int z0 = FIXED(c1 * s0);
m->m[2][1] = FIXED(s1 * s2) + FIXED(z0 * c2);
m->m[2][0] = FIXED(z0 * s2) - FIXED(s1 * c2);
m->m[2][2] = FIXED(c1 * c0);
return m;
}
MATRIX* RotMatrixX(long r, MATRIX* m)
{
// correct Psy-Q implementation
int s0 = rsin(r);
int c0 = rcos(r);
int t1, t2;
@ -1604,6 +1565,7 @@ MATRIX* RotMatrixX(long r, MATRIX* m)
MATRIX* RotMatrixY(long r, MATRIX* m)
{
// correct Psy-Q implementation
int s0 = rsin(r);
int c0 = rcos(r);
int t1, t2;
@ -1625,6 +1587,7 @@ MATRIX* RotMatrixY(long r, MATRIX* m)
MATRIX* RotMatrixZ(long r, MATRIX* m)
{
// correct Psy-Q implementation
int s0 = rsin(r);
int c0 = rcos(r);
int t1, t2;
@ -1647,9 +1610,8 @@ MATRIX* RotMatrixZ(long r, MATRIX* m)
MATRIX* RotMatrixZYX_gte(SVECTOR* r, MATRIX* m)
{
#if 0
// TODO:...
// TODO: correct Psy-Q implementation
#else
// FIXME: make a proper function
m->m[0][0] = 0x1000;
m->m[0][1] = 0;
m->m[0][2] = 0;
@ -1713,29 +1675,23 @@ void SetFogNear(long a, long h)
int rsin(int a)
{
if (a < 0)
return -rcossin_tbl[(-a & 0xfffU) * 2];
//if (a < 0) // really not needed; bit mask does it all
// return -rcossin_tbl[(-a & 0xfffU) * 2];
return rcossin_tbl[(a & 0xfffU) * 2];
}
int rcos(int a)
{
if (a < 0)
return rcossin_tbl[(-a & 0xfffU) * 2 + 1];
//if (a < 0) // really not needed; bit mask does it all
// return rcossin_tbl[(-a & 0xfffU) * 2 + 1];
return rcossin_tbl[(a & 0xfffU) * 2 + 1];
}
long ratan2(long y, long x)
{
#if 0 // don't use it
const double ONE_BY_2048 = 1.0 / 2048;
const double CONV = 2048.0 / M_PI;
float real = atan2(double(y) * ONE_BY_2048, double(x) * ONE_BY_2048);
return real * CONV;
#else
// correct Psy-Q implementation
long v;
ulong ang;
@ -1777,14 +1733,11 @@ long ratan2(long y, long x)
v = -v;
return v;
#endif
}
long SquareRoot0(long a)
{
#if 0
return sqrtl(a);
#else
// correct Psy-Q implementation
int idx;
int lzcs;
lzcs = gte_leadingzerocount(a);
@ -1800,5 +1753,4 @@ long SquareRoot0(long a)
idx = a << (lzcs - 24);
return SQRT[idx - 64] << (31 - lzcs >> 1) >> 12;
#endif
}

View File

@ -24,19 +24,26 @@ void Apply_Inv_CameraMatrix(VECTOR *v)
int Apply_InvCameraMatrixSetTrans(VECTOR_NOPAD *pos)
{
VECTOR vfc;
VECTOR vec;
VECTOR local;
gte_stfc(&vfc);
VECTOR local;
local.vx = (pos->vx - vfc.vx);// *0x10000 >> 0x10;
local.vy = (pos->vy - vfc.vy);// *0x10000 >> 0x10;
local.vz = (pos->vz - vfc.vz);// *0x10000 >> 0x10;
local.vx = (pos->vx - vfc.vx) << 0x10 >> 0x10;
local.vy = (pos->vy - vfc.vy) << 0x10 >> 0x10;
local.vz = (pos->vz - vfc.vz) << 0x10 >> 0x10;
#if 0
gte_ldlvl(&local);
gte_lcir();
VECTOR vec;
gte_stlvl(&vec);
#else
MATRIX lc;
gte_ReadColorMatrix(&lc);
vec.vx = FIXED(lc.m[0][0] * local.vx + lc.m[0][1] * local.vy + lc.m[0][2] * local.vz);
vec.vy = FIXED(lc.m[1][0] * local.vx + lc.m[1][1] * local.vy + lc.m[1][2] * local.vz);
vec.vz = FIXED(lc.m[2][0] * local.vx + lc.m[2][1] * local.vy + lc.m[2][2] * local.vz);
#endif
gte_SetTransVector(&vec);
if (vec.vx >> 1 < 0)
@ -49,23 +56,32 @@ int Apply_InvCameraMatrixSetTrans(VECTOR_NOPAD *pos)
int Apply_InvCameraMatrixAndSetMatrix(VECTOR_NOPAD *pos, MATRIX2 *mtx)
{
VECTOR vfc;
VECTOR vec;
VECTOR local;
gte_stfc(&vfc);
VECTOR local;
local.vx = (pos->vx - vfc.vx);// *0x10000 >> 0x10;
local.vy = (pos->vy - vfc.vy);// *0x10000 >> 0x10;
local.vz = (pos->vz - vfc.vz);// *0x10000 >> 0x10;
gte_ldlvl(&local);
local.vx = (pos->vx - vfc.vx) << 0x10 >> 0x10;
local.vy = (pos->vy - vfc.vy) << 0x10 >> 0x10;
local.vz = (pos->vz - vfc.vz) << 0x10 >> 0x10;
#if 0
gte_ldlvl(&local);
gte_lcir();
gte_stlvl(&vec);
#else
MATRIX lc;
gte_ReadColorMatrix(&lc);
vec.vx = FIXED(lc.m[0][0] * local.vx + lc.m[0][1] * local.vy + lc.m[0][2] * local.vz);
vec.vy = FIXED(lc.m[1][0] * local.vx + lc.m[1][1] * local.vy + lc.m[1][2] * local.vz);
vec.vz = FIXED(lc.m[2][0] * local.vx + lc.m[2][1] * local.vy + lc.m[2][2] * local.vz);
#endif
gte_SetRotMatrix(mtx);
VECTOR vec;
gte_stlvl(&vec);
gte_SetTransVector(&vec);
if (vec.vx >> 1 < 0)
return vec.vz - vec.vx;
@ -78,9 +94,9 @@ extern MATRIX frustrum_matrix;
int FrustrumCheck16(PACKED_CELL_OBJECT *pcop, int bounding_sphere)
{
VECTOR local;
local.vx = (pcop->pos.vx - camera_position.vx) * 0x10000 >> 0x11;
local.vy = (pcop->pos.vy - camera_position.vy) * 0x10000 >> 0x11;
local.vz = (pcop->pos.vz - camera_position.vz) * 0x10000 >> 0x11;
local.vx = (pcop->pos.vx - camera_position.vx) << 0x10 >> 0x11;
local.vy = (pcop->pos.vy - camera_position.vy) << 0x10 >> 0x11;
local.vz = (pcop->pos.vz - camera_position.vz) << 0x10 >> 0x11;
gte_ldlvl(&local);

View File

@ -90,6 +90,11 @@ SVECTOR night_colours[4] =
{ 880, 880, 905, 0 }
};
void* model_object_ptrs[MAX_DRAWN_BUILDINGS];
void* model_tile_ptrs[MAX_DRAWN_TILES];
void* anim_obj_buffer[MAX_DRAWN_ANIMATING];
void* spriteList[MAX_DRAWN_SPRITES];
unsigned long planeColours[8];
MATRIX inv_camera_matrix;
@ -105,11 +110,6 @@ int current_object_computed_value = 0;
int combointensity;
void* model_object_ptrs[192];
void* model_tile_ptrs[320];
void* anim_obj_buffer[20];
void* spriteList[75];
#ifndef PSX
OUT_CELL_FILE_HEADER cell_header;
#endif // PSX
@ -871,21 +871,27 @@ void DrawMapPSX(int* comp_val)
// walk through all cells
while (i >= 0)
{
if (ABS(hloop) + ABS(vloop) < 16)
{
if (ABS(hloop) + ABS(vloop) < 21)
{
// clamped vis values
int vis_h = MIN(MAX(hloop, -9), 10);
int vis_v = MIN(MAX(vloop, -9), 10);
cellx = cellxpos + hloop;
cellz = cellzpos + vloop;
if (rightPlane < 0 &&
leftPlane > 0 &&
backPlane < farClipLimit && // check planes
cellx > -1 && cellx < cells_across && // check cell ranges
cellz > -1 && cellz < cells_down &&
PVS_ptr[hloop]) // check PVS table // [A] please enable after PVSDecode will work properly
PVS_ptr[vis_v * pvs_square + vis_h]) // check PVS table
{
ppco = GetFirstPackedCop(cellx, cellz, &ci, 1);
// walk each cell object in cell
while (ppco != NULL)
{
@ -896,7 +902,7 @@ void DrawMapPSX(int* comp_val)
// sprity type
if (model->shape_flags & 0x4000)
{
if (sprites_found < 75)
if (sprites_found < MAX_DRAWN_SPRITES)
spriteList[sprites_found++] = ppco;
if ((model->flags2 & 1) && anim_objs_found < 20)
@ -967,17 +973,17 @@ void DrawMapPSX(int* comp_val)
}
}
if (tiles_found < 320)
if (tiles_found < MAX_DRAWN_TILES)
model_tile_ptrs[tiles_found++] = ppco;
}
else
{
cop = UnpackCellObject(ppco, &ci.nearCell);
if (other_models_found < 192)
if (other_models_found < MAX_DRAWN_BUILDINGS)
model_object_ptrs[other_models_found++] = cop;
if ((model->flags2 & 1) && anim_objs_found < 20)
if ((model->flags2 & 1) && anim_objs_found < MAX_DRAWN_ANIMATING)
anim_obj_buffer[anim_objs_found++] = cop;
}
}
@ -1006,7 +1012,7 @@ void DrawMapPSX(int* comp_val)
rightPlane += rightsin;
vloop++;
PVS_ptr += pvs_square;
//PVS_ptr += pvs_square;
if (hloop == vloop)
dir = 2;
@ -1028,7 +1034,7 @@ void DrawMapPSX(int* comp_val)
rightPlane -= rightsin;
vloop--;
PVS_ptr -= pvs_square;
//PVS_ptr -= pvs_square;
if (hloop == vloop)
dir = 0;

View File

@ -14,6 +14,23 @@ extern MATRIX face_camera;
extern MATRIX2 matrixtable[64];
extern MATRIX2 CompoundMatrix[64];
#ifdef PSX
#define MAX_DRAWN_BUILDINGS 192
#define MAX_DRAWN_TILES 320
#define MAX_DRAWN_ANIMATING 20
#define MAX_DRAWN_SPRITES 75
#else
#define MAX_DRAWN_BUILDINGS 384
#define MAX_DRAWN_TILES 750
#define MAX_DRAWN_ANIMATING 48
#define MAX_DRAWN_SPRITES 128
#endif
extern void* model_tile_ptrs[MAX_DRAWN_TILES];
extern int units_across_halved;
extern int units_down_halved;
@ -21,8 +38,6 @@ extern int pvs_square;
extern int pvs_square_sq;
extern int PolySizes[56];
extern void* model_tile_ptrs[320];
extern int combointensity;
extern int gForceLowDetailCars;

View File

@ -270,30 +270,31 @@ int ResidentModelsBodge(void)
{
i = 11;
if (j == 9)
return 4;
if (j != 9)
return 3;
}
else if (GameLevel == 1)
else if (GameLevel == 1)
{
i = 11;
if (j - 8U > 1)
if (j - 8U > 1)
return 3;
}
else if (GameLevel == 2)
{
i = 8;
if (j != i)
return 3;
}
else if (GameLevel == 3)
{
i = 11;
if (j != i)
return 3;
}
else
return 3;
if (j != i)
return 3;
return 4;
}
@ -2729,7 +2730,7 @@ void AddTunnels(int level)
InitTunnels(29);
AddTunnel(-78200, 0, -125000, -43800, -800, -159500);
AddTunnel(-65000, 0, -122700, -425984, -800, -125000);
AddTunnel(-65000, 0, -122700, -68000, -800, -125000);
AddTunnel(-48600, 0, -237000, -50350, -800, -235900);
AddTunnel(-219895, 0, 675067, -208647, -2500, 668935);

View File

@ -1,8 +1,6 @@
#include "DRIVER2.H"
#include "MAIN.H"
#include <algorithm>
#include "LIBETC.H"
#include "LIBSPU.H"
@ -2732,6 +2730,7 @@ void UpdatePlayerInformation(void)
WHEEL* wheel;
int i, j;
int wheelsInWater;
int wheelsAboveWaterToDieWithFade;
_CAR_DATA* cp;
cp = NULL;
@ -2749,8 +2748,7 @@ void UpdatePlayerInformation(void)
FelonyBar.position = *playerFelony;
i = 0;
while (i < NumPlayers)
for (i = 0; i < NumPlayers; i++)
{
if (player[i].playerType == 1)
{
@ -2763,29 +2761,37 @@ void UpdatePlayerInformation(void)
}
wheelsInWater = 0;
wheelsAboveWaterToDieWithFade = 0;
j = 0;
wheel = cp->hd.wheel;
do {
if ((wheel->surface & 0x7) == 1)
// [A] count the wheels above the water and in the water
for (j = 0; j < 4; j++)
{
if ((wheel->surface & 7) == 1)
{
if (wheel->susCompression == 0)
{
if (cp->hd.where.t[1] < -1000 && gDieWithFade == 0)
{
gDieWithFade = wheel->surface & 7;
}
}
wheelsAboveWaterToDieWithFade++;
else
{
wheelsInWater++;
}
}
wheel++;
j++;
} while (j < 4);
}
// [A] if all wheels above the water surface and we are falling down
// fade out and end the game
if(cp->hd.where.t[1] < -1000 && gDieWithFade == 0)
{
// fix for Havana tunnels
if (GameLevel == 1)
{
if(wheelsAboveWaterToDieWithFade == 4)
gDieWithFade = 1;
}
else // car drown as usual
gDieWithFade = 1;
}
if (wheelsInWater == 4) // apply water damage
cp->totalDamage += MaxPlayerDamage[i] / 80;
@ -2813,8 +2819,6 @@ void UpdatePlayerInformation(void)
{
gDieWithFade = 1;
}
i++;
}
}

View File

@ -313,7 +313,8 @@ void LoadFont(char *buffer)
dest.w = 64;
dest.h = 46;
fonttpage = GetTPage(0,0,0x3c0,0x1d2);
fonttpage = GetTPage(0,0,960,466);
LoadImage(&fontclutpos, (u_long *)(file + 0x100));
LoadImage(&dest, (u_long *)(file + 0x120));

View File

@ -353,6 +353,8 @@ void DrawSkyDome(void)
{
calc_sky_brightness();
#ifdef PSX
// FIXME: use frustrum angle instead?
if (((camera_angle.vy - 1450U) & 0xFFF) > 2250)
PlotHorizonMDL(modelpointers[0],HorizonLookup[GameLevel][0]);
@ -364,6 +366,13 @@ void DrawSkyDome(void)
if (((camera_angle.vy - 400U) & 0xFFF) > 2300)
PlotHorizonMDL(modelpointers[1],HorizonLookup[GameLevel][3]);
#else
// draw full sky - no need in frustrum culling
PlotHorizonMDL(modelpointers[0],HorizonLookup[GameLevel][0]);
PlotHorizonMDL(modelpointers[2],HorizonLookup[GameLevel][1]);
PlotHorizonMDL(modelpointers[3],HorizonLookup[GameLevel][2]);
PlotHorizonMDL(modelpointers[1],HorizonLookup[GameLevel][3]);
#endif
}
@ -1291,15 +1300,15 @@ void PlotHorizonMDL(MODEL* model, int horizontaboffset)
#ifndef PSX
// scale sky to get rid of vobbling
sv0.vx *= 100;
sv0.vy *= 100;
sv0.vz *= 100;
sv1.vx *= 100;
sv1.vy *= 100;
sv1.vz *= 100;
sv2.vx *= 100;
sv2.vy *= 100;
sv2.vz *= 100;
sv0.vx *= 110;
sv0.vy *= 110;
sv0.vz *= 110;
sv1.vx *= 110;
sv1.vy *= 110;
sv1.vz *= 110;
sv2.vx *= 110;
sv2.vy *= 110;
sv2.vz *= 110;
#endif
gte_ldv3(&sv0, &sv1, &sv2);