public byte[] Process(Packet readPacket) { if (readPacket is NewTransferPacket newTransferPacket) { if (freeIds.IsEmpty()) { return(null); } byte localId = freeIds.Dequeue(); byte transferId = newTransferPacket.TransferId; if (ids.ContainsKey(transferId) && ids[transferId] == 0 || transfers[localId] != null) { return(null); } ids[transferId] = localId; transfers[localId] = new byte[newTransferPacket.TransferLength]; return(Process(new DataPacket(transferId, newTransferPacket.Data))); } else if (readPacket is DataPacket dataPacket) { byte localId = ids[dataPacket.TransferId]; Array.Copy(dataPacket.Data, 0, transfers[localId], offsets[localId], dataPacket.DataLength); offsets[localId] += dataPacket.DataLength; if (offsets[localId] == transfers[localId].Length - 1) { byte[] readData = transfers[localId]; transfers[localId] = null; offsets[localId] = 0; freeIds.Enqueue(localId); ids[localId] = 0; return(readData); } } else if (readPacket is SmallDataPacket smallDataPacket) { return(smallDataPacket.Data); } return(null); }
public void UpdateToXpa() { if (disposed) { return; } if (solid == null) { return; } lock (positionLocker) if (positionChanged) { solid.Position = position; positionChanged = false; Debug.Assert(!float.IsNaN(solid.Position.X)); } lock (orientationLocker) if (orientationChanged) { solid.Orientation = orientation; orientationChanged = false; Debug.Assert(!float.IsNaN(solid.Orientation.X)); } lock (isStaticLocker) if (isStaticChanged) { solid.Static = isStatic; isStaticChanged = false; } lock (isInfluencedByGravityLocker) if (isInfluencedByGravityChanged) { solid.InfluencedByGravity = isInfluencedByGravity; isInfluencedByGravityChanged = false; } Helper.Helper.BeginTimeMeasurementDebugOutput("solid_85"); lock (shapes) { Helper.Helper.EndTimeMeasurementDebugOutput("solid_85"); if (shapesChanged) { solid.ClearShapes(); foreach (ShapeData data in shapes) { solid.AddShape(data); } shapesChanged = false; } } while (forces.Count > 0) { solid.AddForce(forces.Dequeue()); } lock (userDataLocker) if (userDataChanged) { solid.UserData = userData; userDataChanged = false; } lock (collisionEventProcessorLocker) if (collisionEventProcessorChanged) { solid.CollisionEventHandler = collisionEventProcessor; collisionEventProcessorChanged = false; } lock (massLocker) if (massChanged || massOffsetChanged) { Debug.Assert(mass != null); solid.SetMass(mass, massOffset); massChanged = false; massOffsetChanged = false; } lock (globalLinearVelLocker) if (globalLinearVelChanged) { solid.GlobalLinearVel = globalLinearVel; globalLinearVelChanged = false; Debug.Assert(!float.IsNaN(solid.GlobalLinearVel.X)); } lock (globalAngularVelLocker) if (globalAngularVelChanged) { solid.GlobalAngularVel = globalAngularVel; globalAngularVelChanged = false; Debug.Assert(!float.IsNaN(solid.GlobalAngularVel.X)); } }
private void DoJob() { _jobQueue.Dequeue()?.Invoke(); }