From abd6275f17a19707163f31a3fefd56b7f5e266f9 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Mon, 21 Nov 2022 14:53:52 +1100 Subject: [PATCH] - Add new double `DCoreActor::viewzoffset` set in spawning code during level loads. * Interpolated backup copy isn't needed for Duke, but will be for SW. --- source/core/coreactor.h | 3 +++ source/core/savegamehelp.cpp | 9 +++++++-- source/core/vmexports.cpp | 1 + source/games/duke/src/premap.cpp | 5 ++++- wadsrc/static/zscript/coreactor.zs | 1 + 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/source/core/coreactor.h b/source/core/coreactor.h index bec88ea60..3c8202ba1 100644 --- a/source/core/coreactor.h +++ b/source/core/coreactor.h @@ -44,6 +44,7 @@ public: DVector3 opos; DAngle oang; DVector3 vel; + double oviewzoffset, viewzoffset; double clipdist; int time; @@ -113,6 +114,7 @@ public: void backupz() { opos.Z = spr.pos.Z; + oviewzoffset = viewzoffset; } void backupvec2() @@ -123,6 +125,7 @@ public: void backuppos() { opos = spr.pos; + oviewzoffset = viewzoffset; } void backupang() diff --git a/source/core/savegamehelp.cpp b/source/core/savegamehelp.cpp index 7bbc48761..96fc6615f 100644 --- a/source/core/savegamehelp.cpp +++ b/source/core/savegamehelp.cpp @@ -627,9 +627,14 @@ void DCoreActor::Serialize(FSerializer& arc) ("spriteext", sprext) ("xvel", vel.X) ("yvel", vel.Y) - ("zvel", vel.Z); + ("zvel", vel.Z) + ("viewzoffset", viewzoffset); - if (arc.isReading()) spsmooth = {}; + if (arc.isReading()) + { + spsmooth = {}; + backuppos(); + } } diff --git a/source/core/vmexports.cpp b/source/core/vmexports.cpp index 43ef4f383..67383b5dc 100644 --- a/source/core/vmexports.cpp +++ b/source/core/vmexports.cpp @@ -619,6 +619,7 @@ DEFINE_FIELD_NAMED(DCoreActor, time, spawnindex) DEFINE_FIELD(DCoreActor, spritesetindex) DEFINE_FIELD_NAMED(DCoreActor, spr.angle, angle) DEFINE_FIELD(DCoreActor, vel) +DEFINE_FIELD(DCoreActor, viewzoffset) void coreactor_setpos(DCoreActor* self, double x, double y, double z, int relink) { diff --git a/source/games/duke/src/premap.cpp b/source/games/duke/src/premap.cpp index 61dd1a733..1f1df86cd 100644 --- a/source/games/duke/src/premap.cpp +++ b/source/games/duke/src/premap.cpp @@ -512,9 +512,12 @@ void resetpspritevars(int g) int aimmode[MAXPLAYERS]; STATUSBARTYPE tsbar[MAXPLAYERS]; - CreateActor(ps[0].cursector, ps[0].posGet(), + auto newActor = CreateActor(ps[0].cursector, ps[0].posGet(), TILE_APLAYER, 0, DVector2(0, 0), ps[0].angle.ang, 0., 0., nullptr, 10); + newActor->viewzoffset = -gs.playerheight; + newActor->backupz(); + if (ud.recstat != 2) for (i = 0; i < MAXPLAYERS; i++) { aimmode[i] = ps[i].aim_mode; diff --git a/wadsrc/static/zscript/coreactor.zs b/wadsrc/static/zscript/coreactor.zs index 6c3216b79..424c1a3eb 100644 --- a/wadsrc/static/zscript/coreactor.zs +++ b/wadsrc/static/zscript/coreactor.zs @@ -45,6 +45,7 @@ class CoreActor native native double clipdist; native double angle; native Vector3 vel; + native double viewzoffset; native readonly int16 spritesetindex; native readonly int spawnindex;