private bool IsAllreadyCollide(ISpaceObject hiter, ISpaceObject dest) { foreach (ISpaceObject collide_obj in hiter.GetCollideObjects()) { if (collide_obj.GetID() == dest.GetID() && collide_obj.GetObjType() == dest.GetObjType()) { return(true); } } return(false); }
/** * collide module 心跳tick, 处理相关计算 */ public void Tick() { // 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(); 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>(); } //构造空间索引 if (obj_list.Count > 0) { m_KdTree.Build(obj_list); } else { m_KdTree.Clear(); } bool isCountTick = false; long curTime = TimeUtility.GetServerMilliseconds(); if (m_LastCountTime + c_CountInterval < curTime) { m_LastCountTime = curTime; isCountTick = true; } int userCt = 0; int npcCt = 0; int bulletCt = 0; foreach (ISpaceObject hiter in obj_list) { if (isCountTick) { switch (hiter.GetObjType()) { case SpatialObjType.kUser: ++userCt; break; case SpatialObjType.kNPC: ++npcCt; break; case SpatialObjType.kBullet: ++bulletCt; 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); * } * });*/ } if (isCountTick) { LogSystem.Debug("SpatialSystem object count:{0} user:{1} npc:{2} bullet:{3}", obj_list.Count, userCt, npcCt, bulletCt); } }