Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix slowdown on longer play sessions #188

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix percision lost when calculating the frame time. Started after ~4 …
…minutes due to float percision limits, would be visible after ~18-36 hours when it would be off by 4-8ms.
Jarcho committed Apr 7, 2023
commit d314dddb239de58dac0eaa67bb9083e2ea2863da
4 changes: 2 additions & 2 deletions src/d2dx/RenderContext.cpp
Original file line number Diff line number Diff line change
@@ -468,8 +468,8 @@ void RenderContext::Present()
break;
}

double curTime = TimeEndMs(_timeStart);
_frameTimeMs = curTime - _prevTime;
auto curTime = TimeEnd(_timeStart);
_frameTimeMs = TimeToMs(curTime - _prevTime);
_prevTime = curTime;

if (_deviceContext1)
2 changes: 1 addition & 1 deletion src/d2dx/RenderContext.h
Original file line number Diff line number Diff line change
@@ -211,7 +211,7 @@ namespace d2dx
int64_t _timeStart;
bool _hasAdjustedWindowPlacement = false;

double _prevTime;
int64_t _prevTime;
double _frameTimeMs;
};
}
10 changes: 7 additions & 3 deletions src/d2dx/Utils.cpp
Original file line number Diff line number Diff line change
@@ -51,13 +51,17 @@ int64_t d2dx::TimeStart()
return (int64_t)li.QuadPart;
}

float d2dx::TimeEndMs(int64_t sinceThisTime)
int64_t d2dx::TimeEnd(int64_t sinceThisTime)
{
warmup();
LARGE_INTEGER li;
QueryPerformanceCounter(&li);
return li.QuadPart - sinceThisTime;
}

double d2dx::TimeToMs(int64_t time)
{
assert(_freq);
return (float)(double(li.QuadPart - sinceThisTime) / _freq);
return static_cast<double>(time) / _freq;
}

#define STATUS_SUCCESS (0x00000000)
3 changes: 2 additions & 1 deletion src/d2dx/Utils.h
Original file line number Diff line number Diff line change
@@ -29,7 +29,8 @@ namespace d2dx
}

int64_t TimeStart();
float TimeEndMs(int64_t start);
int64_t TimeEnd(int64_t start);
double TimeToMs(int64_t time);


#ifdef NDEBUG