Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polygon getPositions #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion bwta/Polygon.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public Position getNearestPoint(Position p) {
return getNearestPoint_native(pointer, p);
}

public List<Position> getPositions(){
return getPositions_native(pointer);
}

private static Map<Long, Polygon> instances = new HashMap<Long, Polygon>();

Expand Down Expand Up @@ -63,5 +66,5 @@ private static Polygon get(long pointer) {

private native Position getNearestPoint_native(long pointer, Position p);


private native List<Position> getPositions_native(long pointer);
}
19 changes: 17 additions & 2 deletions c/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3614,6 +3614,21 @@ jmethodID retConsID = FindCachedMethod(env, retcls, "<init>", "(II)V");
jobject result = env->NewObject(retcls, retConsID, cresult.x(), cresult.y());
return result;
}
JNIEXPORT jobject JNICALL Java_bwta_Polygon_getPositions_1native(JNIEnv * env, jobject obj, jlong pointer){
BWTA::Polygon* x_polygon = (BWTA::Polygon*)pointer;
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/Position");
jmethodID getMethodID = FindCachedMethodStatic(env, elemClass, "get", "(J)Lbwta/Position;");
for(BWTA::Polygon::const_iterator it = x_polygon.begin(); it != x_polygon.end(); it++ ){
const BWTA::Position* elem_ptr = *it;
jobject elem = env->CallStaticObjectMethod(elemClass, getMethodID, (long)elem_ptr) ;
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();
Expand Down Expand Up @@ -3693,7 +3708,7 @@ void reconnect()

void flushPrint(const char * text){
printf(text);
fflush(stdout);
fflush(stdout);
}

void println(const char * text){
Expand Down Expand Up @@ -5288,7 +5303,7 @@ println("Connecting to Broodwar...");
println("Game ready!!!");

while (Broodwar->isInGame()) {

env->CallVoidMethod(obj, updateMethodID);


Expand Down
Loading