public void OnSimUpdated(FrameSnapshot frame, float interpolation, bool replay) { if (!replay) { // Don't update selections from sim during play, it's controlled via direct user input return; } // Do update selections during replay // @TODO: determine which entities were actually updated last tick and only loop through them (raise event when SimSystem makes update?) SimSelectable[] simSelections = frame.Snapshot.GetComponents <SimSelectable>().Where(s => s.Selected).ToArray(); if (simSelections.Length <= 0) { Clear(); return; } List <SelectableComponent> remainingSelections = Selected.ToList(); for (int i = 0; i < simSelections.Length; i++) { SelectableComponent selection = GameState.GetGameObject(simSelections[i].EntityID).GameObject.GetComponent <SelectableComponent>(); remainingSelections.Remove(selection); Select(selection, true); } foreach (SelectableComponent deselect in remainingSelections) { deselect.Deselect(); } }
public bool TranslatePacket(BasePacketHeader packet) { bool toReturn = false; if (packet != null) { switch (packet.messageHeader.MessageType) { case MessageHeaderMessage.Types.MessageType.RigidBodyUpdate: FrameSnapshot snapshot = FindOrCreateSnapshotForFrame(packet.messageHeader.FrameId); ProcessRigidBodyFrameUpdate(packet, snapshot); toReturn = true; break; case MessageHeaderMessage.Types.MessageType.ShapeCreated: ProcessShapeAdded(packet); toReturn = true; break; case MessageHeaderMessage.Types.MessageType.FrameStats: ProcessFrameStats(packet); toReturn = true; break; default: break; } } return(toReturn); }
private void ProcessRigidBodyFrameUpdate(BasePacketHeader packet, FrameSnapshot snapshot) { RigidBodyListPacket rigidBodyList = RigidBodyListPacket.Parser.ParseFrom(packet.PacketBytes, packet.startOfPacketData, packet.messageHeader.DataSize); foreach (RigidBodyPacket packetBody in rigidBodyList.RigidBodies) { // todo: error handle - what if the rigid body already exists? snapshot.AddRigidBody(packetBody); } }
/// <summary> /// 玩家请求获取当前战场快照 /// </summary> internal void HandleRequestSnapshot(Battle battle, Protos.GC2BS_RequestSnapshot request, Protos.BS2GC_RequestSnapshotRet ret) { FrameSnapshot snapshot = battle.GetSnapshot(request.Frame); ret.ReqFrame = request.Frame; ret.CurFrame = battle.frame; if (snapshot != null) { ret.Snapshot = snapshot.data; } }
public void FreeBaselines() { if (Baseline != null) { Baseline.ReleaseRefrence(); Baseline = null; } BaselineUpdateTick = -1; BaselineUsed = 0; }
public void OnRequestFullUpdate() { // client requests a full update _lastSnapshot = null; // free old baseline snapshot FreeBaselines(); Baseline = Program.FrameSnapshotManager.CreateEmptySnapshot(0, 1 << 11); Out.Debug("Sending full update to client \"{0}\"", GetClientName()); }
public BaseClient(BaseServer server) { Server = server; SignonState = ESignonState.None; _sendServerInfo = false; _conVarsChanged = false; _lastSnapshot = null; _forceWaitForTick = -1; _deltaTick = -1; BaselineUsed = 0; Baseline = null; }
public FrameSnapshot FindOrCreateSnapshotForFrame(int frameId) { FrameSnapshot snapshot = FindSnapshotForFrame(frameId); if (snapshot == null) { snapshot = new FrameSnapshot(); snapshot.FrameId = frameId; ConstructedSnaphots.Add(frameId, new Tuple <bool, FrameSnapshot>(false, snapshot)); } return(snapshot); }
public FrameSnapshot FindSnapshotForFrame(int frameId) { FrameSnapshot snapshot = null; // todo: Error handling - if you do packets broken up into bits, they you'll need to keep a list of the bits you've recieved, so you know if you recieve a piece twice! Tuple <bool, FrameSnapshot> tuple = null; if (ConstructedSnaphots.TryGetValue(frameId, out tuple)) { snapshot = tuple.Item2; } return(snapshot); }
public void SetupPackInfo(FrameSnapshot snapshot) { // TODO: Setup PVS visibility CurrentFrame = new ClientFrame(); CurrentFrame.Init(snapshot); var maxFrames = ClientFrame.MaxClientFrames; if (maxFrames < AddClientFrame(CurrentFrame)) { RemoveOldestFrame(); } }
public void OnSimUpdated(FrameSnapshot frame, float interpolation, bool replay) { // @TODO: determine which entities were actually updated last tick and only loop through them (raise event when SimSystem makes update?) SimPosition[] positions = frame.Snapshot.GetComponents <SimPosition>().ToArray(); SimPosition[] nextPositions = frame.NextSnapshot.GetComponents <SimPosition>().ToArray(); for (int i = 0; i < positions.Length; i++) { // @TODO: more efficiently get GameObject, related SimComponents and MonoBehaviours GameObject go = GameState.GetGameObject(positions[i].EntityID).GameObject; Transform transform = go.GetComponent <Transform>(); Vector2 newPosition = Vector2.Lerp(positions[i].Position, nextPositions[i].Position, interpolation); transform.position = new Vector3(newPosition.x, newPosition.y, transform.position.z); } }
public void Clear() { if (_netChannel != null) { _netChannel.Shutdown("Disconnect by server"); _netChannel = null; } _clientName = string.Empty; SignonState = ESignonState.None; _sendServerInfo = false; _conVarsChanged = false; NextMessageTime = 0; _lastSnapshot = null; _forceWaitForTick = -1; _deltaTick = -1; BaselineUpdateTick = -1; BaselineUsed = 0; }
public void SetSnapshot(FrameSnapshot snapshot) { if (_snapshot == snapshot) { return; } if (snapshot != null) { snapshot.AddRefrence(); } if (_snapshot != null) { _snapshot.ReleaseRefrence(); } _snapshot = snapshot; }
public void OnSimUpdated(FrameSnapshot frame, float interpolation, bool replay) { if (!replay) { // Don't update camera location from sim during play, it's controlled via direct user input return; } // Do update camera location during replay // @TODO: determine which entities were actually updated last tick and only loop through them (raise event when SimSystem makes update?) SimCamera[] simCameras = frame.Snapshot.GetComponents <SimCamera>().ToArray(); SimCamera[] nextCameras = frame.NextSnapshot.GetComponents <SimCamera>().ToArray(); for (int i = 0; i < simCameras.Length; i++) { // @TODO: more efficiently get GameObject, related SimComponents and MonoBehaviours GameObject go = GameState.GetGameObject(simCameras[i].EntityID).GameObject; Transform transform = go.GetComponent <Transform>(); Vector2 newPosition = Vector2.Lerp(simCameras[i].Position, nextCameras[i].Position, interpolation); transform.position = new Vector3(newPosition.x, newPosition.y, transform.position.z); } }
//构建帧快照 public void BuildSnapshot(string tag) { //清除指定tag的网格 { var tmp = new SortedDictionary <int, MeshFrame>(); foreach (var curr in FrameSnapshot) { if (curr.Value.tag != tag) { tmp.Add(curr.Key, curr.Value); } } FrameSnapshot = tmp; } int index = 0; foreach (MFABone curr in Skeletals) { index++; string[] ns = curr.gameObject.name.Split('#'); string ctag = (ns.Length > 1) ? ns[ns.Length - 1] : ""; if (!string.IsNullOrEmpty(tag) && ctag != tag) { continue; } MeshFrame f = new MeshFrame(); SkinnedMeshRenderer skMR = curr.gameObject.GetComponent <SkinnedMeshRenderer>(); //新建一个mesh并进行蒙皮计算 Mesh mesh = new Mesh(); f.tag = ctag; skMR.BakeMesh(mesh); Matrix4x4 mxParent = new Matrix4x4(); mxParent.SetTRS( Vector3.zero, RootBones[0].gameObject.transform.localRotation, Vector3.one ); Matrix4x4 mx4 = new Matrix4x4(); Vector3 localpos = curr.gameObject.transform.localPosition; Vector3 scale = RootBones[0].gameObject.transform.lossyScale; mx4.SetTRS( new Vector3(localpos.x * scale.x, localpos.y * scale.y, localpos.z * scale.z) + RootBones[0].gameObject.transform.localPosition, curr.gameObject.transform.localRotation, Vector3.one ); f.TransformMX = mxParent * mx4; f.mesh = (mesh); FrameSnapshot.Add(index, f); } foreach (MFABone curr in Meshs) { index++; string[] ns = curr.gameObject.name.Split('#'); string ctag = (ns.Length > 1) ? ns[ns.Length - 1] : ""; if (!string.IsNullOrEmpty(tag) && ctag != tag) { continue; } MeshFrame f = new MeshFrame(); f.mesh = (curr.gameObject.GetComponent <MeshFilter>().sharedMesh); f.TransformMX = curr.TransformMX; f.tag = ctag; FrameSnapshot.Add(index, f); } }
public void WriteTempEntities(BaseClient baseClient, FrameSnapshot getSnapshot, FrameSnapshot lastSnapshot, BufferWrite msg, int maxTempEnts) { // CBaseServer::WriteTempEntities }
public virtual void SendSnapshot(ClientFrame frame) { // do not send same snapshot twice if (_lastSnapshot == frame.GetSnapshot()) { NetChannel.Transmit(); return; } // if we send a full snapshot (no delta-compression) before, wait until client // received and acknowledge that update. don't spam client with full updates if (_forceWaitForTick > 0) { NetChannel.Transmit(); return; } var msg = new BufferWrite(); var deltaFrame = GetDeltaFrame(_deltaTick); if (deltaFrame == null) { // We need to send a full update and reset the instanced baselines OnRequestFullUpdate(); } var tickmsg = new NetMessageTick(frame.TickCount, Program.HostFrametimeUnbounded, Program.HostFrametimeStdDeviation); tickmsg.WriteToBuffer(msg); // send entity update, delta compressed if deltaFrame != NULL Server.WriteDeltaEntities(this, frame, deltaFrame, msg); var maxTempEnts = 255; Server.WriteTempEntities(this, frame.GetSnapshot(), _lastSnapshot, msg, maxTempEnts); _lastSnapshot = frame.GetSnapshot(); if (NetChannel == null) { _deltaTick = frame.TickCount; return; } bool sendOk; if (deltaFrame == null) { sendOk = NetChannel.SendData(msg); sendOk = sendOk && NetChannel.Transmit(); // remember this tickcount we send the reliable snapshot // so we can continue sending other updates if this has been acknowledged _forceWaitForTick = frame.TickCount; } else { sendOk = NetChannel.SendDatagram(msg) > 0; } if (!sendOk) { Disconnect("Error! Couldn't send snapshot"); } }
public void ClearSnapshot( ) { FrameSnapshot.Clear( ); }
public void Init(FrameSnapshot snapshot) { TickCount = snapshot.TickCount; SetSnapshot(snapshot); }
public ClientFrame() { TickCount = 0; _snapshot = null; NextFrame = null; }
public ClientFrame(int tickcount) { TickCount = tickcount; _snapshot = null; NextFrame = null; }
public void CopyTempEntities(FrameSnapshot snapshot) { }
private void RenderFrame(int frameIndex) { float time = animate ? clock.ElapsedMilliseconds / 1000.0f : 0.0f; FrameSnapshot latestFrame = frameData.Frames != null && frameData.Frames.Count > 0 ? frameData.Frames[frameIndex] : null; if (latestFrame != null) { int nextRenderInstanceId = 1; // the first instance is the world reference plane foreach (RigidBody rigidBody in latestFrame.RigidBodies.Values) { foreach (uint shapeId in rigidBody.CollisionShapeIds) { RenderInstance instanceToRender = null; ShapeFrameIdPair actualShapePair = frameData.ShapeData.RetrieveShapeForFrame(shapeId, frameData.Frames[frameIndex].FrameId); if (actualShapePair != null) { if (nextRenderInstanceId < mainViewport.Renderer.InstanceList.Count) { instanceToRender = mainViewport.Renderer.InstanceList[nextRenderInstanceId]; } else { instanceToRender = new RenderInstance(Matrix.Translation(5.0f, 0.0f, 5.0f), TetrahedronMeshId); mainViewport.Renderer.InstanceList.Add(instanceToRender); } // todo - do the rest of the shape types and properly setup the position of the shapes switch (actualShapePair.Shape.ShapeType) { case ShapeType.eObb: instanceToRender.MeshId = CubeMeshId; break; case ShapeType.eSphere: break; case ShapeType.eCone: break; case ShapeType.eConvexHull: instanceToRender.MeshId = shapeRenderMeshBindings[actualShapePair]; break; case ShapeType.eTetrahedron: instanceToRender.MeshId = TetrahedronMeshId; break; default: break; } instanceToRender.UserDataValue = actualShapePair.Shape.Id; Matrix rotationAnimation = Matrix.RotationX(time) * Matrix.RotationY(time * 2.0f) * Matrix.RotationZ(time * 0.7f); Matrix translationMatrix = Matrix.Translation( rigidBody.WorldMatrix.Translation.X , rigidBody.WorldMatrix.Translation.Y , rigidBody.WorldMatrix.Translation.Z); if (actualShapePair.Shape.HasLocalMatrix) { Matrix localMatrix = Matrix.Translation( actualShapePair.Shape.LocalMatrix.Translation.X , actualShapePair.Shape.LocalMatrix.Translation.Y , actualShapePair.Shape.LocalMatrix.Translation.Z); instanceToRender.WorldMatrix = localMatrix * rotationAnimation * translationMatrix; } else { instanceToRender.WorldMatrix = rotationAnimation * translationMatrix; } if (actualShapePair.Shape.Id == selectedShapeId) { instanceToRender.Material.ColourTint = new Vector4(0.5f, 1.0f, 0.5f, 1.0f); instanceToRender.Material.AmbientLightStrength = 0.6f; } else if (actualShapePair.Shape.Id == highlightedShapeId) { instanceToRender.Material.ColourTint = new Vector4(0.5f, 1.0f, 0.5f, 1.0f); instanceToRender.Material.AmbientLightStrength = 0.3f; } else { instanceToRender.Material.ColourTint = new Vector4(0.0f, 1.0f, 0.0f, 1.0f); instanceToRender.Material.AmbientLightStrength = 0.1f; } ++nextRenderInstanceId; } } } int differenceInRenderInstances = mainViewport.Renderer.InstanceList.Count - nextRenderInstanceId; mainViewport.Renderer.InstanceList.RemoveRange(mainViewport.Renderer.InstanceList.Count - differenceInRenderInstances, differenceInRenderInstances); } }