public override void SendRawData(CTSMarker ctsMarker, MsgPrefix msgNote, byte[] protoBytes) { if (m_LcrsService != null) { if (msgNote.MsgID == (UInt16)eMsgID.S2C_RadianceStream) { LCRS.Log("==================================================== Send data with: " + protoBytes.Length); if (m_SessionDataBufferMap.ContainsKey(ctsMarker.sessionId) == false) { m_SessionDataBufferMap.Add(ctsMarker.sessionId, new AccumDataBuffer(m_LcrsService, ctsMarker.sessionId)); } m_SessionDataBufferMap[ctsMarker.sessionId].PushData(protoBytes); } else if (((eMsgID)msgNote.MsgID).ToString().Contains("Json")) { LCRS.Log("==================================================== Send data with: " + protoBytes.Length); m_LcrsService.Sessions.SendTo(ctsMarker.sessionId, protoBytes); } //m_LcrsService.Sessions.SendToAsync(ctsMarker.sessionId, protoBytes, SendAsyncCompleted); // Debug: save the file //string strSaveFile = Application.dataPath + "/rt_" + System.DateTime.Now.Minute + "_" + System.DateTime.Now.Second + "_web.png"; //FileStream fs = File.Open(strSaveFile, FileMode.Create); //fs.Write(protoBytes, 0, protoBytes.Length); //fs.Close(); } }
public override void SendRawData(CTSMarker ctsMarker, MsgPrefix msgNote, byte[] protoBytes) { msgNote.msgSize = (ushort)(ctsMarker.tcpSocket.MsgPrefixLength + (protoBytes != null ? protoBytes.Length : 0)); ctsMarker.tcpSocket.SendData(msgNote, protoBytes); LCRS.Log("================================================= Send data to client"); }
public void ProcessAttributeStream(CTSMarker ctsMarker, byte[] msgStream) { if (mTcpToCloudSocketMap.ContainsKey(ctsMarker)) { mTcpToCloudSocketMap[ctsMarker].EnqueueAttributeData(new AttributeData(msgStream)); LCRS.Log("============================================= Enqueue attribute"); } }
public void SyncObjectPosition(ClientSyncObjectData data) { var objToSync = GameObject.Find(data.name); if (objToSync != null) { LCRS.Log("====SYNC OBJECT: " + data.name); objToSync.transform.position = new Vector3(data.positionX, data.positionY, data.positionZ); } }
public override void Startup(string strIpAddress, int port) { m_WebServer = new WebSocketServer(IPAddress.Parse(strIpAddress), port); m_WebServer.Start(); m_WebServer.AddWebSocketService <LcrsService>("/Lcrs"); m_WebServer.WebSocketServices.TryGetServiceHost("/Lcrs", out m_LcrsService); LCRS.Log("Startup"); }
public void Update() { if (mRadianceCollector != null) { AttributeData attributeData = null; while ((attributeData = mCloudSocket.DequeueAttributeData()) != null) { var msgHeader = MsgNoteUtils.GetMessageHead(attributeData.RawData); LCRS.Log("msgHeader: " + msgHeader); if (msgHeader == eMsgID.C2S_DGI_Init) { Baker.Instance.Init(); Baker.Instance.SetLightMap(); //不需要传ST了:导出json的时候已经计算好了 //mCloudSocket.EnqueueJsonData(new LightmapSTJsonData(Object.FindObjectsOfType<MeshRenderer>(), eMsgID.S2C_Json_LightmapST)); mCloudSocket.EnqueueJsonData(new LightmapArrayJsonData(eMsgID.S2C_Json_LightmapArray)); } else if (msgHeader == eMsgID.C2D_DGI_RecalcLightmap) { Baker.Instance.Init(); Baker.Instance.SetLightMap(); mCloudSocket.EnqueueJsonData(new LightmapArrayJsonData(eMsgID.S2C_Json_LightmapArray)); } else if (msgHeader == eMsgID.C2S_Json_UpdateObjectPosition) { byte[] clientObjBytes = MsgNoteUtils.GetMessageBody(attributeData.RawData); string jsonStr = Encoding.UTF8.GetString(clientObjBytes); JsonMapper.RegisterExporter <float>((obj, writer) => writer.Write(Convert.ToDouble(obj))); JsonMapper.RegisterImporter <double, float>(input => Convert.ToSingle(input)); ClientSyncObjectData syncObject = JsonMapper.ToObject <ClientSyncObjectData>(jsonStr); Baker.Instance.SyncObjectPosition(syncObject); Baker.Instance.Init(); Baker.Instance.SetLightMap(); mCloudSocket.EnqueueJsonData(new LightmapArrayJsonData(eMsgID.S2C_Json_LightmapArray)); } else { ClientObjectAttribute clientObjAttribute = (ClientObjectAttribute)MsgNoteUtils.BytesToStruct(attributeData.RawData, typeof(ClientObjectAttribute)); int height = (int)clientObjAttribute.Param % mWebClientExchangeCode; int width = (int)clientObjAttribute.Param / mWebClientExchangeCode; LCRS.Log("===================================================== Log: " + width + "==324234234235^%$^%@#R@3: " + (ushort)clientObjAttribute.LightPosZ); // mRadianceCollector.Collect(width, height, clientObjAttribute); // mCloudSocket.EnqueueRadianceData(new RadianceData((ushort)clientObjAttribute.LightPosZ, (ushort)width, (ushort)height, mRadianceCollector.GetRadianceDataInPng())); } } } }
void HandleReceiveData(TcpSocket <XPacket> srcSocket, XPacket msgNote, MemoryStream msgStream) { if (msgNote.MsgID == (ushort)eMsgID.S2C_RadianceStream) { LCRS.Log("======================================= Receive radiance from sever: " + msgNote.MsgID + ", " + msgNote.msgSize); Launcher.instance.stats.ShowRadianceTexture(msgNote.ScreenWidth, msgNote.ScreenHeight, msgStream.ToArray()); } else { // Common message } }
protected override void OnOpen() { //base.OnOpen(); CTSMarker marker = new CTSMarker(null, this.ID); m_MarkerDic.Add(this.ID, marker); Launcher.instance.connectionMgr.BuildConnection(new CloudSocket(), marker); mUserEndPointInfo = this.Context.UserEndPoint.ToString(); LCRS.Log("========================================================== Connect client: " + this.ID + ", " + this.Context.UserEndPoint); Launcher.instance.stats.Log("Build connection with " + this.Context.UserEndPoint); }
void SyncrhonizeRadiance() { for (int i = 0; i < mCloudConnections.Count; ++i) { RadianceData radianceData = null; while ((radianceData = mCloudConnections[i].cloudSocket.DequeueRadianceData()) != null) { LCRS.Log("================================ Send data with: " + radianceData.Width + ", " + radianceData.Height); NetworkServer.SendRawData(mCloudToTcpSocketMap[mCloudConnections[i].cloudSocket], new XPacket((ushort)eMsgID.S2C_RadianceStream, radianceData.Width, radianceData.Height), radianceData.packedData); } JsonData jsonData = null; while ((jsonData = mCloudConnections[i].cloudSocket.DequeueJsonData()) != null) { LCRS.Log("================================ Send json data : " + jsonData.MsgID); var jsonPack = new JsonPacket((ushort)jsonData.MsgID); NetworkServer.SendRawData(mCloudToTcpSocketMap[mCloudConnections[i].cloudSocket], jsonPack, jsonPack.AddMsgHeader(jsonData.Pack())); } } }
void BoundAndCenter() { MeshRenderer[] mrs = this.GetComponentsInChildren <MeshRenderer>(); for (int i = 0; i < mrs.Length; ++i) { if (mIsInitialized == false) { mIsInitialized = true; mBounds.SetMinMax(mrs[i].bounds.min, mrs[i].bounds.max); } else { mBounds.Encapsulate(mrs[i].bounds); } } this.transform.position -= mBounds.center; LCRS.Log("===========Max: " + mBounds.max + ", " + mBounds.min); }
void OnConnectedCallback() { LCRS.Log("Server connected: " + m_IpAddress + ", " + m_Port); StartCoroutine(SyncClientAttribute()); }