public static void DebugReport(GPUData data) { double now = Serilization.ConvertFrom2019(); double diff = now - data.serverTime; Debug.LogFormat("Server time is {0:0.000000}, with delta {1:0.000000}", data.serverTime, data.deltaTime); Debug.LogFormat("Client time is {0:0.000000}", now); Debug.LogFormat("Diff is {0:0.000000}", diff); }
// Update is called once per frame void Update() { //this.socket.Send(Time.deltaTime.ToString()); UDPServer.GPUData data; var now = Serilization.ConvertFrom2019(); //Debug.Log("Frame Start"); var deltaThisFrame = 0.0d; while (this.socket.deltaQueue.TryPeek(out data)) { var server = data.serverTime; var clientTarget = server + 5000; deltaThisFrame = clientTarget - now; //Debug.Log("deltaThisFrame" + deltaThisFrame); if (deltaThisFrame < 0) { if (this.socket.deltaQueue.TryDequeue(out data)) { //this.gameObject.transform.Rotate(Vector3.right * (data.deltaTime) * 20); var timeInSecond = (float)deltaThisFrame * 0.001f; var timeTick = data.deltaTime; this.gameObject.transform.localPosition = new Vector3( transform.localPosition.x, Mathf.Sin(sin += timeTick) * 5, transform.localPosition.z); currentDalta += timeInSecond + data.deltaTime; //Debug.Log("Tick" + deltaThisFrame); //Debug.Log("currentDalta" + currentDalta); } } else { break; } } if (currentDalta > 0 && false) { var tickTime = Mathf.Min(Time.deltaTime, (float)currentDalta); this.gameObject.transform.localPosition = new Vector3( transform.localPosition.x, Mathf.Sin(sin += tickTime) * 5, transform.localPosition.z); currentDalta -= tickTime; //Debug.Log("currentDalta Tick" + currentDalta); } }
IEnumerator Broadcast() { var socket = SocketData.Make("localhost", 12345); var socket1 = SocketData.Make("localhost", 12346); //socket.endPoint.Address = IPAddress.Broadcast; //this.socket.Setup(UDPSocket<GPUData>.SocketRole.Broadcast); var data = new GPUData(); while (true) { data.deltaTime = Time.deltaTime; data.serverTime = Serilization.ConvertFrom2019(); //this.socket.Send(socket, data); //this.socket.Send(socket1, data); this.socket.Broadcast(data, 12347); this.socket.Broadcast(data, 12348); yield return(new WaitForEndOfFrame()); } }