- refactor OBJCOLL.C

This commit is contained in:
Ilya Shurumov 2020-10-17 16:48:32 +06:00
parent 3c09c374eb
commit a0511e6c6e

View File

@ -72,7 +72,7 @@
/* end block 2 */
// End Line: 127
// [D] [A] might be bugged
// [D] [T]
char CellEmpty(VECTOR *pPosition, int radius)
{
PACKED_CELL_OBJECT* ppco;
@ -82,11 +82,7 @@ char CellEmpty(VECTOR *pPosition, int radius)
int box_loop;
int sphere_sq;
int zd;
int iVar2;
int iVar3;
uint theta;
int sn;
int* piVar6;
int ypos;
int cs;
COLLISION_PACKET* collide;
@ -106,11 +102,9 @@ char CellEmpty(VECTOR *pPosition, int radius)
{
pModel = modelpointers[pCellObject->type];
piVar6 = (int*)pModel->collision_block;
if (piVar6 != NULL)
if (pModel->collision_block > 0)
{
num_cb = *piVar6;
num_cb = *(int*)pModel->collision_block;
xd = (pCellObject->pos.vx - pPosition->vx);
zd = (pCellObject->pos.vz - pPosition->vz);
@ -118,7 +112,7 @@ char CellEmpty(VECTOR *pPosition, int radius)
sphere_sq = pModel->bounding_sphere + 580;
sphere_sq = (sphere_sq * sphere_sq);
collide = (COLLISION_PACKET*)(piVar6 + 1);
collide = (COLLISION_PACKET*)(pModel->collision_block + sizeof(int));
if (xd * xd + zd * zd < sphere_sq)
{
@ -126,7 +120,7 @@ char CellEmpty(VECTOR *pPosition, int radius)
while (box_loop < num_cb)
{
// ORIGINAL
// [A] ORIGINAL
/*
zs = collide->zsize * 0x800 + radius * 0x1000;
xs = collide->xsize * 0x800 + radius * 0x1000;
@ -138,7 +132,7 @@ char CellEmpty(VECTOR *pPosition, int radius)
sn = rcossin_tbl[theta * 2];
*/
// NEW
// [A] NEW
int xxd, zzd;
int yang;
int theta;
@ -299,36 +293,27 @@ char CellEmpty(VECTOR *pPosition, int radius)
/* end block 4 */
// End Line: 1774
// [D]
// [D] [T]
int GlobalPositionToCellNumber(VECTOR *pPosition)
{
int iVar1;
int iVar2;
int iVar3;
uint uVar4;
uint uVar5;
int iVar6;
int cellZ;
int cellX;
int cbrZ;
int cbrX;
int cbr;
iVar1 = pPosition->vx + units_across_halved;
iVar3 = iVar1 - 1024;
cellX = (pPosition->vx + units_across_halved - 1024) / 2048;
cellZ = (pPosition->vz + units_down_halved - 1024) / 2048;
cbrX = cellX / 32;
cbrZ = cellZ / 32;
iVar1 = pPosition->vz + units_down_halved;
iVar2 = iVar1 - 1024;
iVar3 = FixFloorSigned(iVar3, 0xb);
cbr = (cbrX & 1) + (cbrZ & 1) * 2;
iVar2 = FixFloorSigned(iVar2, 0xb);
iVar1 = iVar3;
uVar5 = FixFloorSigned(iVar1, 5);
iVar1 = iVar2;
uVar4 = FixFloorSigned(iVar1, 5);
iVar6 = (uVar5 & 1) + (uVar4 & 1) * 2;
if (RoadMapRegions[iVar6] != uVar5 + uVar4 * FixFloorSigned(cells_across, 5))
if (RoadMapRegions[cbr] != cbrX + cbrZ * (cells_across / 32))
return -1;
return cell_ptrs[(iVar2 - uVar4 * 32) * 32 + iVar6 * 1024 + iVar3 - uVar5 * 32];
return cell_ptrs[(cellZ - cbrZ * 32) * 32 + cbr * 1024 + cellX - cbrX * 32];
}
@ -354,19 +339,13 @@ int GlobalPositionToCellNumber(VECTOR *pPosition)
/* end block 3 */
// End Line: 1836
// [D]
// [D] [T]
char CellAtPositionEmpty(VECTOR *pPosition, int radius)
{
char cVar1;
int iVar2;
if (GlobalPositionToCellNumber(pPosition) == -1)
return 1;
iVar2 = GlobalPositionToCellNumber(pPosition);
if (iVar2 == -1)
cVar1 = 1;
else
cVar1 = CellEmpty(pPosition, radius);
return cVar1;
return CellEmpty(pPosition, radius);
}
@ -411,13 +390,11 @@ char CellAtPositionEmpty(VECTOR *pPosition, int radius)
/* end block 4 */
// End Line: 507
// [D]
// [D] [T]
int RaySlabsIntersection(tRay *ray, tAABB *bbox)
{
int iVar1;
int dir;
int iVar3;
int local_t0_36;
int d;
int i;
tRange inside;
@ -429,7 +406,7 @@ int RaySlabsIntersection(tRay *ray, tAABB *bbox)
i = 0;
do {
local_t0_36 = -1;
d = -1;
cabbage.lower = bbox->slab[i].lower - ray->org[i];
cabbage.upper = bbox->slab[i].upper - ray->org[i];
@ -437,9 +414,9 @@ int RaySlabsIntersection(tRay *ray, tAABB *bbox)
dir = ray->dir[i];
if (dir > -1)
local_t0_36 = (dir != 0);
d = (dir != 0);
if (local_t0_36 == 0)
if (d == 0)
{
if (cabbage.lower > 0)
return 0;
@ -450,12 +427,12 @@ int RaySlabsIntersection(tRay *ray, tAABB *bbox)
scaledCabbage.upper = 0x3000;
scaledCabbage.lower = -0x3000;
}
else if (local_t0_36 == -1)
else if (d == -1)
{
scaledCabbage.upper = (cabbage.lower * 4096) / dir;
scaledCabbage.lower = (cabbage.upper * 4096) / dir;
}
else if (local_t0_36 == 1)
else if (d == 1)
{
scaledCabbage.lower = (cabbage.lower * 4096) / dir;
scaledCabbage.upper = (cabbage.upper * 4096) / dir;
@ -581,23 +558,23 @@ int RaySlabsIntersection(tRay *ray, tAABB *bbox)
int testRadius = 222;
// [D]
// [D] [T]
char lineClear(VECTOR *v1, VECTOR *v2)
{
PACKED_CELL_OBJECT* ppco;
CELL_OBJECT* pCellObject;
MATRIX2* mat;
int pos_z;
int cell_z;
int cell_x;
int local_a0_592;
int yang;
MODEL* pModel;
int* piVar2;
int local_a3_704;
int iVar3;
int theta;
int dx,dz;
int cs;
int sn;
int iVar4;
COLLISION_PACKET* collide;
VECTOR pos;
VECTOR va;
@ -649,32 +626,31 @@ char lineClear(VECTOR *v1, VECTOR *v2)
while (pCellObject = UnpackCellObject(ppco, &ci.nearCell), pCellObject != NULL)
{
pModel = modelpointers[pCellObject->type];
piVar2 = (int*)pModel->collision_block;
xd = ((pCellObject->pos.vx - ((va.vx + vb.vx) / 2 & 0xffffU)) * 0x10000) >> 0x10;
zd = ((pCellObject->pos.vz - ((va.vz + vb.vz) / 2 & 0xffffU)) * 0x10000) >> 0x10;
sphere_sq = pModel->bounding_sphere + 800;
if (piVar2 != NULL && (pModel->flags2 & 0xA00) == 0 && (xd*xd + zd*zd < sphere_sq*sphere_sq))
if (pModel->collision_block > 0 && (pModel->flags2 & 0xA00) == 0 && (xd*xd + zd*zd < sphere_sq*sphere_sq))
{
collide = (COLLISION_PACKET*)(piVar2 + 1);
num_cb = *piVar2;
num_cb = *(int*)pModel->collision_block;
box_loop = 0;
collide = (COLLISION_PACKET*)(pModel->collision_block + sizeof(int));
while (box_loop < num_cb)
{
local_a0_592 = -pCellObject->yang & 0x3f;
local_a3_704 = (pCellObject->yang + collide->yang) * 64 & 0xfff;
yang = -pCellObject->yang & 0x3f;
theta = (pCellObject->yang + collide->yang) * 64 & 0xfff;
mat = &matrixtable[local_a0_592];
mat = &matrixtable[yang];
cs = rcossin_tbl[local_a3_704 * 2 + 1];
sn = rcossin_tbl[local_a3_704 * 2];
cs = rcossin_tbl[theta * 2 + 1];
sn = rcossin_tbl[theta * 2];
iVar4 = va.vx - (pCellObject->pos.vx + FIXEDH(collide->xpos * mat->m[0][0] + collide->zpos * mat->m[2][0]));
iVar3 = va.vz - (pCellObject->pos.vz + FIXEDH(collide->xpos * mat->m[0][2] + collide->zpos * mat->m[2][2]));
dx = va.vx - (pCellObject->pos.vx + FIXEDH(collide->xpos * mat->m[0][0] + collide->zpos * mat->m[2][0]));
dz = va.vz - (pCellObject->pos.vz + FIXEDH(collide->xpos * mat->m[0][2] + collide->zpos * mat->m[2][2]));
box.slab[0].upper = collide->xsize / 2 +testRadius;
box.slab[0].lower = -box.slab[0].upper;
@ -685,8 +661,8 @@ char lineClear(VECTOR *v1, VECTOR *v2)
box.slab[2].upper = collide->zsize / 2 +testRadius;
box.slab[2].lower = -box.slab[2].upper;
ray.org[0] = FIXEDH(cs * iVar4 - sn * iVar3);
ray.org[2] = FIXEDH(cs * iVar3 + sn * iVar4);
ray.org[0] = FIXEDH(cs * dx - sn * dz);
ray.org[2] = FIXEDH(cs * dz + sn * dx);
ray.org[1] = (va.vy - (((-collide->ypos - pCellObject->pos.vy) * 0x10000) >> 0x10)) + 80;
ray.dir[0] = FIXEDH(cs * pos.vx - sn * pos.vz);
@ -821,7 +797,7 @@ char lineClear(VECTOR *v1, VECTOR *v2)
/* end block 5 */
// End Line: 2230
// [D]
// [D] [T]
void SetCopListCell(int x, int z)
{
XZPAIR cell;
@ -847,7 +823,7 @@ void SetCopListCell(int x, int z)
/* end block 2 */
// End Line: 2249
// [D]
// [D] [T]
void BuildCollisionCopList(int *count)
{
CollisionCopList(NULL, count);
@ -899,7 +875,7 @@ void BuildCollisionCopList(int *count)
/* end block 3 */
// End Line: 1240
// [D]
// [D] [T]
void CollisionCopList(XZPAIR *pos, int *count)
{
static XZPAIR initial;
@ -911,6 +887,7 @@ void CollisionCopList(XZPAIR *pos, int *count)
XZPAIR cell;
CELL_ITERATOR ci;
XZPAIR cbr;
MODEL* model;
if (pos == NULL)
{
@ -932,14 +909,22 @@ void CollisionCopList(XZPAIR *pos, int *count)
while (cop != NULL)
{
cop->pad = *count;
model = modelpointers[cop->type];
coplist[*count] = cop;
pcoplist[*count] = ci.ppco;
if (model->collision_block > 0 &&
model->num_vertices-3 < 300 &&
model->num_point_normals < 300 &&
model->num_polys < 300 &&
*(int *)model->collision_block > 0)
{
coplist[*count] = cop;
pcoplist[*count] = ci.ppco;
(*count)++;
}
ppco = GetNextPackedCop(&ci);
cop = UnpackCellObject(ppco, &ci.nearCell);
(*count)++;
}
}
@ -1016,34 +1001,26 @@ extern int boxOverlap;
ushort gLastModelCollisionCheck;
int ExBoxDamage = 0;
// [D]
// [D] [T]
void CheckScenaryCollisions(_CAR_DATA *cp)
{
long lVar1;
long lVar2;
int iVar3;
int iVar5;
int iVar6;
int iVar7;
int iVar8;
int uVar9;
int iVar10;
int *piVar11;
int iVar12;
int iVar13;
int count;
int num_cb;
int coll_test_count;
int yang;
int minDist;
COLLISION_PACKET *collide;
CELL_OBJECT *cop;
VECTOR player_pos;
BUILDING_BOX bbox;
XZPAIR box;
VECTOR offset;
XZPAIR cell;
int mdcount;
MODEL *model;
int num_cb;
int x1;
int lbody;
int extraDist;
int sphereSq;
int dx, dz;
if (cp->controlType == CONTROL_TYPE_CAMERACOLLIDER || cp->ap.carCos == NULL)
lbody = 360;
else
@ -1055,158 +1032,150 @@ void CheckScenaryCollisions(_CAR_DATA *cp)
trap(0x400);
}
if (ghost_mode == 0 && (cp->controlType != CONTROL_TYPE_PLAYER || playerghost == 0))
{
EventCollisions(cp, 0);
if (ghost_mode != 0 || cp->controlType == CONTROL_TYPE_PLAYER && playerghost != 0)
return;
lVar2 = car_data[0].hd.where.t[2];
lVar1 = car_data[0].hd.where.t[0];
EventCollisions(cp, 0);
player_pos.vx = cp->hd.where.t[0];
player_pos.vz = cp->hd.where.t[2];
boxOverlap = -1;
if (cp->controlType == CONTROL_TYPE_TANNERCOLLIDER)
extraDist = 100;
else
extraDist = 580;
iVar10 = cp->hd.where.t[0];
iVar12 = cp->hd.where.t[2];
// [A] FIXME: replace with 'cell_header.cell_size'
cell.x = (player_pos.vx + units_across_halved - 1024) / 2048;
cell.z = (player_pos.vz + units_down_halved - 1024) / 2048;
boxOverlap = -1;
SetCopListCell(cell.x, cell.z);
if (cp->controlType == 6)
extraDist = 100;
iVar3 = iVar10 + units_across_halved;
iVar6 = iVar3 - 1024;
//if (iVar6 < 0)
// iVar6 = iVar3 + 1023;
iVar3 = iVar12 + units_down_halved;
iVar8 = iVar3 - 1024;
//if (iVar8 < 0)
// iVar8 = iVar3 + 1023;
// [A] FIXME: replace with 'cell_header.cell_size'
SetCopListCell(iVar6 / 2048, iVar8 / 2048);
mdcount = 0;
Havana3DOcclusion(BuildCollisionCopList, &mdcount);
mdcount = 0;
Havana3DOcclusion(BuildCollisionCopList, &mdcount);
x1 = 0;
if (mdcount + event_models_active > 0)
count = 0;
while (count < mdcount + event_models_active)
{
if (count < mdcount)
cop = coplist[count];
else
cop = &EventCop[count - mdcount];
model = modelpointers[cop->type];
if (model->collision_block > 0 &&
model->num_vertices-3 < 300 &&
model->num_point_normals < 300 &&
model->num_polys < 300)
{
do {
if (x1 < mdcount)
cop = coplist[x1];
else
cop = &EventCop[x1 - mdcount];
model = modelpointers[cop->type];
iVar3 = x1 + 1;
dx = cop->pos.vx - player_pos.vx;
dz = cop->pos.vz - player_pos.vz;
sphereSq = model->bounding_sphere + extraDist + cp->hd.speed;
if (model->collision_block > 0 &&
model->num_vertices-3 < 300 &&
model->num_point_normals < 300 &&
model->num_polys < 300)
if (dx * dx + dz * dz < sphereSq * sphereSq)
{
num_cb = *(int *)model->collision_block; // box count
collide = (COLLISION_PACKET*)(model->collision_block + sizeof(int));
while(num_cb--)
{
iVar8 = cop->pos.vx - iVar10;
iVar7 = cop->pos.vz - iVar12;
iVar6 = model->bounding_sphere + extraDist + cp->hd.speed;
yang = -cop->yang & 0x3f;
if (iVar8 * iVar8 + iVar7 * iVar7 < iVar6 * iVar6)
// box 'rotated' by matrix
// [A] FIXME: replace add+shift by division
bbox.pos.vx = cop->pos.vx + FIXEDH(collide->xpos * matrixtable[yang].m[0][0] + collide->zpos * matrixtable[yang].m[2][0]);
bbox.pos.vy = cop->pos.vy + collide->ypos;
bbox.pos.vz = cop->pos.vz + FIXEDH(collide->xpos * matrixtable[yang].m[0][2] + collide->zpos * matrixtable[yang].m[2][2]);
bbox.pos.pad = (model->flags2 >> 10) & 1;
bbox.xsize = (collide->zsize >> 1);
bbox.zsize = (collide->xsize >> 1);
bbox.height = collide->ysize;
bbox.theta = (cop->yang + collide->yang) * 64 & 0xfff;
gLastModelCollisionCheck = cop->type;
if (CAR_INDEX(cp) == 21)
{
iVar6 = *(int *)model->collision_block; // box count
collide = (COLLISION_PACKET*)(model->collision_block + 4);
for (int i = 0; i < iVar6; i++)
if (count >= mdcount && cop->pad != 0)
{
uVar9 = -cop->yang & 0x3f;
// box 'rotated' by matrix
// [A] FIXME: replace add+shift by division
bbox.pos.vx = cop->pos.vx + FIXEDH(collide->xpos * matrixtable[uVar9].m[0][0] + collide->zpos * matrixtable[uVar9].m[2][0]);
bbox.pos.vy = cop->pos.vy + collide->ypos;
bbox.pos.vz = cop->pos.vz + FIXEDH(collide->xpos * matrixtable[uVar9].m[0][2] + collide->zpos * matrixtable[uVar9].m[2][2]);
bbox.pos.pad = (model->flags2 >> 10) & 1;
bbox.xsize = (collide->zsize >> 1);// &0xFFFE;
bbox.zsize = (collide->xsize >> 1);// &0xFFFE;
bbox.height = collide->ysize;
bbox.theta = (cop->yang + collide->yang) * 64 & 0xfff;
gLastModelCollisionCheck = cop->type;
if (CAR_INDEX(cp) == 21)
if (CarBuildingCollision(cp, &bbox, cop, 0) != 0)
{
if (x1 < mdcount || cop->pad == 0)
{
CarBuildingCollision(cp, &bbox, cop, 0);
}
else if (CarBuildingCollision(cp, &bbox, cop, 0) != 0)
{
if (!bKillTanner)
player[0].dying = 1;
if (!bKillTanner)
player[0].dying = 1;
bKillTanner = 1;
}
bKillTanner = 1;
}
else if (cp->controlType == CONTROL_TYPE_CAMERACOLLIDER)
{
if ((model->flags2 & 0xa00) == 0 && (100 < bbox.xsize || (100 < bbox.zsize)))
{
iVar7 = 5;
bbox.xsize += 100;
bbox.zsize += 100;
boxOverlap = -1;
while ((iVar13 = lbody / 2, iVar13 <= gCameraDistance &&
CarBuildingCollision(cp, &bbox, cop, 0) && 0 < iVar7))
{
gCameraDistance -= boxOverlap;
if (gCameraDistance < iVar13)
gCameraDistance = iVar13;
uVar9 = cp->hd.direction & 0xfff;
cp->hd.where.t[0] = lVar1 + FIXEDH((gCameraDistance * rcossin_tbl[uVar9 * 2]) / 2);
cp->hd.where.t[2] = lVar2 + FIXEDH((gCameraDistance * rcossin_tbl[uVar9 * 2 + 1]) / 2);
iVar7--;
}
}
}
else
{
if (x1 < mdcount || cop->pad == 0)
{
if (CarBuildingCollision(cp, &bbox, cop, (model->flags2 >> 10) & 1) != 0)
cp->ap.needsDenting = 1;
}
else
{
cp->st.n.linearVelocity[2] = ExBoxDamage + cp->st.n.linearVelocity[2];
if (CarBuildingCollision(cp, &bbox, cop, (cop->pad == 1) ? 0x2 : 0) != 0)
{
cp->ap.needsDenting = 1;
}
//cp->st.n.linearVelocity[2] -= 700000; // [A] Vegas train velocity - disabled here
}
}
collide++;
};
}
else
{
CarBuildingCollision(cp, &bbox, cop, 0);
}
}
else if (cp->controlType == CONTROL_TYPE_CAMERACOLLIDER)
{
if ((model->flags2 & 0xa00) == 0 && (bbox.xsize > 100 || (bbox.zsize > 100)))
{
coll_test_count = 5;
bbox.xsize += 100;
bbox.zsize += 100;
boxOverlap = -1;
minDist = lbody / 2;
while (coll_test_count > 0 && minDist <= gCameraDistance && CarBuildingCollision(cp, &bbox, cop, 0))
{
gCameraDistance -= boxOverlap;
if (gCameraDistance < minDist)
gCameraDistance = minDist;
yang = cp->hd.direction & 0xfff;
cp->hd.where.t[0] = car_data[0].hd.where.t[0] + FIXEDH((gCameraDistance * rcossin_tbl[yang * 2]) / 2);
cp->hd.where.t[2] = car_data[0].hd.where.t[2] + FIXEDH((gCameraDistance * rcossin_tbl[yang * 2 + 1]) / 2);
coll_test_count--;
}
}
}
else
{
if (count >= mdcount && cop->pad != 0)
{
cp->st.n.linearVelocity[2] = ExBoxDamage + cp->st.n.linearVelocity[2];
if (CarBuildingCollision(cp, &bbox, cop, (cop->pad == 1) ? 0x2 : 0) != 0)
{
cp->ap.needsDenting = 1;
}
//cp->st.n.linearVelocity[2] -= 700000; // [A] Vegas train velocity - disabled here
}
else
{
if (CarBuildingCollision(cp, &bbox, cop, (model->flags2 >> 10) & 1) != 0)
cp->ap.needsDenting = 1;
}
}
collide++;
}
x1 = iVar3;
} while (iVar3 < mdcount + event_models_active);
}
}
EventCollisions(cp, 1);
count++;
}
EventCollisions(cp, 1);
}
@ -1259,206 +1228,190 @@ void CheckScenaryCollisions(_CAR_DATA *cp)
/* end block 2 */
// End Line: 1892
// [D]
// [D] [T]
int QuickBuildingCollisionCheck(VECTOR *pPos, int dir, int l, int w, int extra)
{
CDATA2D cd[2] = { 0 };
bool bVar1;
int iVar2;
int iVar3;
int iVar4;
int iVar5;
int iVar6;
int iVar7;
int count;
int num_cb;
MODEL *model;
uint uVar9;
int iVar10;
int *piVar11;
int iVar12;
int iVar13;
uint yang;
int sphereSq;
COLLISION_PACKET *collide;
CELL_OBJECT *cop;
XZPAIR cell;
VECTOR player_pos;
BUILDING_BOX bbox;
VECTOR offset;
int mdcount;
int dx, dz;
iVar5 = pPos->vx;
boxOverlap = -1;
iVar12 = pPos->vz;
iVar13 = iVar5 + units_across_halved;
iVar4 = iVar13 - 0x400;
iVar13 = iVar12 + units_down_halved;
iVar7 = iVar13 - 0x400;
SetCopListCell(iVar4 / 2048, iVar7 / 2048);
player_pos.vx = pPos->vx;
player_pos.vz = pPos->vz;
cell.x = (player_pos.vx + units_across_halved - 1024) / 2048;
cell.z = (player_pos.vz + units_down_halved - 1024) / 2048;
SetCopListCell(cell.x, cell.z);
mdcount = 0;
Havana3DOcclusion(BuildCollisionCopList, &mdcount);
iVar4 = 0;
if (0 < mdcount + event_models_active)
count = 0;
while (count < mdcount + event_models_active)
{
bVar1 = 0 < mdcount;
do {
if (bVar1)
cop = coplist[iVar4];
else
cop = EventCop + (iVar4 - mdcount);
if (count < mdcount)
cop = coplist[count];
else
cop = EventCop + (count - mdcount);
model = modelpointers[cop->type];
count++;
if (model->collision_block > 0 &&
model->num_vertices - 3 < 300 &&
model->num_point_normals < 300 &&
model->num_polys < 300)
model = modelpointers[cop->type];
if (model->collision_block > 0 &&
model->num_vertices - 3 < 300 &&
model->num_point_normals < 300 &&
model->num_polys < 300)
{
sphereSq = model->bounding_sphere + extra;
dx = cop->pos.vx - player_pos.vx;
dz = cop->pos.vz - player_pos.vz;
if (dx * dx + dz * dz < sphereSq * sphereSq)
{
piVar11 = (int *)model->collision_block;
num_cb = *(int *)model->collision_block;
collide = (COLLISION_PACKET*)(model->collision_block + sizeof(int));
iVar13 = model->bounding_sphere + extra;
iVar7 = cop->pos.vx - iVar5;
iVar6 = cop->pos.vz - iVar12;
if (iVar7 * iVar7 + iVar6 * iVar6 < iVar13 * iVar13)
while(num_cb--)
{
iVar7 = *(int *)model->collision_block;
collide = (COLLISION_PACKET*)(model->collision_block + 4);
yang = -cop->yang & 0x3f;
bbox.pos.vy = cop->pos.vy + collide->ypos;
for (int i = 0; i < iVar7; i++)
if (ABS(pPos->vy + bbox.pos.vy) < collide->ysize / 2)
{
uVar9 = -cop->yang & 0x3f;
bbox.pos.vy = cop->pos.vy + collide->ypos;
iVar2 = collide->zsize;
iVar3 = collide->xsize;
iVar10 = collide->ysize;
iVar6 = pPos->vy + bbox.pos.vy;
gLastModelCollisionCheck = cop->type;
if (iVar6 < 0)
iVar6 = -iVar6;
cd[0].theta = dir;
cd[0].length[0] = l;
cd[0].length[1] = w;
if (iVar6 < (iVar10) / 2)
{
gLastModelCollisionCheck = cop->type;
cd[0].x.vx = pPos->vx;
cd[0].x.vz = pPos->vz;
cd[0].theta = dir;
cd[0].length[0] = l;
cd[0].length[1] = w;
cd[0].vel.vx = 0;
cd[0].vel.vz = 0;
cd[0].x.vx = pPos->vx;
cd[0].x.vz = pPos->vz;
offset.vx = cop->pos.vx + FIXEDH(collide->xpos * matrixtable[yang].m[0][0] + collide->zpos * matrixtable[yang].m[2][0]);
offset.vz = cop->pos.vz + FIXEDH(collide->xpos * matrixtable[yang].m[0][2] + collide->zpos * matrixtable[yang].m[2][2]);
cd[0].vel.vx = 0;
cd[0].vel.vz = 0;
cd[1].theta = (cop->yang + collide->yang) * 64 & 0xfff;
offset.vx = cop->pos.vx + FIXEDH(collide->xpos * matrixtable[uVar9].m[0][0] + collide->zpos * matrixtable[uVar9].m[2][0]);
offset.vz = cop->pos.vz + FIXEDH(collide->xpos * matrixtable[uVar9].m[0][2] + collide->zpos * matrixtable[uVar9].m[2][2]);
cd[1].length[0] = collide->zsize / 2 + 100;
cd[1].length[1] = collide->xsize / 2 + 100;
cd[1].theta = (cop->yang + collide->yang) * 64 & 0xfff;
cd[1].x.vx = pPos->vx + (((offset.vx - pPos->vx) << 0x10) >> 0x10);
cd[1].x.vz = pPos->vz + (((offset.vz - pPos->vz) << 0x10) >> 0x10);
cd[1].length[0] = collide->zsize / 2 + 100;
cd[1].length[1] = collide->xsize / 2 + 100;
cd[1].vel.vx = 0;
cd[1].vel.vz = 0;
cd[1].avel = 0;
cd[1].x.vx = pPos->vx + (((offset.vx - pPos->vx) << 0x10) >> 0x10);
cd[1].x.vz = pPos->vz + (((offset.vz - pPos->vz) << 0x10) >> 0x10);
cd[1].vel.vx = 0;
cd[1].vel.vz = 0;
cd[1].avel = 0;
int res = bcollided2d(cd, 1);
int res = bcollided2d(cd, 1);
#if defined(COLLISION_DEBUG) && !defined(PSX)
extern int gShowCollisionDebug;
if (gShowCollisionDebug == 1)
extern int gShowCollisionDebug;
if (gShowCollisionDebug == 1)
{
extern void Debug_AddLine(VECTOR& pointA, VECTOR& pointB, CVECTOR& color);
extern void Debug_AddLineOfs(VECTOR& pointA, VECTOR& pointB, VECTOR& ofs, CVECTOR& color);
CVECTOR bbcv = { 0, 0, 250 };
CVECTOR rrcv = { 250, 0, 0 };
CVECTOR yycv = { 250, 250, 0 };
// show both box axes
{
extern void Debug_AddLine(VECTOR& pointA, VECTOR& pointB, CVECTOR& color);
extern void Debug_AddLineOfs(VECTOR& pointA, VECTOR& pointB, VECTOR& ofs, CVECTOR& color);
VECTOR _zero = { 0 };
VECTOR b1p = cd[0].x;
VECTOR b2p = cd[1].x;
b2p.vy = b1p.vy;
CVECTOR bbcv = { 0, 0, 250 };
CVECTOR rrcv = { 250, 0, 0 };
CVECTOR yycv = { 250, 250, 0 };
// show position to position
//Debug_AddLine(b1p1, b2p1, yycv);
// show both box axes
VECTOR b1ax[2] = { {0} , {0} };
b1ax[0].vx = FIXEDH(cd[0].axis[0].vx * cd[0].length[0]);
b1ax[0].vz = FIXEDH(cd[0].axis[0].vz * cd[0].length[0]);
b1ax[1].vx = FIXEDH(cd[0].axis[1].vx * cd[0].length[1]);
b1ax[1].vz = FIXEDH(cd[0].axis[1].vz * cd[0].length[1]);
// show axis of body 1
Debug_AddLineOfs(_zero, b1ax[0], b1p, rrcv);
Debug_AddLineOfs(_zero, b1ax[1], b1p, yycv);
// display 2D box 1
{
VECTOR _zero = { 0 };
VECTOR b1p = cd[0].x;
VECTOR b2p = cd[1].x;
b2p.vy = b1p.vy;
int h = b1ax[0].vy;
VECTOR box_points[4] = {
{b1ax[0].vx - b1ax[1].vx, h, b1ax[0].vz - b1ax[1].vz, 0}, // front left
{b1ax[0].vx + b1ax[1].vx, h, b1ax[0].vz + b1ax[1].vz, 0}, // front right
// show position to position
//Debug_AddLine(b1p1, b2p1, yycv);
{-b1ax[0].vx + b1ax[1].vx, h, -b1ax[0].vz + b1ax[1].vz, 0}, // back right
{-b1ax[0].vx - b1ax[1].vx, h, -b1ax[0].vz - b1ax[1].vz, 0} // back left
};
VECTOR b1ax[2] = { {0} , {0} };
b1ax[0].vx = FIXEDH(cd[0].axis[0].vx * cd[0].length[0]);
b1ax[0].vz = FIXEDH(cd[0].axis[0].vz * cd[0].length[0]);
b1ax[1].vx = FIXEDH(cd[0].axis[1].vx * cd[0].length[1]);
b1ax[1].vz = FIXEDH(cd[0].axis[1].vz * cd[0].length[1]);
Debug_AddLineOfs(box_points[0], box_points[1], b1p, bbcv);
Debug_AddLineOfs(box_points[1], box_points[2], b1p, bbcv);
Debug_AddLineOfs(box_points[2], box_points[3], b1p, bbcv);
Debug_AddLineOfs(box_points[3], box_points[0], b1p, bbcv);
}
// show axis of body 1
Debug_AddLineOfs(_zero, b1ax[0], b1p, rrcv);
Debug_AddLineOfs(_zero, b1ax[1], b1p, yycv);
VECTOR b2ax[2] = { {0} , {0} };
b2ax[0].vx += FIXEDH(cd[1].axis[0].vx * cd[1].length[0]);
b2ax[0].vz += FIXEDH(cd[1].axis[0].vz * cd[1].length[0]);
b2ax[1].vx += FIXEDH(cd[1].axis[1].vx * cd[1].length[1]);
b2ax[1].vz += FIXEDH(cd[1].axis[1].vz * cd[1].length[1]);
// display 2D box 1
{
int h = b1ax[0].vy;
VECTOR box_points[4] = {
{b1ax[0].vx - b1ax[1].vx, h, b1ax[0].vz - b1ax[1].vz, 0}, // front left
{b1ax[0].vx + b1ax[1].vx, h, b1ax[0].vz + b1ax[1].vz, 0}, // front right
// show axis of body 2
Debug_AddLineOfs(_zero, b2ax[0], b2p, rrcv);
Debug_AddLineOfs(_zero, b2ax[1], b2p, yycv);
{-b1ax[0].vx + b1ax[1].vx, h, -b1ax[0].vz + b1ax[1].vz, 0}, // back right
{-b1ax[0].vx - b1ax[1].vx, h, -b1ax[0].vz - b1ax[1].vz, 0} // back left
};
CVECTOR& collColor = res ? rrcv : yycv;
Debug_AddLineOfs(box_points[0], box_points[1], b1p, bbcv);
Debug_AddLineOfs(box_points[1], box_points[2], b1p, bbcv);
Debug_AddLineOfs(box_points[2], box_points[3], b1p, bbcv);
Debug_AddLineOfs(box_points[3], box_points[0], b1p, bbcv);
}
// display 2D box 2
{
int h = b2ax[0].vy;
VECTOR box_points[4] = {
{b2ax[0].vx - b2ax[1].vx, h, b2ax[0].vz - b2ax[1].vz, 0}, // front left
{b2ax[0].vx + b2ax[1].vx, h, b2ax[0].vz + b2ax[1].vz, 0}, // front right
VECTOR b2ax[2] = { {0} , {0} };
b2ax[0].vx += FIXEDH(cd[1].axis[0].vx * cd[1].length[0]);
b2ax[0].vz += FIXEDH(cd[1].axis[0].vz * cd[1].length[0]);
b2ax[1].vx += FIXEDH(cd[1].axis[1].vx * cd[1].length[1]);
b2ax[1].vz += FIXEDH(cd[1].axis[1].vz * cd[1].length[1]);
{-b2ax[0].vx + b2ax[1].vx, h, -b2ax[0].vz + b2ax[1].vz, 0}, // back right
{-b2ax[0].vx - b2ax[1].vx, h, -b2ax[0].vz - b2ax[1].vz, 0} // back left
};
// show axis of body 2
Debug_AddLineOfs(_zero, b2ax[0], b2p, rrcv);
Debug_AddLineOfs(_zero, b2ax[1], b2p, yycv);
CVECTOR& collColor = res ? rrcv : yycv;
// display 2D box 2
{
int h = b2ax[0].vy;
VECTOR box_points[4] = {
{b2ax[0].vx - b2ax[1].vx, h, b2ax[0].vz - b2ax[1].vz, 0}, // front left
{b2ax[0].vx + b2ax[1].vx, h, b2ax[0].vz + b2ax[1].vz, 0}, // front right
{-b2ax[0].vx + b2ax[1].vx, h, -b2ax[0].vz + b2ax[1].vz, 0}, // back right
{-b2ax[0].vx - b2ax[1].vx, h, -b2ax[0].vz - b2ax[1].vz, 0} // back left
};
Debug_AddLineOfs(box_points[0], box_points[1], b2p, collColor);
Debug_AddLineOfs(box_points[1], box_points[2], b2p, collColor);
Debug_AddLineOfs(box_points[2], box_points[3], b2p, collColor);
Debug_AddLineOfs(box_points[3], box_points[0], b2p, collColor);
}
Debug_AddLineOfs(box_points[0], box_points[1], b2p, collColor);
Debug_AddLineOfs(box_points[1], box_points[2], b2p, collColor);
Debug_AddLineOfs(box_points[2], box_points[3], b2p, collColor);
Debug_AddLineOfs(box_points[3], box_points[0], b2p, collColor);
}
}
#endif
if(res)
return 1;
}
collide++;
#endif
if(res)
return 1;
}
collide++;
}
}
iVar4++;
bVar1 = iVar4 < mdcount;
} while (iVar4 < mdcount + event_models_active);
}
}
return 0;
}
@ -1500,7 +1453,7 @@ int QuickBuildingCollisionCheck(VECTOR *pPos, int dir, int l, int w, int extra)
/* WARNING: Unknown calling convention yet parameter storage is locked */
// [D]
// [D] [T]
void DoScenaryCollisions(void)
{
_CAR_DATA *cp;