コード例 #1
0
    public ContextsServerWrapper(Contexts contexts, IUnityAssetManager assetManager, ICoRoutineManager coRoutineManager)
    {
        var ruleId = RuleMap.GetRuleId(SingletonManager.Get <ServerFileSystemConfigManager>().BootConfig.Rule);

        this.contexts = contexts;
#if (!ENTITASDISABLEVISUALDEBUGGING && UNITYEDITOR)
        this.contexts.InitializeContexObservers();
#endif

        SingletonManager.Get <MyProfilerManager>().Contexts = contexts;
        IBin2DManager bin2DManager = CreateBin2DManager();
        IniCurrentTimeSession();

        var entityIdGenerator          = new EntityIdGenerator(EntityIdGenerator.GlobalBaseId);
        var equipmentEntityIdGenerator = new EntityIdGenerator(EntityIdGenerator.EquipmentBaseId);
        InitEntityFactorySession(entityIdGenerator, equipmentEntityIdGenerator);


        InitCommonSession(bin2DManager, entityIdGenerator, equipmentEntityIdGenerator, ruleId, assetManager,
                          coRoutineManager);

        InitServerSession(bin2DManager, ruleId);

        contexts.vehicle.SetSimulationTime(0);



        InitialWeaponSkill();
    }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
0
        public static IGameContexts GetReplicationGameContexts(Contexts contexts, IBin2DManager bin = null)
        {
            var entitasContextInfos = new Core.EntityComponent.GameContexts();

            entitasContextInfos.AddContextInfo(new PlayerGameContext(contexts.player,
                                                                     GetBin2D(bin, (int)EEntityType.Player)));
            entitasContextInfos.AddContextInfo(new BulletGameContext(contexts.bullet,
                                                                     GetBin2D(bin, (int)EEntityType.Bullet)));
            entitasContextInfos.AddContextInfo(new ThrowingGameContext(contexts.throwing,
                                                                       GetBin2D(bin, (int)EEntityType.Throwing)));
            entitasContextInfos.AddContextInfo(new ClientEffectGameContext(contexts.clientEffect,
                                                                           GetBin2D(bin, (int)EEntityType.ClientEffect)));
            entitasContextInfos.AddContextInfo(new VehicleGameContext(contexts.vehicle,
                                                                      GetBin2D(bin, (int)EEntityType.Vehicle)));
            entitasContextInfos.AddContextInfo(new FreeMoveGameContext(contexts.freeMove,
                                                                       GetBin2D(bin, (int)EEntityType.FreeMove)));
            entitasContextInfos.AddContextInfo(new SoundGameContext(contexts.sound,
                                                                    GetBin2D(bin, (int)EEntityType.Sound)));
            if (IsIncludeSceneObject)
            {
                entitasContextInfos.AddContextInfo(new SceneObjectGameContext(contexts.sceneObject,
                                                                              GetBin2D(bin, (int)EEntityType.SceneObject)));
                entitasContextInfos.AddContextInfo(new MapObjectGameContext(contexts.mapObject,
                                                                            GetBin2D(bin, (int)EEntityType.MapObject)));
            }
#if UNITY_EDITOR
            foreach (var context in entitasContextInfos.AllContexts)
            {
                AssertUtility.Assert(context.CanContainComponent <EntityKeyComponent>());
                AssertUtility.Assert(context.CanContainComponent <FlagDestroyComponent>());
                AssertUtility.Assert(context.CanContainComponent <EntityAdapterComponent>());
            }
#endif
            return(entitasContextInfos);
        }
コード例 #5
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;");
        }
コード例 #6
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);
        }
コード例 #7
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);
        }
コード例 #8
0
        public static Bin2D <IGameEntity> GetBin2D(IBin2DManager bin, int type)
        {
            if (bin == null)
            {
                return(null);
            }
            var b = bin.GetBin2D(type);

            if (b == null)
            {
                return(null);
            }
            return(b.Bin2D);
        }
コード例 #9
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);
 }
コード例 #10
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);
        }
コード例 #11
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);
        }
コード例 #12
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);
 }
コード例 #13
0
    private void InitServerSession(IBin2DManager bin2DManager, int ruleId)
    {
        contexts.session.SetServerSessionObjects();
        var serverSessionObjects = contexts.session.serverSessionObjects;

        serverSessionObjects.SnapshotSelector = new SnapshotPool();
        serverSessionObjects.Bin2DConfig      = new Bin2DConfig(-9000, -9000, 9000, 9000, 100, 16000);

        serverSessionObjects.Bin2dManager = bin2DManager;

        serverSessionObjects.SimulationTimer             = new ServerSimulationTimer();
        serverSessionObjects.SimulationTimer.CurrentTime = 0;
        serverSessionObjects.VehicleTimer = new VehicleTimer();

        serverSessionObjects.GameRule   = ruleId;
        serverSessionObjects.FpsSatatus = new FpsSatatus();
    }
コード例 #14
0
ファイル: ServerRoom.cs プロジェクト: Hengle/CsharpCode
        public ServerRoom(IRoomId roomId, Contexts contexts, IRoomEventDispatchter eventDispatcher,
                          ICoRoutineManager coRoutineManager, IUnityAssetManager assetManager, IPlayerTokenGenerator tokenGenerator)
        {
            //SingletonManager.Get<ServerFileSystemConfigManager>().Reload();
            _state = RoomState.Initialized;

            _tokenGenerator   = tokenGenerator;
            _coRoutineManager = coRoutineManager;

            var entityIdGenerator          = new EntityIdGenerator(EntityIdGenerator.GlobalBaseId);
            var equipmentEntityIdGenerator = new EntityIdGenerator(EntityIdGenerator.EquipmentBaseId);
            var ruleId = RuleMap.GetRuleId(SingletonManager.Get <ServerFileSystemConfigManager>().BootConfig.Rule);

            RoomId    = roomId;
            _contexts = contexts;
#if (!ENTITAS_DISABLE_VISUAL_DEBUGGING && UNITY_EDITOR)
            _contexts.InitializeContexObservers();
#endif
            SingletonManager.Get <MyProfilerManager>().Contexts = _contexts;
            _eventDispatcher = eventDispatcher;
            _bin2DManager    = CreateBin2DManager();
            IniCurrentTimeSession();


            InitEntityFactorySession(entityIdGenerator, equipmentEntityIdGenerator);
            _assetManager = assetManager;


            InitCommonSession(entityIdGenerator,
                              equipmentEntityIdGenerator, ruleId);

            InitServerSession(_bin2DManager, ruleId);


            _contexts.vehicle.SetSimulationTime(0);
            MessageDispatcher    = CreateNetworMessageHandlers();
            _snapshotFactory     = new SnapshotFactory(_contexts.session.commonSession.GameContexts);
            _sessionStateMachine = new ServerSessionStateMachine(_contexts, this);

            _damager = new SimplePlayerDamager(this);
            VehicleDamageUtility._damager = _damager;
            _sendSnapshotManager          = new SendSnapshotManager(_contexts);

            InitialWeaponSkill();
        }
コード例 #15
0
    private void InitCommonSession(IBin2DManager bin2DManager, EntityIdGenerator entityIdGenerator,
                                   EntityIdGenerator equipmentEntityIdGenerator, int ruleId,
                                   IUnityAssetManager assetManager, ICoRoutineManager coRoutineManager)
    {
        contexts.session.SetCommonSession();
        var commonSession = contexts.session.commonSession;

        commonSession.InitPosition = Vector3.zero;

        commonSession.AssetManager = assetManager;

        commonSession.CoRoutineManager = coRoutineManager;
        commonSession.GameContexts     =
            GameContextsUtility.GetReplicationGameContexts(contexts, bin2DManager);
        commonSession.EntityIdGenerator          = entityIdGenerator;
        commonSession.EquipmentEntityIdGenerator = equipmentEntityIdGenerator;
        commonSession.RoomInfo = new RoomInfo
        {
            MapId  = SingletonManager.Get <ServerFileSystemConfigManager>().BootConfig.MapId,
            ModeId = ruleId
        };

        MakeWeaponLogicManager();
    }
コード例 #16
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;");
        }