public int Update() { int free; while (m_PendingFree.TryDequeue(out free)) { int ver = m_ConnectionList[free].Version + 1; if (ver == 0) { ver = 1; } m_ConnectionList[free] = new Connection { Id = free, Version = ver }; m_FreeList.ReleaseConnectionId(free); } if (m_EventQueue.Count != 0) { Debug.LogError("Resetting event queue with pending events (Count=" + m_EventQueue.Count + ")"); } m_EventQueue.Reset(); m_BitStream.Reset(); CheckTimeouts(); return(ProcessPackets(m_BitStream)); }
protected override JobHandle OnUpdate(JobHandle inputDependencies) { timeout -= Time.deltaTime; if (timeout < 0) { if (!settings) { CreateTexts(); } timeout += settings.tickTime; var job = new AsteroidSystemJob() { changes = changes.ToConcurrent(), launches = launches.ToConcurrent(), minShip = settings.minShipStock, shipCost = settings.shipCost }; int2 todo; while (changes.TryDequeue(out todo)) { texts[todo.x].text = cache[todo.y + 1]; } int l; while (launches.TryDequeue(out l)) { SpawnShip(l); } return(job.Schedule(this, inputDependencies)); } else { return(inputDependencies); } }
[Obsolete] internal void UpdateSend <T>(T driver, out int updateCount) where T : struct, INetworkPipelineSender { NativeArray <UpdatePipeline> sendUpdates = new NativeArray <UpdatePipeline>(m_SendStageNeedsUpdateRead.Count + m_SendStageNeedsUpdate.Length, Allocator.Temp); UpdatePipeline updateItem; updateCount = 0; while (m_SendStageNeedsUpdateRead.TryDequeue(out updateItem)) { sendUpdates[updateCount++] = updateItem; } int startLength = updateCount; for (int i = 0; i < m_SendStageNeedsUpdate.Length; i++) { sendUpdates[startLength + i] = m_SendStageNeedsUpdate[i]; updateCount++; } NativeList <UpdatePipeline> currentUpdates = new NativeList <UpdatePipeline>(128, Allocator.Temp); // Move the updates requested in this iteration to the concurrent queue so it can be read/parsed in update routine for (int i = 0; i < updateCount; ++i) { updateItem = sendUpdates[i]; var inboundBuffer = default(NativeSlice <byte>); ToConcurrent().ProcessPipelineSend(driver, updateItem.stage, updateItem.pipeline, updateItem.connection, inboundBuffer, currentUpdates); } for (int i = 0; i < currentUpdates.Length; ++i) { m_SendStageNeedsUpdateRead.Enqueue(currentUpdates[i]); } }
public void Execute(int index) { var searchQueue = new NativeQueue <int>(Allocator.Temp); var sumProvinceWeights = 0; var rawAverage = new float2(0); var cursor = NationalCapitals[index]; do { if (CheckedProvinces[cursor] || ProvinceLifeRating[cursor] < 0.1f || // Ocean ProvinceOwnership[cursor] != index) { continue; } ContiguousProvinces.Add(index, ProvinceCentroids[cursor]); CheckedProvinces[cursor] = true; rawAverage += ProvinceCentroids[cursor] * ProvincePixels[cursor]; sumProvinceWeights += ProvincePixels[cursor]; var end = cursor > 0 ? BorderEnds[cursor - 1] : 0; for (var i = end; i < BorderEnds[cursor]; i++) { searchQueue.Enqueue(BorderIndices[i]); } } while (searchQueue.TryDequeue(out cursor)); CenterNationals[index] = rawAverage / (sumProvinceWeights > 0 ? sumProvinceWeights : 1); //searchQueue.Dispose(); // Not needed? What is documentation anyways. }
protected override JobHandle OnUpdate(JobHandle inputDep) { int spawnCount = 0; int cnt; while (spawnCountQueue.TryDequeue(out cnt)) { spawnCount += cnt; } SetSingleton(new ParticleSpawnCountComponent { spawnCount = spawnCount }); var commandBuffer = barrier.CreateCommandBuffer().ToConcurrent(); var spawnJob = new ParticleSpawnJob(); spawnJob.spawnCountQueue = spawnCountQueue.ToConcurrent(); spawnJob.commandBuffer = commandBuffer; spawnJob.deltaTime = Time.deltaTime; spawnJob.m_ColorSizeParticleArchetype = m_ColorSizeParticleArchetype; spawnJob.m_ColorParticleArchetype = m_ColorParticleArchetype; spawnJob.m_SizeParticleArchetype = m_SizeParticleArchetype; spawnJob.m_ParticleArchetype = m_ParticleArchetype; inputDep = spawnJob.Schedule(this, inputDep); barrier.AddJobHandleForProducer(inputDep); return(inputDep); }
public override void UpdateSystem() { Dependency = JobHandle.CombineDependencies(Dependency, m_spawningQueueSystem.spawnQueueDependencies); EntityCommandBuffer ecb = m_entityCommandBuffer.CreateCommandBuffer(); NativeQueue <Translation> spawnQueue = m_spawningQueueSystem.spawnQueue; Dependency = Entities.ForEach((ref RuntimePrefabData runtimePrefabData) => { Translation translation; while (spawnQueue.TryDequeue(out translation)) { Rotation rotation = GetComponent <Rotation>(runtimePrefabData.aiDrone); Entity e = ecb.Instantiate(runtimePrefabData.aiDrone); ecb.SetComponent(e, translation); ecb.SetComponent(e, new LocalToWorld { Value = new float4x4(rotation.Value, translation.Value) }); } }).Schedule(Dependency); m_entityCommandBuffer.AddJobHandleForProducer(Dependency); }
void InternalUpdate() { #if ENABLE_UNITY_COLLECTIONS_CHECKS for (int i = 0; i < m_ConnectionList.Length; ++i) { int conCount = m_EventQueue.GetCountForConnection(i); if (conCount != 0 && m_ConnectionList[i].State != NetworkConnection.State.Disconnected) { UnityEngine.Debug.LogError("Resetting event queue with pending events (Count=" + conCount + ", ConnectionID=" + i + ") Listening: " + Listening); } } #endif int free; while (m_PendingFree.TryDequeue(out free)) { int ver = m_ConnectionList[free].Version + 1; if (ver == 0) { ver = 1; } m_ConnectionList[free] = new Connection { Id = free, Version = ver }; m_FreeList.Enqueue(free); } m_EventQueue.Clear(); m_DataStream.Clear(); CheckTimeouts(); }
public void Execute() { var count = counter.Count; var averageCount = math.min((count / (MAX_QUERIES - ID)) + 1, RequestBatch.MAX_COUNT); var s = batch.state[0]; var perfectSplit = averageCount - s.entitySize; for (var i = 0; i < perfectSplit; ++i) { if (s.entitySize >= RequestBatch.MAX_COUNT - 1) { break; } Entity entity; if (!waitingEntities.TryDequeue(out entity)) { break; } batch.entities[s.entitySize] = entity; var request = requests[entity]; request.status = PathRequestStatus.InQueue; requests[entity] = request; batch.requests[s.entitySize] = request; count -= 1; s.entitySize += 1; } batch.state[0] = s; counter.Count = count; }
/// <summary> /// Process all queued events. /// </summary> public void ProcessEvents() { // Early bail to avoid setting up job stuff unnecessarily if (_queuedEvents.Length == 0) { return; } NativeQueue <UnityEvent <T_Event> > eventsToProcessQueue = new NativeQueue <UnityEvent <T_Event> >(Allocator.TempJob); BuildEventQueueJob job = new BuildEventQueueJob(); job.queuedEvents = _queuedEvents; job.subscribers = _subscribers; job.eventsToProcess = eventsToProcessQueue.ToConcurrent(); job.Schedule(_queuedEvents.Length, _batchCount).Complete(); while (eventsToProcessQueue.TryDequeue(out UnityEvent <T_Event> ev)) { try { _subscriberCallbacks[ev.subscriberIndex](ev.ev); } catch (Exception e) { Debug.LogException(e); } } eventsToProcessQueue.Dispose(); _queuedEvents.Clear(); }
public void Execute() { Entity entity; while (ShipArrivedQueue.TryDequeue(out entity)) { EntityCommandBuffer.AddComponent(entity, new ShipArrivedTag()); } }
internal void Update(NativeQueue <IPCQueuedMessage> queue) { IPCQueuedMessage val; while (queue.TryDequeue(out val)) { m_IPCQueue.Enqueue(val.dest, val.data); } }
public void Execute() { int index = 0; RenderData renderData; while (queue.TryDequeue(out renderData)) { array[index++] = renderData; } }
public void Execute() { int index = 0; RenderData renderData; while (renderQueue1.TryDequeue(out renderData)) { renderArray[index] = renderData; index++; } }
public void Execute() { int index = 0; Entity renderData; while (destroyedPlanetoidQueue.TryDequeue(out renderData)) { destroyedPlanetoidArray[index] = renderData; index++; } }
public void Execute() { int index = 0; SpriteSheetAnimationComponent SpriteSheetAnimationComponent; while (nativeQueue.TryDequeue(out SpriteSheetAnimationComponent)) { nativeArray[index++] = SpriteSheetAnimationComponent; } }
public void Execute() { int index = 0; RenderData entity; while (nativeQueue.TryDequeue(out entity)) { nativeArray[index] = entity; index++; } }
public void Execute() { int index = 0; RenderData renderData; while (nativeQueue.TryDequeue(out renderData)) { nativeArray[index] = renderData; index++; } }
public void Execute() { int index = 0; int arrayLength = array.Length; T rdata; while (index < arrayLength && queue.TryDequeue(out rdata)) { array[index] = rdata; index++; } }
public void Execute() { COMMAND command; while (CommandsQueue.TryDequeue(out command)) { CommandsMap.Add(new MapKey() { Value = command.RegistryReference.TypeId }, command); } }
public void Execute(ref LineRendererComponentData lineData) { if (level.Length > 0) { list.Add(new Line(new float2(0, 0), new float2(level[0].width, 0), new float4(1, 0, 0, 1), 5)); list.Add(new Line(new float2(0, 0), new float2(0, level[0].height), new float4(1, 0, 0, 1), 5)); list.Add(new Line(new float2(0, level[0].height), new float2(level[0].width, level[0].height), new float4(1, 0, 0, 1), 5)); list.Add(new Line(new float2(level[0].width, 0), new float2(level[0].width, level[0].height), new float4(1, 0, 0, 1), 5)); } var offset = renderOffset[0]; var target = lineData.targetOffset; renderOffset[1] = target; float maxPxPerSec = 500; if (math.any(offset != target)) { if (lineData.teleport != 0) { offset = target; } else { float2 delta = (target - offset); float deltaLen = math.length(delta); float maxDiff = maxPxPerSec * deltaTime; if (deltaLen > maxDiff || deltaLen < -maxDiff) { delta *= maxDiff / deltaLen; } offset += delta; } renderOffset[0] = offset; } Line line; while (queue.TryDequeue(out line)) { if ((line.start.x < offset.x - line.width && line.end.x < offset.x - line.width) || (line.start.x > offset.x + renderSize.x + line.width && line.end.x > offset.x + renderSize.x + line.width) || (line.start.y < offset.y - line.width && line.end.y < offset.y - line.width) || (line.start.y > offset.y + renderSize.y + line.width && line.end.y > offset.y + renderSize.y + line.width)) { continue; } list.Add(line); } }
public void Execute() { TVal val; while (vals.TryDequeue(out val)) { if (!uniqueVals.ContainsValue(val)) { uniqueVals.Add(val); } } }
public NetworkConnection Connect(NetworkEndPoint endpoint) { #if ENABLE_UNITY_COLLECTIONS_CHECKS if (!m_InternalState.IsCreated) { throw new InvalidOperationException( "Driver must be constructed with a populated or empty INetworkParameter params list"); } #endif int id; if (!m_FreeList.TryDequeue(out id)) { id = m_ConnectionList.Length; m_ConnectionList.Add(new Connection { Id = id, Version = 1 }); } int ver = m_ConnectionList[id].Version; var c = new Connection { Id = id, Version = ver, State = NetworkConnection.State.Connecting, Address = endpoint, Attempts = 1, LastAttempt = m_updateTime, SendToken = 0, ReceiveToken = m_SessionIdCounter[0] }; m_SessionIdCounter[0] = (ushort)(m_SessionIdCounter[0] + 1); m_ConnectionList[id] = c; var netcon = new NetworkConnection { m_NetworkId = id, m_NetworkVersion = ver }; SendConnectionRequest(c); return(netcon); }
internal unsafe void Update(NetworkInterfaceEndPoint local, NativeQueue <QueuedSendMessage> queue) { QueuedSendMessage val; while (queue.TryDequeue(out val)) { var ipcData = new IPCData(); UnsafeUtility.MemCpy(ipcData.data, val.Data, val.DataLength); ipcData.length = val.DataLength; ipcData.from = *(int *)local.data; m_IPCQueue.Enqueue(*(int *)val.Dest.data, ipcData); } }
public void Execute() { Entity ent; while (playerClearQueue.TryDequeue(out ent)) { if (commandTarget.HasComponent(ent)) { var state = commandTarget[ent]; state.targetEntity = Entity.Null; commandTarget[ent] = state; } } }
public void Execute() { Entity ent; while (playerClearQueue.TryDequeue(out ent)) { if (playerState.Exists(ent)) { var state = playerState[ent]; state.PlayerShip = Entity.Null; playerState[ent] = state; } } }
public void Execute() { NetworkConnection con; while ((con = driver.Accept()) != default(NetworkConnection)) { // New connection can never have any events, if this one does - just close it DataStreamReader reader; if (con.PopEvent(driver, out reader) != NetworkEvent.Type.Empty) { con.Disconnect(driver); continue; } // create an entity for the new connection var ent = commandBuffer.CreateEntity(); commandBuffer.AddComponent(ent, new NetworkStreamConnection { Value = con }); commandBuffer.AddComponent(ent, new NetworkSnapshotAckComponent()); commandBuffer.AddComponent(ent, new CommandTargetComponent()); commandBuffer.AddBuffer <IncomingRpcDataStreamBufferComponent>(ent); var rpcBuffer = commandBuffer.AddBuffer <OutgoingRpcDataStreamBufferComponent>(ent); commandBuffer.AddBuffer <IncomingCommandDataStreamBufferComponent>(ent); commandBuffer.AddBuffer <IncomingSnapshotDataStreamBufferComponent>(ent); RpcSystem.SendProtocolVersion(rpcBuffer, protocolVersion); // Send RPC - assign network id int nid; if (!freeNetworkIds.TryDequeue(out nid)) { // Avoid using 0 nid = numNetworkId[0] + 1; numNetworkId[0] = nid; } commandBuffer.AddComponent(ent, new NetworkIdComponent { Value = nid }); rpcQueue.Schedule(rpcBuffer, new RpcSetNetworkId { nid = nid, netTickRate = tickRate.NetworkTickRate, simMaxSteps = tickRate.MaxSimulationStepsPerFrame, simTickRate = tickRate.SimulationTickRate }); } }
public NetworkConnection Accept() { if (!Listening) { return(default(NetworkConnection)); } int id; if (!m_NetworkAcceptQueue.TryDequeue(out id)) { return(default(NetworkConnection)); } return(new NetworkConnection { m_NetworkId = id, m_NetworkVersion = m_ConnectionList[id].Version }); }
protected override void OnUpdate() { var animationsToSet = new NativeQueue <SetterData>(Allocator.TempJob); new StateMachineJob() { animationsToSet = animationsToSet.AsParallelWriter() }.Schedule(this).Complete(); SetterData setData; while (animationsToSet.TryDequeue(out setData)) { AnimationSetterUtil.SetAnimation(EntityManager, setData.entity, setData.animation); } animationsToSet.Dispose(); }
protected override void OnUpdate() { base.OnUpdate(); LineData3D line; float recip = 1.0f / 255.0f; while (Lines.TryDequeue(out line)) { float r = ((line.Color & 0xff0000) >> 16) * recip; float g = ((line.Color & 0x00ff00) >> 8) * recip; float b = ((line.Color & 0x0000ff)) * recip; Debug.DrawLine(line.A, line.B, new Color(r, g, b)); } Lines.Dispose(); Lines = new NativeQueue <LineData3D>(Allocator.TempJob); }
protected override void OnUpdate() { var manager = EntityManager; var toDestroy = new NativeQueue <Entity>(Allocator.TempJob); var timerJob = new DecreaseTimerJob() { deltaTime = Time.deltaTime, toDestroy = toDestroy.AsParallelWriter() }; timerJob.Schedule(this).Complete(); Entity entity; while (toDestroy.TryDequeue(out entity)) { manager.DestroyEntity(entity); } toDestroy.Dispose(); }