コード例 #1
0
        public ISnapshot GeneratePartialSnapshot(int seq,
                                                 EntityKey self,
                                                 Vector3 position,
                                                 Bin2DConfig config,
                                                 IBin2DManager bin,
                                                 List <IGameEntity> preEntitys)
        {
            _preEntitys.Clear();
            _seq = seq;
            _filter.Init(self, position);
            _snapshot = Snapshot.Allocate();

            foreach (var gameEntity in preEntitys)
            {
                DoInsert(gameEntity);
                _preEntitys.Add(gameEntity.EntityKey);
            }


            foreach (var bin2DState in bin.GetBin2Ds())
            {
                Rect rect = new Rect(position.x - bin2DState.VisibleRadius, position.z - bin2DState.VisibleRadius,
                                     bin2DState.VisibleRadius * 2, bin2DState.VisibleRadius * 2);
                bin2DState.Retrieve(position, rect, _doInsert);
            }


            return(_snapshot);
        }
コード例 #2
0
        public static IBin2DManager GetReplicationBin2DManager(float minX, float minY, float maxX, float maxY,
                                                               int visibleRadius, Dictionary <int, int> customVisibleRadiusDict)
        {
            IBin2DManager bin2DManager = new Bin2DManager();

            for (int i = 0; i < (int)EEntityType.End; i++)
            {
                var v = visibleRadius;
                if (customVisibleRadiusDict.ContainsKey(i))
                {
                    v = customVisibleRadiusDict[i];
                }

                var         cell    = next_p2(v) / 4 > 8 ? next_p2(v) / 4 : 8;
                Bin2DConfig _config = new Bin2DConfig(minX, minY, maxX, maxY, cell, v);
                if (i == (int)EEntityType.SceneObject || i == (int)EEntityType.MapObject)
                {
                    bin2DManager.AddBin2D(i, new Bin2D <IGameEntity>(_config), v, SceneObjectFilter);
                }
                else
                {
                    bin2DManager.AddBin2D(i, new Bin2D <IGameEntity>(_config), v);
                }
            }

            return(bin2DManager);
        }
コード例 #3
0
        //private GameObject[] roots;

        public void Initial(Contexts contexts)
        {
            this.contexts = contexts;

            Bin2DConfig config = new Bin2DConfig(-4000, -4000, 4000, 4000, 50, 50);

            map      = new Map2D <GameObject>(config);
            smallMap = new Map2D <GameObject>(config);
            MidMap   = new Map2D <GameObject>(config);

            InternalBounds bouds = map.GetInternalBounds(new Rect(-4000, -4000, 8000, 8000));

            MaxLen = bouds.MaxX - bouds.MinX + 1;

            recSet     = new BitArray(100);
            lastRecSet = new BitArray(100);
            countDic   = new int[100];

            lastSet     = new BitArray(MaxLen * MaxLen);
            currentSet  = new BitArray(MaxLen * MaxLen);
            lastSetS    = new BitArray(MaxLen * MaxLen);
            currentSetS = new BitArray(MaxLen * MaxLen);
            lastSetM    = new BitArray(MaxLen * MaxLen);
            currentSetM = new BitArray(MaxLen * MaxLen);

            //roots = new GameObject[MaxLen * MaxLen];

            //for (int i = 0; i < MaxLen * MaxLen; i++)
            //{
            //   roots[i] = new GameObject();
            //   roots[i].name = "root" + i;
            // }
        }
コード例 #4
0
        public void SendSnapshot(int interval, SnapshotFactory snapshotFactory,
                                 Dictionary <INetworkChannel, PlayerEntity> channelToPlayer)
        {
            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;

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

            foreach (var entry in channelToPlayer)
            {
                INetworkChannel channel = entry.Key;
                PlayerEntity    player  = entry.Value;
                if (player.hasStage &&
                    player.stage.CanSendSnapshot() &&
                    channel.IsConnected &&
                    !player.network.NetworkChannel.Serializer.MessageTypeInfo.SkipSendSnapShot(serverTime))
                {
                    var p = ObjectAllocatorHolder <CreateSnapshotParams> .Allocate().Build(snapshotFactory, player,
                                                                                           bin2DConfig, bin, serverTime,
                                                                                           snapshotSeq,
                                                                                           vehicleSimulationTime, channel);

                    var entitys = p.PreEnitys;
                    AddTeamPlayers(player, entitys, _contexts);
                    AddGlobalFreeMove(player, entitys, freeMoveEntitys);
                    AddWeapon(player, entitys, weaponEntities);
                    _sendSnapshotTasks.Add(p);
                }
                else
                {
                    player.network.NetworkChannel.Serializer.MessageTypeInfo.IncSendSnapShot();
                    _logger.DebugFormat("channel:{2} skip SendSnapshot :{0} {1}!", channel.IsConnected,
                                        !player.network.NetworkChannel.Serializer.MessageTypeInfo.SkipSendSnapShot(serverTime),
                                        channel.IdInfo());
                }
            }

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

            _logger.DebugFormat("SendSnapshot Threads Done;");
        }
コード例 #5
0
        /// <summary>
        /// Creates a new Bin.
        /// </summary>
        public Map2D(Bin2DConfig config)
        {
            _grid = new Grid2D <LinkedList <T> >(config.GridWidth, config.GridHeight);

            CellWidth   = config.CellWidth;
            CellHeight  = config.CellHeight;
            _bottomLeft = config.BottomLeft;
            _topRight   = new Vector2(_bottomLeft.x + config.GridWidth * config.CellWidth,
                                      _bottomLeft.y + config.GridHeight * config.CellHeight);
        }
コード例 #6
0
 public CreateSnapshotParams Build(SnapshotFactory snapshotFactory, PlayerEntity player, Bin2DConfig bin2DConfig,
                                   IBin2DManager bin, int serverTime, int snapshotSeq, int vehicleSimulationTime, INetworkChannel channel)
 {
     SnapshotFactory       = snapshotFactory;
     Player                = player;
     Bin2DConfig           = bin2DConfig;
     Bin                   = bin;
     ServerTime            = serverTime;
     SnapshotSeq           = snapshotSeq;
     VehicleSimulationTime = vehicleSimulationTime;
     Channel               = channel;
     PreEnitys.Clear();
     return(this);
 }
コード例 #7
0
        protected override void OnCleanUp()
        {
            Player                = null;
            Bin2DConfig           = null;
            Bin                   = null;
            ServerTime            = 0;
            SnapshotSeq           = 0;
            VehicleSimulationTime = 0;
            Channel               = null;

            PreEntitas.Clear();
            _contexts = null;
            ObjectAllocatorHolder <CreateSnapshotTask> .Free(this);
        }
コード例 #8
0
        protected override void OnCleanUp()
        {
            Snapshot              = null;
            SnapshotFactory       = null;
            Player                = null;
            Bin2DConfig           = null;
            Bin                   = null;
            ServerTime            = 0;
            SnapshotSeq           = 0;
            VehicleSimulationTime = 0;
            Channel               = null;

            PreEnitys.Clear();
            ObjectAllocatorHolder <CreateSnapshotParams> .Free(this);
        }
コード例 #9
0
 public CreateSnapshotTask Build(PlayerEntity player, Bin2DConfig bin2DConfig,
                                 IBin2DManager bin, int serverTime, int snapshotSeq, int vehicleSimulationTime,
                                 INetworkChannel channel, Contexts _newContexts)
 {
     Player                = player;
     Bin2DConfig           = bin2DConfig;
     Bin                   = bin;
     ServerTime            = serverTime;
     SnapshotSeq           = snapshotSeq;
     VehicleSimulationTime = vehicleSimulationTime;
     Channel               = channel;
     PreEntitas.Clear();
     _contexts = _newContexts;
     Status    = 0;
     return(this);
 }
コード例 #10
0
        public ISnapshot GeneratePerPlayerSnapshot(int seq, EntityKey self, Vector3 position, Bin2DConfig config,
                                                   IBin2DManager bin, List <IGameEntity> preEntitys, bool isAccountStage,
                                                   bool isPrepareStage, SnapshotEntityInsert onInsert)
        {
            preEntityKeys.Clear();

            sendSnapshotFilter.Init(self, position);
            snapshot            = Snapshot.Allocate();
            forPre              = true;
            this.isPrepareStage = isPrepareStage;
            this.isAccountStage = isAccountStage;
            this.seq            = seq;
            this.onInsert       = onInsert;
            foreach (var gameEntity in preEntitys)
            {
                DoInsert(gameEntity);
                preEntityKeys.Add(gameEntity.EntityKey);
            }

            forPre = false;

            foreach (var bin2DState in bin.GetBin2Ds())
            {
                Rect rect = new Rect(position.x - bin2DState.VisibleRadius, position.z - bin2DState.VisibleRadius,
                                     bin2DState.VisibleRadius * 2, bin2DState.VisibleRadius * 2);
                bin2DState.Retrieve(position, rect, gameEntity => DoInsert(gameEntity));
            }

            return(snapshot);
        }
コード例 #11
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;");
        }
コード例 #12
0
        public ISnapshot GeneratePerPlayerSnapshot(int seq, EntityKey self, Vector3 position, Bin2DConfig config,
                                                   IBin2DManager bin, List <IGameEntity> preEntitys)
        {
            var factory = ObjectAllocatorHolder <PartialSnapshotFactory> .Allocate();

            var ret = factory.GeneratePartialSnapshot(seq, self, position, config, bin, preEntitys);

            factory.ReleaseReference();
            return(ret);
        }
コード例 #13
0
        public ISnapshot GeneratePerPlayerSnapshot(int seq, EntityKey self, Vector3 position, Bin2DConfig config,
                                                   IBin2DManager bin, List <IGameEntity> preEntitys, bool isAccountStage,
                                                   bool isPrepareStage, SnapshotEntityInsert insertFun)
        {
            var helper = ObjectAllocatorHolder <SnapshotCreationHelper> .Allocate();

            var snapshot = helper.GeneratePerPlayerSnapshot(seq, self, position, config, bin, preEntitys, isAccountStage,
                                                            isPrepareStage, null);

            helper.ReleaseReference();
            return(snapshot);
        }