|
@@ -0,0 +1,160 @@
|
|
|
+#ifndef _AREA_HPP_
|
|
|
+#define _AREA_HPP_
|
|
|
+
|
|
|
+#include <atomic>
|
|
|
+#include <algorithm>
|
|
|
+#include <iterator>
|
|
|
+#include <point.h>
|
|
|
+
|
|
|
+#include <write-copy.h>
|
|
|
+
|
|
|
+struct area_hover;
|
|
|
+struct point;
|
|
|
+struct area
|
|
|
+{
|
|
|
+ area()
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ virtual void on_hover(int card_id,std::shared_ptr<area_hover>&c,double speed)=0;
|
|
|
+ virtual void on_enter(int card_id,std::shared_ptr<area_hover>&c,double speed)=0;
|
|
|
+ virtual void on_leave(int card_id,std::shared_ptr<area_hover>&c,double speed)=0;
|
|
|
+
|
|
|
+ int id()const
|
|
|
+ {
|
|
|
+ return m_id;
|
|
|
+ }
|
|
|
+
|
|
|
+ std::atomic<int> m_card_count;
|
|
|
+
|
|
|
+ int m_id;
|
|
|
+ double m_limit_speed;
|
|
|
+
|
|
|
+// std::string m_name;
|
|
|
+// int m_limit_time_second;
|
|
|
+// int m_limit_person_count;
|
|
|
+// int m_area_type;
|
|
|
+
|
|
|
+ std::vector<point> m_bound;
|
|
|
+};
|
|
|
+
|
|
|
+struct area_list:single_base<area_list,int,std::shared_ptr<area>>
|
|
|
+{
|
|
|
+ area_list();
|
|
|
+
|
|
|
+ std::vector<std::shared_ptr<area>> get_area(const point&pt);
|
|
|
+ static void init_from_db()
|
|
|
+ {
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+struct area_hover
|
|
|
+{
|
|
|
+ std::shared_ptr<area> m_area;
|
|
|
+ time_t m_enter_time,m_last_time;
|
|
|
+ point m_enter_point,m_last_point;
|
|
|
+ int m_num_speeding;
|
|
|
+
|
|
|
+ area_hover(std::shared_ptr<area>&area,const point&pt,double speed)
|
|
|
+ :m_area(area)
|
|
|
+ {
|
|
|
+ m_enter_time=m_last_time=time(0);
|
|
|
+ m_enter_point=m_last_point=pt;
|
|
|
+ m_num_speeding=0;
|
|
|
+ if(speed>m_area->m_limit_speed)
|
|
|
+ m_num_speeding++;
|
|
|
+ }
|
|
|
+
|
|
|
+ int id()const
|
|
|
+ {
|
|
|
+ return m_area->id();
|
|
|
+ }
|
|
|
+
|
|
|
+ bool operator == (const area_hover&o)const
|
|
|
+ {
|
|
|
+ return m_area->id()==o.m_area->id();
|
|
|
+ }
|
|
|
+
|
|
|
+ bool operator < (const area_hover&o)const
|
|
|
+ {
|
|
|
+ return m_area->id()<o.m_area->id();
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+struct area_tool
|
|
|
+{
|
|
|
+ std::vector<std::shared_ptr<area_hover>> m_clist;
|
|
|
+ void on_point(int card_id,const point&pt,double speed)
|
|
|
+ {
|
|
|
+ std::vector<std::shared_ptr<area>> areas=area_list::instance()->get_area(pt);//找出所有的区域
|
|
|
+ std::sort(areas.begin(),areas.end(),[](std::shared_ptr<area>&l,std::shared_ptr<area>&r){
|
|
|
+ return l->id()<r->id();
|
|
|
+ });
|
|
|
+
|
|
|
+ auto c1=m_clist.begin(),ce=m_clist.end();
|
|
|
+ auto a1=areas.begin() ,ae=areas.end();
|
|
|
+
|
|
|
+ std::vector<std::shared_ptr<area_hover>> nlist;
|
|
|
+
|
|
|
+ while (c1!=ce && a1!=ae)
|
|
|
+ {
|
|
|
+ if ((*c1)->id()<(*a1)->id())
|
|
|
+ {
|
|
|
+ do_leave_biz(card_id,*c1,speed);
|
|
|
+ ++c1;
|
|
|
+ }
|
|
|
+ else if ((*a1)->id()<(*c1)->id())
|
|
|
+ {
|
|
|
+ nlist.push_back(std::make_shared<area_hover>(*a1,pt,speed));
|
|
|
+ do_enter_biz(card_id,nlist.back(),speed);
|
|
|
+ ++a1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ nlist.push_back(*c1);
|
|
|
+ do_hover_biz(card_id,nlist.back(),speed);
|
|
|
+ ++c1,++a1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ while(c1!=ce)
|
|
|
+ {
|
|
|
+ do_leave_biz(card_id,*c1,speed);
|
|
|
+ ++c1;
|
|
|
+ }
|
|
|
+
|
|
|
+ while(a1!=ae)
|
|
|
+ {
|
|
|
+ nlist.push_back(std::make_shared<area_hover>(*a1,pt,speed));
|
|
|
+ do_enter_biz(card_id,nlist.back(),speed);
|
|
|
+ ++a1;
|
|
|
+ }
|
|
|
+
|
|
|
+ m_clist=std::move(nlist);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //检测是否超时
|
|
|
+ void on_timer(int card_id)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ void do_hover_biz(int card_id,std::shared_ptr<area_hover>&a,double speed)
|
|
|
+ {
|
|
|
+ a->m_area->on_hover(card_id,a,speed);
|
|
|
+ }
|
|
|
+
|
|
|
+ void do_enter_biz(int card_id,std::shared_ptr<area_hover> a,double speed)
|
|
|
+ {
|
|
|
+ a->m_area->on_enter(card_id,a,speed);
|
|
|
+ }
|
|
|
+
|
|
|
+ void do_leave_biz(int card_id,std::shared_ptr<area_hover> a,double speed)
|
|
|
+ {
|
|
|
+ a->m_area->on_leave(card_id,a,speed);
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+#endif
|
|
|
+
|