diff --git a/src/d_main.cpp b/src/d_main.cpp index 2853cceb3..65458d7a9 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -754,9 +754,15 @@ void D_Display () Level->HasDynamicLights = !!level.lights; } else Level->HasDynamicLights = false; // lights are off so effectively we have none. + Level->interpolator.DoInterpolations(I_GetTimeFrac()); } - viewsec = screen->RenderView(&players[consoleplayer]); + + for (auto Level : AllLevels()) + { + Level->interpolator.RestoreInterpolations(); + } + screen->Begin2D(); screen->DrawBlend(viewsec); if (automapactive) diff --git a/src/dobjgc.cpp b/src/dobjgc.cpp index 169baf32c..5f0a995c0 100644 --- a/src/dobjgc.cpp +++ b/src/dobjgc.cpp @@ -331,7 +331,6 @@ static void MarkRoot() SectorMarker->SecNum = 0; } Mark(SectorMarker); - Mark(interpolator.Head); // Mark bot stuff. Mark(bglobal.firstthing); Mark(bglobal.body1); diff --git a/src/g_level.cpp b/src/g_level.cpp index 581ff9b34..51367df8e 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -1983,6 +1983,7 @@ void FLevelLocals::Mark() GC::Mark(FraggleScriptThinker); GC::Mark(ACSThinker); GC::Mark(automap); + GC::Mark(interpolator.Head); canvasTextureInfo.Mark(); for (auto &c : CorpseQueue) { diff --git a/src/g_levellocals.h b/src/g_levellocals.h index f95b38f5c..38d424868 100644 --- a/src/g_levellocals.h +++ b/src/g_levellocals.h @@ -50,6 +50,7 @@ #include "p_destructible.h" #include "r_data/r_sections.h" #include "r_data/r_canvastexture.h" +#include "r_data/r_interpolate.h" //============================================================================ // @@ -442,6 +443,7 @@ public: FString F1Pic; EMapType maptype; FTagManager tagManager; + FInterpolator interpolator; uint64_t ShaderStartTime = 0; // tell the shader system when we started the level (forces a timer restart) diff --git a/src/gl/renderer/gl_scene.cpp b/src/gl/renderer/gl_scene.cpp index 52c461288..8e6475c96 100644 --- a/src/gl/renderer/gl_scene.cpp +++ b/src/gl/renderer/gl_scene.cpp @@ -218,7 +218,6 @@ sector_t * FGLRenderer::RenderViewpoint (FRenderViewpoint &mainvp, AActor * came mBuffers->BlitToEyeTexture(eye_ix); } - interpolator.RestoreInterpolations (); return mainvp.sector; } diff --git a/src/p_saveg.cpp b/src/p_saveg.cpp index a1d68b235..593aacb38 100644 --- a/src/p_saveg.cpp +++ b/src/p_saveg.cpp @@ -962,9 +962,10 @@ void FLevelLocals::Serialize(FSerializer &arc, bool hubload) ("spotstate", SpotState) ("fragglethinker", FraggleScriptThinker) ("acsthinker", ACSThinker) - ("impactdecalcount", ImpactDecalCount) + ("impactdecalcount", ImpactDecalCount) ("scrolls", Scrolls) - ("automap", automap); + ("automap", automap) + ("interpolator", interpolator); // Hub transitions must keep the current total time diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 405892c35..bef044331 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -288,6 +288,7 @@ void FLevelLocals::ClearLevelData() } ClearPortals(); + interpolator.ClearInterpolations(); // [RH] Nothing to interpolate on a fresh level. tagManager.Clear(); ClearTIDHashes(); Behaviors.UnloadModules(); @@ -350,7 +351,6 @@ void P_FreeLevelData () R_FreePastViewers(); P_ClearUDMFKeys(); - interpolator.ClearInterpolations(); // [RH] Nothing to interpolate on a fresh level. SN_StopAllSequences (); DThinker::DestroyAllThinkers (); diff --git a/src/p_tick.cpp b/src/p_tick.cpp index 562184edb..1fc66dda2 100644 --- a/src/p_tick.cpp +++ b/src/p_tick.cpp @@ -75,7 +75,10 @@ void P_Ticker (void) { int i; - interpolator.UpdateInterpolations (); + for (auto Level : AllLevels()) + { + Level->interpolator.UpdateInterpolations(); + } r_NoInterpolate = true; if (!demoplayback) diff --git a/src/polyrenderer/poly_renderer.cpp b/src/polyrenderer/poly_renderer.cpp index 87642d831..338def63a 100644 --- a/src/polyrenderer/poly_renderer.cpp +++ b/src/polyrenderer/poly_renderer.cpp @@ -188,7 +188,6 @@ void PolyRenderer::RenderActorView(AActor *actor, bool dontmaplines) if (Viewpoint.camera) Viewpoint.camera->renderflags = savedflags; - interpolator.RestoreInterpolations (); NetUpdate(); } diff --git a/src/r_data/r_interpolate.cpp b/src/r_data/r_interpolate.cpp index 70cf09393..b3a8e08b2 100644 --- a/src/r_data/r_interpolate.cpp +++ b/src/r_data/r_interpolate.cpp @@ -39,6 +39,7 @@ #include "p_local.h" #include "po_man.h" #include "serializer.h" +#include "g_levellocals.h" //========================================================================== // @@ -312,6 +313,16 @@ void FInterpolator::ClearInterpolations() } } +FSerializer &Serialize(FSerializer &arc, const char *key, FInterpolator &rs, FInterpolator *def) +{ + if (arc.BeginObject(key)) + { + arc("head", rs.Head) + ("count", rs.count) + .EndObject(); + } + return arc; +} //========================================================================== // @@ -379,10 +390,6 @@ void DInterpolation::Serialize(FSerializer &arc) { Super::Serialize(arc); arc("refcount", refcount); - if (arc.isReading()) - { - interpolator.AddInterpolation(this); - } } //========================================================================== @@ -408,7 +415,7 @@ DSectorPlaneInterpolation::DSectorPlaneInterpolation(sector_t *_sector, bool _pl P_Start3dMidtexInterpolations(attached, sector, ceiling); P_StartLinkedSectorInterpolations(attached, sector, ceiling); } - interpolator.AddInterpolation(this); + sector->Level->interpolator.AddInterpolation(this); } //========================================================================== @@ -567,7 +574,7 @@ DSectorScrollInterpolation::DSectorScrollInterpolation(sector_t *_sector, bool _ sector = _sector; ceiling = _plane; UpdateInterpolation (); - interpolator.AddInterpolation(this); + sector->Level->interpolator.AddInterpolation(this); } //========================================================================== @@ -672,7 +679,7 @@ DWallScrollInterpolation::DWallScrollInterpolation(side_t *_side, int _part) side = _side; part = _part; UpdateInterpolation (); - interpolator.AddInterpolation(this); + side->GetLevel()->interpolator.AddInterpolation(this); } //========================================================================== @@ -770,7 +777,7 @@ DPolyobjInterpolation::DPolyobjInterpolation(FPolyObj *po) oldverts.Resize(po->Vertices.Size() << 1); bakverts.Resize(po->Vertices.Size() << 1); UpdateInterpolation (); - interpolator.AddInterpolation(this); + po->Level->interpolator.AddInterpolation(this); } //========================================================================== diff --git a/src/r_data/r_interpolate.h b/src/r_data/r_interpolate.h index dabfa3a1e..0696bf85f 100644 --- a/src/r_data/r_interpolate.h +++ b/src/r_data/r_interpolate.h @@ -43,19 +43,13 @@ public: struct FInterpolator { - TObjPtr Head; - bool didInterp; - int count; + TObjPtr Head = nullptr; + bool didInterp = false; + int count = 0; int CountInterpolations (); public: - FInterpolator() - { - Head = nullptr; - didInterp = false; - count = 0; - } void UpdateInterpolations(); void AddInterpolation(DInterpolation *); void RemoveInterpolation(DInterpolation *); @@ -64,9 +58,6 @@ public: void ClearInterpolations(); }; -extern FInterpolator interpolator; - - #endif diff --git a/src/r_utility.cpp b/src/r_utility.cpp index 9a6f675cb..89a631712 100644 --- a/src/r_utility.cpp +++ b/src/r_utility.cpp @@ -854,8 +854,6 @@ void R_SetupFrame (FRenderViewpoint &viewpoint, FViewWindow &viewwindow, AActor viewpoint.SetViewAngle (viewwindow); - interpolator.DoInterpolations (viewpoint.TicFrac); - // Keep the view within the sector's floor and ceiling if (viewpoint.sector->PortalBlocksMovement(sector_t::ceiling)) { diff --git a/src/serializer.h b/src/serializer.h index d7d2a1e1a..2957dbdc7 100644 --- a/src/serializer.h +++ b/src/serializer.h @@ -24,6 +24,7 @@ struct FDoorAnimation; class FSoundID; struct FPolyObj; union FRenderStyle; +struct FInterpolator; inline bool nullcmp(const void *buffer, size_t length) { @@ -202,6 +203,7 @@ FSerializer &Serialize(FSerializer &arc, const char *key, FString &sid, FString FSerializer &Serialize(FSerializer &arc, const char *key, NumericValue &sid, NumericValue *def); FSerializer &Serialize(FSerializer &arc, const char *key, ticcmd_t &sid, ticcmd_t *def); FSerializer &Serialize(FSerializer &arc, const char *key, usercmd_t &cmd, usercmd_t *def); +FSerializer &Serialize(FSerializer &arc, const char *key, FInterpolator &rs, FInterpolator *def); template FSerializer &Serialize(FSerializer &arc, const char *key, T *&value, T **) diff --git a/src/swrenderer/scene/r_scene.cpp b/src/swrenderer/scene/r_scene.cpp index 0678607a2..02bd00755 100644 --- a/src/swrenderer/scene/r_scene.cpp +++ b/src/swrenderer/scene/r_scene.cpp @@ -189,7 +189,6 @@ namespace swrenderer RenderPSprites(); MainThread()->Viewport->viewpoint.camera->renderflags = savedflags; - interpolator.RestoreInterpolations(); } void RenderScene::RenderPSprites()