Compare commits

..

6 commits
2.7 ... master

Author SHA1 Message Date
Gered 0702faf9b0 version 2.7.1 2017-04-19 22:57:31 -04:00
gered ec71d44c86 update initial console output again... decided i like less afterall 2017-04-19 22:21:37 -04:00
gered e450e25e99 fix Unit.getUnitsInWeaponRange crashing due to bwapi bug
bwapi's implementation of getUnitsInWeaponRange does not check for a
null filter function, so it crashes if one is not passed in. we were
never passing one in here. to work around this for now, we'll just pass
in a dummy filter function that always returns true (so returns all
units in range always).
2017-04-19 21:52:06 -04:00
gered 688c611e91 add missing bwapi classes to jni generator constant types list 2017-04-19 07:18:43 -04:00
gered 544e825362 should be casting pointers passed to Java via JNI as jlong, not long
this was the only remaining place where this wasn't being done this way
2017-04-18 21:54:36 -04:00
gered 3737998f60 minor initTables adjustments 2017-04-18 21:49:28 -04:00
7 changed files with 31 additions and 9 deletions

View file

@ -14,7 +14,7 @@ If your project uses Maven, you can add a dependency to BWMirror:
<dependency>
<groupId>com.github.gered</groupId>
<artifactId>bwmirror</artifactId>
<version>2.7</version>
<version>2.7.1</version>
</dependency>
```

View file

@ -4,7 +4,7 @@
<groupId>com.github.gered</groupId>
<artifactId>bwmirror</artifactId>
<version>2.7</version>
<version>2.7.1</version>
<packaging>jar</packaging>
<name>BWMirror</name>

View file

@ -1,11 +1,13 @@
package bwmirror.generator;
import bwmirror.c.Param;
import bwmirror.util.Generic;
import bwmirror.util.PointerTest;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 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> 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");
@ -29,6 +31,8 @@ public class JavaContext {
private List<String> selfReturnTypes = Arrays.asList("BWTA::Polygon");
private Map<String, Param> requiresExplicitDummyPredicate = new HashMap<>();
private String packageName = "bwapi";
@ -39,6 +43,8 @@ public class JavaContext {
javaToCType.put("void", "void");
javaToCType.put("boolean", "jboolean");
javaToCType.put("String", "jstring");
requiresExplicitDummyPredicate.put("getUnitsInWeaponRange", new Param("", "IdentityUnitFilter"));
}
public boolean isSelfReturnType(String clsName, String methodName) {
@ -93,6 +99,10 @@ public class JavaContext {
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() {
return "jobject";
}

View file

@ -48,7 +48,10 @@ public class Bind {
private void implementMirror_initTables(List<CDeclaration> declarationList) {
out.println("JNIEXPORT void JNICALL Java_" + context.getPackageName() + "_Mirror_initTables(JNIEnv * env, jclass jclz){");
out.println("if (areTypeTablesInitialized) return;");
implementVariablesBind(declarationList);
out.println("areTypeTablesInitialized = true;");
out.println("println(\"BWMirror C++ lookup tables are now initialized.\");");
out.println("}");
out.println();
}
@ -58,7 +61,7 @@ public class Bind {
"JNIEXPORT jobject JNICALL Java_" + context.getPackageName() + "_Mirror_getInternalGame(JNIEnv * env, jobject obj){\n" +
" jclass gamecls = env->FindClass(\"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"
);
out.println();
@ -196,6 +199,7 @@ public class Bind {
out.println("getId = env->GetMethodID(cls,\"<init>\", \"(III)V\");");
} else {
out.println("getId = env->GetStaticMethodID(cls, \"get\", \"(J)L" + context.getPackageName() + "/" + cClass.getName() + ";\");");
out.println("table" + cClass.getName() + ".clear();");
}
printedIntro = true;
}

View file

@ -28,6 +28,8 @@ public class TypeTable {
}
}
out.println();
out.println("bool areTypeTablesInitialized = false;");
out.println();
}
private void checkTypeTable(CClass cClass) {

View file

@ -60,7 +60,12 @@ public class CallImplementer {
"#include <jni.h>\n" +
"#include <cstring>\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) {
@ -382,7 +387,7 @@ public class CallImplementer {
out.println("*it;");
}
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 {
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));
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 + "("));
if (javaContext.needsExtraFilterParameter(javaMethodName))
params.add(javaContext.getExtraFilterParameter(javaMethodName));
implementRealParams(params);
if (!javaContext.isSelfReturnType(clsName, javaMethodName)) {
out.print(")");

View file

@ -63,8 +63,8 @@ public class Mirror {
System.out.println(LOG_TAG + "Creating ./bwapi-data/BWTA2 directory");
new File("./bwapi-data/BWTA2").mkdirs();
System.out.println("Extracting " + bwtaFilenames.size() + " BWTA2 files to ./bwapi-data/BWTA2");
for (String filename : bwtaFilenames) {
System.out.println(LOG_TAG + "Extracting " + filename);
String outputFilename = "./" + filename;
extractResourceFile(filename, outputFilename);
}
@ -94,7 +94,6 @@ public class Mirror {
if (!extractBwtaDataFiles())
System.exit(1);
System.out.println(LOG_TAG + "Initializing constants tables.");
initTables();
}
@ -109,7 +108,7 @@ public class Mirror {
/**
* 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