Example #1
0
        public void Initialize(
            ISimulationController <WS> simulationController,
            OnlineSession onlineSession,
            int localPlayerControllersCapacity,
            int totalPlayerControllersCapacity,
            int initialReceivedPlayerCommandsCapacity,
            int snapshotsRingBufferCapacity)
        {
            _simulationController        = simulationController;
            OnlineSession                = onlineSession;
            LocalPlayerControllers       = new Dictionary <int, PC>(localPlayerControllersCapacity);
            RegisteredPlayerControllers  = new Dictionary <int, PC>(totalPlayerControllersCapacity);
            ReceivedPlayerCommandsBuffer = new List <TimestampedIdentifiedConnectionData <CMD> >(initialReceivedPlayerCommandsCapacity);

            OnlineSession.NetworkEventHandler = this;

            // Initialize snapshots
            SnapshotsCapacity   = snapshotsRingBufferCapacity;
            SnapshotsRingBuffer = new GlobalSnapshot <CMD, WS> [SnapshotsCapacity];
            for (int i = 0; i < SnapshotsCapacity; i++)
            {
                SnapshotsRingBuffer[i].SimulationEvents = new List <ISimulationEvent>();
                SnapshotsRingBuffer[i].CommandsSnapshot.Initialize(totalPlayerControllersCapacity);
                _simulationController.InitializeSnapshot(ref SnapshotsRingBuffer[i].WorldSnapshot);
            }

            _tmpConnectionsToUpdateBuffer = new Dictionary <int, int>(totalPlayerControllersCapacity);

            InitializeAtTick(0);
        }
Example #2
0
        public static void CreateOnlineSession()
        {
            if (OnlineSession)
            {
                GameObject.Destroy(OnlineSession.gameObject);
            }

            OnlineSession = GameObject.Instantiate <OnlineSession>(GameData.OnlineSessionPrefab);
        }