Skip to content

Commit

Permalink
- more timer cleanup
Browse files Browse the repository at this point in the history
* store the frame time in the current screen buffer from where all render code can access it.
* replace some uses of I_MSTime with I_FPSTime, because they should not use a per-frame timer. The only one left is the wipe code but even this doesn't look like it needs either a per-frame timer or a timer counting from the start of the playsim.
  • Loading branch information
coelckers committed Nov 12, 2017
1 parent e94109f commit 2c65f08
Show file tree
Hide file tree
Showing 24 changed files with 31 additions and 38 deletions.
4 changes: 2 additions & 2 deletions src/c_bind.cpp
Expand Up @@ -744,8 +744,8 @@ bool C_DoKey (event_t *ev, FKeyBindings *binds, FKeyBindings *doublebinds)
dclick = false;

// This used level.time which didn't work outside a level.
nowtime = I_MSTime();
if (doublebinds != NULL && DClickTime[ev->data1] > nowtime && ev->type == EV_KeyDown)
nowtime = I_FPSTime();
if (doublebinds != NULL && int(DClickTime[ev->data1] - nowtime) > 0 && ev->type == EV_KeyDown)
{
// Key pressed for a double click
binding = doublebinds->GetBinding(ev->data1);
Expand Down
8 changes: 4 additions & 4 deletions src/d_main.cpp
Expand Up @@ -779,9 +779,9 @@ void D_Display ()


{
unsigned int nowtime = I_FPSTime();
TexMan.UpdateAnimations(nowtime);
R_UpdateSky(nowtime);
screen->FrameTime = I_FPSTime();
TexMan.UpdateAnimations(screen->FrameTime);
R_UpdateSky(screen->FrameTime);
switch (gamestate)
{
case GS_FULLCONSOLE:
Expand All @@ -808,7 +808,7 @@ void D_Display ()
// [ZZ] execute event hook that we just started the frame
//E_RenderFrame();
//
Renderer->RenderView(&players[consoleplayer], nowtime);
Renderer->RenderView(&players[consoleplayer]);

if ((hw2d = screen->Begin2D(viewactive)))
{
Expand Down
2 changes: 1 addition & 1 deletion src/d_net.cpp
Expand Up @@ -783,7 +783,7 @@ void GetPackets (void)
// [RH] Get "ping" times - totally useless, since it's bound to the frequency
// packets go out at.
lastrecvtime[netconsole] = currrecvtime[netconsole];
currrecvtime[netconsole] = I_MSTime ();
currrecvtime[netconsole] = I_FPSTime ();

// check for exiting the game
if (netbuffer[0] & NCMD_EXIT)
Expand Down
1 change: 0 additions & 1 deletion src/gl/data/gl_data.cpp
Expand Up @@ -55,7 +55,6 @@
#include "gl/gl_functions.h"

GLRenderSettings glset;
long gl_frameMS;

EXTERN_CVAR(Int, gl_lightmode)
EXTERN_CVAR(Bool, gl_brightfog)
Expand Down
2 changes: 0 additions & 2 deletions src/gl/data/gl_data.h
Expand Up @@ -65,6 +65,4 @@ void gl_InitPortals();
void gl_BuildPortalCoverage(FPortalCoverage *coverage, subsector_t *subsector, const DVector2 &displacement);
void gl_InitData();

extern long gl_frameMS;

#endif
2 changes: 1 addition & 1 deletion src/gl/models/gl_models.cpp
Expand Up @@ -55,7 +55,7 @@

static inline float GetTimeFloat()
{
return (float)gl_frameMS * (float)TICRATE / 1000.0f;
return (float)screen->FrameTime * (float)TICRATE / 1000.0f;
}

CVAR(Bool, gl_interpolate_model_frames, true, CVAR_ARCHIVE)
Expand Down
2 changes: 1 addition & 1 deletion src/gl/renderer/gl_renderer.h
Expand Up @@ -171,7 +171,7 @@ class FGLRenderer
unsigned char *GetTextureBuffer(FTexture *tex, int &w, int &h);
void SetupLevel();

void RenderView(player_t* player, unsigned int nowtime);
void RenderView(player_t* player);

void RenderScreenQuad();
void PostProcessScene(int fixedcm);
Expand Down
2 changes: 1 addition & 1 deletion src/gl/renderer/gl_renderstate.cpp
Expand Up @@ -161,7 +161,7 @@ bool FRenderState::ApplyShader()
activeShader->muInterpolationFactor.Set(mInterpolationFactor);
activeShader->muClipHeight.Set(mClipHeight);
activeShader->muClipHeightDirection.Set(mClipHeightDirection);
activeShader->muTimer.Set(gl_frameMS * mShaderTimer / 1000.f);
activeShader->muTimer.Set(screen->FrameTime * mShaderTimer / 1000.f);
activeShader->muAlphaThreshold.Set(mAlphaThreshold);
activeShader->muLightIndex.Set(mLightIndex); // will always be -1 for now
activeShader->muClipSplit.Set(mClipSplit);
Expand Down
15 changes: 7 additions & 8 deletions src/gl/scene/gl_scene.cpp
Expand Up @@ -785,7 +785,7 @@ sector_t * GLSceneDrawer::RenderViewpoint (AActor * camera, GL_IRECT * bounds, f
GLRenderer->mSceneClearColor[0] = 0.0f;
GLRenderer->mSceneClearColor[1] = 0.0f;
GLRenderer->mSceneClearColor[2] = 0.0f;
R_SetupFrame (r_viewpoint, r_viewwindow, camera, gl_frameMS);
R_SetupFrame (r_viewpoint, r_viewwindow, camera);
SetViewArea();

GLRenderer->mGlobVis = R_GetGlobVis(r_viewwindow, r_visibility);
Expand All @@ -800,8 +800,8 @@ sector_t * GLSceneDrawer::RenderViewpoint (AActor * camera, GL_IRECT * bounds, f
GLRenderer->mAngles.Roll.Degrees = r_viewpoint.Angles.Roll.Degrees;

// Scroll the sky
GLRenderer->mSky1Pos = (float)fmod(gl_frameMS * level.skyspeed1, 1024.f) * 90.f/256.f;
GLRenderer->mSky2Pos = (float)fmod(gl_frameMS * level.skyspeed2, 1024.f) * 90.f/256.f;
GLRenderer->mSky1Pos = (float)fmod(screen->FrameTime * level.skyspeed1, 1024.f) * 90.f/256.f;
GLRenderer->mSky2Pos = (float)fmod(screen->FrameTime * level.skyspeed2, 1024.f) * 90.f/256.f;



Expand Down Expand Up @@ -878,7 +878,7 @@ sector_t * GLSceneDrawer::RenderViewpoint (AActor * camera, GL_IRECT * bounds, f
//
//-----------------------------------------------------------------------------

void FGLRenderer::RenderView (player_t* player, unsigned int nowtime)
void FGLRenderer::RenderView (player_t* player)
{
checkBenchActive();

Expand All @@ -891,7 +891,6 @@ void FGLRenderer::RenderView (player_t* player, unsigned int nowtime)
// Get this before everything else
if (cl_capfps || r_NoInterpolate) r_viewpoint.TicFrac = 1.;
else r_viewpoint.TicFrac = I_GetTimeFrac (&r_viewpoint.FrameTime);
gl_frameMS = nowtime;

P_FindParticleSubsectors ();

Expand Down Expand Up @@ -984,7 +983,7 @@ void GLSceneDrawer::WriteSavePic (player_t *player, FileWriter *file, int width,
struct FGLInterface : public FRenderer
{
void Precache(uint8_t *texhitlist, TMap<PClassActor*, bool> &actorhitlist) override;
void RenderView(player_t *player, unsigned int nowtime) override;
void RenderView(player_t *player) override;
void WriteSavePic (player_t *player, FileWriter *file, int width, int height) override;
void StartSerialize(FSerializer &arc) override;
void EndSerialize(FSerializer &arc) override;
Expand Down Expand Up @@ -1075,9 +1074,9 @@ void FGLInterface::WriteSavePic (player_t *player, FileWriter *file, int width,
//
//===========================================================================

void FGLInterface::RenderView(player_t *player, unsigned int nowtime)
void FGLInterface::RenderView(player_t *player)
{
GLRenderer->RenderView(player, nowtime);
GLRenderer->RenderView(player);
}

//===========================================================================
Expand Down
2 changes: 1 addition & 1 deletion src/gl/scene/gl_scenedrawer.h
Expand Up @@ -60,7 +60,7 @@ class GLSceneDrawer
void CheckViewArea(vertex_t *v1, vertex_t *v2, sector_t *frontsector, sector_t *backsector);

sector_t *RenderViewpoint(AActor * camera, GL_IRECT * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen);
void RenderView(player_t *player, unsigned int nowtime);
void RenderView(player_t *player);
void WriteSavePic(player_t *player, FileWriter *file, int width, int height);

void DrawPSprite(player_t * player, DPSprite *psp, float sx, float sy, bool hudModelStep, int OverrideShader, bool alphatexture);
Expand Down
1 change: 0 additions & 1 deletion src/gl/system/gl_framebuffer.h
Expand Up @@ -12,7 +12,6 @@ class FHardwareTexture;
class FSimpleVertexBuffer;
class FGLDebug;

extern long gl_frameMS;
#ifdef _WIN32
class OpenGLFrameBuffer : public Win32GLFrameBuffer
{
Expand Down
2 changes: 1 addition & 1 deletion src/polyrenderer/poly_renderer.cpp
Expand Up @@ -115,7 +115,7 @@ void PolyRenderer::RenderActorView(AActor *actor, bool dontmaplines)

DontMapLines = dontmaplines;

R_SetupFrame(Viewpoint, Viewwindow, actor, swrenderer::renderTime);
R_SetupFrame(Viewpoint, Viewwindow, actor);
P_FindParticleSubsectors();
PO_LinkToSubsectors();

Expand Down
2 changes: 1 addition & 1 deletion src/posix/cocoa/st_console.mm
Expand Up @@ -200,7 +200,7 @@
{
explicit TimedUpdater(const Function& function)
{
const unsigned int currentTime = I_MSTime();
const unsigned int currentTime = I_FPSTime();

if (currentTime - m_previousTime > interval)
{
Expand Down
2 changes: 1 addition & 1 deletion src/r_renderer.h
Expand Up @@ -29,7 +29,7 @@ struct FRenderer
virtual void Precache(uint8_t *texhitlist, TMap<PClassActor*, bool> &actorhitlist) = 0;

// render 3D view
virtual void RenderView(player_t *player, unsigned int nowtime) = 0;
virtual void RenderView(player_t *player) = 0;

// Remap voxel palette
virtual void RemapVoxels() {}
Expand Down
6 changes: 3 additions & 3 deletions src/r_utility.cpp
Expand Up @@ -751,7 +751,7 @@ static double QuakePower(double factor, double intensity, double offset)
//
//==========================================================================

void R_SetupFrame (FRenderViewpoint &viewpoint, FViewWindow &viewwindow, AActor *actor, unsigned int renderTime)
void R_SetupFrame (FRenderViewpoint &viewpoint, FViewWindow &viewwindow, AActor *actor)
{
if (actor == NULL)
{
Expand Down Expand Up @@ -982,7 +982,7 @@ void R_SetupFrame (FRenderViewpoint &viewpoint, FViewWindow &viewwindow, AActor

if (hom == 3)
{
hom = ((renderTime / 128) & 1) + 1;
hom = ((screen->FrameTime / 128) & 1) + 1;
}
if (hom == 1)
{
Expand All @@ -994,7 +994,7 @@ void R_SetupFrame (FRenderViewpoint &viewpoint, FViewWindow &viewwindow, AActor
}
else if (hom == 4)
{
color = (renderTime / 32) & 255;
color = (screen->FrameTime / 32) & 255;
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/r_utility.h
Expand Up @@ -111,7 +111,7 @@ void R_ClearInterpolationPath();
void R_AddInterpolationPoint(const DVector3a &vec);
void R_SetViewSize (int blocks);
void R_SetFOV (FRenderViewpoint &viewpoint, DAngle fov);
void R_SetupFrame (FRenderViewpoint &viewpoint, FViewWindow &viewwindow, AActor * camera, unsigned int renderTime);
void R_SetupFrame (FRenderViewpoint &viewpoint, FViewWindow &viewwindow, AActor * camera);
void R_SetViewAngle (FRenderViewpoint &viewpoint, const FViewWindow &viewwindow);

// Called by startup code.
Expand Down
1 change: 0 additions & 1 deletion src/swrenderer/drawers/r_draw.cpp
Expand Up @@ -64,7 +64,6 @@ namespace swrenderer
int fuzzoffset[FUZZTABLE + 1];
int fuzzpos;
int fuzzviewheight;
unsigned int renderTime;

int fuzz_random_x_offset[FUZZ_RANDOM_X_SIZE] =
{
Expand Down
1 change: 0 additions & 1 deletion src/swrenderer/drawers/r_draw.h
Expand Up @@ -35,7 +35,6 @@ namespace swrenderer
extern FDynamicColormap ShadeFakeColormap[16];
extern uint8_t identitymap[256];
extern FDynamicColormap identitycolormap;
extern unsigned int renderTime;

// Constant arrays used for psprite clipping and initializing clipping.
extern short zeroarray[MAXWIDTH];
Expand Down
3 changes: 1 addition & 2 deletions src/swrenderer/r_swrenderer.cpp
Expand Up @@ -170,9 +170,8 @@ void FSoftwareRenderer::Precache(uint8_t *texhitlist, TMap<PClassActor*, bool> &
}
}

void FSoftwareRenderer::RenderView(player_t *player, unsigned int nowtime)
void FSoftwareRenderer::RenderView(player_t *player)
{
renderTime = nowtime;
if (r_polyrenderer)
{
PolyRenderer::Instance()->Viewpoint = r_viewpoint;
Expand Down
2 changes: 1 addition & 1 deletion src/swrenderer/r_swrenderer.h
Expand Up @@ -13,7 +13,7 @@ struct FSoftwareRenderer : public FRenderer
void Precache(uint8_t *texhitlist, TMap<PClassActor*, bool> &actorhitlist) override;

// render 3D view
void RenderView(player_t *player, unsigned int nowtime) override;
void RenderView(player_t *player) override;

// Remap voxel palette
void RemapVoxels() override;
Expand Down
2 changes: 1 addition & 1 deletion src/swrenderer/scene/r_scene.cpp
Expand Up @@ -136,7 +136,7 @@ namespace swrenderer
MaskedCycles.Reset();
DrawerWaitCycles.Reset();

R_SetupFrame(MainThread()->Viewport->viewpoint, MainThread()->Viewport->viewwindow, actor, renderTime);
R_SetupFrame(MainThread()->Viewport->viewpoint, MainThread()->Viewport->viewwindow, actor);

if (APART(R_OldBlend)) NormalLight.Maps = realcolormaps.Maps;
else NormalLight.Maps = realcolormaps.Maps + NUMCOLORMAPS * 256 * R_OldBlend;
Expand Down
2 changes: 1 addition & 1 deletion src/swrenderer/things/r_voxel.cpp
Expand Up @@ -135,7 +135,7 @@ namespace swrenderer
int voxelspin = (thing->flags & MF_DROPPED) ? voxel->DroppedSpin : voxel->PlacedSpin;
if (voxelspin != 0)
{
DAngle ang = double(renderTime) * voxelspin / 1000;
DAngle ang = double(screen->FrameTime) * voxelspin / 1000;
vis->Angle -= ang;
}

Expand Down
2 changes: 1 addition & 1 deletion src/v_video.cpp
Expand Up @@ -870,7 +870,7 @@ void DFrameBuffer::DrawRateStuff ()
// Draws frame time and cumulative fps
if (vid_fps)
{
uint32_t ms = I_FPSTime();
uint32_t ms = screen->FrameTime;
uint32_t howlong = ms - LastMS;
if ((signed)howlong >= 0)
{
Expand Down
1 change: 1 addition & 0 deletions src/v_video.h
Expand Up @@ -453,6 +453,7 @@ class DFrameBuffer : public DSimpleCanvas
// The original size of the framebuffer as selected in the video menu.
int VideoWidth = 0;
int VideoHeight = 0;
uint32_t FrameTime = 0;

protected:
void DrawRateStuff ();
Expand Down

0 comments on commit 2c65f08

Please sign in to comment.