visualsenderplayer.h

来自「2009 ROBOCUP 仿真2DSERVER 源码」· C头文件 代码 · 共 612 行 · 第 1/2 页

H
612
字号
// -*-c++-*-/***************************************************************************                             visualsenderplayer.h                 Classes for building visual messages for players                             -------------------    begin                : 2008-02-17    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.                                                        * *                                                                         * ***************************************************************************/#ifndef RCSS_VISUALSENDER_PLAYER_H#define RCSS_VISUALSENDER_PLAYER_H#include "visual.h"#include "observer.h"#include "player.h"#include "random.h"#include <rcssbase/factory.hpp>class Stadium;namespace rcss {class SerializerPlayer;/*!//===================================================================////  CLASS: VisualSenderPlayer////  DESC: Base class for the visual protocol for players.////===================================================================*/class VisualSenderPlayer    : public VisualSender {public:    class Params {    public:        std::ostream & M_transport;        const Player & M_self;        const SerializerPlayer & M_serializer;        const Stadium & M_stadium;        Params( std::ostream & transport,                const Player & self,                const SerializerPlayer & serializer,                const Stadium & stadium )            : M_transport( transport )            , M_self( self )            , M_serializer( serializer )            , M_stadium( stadium )          { }    };private:    const SerializerPlayer & M_serializer;    /*:TODO: M_self needs to be replaced with a reference to a      Observer and Observer should have virtual functions for      stuff like velocity, stamina, etc */    const Player & M_self;    const Stadium & M_stadium;    int M_sendcnt;public:    typedef std::auto_ptr< VisualSenderPlayer > Ptr;    typedef Ptr (*Creator)( const VisualSenderPlayer::Params & );    typedef rcss::Factory< Creator, int > FactoryHolder;    static    FactoryHolder & factory();    VisualSenderPlayer( const Params & params );    ~VisualSenderPlayer();protected:    const    SerializerPlayer & serializer() const      {          return M_serializer;      }    const    Player & self() const      {          return M_self;      }    const    Stadium & stadium() const      {          return M_stadium;      }    int sendCount() const      {          return M_sendcnt;      }    void incSendCount()      {          ++M_sendcnt;      }    void resetSendCount()      {          M_sendcnt = 0;      }};/*!//===================================================================////  CLASS: ObserverPlayer////  DESC: Interface for players that receives visual information.////===================================================================*/class ObserverPlayer    : protected BaseObserver< VisualSenderPlayer > {public:    ObserverPlayer()      { }    ObserverPlayer( VisualSenderPlayer & sender )        : BaseObserver< VisualSenderPlayer >( sender )      { }    ObserverPlayer( std::auto_ptr< VisualSenderPlayer > sender )        : BaseObserver< VisualSenderPlayer >( sender )      { }    ~ObserverPlayer()      { }    void setVisualSender( VisualSenderPlayer & sender )      {          BaseObserver< VisualSenderPlayer >::setSender( sender );      }    void setVisualSender( std::auto_ptr< VisualSenderPlayer > sender )      {          BaseObserver< VisualSenderPlayer >::setSender( sender );      }    void sendVisual()      {          BaseObserver< VisualSenderPlayer >::sender().sendVisual();      }};/*!//===================================================================////  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.////===================================================================*/class VisualSenderPlayerV1    : public VisualSenderPlayer {public:    VisualSenderPlayerV1( const Params & params );    virtual    ~VisualSenderPlayerV1();    virtual    void    sendVisual();private:    void sendFlag( const PObject & obj )      {          (this->*M_send_flag)( obj );      }    void sendBall( const MPObject & obj )      {          (this->*M_send_ball)( obj );      }    void sendPlayer( const Player & obj )      {          (this->*M_send_player)( obj );      }    void serializeLine( const std::string & name,                        const int dir,                        const double & sight_2_line_ang,                        const double & player_2_line )      {          (this->*M_serialize_line)( name, dir,                                     sight_2_line_ang, player_2_line );      }    void sendFlags();    void sendBalls();    void sendPlayers();    void sendLines();    void sendLowFlag( const PObject & flag );    void sendHighFlag( const PObject & flag );    void sendLowBall( const MPObject & ball );    void sendHighBall( const MPObject & ball );    void sendLowPlayer( const Player & player );    void sendHighPlayer( const Player & player );    bool sendLine( const PObject & line );    void serializeLowLine( const std::string & name,                           const int dir,                           const double &,                           const double & );    void serializeHighLine( const std::string & name,                            const int dir,                            const double & sight_2_line_ang,                            const double & player_2_line );    double calcRadDir( const PObject & obj )      {          return normalize_angle( self().angleFromBody( obj )                                  - self().angleNeckCommitted() );      }    int calcDegDir( const double & rad_dir ) const      {          return rad2Deg( rad_dir );      }    double calcLineRadDir( const double & line_normal ) const      {          return normalize_angle( line_normal                                  - self().angleBodyCommitted()                                  - self().angleNeckCommitted() );      }    int calcLineDir( const double & sight_2_line_ang ) const      {          if ( sight_2_line_ang > 0 )              return calcDegDir( sight_2_line_ang - M_PI*0.5 );          else              return calcDegDir( sight_2_line_ang + M_PI*0.5 );      }    double calcUnQuantDist( const PObject& obj ) const      {          return self().pos().distance( obj.pos() );      }    double calcQuantDist( const double& dist,                          const double& qstep ) const      {          return Quantize( std::exp( Quantize( std::log( dist + EPS ), qstep ) ), 0.1 );      }    double calcLineDist( const double & sight_2_line_ang,                         const double & player_2_line,                         const double & qstep ) const

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?