Browse Source

加地标和地质断层更新代码,修正升级后loction_card未初始化情况

liulei 5 years ago
parent
commit
c457253941
7 changed files with 43 additions and 70 deletions
  1. 1 1
      area.cpp
  2. 0 1
      card_base.cpp
  3. 2 14
      his_location.cpp
  4. 0 2
      his_location.h
  5. 32 45
      landmark.cpp
  6. 7 6
      landmark.h
  7. 1 1
      module_service/module_meta_date_changed.cpp

+ 1 - 1
area.cpp

@@ -729,7 +729,7 @@ void area_tool::set_area_info(int mapid,double scale,int areaid,const point &pt,
 
 void area_tool::set_area_info(int mapid,int areaid,const point &pt,uint64_t t)
 {
-	auto lm = Landmark_list::instance()->get(mapid,areaid,pt);
+	auto lm = Landmark_list::instance()->get_landmark(mapid,areaid,pt);
 	int landmark_id = std::get<0>(lm);
 	int landmark_dir = std::get<1>(lm);
 	double landmark_dis = std::get<2>(lm)*m_scale;

+ 0 - 1
card_base.cpp

@@ -128,7 +128,6 @@ void card_location_base::on_message(zloop<task*> * loop,const message_locinfo&lo
 	{
         log_info("%d被井上分站[%d]收到",m_id,site_ptr->id());
 		area_tool->on_point(shared_from_this(),point(1,1));
-		m_his_location_card->deal_up_well();
 		this->site_hover(loc.m_site_id);
 	}
 	else

+ 2 - 14
his_location.cpp

@@ -149,6 +149,7 @@ void location_card::push(uint64_t timestamp,const point & p,int32_t areaid,int32
     if (bclose) //卡移除后直接更新his_location
     {
         update(p,timestamp);
+		init();
         return;
     }
     if(m_p.empty() || m_timestamp==0||m_areaid<0||m_mapid<0)
@@ -305,17 +306,4 @@ bool location_card::handle_path(std::vector<point> &rc,uint64_t timestamp,bool f
         flag=true;
     }
     return false;
-}
-
-void location_card::deal_up_well()
-{
-	//更新location
-	if (m_d.size()>0)
-	{
-		last_timestamp = 0;
-		update(m_d.back().p, m_d.back().time);
-	}
-	
-	//重置参数
-	init();
-}
+}

+ 0 - 2
his_location.h

@@ -67,7 +67,5 @@ struct location_card
 	bool  handle_message(const point &p,uint64_t timestamp);
     // 处理获取到点的集合,在路径上
     bool handle_path(std::vector<point> &rc,uint64_t timestamp,bool flag);
-	//升井后处理
-	void deal_up_well();
 };
 #endif

+ 32 - 45
landmark.cpp

@@ -4,11 +4,11 @@
 #include "log.h"
 
 
-Landmark_list * Landmark_list::instance()
-{
-	static Landmark_list  lm_list;
-	return &lm_list;
-}
+//Landmark_list * Landmark_list::instance()
+//{
+//	static Landmark_list  lm_list;
+//	return &lm_list;
+//}
 void Landmark_list::init_mapDirection()
 {
 	const char * sql = "select map_direction_id, map_id, north_angle from dat_map_direction;";
@@ -29,7 +29,7 @@ void Landmark_list::init_mapDirection()
 			DBRes.GetField( "north_angle",north_angle, Error );
 
 			std::shared_ptr<map_direction> md = std::make_shared<map_direction>(map_id,north_angle);
-			m_map.insert({map_id,md});
+			m_map_direction.insert({map_id,md});
 			log_info("map_direction.....mapid:%d,north:%d",map_id,north_angle);
 		}
 	}
@@ -55,11 +55,11 @@ void Landmark_list::init_landmarkInfo(int id/*=-1*/)
 	YADB::CDBResultSet DBRes;
 	sDBConnPool.Query(sql.c_str(),DBRes,Error);
 	int nCount = DBRes.GetRecordCount( Error );
-	std::lock_guard<std::mutex> lock(m_mutex);
+	
 	if (nCount > 0)
 	{
 		log_info( "init_landmark_info. The record count=%d\n", nCount );
-
+		std::unordered_map<int, std::shared_ptr<LandmarkInfo>> map;
 		while ( DBRes.GetNextRecod(Error) )
 		{
 			int landmark_id  = 0;
@@ -85,63 +85,49 @@ void Landmark_list::init_landmarkInfo(int id/*=-1*/)
 			point p(x,y,z);
 			std::shared_ptr<LandmarkInfo> landmark = std::make_shared<LandmarkInfo>(p, landmark_id, name, map_id, area_id);
 			if (-1 == id)
-			{				
-				m_v.push_back(landmark);
+			{	
+				map.insert(std::make_pair(landmark_id, landmark));
+				//m_v.push_back(landmark);
 				log_info("landmark ......id:%d,name:%s,mapid:%d,area_id:%d,x:%.2f,y:%.2f,z:%.2f", landmark_id, name.c_str(), map_id, area_id, x, y, z);
 			}
 			else
 			{
-				bool befind = false;
-				for (size_t i = 0; i < m_v.size(); i++)
+				auto markptr = Landmark_list::instance()->get(landmark_id);
+				if (markptr != nullptr)
 				{
-					if (m_v[i]->landmark_id==id)
-					{
-						m_v[i]->set(p);
-						m_v[i]->landmark_id = landmark_id;
-						m_v[i]->landmark_name = name;
-						m_v[i]->map_id = map_id;
-						m_v[i]->area_id = area_id;
-						befind = true;
-						log_info("update landmark ......id:%d,name:%s,mapid:%d,area_id:%d,x:%.2f,y:%.2f,z:%.2f", landmark_id, name.c_str(), map_id, area_id, x, y, z);
-						break;
-					}
+					markptr->set(p);
+					markptr->landmark_id = landmark_id;
+					markptr->landmark_name = name;
+					markptr->map_id = map_id;
+					markptr->area_id = area_id;
+					log_info("update landmark ......id:%d,name:%s,mapid:%d,area_id:%d,x:%.2f,y:%.2f,z:%.2f", landmark_id, name.c_str(), map_id, area_id, x, y, z);
 				}
-				if (!befind)
+				else
 				{
 					log_info("add landmark ......id:%d,name:%s,mapid:%d,area_id:%d,x:%.2f,y:%.2f,z:%.2f", landmark_id, name.c_str(), map_id, area_id, x, y, z);
-					m_v.push_back(landmark);
+					Landmark_list::instance()->add(landmark_id, landmark);
 				}
 				break;
 			}
 		}
-	}
-
-}
-
-void Landmark_list::remove_landmarkInfo(int id)
-{
-	std::lock_guard<std::mutex> lock(m_mutex);
-	std::vector<std::shared_ptr<LandmarkInfo>>::iterator it_s = m_v.begin();
-	while (it_s!= m_v.end())
-	{
-		if ((*it_s)->landmark_id == id)
+		if (-1== id)
 		{
-			m_v.erase(it_s);
-			log_info("delete landmark ......id:%d,name:%s", (*it_s)->landmark_id, (*it_s)->landmark_name);
-			break;
+			Landmark_list::instance()->add(map);
 		}
-		it_s++;
 	}
+
 }
 
-std::tuple<int,int,double> Landmark_list::get(int mapid ,int areaid,const point &pt)
+std::tuple<int,int,double> Landmark_list::get_landmark(int mapid ,int areaid,const point &pt)
 {
 	int32_t id = -1;
 	double dis = DBL_MAX;
 	point p;
-	std::lock_guard<std::mutex> lock(m_mutex);
-	for(const auto &lm : m_v)	
+	auto m_v = Landmark_list::instance()->m_map;
+	auto it_s = m_v.begin();
+	while(it_s!=m_v.end())	
 	{
+		auto lm = it_s->second;
 		if(lm->area_id == areaid)
 		{
 			double tmp = pt.dist(*lm);
@@ -152,6 +138,7 @@ std::tuple<int,int,double> Landmark_list::get(int mapid ,int areaid,const point
 				p=*lm;
 			}
 		}
+		it_s++;
 	}
 	if(id==-1)
 	  return std::make_tuple(0,0,0);
@@ -173,8 +160,8 @@ DIRECTION_TYPE Landmark_list::GetDirectionType(point card_point, point landmark_
 		y_offset = 0;
 
 	std::shared_ptr<map_direction> pMapDirectoryInfo = nullptr;
-	auto it = m_map.find(map_id);		
-	if(it == m_map.end())
+	auto it = m_map_direction.find(map_id);
+	if(it == m_map_direction.end())
 	{
 		return NODIRECTORY;
 	}

+ 7 - 6
landmark.h

@@ -6,6 +6,7 @@
 #include <map>
 #include <memory>
 #include <tuple>
+#include "write-copy.h"
 #include "point.h"
 enum DIRECTION_TYPE{
 	NODIRECTORY = 0,
@@ -43,17 +44,17 @@ struct map_direction
 	int map_id;
 	int north_angle;
 };
-struct Landmark_list
+struct Landmark_list:single_base<Landmark_list, int, std::shared_ptr<LandmarkInfo>>
 {
-	std::vector<std::shared_ptr<LandmarkInfo>> m_v;
-	std::map<int,std::shared_ptr<map_direction>> m_map;
-	static Landmark_list * instance();
+	//std::vector<std::shared_ptr<LandmarkInfo>> m_v;
+	std::map<int,std::shared_ptr<map_direction>> m_map_direction;
+	//static Landmark_list * instance();
 	void init_from_db();
 	void init_landmarkInfo(int id = -1);
-	void remove_landmarkInfo(int id);
+	
 	void init_mapDirection();
 	//landmarkId landmark_direction  landmark_dis
-	std::tuple<int,int,double> get(int mapid,int areaid,const point &pt);
+	std::tuple<int,int,double> get_landmark(int mapid,int areaid,const point &pt);
 	DIRECTION_TYPE GetDirectionType(point card_point, point landmark_point, int map_id);
 	std::mutex m_mutex;
 };

+ 1 - 1
module_service/module_meta_date_changed.cpp

@@ -326,7 +326,7 @@ void module_meta_date_changed::deal_call_edit_landmark(const std::string & landm
 	}
 	else if (ET_DELETE == edit_type_id)
 	{
-		Landmark_list::instance()->remove_landmarkInfo(id);
+		Landmark_list::instance()->remove(id);
 	}
 }