コード例 #1
0
        public void Update()
        {
            List <ThreadedJob> toRemove = new List <ThreadedJob>();

            foreach (ThreadedJob thread in RunningThreads)
            {
                thread.Update();
                if (thread.IsDone)
                {
                    toRemove.Add(thread);
                }
            }
            foreach (ThreadedJob thread in toRemove)
            {
                RunningThreads.Remove(thread);
            }

            lock (AccessToThreadQueue)
            {
                int newThreads = MaximumThreads - RunningThreads.Count;
                for (int i = 0; i < newThreads && ThreadQueue.Count != 0; i++)
                {
                    ThreadedJob thread = ThreadQueue.Dequeue();
                    RunningThreads.Add(thread);
                    thread.Start();
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Check and manage any chunk generation jobs in the queue
 /// </summary>
 void checkGenerateJobQueue()
 {
     if (genJobQueue.Count > 0 && genJobCount < MAX_GEN_JOB_COUNT)
     {
         genJobCount++;
         ThreadedJob jobToStart = genJobQueue[0];
         genJobQueue.RemoveAt(0);
         genRunningJobs.Add(jobToStart);
         jobToStart.Start();
     }
     if (genRunningJobs.Count != 0)
     {
         genRunningJobs.RemoveAll((ThreadedJob runningJob) => {
             if (runningJob != null && runningJob.Update())
             {
                 genJobCount--;
                 return(true);
             }
             else
             {
                 return(false);
             }
         });
     }
 }
コード例 #3
0
ファイル: ThreadManager.cs プロジェクト: nolimet/RandomStuff
 /// <summary>
 /// Adds a job to jobList
 /// </summary>
 /// <param name="j">Job to done by the thread</param>
 /// <returns>Key that can be used to track the job</returns>
 public static string addJob(ThreadedJob j)
 {
     string key = RandomString(8);
     jobs.Add(key, j);
     jobIndex++;
     return key;
 }
コード例 #4
0
 public void Enqueue(ThreadedJob thread)
 {
     lock (AccessToThreadQueue)
     {
         ThreadQueue.Enqueue(thread);
     }
 }
コード例 #5
0
    // Use this for initialization
    static void Start()
    {
        // if watch, connect to server
        network = new ThreadedJob();
        network.Start();

        // constant frame rate to avoid rendering side effects
        //Application.targetFrameRate = 60;
    }
コード例 #6
0
 public void Tick()
 {
     if (thisJob != null)
     {
         if (thisJob.IsDone)
         {
             thisJob = null;
             done = true;
         }
     }
 }
コード例 #7
0
 public void Tick()
 {
     if (thisJob != null)
     {
         if (thisJob.IsDone)
         {
             thisJob = null;
             done    = true;
         }
     }
 }
コード例 #8
0
    public override void Update()
    {
        if (!isOpen)
        {
            canvasGroup.alpha          = 0;
            canvasGroup.blocksRaycasts = canvasGroup.interactable = false;
        }

        if (texPath != null)
        {
            viewingPanel.GetComponentInChildren <Text>().text = "Processing LaTeX ...";
            nextID  = qManager.getNextID();
            imgPath = imagesDirPath + "/question_" + nextID + ".png";

            if (System.IO.File.Exists(errorLogPath))
            {
                System.IO.File.Delete(errorLogPath);
            }

            if (System.IO.File.Exists(outputLogPath))
            {
                System.IO.File.Delete(outputLogPath);
            }

            texJob          = new ThreadedJob();
            texJob.nextID   = nextID;
            texJob.texPath  = texPath;
            texJob.imgPath  = imgPath;
            texJob.workPath = workPath;
            texJob.Start();
            texPath = null;

            vpCanvasGroup.alpha        = 1;
            canvasGroup.alpha          = 1;
            canvasGroup.blocksRaycasts = canvasGroup.interactable = true;
        }

        if (texJob != null)
        {
            if (texJob.Update() && !loadingOn)
            {
                string wwwURL = "file:///" + imgPath;
                StartCoroutine(loadImage(wwwURL));
                loadingOn = true;
            }
        }
    }
コード例 #9
0
    public void FindAllLinkableCharacter(List <List <GameObject> > tiles)
    {
        if (!showHints)
        {
            return;
        }

        List <List <string> > characters = new List <List <string> >();

        for (int i = 0; i < tiles.Count; i++)
        {
            characters.Add(new List <string>());
            for (int j = 0; j < tiles[i].Count; j++)
            {
                if (tiles[i][j] == null)
                {
                    characters[i].Add("");
                }
                else
                {
                    characters[i].Add(tiles[i][j].GetComponent <TileBehaviour>().character);
                }
            }
        }

        ThreadedJob job = new ThreadedJob();

        job.threadFunctions.Add(() => {
            job.args["list_of_linkables"] = trie.FindAllLinkableCharacters(characters);
        });
        job.onFinish.Add(() => {
            print("finished");
            TileManager.GetInstance().ClearHints();
            foreach (LinkableCharacter linkable in (List <LinkableCharacter>)job.args["list_of_linkables"])
            {
                print(linkable.row + " " + linkable.col + ": " + linkable.word);
                tiles[linkable.row][linkable.col].GetComponent <TileBehaviour>().isHint = true;
            }
        });

        job.Start();
        StartCoroutine(job.WaitFor());
    }
コード例 #10
0
    private void resetUI()
    {
        canvas.GetComponent <MenuMan>().ShowMenu(qMenu);
        vpCanvasGroup.alpha = 0;
        viewingPanel.transform.GetChild(0).gameObject.GetComponent <RawImage> ().texture = null;
        texJob    = null;
        displayOn = false;
        loadingOn = false;

        Slider diffSlider = GetComponentInChildren <Slider> ();

        InputField[] ifsQuestion = GetComponentsInChildren <InputField> ();
        diffSlider.value = 0;
        diffSlider.transform.parent.GetComponentInChildren <Text>().text = "Low";
        ifsQuestion[0].text = "";
        ifsQuestion[1].text = "";
        ifsQuestion[2].text = "";
        ifsQuestion[3].text = "";
        errorMan.remError();
    }
コード例 #11
0
        private void Update()
        {
            if (_MyJob != null)
            {
                if (_MyJob.Update())
                {
                    UnityEngine.Debug.Log("Job done");
                    _MyJob = null;
                }
            }

            if (_GetMusics != null)
            {
                if (_GetMusics.Update())
                {
                    UnityEngine.Debug.Log("Job done");
                    _GetMusics = null;
                }
            }

            RenderSettings.haloStrength = GetIntensity();

            if (Input.GetKeyDown(KeyCode.Space))
            {
                _ShowNavigator = !_ShowNavigator;
            }

            if (_CurrentStreamTime != 0)
            {
                _CurrentTime += Time.deltaTime;
                if (_CurrentTime >= _CurrentStreamTime)
                {
                    StartMusic(null);
                }
            }
        }
コード例 #12
0
 public static void AddJob(ThreadedJob job)
 {
     inst.JobsToComplete.Add(job);
     inst.JobsToComplete.Sort();
 }
コード例 #13
0
 public void Init(ThreadedJob job)
 {
     // Don't touch any data in the job class after initialization until IsDone is true.
     thisJob = job;
 }
コード例 #14
0
 public void Init(ThreadedJob job)
 {
     // Don't touch any data in the job class after initialization until IsDone is true.
     thisJob = job;
 }