raze/source/core/gamefuncs.cpp

813 lines
23 KiB
C++
Raw Normal View History

2022-01-22 13:37:17 +00:00
//-------------------------------------------------------------------------
/*
Copyright (C) 2021 Christoph Oelckers & Mitchell Richters
This is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
//-------------------------------------------------------------------------
#include "gamefuncs.h"
#include "gamestruct.h"
#include "intvec.h"
#include "coreactor.h"
#include "interpolate.h"
#include "hw_voxels.h"
2022-01-22 13:37:17 +00:00
IntRect viewport3d;
2022-01-22 13:37:17 +00:00
//---------------------------------------------------------------------------
//
// Unified chasecam function for all games.
//
//---------------------------------------------------------------------------
double cameradist, cameraclock;
2022-01-22 13:37:17 +00:00
bool calcChaseCamPos(DVector3& ppos, DCoreActor* act, sectortype** psect, DAngle ang, fixedhoriz horiz, double const interpfrac)
2022-01-22 13:37:17 +00:00
{
if (!*psect) return false;
// Calculate new pos to shoot backwards
DVector3 npos = gi->chaseCamPos(ang, horiz);
2022-01-22 13:37:17 +00:00
HitInfoBase hitinfo;
2022-01-22 13:37:17 +00:00
auto bakcstat = act->spr.cstat;
act->spr.cstat &= ~CSTAT_SPRITE_BLOCK_ALL;
updatesectorz(ppos, psect);
hitscan(ppos, *psect, npos, hitinfo, CLIPMASK1);
2022-01-22 13:37:17 +00:00
act->spr.cstat = bakcstat;
auto hpos = hitinfo.hitpos - ppos;
2022-01-22 13:37:17 +00:00
if (!*psect) return false;
2022-01-22 13:37:17 +00:00
// If something is in the way, make cameradist lower if necessary
if (npos.XY().Sum() > hpos.XY().Sum())
2022-01-22 13:37:17 +00:00
{
double DVector3::* c = fabs(npos.X) > fabs(npos.Y) ? &DVector3::X : &DVector3::Y;
2022-01-22 13:37:17 +00:00
if (hitinfo.hitWall != nullptr)
{
// Push you a little bit off the wall
*psect = hitinfo.hitSector;
hpos.*c -= npos.*c * npos.XY().dot(hitinfo.hitWall->delta().Angle().ToVector().Rotated90CW()) * (1. / 1024.);
2022-01-22 13:37:17 +00:00
}
else if (hitinfo.hitActor == nullptr)
{
// Push you off the ceiling/floor
*psect = hitinfo.hitSector;
hpos.*c -= npos.*c * (1. / 32.);
2022-01-22 13:37:17 +00:00
}
else
{
// If you hit a sprite that's not a wall sprite - try again.
if (!(hitinfo.hitActor->spr.cstat & CSTAT_SPRITE_ALIGNMENT_WALL))
2022-01-22 13:37:17 +00:00
{
bakcstat = hitinfo.hitActor->spr.cstat;
hitinfo.hitActor->spr.cstat &= ~(CSTAT_SPRITE_BLOCK | CSTAT_SPRITE_BLOCK_HITSCAN);
calcChaseCamPos(ppos, act, psect, ang, horiz, interpfrac);
hitinfo.hitActor->spr.cstat = bakcstat;
2022-01-22 13:37:17 +00:00
return false;
}
else
{
// same as wall calculation.
hpos.*c -= npos.*c * npos.XY().dot((act->spr.angle - DAngle90).ToVector().Rotated90CW()) * (1. / 1024.);
2022-01-22 13:37:17 +00:00
}
}
double newdist = hpos.*c / npos.*c;
if (newdist < cameradist) cameradist = newdist;
2022-01-22 13:37:17 +00:00
}
// Actually move you! (camerdist is 1 if nothing is in the way)
ppos += npos * cameradist;
2022-01-22 13:37:17 +00:00
// Calculate clock using GameTicRate so it increases the same rate on all speed computers.
double myclock = PlayClock + 120 / GameTicRate * interpfrac;
2022-01-22 13:37:17 +00:00
if (cameraclock == INT_MIN)
{
// Third person view was just started.
cameraclock = myclock;
}
// Slowly increase cameradist until it reaches 1.
cameradist = min(cameradist + ((myclock - cameraclock) * (1. / 64.)), 1.);
2022-01-22 13:37:17 +00:00
cameraclock = myclock;
// Make sure psectnum is correct.
updatesectorz(ppos, psect);
2022-01-22 13:37:17 +00:00
return true;
}
//==========================================================================
//
// consolidated slope calculation
//
//==========================================================================
void calcSlope(const sectortype* sec, double xpos, double ypos, double* pceilz, double* pflorz)
2022-01-22 13:37:17 +00:00
{
int bits = 0;
if (pceilz)
{
bits |= sec->ceilingstat;
*pceilz = sec->ceilingz;
2022-01-22 13:37:17 +00:00
}
if (pflorz)
{
bits |= sec->floorstat;
*pflorz = sec->floorz;
2022-01-22 13:37:17 +00:00
}
if ((bits & CSTAT_SECTOR_SLOPE) == CSTAT_SECTOR_SLOPE)
{
auto wal = sec->firstWall();
double len = wal->Length();
2022-01-22 13:37:17 +00:00
if (len != 0)
{
float fac = (wal->delta().X * (ypos - wal->pos.Y) - wal->delta().Y * (xpos - wal->pos.X)) / len * (1. / SLOPEVAL_FACTOR);
2022-01-22 13:37:17 +00:00
if (pceilz && sec->ceilingstat & CSTAT_SECTOR_SLOPE) *pceilz += (sec->ceilingheinum * fac);
if (pflorz && sec->floorstat & CSTAT_SECTOR_SLOPE) *pflorz += (sec->floorheinum * fac);
}
}
}
// only used by clipmove et.al.
void getcorrectzsofslope(int sectnum, int dax, int day, int* ceilz, int* florz)
{
DVector2 closestv;
SquareDistToSector(dax * inttoworld, day * inttoworld, &sector[sectnum], &closestv);
double ffloorz, fceilz;
calcSlope(&sector[sectnum], closestv.X, closestv.Y, &fceilz, &ffloorz);
if (ceilz) *ceilz = int(fceilz * zworldtoint);
if (florz) *florz = int(ffloorz * zworldtoint);
}
2022-01-22 13:37:17 +00:00
//==========================================================================
//
//
//
//==========================================================================
int getslopeval(sectortype* sect, const DVector3& pos, double basez)
2022-01-22 13:37:17 +00:00
{
auto wal = sect->firstWall();
auto delta = wal->delta();
double i = (pos.Y - wal->pos.Y) * delta.X - (pos.X - wal->pos.X) * delta.Y;
return i == 0? 0 : SLOPEVAL_FACTOR * (pos.Z - basez) * wal->Length() / i;
2022-01-22 13:37:17 +00:00
}
//==========================================================================
//
// Calculate the distance to the closest point in the given sector
//
//==========================================================================
double SquareDistToSector(double px, double py, const sectortype* sect, DVector2* point)
{
if (inside(px, py, sect))
{
if (point)
*point = { px, py };
return 0;
}
double bestdist = DBL_MAX;
DVector2 bestpt = { px, py };
for (auto& wal : wallsofsector(sect))
{
DVector2 pt;
auto dist = SquareDistToWall(px, py, &wal, &pt);
if (dist < bestdist)
{
bestdist = dist;
bestpt = pt;
}
}
if (point) *point = bestpt;
return bestdist;
}
2022-01-22 13:37:17 +00:00
//==========================================================================
//
// Calculate the position of a wall sprite in the world
//
//==========================================================================
void GetWallSpritePosition(const spritetypebase* spr, const DVector2& pos, DVector2* out, bool render)
2022-01-22 13:37:17 +00:00
{
auto tex = tileGetTexture(spr->picnum);
double width, xoffset;
2022-01-22 13:37:17 +00:00
if (render && hw_hightile && TileFiles.tiledata[spr->picnum].hiofs.xsize)
{
width = TileFiles.tiledata[spr->picnum].hiofs.xsize;
xoffset = (TileFiles.tiledata[spr->picnum].hiofs.xoffs + spr->xoffset);
2022-01-22 13:37:17 +00:00
}
else
{
width = tex->GetDisplayWidth();
xoffset = tex->GetDisplayLeftOffset() + spr->xoffset;
2022-01-22 13:37:17 +00:00
}
double x = spr->angle.Sin() * spr->xrepeat * REPEAT_SCALE;
double y = -spr->angle.Cos() * spr->xrepeat * REPEAT_SCALE;
2022-01-22 13:37:17 +00:00
if (spr->cstat & CSTAT_SPRITE_XFLIP) xoffset = -xoffset;
double origin = (width * 0.5) + xoffset;
2022-01-22 13:37:17 +00:00
out[0].X = pos.X - x * origin;
out[0].Y = pos.Y - y * origin;
out[1].X = out[0].X + x * width;
out[1].Y = out[0].Y + y * width;
2022-01-22 13:37:17 +00:00
}
//==========================================================================
//
// Calculate the position of a floor sprite in the world
2022-01-22 13:37:17 +00:00
//
//==========================================================================
void TGetFlatSpritePosition(const spritetypebase* spr, const DVector2& pos, DVector2* out, double* outz, int heinum, bool render)
2022-01-22 13:37:17 +00:00
{
auto tex = tileGetTexture(spr->picnum);
double width, height, leftofs, topofs;
double sloperatio = sqrt(heinum * heinum + SLOPEVAL_FACTOR * SLOPEVAL_FACTOR) * (1. / SLOPEVAL_FACTOR);
double xrepeat = spr->xrepeat * REPEAT_SCALE;
double yrepeat = spr->yrepeat * REPEAT_SCALE;
2022-01-22 13:37:17 +00:00
int xo = heinum ? 0 : spr->xoffset;
int yo = heinum ? 0 : spr->yoffset;
if (render && hw_hightile && TileFiles.tiledata[spr->picnum].hiofs.xsize)
{
width = TileFiles.tiledata[spr->picnum].hiofs.xsize * xrepeat;
height = TileFiles.tiledata[spr->picnum].hiofs.ysize * yrepeat;
leftofs = (TileFiles.tiledata[spr->picnum].hiofs.xoffs + xo) * xrepeat;
topofs = (TileFiles.tiledata[spr->picnum].hiofs.yoffs + yo) * yrepeat;
2022-01-22 13:37:17 +00:00
}
else
{
width = (int)tex->GetDisplayWidth() * xrepeat;
height = (int)tex->GetDisplayHeight() * yrepeat;
leftofs = ((int)tex->GetDisplayLeftOffset() + xo) * xrepeat;
topofs = ((int)tex->GetDisplayTopOffset() + yo) * yrepeat;
2022-01-22 13:37:17 +00:00
}
if (spr->cstat & CSTAT_SPRITE_XFLIP) leftofs = -leftofs;
if (spr->cstat & CSTAT_SPRITE_YFLIP) topofs = -topofs;
double sprcenterx = (width * 0.5) + leftofs;
double sprcentery = (height * 0.5) + topofs;
2022-01-22 13:37:17 +00:00
double cosang = spr->angle.Cos();
double sinang = spr->angle.Sin();
double cosangslope = cosang / sloperatio;
double sinangslope = sinang / sloperatio;
2022-01-22 13:37:17 +00:00
out[0].X = pos.X + sinang * sprcenterx + cosangslope * sprcentery;
out[0].Y = pos.Y + sinangslope * sprcentery - cosang * sprcenterx;
2022-01-22 13:37:17 +00:00
out[1].X = out[0].X - sinang * width;
out[1].Y = out[0].Y + cosang * width;
2022-01-22 13:37:17 +00:00
DVector2 sub = { cosangslope * height, sinangslope * height };
2022-01-22 13:37:17 +00:00
out[2] = out[1] - sub;
out[3] = out[0] - sub;
if (outz)
{
if (!heinum) outz[3] = outz[2] = outz[1] = outz[0] = 0;
else
{
for (int i = 0; i < 4; i++)
{
outz[i] = (sinang * (out[i].Y - pos.Y) + cosang * (out[i].X - pos.X)) * heinum * (1. / SLOPEVAL_FACTOR);
2022-01-22 13:37:17 +00:00
}
}
}
}
void GetFlatSpritePosition(DCoreActor* actor, const DVector2& pos, DVector2* out, double* outz, bool render)
2022-01-22 13:37:17 +00:00
{
TGetFlatSpritePosition(&actor->spr, pos, out, outz, spriteGetSlope(actor), render);
2022-01-22 13:37:17 +00:00
}
void GetFlatSpritePosition(const tspritetype* spr, const DVector2& pos, DVector2* out, double* outz, bool render)
2022-01-22 13:37:17 +00:00
{
TGetFlatSpritePosition(spr, pos, out, outz, tspriteGetSlope(spr), render);
}
//==========================================================================
//
// checks if the given point is sufficiently close to the given line segment.
//
//==========================================================================
EClose IsCloseToLine(const DVector2& point, const DVector2& start, const DVector2& end, double maxdist)
{
auto const v1 = start - point;
auto const v2 = end - point;
// trivially outside the box.
if (
((v1.X < -maxdist) && (v2.X < -maxdist)) || // fully to the left
((v1.Y < -maxdist) && (v2.Y < -maxdist)) || // fully below
((v1.X >= maxdist) && (v2.X >= maxdist)) || // fully to the right
((v1.Y >= maxdist) && (v2.Y >= maxdist))) // fully above
return EClose::Outside;
auto waldelta = end - start;
if (waldelta.X * v1.Y <= waldelta.Y * v1.X)
{
// is it in front?
waldelta.X *= waldelta.X > 0 ? v1.Y + maxdist : v1.Y - maxdist;
waldelta.Y *= waldelta.Y > 0 ? v1.X - maxdist : v1.X + maxdist;
return waldelta.X > waldelta.Y ? EClose::InFront : EClose::Outside;
}
else
{
// or behind?
waldelta.X *= waldelta.X > 0 ? v1.Y - maxdist : v1.Y + maxdist;
waldelta.Y *= waldelta.Y > 0 ? v1.X + maxdist : v1.X - maxdist;
return (waldelta.X <= waldelta.Y) ? EClose::Behind : EClose::Outside;
}
}
EClose IsCloseToWall(const DVector2& point, walltype* wal, double maxdist)
{
return IsCloseToLine(point, wal->pos, wal->point2Wall()->pos, maxdist);
}
2022-01-22 13:37:17 +00:00
//==========================================================================
//
// Check if some walls are set to use rotated textures.
// Ideally this should just have been done with texture rotation,
// but the effects on the render code would be too severe due to the alignment mess.
//
//==========================================================================
void checkRotatedWalls()
{
for (auto& w : wall)
{
if (w.cstat & CSTAT_WALL_ROTATE_90)
{
int picnum = w.picnum;
tileUpdatePicnum(&picnum);
auto& tile = RotTile(picnum);
2022-01-22 13:37:17 +00:00
if (tile.newtile == -1 && tile.owner == -1)
{
tile.newtile = TileFiles.tileCreateRotated(picnum);
2022-01-22 13:37:17 +00:00
assert(tile.newtile != -1);
RotTile(tile.newtile).owner = picnum;
2022-01-22 13:37:17 +00:00
}
}
}
}
//==========================================================================
//
// check if two sectors share a wall connection
//
//==========================================================================
bool sectorsConnected(int sect1, int sect2)
{
for (auto& wal : wallsofsector(sect1))
{
if (wal.nextsector == sect2) return true;
}
return false;
}
//==========================================================================
//
//
//
//==========================================================================
void dragpoint(walltype* startwall, int newx, int newy)
{
vertexscan(startwall, [&](walltype* wal)
{
wal->movexy(newx, newy);
2022-01-22 13:37:17 +00:00
wal->sectorp()->exflags |= SECTOREX_DRAGGED;
});
}
void dragpoint(walltype* startwall, const DVector2& pos)
{
vertexscan(startwall, [&](walltype* wal)
{
wal->move(pos);
wal->sectorp()->exflags |= SECTOREX_DRAGGED;
});
}
//==========================================================================
//
//
//
//==========================================================================
int64_t checkforinside(double x, double y, const DVector2& pt1, const DVector2& pt2)
{
// Perform the checks here in 48.16 fixed point.
// Doing it directly with floats and multiplications does not work reliably due to underflows.
// Unfortunately, due to the conversions, this is a bit slower. :(
int64_t xs = int64_t(0x10000 * (pt1.X - x));
int64_t ys = int64_t(0x10000 * (pt1.Y - y));
int64_t xe = int64_t(0x10000 * (pt2.X - x));
int64_t ye = int64_t(0x10000 * (pt2.Y - y));
if ((ys ^ ye) < 0)
{
int64_t val;
if ((xs ^ xe) >= 0) val = xs;
else val = ((xs * ye) - xe * ys) ^ ye;
return val;
}
return 0;
}
2022-01-22 13:37:17 +00:00
//==========================================================================
//
//
//
//==========================================================================
int inside(double x, double y, const sectortype* sect)
{
if (sect)
{
int64_t acc = 1;
for (auto& wal : wallsofsector(sect))
{
acc ^= checkforinside(x, y, wal.pos, wal.point2Wall()->pos);
}
return acc < 0;
}
return -1;
}
//==========================================================================
//
//
//
//==========================================================================
int insidePoly(double x, double y, const DVector2* points, int count)
{
int64_t acc = 1;
for (int i = 0; i < count; i++)
{
int j = (i + 1) % count;
acc ^= checkforinside(x, y, points[i], points[j]);
}
return acc < 0;
}
//==========================================================================
//
// find the closest neighboring sector plane in the given direction.
// Does not consider slopes, just like the original!
//
//==========================================================================
sectortype* nextsectorneighborzptr(sectortype* sectp, double startz, int flags)
{
double factor = (flags & Find_Up)? -1 : 1;
double bestz = INT_MAX;
sectortype* bestsec = (flags & Find_Safe)? sectp : nullptr;
const auto planez = (flags & Find_Ceiling)? &sectortype::ceilingz : &sectortype::floorz;
startz *= factor;
for(auto& wal : wallsofsector(sectp))
{
if (wal.twoSided())
{
auto nextsec = wal.nextSector();
auto nextz = factor * nextsec->*planez;
if (startz < nextz && nextz < bestz)
{
bestz = nextz;
bestsec = nextsec;
}
}
}
return bestsec;
}
//==========================================================================
//
//
//
//==========================================================================
bool cansee(const DVector3& start, sectortype* sect1, const DVector3& end, sectortype* sect2)
{
if (!sect1 || !sect2) return false;
auto delta = end - start;
if (delta.XY().isZero())
return (sect1 == sect2);
BFSSectorSearch search(sect1);
while (auto sec = search.GetNext())
{
for (auto& wal : wallsofsector(sec))
{
double factor = InterceptLineSegments(start.X, start.Y, delta.X, delta.Y, wal.pos.X, wal.pos.Y, wal.delta().X, wal.delta().Y, nullptr, true);
if (factor <= 0 || factor >= 1) continue;
if (!wal.twoSided() || wal.cstat & CSTAT_WALL_1WAY)
return false;
auto spot = start + delta * factor;
double floorz, ceilz;
for (auto isec : { sec, wal.nextSector() })
{
getzsofslopeptr(isec, spot, &ceilz, &floorz);
if (spot.Z <= ceilz || spot.Z >= floorz)
return false;
}
search.Add(wal.nextSector());
}
}
return search.Check(sect2);
}
//==========================================================================
//
//
//
//==========================================================================
bool intersectSprite(DCoreActor* actor, const DVector3& start, const DVector3& direction, DVector3& result, double displacement)
{
auto end = start + direction;
if (direction.isZero()) return false;
// use dot product to check if the sprite is behind us (or ourselves if the result is 0)
auto dotprod = direction.XY().dot(actor->spr.pos.XY() - start.XY());
if (dotprod <= 0) return false;
// get point on trace that is closest to the sprite
double const length = direction.XY().LengthSquared();
DVector3 point = start + direction * (dotprod / length);
// This is somewhat smaller than the sprite's actual size, but that's how it was
auto sprwidth = tileWidth(actor->spr.picnum) * actor->spr.xrepeat * (REPEAT_SCALE * 0.5) + displacement;
// Using proper distance here, Build originally used the sum of x- and y-distance
if ((point.XY() - actor->spr.pos.XY()).LengthSquared() > sprwidth * sprwidth * 0.5) return false; // too far away
double newz = point.Z;
double siz;
double const hitz = actor->spr.pos.Z + actor->GetOffsetAndHeight(siz);
if (newz < hitz - siz || newz > hitz)
return 0;
result.XY() = point;
result.Z = newz;
return 1;
}
2022-09-25 08:57:46 +00:00
//==========================================================================
//
//
//
//==========================================================================
void neartag(const DVector3& pos, sectortype* startsect, DAngle angle, HitInfoBase& result, double range, int flags)
{
auto checkTag = [=](const auto* object)
{
return (((flags & NT_Lotag) && object->lotag) || ((flags & NT_Hitag) && object->hitag));
};
auto v = DVector3(angle.ToVector() * range * 1.000001, 0); // extend the range a tiny bit so that we really find everything we need.
result.clearObj();
result.hitpos.X = result.hitpos.Y = 0;
if (!startsect || (flags & (NT_Lotag | NT_Hitag)) == 0)
return;
2022-09-25 08:57:46 +00:00
BFSSectorSearch search(startsect);
while (auto sect = search.GetNext())
{
for (auto& wal : wallsofsector(sect))
{
const auto nextsect = wal.nextSector();
if (PointOnLineSide(pos.XY(), &wal) > 0) continue;
double factor = InterceptLineSegments(pos.X, pos.Y, v.X, v.Y, wal.pos.X, wal.pos.Y, wal.delta().X, wal.delta().Y);
if (factor > 0 && factor < 1)
{
bool foundsector = (wal.twoSided() && checkTag(nextsect));
bool foundwall = checkTag(&wal);
#if 0 // does not work if the trace goes right through the vertex between two walls.
if (!wal.twoSided() && !foundwall && !foundsector)
{
// this case was not handled by Build:
// If we hit an untagged one-sided wall it should both shorten the scan trace and clear all hits beyond.
// Otherwise this may cause problems with some weirdly shaped sectors.
result.hitSector = nullptr;
result.hitWall = nullptr;
result.hitpos.X = 0;
v *= factor;
continue;
}
#endif
if (foundsector) result.hitSector = nextsect;
if (foundwall) result.hitWall = &wal;
if (foundwall || foundsector)
{
v *= factor;
result.hitpos.X = v.XY().Length();
}
if (wal.twoSided())
{
search.Add(nextsect);
}
}
}
if (!(flags & NT_NoSpriteCheck))
{
TSectIterator<DCoreActor> it(sect);
while (auto actor = it.Next())
{
if (actor->spr.cstat2 & CSTAT2_SPRITE_NOFIND)
continue;
if (checkTag(&actor->spr))
{
DVector3 spot;
if (intersectSprite(actor, pos, v, spot, 1 / 256.))
{
result.hitActor = actor;
// return distance to sprite in a separate variable because there is
// no means to determine what is for if both a sprite and wall are found.
// Only SW's NearTagList actually uses it.
result.hitpos.Y = (spot - pos).XY().Length();
}
}
}
}
}
}
//==========================================================================
//
//
//
//==========================================================================
bool isAwayFromWall(DCoreActor* ac, double delta)
{
sectortype* s1;
updatesector(ac->spr.pos + DVector2(delta, delta), &s1);
if (s1 == ac->sector())
{
updatesector(ac->spr.pos - DVector2(delta, delta), &s1);
if (s1 == ac->sector())
{
updatesector(ac->spr.pos + DVector2(delta, -delta), &s1);
if (s1 == ac->sector())
{
updatesector(ac->spr.pos + DVector2(-delta, delta), &s1);
if (s1 == ac->sector())
return true;
}
}
}
return false;
}
//==========================================================================
//
//
//
//==========================================================================
tspritetype* renderAddTsprite(tspriteArray& tsprites, DCoreActor* actor)
2022-01-22 13:37:17 +00:00
{
auto tspr = tsprites.newTSprite();
2022-01-22 13:37:17 +00:00
tspr->pos = actor->spr.pos;
2022-01-22 13:37:17 +00:00
tspr->cstat = actor->spr.cstat;
tspr->picnum = actor->spr.picnum;
tspr->shade = actor->spr.shade;
tspr->pal = actor->spr.pal;
tspr->clipdist = 0;
tspr->blend = actor->spr.blend;
tspr->xrepeat = actor->spr.xrepeat;
tspr->yrepeat = actor->spr.yrepeat;
tspr->xoffset = actor->spr.xoffset;
tspr->yoffset = actor->spr.yoffset;
tspr->sectp = actor->spr.sectp;
tspr->statnum = actor->spr.statnum;
tspr->angle = actor->spr.angle;
tspr->xint = actor->spr.xint;
tspr->yint = actor->spr.yint;
tspr->inittype = actor->spr.inittype; // not used by tsprites.
2022-01-22 13:37:17 +00:00
tspr->lotag = actor->spr.lotag;
tspr->hitag = actor->spr.hitag;
tspr->extra = actor->spr.extra;
tspr->time = actor->time;
tspr->cstat2 = actor->spr.cstat2;
2022-01-22 13:37:17 +00:00
tspr->ownerActor = actor;
// need to copy the slope sprite flag around because for tsprites the bit combination means 'voxel'.
if ((tspr->cstat & CSTAT_SPRITE_ALIGNMENT_MASK) == CSTAT_SPRITE_ALIGNMENT_SLOPE)
{
tspr->cstat &= ~CSTAT_SPRITE_ALIGNMENT_WALL;
tspr->clipdist |= TSPR_SLOPESPRITE;
}
return tspr;
}
//==========================================================================
//
//
//
//==========================================================================
int tilehasmodelorvoxel(int const tilenume, int pal)
{
return
(mdinited && hw_models && tile2model[Ptile2tile(tilenume, pal)].modelid != -1) ||
(r_voxels && tiletovox[tilenume] != -1);
}
2022-01-22 13:37:17 +00:00
//==========================================================================
//
// vector serializers
//
//==========================================================================
FSerializer& Serialize(FSerializer& arc, const char* key, vec2_t& c, vec2_t* def)
{
if (arc.isWriting() && def && !memcmp(&c, def, sizeof(c))) return arc;
if (arc.BeginObject(key))
{
arc("x", c.X, def ? &def->X : nullptr)
("y", c.Y, def ? &def->Y : nullptr)
.EndObject();
}
return arc;
}
FSerializer& Serialize(FSerializer& arc, const char* key, vec3_t& c, vec3_t* def)
{
if (arc.isWriting() && def && !memcmp(&c, def, sizeof(c))) return arc;
if (arc.BeginObject(key))
{
arc("x", c.X, def ? &def->X : nullptr)
("y", c.Y, def ? &def->Y : nullptr)
("z", c.Z, def ? &def->Z : nullptr)
.EndObject();
}
return arc;
}