diff --git a/bwmirror_v1_2.jar b/bwmirror_v1_2.jar index 3365170..d172eb1 100644 Binary files a/bwmirror_v1_2.jar and b/bwmirror_v1_2.jar differ diff --git a/bwmirror_v2_3.jar b/bwmirror_v2_3.jar new file mode 100644 index 0000000..98de1db Binary files /dev/null and b/bwmirror_v2_3.jar differ diff --git a/c4/impl.cpp b/c4/impl.cpp index d5b97cf..12ff5df 100644 --- a/c4/impl.cpp +++ b/c4/impl.cpp @@ -1610,6 +1610,10 @@ JNIEXPORT jstring JNICALL Java_bwapi_GameType_toString_1native(JNIEnv * env, job GameType* x_gameType = (GameType*)pointer; return env->NewStringUTF(x_gameType->toString().c_str()); } +JNIEXPORT jstring JNICALL Java_bwapi_Order_toString_1native(JNIEnv * env, jobject obj, jlong pointer){ +Order* x_order = (Order*)pointer; +return env->NewStringUTF(x_order->toString().c_str()); +} JNIEXPORT jint JNICALL Java_bwapi_Player_getID_1native(JNIEnv * env, jobject obj, jlong pointer){ Player x_player = (Player)pointer; return x_player->getID(); @@ -6270,6 +6274,49 @@ env->CallVoidMethod(result, addMethodID, keyElem, valueElem); } return result; } +JNIEXPORT jobject JNICALL Java_bwta_BWTA_getShortestPath__Lbwapi_TilePosition_2Lbwapi_TilePosition_2(JNIEnv * env, jclass jclz, jobject p_start, jobject p_end){ +TilePosition start((int)env->GetIntField(p_start, FindCachedField(env, env->GetObjectClass(p_start), "x", "I")), (int)env->GetIntField(p_start, FindCachedField(env, env->GetObjectClass(p_start), "y", "I"))); +TilePosition end((int)env->GetIntField(p_end, FindCachedField(env, env->GetObjectClass(p_end), "x", "I")), (int)env->GetIntField(p_end, FindCachedField(env, env->GetObjectClass(p_end), "y", "I"))); +std::vector cresult = BWTA::getShortestPath(start, end); +jclass listCls = FindCachedClass(env, "java/util/ArrayList"); +jmethodID listConsID = FindCachedMethod(env, listCls, "", "()V"); +jobject result = env->NewObject(listCls, listConsID); +jmethodID addMethodID = FindCachedMethod(env, listCls, "add", "(Ljava/lang/Object;)Z"); +jclass elemClass = FindCachedClass(env, "bwapi/TilePosition"); +jmethodID elemConsID = FindCachedMethod(env, elemClass, "", "(II)V"); +for(std::vector::const_iterator it = cresult.begin(); it != cresult.end(); it++ ){ +const TilePosition elem_ptr = *it; +jobject elem = env->NewObject(elemClass, elemConsID, elem_ptr.x, elem_ptr.y); +env->CallVoidMethod(result, addMethodID, elem); +} +return result; +} +JNIEXPORT jobject JNICALL Java_bwta_BWTA_getShortestPath__Lbwapi_TilePosition_2Ljava_util_List_2(JNIEnv * env, jclass jclz, jobject p_start, jobject p_targets){ +TilePosition start((int)env->GetIntField(p_start, FindCachedField(env, env->GetObjectClass(p_start), "x", "I")), (int)env->GetIntField(p_start, FindCachedField(env, env->GetObjectClass(p_start), "y", "I"))); +std::set targets; +jclass colClass = env->GetObjectClass(p_targets); +jmethodID sizeMethodId = FindCachedMethod(env, colClass, "size", "()I"); +jmethodID getMethodId = FindCachedMethod(env, colClass, "get", "(I)Ljava/lang/Object;"); +int size = (int)env->CallIntMethod(p_targets, sizeMethodId); +for( int i = 0; i < size; i++ ) { +jobject p_cObj = env->CallObjectMethod(p_targets,getMethodId); +TilePosition cObj((int)env->GetIntField(p_cObj, FindCachedField(env, env->GetObjectClass(p_cObj), "x", "I")), (int)env->GetIntField(p_cObj, FindCachedField(env, env->GetObjectClass(p_cObj), "y", "I"))); +targets.insert(cObj); +} +std::vector cresult = BWTA::getShortestPath(start, targets); +jclass listCls = FindCachedClass(env, "java/util/ArrayList"); +jmethodID listConsID = FindCachedMethod(env, listCls, "", "()V"); +jobject result = env->NewObject(listCls, listConsID); +jmethodID addMethodID = FindCachedMethod(env, listCls, "add", "(Ljava/lang/Object;)Z"); +jclass elemClass = FindCachedClass(env, "bwapi/TilePosition"); +jmethodID elemConsID = FindCachedMethod(env, elemClass, "", "(II)V"); +for(std::vector::const_iterator it = cresult.begin(); it != cresult.end(); it++ ){ +const TilePosition elem_ptr = *it; +jobject elem = env->NewObject(elemClass, elemConsID, elem_ptr.x, elem_ptr.y); +env->CallVoidMethod(result, addMethodID, elem); +} +return result; +} JNIEXPORT void JNICALL Java_bwta_BWTA_buildChokeNodes(JNIEnv * env, jclass jclz){ BWTA::buildChokeNodes(); } @@ -6320,6 +6367,38 @@ jmethodID retConsID = FindCachedMethod(env, retcls, "", "(II)V"); jobject result = env->NewObject(retcls, retConsID, cresult.x, cresult.y); return result; } +JNIEXPORT jobject JNICALL Java_bwta_Polygon_getHoles_1native(JNIEnv * env, jobject obj, jlong pointer){ +BWTA::Polygon* x_polygon = (BWTA::Polygon*)pointer; +std::vector cresult = x_polygon->getHoles(); +jclass listCls = FindCachedClass(env, "java/util/ArrayList"); +jmethodID listConsID = FindCachedMethod(env, listCls, "", "()V"); +jobject result = env->NewObject(listCls, listConsID); +jmethodID addMethodID = FindCachedMethod(env, listCls, "add", "(Ljava/lang/Object;)Z"); +jclass elemClass = FindCachedClass(env, "bwta/Polygon"); +jmethodID getMethodID = FindCachedMethodStatic(env, elemClass, "get", "(J)Lbwta/Polygon;"); +for(std::vector::const_iterator it = cresult.begin(); it != cresult.end(); it++ ){ +const BWTA::Polygon* elem_ptr = &*it; +jobject elem = env->CallStaticObjectMethod(elemClass, getMethodID, (long)elem_ptr) ; +env->CallVoidMethod(result, addMethodID, elem); +} +return result; +} +JNIEXPORT jobject JNICALL Java_bwta_Polygon_getPoints_1native(JNIEnv * env, jobject obj, jlong pointer){ +BWTA::Polygon* x_polygon = (BWTA::Polygon*)pointer; +std::vector cresult = *x_polygon; +jclass listCls = FindCachedClass(env, "java/util/ArrayList"); +jmethodID listConsID = FindCachedMethod(env, listCls, "", "()V"); +jobject result = env->NewObject(listCls, listConsID); +jmethodID addMethodID = FindCachedMethod(env, listCls, "add", "(Ljava/lang/Object;)Z"); +jclass elemClass = FindCachedClass(env, "bwapi/Position"); +jmethodID elemConsID = FindCachedMethod(env, elemClass, "", "(II)V"); +for(std::vector::const_iterator it = cresult.begin(); it != cresult.end(); it++ ){ +const Position elem_ptr = *it; +jobject elem = env->NewObject(elemClass, elemConsID, elem_ptr.x, elem_ptr.y); +env->CallVoidMethod(result, addMethodID, elem); +} +return result; +} JNIEXPORT jobject JNICALL Java_bwta_Region_getPolygon_1native(JNIEnv * env, jobject obj, jlong pointer){ BWTA::Region* x_region = (BWTA::Region*)pointer; jlong resptr = (jlong)&x_region->getPolygon(); diff --git a/compiled4/bwapi/Mirror.class b/compiled4/bwapi/Mirror.class index d682c78..6f0d314 100644 Binary files a/compiled4/bwapi/Mirror.class and b/compiled4/bwapi/Mirror.class differ diff --git a/compiled4/bwapi/Order.class b/compiled4/bwapi/Order.class index d90849b..021ccae 100644 Binary files a/compiled4/bwapi/Order.class and b/compiled4/bwapi/Order.class differ diff --git a/compiled4/bwta/BWTA.class b/compiled4/bwta/BWTA.class index a693b60..3b810fd 100644 Binary files a/compiled4/bwta/BWTA.class and b/compiled4/bwta/BWTA.class differ diff --git a/compiled4/bwta/Polygon.class b/compiled4/bwta/Polygon.class index df2cfd6..311c67b 100644 Binary files a/compiled4/bwta/Polygon.class and b/compiled4/bwta/Polygon.class differ diff --git a/concat_header4.h b/concat_header4.h index 1a1ea15..4579684 100644 --- a/concat_header4.h +++ b/concat_header4.h @@ -2287,6 +2287,14 @@ extern "C" { #ifdef __cplusplus extern "C" { #endif +/* + * Class: bwapi_Order + * Method: toString_native + * Signature: (J)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_bwapi_Order_toString_1native + (JNIEnv *, jobject, jlong); + #ifdef __cplusplus } #endif @@ -9291,6 +9299,22 @@ JNIEXPORT jobject JNICALL Java_bwta_BWTA_getNearestTilePosition JNIEXPORT jobject JNICALL Java_bwta_BWTA_getGroundDistances (JNIEnv *, jclass, jobject, jobject); +/* + * Class: bwta_BWTA + * Method: getShortestPath + * Signature: (Lbwapi/TilePosition;Lbwapi/TilePosition;)Ljava/util/List; + */ +JNIEXPORT jobject JNICALL Java_bwta_BWTA_getShortestPath__Lbwapi_TilePosition_2Lbwapi_TilePosition_2 + (JNIEnv *, jclass, jobject, jobject); + +/* + * Class: bwta_BWTA + * Method: getShortestPath + * Signature: (Lbwapi/TilePosition;Ljava/util/List;)Ljava/util/List; + */ +JNIEXPORT jobject JNICALL Java_bwta_BWTA_getShortestPath__Lbwapi_TilePosition_2Ljava_util_List_2 + (JNIEnv *, jclass, jobject, jobject); + /* * Class: bwta_BWTA * Method: buildChokeNodes @@ -9385,6 +9409,22 @@ JNIEXPORT jboolean JNICALL Java_bwta_Polygon_isInside_1native JNIEXPORT jobject JNICALL Java_bwta_Polygon_getNearestPoint_1native (JNIEnv *, jobject, jlong, jobject); +/* + * Class: bwta_Polygon + * Method: getHoles_native + * Signature: (J)Ljava/util/List; + */ +JNIEXPORT jobject JNICALL Java_bwta_Polygon_getHoles_1native + (JNIEnv *, jobject, jlong); + +/* + * Class: bwta_Polygon + * Method: getPoints_native + * Signature: (J)Ljava/util/List; + */ +JNIEXPORT jobject JNICALL Java_bwta_Polygon_getPoints_1native + (JNIEnv *, jobject, jlong); + #ifdef __cplusplus } #endif diff --git a/generated/bwapi/Mirror.java b/generated/bwapi/Mirror.java index b56b035..67239d3 100644 --- a/generated/bwapi/Mirror.java +++ b/generated/bwapi/Mirror.java @@ -56,7 +56,7 @@ public class Mirror { private static final boolean EXTRACT_JAR = true; - private static final String VERSION = "2_2"; + private static final String VERSION = "2_3"; static { String arch = System.getProperty("os.arch"); diff --git a/generated/bwapi/Order.java b/generated/bwapi/Order.java index 1641c59..7a2b16d 100644 --- a/generated/bwapi/Order.java +++ b/generated/bwapi/Order.java @@ -9,6 +9,10 @@ import java.util.List; public class Order { + public String toString() { + return toString_native(pointer); + } + public static Order Die; public static Order Stop; @@ -342,5 +346,7 @@ public class Order { private long pointer; + private native String toString_native(long pointer); + } diff --git a/generated/bwta/BWTA.java b/generated/bwta/BWTA.java index 33c28e9..4f1b857 100644 --- a/generated/bwta/BWTA.java +++ b/generated/bwta/BWTA.java @@ -72,6 +72,10 @@ public class BWTA { public static native Map getGroundDistances(TilePosition start, List targets); + public static native List getShortestPath(TilePosition start, TilePosition end); + + public static native List getShortestPath(TilePosition start, List targets); + public static native void buildChokeNodes(); public static native int getGroundDistance2(TilePosition start, TilePosition end); diff --git a/generated/bwta/Polygon.java b/generated/bwta/Polygon.java index cf8f932..024722b 100644 --- a/generated/bwta/Polygon.java +++ b/generated/bwta/Polygon.java @@ -34,6 +34,14 @@ public class Polygon { return getNearestPoint_native(pointer, p); } + public List getHoles() { + return getHoles_native(pointer); + } + + public List getPoints() { + return getPoints_native(pointer); + } + private static Map instances = new HashMap(); @@ -65,5 +73,9 @@ public class Polygon { private native Position getNearestPoint_native(long pointer, Position p); + private native List getHoles_native(long pointer); + + private native List getPoints_native(long pointer); + } diff --git a/headers4/bwapi_Order.h b/headers4/bwapi_Order.h index bff8b01..f6a62a4 100644 --- a/headers4/bwapi_Order.h +++ b/headers4/bwapi_Order.h @@ -7,6 +7,14 @@ #ifdef __cplusplus extern "C" { #endif +/* + * Class: bwapi_Order + * Method: toString_native + * Signature: (J)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_bwapi_Order_toString_1native + (JNIEnv *, jobject, jlong); + #ifdef __cplusplus } #endif diff --git a/headers4/bwta_BWTA.h b/headers4/bwta_BWTA.h index bb0f8d7..ee8428e 100644 --- a/headers4/bwta_BWTA.h +++ b/headers4/bwta_BWTA.h @@ -239,6 +239,22 @@ JNIEXPORT jobject JNICALL Java_bwta_BWTA_getNearestTilePosition JNIEXPORT jobject JNICALL Java_bwta_BWTA_getGroundDistances (JNIEnv *, jclass, jobject, jobject); +/* + * Class: bwta_BWTA + * Method: getShortestPath + * Signature: (Lbwapi/TilePosition;Lbwapi/TilePosition;)Ljava/util/List; + */ +JNIEXPORT jobject JNICALL Java_bwta_BWTA_getShortestPath__Lbwapi_TilePosition_2Lbwapi_TilePosition_2 + (JNIEnv *, jclass, jobject, jobject); + +/* + * Class: bwta_BWTA + * Method: getShortestPath + * Signature: (Lbwapi/TilePosition;Ljava/util/List;)Ljava/util/List; + */ +JNIEXPORT jobject JNICALL Java_bwta_BWTA_getShortestPath__Lbwapi_TilePosition_2Ljava_util_List_2 + (JNIEnv *, jclass, jobject, jobject); + /* * Class: bwta_BWTA * Method: buildChokeNodes diff --git a/headers4/bwta_Polygon.h b/headers4/bwta_Polygon.h index 80e661b..acbb470 100644 --- a/headers4/bwta_Polygon.h +++ b/headers4/bwta_Polygon.h @@ -47,6 +47,22 @@ JNIEXPORT jboolean JNICALL Java_bwta_Polygon_isInside_1native JNIEXPORT jobject JNICALL Java_bwta_Polygon_getNearestPoint_1native (JNIEnv *, jobject, jlong, jobject); +/* + * Class: bwta_Polygon + * Method: getHoles_native + * Signature: (J)Ljava/util/List; + */ +JNIEXPORT jobject JNICALL Java_bwta_Polygon_getHoles_1native + (JNIEnv *, jobject, jlong); + +/* + * Class: bwta_Polygon + * Method: getPoints_native + * Signature: (J)Ljava/util/List; + */ +JNIEXPORT jobject JNICALL Java_bwta_Polygon_getPoints_1native + (JNIEnv *, jobject, jlong); + #ifdef __cplusplus } #endif diff --git a/manual-bwapi4/Mirror.java b/manual-bwapi4/Mirror.java index b56b035..67239d3 100644 --- a/manual-bwapi4/Mirror.java +++ b/manual-bwapi4/Mirror.java @@ -56,7 +56,7 @@ public class Mirror { private static final boolean EXTRACT_JAR = true; - private static final String VERSION = "2_2"; + private static final String VERSION = "2_3"; static { String arch = System.getProperty("os.arch"); diff --git a/out/production/InvokeGenerator/generator/CJavaPipeline$1.class b/out/production/InvokeGenerator/generator/CJavaPipeline$1.class index 2d2f755..0bd9819 100644 Binary files a/out/production/InvokeGenerator/generator/CJavaPipeline$1.class and b/out/production/InvokeGenerator/generator/CJavaPipeline$1.class differ diff --git a/out/production/InvokeGenerator/generator/CJavaPipeline$2.class b/out/production/InvokeGenerator/generator/CJavaPipeline$2.class index 1fd7853..679cd11 100644 Binary files a/out/production/InvokeGenerator/generator/CJavaPipeline$2.class and b/out/production/InvokeGenerator/generator/CJavaPipeline$2.class differ diff --git a/out/production/InvokeGenerator/generator/CJavaPipeline.class b/out/production/InvokeGenerator/generator/CJavaPipeline.class index 7cd90e1..17a193c 100644 Binary files a/out/production/InvokeGenerator/generator/CJavaPipeline.class and b/out/production/InvokeGenerator/generator/CJavaPipeline.class differ diff --git a/out/production/InvokeGenerator/generator/JavaContext.class b/out/production/InvokeGenerator/generator/JavaContext.class index 389c0e6..da8293a 100644 Binary files a/out/production/InvokeGenerator/generator/JavaContext.class and b/out/production/InvokeGenerator/generator/JavaContext.class differ diff --git a/out/production/InvokeGenerator/generator/MirrorContext.class b/out/production/InvokeGenerator/generator/MirrorContext.class index afefdc5..1fe310a 100644 Binary files a/out/production/InvokeGenerator/generator/MirrorContext.class and b/out/production/InvokeGenerator/generator/MirrorContext.class differ diff --git a/out/production/InvokeGenerator/generator/ccalls/CallImplementer.class b/out/production/InvokeGenerator/generator/ccalls/CallImplementer.class index 045a76e..505a27c 100644 Binary files a/out/production/InvokeGenerator/generator/ccalls/CallImplementer.class and b/out/production/InvokeGenerator/generator/ccalls/CallImplementer.class differ diff --git a/out/production/InvokeGenerator/impl/CApiParser.class b/out/production/InvokeGenerator/impl/CApiParser.class index a18c1d8..ead4382 100644 Binary files a/out/production/InvokeGenerator/impl/CApiParser.class and b/out/production/InvokeGenerator/impl/CApiParser.class differ diff --git a/out/production/InvokeGenerator/impl/Function.class b/out/production/InvokeGenerator/impl/Function.class index aa69493..6747bc6 100644 Binary files a/out/production/InvokeGenerator/impl/Function.class and b/out/production/InvokeGenerator/impl/Function.class differ diff --git a/out/production/InvokeGenerator/test/api/TestBot1$1.class b/out/production/InvokeGenerator/test/api/TestBot1$1.class index 6011e6e..e1222aa 100644 Binary files a/out/production/InvokeGenerator/test/api/TestBot1$1.class and b/out/production/InvokeGenerator/test/api/TestBot1$1.class differ diff --git a/out/production/InvokeGenerator/test/api/TestBot1.class b/out/production/InvokeGenerator/test/api/TestBot1.class index e7e007b..ad7107b 100644 Binary files a/out/production/InvokeGenerator/test/api/TestBot1.class and b/out/production/InvokeGenerator/test/api/TestBot1.class differ diff --git a/out/production/InvokeGenerator/util/PointerTest.class b/out/production/InvokeGenerator/util/PointerTest.class index 63e8400..1a9eb7c 100644 Binary files a/out/production/InvokeGenerator/util/PointerTest.class and b/out/production/InvokeGenerator/util/PointerTest.class differ diff --git a/src/api/DefaultEventListener.java b/src/api/DefaultEventListener.java new file mode 100644 index 0000000..571512b --- /dev/null +++ b/src/api/DefaultEventListener.java @@ -0,0 +1,63 @@ +package api; + +import c.CClass; +import c.CDeclaration; +import c.Param; +import generator.Generator; +import generator.MirrorContext; +import generator.PackageProcessOptions; +import impl.Function; + +import java.util.ArrayList; +import java.util.List; + +/** + * User: PC + * Date: 19. 4. 2015 + * Time: 16:06 + */ +public class DefaultEventListener implements GeneratorEventListener { + @Override + public void onPackageProcessingStart(PackageProcessOptions packageProcessOptions, MirrorContext mirrorContext, Generator generator, List cDeclarationList) { + + } + + @Override + public void onCDeclarationRead(PackageProcessOptions packageProcessOptions, CDeclaration cDeclaration) { + } + + @Override + public void onPackageProcessingEnd(PackageProcessOptions packageProcessOptions) { + + } + + @Override + public void beforeManual() { + + } + + @Override + public void afterManual() { + + } + + @Override + public void beforeCompile() { + + } + + @Override + public void afterCompile() { + + } + + @Override + public void beforeHeaders() { + + } + + @Override + public void afterHeaders() { + + } +} diff --git a/src/api/GeneratorEventListener.java b/src/api/GeneratorEventListener.java new file mode 100644 index 0000000..deb6582 --- /dev/null +++ b/src/api/GeneratorEventListener.java @@ -0,0 +1,38 @@ +package api; + +import c.CDeclaration; +import generator.Generator; +import generator.MirrorContext; +import generator.PackageProcessOptions; + +import java.util.List; + +/** + * User: PC + * Date: 19. 4. 2015 + * Time: 16:00 + */ +public interface GeneratorEventListener { + + + public void onPackageProcessingStart(PackageProcessOptions packageProcessOptions, MirrorContext mirrorContext, Generator generator, List cDeclarationList); + + public void onCDeclarationRead(PackageProcessOptions packageProcessOptions, CDeclaration cDeclaration); + + public void onPackageProcessingEnd(PackageProcessOptions packageProcessOptions); + + public void beforeManual(); + + public void afterManual(); + + public void beforeCompile(); + + public void afterCompile(); + + public void beforeHeaders(); + + public void afterHeaders(); + + + +} diff --git a/src/generator/CJavaPipeline.java b/src/generator/CJavaPipeline.java index 7fea663..fbdc335 100644 --- a/src/generator/CJavaPipeline.java +++ b/src/generator/CJavaPipeline.java @@ -1,5 +1,7 @@ package generator; +import api.DefaultEventListener; +import api.GeneratorEventListener; import c.CClass; import c.CDeclaration; import c.CEnum; @@ -11,6 +13,7 @@ import generator.c.TypeTable; import generator.ccalls.CallImplementer; import impl.CApiParser; import impl.Clazz; +import inject.GetPolygonPointsInjector; import util.FileUtils; import java.io.*; @@ -44,6 +47,8 @@ public class CJavaPipeline { private static final HashMap superClasses = new HashMap<>(); + private GeneratorEventListener listener = new DefaultEventListener(); + static { superClasses.put("Unit", "PositionedObject"); superClasses.put("Region", "CenteredObject"); @@ -51,6 +56,10 @@ public class CJavaPipeline { superClasses.put("BaseLocation", "PositionedObject"); } + public CJavaPipeline() { + listener = new GetPolygonPointsInjector(); + } + public void run(PackageProcessOptions[] packages, Properties processingOptions) { /** Init @@ -96,6 +105,9 @@ public class CJavaPipeline { if (ignoredClasses.contains(cDeclaration.getName())) { continue; } + + listener.onCDeclarationRead(pkg, cDeclaration); + if (cDeclaration.getDeclType().equals(DeclarationType.CLASS)) { generator.addClass((CClass) cDeclaration); } else if (cDeclaration.getDeclType().equals(DeclarationType.ENUM)) { diff --git a/src/generator/JavaContext.java b/src/generator/JavaContext.java index 4361da3..8181a6a 100644 --- a/src/generator/JavaContext.java +++ b/src/generator/JavaContext.java @@ -26,6 +26,8 @@ public class JavaContext { private List bwtaClasses = Arrays.asList("Chokepoint", "Region", "RectangleArray", "Polygon", "BaseLocation"); + private List selfReturnTypes = Arrays.asList("BWTA::Polygon"); + private String packageName = "bwapi"; @@ -38,6 +40,10 @@ public class JavaContext { javaToCType.put("String", "jstring"); } + public boolean isSelfReturnType(String clsName, String methodName){ + return packageName.equals("bwta") && selfReturnTypes.contains(clsName) && methodName.equals("getPoints"); + } + public String getPackageName() { return packageName; } diff --git a/src/generator/MirrorContext.java b/src/generator/MirrorContext.java index fa73c8a..d9ffaa7 100644 --- a/src/generator/MirrorContext.java +++ b/src/generator/MirrorContext.java @@ -45,7 +45,7 @@ public class MirrorContext { } private boolean isCollection(String cType) { - return cType.startsWith("set<"); + return cType.startsWith("set<") || cType.startsWith("vector<"); } private boolean isMap(String cType) { diff --git a/src/generator/ccalls/CallImplementer.java b/src/generator/ccalls/CallImplementer.java index a4d4615..17df6b6 100644 --- a/src/generator/ccalls/CallImplementer.java +++ b/src/generator/ccalls/CallImplementer.java @@ -101,7 +101,7 @@ public class CallImplementer { if (!javaContext.isValueType(genericType)) { out.println("jobject jobj = env->CallObjectMethod(" + paramName + ",getMethodId);"); - } else{ + } else { out.println("jobject p_cObj = env->CallObjectMethod(" + paramName + ",getMethodId);"); out.println(javaContext.copyJavaObjectToC(genericType, "cObj")); } @@ -110,8 +110,7 @@ public class CallImplementer { if (!javaContext.isValueType(genericType)) { out.print("(" + PointerTest.test(genericType) + ")"); out.print("env->GetLongField(jobj, FindCachedField(env, env->GetObjectClass(jobj), \"pointer\", \"J\"))"); - } - else{ + } else { out.print("cObj"); } out.println(");"); @@ -185,15 +184,24 @@ public class CallImplementer { } - - private String wrapInCCollection(String genericType) { + private String wrapInCCollection(String genericType, String javaMethodName) { String buffer = ""; boolean isBWAPI4Collection = !CJavaPipeline.isBWAPI3() && !genericType.startsWith("BWTA::"); if (!isBWAPI4Collection) { - buffer += "std::set<"; + if(javaMethodName.equals("getHoles")){ + buffer += "std::vector<"; + } + else{ + buffer += "std::set<"; + } } - if (!javaContext.isConstantTye(genericType) && !javaContext.isValueType(genericType)) { - buffer += (PointerTest.test(genericType)); + if (!javaContext.isConstantTye(genericType) && !javaContext.isValueType(genericType) ) { + if(!javaMethodName.equals("getHoles")){ + buffer += (PointerTest.test(genericType)); + } + else{ + buffer += genericType; + } } if (!isBWAPI4Collection) { buffer += ">"; @@ -201,7 +209,10 @@ public class CallImplementer { buffer += "set"; } - if(buffer.equals("set") && !CJavaPipeline.isBWAPI3()){ + if (buffer.equals("set") && !CJavaPipeline.isBWAPI3()) { + if(javaContext.getPackageName().equals("bwta")){ + return "std::vector<" + genericType + ">"; + } return "SetContainer<" + genericType + ">"; } @@ -325,7 +336,7 @@ public class CallImplementer { * * @param genericType */ - private void implementCollectionReturn(String genericType) { + private void implementCollectionReturn(String genericType, String javaMethodName) { String classGenericType = genericType; if (classGenericType.contains("::")) { classGenericType = classGenericType.substring(classGenericType.lastIndexOf(":") + 1); @@ -346,7 +357,7 @@ public class CallImplementer { //the for loop - out.println("for(" + wrapInCCollection(genericType) + "::const_iterator it = cresult.begin(); it != cresult.end(); it++ ){"); + out.println("for(" + wrapInCCollection(genericType, javaMethodName) + "::const_iterator it = cresult.begin(); it != cresult.end(); it++ ){"); out.print("const " + genericType); if (!javaContext.isValueType(genericType)) { out.print(PointerTest.test(genericType, false)); @@ -355,6 +366,9 @@ public class CallImplementer { if (javaContext.isConstantTye(genericType)) { out.println("table" + genericType + ".find((*it).getID())->second;"); } else { + if(javaMethodName.equals("getHoles")){ + out.print("&"); + } out.println("*it;"); } if (!javaContext.isValueType(genericType)) { @@ -370,8 +384,8 @@ public class CallImplementer { } - private void implementPairReturn(String javaPairType){ - String [] pair = Generic.extractPair(javaPairType); + private void implementPairReturn(String javaPairType) { + String[] pair = Generic.extractPair(javaPairType); String cFirst = pair[0]; String cSecond = pair[1]; @@ -423,7 +437,7 @@ public class CallImplementer { } - //first dynamic part + //first dynamic part out.print("const " + cFirst); if (!javaContext.isValueType(javaFirstType)) { out.print(PointerTest.test(cFirst, false)); @@ -459,25 +473,35 @@ public class CallImplementer { } else { out.println("jobject second = env->NewObject(secondElemClass, secondElemConsID" + javaContext.implementCopyReturn(cSecond, "second_elem_ptr") + ")" + SEMICOLON); } - - //for loop ends here + + //for loop ends here } - - + + private void implementMethodReturn(String objName, String javaMethodName, List params, String cReturnType, String javaRetType, String javaPackageName, String clsName, boolean isStatic) { - String objectAccessor = VARIABLE_PREFIX + objName + (javaContext.isValueType(clsName) ? "." : "->"); + String objectAccessor = VARIABLE_PREFIX + objName; if (isStatic) { objectAccessor = clsName + "::"; + } else { + if (!javaContext.isSelfReturnType(clsName, javaMethodName)) { + objectAccessor += (javaContext.isValueType(clsName) ? "." : "->"); + } + else{ + objectAccessor = "*" + objectAccessor; + } } //case 1 - method returns a collection type, this requires a LOT of work, so get the std::set and proceed in implementCollectionReturn if (javaContext.isCollection(javaRetType)) { String genericType = convertToBWTA(Generic.extractGeneric(javaRetType)); - out.print(wrapInCCollection(genericType) + " cresult = " + objectAccessor + javaMethodName + "("); + out.print(wrapInCCollection(genericType, javaMethodName) + " cresult = " + objectAccessor + (javaContext.isSelfReturnType(clsName, javaMethodName) ? "" : javaMethodName + "(")); implementRealParams(params); - out.println(")" + SEMICOLON); - implementCollectionReturn(genericType); + if (!javaContext.isSelfReturnType(clsName, javaMethodName)) { + out.print(")"); + } + out.println(SEMICOLON); + implementCollectionReturn(genericType, javaMethodName); return; } @@ -508,7 +532,7 @@ public class CallImplementer { out.print(")"); out.println(SEMICOLON); //handle pairs - if(javaRetType.equals("Pair")){ + if (javaRetType.equals("Pair")) { implementPairReturn(fullReturnType); } diff --git a/src/impl/CApiParser.java b/src/impl/CApiParser.java index 42e674b..f905962 100644 --- a/src/impl/CApiParser.java +++ b/src/impl/CApiParser.java @@ -43,12 +43,12 @@ public class CApiParser { //String FUNC_REGEX = "^(\\s*)(virtual)?\\s(BWAPI::)?([\\w\\*]+)\\s([\\w\\*]+)\\((.*)\\)((\\sconst)?\\s=\\s0;)?"; //String FUNC_REGEX = "^(\\s*)(virtual)?\\s((BWAPI)|(std)::)?([\\w\\*]+)\\s([\\w\\*]+)\\((.*)\\)((\\sconst)?\\s=\\s0;)?"; // 1 2 3 4 56 7 891011 12 13 14 15 16 17 18 19 20 - String FUNC_REGEX = "^(\\s*)(virtual\\s)?(const\\s)?(static\\s)?((BWAPI::)|(std::))?((((pair)|(set)|(map)|(SetContainer))<(\\s*(BWAPI::)?\\w+\\*?\\s*)(\\s*,\\s*\\w+\\s*)?>)|([\\w\\*]+))&?\\s+(&?[\\w\\*]+)\\((.*)\\)(\\s*const)?(\\s*=\\s0)?(;)?\\s*"; + String FUNC_REGEX = "^(\\s*)(virtual\\s)?(const\\s)?(static\\s)?((BWAPI::)|(std::))?((((pair)|(vector)|(set)|(map)|(SetContainer))<(\\s*(BWAPI::)?\\w+\\*?\\s*)(\\s*,\\s*\\w+\\s*)?>)|([\\w\\*]+))&?\\s+(&?[\\w\\*]+)\\((.*)\\)(\\s*const)?(\\s*=\\s0)?(;)?\\s*"; static final int F_REGEX_STATIC = 4; static final int F_REGEX_RETURN_TYPE = 8; - static final int F_REGEX_NAME = 19; - static final int F_REGEX_PARAMS = 20; + static final int F_REGEX_NAME = 20; + static final int F_REGEX_PARAMS = 21; String ENUM_VALUE_REGEX = "^(\\s*)(\\w+)(\\s*=\\s*(0x)?([0-9A-Fa-f]+))?\\s*[\\,;]"; @@ -504,7 +504,7 @@ public class CApiParser { Clazz clz = new Clazz(clazzName); if(!CJavaPipeline.isBWAPI3()){ - if(clazzName.endsWith("Type") || clazzName.equals("Error") || clazzName.equals("Race")){ + if(clazzName.endsWith("Type") || clazzName.equals("Error") || clazzName.equals("Race") || clazzName.equals("Order")){ Function function = new Function(); function.name = "toString"; function.returnType = "string"; diff --git a/src/impl/Function.java b/src/impl/Function.java index 423be29..8d5198b 100644 --- a/src/impl/Function.java +++ b/src/impl/Function.java @@ -37,6 +37,16 @@ public class Function implements Method { return f; } + Function() { + } + + public Function(String name, String returnType, boolean isStatic, ArrayList args) { + this.name = name; + this.returnType = returnType; + this.isStatic = isStatic; + this.args = args; + } + @Override public String getType() { return returnType; diff --git a/src/inject/GetPolygonPointsInjector.java b/src/inject/GetPolygonPointsInjector.java new file mode 100644 index 0000000..3f6589b --- /dev/null +++ b/src/inject/GetPolygonPointsInjector.java @@ -0,0 +1,24 @@ +package inject; + +import api.DefaultEventListener; +import c.CClass; +import c.CDeclaration; +import c.Param; +import generator.PackageProcessOptions; +import impl.Function; + +import java.util.ArrayList; + +public class GetPolygonPointsInjector extends DefaultEventListener { + + + @Override + public void onCDeclarationRead(PackageProcessOptions packageProcessOptions, CDeclaration cDeclaration) { + if (cDeclaration.getName().equals("Polygon") && packageProcessOptions.packageName.equals("bwta")) { + CClass cClass = (CClass) cDeclaration; + + Function getPolygons = new Function("getPoints", "set", false, new ArrayList()); + cClass.getFields().add(getPolygons); + } + } +} \ No newline at end of file diff --git a/src/test/api/TestBot1.java b/src/test/api/TestBot1.java index 9e50c2e..ec72421 100644 --- a/src/test/api/TestBot1.java +++ b/src/test/api/TestBot1.java @@ -5,9 +5,9 @@ import bwapi.Text.Size.Enum; import bwta.BWTA; import bwta.BaseLocation; import bwta.Chokepoint; -import util.Pair; +import bwta.Polygon; -import java.io.File; +import java.util.List; /** * User: PC @@ -36,11 +36,16 @@ public class TestBot1 { mirror.getGame().enableFlag(bwapi.Flag.Enum.UserInput.getValue()); } + @Override + public void onEnd(boolean b) { + System.out.println("Ended"); + //System.exit(0); + } + @Override public void onFrame() { Game game = mirror.getGame(); Player self = game.self(); - UnitType.Protoss_Archon.whatBuilds(); game.drawBoxScreen(0, 0, 100, 100, Color.Red, true); @@ -49,17 +54,17 @@ public class TestBot1 { StringBuilder units = new StringBuilder("My units:\n"); - for(BaseLocation baseLocation : BWTA.getBaseLocations()){ + for (BaseLocation baseLocation : BWTA.getBaseLocations()) { //System.out.println(baseLocation.getPosition()); //System.out.println(baseLocation.getTilePosition()); } - for(Chokepoint chokepoint : BWTA.getChokepoints()){ + for (Chokepoint chokepoint : BWTA.getChokepoints()) { //System.out.println(chokepoint.getCenter()); } for (Player player : game.getPlayers()) { - // System.out.println(player.getName()); + // System.out.println(player.getName()); for (Unit enemyUnit : player.getUnits()) { // System.out.println(enemyUnit.getType()); } @@ -95,6 +100,17 @@ public class TestBot1 { } + for (Unit myUnit : self.getUnits()) { + if (myUnit.getType() == UnitType.Zerg_Hatchery) { + Position p = myUnit.getPosition(); + TilePosition t = myUnit.getTilePosition(); + + game.drawBoxMap(p.getX(), p.getY(), p.getX() + 20, p.getY() + 20, Color.Cyan); + game.drawTextMap(p.getX(), p.getY(), "Can build? " + game.canBuildHere(t, UnitType.Zerg_Spawning_Pool) + "\nHas Creep? " + game.hasCreep(t.getX(), t.getY())); + } + } + + //draw my units on screen //game.drawTextScreen(10, 25, Utils.formatText("hello world", Utils.Blue)); game.drawTextScreen(10, 25, Utils.formatText(units.toString(), Utils.Blue)); @@ -110,6 +126,7 @@ public class TestBot1 { }); */ mirror.startGame(); + System.out.println("It's over"); } public static void main(String... args) { diff --git a/src/util/PointerTest.java b/src/util/PointerTest.java index 6f810ed..ae64d34 100644 --- a/src/util/PointerTest.java +++ b/src/util/PointerTest.java @@ -12,7 +12,7 @@ import java.util.List; */ public class PointerTest { - private static final List BWAPI4_INTERFACES = Arrays.asList("Client", "Game", "AIModule" ,"Event", "Race", "Error"); + private static final List BWAPI4_INTERFACES = Arrays.asList("Client", "Game", "AIModule" ,"Event", "Race", "Error", "Order"); private static boolean testCls(String cls){ return BWAPI4_INTERFACES.contains(cls) || cls.endsWith("set") || cls.endsWith("Type") || cls.startsWith("BWTA");