bwmirror 2.3

This commit is contained in:
vjurenka 2015-04-19 18:13:03 +02:00
parent 877663c34f
commit 0c7d1e7275
38 changed files with 412 additions and 37 deletions

Binary file not shown.

BIN
bwmirror_v2_3.jar Normal file

Binary file not shown.

View file

@ -1610,6 +1610,10 @@ JNIEXPORT jstring JNICALL Java_bwapi_GameType_toString_1native(JNIEnv * env, job
GameType* x_gameType = (GameType*)pointer; GameType* x_gameType = (GameType*)pointer;
return env->NewStringUTF(x_gameType->toString().c_str()); 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){ JNIEXPORT jint JNICALL Java_bwapi_Player_getID_1native(JNIEnv * env, jobject obj, jlong pointer){
Player x_player = (Player)pointer; Player x_player = (Player)pointer;
return x_player->getID(); return x_player->getID();
@ -6270,6 +6274,49 @@ env->CallVoidMethod(result, addMethodID, keyElem, valueElem);
} }
return result; 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<TilePosition> cresult = BWTA::getShortestPath(start, end);
jclass listCls = FindCachedClass(env, "java/util/ArrayList");
jmethodID listConsID = FindCachedMethod(env, listCls, "<init>", "()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, "<init>", "(II)V");
for(std::vector<TilePosition>::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<TilePosition> 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<TilePosition> cresult = BWTA::getShortestPath(start, targets);
jclass listCls = FindCachedClass(env, "java/util/ArrayList");
jmethodID listConsID = FindCachedMethod(env, listCls, "<init>", "()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, "<init>", "(II)V");
for(std::vector<TilePosition>::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){ JNIEXPORT void JNICALL Java_bwta_BWTA_buildChokeNodes(JNIEnv * env, jclass jclz){
BWTA::buildChokeNodes(); BWTA::buildChokeNodes();
} }
@ -6320,6 +6367,38 @@ jmethodID retConsID = FindCachedMethod(env, retcls, "<init>", "(II)V");
jobject result = env->NewObject(retcls, retConsID, cresult.x, cresult.y); jobject result = env->NewObject(retcls, retConsID, cresult.x, cresult.y);
return result; 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<BWTA::Polygon> cresult = x_polygon->getHoles();
jclass listCls = FindCachedClass(env, "java/util/ArrayList");
jmethodID listConsID = FindCachedMethod(env, listCls, "<init>", "()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<BWTA::Polygon>::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<Position> cresult = *x_polygon;
jclass listCls = FindCachedClass(env, "java/util/ArrayList");
jmethodID listConsID = FindCachedMethod(env, listCls, "<init>", "()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, "<init>", "(II)V");
for(std::vector<Position>::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){ JNIEXPORT jobject JNICALL Java_bwta_Region_getPolygon_1native(JNIEnv * env, jobject obj, jlong pointer){
BWTA::Region* x_region = (BWTA::Region*)pointer; BWTA::Region* x_region = (BWTA::Region*)pointer;
jlong resptr = (jlong)&x_region->getPolygon(); jlong resptr = (jlong)&x_region->getPolygon();

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -2287,6 +2287,14 @@ extern "C" {
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #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 #ifdef __cplusplus
} }
#endif #endif
@ -9291,6 +9299,22 @@ JNIEXPORT jobject JNICALL Java_bwta_BWTA_getNearestTilePosition
JNIEXPORT jobject JNICALL Java_bwta_BWTA_getGroundDistances JNIEXPORT jobject JNICALL Java_bwta_BWTA_getGroundDistances
(JNIEnv *, jclass, jobject, jobject); (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 * Class: bwta_BWTA
* Method: buildChokeNodes * Method: buildChokeNodes
@ -9385,6 +9409,22 @@ JNIEXPORT jboolean JNICALL Java_bwta_Polygon_isInside_1native
JNIEXPORT jobject JNICALL Java_bwta_Polygon_getNearestPoint_1native JNIEXPORT jobject JNICALL Java_bwta_Polygon_getNearestPoint_1native
(JNIEnv *, jobject, jlong, jobject); (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 #ifdef __cplusplus
} }
#endif #endif

View file

@ -56,7 +56,7 @@ public class Mirror {
private static final boolean EXTRACT_JAR = true; private static final boolean EXTRACT_JAR = true;
private static final String VERSION = "2_2"; private static final String VERSION = "2_3";
static { static {
String arch = System.getProperty("os.arch"); String arch = System.getProperty("os.arch");

View file

@ -9,6 +9,10 @@ import java.util.List;
public class Order { public class Order {
public String toString() {
return toString_native(pointer);
}
public static Order Die; public static Order Die;
public static Order Stop; public static Order Stop;
@ -342,5 +346,7 @@ public class Order {
private long pointer; private long pointer;
private native String toString_native(long pointer);
} }

View file

@ -72,6 +72,10 @@ public class BWTA {
public static native Map<TilePosition, Double> getGroundDistances(TilePosition start, List<TilePosition> targets); public static native Map<TilePosition, Double> getGroundDistances(TilePosition start, List<TilePosition> targets);
public static native List<TilePosition> getShortestPath(TilePosition start, TilePosition end);
public static native List<TilePosition> getShortestPath(TilePosition start, List<TilePosition> targets);
public static native void buildChokeNodes(); public static native void buildChokeNodes();
public static native int getGroundDistance2(TilePosition start, TilePosition end); public static native int getGroundDistance2(TilePosition start, TilePosition end);

View file

@ -34,6 +34,14 @@ public class Polygon {
return getNearestPoint_native(pointer, p); return getNearestPoint_native(pointer, p);
} }
public List<Polygon> getHoles() {
return getHoles_native(pointer);
}
public List<Position> getPoints() {
return getPoints_native(pointer);
}
private static Map<Long, Polygon> instances = new HashMap<Long, Polygon>(); private static Map<Long, Polygon> instances = new HashMap<Long, Polygon>();
@ -65,5 +73,9 @@ public class Polygon {
private native Position getNearestPoint_native(long pointer, Position p); private native Position getNearestPoint_native(long pointer, Position p);
private native List<Polygon> getHoles_native(long pointer);
private native List<Position> getPoints_native(long pointer);
} }

View file

@ -7,6 +7,14 @@
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #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 #ifdef __cplusplus
} }
#endif #endif

View file

@ -239,6 +239,22 @@ JNIEXPORT jobject JNICALL Java_bwta_BWTA_getNearestTilePosition
JNIEXPORT jobject JNICALL Java_bwta_BWTA_getGroundDistances JNIEXPORT jobject JNICALL Java_bwta_BWTA_getGroundDistances
(JNIEnv *, jclass, jobject, jobject); (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 * Class: bwta_BWTA
* Method: buildChokeNodes * Method: buildChokeNodes

View file

@ -47,6 +47,22 @@ JNIEXPORT jboolean JNICALL Java_bwta_Polygon_isInside_1native
JNIEXPORT jobject JNICALL Java_bwta_Polygon_getNearestPoint_1native JNIEXPORT jobject JNICALL Java_bwta_Polygon_getNearestPoint_1native
(JNIEnv *, jobject, jlong, jobject); (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 #ifdef __cplusplus
} }
#endif #endif

View file

@ -56,7 +56,7 @@ public class Mirror {
private static final boolean EXTRACT_JAR = true; private static final boolean EXTRACT_JAR = true;
private static final String VERSION = "2_2"; private static final String VERSION = "2_3";
static { static {
String arch = System.getProperty("os.arch"); String arch = System.getProperty("os.arch");

View file

@ -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<CDeclaration> 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() {
}
}

View file

@ -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<CDeclaration> 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();
}

View file

@ -1,5 +1,7 @@
package generator; package generator;
import api.DefaultEventListener;
import api.GeneratorEventListener;
import c.CClass; import c.CClass;
import c.CDeclaration; import c.CDeclaration;
import c.CEnum; import c.CEnum;
@ -11,6 +13,7 @@ import generator.c.TypeTable;
import generator.ccalls.CallImplementer; import generator.ccalls.CallImplementer;
import impl.CApiParser; import impl.CApiParser;
import impl.Clazz; import impl.Clazz;
import inject.GetPolygonPointsInjector;
import util.FileUtils; import util.FileUtils;
import java.io.*; import java.io.*;
@ -44,6 +47,8 @@ public class CJavaPipeline {
private static final HashMap<String, String> superClasses = new HashMap<>(); private static final HashMap<String, String> superClasses = new HashMap<>();
private GeneratorEventListener listener = new DefaultEventListener();
static { static {
superClasses.put("Unit", "PositionedObject"); superClasses.put("Unit", "PositionedObject");
superClasses.put("Region", "CenteredObject"); superClasses.put("Region", "CenteredObject");
@ -51,6 +56,10 @@ public class CJavaPipeline {
superClasses.put("BaseLocation", "PositionedObject"); superClasses.put("BaseLocation", "PositionedObject");
} }
public CJavaPipeline() {
listener = new GetPolygonPointsInjector();
}
public void run(PackageProcessOptions[] packages, Properties processingOptions) { public void run(PackageProcessOptions[] packages, Properties processingOptions) {
/** /**
Init Init
@ -96,6 +105,9 @@ public class CJavaPipeline {
if (ignoredClasses.contains(cDeclaration.getName())) { if (ignoredClasses.contains(cDeclaration.getName())) {
continue; continue;
} }
listener.onCDeclarationRead(pkg, cDeclaration);
if (cDeclaration.getDeclType().equals(DeclarationType.CLASS)) { if (cDeclaration.getDeclType().equals(DeclarationType.CLASS)) {
generator.addClass((CClass) cDeclaration); generator.addClass((CClass) cDeclaration);
} else if (cDeclaration.getDeclType().equals(DeclarationType.ENUM)) { } else if (cDeclaration.getDeclType().equals(DeclarationType.ENUM)) {

View file

@ -26,6 +26,8 @@ public class JavaContext {
private List<String> bwtaClasses = Arrays.asList("Chokepoint", "Region", "RectangleArray", "Polygon", "BaseLocation"); private List<String> bwtaClasses = Arrays.asList("Chokepoint", "Region", "RectangleArray", "Polygon", "BaseLocation");
private List<String> selfReturnTypes = Arrays.asList("BWTA::Polygon");
private String packageName = "bwapi"; private String packageName = "bwapi";
@ -38,6 +40,10 @@ public class JavaContext {
javaToCType.put("String", "jstring"); javaToCType.put("String", "jstring");
} }
public boolean isSelfReturnType(String clsName, String methodName){
return packageName.equals("bwta") && selfReturnTypes.contains(clsName) && methodName.equals("getPoints");
}
public String getPackageName() { public String getPackageName() {
return packageName; return packageName;
} }

View file

@ -45,7 +45,7 @@ public class MirrorContext {
} }
private boolean isCollection(String cType) { private boolean isCollection(String cType) {
return cType.startsWith("set<"); return cType.startsWith("set<") || cType.startsWith("vector<");
} }
private boolean isMap(String cType) { private boolean isMap(String cType) {

View file

@ -110,8 +110,7 @@ public class CallImplementer {
if (!javaContext.isValueType(genericType)) { if (!javaContext.isValueType(genericType)) {
out.print("(" + PointerTest.test(genericType) + ")"); out.print("(" + PointerTest.test(genericType) + ")");
out.print("env->GetLongField(jobj, FindCachedField(env, env->GetObjectClass(jobj), \"pointer\", \"J\"))"); out.print("env->GetLongField(jobj, FindCachedField(env, env->GetObjectClass(jobj), \"pointer\", \"J\"))");
} } else {
else{
out.print("cObj"); out.print("cObj");
} }
out.println(");"); out.println(");");
@ -185,16 +184,25 @@ public class CallImplementer {
} }
private String wrapInCCollection(String genericType, String javaMethodName) {
private String wrapInCCollection(String genericType) {
String buffer = ""; String buffer = "";
boolean isBWAPI4Collection = !CJavaPipeline.isBWAPI3() && !genericType.startsWith("BWTA::"); boolean isBWAPI4Collection = !CJavaPipeline.isBWAPI3() && !genericType.startsWith("BWTA::");
if (!isBWAPI4Collection) { if (!isBWAPI4Collection) {
if(javaMethodName.equals("getHoles")){
buffer += "std::vector<";
}
else{
buffer += "std::set<"; buffer += "std::set<";
} }
}
if (!javaContext.isConstantTye(genericType) && !javaContext.isValueType(genericType) ) { if (!javaContext.isConstantTye(genericType) && !javaContext.isValueType(genericType) ) {
if(!javaMethodName.equals("getHoles")){
buffer += (PointerTest.test(genericType)); buffer += (PointerTest.test(genericType));
} }
else{
buffer += genericType;
}
}
if (!isBWAPI4Collection) { if (!isBWAPI4Collection) {
buffer += ">"; buffer += ">";
} else { } else {
@ -202,6 +210,9 @@ public class CallImplementer {
} }
if (buffer.equals("set") && !CJavaPipeline.isBWAPI3()) { if (buffer.equals("set") && !CJavaPipeline.isBWAPI3()) {
if(javaContext.getPackageName().equals("bwta")){
return "std::vector<" + genericType + ">";
}
return "SetContainer<" + genericType + ">"; return "SetContainer<" + genericType + ">";
} }
@ -325,7 +336,7 @@ public class CallImplementer {
* *
* @param genericType * @param genericType
*/ */
private void implementCollectionReturn(String genericType) { private void implementCollectionReturn(String genericType, String javaMethodName) {
String classGenericType = genericType; String classGenericType = genericType;
if (classGenericType.contains("::")) { if (classGenericType.contains("::")) {
classGenericType = classGenericType.substring(classGenericType.lastIndexOf(":") + 1); classGenericType = classGenericType.substring(classGenericType.lastIndexOf(":") + 1);
@ -346,7 +357,7 @@ public class CallImplementer {
//the for loop //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); out.print("const " + genericType);
if (!javaContext.isValueType(genericType)) { if (!javaContext.isValueType(genericType)) {
out.print(PointerTest.test(genericType, false)); out.print(PointerTest.test(genericType, false));
@ -355,6 +366,9 @@ public class CallImplementer {
if (javaContext.isConstantTye(genericType)) { if (javaContext.isConstantTye(genericType)) {
out.println("table" + genericType + ".find((*it).getID())->second;"); out.println("table" + genericType + ".find((*it).getID())->second;");
} else { } else {
if(javaMethodName.equals("getHoles")){
out.print("&");
}
out.println("*it;"); out.println("*it;");
} }
if (!javaContext.isValueType(genericType)) { if (!javaContext.isValueType(genericType)) {
@ -466,18 +480,28 @@ public class CallImplementer {
private void implementMethodReturn(String objName, String javaMethodName, List<Param> params, String cReturnType, String javaRetType, String javaPackageName, String clsName, boolean isStatic) { private void implementMethodReturn(String objName, String javaMethodName, List<Param> 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) { if (isStatic) {
objectAccessor = clsName + "::"; 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 //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)) { if (javaContext.isCollection(javaRetType)) {
String genericType = convertToBWTA(Generic.extractGeneric(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); implementRealParams(params);
out.println(")" + SEMICOLON); if (!javaContext.isSelfReturnType(clsName, javaMethodName)) {
implementCollectionReturn(genericType); out.print(")");
}
out.println(SEMICOLON);
implementCollectionReturn(genericType, javaMethodName);
return; return;
} }

View file

@ -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::)?([\\w\\*]+)\\s([\\w\\*]+)\\((.*)\\)((\\sconst)?\\s=\\s0;)?";
//String FUNC_REGEX = "^(\\s*)(virtual)?\\s((BWAPI)|(std)::)?([\\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 // 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_STATIC = 4;
static final int F_REGEX_RETURN_TYPE = 8; static final int F_REGEX_RETURN_TYPE = 8;
static final int F_REGEX_NAME = 19; static final int F_REGEX_NAME = 20;
static final int F_REGEX_PARAMS = 20; static final int F_REGEX_PARAMS = 21;
String ENUM_VALUE_REGEX = "^(\\s*)(\\w+)(\\s*=\\s*(0x)?([0-9A-Fa-f]+))?\\s*[\\,;]"; 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); Clazz clz = new Clazz(clazzName);
if(!CJavaPipeline.isBWAPI3()){ 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 function = new Function();
function.name = "toString"; function.name = "toString";
function.returnType = "string"; function.returnType = "string";

View file

@ -37,6 +37,16 @@ public class Function implements Method {
return f; return f;
} }
Function() {
}
public Function(String name, String returnType, boolean isStatic, ArrayList<Param> args) {
this.name = name;
this.returnType = returnType;
this.isStatic = isStatic;
this.args = args;
}
@Override @Override
public String getType() { public String getType() {
return returnType; return returnType;

View file

@ -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<Position>", false, new ArrayList<Param>());
cClass.getFields().add(getPolygons);
}
}
}

View file

@ -5,9 +5,9 @@ import bwapi.Text.Size.Enum;
import bwta.BWTA; import bwta.BWTA;
import bwta.BaseLocation; import bwta.BaseLocation;
import bwta.Chokepoint; import bwta.Chokepoint;
import util.Pair; import bwta.Polygon;
import java.io.File; import java.util.List;
/** /**
* User: PC * User: PC
@ -36,11 +36,16 @@ public class TestBot1 {
mirror.getGame().enableFlag(bwapi.Flag.Enum.UserInput.getValue()); mirror.getGame().enableFlag(bwapi.Flag.Enum.UserInput.getValue());
} }
@Override
public void onEnd(boolean b) {
System.out.println("Ended");
//System.exit(0);
}
@Override @Override
public void onFrame() { public void onFrame() {
Game game = mirror.getGame(); Game game = mirror.getGame();
Player self = game.self(); Player self = game.self();
UnitType.Protoss_Archon.whatBuilds();
game.drawBoxScreen(0, 0, 100, 100, Color.Red, true); game.drawBoxScreen(0, 0, 100, 100, Color.Red, true);
@ -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 //draw my units on screen
//game.drawTextScreen(10, 25, Utils.formatText("hello world", Utils.Blue)); //game.drawTextScreen(10, 25, Utils.formatText("hello world", Utils.Blue));
game.drawTextScreen(10, 25, Utils.formatText(units.toString(), Utils.Blue)); game.drawTextScreen(10, 25, Utils.formatText(units.toString(), Utils.Blue));
@ -110,6 +126,7 @@ public class TestBot1 {
}); });
*/ */
mirror.startGame(); mirror.startGame();
System.out.println("It's over");
} }
public static void main(String... args) { public static void main(String... args) {

View file

@ -12,7 +12,7 @@ import java.util.List;
*/ */
public class PointerTest { public class PointerTest {
private static final List<String> BWAPI4_INTERFACES = Arrays.asList("Client", "Game", "AIModule" ,"Event", "Race", "Error"); private static final List<String> BWAPI4_INTERFACES = Arrays.asList("Client", "Game", "AIModule" ,"Event", "Race", "Error", "Order");
private static boolean testCls(String cls){ private static boolean testCls(String cls){
return BWAPI4_INTERFACES.contains(cls) || cls.endsWith("set") || cls.endsWith("Type") || cls.startsWith("BWTA"); return BWAPI4_INTERFACES.contains(cls) || cls.endsWith("set") || cls.endsWith("Type") || cls.startsWith("BWTA");