Example #1
0
        /// <summary>
        /// Invokes a method call in the OpenGL thread.
        /// </summary>
        /// <param name="routine"></param>
        public static void Invoke(DeferredRoutine routine)
        {
            // Don't make warning "Obsolete"
#pragma warning disable 618
            Game.Current.InvokeOpenGL(routine);
#pragma warning restore 618
        }
Example #2
0
 public void InvokeOpenGL(DeferredRoutine routine)
 {
     if (routine == null)
     {
         return;
     }
     if (Thread.CurrentThread == this.drawThread)
     {
         routine();
     }
     else
     {
         this.DeferRoutine(true, routine).WaitOne();
     }
 }
Example #3
0
 /// <summary>
 /// Deferres a routine into the OpenAL thread and waits for the execution.
 /// </summary>
 /// <param name="routine">The routine to be deferred.</param>
 public void InvokeOpenAL(DeferredRoutine routine)
 {
     if (routine == null)
     {
         return;
     }
     if (Thread.CurrentThread == this.soundThread)
     {
         routine();
     }
     else
     {
         var handler = new DeferredRoutineHandler()
         {
             Routine        = routine,
             WaitHandle     = new ManualResetEvent(false),
             CreatingMethod = new StackTrace().GetFrame(1).GetMethod()
         };
         this.deferredALRoutines.Enqueue(handler);
         handler.WaitHandle.WaitOne();
     }
 }
Example #4
0
        /// <summary>
        /// Deferres a routine into another thread so the current thread can continue.
        /// </summary>
        /// <remarks>Useful for loading assets or resources.</remarks>
        /// <param name="openGL">Defines if the routine is deferred into the OpenGL thread or not.</param>
        /// <param name="routine">The routine to be deferred.</param>
        public WaitHandle DeferRoutine(bool openGL, DeferredRoutine routine)
        {
            if (routine == null)
            {
                return(null);
            }
            var handler = new DeferredRoutineHandler()
            {
                Routine    = routine,
                WaitHandle = new ManualResetEvent(false)
            };

            if (openGL)
            {
                this.deferredGLRoutines.Enqueue(handler);
            }
            else
            {
                this.deferredRoutines.Enqueue(handler);
            }
            return(handler.WaitHandle);
        }
 public NextUpdateCall(Action a)
 {
     _Routine = (b) => { a(); return true; };
 }
 public NextUpdateCall(DeferredRoutine callMethod)
 {
     _Routine = callMethod;
 }
Example #7
0
 /// <summary>
 /// Deferres a routine into another thread so the current thread can continue.
 /// </summary>
 /// <remarks>Useful for loading assets or resources.</remarks>
 /// <param name="routine">The routine to be deferred.</param>
 public WaitHandle DeferRoutine(DeferredRoutine routine)
 {
     return(this.DeferRoutine(false, routine));
 }