Skip to content

Commit

Permalink
- floatify SW's sector object rotation.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Feb 15, 2022
1 parent a12093a commit 6e96b1e
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 33 deletions.
11 changes: 10 additions & 1 deletion source/core/gamefuncs.cpp
Expand Up @@ -399,11 +399,20 @@ void dragpoint(walltype* startwall, int newx, int newy)
{
vertexscan(startwall, [&](walltype* wal)
{
wal->move(newx, newy);
wal->movexy(newx, newy);
wal->sectorp()->exflags |= SECTOREX_DRAGGED;
});
}

void dragpoint(walltype* startwall, const DVector2& pos)
{
vertexscan(startwall, [&](walltype* wal)
{
wal->move(pos);
wal->sectorp()->exflags |= SECTOREX_DRAGGED;
});
}

//==========================================================================
//
//
Expand Down
1 change: 1 addition & 0 deletions source/core/gamefuncs.h
Expand Up @@ -169,6 +169,7 @@ void GetFlatSpritePosition(const tspritetype* spr, vec2_t pos, vec2_t* out, int*
void checkRotatedWalls();
bool sectorsConnected(int sect1, int sect2);
void dragpoint(walltype* wal, int newx, int newy);
void dragpoint(walltype* wal, const DVector2& pos);
DVector2 rotatepoint(const DVector2& pivot, const DVector2& point, binangle angle);

// y is negated so that the orientation is the same as in GZDoom, in order to use its utilities.
Expand Down
10 changes: 8 additions & 2 deletions source/core/maptypes.h
Expand Up @@ -417,7 +417,13 @@ struct walltype
bool twoSided() const { return nextsector >= 0; }
int Length();
void calcLength(); // this is deliberately not inlined and stored in a file where it can't be found at compile time.
void move(int newx, int newy);
void movexy(int newx, int newy);
void move(const DVector2& vec)
{
pos = vec;
moved();
}

void moved();

Blood::XWALL& xw() const { return *_xw; }
Expand Down Expand Up @@ -553,7 +559,7 @@ inline void walltype::moved()
sectorp()->dirty = EDirty::AllDirty;
}

inline void walltype::move(int newx, int newy)
inline void walltype::movexy(int newx, int newy)
{
pos.X = newx * maptoworld;
pos.Y = newy * maptoworld;
Expand Down
1 change: 1 addition & 0 deletions source/games/sw/src/game.h
Expand Up @@ -100,6 +100,7 @@ enum


#define PRODUCTION_ASSERT(f) \
assert(f);\
do { \
if (!(f)) \
I_FatalError("Assertion failed: %s %s, line %u", #f, __FILE__, __LINE__); \
Expand Down
10 changes: 7 additions & 3 deletions source/games/sw/src/interpso.cpp
Expand Up @@ -340,7 +340,9 @@ void so_updateinterpolations(void) // Stick at beginning of domovethings
}
}
else
{
data->oldipos = getvalue(*data);
}

if (!interpolating)
data->lastipos = data->lastoldipos = data->oldipos;
Expand All @@ -352,7 +354,7 @@ void so_updateinterpolations(void) // Stick at beginning of domovethings
// make sure you don't exit
void so_dointerpolations(int32_t smoothratio) // Stick at beginning of drawscreen
{
int32_t i, delta;
int32_t i;
SECTOR_OBJECT* sop;
so_interp *interp;
so_interp::interp_data *data;
Expand Down Expand Up @@ -445,8 +447,8 @@ void so_dointerpolations(int32_t smoothratio) // Stick at b
}
else
{
delta = data->lastipos - data->lastoldipos;
setvalue(*data, data->lastoldipos + MulScale(delta, ratio, 16));
double delta = data->lastipos - data->lastoldipos;
setvalue(*data, data->lastoldipos + MulScaleF(delta, ratio, 16));
}
}
}
Expand All @@ -473,7 +475,9 @@ void so_restoreinterpolations(void) // Stick at end of drawscree
if (actorofang) actorofang->spr.ang = data->bakipos;
}
else
{
setvalue(*data, data->bakipos);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions source/games/sw/src/player.cpp
Expand Up @@ -3830,7 +3830,7 @@ int PlayerCanDiveNoWarp(PLAYER* pp)
int GetOverlapSector(int x, int y, sectortype** over, sectortype** under)
{
int i, found = 0;
sectortype* sf[2]= {nullptr,nullptr}; // sectors found
sectortype* sf[3]= {nullptr,nullptr}; // sectors found
auto secto = *over;
auto sectu = *under;

Expand Down Expand Up @@ -3859,7 +3859,7 @@ int GetOverlapSector(int x, int y, sectortype** over, sectortype** under)
{
sf[found] = §
found++;
PRODUCTION_ASSERT(found <= 2);
if (found > 2) return 0;
}
}
}
Expand Down
32 changes: 16 additions & 16 deletions source/games/sw/src/slidor.cpp
Expand Up @@ -274,11 +274,11 @@ int DoSlidorMoveWalls(DSWActor* actor, int amt)
if (!wal->twoSided())
{
// white wall - move 4 points
wal->move(wal->wall_int_pos().X - amt, wal->wall_int_pos().Y);
pwal->move(pwal->wall_int_pos().X - amt, pwal->wall_int_pos().Y);
wal->point2Wall()->move(wal->point2Wall()->wall_int_pos().X - amt, wal->point2Wall()->wall_int_pos().Y);
wal->movexy(wal->wall_int_pos().X - amt, wal->wall_int_pos().Y);
pwal->movexy(pwal->wall_int_pos().X - amt, pwal->wall_int_pos().Y);
wal->point2Wall()->movexy(wal->point2Wall()->wall_int_pos().X - amt, wal->point2Wall()->wall_int_pos().Y);
auto pwal2 = wal->point2Wall()->point2Wall();
pwal2->move(pwal2->wall_int_pos().X - amt, pwal2->wall_int_pos().Y);
pwal2->movexy(pwal2->wall_int_pos().X - amt, pwal2->wall_int_pos().Y);
}
else
{
Expand All @@ -299,11 +299,11 @@ int DoSlidorMoveWalls(DSWActor* actor, int amt)
if (!wal->twoSided())
{
// white wall - move 4 points
wal->move(wal->wall_int_pos().X + amt, wal->wall_int_pos().Y);
pwal->move(pwal->wall_int_pos().X + amt, pwal->wall_int_pos().Y);
wal->point2Wall()->move(wal->point2Wall()->wall_int_pos().X + amt, wal->point2Wall()->wall_int_pos().Y);
wal->movexy(wal->wall_int_pos().X + amt, wal->wall_int_pos().Y);
pwal->movexy(pwal->wall_int_pos().X + amt, pwal->wall_int_pos().Y);
wal->point2Wall()->movexy(wal->point2Wall()->wall_int_pos().X + amt, wal->point2Wall()->wall_int_pos().Y);
auto pwal2 = wal->point2Wall()->point2Wall();
pwal2->move(pwal2->wall_int_pos().X + amt, pwal2->wall_int_pos().Y);
pwal2->movexy(pwal2->wall_int_pos().X + amt, pwal2->wall_int_pos().Y);
}
else
{
Expand All @@ -323,11 +323,11 @@ int DoSlidorMoveWalls(DSWActor* actor, int amt)

if (!wal->twoSided())
{
wal->move(wal->wall_int_pos().X, wal->wall_int_pos().Y - amt);
pwal->move(pwal->wall_int_pos().X, pwal->wall_int_pos().Y - amt);
wal->point2Wall()->move(wal->point2Wall()->wall_int_pos().X, wal->point2Wall()->wall_int_pos().Y - amt);
wal->movexy(wal->wall_int_pos().X, wal->wall_int_pos().Y - amt);
pwal->movexy(pwal->wall_int_pos().X, pwal->wall_int_pos().Y - amt);
wal->point2Wall()->movexy(wal->point2Wall()->wall_int_pos().X, wal->point2Wall()->wall_int_pos().Y - amt);
auto pwal2 = wal->point2Wall()->point2Wall();
pwal2->move(pwal2->wall_int_pos().X, pwal2->wall_int_pos().Y - amt);
pwal2->movexy(pwal2->wall_int_pos().X, pwal2->wall_int_pos().Y - amt);
}
else
{
Expand All @@ -346,11 +346,11 @@ int DoSlidorMoveWalls(DSWActor* actor, int amt)

if (!wal->twoSided())
{
wal->move(wal->wall_int_pos().X, wal->wall_int_pos().Y + amt);
pwal->move(pwal->wall_int_pos().X, pwal->wall_int_pos().Y + amt);
wal->point2Wall()->move(wal->point2Wall()->wall_int_pos().X, wal->point2Wall()->wall_int_pos().Y + amt);
wal->movexy(wal->wall_int_pos().X, wal->wall_int_pos().Y + amt);
pwal->movexy(pwal->wall_int_pos().X, pwal->wall_int_pos().Y + amt);
wal->point2Wall()->movexy(wal->point2Wall()->wall_int_pos().X, wal->point2Wall()->wall_int_pos().Y + amt);
auto pwal2 = wal->point2Wall()->point2Wall();
pwal2->move(pwal2->wall_int_pos().X, pwal2->wall_int_pos().Y + amt);
pwal2->movexy(pwal2->wall_int_pos().X, pwal2->wall_int_pos().Y + amt);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion source/games/sw/src/sprite.cpp
Expand Up @@ -1454,7 +1454,7 @@ void PreMapCombineFloors(void)

for (auto& wal : wallsofsector(dasect))
{
wal.move(wal.wall_int_pos().X + dx, wal.wall_int_pos().Y + dy);
wal.movexy(wal.wall_int_pos().X + dx, wal.wall_int_pos().Y + dy);

if (wal.twoSided())
search.Add(wal.nextSector());
Expand Down
16 changes: 9 additions & 7 deletions source/games/sw/src/track.cpp
Expand Up @@ -1610,6 +1610,8 @@ void MovePoints(SECTOR_OBJECT* sop, short delta_ang, int nx, int ny)
if ((sop->flags & SOBJ_ZMID_FLOOR))
sop->pmid.Z = sop->mid_sector->floorz;

DVector2 pivot = { sop->pmid.X * maptoworld, sop->pmid.Y * maptoworld };
DVector2 move = { nx * maptoworld, ny * maptoworld };
for (sectp = sop->sectp, j = 0; *sectp; sectp++, j++)
{
if ((sop->flags & (SOBJ_SPRITE_OBJ | SOBJ_DONT_ROTATE)))
Expand All @@ -1623,11 +1625,11 @@ void MovePoints(SECTOR_OBJECT* sop, short delta_ang, int nx, int ny)

if (wal.extra && (wal.extra & WALLFX_LOOP_OUTER))
{
dragpoint(&wal, wal.wall_int_pos().X + nx, wal.wall_int_pos().Y + ny);
dragpoint(&wal, wal.pos + move);
}
else
{
wal.move(wal.wall_int_pos().X + nx, wal.wall_int_pos().Y + ny);
wal.move(wal.pos + move);
}

rot_ang = delta_ang;
Expand All @@ -1641,15 +1643,15 @@ void MovePoints(SECTOR_OBJECT* sop, short delta_ang, int nx, int ny)
if ((wal.extra & WALLFX_LOOP_SPIN_4X))
rot_ang = NORM_ANGLE(rot_ang * 4);

rotatepoint(sop->pmid.vec2, wal.wall_int_pos(), rot_ang, &rxy);
auto vec = rotatepoint(pivot, wal.pos, buildang(rot_ang));

if (wal.extra && (wal.extra & WALLFX_LOOP_OUTER))
{
dragpoint(&wal, rxy.X, rxy.Y);
dragpoint(&wal, vec);
}
else
{
wal.move(rxy.X, rxy.Y);
wal.move(vec);
}
}

Expand Down Expand Up @@ -1870,7 +1872,7 @@ void RefreshPoints(SECTOR_OBJECT* sop, int nx, int ny, bool dynamic)
}
else
{
wal.move(dx, dy);
wal.movexy(dx, dy);
}
}

Expand Down Expand Up @@ -2018,7 +2020,7 @@ void CollapseSectorObject(SECTOR_OBJECT* sop, int nx, int ny)
}
else
{
wal.move(nx, ny);
wal.movexy(nx, ny);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/games/sw/src/wallmove.cpp
Expand Up @@ -115,7 +115,7 @@ int DoWallMove(DSWActor* actor)
}
else
{
wal.move(actor->spr.pos.X + nx, actor->spr.pos.Y + ny);
wal.movexy(actor->spr.pos.X + nx, actor->spr.pos.Y + ny);
}

if (shade1)
Expand Down

0 comments on commit 6e96b1e

Please sign in to comment.