internal void Reset(TimeSpan time)
 {
     for (var Index = 0; Index < _Records.Length; Index++)
     {
         SectionState.Reset(ref _Records[Index], time);
     }
 }
Example #2
0
    private void RecalculateSectionProperties()
    {
        _sectionStates = new SectionState[_numSections];

        for (int i = 0; i < _numSections; i++)
        {
            var section = new SectionState();

            // Find surface area for each section (uses property of trapezoids as shortcut)
            float sectionSpan       = _span / _numSections;
            float averageCordLength = Mathf.Lerp(_cordLengthA, _cordLengthB, 1f / _numSections / 2f + i / (float)_numSections);
            section.SurfaceArea = sectionSpan * averageCordLength;

            // Spread sections evenly over the width of the wing
            float spanPosition = -0.5f * _span + sectionSpan * i + sectionSpan * 0.5f;

            // Choose point along cord line
            float cordPosition = averageCordLength * _cordPressurePoint;

            section.LocalPosition            = new Vector3(spanPosition, 0f, cordPosition);
            section.LastSectionWorldPosition = transform.TransformPoint(section.LocalPosition);

            _sectionStates[i] = section;
        }
    }
    private void OnDrawGizmos()
    {
        if (!Application.isPlaying)
        {
            return;
        }

        const float scale = PhysicsUtils.DebugForceScale;

        float mass = CalculateTotalMass();

        for (int i = 0; i < _airfoil.SectionStates.Length; i++)
        {
            SectionState sectionState = _airfoil.SectionStates[i];
            Vector3      position     = transform.TransformPoint(sectionState.LocalPosition);

            //Gizmos.color = Color.white;
            //Gizmos.DrawSphere(position, 0.01f);
            //Gizmos.DrawRay(position, sectionState.RelativeVelocity / 10f);
            Gizmos.color = Color.green;
            Gizmos.DrawRay(position, sectionState.Lift / mass * scale);
            Gizmos.color = Color.red;
            Gizmos.DrawRay(position, sectionState.Drag / mass * scale);
            Gizmos.color = Color.blue;
            Gizmos.DrawRay(position, sectionState.Moment / mass * scale);
        }
    }
            //****************************************

            internal void Finish(TimeSpan startTime)
            {
                var Ticks   = _Profiler.GetTicks();
                var Elapsed = Ticks - startTime;

                for (var Index = 0; Index < _Records.Length; Index++)
                {
                    SectionState.Finish(ref _Records[Index], Ticks, Elapsed);
                }
            }
            //****************************************

            internal Section(string name, Profiler profiler)
            {
                Name      = name;
                _Profiler = profiler;

                var Intervals = profiler._Intervals;

                _Records = new SectionState[Intervals.Length];

                for (var Index = 0; Index < Intervals.Length; Index++)
                {
                    _Records[Index] = new SectionState(Intervals[Index], TimeSpan.Zero);
                }
            }
            //****************************************

            internal static void Reset(ref SectionState state, TimeSpan time)
            {
                var NewState = new SectionState(state.Interval, time);

                Interlocked.Exchange(ref state, NewState);
            }
Example #7
0
 internal virtual async Task WriteEndSectionAsync(SectionState state)
 {
     await WriteEndElementAsync(); //content | sections
     await WriteEndElementAsync(); //section
 }
Example #8
0
            public SectionState[] DoCheckLine()
            {
                var count  = sections.Length;
                var result = new SectionState[count];

                if (count == 0 || (count == 1 && sections[0] == 0))
                {
                    var state =
                        cells.Any(c => c == CellState.Fill)
                            ? SectionState.Wrong
                            : cells.All(c => c == CellState.Dot)
                                ? SectionState.Right
                                : SectionState.InProgress;
                    result.Fill(state);
                    return(result);
                }

                if (cells.All(c => c == CellState.Unknown))
                {
                    result.Fill(SectionState.InProgress);
                    return(result);
                }

                posFlags   = new bool[count, cells.Length];
                passResult = PassResultPosition;

                CheckLineRecursion(0, 0);

                for (int i = 0; i < count; i++)
                {
                    int trueCount =
                        posFlags
                        .AsEnumerableDimension1(i)
                        .Count(f => f);
                    switch (trueCount)
                    {
                    //not founded any position, answer is wrong
                    case 0:
                        result.Fill(SectionState.Wrong);
                        return(result);

                    //only one position, is good
                    case 1:
                        //check position of True value
                        int pos =
                            posFlags
                            .AsEnumerableDimension1(i)
                            .TakeWhile(f => !f)
                            .Count();
                        //check all Fill from position
                        bool allIsFill =
                            cells
                            .Skip(pos)
                            .Take(sections[i])
                            .All(cs => cs == CellState.Fill);

                        result[i] = allIsFill ? SectionState.Right : SectionState.InProgress;
                        break;

                    default:
                        result[i] = SectionState.InProgress;
                        break;
                    }
                }
                return(result);
            }
Example #9
0
 private void CreateButton(string buttonTitle, SectionState sectionType)
 {
     list.AddButton(buttonTitle, () => OnChooseSection(sectionType));
 }
Example #10
0
 internal override async Task WriteEndSectionAsync(SectionState state)
 {
     await WriteEndElementAsync(); //procedure
 }
Example #11
0
            public SectionState[] DoCheckLine()
            {
                var count = sections.Length;
                var result = new SectionState[count];

                if (count == 0 || (count == 1 && sections[0] == 0))
                {
                    var state =
                        cells.Any(c => c == CellState.Fill)
                            ? SectionState.Wrong
                            : cells.All(c => c == CellState.Dot)
                                ? SectionState.Right
                                : SectionState.InProgress;
                    result.Fill(state);
                    return result;
                }

                if (cells.All(c => c == CellState.Unknown))
                {
                    result.Fill(SectionState.InProgress);
                    return result;
                }

                posFlags = new bool[count, cells.Length];
                passResult = PassResultPosition;

                CheckLineRecursion(0, 0);

                for (int i = 0; i < count; i++)
                {
                    int trueCount =
                        posFlags
                            .AsEnumerableDimension1(i)
                            .Count(f => f);
                    switch (trueCount)
                    {
                        //not founded any position, answer is wrong
                        case 0:
                            result.Fill(SectionState.Wrong);
                            return result;
                        //only one position, is good
                        case 1:
                            //check position of True value
                            int pos =
                                posFlags
                                    .AsEnumerableDimension1(i)
                                    .TakeWhile(f => !f)
                                    .Count();
                            //check all Fill from position
                            bool allIsFill =
                                cells
                                    .Skip(pos)
                                    .Take(sections[i])
                                    .All(cs => cs == CellState.Fill);

                            result[i] = allIsFill ? SectionState.Right : SectionState.InProgress;
                            break;

                        default:
                            result[i] = SectionState.InProgress;
                            break;
                    }
                }
                return result;
            }
Example #12
0
 public Section(int len)
 {
     Len = len;
     State = SectionState.InProgress;
 }
Example #13
0
 internal void SetSectionState(SectionState state)
 {
     SectionStates.Pop();
     SectionStates.Push(state);
 }
            internal static void Finish(ref SectionState state, TimeSpan time, TimeSpan elapsed)
            {
                SectionState State;
                var          Elapsed = elapsed.Ticks;

                for (; ;)
                {
                    State = Volatile.Read(ref state);

                    var Interval = State._Interval;

                    if (Interval == TimeSpan.Zero)
                    {
                        lock (State)
                        {
                            State._Current = State._Current.Add(Elapsed);
                        }

                        return;
                    }

                    var Finish = State._Time + Interval;

                    if (time < Finish)
                    {
                        // Still within the time interval
                        lock (State)
                        {
                            if (!State.IsExpired)
                            {
                                // Not expired, so update it and return
                                State._Current = State._Current.Add(Elapsed);

                                return;
                            }
                        }

                        // Another thread is performing a replacement, try again
                    }
                    else if (time < Finish + Interval)
                    {
                        // We're within the next time interval, flag the state as expired so we can lock in that interval
                        lock (State)
                        {
                            if (!State.IsExpired)
                            {
                                State._IsExpired = -1;

                                var NewState = new SectionState(Interval, time, ProfilerRecord.Empty.Add(Elapsed), State._Current);

                                // Replace the current state with a new state
                                if (Interlocked.CompareExchange(ref state, NewState, State) == State)
                                {
                                    return;
                                }
                            }
                        }

                        // Another thread is performing a replacement, try again
                    }
                    else
                    {
                        // Two intervals have passed since this state began recording, so we replace with a zero previous record
                        var NewState = new SectionState(Interval, time, ProfilerRecord.Empty.Add(Elapsed));

                        // Replace the current state with a new state
                        if (Interlocked.CompareExchange(ref state, NewState, State) == State)
                        {
                            return;
                        }

                        // Another thread is performing a replacement, try again
                    }
                }
            }
Example #15
0
 private void OnChooseSection(SectionState sectionArea)
 {
     Messenger <SectionState> .Broadcast(UIEvent.SECTION_PUSH_CHOOSED, sectionArea);
 }
Example #16
0
 public Section(int len)
 {
     Len   = len;
     State = SectionState.InProgress;
 }
 private void OnGetChoosedSection(SectionState section)
 {
     State = section;
 }
Example #18
0
 internal override async Task WriteEndSectionAsync(SectionState state)
 {
     await WriteEndElementAsync(); //glossaryEntry
 }
Example #19
0
 public Section(int mark, SectionState state)
 {
     Mark  = mark;
     State = state;
 }