Compare commits
6 commits
Author | SHA1 | Date | |
---|---|---|---|
Gered | 0702faf9b0 | ||
ec71d44c86 | |||
e450e25e99 | |||
688c611e91 | |||
544e825362 | |||
3737998f60 |
|
@ -14,7 +14,7 @@ If your project uses Maven, you can add a dependency to BWMirror:
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.gered</groupId>
|
<groupId>com.github.gered</groupId>
|
||||||
<artifactId>bwmirror</artifactId>
|
<artifactId>bwmirror</artifactId>
|
||||||
<version>2.7</version>
|
<version>2.7.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
<groupId>com.github.gered</groupId>
|
<groupId>com.github.gered</groupId>
|
||||||
<artifactId>bwmirror</artifactId>
|
<artifactId>bwmirror</artifactId>
|
||||||
<version>2.7</version>
|
<version>2.7.1</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>BWMirror</name>
|
<name>BWMirror</name>
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
package bwmirror.generator;
|
package bwmirror.generator;
|
||||||
|
|
||||||
|
import bwmirror.c.Param;
|
||||||
import bwmirror.util.Generic;
|
import bwmirror.util.Generic;
|
||||||
import bwmirror.util.PointerTest;
|
import bwmirror.util.PointerTest;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created with IntelliJ IDEA.
|
* Created with IntelliJ IDEA.
|
||||||
|
@ -19,7 +21,7 @@ public class JavaContext {
|
||||||
|
|
||||||
private List<String> valueTypes = Arrays.asList("Position", "TilePosition", "WalkPosition", "Color", "BWTA::RectangleArray<double>", "PositionOrUnit", "Point", "UnitCommand", "Integer", "Long", "Double", "Boolean", "int", "void", "double", "long", "Pair");
|
private List<String> valueTypes = Arrays.asList("Position", "TilePosition", "WalkPosition", "Color", "BWTA::RectangleArray<double>", "PositionOrUnit", "Point", "UnitCommand", "Integer", "Long", "Double", "Boolean", "int", "void", "double", "long", "Pair");
|
||||||
|
|
||||||
private List<String> constantTypes = Arrays.asList("UnitType", "TechType", "UpgradeType", "Race", "UnitCommand", "WeaponType", "Order", "GameType", "Error", "PlayerType", "UnitCommandType");
|
private List<String> constantTypes = Arrays.asList("UnitType", "TechType", "UpgradeType", "Race", "UnitCommand", "WeaponType", "Order", "GameType", "Error", "PlayerType", "UnitCommandType", "UnitSizeType", "DamageType", "ExplosionType");
|
||||||
|
|
||||||
private List<String> enumTypes = Arrays.asList("MouseButton", "Key", "bwapi.Text.Size.Enum", "bwapi.CoordinateType.Enum", "Text::Size::Enum", "CoordinateType::Enum");
|
private List<String> enumTypes = Arrays.asList("MouseButton", "Key", "bwapi.Text.Size.Enum", "bwapi.CoordinateType.Enum", "Text::Size::Enum", "CoordinateType::Enum");
|
||||||
|
|
||||||
|
@ -29,6 +31,8 @@ public class JavaContext {
|
||||||
|
|
||||||
private List<String> selfReturnTypes = Arrays.asList("BWTA::Polygon");
|
private List<String> selfReturnTypes = Arrays.asList("BWTA::Polygon");
|
||||||
|
|
||||||
|
private Map<String, Param> requiresExplicitDummyPredicate = new HashMap<>();
|
||||||
|
|
||||||
|
|
||||||
private String packageName = "bwapi";
|
private String packageName = "bwapi";
|
||||||
|
|
||||||
|
@ -39,6 +43,8 @@ public class JavaContext {
|
||||||
javaToCType.put("void", "void");
|
javaToCType.put("void", "void");
|
||||||
javaToCType.put("boolean", "jboolean");
|
javaToCType.put("boolean", "jboolean");
|
||||||
javaToCType.put("String", "jstring");
|
javaToCType.put("String", "jstring");
|
||||||
|
|
||||||
|
requiresExplicitDummyPredicate.put("getUnitsInWeaponRange", new Param("", "IdentityUnitFilter"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSelfReturnType(String clsName, String methodName) {
|
public boolean isSelfReturnType(String clsName, String methodName) {
|
||||||
|
@ -93,6 +99,10 @@ public class JavaContext {
|
||||||
return constantTypes.contains(javaType);
|
return constantTypes.contains(javaType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean needsExtraFilterParameter(String methodName) { return requiresExplicitDummyPredicate.containsKey(methodName); }
|
||||||
|
|
||||||
|
public Param getExtraFilterParameter(String methodName) { return requiresExplicitDummyPredicate.get(methodName); }
|
||||||
|
|
||||||
public String ptrCType() {
|
public String ptrCType() {
|
||||||
return "jobject";
|
return "jobject";
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,10 @@ 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("if (areTypeTablesInitialized) return;");
|
||||||
implementVariablesBind(declarationList);
|
implementVariablesBind(declarationList);
|
||||||
|
out.println("areTypeTablesInitialized = true;");
|
||||||
|
out.println("println(\"BWMirror C++ lookup tables are now initialized.\");");
|
||||||
out.println("}");
|
out.println("}");
|
||||||
out.println();
|
out.println();
|
||||||
}
|
}
|
||||||
|
@ -58,7 +61,7 @@ public class Bind {
|
||||||
"JNIEXPORT jobject JNICALL Java_" + context.getPackageName() + "_Mirror_getInternalGame(JNIEnv * env, jobject obj){\n" +
|
"JNIEXPORT jobject JNICALL Java_" + context.getPackageName() + "_Mirror_getInternalGame(JNIEnv * env, jobject obj){\n" +
|
||||||
" jclass gamecls = env->FindClass(\"Lbwapi/Game;\");\n" +
|
" jclass gamecls = env->FindClass(\"Lbwapi/Game;\");\n" +
|
||||||
" jmethodID getMethodID = env->GetStaticMethodID(gamecls, \"get\", \"(J)Lbwapi/Game;\");\n" +
|
" jmethodID getMethodID = env->GetStaticMethodID(gamecls, \"get\", \"(J)Lbwapi/Game;\");\n" +
|
||||||
" return env->CallStaticObjectMethod(gamecls, getMethodID, (long)BroodwarPtr);\n" +
|
" return env->CallStaticObjectMethod(gamecls, getMethodID, (jlong)BroodwarPtr);\n" +
|
||||||
"}\n"
|
"}\n"
|
||||||
);
|
);
|
||||||
out.println();
|
out.println();
|
||||||
|
@ -196,6 +199,7 @@ public class Bind {
|
||||||
out.println("getId = env->GetMethodID(cls,\"<init>\", \"(III)V\");");
|
out.println("getId = env->GetMethodID(cls,\"<init>\", \"(III)V\");");
|
||||||
} else {
|
} else {
|
||||||
out.println("getId = env->GetStaticMethodID(cls, \"get\", \"(J)L" + context.getPackageName() + "/" + cClass.getName() + ";\");");
|
out.println("getId = env->GetStaticMethodID(cls, \"get\", \"(J)L" + context.getPackageName() + "/" + cClass.getName() + ";\");");
|
||||||
|
out.println("table" + cClass.getName() + ".clear();");
|
||||||
}
|
}
|
||||||
printedIntro = true;
|
printedIntro = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,8 @@ public class TypeTable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out.println();
|
out.println();
|
||||||
|
out.println("bool areTypeTablesInitialized = false;");
|
||||||
|
out.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkTypeTable(CClass cClass) {
|
private void checkTypeTable(CClass cClass) {
|
||||||
|
|
|
@ -60,7 +60,12 @@ public class CallImplementer {
|
||||||
"#include <jni.h>\n" +
|
"#include <jni.h>\n" +
|
||||||
"#include <cstring>\n" +
|
"#include <cstring>\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"using namespace BWAPI;\n\n");
|
"using namespace BWAPI;\n\n" +
|
||||||
|
"\n" +
|
||||||
|
"bool IdentityUnitFilter(Unit u) {\n" +
|
||||||
|
"\treturn true;\n" +
|
||||||
|
"}\n" +
|
||||||
|
"\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void implementAccessObject(String clsName, String objName) {
|
private void implementAccessObject(String clsName, String objName) {
|
||||||
|
@ -382,7 +387,7 @@ public class CallImplementer {
|
||||||
out.println("*it;");
|
out.println("*it;");
|
||||||
}
|
}
|
||||||
if (!javaContext.isValueType(genericType)) {
|
if (!javaContext.isValueType(genericType)) {
|
||||||
out.println("jobject elem = env->CallStaticObjectMethod(elemClass, getMethodID, (long)elem_ptr) ;");
|
out.println("jobject elem = env->CallStaticObjectMethod(elemClass, getMethodID, (jlong)elem_ptr) ;");
|
||||||
} else {
|
} else {
|
||||||
out.println("jobject elem = env->NewObject(elemClass, elemConsID" + javaContext.implementCopyReturn(genericType, "elem_ptr") + ")" + SEMICOLON);
|
out.println("jobject elem = env->NewObject(elemClass, elemConsID" + javaContext.implementCopyReturn(genericType, "elem_ptr") + ")" + SEMICOLON);
|
||||||
}
|
}
|
||||||
|
@ -505,6 +510,8 @@ public class CallImplementer {
|
||||||
String genericType = convertToBWTA(Generic.extractGeneric(javaRetType));
|
String genericType = convertToBWTA(Generic.extractGeneric(javaRetType));
|
||||||
if (javaPackageName.equals("bwta") || (!genericType.equals("UnitType") && !genericType.equals("Position") && !genericType.equals("TilePosition"))){
|
if (javaPackageName.equals("bwta") || (!genericType.equals("UnitType") && !genericType.equals("Position") && !genericType.equals("TilePosition"))){
|
||||||
out.print(wrapInCCollection(genericType, javaMethodName) + " cresult = " + objectAccessor + (javaContext.isSelfReturnType(clsName, javaMethodName) ? "" : javaMethodName + "("));
|
out.print(wrapInCCollection(genericType, javaMethodName) + " cresult = " + objectAccessor + (javaContext.isSelfReturnType(clsName, javaMethodName) ? "" : javaMethodName + "("));
|
||||||
|
if (javaContext.needsExtraFilterParameter(javaMethodName))
|
||||||
|
params.add(javaContext.getExtraFilterParameter(javaMethodName));
|
||||||
implementRealParams(params);
|
implementRealParams(params);
|
||||||
if (!javaContext.isSelfReturnType(clsName, javaMethodName)) {
|
if (!javaContext.isSelfReturnType(clsName, javaMethodName)) {
|
||||||
out.print(")");
|
out.print(")");
|
||||||
|
|
|
@ -63,8 +63,8 @@ public class Mirror {
|
||||||
System.out.println(LOG_TAG + "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();
|
||||||
|
|
||||||
|
System.out.println("Extracting " + bwtaFilenames.size() + " BWTA2 files to ./bwapi-data/BWTA2");
|
||||||
for (String filename : bwtaFilenames) {
|
for (String filename : bwtaFilenames) {
|
||||||
System.out.println(LOG_TAG + "Extracting " + filename);
|
|
||||||
String outputFilename = "./" + filename;
|
String outputFilename = "./" + filename;
|
||||||
extractResourceFile(filename, outputFilename);
|
extractResourceFile(filename, outputFilename);
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,6 @@ public class Mirror {
|
||||||
if (!extractBwtaDataFiles())
|
if (!extractBwtaDataFiles())
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
|
|
||||||
System.out.println(LOG_TAG + "Initializing constants tables.");
|
|
||||||
initTables();
|
initTables();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +108,7 @@ public class Mirror {
|
||||||
/**
|
/**
|
||||||
* Initializes all BWAPI constant lookup tables.
|
* Initializes all BWAPI constant lookup tables.
|
||||||
*/
|
*/
|
||||||
private static native void initTables();
|
public static native void initTables();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes a connection to Broodwar, initializes the a {@link Game} object, and dispatches
|
* Initializes a connection to Broodwar, initializes the a {@link Game} object, and dispatches
|
||||||
|
|
Reference in a new issue