From 7745701d4b1261a59d8cfc4f40864e24e1279a26 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 3 Feb 2022 22:06:09 +0100 Subject: [PATCH] - floatified opos. --- source/core/coreactor.h | 64 +++++++++++++++++++++++------- source/games/duke/src/actors.cpp | 2 +- source/games/duke/src/actors_d.cpp | 8 ++-- source/games/duke/src/actors_r.cpp | 4 +- source/games/sw/src/player.cpp | 4 +- source/games/sw/src/sprite.cpp | 18 +++++---- source/games/sw/src/track.cpp | 2 +- 7 files changed, 71 insertions(+), 31 deletions(-) diff --git a/source/core/coreactor.h b/source/core/coreactor.h index 594c0c443..5b27fbc75 100644 --- a/source/core/coreactor.h +++ b/source/core/coreactor.h @@ -41,7 +41,7 @@ public: spriteext_t sprext; spritesmooth_t spsmooth; - vec3_t opos; + DVector3 opos; int time; int16_t oang; int16_t spritesetindex; @@ -129,27 +129,62 @@ public: return { spr.pos.X, -spr.pos.Y, -spr.pos.Z }; } + double interpolatedx(double const smoothratio, int const scale = 16) + { + return interpolatedvaluef(opos.X, spr.pos.X, smoothratio, scale); + } + + double interpolatedy(double const smoothratio, int const scale = 16) + { + return interpolatedvaluef(opos.Y, spr.pos.Y, smoothratio, scale); + } + + double interpolatedz(double const smoothratio, int const scale = 16) + { + return interpolatedvalue(opos.Z, spr.pos.Z, smoothratio, scale); + } + + DVector2 interpolatedvec2(double const smoothratio, int const scale = 16) + { + return + { + interpolatedx(smoothratio, scale), + interpolatedy(smoothratio, scale) + }; + } + + DVector3 interpolatedvec3(double const smoothratio, int const scale = 16) + { + return + { + interpolatedx(smoothratio, scale), + interpolatedy(smoothratio, scale), + interpolatedz(smoothratio, scale) + }; + } + + int32_t __interpolatedx(double const smoothratio, int const scale = 16) { - return interpolatedvalue(opos.X, spr.int_pos().X, smoothratio, scale); + return interpolatedx(smoothratio, scale) * worldtoint; } int32_t __interpolatedy(double const smoothratio, int const scale = 16) { - return interpolatedvalue(opos.Y, spr.int_pos().Y, smoothratio, scale); + return interpolatedy(smoothratio, scale) * worldtoint; } int32_t __interpolatedz(double const smoothratio, int const scale = 16) { - return interpolatedvalue(opos.Z, spr.int_pos().Z, smoothratio, scale); + return interpolatedz(smoothratio, scale) * zworldtoint; } vec2_t __interpolatedvec2(double const smoothratio, int const scale = 16) { return { - __interpolatedx(smoothratio, scale), - __interpolatedy(smoothratio, scale) + (int)(interpolatedx(smoothratio, scale) * worldtoint), + (int)(interpolatedy(smoothratio, scale) * worldtoint) }; } @@ -157,9 +192,9 @@ public: { return { - __interpolatedx(smoothratio, scale), - __interpolatedy(smoothratio, scale), - __interpolatedz(smoothratio, scale) + (int)(interpolatedx(smoothratio, scale)* worldtoint), + (int)(interpolatedy(smoothratio, scale)* worldtoint), + (int)(interpolatedz(smoothratio, scale)* zworldtoint) }; } @@ -171,27 +206,28 @@ public: void backupx() { - opos.X = spr.int_pos().X; + opos.X = spr.pos.X; } void backupy() { - opos.Y = spr.int_pos().Y; + opos.Y = spr.pos.Y; } void backupz() { - opos.Z = spr.int_pos().Z; + opos.Z = spr.pos.Z; } void backupvec2() { - opos.vec2 = spr.int_pos().vec2; + backupx(); + backupy(); } void backuppos() { - opos = spr.int_pos(); + opos = spr.pos; } void backupang() diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index 0aefa4c32..f8fd4cb88 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -785,7 +785,7 @@ void movecrane(DDukeActor *actor, int crane) { SetActor(Owner, actor->int_pos()); - Owner->opos = actor->int_pos(); + Owner->opos = actor->spr.pos; actor->spr.zvel = 0; } diff --git a/source/games/duke/src/actors_d.cpp b/source/games/duke/src/actors_d.cpp index 47c3a5196..b3049950d 100644 --- a/source/games/duke/src/actors_d.cpp +++ b/source/games/duke/src/actors_d.cpp @@ -1585,7 +1585,7 @@ static void weaponcommon_d(DDukeActor* proj) if (spawned) { - spawned->opos = proj->opos + offset; + spawned->opos = proj->opos + DVector3(offset.X * inttoworld, offset.Y * inttoworld, offset.Z * zinttoworld); spawned->spr.cstat = CSTAT_SPRITE_YCENTER; spawned->spr.pal = proj->spr.pal; } @@ -1837,7 +1837,7 @@ void movetransports_d(void) ps[p].opos.Z = ps[p].pos.Z; auto pa = ps[p].GetActor(); - pa->opos = ps[p].pos; + pa->opos = DVector3(ps[p].pos.X * inttoworld, ps[p].pos.Y * inttoworld, ps[p].pos.Z * zinttoworld); ChangeActorSect(act2, Owner->sector()); ps[p].setCursector(Owner->sector()); @@ -3553,7 +3553,7 @@ void move_d(DDukeActor *actor, int playernum, int xvel) if (actor->temp_data[1] == 0 || a == 0) { - if ((badguy(actor) && actor->spr.extra <= 0) || (actor->opos.X != actor->int_pos().X) || (actor->opos.Y != actor->int_pos().Y)) + if ((badguy(actor) && actor->spr.extra <= 0) || (actor->opos.X != actor->spr.pos.X) || (actor->opos.Y != actor->spr.pos.Y)) { actor->backupvec2(); SetActor(actor, actor->int_pos()); @@ -3662,7 +3662,7 @@ void move_d(DDukeActor *actor, int playernum, int xvel) { if (!*(moveptr + 1)) { - if (actor->opos.Z != actor->int_pos().Z || (ud.multimode < 2 && ud.player_skill < 2)) + if (actor->opos.Z != actor->spr.pos.Z || (ud.multimode < 2 && ud.player_skill < 2)) { if ((actor->temp_data[0] & 1) || ps[playernum].actorsqu == actor) return; else daxvel <<= 1; diff --git a/source/games/duke/src/actors_r.cpp b/source/games/duke/src/actors_r.cpp index 577f79260..f7af27011 100644 --- a/source/games/duke/src/actors_r.cpp +++ b/source/games/duke/src/actors_r.cpp @@ -3592,7 +3592,7 @@ void move_r(DDukeActor *actor, int pnum, int xvel) if (actor->temp_data[1] == 0 || a == 0) { - if ((badguy(actor) && actor->spr.extra <= 0) || (actor->opos.X != actor->int_pos().X) || (actor->opos.Y != actor->int_pos().Y)) + if ((badguy(actor) && actor->spr.extra <= 0) || (actor->opos.X != actor->spr.pos.X) || (actor->opos.Y != actor->spr.pos.Y)) { actor->backupvec2(); SetActor(actor, actor->int_pos()); @@ -3707,7 +3707,7 @@ void move_r(DDukeActor *actor, int pnum, int xvel) { if (!*(moveptr + 1)) { - if (actor->opos.Z != actor->int_pos().Z || (ud.multimode < 2 && ud.player_skill < 2)) + if (actor->opos.Z != actor->spr.pos.Z || (ud.multimode < 2 && ud.player_skill < 2)) { if ((actor->temp_data[0] & 1) || ps[pnum].actorsqu == actor) return; else daxvel <<= 1; diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index 4560803ee..278ac1efd 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -6402,7 +6402,7 @@ void MoveSkipSavePos(void) { if (!actor->hasU()) continue; actor->backuppos(); - actor->user.oz = actor->opos.Z; + actor->user.oz = actor->opos.Z * zworldtoint; } } } @@ -6419,7 +6419,7 @@ void MoveSkipSavePos(void) { if (!actor->hasU()) continue; actor->backuppos(); - actor->user.oz = actor->opos.Z; + actor->user.oz = actor->opos.Z * zworldtoint; } } } diff --git a/source/games/sw/src/sprite.cpp b/source/games/sw/src/sprite.cpp index 39ae04848..9b812ea30 100644 --- a/source/games/sw/src/sprite.cpp +++ b/source/games/sw/src/sprite.cpp @@ -850,7 +850,7 @@ void SpawnUser(DSWActor* actor, short id, STATE* state) actor->user.motion_blur_dist = 256; actor->backuppos(); - actor->user.oz = actor->opos.Z; + actor->user.oz = actor->opos.Z * zworldtoint; actor->user.active_range = MIN_ACTIVE_RANGE; @@ -2059,7 +2059,8 @@ void SpriteSetup(void) } // set orig z - actor->user.oz = actor->opos.Z = sectp->int_floorz(); + actor->opos.Z = sectp->floorz; + actor->user.oz = actor->opos.Z * zworldtoint; } else { @@ -2079,7 +2080,8 @@ void SpriteSetup(void) } // set orig z - actor->user.oz = actor->opos.Z = sectp->int_ceilingz(); + actor->opos.Z = sectp->ceilingz; + actor->user.oz = actor->opos.Z * zworldtoint; } @@ -2261,7 +2263,8 @@ void SpriteSetup(void) } // set orig z - actor->user.oz = actor->opos.Z = actor->user.zclip; + actor->user.oz = actor->user.zclip; + actor->opos.Z = actor->user.oz * zinttoworld; } else { @@ -2279,7 +2282,8 @@ void SpriteSetup(void) } // set orig z - actor->user.oz = actor->opos.Z = actor->user.zclip; + actor->user.oz = actor->user.zclip; + actor->opos.Z = actor->user.oz * zinttoworld; } change_actor_stat(actor, STAT_SPIKE); @@ -6329,7 +6333,7 @@ Collision move_sprite(DSWActor* actor, int xchange, int ychange, int zchange, in void MissileWarpUpdatePos(DSWActor* actor, sectortype* sect) { actor->backuppos(); - actor->user.oz = actor->opos.Z; + actor->user.oz = actor->opos.Z * zworldtoint; ChangeActorSect(actor, sect); MissileZrange(actor); } @@ -6337,7 +6341,7 @@ void MissileWarpUpdatePos(DSWActor* actor, sectortype* sect) void ActorWarpUpdatePos(DSWActor* actor, sectortype* sect) { actor->backuppos(); - actor->user.oz = actor->opos.Z; + actor->user.oz = actor->opos.Z * zworldtoint; ChangeActorSect(actor, sect); DoActorZrange(actor); } diff --git a/source/games/sw/src/track.cpp b/source/games/sw/src/track.cpp index 621bf7515..8da6eba11 100644 --- a/source/games/sw/src/track.cpp +++ b/source/games/sw/src/track.cpp @@ -832,7 +832,7 @@ void SectorObjectSetupBounds(SECTOR_OBJECT* sop) itActor->user.RotNum = 0; itActor->backuppos(); - itActor->user.oz = itActor->opos.Z; + itActor->user.oz = itActor->opos.Z * zworldtoint; switch (itActor->spr.statnum) {