- rcossin_tbl[*] -> RSIN/RCOS

- some OD2 porting prepaprations
- fix CreateRoadblock refactoring bug (missing noMoreCars setup)
This commit is contained in:
Ilya Shurumov 2021-06-20 21:13:54 +06:00 committed by InspirationByte
parent fbdccb81b7
commit 0cfa16e3d5
27 changed files with 751 additions and 739 deletions

View File

@ -140,8 +140,8 @@ void DrawDebugOverlays()
dz = carPos->vz - roadInfo.straight->Midz;
segLen = roadInfo.straight->length;
theta = (roadInfo.straight->angle - ratan2(dx, dz) & 0xfffU);
distAlongSegment = (segLen / 2) + FIXEDH(rcossin_tbl[theta * 2 + 1] * SquareRoot0(dx * dx + dz * dz));
theta = roadInfo.straight->angle - ratan2(dx, dz);
distAlongSegment = (segLen / 2) + FIXEDH(RCOS(theta) * SquareRoot0(dx * dx + dz * dz));
}
else
{

View File

@ -34,8 +34,8 @@ int bcollided2d(CDATA2D *body, int* boxOverlap)
// calc axes of each box
for (i = 0; i < 2; i++)
{
as = rcossin_tbl[(body[i].theta & 0xfff) * 2];
ac = rcossin_tbl[(body[i].theta & 0xfff) * 2 + 1];
as = RSIN(body[i].theta);
ac = RCOS(body[i].theta);
body[i].axis[0].vx = as;
body[i].axis[0].vz = ac;
@ -44,6 +44,7 @@ int bcollided2d(CDATA2D *body, int* boxOverlap)
body[i].axis[1].vx = ac;
}
// hmmm, why?
as = rcossin_tbl[(dtheta & 0x7ff) * 2];
ac = rcossin_tbl[(dtheta + 1024 & 0x7ff) * 2];
@ -110,30 +111,24 @@ int bcollided2d(CDATA2D *body, int* boxOverlap)
// [D] [T]
void bFindCollisionPoint(CDATA2D *body, CRET2D *collisionResult)
{
bool carBarrierCollision;
int lower;
int upper;
int k;
int sign;
int sign0;
int sign1;
int smallest;
int besti;
int bestk;
int carBarrierCollision;
int lower, upper;
int i, k, besti, bestk;
int sign, sign0, sign1, smallest;
CDATA2D* cd;
int i;
besti = 0;
bestk = 0;
sign = 0;
carBarrierCollision = false;
carBarrierCollision = 0;
smallest = body[0].limit[0] + 1;
if (!body[0].isCameraOrTanner && !body[1].isCameraOrTanner &&
(body[1].length[1] >= body[1].length[0] * 4 || body[1].length[0] >= body[1].length[1] * 4))
{
carBarrierCollision = true;
carBarrierCollision = 1;
}
i = 1;
@ -222,10 +217,8 @@ void bFindCollisionPoint(CDATA2D *body, CRET2D *collisionResult)
int bFindCollisionTime(CDATA2D *cd, CRET2D *collisionResult)
{
int hit;
int q;
int time;
int step;
int i;
int i, q;
int time, step;
int neverfree;
CDATA2D original[2];
@ -493,12 +486,8 @@ void DamageCar(CAR_DATA *cp, CDATA2D *cd, CRET2D *collisionResult, int strikeVel
{
int impact;
int player_id;
int value;
int nose;
int door;
int region;
int dz;
int dx;
int nose, door, region, value;
int dx, dz;
int lbody;
player_id = GetPlayerId(cp);
@ -969,6 +958,7 @@ int CarBuildingCollision(CAR_DATA *cp, BUILDING_BOX *building, CELL_OBJECT *cop,
cp->hd.aacc[1] += FIXEDH(lever[2] * reaction[0]) - FIXEDH(lever[0] * reaction[2]);
// angular impulse calculation and modifiers
if (cp->controlType != CONTROL_TYPE_LEAD_AI)
{
temp = FIXEDH(lever[1] * reaction[2]);

View File

@ -104,20 +104,23 @@ void DrawThrownBombs(void)
// [D] [T]
void BombThePlayerToHellAndBack(int car)
{
CAR_DATA* cp;
BOMB *bomb;
if (car == -1)
return;
car_data[car].ap.damage[0] = 0xfff;
car_data[car].ap.damage[1] = 0xfff;
car_data[car].ap.damage[2] = 0xfff;
car_data[car].ap.damage[3] = 0xfff;
car_data[car].ap.damage[4] = 0xfff;
car_data[car].ap.damage[5] = 0xfff;
cp = &car_data[car];
cp->ap.damage[0] = 0xfff;
cp->ap.damage[1] = 0xfff;
cp->ap.damage[2] = 0xfff;
cp->ap.damage[3] = 0xfff;
cp->ap.damage[4] = 0xfff;
cp->ap.damage[5] = 0xfff;
car_data[car].ap.needsDenting = 1;
car_data[car].totalDamage = MaxPlayerDamage[0];
cp->ap.needsDenting = 1;
cp->totalDamage = MaxPlayerDamage[0];
DentCar(&car_data[car]);
@ -134,9 +137,9 @@ void BombThePlayerToHellAndBack(int car)
bomb->flags = 1;
bomb->active = 1;
bomb->position.vx = car_data[car].hd.where.t[0];
bomb->position.vy = car_data[car].hd.where.t[1];
bomb->position.vz = car_data[car].hd.where.t[2];
bomb->position.vx = cp->hd.where.t[0];
bomb->position.vy = cp->hd.where.t[1];
bomb->position.vz = cp->hd.where.t[2];
bomb->velocity.vx = 0;
bomb->velocity.vy = 0;
@ -148,9 +151,9 @@ void BombThePlayerToHellAndBack(int car)
bomb->flags = 1;
bomb->active = 1;
bomb->position.vx = car_data[car].hd.where.t[0] + 170;
bomb->position.vy = car_data[car].hd.where.t[1];
bomb->position.vz = car_data[car].hd.where.t[2] + 73;
bomb->position.vx = cp->hd.where.t[0] + 170;
bomb->position.vy = cp->hd.where.t[1];
bomb->position.vz = cp->hd.where.t[2] + 73;
bomb->velocity.vx = 0;
bomb->velocity.vy = 0;
@ -161,9 +164,9 @@ void BombThePlayerToHellAndBack(int car)
bomb->flags = 1;
bomb->active = 1;
bomb->position.vx = car_data[car].hd.where.t[0] - 109;
bomb->position.vy = car_data[car].hd.where.t[1];
bomb->position.vz = car_data[car].hd.where.t[2] - 147;
bomb->position.vx = cp->hd.where.t[0] - 109;
bomb->position.vy = cp->hd.where.t[1];
bomb->position.vz = cp->hd.where.t[2] - 147;
bomb->velocity.vx = 0;
bomb->velocity.vy = 0;
@ -440,8 +443,7 @@ void HandleThrownBombs(void)
bomb = ThrownBombs;
i = 0;
while (i < MAX_THROWN_BOMBS)
for (i = 0; i < MAX_THROWN_BOMBS; i++)
{
if (bomb->flags & 1)
{
@ -494,6 +496,5 @@ void HandleThrownBombs(void)
}
}
bomb++;
i++;
}
}

View File

@ -244,9 +244,9 @@ void ModifyCamera(void)
CalcCameraBasePos(lp);
angle = baseDir + 2048 & 0xfff;
lp->cameraPos.vx = basePos[0] + FIXEDH(rcossin_tbl[angle * 2] * (length - 60));
lp->cameraPos.vz = basePos[2] + FIXEDH(rcossin_tbl[angle * 2 + 1] * (length - 60));
angle = baseDir + 2048;
lp->cameraPos.vx = basePos[0] + FIXEDH(RSIN(angle) * (length - 60));
lp->cameraPos.vz = basePos[2] + FIXEDH(RCOS(angle) * (length - 60));
}
}
}
@ -463,14 +463,14 @@ void PlaceCameraFollowCar(PLAYER *lp)
camera_angle.vx = 25;
camAngle = lp->cameraAngle - (lp->headPos >> 16) & 0xfff;
camAngle = lp->cameraAngle - (lp->headPos >> 16);
if (pauseflag == 0 || EditMode == 2)
{
// [A] handle REDRIVER2 dedicated look back button
if ((paddCamera & CAMERA_PAD_LOOK_BACK) == CAMERA_PAD_LOOK_BACK || (paddCamera & CAMERA_PAD_LOOK_BACK_DED))
{
camAngle = baseDir & 0xfff; // look back
camAngle = baseDir; // look back
}
else
{
@ -480,8 +480,8 @@ void PlaceCameraFollowCar(PLAYER *lp)
}
}
lp->cameraPos.vx = basePos[0] + FIXEDH(rcossin_tbl[camAngle * 2] * lp->cameraDist);
lp->cameraPos.vz = basePos[2] + FIXEDH(rcossin_tbl[camAngle * 2 + 1] * lp->cameraDist);
lp->cameraPos.vx = basePos[0] + FIXEDH(RSIN(camAngle) * lp->cameraDist);
lp->cameraPos.vz = basePos[2] + FIXEDH(RCOS(camAngle) * lp->cameraDist);
lp->cameraPos.vy = basePos[1];
camPosVy = MapHeight(&lp->cameraPos);
@ -511,10 +511,10 @@ void PlaceCameraFollowCar(PLAYER *lp)
if (lp->cameraCarId >= 0)
jcam->ap.carCos = car_data[lp->cameraCarId].ap.carCos;
jcam->hd.direction = camAngle;
jcam->hd.direction = camAngle & 0xfff;
sdist = maxCameraDist * rcossin_tbl[camAngle * 2] + 0x800;
cdist = maxCameraDist * rcossin_tbl[camAngle * 2 + 1] + 0x800;
sdist = maxCameraDist * RSIN(camAngle) + 2048;
cdist = maxCameraDist * RCOS(camAngle) + 2048;
jcam->hd.oBox.location.vx = jcam->hd.where.t[0] = basePos[0] + (sdist >> 13);
jcam->hd.oBox.location.vy = jcam->hd.where.t[1] = -lp->cameraPos.vy;
@ -528,8 +528,8 @@ void PlaceCameraFollowCar(PLAYER *lp)
lp->cameraDist = gCameraDistance;
lp->cameraPos.vy = -jcam->hd.where.t[1];
lp->cameraPos.vx = basePos[0] + FIXEDH(lp->cameraDist * rcossin_tbl[(jcam->hd.direction & 0xfff) * 2]);
lp->cameraPos.vz = basePos[2] + FIXEDH(lp->cameraDist * rcossin_tbl[(jcam->hd.direction & 0xfff) * 2 + 1]);
lp->cameraPos.vx = basePos[0] + FIXEDH(lp->cameraDist * RSIN(jcam->hd.direction));
lp->cameraPos.vz = basePos[2] + FIXEDH(lp->cameraDist * RCOS(jcam->hd.direction));
if (lp->cameraCarId < 0)
camera_angle.vy = -(jcam->hd.direction + 2048);
@ -631,11 +631,11 @@ void PlaceCameraInCar(PLAYER *lp, int BumperCam)
viewer_position.vy += lp->pPed->head_pos - 25;
//viewer_position.vz += 45;
angle = -baseDir & 0xfff;
angle = -baseDir;
lp->cameraPos.vx = basePos[0] + FIXEDH(rcossin_tbl[angle * 2] * viewer_position.vz);
lp->cameraPos.vx = basePos[0] + FIXEDH(RSIN(angle) * viewer_position.vz);
lp->cameraPos.vy = viewer_position.vy - basePos[1];
lp->cameraPos.vz = basePos[2] - FIXEDH(rcossin_tbl[angle * 2 + 1] * viewer_position.vz);
lp->cameraPos.vz = basePos[2] - FIXEDH(RCOS(angle) * viewer_position.vz);
}
SetGeomScreen(scr_z = gCameraDefaultScrZ);

View File

@ -607,8 +607,8 @@ void DrawCarWheels(CAR_DATA *cp, MATRIX *RearMatrix, VECTOR *pos, int zclip)
// rotate wheel verts
FW1z = FIXEDH(rcossin_tbl[(FrontWheelRotation[car_id] & 0xfff) * 2] * sizeScale);
FW2z = FIXEDH(rcossin_tbl[(FrontWheelRotation[car_id] & 0xfff) * 2 + 1] * sizeScale);
FW1z = FIXEDH(RSIN(FrontWheelRotation[car_id]) * sizeScale);
FW2z = FIXEDH(RCOS(FrontWheelRotation[car_id]) * sizeScale);
VertPtr = (SVECTOR*)WheelModelFront->vertices;
@ -651,8 +651,8 @@ void DrawCarWheels(CAR_DATA *cp, MATRIX *RearMatrix, VECTOR *pos, int zclip)
VertPtr[17].vy = -wheelSize;
VertPtr[16].vy = -wheelSize;
BW1z = FIXEDH(rcossin_tbl[(BackWheelRotation[car_id] & 0xfff) * 2] * sizeScale);
BW2z = FIXEDH(rcossin_tbl[(BackWheelRotation[car_id] & 0xfff) * 2 + 1] * sizeScale);
BW1z = FIXEDH(RSIN(BackWheelRotation[car_id]) * sizeScale);
BW2z = FIXEDH(RCOS(BackWheelRotation[car_id]) * sizeScale);
VertPtr = (SVECTOR *)WheelModelBack->vertices;
@ -695,8 +695,8 @@ void DrawCarWheels(CAR_DATA *cp, MATRIX *RearMatrix, VECTOR *pos, int zclip)
VertPtr[17].vy = -wheelSize;
VertPtr[16].vy = -wheelSize;
SteerMatrix.m[0][0] = rcossin_tbl[(cp->wheel_angle & 0xfff) * 2 + 1];
SteerMatrix.m[0][2] = rcossin_tbl[(cp->wheel_angle & 0xfff) * 2];
SteerMatrix.m[0][0] = RCOS(cp->wheel_angle);
SteerMatrix.m[0][2] = RSIN(cp->wheel_angle);
SteerMatrix.m[1][1] = ONE;
SteerMatrix.m[2][1] = 0;
SteerMatrix.m[1][2] = 0;

View File

@ -828,7 +828,8 @@ int GetNextRoadInfo(CAR_DATA* cp, int randomExit, int* turnAngle, int* startDist
dx = (oldNode->x - roadInfo.straight->Midx);
dz = (oldNode->z - roadInfo.straight->Midz);
tmpNewLane[roadCnt] = ROAD_LANES_COUNT(&roadInfo) - (FIXEDH(dx * rcossin_tbl[(roadInfo.straight->angle & 0xfff) * 2 + 1] - dz * rcossin_tbl[(roadInfo.straight->angle & 0xfff) * 2]) + 512 >> 9);
tmpNewLane[roadCnt] = ROAD_LANES_COUNT(&roadInfo)
- (FIXEDH(dx * RCOS(roadInfo.straight->angle) - dz * RSIN(roadInfo.straight->angle)) + 512 >> 9);
}
else
@ -981,10 +982,10 @@ void InitNodeList(CAR_DATA* cp, EXTRA_CIV_DATA* extraData)
dx = cp->hd.where.t[0] - straight->Midx;
dz = cp->hd.where.t[2] - straight->Midz;
theta = (straight->angle - ratan2(dx, dz) & 0xfffU);
cr->distAlongSegment = (straight->length / 2) + FIXEDH(rcossin_tbl[theta * 2 + 1] * SquareRoot0(dx * dx + dz * dz));
theta = straight->angle - ratan2(dx, dz);
cr->distAlongSegment = (straight->length / 2) + FIXEDH(RCOS(theta) * SquareRoot0(dx * dx + dz * dz));
laneDist = ROAD_LANES_COUNT(straight) * 512 + FIXEDH(-dx * rcossin_tbl[(straight->angle & 0xfff) * 2 + 1] + dz * rcossin_tbl[(straight->angle & 0xfff) * 2]);
laneDist = ROAD_LANES_COUNT(straight) * 512 + FIXEDH(-dx * RCOS(straight->angle) + dz * RSIN(straight->angle));
cp->ai.c.currentLane = laneDist / 512;
// calc all dirs
@ -1059,11 +1060,11 @@ int GetNodePos(DRIVER2_STRAIGHT* straight, DRIVER2_JUNCTION* junction, DRIVER2_C
sideShift = (ROAD_LANES_COUNT(straight) * 512 - (laneNo * 512 + 256)) + test42;
*x = straight->Midx + FIXEDH(distFromCentre * rcossin_tbl[(angle & 0xfffU) * 2]) +
FIXEDH(sideShift * rcossin_tbl[(angle & 0xfffU) * 2 + 1]);
*x = straight->Midx + FIXEDH(distFromCentre * RSIN(angle)) +
FIXEDH(sideShift * RCOS(angle));
*z = straight->Midz + FIXEDH(distFromCentre * rcossin_tbl[(angle & 0xfffU) * 2 + 1]) -
FIXEDH(sideShift * rcossin_tbl[(angle & 0xfffU) * 2]);
*z = straight->Midz + FIXEDH(distFromCentre * RCOS(angle)) -
FIXEDH(sideShift * RSIN(angle));
}
else if (cp)
{
@ -1082,8 +1083,8 @@ int GetNodePos(DRIVER2_STRAIGHT* straight, DRIVER2_JUNCTION* junction, DRIVER2_C
radius = curve->inside * 1024 + laneNo * 512 + 256 + test42;
*x = curve->Midx + FIXEDH(radius * rcossin_tbl[(angle & 0xfffU) * 2]);
*z = curve->Midz + FIXEDH(radius * rcossin_tbl[(angle & 0xfffU) * 2 + 1]);
*x = curve->Midx + FIXEDH(radius * RSIN(angle));
*z = curve->Midz + FIXEDH(radius * RCOS(angle));
}
else if (junction)
{
@ -1217,8 +1218,8 @@ int CheckChangeLanes(DRIVER2_STRAIGHT* straight, DRIVER2_CURVE* curve, int distA
else
theta = cp->hd.direction - 1024;
cd[0].x.vx = cp->hd.oBox.location.vx + FIXEDH(rcossin_tbl[(theta & 0xfff) * 2] * 512);
cd[0].x.vz = cp->hd.oBox.location.vz + FIXEDH(rcossin_tbl[(theta & 0xfff) * 2 + 1] * 512);
cd[0].x.vx = cp->hd.oBox.location.vx + FIXEDH(RSIN(theta) * 512);
cd[0].x.vz = cp->hd.oBox.location.vz + FIXEDH(RCOS(theta) * 512);
cd[0].length[0] = cp->ap.carCos->colBox.vz + 93;
cd[0].length[1] = cp->ap.carCos->colBox.vx;
cd[0].theta = cp->hd.direction;
@ -1483,13 +1484,13 @@ int CreateNewNode(CAR_DATA * cp)
segLength = (SquareRoot0(dx * dx + dz * dz) - (cp->hd.wheel_speed / 170));
cornerAngle = DIFF_ANGLES(start->dir, ratan2(dx, dz)); //((ratan2(dx, dz) - start->dir) + 2048U & 0xfff) - 2048;
tmp = FIXEDH(segLength * rcossin_tbl[(cornerAngle & 0xfffU) * 2 + 1]);
tmp = FIXEDH(segLength * RCOS(cornerAngle));
retNode = newNode;
if (tmp > 0)
{
newNode->x = start->x + FIXEDH(tmp * rcossin_tbl[(start->dir & 0xfff) * 2]);
newNode->z = start->z + FIXEDH(tmp * rcossin_tbl[(start->dir & 0xfff) * 2 + 1]);
newNode->x = start->x + FIXEDH(tmp * RSIN(start->dir));
newNode->z = start->z + FIXEDH(tmp * RCOS(start->dir));
newNode->pathType = 1;
newNode->dir = start->dir;
@ -1497,14 +1498,14 @@ int CreateNewNode(CAR_DATA * cp)
retNode = GET_NEXT_NODE(cp, newNode);
}
tmp = FIXEDH(segLength * rcossin_tbl[(cornerAngle & 0xfffU) * 2]);
tmp = FIXEDH(segLength * RSIN(cornerAngle));
newNode = retNode;
if (tmp < 0)
{
retNode->x = tempNode.x + FIXEDH(tmp * rcossin_tbl[(tempNode.dir & 0xfff) * 2]);
retNode->z = tempNode.z + FIXEDH(tmp * rcossin_tbl[(tempNode.dir & 0xfff) * 2 + 1]);
retNode->x = tempNode.x + FIXEDH(tmp * RSIN(tempNode.dir));
retNode->z = tempNode.z + FIXEDH(tmp * RCOS(tempNode.dir));
retNode->pathType = 1;
retNode->dir = tempNode.dir;
@ -1808,8 +1809,8 @@ int CreateCivCarWotDrivesABitThenStops(int direction, LONGVECTOR4* startPos, LON
pNewCar->ai.c.maxSpeed = EVENT_CAR_SPEED;
pNewCar->st.n.linearVelocity[1] = 0;
pNewCar->st.n.linearVelocity[0] = EVENT_CAR_SPEED * rcossin_tbl[(direction & 0xfffU) * 2];
pNewCar->st.n.linearVelocity[2] = EVENT_CAR_SPEED * rcossin_tbl[(direction & 0xfffU) * 2 + 1];
pNewCar->st.n.linearVelocity[0] = EVENT_CAR_SPEED * RSIN(direction);
pNewCar->st.n.linearVelocity[2] = EVENT_CAR_SPEED * RCOS(direction);
pNewCar->ai.c.velRatio = (EVENT_CAR_SPEED * ONE) / (DistanceTriggerCarMoves - pNewCar->ap.carCos->colBox.vz * 3);
pNewCar->ai.c.targetRoute[0].x = (*startPos)[0];
@ -1822,16 +1823,16 @@ int CreateCivCarWotDrivesABitThenStops(int direction, LONGVECTOR4* startPos, LON
stopNode->dir = direction;
stopNode->distAlongSegment = 0;
stopNode->x = (*startPos)[0] + FIXEDH(DistanceTriggerCarMoves * rcossin_tbl[(direction & 0xfffU) * 2]);
stopNode->z = (*startPos)[2] + FIXEDH(DistanceTriggerCarMoves * rcossin_tbl[(direction & 0xfffU) * 2 + 1]);
stopNode->x = (*startPos)[0] + FIXEDH(DistanceTriggerCarMoves * RSIN(direction));
stopNode->z = (*startPos)[2] + FIXEDH(DistanceTriggerCarMoves * RCOS(direction));
spareNode = &pNewCar->ai.c.targetRoute[2];
spareNode->pathType = 1;
spareNode->dir = direction;
spareNode->distAlongSegment = 0;
spareNode->x = (*startPos)[0] + FIXEDH(DistanceTriggerCarMoves * rcossin_tbl[(direction & 0xfffU) * 2] * 3);
spareNode->z = (*startPos)[2] + FIXEDH(DistanceTriggerCarMoves * rcossin_tbl[(direction & 0xfffU) * 2 + 1] * 3);
spareNode->x = (*startPos)[0] + FIXEDH(DistanceTriggerCarMoves * RSIN(direction) * 3);
spareNode->z = (*startPos)[2] + FIXEDH(DistanceTriggerCarMoves * RCOS(direction) * 3);
numCivCars++;
@ -1908,16 +1909,16 @@ int CreateStationaryCivCar(int direction, long orientX, long orientZ, LONGVECTOR
InitCar(newCar, direction, startPos, 2, model, 0, (char*)&civDat);
dx = rcossin_tbl[((orientZ / 2) & 0xfff) * 2];
dz = rcossin_tbl[((orientZ / 2) & 0xfff) * 2 + 1];
dx = RSIN(orientZ / 2);
dz = RCOS(orientZ / 2);
tmpQ[0] = FIXEDH(newCar->st.n.orientation[1] * dx + newCar->st.n.orientation[0] * dz);
tmpQ[1] = FIXEDH(newCar->st.n.orientation[1] * dz - newCar->st.n.orientation[0] * dx);
tmpQ[2] = FIXEDH(newCar->st.n.orientation[3] * dx + newCar->st.n.orientation[2] * dz);
tmpQ[3] = FIXEDH(newCar->st.n.orientation[3] * dz - newCar->st.n.orientation[2] * dx);
dx = rcossin_tbl[((orientX / 2) & 0xfff) * 2];
dz = rcossin_tbl[((orientX / 2) & 0xfff) * 2 + 1];
dx = RSIN(orientX / 2);
dz = RCOS(orientX / 2);
newCar->st.n.orientation[0] = FIXEDH(tmpQ[3] * dx + tmpQ[0] * dz);
newCar->st.n.orientation[1] = FIXEDH(tmpQ[2] * dx + tmpQ[1] * dz);
@ -1940,6 +1941,9 @@ int dx = 0; // offset 0xAAB40
int dy = 0; // offset 0xAAB44
int dz = 0; // offset 0xAAB48
#define PINGIN_DIST_WANTED_MULT (10)
#define PINGIN_DIST_MULT (8)
// [D] [T] [A] - some register is not properly decompiled
int PingInCivCar(int minPingInDist)
{
@ -2046,17 +2050,17 @@ int PingInCivCar(int minPingInDist)
return 0;
}
if (requestCopCar == 0)
if (requestCopCar != 0)
{
angle = (cookieCount * ONE) / 44 & 0xfff;
dx = rcossin_tbl[(angle & 0xfff) * 2] << 3;
dz = rcossin_tbl[(angle & 0xfff) * 2 + 1] << 3;
angle = (cookieCount * ONE) / 56;
dx = RSIN(angle) * PINGIN_DIST_WANTED_MULT;
dz = RCOS(angle) * PINGIN_DIST_WANTED_MULT;
}
else
{
angle = (cookieCount * ONE) / 56 & 0xfff;
dx = rcossin_tbl[(angle & 0xfff) * 2] * 10;
dz = rcossin_tbl[(angle & 0xfff) * 2 + 1] * 10;
angle = (cookieCount * ONE) / 44;
dx = RSIN(angle) * PINGIN_DIST_MULT;
dz = RCOS(angle) * PINGIN_DIST_MULT;
}
randomLoc.vx = baseLoc.vx + FIXEDH(dx) * 2048;
@ -2109,17 +2113,17 @@ int PingInCivCar(int minPingInDist)
break;
}
if (requestCopCar == 0)
if (requestCopCar != 0)
{
angle = (cookieCount * ONE) / 44 & 0xfff;
dx = rcossin_tbl[(angle & 0xfff) * 2] << 3;
dz = rcossin_tbl[(angle & 0xfff) * 2 + 1] << 3;
angle = (cookieCount * ONE) / 56;
dx = RSIN(angle) * PINGIN_DIST_WANTED_MULT;
dz = RCOS(angle) * PINGIN_DIST_WANTED_MULT;
}
else
{
angle = (cookieCount * ONE) / 56 & 0xfff;
dx = rcossin_tbl[(angle & 0xfff) * 2] * 10;
dz = rcossin_tbl[(angle & 0xfff) * 2 + 1] * 10;
angle = (cookieCount * ONE) / 44;
dx = RSIN(angle) * PINGIN_DIST_MULT;
dz = RCOS(angle) * PINGIN_DIST_MULT;
}
// [A] make limo ping in closer and in right direction
@ -2321,9 +2325,9 @@ int PingInCivCar(int minPingInDist)
dx = randomLoc.vx - roadInfo.straight->Midx;
dz = randomLoc.vz - roadInfo.straight->Midz;
theta = (roadInfo.straight->angle - ratan2(dx, dz) & 0xfffU);
theta = roadInfo.straight->angle - ratan2(dx, dz);
civDat.distAlongSegment = (roadInfo.straight->length / 2) + FIXEDH(rcossin_tbl[theta * 2 + 1] * SquareRoot0(dx * dx + dz * dz));
civDat.distAlongSegment = (roadInfo.straight->length / 2) + FIXEDH(RCOS(theta) * SquareRoot0(dx * dx + dz * dz));
if (requestCopCar == 0)
{
@ -2684,7 +2688,7 @@ int CivAccelTrafficRules(CAR_DATA * cp, int* distToNode)
else
checkObstDist = 512;
carDir = cp->hd.direction & 0xfff;
carDir = cp->hd.direction;
distToObstacle = 0x7fffff;
lcp = &car_data[MAX_CARS-1];
@ -2698,8 +2702,8 @@ int CivAccelTrafficRules(CAR_DATA * cp, int* distToNode)
dx = lcp->hd.where.t[0] - cp->hd.where.t[0];
dz = lcp->hd.where.t[2] - cp->hd.where.t[2];
tangent = FIXEDH(dx * rcossin_tbl[carDir * 2] + dz * rcossin_tbl[carDir * 2 + 1]);
normal = FIXEDH(dx * rcossin_tbl[carDir * 2 + 1] - dz * rcossin_tbl[carDir * 2]);
tangent = FIXEDH(dx * RSIN(carDir) + dz * RCOS(carDir));
normal = FIXEDH(dx * RCOS(carDir) - dz * RSIN(carDir));
if (tangent > 0)
{
@ -3396,51 +3400,53 @@ void CreateRoadblock(void)
angle = 0;
// scan angle
// scan for roads
do {
int dv;
if (requestCopCar == 0)
dv = rcossin_tbl[(dir + angle & 0xfffU) * 2] << 3;
int dx, dz;
if (requestCopCar != 0)
{
dx = RSIN(dir + angle) * PINGIN_DIST_WANTED_MULT;
dz = RCOS(dir + angle) * PINGIN_DIST_WANTED_MULT;
}
else
dv = rcossin_tbl[(dir + angle & 0xfffU) * 2] * 10;
{
dx = RSIN(dir + angle) * PINGIN_DIST_MULT;
dz = RCOS(dir + angle) * PINGIN_DIST_MULT;
}
roadblockLoc.vx = baseLoc.vx + FIXEDH(dv) * 2048;
if (requestCopCar == 0)
dv = rcossin_tbl[(dir + angle & 0xfffU) * 2 + 1] << 3;
else
dv = rcossin_tbl[(dir + angle & 0xfffU) * 2 + 1] * 10;
roadblockLoc.vz = baseLoc.vz + FIXEDH(dv) * 2048;
roadblockLoc.vx = baseLoc.vx + FIXEDH(dx) * 2048;
roadblockLoc.vz = baseLoc.vz + FIXEDH(dz) * 2048;
roadSeg = RoadInCell(&roadblockLoc);
if (IS_STRAIGHT_SURFACE(roadSeg) || IS_CURVED_SURFACE(roadSeg))
break;
if (requestCopCar == 0)
dv = rcossin_tbl[(dir - angle & 0xfffU) * 2] << 3;
if (requestCopCar != 0)
{
dx = RSIN(dir - angle) * PINGIN_DIST_WANTED_MULT;
dz = RCOS(dir - angle) * PINGIN_DIST_WANTED_MULT;
}
else
dv = rcossin_tbl[(dir - angle & 0xfffU) * 2] * 10;
{
dx = RSIN(dir - angle) * PINGIN_DIST_MULT;
dz = RCOS(dir - angle) * PINGIN_DIST_MULT;
}
roadblockLoc.vx = baseLoc.vx + FIXEDH(dv) * 2048;
if (requestCopCar == 0)
dv = rcossin_tbl[(dir - angle & 0xfffU) * 2 + 1] << 3;
else
dv = rcossin_tbl[(dir - angle & 0xfffU) * 2 + 1] * 10;
roadblockLoc.vz = baseLoc.vz + FIXEDH(dv) * 2048;
roadblockLoc.vx = baseLoc.vx + FIXEDH(dx) * 2048;
roadblockLoc.vz = baseLoc.vz + FIXEDH(dz) * 2048;
roadSeg = RoadInCell(&roadblockLoc);
if (IS_STRAIGHT_SURFACE(roadSeg) || IS_CURVED_SURFACE(roadSeg))
break;
if (requestCopCar == 0)
angle = angle + 93;
// FIXME: there must be some computed constant
if (requestCopCar != 0)
angle += 73;
else
angle = angle + 73;
angle += 93;
} while (angle < 2048);
@ -3457,7 +3463,7 @@ void CreateRoadblock(void)
dz = roadblockLoc.vz - str->Midz;
segmentLen = str->length;
distAlongSegment = (str->length / 2) + FIXEDH(rcossin_tbl[(str->angle - ratan2(dx, dz) & 0xfffU) * 2 + 1] * SquareRoot0(dx * dx + dz * dz));
distAlongSegment = (str->length / 2) + FIXEDH(RCOS(str->angle - ratan2(dx, dz)) * SquareRoot0(dx * dx + dz * dz));
if (segmentLen < lbody * 6)
return;
@ -3518,8 +3524,8 @@ void CreateRoadblock(void)
{
laneNo = (delta >> 9);
currentPos.vx = startPos.vx + FIXEDH(delta * rcossin_tbl[(dir2NextRow & 0xfff) * 2]);
currentPos.vz = startPos.vz + FIXEDH(delta * rcossin_tbl[(dir2NextRow & 0xfff) * 2 + 1]);
currentPos.vx = startPos.vx + FIXEDH(delta * RSIN(dir2NextRow));
currentPos.vz = startPos.vz + FIXEDH(delta * RCOS(dir2NextRow));
if((str && ROAD_IS_AI_LANE(str, laneNo) || crv && ROAD_IS_AI_LANE(crv, laneNo)) &&
CellEmpty(&currentPos, lbody))
@ -3527,7 +3533,10 @@ void CreateRoadblock(void)
newSlot = CreateStationaryCivCar(dir2NextRow + (Random2(0) * 0x10001 >> (laneNo) & 0x3ffU) - 512, 0, 0, (LONGVECTOR4 *)&currentPos, externalCopModel, 0, 2);
if (newSlot == -1)
{
noMoreCars = 1;
break;
}
newCar = &car_data[newSlot];
@ -3579,9 +3588,9 @@ void CreateRoadblock(void)
else
faceDir = dir2NextRow;
theta = dir2NextRow + deltaAngle & 0xfff;
px = startPos.vx + FIXEDH(rcossin_tbl[theta * 2] * 1500);
pz = startPos.vz + FIXEDH(rcossin_tbl[theta * 2 + 1] * 1500);
theta = dir2NextRow + deltaAngle;
px = startPos.vx + FIXEDH(RSIN(theta) * 1500);
pz = startPos.vz + FIXEDH(RCOS(theta) * 1500);
numSpareCars = (maxCivCars - numCivCars) + 2;
numSpots = numLanes / 2 - 1;
@ -3596,8 +3605,8 @@ void CreateRoadblock(void)
{
delta = ((numSpots * (count * 2 + 1)) / (numCarsToAdd * 2)) * 1024 + 768;
currentPos.vx = px + FIXEDH(delta * rcossin_tbl[(dir2NextRow & 0xfff) * 2]);
currentPos.vz = pz + FIXEDH(delta * rcossin_tbl[(dir2NextRow & 0xfff) * 2 + 1]);
currentPos.vx = px + FIXEDH(delta * RSIN(dir2NextRow));
currentPos.vz = pz + FIXEDH(delta * RCOS(dir2NextRow));
test42 = delta;
@ -3710,11 +3719,11 @@ int CivControl(CAR_DATA* cp)
test42 = 0 * 0x80;
sideShift = ((straight->NumLanes & 0xf) * 0x200 - (laneNo * 0x200 + 0x100)) + test42;
int straightX1 = straight->Midx + FIXED(distFromCentreA * rcossin_tbl[(angle & 0xfffU) * 2]) + FIXED(sideShift * rcossin_tbl[(angle & 0xfffU) * 2 + 1]);
int straightZ1 = (straight->Midz + FIXED(distFromCentreA * rcossin_tbl[(angle & 0xfffU) * 2 + 1])) - FIXED(sideShift * rcossin_tbl[(angle & 0xfffU) * 2]);
int straightX1 = straight->Midx + FIXED(distFromCentreA * RSIN(angle)) + FIXED(sideShift * RCOS(angle));
int straightZ1 = (straight->Midz + FIXED(distFromCentreA * RCOS(angle))) - FIXED(sideShift * RSIN(angle));
int straightX2 = straight->Midx + FIXED(distFromCentreB * rcossin_tbl[(angle & 0xfffU) * 2]) + FIXED(sideShift * rcossin_tbl[(angle & 0xfffU) * 2 + 1]);
int straightZ2 = (straight->Midz + FIXED(distFromCentreB * rcossin_tbl[(angle & 0xfffU) * 2 + 1])) - FIXED(sideShift * rcossin_tbl[(angle & 0xfffU) * 2]);
int straightX2 = straight->Midx + FIXED(distFromCentreB * RSIN(angle)) + FIXED(sideShift * RCOS(angle));
int straightZ2 = (straight->Midz + FIXED(distFromCentreB * RCOS(angle))) - FIXED(sideShift * RSIN(angle));
VECTOR roadA = { straightX1, cp->hd.where.t[1], straightZ1 };
VECTOR roadB = { straightX2, cp->hd.where.t[1], straightZ2 };

View File

@ -149,9 +149,8 @@ void WibbleDownTheRoad(VECTOR *from, int distance, VECTOR *to)
pos.vz = from->vz;
pos.pad = from->pad;
j = 0;
do {
for (j = 0; j < 4; j++)
{
ReplayLog_Fnarr_He_Said_Log(pos.vx);
ReplayLog_Fnarr_He_Said_Log(pos.vy);
ReplayLog_Fnarr_He_Said_Log(pos.vz);
@ -166,8 +165,8 @@ void WibbleDownTheRoad(VECTOR *from, int distance, VECTOR *to)
}
dir.vy = 0;
dir.vx = FIXEDH((distance >> 2) * rcossin_tbl[(val & 0xfff) * 2]);
dir.vz = FIXEDH((distance >> 2) * rcossin_tbl[(val & 0xfff) * 2 + 1]);
dir.vx = FIXEDH((distance >> 2) * RSIN(val));
dir.vz = FIXEDH((distance >> 2) * RCOS(val));
thl[j] = val;
@ -194,9 +193,7 @@ void WibbleDownTheRoad(VECTOR *from, int distance, VECTOR *to)
Debug_AddLine(p2, pos, bbcv);
}
#endif
j++;
} while (j < 4);
}
to->vx = pos.vx;
to->vy = pos.vy;

View File

@ -1706,20 +1706,14 @@ void ShowFlare(VECTOR* v1, CVECTOR* col, short size, int rotation)
void AddTrafficLight(CELL_OBJECT *cop, int x, int y, int z, int flag, int yang)
{
int tempfade;
int r;
int lDiffAnglesX;
int lDiffAnglesY;
int AbsX;
int AbsY;
CVECTOR a;
CVECTOR c;
VECTOR v1;
VECTOR v2;
int lDiffAnglesX, lDiffAnglesY;
int AbsX, AbsY;
CVECTOR a, c;
VECTOR v1, v2;
r = yang & 0xfff;
v1.vy = (cop->pos.vy - camera_position.vy) + y;
v1.vx = (cop->pos.vx - camera_position.vx) + FIXEDH(rcossin_tbl[r * 2 + 1] * x + rcossin_tbl[r * 2] * z);
v1.vz = (cop->pos.vz - camera_position.vz) + FIXEDH(rcossin_tbl[r * 2 + 1] * z - rcossin_tbl[r * 2] * x);
v1.vx = (cop->pos.vx - camera_position.vx) + FIXEDH(RCOS(yang) * x + RSIN(yang) * z);
v1.vz = (cop->pos.vz - camera_position.vz) + FIXEDH(RCOS(yang) * z - RSIN(yang) * x);
a.cd = 0;
@ -2104,8 +2098,8 @@ void ShowLight(VECTOR *v1, CVECTOR *col, short size, TEXTURE_DETAILS *texture)
width = ABS(poly->x0 - poly->x3);
#ifdef PSX
dx = rcossin_tbl[angle * 2 + 1] * width * 3;
dy = rcossin_tbl[angle * 2] * width * 3;
dx = RCOS(angle) * width * 3;
dy = RSIN(angle) * width * 3;
if (col->cd & 0x40)
{
@ -2130,12 +2124,13 @@ void ShowLight(VECTOR *v1, CVECTOR *col, short size, TEXTURE_DETAILS *texture)
trail->x3 = old_x - dx;
trail->y3 = old_y - dy;
#else
dx = rcossin_tbl[angle * 2 + 1];
dy = rcossin_tbl[angle * 2];
// [A] slightly bigger light trail
dx = RCOS(angle);
dy = RSIN(angle);
if (col->cd & 0x40)
{
dx = dx / 40000.0f; // [A] slightly bigger light trail
dx = dx / 40000.0f;
dy = dy / 40000.0f;
}
else
@ -2541,9 +2536,9 @@ void GetSmokeDrift(VECTOR *Wind)
SinTabIndex2 = SinTabIndex2 + 5 & 0xfff;
SinTabIndex3 = SinTabIndex3 + 7 & 0xfff;
SinX = rcossin_tbl[SinTabIndex1 * 2] + rcossin_tbl[SinTabIndex2 * 2];
CosX = rcossin_tbl[(SinTabIndex1 + 1024 & 0xfff) * 2] + rcossin_tbl[(SinTabIndex2 + 1024 & 0xfff) * 2];
WindMagnitude = rcossin_tbl[SinTabIndex3 * 2] >> 0xb;
SinX = isin(SinTabIndex1) + isin(SinTabIndex2);
CosX = icos(SinTabIndex1) + icos(SinTabIndex2);
WindMagnitude = isin(SinTabIndex3) >> 0xb;
}
Wind->vy = 0;
@ -3245,11 +3240,11 @@ void HandleDebris(void)
lf->sin_index1 &= 0xfff;
lf->sin_index2 &= 0xfff;
sn1 = rcossin_tbl[lf->sin_index1 * 2];
sn2 = rcossin_tbl[lf->sin_index2 * 2];
sn1 = RSIN(lf->sin_index1);
sn2 = RSIN(lf->sin_index2);
cs1 = rcossin_tbl[lf->sin_index1 * 2 + 1];
cs2 = rcossin_tbl[lf->sin_index2 * 2 + 1];
cs1 = RCOS(lf->sin_index1);
cs2 = RCOS(lf->sin_index2);
// then we compute completely new direction
lf->direction.vy = ((sn1 + sn2) >> 0xb) + 4;
@ -3361,21 +3356,23 @@ void HandleDebris(void)
{
main_cop_light_pos++;
main_cop_light_pos &= 7;
}
if (variable_weather)
{
static int weather_level = 0;
variable_weather = 1;
weather_level = rcossin_tbl[(CameraCnt & 0xfffU) * 2] + (int)*(short *)((int)rcossin_tbl + (CameraCnt & 0x3ffcU));
if (weather_level < 1)
gRainCount = -weather_level >> 8;
else
gRainCount = weather_level >> 8;
if (variable_weather != 0)
{
static int weather_level = 0;
if (gRainCount > MAX_RAIN_DROPS)
gRainCount = MAX_RAIN_DROPS;
weather_level = RSIN(CameraCnt) + RSIN(CameraCnt / 4);
if (weather_level < 1)
gRainCount = -weather_level >> 8;
else
gRainCount = weather_level >> 8;
if (gRainCount > MAX_RAIN_DROPS)
gRainCount = MAX_RAIN_DROPS;
}
}
}
@ -3488,18 +3485,19 @@ void DisplaySplashes(void)
CamGnd.vz = camera_position.vz;
CamGnd.vy = -camera_position.vy - MapHeight(&CamGnd);
ang = FrAng - camera_angle.vy & 0xfff;
ang = FrAng - camera_angle.vy;
Gnd1.vx = rcossin_tbl[ang * 2] + camera_position.vx;
Gnd1.vz = rcossin_tbl[ang * 2 + 1] + camera_position.vz;
Gnd1.vx = RSIN(ang) + camera_position.vx;
Gnd1.vz = RCOS(ang) + camera_position.vz;
Gnd1.vx = Gnd1.vx - CamGnd.vx;
Gnd1.vy = -camera_position.vy - MapHeight(&Gnd1) - CamGnd.vy;
Gnd1.vz = Gnd1.vz - CamGnd.vz;
ang = -FrAng - camera_angle.vy & 0xfff;
Gnd2.vx = rcossin_tbl[ang * 2] + camera_position.vx;
Gnd2.vz = rcossin_tbl[ang * 2 + 1] + camera_position.vz;
ang = -FrAng - camera_angle.vy;
Gnd2.vx = RSIN(ang) + camera_position.vx;
Gnd2.vz = RCOS(ang) + camera_position.vz;
Gnd2.vx = Gnd2.vx - CamGnd.vx;
Gnd2.vy = (-camera_position.vy - MapHeight(&Gnd2)) - CamGnd.vy;

View File

@ -472,7 +472,7 @@ int IsMovingCamera(PLAYBACKCAMERA* lastcam, PLAYBACKCAMERA* nextcam, int camerac
cameracnt -= lastcam->FrameCnt;
f = nextcam->FrameCnt - lastcam->FrameCnt;
s = (cameracnt * 2048) / f;
t = (rcossin_tbl[(s * 3 & 0xfff) * 2 + 1] + rcossin_tbl[(s & 0xfff) * 2 + 1] * -9 >> 4) + 0x800;
t = (RCOS(s*3) - RCOS(s) * 9 >> 4) + 2048;
xdist = FixHalfRound((nextcam->position.vx - lastcam->position.vx) * 64 * t, 18);
@ -1249,8 +1249,8 @@ void ControlReplay(void)
x = -d;
}
player[0].cameraPos.vx = (player[0].cameraPos.vx + FIXED(z * rcossin_tbl[(dir & 0xfff) * 2])) - FIXED(x * rcossin_tbl[(dir & 0xfff) * 2 + 1]);
player[0].cameraPos.vz = (player[0].cameraPos.vz - FIXED(z * rcossin_tbl[(dir & 0xfff) * 2 + 1])) - FIXED(x * rcossin_tbl[(dir & 0xfff) * 2]);
player[0].cameraPos.vx = (player[0].cameraPos.vx + FIXED(z * RSIN(dir))) - FIXED(x * RCOS(dir));
player[0].cameraPos.vz = (player[0].cameraPos.vz - FIXED(z * RCOS(dir))) - FIXED(x * RSIN(dir));
tmpPos.vx = player[0].cameraPos.vx;
tmpPos.vy = -player[0].cameraPos.vy;

View File

@ -134,8 +134,8 @@ int GetLaneByPositionOnRoad(DRIVER2_ROAD_INFO* roadInfo, VECTOR* pos)
dx = pos->vx - roadInfo->straight->Midx;
dz = pos->vz - roadInfo->straight->Midz;
lane = ROAD_LANES_COUNT(roadInfo) - (FIXEDH(dx * rcossin_tbl[(roadInfo->straight->angle & 0xfff) * 2 + 1] -
dz * rcossin_tbl[(roadInfo->straight->angle & 0xfff) * 2]) + 512 >> 9);
lane = ROAD_LANES_COUNT(roadInfo) - (FIXEDH(dx * RCOS(roadInfo->straight->angle) -
dz * RSIN(roadInfo->straight->angle)) + 512 >> 9);
if (lane < 0)
lane = 0;
@ -280,12 +280,11 @@ int sdHeightOnPlane(VECTOR *pos, sdPlane *plane)
// [D] [T]
short* sdGetBSP(sdNode *node, XYPAIR *pos)
{
int ang, dot;
int dot;
while (node->value < 0) // & 0x80000000U)
{
ang = (node->n.angle & 0xfff) * 2;
dot = pos->y * rcossin_tbl[ang + 1] - pos->x * rcossin_tbl[ang];
dot = pos->y * RCOS(node->n.angle) - pos->x * RSIN(node->n.angle);
if (dot < node->n.dist * 4096)
node++;
@ -557,9 +556,9 @@ int FindSurfaceD2(VECTOR *pos, VECTOR *normal, VECTOR *out, sdPlane **plane)
else if ((*plane)->surface == 4)
{
if (gInGameCutsceneActive && gCurrentMissionNumber == 23 && gInGameCutsceneID == 0)
out->vy += rcossin_tbl[(pos->vx + pos->vz) * 4 & 0x1fff] >> 9;
out->vy += RSIN((pos->vx + pos->vz) * 2) >> 9; // rcossin_tbl[(pos->vx + pos->vz) * 4 & 0x1fff] >> 9;
else
out->vy += (rcossin_tbl[(pos->vx + pos->vz) * 4 & 0x1fff] >> 8) / 3;
out->vy += (RSIN((pos->vx + pos->vz) * 2) >> 8) / 3; // (rcossin_tbl[(pos->vx + pos->vz) * 4 & 0x1fff] >> 8) / 3;
return 2048;
}

View File

@ -418,20 +418,20 @@ void InitFrustrumMatrix(void)
a = -camera_angle.vy;
frustrum_matrix.m[0][1] = 0;
frustrum_matrix.m[0][0] = rcossin_tbl[(a & 0xfffU) * 2];
frustrum_matrix.m[0][2] = rcossin_tbl[(a & 0xfffU) * 2 + 1];
frustrum_matrix.m[0][0] = RSIN(a);
frustrum_matrix.m[0][2] = RCOS(a);
a = (FrAng - 1024) - camera_angle.vy;
frustrum_matrix.m[1][1] = 0;
frustrum_matrix.m[1][0] = rcossin_tbl[(a & 0xfff) * 2];
frustrum_matrix.m[1][2] = rcossin_tbl[(a & 0xfff) * 2 + 1];
frustrum_matrix.m[1][0] = RSIN(a);
frustrum_matrix.m[1][2] = RCOS(a);
a = -(FrAng - 1024) - camera_angle.vy;
frustrum_matrix.m[2][1] = 0;
frustrum_matrix.m[2][0] = rcossin_tbl[(a & 0xfff) * 2];
frustrum_matrix.m[2][2] = rcossin_tbl[(a & 0xfff) * 2 + 1];
frustrum_matrix.m[2][0] = RSIN(a);
frustrum_matrix.m[2][2] = RCOS(a);
frustrum_matrix.t[0] = -80;
}
@ -1337,17 +1337,18 @@ void DrawMapPSX(int* comp_val)
drawData.leftPlane = 6144;
// setup planes
drawData.rightAng = camera_angle.vy - FrAng & 0xfff;
drawData.leftAng = camera_angle.vy + FrAng & 0xfff;
drawData.backAng = camera_angle.vy + 0x400U & 0xfff;
drawData.rightAng = camera_angle.vy - FrAng;
drawData.leftAng = camera_angle.vy + FrAng;
drawData.backAng = camera_angle.vy + 1024;
drawData.rightcos = rcossin_tbl[drawData.rightAng * 2 + 1];
drawData.rightsin = rcossin_tbl[drawData.rightAng * 2];
drawData.rightcos = RCOS(drawData.rightAng);
drawData.rightsin = RSIN(drawData.rightAng);
drawData.leftcos = rcossin_tbl[drawData.leftAng * 2 + 1];
drawData.leftsin = rcossin_tbl[drawData.leftAng * 2];
drawData.backcos = rcossin_tbl[drawData.backAng * 2 + 1];
drawData.backsin = rcossin_tbl[drawData.backAng * 2];
drawData.leftcos = RCOS(drawData.leftAng);
drawData.leftsin = RSIN(drawData.leftAng);
drawData.backcos = RCOS(drawData.backAng);
drawData.backsin = RSIN(drawData.backAng);
#ifdef PSX
if (NumPlayers == 2)

View File

@ -276,7 +276,7 @@ void DrawSmashedCone(SMASHED_CONE *sc, VECTOR *wpos)
void GetConePos(int cone, VECTOR *pos, int side)
{
TRAILBLAZER_DATA *tbd;
int x, z, r;
int x, z;
int radius;
tbd = &gTrailblazerData[cone];
@ -290,11 +290,10 @@ void GetConePos(int cone, VECTOR *pos, int side)
}
else
{
r = tbd->rot & 0xfff;
radius = cone * -4 + 600;
x = radius * rcossin_tbl[r * 2 + 1];
z = -radius * rcossin_tbl[r * 2];
x = radius * RCOS(tbd->rot);
z = -radius * RSIN(tbd->rot);
if (side == 0)
{
@ -390,15 +389,14 @@ void HandleDrivingGames(void)
{
int sn, cs;
int dx, dz;
int r, radius;
int radius;
tbd = &gTrailblazerData[cone];
r = tbd->rot & 0xfff;
radius = (600 - (gTrailblazerConeIndex * 400 + i) / 100) * 4096;
sn = rcossin_tbl[r * 2];
cs = rcossin_tbl[r * 2 + 1];
sn = RSIN(tbd->rot);
cs = RCOS(tbd->rot);
dx = player[id].pos[0] - tbd->x;
dz = player[id].pos[2] - tbd->z;

View File

@ -1687,14 +1687,14 @@ void StepFromToEvent(EVENT* ev)
if (md > 1024)
md = ev->data[0] ^ df;
else
md = ((ev->data[0] - 1) * rcossin_tbl[(md & 0xfff) * 2]) / 4096 + 1 ^ df;
md = ((ev->data[0] - 1) * RSIN(md)) / 4096 + 1 ^ df;
}
else
{
if (md > 2048)
md = ev->data[0] ^ df;
else
md = ((ev->data[0] - 1) * rcossin_tbl[(md >> 1 & 0xfff) * 2]) / 4096 + 1U ^ df;
md = ((ev->data[0] - 1) * RSIN(md >> 1)) / 4096 + 1U ^ df;
}
*curr += (md - df);
@ -1811,7 +1811,7 @@ void StepPathEvent(EVENT* ev)
if ((d1 < 6000 && d1 < 8048) && (ev->flags & 0x400))
{
speed = ev->data[0] + (speed - ev->data[0]) * rcossin_tbl[(((d1 - 2048) * 1024) / 8048 & 0xfffU) * 2] / 4096;
speed = ev->data[0] + (speed - ev->data[0]) * RSIN(((d1 - 2048) * 1024) / 8048) / 4096;
}
*curr += speed * dir;
@ -2031,13 +2031,13 @@ void StepPathEvent(EVENT* ev)
{
if ((ev->flags & 0x7000U) == 0x3000)
{
speed = ev->data[0] + (speed - ev->data[0]) * rcossin_tbl[(((d1 - 2048) * 1024) / 8048 & 0xfffU) * 2] / 4096;
speed = ev->data[0] + (speed - ev->data[0]) * RSIN(((d1 - 2048) * 1024) / 8048) / 4096;
}
}
else
{
// acceleration or slowdown
speed = 5 + (speed - 5) * rcossin_tbl[((d1 << 10) / 6000 & 0xfffU) * 2] / 4096;
speed = 5 + (speed - 5) * RSIN((d1 << 10) / 6000) / 4096;
}
}
@ -2097,7 +2097,7 @@ int GetBridgeRotation(int timer)
else if (timer > 1000)
timer = 1000;
return (4096 - rcossin_tbl[((timer * 2048) / 1000 & 0xfffU) * 2 + 1]) * 800 / 8192;
return (4096 - RCOS((timer * 2048) / 1000)) * 800 / 8192;
}
// [D] [T]
@ -2162,15 +2162,15 @@ void StepHelicopter(EVENT* ev)
vel.z = ev->position.vz - HelicopterData.lastZ;
}
rot = ev->rotation & 0xfff;
rot = ev->rotation;
vz = vel.z * rcossin_tbl[rot * 2 + 1] + vel.x * rcossin_tbl[rot * 2];
vx = vel.x * rcossin_tbl[rot * 2 + 1] - vel.z * rcossin_tbl[rot * 2];
vz = vel.z * RCOS(rot) + vel.x * RSIN(rot);
vx = vel.x * RCOS(rot) - vel.z * RSIN(rot);
pitch = HelicopterData.pitch;
if (ABS(vz) <= 900000)
pitch = -HelicopterData.pitch - (rcossin_tbl[((vz * 1024) / 900000 & 0xfffU) * 2] >> 3);
pitch = -HelicopterData.pitch - (RSIN((vz * 1024) / 900000) >> 3);
else if (vz < 1)
pitch = 512 - pitch;
else
@ -2179,7 +2179,7 @@ void StepHelicopter(EVENT* ev)
roll = HelicopterData.roll;
if (ABS(vx) <= 150000)
roll = (rcossin_tbl[((vx * 1024) / 150000 & 0xfff) * 2] >> 3) - roll;
roll = (RSIN((vx * 1024) / 150000) >> 3) - roll;
else if (vx < 1)
roll = -512 - roll;
else
@ -2223,7 +2223,7 @@ void StepHelicopter(EVENT* ev)
}
else
{
direction = rcossin_tbl[(rot & 0x7ff) * 4] >> 2;
direction = RSIN(rot * 2) >> 2;
}
ev->rotation += FIXEDH(FIXEDH(direction * direction) * direction);
@ -2345,6 +2345,8 @@ void StepEvents(void)
if (ev->flags & 0x800)
{
// [A] what the fuck this code is doing? Makes boat float harder after explosion?
int tmSqr;
ev->data[1] = rcossin_tbl[(CameraCnt & 0x7f) * 64] >> 9 & 0xfff;
@ -2440,7 +2442,7 @@ void StepEvents(void)
rotAngle = ABS(door->rotation - door->initialRotation) * 2048 / ABS(door->finalRotation - door->initialRotation);
sign = (*target - door->rotation) >> 0x1f;
door->rotation += (door->minSpeed + (rcossin_tbl[(rotAngle & 0xfffU) * 2] * (door->maxSpeed - door->minSpeed) >> 0xc) ^ sign) - sign;
door->rotation += (door->minSpeed + (RSIN(rotAngle) * (door->maxSpeed - door->minSpeed) >> 0xc) ^ sign) - sign;
// check if complete
if (((*target - door->rotation) ^ sign) - sign < 0)
@ -2590,7 +2592,7 @@ void DrawFerrisWheel(MATRIX* matrix, VECTOR* pos)
{
MODEL* model;
int loop;
int cx, sx, angle;
int sn, cs, angle;
int rotation;
VECTOR offset;
VECTOR carPos;
@ -2627,14 +2629,14 @@ void DrawFerrisWheel(MATRIX* matrix, VECTOR* pos)
for (loop = 0; loop < 5; loop++)
{
angle = chicagoDoor[2].rotation + rotation & 0xfff;
angle = chicagoDoor[2].rotation + rotation;
cx = rcossin_tbl[angle * 2];
sx = rcossin_tbl[angle * 2 + 1];
sn = RSIN(angle);
cs = RCOS(angle);
offset.vx = FIXEDH(spoke[0].vx * cx + spoke[1].vx * sx);
offset.vy = FIXEDH(spoke[0].vy * cx + spoke[1].vy * sx);
offset.vz = FIXEDH(spoke[0].vz * cx + spoke[1].vz * sx);
offset.vx = FIXEDH(spoke[0].vx * sn + spoke[1].vx * cs);
offset.vy = FIXEDH(spoke[0].vy * sn + spoke[1].vy * cs);
offset.vz = FIXEDH(spoke[0].vz * sn + spoke[1].vz * cs);
carPos.vx = pos->vx + offset.vx;
carPos.vy = pos->vy + offset.vy;
@ -2881,7 +2883,7 @@ void DrawEvents(int camera)
pos.vx = pos.vx - boatOffset.vx;
pos.vz = pos.vz - boatOffset.vz;
pos.vy = (pos.vy - boatOffset.vy) + FIXEDH((int)ev->node * rcossin_tbl[(*ev->data & 0xfffU) * 2]);
pos.vy = (pos.vy - boatOffset.vy) + FIXEDH((int)ev->node * RSIN(*ev->data));
}
else if (type == 0x400)
{
@ -3122,9 +3124,9 @@ sdPlane* EventSurface(VECTOR* pos, sdPlane* plane)
else
end = ev->data[-1];
d = ev->rotation & 0xfff;
sin = rcossin_tbl[d * 2];
cos = rcossin_tbl[d * 2 + 1];
d = ev->rotation;
sin = RSIN(d);
cos = RCOS(d);
d1 = (end - ev->data[0]) * cos;
d2 = dist - ev->data[0];
@ -3185,20 +3187,20 @@ sdPlane* EventSurface(VECTOR* pos, sdPlane* plane)
height = 200;
d = ev->data[1] & 0xfff;
d = ev->data[1];
sin = rcossin_tbl[d * 2];
cos = rcossin_tbl[d * 2 + 1];
sin = RSIN(d);
cos = RCOS(d);
offset = dist * -4096 + cos * -3328;
if (GameLevel == 3 && offset > 0)
{
int sin2;
d = 160 - ev->data[1] & 0xfff;
d = 160 - ev->data[1];
cos = rcossin_tbl[d * 2 + 1];
sin2 = rcossin_tbl[d * 2];
cos = RCOS(d);
sin2 = RSIN(d);
if (offset > cos * 2048)
{

View File

@ -44,6 +44,7 @@ void InitCarPhysics(CAR_DATA* cp, LONGVECTOR4* startpos, int direction)
int ty;
int odz;
int dz;
int sn, cs;
dz = car_cosmetics[cp->ap.model].wheelDisp[0].vz + car_cosmetics[cp->ap.model].wheelDisp[1].vz;
ty = dz / 5;
@ -53,10 +54,13 @@ void InitCarPhysics(CAR_DATA* cp, LONGVECTOR4* startpos, int direction)
cp->hd.autoBrake = 0;
cp->st.n.orientation[0] = FIXEDH(-rcossin_tbl[(direction & 0xffeU) + 1] * ty);
cp->st.n.orientation[1] = rcossin_tbl[direction & 0xffeU];
cp->st.n.orientation[2] = FIXEDH(rcossin_tbl[direction & 0xffeU] * ty);
cp->st.n.orientation[3] = rcossin_tbl[(direction & 0xffeU) + 1];
sn = RSIN(direction / 2);
cs = RCOS(direction / 2);
cp->st.n.orientation[0] = FIXEDH(-cs * ty);
cp->st.n.orientation[1] = sn;
cp->st.n.orientation[2] = FIXEDH(sn * ty);
cp->st.n.orientation[3] = cs;
cp->st.n.fposition[0] = (*startpos)[0] << 4;
cp->st.n.fposition[1] = (*startpos)[1] << 4;
@ -95,7 +99,7 @@ void InitCarPhysics(CAR_DATA* cp, LONGVECTOR4* startpos, int direction)
void TempBuildHandlingMatrix(CAR_DATA* cp, int init)
{
int dz;
int ang;
int sn, cs;
dz = (car_cosmetics[cp->ap.model].wheelDisp[0].vz + car_cosmetics[cp->ap.model].wheelDisp[1].vz) / 5;
@ -106,12 +110,13 @@ void TempBuildHandlingMatrix(CAR_DATA* cp, int init)
cp->st.n.fposition[2] = cp->hd.where.t[2] << 4;
}
ang = cp->hd.direction & 0xffe;
sn = RSIN(cp->hd.direction / 2);
cs = RCOS(cp->hd.direction / 2);
cp->st.n.orientation[0] = FIXEDH(-rcossin_tbl[ang + 1] * dz);
cp->st.n.orientation[1] = rcossin_tbl[ang];
cp->st.n.orientation[2] = FIXEDH(rcossin_tbl[ang] * dz);
cp->st.n.orientation[3] = rcossin_tbl[ang + 1];
cp->st.n.orientation[0] = FIXEDH(-cs * dz);
cp->st.n.orientation[1] = sn;
cp->st.n.orientation[2] = FIXEDH(sn * dz);
cp->st.n.orientation[3] = cs;
RebuildCarMatrix(&cp->st, cp);
}

View File

@ -85,10 +85,9 @@ void HandleExplosion(void)
if (pauseflag != 0)
return;
i = 0;
exp = explosion;
while (i < MAX_EXPLOSION_OBJECTS)
for (i = 0; i < MAX_EXPLOSION_OBJECTS; i++)
{
if (exp->time != -1 && exp->type != BANG_USED)
{
@ -102,14 +101,11 @@ void HandleExplosion(void)
} while (cp < &car_data[MAX_CARS + 1]); // + TANNER_COLLIDER_CARID
}
i++;
exp++;
}
i = 0;
exp = explosion;
while (i < MAX_EXPLOSION_OBJECTS)
for (i = 0; i < MAX_EXPLOSION_OBJECTS; i++)
{
if (exp->time != -1)
{
@ -133,7 +129,6 @@ void HandleExplosion(void)
}
exp++;
i++;
}
}
@ -151,72 +146,66 @@ void initExplosion(void)
d1 = 0;
d2 = 128;
i = 0;
do {
for (i = 0; i < 18; i++)
{
vert[0].vy = 5;
vert[1].vy = -265;
vert[0].vx = FIXEDH(rcossin_tbl[(d1 & 0xf) * 512 + 1] * 512);
vert[0].vz = FIXEDH(rcossin_tbl[(d1 & 0xf) * 512] * 512);
vert[0].vx = FIXEDH(RCOS((d1 & 15) * 256) * 512);
vert[0].vz = FIXEDH(RSIN((d1 & 15) * 256) * 512);
vert[1].vx = FIXEDH(rcossin_tbl[(d2 & 0xfff) * 2 + 1] * 490);
vert[1].vz = FIXEDH(rcossin_tbl[(d2 & 0xfff) * 2] * 490);
vert[1].vx = FIXEDH(RCOS(d2) * 490);
vert[1].vz = FIXEDH(RSIN(d2) * 490);
vert += 2;
d1 += 2;
d2 += 512;
i++;
} while (i < 18);
}
vert = globemesh + 18;
d1 = 0x1280;
d2 = 0x1300;
i = 0;
do {
for (i = 0; i < 18; i+=2)
{
vert[0].vy = -265;
vert[1].vy = -505;
vert[0].vx = FIXEDH(rcossin_tbl[(d1 & 0xfff) * 2 + 1] * 490);
vert[0].vz = FIXEDH(rcossin_tbl[(d1 & 0xfff) * 2] * 490);
vert[1].vx = FIXEDH(rcossin_tbl[(d2 & 0xfff) * 2 + 1] * 330);
vert[1].vz = FIXEDH(rcossin_tbl[(d2 & 0xfff) * 2] * 330);
vert[0].vx = FIXEDH(RCOS(d1) * 490);
vert[0].vz = FIXEDH(RSIN(d1) * 490);
vert[1].vx = FIXEDH(RCOS(d2) * 330);
vert[1].vz = FIXEDH(RSIN(d2) * 330);
vert += 2;
d1 += 512;
d2 += 512;
i += 2;
} while (i < 18);
}
vert = globemesh + 36;
d1 = 0x2500;
d2 = 9600;
i = 0;
do {
for (i = 0; i < 18; i+=2)
{
vert[0].vy = -505;
vert[1].vy = -617;
vert[0].vx = FIXEDH(rcossin_tbl[(d1 & 0xfff) * 2 + 1] * 330);
vert[0].vz = FIXEDH(rcossin_tbl[(d1 & 0xfff) * 2] * 330);
vert[0].vx = FIXEDH(RCOS(d1) * 330);
vert[0].vz = FIXEDH(RSIN(d1) * 330);
vert[1].vx = FIXEDH(rcossin_tbl[(d2 & 0xfff) * 2 + 1] * 100);
vert[1].vz = FIXEDH(rcossin_tbl[(d2 & 0xfff) * 2] * 100);
vert[1].vx = FIXEDH(RCOS(d2) * 100);
vert[1].vz = FIXEDH(RSIN(d1) * 100);
vert += 2;
d1 += 512;
d2 += 512;
i += 2;
} while (i < 18);
}
}
@ -259,13 +248,13 @@ void DrawExplosion(int time, VECTOR position, int hscale, int rscale)
sf1 = FIXEDH(time * (5000 - time) * 4) + 12;
sf2 = FIXEDH(time * (10000 - time) * 2) + 12;
i = 0;
do {
sf = CameraCnt * (64 - i*90) & 0xfff;
for (i = 0; i < 2; i++)
{
sf = CameraCnt * (64 - i * 90);
SS.m[1][1] = FIXED(sf1 * hscale);
SS.m[0][0] = FIXEDH(FIXED(sf1 * rscale) * rcossin_tbl[sf * 2 + 1]);
SS.m[2][0] = FIXEDH(FIXED(sf1 * rscale) * rcossin_tbl[sf * 2]);
SS.m[0][0] = FIXEDH(FIXED(sf1 * rscale) * RCOS(sf));
SS.m[2][0] = FIXEDH(FIXED(sf1 * rscale) * RSIN(sf));
SS.m[0][2] = -SS.m[2][0];
SS.m[2][2] = SS.m[0][0];
@ -274,16 +263,16 @@ void DrawExplosion(int time, VECTOR position, int hscale, int rscale)
gte_SetRotMatrix(&workmatrix);
src = globemesh;
j = 0;
do {
poly = (POLY_FT4 *)current->primptr;
for (j = 0; j < 12; j++)
{
poly = (POLY_FT4*)current->primptr;
gte_ldv3(&src[0], &src[1], &src[2]);
gte_rtpt();
*(u_int *)&poly[0].r0 = rgb;
*(u_int *)&poly[1].r0 = rgb;
*(u_int*)&poly[0].r0 = rgb;
*(u_int*)&poly[1].r0 = rgb;
setPolyFT4(&poly[0]);
setSemiTrans(&poly[0], 1);
@ -297,6 +286,83 @@ void DrawExplosion(int time, VECTOR position, int hscale, int rscale)
gte_stsz(&z);
if (z > 32)
{
gte_ldv3(&src[3], &src[4], &src[5]);
gte_rtpt();
*(u_int*)&poly[0].u0 = u0;
*(u_int*)&poly[0].u1 = u1;
*(u_int*)&poly[0].u2 = u2;
*(u_int*)&poly[0].u3 = u3;
*(u_int*)&poly[1].u0 = u0;
*(u_int*)&poly[1].u1 = u1;
*(u_int*)&poly[1].u2 = u2;
*(u_int*)&poly[1].u3 = u3;
setPolyFT4(poly);
setSemiTrans(poly, 1);
setPolyFT4(&poly[1]);
setSemiTrans(&poly[1], 1);
gte_stsxy3(&poly[1].x1, &poly[1].x2, &poly[1].x3);
gte_stsxy0(&poly[0].x3);
addPrim(current->ot + (z >> 3), &poly[0]);
addPrim(current->ot + (z >> 3), &poly[1]);
current->primptr += sizeof(POLY_FT4) * 2;
}
if ((j & 3) == 3)
src += 6;
else
src += 4;
}
}
transparency = 255 - (time >> 4);
rgb = transparency >> 1;
rgb = (rgb + (transparency * transparency >> 10) >> 1 << 8 |
rgb + ((255 - transparency) * (transparency >> 2) + transparency * rgb >> 8) >> 1) << 8 |
rgb | 0x2e000000;
for (i = 0; i < 2; i++)
{
sf = CameraCnt * (i * -90 + 64);
SS.m[1][1] = FIXED(sf2 * hscale);
SS.m[0][0] = FIXEDH(FIXED(sf2 * rscale) * RCOS(sf));
SS.m[2][0] = FIXEDH(FIXED(sf2 * rscale) * RSIN(sf));
SS.m[0][2] = -SS.m[2][0];
SS.m[2][2] = SS.m[0][0];
MulMatrix0(&inv_camera_matrix, &SS, &workmatrix);
gte_SetRotMatrix(&workmatrix);
src = globemesh;
for (j = 0; j < 8; j++)
{
poly = (POLY_FT4 *)current->primptr;
gte_ldv3(&src[0], &src[1], &src[2]);
gte_rtpt();
*(u_int *)&poly[1].r0 = rgb;
*(u_int *)&poly[0].r0 = rgb;
gte_stsxy3(&poly[0].x0, &poly[0].x1, &poly[0].x2);
gte_stsxy2(&poly[1].x0);
gte_stsz(&z);
if (z > 32)
{
gte_ldv3(&src[3], &src[4], &src[5]);
@ -306,7 +372,6 @@ void DrawExplosion(int time, VECTOR position, int hscale, int rscale)
*(u_int *)&poly[0].u1 = u1;
*(u_int *)&poly[0].u2 = u2;
*(u_int *)&poly[0].u3 = u3;
*(u_int *)&poly[1].u0 = u0;
*(u_int *)&poly[1].u1 = u1;
*(u_int *)&poly[1].u2 = u2;
@ -332,90 +397,8 @@ void DrawExplosion(int time, VECTOR position, int hscale, int rscale)
src += 6;
else
src += 4;
j++;
} while (j < 12);
i++;
} while (i < 2);
transparency = 255 - (time >> 4);
rgb = transparency >> 1;
rgb = (rgb + (transparency * transparency >> 10) >> 1 << 8 |
rgb + ((255 - transparency) * (transparency >> 2) + transparency * rgb >> 8) >> 1) << 8 |
rgb | 0x2e000000;
i = 0;
do {
sf = CameraCnt * (i * -90 + 64) & 0xfff;
SS.m[1][1] = FIXED(sf2 * hscale);
SS.m[0][0] = FIXEDH(FIXED(sf2 * rscale) * rcossin_tbl[sf * 2 + 1]);
SS.m[2][0] = FIXEDH(FIXED(sf2 * rscale) * rcossin_tbl[sf * 2]);
SS.m[0][2] = -SS.m[2][0];
SS.m[2][2] = SS.m[0][0];
MulMatrix0(&inv_camera_matrix, &SS, &workmatrix);
gte_SetRotMatrix(&workmatrix);
src = globemesh;
j = 0;
do {
poly = (POLY_FT4 *)current->primptr;
gte_ldv3(&src[0], &src[1], &src[2]);
gte_rtpt();
*(u_int *)&poly[1].r0 = rgb;
*(u_int *)&poly[0].r0 = rgb;
gte_stsxy3(&poly[0].x0, &poly[0].x1, &poly[0].x2);
gte_stsxy2(&poly[1].x0);
gte_stsz(&z);
if (z > 32)
{
gte_ldv3(&src[3], &src[4], &src[5]);
gte_rtpt();
*(u_int *)&poly[0].u0 = u0;
*(u_int *)&poly[0].u1 = u1;
*(u_int *)&poly[0].u2 = u2;
*(u_int *)&poly[0].u3 = u3;
*(u_int *)&poly[1].u0 = u0;
*(u_int *)&poly[1].u1 = u1;
*(u_int *)&poly[1].u2 = u2;
*(u_int *)&poly[1].u3 = u3;
setPolyFT4(poly);
setSemiTrans(poly, 1);
setPolyFT4(&poly[1]);
setSemiTrans(&poly[1], 1);
gte_stsxy3(&poly[1].x1, &poly[1].x2, &poly[1].x3);
gte_stsxy0(&poly[0].x3);
addPrim(current->ot + (z >> 3), &poly[0]);
addPrim(current->ot + (z >> 3), &poly[1]);
current->primptr += sizeof(POLY_FT4) * 2;
}
if (j & 3 == 3)
src += 6;
else
src += 4;
j++;
} while (j < 8);
i++;
} while (i < 2);
}
}
}
@ -423,13 +406,11 @@ void DrawExplosion(int time, VECTOR position, int hscale, int rscale)
void DrawAllExplosions(void)
{
int i;
i = 0;
while (i < MAX_EXPLOSION_OBJECTS)
for (i = 0; i < MAX_EXPLOSION_OBJECTS; i++)
{
if (explosion[i].time != -1)
DrawExplosion(explosion[i].time, explosion[i].pos, explosion[i].hscale, explosion[i].rscale);
i++;
}
}

View File

@ -259,8 +259,8 @@ void LeadUpdateState(CAR_DATA* cp)
CheckCurrentRoad(cp);
dx = (cp->ai.l.targetX - x) * rcossin_tbl[(cp->hd.direction & 0xfff) * 2];
dz = (cp->ai.l.targetZ - z) * rcossin_tbl[(cp->hd.direction & 0xfff) * 2 + 1];
dx = (cp->ai.l.targetX - x) * RSIN(cp->hd.direction);
dz = (cp->ai.l.targetZ - z) * RCOS(cp->hd.direction);
dist = FIXEDH(dx + dz);
@ -444,8 +444,8 @@ u_int LeadPadResponse(CAR_DATA* cp)
volatile int deltaVel;
volatile int steerDelta;
dx = -rcossin_tbl[(cp->ai.l.targetDir & 0xfff) * 2 + 1] * (cp->hd.where.t[0] - cp->ai.l.targetX);
dz = rcossin_tbl[(cp->ai.l.targetDir & 0xfff) * 2] * (cp->hd.where.t[2] - cp->ai.l.targetZ);
dx = -RCOS(cp->ai.l.targetDir) * (cp->hd.where.t[0] - cp->ai.l.targetX);
dz = RSIN(cp->ai.l.targetDir) * (cp->hd.where.t[2] - cp->ai.l.targetZ);
deltaPos = FIXEDH(dx + dz);
@ -455,8 +455,8 @@ u_int LeadPadResponse(CAR_DATA* cp)
deltaPos = maxDist;
deltaVel = FIXEDH(
-rcossin_tbl[(cp->ai.l.targetDir & 0xfff) * 2 + 1] * FIXEDH(cp->st.n.linearVelocity[0])
+ rcossin_tbl[(cp->ai.l.targetDir & 0xfff) * 2] * FIXEDH(cp->st.n.linearVelocity[2]));
- RCOS(cp->ai.l.targetDir) * FIXEDH(cp->st.n.linearVelocity[0])
+ RSIN(cp->ai.l.targetDir) * FIXEDH(cp->st.n.linearVelocity[2]));
steerDelta = FIXEDH(
pathParams[0] * deltaVel
@ -649,8 +649,9 @@ void FakeMotion(CAR_DATA* cp)
nextJunction = (straight->ConnectIdx[2]);
}
c = rcossin_tbl[(angle & 0xfff) * 2];
s = rcossin_tbl[(angle & 0xfff) * 2 + 1];
// WARNING: variables are flipped!
c = RSIN(angle);
s = RCOS(angle);
d = FIXEDH(c * dx + s * dz);
@ -706,8 +707,8 @@ void FakeMotion(CAR_DATA* cp)
cp->ai.l.targetDir = (dir + 1024) & 0xfff;
cp->hd.where.t[0] = FIXEDH(rcossin_tbl[(dir & 0xfff) * 2] * radius) + curve->Midx;
cp->hd.where.t[2] = FIXEDH(rcossin_tbl[(dir & 0xfff) * 2 + 1] * radius) + curve->Midz;
cp->hd.where.t[0] = FIXEDH(RSIN(dir)* radius) + curve->Midx;
cp->hd.where.t[2] = FIXEDH(RCOS(dir) * radius) + curve->Midz;
return;
}
@ -723,8 +724,8 @@ void FakeMotion(CAR_DATA* cp)
cp->ai.l.targetDir = (dir - 1024) & 0xfff;
cp->hd.where.t[0] = FIXEDH(rcossin_tbl[(dir & 0xfff) * 2] * radius) + curve->Midx;
cp->hd.where.t[2] = FIXEDH(rcossin_tbl[(dir & 0xfff) * 2 + 1] * radius) + curve->Midz;
cp->hd.where.t[0] = FIXEDH(RSIN(dir) * radius) + curve->Midx;
cp->hd.where.t[2] = FIXEDH(RCOS(dir) * radius) + curve->Midz;
return;
}
@ -767,7 +768,7 @@ void PosToIndex(int* normal, int* tangent, int intention, CAR_DATA* cp)
{
int dist;
dist = FIXEDH(*tangent * rcossin_tbl[(*normal & 0xfff) * 2]);
dist = FIXEDH(*tangent * RSIN(*normal));
if (dist > 125)
{
@ -1017,8 +1018,8 @@ void BlockToMap(MAP_DATA* data)
tangent = ratan2(dx, dz);
s = rcossin_tbl[((tangent + 1024u) & 0xfff) * 2];
c = rcossin_tbl[((tangent + 1024u) & 0xfff) * 2 + 1];
s = RSIN(tangent + 1024);
c = RCOS(tangent + 1024);
tangent = DIFF_ANGLES(data->cp->ai.l.base_Angle, tangent) * //(((tangent - data->cp->ai.l.base_Angle) + 2048U & 0xfff) - 2048) *
data->cp->ai.l.base_Dir * ((curve->inside * 45056) / 28672);
@ -1099,8 +1100,8 @@ void BlockToMap(MAP_DATA* data)
angle = DIFF_ANGLES(0, ratan2(dx, dz)); //(ratan2(dx, dz) + 2048U & 0xfff) - 2048;
s = rcossin_tbl[(angle & 0xfff) * 2];
c = rcossin_tbl[(angle & 0xfff) * 2 + 1];
s = RSIN(angle);
c = RCOS(angle);
someVar = FIXEDH(ABS(data->size->vx * s) + ABS(data->size->vz * c));
@ -1187,10 +1188,10 @@ void BlockToMap(MAP_DATA* data)
dx = corners[left][1] - corners[right][1];
dy = corners[left][0] - corners[right][0];
theta = (ratan2(dy, dx) + 3072u & 0xfff) - 2048;
theta = (ratan2(dy, dx) + 3072 & 0xfff) - 2048; // there should be DIFF_ANGLES but idk
vx = rcossin_tbl[(theta & 0xfff) * 2] * corners[left][0];
vz = rcossin_tbl[(theta & 0xfff) * 2 + 1] * corners[left][1];
vx = RSIN(theta) * corners[left][0];
vz = RCOS(theta) * corners[left][1];
left = DIFF_ANGLES(data->cp->hd.direction, corners[left][2]); // corners[left][2] - data->cp->hd.direction;
right = DIFF_ANGLES(data->cp->hd.direction, corners[right][2]); // corners[right][2] - data->cp->hd.direction;
@ -1458,8 +1459,8 @@ void UpdateRoadPosition(CAR_DATA* cp, VECTOR* basePos, int intention)
laneAvoid = -1;
road_s = rcossin_tbl[(cp->ai.l.targetDir & 0xfff) * 2];
road_c = rcossin_tbl[(cp->ai.l.targetDir & 0xfff) * 2 + 1];
road_s = RSIN(cp->ai.l.targetDir);
road_c = RCOS(cp->ai.l.targetDir);
ClearCopUsage();
@ -1525,13 +1526,13 @@ void UpdateRoadPosition(CAR_DATA* cp, VECTOR* basePos, int intention)
{
int cs, sn;
theta = (tempCO.yang + collide->yang) * 64 & 0xfff;
theta = (tempCO.yang + collide->yang) * 64;
xsize = collide->xsize / 2;
zsize = collide->zsize / 2;
cs = rcossin_tbl[theta * 2 + 1];
sn = rcossin_tbl[theta * 2];
cs = RCOS(theta);
sn = RSIN(theta);
size.vx = FIXEDH(ABS(zsize * sn) + ABS(xsize * cs));
size.vy = collide->ysize;
@ -1565,13 +1566,13 @@ void UpdateRoadPosition(CAR_DATA* cp, VECTOR* basePos, int intention)
cd[0].length[1] = collide->xsize / 2;
// calc axes of box
int dtheta = cd[0].theta & 0xfff;
int dtheta = cd[0].theta;
cd[0].axis[0].vx = rcossin_tbl[dtheta * 2];
cd[0].axis[0].vz = rcossin_tbl[dtheta * 2 + 1];
cd[0].axis[0].vx = RSIN(dtheta);
cd[0].axis[0].vz = RCOS(dtheta);
cd[0].axis[1].vz = -rcossin_tbl[dtheta * 2];
cd[0].axis[1].vx = rcossin_tbl[dtheta * 2 + 1];
cd[0].axis[1].vz = -RSIN(dtheta);
cd[0].axis[1].vx = RCOS(dtheta);
extern void Debug_AddLine(VECTOR & pointA, VECTOR & pointB, CVECTOR & color);
extern void Debug_AddLineOfs(VECTOR & pointA, VECTOR & pointB, VECTOR & ofs, CVECTOR & color);
@ -2194,9 +2195,9 @@ void CheckCurrentRoad(CAR_DATA* cp)
else
nextJunction = straight->ConnectIdx[3];
}
s = rcossin_tbl[(angle & 0xfff) * 2];
c = rcossin_tbl[(angle & 0xfff) * 2 + 1];
s = RSIN(angle);
c = RCOS(angle);
d = FIXEDH(s * dx + c * dz);
@ -2383,8 +2384,8 @@ void CheckCurrentRoad(CAR_DATA* cp)
straight = GET_STRAIGHT(currentRoad);
sn = rcossin_tbl[(heading & 0xfff) * 2];
cs = rcossin_tbl[(heading & 0xfff) * 2 + 1];
sn = RSIN(heading);
cs = RCOS(heading);
offx = straight->Midx - cp->hd.where.t[0];
offz = straight->Midz - cp->hd.where.t[2];
@ -2421,10 +2422,10 @@ void CheckCurrentRoad(CAR_DATA* cp)
angle = ratan2(dx, dz);
// check directions
if (angle - heading & 0x800)
if (angle - heading & 2048)
{
basex = FIXEDH(rcossin_tbl[(curve->start & 0xfff) * 2] * radius);
basez = FIXEDH(rcossin_tbl[(curve->start & 0xfff) * 2 + 1] * radius);
basex = FIXEDH(RSIN(curve->start) * radius);
basez = FIXEDH(RCOS(curve->start) * radius);
cp->ai.l.base_Normal = cp->ai.l.d = hypot(dx, dz);
cp->ai.l.base_Dir = 1;
@ -2433,8 +2434,8 @@ void CheckCurrentRoad(CAR_DATA* cp)
}
else
{
basex = FIXEDH(rcossin_tbl[(curve->end & 0xfff) * 2] * radius);
basez = FIXEDH(rcossin_tbl[(curve->end & 0xfff) * 2 + 1] * radius);
basex = FIXEDH(RSIN(curve->end) * radius);
basez = FIXEDH(RCOS(curve->end) * radius);
cp->ai.l.base_Normal = cp->ai.l.d = hypot(dx, dz);
cp->ai.l.base_Dir = -1;
@ -2446,9 +2447,9 @@ void CheckCurrentRoad(CAR_DATA* cp)
offx = basex - cp->hd.where.t[0];
offz = basez - cp->hd.where.t[2];
dist = -FIXEDH(offx * rcossin_tbl[(heading & 0xfff) * 2] + offz * rcossin_tbl[(heading & 0xfff) * 2 + 1]);
dx = FIXEDH(rcossin_tbl[(heading & 0xfff) * 2] * dist);
dz = FIXEDH(rcossin_tbl[(heading & 0xfff) * 2 + 1] * dist);
dist = -FIXEDH(offx * RSIN(heading) + offz * RCOS(heading));
dx = FIXEDH(RSIN(heading) * dist);
dz = FIXEDH(RCOS(heading) * dist);
basePosition.vx = basex + dx;
basePosition.vy = cp->hd.where.t[1];
@ -2538,15 +2539,17 @@ void SetTarget(CAR_DATA* cp, int curRoad, int heading, int* nextJunction)
if (cp->ai.l.offRoad == 1)
{
cp->ai.l.targetDir = cp->ai.l.roadPosition;
int dir = cp->ai.l.roadPosition;
// get the road
dx = FIXEDH(rcossin_tbl[(cp->ai.l.targetDir & 0xfff) * 2 + 1] * cp->ai.l.roadForward);
dz = FIXEDH(rcossin_tbl[(cp->ai.l.targetDir & 0xfff) * 2] * cp->ai.l.roadForward);
dx = FIXEDH(RCOS(dir) * cp->ai.l.roadForward);
dz = FIXEDH(RSIN(dir) * cp->ai.l.roadForward);
cp->ai.l.targetX = cp->hd.where.t[0] + dx;
cp->ai.l.targetZ = cp->hd.where.t[2] + dz;
cp->ai.l.targetDir = dir;
return;
}
@ -2577,17 +2580,18 @@ void SetTarget(CAR_DATA* cp, int curRoad, int heading, int* nextJunction)
*nextJunction = straight->ConnectIdx[3];
}
angle = cp->ai.l.targetDir + 1024U & 0xfff;
d = cp->ai.l.targetDir & 0xfff;
dx = straight->Midx - cp->hd.where.t[0];
dz = straight->Midz - cp->hd.where.t[2];
rx = FIXEDH(rcossin_tbl[d * 2] * cp->ai.l.roadForward);
rz = FIXEDH(rcossin_tbl[d * 2 + 1] * cp->ai.l.roadForward);
angle = cp->ai.l.targetDir;
rx = FIXEDH(RSIN(angle) * cp->ai.l.roadForward);
rz = FIXEDH(RCOS(angle) * cp->ai.l.roadForward);
ux = rcossin_tbl[angle * 2];
uz = rcossin_tbl[angle * 2 + 1];
angle = cp->ai.l.targetDir + 1024;
ux = RSIN(angle);
uz = RCOS(angle);
// l.roadPosition gives the lane offset
// [A] it's obviously bugged somewhere as car always tends to be on left lanes
@ -2640,8 +2644,8 @@ void SetTarget(CAR_DATA* cp, int curRoad, int heading, int* nextJunction)
*nextJunction = curve->ConnectIdx[3];
}
cp->ai.l.targetX = curve->Midx + FIXEDH(radius * rcossin_tbl[(angle & 0xfff) * 2]);
cp->ai.l.targetZ = curve->Midz + FIXEDH(radius * rcossin_tbl[(angle & 0xfff) * 2 + 1]);
cp->ai.l.targetX = curve->Midx + FIXEDH(radius * RSIN(angle));
cp->ai.l.targetZ = curve->Midz + FIXEDH(radius * RCOS(angle));
}
}

View File

@ -538,7 +538,7 @@ void DrawBodySprite(PEDESTRIAN* pDrawingPed, int boneId, VERTTYPE v1[2], VERTTYP
{
// make ped thinner from side view
u_int ang;
ang = rcossin_tbl[((pDrawingPed->dir.vy + camera_angle.vy) * 4 & 0xfffU) + 1] >> 6;
ang = RCOS((pDrawingPed->dir.vy + camera_angle.vy) * 2) >> 6;
z2 += ang;
}
@ -567,10 +567,10 @@ void DrawBodySprite(PEDESTRIAN* pDrawingPed, int boneId, VERTTYPE v1[2], VERTTYP
x = v1[0] - v2[0];
y = v1[1] - v2[1];
angle = ratan2(y, x);
angle = -ratan2(y, x);
cs = FIXEDH(z2 * rcossin_tbl[(-angle & 0xfffU) * 2] * (width & 0x3f) * 2);
sn = FIXEDH(z2 * rcossin_tbl[(-angle & 0xfffU) * 2 + 1] * (width & 0x3f) * 2);
cs = FIXEDH(z2 * RSIN(angle) * (width & 0x3f) * 2);
sn = FIXEDH(z2 * RCOS(angle) * (width & 0x3f) * 2);
tmp = MainPed[bone].cAdj & 0xf;
@ -623,10 +623,10 @@ void DrawBodySprite(PEDESTRIAN* pDrawingPed, int boneId, VERTTYPE v1[2], VERTTYP
// compute normalization lengths
len = 1.0 / sqrtf(float(x*x) + float(y*y) + 1.0);
angle = ratan2(y, x);
angle = -ratan2(y, x);
sn = rcossin_tbl[(-angle & 0xfffU) * 2] * width;
cs = rcossin_tbl[(-angle & 0xfffU) * 2 + 1] * width;
sn = RSIN(angle) * width;
cs = RCOS(angle) * width;
tmp = MainPed[bone].cAdj & 0xf;

View File

@ -74,11 +74,11 @@ char CellEmpty(VECTOR *pPosition, int radius)
zs = collide->zsize * 0x800 + radius * 0x1000;
xs = collide->xsize * 0x800 + radius * 0x1000;
theta = (tempCO.yang + collide->yang) * 64 & 0xfff;
theta = (tempCO.yang + collide->yang) * 64;
ypos = pPosition->vy + (tempCO.pos.vy + collide->ypos) + 80;
cs = rcossin_tbl[theta * 2 + 1];
sn = rcossin_tbl[theta * 2];
cs = RCOS(theta);
sn = RSIN(theta);
*/
// [A] NEW
@ -88,12 +88,12 @@ char CellEmpty(VECTOR *pPosition, int radius)
MATRIX2* mat;
yang = -tempCO.yang & 0x3f;
theta = (tempCO.yang + collide->yang) * 64 & 0xfff;
theta = (tempCO.yang + collide->yang) * 64;
mat = &matrixtable[yang];
cs = rcossin_tbl[theta * 2 + 1];
sn = rcossin_tbl[theta * 2];
cs = RCOS(theta);
sn = RSIN(theta);
xxd = FIXEDH(collide->xpos * mat->m[0][0] + collide->zpos * mat->m[2][0]);
zzd = FIXEDH(collide->xpos * mat->m[0][2] + collide->zpos * mat->m[2][2]);
@ -132,11 +132,11 @@ char CellEmpty(VECTOR *pPosition, int radius)
// calc axes of box
int dtheta = cd[0].theta & 0xfff;
cd[0].axis[0].vx = rcossin_tbl[dtheta * 2];
cd[0].axis[0].vz = rcossin_tbl[dtheta * 2 + 1];
cd[0].axis[0].vx = RSIN(dtheta);
cd[0].axis[0].vz = RCOS(dtheta);
cd[0].axis[1].vz = -rcossin_tbl[dtheta * 2];
cd[0].axis[1].vx = rcossin_tbl[dtheta * 2 + 1];
cd[0].axis[1].vz = -RSIN(dtheta);
cd[0].axis[1].vx = RCOS(dtheta);
extern void Debug_AddLine(VECTOR & pointA, VECTOR & pointB, CVECTOR & color);
extern void Debug_AddLineOfs(VECTOR & pointA, VECTOR & pointB, VECTOR & ofs, CVECTOR & color);
@ -396,12 +396,12 @@ char lineClear(VECTOR *v1, VECTOR *v2)
while (box_loop < num_cb)
{
yang = -tempCO.yang & 0x3f;
theta = (tempCO.yang + collide->yang) * 64 & 0xfff;
theta = (tempCO.yang + collide->yang) * 64;
mat = &matrixtable[yang];
cs = rcossin_tbl[theta * 2 + 1];
sn = rcossin_tbl[theta * 2];
cs = RCOS(theta);
sn = RSIN(theta);
dx = va.vx - (tempCO.pos.vx + FIXEDH(collide->xpos * mat->m[0][0] + collide->zpos * mat->m[2][0]));
dz = va.vz - (tempCO.pos.vz + FIXEDH(collide->xpos * mat->m[0][2] + collide->zpos * mat->m[2][2]));
@ -442,11 +442,11 @@ char lineClear(VECTOR *v1, VECTOR *v2)
// calc axes of box
int dtheta = cd[0].theta & 0xfff;
cd[0].axis[0].vx = rcossin_tbl[dtheta * 2];
cd[0].axis[0].vz = rcossin_tbl[dtheta * 2 + 1];
cd[0].axis[0].vx = RSIN(dtheta);
cd[0].axis[0].vz = RCOS(dtheta);
cd[0].axis[1].vz = -rcossin_tbl[dtheta * 2];
cd[0].axis[1].vx = rcossin_tbl[dtheta * 2 + 1];
cd[0].axis[1].vz = -RSIN(dtheta);
cd[0].axis[1].vx = RCOS(dtheta);
extern void Debug_AddLine(VECTOR & pointA, VECTOR & pointB, CVECTOR & color);
extern void Debug_AddLineOfs(VECTOR & pointA, VECTOR & pointB, VECTOR & ofs, CVECTOR & color);
@ -752,10 +752,8 @@ void CheckScenaryCollisions(CAR_DATA *cp)
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);
cp->hd.where.t[0] = car_data[0].hd.where.t[0] + FIXEDH((gCameraDistance * RSIN(cp->hd.direction)) / 2);
cp->hd.where.t[2] = car_data[0].hd.where.t[2] + FIXEDH((gCameraDistance * RCOS(cp->hd.direction)) / 2);
coll_test_count--;
}

View File

@ -317,8 +317,8 @@ void DrawPlayerDot(VECTOR *pos, short rot, u_char r, u_char g, u_char b, int fla
vec.vz += map_z_offset;
}
sn = rcossin_tbl[(rot & 0xfffU) * 2];
cs = rcossin_tbl[(rot & 0xfffU) * 2 + 1];
sn = RSIN(rot);
cs = RCOS(rot);
opos[2].vx = vec.vx;
opos[2].vz = vec.vz;
@ -615,10 +615,8 @@ void DrawCompass(void)
void DrawBigCompass(VECTOR *root, int angle)
{
int i;
u_int ang2;
LINE_G2 *lineg2;
int ang;
int ang3;
int ang, ang2, sn, cs;
VECTOR *pPosition;
VECTOR position[5];
@ -626,24 +624,34 @@ void DrawBigCompass(VECTOR *root, int angle)
position[2].vx = root->vx + map_x_offset;
position[2].vy = root->vz + map_z_offset;
position[1].vx = position[2].vx + (rcossin_tbl[ang * 2] * 0x19 >> 0xc);
position[0].vx = position[2].vx + (rcossin_tbl[ang * 2] * 0xf >> 0xb);
sn = RSIN(ang);
cs = RCOS(ang);
position[1].vx = position[2].vx + (sn * 0x19 >> 0xc);
position[0].vx = position[2].vx + (sn * 0xf >> 0xb);
position[1].vy = position[2].vy + (cs * 0x19 >> 0xc);
position[0].vz = position[2].vy + (cs * 0xf >> 0xb);
ang2 = ang - 200 & 0xfff;
ang3 = ang + 200 & 0xfff;
sn = RSIN(ang2);
cs = RCOS(ang2);
position[1].vy = position[2].vy + (rcossin_tbl[ang * 2 + 1] * 0x19 >> 0xc);
position[0].vz = position[2].vy + (rcossin_tbl[ang * 2 + 1] * 0xf >> 0xb);
position[3].vx = position[2].vx + (rcossin_tbl[ang2 * 2] * 5 >> 10);
position[3].vy = position[2].vy + (rcossin_tbl[ang2 * 2 + 1] * 5 >> 10);
position[4].vx = position[2].vx + (rcossin_tbl[ang3 * 2] * 5 >> 10);
position[4].vy = position[2].vy + (rcossin_tbl[ang3 * 2 + 1] * 5 >> 10);
position[3].vx = position[2].vx + (sn * 5 >> 10);
position[3].vy = position[2].vy + (cs * 5 >> 10);
ang2 = ang + 200 & 0xfff;
sn = RSIN(ang2);
cs = RCOS(ang2);
position[4].vx = position[2].vx + (sn * 5 >> 10);
position[4].vy = position[2].vy + (cs * 5 >> 10);
i = 0;
pPosition = position + 2;
do {
lineg2 = (LINE_G2 *)current->primptr;
for (i = 0; i < 3; i++)
{
lineg2 = (LINE_G2*)current->primptr;
setLineG2(lineg2);
setSemiTrans(lineg2, 1);
@ -666,9 +674,7 @@ void DrawBigCompass(VECTOR *root, int angle)
pPosition++;
//current->primptr += sizeof(LINE_G2);
i++;
} while (i < 3);
}
DrawN(position, 1);
}
@ -764,8 +770,8 @@ void DrawSightCone(COP_SIGHT_DATA *pCopSightData, VECTOR *pPosition, int directi
dir = angle + direction & 0xfff;
angle += 512;
pVertex->vx = vertex[0].vx + FIXEDH(rcossin_tbl[dir * 2] * temp);
pVertex->vz = vertex[0].vz + FIXEDH(rcossin_tbl[dir * 2 + 1] * temp);
pVertex->vx = vertex[0].vx + FIXEDH(RSIN(dir) * temp);
pVertex->vz = vertex[0].vz + FIXEDH(RCOS(dir) * temp);
pVertex++;
@ -837,12 +843,12 @@ u_int Long2DDistance(VECTOR *pPoint1, VECTOR *pPoint2)
if ((theta & 0x7ff) - 512U <= 1024)
{
tempTheta = rcossin_tbl[(theta & 0xfff) * 2];
tempTheta = RSIN(theta);
result = delta.vz;
}
else
{
tempTheta = rcossin_tbl[(theta & 0xfff) * 2 + 1];
tempTheta = RCOS(theta);
result = delta.vx;
}
@ -1803,8 +1809,8 @@ void DrawCopIndicators(void)
int p, q;
CAR_DATA *cp;
cc = rcossin_tbl[(player[0].dir & 0xfffU) * 2 + 1];
cs = rcossin_tbl[(player[0].dir & 0xfffU) * 2];
cc = RCOS(player[0].dir);
cs = RSIN(player[0].dir);
cp = car_data;
do {

View File

@ -361,12 +361,8 @@ void PlaceRoadBlockCops(void)
cp++;
} while (cp < &car_data[MAX_CARS]);
if (!numCops)
return;
i = 0;
do {
for (i = 0; i < numCops; i++)
{
pCar = pCopCars[i];
sn = rsin(pCar->hd.direction);
@ -382,9 +378,9 @@ void PlaceRoadBlockCops(void)
if (FIXED(cs * 0x1000) * disp[0] - FIXED(sn * 0x1000) * disp[2] + 0x800 < 0)
wbody = -wbody;
dir = pCar->hd.direction + 0x800U & 0xfff;
cs = rcossin_tbl[dir * 2 + 1];
sn = rcossin_tbl[dir * 2];
dir = pCar->hd.direction + 2048;
cs = RCOS(dir);
sn = RSIN(dir);
disp[0] = pCar->hd.where.t[0] - (FIXED(wbody * cs) - FIXED(lbody * sn));
disp[1] = -pCar->hd.where.t[1];
@ -399,9 +395,7 @@ void PlaceRoadBlockCops(void)
if (CreatePedAtLocation(&disp, 13) != 0)
numCopPeds++;
i++;
} while (i < numCops);
}
}
// [D] [T]
@ -613,14 +607,14 @@ void AnimatePed(PEDESTRIAN* pPed)
if (pPed->speed < 0)
{
dir = pPed->dir.vy;
pPed->position.vx -= FIXED(pPed->speed * rcossin_tbl[(dir & 0xfff) * 2]);
pPed->position.vz -= FIXED(pPed->speed * rcossin_tbl[(-dir & 0xfffU) * 2 + 1]);
pPed->position.vx -= FIXED(pPed->speed * RSIN(dir));
pPed->position.vz -= FIXED(pPed->speed * RCOS(-dir));
}
else
{
dir = pPed->dir.vy - 0x800U & 0xfff;
pPed->position.vx += FIXED(pPed->speed * rcossin_tbl[dir * 2]);
pPed->position.vz += FIXED(pPed->speed * rcossin_tbl[dir * 2 + 1]);
dir = pPed->dir.vy - 2048;
pPed->position.vx += FIXED(pPed->speed * RSIN(dir));
pPed->position.vz += FIXED(pPed->speed * RCOS(dir));
}
if (pPed->type != PED_ACTION_SIT &&
@ -1117,15 +1111,15 @@ void SetupGetOutCar(PEDESTRIAN* pPed, CAR_DATA* pCar, int side)
else
xOfs = 400;
carDir = pCar->hd.direction + 0x800U & 0xfff;
carDir = pCar->hd.direction + 2048;
if (NoPlayerControl == 0)
{
player[playerId].cameraView = 5;
player[playerId].cameraPos.vx = pCar->hd.where.t[0] - (FIXED(xOfs * rcossin_tbl[carDir * 2 + 1]) - FIXED(rcossin_tbl[carDir * 2] * 800));
player[playerId].cameraPos.vx = pCar->hd.where.t[0] - (FIXED(xOfs * RCOS(carDir)) - FIXED(RSIN(carDir) * 800));
player[playerId].cameraPos.vy = -200 - pCar->hd.where.t[1];
player[playerId].cameraPos.vz = pCar->hd.where.t[2] + (FIXED(xOfs * rcossin_tbl[carDir * 2]) + FIXED(rcossin_tbl[carDir * 2 + 1] * 800));
player[playerId].cameraPos.vz = pCar->hd.where.t[2] + (FIXED(xOfs * RSIN(carDir)) + FIXED(RCOS(carDir) * 800));
}
pPed->frame1 = 0;
@ -1165,14 +1159,14 @@ void SetupGetInCar(PEDESTRIAN* pPed)
else
xOfs = 400;
carDir = carToGetIn->hd.direction + 0x800U & 0xfff;
carDir = carToGetIn->hd.direction + 2048;
if (NoPlayerControl == 0 && gInGameCutsceneActive == 0)
{
player[playerId].cameraView = 5;
player[playerId].cameraPos.vx = carToGetIn->hd.where.t[0] - (FIXED(xOfs * rcossin_tbl[carDir * 2 + 1]) - FIXED(rcossin_tbl[carDir * 2] * 800));
player[playerId].cameraPos.vx = carToGetIn->hd.where.t[0] - (FIXED(xOfs * RCOS(carDir)) - FIXED(RSIN(carDir) * 800));
player[playerId].cameraPos.vy = -200 - carToGetIn->hd.where.t[1];
player[playerId].cameraPos.vz = carToGetIn->hd.where.t[2] + (FIXED(xOfs * rcossin_tbl[carDir * 2]) + FIXED(rcossin_tbl[carDir * 2 + 1] * 800));
player[playerId].cameraPos.vz = carToGetIn->hd.where.t[2] + (FIXED(xOfs * RSIN(carDir)) + FIXED(RCOS(carDir) * 800));
}
if ((carToGetIn->controlFlags & CONTROL_FLAG_WAS_PARKED) == 0)
@ -1428,8 +1422,8 @@ void PingInPedestrians(void)
pingInDist = Random2(0) % 128 + 1536;
randomLoc.vy = baseLoc.vy;
randomLoc.vx = baseLoc.vx + pingInDist * FIXEDH(rcossin_tbl[(pinginPedAngle & 0xfffU) * 2] * 8);
randomLoc.vz = baseLoc.vz + pingInDist * FIXEDH(rcossin_tbl[(pinginPedAngle & 0xfffU) * 2 + 1] * 8);
randomLoc.vx = baseLoc.vx + pingInDist * FIXEDH(RSIN(pinginPedAngle) * 8);
randomLoc.vz = baseLoc.vz + pingInDist * FIXEDH(RCOS(pinginPedAngle) * 8);
randomLoc.vy = -MapHeight(&randomLoc);
@ -1616,11 +1610,11 @@ int FindPointOfCollision(CAR_DATA* pCar, PEDESTRIAN* pPed)
#endif
dx = FIXED((collisionResult.hit.vx - cd[1].x.vx) * rcossin_tbl[(cd[1].theta & 0xfffU) * 2 + 1]) -
FIXED((collisionResult.hit.vz - cd[1].x.vz) * rcossin_tbl[(cd[1].theta & 0xfffU) * 2]);
dx = FIXED((collisionResult.hit.vx - cd[1].x.vx) * RCOS(cd[1].theta)) -
FIXED((collisionResult.hit.vz - cd[1].x.vz) * RSIN(cd[1].theta));
dz = FIXED((collisionResult.hit.vx - cd[1].x.vx) * rcossin_tbl[(cd[1].theta & 0xfffU) * 2]) +
FIXED((collisionResult.hit.vz - cd[1].x.vz) * rcossin_tbl[(cd[1].theta & 0xfffU) * 2 + 1]);
dz = FIXED((collisionResult.hit.vx - cd[1].x.vx) * RSIN(cd[1].theta)) +
FIXED((collisionResult.hit.vz - cd[1].x.vz) * RCOS(cd[1].theta));
minX = car_cos->colBox.vx + 96;
maxX = car_cos->colBox.vx - 96;
@ -1782,12 +1776,13 @@ void SetupCivJump(PEDESTRIAN* pPed, CAR_DATA* cp)
pPed->frame1 = 0;
pPed->speed = 30;
// if player horns make scare box bigger and give player felony
if (cp == &car_data[player[0].playerCarId])
{
if (player[0].horn.on != 0)
scale = 0x800;
scale = 2048;
else
scale = 0x1000;
scale = 4096;
NoteFelony(&felonyData, 1, scale);
}
@ -1807,14 +1802,18 @@ void SetupCivJump(PEDESTRIAN* pPed, CAR_DATA* cp)
}
else
{
int d;
dx = player[0].pPed->position.vx - pPed->position.vx;
dz = player[0].pPed->position.vz - pPed->position.vz;
dir[0] = player[0].pPed->speed * rcossin_tbl[(player[0].pPed->dir.vy - 0x800U & 0xfff) * 2 + 1];
dir[2] = player[0].pPed->speed * rcossin_tbl[(player[0].pPed->dir.vy - 0x800U & 0xfff) * 2];
d = player[0].pPed->dir.vy - 2048;
dir[0] = player[0].pPed->speed * RCOS(d);
dir[2] = player[0].pPed->speed * RSIN(d);
// [A] fuck....
if (FIXED(-dir[0]) * dx + FIXED(dir[2]) * dz + 0x800 < 0)
if (FIXED(-dir[0]) * dx + FIXED(dir[2]) * dz + 2048 < 0)
angle = -1024;
else
angle = 1024;
@ -1887,7 +1886,7 @@ void CivPedWalk(PEDESTRIAN* pPed)
int dir;
int turn;
if ((pPed->flags & 0x10U) == 0)
if ((pPed->flags & 0x10) == 0)
SetupCivPedWalk(pPed);
if (pPed->finished_turn == 9)
@ -1895,20 +1894,26 @@ void CivPedWalk(PEDESTRIAN* pPed)
else
dir = pPed->dir.vy + 1850;
if ((pPed->flags & 2U) == 0)
if ((pPed->flags & 2U) != 0)
{
if (IsPavement(pPed->position.vx + (rcossin_tbl[(dir & 0xfff) * 2] >> 5),
pPed->speed = 0;
pPed->dir.vy += pPed->head_rot;
}
else
{
if (IsPavement(
pPed->position.vx + (RSIN(dir) >> 5),
pPed->position.vy,
pPed->position.vz + (rcossin_tbl[(dir & 0xfff) * 2 + 1] >> 5), pPed) == 0)
pPed->position.vz + (RCOS(dir) >> 5), pPed) == 0)
{
if (pPed->finished_turn == 9)
{
dir = pPed->dir.vy + 0xa00U & 0xfff;
dir = pPed->dir.vy + 2560;
if (IsPavement(
pPed->position.vx + FIXED(rcossin_tbl[dir * 2] * 0x80),
pPed->position.vx + FIXED(RSIN(dir) * 128),
pPed->position.vy,
pPed->position.vz + FIXED(rcossin_tbl[dir * 2 + 1] * 0x80), NULL) == 0)
pPed->position.vz + FIXED(RCOS(dir) * 128), NULL) == 0)
pPed->flags &= ~0x2000;
else
@ -1927,10 +1932,10 @@ void CivPedWalk(PEDESTRIAN* pPed)
}
else
{
dir = pPed->dir.vy + 0x800U & 0xfff;
dir = pPed->dir.vy + 2048;
pPed->velocity.vx = FIXED(pPed->speed * rcossin_tbl[dir * 2]);
pPed->velocity.vz = FIXED(pPed->speed * rcossin_tbl[dir * 2 + 1]);
pPed->velocity.vx = FIXED(pPed->speed * RSIN(dir));
pPed->velocity.vz = FIXED(pPed->speed * RCOS(dir));
}
pPed->finished_turn = 0;
}
@ -1940,22 +1945,17 @@ void CivPedWalk(PEDESTRIAN* pPed)
if (pPed->finished_turn++ > 8)
{
pPed->dir.vy += 0x200U & 0xfc00;
pPed->dir.vy = pPed->dir.vy + 512 & 0xfc00;
dir = pPed->dir.vy + 0x800U & 0xfff;
dir = pPed->dir.vy + 2048 & 0xfff;
pPed->velocity.vx = FIXED(pPed->speed * rcossin_tbl[dir * 2]);
pPed->velocity.vz = FIXED(pPed->speed * rcossin_tbl[dir * 2 + 1]);
pPed->velocity.vx = FIXED(pPed->speed * RSIN(dir));
pPed->velocity.vz = FIXED(pPed->speed * RCOS(dir));
pPed->finished_turn = 9;
}
}
}
else
{
pPed->speed = 0;
pPed->dir.vy += pPed->head_rot;
}
AnimatePed(pPed);
}
@ -2127,15 +2127,15 @@ void SetPedestrianTurn(PEDESTRIAN* pedestrian, int turn)
pedestrian->dir.vy = dir;
dir = dir + 0x800 & 0xfff;
dir += 2048;
pedestrian->position.vz -= pedestrian->velocity.vz;
pedestrian->position.vx -= pedestrian->velocity.vx;
speed = pedestrian->speed;
pedestrian->velocity.vx = FIXEDH(speed * rcossin_tbl[dir * 2]);
pedestrian->velocity.vz = FIXEDH(speed * rcossin_tbl[dir * 2 + 1]);
pedestrian->velocity.vx = FIXEDH(speed * RSIN(dir));
pedestrian->velocity.vz = FIXEDH(speed * RCOS(dir));
}
// [D] [T]
@ -2358,10 +2358,10 @@ void BuildCarCollisionBox(void)
if (player[0].playerType == 2)
{
dir = player[0].pPed->dir.vy - 0x800U & 0xfff;
dir = player[0].pPed->dir.vy - 2048;
vx = FIXED(player[0].pPed->speed * rcossin_tbl[dir * 2] * 4);
vz = FIXED(player[0].pPed->speed * rcossin_tbl[dir * 2 + 1] * 4);
vx = FIXED(player[0].pPed->speed * RSIN(dir) * 4);
vz = FIXED(player[0].pPed->speed * RCOS(dir) * 4);
tanner_collision_box.min_x = player[0].pPed->position.vx + vx - 148;
tanner_collision_box.max_x = player[0].pPed->position.vx + vx + 148;
@ -2601,11 +2601,11 @@ void ProcessTannerPad(PEDESTRIAN* pPed, u_int pad, char PadSteer, char use_analo
vec.vy = -pPed->position.vy;
vec.vz = pPed->position.vz;
direction = pPed->dir.vy - 0x800U & 0xfff;
direction = pPed->dir.vy - 2048;
tVec.vx = vec.vx + (rcossin_tbl[direction * 2] * 5 >> 9);
tVec.vx = vec.vx + (RSIN(direction) * 5 >> 9);
tVec.vy = vec.vy;
tVec.vz = vec.vz + (rcossin_tbl[direction * 2 + 1] * 5 >> 9);
tVec.vz = vec.vz + (RCOS(direction) * 5 >> 9);
bStopTanner = 0;
@ -2820,8 +2820,8 @@ int ActivatePlayerPedestrian(CAR_DATA* pCar, char* padId, int direction, LONGVEC
dir = d - 2048;
v.vy = y;
v.vx = x - FIXED(wbody * rcossin_tbl[(d & 0xfffU) * 2 + 1]);
v.vz = z + FIXED(wbody * rcossin_tbl[(d & 0xfffU) * 2]);
v.vx = x - FIXED(wbody * RCOS(d));
v.vz = z + FIXED(wbody * RSIN(d));
side = 0;
@ -2834,8 +2834,8 @@ int ActivatePlayerPedestrian(CAR_DATA* pCar, char* padId, int direction, LONGVEC
v.vy = y;
v.vx = x - FIXED(-wbody * rcossin_tbl[(d & 0xfffU) * 2 + 1]);
v.vz = z + FIXED(-wbody * rcossin_tbl[(d & 0xfffU) * 2]);
v.vx = x - FIXED(-wbody * RCOS(d));
v.vz = z + FIXED(-wbody * RSIN(d));
if (QuickBuildingCollisionCheck(&v, dir, 10, 10, 10))
return 0;

View File

@ -214,10 +214,10 @@ void AddTyreTrack(int wheel, int tracksAndSmoke, int padid)
if (tracksAndSmoke)
{
int dir;
dir = ratan2(oldtp->vz - newtp->vz, oldtp->vx - newtp->vx);
dir = -ratan2(oldtp->vz - newtp->vz, oldtp->vx - newtp->vx);
x = FixHalfRound(rcossin_tbl[(-dir & 0xfffU) * 2] * 35, 13);
z = FixHalfRound(rcossin_tbl[(-dir & 0xfffU) * 2 + 1] * 35, 13);
x = FixHalfRound(RSIN(dir) * 35, 13);
z = FixHalfRound(RCOS(dir) * 35, 13);
New1.vy = oldtp->vy + 10;
New3.vy = newtp->vy + 10;

View File

@ -294,20 +294,14 @@ void DisplaySun(DVECTORF* pos, CVECTOR* col, int flare_col)
void DisplaySun(DVECTOR* pos, CVECTOR* col, int flare_col)
#endif
{
short cs;
short sn;
short sn, cs;
int sz;
POLY_FT4* polys;
POLY_FT3* null;
int u1;
int v2;
int u0;
int v0;
short width;
short height;
int u0, u1, v0, v2;
short width, height;
u0 = sun_texture.coords.u0;
u1 = sun_texture.coords.u1;
@ -362,8 +356,8 @@ void DisplaySun(DVECTOR* pos, CVECTOR* col, int flare_col)
addPrim(current->ot + 0x1079, polys);
current->primptr += sizeof(POLY_FT4);
cs = rcossin_tbl[(camera_angle.vy & 0x1ffe) + 1];
sn = rcossin_tbl[camera_angle.vy & 0x1ffe];
cs = RCOS(camera_angle.vy); //rcossin_tbl[(camera_angle.vy & 0x1ffe) + 1];
sn = RSIN(camera_angle.vy); //rcossin_tbl[camera_angle.vy & 0x1ffe];
sz = -(((flare_texture.coords.u1 - (flare_texture.coords.u0 - 1)) / 2) * 3) / 4;

View File

@ -25,10 +25,14 @@ typedef struct __pauseinfo
u_short pitch[MAX_SFX_CHANNELS];
u_short voll[MAX_SFX_CHANNELS];
u_short volr[MAX_SFX_CHANNELS];
u_short max;
u_short lev;
u_short max, lev;
} pauseinfo;
struct SAMPLE_DATA
{
u_int address, length, loop, samplerate;
};
static pauseinfo pause;
static LSBDinfo lsbTabs;
@ -132,25 +136,30 @@ void InitSound(void)
// [D] [T]
void ClearChannelFields(int channel)
{
channels[channel].loop = 0;
channels[channel].locked = 0;
channels[channel].time = 0;
channels[channel].samplerate = 0;
channels[channel].srcvolume = -10000;
channels[channel].srcpitch = 4096;
channels[channel].volumeScale = 4096;
channels[channel].dopplerScale = 4096;
channels[channel].srcposition = NULL;
channels[channel].position.vx = 0;
channels[channel].position.vy = 0;
channels[channel].position.vz = 0;
channels[channel].srcvelocity = (LONGVECTOR3*)dummylong;
channels[channel].player = 0;
CHANNEL_DATA* chan;
chan = &channels[channel];
chan->loop = 0;
chan->locked = 0;
chan->time = 0;
chan->samplerate = 0;
chan->srcvolume = -10000;
chan->srcpitch = 4096;
chan->volumeScale = 4096;
chan->dopplerScale = 4096;
chan->srcposition = NULL;
chan->position.vx = 0;
chan->position.vy = 0;
chan->position.vz = 0;
chan->srcvelocity = (LONGVECTOR3*)dummylong;
chan->player = 0;
}
// [D] [T]
void ResetSound(void)
{
CHANNEL_DATA* chan;
int ct;
stop_sound_handler = 1;
@ -163,25 +172,23 @@ void ResetSound(void)
SpuSetCommonAttr(&sound_attr);
ct = 0;
do {
memset((u_char*)&channels[ct], 0, sizeof(CHANNEL_DATA));
for (ct = 0; ct < MAX_SFX_CHANNELS; ct++)
{
chan = &channels[ct];
memset((u_char*)chan, 0, sizeof(CHANNEL_DATA));
channels[ct].attr.volmode.left = 0;
channels[ct].attr.volmode.right = 0;
channels[ct].attr.voice = SPU_KEYCH(ct);
chan->attr.volmode.left = 0;
chan->attr.volmode.right = 0;
chan->attr.voice = SPU_KEYCH(ct);
ClearChannelFields(ct);
ct++;
} while (ct < MAX_SFX_CHANNELS);
}
ct = 0;
do {
for (ct = 0; ct < MAX_SFX_CHANNELS; ct++)
{
SpuSetVoiceRR(ct, 6);
SpuSetVoiceAR(ct, 35);
ct++;
} while (ct < MAX_SFX_CHANNELS);
}
stop_sound_handler = 0;
}
@ -270,19 +277,22 @@ int CalculateVolume(int channel)
VECTOR *srcPos;
VECTOR *plPos;
VECTOR ofse;
CHANNEL_DATA* chan;
volume = 10000 + channels[channel].srcvolume;
chan = &channels[channel];
volume = 10000 + chan->srcvolume;
if (NumPlayers > 1 && NoPlayerControl == 0)
{
volume = (volume * 3 / 4);
}
srcPos = channels[channel].srcposition;
srcPos = chan->srcposition;
if (srcPos != NULL)
{
plPos = &player[channels[channel].player].cameraPos;
plPos = &player[chan->player].cameraPos;
ofse.vx = srcPos->vx - plPos->vx;
ofse.vy = srcPos->vy + plPos->vy;
@ -324,10 +334,11 @@ void UpdateVolumeAttributesS(int channel, int proximity)
int dist;
int cam_ang, ang;
int damp;
CHANNEL_DATA* chan;
player_id = channels[channel].player;
pos = channels[channel].srcposition;
chan = &channels[channel];
player_id = chan->player;
pos = chan->srcposition;
cam_pos = &player[player_id].cameraPos;
cam_ang = player[player_id].snd_cam_ang;
@ -340,8 +351,8 @@ void UpdateVolumeAttributesS(int channel, int proximity)
vol = (vol + vol / 2 + vol / 8 + vol / 128) * master_volume / 16384;
channels[channel].attr.volume.left = vol;
channels[channel].attr.volume.right = gSurround ? -vol : vol; // HMM: why like that?
chan->attr.volume.left = vol;
chan->attr.volume.right = gSurround ? -vol : vol; // HMM: why like that?
if (vol == 0)
return;
@ -406,7 +417,7 @@ void UpdateVolumeAttributesS(int channel, int proximity)
if (proximity > 0)
damp = damp * dist / 12000;
channels[channel].attr.volume.left = MAX(0, vol - damp);
chan->attr.volume.left = MAX(0, vol - damp);
}
else if (ang < 0)
{
@ -415,7 +426,7 @@ void UpdateVolumeAttributesS(int channel, int proximity)
if (proximity > 0)
damp = damp * dist / 12000;
channels[channel].attr.volume.right = gSurround ? -MAX(0, vol - damp) : MAX(0, vol - damp);
chan->attr.volume.right = gSurround ? -MAX(0, vol - damp) : MAX(0, vol - damp);
}
}
@ -443,6 +454,7 @@ int CompleteSoundSetup(int channel, int bank, int sample, int pitch, int proximi
{
int bpf;
int rate;
CHANNEL_DATA* chan;
rate = samples[bank][sample].samplerate * pitch;
bpf = (rate / 4096) / 50;
@ -453,6 +465,8 @@ int CompleteSoundSetup(int channel, int bank, int sample, int pitch, int proximi
}
else
{
chan = &channels[channel];
if (gSoundMode == 1 && proximity != -1)
UpdateVolumeAttributesS(channel, proximity);
else
@ -460,22 +474,22 @@ int CompleteSoundSetup(int channel, int bank, int sample, int pitch, int proximi
stop_sound_handler = 1;
channels[channel].attr.mask = SPU_VOICE_VOLL | SPU_VOICE_VOLR | SPU_VOICE_VOLMODEL | SPU_VOICE_VOLMODER | SPU_VOICE_PITCH | SPU_VOICE_WDSA;
channels[channel].attr.addr = samples[bank][sample].address;
channels[channel].attr.pitch = MIN(rate / 44100, 16383);
channels[channel].time = (samples[bank][sample].length / bpf) * 2 + 2;
channels[channel].loop = samples[bank][sample].loop;
chan->attr.mask = SPU_VOICE_VOLL | SPU_VOICE_VOLR | SPU_VOICE_VOLMODEL | SPU_VOICE_VOLMODER | SPU_VOICE_PITCH | SPU_VOICE_WDSA;
chan->attr.addr = samples[bank][sample].address;
chan->attr.pitch = MIN(rate / 44100, 16383);
chan->time = (samples[bank][sample].length / bpf) * 2 + 2;
chan->loop = samples[bank][sample].loop;
channels[channel].samplerate = samples[bank][sample].samplerate;
chan->samplerate = samples[bank][sample].samplerate;
if (sound_paused != 0)
{
channels[channel].attr.volume.left = 0;
channels[channel].attr.volume.right = 0;
chan->attr.volume.left = 0;
chan->attr.volume.right = 0;
}
SpuSetVoiceAttr(&channels[channel].attr);
SpuSetKey(1, channels[channel].attr.voice);
SpuSetVoiceAttr(&chan->attr);
SpuSetKey(1, chan->attr.voice);
stop_sound_handler = 0;
}
@ -546,16 +560,20 @@ int StartSound(int channel, int bank, int sample, int volume, int pitch)
// [D] [T]
int Start3DTrackingSound(int channel, int bank, int sample, VECTOR *position, LONGVECTOR3* velocity)
{
CHANNEL_DATA* chan;
if (channel < 0)
channel = GetFreeChannel();
if (channel < 0 || channel >= MAX_SFX_CHANNELS) // [A]
return -1;
channels[channel].srcposition = position;
channels[channel].srcvelocity = velocity ? velocity : (LONGVECTOR3*)dummylong;
channels[channel].srcpitch = 4096;
channels[channel].srcvolume = 0;
chan = &channels[channel];
chan->srcposition = position;
chan->srcvelocity = velocity ? velocity : (LONGVECTOR3*)dummylong;
chan->srcpitch = 4096;
chan->srcvolume = 0;
channel = CompleteSoundSetup(channel, bank, sample, 4096, 0);
@ -568,19 +586,22 @@ int Start3DTrackingSound(int channel, int bank, int sample, VECTOR *position, LO
// [D] [T]
int Start3DSoundVolPitch(int channel, int bank, int sample, int x, int y, int z, int volume, int pitch)
{
CHANNEL_DATA* chan;
if (channel < 0)
channel = GetFreeChannel();
if (channel < 0 || channel >= MAX_SFX_CHANNELS) // [A]
return -1;
chan = &channels[channel];
channels[channel].srcposition = &channels[channel].position;
channels[channel].srcvelocity = (LONGVECTOR3*)dummylong;
channels[channel].position.vx = x;
channels[channel].position.vy = y;
channels[channel].position.vz = z;
channels[channel].srcvolume = volume;
channels[channel].srcpitch = pitch;
chan->srcposition = &chan->position;
chan->srcvelocity = (LONGVECTOR3*)dummylong;
chan->position.vx = x;
chan->position.vy = y;
chan->position.vz = z;
chan->srcvolume = volume;
chan->srcpitch = pitch;
channel = CompleteSoundSetup(channel, bank, sample, pitch, 0);
@ -594,6 +615,7 @@ int Start3DSoundVolPitch(int channel, int bank, int sample, int x, int y, int z,
// [D] [T]
void SetChannelPitch(int channel, int pitch)
{
CHANNEL_DATA* chan;
int rate;
if (channel < 0 || channel >= MAX_SFX_CHANNELS) // [A]
@ -601,65 +623,75 @@ void SetChannelPitch(int channel, int pitch)
if (sound_paused)
return;
chan = &channels[channel];
if (channels[channel].time != 0 && pitch > 128)
if (chan->time != 0 && pitch > 128)
{
channels[channel].srcpitch = pitch;
chan->srcpitch = pitch;
rate = (channels[channel].samplerate * ((channels[channel].dopplerScale * pitch) / 4096)) / 44100;
rate = (chan->samplerate * ((chan->dopplerScale * pitch) / 4096)) / 44100;
channels[channel].attr.mask = SPU_VOICE_PITCH;
channels[channel].attr.pitch = MIN(rate, 16383);
chan->attr.mask = SPU_VOICE_PITCH;
chan->attr.pitch = MIN(rate, 16383);
SpuSetVoiceAttr(&channels[channel].attr);
SpuSetVoiceAttr(&chan->attr);
}
}
// [D] [T]
void SetChannelVolume(int channel, int volume, int proximity)
{
CHANNEL_DATA* chan;
if (channel < 0 || channel >= MAX_SFX_CHANNELS) // [A]
return;
if (sound_paused == 0 && channels[channel].time != 0)
chan = &channels[channel];
if (sound_paused == 0 && chan->time != 0)
{
channels[channel].srcvolume = volume;
chan->srcvolume = volume;
if (gSoundMode == 1)
UpdateVolumeAttributesS(channel, proximity);
else
UpdateVolumeAttributesM(channel);
channels[channel].attr.mask = SPU_VOICE_VOLL | SPU_VOICE_VOLR | SPU_VOICE_VOLMODEL | SPU_VOICE_VOLMODER;
SpuSetVoiceAttr(&channels[channel].attr);
chan->attr.mask = SPU_VOICE_VOLL | SPU_VOICE_VOLR | SPU_VOICE_VOLMODEL | SPU_VOICE_VOLMODER;
SpuSetVoiceAttr(&chan->attr);
}
}
// [D] [T]
void SetChannelPosition3(int channel, VECTOR *position, LONGVECTOR3* velocity, int volume, int pitch, int proximity)
{
CHANNEL_DATA* chan;
if (channel < 0 || channel >= MAX_SFX_CHANNELS)
return;
if (camera_change != 1 && old_camera_change != 1 && sound_paused == 0)
{
channels[channel].srcposition = position;
channels[channel].srcvelocity = velocity ? velocity : (LONGVECTOR3*)dummylong;
channels[channel].srcvolume = volume;
if (camera_change == 1 || old_camera_change == 1 || sound_paused != 0)
return;
if (gSoundMode == 1)
UpdateVolumeAttributesS(channel, proximity);
else
UpdateVolumeAttributesM(channel);
chan = &channels[channel];
chan->srcposition = position;
chan->srcvelocity = velocity ? velocity : (LONGVECTOR3*)dummylong;
chan->srcvolume = volume;
channels[channel].attr.mask = SPU_VOICE_VOLL | SPU_VOICE_VOLR | SPU_VOICE_VOLMODEL | SPU_VOICE_VOLMODER;
if (gSoundMode == 1)
UpdateVolumeAttributesS(channel, proximity);
else
UpdateVolumeAttributesM(channel);
SpuSetVoiceAttr(&channels[channel].attr);
chan->attr.mask = SPU_VOICE_VOLL | SPU_VOICE_VOLR | SPU_VOICE_VOLMODEL | SPU_VOICE_VOLMODER;
ComputeDoppler(&channels[channel]);
SpuSetVoiceAttr(&chan->attr);
SetChannelPitch(channel, pitch);
}
ComputeDoppler(&channels[channel]);
SetChannelPitch(channel, pitch);
}
@ -745,22 +777,22 @@ void PauseSound(void)
// [D] [T]
void UnPauseXM(void)
{
int fade;
if (Song_ID == -1)
return;
int fade;
if (music_paused == 0)
return;
if (music_paused != 0)
{
fade = 0;
fade = 0;
do {
fade += 96;
} while (fade < music_pause_max); // [A] WTF?
do {
fade += 96;
} while (fade < music_pause_max); // [A] WTF?
XM_Restart(Song_ID);
music_paused = 0;
}
XM_Restart(Song_ID);
music_paused = 0;
}
// [D] [T]
@ -816,7 +848,7 @@ void UnPauseSound(void)
// [D] [T]
void StopChannel(int channel)
{
unsigned char lock;
u_char lock;
int vsync;
if (channel < 0 || channel >= MAX_SFX_CHANNELS)

View File

@ -1,12 +1,36 @@
#ifndef SOUND_H
#define SOUND_H
struct CHANNEL_DATA
{
SpuVoiceAttr attr;
u_char loop;
u_char locked;
u_short time;
int samplerate;
char player;
int srcvolume;
int volumeScale;
u_short srcpitch;
u_short dopplerScale;
int cameradist;
int lastcameradist;
VECTOR* srcposition;
VECTOR position;
LONGVECTOR3* srcvelocity;
};
extern CHANNEL_DATA channels[16];
extern int gMasterVolume;
extern int gMusicVolume;
extern int gSoundMode;
extern CHANNEL_DATA channels[16];
extern int Song_ID;
extern int VABID;
extern int music_paused;

View File

@ -222,12 +222,12 @@ void AddWheelForcesDriver1(CAR_DATA* cp, CAR_LOCALS* cl)
oldSpeed = 1424 - oldSpeed;
dir = cp->hd.direction;
cdx = rcossin_tbl[(dir & 0xfff) * 2];
cdz = rcossin_tbl[(dir & 0xfff) * 2 + 1];
cdx = RSIN(dir);
cdz = RCOS(dir);
dir += cp->wheel_angle;
sdx = rcossin_tbl[(dir & 0xfff) * 2];
sdz = rcossin_tbl[(dir & 0xfff) * 2 + 1];
sdx = RSIN(dir);
sdz = RCOS(dir);
player_id = GetPlayerId(cp);
car_cos = &car_cosmetics[cp->ap.model];
@ -353,8 +353,8 @@ void AddWheelForcesDriver1(CAR_DATA* cp, CAR_LOCALS* cl)
{
dir = ratan2(pointVel[0] >> 6, pointVel[2] >> 6);
lfx = rcossin_tbl[(dir & 0xfff) * 2];
lfz = rcossin_tbl[(dir & 0xfff) * 2 + 1];
lfx = RSIN(dir);
lfz = RCOS(dir);
if (ABS(pointVel[0]) + ABS(pointVel[2]) < 8000)
{

View File

@ -27,8 +27,11 @@ extern short rcossin_tbl[8192];
#define FIXEDH(a) FixHalfRound(a, ONE_BITS) // Fixed Half Round number
#define FIXED(a) ((a) >> ONE_BITS) // Fixed number (unsigned)
#define RSIN(a) rcossin_tbl[(a & 0xFFFU) * 2]
#define RCOS(a) rcossin_tbl[(a & 0xFFFU) * 2 + 1]
#define RSIN(a) (rcossin_tbl[((a) & 4095) * 2])
#define RCOS(a) (rcossin_tbl[((a) & 4095) * 2 + 1])
#define isin(a) (rcossin_tbl[( ( a ) & 4095) * 2])
#define icos(a) (rcossin_tbl[((( a )+1024) & 4095) * 2])
#define DIFF_ANGLES( A, B ) \
(((((B) - (A)) + 2048) & 4095) - 2048)

View File

@ -1908,36 +1908,6 @@ struct TYRE_TRACK
SVECTOR_NOPAD p4;
};
//---------------------------------------------------------------------------------------
// TODO: SOUND.H
struct CHANNEL_DATA
{
SpuVoiceAttr attr;
u_char loop;
u_char locked;
u_short time;
int samplerate;
char player;
int srcvolume;
int volumeScale;
u_short srcpitch;
u_short dopplerScale;
int cameradist;
int lastcameradist;
VECTOR* srcposition;
VECTOR position;
LONGVECTOR3* srcvelocity;
};
struct SAMPLE_DATA
{
u_int address;
u_int length;
u_int loop;
u_int samplerate;
};
//---------------------------------------------------------------------------------------
// TODO: SYSTEM.H