Skip to content

Commit a6fce10

Browse files
committed
compress javabwapilistener to one file
1 parent 60cb87d commit a6fce10

File tree

4 files changed

+39
-46
lines changed

4 files changed

+39
-46
lines changed

src/main/java/bwapi/Client.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
package bwapi;
22

3+
import com.sun.jna.Native;
34
import com.sun.jna.platform.win32.Kernel32;
5+
import com.sun.jna.win32.W32APIOptions;
46

7+
import java.io.FileNotFoundException;
8+
import java.io.IOException;
9+
import java.io.RandomAccessFile;
510
import java.nio.ByteBuffer;
611
import java.nio.ByteOrder;
712
import java.nio.CharBuffer;
@@ -65,6 +70,12 @@ public void update(EventHandler handler) throws Throwable {
6570
handler.operation(data.event(i));
6671
}
6772

73+
interface MappingKernel extends Kernel32 {
74+
MappingKernel INSTANCE = Native.loadLibrary(MappingKernel.class, W32APIOptions.DEFAULT_OPTIONS);
75+
76+
HANDLE OpenFileMapping(int desiredAccess, boolean inherit, String name);
77+
}
78+
6879
public interface EventHandler {
6980
void operation(GameData.Event event);
7081
}
@@ -113,6 +124,34 @@ public Shape(int type, int coordType, int x1, int y1, int x2, int y2, int extra1
113124
}
114125
}
115126

127+
class LittleEndianPipe {
128+
RandomAccessFile pipe;
129+
130+
LittleEndianPipe(String name, String mode) throws FileNotFoundException {
131+
pipe = new RandomAccessFile(name, mode);
132+
}
133+
134+
final int readByte() throws IOException {
135+
return pipe.readByte();
136+
}
137+
138+
final void writeByte(int b) throws IOException {
139+
pipe.writeByte(b);
140+
}
141+
142+
final int readInt() throws IOException {
143+
int b1 = readByte(), b2 = readByte(), b3 = readByte(), b4 = readByte();
144+
return (b4 << 24) | (b3 << 16) | (b2 << 8) | b1;
145+
}
146+
147+
final void writeInt(int i) throws IOException {
148+
writeByte(i >> 24);
149+
writeByte((i >> 16) & 0xff);
150+
writeByte((i >> 8) & 0xff);
151+
writeByte(i & 0xff);
152+
}
153+
}
154+
116155
public final class GameData {
117156
private static final int MetaOffset = 0;
118157
private static final int ForceOffset = 0x18;

src/main/java/bwapi/LittleEndianPipe.java

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/main/java/bwapi/MappingKernel.java

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/main/java/bwapi/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
The license for
44
- Client.java
5-
- LittleEndianPipe.java
6-
- MappingKernel.java
75

86
is LICENSE1 included in this directory
97

0 commit comments

Comments
 (0)