Skip to content

Commit a7f2f08

Browse files
committed
Removed more Windows-specific JNA calls
1 parent a078758 commit a7f2f08

File tree

4 files changed

+2
-56
lines changed

4 files changed

+2
-56
lines changed

src/main/java/bwapi/BWClient.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,9 @@ public void startGame(BWClientConfiguration gameConfiguration) {
119119
}
120120
}
121121
while (liveGameData.isInGame()) {
122-
long ticksBefore = Kernel32.INSTANCE.GetTickCount();
123-
124122
botWrapper.onFrame();
125123
performanceMetrics.getFlushSideEffects().time(() -> getGame().sideEffects.flushTo(liveGameData));
126124
performanceMetrics.getFrameDurationReceiveToSend().stopTiming();
127-
long ticksAfter = Kernel32.INSTANCE.GetTickCount();
128125

129126
client.sendFrameReceiveFrame();
130127
if (!client.isConnected()) {

src/main/java/bwapi/Client.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,10 @@ void sendFrameReceiveFrame() {
246246
}
247247
metrics.getCommunicationSendToSent().stopTiming();
248248
metrics.getFrameDurationReceiveToSent().stopTiming();
249-
metrics.getFrameDurationReceiveToSentGTC().stopTiming();
250249
if (bwClient.doTime()) {
251250
final int eventCount = clientData.gameData().getEventCount();
252251
metrics.getNumberOfEvents().record(eventCount);
253252
metrics.getNumberOfEventsTimesDurationReceiveToSent().record(eventCount * metrics.getFrameDurationReceiveToSent().getRunningTotal().getLast());
254-
metrics.getNumberOfEventsTimesDurationReceiveToSentGTC().record(eventCount * metrics.getFrameDurationReceiveToSentGTC().getRunningTotal().getLast());
255253
}
256254

257255
// Listen for BWAPI to indicate that a new frame is ready
@@ -279,13 +277,10 @@ void sendFrameReceiveFrame() {
279277
if (bwClient.doTime()) {
280278
metrics.getFrameDurationReceiveToSend().startTiming();
281279
metrics.getFrameDurationReceiveToSent().startTiming();
282-
metrics.getFrameDurationReceiveToSentGTC().startTiming();
283280
}
284281
metrics.getFrameDurationReceiveToReceive().stopTiming();
285-
metrics.getFrameDurationReceiveToReceiveGTC().stopTiming();
286282
if (bwClient.doTime()) {
287283
metrics.getFrameDurationReceiveToReceive().startTiming();
288-
metrics.getFrameDurationReceiveToReceiveGTC().startTiming();
289284
}
290285
}
291286

src/main/java/bwapi/PerformanceMetric.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public String toString() {
6161
private final String name;
6262
private long timeStarted = 0;
6363
private int interrupted = 0;
64-
private boolean usingGetTickCount = false;
6564

6665
private final RunningTotal runningTotal = new RunningTotal();
6766
private ArrayList<Threshold> thresholds = new ArrayList<>();
@@ -105,15 +104,6 @@ void timeIf(boolean condition, Runnable runnable) {
105104
}
106105
}
107106

108-
PerformanceMetric useGetTickCount() {
109-
usingGetTickCount = true;
110-
return this;
111-
}
112-
113-
long getNanoseconds() {
114-
return usingGetTickCount ? Kernel32.INSTANCE.GetTickCount() * 1000000L: System.nanoTime();
115-
}
116-
117107
/**
118108
* Manually start timing.
119109
* The next call to stopTiming() will record the duration in fractional milliseconds.
@@ -122,7 +112,7 @@ void startTiming() {
122112
if (timeStarted > 0) {
123113
++interrupted;
124114
}
125-
timeStarted = getNanoseconds();
115+
timeStarted = System.nanoTime();
126116
}
127117

128118

@@ -133,7 +123,7 @@ void startTiming() {
133123
void stopTiming() {
134124
if (timeStarted <= 0) return;
135125
// Use nanosecond resolution timer, but record in units of milliseconds.
136-
long timeEnded = getNanoseconds();
126+
long timeEnded = System.nanoTime();
137127
long timeDiff = timeEnded - timeStarted;
138128
timeStarted = 0;
139129
record(timeDiff / 1000000d);

src/main/java/bwapi/PerformanceMetrics.java

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,6 @@ public PerformanceMetric getFrameDurationReceiveToSent() {
2929
}
3030
private PerformanceMetric frameDurationReceiveToSent;
3131

32-
/**
33-
* Duration of a frame cycle originating at
34-
* the time when JBWAPI observes a new frame in shared memory.
35-
* Uses GetTickCount() instead of System.nanoRime()
36-
*/
37-
public PerformanceMetric getFrameDurationReceiveToSentGTC() {
38-
return frameDurationReceiveToSentGTC;
39-
}
40-
private PerformanceMetric frameDurationReceiveToSentGTC;
41-
4232
/**
4333
* Duration of a frame cycle originating at
4434
* the time when JBWAPI observes a new frame in shared memory.
@@ -48,16 +38,6 @@ public PerformanceMetric getFrameDurationReceiveToReceive() {
4838
}
4939
private PerformanceMetric frameDurationReceiveToReceive;
5040

51-
/**
52-
* Duration of a frame cycle originating at
53-
* the time when JBWAPI observes a new frame in shared memory.
54-
* Uses GetTickCount() instead of System.nanoRime()
55-
*/
56-
public PerformanceMetric getFrameDurationReceiveToReceiveGTC() {
57-
return frameDurationReceiveToReceiveGTC;
58-
}
59-
private PerformanceMetric frameDurationReceiveToReceiveGTC;
60-
6141
/**
6242
* Time spent copying game data from system pipe shared memory to a frame buffer.
6343
* Applicable only in asynchronous mode.
@@ -188,19 +168,6 @@ public PerformanceMetric getNumberOfEventsTimesDurationReceiveToSent() {
188168
}
189169
PerformanceMetric numberOfEventsTimesDurationReceiveToSent;
190170

191-
/**
192-
* The number of events sent by BWAPI each frame,
193-
* multiplied by the duration of time spent on that frame (receive-to-sent),
194-
* and using GetTickCount() instead of System.nanoTime().
195-
* Helps detect use of broken BWAPI 4.4 tournament modules, with respect to:
196-
* * - https://github.com/bwapi/bwapi/issues/860
197-
* * - https://github.com/davechurchill/StarcraftAITournamentManager/issues/42
198-
*/
199-
public PerformanceMetric getNumberOfEventsTimesDurationReceiveToSentGTC() {
200-
return numberOfEventsTimesDurationReceiveToSentGTC;
201-
}
202-
PerformanceMetric numberOfEventsTimesDurationReceiveToSentGTC;
203-
204171
private BWClientConfiguration configuration;
205172
private ArrayList<PerformanceMetric> performanceMetrics = new ArrayList<>();
206173

@@ -216,9 +183,7 @@ public void reset() {
216183
performanceMetrics.clear();
217184
frameDurationReceiveToSend = new PerformanceMetric(this, "Frame duration: After receiving 'frame ready' -> before sending 'frame done'", 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 85);
218185
frameDurationReceiveToSent = new PerformanceMetric(this, "Frame duration: After receiving 'frame ready' -> after sending 'frame done'", 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 85);
219-
frameDurationReceiveToSentGTC = new PerformanceMetric(this, "Frame duration: After receiving 'frame ready' -> after sending 'frame done' (Using GetTickCount())", 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 85).useGetTickCount();
220186
frameDurationReceiveToReceive = new PerformanceMetric(this, "Frame duration: After receiving 'frame ready' -> receiving next 'frame ready'", 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 85);
221-
frameDurationReceiveToReceiveGTC = new PerformanceMetric(this, "Frame duration: After receiving 'frame ready' -> receiving next 'frame ready' (Using GetTickCount())", 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 85).useGetTickCount();
222187
communicationSendToReceive = new PerformanceMetric(this, "BWAPI duration: Before sending 'frame done' -> After receiving 'frame ready'", 1, 3, 5, 10, 15, 20, 30);
223188
communicationSendToSent = new PerformanceMetric(this, "BWAPI duration: Before sending 'frame done' -> After sending 'frame done'", 1, 3, 5, 10, 15, 20, 30);
224189
communicationListenToReceive = new PerformanceMetric(this, "BWAPI duration: Before listening for 'frame ready' -> After receiving 'frame ready'", 1, 3, 5, 10, 15, 20, 30);
@@ -233,7 +198,6 @@ public void reset() {
233198
excessSleep = new PerformanceMetric(this, "Excess duration of client sleep", 1, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 85);
234199
numberOfEvents = new PerformanceMetric(this, "Number of events received from BWAPI", 1, 2, 3, 4, 5, 6, 8, 10, 15, 20);
235200
numberOfEventsTimesDurationReceiveToSent = new PerformanceMetric(this, "Number of events received from BWAPI, multiplied by the receive-to-sent duration of that frame", 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 85);
236-
numberOfEventsTimesDurationReceiveToSentGTC = new PerformanceMetric(this, "Number of events received from BWAPI, multiplied by the receive-to-sent duration of that frame (Using GetTickCount())", 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 85);
237201
}
238202

239203
void addMetric(PerformanceMetric performanceMetric) {

0 commit comments

Comments
 (0)