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
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions src/d2dx/RenderContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/d2dx/RenderContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ namespace d2dx
int64_t _timeStart;
bool _hasAdjustedWindowPlacement = false;

double _prevTime;
int64_t _prevTime;
double _frameTimeMs;
};
}
12 changes: 6 additions & 6 deletions src/d2dx/UnitMotionPredictor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ Offset UnitMotionPredictor::GetOffset(

for (int32_t i = 0; i < _unitsCount; ++i)
{
if (_unitIdAndTypes.items[i].unitId == (uint16_t)unitId &&
_unitIdAndTypes.items[i].unitType == (uint16_t)unitType)
if (_unitIdAndTypes.items[i].unitId == unitId &&
_unitIdAndTypes.items[i].unitType == (uint32_t)unitType)
{
_unitMotions.items[i].lastUsedFrame = _frame;
unitIndex = i;
Expand All @@ -182,8 +182,8 @@ Offset UnitMotionPredictor::GetOffset(
if (_unitsCount < (int32_t)_unitIdAndTypes.capacity)
{
unitIndex = _unitsCount++;
_unitIdAndTypes.items[unitIndex].unitId = (uint16_t)unitId;
_unitIdAndTypes.items[unitIndex].unitType = (uint16_t)unitType;
_unitIdAndTypes.items[unitIndex].unitId = unitId;
_unitIdAndTypes.items[unitIndex].unitType = (uint32_t)unitType;
_unitMotions.items[unitIndex] = { };
_unitMotions.items[unitIndex].lastUsedFrame = _frame;
}
Expand Down Expand Up @@ -212,8 +212,8 @@ void UnitMotionPredictor::SetUnitScreenPos(

for (int32_t unitIndex = 0; unitIndex < _unitsCount; ++unitIndex)
{
if (_unitIdAndTypes.items[unitIndex].unitId == (uint16_t)unitId &&
_unitIdAndTypes.items[unitIndex].unitType == (uint16_t)unitType)
if (_unitIdAndTypes.items[unitIndex].unitId == unitId &&
_unitIdAndTypes.items[unitIndex].unitType == (uint32_t)unitType)
{
_unitScreenPositions.items[unitIndex] = { x, y };
break;
Expand Down
4 changes: 2 additions & 2 deletions src/d2dx/UnitMotionPredictor.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ namespace d2dx
private:
struct UnitIdAndType final
{
uint16_t unitType = 0;
uint16_t unitId = 0;
uint32_t unitType = 0;
uint32_t unitId = 0;
};

struct UnitMotion final
Expand Down
10 changes: 7 additions & 3 deletions src/d2dx/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/d2dx/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down