示例#1
0
        public void ProcessCommand(int connectionId, int tick, ref NetworkReader data)
        {
            var serverTick    = GetSingleton <WorldTime>().Tick;
            var commandBuffer = new UserCommandBuffer();

            commandBuffer.Command.Deserialize(ref data);
            //  FSLog.Info($"ServerTick:{tick}");
            // FSLog.Debug($"[{inSequence}] server recv data");
            Entities.ForEach((Entity e, ref Connection con /*,ref UserCommand command*/) =>
            {
                //FSLog.Info($"[{ConnectionId},{con.id}] recv command:{commandBuffer.command.renderTick}," +
                //      $"{commandBuffer.command.checkTick}," +
                //      $"{tick}");
                if (connectionId != con.SessionId)
                {
                    return;
                }

                if (commandBuffer.Command.CheckTick >= serverTick)
                {
                    EntityManager.GetBuffer <UserCommandBuffer>(e).Add(commandBuffer);
                }
                //   FSLog.Info($"buffer command:{commandBuffer.command.renderTick},{commandBuffer.command.checkTick},{tick}");
                //     FSLog.Info($"UserCommandBuffer add new {commandBuffer.command.checkTick},{tick}");
            });
        }
示例#2
0
        protected override void OnUpdate()
        {
            return;

            var gameQuery = GetEntityQuery(new EntityQueryDesc
            {
                All = new ComponentType[]
                {
                    typeof(GameStateComponent)
                }
            });

            if (gameQuery.CalculateEntityCount() < 1)
            {
                return;
            }

            var gameEntities = gameQuery.ToEntityArray(Allocator.TempJob);
            var gameState    = EntityManager.GetComponentData <GameStateComponent>(gameEntities[0]);

            if (gameState.State != GameState.Playing)
            {
                gameEntities.Dispose();
                return;
            }
            gameEntities.Dispose();
            //    FSLog.Info("RobotsControlSystem");
            Entities
            .WithStructuralChanges()
            .ForEach((Entity entity, in Robot robot) =>
            {
                var serverTick    = GetSingleton <WorldTime>().Tick;
                var commandBuffer = new UserCommandBuffer();

                if (serverTick % 100 == 0)
                {
                    x = random.NextFloat(-1, 1);
                    z = random.NextFloat(-1, 1);
                }

                if (serverTick % 100 < 10)
                {
                    commandBuffer.Command.TargetDir =
                        (new Vector3(x, 0, z)).normalized;
                }

                //  commandBuffer.Command.Buttons.Set(UserCommand.Button.Jump, true);
                commandBuffer.Command.CheckTick = serverTick + 1;
                EntityManager.GetBuffer <UserCommandBuffer>(entity).Add(commandBuffer);
            }).Run();
        }