mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-30 10:26:58 +01:00
add devOrder (= hostID) to params passed on connect. Fix to pass new
param from jni; use object to pass params into UI thread since there are now too many for handler.
This commit is contained in:
parent
ab708e4db1
commit
b115ce14ed
4 changed files with 45 additions and 23 deletions
|
@ -96,17 +96,17 @@ and_xport_relayStatus( void* closure, CommsRelayState newState )
|
||||||
|
|
||||||
static void
|
static void
|
||||||
and_xport_relayConnd( void* closure, XP_UCHAR* const room,
|
and_xport_relayConnd( void* closure, XP_UCHAR* const room,
|
||||||
XP_Bool allHere, XP_U16 nMissing )
|
XP_U16 devOrder, XP_Bool allHere, XP_U16 nMissing )
|
||||||
{
|
{
|
||||||
AndTransportProcs* aprocs = (AndTransportProcs*)closure;
|
AndTransportProcs* aprocs = (AndTransportProcs*)closure;
|
||||||
if ( NULL != aprocs->jxport ) {
|
if ( NULL != aprocs->jxport ) {
|
||||||
JNIEnv* env = *aprocs->envp;
|
JNIEnv* env = *aprocs->envp;
|
||||||
const char* sig = "(Ljava/lang/String;ZI)V";
|
const char* sig = "(Ljava/lang/String;IZI)V";
|
||||||
jmethodID mid = getMethodID( env, aprocs->jxport, "relayConnd", sig );
|
jmethodID mid = getMethodID( env, aprocs->jxport, "relayConnd", sig );
|
||||||
|
|
||||||
jstring str = (*env)->NewStringUTF( env, room );
|
jstring str = (*env)->NewStringUTF( env, room );
|
||||||
(*env)->CallVoidMethod( env, aprocs->jxport, mid,
|
(*env)->CallVoidMethod( env, aprocs->jxport, mid,
|
||||||
str, allHere, nMissing );
|
str, devOrder, allHere, nMissing );
|
||||||
(*env)->DeleteLocalRef( env, str );
|
(*env)->DeleteLocalRef( env, str );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -607,19 +607,32 @@ public class BoardActivity extends XWActivity implements UtilCtxt {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// You have started a game in a new room. Once the remaining
|
||||||
|
// devices have joined your room and you have assigned them tiles
|
||||||
|
// (which Crosswords does for you) the game can begin.
|
||||||
|
|
||||||
|
// You have joined a game on the relay. Once the remaining
|
||||||
|
// devices have joined your room the game can begin.
|
||||||
|
|
||||||
|
// You have joined a game on the relay and the room is now full.
|
||||||
|
// Next you will receive your initial tiles from the device that
|
||||||
|
// created the room and play can begin.
|
||||||
|
|
||||||
private void handleConndMessage( Message msg )
|
private void handleConndMessage( Message msg )
|
||||||
{
|
{
|
||||||
|
CommsTransport.ConndMsg cndmsg =
|
||||||
|
(CommsTransport.ConndMsg)msg.obj;
|
||||||
|
Utils.logf( "handleConndMessage: devOrder=%d", cndmsg.m_devOrder );
|
||||||
String str = null;
|
String str = null;
|
||||||
String fmt;
|
if ( cndmsg.m_allHere ) {
|
||||||
switch ( msg.arg1 ) {
|
// All players have now joined the game. The device that
|
||||||
case CommsTransport.RELAY_CONNND_ALLHERE:
|
// created the room will assign tiles. Then it will be
|
||||||
fmt = getString( R.string.msg_relay_all_heref );
|
// the first player's turn
|
||||||
str = String.format( fmt, (String)msg.obj );
|
String fmt = getString( R.string.msg_relay_all_heref );
|
||||||
break;
|
str = String.format( fmt, cndmsg.m_room );
|
||||||
case CommsTransport.RELAY_CONNND_MISSING:
|
} else if ( cndmsg.m_nMissing > 0 ) {
|
||||||
fmt = getString( R.string.msg_relay_waiting );
|
String fmt = getString( R.string.msg_relay_waiting );
|
||||||
str = String.format( fmt, (String)msg.obj, msg.arg2 );
|
str = String.format( fmt, cndmsg.m_room, cndmsg.m_nMissing );
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( null != str ) {
|
if ( null != str ) {
|
||||||
|
|
|
@ -51,6 +51,20 @@ public class CommsTransport extends Thread implements TransportProcs {
|
||||||
public static final int RELAY_CONNND_ALLHERE = 0;
|
public static final int RELAY_CONNND_ALLHERE = 0;
|
||||||
public static final int RELAY_CONNND_MISSING = 1;
|
public static final int RELAY_CONNND_MISSING = 1;
|
||||||
|
|
||||||
|
public class ConndMsg {
|
||||||
|
ConndMsg( String room, int devOrder, boolean allHere, int nMissing )
|
||||||
|
{
|
||||||
|
m_room = room;
|
||||||
|
m_devOrder = devOrder;
|
||||||
|
m_allHere = allHere;
|
||||||
|
m_nMissing = nMissing;
|
||||||
|
}
|
||||||
|
public String m_room;
|
||||||
|
public int m_devOrder;
|
||||||
|
public boolean m_allHere;
|
||||||
|
public int m_nMissing;
|
||||||
|
}
|
||||||
|
|
||||||
private Selector m_selector;
|
private Selector m_selector;
|
||||||
private SocketChannel m_socketChannel;
|
private SocketChannel m_socketChannel;
|
||||||
private int m_jniGamePtr;
|
private int m_jniGamePtr;
|
||||||
|
@ -353,16 +367,11 @@ public class CommsTransport extends Thread implements TransportProcs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void relayConnd( String room, boolean allHere, int nMissing )
|
public void relayConnd( String room, int devOrder, boolean allHere,
|
||||||
|
int nMissing )
|
||||||
{
|
{
|
||||||
String message = null;
|
ConndMsg cndmsg = new ConndMsg( room, devOrder, allHere, nMissing );
|
||||||
if ( allHere ) {
|
Message.obtain( m_handler, RELAY_COND, cndmsg ).sendToTarget();
|
||||||
Message.obtain( m_handler, RELAY_COND, RELAY_CONNND_ALLHERE,
|
|
||||||
-1/*ignored*/, room ).sendToTarget();
|
|
||||||
} else if ( nMissing > 0 ) {
|
|
||||||
Message.obtain( m_handler, RELAY_COND, RELAY_CONNND_MISSING,
|
|
||||||
nMissing, room ).sendToTarget();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void relayErrorProc( XWRELAY_ERROR relayErr )
|
public void relayErrorProc( XWRELAY_ERROR relayErr )
|
||||||
|
|
|
@ -32,7 +32,7 @@ public interface TransportProcs {
|
||||||
};
|
};
|
||||||
void relayStatus( CommsRelayState newState );
|
void relayStatus( CommsRelayState newState );
|
||||||
|
|
||||||
void relayConnd( String room, boolean allHere, int nMissing );
|
void relayConnd( String room, int devOrder, boolean allHere, int nMissing );
|
||||||
|
|
||||||
public static enum XWRELAY_ERROR { NONE
|
public static enum XWRELAY_ERROR { NONE
|
||||||
,OLDFLAGS
|
,OLDFLAGS
|
||||||
|
|
Loading…
Reference in a new issue