Ejemplo n.º 1
0
 public void Offer(Job job)
 {
     _queue.AddRef();
     _queue.Enqueue(job);
 }
Ejemplo n.º 2
0
        public void SendSnapshot(int interval, SnapshotFactory snapshotFactory)
        {
            _logger.InfoFormat("SendSnapShot");
            this.snapshotFactory = snapshotFactory;
            var           sessionObjects        = _contexts.session.serverSessionObjects;
            Bin2DConfig   bin2DConfig           = sessionObjects.Bin2DConfig;
            IBin2DManager bin                   = sessionObjects.Bin2dManager;
            int           snapshotSeq           = sessionObjects.GetNextSnapshotSeq();
            int           vehicleSimulationTime = sessionObjects.SimulationTimer.CurrentTime;
            int           serverTime            = _contexts.session.currentTimeObject.CurrentTime;

            snapshotSendTasks.Clear();
            var freeMoveEntitys = _globalFreeMoveEntities.GetEntities();
            var weaponEntities  = _globalWeaponEntities.GetEntities();

            foreach (var player in _playerEntities.GetEntities())
            {
                if (player.hasStage && player.stage.CanSendSnapshot() && player.network.NetworkChannel.IsConnected &&
                    !player.network.NetworkChannel.Serializer.MessageTypeInfo.SkipSendSnapShot(serverTime))
                {
                    var p = ObjectAllocatorHolder <CreateSnapshotTask> .Allocate().Build(player,
                                                                                         bin2DConfig, bin, serverTime, snapshotSeq, vehicleSimulationTime, player.network.NetworkChannel,
                                                                                         _contexts);

                    AddTeamPlayers(player, p.PreEntitas, _contexts);
                    AddGlobalFreeMove(player, p.PreEntitas, freeMoveEntitys);
                    AddWeapon(player, p.PreEntitas, weaponEntities);

                    snapshotSendTasks.Add(p);
#if ENABLE_NEW_SENDSNAPSHOT_THREAD
                    if (SharedConfig.MutilThread)
                    {
                        _queue.AddRef();
                        _queue.Enqueue(p);
                    }
#endif

                    //_logger.InfoFormat("SendSnapshot:{0} {1}",player.entityKey.Value, player.position.Value);
                }
                else
                {
                    player.network.NetworkChannel.Serializer.MessageTypeInfo.IncSendSnapShot();
                    _logger.DebugFormat("channel:{2} skip SendSnapshot :{0} {1}!",
                                        player.network.NetworkChannel.IsConnected,
                                        !player.network.NetworkChannel.Serializer.MessageTypeInfo.SkipSendSnapShot(serverTime),
                                        player.network.NetworkChannel.IdInfo());
                }
            }

            if (SharedConfig.MutilThread)
            {
#if ENABLE_NEW_SENDSNAPSHOT_THREAD
                ConsumerExecute();
#else
                MutilExecute();
#endif
            }
            else
            {
                MainExecute();
            }

            _logger.DebugFormat("SendSnapshot Threads Done;");
        }