From facedb632561b0c2988759e51e2d59b868cfa536 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 13 Sep 2022 20:09:29 +0200 Subject: [PATCH] - floatified movesprite_ex --- source/games/duke/src/actors_d.cpp | 20 ++++++++++---------- source/games/duke/src/actors_r.cpp | 18 +++++++++--------- source/games/duke/src/dukeactor.h | 14 +++----------- 3 files changed, 22 insertions(+), 30 deletions(-) diff --git a/source/games/duke/src/actors_d.cpp b/source/games/duke/src/actors_d.cpp index 0fffb939f..1f6053b7e 100644 --- a/source/games/duke/src/actors_d.cpp +++ b/source/games/duke/src/actors_d.cpp @@ -436,14 +436,14 @@ void hitradius_d(DDukeActor* actor, int r, int hp1, int hp2, int hp3, int h //--------------------------------------------------------------------------- -int movesprite_ex_d(DDukeActor* actor, int xchange, int ychange, int zchange, unsigned int cliptype, Collision &result) +int movesprite_ex_d(DDukeActor* actor, const DVector3& change, unsigned int cliptype, Collision &result) { int clipdist; int bg = badguy(actor); if (actor->spr.statnum == STAT_MISC || (bg && actor->spr.xrepeat < 4)) { - actor->add_int_pos({ (xchange * TICSPERFRAME) >> 2, (ychange * TICSPERFRAME) >> 2, (zchange * TICSPERFRAME) >> 2 }); + actor->spr.pos += change; if (bg) SetActor(actor, actor->spr.pos); return result.setNone(); @@ -457,7 +457,7 @@ int movesprite_ex_d(DDukeActor* actor, int xchange, int ychange, int zchange, un if (bg) { if (actor->spr.xrepeat > 60) - clipmove(ppos, &dasectp, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), 1024, (4 << 8), (4 << 8), cliptype, result); + clipmove(ppos, &dasectp, FloatToFixed<18>(change.X * 0.5), FloatToFixed<18>(change.Y * 0.5), 1024, (4 << 8), (4 << 8), cliptype, result); else { if (actor->spr.picnum == LIZMAN) @@ -467,7 +467,7 @@ int movesprite_ex_d(DDukeActor* actor, int xchange, int ychange, int zchange, un else clipdist = 192; - clipmove(ppos, &dasectp, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), clipdist, (4 << 8), (4 << 8), cliptype, result); + clipmove(ppos, &dasectp, FloatToFixed<18>(change.X * 0.5), FloatToFixed<18>(change.Y * 0.5), clipdist, (4 << 8), (4 << 8), cliptype, result); } // conditional code from hell... @@ -480,28 +480,28 @@ int movesprite_ex_d(DDukeActor* actor, int xchange, int ychange, int zchange, un ) { if (dasectp && dasectp->lotag == ST_1_ABOVE_WATER && actor->spr.picnum == LIZMAN) - actor->set_int_ang((krand()&2047)); + actor->spr.angle = randomAngle(); else if ((actor->temp_data[0]&3) == 1 && actor->spr.picnum != COMMANDER) - actor->set_int_ang((krand()&2047)); + actor->spr.angle = randomAngle(); SetActor(actor,actor->spr.pos); if (dasectp == nullptr) dasectp = §or[0]; return result.setSector(dasectp); } - if ((result.type == kHitWall || result.type == kHitSprite) && (actor->cgg == 0)) actor->add_int_ang(768); + if ((result.type == kHitWall || result.type == kHitSprite) && (actor->cgg == 0)) actor->spr.angle += DAngle90 + DAngle45; } else { if (actor->spr.statnum == STAT_PROJECTILE) - clipmove(ppos, &dasectp, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), 8, (4 << 8), (4 << 8), cliptype, result); + clipmove(ppos, &dasectp, FloatToFixed<18>(change.X * 0.5), FloatToFixed<18>(change.Y * 0.5), 8, (4 << 8), (4 << 8), cliptype, result); else - clipmove(ppos, &dasectp, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), (int)(actor->int_clipdist()), (4 << 8), (4 << 8), cliptype, result); + clipmove(ppos, &dasectp, FloatToFixed<18>(change.X * 0.5), FloatToFixed<18>(change.Y * 0.5), (int)(actor->int_clipdist()), (4 << 8), (4 << 8), cliptype, result); } actor->spr.pos.XY() = ppos.XY(); if (dasectp != nullptr && dasectp != actor->sector()) ChangeActorSect(actor, dasectp); - double daz = actor->spr.pos.Z + ((zchange * TICSPERFRAME) >> 3) * zinttoworld; + double daz = actor->spr.pos.Z + change.Z * 0.5; if (daz > actor->ceilingz && daz <= actor->floorz) actor->spr.pos.Z = daz; else if (result.type == kHitNone) diff --git a/source/games/duke/src/actors_r.cpp b/source/games/duke/src/actors_r.cpp index fe65aa5d5..2a6bb816e 100644 --- a/source/games/duke/src/actors_r.cpp +++ b/source/games/duke/src/actors_r.cpp @@ -364,14 +364,14 @@ void hitradius_r(DDukeActor* actor, int r, int hp1, int hp2, int hp3, int h // //--------------------------------------------------------------------------- -int movesprite_ex_r(DDukeActor* actor, int xchange, int ychange, int zchange, unsigned int cliptype, Collision &result) +int movesprite_ex_r(DDukeActor* actor, const DVector3& change, unsigned int cliptype, Collision &result) { int clipdist; int bg = badguy(actor); if (actor->spr.statnum == 5 || (bg && actor->spr.xrepeat < 4)) { - actor->add_int_pos({ (xchange * TICSPERFRAME) >> 2, (ychange * TICSPERFRAME) >> 2, (zchange * TICSPERFRAME) >> 2 }); + actor->spr.pos += change; if (bg) SetActor(actor, actor->spr.pos); return result.setNone(); @@ -385,19 +385,19 @@ int movesprite_ex_r(DDukeActor* actor, int xchange, int ychange, int zchange, un if (bg) { if (actor->spr.xrepeat > 60) - clipmove(ppos, &dasectp, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), 1024, (4 << 8), (4 << 8), cliptype, result); + clipmove(ppos, &dasectp, FloatToFixed<18>(change.X * 0.5), FloatToFixed<18>(change.Y * 0.5), 1024, (4 << 8), (4 << 8), cliptype, result); else { clipdist = 192; - clipmove(ppos, &dasectp, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), clipdist, (4 << 8), (4 << 8), cliptype, result); + clipmove(ppos, &dasectp, FloatToFixed<18>(change.X * 0.5), FloatToFixed<18>(change.Y * 0.5), clipdist, (4 << 8), (4 << 8), cliptype, result); } if (dasectp == nullptr || (dasectp != nullptr && actor->actorstayput != nullptr && actor->actorstayput != dasectp)) { if (dasectp && dasectp->lotag == ST_1_ABOVE_WATER) - actor->set_int_ang((krand() & 2047)); + actor->spr.angle = randomAngle(); else if ((actor->temp_data[0] & 3) == 1) - actor->set_int_ang((krand() & 2047)); + actor->spr.angle = randomAngle(); SetActor(actor, actor->spr.pos); if (dasectp == nullptr) dasectp = §or[0]; return result.setSector(dasectp); @@ -407,16 +407,16 @@ int movesprite_ex_r(DDukeActor* actor, int xchange, int ychange, int zchange, un else { if (actor->spr.statnum == STAT_PROJECTILE) - clipmove(ppos, &dasectp, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), 8, (4 << 8), (4 << 8), cliptype, result); + clipmove(ppos, &dasectp, FloatToFixed<18>(change.X * 0.5), FloatToFixed<18>(change.Y * 0.5), 8, (4 << 8), (4 << 8), cliptype, result); else - clipmove(ppos, &dasectp, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), 128, (4 << 8), (4 << 8), cliptype, result); + clipmove(ppos, &dasectp, FloatToFixed<18>(change.X * 0.5), FloatToFixed<18>(change.Y * 0.5), (int)(actor->int_clipdist()), (4 << 8), (4 << 8), cliptype, result); } actor->spr.pos.XY() = ppos.XY(); if (dasectp) if ((dasectp != actor->sector())) ChangeActorSect(actor, dasectp); - double daz = actor->spr.pos.Z + ((zchange * TICSPERFRAME) >> 3) * zinttoworld; + double daz = actor->spr.pos.Z + change.Z * 0.5; if (daz > actor->ceilingz && daz <= actor->floorz) actor->spr.pos.Z = daz; else if (result.type == kHitNone) diff --git a/source/games/duke/src/dukeactor.h b/source/games/duke/src/dukeactor.h index 157a03287..28bea92d0 100644 --- a/source/games/duke/src/dukeactor.h +++ b/source/games/duke/src/dukeactor.h @@ -33,21 +33,13 @@ inline int bossguy(DDukeActor* pSprite) // old interface versions of already changed functions -int movesprite_ex_d(DDukeActor* actor, int xchange, int ychange, int zchange, unsigned int cliptype, Collision& result); -int movesprite_ex_r(DDukeActor* actor, int xchange, int ychange, int zchange, unsigned int cliptype, Collision& result); - -/* -inline int movesprite_ex(DDukeActor* actor, int xchange, int ychange, int zchange, unsigned int cliptype, Collision& result) -{ - auto f = isRR() ? movesprite_ex_r : movesprite_ex_d; - return f(actor, xchange, ychange, zchange, cliptype, result); -} - */ +int movesprite_ex_d(DDukeActor* actor, const DVector3& change, unsigned int cliptype, Collision& result); +int movesprite_ex_r(DDukeActor* actor, const DVector3& change, unsigned int cliptype, Collision& result); inline int movesprite_ex(DDukeActor* actor, const DVector3& change, unsigned int cliptype, Collision& result) { auto f = isRR() ? movesprite_ex_r : movesprite_ex_d; - return f(actor, change.X * worldtoint, change.Y * worldtoint, change.Z * zworldtoint, cliptype, result); + return f(actor, change, cliptype, result); }