#ifndef _AREA_HPP_ #define _AREA_HPP_ #include #include #include #include #include "common.h" #include struct area_hover; struct point; struct area { area(int id,int limit_count_person, int limit_time_person,double scale,int32_t mapid,int32_t type) :m_id(id) ,m_area_type(type) ,m_limit_person_second(limit_time_person) ,m_limit_person_count(limit_count_person) ,m_scale(scale) ,m_mapid(mapid) ,m_person_count(0) ,m_vehicle_count(0) { } virtual void on_hover(uint32_t card_id,std::shared_ptr&c,double speed,int32_t type); virtual void on_enter(uint32_t card_id,std::shared_ptr&c,double speed,int32_t type); virtual void on_leave(uint32_t card_id,std::shared_ptr&c,double speed,int32_t type); bool in_area(const point & p); int id()const { return m_id; } int mapid()const { return m_mapid; } double scale()const { return m_scale; } bool special()const { return m_area_type == AREA_TYPE_NO_COVER; } virtual ~area() {} ///区域卡数 int card_count()const { return m_person_count + m_vehicle_count; } std::vector m_bound; public: //std::atomic m_card_count; int m_id; ///区域类型 AREA_TYPE int m_area_type; int m_limit_person_second; int m_limit_person_count; int m_limit_vehicle_second; int m_limit_vehicle_count; double m_scale; int32_t m_mapid; ///区域人卡数 std::atomic m_person_count; ///区域车卡数 std::atomic m_vehicle_count; }; struct area_list:single_base> { area_list(); std::shared_ptr get_area(const point&pt); std::vector init_path(std::string &str); void init_from_db(); void init_monkeycar_area(); }; struct area_hover { std::shared_ptr m_area; time_t m_enter_time,m_last_time; point m_enter_point,m_last_point; int landmark_id; int landmark_dir; double landmark_dis; area_hover()=default; area_hover(std::shared_ptr&area,const point&pt,double speed) :m_area(area) { m_enter_time=m_last_time=time(0); m_enter_point=m_last_point=pt; landmark_id=0; landmark_dir=0; landmark_dis=0; } int id()const { return m_area->id(); } int mapid()const { return m_area->mapid(); } double scale()const { return m_area->scale(); } 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()id(); } std::tuple getLandmark() { return std::make_tuple(m_enter_time,m_last_time,mapid(),id(),landmark_id,landmark_dir,landmark_dis); } void setLandmark(const point &pt); void set(const point&pt) { m_last_time=time(0); m_last_point = pt; } }; //每张卡包含一个对象 //在解析出数据点时,调用on_point struct area_tool { std::shared_ptr m_area_hover=nullptr; void on_point(uint32_t card_id,const point&pt,double speed,int16_t type); void setLandmark(const point &pt) { if(m_area_hover) { m_area_hover->setLandmark(pt); } } //special area or no area att.,return true;else return false. bool special_area() { if(m_area_hover==nullptr) return true; return m_area_hover->m_area->special(); } std::tuple getLandmark() { if(m_area_hover) return m_area_hover->getLandmark(); else return std::make_tuple(0,0,0,0,0,0,0); } //检测是否超时 void on_timer(int64_t card_id) { } void do_hover_biz(uint32_t card_id,double speed,int16_t type) { m_area_hover->m_area->on_hover(card_id,m_area_hover,speed,type); } void do_enter_biz(uint32_t card_id,double speed,int16_t type) { m_area_hover->m_area->on_enter(card_id,m_area_hover,speed,type); } void do_leave_biz(uint32_t card_id,double speed,int16_t type) { m_area_hover->m_area->on_leave(card_id,m_area_hover,speed,type); } void change_area(uint32_t card_id,double speed,int16_t type,int32_t new_areaid) { do_leave_biz(card_id,speed,type); auto area = area_list::instance()->get(new_areaid); point pt; m_area_hover.reset(new area_hover(area,pt,speed)); do_enter_biz(card_id,speed,type); } }; #endif