Commit bd22e195 authored by kenan's avatar kenan

刷新会闪退

parent 0f6ff7ba
...@@ -199,7 +199,7 @@ void Game::DrawBackGround() { ...@@ -199,7 +199,7 @@ void Game::DrawBackGround() {
DrawShadowText(numFont, dInfo.str_total_attack[1], recti(885 * mainGame->xScale, 271 * mainGame->yScale, 905 * mainGame->xScale, 291 * mainGame->yScale), recti(0, 1, 2, 0), dInfo.total_attack_color[1], 0xff000000, true, false, 0); DrawShadowText(numFont, dInfo.str_total_attack[1], recti(885 * mainGame->xScale, 271 * mainGame->yScale, 905 * mainGame->xScale, 291 * mainGame->yScale), recti(0, 1, 2, 0), dInfo.total_attack_color[1], 0xff000000, true, false, 0);
} else { } else {
driver->drawVertexPrimitiveList(matManager.vTotalAtkopT, 4, matManager.iRectangle, 2); driver->drawVertexPrimitiveList(matManager.vTotalAtkopT, 4, matManager.iRectangle, 2);
DrawShadowText(numFont, dInfo.str_total_attack[1], recti(740 * mainGame->xScale, 295 * mainGame->yScale, 760 * mainGame->xScale, 3315 * mainGame->yScale), recti(0, 1, 2, 0), dInfo.total_attack_color[1], 0xff000000, true, false, 0); DrawShadowText(numFont, dInfo.str_total_attack[1], recti(740 * mainGame->xScale, 295 * mainGame->yScale, 760 * mainGame->xScale, 315 * mainGame->yScale), recti(0, 1, 2, 0), dInfo.total_attack_color[1], 0xff000000, true, false, 0);
} }
} }
......
...@@ -226,37 +226,26 @@ static void* join_game_thread(void* param) { ...@@ -226,37 +226,26 @@ static void* join_game_thread(void* param) {
return NULL; return NULL;
} }
bool sendKey(int handle, int keycode, bool begin){
if(handle) {
CIrrDeviceAndroid *device = (CIrrDeviceAndroid *) handle;
if (device->isWindowFocused()) {
SEvent event;
event.EventType = EET_KEY_INPUT_EVENT;
int keyCode = keycode;
if (keyCode >= 0 && (u32) keyCode < device->KeyMap.size())
event.KeyInput.Key = device->KeyMap[keyCode];
else
event.KeyInput.Key = KEY_UNKNOWN;
event.KeyInput.PressedDown = begin;
event.KeyInput.Shift = false;
event.KeyInput.Control = false;
device->postEventFromUser(event);
return true;
}
}
return false;
}
/* /*
* Class: cn_garymb_ygomobile_core_IrrlichtBridge * Class: cn_garymb_ygomobile_core_IrrlichtBridge
* Method: nativeRefreshTexture * Method: nativeRefreshTexture
* Signature: (I)V * Signature: (I)V
*/JNIEXPORT void JNICALL Java_cn_garymb_ygomobile_core_IrrlichtBridge_nativeRefreshTexture( */JNIEXPORT void JNICALL Java_cn_garymb_ygomobile_core_IrrlichtBridge_nativeRefreshTexture(
JNIEnv* env, jclass clazz, jint handle) { JNIEnv* env, jclass clazz, jint handle) {
if (handle) {
IrrlichtDevice* device = (IrrlichtDevice*) handle;
if(sendKey(handle, KEY_KEY_R, true)){ if (device->isWindowFocused()) {
irr::os::Printer::log("before send refresh event"); irr::os::Printer::log("before send refresh event");
SEvent event;
event.EventType = EET_KEY_INPUT_EVENT;
//just cause a right up event to refresh texture
event.KeyInput.PressedDown = true;
event.KeyInput.Shift = false;
event.KeyInput.Control = false;
event.KeyInput.Key = KEY_KEY_R;
device->postEventFromUser(event);
}
} }
} }
...@@ -266,8 +255,19 @@ bool sendKey(int handle, int keycode, bool begin){ ...@@ -266,8 +255,19 @@ bool sendKey(int handle, int keycode, bool begin){
* Signature: (IZ)V * Signature: (IZ)V
*/JNIEXPORT void JNICALL Java_cn_garymb_ygomobile_core_IrrlichtBridge_nativeIgnoreChain( */JNIEXPORT void JNICALL Java_cn_garymb_ygomobile_core_IrrlichtBridge_nativeIgnoreChain(
JNIEnv* env, jclass clazz, jint handle, jboolean begin) { JNIEnv* env, jclass clazz, jint handle, jboolean begin) {
if(sendKey(handle, KEY_KEY_S, true)){ if (handle) {
IrrlichtDevice* device = (IrrlichtDevice*) handle;
if (device->isWindowFocused()) {
irr::os::Printer::log("before send ignore chain"); irr::os::Printer::log("before send ignore chain");
SEvent event;
event.EventType = EET_KEY_INPUT_EVENT;
//just cause a right up event to refresh texture
event.KeyInput.PressedDown = begin;
event.KeyInput.Shift = false;
event.KeyInput.Control = false;
event.KeyInput.Key = KEY_KEY_S;
device->postEventFromUser(event);
}
} }
} }
...@@ -277,16 +277,19 @@ bool sendKey(int handle, int keycode, bool begin){ ...@@ -277,16 +277,19 @@ bool sendKey(int handle, int keycode, bool begin){
* Signature: (IZ)V * Signature: (IZ)V
*/JNIEXPORT void JNICALL Java_cn_garymb_ygomobile_core_IrrlichtBridge_nativeReactChain( */JNIEXPORT void JNICALL Java_cn_garymb_ygomobile_core_IrrlichtBridge_nativeReactChain(
JNIEnv* env, jclass clazz, jint handle, jboolean begin) { JNIEnv* env, jclass clazz, jint handle, jboolean begin) {
if(sendKey(handle, KEY_KEY_A, true)){ if (handle) {
IrrlichtDevice* device = (IrrlichtDevice*) handle;
if (device->isWindowFocused()) {
irr::os::Printer::log("before send react chain"); irr::os::Printer::log("before send react chain");
SEvent event;
event.EventType = EET_KEY_INPUT_EVENT;
//just cause a right up event to refresh texture
event.KeyInput.PressedDown = begin;
event.KeyInput.Shift = false;
event.KeyInput.Control = false;
event.KeyInput.Key = KEY_KEY_A;
device->postEventFromUser(event);
} }
}
//key事件
JNIEXPORT void JNICALL Java_cn_garymb_ygomobile_core_IrrlichtBridge_nativeSendKey(
JNIEnv* env, jclass clazz, jint handle, jint keycode, jboolean begin) {
if(sendKey(handle, keycode, begin)){
irr::os::Printer::log("before send nativeSendKey");
} }
} }
......
...@@ -263,8 +263,8 @@ public class YGOMobileActivity extends NativeActivity implements ...@@ -263,8 +263,8 @@ public class YGOMobileActivity extends NativeActivity implements
int[] size = getGameSize(); int[] size = getGameSize();
int w = size[0]; int w = size[0];
int h = size[1]; int h = size[1];
getWindow().takeInputQueue(null);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(w, h); FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(w, h);
lp.gravity = Gravity.CENTER; lp.gravity = Gravity.CENTER;
layout.addView(mSurfaceView, lp); layout.addView(mSurfaceView, lp);
layout.addView(view, lp); layout.addView(view, lp);
...@@ -290,7 +290,7 @@ public class YGOMobileActivity extends NativeActivity implements ...@@ -290,7 +290,7 @@ public class YGOMobileActivity extends NativeActivity implements
final int action = event.getAction(); final int action = event.getAction();
final float x = event.getX(); final float x = event.getX();
final float y = event.getY(); final float y = event.getY();
mWorker.post(new Runnable() { doWork(new Runnable() {
@Override @Override
public void run() { public void run() {
IrrlichtBridge.sendTouch(action, x, y, 0); IrrlichtBridge.sendTouch(action, x, y, 0);
...@@ -303,9 +303,8 @@ public class YGOMobileActivity extends NativeActivity implements ...@@ -303,9 +303,8 @@ public class YGOMobileActivity extends NativeActivity implements
// getWindow().setLayout(w, h); // getWindow().setLayout(w, h);
// getWindow().setGravity(Gravity.CENTER); // getWindow().setGravity(Gravity.CENTER);
super.setContentView(layout); super.setContentView(layout);
mSurfaceView.requestFocus();
getWindow().takeSurface(null); getWindow().takeSurface(null);
getWindow().takeInputQueue(null); mSurfaceView.requestFocus();
} }
@Override @Override
...@@ -321,7 +320,7 @@ public class YGOMobileActivity extends NativeActivity implements ...@@ -321,7 +320,7 @@ public class YGOMobileActivity extends NativeActivity implements
@Override @Override
public boolean onKeyDown(final int keyCode, KeyEvent event) { public boolean onKeyDown(final int keyCode, KeyEvent event) {
if(keyCode != KeyEvent.KEYCODE_BACK){ if(keyCode != KeyEvent.KEYCODE_BACK){
mWorker.post(new Runnable() { doWork(new Runnable() {
@Override @Override
public void run() { public void run() {
IrrlichtBridge.sendKey(keyCode, true); IrrlichtBridge.sendKey(keyCode, true);
...@@ -335,7 +334,7 @@ public class YGOMobileActivity extends NativeActivity implements ...@@ -335,7 +334,7 @@ public class YGOMobileActivity extends NativeActivity implements
@Override @Override
public boolean onKeyUp(final int keyCode, KeyEvent event) { public boolean onKeyUp(final int keyCode, KeyEvent event) {
if(keyCode != KeyEvent.KEYCODE_BACK){ if(keyCode != KeyEvent.KEYCODE_BACK){
mWorker.post(new Runnable() { doWork(new Runnable() {
@Override @Override
public void run() { public void run() {
IrrlichtBridge.sendKey(keyCode, false); IrrlichtBridge.sendKey(keyCode, false);
...@@ -346,6 +345,10 @@ public class YGOMobileActivity extends NativeActivity implements ...@@ -346,6 +345,10 @@ public class YGOMobileActivity extends NativeActivity implements
return super.onKeyUp(keyCode, event); return super.onKeyUp(keyCode, event);
} }
private void doWork(Runnable runnable){
mWorker.post(runnable);
}
@Override @Override
public void onBackPressed() { public void onBackPressed() {
Toast.makeText(this, "请在游戏里面退出", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "请在游戏里面退出", Toast.LENGTH_SHORT).show();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment