fixed the render frame time and cleaned up some more code

This commit is contained in:
Magnus Auvinen 2012-01-01 13:38:46 +01:00
parent 8b76105cfa
commit c1942ca6cb
7 changed files with 54 additions and 166 deletions

View file

@ -23,7 +23,7 @@ protected:
float m_PredIntraTick; float m_PredIntraTick;
float m_LocalTime; float m_LocalTime;
float m_FrameTime; float m_RenderFrameTime;
int m_GameTickSpeed; int m_GameTickSpeed;
public: public:
@ -68,7 +68,7 @@ public:
inline int GameTickSpeed() const { return m_GameTickSpeed; } inline int GameTickSpeed() const { return m_GameTickSpeed; }
// other time access // other time access
inline float FrameTime() const { return m_FrameTime; } inline float RenderFrameTime() const { return m_RenderFrameTime; }
inline float LocalTime() const { return m_LocalTime; } inline float LocalTime() const { return m_LocalTime; }
// actions // actions

View file

@ -244,10 +244,11 @@ CClient::CClient() : m_DemoPlayer(&m_SnapshotDelta), m_DemoRecorder(&m_SnapshotD
m_pMap = 0; m_pMap = 0;
m_pConsole = 0; m_pConsole = 0;
m_FrameTime = 0.0001f; m_RenderFrameTime = 0.0001f;
m_FrameTimeLow = 1.0f; m_RenderFrameTimeLow = 1.0f;
m_FrameTimeHigh = 0.0f; m_RenderFrameTimeHigh = 0.0f;
m_Frames = 0; m_RenderFrames = 0;
m_LastRenderTime = time_get();
m_GameTickSpeed = SERVER_TICK_SPEED; m_GameTickSpeed = SERVER_TICK_SPEED;
@ -681,13 +682,13 @@ void CClient::DebugRender()
udp = 8 udp = 8
total = 42 total = 42
*/ */
FrameTimeAvg = FrameTimeAvg*0.9f + m_FrameTime*0.1f; FrameTimeAvg = FrameTimeAvg*0.9f + m_RenderFrameTime*0.1f;
str_format(aBuffer, sizeof(aBuffer), "ticks: %8d %8d mem %dk %d gfxmem: %dk fps: %3d", str_format(aBuffer, sizeof(aBuffer), "ticks: %8d %8d mem %dk %d gfxmem: %dk fps: %3d",
m_CurGameTick, m_PredTick, m_CurGameTick, m_PredTick,
mem_stats()->allocated/1024, mem_stats()->allocated/1024,
mem_stats()->total_allocations, mem_stats()->total_allocations,
Graphics()->MemoryUsage()/1024, Graphics()->MemoryUsage()/1024,
(int)(1.0f/FrameTimeAvg)); (int)(1.0f/FrameTimeAvg + 0.5f));
Graphics()->QuadsText(2, 2, 16, 1,1,1,1, aBuffer); Graphics()->QuadsText(2, 2, 16, 1,1,1,1, aBuffer);
@ -1691,9 +1692,6 @@ void CClient::InitInterfaces()
void CClient::Run() void CClient::Run()
{ {
int64 ReportTime = time_get();
int64 ReportInterval = time_freq()*1;
m_LocalStartTime = time_get(); m_LocalStartTime = time_get();
m_SnapshotParts = 0; m_SnapshotParts = 0;
@ -1772,9 +1770,6 @@ void CClient::Run()
while (1) while (1)
{ {
int64 FrameStartTime = time_get();
m_Frames++;
// //
VersionUpdate(); VersionUpdate();
@ -1866,9 +1861,22 @@ void CClient::Run()
if(!g_Config.m_GfxAsyncRender || m_pGraphics->IsIdle()) if(!g_Config.m_GfxAsyncRender || m_pGraphics->IsIdle())
{ {
m_RenderFrames++;
// update frametime
int64 Now = time_get();
m_RenderFrameTime = (Now - m_LastRenderTime) / (float)time_freq();
if(m_RenderFrameTime < m_RenderFrameTimeLow)
m_RenderFrameTimeLow = m_RenderFrameTime;
if(m_RenderFrameTime > m_RenderFrameTimeHigh)
m_RenderFrameTimeHigh = m_RenderFrameTime;
m_FpsGraph.Add(1.0f/m_RenderFrameTime, 1,1,1);
m_LastRenderTime = Now;
if(g_Config.m_DbgStress) if(g_Config.m_DbgStress)
{ {
if((m_Frames%10) == 0) if((m_RenderFrames%10) == 0)
{ {
Render(); Render();
m_pGraphics->Swap(); m_pGraphics->Swap();
@ -1879,6 +1887,9 @@ void CClient::Run()
Render(); Render();
m_pGraphics->Swap(); m_pGraphics->Swap();
} }
} }
} }
@ -1900,32 +1911,25 @@ void CClient::Run()
g_Config.m_DbgHitch = 0; g_Config.m_DbgHitch = 0;
} }
/*
if(ReportTime < time_get()) if(ReportTime < time_get())
{ {
if(0 && g_Config.m_Debug) if(0 && g_Config.m_Debug)
{ {
dbg_msg("client/report", "fps=%.02f (%.02f %.02f) netstate=%d", dbg_msg("client/report", "fps=%.02f (%.02f %.02f) netstate=%d",
m_Frames/(float)(ReportInterval/time_freq()), m_Frames/(float)(ReportInterval/time_freq()),
1.0f/m_FrameTimeHigh, 1.0f/m_RenderFrameTimeHigh,
1.0f/m_FrameTimeLow, 1.0f/m_RenderFrameTimeLow,
m_NetClient.State()); m_NetClient.State());
} }
m_FrameTimeLow = 1; m_RenderFrameTimeLow = 1;
m_FrameTimeHigh = 0; m_RenderFrameTimeHigh = 0;
m_Frames = 0; m_RenderFrames = 0;
ReportTime += ReportInterval; ReportTime += ReportInterval;
} }*/
// update frametime
m_FrameTime = (time_get()-FrameStartTime)/(float)time_freq();
if(m_FrameTime < m_FrameTimeLow)
m_FrameTimeLow = m_FrameTime;
if(m_FrameTime > m_FrameTimeHigh)
m_FrameTimeHigh = m_FrameTime;
// update local time
m_LocalTime = (time_get()-m_LocalStartTime)/(float)time_freq(); m_LocalTime = (time_get()-m_LocalStartTime)/(float)time_freq();
m_FpsGraph.Add(1.0f/m_FrameTime, 1,1,1);
} }
GameClient()->OnShutdown(); GameClient()->OnShutdown();

View file

@ -84,9 +84,12 @@ class CClient : public IClient, public CDemoPlayer::IListner
int64 m_LocalStartTime; int64 m_LocalStartTime;
int m_DebugFont; int m_DebugFont;
float m_FrameTimeLow;
float m_FrameTimeHigh; int64 m_LastRenderTime;
int m_Frames; float m_RenderFrameTimeLow;
float m_RenderFrameTimeHigh;
int m_RenderFrames;
NETADDR m_ServerAddress; NETADDR m_ServerAddress;
int m_WindowMustRefocus; int m_WindowMustRefocus;
int m_SnapCrcErrors; int m_SnapCrcErrors;

View file

@ -230,130 +230,6 @@ class CCommandProcessorFragment_SDL
// SDL stuff // SDL stuff
SDL_Surface *m_pScreenSurface; SDL_Surface *m_pScreenSurface;
bool m_SystemInited; bool m_SystemInited;
/*
int TryInit()
{
const SDL_VideoInfo *pInfo = SDL_GetVideoInfo();
SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
// set flags
int Flags = SDL_OPENGL;
if(g_Config.m_DbgResizable)
Flags |= SDL_RESIZABLE;
if(pInfo->hw_available) // ignore_convention
Flags |= SDL_HWSURFACE;
else
Flags |= SDL_SWSURFACE;
if(pInfo->blit_hw) // ignore_convention
Flags |= SDL_HWACCEL;
if(g_Config.m_GfxFullscreen)
Flags |= SDL_FULLSCREEN;
// set gl attributes
if(g_Config.m_GfxFsaaSamples)
{
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, g_Config.m_GfxFsaaSamples);
}
else
{
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
}
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, g_Config.m_GfxVsync);
// set caption
SDL_WM_SetCaption("Teeworlds", "Teeworlds");
// create window
m_pScreenSurface = SDL_SetVideoMode(g_Config.m_GfxScreenWidth, g_Config.m_GfxScreenHeight, 0, Flags);
if(m_pScreenSurface == NULL)
{
dbg_msg("gfx", "unable to set video mode: %s", SDL_GetError());
return -1;
}
return 0;
}
int InitWindow()
{
if(TryInit() == 0)
return 0;
// try disabling fsaa
while(g_Config.m_GfxFsaaSamples)
{
g_Config.m_GfxFsaaSamples--;
if(g_Config.m_GfxFsaaSamples)
dbg_msg("gfx", "lowering FSAA to %d and trying again", g_Config.m_GfxFsaaSamples);
else
dbg_msg("gfx", "disabling FSAA and trying again");
if(TryInit() == 0)
return 0;
}
// try lowering the resolution
if(g_Config.m_GfxScreenWidth != 640 || g_Config.m_GfxScreenHeight != 480)
{
dbg_msg("gfx", "setting resolution to 640x480 and trying again");
g_Config.m_GfxScreenWidth = 640;
g_Config.m_GfxScreenHeight = 480;
if(TryInit() == 0)
return 0;
}
dbg_msg("gfx", "out of ideas. failed to init graphics");
return -1;
}
int Init()
{
{
int Systems = SDL_INIT_VIDEO;
if(g_Config.m_SndEnable)
Systems |= SDL_INIT_AUDIO;
if(g_Config.m_ClEventthread)
Systems |= SDL_INIT_EVENTTHREAD;
if(SDL_Init(Systems) < 0)
{
dbg_msg("gfx", "unable to init SDL: %s", SDL_GetError());
return -1;
}
}
if(InitWindow() != 0)
return -1;
SDL_ShowCursor(0);
// set some default settings
glEnable(GL_BLEND);
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glAlphaFunc(GL_GREATER, 0);
glEnable(GL_ALPHA_TEST);
glDepthMask(0);
return 0;
}*/
void Cmd_Init(const CCommandBuffer::SCommand_Init *pCommand) void Cmd_Init(const CCommandBuffer::SCommand_Init *pCommand)
{ {
@ -445,14 +321,11 @@ class CCommandProcessorFragment_SDL
dbg_msg("gfx", "unable to set video mode: %s", SDL_GetError()); dbg_msg("gfx", "unable to set video mode: %s", SDL_GetError());
*pCommand->m_pResult = -1; *pCommand->m_pResult = -1;
} }
//*pCommand->m_pResult = Init();
} }
void Cmd_Shutdown(const CCommandBuffer::SCommand_Shutdown *pCommand) void Cmd_Shutdown(const CCommandBuffer::SCommand_Shutdown *pCommand)
{ {
SDL_Quit();
} }
void Cmd_Swap(const CCommandBuffer::SCommand_Swap *pCommand) void Cmd_Swap(const CCommandBuffer::SCommand_Swap *pCommand)
@ -1312,7 +1185,8 @@ bool CGraphics_Threaded::Init()
void CGraphics_Threaded::Shutdown() void CGraphics_Threaded::Shutdown()
{ {
// TODO: SDL, is this correct? // TODO: SDL, is this correct?
SDL_Quit();
//
} }
void CGraphics_Threaded::Minimize() void CGraphics_Threaded::Minimize()

View file

@ -78,6 +78,9 @@ public:
// swap // swap
CMD_SWAP, CMD_SWAP,
//
CMD_SCREENSHOT,
}; };
enum enum
@ -192,6 +195,13 @@ public:
SVertex *m_pVertices; SVertex *m_pVertices;
}; };
struct SCommand_Screenshot : public SCommand
{
SCommand_Screenshot() : SCommand(CMD_SCREENSHOT) {}
CImageInfo *m_pImage; // processor will fill this out
};
struct SCommand_Swap : public SCommand struct SCommand_Swap : public SCommand
{ {
SCommand_Swap() : SCommand(CMD_SWAP) {} SCommand_Swap() : SCommand(CMD_SWAP) {}

View file

@ -248,7 +248,7 @@ void CHud::RenderFps()
if(g_Config.m_ClShowfps) if(g_Config.m_ClShowfps)
{ {
// calculate avg. fps // calculate avg. fps
float FPS = 1.0f / Client()->FrameTime(); float FPS = 1.0f / Client()->RenderFrameTime();
m_AverageFPS = (m_AverageFPS*(1.0f-(1.0f/m_AverageFPS))) + (FPS*(1.0f/m_AverageFPS)); m_AverageFPS = (m_AverageFPS*(1.0f-(1.0f/m_AverageFPS))) + (FPS*(1.0f/m_AverageFPS));
char Buf[512]; char Buf[512];
str_format(Buf, sizeof(Buf), "%d", (int)m_AverageFPS); str_format(Buf, sizeof(Buf), "%d", (int)m_AverageFPS);

View file

@ -22,7 +22,6 @@ void CItems::OnReset()
void CItems::RenderProjectile(const CNetObj_Projectile *pCurrent, int ItemID) void CItems::RenderProjectile(const CNetObj_Projectile *pCurrent, int ItemID)
{ {
// get positions // get positions
float Curvature = 0; float Curvature = 0;
float Speed = 0; float Speed = 0;
@ -64,7 +63,6 @@ void CItems::RenderProjectile(const CNetObj_Projectile *pCurrent, int ItemID)
if(pCurrent->m_Type == WEAPON_GRENADE) if(pCurrent->m_Type == WEAPON_GRENADE)
{ {
m_pClient->m_pEffects->SmokeTrail(Pos, Vel*-1); m_pClient->m_pEffects->SmokeTrail(Pos, Vel*-1);
m_pClient->m_pFlow->Add(Pos, Vel*1000*Client()->FrameTime(), 10.0f);
if(Client()->State() == IClient::STATE_DEMOPLAYBACK) if(Client()->State() == IClient::STATE_DEMOPLAYBACK)
{ {
@ -85,7 +83,6 @@ void CItems::RenderProjectile(const CNetObj_Projectile *pCurrent, int ItemID)
else else
{ {
m_pClient->m_pEffects->BulletTrail(Pos); m_pClient->m_pEffects->BulletTrail(Pos);
m_pClient->m_pFlow->Add(Pos, Vel*1000*Client()->FrameTime(), 10.0f);
if(length(Vel) > 0.00001f) if(length(Vel) > 0.00001f)
Graphics()->QuadsSetRotation(GetAngle(Vel)); Graphics()->QuadsSetRotation(GetAngle(Vel));