void WriteLastMoveTimestampIfDirty(NetOutgoingMessage inOutputStream, ClientProxy inClientProxy) { //first, dirty? bool isTimestampDirty = inClientProxy.IsLastMoveTimestampDirty(); inOutputStream.Write(isTimestampDirty); if (isTimestampDirty) { inOutputStream.Write(inClientProxy.GetUnprocessedMoveList().GetLastMoveTimestamp()); inClientProxy.SetIsLastMoveTimestampDirty(false); } }
void HandleInputPacket(ClientProxy inClientProxy, NetIncomingMessage inInputStream) { Move move = new Move(); uint32_t moveCount = inInputStream.ReadUInt32(2); for (; moveCount > 0; --moveCount) { if (move.Read(inInputStream)) { //log.InfoFormat("recv move {0}, {1}, {2}, {3}", move.GetDeltaTime(), move.GetInputState(), move.GetTimestamp(), moveCount); if (inClientProxy.GetUnprocessedMoveList().AddMoveIfNew(move)) { inClientProxy.SetIsLastMoveTimestampDirty(true); } } } }
public override void Update() { base.Update(); oldLocation.Copy(GetLocation()); oldVelocity.Copy(GetVelocity()); oldRotation.Copy(GetRotation()); //are you controlled by a player? //if so, is there a move we haven't processed yet? if (mActorControlType == EActorControlType.ESCT_Human) { if (mClient != null) { MoveList moveList = mClient.GetUnprocessedMoveList(); foreach (var unprocessedMove in moveList.mMoves) { var currentState = unprocessedMove.GetInputState(); float deltaTime = unprocessedMove.GetDeltaTime(); ProcessInput(deltaTime, currentState); // 서버만 y 축 좌표를 업데이트한다. 서버에서는 물리 연산이 없으므로 if (currentState.mIsChangeY) { // todo : y 좌표값 변경 허가 여부 체크 // raycast를 사용하여 위, 아래 // up 근처에 경사로가 있는지 // down 낙하 지점인지 GetLocation().y = currentState.mYaxis; } SimulateMovement(deltaTime); //log.InfoFormat( "Server Move Time: {0} deltaTime: {1} location:{2}, old_location{3}, player_id{4}", unprocessedMove.GetTimestamp(), deltaTime, GetLocation(), oldLocation, GetPlayerId() ); //Log.Information("Location:" + GetLocation() + ", Velocity:" + GetVelocity() + ", player_id:" + GetPlayerId()); } moveList.Clear(); } } else { //do some AI stuff SimulateMovement(Timing.sInstance.GetDeltaTime()); } HandleShooting(); HandleBomb(); #if _USE_BEPU_PHYSICS mCharacterController.Body.Position = GetLocation().CopyTo(ref physicsLocation); mDirection.CopyTo(ref mCharacterController.HorizontalMotionConstraint.LastDirection); if (mCharacterController.HorizontalMotionConstraint.MovementMode != BEPUphysics.Character.MovementMode.Floating) { if (GetVelocity().IsZero() == false) { mCharacterController.Body.LinearVelocity = GetVelocity().CopyTo(ref physicsVelocity); } } #endif if (!oldLocation.Equals(GetLocation()) || !oldVelocity.Equals(GetVelocity()) || !oldRotation.Equals(GetRotation()) ) { //log.InfoFormat("ol {0} cl {1} ov {2} cv {3} or{4} cr{5}", oldLocation, GetLocation(), oldVelocity, GetVelocity(), oldRotation, GetRotation()); NetworkManagerServer.sInstance.SetStateDirty(GetNetworkId(), WorldId, (uint)EActorReplicationState.ECRS_Pose); } }