예제 #1
0
        protected override void OnCreate()
        {
            FSLog.Info("PreviewClientSimulationSystemGroup OnCreate");
            Application.targetFrameRate     = 60;
            UnityEngine.Time.fixedDeltaTime = gameTime.TickInterval;
            ConfigVar.Init();
            ItemCreateUtilities.Init();
            ClientCharacterUtilities.Init();
            IconUtilities.Init();
            GameWorld.Active = new GameWorld();
            EntityManager.CreateEntity(typeof(Server));
            SetSingleton(new Server());

            inputSystem = World.GetOrCreateSystem <InputSystem>();
            m_systemsToUpdate.Add(inputSystem);

            initSystemGroup = World.GetOrCreateSystem <InitSystemGroup>();
            m_systemsToUpdate.Add(initSystemGroup);

            spawnCharacterSystem = World.GetOrCreateSystem <SpawnCharactersSystem>();
            m_systemsToUpdate.Add(spawnCharacterSystem);

            spawnSystemGroup = World.GetOrCreateSystem <SpawnSystemGroup>();
            m_systemsToUpdate.Add(spawnSystemGroup);

            updateReplicatedOwnerFlag = World.GetOrCreateSystem <UpdateReplicatedOwnerFlag>();
            m_systemsToUpdate.Add(updateReplicatedOwnerFlag);

            predictUpdateSystem = World.GetOrCreateSystem <PredictUpdateSystemGroup>();
            m_systemsToUpdate.Add(predictUpdateSystem);

            serverSystemGroup = World.GetOrCreateSystem <ServerSystemGroup>();
            m_systemsToUpdate.Add(serverSystemGroup);

            predictPresentationSystemGroup = World.GetOrCreateSystem <PredictPresentationSystemGroup>();
            m_systemsToUpdate.Add(predictPresentationSystemGroup);

            despawnSystemGroup = World.GetOrCreateSystem <DespawnSystemGroup>();
            m_systemsToUpdate.Add(despawnSystemGroup);

            addItemComponentSystem = World.GetOrCreateSystem <AddItemComponentSystem>();
            m_systemsToUpdate.Add(addItemComponentSystem);

            addDespawnServerSystem = World.GetOrCreateSystem <AddDespawnServerSystem>();
            m_systemsToUpdate.Add(addDespawnServerSystem);


            updateReplicatedOwnerFlag.SetLocalPlayerId(0);
        }
        protected override void OnCreate()
        {
            ConfigVar.Init();

            var commandLineArgs = Environment.GetCommandLineArgs();
            foreach (var commandLine in commandLineArgs)
            {
                if(commandLine.StartsWith("-Port:"))
                    NetworkConfig.serverPort.Value = commandLine.Substring(6);
                FSLog.Info($"commandLineArgs:{commandLine}");
            }
        

            ItemCreateUtilities.Init();

            GameWorld.Active = new GameWorld();
            UnityEngine.Time.fixedDeltaTime = GameTick.DefaultGameTick.TickInterval;

            EntityManager.CreateEntity(typeof(Server));
            SetSingleton(new Server());

            m_systemsToUpdate.Add(World.GetOrCreateSystem<WorldSceneEntitiesSystem>());
            networkServerSystem = World.GetOrCreateSystem<NetworkServerSystem>();

            m_systemsToUpdate.Add(World.GetOrCreateSystem<ReplicateEntityServerSystem>());
            m_systemsToUpdate.Add(World.GetOrCreateSystem<HandleCommandsSystem>());

            m_systemsToUpdate.Add(World.GetOrCreateSystem<InitSystemGroup>());
            m_systemsToUpdate.Add(World.GetOrCreateSystem<SpawnPlayerServerSystem>());
            m_systemsToUpdate.Add(World.GetOrCreateSystem<SpawnRobotsSystem>());
            m_systemsToUpdate.Add(World.GetOrCreateSystem<SpawnSystemGroup>());

            m_systemsToUpdate.Add(World.GetOrCreateSystem<RegisterEntityToNetwork>());

            m_systemsToUpdate.Add(World.GetOrCreateSystem<PrintGameStateSystem>());
            m_systemsToUpdate.Add(World.GetOrCreateSystem<RobotsControlSystem>());
            m_systemsToUpdate.Add(World.GetOrCreateSystem<UpdateReplicatedOwnerFlag>());

            m_systemsToUpdate.Add(World.GetOrCreateSystem<PredictUpdateSystemGroup>());
            m_systemsToUpdate.Add(World.GetOrCreateSystem<ServerSystemGroup>());

            m_systemsToUpdate.Add(World.GetOrCreateSystem<PredictPresentationSystemGroup>());
            
            m_systemsToUpdate.Add(World.GetOrCreateSystem<DespawnServerSystem>());
            m_systemsToUpdate.Add(World.GetOrCreateSystem<DespawnCharacterSystem>());
            m_systemsToUpdate.Add(World.GetOrCreateSystem<DespawnItemOwnerSystem>());
            m_systemsToUpdate.Add(World.GetOrCreateSystem<DespawnSystem>());            
        }
예제 #3
0
        protected override void OnUpdate()
        {
            var entity   = GetSingletonEntity <SpawnItemArray>();
            var requests = EntityManager.GetBuffer <SpawnItemRequest>(entity);

            //  FSLog.Info($"Spwan item :{requests.Length}");
            if (requests.Length == 0)
            {
                return;
            }

            var array = requests.ToNativeArray(Allocator.Temp);

            requests.Clear();

            foreach (var t in array)
            {
                var spawnItem = t;
                if (spawnItem.DeferFrame > 0)
                {
                    spawnItem.DeferFrame = spawnItem.DeferFrame - 1;
                    requests.Add(spawnItem);
                    continue;
                }

                FSLog.Info($"Spawn item:{spawnItem.Type}");


                var e = ItemCreateUtilities.CreateItem(EntityManager, spawnItem.Type,
                                                       spawnItem.OffPos, spawnItem.Owner);

                if (e == Entity.Null)
                {
                    continue;
                }

                if (spawnItem.Owner == Entity.Null)
                {
                    continue;
                }

                ItemAttachUtilities.ItemAttachToOwner(EntityManager,
                                                      e, spawnItem.Owner, Entity.Null);
            }

            array.Dispose();
        }
        protected override void OnCreate()
        {
            FSLog.Info("KitchenClientSimulationSystemGroup OnCreate");

            ConfigVar.Init();
            GameWorld.Active = new GameWorld();
            ItemCreateUtilities.Init();
            ClientCharacterUtilities.Init();
            MenuUtilities.Init();
            IconUtilities.Init();
            Application.targetFrameRate     = 60;
            UnityEngine.Time.fixedDeltaTime = GameTick.DefaultGameTick.TickInterval;

            worldSceneEntitiesSystem = World.GetOrCreateSystem <WorldSceneEntitiesSystem>();
            m_systemsToUpdate.Add(worldSceneEntitiesSystem);

            networkSystem = World.GetOrCreateSystem <NetworkClientSystem>();
            m_systemsToUpdate.Add(networkSystem);

            handleTimeSystem = World.GetOrCreateSystem <HandleTimeSystem>();
            m_systemsToUpdate.Add(handleTimeSystem);

            setRenderTimeSystem = World.GetOrCreateSystem <SetRenderTimeSystem>();
            m_systemsToUpdate.Add(setRenderTimeSystem);

            replicateEntitySystemGroup = World.GetOrCreateSystem <ReplicateEntitySystemGroup>();
            m_systemsToUpdate.Add(replicateEntitySystemGroup);


            setPredictTimeSystem = World.GetOrCreateSystem <SetPredictTimeSystem>();
            m_systemsToUpdate.Add(setPredictTimeSystem);

            predictSystem = World.GetOrCreateSystem <PredictSystem>();
            m_systemsToUpdate.Add(predictSystem);

            itemClientSystemGroup = World.GetOrCreateSystem <ItemClientSystemGroup>();
            m_systemsToUpdate.Add(itemClientSystemGroup);


            predictPresentationSystemGroup = World.GetOrCreateSystem <PredictPresentationSystemGroup>();
            m_systemsToUpdate.Add(predictPresentationSystemGroup);

            despawnSystemGroup = World.GetOrCreateSystem <DespawnSystemGroup>();
            m_systemsToUpdate.Add(despawnSystemGroup);
        }
예제 #5
0
        public override Entity Create(EntityManager entityManager, BundledResourceManager resourceManager,
                                      GameWorld world, ushort type)
        {
            //已经有预测的item,直接返回
            var e = AttachPredictItem(entityManager, type);

            if (e != Entity.Null)
            {
                return(e);
            }

            //没有预测的item,创建新的item
            e = ItemCreateUtilities.CreateItem(entityManager,
                                               (EntityType)type, new float3 {
                x = 0.0f, y = -30f, z = 0.0f
            }, Entity.Null);

            entityManager.AddComponentData(e, new NewServerEntity()
            {
                Tick = 1
            });
            entityManager.AddComponentData(e, new UIObject());
            return(e);
        }
        protected override void OnUpdate()
        {
            var entity   = GetSingletonEntity <SpawnItemArray>();
            var requests = EntityManager.GetBuffer <SpawnItemRequest>(entity);

            //  FSLog.Info($"Spwan item :{requests.Length}");
            if (requests.Length == 0)
            {
                return;
            }

            var array = requests.ToNativeArray(Allocator.Temp);

            requests.Clear();

            var query = EntityManager.CreateEntityQuery(ComponentType.ReadOnly <PredictedItem>());
            var predictedItemEntities = query.ToEntityArray(Allocator.TempJob);


            foreach (var t in array)
            {
                var spawnItem = t;
                if (spawnItem.DeferFrame > 0)
                {
                    spawnItem.DeferFrame = spawnItem.DeferFrame - 1;
                    requests.Add(spawnItem);
                    continue;
                }


                //排除掉重返的request
                var isRepeatRequest = false;
                foreach (var predictedItemEntity in predictedItemEntities)
                {
                    var predictedItem = EntityManager.GetComponentData <PredictedItem>(predictedItemEntity);
                    var ownerState    = EntityManager.GetComponentData <OwnerPredictedState>(predictedItemEntity);

                    if (predictedItem.StartTick == spawnItem.StartTick &&
                        ownerState.Owner == spawnItem.Owner)
                    {
                        isRepeatRequest = true;
                        ItemAttachUtilities.ItemAttachToOwner(EntityManager,
                                                              predictedItemEntity, spawnItem.Owner, Entity.Null);
                        break;
                    }
                }
                if (isRepeatRequest)
                {
                    continue;
                }

                FSLog.Info($"Spawn item:{spawnItem.Type}");

                var e = ItemCreateUtilities.CreateItem(EntityManager, spawnItem.Type,
                                                       spawnItem.OffPos, spawnItem.Owner);

                if (e == Entity.Null)
                {
                    continue;
                }

                EntityManager.AddComponentData(e, new PredictedItem()
                {
                    StartTick = spawnItem.StartTick
                });
                EntityManager.AddComponentData(e, new UIObject());
                if (spawnItem.Owner == Entity.Null)
                {
                    continue;
                }

                ItemAttachUtilities.ItemAttachToOwner(EntityManager,
                                                      e, spawnItem.Owner, Entity.Null);
            }

            predictedItemEntities.Dispose();
            array.Dispose();
        }