Пример #1
0
        public Room(IShamanLogger logger, ITaskSchedulerFactory taskSchedulerFactory, IRoomManager roomManager,
                    IRoomPropertiesContainer roomPropertiesContainer,
                    IRoomControllerFactory roomControllerFactory, IPacketSender packetSender,
                    Guid roomId, IRoomStateUpdater roomStateUpdater)
        {
            _logger                  = logger;
            _roomId                  = roomId;
            _roomStateUpdater        = roomStateUpdater;
            _createdOn               = DateTime.UtcNow;
            _taskScheduler           = taskSchedulerFactory.GetTaskScheduler();
            _roomPropertiesContainer = roomPropertiesContainer;
            _packetSender            = packetSender;

            _roomStats = new RoomStats(GetRoomId(), roomPropertiesContainer.GetPlayersCount());

            _roomController =
                roomControllerFactory.GetGameModeController(
                    new RoomContext(this), _taskScheduler, roomPropertiesContainer);

            _ = _taskScheduler.ScheduleOnInterval(() =>
            {
                var maxQueueSIze = _packetSender.GetMaxQueueSIze();
                _roomStats.AddMaxQueueSize(maxQueueSIze);
                _roomStats.AddAvgQueueSize(_packetSender.GetAverageQueueSize());
            }, 0, 1000, true);

            _ = _taskScheduler.ScheduleOnInterval(async() => await SendRoomStateUpdate(), 0, 2000, true);
        }