static void readyToEndCallback (NetConnection *conn, void *arg) { // This callback function gets called from inside the function that // updates the frame counter, but this is not a problem as the // ending frame count will at least be 1 greater than the current // frame count. BattleStateData *battleStateData; battleStateData = (BattleStateData *) NetConnection_getStateData(conn); #ifdef NETPLAY_DEBUG fprintf (stderr, "Both sides are ready to end the battle; starting " "end-of-battle synchronisation.\n"); #endif NetConnection_setState (conn, NetState_endingBattle); if (battleFrameCount + 1 > battleStateData->endFrameCount) battleStateData->endFrameCount = battleFrameCount + 1; Netplay_Notify_frameCount (conn, battleFrameCount + 1); // The +1 is to ensure that after the remote side receives the // frame count it will still receive one more frame data packet, // so it will know in advance when the last frame data packet // will come so it won't block. It also ensures that the // local frame counter won't go past the sent number, which // could happen when the function triggering the call to this // function is the frame update function which might update // the frame counter one more time. flushPacketQueue (conn); #ifdef NETPLAY_DEBUG fprintf (stderr, "NETPLAY: [%d] ==> Sent battleFrameCount %d.\n", NetConnection_getPlayerNr(conn), battleFrameCount + 1); #endif Netplay_localReady(conn, readyToEnd2Callback, NULL, false); (void) arg; }
// Auxiliary function for closing, used by both closeCallback() and // NetConnection_close() static void NetConnection_doClose(NetConnection *conn) { conn->stateFlags.connected = false; conn->stateFlags.disconnected = true; // First the callback, so that it can still use the information // of what is the current state, and the stateData: Netplay_doCloseCallback(conn); NetConnection_setState(conn, NetState_unconnected); }
static void readyToEnd2Callback (NetConnection *conn, void *arg) { NetConnection_setState (conn, NetState_endingBattle2); (void) arg; }