protected void GetResponseObject() { if (responseObject.obj == null) { responseObject = messageManager.GetReusableSeaaBuffer(); } }
public void ReturnEntity(ReusableObject robj) { robj.ClearForBuffer(); // Debug.Log("ReturnToPool " + obj); robj.gameObject.transform.SetParent(trsPoolParent); robj.gameObject.SetActive(false); }
private void Awake() { Instance = this; projectileCache_ = new ReusableObject <Basic>(100, this); basicProjectiles_ = new List <Basic>(); removeListBasic_ = new List <Basic>(50); arenaBoundsY_ = Camera.main.orthographicSize; arenaBoundsX_ = arenaBoundsY_ / 0.75f; // 4:3 ratio }
void HyperConnection_ConnectionStatusChanged(object sender, ConnectionStatusEventArgs e) { if (e.Status == ConnectionStatus.Disconnected) { _tail = null; if (_tempBuffer.Object != null) { _tempBuffer.Dispose(); _tempBuffer = new ReusableObject <byte[]>(); } } }
private bool CheckSegmentReceiveReady() { if (_tempBufferOffset == _tempBuffer.Object.Length) { HyperSegmentDataMessage msg; msg.Token = _tempToken; msg.Buffer = _tempBuffer; OnMessageSegmentData(msg); _tempBuffer = new ReusableObject <byte[]>(); _tempBufferOffset = 0; _tempToken = 0; return(true); } return(false); }
private void ParseRawInternal(byte[] buffer, int offset, int length) { if (_tempBuffer.Object != null) { // continue to receive var bytesToCopy = Math.Min(_tempMessageLength - _tempBufferOffset - 5, length); Buffer.BlockCopy(buffer, offset, _tempBuffer.Object, _tempBufferOffset, bytesToCopy); _tempBufferOffset += bytesToCopy; if (!CheckSegmentReceiveReady()) { return; } // parse following messages... offset += bytesToCopy; length -= bytesToCopy; if (length == 0) { return; } } if (_tail != null) { var newBuffer = new byte[_tail.Length + length]; Buffer.BlockCopy(_tail, 0, newBuffer, 0, _tail.Length); Buffer.BlockCopy(buffer, offset, newBuffer, _tail.Length, length); buffer = newBuffer; offset = 0; length += _tail.Length; _tail = null; } var memoryStream = new MemoryStream(buffer, offset, length, false); var reader = new BinaryReader(memoryStream); while (memoryStream.Position + 5 < memoryStream.Length) // 4 (message length) + 1 (messageId) = 5 { var backupPosition = (int)memoryStream.Position; var msgLen = reader.ReadInt32(); var msgId = (HyperMessage)reader.ReadByte(); // we no need to use tailing for segment receiving if (msgId == HyperMessage.SegmentData) { if (memoryStream.Length - memoryStream.Position < 4) { memoryStream.Position = backupPosition; break; } _tempMessageLength = msgLen; _tempBuffer = GetBuffer(); _tempBufferOffset = 0; _tempToken = reader.ReadInt32(); var bytesToCopy = Math.Min(msgLen - 5, length - (int)memoryStream.Position); Buffer.BlockCopy(buffer, offset + (int)memoryStream.Position, _tempBuffer.Object, _tempBufferOffset, bytesToCopy); _tempBufferOffset += bytesToCopy; if (!CheckSegmentReceiveReady()) { return; } // following code actually should never happen to execute (receive whole segment in one message) // but just to keep it complete we will support that behaviour Debugger.Break(); memoryStream.Seek(bytesToCopy, SeekOrigin.Current); continue; } var bytesLeftInMemory = memoryStream.Length - memoryStream.Position; var bytesNeeded = msgLen - 1; // 1 because we just read the msgId if (bytesLeftInMemory < bytesNeeded) { if (msgLen > 4 * 1024) { Logger.Warn("Data corruption detected"); return; } //Logger.Warn("Backuping tail bytes: {2} pos: {0} len: {1} cutMsgLen={3} cutMsgType={4}", backupPosition, memoryStream.Length, memoryStream.Length - backupPosition, msgLen, msgId); // we can't read whole message, backup it for the next operation _tail = new byte[memoryStream.Length - backupPosition]; Buffer.BlockCopy(buffer, offset + backupPosition, _tail, 0, _tail.Length); return; } switch (msgId) { case HyperMessage.Handshake: { HyperHandshakeMessge msg; msg.SessionToken = reader.ReadInt64(); msg.IsControl = reader.ReadBoolean(); OnMessageHandshake(msg); } break; case HyperMessage.FileCheckResult: { HyperFileResultMessage msg; msg.Token = reader.ReadInt32(); msg.Size = reader.ReadInt64(); OnMessageFileResult(msg); } break; case HyperMessage.Request: { HyperRequestMessage msg; msg.Token = reader.ReadInt32(); msg.Path = reader.ReadString(); msg.Offset = reader.ReadInt64(); msg.Length = reader.ReadInt32(); OnMessageSegmentRequest(msg); } break; case HyperMessage.Error: { HyperErrorMessage msg; msg.Token = reader.ReadInt32(); msg.ErrorCode = reader.ReadInt32(); OnMessageError(msg); } break; default: throw new ArgumentOutOfRangeException(); } } if (memoryStream.Position < memoryStream.Length) { //Logger.Warn("Backuping2 tail bytes: {2} pos: {0} len: {1}", memoryStream.Position, memoryStream.Length, memoryStream.Length - memoryStream.Position); // we can't even read the length, backup... _tail = new byte[memoryStream.Length - memoryStream.Position]; Buffer.BlockCopy(buffer, offset + (int)memoryStream.Position, _tail, 0, _tail.Length); } }
IEnumerator DestroyCoroutine(ReusableObject obj, float time) { yield return(new WaitForSeconds(time)); Game.Instance.ObjectPool.Unspawn(obj.gameObject); }
void Start() { sprites_ = new ReusableObject <ProjectileInfo>(100, this); }