- floatified GetOverlapSector and its callers

This commit is contained in:
Christoph Oelckers 2022-09-05 18:02:55 +02:00
parent 92b7ede649
commit d1e29aad36
3 changed files with 71 additions and 51 deletions

View file

@ -170,7 +170,7 @@ void PlayerWarpUpdatePos(PLAYER* pp);
void DoPlayerBeginDiveNoWarp(PLAYER* pp);
int PlayerCanDiveNoWarp(PLAYER* pp);
void DoPlayerCurrent(PLAYER* pp);
int GetOverlapSector2(int x, int y, sectortype** over, sectortype** under);
int GetOverlapSector2(const DVector2& pos, sectortype** over, sectortype** under);
void PlayerToRemote(PLAYER* pp);
void PlayerRemoteInit(PLAYER* pp);
void PlayerSpawnPosition(PLAYER* pp);
@ -3935,6 +3935,12 @@ bool PlayerOnLadder(PLAYER* pp)
return true;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
bool DoPlayerTestCrawl(PLAYER* pp)
{
if (abs(pp->loz - pp->hiz) < PLAYER_STANDING_ROOM)
@ -3943,6 +3949,12 @@ bool DoPlayerTestCrawl(PLAYER* pp)
return false;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
int PlayerInDiveArea(PLAYER* pp)
{
sectortype* sectp;
@ -3967,6 +3979,12 @@ int PlayerInDiveArea(PLAYER* pp)
return false;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
int PlayerCanDive(PLAYER* pp)
{
if (Prediction)
@ -3993,6 +4011,12 @@ int PlayerCanDive(PLAYER* pp)
return false;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
int PlayerCanDiveNoWarp(PLAYER* pp)
{
if (Prediction)
@ -4026,7 +4050,13 @@ int PlayerCanDiveNoWarp(PLAYER* pp)
}
int GetOverlapSector(int x, int y, sectortype** over, sectortype** under)
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
int GetOverlapSector(const DVector2& pos, sectortype** over, sectortype** under)
{
int i, found = 0;
sectortype* sf[3]= {nullptr,nullptr}; // sectors found
@ -4034,16 +4064,16 @@ int GetOverlapSector(int x, int y, sectortype** over, sectortype** under)
auto sectu = *under;
if ((sectu->hasU() && sectu->number >= 30000) || (secto->hasU() && secto->number >= 30000))
return GetOverlapSector2(x,y,over,under);
return GetOverlapSector2(pos, over, under);
// instead of check ALL sectors, just check the two most likely first
if (inside(x, y, *over))
if (inside(pos.X, pos.Y, *over))
{
sf[found] = *over;
found++;
}
if (inside(x, y, *under))
if (inside(pos.X, pos.Y, *under))
{
sf[found] = *under;
found++;
@ -4054,7 +4084,7 @@ int GetOverlapSector(int x, int y, sectortype** over, sectortype** under)
{
for (auto& sect: sector)
{
if (inside(x, y, &sect))
if (inside(pos.X, pos.Y, &sect))
{
sf[found] = &sect;
found++;
@ -4066,7 +4096,6 @@ int GetOverlapSector(int x, int y, sectortype** over, sectortype** under)
if (!found)
{
// Contrary to expectations, this *CAN* happen in valid scenarios and therefore should not abort.
//I_Error("GetOverlapSector x = %d, y = %d, over %d, under %d", x, y, sectnum(*over), sectnum(*under));
return 0;
}
@ -4096,7 +4125,13 @@ int GetOverlapSector(int x, int y, sectortype** over, sectortype** under)
return found;
}
int GetOverlapSector2(int x, int y, sectortype** over, sectortype** under)
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
int GetOverlapSector2(const DVector2& pos, sectortype** over, sectortype** under)
{
int found = 0;
sectortype* sf[2]= {nullptr, nullptr}; // sectors found
@ -4108,13 +4143,13 @@ int GetOverlapSector2(int x, int y, sectortype** over, sectortype** under)
// method.
// instead of check ALL sectors, just check the two most likely first
if (inside(x, y, *over))
if (inside(pos.X, pos.Y, *over))
{
sf[found] = *over;
found++;
}
if (inside(x, y, *under))
if (inside(pos.X, pos.Y, *under))
{
sf[found] = *under;
found++;
@ -4126,7 +4161,7 @@ int GetOverlapSector2(int x, int y, sectortype** over, sectortype** under)
SWStatIterator it(STAT_DIVE_AREA);
while (auto actor = it.Next())
{
if (inside(x, y, actor->sector()))
if (inside(pos.X, pos.Y, actor->sector()))
{
sf[found] = actor->sector();
found++;
@ -4143,7 +4178,7 @@ int GetOverlapSector2(int x, int y, sectortype** over, sectortype** under)
if (actor->spr.lotag == 0)
continue;
if (inside(x, y, actor->sector()))
if (inside(pos.X, pos.Y, actor->sector()))
{
sf[found] = actor->sector();
found++;
@ -4156,7 +4191,6 @@ int GetOverlapSector2(int x, int y, sectortype** over, sectortype** under)
if (!found)
{
// Contrary to expectations, this *CAN* happen in valid scenarios and therefore should not abort.
//I_Error("GetOverlapSector2 x = %d, y = %d, over %d, under %d", x, y, sectnum(*over), sectnum(*under));
return 0;
}
@ -4187,6 +4221,12 @@ int GetOverlapSector2(int x, int y, sectortype** over, sectortype** under)
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void DoPlayerWarpToUnderwater(PLAYER* pp)
{
DSWActor* plActor = pp->actor;
@ -4239,7 +4279,7 @@ void DoPlayerWarpToUnderwater(PLAYER* pp)
auto over = over_act->sector();
auto under = under_act->sector();
if (GetOverlapSector(pp->int_ppos().X, pp->int_ppos().Y, &over, &under) == 2)
if (GetOverlapSector(pp->pos, &over, &under) == 2)
{
pp->setcursector(under);
}
@ -4305,7 +4345,7 @@ void DoPlayerWarpToSurface(PLAYER* pp)
auto over = over_act->sector();
auto under = under_act->sector();
if (GetOverlapSector(pp->int_ppos().X, pp->int_ppos().Y, &over, &under))
if (GetOverlapSector(pp->pos, &over, &under))
{
pp->setcursector(over);
}

View file

@ -109,24 +109,9 @@ ANIMATOR DoShrapJumpFall;
ANIMATOR DoFastShrapJumpFall;
int SpawnSmokePuff(DSWActor* actor);
bool WarpToUnderwater(sectortype** sect, int *x, int *y, int *z);
bool WarpToSurface(sectortype** sect, int *x, int *y, int *z);
inline bool WarpToSurface(DVector3& pos, sectortype** sect)
{
vec3_t vv = { int(pos.X * worldtoint), int(pos.Y * worldtoint), int(pos.Z * zworldtoint) };
auto act = WarpToSurface(sect, &vv.X, &vv.Y, &vv.Z);
pos = { vv.X * inttoworld, vv.Y * inttoworld, vv.Z * zinttoworld };
return act;
}
inline bool WarpToUnderwater(DVector3& pos, sectortype** sect)
{
vec3_t vv = { int(pos.X * worldtoint), int(pos.Y * worldtoint), int(pos.Z * zworldtoint) };
auto act = WarpToUnderwater(sect, &vv.X, &vv.Y, &vv.Z);
pos = { vv.X * inttoworld, vv.Y * inttoworld, vv.Z * zinttoworld };
return act;
}
bool WarpToSurface(DVector3& pos, sectortype** sect);
bool WarpToUnderwater(DVector3& pos, sectortype** sect);
bool TestDontStickSector(sectortype* hit_sect);
ANIMATOR SpawnShrapX;
@ -16183,12 +16168,12 @@ int InitEnemyFireball(DSWActor* actor)
// for hitscans or other uses
///////////////////////////////////////////////////////////////////////////////
bool WarpToUnderwater(sectortype** psectu, int *x, int *y, int *z)
bool WarpToUnderwater(DVector3& pos, sectortype** psectu)
{
int i;
auto sectu = *psectu;
bool Found = false;
int sx, sy;
DVector2 spos;
DSWActor* overActor = nullptr;
DSWActor* underActor = nullptr;
@ -16228,17 +16213,15 @@ bool WarpToUnderwater(sectortype** psectu, int *x, int *y, int *z)
ASSERT(Found);
// get the offset from the sprite
sx = overActor->int_pos().X - *x;
sy = overActor->int_pos().Y - *y;
spos = overActor->spr.pos.XY() - pos.XY();
// update to the new x y position
*x = underActor->int_pos().X - sx;
*y = underActor->int_pos().Y - sy;
pos.XY() = underActor->spr.pos - spos;
auto over = overActor->sector();
auto under = underActor->sector();
if (GetOverlapSector(*x, *y, &over, &under) == 2)
if (GetOverlapSector(pos.XY(), &over, &under) == 2)
{
*psectu = under;
}
@ -16247,16 +16230,15 @@ bool WarpToUnderwater(sectortype** psectu, int *x, int *y, int *z)
*psectu = under;
}
*z = underActor->sector()->int_ceilingz() + Z(1);
pos.Z = underActor->sector()->ceilingz+ 1;
return true;
}
bool WarpToSurface(sectortype** psectu, int *x, int *y, int *z)
bool WarpToSurface(DVector3& pos, sectortype** psectu)
{
int i;
auto sectu = *psectu;
int sx, sy;
DSWActor* overActor = nullptr;
DSWActor* underActor = nullptr;
bool Found = false;
@ -16297,22 +16279,20 @@ bool WarpToSurface(sectortype** psectu, int *x, int *y, int *z)
ASSERT(Found);
// get the offset from the under sprite
sx = underActor->int_pos().X - *x;
sy = underActor->int_pos().Y - *y;
DVector2 spos = underActor->spr.pos.XY() - pos.XY();
// update to the new x y position
*x = overActor->int_pos().X - sx;
*y = overActor->int_pos().Y - sy;
pos.XY() = overActor->spr.pos.XY() - spos;
auto over = overActor->sector();
auto under = underActor->sector();
if (GetOverlapSector(*x, *y, &over, &under))
if (GetOverlapSector(pos.XY(), &over, &under))
{
*psectu = over;
}
*z = overActor->sector()->int_floorz() - Z(2);
pos.Z = overActor->sector()->floorz- 2;
return true;
}
@ -16367,7 +16347,7 @@ bool SpriteWarpToUnderwater(DSWActor* actor)
auto over = overActor->sector();
auto under = underActor->sector();
if (GetOverlapSector(actor->int_pos().X, actor->int_pos().Y, &over, &under) == 2)
if (GetOverlapSector(actor->spr.pos, &over, &under) == 2)
{
ChangeActorSect(actor, under);
}
@ -16437,7 +16417,7 @@ bool SpriteWarpToSurface(DSWActor* actor)
auto over = overActor->sector();
auto under = underActor->sector();
if (GetOverlapSector(actor->int_pos().X, actor->int_pos().Y, &over, &under))
if (GetOverlapSector(actor->spr.pos, &over, &under))
{
ChangeActorSect(actor, over);
}

View file

@ -171,7 +171,7 @@ extern short target_ang;
DSWActor* SpawnShotgunSparks(PLAYER* pp, sectortype* hit_sect, walltype* hit_wall, int hit_x, int hit_y, int hit_z, short hit_ang);
int DoActorBeginSlide(DSWActor* actor, DAngle ang, double vel);
int GetOverlapSector(int x, int y, sectortype** over, sectortype** under);
int GetOverlapSector(const DVector2& pos, sectortype** over, sectortype** under);
bool MissileHitDiveArea(DSWActor*);