Merge pull request #488 from marynate/PR-godot-java

More callbacks for Godot.SingletonBase (android)
This commit is contained in:
reduz 2014-06-11 01:13:12 -03:00
commit 9ae371519c
3 changed files with 362 additions and 317 deletions

View File

@ -62,6 +62,7 @@ import android.widget.FrameLayout;
import com.android.godot.input.*; import com.android.godot.input.*;
import java.io.InputStream; import java.io.InputStream;
import javax.microedition.khronos.opengles.GL10;
public class Godot extends Activity implements SensorEventListener public class Godot extends Activity implements SensorEventListener
{ {
@ -116,11 +117,13 @@ public class Godot extends Activity implements SensorEventListener
} }
protected void onMainResume() { protected void onMainPause() {}
protected void onMainResume() {}
protected void onMainDestroy() {}
}
protected void onGLDrawFrame(GL10 gl) {}
protected void onGLSurfaceChanged(GL10 gl, int width, int height) {} // singletons will always miss first onGLSurfaceChanged call
//protected void onGLSurfaceCreated(GL10 gl, EGLConfig config) {} // singletons won't be ready until first GodotLib.step()
public void registerMethods() {} public void registerMethods() {}
} }
@ -141,6 +144,7 @@ public class Godot extends Activity implements SensorEventListener
private Sensor mAccelerometer; private Sensor mAccelerometer;
public FrameLayout layout; public FrameLayout layout;
public RelativeLayout adLayout;
static public GodotIO io; static public GodotIO io;
@ -154,7 +158,6 @@ public class Godot extends Activity implements SensorEventListener
static int singleton_count=0; static int singleton_count=0;
public interface ResultCallback { public interface ResultCallback {
public void callback(int requestCode, int resultCode, Intent data); public void callback(int requestCode, int resultCode, Intent data);
}; };
@ -197,6 +200,12 @@ public class Godot extends Activity implements SensorEventListener
edittext.setView(mView); edittext.setView(mView);
io.setEdit(edittext); io.setEdit(edittext);
// Ad layout
adLayout = new RelativeLayout(this);
adLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
layout.addView(adLayout);
} }
private static Godot _self; private static Godot _self;
@ -282,6 +291,9 @@ public class Godot extends Activity implements SensorEventListener
@Override protected void onDestroy(){ @Override protected void onDestroy(){
if(mPaymentsManager != null ) mPaymentsManager.destroy(); if(mPaymentsManager != null ) mPaymentsManager.destroy();
for(int i=0;i<singleton_count;i++) {
singletons[i].onMainDestroy();
}
super.onDestroy(); super.onDestroy();
} }
@ -291,6 +303,9 @@ public class Godot extends Activity implements SensorEventListener
mSensorManager.unregisterListener(this); mSensorManager.unregisterListener(this);
GodotLib.focusout(); GodotLib.focusout();
for(int i=0;i<singleton_count;i++) {
singletons[i].onMainPause();
}
} }
@Override protected void onResume() { @Override protected void onResume() {

View File

@ -62,6 +62,7 @@ import javax.microedition.khronos.opengles.GL10;
* bit depths). Failure to do so would result in an EGL_BAD_MATCH error. * bit depths). Failure to do so would result in an EGL_BAD_MATCH error.
*/ */
public class GodotView extends GLSurfaceView { public class GodotView extends GLSurfaceView {
private static String TAG = "GodotView"; private static String TAG = "GodotView";
private static final boolean DEBUG = false; private static final boolean DEBUG = false;
private static Context ctx; private static Context ctx;
@ -379,12 +380,18 @@ public class GodotView extends GLSurfaceView {
public void onDrawFrame(GL10 gl) { public void onDrawFrame(GL10 gl) {
GodotLib.step(); GodotLib.step();
for(int i=0;i<Godot.singleton_count;i++) {
Godot.singletons[i].onGLDrawFrame(gl);
}
} }
public void onSurfaceChanged(GL10 gl, int width, int height) { public void onSurfaceChanged(GL10 gl, int width, int height) {
GodotLib.resize(width, height,!firsttime); GodotLib.resize(width, height,!firsttime);
firsttime=false; firsttime=false;
for(int i=0;i<Godot.singleton_count;i++) {
Godot.singletons[i].onGLSurfaceChanged(gl, width, height);
}
} }
public void onSurfaceCreated(GL10 gl, EGLConfig config) { public void onSurfaceCreated(GL10 gl, EGLConfig config) {

View File

@ -152,6 +152,14 @@ jvalue _variant_to_jvalue(JNIEnv *env, Variant::Type p_type, const Variant* p_ar
env->SetIntArrayRegion(arr,0,array.size(),r.ptr()); env->SetIntArrayRegion(arr,0,array.size(),r.ptr());
v.l=arr; v.l=arr;
} break;
case Variant::RAW_ARRAY: {
DVector<uint8_t> array = *p_arg;
jbyteArray arr = env->NewByteArray(array.size());
DVector<uint8_t>::Read r = array.read();
env->SetByteArrayRegion(arr,0,array.size(),reinterpret_cast<const signed char*>(r.ptr()));
v.l=arr;
} break; } break;
case Variant::REAL_ARRAY: { case Variant::REAL_ARRAY: {
@ -244,6 +252,19 @@ Variant _jobject_to_variant(JNIEnv * env, jobject obj) {
return sarr; return sarr;
}; };
if (name == "[B") {
jbyteArray arr = (jbyteArray)obj;
int fCount = env->GetArrayLength(arr);
DVector<uint8_t> sarr;
sarr.resize(fCount);
DVector<uint8_t>::Write w = sarr.write();
env->GetByteArrayRegion(arr,0,fCount,reinterpret_cast<signed char*>(w.ptr()));
w = DVector<uint8_t>::Write();
return sarr;
};
if (name == "java.lang.Float" || name == "java.lang.Double") { if (name == "java.lang.Float" || name == "java.lang.Double") {
jclass nclass = env->FindClass("java/lang/Number"); jclass nclass = env->FindClass("java/lang/Number");
@ -1346,6 +1367,7 @@ static Variant::Type get_jni_type(const String& p_type) {
{"double", Variant::REAL}, {"double", Variant::REAL},
{"java.lang.String",Variant::STRING}, {"java.lang.String",Variant::STRING},
{"[I",Variant::INT_ARRAY}, {"[I",Variant::INT_ARRAY},
{"[B",Variant::RAW_ARRAY},
{"[F",Variant::REAL_ARRAY}, {"[F",Variant::REAL_ARRAY},
{"[java.lang.String",Variant::STRING_ARRAY}, {"[java.lang.String",Variant::STRING_ARRAY},
{"com.android.godot.Dictionary", Variant::DICTIONARY}, {"com.android.godot.Dictionary", Variant::DICTIONARY},
@ -1381,6 +1403,7 @@ static const char* get_jni_sig(const String& p_type) {
{"java.lang.String","Ljava/lang/String;"}, {"java.lang.String","Ljava/lang/String;"},
{"com.android.godot.Dictionary", "Lcom/android/godot/Dictionary;"}, {"com.android.godot.Dictionary", "Lcom/android/godot/Dictionary;"},
{"[I","[I"}, {"[I","[I"},
{"[B","[B"},
{"[F","[F"}, {"[F","[F"},
{"[java.lang.String","[Ljava/lang/String;"}, {"[java.lang.String","[Ljava/lang/String;"},
{NULL,"V"} {NULL,"V"}