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

Use high-resolution clock when computing lastEventTime #889

Open
wants to merge 1 commit 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions bwapi/BWAPI/Source/BWAPI/GameEvents.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "GameImpl.h"
#include <ctime>
#include <chrono>

#include <Util/Path.h>
#include <Util/StringUtil.h>
Expand Down Expand Up @@ -503,13 +504,13 @@ namespace BWAPI
return;
for (Event e : events)
{
static DWORD dwLastEventTime = 0;
static std::chrono::time_point<std::chrono::high_resolution_clock> lastEventStart;

// Reset event stopwatch
if ( tournamentAI )
{
this->lastEventTime = 0;
dwLastEventTime = GetTickCount();
lastEventStart = std::chrono::high_resolution_clock::now();
}

// Send event to the AI Client module
Expand All @@ -520,7 +521,8 @@ namespace BWAPI
continue;

// Save the last event time
this->lastEventTime = GetTickCount() - dwLastEventTime;
auto const duration = std::chrono::high_resolution_clock::now() - lastEventStart;
this->lastEventTime = (int)std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();

// Send same event to the Tournament module for post-processing
isTournamentCall = true;
Expand Down
6 changes: 4 additions & 2 deletions bwapi/BWAPI/Source/BWAPI/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <cassert>
#include <sstream>
#include <AclAPI.h>
#include <chrono>

#include "GameImpl.h"
#include "PlayerImpl.h"
Expand Down Expand Up @@ -238,9 +239,10 @@ namespace BWAPI
{
// Update BWAPI Client
updateSharedMemory();
auto const onFrameStart = GetTickCount();
auto const onFrameStart = std::chrono::high_resolution_clock::now();
callOnFrame();
BroodwarImpl.setLastEventTime(GetTickCount() - onFrameStart);
auto const duration = std::chrono::high_resolution_clock::now() - onFrameStart;
BroodwarImpl.setLastEventTime((int)std::chrono::duration_cast<std::chrono::milliseconds>(duration).count());
processCommands();
}
else
Expand Down