project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/ThreadedNetConnection.java
equal
deleted
inserted
replaced
33 import org.hedgewars.hedgeroid.Datastructures.TeamInGame; |
33 import org.hedgewars.hedgeroid.Datastructures.TeamInGame; |
34 import org.hedgewars.hedgeroid.Datastructures.Weaponset; |
34 import org.hedgewars.hedgeroid.Datastructures.Weaponset; |
35 import org.hedgewars.hedgeroid.frontlib.Flib; |
35 import org.hedgewars.hedgeroid.frontlib.Flib; |
36 import org.hedgewars.hedgeroid.frontlib.Frontlib; |
36 import org.hedgewars.hedgeroid.frontlib.Frontlib; |
37 import org.hedgewars.hedgeroid.frontlib.Frontlib.BoolCallback; |
37 import org.hedgewars.hedgeroid.frontlib.Frontlib.BoolCallback; |
|
38 import org.hedgewars.hedgeroid.frontlib.Frontlib.ByteArrayPtr; |
38 import org.hedgewars.hedgeroid.frontlib.Frontlib.BytesCallback; |
39 import org.hedgewars.hedgeroid.frontlib.Frontlib.BytesCallback; |
39 import org.hedgewars.hedgeroid.frontlib.Frontlib.GameSetupPtr; |
40 import org.hedgewars.hedgeroid.frontlib.Frontlib.GameSetupPtr; |
40 import org.hedgewars.hedgeroid.frontlib.Frontlib.IntStrCallback; |
41 import org.hedgewars.hedgeroid.frontlib.Frontlib.IntStrCallback; |
41 import org.hedgewars.hedgeroid.frontlib.Frontlib.MapIntCallback; |
42 import org.hedgewars.hedgeroid.frontlib.Frontlib.MapIntCallback; |
42 import org.hedgewars.hedgeroid.frontlib.Frontlib.MapRecipePtr; |
43 import org.hedgewars.hedgeroid.frontlib.Frontlib.MapRecipePtr; |
71 import android.os.Looper; |
72 import android.os.Looper; |
72 import android.os.Message; |
73 import android.os.Message; |
73 import android.util.Log; |
74 import android.util.Log; |
74 import android.util.Pair; |
75 import android.util.Pair; |
75 |
76 |
76 import com.sun.jna.Memory; |
|
77 import com.sun.jna.Pointer; |
77 import com.sun.jna.Pointer; |
78 |
78 |
79 /** |
79 /** |
80 * This class handles the actual communication with the networking library, running on a separate thread. |
80 * This class handles the actual communication with the networking library, running on a separate thread. |
81 * |
81 * |
126 if(conn == null) { |
126 if(conn == null) { |
127 shutdown(true, appContext.getString(R.string.error_connection_failed)); |
127 shutdown(true, appContext.getString(R.string.error_connection_failed)); |
128 return; |
128 return; |
129 } |
129 } |
130 |
130 |
131 //FLIB.flib_netconn_onAdminAccess(conn, adminAccessCb, null) |
131 // FLIB.flib_netconn_onAdminAccess(conn, adminAccessCb, null) |
132 FLIB.flib_netconn_onSchemeChanged(conn, cfgSchemeCb, null); |
132 FLIB.flib_netconn_onSchemeChanged(conn, cfgSchemeCb, null); |
133 FLIB.flib_netconn_onChat(conn, chatCb, null); |
133 FLIB.flib_netconn_onChat(conn, chatCb, null); |
134 FLIB.flib_netconn_onConnected(conn, connectedCb, null); |
134 FLIB.flib_netconn_onConnected(conn, connectedCb, null); |
135 FLIB.flib_netconn_onDisconnected(conn, disconnectCb, null); |
135 FLIB.flib_netconn_onDisconnected(conn, disconnectCb, null); |
136 FLIB.flib_netconn_onEngineMessage(conn, engineMessageCb, null); |
136 FLIB.flib_netconn_onEngineMessage(conn, engineMessageCb, null); |
329 sendFromNet(MSG_HOG_COUNT_CHANGED, hogCount, teamName); |
329 sendFromNet(MSG_HOG_COUNT_CHANGED, hogCount, teamName); |
330 } |
330 } |
331 }; |
331 }; |
332 |
332 |
333 private final BytesCallback engineMessageCb = new BytesCallback() { |
333 private final BytesCallback engineMessageCb = new BytesCallback() { |
334 public void callback(Pointer context, Pointer buffer, NativeSizeT size) { |
334 public void callback(Pointer context, ByteArrayPtr buffer, NativeSizeT size) { |
335 sendFromNet(MSG_ENGINE_MESSAGE, buffer.getByteArray(0, size.intValue())); |
335 sendFromNet(MSG_ENGINE_MESSAGE, buffer.deref(size.intValue())); |
336 } |
336 } |
337 }; |
337 }; |
338 |
338 |
339 private final VoidCallback runGameCb = new VoidCallback() { |
339 private final VoidCallback runGameCb = new VoidCallback() { |
340 public void callback(Pointer context) { |
340 public void callback(Pointer context) { |
510 FLIB.flib_netconn_send_teamHogCount(conn, (String)msg.obj, msg.arg1); |
510 FLIB.flib_netconn_send_teamHogCount(conn, (String)msg.obj, msg.arg1); |
511 break; |
511 break; |
512 } |
512 } |
513 case MSG_SEND_ENGINE_MESSAGE: { |
513 case MSG_SEND_ENGINE_MESSAGE: { |
514 byte[] message = (byte[])msg.obj; |
514 byte[] message = (byte[])msg.obj; |
515 Memory mem = new Memory(message.length); |
515 ByteArrayPtr ptr = ByteArrayPtr.createJavaOwned(message); |
516 mem.write(0, message, 0, message.length); |
516 FLIB.flib_netconn_send_engineMessage(conn, ptr, NativeSizeT.valueOf(message.length)); |
517 FLIB.flib_netconn_send_engineMessage(conn, mem, NativeSizeT.valueOf(message.length)); |
|
518 break; |
517 break; |
519 } |
518 } |
520 case MSG_SEND_ROUND_FINISHED: { |
519 case MSG_SEND_ROUND_FINISHED: { |
521 FLIB.flib_netconn_send_roundfinished(conn, (Boolean)msg.obj); |
520 FLIB.flib_netconn_send_roundfinished(conn, (Boolean)msg.obj); |
522 break; |
521 break; |
561 FLIB.flib_netconn_send_mapTheme(conn, (String) msg.obj); |
560 FLIB.flib_netconn_send_mapTheme(conn, (String) msg.obj); |
562 break; |
561 break; |
563 } |
562 } |
564 case MSG_SEND_MAP_DRAWDATA: { |
563 case MSG_SEND_MAP_DRAWDATA: { |
565 byte[] message = (byte[])msg.obj; |
564 byte[] message = (byte[])msg.obj; |
566 Memory mem = new Memory(message.length); |
565 ByteArrayPtr ptr = ByteArrayPtr.createJavaOwned(message); |
567 mem.write(0, message, 0, message.length); |
566 FLIB.flib_netconn_send_mapDrawdata(conn, ptr, NativeSizeT.valueOf(message.length)); |
568 FLIB.flib_netconn_send_mapDrawdata(conn, mem, NativeSizeT.valueOf(message.length)); |
|
569 break; |
567 break; |
570 } |
568 } |
571 case MSG_SEND_GAMESTYLE: { |
569 case MSG_SEND_GAMESTYLE: { |
572 FLIB.flib_netconn_send_script(conn, (String) msg.obj); |
570 FLIB.flib_netconn_send_script(conn, (String) msg.obj); |
573 break; |
571 break; |