Exemple #1
0
        // GET: Home
        public ActionResult Index()
        {
            JobLogger jobLogger = new JobLogger();

            jobLogger.Log(LogLevel.Error, "Mensaje de prueba");
            return(View());
        }
Exemple #2
0
 public void Execute(int index)
 {
     foreach (var t1 in ChainIDWithData)
     {
         var count = JobReader.BeginBatch(t1);
         for (int j = 0; j < count; j++)
         {
             var t = JobReader.Read <Hpp>();
             JobLogger.Log("t.hp= ", t.hp, "t.dd= ", t.dd);
             Assert.AreEqual(j, t.hp);
         }
         JobReader.EndBatch();
     }
 }
Exemple #3
0
 public void Execute(int index)
 {
     foreach (var t1 in ChainIDWithData)
     {
         var count = JobReader.BeginBatch(t1);
         for (int j = 0; j < count; j++)
         {
             var t = JobReader.Read <BigDataTest>();
             unsafe
             {
                 JobLogger.Log(t.BigLong[0]);
                 Assert.AreEqual(j, t.BigLong[0]);
             }
         }
         JobReader.EndBatch();
     }
 }
Exemple #4
0
            protected override void OnUpdate()
            {
                Debug.Log("PopEventSystem.OnUpdate");
                var w = eventSystem.GetStreamWriter();

                eventSystem.WaiteFroStreamAccess = Job.WithName("PopEvents").WithCode(() =>
                {
                    JobLogger.Log("Poping Events to Streamer");

                    var handle = w.BeginBatch();
                    handle.WriteEvent(10, 10);
                    handle.WriteEvent(11, new Entity()
                    {
                        Index = 10, Version = 5
                    }, (long)3);
                    handle.EndBatch();
                }).Schedule(eventSystem.WaiteFroStreamAccess);
            }
Exemple #5
0
        protected override void OnUpdate()
        {
            var enemyCount  = m_EnemyQuery.CalculateEntityCount();
            var targetCount = m_TargetQuery.CalculateEntityCount();

            EntityManager.GetAllUniqueSharedComponentData(m_UniqueTypes);

            // Each variant of the Boid represents a different value of the SharedComponentData and is self-contained,
            // meaning Boids of the same variant only interact with one another. Thus, this loop processes each
            // variant type individually.
            for (int boidVariantIndex = 0; boidVariantIndex < m_UniqueTypes.Count; boidVariantIndex++)
            {
                var settings = m_UniqueTypes[boidVariantIndex];
                m_BoidQuery.AddSharedComponentFilter(settings);

                var boidCount = m_BoidQuery.CalculateEntityCount();

                if (boidCount == 0)
                {
                    // Early out. If the given variant includes no Boids, move on to the next loop.
                    // For example, variant 0 will always exit early bc it's it represents a default, uninitialized
                    // Boid struct, which does not appear in this sample.
                    m_BoidQuery.ResetFilter();
                    continue;
                }

                // The following calculates spatial cells of neighboring Boids
                // note: working with a sparse grid and not a dense bounded grid so there
                // are no predefined borders of the space.

                var hashMap                 = new NativeMultiHashMap <int, int>(boidCount, Allocator.TempJob);
                var cellIndices             = new NativeArray <int>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
                var cellEnemyPositionIndex  = new NativeArray <int>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
                var cellTargetPositionIndex = new NativeArray <int>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
                var cellCount               = new NativeArray <int>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
                var cellEnemyDistance       = new NativeArray <float>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
                var cellAlignment           = new NativeArray <float3>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
                var cellSeparation          = new NativeArray <float3>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
                var raycastInputs           = new NativeArray <RaycastInput>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
                var initialRaycastResults   = new NativeArray <RaycastHit>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
                var unobstructedDirections  = new NativeArray <float3>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
                var copyTargetPositions     = new NativeArray <float3>(targetCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
                var copyEnemyPositions      = new NativeArray <float3>(enemyCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
                // The following jobs all run in parallel because the same JobHandle is passed for their
                // input dependencies when the jobs are scheduled; thus, they can run in any order (or concurrently).
                // The concurrency is property of how they're scheduled, not of the job structs themselves.

                // These jobs extract the relevant position, heading component
                // to NativeArrays so that they can be randomly accessed by the `MergeCells` and `Steer` jobs.
                // These jobs are defined inline using the Entities.ForEach lambda syntax.
                var initialCellAlignmentJobHandle = Entities
                                                    .WithSharedComponentFilter(settings)
                                                    .WithName("InitialCellAlignmentJob")
                                                    .ForEach((int entityInQueryIndex, in LocalToWorld localToWorld) =>
                {
                    cellAlignment[entityInQueryIndex] = localToWorld.Forward;
                })
                                                    .ScheduleParallel(Dependency);

                var initialCellSeparationJobHandle = Entities
                                                     .WithSharedComponentFilter(settings)
                                                     .WithName("InitialCellSeparationJob")
                                                     .ForEach((int entityInQueryIndex, in LocalToWorld localToWorld) =>
                {
                    cellSeparation[entityInQueryIndex] = localToWorld.Position;
                })
                                                     .ScheduleParallel(Dependency);

                var initialRaycastInputsJobHandle = Entities
                                                    .WithSharedComponentFilter(settings)
                                                    .WithName("InitialRaycastInputsJob")
                                                    .ForEach((int entityInQueryIndex, in LocalToWorld localToWorld) =>
                {
                    raycastInputs[entityInQueryIndex] = new RaycastInput
                    {
                        Start  = localToWorld.Position,
                        End    = localToWorld.Position + (localToWorld.Forward * settings.OuterDetectionRadius),
                        Filter = new CollisionFilter
                        {
                            BelongsTo    = ~0u,
                            CollidesWith = 1,     // Environment layer
                            GroupIndex   = 0
                        },
                    };
                })
                                                    .ScheduleParallel(Dependency);

                var world = World.DefaultGameObjectInjectionWorld.GetExistingSystem <Unity.Physics.Systems.BuildPhysicsWorld>().PhysicsWorld.CollisionWorld;
                var batchRaycastJobHandle = ScheduleBatchRayCast(world, raycastInputs, initialRaycastResults, initialRaycastInputsJobHandle);

                var findUnobstructedDirectionsJobHandle = Entities
                                                          .WithName("FindUnobstructedDirectionsJob")
                                                          .WithSharedComponentFilter(settings)
                                                          .ForEach((int entityInQueryIndex, in LocalToWorld localToWorld, in DynamicBuffer <Float3BufferElement> buffer) =>
                {
                    JobLogger.Log("In find unobstructed job");
                    float3 bestDir    = float3.zero;
                    float furthestHit = 0f;
                    RaycastHit hit;
                    DynamicBuffer <float3> float3buffer = buffer.Reinterpret <float3>();
                    for (int i = 0; i < float3buffer.Length; i++)
                    {
                        float3 end         = localToWorld.Position + ((math.mul(localToWorld.Value, new float4(float3buffer[i], 1)) * settings.OuterDetectionRadius)).xyz;
                        RaycastInput input = new RaycastInput()
                        {
                            Start  = localToWorld.Position,
                            End    = end,
                            Filter = new CollisionFilter
                            {
                                BelongsTo    = ~0u,
                                CollidesWith = 1,     // Environment layer
                                GroupIndex   = 0
                            },
                        };
                        if (world.CastRay(input, out hit))
                        {
                            var dist = math.distance(hit.Position, localToWorld.Position);
                            if (dist > furthestHit)
                            {
                                bestDir     = hit.Position - localToWorld.Position;
                                furthestHit = dist;
                                JobLogger.Log("Found a better way");
                            }
                        }
                        else     // this direction is unobstructed, return
                        {
                            unobstructedDirections[entityInQueryIndex] = hit.Position - localToWorld.Position;
                            JobLogger.Log("Found a way");
                            return;
                        }
                    }
                    unobstructedDirections[entityInQueryIndex] = bestDir;
                }).ScheduleParallel(batchRaycastJobHandle);
Exemple #6
0
        private void Run()
        {
            TriggerParam triggerParam = null;

            while (!_toStop)
            {
                _running     = false;
                triggerParam = null;
                ReturnT executeResult = null;
                try
                {
                    if (_triggerQueue.TryDequeue(out triggerParam))
                    {
                        _running = true;
                        byte temp;
                        _triggerLogIdSet.TryRemove(triggerParam.logId, out temp);
                        JobLogger.SetLogFileName(triggerParam.logDateTim, triggerParam.logId);
                        var executionContext = new JobExecutionContext()
                        {
                            BroadcastIndex = triggerParam.broadcastIndex,
                            BroadcastTotal = triggerParam.broadcastTotal,
                            ExecutorParams = triggerParam.executorParams
                        };
                        // execute
                        JobLogger.Log("<br>----------- xxl-job job execute start -----------<br>----------- Param:" + triggerParam.executorParams);

                        var handler = _jobHandlerFactory.GetJobHandler(triggerParam.executorHandler);
                        executeResult = handler.Execute(executionContext);
                        JobLogger.Log("<br>----------- xxl-job job execute end(finish) -----------<br>----------- ReturnT:" + executeResult);
                    }
                    else
                    {
                        if (!_queueHasDataEvent.WaitOne(Constants.JobThreadWaitTime))
                        {
                            ToStop("excutor idel times over limit.");
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (triggerParam != null)
                    {
                        if (_toStop)
                        {
                            JobLogger.Log("<br>----------- JobThread toStop, stopReason:" + _stopReason);
                        }
                        var errorMsg = ex.ToString();
                        executeResult = ReturnT.CreateFailedResult(errorMsg);
                        JobLogger.Log("<br>----------- JobThread Exception:" + errorMsg + "<br>----------- xxl-job job execute end(error) -----------");
                    }
                    else
                    {
                        _logger.LogError(ex, "JobThread exception.");
                    }
                }
                finally
                {
                    if (triggerParam != null)
                    {
                        OnCallback?.Invoke(this, new HandleCallbackParam(triggerParam.logId, triggerParam.logDateTim, executeResult ?? ReturnT.FAIL));
                    }
                }
            }

            // callback trigger request in queue
            while (_triggerQueue.TryDequeue(out triggerParam))
            {
                var stopResult = ReturnT.CreateFailedResult(_stopReason + " [job not executed, in the job queue, killed.]");
                OnCallback?.Invoke(this, new HandleCallbackParam(triggerParam.logId, triggerParam.logDateTim, stopResult));
            }
        }