📄 mediator.h
字号:
/*
Copyright (C) 2001 Tsinghuaeolus
Authors : ChenJiang, YaoJinyi, CaiYunpeng, Lishi
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
If you make any changes or have any comments we would appreciate a
message to yjy01@mails.tsinghua.edu.cn.
*/
#ifndef _mediator
#define _mediator
#include "Geometry.h"
#include "Command.h"
#include "bpn.h"
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 */
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);
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);
void DisableViewWidth();
void SetVisualRequests(VisualRequest* requests, int& totalrequests, VIEWWIDTH view_width, int max_requests = CP_max_visualrequests);
void SetVisualRequests();
void mediation();
ActionType LastActionType();
CMDType LastCmdType();
void Getbestaction(PrioredCommand& bestaction);
/*** For Visual Decision and Audio Decision ***/
bool IsLastCycleIntercept;//It is last cycle of interception, please change view
TimedData<bool> PassOut;
friend class VisualSystem;
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -