Changeset View
Changeset View
Standalone View
Standalone View
source/main.cpp
Show First 20 Lines • Show All 324 Lines • ▼ Show 20 Lines | |||||||||||||||
{ | { | ||||||||||||||
g_Profiler2.RecordFrameStart(); | g_Profiler2.RecordFrameStart(); | ||||||||||||||
PROFILE2("frame"); | PROFILE2("frame"); | ||||||||||||||
g_Profiler2.IncrementFrameNumber(); | g_Profiler2.IncrementFrameNumber(); | ||||||||||||||
PROFILE2_ATTR("%d", g_Profiler2.GetFrameNumber()); | PROFILE2_ATTR("%d", g_Profiler2.GetFrameNumber()); | ||||||||||||||
ogl_WarnIfError(); | ogl_WarnIfError(); | ||||||||||||||
// get elapsed time | // Get elapsed time. | ||||||||||||||
const double time = timer_Time(); | static double last_time = 0.0; | ||||||||||||||
vladislavbelov: That's the bad value. You might get a huge `realTimeSinceLastFrame` to update some components. | |||||||||||||||
double time = timer_Time(); | |||||||||||||||
g_frequencyFilter->Update(time); | g_frequencyFilter->Update(time); | ||||||||||||||
// .. old method - "exact" but contains jumps | const float realTimeSinceLastFrame = (float)(time-last_time); | ||||||||||||||
StanUnsubmitted Not Done Inline Actions
Stan: | |||||||||||||||
vladislavbelovUnsubmitted Not Done Inline ActionsHow this difference solves the problem with spikes (because of CPU/GPU stall, OS pause)? vladislavbelov: How this difference solves the problem with spikes (because of CPU/GPU stall, OS pause)? | |||||||||||||||
#if 0 | |||||||||||||||
static double last_time; | |||||||||||||||
const double time = timer_Time(); | |||||||||||||||
const float TimeSinceLastFrame = (float)(time-last_time); | |||||||||||||||
last_time = time; | last_time = time; | ||||||||||||||
ONCE(return); // first call: set last_time and return | |||||||||||||||
// .. new method - filtered and more smooth, but errors may accumulate | |||||||||||||||
#else | |||||||||||||||
const float realTimeSinceLastFrame = 1.0 / g_frequencyFilter->SmoothedFrequency(); | |||||||||||||||
#endif | |||||||||||||||
ENSURE(realTimeSinceLastFrame > 0.0f); | ENSURE(realTimeSinceLastFrame > 0.0f); | ||||||||||||||
// Decide if update is necessary | // Decide if update is necessary | ||||||||||||||
bool need_update = true; | bool need_update = true; | ||||||||||||||
// If we are not running a multiplayer game, disable updates when the game is | // If we are not running a multiplayer game, disable updates when the game is | ||||||||||||||
// minimized or out of focus and relinquish the CPU a bit, in order to make | // minimized or out of focus and relinquish the CPU a bit, in order to make | ||||||||||||||
// debugging easier. | // debugging easier. | ||||||||||||||
Show All 40 Lines | static void Frame() | ||||||||||||||
if (g_RLInterface) | if (g_RLInterface) | ||||||||||||||
g_RLInterface->TryApplyMessage(); | g_RLInterface->TryApplyMessage(); | ||||||||||||||
if (g_Game && g_Game->IsGameStarted() && need_update) | if (g_Game && g_Game->IsGameStarted() && need_update) | ||||||||||||||
{ | { | ||||||||||||||
if (!g_RLInterface) | if (!g_RLInterface) | ||||||||||||||
g_Game->Update(realTimeSinceLastFrame); | g_Game->Update(realTimeSinceLastFrame); | ||||||||||||||
g_Game->GetView()->Update(float(realTimeSinceLastFrame)); | g_Game->GetView()->Update(float(realTimeSinceLastFrame)); | ||||||||||||||
StanUnsubmitted Not Done Inline ActionsUseless cast. Stan: Useless cast. | |||||||||||||||
} | } | ||||||||||||||
// Immediately flush any messages produced by simulation code | // Immediately flush any messages produced by simulation code | ||||||||||||||
if (g_NetClient) | if (g_NetClient) | ||||||||||||||
g_NetClient->Flush(); | g_NetClient->Flush(); | ||||||||||||||
// Keep us connected to any XMPP servers | // Keep us connected to any XMPP servers | ||||||||||||||
if (g_XmppClient) | if (g_XmppClient) | ||||||||||||||
▲ Show 20 Lines • Show All 359 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
That's the bad value. You might get a huge realTimeSinceLastFrame to update some components.