Esempio n. 1
0
        protected void DrawConnectState(Graphics g, int which, Ship ship, PlayerConnectionInfo info)
        {
            string status   = string.Empty;
            int    progress = -1;

            switch (info.state)
            {
            case PlayerConnectState.Connecting:
                status = info.type == GGPOPlayerType.Local ? "Local Player" : "Connecting...";
                break;

            case PlayerConnectState.Synchronizing:
                progress = info.connectProgress;
                status   = info.type == GGPOPlayerType.Local ? "Local Player" : "Synchronizing...";
                break;

            case PlayerConnectState.Disconnected:
                status = "Disconnected";
                break;

            case PlayerConnectState.Disconnecting:
                status   = "Waiting for player...";
                progress = (int)(Utility.GetCurrentTime() - info.disconnectStart) * 100 / info.disconnectTimeout;
                break;
            }

            if (!string.IsNullOrWhiteSpace(status))
            {
                TextRenderer.DrawText(
                    g,
                    status,
                    font,
                    new Rectangle((int)(ship.position.x - ProgressTextWidth / 2),
                                  (int)(ship.position.y + ProgressTextOffset),
                                  ProgressTextWidth,
                                  TextBoxHeight),
                    shipColors[which],
                    TextFormatFlags.Top | TextFormatFlags.HorizontalCenter);
            }

            if (progress >= 0)
            {
                Brush     bar = info.state == PlayerConnectState.Synchronizing ? whiteBrush : redBrush;
                Rectangle rc  = new Rectangle(
                    (int)(ship.position.x - (ProgressBarWidth / 2)),
                    (int)(ship.position.y + ProgressBarTopOffset),
                    ProgressBarWidth,
                    ProgressBarHeight);

                g.DrawRectangle(grayPen, rc);
                rc.Width = Math.Min(100, progress) * ProgressBarWidth / 100;
                g.FillRectangle(bar, Rectangle.Inflate(rc, -1, -1));
            }
        }
Esempio n. 2
0
        public void Populate(Ship shipGs, PlayerConnectionInfo info)
        {
            transform.position = shipGs.position;
            model.rotation     = Quaternion.Euler(0, 0, shipGs.heading);
            string status   = "";
            int    progress = -1;

            switch (info.state)
            {
            case PlayerConnectState.Connecting:
                status = (info.type == GGPOPlayerType.GGPO_PLAYERTYPE_LOCAL) ? "Local Player" : "Connecting...";
                break;

            case PlayerConnectState.Synchronizing:
                progress = info.connect_progress;
                status   = (info.type == GGPOPlayerType.GGPO_PLAYERTYPE_LOCAL) ? "Local Player" : "Synchronizing...";
                break;

            case PlayerConnectState.Disconnected:
                status = "Disconnected";
                break;

            case PlayerConnectState.Disconnecting:
                status   = "Waiting for player...";
                progress = (Utils.TimeGetTime() - info.disconnect_start) * 100 / info.disconnect_timeout;
                break;
            }

            if (progress > 0)
            {
                imgProgress.gameObject.SetActive(true);
                imgProgress.fillAmount = progress / 100f;
            }
            else
            {
                imgProgress.gameObject.SetActive(false);
            }

            if (status.Length > 0)
            {
                txtStatus.gameObject.SetActive(true);
                txtStatus.text = status;
            }
            else
            {
                txtStatus.gameObject.SetActive(false);
            }
        }
Esempio n. 3
0
        /*
         * Init --
         *
         * Initialize the vector war game.  This initializes the game state and
         * the video renderer and creates a new network session.
         */

        public static void Init(int localport, int num_players, IList <GGPOPlayer> players, int num_spectators)
        {
            // Initialize the game state
            gs.Init(num_players);

#if SYNC_TEST
            var result = ggpo_start_synctest(cb, "vectorwar", num_players, 1);
#else
            SetFuncPointers();

            var result = GGPO.StartSession(out ggpo,
                                           vw_begin_game_callback,
                                           vw_advance_frame_callback,
                                           vw_load_game_state_callback,
                                           vw_log_game_state,
                                           vw_save_game_state_callback,
                                           vw_free_buffer_callback,
                                           vw_on_event_callback,
                                           "vectorwar", num_players, localport);

            if (ggpo == IntPtr.Zero)
            {
                OnLog?.Invoke("Session Error");
            }
#endif
            ReportFailure(result);

            // 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.
            ReportFailure(GGPO.SetDisconnectTimeout(ggpo, 3000));
            ReportFailure(GGPO.SetDisconnectNotifyStart(ggpo, 1000));

            int controllerId = 0;
            int playerIndex  = 0;
            ngs.players = new PlayerConnectionInfo[num_players];
            for (int i = 0; i < players.Count; i++)
            {
                ReportFailure(GGPO.AddPlayer(ggpo,
                                             (int)players[i].type,
                                             players[i].player_num,
                                             players[i].ip_address,
                                             players[i].port,
                                             out int handle));

                if (players[i].type == GGPOPlayerType.GGPO_PLAYERTYPE_LOCAL)
                {
                    var playerInfo = new PlayerConnectionInfo();
                    playerInfo.handle           = handle;
                    playerInfo.type             = players[i].type;
                    playerInfo.connect_progress = 100;
                    playerInfo.controllerId     = controllerId++;
                    ngs.players[playerIndex++]  = playerInfo;
                    ngs.SetConnectState(handle, PlayerConnectState.Connecting);
                    ReportFailure(GGPO.SetFrameDelay(ggpo, handle, FRAME_DELAY));
                }
                else if (players[i].type == GGPOPlayerType.GGPO_PLAYERTYPE_REMOTE)
                {
                    var playerInfo = new PlayerConnectionInfo();
                    playerInfo.handle           = handle;
                    playerInfo.type             = players[i].type;
                    playerInfo.connect_progress = 0;
                    ngs.players[playerIndex++]  = playerInfo;
                }
            }

            perf.ggpoutil_perfmon_init();
            SetStatusText("Connecting to peers.");
        }
Esempio n. 4
0
        /*
         * Init --
         *
         * Initialize the vector war game.  This initializes the game state and
         * the video renderer and creates a new network session.
         */

        public static void Init(int localport, int num_players, IList <GGPOPlayer> players, int num_spectators)
        {
            // Initialize the game state
            gs.Init(num_players);

#if SYNC_TEST
            var result = ggpo_start_synctest(cb, "vectorwar", num_players, 1);
#else
            var result = GGPO.Session.StartSession(Vw_begin_game_callback,
                                                   Vw_advance_frame_callback,
                                                   Vw_load_game_state_callback,
                                                   Vw_log_game_state,
                                                   Vw_save_game_state_callback,
                                                   Vw_free_buffer_callback,
                                                   OnEventConnectedToPeerDelegate,
                                                   OnEventSynchronizingWithPeerDelegate,
                                                   OnEventSynchronizedWithPeerDelegate,
                                                   OnEventRunningDelegate,
                                                   OnEventConnectionInterruptedDelegate,
                                                   OnEventConnectionResumedDelegate,
                                                   OnEventDisconnectedFromPeerDelegate,
                                                   OnEventEventcodeTimesyncDelegate,
                                                   "vectorwar", num_players, localport);
#endif
            ReportFailure(result);

            // 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.
            ReportFailure(GGPO.Session.SetDisconnectTimeout(3000));
            ReportFailure(GGPO.Session.SetDisconnectNotifyStart(1000));

            int controllerId = 0;
            int playerIndex  = 0;
            ngs.players = new PlayerConnectionInfo[num_players];
            for (int i = 0; i < players.Count; i++)
            {
                ReportFailure(GGPO.Session.AddPlayer(players[i], out int handle));

                if (players[i].type == GGPOPlayerType.GGPO_PLAYERTYPE_LOCAL)
                {
                    var playerInfo = new PlayerConnectionInfo();
                    playerInfo.handle           = handle;
                    playerInfo.type             = players[i].type;
                    playerInfo.connect_progress = 100;
                    playerInfo.controllerId     = controllerId++;
                    ngs.players[playerIndex++]  = playerInfo;
                    ngs.SetConnectState(handle, PlayerConnectState.Connecting);
                    ReportFailure(GGPO.Session.SetFrameDelay(handle, FRAME_DELAY));
                }
                else if (players[i].type == GGPOPlayerType.GGPO_PLAYERTYPE_REMOTE)
                {
                    var playerInfo = new PlayerConnectionInfo();
                    playerInfo.handle           = handle;
                    playerInfo.type             = players[i].type;
                    playerInfo.connect_progress = 0;
                    ngs.players[playerIndex++]  = playerInfo;
                }
            }

            perf.ggpoutil_perfmon_init();
            SetStatusText("Connecting to peers.");
        }