Beispiel #1
0
    private void LateUpdate()
    {
        if (Running)
        {
            int currentIndex = (int)CurrentState;
            int nextIndex    = currentIndex + 1;
            if (nextIndex >= totalStateLength)
            {
                nextIndex = 0;
            }

            float currentRotation = rotationAngles[currentIndex];
            float nextRotation    = rotationAngles[nextIndex];
            if (nextIndex == 0)
            {
                nextRotation = 360f;
            }

            float progress = (Time.time - StartTime) / timesInSeconds[currentIndex];

            transform.localRotation = Quaternion.Euler(new Vector3(0, 0, currentRotation + progress * (nextRotation - currentRotation)));
            foreach (var g in stateImages)
            {
                g.transform.localRotation = Quaternion.Euler(new Vector3(0, 0, -transform.localRotation.eulerAngles.z));
            }

            if (progress > 1)
            {
                CurrentState = (LoopState)nextIndex;
                StartTime    = Time.time;

                ActivateState(CurrentState);
            }
        }
    }
Beispiel #2
0
    public void Reset()
    {
        CurrentState = (LoopState)0;
        StartTime    = Time.time;

        ActivateState(CurrentState);
    }
Beispiel #3
0
    public void ForceState(LoopState s)
    {
        CurrentState = s;
        StartTime    = Time.time;

        ActivateState(CurrentState);
    }
        bool TryParseVersionAndPackage(LoopState loopState, out VersionRange snippetVersion, out string error)
        {
            snippetVersion = null;
            if (loopState.Version == null)
            {
                snippetVersion = fileVersion;
                error          = null;
                return(true);
            }

            VersionRange version;

            if (VersionRangeParser.TryParseVersion(loopState.Version, out version))
            {
                if (fileVersion.IsPreRelease())
                {
                    error = $"Could not use '{loopState.Version}' since directory is flagged as Prerelease. FileVersion: {fileVersion.ToFriendlyString()}.";
                    return(false);
                }
                snippetVersion = version;

                error = null;
                return(true);
            }

            error = $"Expected '{loopState.Version}' to be parsable as a version.";
            return(false);
        }
Beispiel #5
0
        public void StartLoop(CancellationToken token)
        {
            RxLoopConfiguration.Trace($"[{LoopGuid}] Starting loop.");
            var loopState = new LoopState(token);

            ScheduleNextRunImmediately(loopState);
        }
Beispiel #6
0
    void HandleDrawing()
    {
        TimeTillReload -= Time.deltaTime;
        if (TimeTillReload <= 0)
        {
            loopState = LoopState.TERMINATED;
            //Play The "empty gun" sound
            loopManager.PlayEmpty();
            return;
        }

        loopTimer         = Time.time + loopDuration;
        currMousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        if (Vector2.Distance(currMousePosition, prevMousePosition) > minDistanceMoved)
        {
            segments = CalculateSegments();
            winding  = LoopUtils.CalculateWinding(segments);

            if (Time.time > mouseDetectionTimer)
            {
                mouseDetectionTimer = Time.time + mouseDetectionInterval;
                if (points.Count >= maxSegments && points.Count > 0)
                {
                    points.RemoveAt(0);
                }
                points.Add(currMousePosition);
            }
            prevMousePosition = currMousePosition;
        }
    }
Beispiel #7
0
 private void ButtonLoop_Click(object sender, EventArgs e)
 {
     if (LoopState == LoopState.One)
     {
         LoopState = LoopState.All;
         LoopModeAllToolStripMenuItem.Checked = true;
         LoopModeOneToolStripMenuItem.Checked = false;
         LoopModeOffToolStripMenuItem.Checked = false;
         ButtonLoop.BackgroundImage           = Properties.Resources.LoopAll;
     }
     else if (LoopState == LoopState.All)
     {
         LoopState = LoopState.Off;
         LoopModeOffToolStripMenuItem.Checked = true;
         LoopModeOneToolStripMenuItem.Checked = false;
         LoopModeAllToolStripMenuItem.Checked = false;
         ButtonLoop.BackgroundImage           = Properties.Resources.LoopOff;
     }
     else if (LoopState == LoopState.Off)
     {
         LoopState = LoopState.One;
         LoopModeOneToolStripMenuItem.Checked = true;
         LoopModeAllToolStripMenuItem.Checked = false;
         LoopModeOffToolStripMenuItem.Checked = false;
         ButtonLoop.BackgroundImage           = Properties.Resources.LoopOne;
     }
 }
Beispiel #8
0
        private void btnStop_Click(object sender, EventArgs e)
        {
            int    sum = 0;
            string msg = "";

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); //引用stopwatch物件
            sw.Reset();                                                           //碼表歸零
            sw.Start();                                                           //碼表開始計時
            object sync = new object();

            Parallel.For(1, 11, (i, LoopState) =>
            {
                if (i == 5)
                {
                    LoopState.Stop();
                }
                lock (sync) //若沒有Lock則會因競爭而有資料遺失
                {
                    sum = sum + i;
                }
                string buf = String.Format("i={0},sum={1}\n", i, sum);
                msg        = msg + buf;
            });
            sw.Stop();//碼錶停止
            string ParallelForResult = sw.Elapsed.TotalMilliseconds.ToString();

            rtxtResult.Text = string.Format("Stop執行結束:{0}毫秒。\n{1}", ParallelForResult, msg);
        }
Beispiel #9
0
        public void Start(LoopHandler handler, LoopExceptionHandler exceptionHandler)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(null, "Cannot access diposed Loop instance.");
            }
            if (_started)
            {
                throw new InvalidOperationException("Loop already started.");
            }

            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }
            if (exceptionHandler == null)
            {
                throw new ArgumentNullException(nameof(exceptionHandler));
            }

            _started = true;
            _state   = LoopState.Started;

            _handler          = handler;
            _exceptionHandler = exceptionHandler;

            _thread.Start();
        }
Beispiel #10
0
    // Image FillAmount 코루틴
    //public IEnumerator ieLoopCount()
    //{
    //    while (beats <= maxBeats)
    //    {
    //        loop_BeatCount.fillAmount = ((float)beats) / maxBeats;
    //        beats = (beats + 1) % maxBeats;
    //        yield return new WaitForSeconds(60f / tempo);
    //    }
    //}

    public void SetState(LoopState state)
    {
        this.state = state;
        switch (state)
        {
        case LoopState.Pause:
            playImg.enabled   = true;
            stopImg.enabled   = false;
            playText.enabled  = true;
            stopText.enabled  = false;
            startText.enabled = false;
            break;

        case LoopState.Ready:
            playImg.enabled   = false;
            stopImg.enabled   = false;
            playText.enabled  = false;
            stopText.enabled  = false;
            startText.enabled = true;
            break;

        case LoopState.Play:
            playImg.enabled   = false;
            stopImg.enabled   = true;
            playText.enabled  = false;
            stopText.enabled  = true;
            startText.enabled = false;
            break;
        }
    }
Beispiel #11
0
        public static IEnumerable <T> Track <T>(this IEnumerator <T> enumerator)
        {
            var tracker = new LoopState <T>(CurrentLoop, enumerator);

            CurrentLoop = tracker;
            return(tracker);
        }
Beispiel #12
0
    void ActivateState(LoopState state)
    {
        larva.SetActive(false);
        cockcroach.SetActive(false);
        butterfly.SetActive(false);
        larvaToRoach.SetActive(false);
        roachToButterfly.SetActive(false);
        butterflyDeath.SetActive(false);
        switch (state)
        {
        case LoopState.LarvaBirth: if (nest != null)
            {
                transform.position = nest.transform.position;
            }
            larvabirth.SetActive(true); return;

        case LoopState.Larva: larva.SetActive(true); return;

        case LoopState.LarvaToRoach: larvaToRoach.SetActive(true); return;

        case LoopState.Roach: cockcroach.SetActive(true); return;

        case LoopState.RoachToButterfly: roachToButterfly.SetActive(true); return;

        case LoopState.Butterfly: butterfly.SetActive(true); return;

        case LoopState.ButterflyDeath: butterflyDeath.SetActive(true); return;
        }
    }
    private static LoopState GetLoopState(UnityAction unityAction)
    {
        if (unityAction == null)
        {
            return(null);
        }
        LooperUtilityMono i = m_instanceInScene;

        if (m_instanceInScene == null)
        {
            GameObject go = new GameObject("LoopUtilityMono");
            m_instanceInScene = go.AddComponent <LooperUtilityMono>();
            i = m_instanceInScene;
        }
        if (i == null)
        {
            return(null);
        }
        string id = "" + unityAction.GetHashCode();

        if (!i.m_loopRegister.ContainsKey(id))
        {
            LoopState ls = new LoopState()
            {
                m_actionToPush = unityAction
            };
            i.m_loops.Add(ls);
            i.m_loopRegister.Add(id, ls);
        }
        return(i.m_loopRegister[id]);
    }
Beispiel #14
0
        public override void SimulateEnviroment()
        {
            Exception error = null;

            Parallel.For(0, Species.Length, (i, LoopState) =>
            {
                try
                {
                    Genome FinishedSpecie;
                    do
                    {
                        FinishedSpecie = Species[i].EvolveSpecie();
                        CheckBestCandidate(FinishedSpecie.SpecInfo.GetCopy());
                    } while (FinishedSpecie.BestCandidate.OffSet != 0);
                }
                catch (Exception e)
                {
                    error = e;
                    LoopState.Break();
                }
            });
            if (error != null)
            {
                ExceptionDispatchInfo.Capture(error).Throw();
            }
        }
        protected override object LoopItem(TemplateContext context, LoopState state)
        {
            var localIndex = state.LocalIndex;

            var columnIndex = localIndex % _columnsCount;

            var tableRowLoopState = (TableRowLoopState)state;

            tableRowLoopState.Col      = columnIndex;
            tableRowLoopState.ColFirst = columnIndex == 0;
            tableRowLoopState.ColLast  = ((localIndex + 1) % _columnsCount) == 0;

            if (columnIndex == 0 && localIndex > 0)
            {
                context.Write("</tr>").Write(context.NewLine);
                var rowIndex = (localIndex / _columnsCount) + 1;
                context.Write("<tr class=\"row").Write(rowIndex.ToString(CultureInfo.InvariantCulture)).Write("\">");
            }
            context.Write("<td class=\"col").Write((columnIndex + 1).ToString(CultureInfo.InvariantCulture)).Write("\">");

            var result = base.LoopItem(context, state);

            context.Write("</td>");

            return(result);
        }
Beispiel #16
0
        public void ReadHigh(string FolderPath, string[] StationNumber, string OutputFilePath)//给出大目录和所有站号,求出含有所有站号的文件
        {
            string HighPath = FolderPath;

            string[] dic = new string[] { " " };
            try
            {
                dic = System.IO.Directory.GetDirectories(@HighPath, "high*", SearchOption.AllDirectories);//获取子目录下所有对应的目录
            }
            catch
            {
                //output("error!");
            }
            Parallel.For(0, StationNumber.Count(), (si, LoopState) =>
            {
                if (si >= StationNumber.Count())
                {
                    LoopState.Stop();
                }
                string outfilename = OutputFilePath + @"\" + StationNumber[si] + @"high.txt";

                for (int i = 0; i < dic.Count(); i++)
                {
                    string[] result_line = HighFolder(dic[i], StationNumber[si]);
                    for (int rl = 0; rl < result_line.Count(); rl++)
                    {
                        System.IO.File.AppendAllText(outfilename, result_line[rl], Encoding.GetEncoding("GB2312"));
                    }
                }
            });
        }
Beispiel #17
0
        public override void OnUpdate(LoopState state)
        {
            var inj   = state.Get <Injection>();
            var cache = state.Get <TokenCache>();
            var iter  = inj.Entity.GetEnumerator();

            while (iter.MoveNext())
            {
                var src = iter.Current;

                Token token;
                if (cache.TryGetValue(src.key, out token))
                {
                    inj.Link.Push(new TokenSource {
                        root = token
                    });
                    continue;
                }

                Page page;
                if (!_cache.TryGetPage(cxt.pageIndex, out page))
                {
                    continue;
                }

                inj.Context.Push(new ContextSource {
                    key = cxt.key, body = page.body, count = cxt.count, offset = cxt.offset
                });
            }

            _scheduler.ExecuteFrame(_cache);
        }
Beispiel #18
0
    IEnumerator Start()
    {
        yield return(null);

        stateManager = FindObjectOfType <StateManager>();
        currentState = stateManager.CurrentState;
        ActivateState(currentState);
    }
Beispiel #19
0
        public static IEnumerable <T> Track <T>(this IEnumerator <T> enumerator, IHtmlHelper htmlHelper)
        {
            ContextAccessor = ContextAccessor ?? htmlHelper.ViewContext.HttpContext.RequestServices.GetRequiredService <IHttpContextAccessor>();
            var tracker = new LoopState <T>(CurrentLoop, enumerator);

            CurrentLoop = tracker;
            return(tracker);
        }
        public static IEnumerable <T> Track <T>(this IEnumerator <T> enumerator, IHtmlHelper htmlHelper)
        {
            Context = htmlHelper.ViewContext.HttpContext;
            var tracker = new LoopState <T>(CurrentLoop, enumerator);

            CurrentLoop = tracker;
            return(tracker);
        }
Beispiel #21
0
    public void ExcludeEmptyPaddingLines_whitespace_list()
    {
        var loopState = new LoopState();

        loopState.AppendLine("");
        loopState.AppendLine("  ");
        Approvals.Verify(loopState.GetLines());
    }
Beispiel #22
0
    public void TrimIndentation()
    {
        var loopState = new LoopState();

        loopState.AppendLine("   Line1");
        loopState.AppendLine("    Line2");
        loopState.AppendLine("   Line2");
        Approvals.Verify(loopState.GetLines());
    }
Beispiel #23
0
    public void TrimIndentation_with_mis_match()
    {
        var loopState = new LoopState();

        loopState.AppendLine("      Line2");
        loopState.AppendLine("   ");
        loopState.AppendLine("     Line4");
        Approvals.Verify(loopState.GetLines());
    }
        Snippet BuildSnippet(IndexReader stringReader, string path, LoopState loopState, string language)
        {
            var startRow = loopState.StartLine + 1;

            string error;

            if (isShared && loopState.Version != null)
            {
                return(Snippet.BuildError(
                           error: "Shared snippets cannot contain a version",
                           path: path,
                           lineNumberInError: startRow,
                           key: loopState.Key));
            }
            VersionRange snippetVersion;

            if (!TryParseVersionAndPackage(loopState, out snippetVersion, out error))
            {
                return(Snippet.BuildError(
                           error: error,
                           path: path,
                           lineNumberInError: startRow,
                           key: loopState.Key));
            }
            var value = loopState.GetLines();

            if (value.IndexOfAny(invalidCharacters) > -1)
            {
                var joinedInvalidChars = $@"'{string.Join("', '", invalidCharacters)}'";
                return(Snippet.BuildError(
                           error: $"Snippet contains invalid characters ({joinedInvalidChars}). This was probably caused by copying code from MS Word or Outlook. Dont do that.",
                           path: path,
                           lineNumberInError: startRow,
                           key: loopState.Key));
            }
            if (isShared)
            {
                return(Snippet.BuildShared(
                           startLine: startRow,
                           endLine: stringReader.Index,
                           key: loopState.Key,
                           value: value,
                           path: path,
                           language: language.ToLowerInvariant()));
            }
            return(Snippet.Build(
                       startLine: startRow,
                       endLine: stringReader.Index,
                       key: loopState.Key,
                       version: snippetVersion,
                       value: value,
                       path: path,
                       language: language.ToLowerInvariant(),
                       package: package,
                       isCurrent: isCurrent));
        }
    public static void SetTime(float loopTime, UnityAction unityAction)
    {
        LoopState ls = GetLoopState(unityAction);

        if (ls == null)
        {
            return;
        }
        ls.SetLoopTime(loopTime);
    }
    public static void SetLoopActiveState(bool activateLoop, UnityAction unityAction)
    {
        LoopState ls = GetLoopState(unityAction);

        if (ls == null)
        {
            return;
        }
        ls.SetLoopActiveState(activateLoop);
    }
Beispiel #27
0
    void SetLoopState()
    {
        if (m_CurrentState == null || m_CurrentState == m_DefaultState)
        {
            CurrentLoopState = null;
            return;
        }

        CurrentLoopState = Array.Find(LoopStates, s => s.name == m_CurrentState.name);
    }
 private IEnumerable <T> MakeSources(LoopState state, KeyValuePair <long, T> source)
 {
     for (bool hasMore = true;
          hasMore && !ShouldExitCurrentIteration(source.Key);
          hasMore = _itemQueue.TryTake(out source))
     {
         state.CurrentIndex = source.Key;
         yield return(source.Value);
     }
 }
        private IEnumerable <T> MakeSources(LoopState state, IEnumerator <T> iterator)
        {
            long count = 0;

            do
            {
                state.CurrentIndex = count++;
                yield return(iterator.Current);
            }while (!ShouldExitCurrentIteration(count) && iterator.MoveNext());
        }
Beispiel #30
0
        public static double[,] Subsititution(Data.Condition condition, int dpi, ref int iterate, double omega = 0, double[,] grid = null, double conv = 0)
        {
            if (grid == null)
            {
                grid = new double[condition.X_LMax * dpi, condition.Y_LMax *dpi];
            }

            double[,] temp = new double[condition.X_LMax * dpi, condition.Y_LMax *dpi];
            int cnt = 0;

            Parallel.For(0, iterate, (i, LoopState) =>
            {
                double max = 0;
                for (int x = 1; x + 1 < condition.X_LMax * dpi; x++)
                {
                    for (int y = 1; y + 1 < condition.Y_LMax * dpi; y++)
                    {
                        if (x >= condition.X_Pos * dpi && y >= condition.Y_Pos * dpi)
                        {
                            if (x <= (condition.X_LMax - condition.X_Pos) * dpi && y <= (condition.Y_LMax - condition.Y_Pos) * dpi)
                            {
                                grid[x, y] = 1;
                                continue;
                            }
                        }
                        double data = grid[x, y];
                        if (omega == 0)
                        {
                            temp[x, y] = 0.25 * (grid[x + 1, y] + grid[x - 1, y] + grid[x, y + 1] + grid[x, y - 1]);
                            max        = Math.Abs(data - temp[x, y]) > max ? Math.Abs(data - temp[x, y]) : max;
                            continue;
                        }
                        temp[x, y] = grid[x, y] + omega * (0.25 * (grid[x + 1, y] + grid[x - 1, y] + grid[x, y + 1] + grid[x, y - 1]) - grid[x, y]);
                        max        = Math.Abs(data - temp[x, y]) > max ? Math.Abs(data - temp[x, y]) : max;
                    }
                }
                grid = temp;

                if (conv != 0)
                {
                    if (max < conv)
                    {
                        LoopState.Stop();
                    }
                }
                //cnt = i;
                lock ((object)cnt)
                {
                    cnt++;
                }
            });
            iterate = cnt;
            return(grid);
        }
Beispiel #31
0
        private void DoLoop()
        {
            _state = LoopState.Work;
            if (_started != null)
                _started.Set();
            while (!_isNeedStop)
            {
                if (_isNeedPause)
                {
                    _state = LoopState.Paused;
                    if (_paused != null)
                        _paused.Set();
                    _pausedCancel.WaitOne();
                    _state = LoopState.Work;
                }



                OnLoopIterationEnd(null);
            }
            if (_stoped != null)
                _stoped.Set();
        }
Beispiel #32
0
 public abstract void Loop(global::SnakeGame.Game game, LoopState state);
 static void IsStart(IndexReader stringReader, string trimmedLine, LoopState loopState)
 {
     string version;
     string currentKey;
     if (IsStartCode(trimmedLine, out currentKey, out version))
     {
         loopState.EndFunc = IsEndCode;
         loopState.CurrentKey = currentKey;
         loopState.IsInSnippet = true;
         loopState.Version = version;
         loopState.StartLine = stringReader.Index;
         loopState.SnippetLines = new List<string>();
         return;
     }
     if (IsStartRegion(trimmedLine, out currentKey, out version))
     {
         loopState.EndFunc = IsEndRegion;
         loopState.CurrentKey = currentKey;
         loopState.IsInSnippet = true;
         loopState.Version = version;
         loopState.StartLine = stringReader.Index;
         loopState.SnippetLines = new List<string>();
     }
 }
 void TryAddSnippet(IndexReader stringReader, string file, LoopState loopState, string language, List<ReadSnippetError> errors, List<ReadSnippet> snippets)
 {
     VersionRange parsedVersion;
     var startRow = loopState.StartLine.Value + 1;
     
     if (!TryParseVersion(file, loopState, out parsedVersion))
     {
         errors.Add(new ReadSnippetError(
                                     message : "Could not extract version",
                                     file : file,
                                     line : startRow,
                                     key : loopState.CurrentKey,
                                     version:null));
         return;
     }
     var value = ConvertLinesToValue(loopState.SnippetLines);
     if (value.IndexOfAny(invalidCharacters) > -1)
     {
         var joinedInvalidChars = "'" + string.Join("', '", invalidCharacters) + "'";
         errors.Add(new ReadSnippetError(
             message: $"Snippet contains invalid characters ({joinedInvalidChars}). This was probably caused by you copying code from MS Word or Outlook. Dont do that.",
             file: file,
             line: startRow,
             key: loopState.CurrentKey,
             version: parsedVersion));
     }
     
     var snippet = new ReadSnippet(
                       startLine : startRow,
                       endLine : stringReader.Index,
                       key : loopState.CurrentKey.ToLowerInvariant(),
                       version : parsedVersion,
                       value : value,
                       file : file,
                       language: language.ToLowerInvariant());
     snippets.Add(snippet);
 }
 bool TryParseVersion(string file, LoopState loopState, out VersionRange parsedVersion)
 {
     var stringVersion = loopState.Version;
     if (stringVersion == null)
     {
         parsedVersion = versionFromFilePathExtractor(file);
         if (parsedVersion == null)
         {
             throw new Exception("Null version received from 'versionFromFilePathExtractor'. Did you mean to use 'CaptureSnippets.Version.ExplicitEmpty'.");
         }
         return true;
     }
     return VersionRangeParser.TryParseVersion(stringVersion, out parsedVersion);
 }
        ReadSnippets GetSnippetsFromFile(IndexReader stringReader, string file)
        {
            var errors = new List<ReadSnippetError>();
            var snippets = new List<ReadSnippet>();
            var language = GetLanguageFromFile(file);
            var loopState = new LoopState();
            while (true)
            {
                var line = stringReader.ReadLine();
                if (line == null)
                {
                    if (loopState.IsInSnippet)
                    {
                        errors.Add(new ReadSnippetError(
                            message: "Snippet was not closed",
                            file: file,
                            line: loopState.StartLine.Value + 1,
                            key: loopState.CurrentKey, 
                            version: null));
                    }
                    break;
                }

                var trimmedLine = line.Trim().Replace("  ", " ").ToLowerInvariant();
                if (loopState.IsInSnippet)
                {
                    if (!loopState.EndFunc(trimmedLine))
                    {
                        loopState.SnippetLines.Add(line);
                        continue;
                    }

                    TryAddSnippet(stringReader, file, loopState, language, errors, snippets);
                    loopState.Reset();
                    continue;
                }
                IsStart(stringReader, trimmedLine, loopState);
            }
            return new ReadSnippets(snippets, errors);
        }