コード例 #1
0
        public void ManualCalculation(List <RangeIntersectionCalculator> InvolvedRangeIntersectionCalculatorV2, bool forceCalculation)
        {
            var AllRangeIntersectionCalculatorV2Count = InvolvedRangeIntersectionCalculatorV2.Count;

            if (AllRangeIntersectionCalculatorV2Count > 0)
            {
                #region Counting

                var totalObstacleFrustumPointsCounter = 0;
                foreach (var rangeIntersectionCalculatorV2 in InvolvedRangeIntersectionCalculatorV2)
                {
                    if (forceCalculation || !forceCalculation && rangeIntersectionCalculatorV2.TickChangedPositions())
                    {
                        RangeIntersectionCalculatorThatChangedThatFrame.Add(rangeIntersectionCalculatorV2);
                        foreach (var RangeIntersectionmanager in RangeIntersectionmanagers)
                        {
                            RangeIntersectionmanager.CountingForRangeIntersectionCalculator(rangeIntersectionCalculatorV2);
                        }

                        var associatedObstacleListener = rangeIntersectionCalculatorV2.GetAssociatedObstacleListener();
                        if (associatedObstacleListener != null) //The range can ignore obstacles
                        {
                            //Obstacle listener could have never triggered a calculation
                            ObstacleOcclusionCalculationManagerV2.TryGetCalculatedOcclusionFrustumsForObstacleListener(associatedObstacleListener, out var calculatedFrustumPositions);
                            if (calculatedFrustumPositions != null)
                            {
                                foreach (var calculatedObstacleFrustum in calculatedFrustumPositions.Values)
                                {
                                    totalObstacleFrustumPointsCounter += calculatedObstacleFrustum.Count;
                                }
                            }
                        }
                    }
                }

                #endregion

                if (RangeIntersectionCalculatorThatChangedThatFrame.Count > 0)
                {
                    foreach (var RangeIntersectionmanager in RangeIntersectionmanagers)
                    {
                        RangeIntersectionmanager.CreateNativeArrays();
                    }

                    this.IsOccludedByObstacleJobData = new NativeArray <IsOccludedByObstacleJobData>(AllRangeIntersectionCalculatorV2Count, Allocator.TempJob);

                    RangeObstacleOcclusionIntersection.Prepare(totalObstacleFrustumPointsCounter, _rangeIntersectionCalculatorManager);

                    var currentObstacleIntersectionCalculatorCounter = 0;
                    foreach (var RangeIntersectionCalculatorV2 in RangeIntersectionCalculatorThatChangedThatFrame)
                    {
                        if (RangeObstacleOcclusionIntersection.ForRangeInteresectionCalculator(RangeIntersectionCalculatorV2, ObstacleOcclusionCalculationManagerV2, out var IsOccludedByObstacleJobData))
                        {
                            this.IsOccludedByObstacleJobData[currentObstacleIntersectionCalculatorCounter] = IsOccludedByObstacleJobData;
                            currentObstacleIntersectionCalculatorCounter += 1;
                        }

                        foreach (var RangeIntersectionmanager in RangeIntersectionmanagers)
                        {
                            RangeIntersectionmanager.CalculationDataSetupForRangeIntersectionCalculator(RangeIntersectionCalculatorV2,
                                                                                                        IsOccludedByObstacleJobData, currentObstacleIntersectionCalculatorCounter);
                        }
                    }

                    foreach (var RangeIntersectionmanager in RangeIntersectionmanagers)
                    {
                        RangeIntersectionmanager.BuildJobHandle(IsOccludedByObstacleJobData, RangeObstacleOcclusionIntersection);
                    }

                    if (!forceCalculation)
                    {
                        JobEnded = false;
                    }
                    else
                    {
                        foreach (var RangeIntersectionmanager in RangeIntersectionmanagers)
                        {
                            RangeIntersectionmanager.Complete();
                        }

                        foreach (var RangeIntersectionmanager in RangeIntersectionmanagers)
                        {
                            RangeIntersectionmanager.WaitForResults();
                        }

                        OnJobEnded();
                    }
                }
            }
        }
コード例 #2
0
        public void ManualCalculation(List <RangeIntersectionCalculator> InvolvedRangeIntersectionCalculatorV2, bool forceCalculation)
        {
            var AllRangeIntersectionCalculatorV2Count = InvolvedRangeIntersectionCalculatorV2.Count;

            if (AllRangeIntersectionCalculatorV2Count > 0)
            {
                #region Counting

                var totalObstacleFrustumPointsCounter = 0;
                var totalVisibilityProbePointsCounter = 0;
                foreach (var rangeIntersectionCalculatorV2 in InvolvedRangeIntersectionCalculatorV2)
                {
                    // If the calculation is forced or the intersection calculator needs recalculation
                    if (forceCalculation || !forceCalculation && rangeIntersectionCalculatorV2.TickChangedPositions())
                    {
                        // We push the range intersection calculator to the stack that will be calculated
                        RangeIntersectionCalculatorThatChangedThatFrame.Add(rangeIntersectionCalculatorV2);
                        // We increment manager counter this will be used later to allocate native arrays.
                        foreach (var RangeIntersectionmanager in RangeIntersectionmanagers)
                        {
                            RangeIntersectionmanager.CountingForRangeIntersectionCalculator(rangeIntersectionCalculatorV2);
                        }

                        var associatedObstacleListener = rangeIntersectionCalculatorV2.GetAssociatedObstacleListener();
                        if (associatedObstacleListener != null) //The range can ignore obstacles
                        {
                            //Obstacle listener could have never triggered a calculation
                            // We get the occlusion frustums associated to the obstacle listener. These frustums will be used during the probe visibility
                            ObstacleOcclusionCalculationManagerV2.TryGetCalculatedOcclusionFrustumsForObstacleListener(associatedObstacleListener, out var calculatedFrustumPositions);
                            if (calculatedFrustumPositions != null)
                            {
                                foreach (var calculatedObstacleFrustum in calculatedFrustumPositions.Values)
                                {
                                    totalObstacleFrustumPointsCounter += calculatedObstacleFrustum.Count;
                                }
                            }
                        }

                        // visibility probe counting
                        var visibilityProbes = rangeIntersectionCalculatorV2.TrackedInteractiveObject.InteractiveGameObject.VisibilityProbe;
                        if (visibilityProbes.LocalPoints != null)
                        {
                            totalVisibilityProbePointsCounter += visibilityProbes.LocalPoints.Length;
                        }
                    }
                }

                #endregion

                if (RangeIntersectionCalculatorThatChangedThatFrame.Count > 0)
                {
                    foreach (var RangeIntersectionmanager in RangeIntersectionmanagers)
                    {
                        RangeIntersectionmanager.CreateNativeArrays();
                    }

                    this.IsOccludedByObstacleJobData = new NativeArray <IsOccludedByObstacleJobData>(AllRangeIntersectionCalculatorV2Count, Allocator.TempJob);
                    this.VisibilityProbeLocalPoints  = new NativeArray <Vector3>(totalVisibilityProbePointsCounter, Allocator.TempJob);

                    RangeObstacleOcclusionIntersection.Prepare(totalObstacleFrustumPointsCounter, _rangeIntersectionCalculatorManager);

                    var currentObstacleIntersectionCalculatorCounter = 0;
                    var currentVisibilityProbeLocalPointsCounter     = 0;

                    foreach (var RangeIntersectionCalculatorV2 in RangeIntersectionCalculatorThatChangedThatFrame)
                    {
                        if (RangeObstacleOcclusionIntersection.ForRangeInteresectionCalculator(RangeIntersectionCalculatorV2, ObstacleOcclusionCalculationManagerV2, out var IsOccludedByObstacleJobData))
                        {
                            // when there is occlusion, we push it to the job
                            this.IsOccludedByObstacleJobData[currentObstacleIntersectionCalculatorCounter] = IsOccludedByObstacleJobData;
                            currentObstacleIntersectionCalculatorCounter += 1;
                        }

                        // TODO
                        var VisibilityProbeJobData = CalculatingVisibilityProbeJobData(RangeIntersectionCalculatorV2, ref currentVisibilityProbeLocalPointsCounter);

                        foreach (var RangeIntersectionmanager in RangeIntersectionmanagers)
                        {
                            RangeIntersectionmanager.CalculationDataSetupForRangeIntersectionCalculator(RangeIntersectionCalculatorV2,
                                                                                                        IsOccludedByObstacleJobData, VisibilityProbeJobData, currentObstacleIntersectionCalculatorCounter);
                        }
                    }

                    foreach (var RangeIntersectionmanager in RangeIntersectionmanagers)
                    {
                        RangeIntersectionmanager.BuildJobHandle(IsOccludedByObstacleJobData, this.VisibilityProbeLocalPoints, RangeObstacleOcclusionIntersection);
                    }

                    if (!forceCalculation)
                    {
                        JobEnded = false;
                    }
                    else
                    {
                        foreach (var RangeIntersectionmanager in RangeIntersectionmanagers)
                        {
                            RangeIntersectionmanager.Complete();
                        }

                        foreach (var RangeIntersectionmanager in RangeIntersectionmanagers)
                        {
                            RangeIntersectionmanager.WaitForResults();
                        }

                        OnJobEnded();
                    }
                }
            }
        }