/// <summary> /// sort file paths. /// </summary> static public void Sort(NativeStringList source, NativeStringList result) { var job = new SortJob(source, result, Allocator.TempJob); job.Run(); job.Dispose(); }
void Start() { m_ParticleSystem = GetComponent <ParticleSystem>(); var main = m_ParticleSystem.main; var collision = m_ParticleSystem.collision; int maxParticleCount = main.maxParticles; m_SortKeys = new NativeArray <SortKey>(maxParticleCount, Allocator.Persistent); m_Collisions = new NativeQueue <Collision>(Allocator.Persistent); m_CacheJob = new CacheJob { sortKeys = m_SortKeys, }; m_SortJob = new SortJob { sortKeys = m_SortKeys }; m_CollisionJob = new CollisionJob { sortKeys = m_SortKeys, collisions = m_Collisions.AsParallelWriter(), bounce = collision.bounceMultiplier, radiusScale = collision.radiusScale, maxDiameter = main.startSize.constantMax * collision.radiusScale // TODO - handle different size curve modes and size over life if needed }; m_ApplyCollisionsJob = new ApplyCollisionsJob { collisions = m_Collisions }; }
/// <summary> /// sort file paths with filtering. /// </summary> static public void Sort(NativeStringList source, ReadOnlyStringEntity target_pattern, NativeStringList result) { var job = new SortJob(source, target_pattern, result, Allocator.TempJob); job.Run(); job.Dispose(); }
void Start() { m_ParticleSystem = GetComponent <ParticleSystem>(); var main = m_ParticleSystem.main; int maxParticleCount = main.maxParticles; m_SortKeys = new NativeArray <SortKey>(maxParticleCount, Allocator.Persistent); m_CacheJob = new CacheJob { sortKeys = m_SortKeys, }; m_SortJob = new SortJob { sortKeys = m_SortKeys }; m_ConnectionsJob = new ConnectionsJob { sortKeys = m_SortKeys, distance = distance }; m_Mesh = new Mesh(); }
public static void RemoveFromQueue(Guid Id) { SortJob job = jobs.Where(i => i.Id == Id).FirstOrDefault(); if (job != null) { jobs.Remove(job); } }
public ActionResult <SortJob> GetJob(Guid jobId) { // TODO: Should return a specific job by ID. SortJob sortJob = _sortJobProcessor.GetJobById(jobId); return(sortJob); //throw new NotImplementedException(); }
public static void UpdateQueue(SortJob sortJob) { SortJob job = jobs.Where(i => i.Id == sortJob.Id).FirstOrDefault(); if (job != null) { jobs.Remove(job); jobs.Add(sortJob); } }
public void SetEntry(string jobId, SortJob job) { if (_cache.ContainsKey(jobId)) { _cache[jobId] = job; } else { _cache.Add(jobId, job); } }
public async Task <ActionResult <SortJob> > EnqueueJob(int[] values) { var pendingJob = new SortJob( id: Guid.NewGuid(), status: SortJobStatus.Pending, duration: null, input: values, output: null); var response = await Task.Run(() => _sortJobProcessor.PushQueue(pendingJob)); return(Ok(response)); }
public ActionResult <SortJob> EnqueueJob([FromForm] int[] values) { var pendingJob = new SortJob( id: Guid.NewGuid(), status: SortJobStatus.Pending, duration: null, input: values, output: null); _sortJobProcessorAsync.EnqueueJob(pendingJob); return(Ok(pendingJob)); }
public ActionResult <SortJob> EnqueueJob(int[] values) { // TODO: Should enqueue a job to be processed in the background. var pendingJob = new SortJob( id: Guid.NewGuid(), status: SortJobStatus.Pending, duration: null, input: values, output: null); _sortJobProcessor.Process(pendingJob); return(Ok(pendingJob)); }
public async Task <ActionResult <SortJob> > EnqueueAndRunJob(int[] values) { var pendingJob = new SortJob( id: Guid.NewGuid(), status: SortJobStatus.Pending, duration: null, input: values, output: null); var completedJob = await _sortJobProcessor.Process(pendingJob); return(Ok(completedJob)); }
public async Task <ActionResult <SortJob> > EnqueueJob(int[] values) { var pendingJob = new SortJob( id: Guid.NewGuid(), status: SortJobStatus.Pending, duration: null, input: values, output: null); await _sortJobProcessor.QueueJob(pendingJob); BackgroundJob.Enqueue(() => _sortJobProcessor.BackgroundProcess(pendingJob)); //hangfire fire-and-forget return(Ok(pendingJob)); }
public ActionResult <SortJob> EnqueueJob(int[] values) { var pendingJob = new SortJob( id: Guid.NewGuid(), status: SortJobStatus.Pending, duration: null, input: values, output: null); Task.Run(() => { _sortJobProcessor.Process(pendingJob); }); return(Ok(pendingJob)); }
public ActionResult <SortJob> EnqueueJob(int[] values) { // TODO: Should enqueue a job to be processed in the background. SortJob pendingJob = new SortJob( id: Guid.NewGuid(), status: SortJobStatus.Pending, duration: null, input: values, output: null); _sortJobProcessor.Enqueue(pendingJob); return(Ok(pendingJob)); //throw new NotImplementedException(); }
protected async override Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { using (var scope = serviceProvider.CreateScope()) { var repoService = (IRepoService)scope.ServiceProvider.GetRequiredService(typeof(IRepoService)); List <SortJob> pendingJobs = (await repoService.GetAllJobsAsync("Jobs")).FindAll(x => x.Status == SortJobStatus.Pending); this.logger.LogInformation($"Background Worker ran at {DateTime.Today.TimeOfDay}. There are {pendingJobs.Count} pending sort jobs"); foreach (SortJob job in pendingJobs) { logger.LogInformation($"Processing job with ID {job.Id}"); var stopwatch = Stopwatch.StartNew(); var output = job.Input.OrderBy(n => n).ToArray(); Thread.Sleep(60000); var duration = stopwatch.Elapsed; SortJob sortJob = new SortJob( id: job.Id, status: SortJobStatus.Completed, duration: duration, input: job.Input, output: output); logger.LogInformation("Completed processing job with ID '{JobId}'. Duration: '{Duration}'.", job.Id, duration); var result = await repoService.UpdateJobAsync("Jobs", sortJob); if (result) { logger.LogInformation($"Database succesfully updated for JobId {sortJob.Id}"); } else { logger.LogInformation($"There was some problem while updating the database for JobId: {sortJob.Id}"); } } } } }
public async Task <ActionResult <SortJob> > EnqueueJob(int[] values) { try { var pendingJob = new SortJob( id: Guid.NewGuid(), status: SortJobStatus.Pending, duration: null, input: values, output: null); await Task.Run(() => _sortJobProcessor.SubmitJob(pendingJob)); return(Ok(pendingJob)); } catch (Exception ex) { return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message)); } }
public async Task <ActionResult <SortJob> > EnqueueJob(int[] values) { try { var pendingJob = new SortJob( id: Guid.NewGuid(), status: SortJobStatus.Pending, duration: null, input: values, output: null); var jobStatus = await this._sortJobProcessor.EnqueueJob(pendingJob); return(Ok(jobStatus)); } catch (Exception ex) { return(Problem($"Failed to enqueue the sorting request due to exception: {ex.Message}")); } }
public async Task <ActionResult <SortJob> > EnqueueJob([FromBody] int[] values) { if (values == null) { return(BadRequest()); } var pendingJob = new SortJob( id: Guid.NewGuid(), status: SortJobStatus.Pending, duration: null, input: values, output: null); var result = await repoService.EnqueueJobAsync("Jobs", pendingJob); if (result) { return(Ok()); } return(StatusCode(500, "Unable to schedule the job, please try again after sometime")); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { _logger.LogDebug("Sort Service starting"); stoppingToken.Register(() => _logger.LogDebug($" Sort Service background task is stopping.")); while (!stoppingToken.IsCancellationRequested) { if (MemoryQueue.GetPendingQueue().Count > 0) { foreach (SortJob pendingJob in MemoryQueue.GetPendingQueue()) { SortJob completedJob = await _sortJobProcessor.Process(pendingJob); MemoryQueue.UpdateQueue(completedJob); } } await Task.Delay(5000, stoppingToken); } _logger.LogDebug("Sort Service background task is stopping."); }
void Update() { int i, j; factory.map.IncrementOccupantTicker(); UnityEngine.Profiling.Profiler.BeginSample("BotNavigation"); for (i = 0; i < bots.Count; i++) { FactoryBot bot = bots[i]; Vector2Int tile = new Vector2Int(Mathf.FloorToInt(bot.position.x), Mathf.FloorToInt(bot.position.y)); Vector2 uv = bot.position - new Vector2(tile.x, tile.y); uv.x = 3f * uv.x * uv.x - 2f * uv.x * uv.x * uv.x; uv.y = 3f * uv.y * uv.y - 2f * uv.y * uv.y * uv.y; Vector2Int hitTile = new Vector2Int(Mathf.FloorToInt(bot.position.x + .5f), Mathf.FloorToInt(bot.position.y + .5f)); factory.map.UpdateOccupantTicker(hitTile); if (bot.targetCrafter == null) { bot.targetCrafter = factory.GetRequestingCrafter(); bot.targetCrafter.workerCount++; } else if (bot.targetCrafter.destroyed) { bot.targetCrafter.workerCount--; bot.targetCrafter = null; } else { if (bot.movingToResource == false && bot.holdingResource == false) { bot.movingToResource = true; bot.navigator = factory.resourceNavigator; } else { if (bot.holdingResource == false) { if (factory.map.IsResourceSpawner(hitTile)) { bot.holdingResource = true; } } else { bot.navigator = bot.targetCrafter.navigator; if (hitTile == bot.targetCrafter.position) { bot.targetCrafter.inventory++; bot.holdingResource = false; bot.movingToResource = false; bot.targetCrafter.workerCount--; bot.targetCrafter = null; } } } } var navigator = bot.navigator; if (navigator != null) { if (factory.map.IsInsideMap(tile) && factory.map.IsInsideMap(new Vector2Int(tile.x + 1, tile.y + 1))) { Vector2 a = navigator.Get(tile); Vector2 b = navigator.Get(tile + new Vector2Int(1, 0)); Vector2 c = navigator.Get(tile + new Vector2Int(0, 1)); Vector2 d = navigator.Get(tile + new Vector2Int(1, 1)); if (a == Vector2.zero) { a = b; } if (b == Vector2.zero) { b = a; } if (c == Vector2.zero) { c = d; } if (d == Vector2.zero) { d = c; } Vector2 flow = Vector2.Lerp(Vector2.Lerp(a, b, uv.x), Vector2.Lerp(c, d, uv.x), uv.y); Vector2 moveVector = flow * botMoveSpeed * Time.deltaTime; moveVector += Random.insideUnitCircle * .002f; Vector2Int newTile = new Vector2Int(Mathf.FloorToInt(bot.position.x + moveVector.x + .5f), Mathf.FloorToInt(bot.position.y + .5f)); if (factory.map.IsWall(newTile)) { moveVector.x = 0f; } newTile = new Vector2Int(Mathf.FloorToInt(bot.position.x + .5f), Mathf.FloorToInt(bot.position.y + moveVector.y + .5f)); if (factory.map.IsWall(newTile)) { moveVector.y = 0f; } bot.position += moveVector * (1f - Mathf.Clamp01(bot.hitCount / 10f)); } } bot.hitCount = 0; bots[i] = bot; } UnityEngine.Profiling.Profiler.EndSample(); UnityEngine.Profiling.Profiler.BeginSample("BotSort"); NativeArray <BotData> array = new NativeArray <BotData>(bots.Count, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); for (int k = 0; k < bots.Count; k++) { var b = bots[k]; array[k] = new BotData { pos = b.position, radius = b.radius }; } var myJob2 = new SortJob { bots = array }; myJob2.Run(); for (int k = 0; k < bots.Count; k++) { var b = bots[k]; var a = array[k]; b.position = a.pos; b.radius = a.radius; bots[k] = b; } array.Dispose(); UnityEngine.Profiling.Profiler.EndSample(); UnityEngine.Profiling.Profiler.BeginSample("Transform"); var arrayOfBots = new NativeArray <BotValues>(bots.Count, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); for (int k = 0; k < bots.Count; k++) { arrayOfBots[k] = new BotValues { hitCount = bots[k].hitCount, position = bots[k].position, radius = bots[k].radius }; } var tJob = new BotTransformJob { bots = arrayOfBots, map = factory.map.mapDataStore }; tJob.Run(); for (int k = 0; k < bots.Count; k++) { var tmp = bots[k]; tmp.position = arrayOfBots[k].position; tmp.hitCount = arrayOfBots[k].hitCount; bots[k] = tmp; } arrayOfBots.Dispose(); UnityEngine.Profiling.Profiler.EndSample(); UnityEngine.Profiling.Profiler.BeginSample("MatrixColor"); for (i = 0; i < bots.Count; i++) { FactoryBot bot = bots[i]; botMatrices[i / instanceCount][i - (i / instanceCount) * instanceCount] = Matrix4x4.TRS(GetBotPos(bot.position), Quaternion.Euler(90f, 0f, 0f), Vector3.one * .2f); if (bot.holdingResource == false) { botColors[i / instanceCount][i - (i / instanceCount) * instanceCount] = emptyBotColor; } else { botColors[i / instanceCount][i - (i / instanceCount) * instanceCount] = fullBotColor; } } UnityEngine.Profiling.Profiler.EndSample(); UnityEngine.Profiling.Profiler.BeginSample("DrawMesh"); for (i = 0; i < botMatrices.Count; i++) { if (bots.Count >= i * instanceCount) { botMatProperties[i].SetVectorArray("_Color", botColors[i]); Graphics.DrawMeshInstanced(botMesh, 0, botMaterial, botMatrices[i], Mathf.Min(instanceCount, bots.Count - i * instanceCount), botMatProperties[i]); } } UnityEngine.Profiling.Profiler.EndSample(); }
public async Task <bool> EnqueueJobAsync(string tableName, SortJob sortJob) { return(await databaseWrapper.TryInsertNewRecordAsync(tableName, sortJob)); }
public async Task <bool> UpdateJobAsync(string table, SortJob sortJob) { return(await databaseWrapper.UpdateRecord(table, sortJob.Id, sortJob)); }
public static SortJob GetJob(Guid id) { SortJob job = jobs.Where(i => i.Id == id).FirstOrDefault(); return(job); }
public void UpdateJob(SortJob job) { _cache.SetEntry(job.Id.ToString(), job); }
public async Task <SortJob> Process(SortJob job) { var status = await _processor.Process(job); return(status); }
public void Enqueue(SortJob job) { _cache.SetEntry(job.Id.ToString(), job); }
public static void InsertToQueue(SortJob sortJob) { jobs.Add(sortJob); }
private void Start() { _waterDisplay = GetComponent <WaterDisplay>(); _colliders = FindObjectsOfType <EdgeCollider2D>(); var blobs = _waterDisplay.InitialPositions; var waterBlobsNum = _waterDisplay.BlobsCount; velocities = new NativeArray <float2>(waterBlobsNum, Allocator.Persistent); positions = new NativeArray <float2>(waterBlobsNum, Allocator.Persistent); newVelocities = new NativeArray <float2>(waterBlobsNum, Allocator.Persistent); newPositions = new NativeArray <float2>(waterBlobsNum, Allocator.Persistent); hasCollided = new NativeArray <uint>(waterBlobsNum, Allocator.Persistent); cellSide = forceRadius; var cameraWidth = Camera.main.orthographicSize * 2; var cameraHeight = cameraWidth / Camera.main.aspect; gridSize = new Vector2(cameraWidth, cameraHeight); xCells = (ushort)Mathf.CeilToInt(gridSize.x / cellSide); yCells = (ushort)Mathf.CeilToInt(gridSize.y / cellSide); cellSpace = 10; grid = new NativeArray <int>(xCells * yCells * cellSpace, Allocator.Persistent); for (var i = 0; i < xCells * yCells; i++) { grid[i * cellSpace] = 0; } for (var i = 0; i < positions.Length; i++) { positions[i] = blobs[i]; velocities[i] = 0; } var collidersPointsCount = 0; for (var c = 0; c < _colliders.Length; c++) { collidersPointsCount += _colliders[c].pointCount; } collidersPointsNum = new NativeArray <int>(_colliders.Length, Allocator.Persistent); _oldColliderPositions = new NativeArray <float2>(_colliders.Length, Allocator.Persistent); collidersPoints = new NativeArray <float2>(collidersPointsCount, Allocator.Persistent); var collidersPointsAccumulated = 0; for (var c = 0; c < _colliders.Length; c++) { var points = _colliders[c].pointCount; collidersPointsNum[c] = points; for (var i = 0; i < points; i++) { var collider = _colliders[c]; var point = collider.transform.TransformPoint(new Vector3(collider.points[i].x, collider.points[i].y, 0)); collidersPoints[collidersPointsAccumulated + i] = new float2(point.x, point.y); } collidersPointsAccumulated += points; } for (var key = 0; key < positions.Length; key++) { // Place key in the grid var gridX = (int)math.floor((positions[key].x + gridSize.x / 2) / cellSide); if (gridX < 0) { gridX = 0; } else if (gridX > xCells - 1) { gridX = xCells - 1; } var gridY = (int)math.floor((positions[key].y + gridSize.y / 2) / cellSide); if (gridY < 0) { gridY = 0; } else if (gridY > yCells - 1) { gridY = yCells - 1; } var cellStart = (gridY * xCells + gridX) * cellSpace; var stored = grid[cellStart]; if (stored < cellSpace - 1) { grid[cellStart + 1 + stored] = key; grid[cellStart] = stored + 1; } } _sortJob = new SortJob { grid = grid, xCells = xCells, yCells = yCells, halfXSize = gridSize.x / 2, halfYSize = gridSize.y / 2, cellSpace = cellSpace, cellSide = cellSide }; _waterJob = new WaterJob { gravity = gravity, forceRadius = forceRadius, waterForce = waterForce, waterDamping = waterDamping, colliders = collidersPointsNum, colliderPoints = collidersPoints, ballSize = ballSize, hasCollided = hasCollided, gridSizeX = gridSize.x, gridSizeY = gridSize.y, grid = grid, xCells = xCells, yCells = yCells, cellSpace = cellSpace, cellSide = cellSide }; }