mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-24 13:11:33 +00:00
- fixed the sound location calculations which got somewhat broken by the constant changes during the conversion.
This commit is contained in:
parent
8f5ac9b73f
commit
6445615b5d
15 changed files with 138 additions and 164 deletions
12
src/actor.h
12
src/actor.h
|
@ -931,13 +931,10 @@ public:
|
|||
{
|
||||
SetOrigin(Pos() + vel, true);
|
||||
}
|
||||
void SetOrigin(double x, double y, double z, bool moving)
|
||||
{
|
||||
SetOrigin(FLOAT2FIXED(x), FLOAT2FIXED(y), FLOAT2FIXED(z), moving);
|
||||
}
|
||||
void SetOrigin(double x, double y, double z, bool moving);
|
||||
void SetOrigin(const DVector3 & npos, bool moving)
|
||||
{
|
||||
SetOrigin(FLOAT2FIXED(npos.X), FLOAT2FIXED(npos.Y), FLOAT2FIXED(npos.Z), moving);
|
||||
SetOrigin(npos.X, npos.Y, npos.Z, moving);
|
||||
}
|
||||
|
||||
inline void SetFriendPlayer(player_t *player);
|
||||
|
@ -1167,7 +1164,7 @@ public:
|
|||
void LinkToWorld (bool spawningmapthing=false, sector_t *sector = NULL);
|
||||
void UnlinkFromWorld ();
|
||||
void AdjustFloorClip ();
|
||||
void SetOrigin (fixed_t x, fixed_t y, fixed_t z, bool moving = false);
|
||||
void SetOrigin(fixed_t x, fixed_t y, fixed_t z, bool moving = false) = delete;
|
||||
bool InStateSequence(FState * newstate, FState * basestate);
|
||||
int GetTics(FState * newstate);
|
||||
bool SetState (FState *newstate, bool nofunction=false);
|
||||
|
@ -1244,8 +1241,9 @@ public:
|
|||
|
||||
FVector3 SoundPos() const
|
||||
{
|
||||
// the sound system switches y and z axes so this function must, too.
|
||||
// fixme: This still needs portal handling
|
||||
return{ float(X()), float(Y()), float(Z()) };
|
||||
return{ float(X()), float(Z()), float(Y()) };
|
||||
}
|
||||
DVector3 InterpolatedPosition(double ticFrac) const
|
||||
{
|
||||
|
|
|
@ -162,12 +162,12 @@ void P_RecursiveSound (sector_t *sec, AActor *soundtarget, bool splash, int soun
|
|||
// I wish there was a better method to do this than randomly looking through the portal at a few places...
|
||||
if (checkabove)
|
||||
{
|
||||
sector_t *upper = P_PointInSector(check->V1() + check->Delta() / 2 + sec->SkyBoxes[sector_t::ceiling]->Scale);
|
||||
sector_t *upper = P_PointInSector(check->v1->fPos() + check->Delta() / 2 + sec->SkyBoxes[sector_t::ceiling]->Scale);
|
||||
P_RecursiveSound(upper, soundtarget, splash, soundblocks, emitter, maxdist);
|
||||
}
|
||||
if (checkbelow)
|
||||
{
|
||||
sector_t *lower = P_PointInSector(check->V1() + check->Delta() / 2 + sec->SkyBoxes[sector_t::floor]->Scale);
|
||||
sector_t *lower = P_PointInSector(check->v1->fPos() + check->Delta() / 2 + sec->SkyBoxes[sector_t::floor]->Scale);
|
||||
P_RecursiveSound(lower, soundtarget, splash, soundblocks, emitter, maxdist);
|
||||
}
|
||||
FLinePortal *port = check->getPortal();
|
||||
|
@ -195,18 +195,18 @@ void P_RecursiveSound (sector_t *sec, AActor *soundtarget, bool splash, int soun
|
|||
other = check->sidedef[0]->sector;
|
||||
|
||||
// check for closed door
|
||||
if ((sec->floorplane.ZatPoint (check->V1()) >=
|
||||
other->ceilingplane.ZatPoint (check->V1()) &&
|
||||
sec->floorplane.ZatPoint (check->V2()) >=
|
||||
other->ceilingplane.ZatPoint (check->V2()))
|
||||
|| (other->floorplane.ZatPoint (check->V1()) >=
|
||||
sec->ceilingplane.ZatPoint (check->V1()) &&
|
||||
other->floorplane.ZatPoint (check->V2()) >=
|
||||
sec->ceilingplane.ZatPoint (check->V2()))
|
||||
|| (other->floorplane.ZatPoint (check->V1()) >=
|
||||
other->ceilingplane.ZatPoint (check->V1()) &&
|
||||
other->floorplane.ZatPoint (check->V2()) >=
|
||||
other->ceilingplane.ZatPoint (check->V2())))
|
||||
if ((sec->floorplane.ZatPoint (check->v1->fPos()) >=
|
||||
other->ceilingplane.ZatPoint (check->v1->fPos()) &&
|
||||
sec->floorplane.ZatPoint (check->v2->fPos()) >=
|
||||
other->ceilingplane.ZatPoint (check->v2->fPos()))
|
||||
|| (other->floorplane.ZatPoint (check->v1->fPos()) >=
|
||||
sec->ceilingplane.ZatPoint (check->v1->fPos()) &&
|
||||
other->floorplane.ZatPoint (check->v2->fPos()) >=
|
||||
sec->ceilingplane.ZatPoint (check->v2->fPos()))
|
||||
|| (other->floorplane.ZatPoint (check->v1->fPos()) >=
|
||||
other->ceilingplane.ZatPoint (check->v1->fPos()) &&
|
||||
other->floorplane.ZatPoint (check->v2->fPos()) >=
|
||||
other->ceilingplane.ZatPoint (check->v2->fPos())))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ static void CreateCachedNodes(MapData *map);
|
|||
// fixed 32 bit gl_vert format v2.0+ (glBsp 1.91)
|
||||
struct mapglvertex_t
|
||||
{
|
||||
fixed_t x,y;
|
||||
SDWORD x,y;
|
||||
};
|
||||
|
||||
struct gl3_mapsubsector_t
|
||||
|
|
|
@ -109,7 +109,7 @@ static DVector2 FindRefPoint(line_t *ld, const DVector2 &pos)
|
|||
!ld->frontsector->PortalBlocksMovement(sector_t::floor))
|
||||
{
|
||||
|
||||
DVector2 v1 = ld->V1();
|
||||
DVector2 v1 = ld->v1->fPos();
|
||||
DVector2 d = ld->Delta();
|
||||
double r = clamp(((pos.X - v1.X) * d.X + (pos.Y - v1.Y) * d.Y) / (d.X*d.X + d.Y*d.Y), 0., 1.);
|
||||
return v1 + d*r;
|
||||
|
|
|
@ -516,10 +516,10 @@ void AActor::LinkToWorld(bool spawningmapthing, sector_t *sector)
|
|||
}
|
||||
}
|
||||
|
||||
void AActor::SetOrigin (fixed_t ix, fixed_t iy, fixed_t iz, bool moving)
|
||||
void AActor::SetOrigin(double x, double y, double z, bool moving)
|
||||
{
|
||||
UnlinkFromWorld ();
|
||||
SetXYZ(ix, iy, iz);
|
||||
SetXYZ(x, y, z);
|
||||
LinkToWorld ();
|
||||
P_FindFloorCeiling(this, FFCF_ONLYSPAWNPOS);
|
||||
if (!moving) ClearInterpolation();
|
||||
|
@ -1387,7 +1387,7 @@ intercept_t *FPathTraverse::Next()
|
|||
{
|
||||
intercept_t *in = NULL;
|
||||
|
||||
double dist = FIXED_MAX;
|
||||
double dist = FLT_MAX;
|
||||
for (unsigned scanpos = intercept_index; scanpos < intercepts.Size (); scanpos++)
|
||||
{
|
||||
intercept_t *scan = &intercepts[scanpos];
|
||||
|
@ -1795,10 +1795,8 @@ static int R_PointOnSideSlow(double xx, double yy, node_t *node)
|
|||
{
|
||||
// [RH] This might have been faster than two multiplies and an
|
||||
// add on a 386/486, but it certainly isn't on anything newer than that.
|
||||
fixed_t dx;
|
||||
fixed_t dy;
|
||||
fixed_t x = FloatToFixed(xx);
|
||||
fixed_t y = FloatToFixed(yy);
|
||||
auto x = FloatToFixed(xx);
|
||||
auto y = FloatToFixed(yy);
|
||||
double left;
|
||||
double right;
|
||||
|
||||
|
@ -1817,8 +1815,8 @@ static int R_PointOnSideSlow(double xx, double yy, node_t *node)
|
|||
return node->dx > 0;
|
||||
}
|
||||
|
||||
dx = (x - node->x);
|
||||
dy = (y - node->y);
|
||||
auto dx = (x - node->x);
|
||||
auto dy = (y - node->y);
|
||||
|
||||
// Try to quickly decide by looking at sign bits.
|
||||
if ((node->dy ^ node->dx ^ dx ^ dy) & 0x80000000)
|
||||
|
@ -1832,6 +1830,7 @@ static int R_PointOnSideSlow(double xx, double yy, node_t *node)
|
|||
}
|
||||
|
||||
// we must use doubles here because the fixed point code will produce errors due to loss of precision for extremely short linedefs.
|
||||
// Note that this function is used for all map spawned actors and not just a compatibility fallback!
|
||||
left = (double)node->dy * (double)dx;
|
||||
right = (double)dy * (double)node->dx;
|
||||
|
||||
|
@ -1852,24 +1851,20 @@ static int R_PointOnSideSlow(double xx, double yy, node_t *node)
|
|||
//
|
||||
//===========================================================================
|
||||
|
||||
int P_VanillaPointOnLineSide(fixed_t x, fixed_t y, const line_t* line)
|
||||
int P_VanillaPointOnLineSide(double x, double y, const line_t* line)
|
||||
{
|
||||
fixed_t dx;
|
||||
fixed_t dy;
|
||||
fixed_t left;
|
||||
fixed_t right;
|
||||
DVector2 delta = line->Delta();
|
||||
|
||||
if (delta.X == 0)
|
||||
{
|
||||
if (x <= line->v1->fixX())
|
||||
if (x <= line->v1->fX())
|
||||
return delta.Y > 0;
|
||||
|
||||
return delta.Y < 0;
|
||||
}
|
||||
if (delta.Y == 0)
|
||||
{
|
||||
if (y <= line->v1->fixY())
|
||||
if (y <= line->v1->fY())
|
||||
return delta.X < 0;
|
||||
|
||||
return delta.X > 0;
|
||||
|
@ -1877,13 +1872,13 @@ int P_VanillaPointOnLineSide(fixed_t x, fixed_t y, const line_t* line)
|
|||
|
||||
// Note: This cannot really be converted to floating point
|
||||
// without breaking the intended use of this function
|
||||
// (i.e. to emulate the horrible imprecision of the entire methpd)
|
||||
// (i.e. to emulate the horrible imprecision of the entire method)
|
||||
|
||||
dx = (x - line->v1->fixX());
|
||||
dy = (y - line->v1->fixY());
|
||||
auto dx = FloatToFixed(x - line->v1->fX());
|
||||
auto dy = FloatToFixed(y - line->v1->fY());
|
||||
|
||||
left = FixedMul ( int(delta.Y * 256) , dx );
|
||||
right = FixedMul ( dy , int(delta.X * 256) );
|
||||
auto left = MulScale16( int(delta.Y * 256) , dx );
|
||||
auto right = MulScale16( dy , int(delta.X * 256) );
|
||||
|
||||
if (right < left)
|
||||
return 0; // front side
|
||||
|
|
|
@ -36,40 +36,31 @@ struct intercept_t
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
inline int P_PointOnLineSide (fixed_t x, fixed_t y, const line_t *line)
|
||||
{
|
||||
extern int P_VanillaPointOnLineSide(fixed_t x, fixed_t y, const line_t* line);
|
||||
|
||||
return i_compatflags2 & COMPATF2_POINTONLINE
|
||||
? P_VanillaPointOnLineSide(x, y, line)
|
||||
: DMulScale32 (y-line->v1->fixY(), line->fixDx(), line->v1->fixX()-x, line->fixDy()) > 0;
|
||||
}
|
||||
|
||||
inline int P_PointOnLineSidePrecise (fixed_t x, fixed_t y, const line_t *line)
|
||||
{
|
||||
return DMulScale32 (y-line->v1->fixY(), line->fixDx(), line->v1->fixX()-x, line->fixDy()) > 0;
|
||||
}
|
||||
|
||||
inline int P_PointOnLineSide(double x, double y, const line_t *line)
|
||||
{
|
||||
return P_PointOnLineSide(FLOAT2FIXED(x), FLOAT2FIXED(y), line);
|
||||
}
|
||||
|
||||
inline int P_PointOnLineSide(const DVector2 & p, const line_t *line)
|
||||
{
|
||||
return P_PointOnLineSide(FLOAT2FIXED(p.X), FLOAT2FIXED(p.Y), line);
|
||||
}
|
||||
|
||||
inline int P_PointOnLineSidePrecise(double x, double y, const line_t *line)
|
||||
{
|
||||
return (y - line->v1->fY()) * line->Delta().X + (line->v1->fX() - x) * line->Delta().Y > EQUAL_EPSILON ;
|
||||
return (y - line->v1->fY()) * line->Delta().X + (line->v1->fX() - x) * line->Delta().Y > -EQUAL_EPSILON;
|
||||
}
|
||||
|
||||
inline int P_PointOnLineSidePrecise(const DVector2 &pt, const line_t *line)
|
||||
{
|
||||
return (pt.Y - line->v1->fY()) * line->Delta().X + (line->v1->fX() - pt.X) * line->Delta().Y > EQUAL_EPSILON;
|
||||
return (pt.Y - line->v1->fY()) * line->Delta().X + (line->v1->fX() - pt.X) * line->Delta().Y > -EQUAL_EPSILON;
|
||||
}
|
||||
|
||||
inline int P_PointOnLineSide (double x, double y, const line_t *line)
|
||||
{
|
||||
extern int P_VanillaPointOnLineSide(double x, double y, const line_t* line);
|
||||
|
||||
return i_compatflags2 & COMPATF2_POINTONLINE
|
||||
? P_VanillaPointOnLineSide(x, y, line) : P_PointOnLineSidePrecise(x, y, line);
|
||||
}
|
||||
|
||||
inline int P_PointOnLineSide(const DVector2 & p, const line_t *line)
|
||||
{
|
||||
return P_PointOnLineSide(p.X, p.Y, line);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
|
@ -82,12 +73,12 @@ inline int P_PointOnLineSidePrecise(const DVector2 &pt, const line_t *line)
|
|||
|
||||
inline int P_PointOnDivlineSide(double x, double y, const divline_t *line)
|
||||
{
|
||||
return (y - line->y) * line->dx + (line->x - x) * line->dy > EQUAL_EPSILON;
|
||||
return (y - line->y) * line->dx + (line->x - x) * line->dy > -EQUAL_EPSILON;
|
||||
}
|
||||
|
||||
inline int P_PointOnDivlineSide(const DVector2 &pos, const divline_t *line)
|
||||
{
|
||||
return (pos.Y - line->y) * line->dx + (line->x - pos.X) * line->dy > EQUAL_EPSILON;
|
||||
return (pos.Y - line->y) * line->dx + (line->x - pos.X) * line->dy > -EQUAL_EPSILON;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
|
|
@ -1401,9 +1401,9 @@ void P_ExplodeMissile (AActor *mo, line_t *line, AActor *target)
|
|||
den = line->Delta().LengthSquared();
|
||||
if (den != 0)
|
||||
{
|
||||
frac = clamp<double>((mo->Pos() - line->V1()) | line->Delta(), 0, den) / den;
|
||||
frac = clamp<double>((mo->Pos().XY() - line->v1->fPos()) | line->Delta(), 0, den) / den;
|
||||
|
||||
linepos = DVector3(line->V1() + line->Delta() * frac, pos.Z);
|
||||
linepos = DVector3(line->v1->fPos() + line->Delta() * frac, pos.Z);
|
||||
|
||||
F3DFloor * ffloor=NULL;
|
||||
if (line->sidedef[side^1] != NULL)
|
||||
|
|
|
@ -714,10 +714,10 @@ void sector_t::SetFade(int r, int g, int b)
|
|||
//
|
||||
//===========================================================================
|
||||
|
||||
void sector_t::ClosestPoint(fixed_t fx, fixed_t fy, fixed_t &ox, fixed_t &oy) const
|
||||
void sector_t::ClosestPoint(const DVector2 &in, DVector2 &out) const
|
||||
{
|
||||
int i;
|
||||
double x = fx, y = fy;
|
||||
double x = in.X, y = in.Y;
|
||||
double bestdist = HUGE_VAL;
|
||||
double bestx = 0, besty = 0;
|
||||
|
||||
|
@ -725,34 +725,34 @@ void sector_t::ClosestPoint(fixed_t fx, fixed_t fy, fixed_t &ox, fixed_t &oy) co
|
|||
{
|
||||
vertex_t *v1 = lines[i]->v1;
|
||||
vertex_t *v2 = lines[i]->v2;
|
||||
double a = v2->fixX() - v1->fixX();
|
||||
double b = v2->fixY() - v1->fixY();
|
||||
double a = v2->fX() - v1->fX();
|
||||
double b = v2->fY() - v1->fY();
|
||||
double den = a*a + b*b;
|
||||
double ix, iy, dist;
|
||||
|
||||
if (den == 0)
|
||||
{ // Line is actually a point!
|
||||
ix = v1->fixX();
|
||||
iy = v1->fixY();
|
||||
ix = v1->fX();
|
||||
iy = v1->fY();
|
||||
}
|
||||
else
|
||||
{
|
||||
double num = (x - v1->fixX()) * a + (y - v1->fixY()) * b;
|
||||
double num = (x - v1->fX()) * a + (y - v1->fY()) * b;
|
||||
double u = num / den;
|
||||
if (u <= 0)
|
||||
{
|
||||
ix = v1->fixX();
|
||||
iy = v1->fixY();
|
||||
ix = v1->fX();
|
||||
iy = v1->fY();
|
||||
}
|
||||
else if (u >= 1)
|
||||
{
|
||||
ix = v2->fixX();
|
||||
iy = v2->fixY();
|
||||
ix = v2->fX();
|
||||
iy = v2->fY();
|
||||
}
|
||||
else
|
||||
{
|
||||
ix = v1->fixX() + u * a;
|
||||
iy = v1->fixY() + u * b;
|
||||
ix = v1->fX() + u * a;
|
||||
iy = v1->fY() + u * b;
|
||||
}
|
||||
}
|
||||
a = (ix - x);
|
||||
|
@ -765,8 +765,7 @@ void sector_t::ClosestPoint(fixed_t fx, fixed_t fy, fixed_t &ox, fixed_t &oy) co
|
|||
besty = iy;
|
||||
}
|
||||
}
|
||||
ox = fixed_t(bestx);
|
||||
oy = fixed_t(besty);
|
||||
out = { bestx, besty };
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -375,8 +375,8 @@ bool SightCheck::P_SightCheckLine (line_t *ld)
|
|||
return true;
|
||||
}
|
||||
ld->validcount = validcount;
|
||||
if (P_PointOnDivlineSide (ld->V1(), &Trace) ==
|
||||
P_PointOnDivlineSide (ld->V2(), &Trace))
|
||||
if (P_PointOnDivlineSide (ld->v1->fPos(), &Trace) ==
|
||||
P_PointOnDivlineSide (ld->v2->fPos(), &Trace))
|
||||
{
|
||||
return true; // line isn't crossed
|
||||
}
|
||||
|
|
|
@ -291,7 +291,7 @@ bool P_ChangeSwitchTexture (side_t *side, int useAgain, BYTE special, bool *ques
|
|||
// which wasn't necessarily anywhere near the switch if it was
|
||||
// facing a big sector (and which wasn't necessarily for the
|
||||
// button just activated, either).
|
||||
DVector2 pt(side->linedef->V1() + side->linedef->Delta() / 2);
|
||||
DVector2 pt(side->linedef->v1->fPos() + side->linedef->Delta() / 2);
|
||||
bool playsound;
|
||||
|
||||
side->SetTexture(texture, Switch->frames[0].Texture);
|
||||
|
|
|
@ -438,7 +438,7 @@ bool EV_SilentLineTeleport (line_t *line, int side, AActor *thing, int id, INTBO
|
|||
}
|
||||
else
|
||||
{
|
||||
double num = (thing->Pos().XY() - line->V1()) | line->Delta();
|
||||
double num = (thing->Pos().XY() - line->v1->fPos()) | line->Delta();
|
||||
if (num <= 0)
|
||||
{
|
||||
pos = 0;
|
||||
|
@ -451,7 +451,7 @@ bool EV_SilentLineTeleport (line_t *line, int side, AActor *thing, int id, INTBO
|
|||
{
|
||||
pos = num / den;
|
||||
}
|
||||
npos = thing->Pos().XY() - line->V1() - line->Delta() * pos;
|
||||
npos = thing->Pos().XY() - line->v1->fPos() - line->Delta() * pos;
|
||||
}
|
||||
|
||||
// Get the angle between the two linedefs, for rotating
|
||||
|
@ -476,7 +476,7 @@ bool EV_SilentLineTeleport (line_t *line, int side, AActor *thing, int id, INTBO
|
|||
p.Y = npos.Y*c + npos.X*s;
|
||||
|
||||
// Interpolate position across the exit linedef
|
||||
p += l->V1() + pos*l->Delta();
|
||||
p += l->v1->fPos() + pos*l->Delta();
|
||||
|
||||
// Whether this is a player, and if so, a pointer to its player_t.
|
||||
// Voodoo dolls are excluded by making sure thing->player->mo==thing.
|
||||
|
|
22
src/r_defs.h
22
src/r_defs.h
|
@ -660,7 +660,7 @@ struct sector_t
|
|||
void AdjustFloorClip () const;
|
||||
void SetColor(int r, int g, int b, int desat);
|
||||
void SetFade(int r, int g, int b);
|
||||
void ClosestPoint(fixed_t x, fixed_t y, fixed_t &ox, fixed_t &oy) const;
|
||||
void ClosestPoint(const DVector2 &pos, DVector2 &out) const;
|
||||
int GetFloorLight () const;
|
||||
int GetCeilingLight () const;
|
||||
sector_t *GetHeightSec() const;
|
||||
|
@ -1367,31 +1367,11 @@ public:
|
|||
int locknumber; // [Dusk] lock number for special
|
||||
unsigned portalindex;
|
||||
|
||||
DVector2 V1() const
|
||||
{
|
||||
return v1->fPos();
|
||||
}
|
||||
|
||||
DVector2 V2() const
|
||||
{
|
||||
return v1->fPos();
|
||||
}
|
||||
|
||||
DVector2 Delta() const
|
||||
{
|
||||
return{ FIXED2DBL(dx), FIXED2DBL(dy) };
|
||||
}
|
||||
|
||||
fixed_t fixDx() const
|
||||
{
|
||||
return dx;
|
||||
}
|
||||
|
||||
fixed_t fixDy() const
|
||||
{
|
||||
return dy;
|
||||
}
|
||||
|
||||
void setDelta(fixed_t x, fixed_t y)
|
||||
{
|
||||
dx = x;
|
||||
|
|
|
@ -374,7 +374,7 @@ static inline bool R_ClipSpriteColumnWithPortals(fixed_t x, fixed_t y, vissprite
|
|||
line_t* line = seg->curline->linedef;
|
||||
|
||||
// don't clip if the sprite is in front of the portal
|
||||
if (!P_PointOnLineSidePrecise(x, y, line))
|
||||
if (!P_PointOnLineSidePrecise(FIXED2DBL(x), FIXED2DBL(y), line))
|
||||
continue;
|
||||
|
||||
// now if current column is covered by this drawseg, we clip it away
|
||||
|
|
|
@ -104,8 +104,8 @@ static void S_ActivatePlayList(bool goBack);
|
|||
static void CalcPosVel(FSoundChan *chan, FVector3 *pos, FVector3 *vel);
|
||||
static void CalcPosVel(int type, const AActor *actor, const sector_t *sector, const FPolyObj *poly,
|
||||
const float pt[3], int channel, int chanflags, FVector3 *pos, FVector3 *vel);
|
||||
static void CalcSectorSoundOrg(const sector_t *sec, int channum, fixed_t *x, fixed_t *y, fixed_t *z);
|
||||
static void CalcPolyobjSoundOrg(const FPolyObj *poly, fixed_t *x, fixed_t *y, fixed_t *z);
|
||||
static void CalcSectorSoundOrg(const DVector3 &listenpos, const sector_t *sec, int channum, FVector3 &res);
|
||||
static void CalcPolyobjSoundOrg(const DVector3 &listenpos, const FPolyObj *poly, FVector3 &res);
|
||||
static FSoundChan *S_StartSound(AActor *mover, const sector_t *sec, const FPolyObj *poly,
|
||||
const FVector3 *pt, int channel, FSoundID sound_id, float volume, float attenuation, FRolloffInfo *rolloff);
|
||||
static void S_SetListener(SoundListener &listener, AActor *listenactor);
|
||||
|
@ -658,27 +658,30 @@ static void CalcPosVel(int type, const AActor *actor, const sector_t *sector,
|
|||
{
|
||||
if (pos != NULL)
|
||||
{
|
||||
fixed_t x, y, z;
|
||||
DVector3 listenpos;
|
||||
int pgroup;
|
||||
AActor *listener = players[consoleplayer].camera;
|
||||
|
||||
if (players[consoleplayer].camera != NULL)
|
||||
if (listener != NULL)
|
||||
{
|
||||
FVector3 v = players[consoleplayer].camera->SoundPos();
|
||||
x = FLOAT2FIXED(v.X);
|
||||
y = FLOAT2FIXED(v.Y);
|
||||
z = FLOAT2FIXED(v.Z);
|
||||
listenpos = listener->Pos();
|
||||
pgroup = listener->Sector->PortalGroup;
|
||||
}
|
||||
else
|
||||
{
|
||||
z = y = x = 0;
|
||||
listenpos.Zero();
|
||||
pgroup = 0;
|
||||
}
|
||||
|
||||
// [BL] Moved this case out of the switch statement to make code easier
|
||||
// on static analysis.
|
||||
if(type == SOURCE_Unattached)
|
||||
{
|
||||
pos->X = pt[0];
|
||||
pos->Y = !(chanflags & CHAN_LISTENERZ) ? pt[1] : FIXED2FLOAT(y);
|
||||
pos->Z = pt[2];
|
||||
{
|
||||
sector_t *sec = P_PointInSector(pt[0], pt[2]);
|
||||
DVector2 disp = Displacements.getOffset(pgroup, sec->PortalGroup);
|
||||
pos->X = pt[0] + (float)disp.X;
|
||||
pos->Y = !(chanflags & CHAN_LISTENERZ) ? pt[1] : (float)listenpos.Z;
|
||||
pos->Z = pt[2] + (float)disp.Y;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -692,10 +695,9 @@ static void CalcPosVel(int type, const AActor *actor, const sector_t *sector,
|
|||
//assert(actor != NULL);
|
||||
if (actor != NULL)
|
||||
{
|
||||
FVector3 v = actor->SoundPos();
|
||||
x = FLOAT2FIXED(v.X);
|
||||
y = FLOAT2FIXED(v.Y);
|
||||
z = FLOAT2FIXED(v.Z);
|
||||
DVector2 disp = Displacements.getOffset(pgroup, actor->Sector->PortalGroup);
|
||||
DVector3 posi = actor->Pos() + disp;
|
||||
*pos = { (float)posi.X, (float)posi.Z, (float)posi.Y };
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -703,15 +705,19 @@ static void CalcPosVel(int type, const AActor *actor, const sector_t *sector,
|
|||
assert(sector != NULL);
|
||||
if (sector != NULL)
|
||||
{
|
||||
DVector2 disp = Displacements.getOffset(pgroup, sector->PortalGroup);
|
||||
if (chanflags & CHAN_AREA)
|
||||
{
|
||||
CalcSectorSoundOrg(sector, channum, &x, &z, &y);
|
||||
// listener must be reversely offset to calculate the proper sound origin.
|
||||
CalcSectorSoundOrg(listenpos-disp, sector, channum, *pos);
|
||||
pos->X += (float)disp.X;
|
||||
pos->Z += (float)disp.Y;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
x = FLOAT2FIXED(sector->centerspot.X);
|
||||
z = FLOAT2FIXED(sector->centerspot.Y);
|
||||
pos->X = (float)(sector->centerspot.X + disp.X);
|
||||
pos->Z = (float)(sector->centerspot.Y + disp.Y);
|
||||
chanflags |= CHAN_LISTENERZ;
|
||||
}
|
||||
}
|
||||
|
@ -719,17 +725,20 @@ static void CalcPosVel(int type, const AActor *actor, const sector_t *sector,
|
|||
|
||||
case SOURCE_Polyobj:
|
||||
assert(poly != NULL);
|
||||
CalcPolyobjSoundOrg(poly, &x, &z, &y);
|
||||
if (poly != NULL)
|
||||
{
|
||||
DVector2 disp = Displacements.getOffset(pgroup, poly->CenterSubsector->sector->PortalGroup);
|
||||
CalcPolyobjSoundOrg(listenpos-disp, poly, *pos);
|
||||
pos->X += (float)disp.X;
|
||||
pos->Z += (float)disp.Y;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if ((chanflags & CHAN_LISTENERZ) && players[consoleplayer].camera != NULL)
|
||||
{
|
||||
y = players[consoleplayer].camera != NULL ? FLOAT2FIXED(players[consoleplayer].camera->SoundPos().Z) : 0;
|
||||
pos->Y = (float)listenpos.Z;
|
||||
}
|
||||
pos->X = FIXED2FLOAT(x);
|
||||
pos->Y = FIXED2FLOAT(y);
|
||||
pos->Z = FIXED2FLOAT(z);
|
||||
}
|
||||
}
|
||||
if (vel != NULL)
|
||||
|
@ -758,42 +767,44 @@ static void CalcPosVel(int type, const AActor *actor, const sector_t *sector,
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
static void CalcSectorSoundOrg(const sector_t *sec, int channum, fixed_t *x, fixed_t *y, fixed_t *z)
|
||||
static void CalcSectorSoundOrg(const DVector3 &listenpos, const sector_t *sec, int channum, FVector3 &pos)
|
||||
{
|
||||
if (!(i_compatflags & COMPATF_SECTORSOUNDS))
|
||||
{
|
||||
// Are we inside the sector? If yes, the closest point is the one we're on.
|
||||
if (P_PointInSector(FIXED2DBL(*x), FIXED2DBL(*y)) == sec)
|
||||
if (P_PointInSector(pos.X, pos.Y) == sec)
|
||||
{
|
||||
FVector3 p = players[consoleplayer].camera->SoundPos();
|
||||
*x = FLOAT2FIXED(p.X);
|
||||
*y = FLOAT2FIXED(p.Y);
|
||||
pos.X = (float)listenpos.X;
|
||||
pos.Z = (float)listenpos.Y;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Find the closest point on the sector's boundary lines and use
|
||||
// that as the perceived origin of the sound.
|
||||
sec->ClosestPoint(*x, *y, *x, *y);
|
||||
DVector2 xy;
|
||||
sec->ClosestPoint(listenpos, xy);
|
||||
pos.X = (float)xy.X;
|
||||
pos.Z = (float)xy.Y;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
*x = FLOAT2FIXED(sec->centerspot.X);
|
||||
*y = FLOAT2FIXED(sec->centerspot.Y);
|
||||
pos.X = float(sec->centerspot.X);
|
||||
pos.Z = float(sec->centerspot.Y);
|
||||
}
|
||||
|
||||
// Set sound vertical position based on channel.
|
||||
if (channum == CHAN_FLOOR)
|
||||
{
|
||||
*z = MIN(sec->floorplane.ZatPoint(*x, *y), *z);
|
||||
pos.Y = (float)MIN<double>(sec->floorplane.ZatPoint(listenpos), listenpos.Z);
|
||||
}
|
||||
else if (channum == CHAN_CEILING)
|
||||
{
|
||||
*z = MAX(sec->ceilingplane.ZatPoint(*x, *y), *z);
|
||||
pos.Y = (float)MAX<double>(sec->ceilingplane.ZatPoint(listenpos), listenpos.Z);
|
||||
}
|
||||
else if (channum == CHAN_INTERIOR)
|
||||
{
|
||||
*z = clamp(*z, sec->floorplane.ZatPoint(*x, *y), sec->ceilingplane.ZatPoint(*x, *y));
|
||||
pos.Y = (float)clamp<double>(listenpos.Z, sec->floorplane.ZatPoint(listenpos), sec->ceilingplane.ZatPoint(listenpos));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -808,17 +819,17 @@ static void CalcSectorSoundOrg(const sector_t *sec, int channum, fixed_t *x, fix
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
static void CalcPolyobjSoundOrg(const FPolyObj *poly, fixed_t *x, fixed_t *y, fixed_t *z)
|
||||
static void CalcPolyobjSoundOrg(const DVector3 &listenpos, const FPolyObj *poly, FVector3 &pos)
|
||||
{
|
||||
side_t *side;
|
||||
sector_t *sec;
|
||||
|
||||
DVector2 pos(FIXED2DBL(*x), FIXED2DBL(*y));
|
||||
poly->ClosestPoint(pos, pos, &side);
|
||||
*x = FLOAT2FIXED(pos.X);
|
||||
*y = FLOAT2FIXED(pos.Y);
|
||||
DVector2 ppos;
|
||||
poly->ClosestPoint(listenpos, ppos, &side);
|
||||
pos.X = (float)ppos.X;
|
||||
pos.Z = (float)ppos.Y;
|
||||
sec = side->sector;
|
||||
*z = clamp(*z, sec->floorplane.ZatPoint(*x, *y), sec->ceilingplane.ZatPoint(*x, *y));
|
||||
pos.Y = (float)clamp<double>(listenpos.Z, sec->floorplane.ZatPoint(listenpos), sec->ceilingplane.ZatPoint(listenpos));
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
|
|
@ -493,6 +493,11 @@ struct TVector3
|
|||
return TVector3(v3.X + v2.X, v3.Y + v2.Y, v3.Z);
|
||||
}
|
||||
|
||||
friend TVector3 operator- (const TVector3 &v3, const Vector2 &v2)
|
||||
{
|
||||
return TVector3(v3.X - v2.X, v3.Y - v2.Y, v3.Z);
|
||||
}
|
||||
|
||||
friend Vector2 operator+ (const Vector2 &v2, const TVector3 &v3)
|
||||
{
|
||||
return Vector2(v2.X + v3.X, v2.Y + v3.Y);
|
||||
|
@ -500,11 +505,6 @@ struct TVector3
|
|||
|
||||
// Subtract a 3D vector and a 2D vector.
|
||||
// Discards the Z component of the 3D vector and returns a 2D vector.
|
||||
friend Vector2 operator- (const TVector3 &v3, const Vector2 &v2)
|
||||
{
|
||||
return Vector2(v3.X - v2.X, v3.Y - v2.Y);
|
||||
}
|
||||
|
||||
friend Vector2 operator- (const TVector2<vec_t> &v2, const TVector3 &v3)
|
||||
{
|
||||
return Vector2(v2.X - v3.X, v2.Y - v3.Y);
|
||||
|
|
Loading…
Reference in a new issue