예제 #1
0
파일: NestTest.cs 프로젝트: PWLPavan/Pavan
        private IEnumerator SortRoutine()
        {
            while (true)
            {
                using (PooledList <Transform> children = PooledList <Transform> .Create())
                {
                    if (children.Capacity < SortGroup.childCount)
                    {
                        children.Capacity = SortGroup.childCount;
                    }
                    for (int i = 0; i < SortGroup.childCount; ++i)
                    {
                        children.Add(SortGroup.GetChild(i));
                    }

                    children.Sort(s_HeightSorter);

                    for (int i = 0; i < children.Count; ++i)
                    {
                        children[i].SetSiblingIndex(i);
                    }

                    if (Controller.DraggingObject != null && Controller.DraggingObject.transform.parent == SortGroup)
                    {
                        Controller.DraggingObject.transform.SetAsLastSibling();
                    }
                }

                yield return(0.05f);
            }
        }
예제 #2
0
    private IEnumerator EggAnimationRoutine(int inNumToSend)
    {
        using (PooledList <Transform> targetPositions = PooledList <Transform> .Create())
        {
            for (int i = 0; i < inNumToSend; ++i)
            {
                targetPositions.Add(Counter.GetNextSlot(i + 1));
            }

            SteerableBehavior lastEgg = null;
            for (int i = 0; i < inNumToSend; ++i)
            {
                lastEgg = m_Eggs[m_Eggs.Count - 1];
                m_Eggs.RemoveAt(m_Eggs.Count - 1);
                m_AnimatingEggs.Add(lastEgg);
                SendEggToDestination(lastEgg, targetPositions[i]);
                yield return(TimeBetweenEggs);
            }

            if (m_Eggs.Count == 0 && TwoPhase == false)
            {
                while (lastEgg != null && lastEgg.IsMoving)
                {
                    yield return(null);
                }

                if (OnFinished != null)
                {
                    OnFinished();
                }
            }

            TwoPhase = false;
        }
    }
예제 #3
0
        public void CheckNullValueProcessTag(string key, object value)
        {
            var attributeEnumerationState = new AttributeEnumerationState
            {
                Tags = PooledList <KeyValuePair <string, object> > .Create(),
            };

            ProcessTags(ref attributeEnumerationState, new KeyValuePair <string, object>(key, value));

            Assert.Empty(attributeEnumerationState.Tags);
        }
예제 #4
0
        public void CheckProcessTag(string key, object value)
        {
            var attributeEnumerationState = new AttributeEnumerationState
            {
                Tags = PooledList <KeyValuePair <string, object> > .Create(),
            };

            ProcessTags(ref attributeEnumerationState, new KeyValuePair <string, object>(key, value));

            Assert.Equal(key, attributeEnumerationState.Tags[0].Key);
            Assert.Equal(value, attributeEnumerationState.Tags[0].Value);
        }
            public bool ForEach(ActivityLink activityLink)
            {
                if (!this.Created)
                {
                    this.Links = PooledList <OtlpTrace.Span.Types.Link> .Create();

                    this.Created = true;
                }

                PooledList <OtlpTrace.Span.Types.Link> .Add(ref this.Links, ToOtlpLink(activityLink));

                return(true);
            }
            public bool ForEach(ActivityEvent activityEvent)
            {
                if (!this.Created)
                {
                    this.Events = PooledList <OtlpTrace.Span.Types.Event> .Create();

                    this.Created = true;
                }

                PooledList <OtlpTrace.Span.Types.Event> .Add(ref this.Events, ToOtlpEvent(activityEvent));

                return(true);
            }
            public bool ForEach(ActivityLink activityLink)
            {
                if (!this.Created)
                {
                    this.SpanRefs = PooledList <JaegerSpanRef> .Create();

                    this.Created = true;
                }

                PooledList <JaegerSpanRef> .Add(ref this.SpanRefs, activityLink.ToJaegerSpanRef());

                return(true);
            }
            public bool ForEach(ActivityEvent activityEvent)
            {
                if (!this.Created)
                {
                    this.Logs = PooledList <JaegerLog> .Create();

                    this.Created = true;
                }

                PooledList <JaegerLog> .Add(ref this.Logs, activityEvent.ToJaegerLog());

                return(true);
            }
예제 #9
0
            public bool ForEach(ActivityEvent activityEvent)
            {
                if (!this.Created)
                {
                    this.Annotations = PooledList <ZipkinAnnotation> .Create();

                    this.Created = true;
                }

                PooledList <ZipkinAnnotation> .Add(ref this.Annotations, new ZipkinAnnotation(activityEvent.Timestamp.ToEpochMicroseconds(), activityEvent.Name));

                return(true);
            }
예제 #10
0
        private static void CollectFrame()
        {
            ProfilerFrame frame = new ProfilerFrame();

            frame.frameNumber   = currentFrame;
            frame.frameLength   = (stopwatch.ElapsedTicks / (double)Stopwatch.Frequency) * 1000000.0;
            frame.threadMethods = PooledList <(string, PooledList <ProfilerMethod>)> .Create();

            foreach (var dataList in collectedMethods.Values)
            {
                if (dataList.Count == 0)
                {
                    continue;
                }
                if (profilingThreads.TryGetValue(dataList[0].threadId, out string threadName))
                {
                    var tuple = frame.threadMethods.SingleOrDefault(x => x.Item1 == threadName);
                    PooledList <ProfilerMethod> outList = null;
                    if (tuple.Item1 == null)
                    {
                        outList = PooledList <ProfilerMethod> .Create();

                        frame.threadMethods.Add((threadName, outList));
                    }
                    else
                    {
                        outList = tuple.Item2;
                    }

                    outList.AddRange(dataList);
                }
            }

            foreach (var dataList in collectedMarkers.Values)
            {
                if (frame.markers == null)
                {
                    frame.markers = PooledList <ProfilerMarker> .Create();
                }
                frame.markers.AddRange(dataList);
            }

            if (collectedFrames.IsFull)
            {
                collectedFrames.Front().Dispose();
            }
            collectedFrames.PushBack(frame);
        }
예제 #11
0
 public void HideFrom(Transform inTransform)
 {
     CleanList();
     using (PooledList <Graphic> graphics = PooledList <Graphic> .Create())
     {
         inTransform.GetComponentsInChildren <Graphic>(graphics);
         foreach (var graphic in graphics)
         {
             if (graphic.enabled)
             {
                 graphic.enabled = false;
                 m_GraphicsToRestore.Add(graphic);
             }
         }
     }
 }
예제 #12
0
        private void SpawnChickens()
        {
            using (PooledList <DragHolder> chickenNests = PooledList <DragHolder> .Create())
            {
                int maxChickens = Level.Chickens.Length;
                if (!Level.FixedOperator)
                {
                    maxChickens += 2;
                }
                for (int i = 0; i < maxChickens; ++i)
                {
                    float offset = i - ((maxChickens - 1) / 2.0f);

                    // Spawn the nest
                    DragHolder chickenNest = ((GameObject)Instantiate(ChickenNestPrefab, new Vector3(offset * ChickenSpacing, 0, 0), Quaternion.identity)).GetComponent <DragHolder>();
                    chickenNest.transform.SetParent(ChickenRoot, false);
                    chickenNests.Add(chickenNest);
                    SlotFinder.AddSlot(chickenNest);

                    if (i < Level.Chickens.Length)
                    {
                        // Spawn the chicken
                        ExpressionChicken chicken = ((GameObject)Instantiate(ValueChickenPrefab, new Vector3(offset * ChickenSpacing, 0, 0), Quaternion.identity)).GetComponent <ExpressionChicken>();
                        chicken.transform.SetParent(ChickenRoot, false);
                        chicken.GetComponent <StartingSeat>().SetHolder(chickenNest);
                        chicken.SetValue(Level.Chickens[i]);
                        chicken.SlotFinder = SlotFinder;
                    }
                    else
                    {
                        OperatorType operatorType = i == Level.Chickens.Length ? OperatorType.Add : OperatorType.Subtract;

                        // Spawn the operator chicken
                        ExpressionChicken chicken = ((GameObject)Instantiate(OperatorChickenPrefab, new Vector3(offset * ChickenSpacing, 0, 0), Quaternion.identity)).GetComponent <ExpressionChicken>();
                        chicken.transform.SetParent(ChickenRoot, false);
                        chicken.GetComponent <StartingSeat>().SetHolder(chickenNest);
                        chicken.SetOperator(operatorType);
                        chicken.SlotFinder = SlotFinder;
                    }
                }

                foreach (var nest in chickenNests)
                {
                    nest.transform.SetAsFirstSibling();
                }
            }
        }
예제 #13
0
        private ExpressionMinigameSettings FindContextualLevel()
        {
            Level currentLevel = Session.instance.currentLevel;
            ExpressionMinigameCategories category;

            if (currentLevel.isSingleDigitProblem)
            {
                category = ExpressionMinigameCategories.Single;
            }
            else
            {
                if (currentLevel.value < LOW_DOUBLE_THRESHOLD)
                {
                    category = ExpressionMinigameCategories.DoubleLow;
                }
                else
                {
                    category = ExpressionMinigameCategories.Double;
                    if (currentLevel.requiresRegrouping)
                    {
                        category |= ExpressionMinigameCategories.Regroup;
                    }
                }
            }

            if (currentLevel.isSubtractionProblem)
            {
                category |= ExpressionMinigameCategories.Subtraction;
            }
            else
            {
                category |= ExpressionMinigameCategories.Addition;
            }

            using (PooledList <ExpressionMinigameSettings> listToUse = PooledList <ExpressionMinigameSettings> .Create())
            {
                listToUse.AddRange(m_Levels[category]);
                if ((category | ExpressionMinigameCategories.Regroup) > 0)
                {
                    listToUse.AddRange(m_Levels[category & ~ExpressionMinigameCategories.Regroup]);
                }

                return(RNG.Instance.Choose(listToUse));
            }
        }
예제 #14
0
        private DragHolder FindHolder(PointerEventData inEventData)
        {
            using (PooledList <RaycastResult> raycastResult = PooledList <RaycastResult> .Create())
            {
                EventSystem.current.RaycastAll(inEventData, raycastResult);

                foreach (var result in raycastResult)
                {
                    var b = result.gameObject.GetComponentInParent <DragBase>();
                    if (b != null && b.Type == DragBaseType.Holder)
                    {
                        return((DragHolder)b);
                    }
                }

                return(null);
            }
        }
예제 #15
0
    // Resumes all paused input.
    public void ResumeInputs()
    {
        using (PooledList <string> keys = PooledList <string> .Create())
        {
            keys.AddRange(_temporaryPausedInputs);
            _temporaryPausedInputs.Clear();

            foreach (string key in keys)
            {
                if (_activatedInputs.Contains(key))
                {
                    EnableInput(key, _objects[key], true, false);
                }
            }
        }

        Logger.Log("RESUMING INPUTS");
    }
예제 #16
0
    static public string[] EvaluateConcepts(Level inLevel)
    {
        using (PooledList <Code> codes = PooledList <Code> .Create())
        {
            codes.Capacity = 4;

            if (inLevel.isSingleDigitProblem && inLevel.isTargetNumber)
            {
                codes.Add(Code.M52);
                codes.Add(Code.M53);
            }

            if (inLevel.isDoubleDigitProblem && inLevel.isTargetNumber && !inLevel.requiresRegrouping)
            {
                codes.Add(Code.M64);
            }

            if (inLevel.isSingleDigitProblem && !inLevel.isTargetNumber)
            {
                codes.Add(Code.M80);
                codes.Add(Code.M85);
            }
            if (inLevel.isDoubleDigitProblem)
            {
                codes.Add(Code.M86);
            }
            if (inLevel.isDoubleDigitProblem && inLevel.isTargetNumber && inLevel.requiresRegrouping)
            {
                codes.Add(Code.M87);
            }
            if (!inLevel.requiresRegrouping && !inLevel.isTargetNumber)
            {
                codes.Add(Code.M88);
            }
            if (inLevel.requiresRegrouping)
            {
                codes.Add(Code.M92);
            }

            return(BuildCodeStrings(codes));
        }
    }
예제 #17
0
    static public string[] EvaluateConcepts(Minigames.ExpressionMinigame inMinigame)
    {
        using (PooledList <Code> codes = PooledList <Code> .Create())
        {
            ExpressionMinigameCategories category = inMinigame.Level.Categories;

            codes.Capacity = 4;

            bool bIsDouble = HasCategories(category, ExpressionMinigameCategories.Double) || HasCategories(category, ExpressionMinigameCategories.DoubleLow);

            if (HasCategories(category, ExpressionMinigameCategories.Single))
            {
                codes.Add(Code.M52);
                codes.Add(Code.M53);
                codes.Add(Code.M80);
                codes.Add(Code.M85);
            }

            if (bIsDouble && !HasCategories(category, ExpressionMinigameCategories.Regroup))
            {
                codes.Add(Code.M64);
            }

            if (bIsDouble)
            {
                codes.Add(Code.M86);
            }

            if (HasCategories(category, ExpressionMinigameCategories.Double | ExpressionMinigameCategories.Regroup) ||
                HasCategories(category, ExpressionMinigameCategories.DoubleLow | ExpressionMinigameCategories.Regroup))
            {
                codes.Add(Code.M87);
            }

            if (HasCategories(category, ExpressionMinigameCategories.Regroup))
            {
                codes.Add(Code.M92);
            }

            return(BuildCodeStrings(codes));
        }
    }
        internal static ZipkinSpan ToZipkinSpan(this Activity activity, ZipkinEndpoint defaultLocalEndpoint, bool useShortTraceIds = false)
        {
            var context        = activity.Context;
            var startTimestamp = activity.StartTimeUtc.ToEpochMicroseconds();

            string parentId = EncodeSpanId(activity.ParentSpanId);

            if (string.Equals(parentId, InvalidSpanId, StringComparison.Ordinal))
            {
                parentId = null;
            }

            var attributeEnumerationState = new AttributeEnumerationState
            {
                Tags = PooledList <KeyValuePair <string, string> > .Create(),
            };

            DictionaryEnumerator <string, string, AttributeEnumerationState> .AllocationFreeForEach(activity.Tags, ref attributeEnumerationState, ProcessTagsRef);

            var activitySource = activity.Source;

            if (!string.IsNullOrEmpty(activitySource.Name))
            {
                PooledList <KeyValuePair <string, string> > .Add(ref attributeEnumerationState.Tags, new KeyValuePair <string, string>("library.name", activitySource.Name));

                if (!string.IsNullOrEmpty(activitySource.Version))
                {
                    PooledList <KeyValuePair <string, string> > .Add(ref attributeEnumerationState.Tags, new KeyValuePair <string, string>("library.version", activitySource.Version));
                }
            }

            var localEndpoint = defaultLocalEndpoint;

            var serviceName = attributeEnumerationState.ServiceName;

            // override default service name
            if (!string.IsNullOrWhiteSpace(serviceName))
            {
                if (!string.IsNullOrWhiteSpace(attributeEnumerationState.ServiceNamespace))
                {
                    serviceName = attributeEnumerationState.ServiceNamespace + "." + serviceName;
                }

                if (!LocalEndpointCache.TryGetValue(serviceName, out localEndpoint))
                {
                    localEndpoint = defaultLocalEndpoint.Clone(serviceName);
                    LocalEndpointCache.TryAdd(serviceName, localEndpoint);
                }
            }

            ZipkinEndpoint remoteEndpoint = null;

            if ((activity.Kind == ActivityKind.Client || activity.Kind == ActivityKind.Producer) && attributeEnumerationState.RemoteEndpointServiceName != null)
            {
                remoteEndpoint = RemoteEndpointCache.GetOrAdd(attributeEnumerationState.RemoteEndpointServiceName, ZipkinEndpoint.Create);
            }

            var annotations = PooledList <ZipkinAnnotation> .Create();

            ListEnumerator <ActivityEvent, PooledList <ZipkinAnnotation> > .AllocationFreeForEach(activity.Events, ref annotations, ProcessActivityEventsRef);

            return(new ZipkinSpan(
                       EncodeTraceId(context.TraceId, useShortTraceIds),
                       parentId,
                       EncodeSpanId(context.SpanId),
                       ToActivityKind(activity),
                       activity.OperationName,
                       activity.StartTimeUtc.ToEpochMicroseconds(),
                       duration: (long)activity.Duration.ToEpochMicroseconds(),
                       localEndpoint,
                       remoteEndpoint,
                       annotations,
                       attributeEnumerationState.Tags,
                       null,
                       null));
        }
예제 #19
0
 public Batch(Process process)
 {
     this.Process      = process ?? throw new ArgumentNullException(nameof(process));
     this.spanMessages = PooledList <BufferWriterMemory> .Create();
 }
예제 #20
0
    private void MakeChickenPhoto()
    {
        m_LastPolaroid = configurations[RNG.Instance.Next(0, configurations.Length)];

        if (Session.instance.numEggs == 0)
        {
            if (firstLevelConfiguration != null)
            {
                m_LastPolaroid = firstLevelConfiguration;
            }
            else
            {
                Logger.Warn("Missing PolaroidConfig for first level!");
            }
        }

        // display foreground
        _background.GetComponent <Image>().sprite = m_LastPolaroid.Background;

        // display foreground
        Image image = _foreground.GetComponent <Image>();

        image.sprite  = m_LastPolaroid.Foreground;
        image.enabled = image.sprite != null;

        // clear chicken mounts
        foreach (Transform slot in ChickenSlots)
        {
            slot.GetComponent <Image>().enabled = false;
        }
        foreach (var pilotConfig in PeacockAndKiwi)
        {
            pilotConfig.Slot.gameObject.SetActive(false);
        }

        int numberOfChickensToDisplay = 1;

        if (Session.instance.currentLevel.value > 1 && RNG.Instance.NextBool())
        {
            numberOfChickensToDisplay = 2;
        }

        using (PooledList <Sprite> foregroundChickens = PooledList <Sprite> .Create())
        {
            // HORRIBLE HACK
            GameObject screen   = GameObject.FindGameObjectWithTag("GameScreen");
            MyScreen   myScreen = screen.GetComponent <MyScreen>();

            int brownCount = myScreen.onesColumn.GetNumWithColor(CreatureCtrl.COLOR_BROWN) + myScreen.tensColumn.GetNumWithColor(CreatureCtrl.COLOR_BROWN) * 10;
            int goldCount  = myScreen.tensColumn.GetNumWithColor(CreatureCtrl.COLOR_GOLD) * 10;
            int whiteCount = myScreen.onesColumn.GetNumWithColor(CreatureCtrl.COLOR_WHITE) + myScreen.tensColumn.GetNumWithColor(CreatureCtrl.COLOR_WHITE) * 10;

            bool bCheckExclusionList = Optimizer.instance.DisableMasks;

            if (brownCount == 1)
            {
                Sprite brownChicken = null;
                while (brownChicken == null)
                {
                    brownChicken = RNG.Instance.Choose(m_LastPolaroid.BrownChickens);
                    if (bCheckExclusionList && ExcludedOnLowEnd.Contains(brownChicken))
                    {
                        brownChicken = null;
                    }
                }
                string brownChickenPose = brownChicken.name;
                foregroundChickens.Add(brownChicken);

                Sprite whiteChicken = null;
                int    tries        = m_LastPolaroid.WhiteChickens.Length * 2;
                while (whiteChicken == null && --tries >= 0)
                {
                    whiteChicken = RNG.Instance.Choose(m_LastPolaroid.WhiteChickens);
                    if (whiteChicken.name.Contains(brownChickenPose) || (bCheckExclusionList && ExcludedOnLowEnd.Contains(whiteChicken)))
                    {
                        whiteChicken = null;
                    }
                }
                if (whiteChicken != null)
                {
                    foregroundChickens.Add(whiteChicken);
                }
                else
                {
                    numberOfChickensToDisplay = 1;
                }
            }
            else if (brownCount >= 2)
            {
                AddValidPoses(foregroundChickens, m_LastPolaroid.BrownChickens);
            }
            else
            {
                AddValidPoses(foregroundChickens, m_LastPolaroid.WhiteChickens);
                if (foregroundChickens.Count < 2)
                {
                    numberOfChickensToDisplay = 1;
                }
            }

            ChickenSlots.Shuffle();

            for (int i = 0; i < numberOfChickensToDisplay; ++i)
            {
                int chickenIndex = (i % foregroundChickens.Count);
                if (chickenIndex == 0)
                {
                    foregroundChickens.Shuffle();
                }

                Image slot = ChickenSlots[i].GetComponent <Image>();
                slot.sprite  = foregroundChickens[chickenIndex];
                slot.enabled = true;
                //slot.SetNativeSize();
            }
        }
    }
        internal static ZipkinSpan ToZipkinSpan(this SpanData otelSpan, ZipkinEndpoint defaultLocalEndpoint, bool useShortTraceIds = false)
        {
            var context        = otelSpan.Context;
            var startTimestamp = ToEpochMicroseconds(otelSpan.StartTimestamp);
            var endTimestamp   = ToEpochMicroseconds(otelSpan.EndTimestamp);

            string parentId = null;

            if (otelSpan.ParentSpanId != default)
            {
                parentId = EncodeSpanId(otelSpan.ParentSpanId);
            }

            var attributeEnumerationState = new AttributeEnumerationState
            {
                Tags = PooledList <KeyValuePair <string, string> > .Create(),
            };

            DictionaryEnumerator <string, object, AttributeEnumerationState> .AllocationFreeForEach(otelSpan.Attributes, ref attributeEnumerationState, ProcessAttributesRef);

            DictionaryEnumerator <string, object, AttributeEnumerationState> .AllocationFreeForEach(otelSpan.LibraryResource.Attributes, ref attributeEnumerationState, ProcessLibraryResourcesRef);

            var localEndpoint = defaultLocalEndpoint;

            var serviceName = attributeEnumerationState.ServiceName;

            // override default service name
            if (!string.IsNullOrWhiteSpace(serviceName))
            {
                if (!string.IsNullOrWhiteSpace(attributeEnumerationState.ServiceNamespace))
                {
                    serviceName = attributeEnumerationState.ServiceNamespace + "." + serviceName;
                }

                if (!LocalEndpointCache.TryGetValue(serviceName, out localEndpoint))
                {
                    localEndpoint = defaultLocalEndpoint.Clone(serviceName);
                    LocalEndpointCache.TryAdd(serviceName, localEndpoint);
                }
            }

            ZipkinEndpoint remoteEndpoint = null;

            if ((otelSpan.Kind == SpanKind.Client || otelSpan.Kind == SpanKind.Producer) && attributeEnumerationState.RemoteEndpointServiceName != null)
            {
                remoteEndpoint = RemoteEndpointCache.GetOrAdd(attributeEnumerationState.RemoteEndpointServiceName, ZipkinEndpoint.Create);
            }

            var status = otelSpan.Status;

            if (status.IsValid)
            {
                if (!CanonicalCodeCache.TryGetValue(status.CanonicalCode, out string canonicalCode))
                {
                    canonicalCode = status.CanonicalCode.ToString();
                    CanonicalCodeCache.TryAdd(status.CanonicalCode, canonicalCode);
                }

                PooledList <KeyValuePair <string, string> > .Add(ref attributeEnumerationState.Tags, new KeyValuePair <string, string>(StatusCode, canonicalCode));

                if (status.Description != null)
                {
                    PooledList <KeyValuePair <string, string> > .Add(ref attributeEnumerationState.Tags, new KeyValuePair <string, string>(StatusDescription, status.Description));
                }
            }

            var annotations = PooledList <ZipkinAnnotation> .Create();

            ListEnumerator <Event, PooledList <ZipkinAnnotation> > .AllocationFreeForEach(otelSpan.Events, ref annotations, ProcessEventsRef);

            return(new ZipkinSpan(
                       EncodeTraceId(context.TraceId, useShortTraceIds),
                       parentId,
                       EncodeSpanId(context.SpanId),
                       ToSpanKind(otelSpan),
                       otelSpan.Name,
                       ToEpochMicroseconds(otelSpan.StartTimestamp),
                       duration: endTimestamp - startTimestamp,
                       localEndpoint,
                       remoteEndpoint,
                       annotations,
                       attributeEnumerationState.Tags,
                       null,
                       null));
        }
            public bool ForEach(KeyValuePair <string, object> activityTag)
            {
                if (activityTag.Value == null)
                {
                    return(true);
                }

                var key = activityTag.Key;

                switch (key)
                {
                case SpanAttributeConstants.StatusCodeKey:
                    this.StatusCode = activityTag.Value as string;
                    return(true);

                case SpanAttributeConstants.StatusDescriptionKey:
                    this.StatusDescription = activityTag.Value as string;
                    return(true);
                }

                if (!this.Created)
                {
                    this.Tags = PooledList <OtlpCommon.KeyValue> .Create();

                    this.Created = true;
                }

                OtlpCommon.ArrayValue arrayValue;

                switch (activityTag.Value)
                {
                case string s:
                    PeerServiceResolver.InspectTag(ref this, key, s);
                    PooledList <OtlpCommon.KeyValue> .Add(ref this.Tags, CreateOtlpKeyValue(key, new OtlpCommon.AnyValue {
                        StringValue = s
                    }));

                    break;

                case bool b:
                    PooledList <OtlpCommon.KeyValue> .Add(ref this.Tags, CreateOtlpKeyValue(key, new OtlpCommon.AnyValue {
                        BoolValue = b
                    }));

                    break;

                case int i:
                    PeerServiceResolver.InspectTag(ref this, key, i);
                    PooledList <OtlpCommon.KeyValue> .Add(ref this.Tags, CreateOtlpKeyValue(key, new OtlpCommon.AnyValue {
                        IntValue = i
                    }));

                    break;

                case long l:
                    PooledList <OtlpCommon.KeyValue> .Add(ref this.Tags, CreateOtlpKeyValue(key, new OtlpCommon.AnyValue {
                        IntValue = l
                    }));

                    break;

                case double d:
                    PooledList <OtlpCommon.KeyValue> .Add(ref this.Tags, CreateOtlpKeyValue(key, new OtlpCommon.AnyValue {
                        DoubleValue = d
                    }));

                    break;

                case int[] intArray:
                    arrayValue = new OtlpCommon.ArrayValue();
                    foreach (var item in intArray)
                    {
                        arrayValue.Values.Add(new OtlpCommon.AnyValue {
                            IntValue = item
                        });
                    }

                    PooledList <OtlpCommon.KeyValue> .Add(ref this.Tags, CreateOtlpKeyValue(key, new OtlpCommon.AnyValue {
                        ArrayValue = arrayValue
                    }));

                    break;

                case double[] doubleArray:
                    arrayValue = new OtlpCommon.ArrayValue();
                    foreach (var item in doubleArray)
                    {
                        arrayValue.Values.Add(new OtlpCommon.AnyValue {
                            DoubleValue = item
                        });
                    }

                    PooledList <OtlpCommon.KeyValue> .Add(ref this.Tags, CreateOtlpKeyValue(key, new OtlpCommon.AnyValue {
                        ArrayValue = arrayValue
                    }));

                    break;

                case bool[] boolArray:
                    arrayValue = new OtlpCommon.ArrayValue();
                    foreach (var item in boolArray)
                    {
                        arrayValue.Values.Add(new OtlpCommon.AnyValue {
                            BoolValue = item
                        });
                    }

                    PooledList <OtlpCommon.KeyValue> .Add(ref this.Tags, CreateOtlpKeyValue(key, new OtlpCommon.AnyValue {
                        ArrayValue = arrayValue
                    }));

                    break;

                case string[] stringArray:
                    arrayValue = new OtlpCommon.ArrayValue();
                    foreach (var item in stringArray)
                    {
                        arrayValue.Values.Add(item == null ? new OtlpCommon.AnyValue() : new OtlpCommon.AnyValue {
                            StringValue = item
                        });
                    }

                    PooledList <OtlpCommon.KeyValue> .Add(ref this.Tags, CreateOtlpKeyValue(key, new OtlpCommon.AnyValue {
                        ArrayValue = arrayValue
                    }));

                    break;

                case long[] longArray:
                    arrayValue = new OtlpCommon.ArrayValue();
                    foreach (var item in longArray)
                    {
                        arrayValue.Values.Add(new OtlpCommon.AnyValue {
                            IntValue = item
                        });
                    }

                    PooledList <OtlpCommon.KeyValue> .Add(ref this.Tags, CreateOtlpKeyValue(key, new OtlpCommon.AnyValue {
                        ArrayValue = arrayValue
                    }));

                    break;

                default:
                    PooledList <OtlpCommon.KeyValue> .Add(ref this.Tags, CreateOtlpKeyValue(key, new OtlpCommon.AnyValue {
                        StringValue = activityTag.Value.ToString()
                    }));

                    break;
                }

                return(true);
            }
예제 #23
0
        public static void WriteToFile(string filename, ProfilingFormat format, FrameSelection frameSelection = FrameSelection.Median)
        {
            if (!ProfilingEnabled)
            {
                throw new InvalidOperationException("Cannot write profile to file when profiling is not enabled.");
            }
            ProfilerFrame frame = default;

            if (collectedFrames.IsEmpty)
            {
                return;
            }

            bool needsDispose = false;

            switch (frameSelection)
            {
            case FrameSelection.Median:
                var ordered = collectedFrames.OrderBy(x => x.frameLength).ToArray();
                frame = ordered[(int)Math.Floor(ordered.Length / 2.0)];
                break;

            case FrameSelection.Longest:
                frame = collectedFrames.MaxBy(x => x.frameLength);
                break;

            case FrameSelection.Shortest:
                frame = collectedFrames.MinBy(x => x.frameLength);
                break;

            case FrameSelection.Latest:
                frame = collectedFrames.Back();
                break;

            case FrameSelection.Percentile95:
                ordered = collectedFrames.OrderBy(x => x.frameLength).ToArray();
                int index = ordered.Length - (int)(ordered.Length * 0.05f);
                if (index >= ordered.Length)
                {
                    index = ordered.Length - 1;
                }
                frame = ordered[index];
                break;

            case FrameSelection.All:
                frame             = new ProfilerFrame();
                frame.frameNumber = collectedFrames.Min(x => x.frameNumber);
                frame.frameLength = collectedFrames.Sum(x => x.frameLength);
                frame.markers     = PooledList <ProfilerMarker> .Create();

                double elapsedTime = 0;
                foreach (var collectedFrame in collectedFrames)
                {
                    if (collectedFrame.markers != null)
                    {
                        frame.markers.AddRange(collectedFrame.markers.Select(x =>
                                                                             new ProfilerMarker(x.markName, x.time + elapsedTime)));
                    }
                    elapsedTime += collectedFrame.frameLength;
                }
                frame.threadMethods = PooledList <(string, PooledList <ProfilerMethod>)> .Create();

                elapsedTime = 0;
                foreach (var collectedFrame in collectedFrames)
                {
                    foreach (var collectedFrameThreadMethod in collectedFrame.threadMethods)
                    {
                        var tuple = frame.threadMethods.SingleOrDefault(x => x.Item1 == collectedFrameThreadMethod.Item1);
                        PooledList <ProfilerMethod> outList = null;
                        if (tuple.Item1 == null)
                        {
                            outList = PooledList <ProfilerMethod> .Create();

                            frame.threadMethods.Add((collectedFrameThreadMethod.Item1, outList));
                        }
                        else
                        {
                            outList = tuple.Item2;
                        }
                        outList.AddRange(collectedFrameThreadMethod.Item2.Select(x => new ProfilerMethod(
                                                                                     x.methodName, x.depth, x.startTime + elapsedTime, x.endTime + elapsedTime, x.threadId)));
                    }
                    elapsedTime += collectedFrame.frameLength;
                }

                needsDispose = true;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(frameSelection), frameSelection, null);
            }

            switch (format)
            {
            case ProfilingFormat.SpeedScope:
                SpeedScopeWriter.WriteToFile(frame, filename);
                break;

            case ProfilingFormat.ChromeTracing:
                ChromeTracingWriter.WriteToFile(frame, filename);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(format), format, null);
            }

            if (needsDispose)
            {
                frame.Dispose();
            }
        }
        public GroupActions GetGroupsToUpdate(IGroupVisibilityContext options)
        {
            if (options == null)
            {
                return(null);
            }

            var planes                            = options.CameraPlanes;
            var frustumCorners                    = options.CameraFrustumCorners;
            var cameraPosition                    = options.CameraPosition;
            var cameraLocalToWorldMatrix          = options.CameraLocalToWorldMatrix;
            var parentContainerWorldToLocalMatrix = options.ParentContainerWorldToLocalMatrix;
            var groupBoundsTemplate               = options.GroupBounds;
            var cellInGroupCount                  = options.CellInGroupCount;
            var invalidatedArea                   = options.InvalidatedArea_worldSpace;

            var cameraPositionLocal = parentContainerWorldToLocalMatrix.MultiplyPoint(cameraPosition);

            var localCameraBounds = new Bounds(cameraPositionLocal, new Vector3());

            for (int i = 0; i < 4; i++)
            {
                var vector = parentContainerWorldToLocalMatrix.MultiplyPoint(cameraLocalToWorldMatrix.MultiplyVector(frustumCorners[i]));
                localCameraBounds.Encapsulate(cameraPositionLocal + vector);
            }

            var bounds_center = groupBoundsTemplate.center;
            var bounds_size   = groupBoundsTemplate.size;

            int min_group_x        = Mathf.FloorToInt(localCameraBounds.min.x);
            int min_group_y        = Mathf.FloorToInt(localCameraBounds.min.y);
            int max_group_x        = Mathf.CeilToInt(localCameraBounds.max.x);
            int max_group_y        = Mathf.CeilToInt(localCameraBounds.max.y);
            var cellInGroupCount_x = cellInGroupCount.x;
            var cellInGroupCount_y = cellInGroupCount.y;

            var groupsToRecompute = PooledList <Vector2i> .Create();

            var groupsToKeep = PooledList <Vector2i> .Create();

            for (int group_x = min_group_x; group_x <= max_group_x; group_x++)
            {
                for (int group_y = min_group_y; group_y <= max_group_y; group_y++)
                {
                    var group       = new Vector2i(group_x, group_y);
                    var groupBounds = new Bounds(new Vector3
                                                 (
                                                     bounds_center.x + group_x * cellInGroupCount_x,
                                                     bounds_center.y + group_y * cellInGroupCount_y,
                                                     bounds_center.z
                                                 ), bounds_size);

                    bool isInside = TestPlanesAABB(planes, groupBounds);
                    if (isInside)
                    {
                        var groupArea = new Rect2i(group * cellInGroupCount, cellInGroupCount);
                        if (groupArea.Overlaps(invalidatedArea))
                        {
                            groupsToRecompute.Add(group);
                        }
                        else
                        {
                            if (!options.ExistingGroups.Contains(group))
                            {
                                groupsToRecompute.Add(group);
                            }
                            else
                            {
                                groupsToKeep.Add(group);
                            }
                        }
                    }
                }
            }
            return(new GroupActions(groupsToRecompute, groupsToKeep));
        }