- Blood: Floatify MoveDude() and fixed incorrect velocity check.

This commit is contained in:
Mitchell Richters 2022-09-19 09:40:43 +02:00 committed by Christoph Oelckers
parent 4788e26596
commit b45c95eec5
2 changed files with 31 additions and 38 deletions

View file

@ -4703,17 +4703,17 @@ void MoveDude(DBloodActor* actor)
} }
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
int top, bottom; double top, bottom;
GetActorExtents(actor, &top, &bottom); GetActorExtents(actor, &top, &bottom);
int bz = (bottom - actor->int_pos().Z) / 4; double bz = (bottom - actor->spr.pos.Z) / 4;
int tz = (actor->int_pos().Z - top) / 4; double tz = (actor->spr.pos.Z - top) / 4;
int wd = actor->int_clipdist(); int wd = actor->int_clipdist();
auto pSector = actor->sector(); auto pSector = actor->sector();
int nAiStateType = (actor->xspr.aiState) ? actor->xspr.aiState->stateType : -1; int nAiStateType = (actor->xspr.aiState) ? actor->xspr.aiState->stateType : -1;
assert(pSector); assert(pSector);
if (actor->vel.X != 0 || actor->int_vel().Y) if (actor->vel.X != 0 || actor->vel.Y != 0)
{ {
if (pPlayer && gNoClip) if (pPlayer && gNoClip)
{ {
@ -4726,7 +4726,7 @@ void MoveDude(DBloodActor* actor)
auto bakCstat = actor->spr.cstat; auto bakCstat = actor->spr.cstat;
actor->spr.cstat &= ~CSTAT_SPRITE_BLOCK_ALL; actor->spr.cstat &= ~CSTAT_SPRITE_BLOCK_ALL;
// Note: vel is Q16.16, ClipMove wants Q28.4, which passes it on to clipmove which wants Q14.18. Anyone confused yet...? // Note: vel is Q16.16, ClipMove wants Q28.4, which passes it on to clipmove which wants Q14.18. Anyone confused yet...?
ClipMove(actor->spr.pos, &pSector, actor->int_vel().X >> 12, actor->int_vel().Y >> 12, wd, tz, bz, CLIPMASK0, actor->hit.hit); ClipMove(actor->spr.pos, &pSector, actor->vel.XY(), wd, tz, bz, CLIPMASK0, actor->hit.hit);
if (pSector == nullptr) if (pSector == nullptr)
{ {
pSector = actor->sector(); pSector = actor->sector();
@ -4789,11 +4789,6 @@ void MoveDude(DBloodActor* actor)
if (pDudeInfo->lockOut && pHitXSector && pHitXSector->Wallpush && !pHitXSector->Key && !pHitXSector->dudeLockout && !pHitXSector->state && !pHitXSector->busy && !pPlayer) if (pDudeInfo->lockOut && pHitXSector && pHitXSector->Wallpush && !pHitXSector->Key && !pHitXSector->dudeLockout && !pHitXSector->state && !pHitXSector->busy && !pPlayer)
trTriggerSector(pHitSector, kCmdSectorPush, actor); trTriggerSector(pHitSector, kCmdSectorPush, actor);
if (top < pHitSector->int_ceilingz() || bottom > pHitSector->int_floorz())
{
// ???
}
} }
actWallBounceVector(actor, pHitWall, 0); actWallBounceVector(actor, pHitWall, 0);
break; break;
@ -4841,31 +4836,31 @@ void MoveDude(DBloodActor* actor)
if (pUpperLink && (pUpperLink->spr.type == kMarkerUpWater || pUpperLink->spr.type == kMarkerUpGoo)) bDepth = 1; if (pUpperLink && (pUpperLink->spr.type == kMarkerUpWater || pUpperLink->spr.type == kMarkerUpGoo)) bDepth = 1;
if (pLowerLink && (pLowerLink->spr.type == kMarkerLowWater || pLowerLink->spr.type == kMarkerLowGoo)) bDepth = 1; if (pLowerLink && (pLowerLink->spr.type == kMarkerLowWater || pLowerLink->spr.type == kMarkerLowGoo)) bDepth = 1;
if (pPlayer) wd += 16; if (pPlayer) wd += 16;
if (actor->int_vel().Z) actor->add_int_z(actor->int_vel().Z >> 8); if (actor->vel.Z) actor->spr.pos.Z += actor->vel.Z;
int ceilZ, floorZ; double ceilZ, floorZ;
Collision ceilColl, floorColl; Collision ceilColl, floorColl;
GetZRange(actor, &ceilZ, &ceilColl, &floorZ, &floorColl, wd, CLIPMASK0, PARALLAXCLIP_CEILING | PARALLAXCLIP_FLOOR); GetZRange(actor, &ceilZ, &ceilColl, &floorZ, &floorColl, wd, CLIPMASK0, PARALLAXCLIP_CEILING | PARALLAXCLIP_FLOOR);
GetActorExtents(actor, &top, &bottom); GetActorExtents(actor, &top, &bottom);
if (actor->spr.flags & 2) if (actor->spr.flags & 2)
{ {
int vc = 58254; double vc = FixedToFloat(58254);
if (bDepth) if (bDepth)
{ {
if (bUnderwater) if (bUnderwater)
{ {
int cz = getceilzofslopeptr(pSector, actor->spr.pos); double cz = getceilzofslopeptrf(pSector, actor->spr.pos);
if (cz > top) if (cz > top)
vc += ((bottom - cz) * -80099) / (bottom - top); vc += ((bottom - cz) * -FixedToFloat(80099)) / (bottom - top);
else else
vc = 0; vc = 0;
} }
else else
{ {
int fz = getflorzofslopeptr(pSector, actor->spr.pos); double fz = getflorzofslopeptrf(pSector, actor->spr.pos);
if (fz < bottom) if (fz < bottom)
vc += ((bottom - fz) * -80099) / (bottom - top); vc += ((bottom - fz) * -FixedToFloat(80099)) / (bottom - top);
} }
} }
else else
@ -4877,11 +4872,11 @@ void MoveDude(DBloodActor* actor)
} }
if (vc) if (vc)
{ {
actor->add_int_z(((vc * 4) / 2) >> 8); actor->spr.pos.Z += (vc * 4) / 2;
actor->add_int_bvel_z(vc); actor->vel.Z += vc;
} }
} }
if (pPlayer && actor->vel.Z > 0x155555 && !pPlayer->fallScream && actor->xspr.height > 0) if (pPlayer && actor->vel.Z > FixedToFloat(0x155555) && !pPlayer->fallScream && actor->xspr.height > 0)
{ {
const bool playerAlive = (actor->xspr.health > 0) || VanillaMode(); // only trigger falling scream if player is alive or vanilla mode const bool playerAlive = (actor->xspr.health > 0) || VanillaMode(); // only trigger falling scream if player is alive or vanilla mode
if (playerAlive) if (playerAlive)
@ -4969,7 +4964,7 @@ void MoveDude(DBloodActor* actor)
pPlayer->posture = 1; pPlayer->posture = 1;
actor->xspr.burnTime = 0; actor->xspr.burnTime = 0;
pPlayer->bubbleTime = abs(actor->int_vel().Z) >> 12; pPlayer->bubbleTime = abs(actor->vel.Z * worldtoint);
evPostActor(actor, 0, kCallbackPlayerBubble); evPostActor(actor, 0, kCallbackPlayerBubble);
sfxPlay3DSound(actor, 720, -1, 0); sfxPlay3DSound(actor, 720, -1, 0);
} }
@ -5056,10 +5051,10 @@ void MoveDude(DBloodActor* actor)
GetActorExtents(actor, &top, &bottom); GetActorExtents(actor, &top, &bottom);
if (pPlayer && bottom >= floorZ) if (pPlayer && bottom >= floorZ)
{ {
int floorZ2 = floorZ; double floorZ2 = floorZ;
auto floorColl2 = floorColl; auto floorColl2 = floorColl;
GetZRange(actor, &ceilZ, &ceilColl, &floorZ, &floorColl, actor->int_clipdist(), CLIPMASK0, PARALLAXCLIP_CEILING | PARALLAXCLIP_FLOOR); GetZRange(actor, &ceilZ, &ceilColl, &floorZ, &floorColl, actor->int_clipdist(), CLIPMASK0, PARALLAXCLIP_CEILING | PARALLAXCLIP_FLOOR);
if (bottom <= floorZ && actor->int_pos().Z - floorZ2 < bz) if (bottom <= floorZ && actor->spr.pos.Z - floorZ2 < bz)
{ {
floorZ = floorZ2; floorZ = floorZ2;
floorColl = floorColl2; floorColl = floorColl2;
@ -5068,7 +5063,7 @@ void MoveDude(DBloodActor* actor)
if (floorZ <= bottom) if (floorZ <= bottom)
{ {
actor->hit.florhit = floorColl; actor->hit.florhit = floorColl;
actor->add_int_z(floorZ - bottom); actor->spr.pos.Z += floorZ - bottom;
double veldiff = actor->vel.Z - actor->sector()->velFloor; double veldiff = actor->vel.Z - actor->sector()->velFloor;
if (veldiff > 0) if (veldiff > 0)
{ {
@ -5089,7 +5084,7 @@ void MoveDude(DBloodActor* actor)
nDamage -= 100 << 4; nDamage -= 100 << 4;
if (nDamage > 0) if (nDamage > 0)
actDamageSprite(actor, actor, kDamageFall, nDamage); actDamageSprite(actor, actor, kDamageFall, nDamage);
actor->set_int_bvel_z(FloatToFixed(vec4.Z)); actor->vel.Z = vec4.Z;
if (abs(actor->vel.Z) < 1) if (abs(actor->vel.Z) < 1)
{ {
actor->vel.Z = actor->sector()->velFloor; actor->vel.Z = actor->sector()->velFloor;
@ -5138,26 +5133,25 @@ void MoveDude(DBloodActor* actor)
if (top <= ceilZ) if (top <= ceilZ)
{ {
actor->hit.ceilhit = ceilColl; actor->hit.ceilhit = ceilColl;
actor->add_int_z(ClipLow(ceilZ - top, 0)); actor->spr.pos.Z += max(ceilZ - top, 0.);
if (actor->int_vel().Z <= 0 && (actor->spr.flags & 4)) if (actor->vel.Z <= 0 && (actor->spr.flags & 4))
actor->set_int_bvel_z(MulScale(-actor->int_vel().Z, 0x2000, 16)); actor->vel.Z = -actor->vel.Z * (1. / 8.);
} }
else else
actor->hit.ceilhit.setNone(); actor->hit.ceilhit.setNone();
GetActorExtents(actor, &top, &bottom); GetActorExtents(actor, &top, &bottom);
actor->xspr.height = ClipLow(floorZ - bottom, 0) >> 8; actor->xspr.height = int(max(floorZ - bottom, 0.));
if (actor->vel.X != 0 || actor->int_vel().Y) if (actor->vel.X != 0 || actor->vel.Y != 0)
{ {
if (floorColl.type == kHitSprite) if (floorColl.type == kHitSprite)
{ {
auto hitAct = floorColl.actor(); auto hitAct = floorColl.actor();
if ((hitAct->spr.cstat & CSTAT_SPRITE_ALIGNMENT_MASK) == CSTAT_SPRITE_ALIGNMENT_FACING) if ((hitAct->spr.cstat & CSTAT_SPRITE_ALIGNMENT_MASK) == CSTAT_SPRITE_ALIGNMENT_FACING)
{ {
actor->add_int_bvel_x(MulScale(4, actor->int_pos().X - hitAct->int_pos().X, 2)); actor->vel.XY() += (actor->spr.pos - hitAct->spr.pos).XY() * (1. / 4096.);
actor->add_int_bvel_y(MulScale(4, actor->int_pos().Y - hitAct->int_pos().Y, 2));
return; return;
} }
} }
@ -5165,13 +5159,12 @@ void MoveDude(DBloodActor* actor)
return; return;
if (actor->xspr.height >= 0x100) if (actor->xspr.height >= 0x100)
return; return;
int nDrag = gDudeDrag; double nDrag = gDudeDrag;
if (actor->xspr.height > 0) if (actor->xspr.height > 0)
nDrag -= Scale(gDudeDrag, actor->xspr.height, 0x100); nDrag -= Scale(gDudeDrag, (double)actor->xspr.height, 256.);
actor->add_int_bvel_x(-mulscale16r(actor->int_vel().X, nDrag)); actor->vel.XY() += -actor->vel * nDrag;
actor->add_int_bvel_y(-mulscale16r(actor->int_vel().Y, nDrag));
if (approxDist(actor->int_vel().X, actor->int_vel().Y) < 0x1000) if (actor->vel.XY().Length() < 0.0625)
actor->ZeroVelocityXY(); actor->ZeroVelocityXY();
} }
} }

View file

@ -169,7 +169,7 @@ extern const EXPLOSION explodeInfo[];
extern const THINGINFO thingInfo[]; extern const THINGINFO thingInfo[];
extern VECTORDATA gVectorData[]; extern VECTORDATA gVectorData[];
const int gDudeDrag = 0x2a00; const double gDudeDrag = FixedToFloat(0x2a00);
template<typename T> bool IsPlayerSprite(T const * const pSprite) template<typename T> bool IsPlayerSprite(T const * const pSprite)
{ {