public static int CreateThread(ParameterizedThreadStart pThreadStart, object LoadData)
    {
        ThreadedTask newTask = new ThreadedTask(pThreadStart, LoadData);

        ThreadRunner.AddThread(newTask);
        return(newTask.ManagedThreadId);
    }
예제 #2
0
        /// <summary>
        /// change music to another music track
        /// </summary>
        /// <param name="musicFile">filename of a .wav or .ogg music file to play</param>
        public void Play(string musicFile, double volume, double musicStartTime)
        {
            ITask t = new ThreadedTask(new MusicLoader(this, musicFile, volume, musicStartTime));

            UserWantsMusic = true;
            t.Start();
        }
예제 #3
0
        /// <summary>
        /// called by a child GUI component to launch a game
        /// </summary>
        /// <param name="g">game to launch</param>
        public void ActionLaunchGame(GardenItem g, GameThumbnail thumb)
        {
            if (g.IsInstalled)
            {
                if (g.IsPlayable)
                {
                    // if installed, then launch it if possible
                    if ((launcher == null || launcher.IsFinished() == true) &&
                        (launchGameThread == null || launchGameThread.IsFinished()))
                    {
                        loadingDisplay.SetLoadingGame(g, thumb);
                        // set state of game to 'game playing state'
                        TreeRoot.SetNextState(new StatePlayingGame());

                        launcher         = new GameLauncherTask(g);
                        launchGameThread = new ThreadedTask(launcher);
                        launchGameThread.TaskSuccessEvent += new TaskEventHandler(taskThread_TaskFinishedEvent);
                        launchGameThread.TaskFailEvent    += new TaskEventHandler(taskThread_TaskFinishedEvent);
                        launchGameThread.Start();
                    }
                }
                if (g.IsMusic)
                {
                    music.Play(g.ExeFilepath, 0.5f, 0f);   // TODO vary audio volume per track.
                }
            }
        }
예제 #4
0
        /// <summary>
        /// indicate to game that asap we should clean up and exit, no way back
        /// </summary>
        public void SignalExitGame()
        {
            isExiting = true;
            ITask t = new ThreadedTask(new DownloadsAllPausedTask());

            t.Start();
        }
예제 #5
0
        public void ActionLaunchWebsite(GardenItem g, GameThumbnail thumb)
        {
            ITask t = new ThreadedTask(new SiteLauncherTask(g));

            t.Start();
            loadingDisplay.SetLoadingGame(g, thumb);
            TreeRoot.SetNextState(new StatePlayingGame(2f, false));
        }
예제 #6
0
        protected bool DownloadConfig()
        {
            // download config - if needed or if could not be loaded
            ConfigDownloader dl = new ConfigDownloader(GardenConfig.Instance);

            configDownloadThread = new ThreadedTask(dl);
            if (dl.IsDownloadNeeded())
            {
                // start the task
                configDownloadThread.Start();

                // then wait for a short while until success of the task thread
                long timer = 0;
                long blockingWaitPeriodTicks = System.TimeSpan.TicksPerSecond * 0;  // TODO const in config
                if (!GardenConfig.Instance.IsValid())
                {
                    blockingWaitPeriodTicks = System.TimeSpan.TicksPerSecond * 30;  // TODO const in config
                }
                if (blockingWaitPeriodTicks > 0)
                {
                    while (configDownloadThread.Status() == ITaskStatus.CREATED)
                    {
                        // block until in RUNNING state
                    }
                    while (configDownloadThread.Status() == ITaskStatus.RUNNING && timer < blockingWaitPeriodTicks)
                    {
                        Thread.Sleep(100);
                        timer += (System.TimeSpan.TicksPerMillisecond * 100);
                    }

                    switch (dl.Status())
                    {
                    case ITaskStatus.SUCCESS:
                        GardenConfig.Instance = dl.NewConfig;
                        break;

                    case ITaskStatus.FAIL:
                        initError = new Exception(dl.StatusMsg());
                        break;

                    case ITaskStatus.CREATED:
                    case ITaskStatus.RUNNING:
                        // let the downloading simply finish in the background. Load it another time.
                        break;
                    }
                }
            }

            // if still not ok after attempted download, warn the user and exit
            // a missing config counts as a valid one (then uses default params to create a new config)
            if (!GardenConfig.Instance.IsValid())
            {
                IsMouseVisible = true;
                MsgBox.Show("Could not load configuration", "Could not load configuration file. Is it missing or corrupted?");
                return(false);
            }
            return(true);
        }
 public static void AddThread(ThreadedTask t)
 {
     // Debug.Log("[THREADRUNNER] Enrolled thread and prepared storage, for ID # " + t.ManagedThreadId);
     mThreadStack.Add(t.ManagedThreadId, t);
     mThreadData.Add(t.ManagedThreadId, null);
 }
예제 #8
0
        /*
         * static void ReportErrorHttpPost(Exception ex)
         * {
         *  string u = "http://indieget.appspot.com/errPost" ;
         *  string payload = ex + "\n" + ex.TargetSite + "\n" + ex.StackTrace;
         *  HttpPost.HttpPostText(u,payload);
         * }
         */

        static void ReportErrorOverNetwork(Exception ex)
        {
            ITask t = new ThreadedTask(new ReportErrorOverNetworkTask(ex));

            t.Start();
        }
예제 #9
0
        /// <summary>
        /// Creates the data for this conditions spectrum for this time value.
        /// </summary>
        public override void Run(WaveSpectrumCondition condition, float time)
        {
            //Can only run if all tasks have finished.
            if (!IsDone())
            {
                throw new InvalidOperationException("Can not run when there are tasks that have not finished");
            }

            TimeValue   = time;
            HasRun      = true;
            BeenSampled = false;

            //All tasks done, clear and create new ones.
            m_fourierTasks.Clear();

            //If no buffers are enabled nothing to do.
            if (EnabledBuffers() == 0)
            {
                return;
            }

            //Create the Initialization task.
            //This is created by the superclass
            //to the m_initTask object.
            Initilize(condition, time);

            ThreadedTask initTask = m_initTask as ThreadedTask;

            if (initTask == null)
            {
                throw new InvalidCastException("Init spectrum task is not a threaded task");
            }

            //Must run init task first if mutithreading disabled
            if (Ocean.DISABLE_FOURIER_MULTITHREADING)
            {
                //Multithreading disabled, run now on this thread.
                initTask.Start();
                initTask.Run();
                initTask.End();
            }

            int numBuffers = m_buffers.Length;

            //float t = Time.realtimeSinceStartup;

            //for each buffer run a fourier task.
            for (int i = 0; i < numBuffers; i++)
            {
                if (m_buffers[i].disabled)
                {
                    continue;
                }

                FourierTask task = new FourierTask(this, m_fourier, i, m_initTask.NumGrids);

                if (Ocean.DISABLE_FOURIER_MULTITHREADING)
                {
                    //Multithreading disabled, run now on this thread.
                    task.Start();
                    task.Run();
                    task.End();
                }
                else
                {
                    //Multithreading enabled, run now on another thread.

                    //If init task has not finished yet the
                    //fourier task must wait on it to finish.
                    task.RunOnStopWaiting = true;
                    task.WaitOn(initTask);
                    m_scheduler.AddWaiting(task);
                }

                m_fourierTasks.Add(task);
            }

            //Debug.Log("Run Fourier time = " + (Time.realtimeSinceStartup - t) * 1000.0f + " tasks = " + m_fourierTasks.Count);

            //Must run init task last if mutithreading not disabled
            if (!Ocean.DISABLE_FOURIER_MULTITHREADING)
            {
                //Must run init task after tasks the are waiting
                //have been added. Otherwise init task may finish
                //before there other tasks have been added and a
                //exception will be thrown.
                initTask.NoFinish = true;
                m_scheduler.Run(initTask);
            }
        }