Example #1
0
        /// <summary>
        /// Creates a new instance
        /// </summary>
        public ParticleSystemManager(IManagerServiceProvider sceneInterface)
        {
            _sceneInterface = sceneInterface;

            ManagerProcessOrder = 100;

            Renderer = new QuadRenderer()
            {
                GraphicsDeviceService = GraphicsDeviceManager,
            };

            Renderer.LoadContent(Application.ContentManager);

            _activeParticles = SystemConsole.GetStatistic("ParticleSystem_ActiveParticles", SystemStatisticCategory.Rendering);
        }
Example #2
0
        /// <summary>
        /// Update loop call
        /// </summary>
        /// <param name="gameTime"/>
        void IUpdate.Update(GameTime gameTime)
        {
            var stat1 = SystemConsole.GetStatistic("Session_PlayerAgents_Count", SystemStatisticCategory.SceneGraph);

            stat1.AccumulationValue = _playerAgents.Count;
            var stat2 = SystemConsole.GetStatistic("Session_NonPlayerAgents_Count", SystemStatisticCategory.SceneGraph);

            stat2.AccumulationValue = _nonPlayerAgents.Count;
            var stat3 = SystemConsole.GetStatistic("Session_BytesPerSecondReceived", SystemStatisticCategory.SceneGraph);

            stat3.AccumulationValue = BytesPerSecondReceived;
            var stat4 = SystemConsole.GetStatistic("Session_BytesPerSecondSent", SystemStatisticCategory.SceneGraph);

            stat4.AccumulationValue = BytesPerSecondSent;

            if (IsHost)
            {
                if (CommandsToSynchronize.Count != 0)
                {
                    for (int i = 0; i < CommandsToSynchronize.Count; i++)
                    {
                        Command command = CommandsToSynchronize.Dequeue();
                        command.Id = command.LocalId;
                        SynchronizeCommandOnClients(command);
                        CommandsToSynchronize.Enqueue(command);
                    }

                    if (Status == SessionState.Starting || Status == SessionState.Playing)
                    {
                        _addPlayersToSynchronize = true;
                    }
                }
                if (SceneEntitiesToSynchronize.Count != 0)
                {
                    for (int i = 0; i < SceneEntitiesToSynchronize.Count; i++)
                    {
                        ISceneEntity entity = SceneEntitiesToSynchronize.Dequeue();
                        SynchronizeSceneEntitiesOnClients(entity);
                        SceneEntitiesToSynchronize.Enqueue(entity);
                    }

                    if (Status == SessionState.Starting || Status == SessionState.Playing)
                    {
                        _addPlayersToSynchronize = true;
                    }
                }

                if (_addPlayersToSynchronize)
                {
                    PlayersToSynchronize.AddRange(AllPlayers);
                    _addPlayersToSynchronize = false;
                }
            }

            // we loop through all local PlayerAgents to retrieve input commands
            if (_playerAgents.Count > 0)
            {
                _playerAgentsProcessQueue = new Queue <PlayerAgent>(_playerAgents);
                while (_playerAgentsProcessQueue.Count != 0)
                {
                    var playerAgent = _playerAgentsProcessQueue.Dequeue();
                    if (playerAgent.ParentObject != null)
                    {
                        playerAgent.Process(gameTime);
                    }
                }
            }

            if (_nonPlayerAgents.Count > 0)
            {
                _nonPlayerAgentsProcessQueue = new Queue <NonPlayerAgent>(_nonPlayerAgents);
                while (_nonPlayerAgentsProcessQueue.Count != 0)
                {
                    var nonPlayerAgent = _nonPlayerAgentsProcessQueue.Dequeue();
                    if (nonPlayerAgent.ParentObject != null)
                    {
                        nonPlayerAgent.Process(gameTime);
                    }
                }
            }

            // we update the session (sending & retrieving network data)
            Update(gameTime);

            // we retrieve all data incoming from the network
            ListenIncoming();

            // if commands and scene entities are created on the client, we tell the server synchronization is done so that the session can effectively start
            if (Status == SessionState.Starting && CommandsToSynchronize.Count == 0 && SceneEntitiesToSynchronize.Count == 0)
            {
                NotifyServerSynchronizationDoneOnClient();
            }
        }