protected override bool ExecCommand(StoryInstance instance, StoryValueParam <int> _params, long delta)
        {
            int  time      = _params.Param1Value;
            long startTime = TimeUtility.GetElapsedTimeUs();

            while (startTime + time > TimeUtility.GetElapsedTimeUs())
            {
            }
            return(false);
        }
 public void Start()
 {
     startTicks = TimeUtility.GetElapsedTimeUs();
 }
Example #3
0
        /**
         * collide module 心跳tick, 处理相关计算
         */
        public void Tick()
        {
            long t1 = TimeUtility.GetElapsedTimeUs();

            // remove objects in delete buffer
            foreach (KeyValuePair <uint, ISpaceObject> pair in delete_obj_buffer_)
            {
                // 删除与当前物体碰撞的物体信息
                ISpaceObject obj2 = pair.Value;
                foreach (ISpaceObject spaceobj in obj2.GetCollideObjects())
                {
                    spaceobj.OnDepartObject(obj2);
                }
                obj2.GetCollideObjects().Clear();
                space_obj_collection_dict_.Remove(pair.Key);
            }
            delete_obj_buffer_.Clear();

            // add new obj
            foreach (KeyValuePair <uint, ISpaceObject> pair in add_obj_buffer_)
            {
                if (!space_obj_collection_dict_.ContainsKey(pair.Key))
                {
                    space_obj_collection_dict_.Add(pair.Key, pair.Value);
                }
            }
            add_obj_buffer_.Clear();

            long t2 = TimeUtility.GetElapsedTimeUs();

            IList <ISpaceObject> obj_list = null;

            if (space_obj_collection_dict_.Count > 0)
            {
                ISpaceObject[] temp = new ISpaceObject[space_obj_collection_dict_.Count];
                space_obj_collection_dict_.Values.CopyTo(temp, 0);
                obj_list = temp;
            }
            else
            {
                obj_list = new List <ISpaceObject>();
            }

            long t3 = TimeUtility.GetElapsedTimeUs();

            //构造空间索引
            if (obj_list.Count > 0)
            {
                m_KdTree.Build(obj_list);
            }
            else
            {
                m_KdTree.Clear();
            }

            long t4 = TimeUtility.GetElapsedTimeUs();

            bool isCountTick = false;
            long curTime     = TimeUtility.GetServerMilliseconds();

            if (m_LastCountTime + c_CountInterval < curTime)
            {
                m_LastCountTime = curTime;
                isCountTick     = true;
            }
            int userCt = 0;
            int npcCt  = 0;

            foreach (ISpaceObject hiter in obj_list)
            {
                if (isCountTick)
                {
                    switch (hiter.GetObjType())
                    {
                    case SpatialObjType.kUser:
                        ++userCt;
                        break;

                    case SpatialObjType.kNPC:
                        ++npcCt;
                        break;
                    }
                }

                /*m_KdTree.Query(hiter, (float)hiter.GetRadius(), (float distSqr, KdTreeObject obj) => {
                 * ISpaceObject dest = obj.SpaceObject;
                 * if (null != dest && IsPassableCollide(hiter, dest)) {
                 *  CheckCollide(hiter, dest);
                 * }
                 * });*/
            }

            long t5 = TimeUtility.GetElapsedTimeUs();

            if (isCountTick && !GlobalVariables.Instance.IsClient)
            {
                LogSystem.Debug("SpatialSystem object count:{0} user:{1} npc:{2} [time] add/remove {3} copy {4} kdtree {5} stat {6}", obj_list.Count, userCt, npcCt, t2 - t1, t3 - t2, t4 - t3, t5 - t4);
            }
            else if (t5 - t1 > 20000)
            {
                LogSystem.Debug("SpatialSystem object count:{0} [time] add/remove {1} copy {2} kdtree {3} stat {4}", obj_list.Count, t2 - t1, t3 - t2, t4 - t3, t5 - t4);
            }
        }
        private void IOHandler()
        {
            while (m_Status == RoomSrvStatus.STATUS_RUNNING)
            {
                try {
                    m_NetServer.MessageReceivedEvent.WaitOne(1000);
                    long startTime = TimeUtility.GetElapsedTimeUs();
                    NetIncomingMessage im;
                    for (int ct = 0; ct < 1024; ++ct)
                    {
                        try {
                            if ((im = m_NetServer.ReadMessage()) != null)
                            {
                                switch (im.MessageType)
                                {
                                case NetIncomingMessageType.DebugMessage:
                                case NetIncomingMessageType.VerboseDebugMessage:
                                    LogSys.Log(LOG_TYPE.DEBUG, "Debug Message: {0}", im.ReadString());
                                    break;

                                case NetIncomingMessageType.ErrorMessage:
                                    LogSys.Log(LOG_TYPE.DEBUG, "Error Message: {0}", im.ReadString());
                                    break;

                                case NetIncomingMessageType.WarningMessage:
                                    LogSys.Log(LOG_TYPE.DEBUG, "Warning Message: {0}", im.ReadString());
                                    break;

                                case NetIncomingMessageType.StatusChanged:
                                    NetConnectionStatus status = (NetConnectionStatus)im.ReadByte();
                                    string reason = im.ReadString();
                                    if (null != im.SenderConnection)
                                    {
                                        RoomPeer peer = RoomPeerMgr.Instance.GetPeerByConnection(im.SenderConnection);
                                        if (null != peer)
                                        {
                                            LogSys.Log(LOG_TYPE.DEBUG, "Network Status Changed: {0} reason:{1} EndPoint:{2} Key:{3} User:{4}\nStatistic:{5}", status, reason, im.SenderEndPoint.ToString(), peer.GetKey(), peer.Guid, im.SenderConnection.Statistics.ToString());
                                        }
                                        else
                                        {
                                            LogSys.Log(LOG_TYPE.DEBUG, "Network Status Changed: {0} reason:{1} EndPoint:{2}\nStatistic:{3}", status, reason, im.SenderEndPoint.ToString(), im.SenderConnection.Statistics.ToString());
                                        }
                                    }
                                    else
                                    {
                                        LogSys.Log(LOG_TYPE.DEBUG, "Network Status Changed:{0} reason:{1}", status, reason);
                                    }
                                    break;

                                case NetIncomingMessageType.Data:
                                    int    id   = 0;
                                    object msg  = null;
                                    byte[] data = null;
                                    try {
                                        data = im.ReadBytes(im.LengthBytes);
                                        msg  = Serialize.Decode(data, out id);
                                    } catch {
                                        if (null != im.SenderConnection)
                                        {
                                            RoomPeer peer = RoomPeerMgr.Instance.GetPeerByConnection(im.SenderConnection);
                                            if (null != peer)
                                            {
                                                LogSys.Log(LOG_TYPE.WARN, "room server decode message error !!! from User:{0}({1})", peer.Guid, peer.GetKey());
                                            }
                                        }
                                    }
                                    if (msg != null)
                                    {
                                        m_Dispatch.Dispatch(id, msg, im.SenderConnection);
                                    }
                                    else
                                    {
                                        if (null != im.SenderConnection)
                                        {
                                            RoomPeer peer = RoomPeerMgr.Instance.GetPeerByConnection(im.SenderConnection);
                                            if (null != peer)
                                            {
                                                LogSys.Log(LOG_TYPE.DEBUG, "got unknow message !!! from User:{0}({1})", peer.Guid, peer.GetKey());
                                            }
                                            else
                                            {
                                                LogSys.Log(LOG_TYPE.DEBUG, "got unknow message !!!");
                                            }
                                        }
                                        else
                                        {
                                            LogSys.Log(LOG_TYPE.DEBUG, "got unknow message !!!");
                                        }
                                    }
                                    break;

                                default:
                                    break;
                                }
                                m_NetServer.Recycle(im);
                            }
                            else
                            {
                                break;
                            }
                        } catch (Exception ex) {
                            LogSys.Log(LOG_TYPE.ERROR, "Exception {0}\n{1}", ex.Message, ex.StackTrace);
                        }
                    }
                    RoomPeerMgr.Instance.Tick();
                    long endTime = TimeUtility.GetElapsedTimeUs();
                    if (endTime - startTime >= 10000)
                    {
                        LogSys.Log(LOG_TYPE.DEBUG, "Warning, IOHandler() cost {0} us !\nNetPeer Statistic:{1}", endTime - startTime, m_NetServer.Statistics.ToString());
                    }
                } catch (Exception ex) {
                    LogSys.Log(LOG_TYPE.ERROR, "Exception {0}\n{1}", ex.Message, ex.StackTrace);
                }

                Thread.Sleep(10);
            }
        }
Example #5
0
 private static long GetTime()
 {
     return(TimeUtility.GetElapsedTimeUs());
 }