diff --git a/source/core/coreactor.h b/source/core/coreactor.h index ac0818255..66dbf7310 100644 --- a/source/core/coreactor.h +++ b/source/core/coreactor.h @@ -575,7 +575,7 @@ inline int clipmove(DVector3& pos, sectortype** const sect, const DVector2& mvec double const walldist, double const ceildist, double const flordist, unsigned const cliptype, CollisionBase& result, int clipmoveboxtracenum = 3) { auto vect = vec3_t(pos.X * worldtoint, pos.Y * worldtoint, pos.Z * zworldtoint); - int res = clipmove(vect, sect, int(mvec.X * worldtoint), int(mvec.Y * worldtoint), int(walldist * worldtoint), int(ceildist * zworldtoint), int(flordist * zworldtoint), cliptype, result, clipmoveboxtracenum); + int res = clipmove(vect, sect, FloatToFixed<18>(mvec.X), FloatToFixed<18>(mvec.Y), int(walldist * worldtoint), int(ceildist * zworldtoint), int(flordist * zworldtoint), cliptype, result, clipmoveboxtracenum); pos = { vect.X * inttoworld, vect.Y * inttoworld, vect.Z * zinttoworld }; return res; } diff --git a/source/games/exhumed/src/aistuff.h b/source/games/exhumed/src/aistuff.h index e07ba6925..85c35534a 100644 --- a/source/games/exhumed/src/aistuff.h +++ b/source/games/exhumed/src/aistuff.h @@ -228,7 +228,7 @@ DExhumedActor* FindPlayer(DExhumedActor* nSprite, int nDistance, bool dontengage DExhumedActor* BuildCreatureChunk(DExhumedActor* pSrc, int nPic, bool bSpecial = false); int PlotCourseToSprite(DExhumedActor* nSprite1, DExhumedActor* nSprite2); -void CheckSectorFloor(sectortype* pSector, int z, int *x, int *y); +void CheckSectorFloor(sectortype* pSector, double z, DVector2& xy); int GetAngleToSprite(DExhumedActor* nSprite1, DExhumedActor* nSprite2); int GetWallNormal(walltype* nWall); void MoveSector(sectortype* pSector, int nAngle, int *nXVel, int *nYVel); diff --git a/source/games/exhumed/src/gun.cpp b/source/games/exhumed/src/gun.cpp index 92932ae07..6a9af0c20 100644 --- a/source/games/exhumed/src/gun.cpp +++ b/source/games/exhumed/src/gun.cpp @@ -814,8 +814,7 @@ loc_flag: BuildSnake(nPlayer, nHeight); nQuake[nPlayer] = 2.; - PlayerList[nPlayer].nThrust.X -= bcos(pPlayerActor->int_ang(), 9); - PlayerList[nPlayer].nThrust.Y -= bsin(pPlayerActor->int_ang(), 9); + PlayerList[nPlayer].nThrust -= pPlayerActor->spr.angle.ToVector() * 2; break; } case kWeaponRing: diff --git a/source/games/exhumed/src/move.cpp b/source/games/exhumed/src/move.cpp index 9cb537dfb..310080fc3 100644 --- a/source/games/exhumed/src/move.cpp +++ b/source/games/exhumed/src/move.cpp @@ -396,14 +396,13 @@ DExhumedActor* insertActor(sectortype* s, int st) Collision movesprite(DExhumedActor* pActor, int dx, int dy, int dz, int ceildist, int flordist, unsigned int clipmask) { + DVector2 vect(FixedToFloat<18>(dx), FixedToFloat<18>(dy)); + bTouchFloor = false; auto spos = pActor->spr.pos; - - int nSpriteHeight = GetActorHeight(pActor); - + double nSpriteHeight = GetActorHeightF(pActor); int nClipDist = pActor->int_clipdist(); - auto pSector = pActor->sector(); assert(pSector); @@ -411,39 +410,33 @@ Collision movesprite(DExhumedActor* pActor, int dx, int dy, int dz, int ceildist if ((pSector->Flag & kSectUnderwater) || (floorZ < spos.Z)) { - dx >>= 1; - dy >>= 1; + vect *= 0.5; } - Collision nRet = movespritez(pActor, dz * zinttoworld, nSpriteHeight * zinttoworld, nClipDist); + Collision nRet = movespritez(pActor, dz * zinttoworld, nSpriteHeight, nClipDist); pSector = pActor->sector(); // modified in movespritez so re-grab this variable if (pActor->spr.statnum == 100) { int nPlayer = GetPlayerFromActor(pActor); + DVector2 thrust(0, 0); - int varA = 0; - int varB = 0; - - CheckSectorFloor(overridesect, pActor->int_pos().Z, &varB, &varA); - - if (varB || varA) + CheckSectorFloor(overridesect, pActor->spr.pos.Z, thrust); + if (!thrust.isZero()) { - PlayerList[nPlayer].nThrust.X = varB; - PlayerList[nPlayer].nThrust.Y = varA; + PlayerList[nPlayer].nThrust = thrust; } - dx += PlayerList[nPlayer].nThrust.X; - dy += PlayerList[nPlayer].nThrust.Y; + vect += PlayerList[nPlayer].nThrust; } else { - CheckSectorFloor(overridesect, pActor->int_pos().Z, &dx, &dy); + CheckSectorFloor(overridesect, pActor->spr.pos.Z, vect); } Collision coll; - clipmove(pActor->spr.pos, &pSector, dx, dy, nClipDist, nSpriteHeight, flordist, clipmask, coll); + clipmove(pActor->spr.pos, &pSector, FloatToFixed<18>(vect.X), FloatToFixed<18>(vect.Y), nClipDist, int(nSpriteHeight * zworldtoint), flordist, clipmask, coll); if (coll.type != kHitNone) // originally this or'ed the two values which can create unpredictable bad values in some edge cases. { coll.exbits = nRet.exbits; @@ -620,7 +613,7 @@ DExhumedActor* FindPlayer(DExhumedActor* pActor, int nDistance, bool dontengage) return pPlayerActor; } -void CheckSectorFloor(sectortype* pSector, int z, int *x, int *y) +void CheckSectorFloor(sectortype* pSector, double z, DVector2& xy) { int nSpeed = pSector->Speed; @@ -628,18 +621,15 @@ void CheckSectorFloor(sectortype* pSector, int z, int *x, int *y) return; } - int nFlag = pSector->Flag; - int nAng = nFlag & kAngleMask; + DAngle nAng = DAngle::fromBuild(pSector->Flag & kAngleMask); - if (z >= pSector->int_floorz()) + if (z >= pSector->floorz) { - *x += bcos(nAng, 3) * nSpeed; - *y += bsin(nAng, 3) * nSpeed; + xy += nAng.ToVector() * nSpeed * 0.5; } - else if (nFlag & 0x800) + else if (pSector->Flag & 0x800) { - *x += bcos(nAng, 4) * nSpeed; - *y += bsin(nAng, 4) * nSpeed; + xy += nAng.ToVector() * nSpeed; } } diff --git a/source/games/exhumed/src/player.cpp b/source/games/exhumed/src/player.cpp index 7dcc15178..8b975e342 100644 --- a/source/games/exhumed/src/player.cpp +++ b/source/games/exhumed/src/player.cpp @@ -369,8 +369,7 @@ void RestartPlayer(int nPlayer) nTemperature[nPlayer] = 0; - plr->nThrust.Y = 0; - plr->nThrust.X = 0; + plr->nThrust.Zero(); plr->nDestVertPan = plr->horizon.ohoriz = plr->horizon.horiz = q16horiz(0); plr->nBreathTimer = 90; @@ -895,8 +894,7 @@ void AIPlayer::Tick(RunListEvent* ev) if (bUnderwater) { - PlayerList[nPlayer].nThrust.X /= 2; - PlayerList[nPlayer].nThrust.Y /= 2; + PlayerList[nPlayer].nThrust /= 2; } // Trigger Ramses? @@ -941,8 +939,7 @@ void AIPlayer::Tick(RunListEvent* ev) if (bTouchFloor) { // Damage stuff.. - PlayerList[nPlayer].nThrust.X /= 2; - PlayerList[nPlayer].nThrust.Y /= 2; + PlayerList[nPlayer].nThrust /= 2; if (nPlayer == nLocalPlayer) { @@ -2510,8 +2507,7 @@ sectdone: if (!PlayerList[nPlayer].nHealth) { - PlayerList[nPlayer].nThrust.Y = 0; - PlayerList[nPlayer].nThrust.X = 0; + PlayerList[nPlayer].nThrust.Zero(); if (PlayerList[nPlayer].eyelevel >= -11) { diff --git a/source/games/exhumed/src/player.h b/source/games/exhumed/src/player.h index 37183b809..9999c3d38 100644 --- a/source/games/exhumed/src/player.h +++ b/source/games/exhumed/src/player.h @@ -92,7 +92,8 @@ struct Player int16_t nPlayerScore; int16_t nPlayerColor; int16_t nPistolClip; - vec2_t nPlayerD, nThrust; + vec2_t nPlayerD; + DVector2 nThrust; int16_t nPlayerOldWeapon; int16_t nPlayerClip; int16_t nPlayerPushSound; diff --git a/source/games/exhumed/src/rex.cpp b/source/games/exhumed/src/rex.cpp index 45914949d..59287a5f9 100644 --- a/source/games/exhumed/src/rex.cpp +++ b/source/games/exhumed/src/rex.cpp @@ -336,8 +336,7 @@ void AIRex::Tick(RunListEvent* ev) if (pHitActor->spr.statnum == 100) { auto nPlayer = GetPlayerFromActor(nMov.actor()); - PlayerList[nPlayer].nThrust.X += (int(vel.X * worldtoint) << 4); - PlayerList[nPlayer].nThrust.Y += (int(vel.Y * worldtoint) << 4); + PlayerList[nPlayer].nThrust += vel / 4096; pHitActor->vel.Z = -14; } else