Esempio n. 1
0
        /// <summary>
        /// Update proc field to reflect the current active H mode, and point loopProcDelegate to the correct LoopProc method in modes where it exists
        /// </summary>
        private void UpdateProc()
        {
            MethodInfo loopProcInfo;
            Type       procType;

            procType = FindProc();

            if (procType == null && isDarkness)
            {
                procType = FindProcDarkness();
            }

            if (procType == null)
            {
                Destroy(this);
                return;
            }

            if (hCategory != HCategory.maleNotVisible)
            {
                loopProcInfo     = AccessTools.Method(procType, "LoopProc", new Type[] { typeof(bool) });
                loopProcDelegate = (LoopProc)Delegate.CreateDelegate(typeof(LoopProc), proc, loopProcInfo);
            }

            animationName = flags.nowAnimationInfo.nameAnimation;
        }
Esempio n. 2
0
 // Threads loop intervals are interwined with each other
 public static void StartLoopsSync(int loopBegin, int loopEnd, LoopProc proc)
 {
     StartThreads(
         delegate(object arg) {
         ThreadInfo threadInfo = arg as ThreadInfo;
         for (int n = loopBegin + threadInfo.ThreadIndex; n < loopEnd; n += threadInfo.Siblings)
         {
             proc(n);
         }
         threadInfo.Finished();
     }
         );
 }
Esempio n. 3
0
 //
 // This method is intended for parallelize loops with different work-load for each steps,
 // e.g, when calculating an triangle matrix.
 // This method slices the loop range into smaller intervals, so that more physical threads
 // will be working at the same time.
 //
 public static void StartLoopsEx(int loopBegin, int loopEnd, LoopProc proc)
 {
     if (CfgWorkThreads != 1)
     {
         int oldThreads = CfgWorkThreads;
         CfgWorkThreads = 3 * CfgWorkThreads + 3;
         StartLoops(loopBegin, loopEnd, proc);
         CfgWorkThreads = oldThreads;
     }
     else
     {
         StartLoops(loopBegin, loopEnd, proc);
     }
 }
Esempio n. 4
0
 //  Parallelize a for-loop by equally slicing the loop range.
 //  Usage: Replaces "for(int n=s; n<t; n++) ..." by
 //  MultiThreading.StartLoops(s, t, delegate(int n) {
 //     ...
 //  });
 //
 public static void StartLoops(int loopBegin, int loopEnd, LoopProc proc)
 {
     StartThreads(
         delegate(object arg) {
         ThreadInfo threadInfo = arg as ThreadInfo;
         LoopInterval loop     = threadInfo.GetLoopInterval(loopEnd - loopBegin);
         for (int n = loop.Begin; n < loop.End; n++)
         {
             proc(loopBegin + n);
         }
         threadInfo.Finished();
     }
         );
 }