From ad9931081ef6ef103beb22c3d73599b4aeb65c3b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 9 Aug 2022 00:11:21 +0200 Subject: [PATCH] -fix some bugs, handle occurences in recently changed code --- source/build/src/clip.cpp | 4 +-- source/core/actorlist.cpp | 30 +++++++--------- source/core/coreactor.h | 34 ++++++++++++++++++- source/core/gamefuncs.cpp | 2 +- .../core/rendering/scene/hw_bunchdrawer.cpp | 2 +- source/core/rendering/scene/hw_portal.cpp | 2 +- source/games/exhumed/src/rat.cpp | 4 +-- 7 files changed, 52 insertions(+), 26 deletions(-) diff --git a/source/build/src/clip.cpp b/source/build/src/clip.cpp index eeb48c5ce..d96faac28 100644 --- a/source/build/src/clip.cpp +++ b/source/build/src/clip.cpp @@ -616,7 +616,7 @@ CollisionBase clipmove_(vec3_t * const pos, int * const sectnum, int32_t xvect, case CSTAT_SPRITE_ALIGNMENT_FACING: if (p1.X >= clipMin.X && p1.X <= clipMax.X && p1.Y >= clipMin.Y && p1.Y <= clipMax.Y) { - int32_t height, daz = int_pos().Z + actor->GetOffsetAndHeight(height); + int32_t height, daz = actor->int_pos().Z + actor->GetOffsetAndHeight(height); if (pos->Z > daz-height-flordist && pos->Z < daz+ceildist) { @@ -1166,7 +1166,7 @@ void getzrange(const vec3_t& pos, sectortype* sect, int32_t* ceilz, CollisionBas int32_t k = walldist+(actor->spr.clipdist<<2)+1; if ((abs(v1.X-pos.X) <= k) && (abs(v1.Y-pos.Y) <= k)) { - daz = int_pos().Z + actor->GetOffsetAndHeight(k); + daz = actor->int_pos().Z + actor->GetOffsetAndHeight(k); daz2 = daz - k; clipyou = 1; } diff --git a/source/core/actorlist.cpp b/source/core/actorlist.cpp index a3c15cc8d..7b02226b2 100644 --- a/source/core/actorlist.cpp +++ b/source/core/actorlist.cpp @@ -528,18 +528,18 @@ DEFINE_FIELD_NAMED(DCoreActor, spritesetindex, spritesetpic) DEFINE_ACTION_FUNCTION(DCoreActor, pos) { PARAM_SELF_PROLOGUE(DCoreActor); - ACTION_RETURN_VEC3(DVector3(self->spr.pos.X * (1 / 16.), self->spr.pos.Y * (1 / 16.), self->spr.pos.Z * (1 / 256.))); + ACTION_RETURN_VEC3(self->float_pos()); } DEFINE_ACTION_FUNCTION(DCoreActor, xy) { PARAM_SELF_PROLOGUE(DCoreActor); - ACTION_RETURN_VEC2(DVector2(self->spr.pos.X * (1 / 16.), self->spr.pos.Y * (1 / 16.))); + ACTION_RETURN_VEC2(self->float_pos().XY()); } double coreactor_z(DCoreActor* self) { - return self->spr.zvel * zinttoworld; + return self->float_pos().Z; } DEFINE_ACTION_FUNCTION_NATIVE(DCoreActor, z, coreactor_z) @@ -550,11 +550,9 @@ DEFINE_ACTION_FUNCTION_NATIVE(DCoreActor, z, coreactor_z) void coreactor_setpos(DCoreActor* self, double x, double y, double z, int relink) { - self->spr.pos.X = int(x * worldtoint); - self->spr.pos.Y = int(y * worldtoint); - self->spr.pos.Z = int(z * zworldtoint); + self->set_float_pos({ x, y, z }); // todo: SW needs to call updatesectorz here or have a separate function. - if (relink) SetActor(self, self->spr.pos); + if (relink) SetActor(self, self->int_pos()); } DEFINE_ACTION_FUNCTION_NATIVE(DCoreActor, setpos, coreactor_setpos) @@ -571,9 +569,9 @@ DEFINE_ACTION_FUNCTION_NATIVE(DCoreActor, setpos, coreactor_setpos) void coreactor_copypos(DCoreActor* self, DCoreActor* other, int relink) { if (!other) return; - self->spr.pos = other->spr.pos; + self->copy_pos(other); // todo: SW needs to call updatesectorz here or have a separate function. - if (relink) SetActor(self, self->spr.pos); + if (relink) SetActor(self, self->int_pos()); } DEFINE_ACTION_FUNCTION_NATIVE(DCoreActor, copypos, coreactor_setpos) @@ -587,11 +585,9 @@ DEFINE_ACTION_FUNCTION_NATIVE(DCoreActor, copypos, coreactor_setpos) void coreactor_move(DCoreActor* self, double x, double y, double z, int relink) { - self->spr.pos.X += int(x * 16); - self->spr.pos.Y += int(y * 16); - self->spr.pos.Z += int(z * 256); + self->add_float_pos({ x, y, z }); // todo: SW needs to call updatesectorz here or have a separate function. - if (relink) SetActor(self, self->spr.pos); + if (relink) SetActor(self, self->int_pos()); } DEFINE_ACTION_FUNCTION_NATIVE(DCoreActor, move, coreactor_move) @@ -607,27 +603,27 @@ DEFINE_ACTION_FUNCTION_NATIVE(DCoreActor, move, coreactor_move) void coreactor_setz(DCoreActor* self, double z) { - self->spr.pos.Z = int(z * 256); + self->set_float_z(z); } DEFINE_ACTION_FUNCTION_NATIVE(DCoreActor, setz, coreactor_setz) { PARAM_SELF_PROLOGUE(DCoreActor); PARAM_FLOAT(z); - self->spr.pos.Z = int(z * 256); + self->set_float_z(z); return 0; } void coreactor_addz(DCoreActor* self, double z) { - self->spr.pos.Z += int(z * 256); + self->add_float_z(z); } DEFINE_ACTION_FUNCTION_NATIVE(DCoreActor, addz, coreactor_addz) { PARAM_SELF_PROLOGUE(DCoreActor); PARAM_FLOAT(z); - self->spr.pos.Z = int(z * 256); + self->add_float_z(z); return 0; } diff --git a/source/core/coreactor.h b/source/core/coreactor.h index 5773a7fcc..9a85ae3d9 100644 --- a/source/core/coreactor.h +++ b/source/core/coreactor.h @@ -68,7 +68,12 @@ public: { // This is only identical with the sprite index for items spawned at map start. return time; - } + } + + void copy_pos(const DCoreActor* other) + { + spr.pos = other->spr.pos; + } const vec3_t int_pos() const { @@ -111,6 +116,33 @@ public: { return { spr.pos.X * inttoworld, spr.pos.Y * inttoworld, spr.pos.Z * zinttoworld }; } + + void set_float_pos(const DVector3& pos) + { + spr.pos = { int(pos.X * worldtoint), int(pos.Y * worldtoint), int(pos.Z * zworldtoint) }; + } + + void add_float_pos(const DVector3& pos) + { + spr.pos += { int(pos.X * worldtoint), int(pos.Y * worldtoint), int(pos.Z * zworldtoint) }; + } + + void set_float_z(int z) + { + spr.pos.Z = int(z * zworldtoint); + } + + void add_float_z(int z) + { + spr.pos.Z += int(z * zworldtoint); + } + + + // Same as above but with invertex y and z axes to match the renderer's coordinate system. + DVector3 render_pos() const + { + return { spr.pos.X * inttoworld, -spr.pos.Y * inttoworld, -spr.pos.Z * zinttoworld }; + } int32_t interpolatedx(double const smoothratio, int const scale = 16) { diff --git a/source/core/gamefuncs.cpp b/source/core/gamefuncs.cpp index a8baf40c0..98cb8935f 100644 --- a/source/core/gamefuncs.cpp +++ b/source/core/gamefuncs.cpp @@ -557,7 +557,7 @@ tspritetype* renderAddTsprite(tspriteArray& tsprites, DCoreActor* actor) { auto tspr = tsprites.newTSprite(); - tspr->pos = actor->spr.pos; + tspr->pos = actor->int_pos(); tspr->cstat = actor->spr.cstat; tspr->picnum = actor->spr.picnum; tspr->shade = actor->spr.shade; diff --git a/source/core/rendering/scene/hw_bunchdrawer.cpp b/source/core/rendering/scene/hw_bunchdrawer.cpp index 03c2c57a4..a22c4c452 100644 --- a/source/core/rendering/scene/hw_bunchdrawer.cpp +++ b/source/core/rendering/scene/hw_bunchdrawer.cpp @@ -676,7 +676,7 @@ void BunchDrawer::ProcessSection(int sectionnum, bool portal) if ((actor->spr.cstat & CSTAT_SPRITE_INVISIBLE) || actor->spr.xrepeat == 0 || actor->spr.yrepeat == 0) // skip invisible sprites continue; - int sx = actor->spr.pos.X - iview.X, sy = actor->spr.pos.Y - int(iview.Y); + int sx = actor->int_pos().X - iview.X, sy = actor->int_pos().Y - int(iview.Y); // this checks if the sprite is it behind the camera, which will not work if the pitch is high enough to necessitate a FOV of more than 180°. //if ((actor->spr.cstat & CSTAT_SPRITE_ALIGNMENT_MASK) || (hw_models && tile2model[actor->spr.picnum].modelid >= 0) || ((sx * gcosang) + (sy * gsinang) > 0)) diff --git a/source/core/rendering/scene/hw_portal.cpp b/source/core/rendering/scene/hw_portal.cpp index 64ea9c84d..0d59b5bad 100644 --- a/source/core/rendering/scene/hw_portal.cpp +++ b/source/core/rendering/scene/hw_portal.cpp @@ -670,7 +670,7 @@ bool HWLineToSpritePortal::Setup(HWDrawInfo* di, FRenderState& rstate, Clipper* di->mClipPortal = this; auto srccenter = (WallStart(origin) + WallEnd(origin)) / 2; - DVector2 destcenter ={ camera->spr.pos.X / 16.f, camera->spr.pos.Y / -16.f }; + DVector2 destcenter = camera->render_pos().XY(); DVector2 npos = vp.Pos - srccenter + destcenter; double origx = vp.Pos.X; diff --git a/source/games/exhumed/src/rat.cpp b/source/games/exhumed/src/rat.cpp index b0acb3106..01e9f5f13 100644 --- a/source/games/exhumed/src/rat.cpp +++ b/source/games/exhumed/src/rat.cpp @@ -89,9 +89,7 @@ void BuildRat(DExhumedActor* pActor, int x, int y, int z, sectortype* pSector, i ChangeActorStat(pActor, 108); } - pActor->spr.pos.X = x; - pActor->spr.pos.Y = y; - pActor->spr.pos.Z = z; + pActor->set_int_pos({ x, y, z }); pActor->spr.cstat = CSTAT_SPRITE_BLOCK_ALL; pActor->spr.shade = -12; pActor->spr.xoffset = 0;