Skip to content

Commit

Permalink
Merge 4c39104 into 61cd2ff
Browse files Browse the repository at this point in the history
  • Loading branch information
bmnielsen committed Apr 11, 2022
2 parents 61cd2ff + 4c39104 commit 8283b22
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
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

0 comments on commit 8283b22

Please sign in to comment.