Esempio n. 1
0
        public bool ForRangeInteresectionCalculator(RangeIntersectionCalculator rangeIntersectionCalculator, ObstacleOcclusionCalculationManagerV2 ObstacleOcclusionCalculationManagerV2,
                                                    out IsOccludedByObstacleJobData IsOccludedByObstacleJobData)
        {
            int ObstacleFrustumPointsPositionsBeginIndex = currentObstacleFrustumPointsCounter;
            var associatedObstacleListener = rangeIntersectionCalculator.GetAssociatedObstacleListener();

            if (associatedObstacleListener != null)
            {
                //obstacle listener may never have triggered calculation
                ObstacleOcclusionCalculationManagerV2.TryGetCalculatedOcclusionFrustumsForObstacleListener(associatedObstacleListener, out Dictionary <int, List <FrustumPointsPositions> > calculatedFrustumPositions);
                if (calculatedFrustumPositions != null)
                {
                    foreach (var calculatedObstacleFrustumList in calculatedFrustumPositions.Values)
                    {
                        foreach (var calculatedObstacleFrustum in calculatedObstacleFrustumList)
                        {
                            this.AssociatedObstacleFrustumPointsPositions[currentObstacleFrustumPointsCounter] = calculatedObstacleFrustum;
                            currentObstacleFrustumPointsCounter += 1;
                        }
                    }
                }

                IsOccludedByObstacleJobData = new IsOccludedByObstacleJobData
                {
                    TestedBoxCollider = new BoxDefinition(rangeIntersectionCalculator.TrackedInteractiveObject.InteractiveGameObject.GetLogicColliderAsBox()),
                    ObstacleFrustumPointsPositionsBeginIndex = ObstacleFrustumPointsPositionsBeginIndex,
                    ObstacleFrustumPointsPositionsEndIndex   = currentObstacleFrustumPointsCounter
                };
                return(true);
            }

            IsOccludedByObstacleJobData = default;
            return(false);
        }
Esempio n. 2
0
        // Try to get all occlusion frustums fro mthe obstacle listener and push them in the AssociatedObstacleFrustumPointsPositions.
        // Returns the index range of insertion of AssociatedObstacleFrustumPointsPositions.
        public bool ForRangeInteresectionCalculator(RangeIntersectionCalculator rangeIntersectionCalculator, ObstacleOcclusionCalculationManagerV2 ObstacleOcclusionCalculationManagerV2,
                                                    out IsOccludedByObstacleJobData IsOccludedByObstacleJobData)
        {
            int ObstacleFrustumPointsPositionsBeginIndex = currentObstacleFrustumPointsCounter;
            var associatedObstacleListener = rangeIntersectionCalculator.GetAssociatedObstacleListener();

            if (associatedObstacleListener != null)
            {
                //obstacle listener may never have triggered calculation
                ObstacleOcclusionCalculationManagerV2.TryGetCalculatedOcclusionFrustumsForObstacleListener(associatedObstacleListener, out Dictionary <int, List <FrustumPointsPositions> > calculatedFrustumPositions);
                if (calculatedFrustumPositions != null)
                {
                    var calculatedFrustumPositionsEnumerator = calculatedFrustumPositions.Values.GetEnumerator();
                    while (calculatedFrustumPositionsEnumerator.MoveNext())
                    {
                        var calculatedObstacleFrustumList = calculatedFrustumPositionsEnumerator.Current;

                        for (int calculatedObstacleFrustumIndex = 0; calculatedObstacleFrustumIndex < calculatedObstacleFrustumList.Count; calculatedObstacleFrustumIndex++)
                        {
                            this.AssociatedObstacleFrustumPointsPositions[currentObstacleFrustumPointsCounter] = calculatedObstacleFrustumList[calculatedObstacleFrustumIndex];
                            currentObstacleFrustumPointsCounter += 1;
                        }
                    }
                }

                IsOccludedByObstacleJobData = new IsOccludedByObstacleJobData
                {
                    ObstacleFrustumPointsPositionsBeginIndex = ObstacleFrustumPointsPositionsBeginIndex,
                    ObstacleFrustumPointsPositionsEndIndex   = currentObstacleFrustumPointsCounter
                };
                return(true);
            }

            IsOccludedByObstacleJobData = default;
            return(false);
        }
Esempio n. 3
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();
                    }
                }
            }
        }
Esempio n. 4
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();
                    }
                }
            }
        }