示例#1
0
        protected override VehicleEntity[] GetLatestEntities()
        {
            var vehicleEntity = PlayerVehicleUtility.GetControlledVehicle(_serverContexts.player.flagSelfEntity, _serverContexts.vehicle);

            if (vehicleEntity != null)
            {
                _one[0] = vehicleEntity;
                return(_one);
            }
            return(_zero);
        }
示例#2
0
        public override void DoHandle(INetworkChannel channel, PlayerEntity entity,
                                      EClient2ServerMessage eClient2ServerMessage, ReusableList <IVehicleCmd> messageBody)
        {
            //_logger.DebugFormat("Server VehicleCmd seq is {0}", messageBody.Seq);
            var vehicle = PlayerVehicleUtility.GetControlledVehicle(entity, _contexts.vehicle);
            var cmdList = messageBody.Value;

            if (vehicle != null)
            {
                vehicle.vehicleCmd.AddLatestList(cmdList);
            }

            CheckVehicleCmdList(cmdList);
        }
        private void CreateVehicleCmd(PlayerEntity player)
        {
            var controlledVehicle = PlayerVehicleUtility.GetControlledVehicle(player, _contexts.vehicle);

            if (controlledVehicle != null)
            {
                var vehicleCmd = VehicleEntityUtility.CreateVehicleCmd(_vehicleCmdGenerator, _contexts.vehicle, player,
                                                                       _simulationTimer.CurrentTime);

                if (vehicleCmd != null)
                {
                    controlledVehicle.vehicleCmd.AddLatest(vehicleCmd);
                }
            }
        }
示例#4
0
        private void SendVehicleCmd(PlayerEntity player, INetworkChannel channel)
        {
            var controlledVehicle = PlayerVehicleUtility.GetControlledVehicle(player, _contexts.vehicle);

            if (controlledVehicle != null)
            {
                var list = controlledVehicle.vehicleCmd.CreateLatestList();

                if (channel != null && list.Value.Count > 0)
                {
                    channel.SendRealTime((int)EClient2ServerMessage.VehicleCmd, list);
                }

                list.ReleaseReference();
            }
        }
        public void OnPlayback()
        {
            try
            {
                SingletonManager.Get <DurationHelp>().ProfileStart(CustomProfilerStep.VehiclePlayBack);
                var selfPlayer  = _playerContext.flagSelfEntity;
                var selfVehicle = PlayerVehicleUtility.GetControlledVehicle(selfPlayer, _vehicleContext);

                if (SharedConfig.DynamicPrediction)
                {
                    if (selfVehicle != null)
                    {
                        VehicleStateUtility.SyncOnPlayerRideOn(selfVehicle);
                    }
                }
                else
                {
                    var vehicles = _vehicles.GetEntities();
                    for (int i = 0; i < vehicles.Length; ++i)
                    {
                        var vehicle = vehicles[i];
                        if (vehicle != selfVehicle && !vehicle.isFlagOffline && VehicleStateUtility.IsReadyForSync(vehicle))
                        {
                            VehicleStateUtility.SyncFromComponent(vehicle);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _logger.ErrorFormat("Exception {0}", e);
            }
            finally
            {
                SingletonManager.Get <DurationHelp>().ProfileEnd(CustomProfilerStep.VehiclePlayBack);
            }
        }
示例#6
0
        private void MergeVehicleCmd(PlayerEntity player)
        {
            var controlledVehicle = PlayerVehicleUtility.GetControlledVehicle(player, _contexts.vehicle);

            if (controlledVehicle != null)
            {
                var tempList = controlledVehicle.vehicleCmd.UserCmdStepList;
                if (tempList.Count == 0)
                {
                    return;
                }
                var last = tempList.Last();
                last.AcquireReference();
                foreach (var cmd in tempList)
                {
                    cmd.ReleaseReference();
                }

                tempList.Clear();
                controlledVehicle.vehicleCmd.AddLatest(last);

                last.ReleaseReference();
            }
        }
        protected override void InternalExecute()
        {
            while (true)
            {
                var item = _contexts.session.clientSessionObjects.Replay.GetItem(EReplayMessageType.OUT, MyGameTime.stage,
                                                                                 MyGameTime.seq,
                                                                                 _contexts.session.clientSessionObjects.NetworkChannel.Id);
                if (item == null)
                {
                    return;
                }

                if (item.MessageBody is ReusableList <UpdateLatestPacakge> && item.ProcessSeq == MyGameTime.seq)
                {
                    var last = _contexts.player.flagSelfEntity.userCmd.Latest as UserCmd;
                    ReusableList <UpdateLatestPacakge> reusableList =
                        item.MessageBody as ReusableList <UpdateLatestPacakge>;
                    var current = reusableList.Value.Last();
                    foreach (var updateComponent in current.UpdateComponents)
                    {
                        if (updateComponent is SendUserCmdComponent)
                        {
                            var right = updateComponent as SendUserCmdComponent;
                            _logger.DebugFormat("replay usercmd: last:{0}, timeseq:{1}, msgSeq:{2} {3}", last.Seq, MyGameTime.seq, current.Head.LastUserCmdSeq, item);
                            //last.Seq = current.Head.UserCmdSeq;
                            //last.SnapshotId = current.Head.LastSnapshotId;
                            _contexts.session.clientSessionObjects.TimeManager.RenderTime = right.RenderTime;
                            last.FrameInterval  = right.FrameInterval;
                            last.MoveHorizontal = right.MoveHorizontal;
                            last.MoveUpDown     = right.MoveUpDown;
                            last.MoveVertical   = right.MoveVertical;
                            last.DeltaYaw       = right.DeltaYaw;
                            last.DeltaPitch     = right.DeltaPitch;
                            last.RenderTime     = right.RenderTime;
                            last.ClientTime     = right.ClientTime;
                            last.ChangedSeat    = right.ChangedSeat;

                            last.BeState      = right.BeState;
                            last.Buttons      = right.Buttons;
                            last.SwitchNumber = right.SwitchNumber;

                            last.CurWeapon         = right.CurWeapon;
                            last.UseEntityId       = right.UseEntityId;
                            last.ManualPickUpEquip = right.ManualPickUpEquip;

                            last.AutoPickUpEquip = UserCmd.CopyList(last.AutoPickUpEquip, right.AutoPickUpEquip);
                            last.UseVehicleSeat  = right.UseVehicleSeat;
                            last.UseType         = right.UseType;
                            last.ChangeChannel   = right.ChangeChannel;
                            last.BagIndex        = right.BagIndex;
                        }
                    }
                }

                if (item.MessageBody is ReusableList <IVehicleCmd> && item.ProcessSeq == MyGameTime.seq)
                {
                    var cmd = (item.MessageBody as ReusableList <IVehicleCmd>).Value.Last();
                    var controlledVehicle = PlayerVehicleUtility.GetControlledVehicle(_contexts.player.flagSelfEntity, _contexts.vehicle);
                    if (controlledVehicle != null)
                    {
                        controlledVehicle.vehicleCmd.AddLatest(cmd);
                    }
                }
                if (item.MessageBody is ReusableList <IRefCounter> )
                {
                    foreach (var updateLatestPacakge in (item.MessageBody as ReusableList <UpdateLatestPacakge>).Value)
                    {
                        updateLatestPacakge.ReleaseReference();
                    }
                }
                item.ReleaseReference();
            }
        }