prefix BWMirror console output so it stands out from BWAPI's output

This commit is contained in:
Gered 2017-04-14 17:51:38 -04:00
parent 4ab3980d24
commit 794678d46e
2 changed files with 20 additions and 18 deletions

View file

@ -48,7 +48,6 @@ public class Bind {
private void implementMirror_initTables(List<CDeclaration> declarationList) { private void implementMirror_initTables(List<CDeclaration> declarationList) {
out.println("JNIEXPORT void JNICALL Java_" + context.getPackageName() + "_Mirror_initTables(JNIEnv * env, jclass jclz){"); out.println("JNIEXPORT void JNICALL Java_" + context.getPackageName() + "_Mirror_initTables(JNIEnv * env, jclass jclz){");
out.println(" println(\"Initializing constants tables\");");
implementVariablesBind(declarationList); implementVariablesBind(declarationList);
out.println("}"); out.println("}");
out.println(); out.println();

View file

@ -9,6 +9,8 @@ import java.util.regex.Pattern;
public class Mirror { public class Mirror {
public static final String LOG_TAG = "[BWMirror] ";
private Game game; private Game game;
private AIModule module = new AIModule(); private AIModule module = new AIModule();
@ -34,16 +36,16 @@ public class Mirror {
private static boolean extractAndLoadNativeLibraries() { private static boolean extractAndLoadNativeLibraries() {
try { try {
System.out.println("Extracting bwapi_bridge.dll"); System.out.println(LOG_TAG + "Extracting bwapi_bridge.dll");
extractResourceFile("bwapi_bridge.dll", "./bwapi_bridge.dll"); extractResourceFile("bwapi_bridge.dll", "./bwapi_bridge.dll");
System.out.println("Extracting libgmp-10.dll"); System.out.println(LOG_TAG + "Extracting libgmp-10.dll");
extractResourceFile("libgmp-10.dll", "./libgmp-10.dll"); extractResourceFile("libgmp-10.dll", "./libgmp-10.dll");
System.out.println("Extracting libmpfr-4.dll"); System.out.println(LOG_TAG + "Extracting libmpfr-4.dll");
extractResourceFile("libmpfr-4.dll", "./libmpfr-4.dll"); extractResourceFile("libmpfr-4.dll", "./libmpfr-4.dll");
System.out.println("Loading native library bwapi_bridge.dll"); System.out.println(LOG_TAG + "Loading native library bwapi_bridge.dll");
System.load(new File("./bwapi_bridge.dll").getAbsolutePath()); System.load(new File("./bwapi_bridge.dll").getAbsolutePath());
} catch (Exception e) { } catch (Exception e) {
@ -58,11 +60,11 @@ public class Mirror {
try { try {
Collection<String> bwtaFilenames = ResourceList.getResources(Pattern.compile("bwapi\\-data/BWTA2/[a-zA-Z0-9]+\\.bwta")); Collection<String> bwtaFilenames = ResourceList.getResources(Pattern.compile("bwapi\\-data/BWTA2/[a-zA-Z0-9]+\\.bwta"));
System.out.println("Creating ./bwapi-data/BWTA2 directory"); System.out.println(LOG_TAG + "Creating ./bwapi-data/BWTA2 directory");
new File("./bwapi-data/BWTA2").mkdirs(); new File("./bwapi-data/BWTA2").mkdirs();
for (String filename : bwtaFilenames) { for (String filename : bwtaFilenames) {
System.out.println("Extracting " + filename); System.out.println(LOG_TAG + "Extracting " + filename);
String outputFilename = "./" + filename; String outputFilename = "./" + filename;
extractResourceFile(filename, outputFilename); extractResourceFile(filename, outputFilename);
} }
@ -92,6 +94,7 @@ public class Mirror {
if (!extractBwtaDataFiles()) if (!extractBwtaDataFiles())
System.exit(1); System.exit(1);
System.out.println(LOG_TAG + "Initializing constants tables.");
initTables(); initTables();
} }
@ -127,11 +130,11 @@ public class Mirror {
* if the connection is interrupted. * if the connection is interrupted.
*/ */
public void startGame(boolean returnOnMatchEnd) { public void startGame(boolean returnOnMatchEnd) {
System.out.println("Connecting to Broodwar..."); System.out.println(LOG_TAG + "Connecting to Broodwar...");
if (reconnect()) if (reconnect())
System.out.println("Connection successful, starting match..."); System.out.println(LOG_TAG + "Connection successful, starting match...");
else { else {
System.out.println("Connection attempt aborted."); System.out.println(LOG_TAG + "Connection attempt aborted.");
return; return;
} }
@ -140,17 +143,17 @@ public class Mirror {
boolean inGame = game.isInGame(); boolean inGame = game.isInGame();
boolean previouslyInGame = inGame; boolean previouslyInGame = inGame;
if (inGame) if (inGame)
System.out.println("Match already running."); System.out.println(LOG_TAG + "Match already running.");
while (true) { while (true) {
if (Thread.interrupted()) { if (Thread.interrupted()) {
System.out.println("Interrupted."); System.out.println(LOG_TAG + "Interrupted.");
break; break;
} }
if (!inGame) { if (!inGame) {
if (previouslyInGame) { if (previouslyInGame) {
System.out.println("Match ended."); System.out.println(LOG_TAG + "Match ended.");
if (returnOnMatchEnd) if (returnOnMatchEnd)
break; break;
} }
@ -159,14 +162,14 @@ public class Mirror {
} else { } else {
if (!previouslyInGame) if (!previouslyInGame)
System.out.println("Game ready!!!"); System.out.println(LOG_TAG + "Game ready!!!");
processGameEvents(); processGameEvents();
update(); update();
} }
if (!isConnected()) { if (!isConnected()) {
System.out.println("Reconnecting..."); System.out.println(LOG_TAG + "Reconnecting...");
reconnect(); reconnect();
} }
@ -174,15 +177,15 @@ public class Mirror {
inGame = game.isInGame(); inGame = game.isInGame();
} }
System.out.println("Finished."); System.out.println(LOG_TAG + "Finished.");
System.out.println("Disconnecting from Broodwar..."); System.out.println(LOG_TAG + "Disconnecting from Broodwar...");
if (isConnected()) if (isConnected())
disconnect(); disconnect();
game = null; game = null;
System.out.println("Returning..."); System.out.println(LOG_TAG + "Returning...");
} }
private boolean reconnect() { private boolean reconnect() {