示例#1
0
 ///------------
 public void Dispose()
 {
     Disconnect();
     _heartBeatTimer.Stop();
     TimerMgr.RemoveTimer(_heartBeatTimer);
     _heartBeatTimer = null;
 }
示例#2
0
 void OnEnable()
 {
     TimerMgr.addSecHandler(Mathf.CeilToInt(lifetime), null, (val) =>
     {
         PoolMgr.Instance.recyleObj(this.gameObject);
     });
 }
示例#3
0
 void Start()
 {
     m_timerInfo           = new TimerInfo();
     m_timerInfo.ClassName = typeof(NetWorkManager).ToString();
     m_timerInfo.Target    = this;
     TimerMgr.AddTimerEvent(m_timerInfo);
 }
示例#4
0
    public HttpLoader(HttpRequest.Handler dataHandler      = null
                      , HttpRequest.Handler errorHandler   = null
                      , HttpRequest.Handler timeoutHandler = null
                      , int nMaxParallelRequest            = 3
                      , float pollInterval = 0.2f)
    {
        _nMaxParallelRequest = nMaxParallelRequest;

        DataHandler    = _dataHandler;
        ErrorHandler   = _errorHandler;
        TimeoutHandler = _timeoutHandler;

        if (dataHandler != null)
        {
            DataHandler = dataHandler;
        }
        if (errorHandler != null)
        {
            ErrorHandler = errorHandler;
        }
        if (timeoutHandler != null)
        {
            TimeoutHandler = timeoutHandler;
        }

        _aliveRequests = new HashSet <HttpRequest>();
        _timer         = TimerMgr.REPEAT(MathEx.INFINITE, pollInterval, _onPollRequest);

        _queuedRequests = new LinkedList <HttpRequest>();

        __deadList           = new QuickList <HttpRequest>();
        __nAliveRequestCount = 0;
    }
示例#5
0
 public static TimerMgr GetInstance()
 {
     if (Instance == null)
     {
         Instance = new TimerMgr();
     }
     return(Instance);
 }
示例#6
0
 public void _Clear()
 {
     if (_timer != null)
     {
         TimerMgr.RemoveTimer(_timer);
         _timer = null;
     }
 }
示例#7
0
 override protected void _onRelease()
 {
     if (_timer != null)
     {
         TimerMgr.RemoveTimer(_timer);
         _timer = null;
     }
 }
示例#8
0
    void Awake()
    {
        _inst = this;
        DontDestroyOnLoad(gameObject);

        _timerList   = new List <TimerElement>();
        _elementPool = new Stack <TimerElement>();
    }
示例#9
0
 private void InitTimer()
 {
     System.Timers.Timer timer = new System.Timers.Timer(50);
     timer.Elapsed += new System.Timers.ElapsedEventHandler((sender, e) => {
         TimerMgr.GetInstance().Update(50);
     });
     timer.AutoReset = true;
     timer.Enabled   = true;
 }
示例#10
0
 public void Copy(string name, TIMER_MODE mode, float startTime, float duration, TimerManagerHandler handler, TimerMgr manager)
 {
     m_Name        = name;
     m_Mode        = mode;
     m_StartTime   = startTime;
     this.Duration = duration;
     m_TimerEvent  = handler;
     m_Manger      = manager;
 }
示例#11
0
 /// Note: This doesn't ensure the remote server don't receives RPC call, but only ensure the caller don't
 /// receives RPC callback.
 public void Cancel()
 {
     if (_timer != null)
     {
         TimerMgr.RemoveTimer(_timer);
         _timer = null;
     }
     _netRPCComponent._CancelRPCCall(this);
 }
示例#12
0
    // Use this for initialization
    void Awake()
    {
        if (TimerMgr.Instance != null && TimerMgr.Instance != this)
        {
            UnityEngine.Object.Destroy(this);
            return;
        }

        _Instance = this;
    }
示例#13
0
 void Start()
 {
     FrameMgr.GetInstance();
     TimerMgr.GetInstance();
     PathMgr.GetInstance();
     ConfigMgr.GetInstance();
     AssetMgr.GetInstance();
     UIMgr.GetInstance();
     SoundMgr.GetInstance();
     LoadSceneMgr.LoadSence("test");
 }
示例#14
0
 public void Copy(string name, TIMER_MODE mode, float startTime, float duration, TimerManagerHandlerArgs handler, int times, TimerMgr manager, params object[] args)
 {
     m_Name           = name;
     m_Mode           = mode;
     m_StartTime      = startTime;
     this.Duration    = duration;
     m_TimerArgsEvent = handler;
     m_Manger         = manager;
     m_Args           = args;
     m_Times          = times;
 }
示例#15
0
    public void Reconnect()
    {
        this.AddState(RoutePlayerState.CONNECTED);
        TimerMgr.GetInstance().DelTimer(this.LogoutTimerId);

        //重连时发送断线期间的信息
        for (int i = 0; i < this.MsgCache.Count; i++)
        {
            this.SendMsg(this.MsgCache[i]);
        }
    }
示例#16
0
        public override void execute(short cmd, short ErrCode, byte[] payloads)
        {
            base.execute(cmd, ErrCode, payloads);
                        #if PROTOBUFF
            #region ######
            TimerMgr.Register("delayHeartBeat", 15f, () => {
                DebugTool.LogRed("发送心跳包");
                //              var mydata = GameProxy.mine;
                //              msg.PlayerInfo playerinfo = new msg.PlayerInfo ();
                //              playerinfo.FrameIndex = 0;
                //              playerinfo.Level = mydata.level;
                //              playerinfo.Userid = mydata.userid;
                //              playerinfo.Nickname = mydata.nickname;
                //              playerinfo.SpawnPos = mydata.spawnPos;//TODO 处理拉回
                Netmanager.sendHeartBeating();
            });
            #endregion


            try {
                var data       = getData <msg.Rspn_HeartBeating> ();
                var statusCode = data.Status;
                // List<msg.PlayerInfo> playerList = data.PlayerList;
                // 暂不使用心跳把拉回坐标 2019.3.26 facade.DispatchEvent (new CEvent (Event_Player.SyncPos_HeartBeat.ToString (), new object[]{ playerList }));

                DebugTool.LogRed(string.Format("收到服务器返回 心跳包:<<<<<<<<<  statusCode :{0}", statusCode));
            } catch (Exception ex) {
                DebugTool.LogError(ex.Message);
            }
//			TimerMgr.Register ("delayHeartBeat", 15f, () => {
//				DebugTool.LogRed ("发送心跳包");
//				msg.PlayerInfo playerinfo = new msg.PlayerInfo();
//				playerinfo.FrameIndex = 0 ;
//				playerinfo.Level =
//				Netmanager.sendHeartBeating (playerinfo);
//			});
                        #else
            foreach (var item in payloads)
            {
                DebugTool.LogYellow(item);
            }
            getData();

            var statusCode = ReadInt();

            DebugTool.LogRed(string.Format("收到服务器返回 心跳包:<<<<<<<<<  statusCode :{0}", statusCode));
            TimerMgr.Register("delayHeartBeat", 15f, () => {
                DebugTool.LogRed("发送心跳包");
                Netmanager.sendHeartBeating();
            });
                        #endif

//			facade.DispatchEvent (new CEvent (Event_Player.New_player.ToString (), new object[]{ data }));
        }
示例#17
0
 public void initialize()
 {
     //检测一次时间池子
     TimerMgr.addEveryMillHandler(checkUseTime, 60000);
     //TimerMgr.addSecHandler(1, null, (count) =>
     //{
     //    disposeAll();
     //    Debug.LogWarning("CS Pool释放所有清理完成");
     //    AssetMgr.clearAll();
     //    Debug.LogWarning("CS AssetMgr.clearAll()清理完成");
     //}, 30);
     //TimerMgr.addEveryMillHandler((count)=> { AssetMgr.clearAll(); },150000 );
 }
示例#18
0
    void Update()
    {
        if (Input.GetKeyUp(KeyCode.A))
        {
            Debug.LogError("启动计时器");
            TimerMgr.GetIns().StartTimer(1f, Callback, 2, null, "test1");
        }

        if (Input.GetKeyUp(KeyCode.B))
        {
            Debug.LogError("停止计时器");
            TimerMgr.GetIns().StopTimer("test1");
        }
    }
示例#19
0
        public UnitySocket()
        {
            OnSocketDataArrival  = UnPacket;
            OnSocketDisconnected = OnSocketDisconnectedHandler;

            reconnect_Lock = false;
            queue_cmd      = new Queue <short> ();
            queue_ret      = new Queue <short> ();
            queue_payloads = new Queue <byte[]> ();
            queue_LogError = new Queue <string> ();
            InitTimer();
            TimerMgr.UpdateTime("socketRuning" + UnityEngine.Random.Range(0f, 1f), () => {
                Updated();
            });
        }
示例#20
0
    public void Disconnect()
    {
        this.CancelState(RoutePlayerState.CONNECTED);

        //3分钟重连时间
        this.LogoutTimerId = TimerMgr.GetInstance().AddTimer(3 * 60 * 1000, data =>
        {
            this.Logout();
        }, null);

        RSPlayerDisconnect protocol = new RSPlayerDisconnect();

        protocol.PlayerId = this.PlayerId;
        Server.GetInstance().SendMsgToAllServer(protocol);
    }
示例#21
0
        public _RPCRetHandler(_NetRPCComponent rpcComponent
                              , NetRPCCall message
                              , long timeoutTime
                              , Action <_NetRPCReturn, Exception> callback)
        {
            _netRPCComponent = rpcComponent;
            _CallMessage     = message;
            _bIsDone         = false;

            _timer = TimerMgr.AddTimer();
            _timer.Handler(_onTimeout);
            _timer.Interval(timeoutTime).Start();

            _OnCallback = callback;
            _error      = null;
        }
示例#22
0
    /// <summary>
    /// 系统提示
    /// </summary>
    /// <param name="sentence"></param>
    public void TipsShow(string sentence)
    {
        parent.SetAsLastSibling();
        var go = GameObject.Instantiate(tips);

        existedTips.Add(go);
        go.SetParent(parent, false);
        var text = go.GetComponent <Text>();

        text.text = sentence;
        go.gameObject.SetActive(true);

        TimerMgr.getMe().CreateTimer(TimeCallBack, 3);
        text.DOFade(0, 3);
        go.DOMove(Vector3.up * posY, 3).SetEase(Ease.InOutCubic).SetRelative();
    }
示例#23
0
        void StartMonsterCreateDone()
        {
            TimerMgr.AddTimer("Monster Create", 2, delegate()
            {
                if (mNpcs.Count == 0)
                {
                    var spawnPoint = ConfigMgr.MonsterSpawnPoints;
                    var list       = spawnPoint.ToList();
                    var index      = AppUtil.Random(0, list.Count);

                    var npcid     = DateTime.UtcNow.Ticks;
                    var view      = new NPCView(npcid, NpcType.Monster);
                    view.position = list[index].Value;
                    mNpcs.Add(npcid, view);

                    Log.Info("Check Monster OnScene Count:>" + mNpcs.Count);
                }
            });
        }
示例#24
0
        /// <summary>
        ///     主循环
        /// </summary>
        public void Run()
        {
            _watch.Start();

            while (!_quit)
            {
                // 1、 定时器调度
                TimerMgr.Update(ElapsedMilliseconds);

                // 2、 协程调度
                CoroutineScheduler.Ins.Update();

                // 3、 job调度
                var enterTime = ElapsedMilliseconds;
                do
                {
                    try {
                        IJob item;
                        if (_workingQueue.TryTake(out item, Period))
                        {
                            item.Do();
                        }
                        else
                        {
                            break;
                        }
                    }
                    catch (Exception ex) {
                        Logger.Ins.Fatal("{0} : {1}", ex.Message, ex.StackTrace);
                    }
                } while (ElapsedMilliseconds - enterTime < Period);
            }

            IJob leftItem;

            while (_workingQueue.TryTake(out leftItem, Period * 10))
            {
                leftItem.Do();
            }

            _watch.Stop();
        }
示例#25
0
        protected virtual void Updated()  //TODO xx
        {
            if (toReconnect)              //连接成功
            {
                toReconnect = false;
                queue_LogError.Enqueue(Enum_NetEvent.WifiOff.ToString());
            }


            while (queue_cmd.Count > 0)              //此处必需在主线程中运行,否则报错 e.g.:: get_realtimeSinceStartup can only be called from the main thread.
            {
                DebugTool.LogYellow("[TCP] [rcv] | queue_cmd.Count : " + queue_cmd.Count);
                short cmd = queue_cmd.Dequeue();
                DebugTool.LogYellow("[TCP] [rcv] cmd:::::::::: " + cmd + " | queue_cmd.Count remain : " + queue_cmd.Count);
                queue_LogError.Enqueue("[TCP] [rcv] cmd:::::::::: " + cmd + " | queue_cmd.Count remain : " + queue_cmd.Count);
                CreateMessage(cmd);                  // cmd short -> int
            }

            //
            if (queue_LogError.Count > 0)
            {
                string log = queue_LogError.Dequeue();
                // DebugTool.Log (">>>>>>>>>> " + log); xxx 暂时去掉,以便调试UDP
                if (log == Enum_NetEvent.WifiOff.ToString())
                {
                    TimerMgr.HeartBeatStop();
                    Facade_Base.instance.DispatchEvent(new CEvent(Enum_NetEvent.WifiOff.ToString(), null)); // 显示出WIFI标识
                    Socket_Create_Connection();                                                             //重新创建连接
                }
                else if (log == Enum_NetEvent.WifiOn.ToString())
                {
                    //					    TimerMgr.HeartBeatStart ();
                    Facade_Base.instance.DispatchEvent(new CEvent(Enum_NetEvent.WifiOn.ToString(), null));
                }
                else if (log == Enum_Base.SocketClosed.ToString())
                {
                    LoginInfo.LoginState = false;
                    Facade_Base.instance.DispatchEvent(new CEvent(Enum_Base.SocketClosed.ToString(), null));
                }
            }
        }
示例#26
0
    public ConnectionOld(IConnectionHost pConnectionHost = null)
    {
        _connectionState = ConnectionState.DISCONNECTED;

        _tcpClient = null;

        __bIsReceivingHeader = true;
        __bInWriting         = false;

        _networkStream = null;

        _sessionKey          = null;
        _encryptedSessionKey = null;

        __receiveBuffer  = new byte[RECEIVE_BUFFER_SIZE];
        __nBytesReceived = 0;

        __sendMsgQueue    = new Queue <MsgBase>();
        __receiveMsgQueue = new QuickList <MsgBase>();

        __lock = new object();

        _pAESMgr = new RijndaelManaged();

        _heartBeatTimer = TimerMgr.AddTimer();
        _heartBeatTimer.LoopCount(MathEx.INFINITE).Interval(HEART_BEAT_INTERVAL).Handler(_onHeartBeat);

        _bInUpdateSessionKey = false;
        _nLastSvrTime        = 0;
        _nLastLocalTime      = 0;
        __nMsgLength         = 0;

        if (pConnectionHost != null)
        {
            _pConnectionHost = pConnectionHost;
        }
        else
        {
            _pConnectionHost = new _DefaultConnectionHost();
        }
    }
示例#27
0
    void Start()
    {
        GameObject.DontDestroyOnLoad(this.gameObject);
        //CS init
        TimerMgr.Initilize();              //计时器
        AtlasMgr.Instance.initialize();    //图集管理器初始化
        ResMgr.Instance.initialize();      //资源接口管理类初始化
        ManifestMgr.Instance.initialize(); //依赖文件初始化
        PoolMgr.Instance.initialize();     //对象池初始化
        LoaderMgr.Instance.initialize();   //加载管理器初始化
        UIMgr.Instance.initialize();       //画布初始化 不需要初始化

        //Lua init
        luaAgent = new LuaEnv();                //全局lua代理
        luaAgent.DoString("require 'LuaInit'"); //Lua初始化 在Lua那边

        scriptEnv = luaAgent.NewTable();
        LuaTable meta = luaAgent.NewTable();

        meta.Set("__index", luaAgent.Global);
        scriptEnv.SetMetaTable(meta);
        meta.Dispose();
        scriptEnv.Set("self", this);
        foreach (var injection in injections)
        {
            scriptEnv.Set(injection.name, injection.value);
        }
        luaAgent.DoString("require 'LuaBehavior'", "LuaBehaviour", scriptEnv);
        // Action luaAwake = scriptEnv.Get<Action>("awake");
        scriptEnv.Get("start", out luaStart);
        scriptEnv.Get("update", out luaUpdate);
        scriptEnv.Get("onTick", out luaTick);
        scriptEnv.Get("ondestroy", out luaOnDestroy);

        if (luaStart != null)
        {
            luaStart();
        }
        // initClock();
    }
        /// <summary>
        /// 设置目标
        /// </summary>
        /// <param name="targetPoint"> 目标点</param>
        /// <param name="callback">目的地到达回调</param>
        /// <param name="moveAfterturn">true: 先转向再移动向目标,false: 转向与移动同时发生,易小转弯时转圈</param>
        /// <param name="toAutoToward">true: 到达目的地后,自动转向 预设方向</param>
        /// <param name="_direction">预设方向</param>
        public void SetTarget(Vector3 targetPoint, Action callback, bool moveAfterturn = false, bool toAutoToward = false, TowardDirection _direction = TowardDirection.South)         //float speed = 0f, Action callback = null)
        {
            if (targetPoint == Vector3.zero)
            {
                return;
            }
            if (_targetPoint != targetPoint)
            {
                forceStop         = false;
                lockOnece         = true;
                arrived           = false;
                _isMovingTarget   = !moveAfterturn;
                this._targetPoint = targetPoint;
                this.toAutoToward = toAutoToward;
                this._endCallback = callback;
                this.Direction    = _direction;
                TimerMgr.UnRegister("delayTurnAnim");
            }


            //        this.Forward = speed;
        }
示例#29
0
 static public void Initilize()
 {
     if (_instance != null)
     {
         return;
     }
     if (_instance == null)
     {
         GameObject obj = GameObject.Find(Tag);
         if (obj == null)
         {
             obj      = new GameObject();
             obj.name = Tag;
         }
         _instance = obj.GetComponent <TimerMgr>();
         if (_instance == null)
         {
             _instance = obj.AddComponent <TimerMgr>();
         }
         _instance.init();
         GameObject.DontDestroyOnLoad(obj);
     }
 }
示例#30
0
        public void _HandleRPCReturn(_NetRPCReturn retMsg, Exception exception)
        {
            if (_timer != null)
            {
                _timer.Stop();
                TimerMgr.RemoveTimer(_timer);
                _timer = null;
            }

            _bIsDone       = true;
            _RetrunMessage = retMsg;

            _error = exception;

            if (_OnCallback != null)
            {
                _OnCallback(retMsg, exception);
            }
            else
            {
                /// Should never go here
                Debugger.Assert(false);
            }
        }
示例#31
0
 private void TimerCallBacktHandler(TimerMgr.TimerItem item)
 {
     this.NextFrame();
 }