diff --git a/src/d2dx/RenderContext.cpp b/src/d2dx/RenderContext.cpp index 9beb040..6a9366e 100644 --- a/src/d2dx/RenderContext.cpp +++ b/src/d2dx/RenderContext.cpp @@ -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) diff --git a/src/d2dx/RenderContext.h b/src/d2dx/RenderContext.h index cc1b919..28af694 100644 --- a/src/d2dx/RenderContext.h +++ b/src/d2dx/RenderContext.h @@ -211,7 +211,7 @@ namespace d2dx int64_t _timeStart; bool _hasAdjustedWindowPlacement = false; - double _prevTime; + int64_t _prevTime; double _frameTimeMs; }; } \ No newline at end of file diff --git a/src/d2dx/UnitMotionPredictor.cpp b/src/d2dx/UnitMotionPredictor.cpp index d7f5ae0..2317817 100644 --- a/src/d2dx/UnitMotionPredictor.cpp +++ b/src/d2dx/UnitMotionPredictor.cpp @@ -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; @@ -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; } @@ -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; diff --git a/src/d2dx/UnitMotionPredictor.h b/src/d2dx/UnitMotionPredictor.h index 54b18c0..e0ba19e 100644 --- a/src/d2dx/UnitMotionPredictor.h +++ b/src/d2dx/UnitMotionPredictor.h @@ -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 diff --git a/src/d2dx/Utils.cpp b/src/d2dx/Utils.cpp index c1f55f7..648c44b 100644 --- a/src/d2dx/Utils.cpp +++ b/src/d2dx/Utils.cpp @@ -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(time) / _freq; } #define STATUS_SUCCESS (0x00000000) diff --git a/src/d2dx/Utils.h b/src/d2dx/Utils.h index ac8d937..7ca8835 100644 --- a/src/d2dx/Utils.h +++ b/src/d2dx/Utils.h @@ -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