示例#1
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.");
        }
示例#2
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.");
        }