📄 mediator.h
字号:
#ifndef __MEDIATOR_H__
#define __MEDIATOR_H__
#include "geometry.h"
#include "command.h"
#include "list.h"
#include "smp_datastruct.h"
const int CP_max_visualrequests = 50;
const int CP_max_actions = 20;
class Mediator;
class PrioredCommand : public Command{
private:
float priority;
ActionType actiontype;
public:
PrioredCommand();
PrioredCommand(Command& cmd, ActionType actiontype, float priority){
*this = cmd;
this->actiontype = actiontype; this->priority = priority;
}
void Reset(){Command::Reset(); actiontype = Action_none; priority = 0.0f;}
void operator =(const Command& cmd){angle = cmd.angle; x = cmd.x; y = cmd.y;
time = cmd.time; type = cmd.type; power = cmd.power;}
bool operator >(const PrioredCommand& pcmd){ return priority > pcmd.priority;}
bool operator ==(const PrioredCommand& pcmd){ return priority == pcmd.priority;}
bool operator <(const PrioredCommand& pcmd){ return priority < pcmd.priority;}
friend class Mediator;
float GetPriority(){return priority;}
ActionType GetActionType(){return actiontype;}
friend class Mediator;
};
class VisualRequest{
private:
float priority;
AngleDeg angle;
AngleDeg angle_inf;
VIEWWIDTH view_width;
bool valid;
public:
VisualRequest(float priority = NoPriority, AngleDeg angle =0.0f);
bool operator >(VisualRequest& vreq){ return angle < vreq.angle;}
bool operator ==(VisualRequest& vreq){ return angle == vreq.angle;}
bool operator < (VisualRequest& vreq){ return angle > vreq.angle;}
AngleDeg RequestedAngle(){return angle;};
AngleDeg RequestedAngle_();
float RequestedPriority();
friend class Mediator;
};
/***************** Mediator *****************************/
class Mediator{
private:
/**** Priored Queue **************/
Ordered_Soft_Queue<VisualRequest, CP_max_visualrequests> vr_queue;
Ordered_Soft_Queue<PrioredCommand, CP_max_actions> ac_queue;
/* visual request */
float Vang_inf, Vang_sup; //可能达到的视觉角度
float Validate_default_angle; //用于验证角度是否可达的默认的视觉宽度
VisualRequest visualrequests[CP_max_visualrequests];
int totalvisualrequests;
TimedData<VIEWWIDTH> designated_viewwidth;
/*********************************/
KT_Res pass_res;
/*********************************/
ActionType lastactiontype;
CMDType lastcmdtype;
void feedback(const PrioredCommand& bestaction , int vr_idx);
float priority_mapping(ActionType actiontype, float priority);
int SetVisualRequests(VisualRequest* requests, int& totalrequests, VIEWWIDTH view_width, int max_requests = CP_max_visualrequests);
int SetVisualRequests();
public:
Mediator();
void ResetBuffer();
bool enroll(PrioredCommand& pcmd);
bool enroll(Command& command, ActionType actiontype, float priority);
bool enroll(float priority, AngleDeg angle);
void SetViewWidth(VIEWWIDTH view_width);
bool IsViewWidthSet();
bool ValidRequestAng(float ang, float shrinked_angle = 0);
void SetViewRange();
void mediation();
ActionType LastActionType();
CMDType LastCmdType();
void Getbestaction(PrioredCommand& bestaction);
/*** For Visual Decision and Audio Decision ***/
TimedData<bool> PassOut;
TimedData<bool> KickOut;
PrioredCommand submitaction;
friend class VisualSystem;
};
#endif //__MEDIATOR_H__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -