📄 visual.cc
字号:
// -*-c++-*-/*************************************************************************** visual.cc Classes for building visual messages ------------------- begin : 5-AUG-2002 copyright : (C) 2002 by The RoboCup Soccer Server Maintenance Group. email : sserver-admin@lists.sourceforge.net ***************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU LGPL as published by the Free Software * * Foundation; either version 2 of the License, or (at your option) any * * later version. * * * ***************************************************************************/#include "visual.h"#include "serializer.h"#include "object.h"#include "player.h"#include "field.h"namespace rcss{/*!//===================================================================//// CLASS: VisualSendor//// DESC: Base class for the visual protocol.////===================================================================*/ VisualSender::VisualSender( std::ostream& transport ) : Sender( transport ) {} VisualSender::~VisualSender() {}/*!//===================================================================//// CLASS: VisualSenderPlayer//// DESC: Base class for the visual protocol for players.////===================================================================*/ VisualSenderPlayer::Factory& VisualSenderPlayer::factory() { static Factory rval; return rval; } VisualSenderPlayer::VisualSenderPlayer( const Params& params ) : VisualSender( params.m_transport ), m_ser( params.m_ser ), m_self( params.m_self ), m_stadium( params.m_stadium ), m_sendcnt( 0 ) {} VisualSenderPlayer::~VisualSenderPlayer() {}/*!//===================================================================//// CLASS: VisualSensorPlayerV1//// DESC: Class for the version 1* visual protocol. This version is// completely unused as far as I am aware of, but it is here// none the less, just in case there is someone somewhere// still using it.//// * It's version 1 to the simualtor in it's current form.// From what I know the original simulator was written in// lisp and the first C++ version was actually version 3. I// don't know if the protocol was compatible with previous// versions, so this may well be the version 3 protocol.////===================================================================*/ VisualSenderPlayerV1::VisualSenderPlayerV1( const Params& params ) : VisualSenderPlayer( params ) {} VisualSenderPlayerV1::~VisualSenderPlayerV1() {} void VisualSenderPlayerV1::sendVisual() { incSendCount(); if( sendCount() >= self().vis_send ) resetSendCount(); else return; serializer().serializeVisualBegin( transport(), stadium().time ); if( self().highquality ) { M_send_flag = &VisualSenderPlayerV1::sendHighFlag; M_send_ball = &VisualSenderPlayerV1::sendHighBall; M_send_player = &VisualSenderPlayerV1::sendHighPlayer; M_serialize_line = &VisualSenderPlayerV1::serializeHighLine; } else { M_send_flag = &VisualSenderPlayerV1::sendLowFlag; M_send_ball = &VisualSenderPlayerV1::sendLowBall; M_send_player = &VisualSenderPlayerV1::sendLowPlayer; M_serialize_line = &VisualSenderPlayerV1::serializeLowLine; } sendFlags(); sendBalls(); sendPlayers(); sendLines(); serializer().serializeVisualEnd( transport() ); transport() << ends << flush; } void VisualSenderPlayerV1::sendFlags() { for( int j = 0 ; j < stadium().votable.n ; j++ ) { switch ( stadium().votable.object[ j ]->getObjectType () ) { case MPObject::OT_GOAL: if( stadium().votable.object[ j ]->obj_ver <= self().version ) sendFlag( *( stadium().votable.object [ j ] ) ); break; case MPObject::OT_FLAG: if( stadium().votable.object[ j ]->obj_ver <= self().version ) sendFlag( *( stadium().votable.object [ j ] ) ); break; default: break; } } } void VisualSenderPlayerV1::sendBalls() { for( int j = 0 ; j < stadium().motable.n ; j++ ) { switch ( stadium().motable.object [ j ]->getObjectType () ) { case MPObject::OT_BALL: if( stadium().votable.object[ j ]->obj_ver <= self().version ) sendBall( *( stadium().motable.object [ j ] ) ); break; default: break; } } } void VisualSenderPlayerV1::sendPlayers() { for( int j = 0 ; j < MAX_PLAYER * 2; j++) if( stadium().player[ j ] != &self() && stadium().player[ j ]->alive != DISABLE && stadium().votable.object[ j ]->obj_ver <= self().version ) sendPlayer( *( stadium().player [ j ] ) ); } void VisualSenderPlayerV1::sendLines() { int line_count = 0; int max_line_count; int min_line_count; if( fabs ( self().pos.x ) < PITCH_LENGTH*0.5 && fabs ( self().pos.y ) < PITCH_WIDTH*0.5 ) min_line_count = max_line_count = 1; else { max_line_count = 2; min_line_count = 0; } if( line_count < max_line_count && stadium().field.line_l.obj_ver <= self().version ) { if( sendLine( stadium().field.line_l ) ) line_count++; } if( line_count < max_line_count && stadium().field.line_r.obj_ver <= self().version ) { if( sendLine( stadium().field.line_r ) ) line_count++; } if( line_count < max_line_count && stadium().field.line_t.obj_ver <= self().version ) { if( sendLine( stadium().field.line_t ) ) line_count++; } if( line_count < max_line_count && stadium().field.line_b.obj_ver <= self().version ) { if( sendLine( stadium().field.line_b ) ) line_count++; } if( line_count < min_line_count ) cerr << __FILE__ << ": " << __LINE__ << ": Error rendering visual: not enough lines\n" << "Player = " << self() << endl; } void VisualSenderPlayerV1::sendLowFlag( const PObject& flag ) { double ang = calcRadDir( flag ); if( fabs( ang ) < self().vis_angle * 0.5 ) { serializer().serializeVisualObject( transport(), calcName( flag ), calcDegDir( ang ) ); } else if( calcUnQuantDist( flag ) <= self().vis_distance ) { serializer().serializeVisualObject( transport(), calcCloseName( flag ), calcDegDir( ang ) ); } } void VisualSenderPlayerV1::sendHighFlag( const PObject& flag ) { double ang = calcRadDir( flag ); double qstep = self().landDistQStep(); double un_quant_dist = calcUnQuantDist( flag ); double quant_dist = calcQuantDist( un_quant_dist, qstep ); if( fabs( ang ) < self().vis_angle * 0.5 ) { double prob; prob = ( ( quant_dist - UNUM_FAR_LENGTH ) / ( UNUM_TOOFAR_LENGTH - UNUM_FAR_LENGTH ) ); if( decide( prob ) ) { serializer().serializeVisualObject( transport(), calcName( flag ), quant_dist, calcDegDir( ang ) ); } else { double dist_chg, dir_chg; calcVel( PVector(), flag.pos, un_quant_dist, quant_dist, dist_chg, dir_chg ); serializer().serializeVisualObject( transport(), calcName( flag ), quant_dist, calcDegDir( ang ), dist_chg, dir_chg ); } } else if( un_quant_dist <= self().vis_distance ) { serializer().serializeVisualObject( transport(), calcCloseName( flag ), quant_dist, calcDegDir( ang ) ); } } void VisualSenderPlayerV1::sendLowBall( const MPObject& ball ) { double ang = calcRadDir( ball ); if( fabs( ang ) < self().vis_angle * 0.5 ) { serializer().serializeVisualObject( transport(), calcName( ball ), calcDegDir( ang ) ); } else if( calcUnQuantDist( ball ) <= self().vis_distance ) { serializer().serializeVisualObject( transport(), calcCloseName( ball ), calcDegDir( ang ) ); } } void VisualSenderPlayerV1::sendHighBall( const MPObject& ball ) { double ang = calcRadDir( ball ); double un_quant_dist = calcUnQuantDist( ball ); double qstep = self().distQStep(); double quant_dist = calcQuantDist( un_quant_dist, qstep ); if( fabs( ang ) < self().vis_angle * 0.5 ) { double prob; prob = ( quant_dist - UNUM_FAR_LENGTH ) / ( UNUM_TOOFAR_LENGTH - UNUM_FAR_LENGTH ); if( decide( prob ) ) { serializer().serializeVisualObject( transport(), calcName( ball ), quant_dist, calcDegDir( ang ) ); } else { double dist_chg, dir_chg; calcVel ( ball.vel, ball.pos, un_quant_dist, quant_dist, dist_chg, dir_chg ); serializer().serializeVisualObject( transport(), calcName( ball ), quant_dist, calcDegDir( ang ), dist_chg, dir_chg ); } } else if( un_quant_dist <= self().vis_distance ) { serializer().serializeVisualObject( transport(), calcCloseName( ball ), quant_dist, calcDegDir( ang ) ); } } void VisualSenderPlayerV1::sendLowPlayer( const Player& player ) { double ang = calcRadDir( player ); double un_quant_dist = calcUnQuantDist( player );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -