Пример #1
0
 /// <summary>
 /// 为当前场景注册信号调度服务
 /// </summary>
 /// <param name="semaphoreName">信号名</param>
 /// <param name="activator">激活函数</param>
 /// <param name="deactivator">反激活函数</param>
 /// <param name="tag">信号附加值</param>
 /// <param name="groupName">信号分组名</param>
 /// <param name="isRebinding">是否为重绑定</param>
 public static void RegisterSemaphoreService(string semaphoreName, SceneFunction activator, SceneFunction deactivator, object tag = null, string groupName = "", bool isRebinding = false)
 {
     lock (SemaphoreDispatcher.syncMutex)
     {
         semaphoreName = semaphoreName.ToUpper();
         if (SemaphoreDispatcher.semaphoreDict.ContainsKey(semaphoreName) == false)
         {
             LogUtils.LogLine("semaphore not exist for binding to " + activator?.GlobalName + ", " + deactivator?.GlobalName,
                              "SemaphoreDispatcher", LogLevel.Error);
             return;
         }
         var hdObject = new SemaphoreHandler(groupName, tag)
         {
             ActivateFunc   = activator,
             DeActivateFunc = deactivator,
             Type           = SemaphoreHandlerType.ScheduleOnce
         };
         SemaphoreDispatcher.semaphoreDict[semaphoreName].Attach(hdObject);
         SemaphoreDispatcher.handlerList.Add(new KeyValuePair <string, SemaphoreHandler>(semaphoreName, hdObject));
         if (isRebinding == false)
         {
             if (Director.RunMana.SemaphoreBindings.ContainsKey(semaphoreName) == false)
             {
                 Director.RunMana.SemaphoreBindings[semaphoreName] = new List <Tuple <string, string> >();
             }
             Director.RunMana.SemaphoreBindings[semaphoreName].Add(new Tuple <string, string>(
                                                                       activator?.Callname, deactivator?.Callname));
         }
     }
 }
Пример #2
0
        /// <summary>
        /// 调度一个信号处理机
        /// </summary>
        /// <param name="selphine">信号量</param>
        /// <param name="shandler">处理机</param>
        public static void Schedule(YuriSemaphore selphine, SemaphoreHandler shandler)
        {
            if (!SemaphoreDispatcher.EnableDispatcher)
            {
                return;
            }
            switch (shandler.Type)
            {
            case SemaphoreHandlerType.ScheduleOnce:
                var handleFunc = selphine.Activated ? shandler.ActivateFunc : shandler.DeActivateFunc;
                if (handleFunc == null)
                {
                    return;
                }
                ParallelExecutor pExec = new ParallelExecutor()
                {
                    Scenario = handleFunc.ParentSceneName
                };
                DispatcherTimer dt = new DispatcherTimer
                {
                    Interval = TimeSpan.FromTicks((long)GlobalConfigContext.DirectorTimerInterval)
                };
                dt.Tick         += Director.RunMana.ParallelHandler;
                pExec.Dispatcher = dt;
                var pvm = new StackMachine();
                pvm.SetMachineName("SemaphoreVM#" + handleFunc.GlobalName);
                pvm.Submit(handleFunc, new List <object>());
                pExec.Executor = pvm;
                ParallelDispatcherArgsPackage pdap = new ParallelDispatcherArgsPackage()
                {
                    Index          = -1,
                    Render         = new UpdateRender(pvm),
                    BindingSF      = handleFunc,
                    IsSemaphore    = true,
                    SemaphoreStack = pvm
                };
                dt.Tag = pdap;
                shandler.Dispatcher = dt;
                dt.Start();
                break;

            case SemaphoreHandlerType.ScheduleForever:
                throw new NotImplementedException();

            case SemaphoreHandlerType.ScheduleWhenActivated:
                throw new NotImplementedException();
            }
        }
Пример #3
0
 /// <summary>
 /// 注册全局信号调度服务,它不会被存档所保存,必须在游戏开头做绑定动作
 /// </summary>
 /// <param name="semaphoreName">信号名</param>
 /// <param name="activator">激活函数</param>
 /// <param name="deactivator">反激活函数</param>
 /// <param name="tag">信号附加值</param>
 /// <param name="groupName">信号分组名</param>
 public static void RegisterGlobalSemaphoreService(string semaphoreName, SceneFunction activator, SceneFunction deactivator, object tag = null, string groupName = "")
 {
     lock (SemaphoreDispatcher.syncMutex)
     {
         semaphoreName = semaphoreName.ToUpper();
         if (SemaphoreDispatcher.semaphoreDict.ContainsKey(semaphoreName) == false)
         {
             LogUtils.LogLine("global semaphore not exist for binding to " + activator?.GlobalName + ", " + deactivator?.GlobalName,
                              "SemaphoreDispatcher", LogLevel.Error);
             return;
         }
         var hdObject = new SemaphoreHandler(groupName, tag)
         {
             ActivateFunc   = activator,
             DeActivateFunc = deactivator,
             Type           = SemaphoreHandlerType.ScheduleOnce,
             IsGlobal       = true
         };
         SemaphoreDispatcher.semaphoreDict[semaphoreName].Attach(hdObject);
         SemaphoreDispatcher.globalHandlerList.Add(new KeyValuePair <string, SemaphoreHandler>(semaphoreName, hdObject));
     }
 }