diff -aruN librcsc-1.4.0-org/rcsc/player/Makefile.am librcsc-1.4.0/rcsc/player/Makefile.am --- librcsc-1.4.0-org/rcsc/player/Makefile.am 2007-08-29 17:50:12.000000000 +0900 +++ librcsc-1.4.0/rcsc/player/Makefile.am 2007-09-26 23:18:34.000000000 +0900 @@ -44,6 +44,7 @@ ball_object.h \ body_sensor.h \ debug_client.h \ + free_message.h \ freeform_parser.h \ fullstate_sensor.h \ interception.h \ diff -aruN librcsc-1.4.0-org/rcsc/player/audio_memory.cpp librcsc-1.4.0/rcsc/player/audio_memory.cpp --- librcsc-1.4.0-org/rcsc/player/audio_memory.cpp 2007-09-10 18:13:51.000000000 +0900 +++ librcsc-1.4.0/rcsc/player/audio_memory.cpp 2007-09-26 23:18:34.000000000 +0900 @@ -67,6 +67,8 @@ , M_dribble_target_pos( 50.0, 0.0 ) , M_dribble_queue_count( 0 ) , M_dribble_target_time( -100, 0 ) + , M_free_message_sender_number( Unum_Unknown ) + , M_free_message_time( -100, 0 ) { } @@ -303,4 +305,23 @@ M_dribble_target_time = current; } +/*-------------------------------------------------------------------*/ +/*! + +*/ +void +AudioMemory::setFreeMessage( const int sender_number, + const std::string & msg, + const GameTime & current ) +{ + dlog.addText( Logger::WORLD, + __FILE__": set heard free message. sender=%d" + " message=[%s]", + sender_number, msg.c_str() ); + + M_free_message_sender_number = sender_number; + M_free_message = msg; + M_free_message_time = current; +} + } diff -aruN librcsc-1.4.0-org/rcsc/player/audio_memory.h librcsc-1.4.0/rcsc/player/audio_memory.h --- librcsc-1.4.0-org/rcsc/player/audio_memory.h 2007-09-10 21:15:23.000000000 +0900 +++ librcsc-1.4.0/rcsc/player/audio_memory.h 2007-09-26 23:18:34.000000000 +0900 @@ -36,6 +36,8 @@ #include #include +#include + namespace rcsc { /*! @@ -107,6 +109,10 @@ int M_dribble_queue_count; //!< the size of dribble action queue GameTime M_dribble_target_time; //!< dribble info heard time + int M_free_message_sender_number; //!< freeform message + std::string M_free_message; //!< freeform message + GameTime M_free_message_time; //!< free message heared time + private: // not used AudioMemory( const AudioMemory & ); @@ -488,6 +494,34 @@ return M_dribble_target_time; } + /*! + \brief get free message sender number + */ + int freeMessageSenderNumber() const + { + return M_free_message_sender_number; + } + + /*! + \brief get heard free message + \return heard message + */ + const + std::string & freeMessage() const + { + return M_free_message; + } + + /*! + \brief get free message heard time + \return time value + */ + const + GameTime & freeMessageTime() const + { + return M_free_message_time; + } + // setter methods @@ -606,6 +640,17 @@ const Vector2D & pos, const int queue_count, const GameTime & current ); + + /*! + \brief set heard freeform message + \param sender_number message sender's uniform number + \param msg heard message + \param current current game time + */ + void setFreeMessage( const int sender_number, + const std::string & msg, + const GameTime & current ); + }; } diff -aruN librcsc-1.4.0-org/rcsc/player/free_message.h librcsc-1.4.0/rcsc/player/free_message.h --- librcsc-1.4.0-org/rcsc/player/free_message.h 1970-01-01 09:00:00.000000000 +0900 +++ librcsc-1.4.0/rcsc/player/free_message.h 2007-09-26 23:18:34.000000000 +0900 @@ -0,0 +1,188 @@ +// -*-c++-*- + +/*! + \file free_message.h + \brief player's freeform say message builder/parser Header File +*/ + +/* + *Copyright: + + Copyright (C) Hidehisa AKIYAMA + + This code 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. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + *EndCopyright: + */ + +///////////////////////////////////////////////////////////////////// + +#ifndef RCSC_PLAYER_FREE_MESSAGE_H +#define RCSC_PLAYER_FREE_MESSAGE_H + +#include +#include +#include +#include +#include + +#include +#include + +namespace rcsc { + +/*-------------------------------------------------------------------*/ +/*! + \class FreeMessageParser9 + \brief player's freeform say message parser +*/ +template < std::size_t LEN > +class FreeMessageParser + : public SayMessageParser { +private: + //! pointer to the audio memory + boost::shared_ptr< AudioMemory > M_memory; + +public: + + /*! + \brief construct with audio memory + \param memory pointer to the memory + */ + explicit + FreeMessageParser( boost::shared_ptr< AudioMemory > memory ) + : M_memory( memory ) + { } + + /*! + \brief get the header character. + \return header character. + */ + char header() const + { + return static_cast< char >( '0' + LEN ); + } + + /*! + \brief virtual method which analyzes audio messages. + \param unum sender's uniform number + \param dir sender's direction + \param msg raw audio message + \param current current game time + \retval bytes read if success + \retval 0 message ID is not match. other parser should be tried. + \retval -1 failed to parse + */ + int parse( const int unum, + const double & dir, + const char * msg, + const GameTime & current ) + { + if ( *msg != header() ) return 0; + ++msg; + if ( std::strlen( msg ) < LEN ) + { + std::cerr << __FILE__ << ':' << __LINE__ + << " FreeMessageParser: Illegal message length. message=" + << msg << " must be length " << LEN + << std::endl; + return -1; + } + + dlog.addText( Logger::SENSOR, + "FreeMessageParser::parse() success! length=%d mssage=[%s]", + LEN, msg ); + M_memory->setFreeMessage( unum, + std::string( msg, 0, LEN ), + current ); + return 1 + LEN; + } + +}; + +/*-------------------------------------------------------------------*/ +/*! + \class FreeMessage + \brief player's freeform say message encoder +*/ +template < std::size_t LEN > +class FreeMessage + : public SayMessage { +private: + + std::string M_message; //!< message without header + +public: + + FreeMessage( const std::string & msg ) + { + M_message = msg; + } + + /*! + \brief pure virtual method. get the header character of this message + \return header character of this message + */ + char header() const + { + return static_cast< char >( '0' + LEN ); + } + + /*! + \brief pure virtual method. get the length of this message + \return the length of encoded message + */ + std::size_t length() const + { + return LEN + 1; + } + + /*! + \brief append the audio message to be sent + \param to reference to the message string instance + \return result status of encoding + */ + bool toStr( std::string & to ) const + { + if ( static_cast< int >( to.length() + 1 + LEN ) + > ServerParam::i().playerSayMsgSize() ) + { + std::cerr << __FILE__ << ':' << __LINE__ + << " FreeMessage: over the capacity. message=" + << M_message << ". current size = " + << to.length() + << std::endl; + return false; + } + + if ( M_message.length() != LEN ) + { + std::cerr << __FILE__ << ':' << __LINE__ + << " Illegal message length. message=" + << M_message << " must be length " << LEN + << std::endl; + return false; + } + + to += header(); + to += M_message; + return true; + } + +}; + +} + +#endif diff -aruN librcsc-1.4.0-org/rcsc/player/player_agent.cpp librcsc-1.4.0/rcsc/player/player_agent.cpp --- librcsc-1.4.0-org/rcsc/player/player_agent.cpp 2007-08-29 18:04:54.000000000 +0900 +++ librcsc-1.4.0/rcsc/player/player_agent.cpp 2007-09-26 23:18:34.000000000 +0900 @@ -40,6 +40,7 @@ #include "audio_sensor.h" #include "fullstate_sensor.h" +#include "free_message.h" #include "audio_memory.h" #include "debug_client.h" #include "freeform_parser.h" @@ -400,6 +401,14 @@ addSayMessageParser( SMP( new BallGoalieMessageParser( audio_memory ) ) ); addSayMessageParser( SMP( new OnePlayerMessageParser( audio_memory ) ) ); addSayMessageParser( SMP( new BallPlayerMessageParser( audio_memory ) ) ); + addSayMessageParser( SMP( new FreeMessageParser< 9 >( audio_memory ) ) ); + addSayMessageParser( SMP( new FreeMessageParser< 8 >( audio_memory ) ) ); + addSayMessageParser( SMP( new FreeMessageParser< 7 >( audio_memory ) ) ); + addSayMessageParser( SMP( new FreeMessageParser< 6 >( audio_memory ) ) ); + addSayMessageParser( SMP( new FreeMessageParser< 5 >( audio_memory ) ) ); + addSayMessageParser( SMP( new FreeMessageParser< 4 >( audio_memory ) ) ); + addSayMessageParser( SMP( new FreeMessageParser< 3 >( audio_memory ) ) ); + addSayMessageParser( SMP( new FreeMessageParser< 2 >( audio_memory ) ) ); M_impl->audio_.addParser( FP( new FreeformParser( M_worldmodel ) ) ); }