Permalink
Browse files

- moved interpolator into FLevelLocals.

- redid P_Ticker. This function is a messy affair of mixing per-level and per-session actions which all depend on proper ordering. As a result it has to run 3 ForAllLevels iterators to ensure that the order does not change.
  • Loading branch information...
coelckers committed Jan 9, 2019
1 parent 45a4bc8 commit c19e1ff5d76fb82c6322afb8ffc7698bff0527ab
@@ -330,7 +330,6 @@ static void MarkRoot()
SectorMarker->SecNum = 0;
}
Mark(SectorMarker);
Mark(interpolator.Head);
// Mark bot stuff.
Mark(bglobal.firstthing);
Mark(bglobal.body1);
@@ -1976,6 +1976,7 @@ void FLevelLocals::Mark()
GC::Mark(SpotState);
GC::Mark(FraggleScriptThinker);
GC::Mark(ACSThinker);
GC::Mark(interpolator.Head);
canvasTextureInfo.Mark();
for (auto &c : CorpseQueue)
{
@@ -46,6 +46,7 @@
#include "p_acs.h"
#include "p_tags.h"
#include "p_destructible.h"
#include "r_data/r_interpolate.h"
#include "r_data/r_sections.h"
#include "r_data/r_canvastexture.h"

@@ -221,6 +222,7 @@ struct FLevelLocals : public FLevelData
uint8_t freeze; //Game in freeze mode.
uint8_t changefreeze; //Game wants to change freeze mode.

FInterpolator interpolator;

TArray<DVector2> Scrolls; // NULL if no DScrollers in this level

@@ -217,7 +217,11 @@ sector_t * FGLRenderer::RenderViewpoint (FRenderViewpoint &mainvp, AActor * came
mBuffers->BlitToEyeTexture(eye_ix);
}

interpolator.RestoreInterpolations ();
// Restore interpolations for all levels.
ForAllLevels([](FLevelLocals *Level)
{
Level->interpolator.RestoreInterpolations();
});
return mainvp.sector;
}

@@ -950,7 +950,7 @@ void G_SerializeLevel(FSerializer &arc, FLevelLocals *Level, bool hubload)
if (arc.isReading())
{
DThinker::DestroyAllThinkers();
interpolator.ClearInterpolations();
Level->interpolator.ClearInterpolations();
arc.ReadObjects(hubload);
}

@@ -272,6 +272,10 @@ void FLevelLocals::ClearLevelData()
DialogueRoots.Clear();
ClassRoots.Clear();

level.interpolator.ClearInterpolations(); // [RH] Nothing to interpolate on a fresh level.
level.ClearAllSubsectorLinks(); // can't be done as part of the polyobj deletion process.
DThinker::DestroyAllThinkers();

// delete allocated data in the level arrays.
if (sectors.Size() > 0)
{
@@ -348,11 +352,7 @@ void P_FreeLevelData ()
R_FreePastViewers();
P_ClearUDMFKeys();


interpolator.ClearInterpolations(); // [RH] Nothing to interpolate on a fresh level.
level.ClearAllSubsectorLinks(); // can't be done as part of the polyobj deletion process.
SN_StopAllSequences ();
DThinker::DestroyAllThinkers ();

level.ClearLevelData();
}
@@ -71,94 +71,93 @@ bool P_CheckTickerPaused ()
//
// P_Ticker
//
// (split up to prepare for running multiple levels.)
//
void P_Ticker (void)
{
int i;

// This must be done before the pause check
ForAllLevels([](FLevelLocals *Level)
{
Level->interpolator.UpdateInterpolations();
});

r_NoInterpolate = true;

// run the tic
if (paused || P_CheckTickerPaused())
return;
level.Tick();

DPSprite::NewTick();

// [BC] Do a quick check to see if anyone has the freeze time power. If they do,
// then don't resume the sound, since one of the effects of that power is to shut
// off the music.
for (i = 0; i < MAXPLAYERS; i++ )
for (i = 0; i < MAXPLAYERS; i++)
{
if (playeringame[i] && players[i].timefreezer != 0)
break;
}

if ( i == MAXPLAYERS )
S_ResumeSound (false);

}

void FLevelLocals::Tick()
{
// run the tic
if (i == MAXPLAYERS)
S_ResumeSound(false);

P_ResetSightCounters(false);
R_ClearInterpolationPath();

interpolator.UpdateInterpolations ();
r_NoInterpolate = true;

DPSprite::NewTick();

// [RH] Frozen mode is only changed every 4 tics, to make it work with A_Tracer().
if ((maptime & 3) == 0)
ForAllLevels([](FLevelLocals *Level)
{
if (changefreeze)
// [RH] Frozen mode is only changed every 4 tics, to make it work with A_Tracer().
if ((Level->time & 3) == 0)
{
freeze ^= 1;
changefreeze = 0;
if (Level->changefreeze)
{
Level->freeze ^= 1;
Level->changefreeze = 0;
}
}
}

// Reset all actor interpolations for all actors before the current thinking turn so that indirect actor movement gets properly interpolated.
TThinkerIterator<AActor> it;
AActor *ac;

P_ResetSightCounters (false);
R_ClearInterpolationPath();
while ((ac = it.Next()))
{
ac->ClearInterpolation();
}

// Reset all actor interpolations for all actors before the current thinking turn so that indirect actor movement gets properly interpolated.
TThinkerIterator<AActor> it;
AActor *ac;
P_ThinkParticles(); // [RH] make the particles think
});

while ((ac = it.Next()))
for (int i = 0; i < MAXPLAYERS; i++)
{
ac->ClearInterpolation();
if (playeringame[i]) P_PlayerThink(&players[i]);
}

// Since things will be moving, it's okay to interpolate them in the renderer.
r_NoInterpolate = false;

P_ThinkParticles(); // [RH] make the particles think

for (int i = 0; i<MAXPLAYERS; i++)
if (playeringame[i] &&
/*Added by MC: Freeze mode.*/!(freeze && players[i].Bot != NULL))
P_PlayerThink (&players[i]);

// [ZZ] call the WorldTick hook
E_WorldTick();
StatusBar->SetLevel(this);
StatusBar->SetLevel(players[consoleplayer].mo->Level);
StatusBar->CallTick (); // [RH] moved this here
// Reset carry sectors
if (Scrolls.Size() > 0)
{
memset (&Scrolls[0], 0, sizeof(Scrolls[0])*Scrolls.Size());
}
DThinker::RunThinkers ();

//if added by MC: Freeze mode.
if (!freeze && !(flags2 & LEVEL2_FROZEN))
ForAllLevels([](FLevelLocals *Level)
{
P_UpdateSpecials (&level);
P_RunEffects (); // [RH] Run particle effects
}
// Reset carry sectors
if (Level->Scrolls.Size() > 0)
{
memset(&Level->Scrolls[0], 0, sizeof(Level->Scrolls[0]) * Level->Scrolls.Size());
}

DThinker::RunThinkers();

//if added by MC: Freeze mode.
if (!Level->freeze && !(Level->flags2 & LEVEL2_FROZEN))
{
P_UpdateSpecials(Level);
P_RunEffects(); // [RH] Run particle effects
}

// for par times
time++;
maptime++;
totaltime++;
// for par times
Level->time++;
Level->maptime++;
Level->totaltime++;
});
}
@@ -1225,6 +1225,12 @@ void P_PlayerThink (player_t *player)
I_Error ("No player %td start\n", player - players + 1);
}

// Bots do not think in freeze mode.
if (!(player->mo->Level->freeze && player->Bot != nullptr))
{
return;
}

if (debugfile && !(player->cheats & CF_PREDICTING))
{
fprintf (debugfile, "tic %d for pl %d: (%f, %f, %f, %f) b:%02x p:%d y:%d f:%d s:%d u:%d\n",
@@ -188,7 +188,10 @@ void PolyRenderer::RenderActorView(AActor *actor, bool dontmaplines)

if (Viewpoint.camera)
Viewpoint.camera->renderflags = savedflags;
interpolator.RestoreInterpolations ();
ForAllLevels([](FLevelLocals *Level)
{
Level->interpolator.RestoreInterpolations();
});

NetUpdate();
}
Oops, something went wrong.

0 comments on commit c19e1ff

Please sign in to comment.