|
@@ -4,6 +4,7 @@
|
|
|
#include "log.h"
|
|
|
|
|
|
#include <area.h>
|
|
|
+#include "worker.h"
|
|
|
#include "point.h"
|
|
|
#include "tool_time.h"
|
|
|
#include "common_tool.h"
|
|
@@ -81,9 +82,35 @@ area::area(int id,int limit_count_person, int limit_time_person,double scale,int
|
|
|
m_event_vehicle_count = false;
|
|
|
m_event_person_show_count = false;
|
|
|
m_event_vehicle_show_count = false;
|
|
|
+
|
|
|
+ m_frozen_count.store(0);
|
|
|
}
|
|
|
|
|
|
|
|
|
+void area::change_business(uint32_t new_bits)
|
|
|
+{
|
|
|
+ worker*w=worker::instance();
|
|
|
+
|
|
|
+ uint32_t del=((m_area_type^new_bits)|m_area_type)^m_area_type;
|
|
|
+ uint32_t add=((m_area_type^new_bits)|new_bits)^new_bits;
|
|
|
+
|
|
|
+ task*t =task::alloc<message_change_business>();
|
|
|
+
|
|
|
+ t->m_cmd_code=0x10001; //区域业务类型修改的编码
|
|
|
+ t->m_hash_id=0; //这个不用
|
|
|
+
|
|
|
+ auto&mcb=t->body<message_change_business>();
|
|
|
+ mcb.area_id=m_id;
|
|
|
+ mcb.del_list=area_business::get_instance_list(del,m_id);
|
|
|
+ mcb.add_list=area_business::get_instance_list(add,m_id);
|
|
|
+ mcb.new_list=area_business::get_instance_list(new_bits,m_id);
|
|
|
+ mcb.ref_count.store(w->num_thread());
|
|
|
+
|
|
|
+ add_frozen_count(w->num_thread()+1);
|
|
|
+
|
|
|
+ w->broadcast(t);
|
|
|
+}
|
|
|
+
|
|
|
void area::on_hover(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c)
|
|
|
{
|
|
|
a->m_last_time=tool_time::now_to_ms();
|
|
@@ -389,15 +416,19 @@ void area_list::init_from_db(int id/*=-1*/)
|
|
|
else
|
|
|
{
|
|
|
auto tmp_ptr = area_list::instance()->get(id);
|
|
|
+ bool newobj=false;
|
|
|
+
|
|
|
if(!tmp_ptr)
|
|
|
{
|
|
|
tmp_ptr = create(area_type_id,area_id,over_count_person,over_time_person, scale,map_id,b_type);
|
|
|
- area_list::instance()->add(id, tmp_ptr);
|
|
|
+ newobj=true;
|
|
|
}
|
|
|
+
|
|
|
tmp_ptr->update(over_count_person, over_time_person,scale,map_id,area_type_id, over_count_vehicle,over_time_vehicle);
|
|
|
tmp_ptr->m_speed=std::move(map_);
|
|
|
tmp_ptr->m_bound=init_path(path,area_id);
|
|
|
tmp_ptr->m_is_work_area = is_work_area;
|
|
|
+
|
|
|
for(const auto &p : tmp_ptr->m_bound)
|
|
|
log_info("point:area_id:%d--x:%.2f,y:%.2f",area_id,p.x,p.y);
|
|
|
|
|
@@ -405,6 +436,15 @@ void area_list::init_from_db(int id/*=-1*/)
|
|
|
,area_type_id:%d,over_count_vehicle:%d,over_time_vehicle:%d",
|
|
|
id,over_count_person, over_time_person,scale,map_id,area_type_id,
|
|
|
over_count_vehicle,over_time_vehicle);
|
|
|
+
|
|
|
+ if(newobj)
|
|
|
+ {
|
|
|
+ area_list::instance()->add(id, tmp_ptr);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ tmp_ptr->change_business(b_type);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -481,9 +521,11 @@ void area_tool::on_point(const std::shared_ptr<card_location_base>& c,const poin
|
|
|
areas.push_back(area_);
|
|
|
}
|
|
|
else
|
|
|
+ {
|
|
|
std::sort(areas.begin(),areas.end(),[](const std::shared_ptr<area>&l,const std::shared_ptr<area>&r){
|
|
|
return l->id()<r->id();
|
|
|
});
|
|
|
+ }
|
|
|
|
|
|
auto c1=m_hover_list.begin(),ce=m_hover_list.end();
|
|
|
auto a1=areas.begin() ,ae=areas.end();
|
|
@@ -492,35 +534,72 @@ void area_tool::on_point(const std::shared_ptr<card_location_base>& c,const poin
|
|
|
|
|
|
while (c1!=ce && a1!=ae)
|
|
|
{
|
|
|
- if ((*c1)->id()<(*a1)->id())
|
|
|
+ if ((*c1)->id()<(*a1)->id()) //离开区域
|
|
|
{
|
|
|
- (*c1)->m_area->on_leave(*c1, c);
|
|
|
+ if((*c1)->m_area->get_frozen_count()==0)//如果该区域未在修改中,调用on_leave
|
|
|
+ {
|
|
|
+ (*c1)->m_area->on_leave(*c1, c);
|
|
|
+ }
|
|
|
+ else//否则,该区域持续保存在卡的区域列表,等待修改完成
|
|
|
+ {
|
|
|
+ nlist.push_back(*c1);
|
|
|
+ log_warn("丢弃离开区域事件,cardid=%d,area_id=%d",c->m_id,(*c1)->id());
|
|
|
+ }
|
|
|
++c1;
|
|
|
}
|
|
|
- else if ((*a1)->id()<(*c1)->id())
|
|
|
+ else if ((*a1)->id()<(*c1)->id()) //进入新区域
|
|
|
{
|
|
|
- nlist.push_back(std::make_shared<area_hover>(*a1,pt));
|
|
|
- (*a1)->on_enter(nlist.back(),c);
|
|
|
+ if((*a1)->get_frozen_count()==0)////如果该区域未在修改中,执行正常逻辑
|
|
|
+ {
|
|
|
+ nlist.push_back(std::make_shared<area_hover>(*a1,pt));
|
|
|
+ (*a1)->on_enter(nlist.back(),c);
|
|
|
+ }
|
|
|
+ else//丢弃本次进入的点,等待修改完成
|
|
|
+ {
|
|
|
+ log_warn("丢弃进入区域事件,cardid=%d,area_id=%d",c->m_id,(*a1)->id());
|
|
|
+ }
|
|
|
++a1;
|
|
|
}
|
|
|
- else
|
|
|
+ else //需要持续的区域
|
|
|
{
|
|
|
nlist.push_back(*c1);
|
|
|
- (*c1)->m_area->on_hover(*c1,c);
|
|
|
+ if((*c1)->m_area->get_frozen_count()==0)//正常情况
|
|
|
+ {
|
|
|
+ (*c1)->m_area->on_hover(*c1,c);
|
|
|
+ }
|
|
|
+ else//丢弃本次on_hover时间
|
|
|
+ {
|
|
|
+ log_warn("丢弃区域行走事件,cardid=%d,area_id=%d",c->m_id,(*c1)->id());
|
|
|
+ }
|
|
|
++c1,++a1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
while(c1!=ce)
|
|
|
{
|
|
|
- (*c1)->m_area->on_leave(*c1, c);
|
|
|
+ if((*c1)->m_area->get_frozen_count()==0)
|
|
|
+ {
|
|
|
+ (*c1)->m_area->on_leave(*c1, c);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ log_warn("丢弃离开区域事件,cardid=%d,area_id=%d",c->m_id,(*c1)->id());
|
|
|
+ }
|
|
|
++c1;
|
|
|
}
|
|
|
|
|
|
while(a1!=ae)
|
|
|
{
|
|
|
- nlist.push_back(std::make_shared<area_hover>(*a1,pt));
|
|
|
- (*a1)->on_enter(nlist.back(),c);
|
|
|
+ if((*a1)->get_frozen_count()==0)
|
|
|
+ {
|
|
|
+ nlist.push_back(std::make_shared<area_hover>(*a1,pt));
|
|
|
+ (*a1)->on_enter(nlist.back(),c);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ log_warn("丢弃进入区域事件,cardid=%d,area_id=%d",c->m_id,(*a1)->id());
|
|
|
+ }
|
|
|
+
|
|
|
++a1;
|
|
|
}
|
|
|
|
|
@@ -577,6 +656,7 @@ void area_tool::set_area_info(int mapid,double scale,int areaid,const point &pt,
|
|
|
log_info("wrong type..");
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
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);
|
|
@@ -588,3 +668,30 @@ void area_tool::set_area_info(int mapid,int areaid,const point &pt,uint64_t t)
|
|
|
m_area_info[areaid].swap(tinfo);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+void area_tool::on_change_business(const std::shared_ptr<card_location_base>& c, const task&t)
|
|
|
+{
|
|
|
+ auto&mcb=t.body<message_change_business>();
|
|
|
+
|
|
|
+ auto i=std::lower_bound(m_hover_list.begin(),m_hover_list.end(),mcb.area_id ,[&mcb](std::shared_ptr<area_hover>&ah,int id){
|
|
|
+ return ah->m_area->m_id<id;
|
|
|
+ });
|
|
|
+
|
|
|
+ if(i==m_hover_list.end())
|
|
|
+ return ;
|
|
|
+
|
|
|
+ if((*i)->m_area->m_id!=mcb.area_id)
|
|
|
+ return;
|
|
|
+
|
|
|
+ log_info("调用调整的区域业务,card_id=%d,area_id=%d", c->m_id, mcb.area_id);
|
|
|
+ for(auto&biz:mcb.add_list)
|
|
|
+ {
|
|
|
+ biz->on_enter(*i,c,(*i)->get_business_data(biz->area_business_type()));
|
|
|
+ }
|
|
|
+
|
|
|
+ for(auto&biz:mcb.del_list)
|
|
|
+ {
|
|
|
+ biz->on_leave(*i,c,(*i)->get_business_data(biz->area_business_type()));
|
|
|
+ }
|
|
|
+}
|
|
|
+
|