Example #1
0
        /// <summary>
        /// Initialize the vector war game.  This initializes the game state and
        /// the video renderer and creates a new network session.
        /// </summary>
        /// <param name="localPort"></param>
        /// <param name="numPlayers"></param>
        /// <param name="players"></param>
        /// <param name="numSpectators"></param>
        public void Init(int localPort, int numPlayers, GGPOPlayer[] players, int numSpectators)
        {
            // Initialize the game state
            InitializeGameState(numPlayers);

            //ggpo = new PeerToPeerBackend(this, new ConsoleLogger(), localPort, numPlayers, 4);
            ggpo = new PeerToPeerBackend(this, new RollingBufferFileLogger("vectorwar"), localPort, numPlayers, 4);

            // automatically disconnect clients after 3000 ms and start our count-down timer
            // for disconnects after 1000 ms.   To completely disable disconnects, simply use
            // a value of 0 for ggpo_set_disconnect_timeout.
            ggpo.SetDisconnectTimeout(3000);
            ggpo.SetDisconnectNotifyStart(1000);

            for (int i = 0; i < numPlayers + numSpectators; i++)
            {
                ggpo.AddPlayer(players[i], out int playerHandle);
                ngs.players[i].playerHandle = playerHandle;
                ngs.players[i].type         = players[i].type;
                if (players[i].type == GGPOPlayerType.Local)
                {
                    ngs.players[i].connectProgress = 100;
                    ngs.LocalPlayerHandle          = playerHandle;
                    ngs.SetConnectState(playerHandle, PlayerConnectState.Connecting);
                    ggpo.SetFrameDelay(playerHandle, Constants.FrameDelay);
                }
                else
                {
                    ngs.players[i].connectProgress = 0;
                }
            }

            lblStatus.Text = "Connecting to peers.";
            Task.Factory.StartNew(() => HandleApplicationIdle(this, ggpo), TaskCreationOptions.LongRunning);
        }
Example #2
0
        /*
         * vw_on_event_callback --
         *
         * Notification from GGPO that something has happened.  Update the status
         * text at the bottom of the screen to notify the user.
         */

        static bool Vw_on_event_callback(IntPtr evtPtr)
        {
            Debug.Assert(gs != null && ngs != null);
            int[] data = new int[4];
            Marshal.Copy(evtPtr, data, 0, 4);
            int info_code                                 = data[0];
            int connected_player                          = data[1];
            int synchronizing_player                      = data[1];
            int synchronizing_count                       = data[2];
            int synchronizing_total                       = data[3];
            int synchronized_player                       = data[1];
            int disconnected_player                       = data[1];
            int timesync_frames_ahead                     = data[1];
            int connection_interrupted_player             = data[1];
            int connection_interrupted_disconnect_timeout = data[2];
            int connection_resumed_player                 = data[1];

            OnLog?.Invoke($"vw_on_event_callback {data[0]} {data[1]} {data[2]} {data[3]}");

            int progress;

            switch (info_code)
            {
            case GGPO.EVENTCODE_CONNECTED_TO_PEER:
                ngs.SetConnectState(connected_player, PlayerConnectState.Synchronizing);
                break;

            case GGPO.EVENTCODE_SYNCHRONIZING_WITH_PEER:
                progress = 100 * synchronizing_count / synchronizing_total;
                ngs.UpdateConnectProgress(synchronizing_player, progress);
                break;

            case GGPO.EVENTCODE_SYNCHRONIZED_WITH_PEER:
                ngs.UpdateConnectProgress(synchronized_player, 100);
                break;

            case GGPO.EVENTCODE_RUNNING:
                ngs.SetConnectState(PlayerConnectState.Running);
                SetStatusText("");
                break;

            case GGPO.EVENTCODE_CONNECTION_INTERRUPTED:
                ngs.SetDisconnectTimeout(connection_interrupted_player,
                                         Helper.TimeGetTime(),
                                         connection_interrupted_disconnect_timeout);
                break;

            case GGPO.EVENTCODE_CONNECTION_RESUMED:
                ngs.SetConnectState(connection_resumed_player, PlayerConnectState.Running);
                break;

            case GGPO.EVENTCODE_DISCONNECTED_FROM_PEER:
                ngs.SetConnectState(disconnected_player, PlayerConnectState.Disconnected);
                break;

            case GGPO.EVENTCODE_TIMESYNC:
                Helper.Sleep(1000 * timesync_frames_ahead / 60);
                break;
            }
            return(true);
        }
Example #3
0
        /*
         * vw_on_event_callback --
         *
         * Notification from GGPO that something has happened.  Update the status
         * text at the bottom of the screen to notify the user.
         */

        static bool OnEventConnectedToPeerDelegate(int connected_player)
        {
            ngs.SetConnectState(connected_player, PlayerConnectState.Synchronizing);
            return(true);
        }