From 39297ffbe8c517940f038552d60553ed206db659 Mon Sep 17 00:00:00 2001 From: Hidehisa Akiyama <522630+hidehisaakiyama@users.noreply.github.com> Date: Tue, 7 Mar 2023 13:00:43 +0900 Subject: [PATCH 1/5] V18 develop observation (#95) (#110) * Add observation variables into heteroplayer * add distance and dictance2 functions in PVector to calculate its distance to Vector2D * add observation variables into types.h * add set_focus function into pcombuilder * remove observation variables from player * remove observation functions from player * add focus variables and functions in player.h * add view angles noise term into player.h and update QStep functions * add focus variables and functions into player.cpp * add NormalizeFocusAngle function into player.cpp * change synch see M_visual_send_interval to 1 in player.cpp * update visualsenderplayer to use focus point, hetero observation variables, and clean code * fix bug in set focus, the committed focus point should be updated after updating pos. * add focus count and focus pos into SerializerMonitorJSON * add DispSenderLoggerV5, InitSenderLoggerV7, SerializerMonitorStdv5 to add focus pos and focus count into log * fix a bug in updating focus point committed * add vm6 into dispsender and v6 into initsendermonitor * add visualsenderplayer vp18 * add serializeFocusPoint into serializerplayerstdv14 * add serializeBodyCounts into serializerplayerstdv1 to send set_focus count * add serializeFocusPoint and serializeBodyCounts into serializer * add InitSenderPlayer vp18 into initsenderplayer * add BodySenderPlayerV18 into bodysender * add AudioSenderPlayer into audio * add FullStateSenderPlayer vp18 into fullstatesender * implement serializerplayerstdv18 and add serializeFSPlayerBegin serializeFocusPoint * add serializerplayerstdv18 into cmake * implement FullStateSenderPlayerV18 * add serializeVisualPlayer and serializeFSPlayerBegin into serializer * add serializeFSCounts into serializerplayerstdv18 to send set_focus count * remove new hetero player observation params from types.h * improve distance calculator functions of PVector * change set_focus command parameters to dir_moment and dist_moment * remove new hetero player from types * add set_focus command parser in player_command_parser.ypp and player_command_tok.lpp * update monitor serializer to send focus point information * update player serializer to send focus point information * remove serializeVisualPlayer from cmake file * update coach serializers and visual sender to send focus point information * update comments in serializer * update view angles noise term to 1 for older player than 18 and 1,2,3 for player version 18 * update visual sender interval to 1 for player version >= 18 and 1,2,3 for older players * update view angle noise terms to 1, 0.75, 0.5 to encourage teams to use the new model * Fix the initialization procedure of observation noise terms * Fix the order of arguments in Player::set_focus() * change the order of set focus command and focus information to dist and then dir * change set_focus to change_focus * Change the policy of update procudure of the focus point. - The distance and direction of the focus informaiton is now stored for each player object. - The global position of the focus point is cached just after change_focus command and just before the cycle update in order to reduce the computational cost during the see message serialization. - change_focus command can be performed several times in the same simulation cycle. * Remove focus information from the online coaches' visual information * Remove unused methods (serializeVisualPlayer) from Serializer class. * Remove unused methods. * Force synch_see mode to v18+ player. * Add default observation distance parameters again. * Add VisualSenderPlayerV18 for new observation model and revert older senders to keep the complete backward compatibility * Fix coding conventions. * Add serializerplayerstdv18.{h,cpp} to the build target. Separate focus info serialization to another method. * Clean up the serialization of command count for the sense_body message. * Clean up the serialization of command count for the fullstate message. * Add SerializerPlayerStdv5 for the serialization of turn_neck count in sense_body messages * Change the order of focus_point information in the fullstate message, and change the format to the s-exp element with 'focus_point' tag. * Add v18 serializer of online coach as an alias of v14 serializer. Delete unused files. * Fix problems of the serializer registration. Delete unnecessary class. * Fix unintended value type of the moment_dir parameter in the change_focus command. Apply Deg2Rad function to convert from degree to radian. * Fix the build problem caused by misconfiguration in CMakeLists.txt * Apply the restriction of focus_dir when players perform change_view command. * Change the format of the focus_point information in the monitor protocol. * Fix the version number of monitor protocol and rcg format. Delete unused dispsender. * Fix the version number of JSON monitor protocol. * Fix the definition of log version. * Fix the protocol version check for creating Logger instance. * Rename InitSenderLoggerV7 to InitSenderLoggerV6 and fix key value for creator. * Modify the console message when JSON protocol monitors connect. * Set initial values to M_focus_dist and M_focus_dir in Player. --------- Co-authored-by: Nader Zare --- src/CMakeLists.txt | 4 +- src/Makefile.am | 4 + src/audio.cpp | 3 + src/bodysender.cpp | 56 +++-- src/bodysender.h | 32 ++- src/dispsender.cpp | 29 +-- src/fullstatesender.cpp | 83 +++++++- src/fullstatesender.h | 26 +++ src/heteroplayer.cpp | 78 ++++++- src/heteroplayer.h | 26 +++ src/initsendercoach.cpp | 1 + src/initsenderlogger.cpp | 46 +++- src/initsenderlogger.h | 20 ++ src/initsendermonitor.cpp | 4 +- src/initsenderonlinecoach.cpp | 1 + src/initsenderplayer.cpp | 1 + src/logger.cpp | 8 +- src/monitor.cpp | 3 +- src/object.h | 11 + src/pcombuilder.h | 1 + src/player.cpp | 105 ++++++++- src/player.h | 59 +++++- src/player_command_parser.ypp | 8 + src/player_command_tok.lpp | 1 + src/serializer.h | 178 ++++++---------- src/serializercoachstdv14.cpp | 1 + src/serializercommonstdv8.cpp | 1 + src/serializermonitor.cpp | 88 +++++++- src/serializermonitor.h | 33 +++ src/serializeronlinecoachstdv14.cpp | 1 + src/serializerplayerstdv1.cpp | 69 +++--- src/serializerplayerstdv1.h | 15 +- src/serializerplayerstdv14.cpp | 2 +- src/serializerplayerstdv18.cpp | 135 ++++++++++++ src/serializerplayerstdv18.h | 72 +++++++ src/serializerplayerstdv5.cpp | 72 +++++++ src/serializerplayerstdv5.h | 51 +++++ src/serializerplayerstdv7.cpp | 15 +- src/serializerplayerstdv7.h | 8 +- src/serializerplayerstdv8.cpp | 47 +++-- src/serializerplayerstdv8.h | 20 +- src/stadium.cpp | 13 +- src/types.h | 4 +- src/visualsendercoach.cpp | 1 + src/visualsenderplayer.cpp | 316 ++++++++++++++++++++++++++-- src/visualsenderplayer.h | 79 +++++-- 46 files changed, 1527 insertions(+), 304 deletions(-) create mode 100644 src/serializerplayerstdv18.cpp create mode 100644 src/serializerplayerstdv18.h create mode 100644 src/serializerplayerstdv5.cpp create mode 100644 src/serializerplayerstdv5.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 44372b54..65cbf42d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -54,7 +54,7 @@ add_executable(RCSSServer serializercoachstdv8.cpp serializercoachstdv13.cpp serializercoachstdv14.cpp - serializercommonstdv1.cpp + serializercommonstdv1.cpp serializercommonstdv7.cpp serializercommonstdv8.cpp serializercommonjson.cpp @@ -66,10 +66,12 @@ add_executable(RCSSServer serializeronlinecoachstdv13.cpp serializeronlinecoachstdv14.cpp serializerplayerstdv1.cpp + serializerplayerstdv5.cpp serializerplayerstdv7.cpp serializerplayerstdv8.cpp serializerplayerstdv13.cpp serializerplayerstdv14.cpp + serializerplayerstdv18.cpp serverparam.cpp stadium.cpp stdoutsaver.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 8d8662fd..277e2dbd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -49,10 +49,12 @@ rcssserver_SOURCES = \ serializeronlinecoachstdv13.cpp \ serializeronlinecoachstdv14.cpp \ serializerplayerstdv1.cpp \ + serializerplayerstdv5.cpp \ serializerplayerstdv7.cpp \ serializerplayerstdv8.cpp \ serializerplayerstdv13.cpp \ serializerplayerstdv14.cpp \ + serializerplayerstdv18.cpp \ serverparam.cpp \ stadium.cpp \ stdoutsaver.cpp \ @@ -120,10 +122,12 @@ noinst_HEADERS = \ serializeronlinecoachstdv13.h \ serializeronlinecoachstdv14.h \ serializerplayerstdv1.h \ + serializerplayerstdv5.h \ serializerplayerstdv7.h \ serializerplayerstdv8.h \ serializerplayerstdv13.h \ serializerplayerstdv14.h \ + serializerplayerstdv18.h \ serializermonitor.h \ serverparam.h \ stadium.h \ diff --git a/src/audio.cpp b/src/audio.cpp index 29f9cb85..b22a21fa 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -984,6 +984,7 @@ RegHolder vp14 = AudioSenderPlayer::factory().autoReg( &create< AudioSenderPlaye RegHolder vp15 = AudioSenderPlayer::factory().autoReg( &create< AudioSenderPlayerv8 >, 15 ); RegHolder vp16 = AudioSenderPlayer::factory().autoReg( &create< AudioSenderPlayerv8 >, 16 ); RegHolder vp17 = AudioSenderPlayer::factory().autoReg( &create< AudioSenderPlayerv8 >, 17 ); +RegHolder vp18 = AudioSenderPlayer::factory().autoReg( &create< AudioSenderPlayerv8 >, 18 ); template< typename Sender > AudioSender::Ptr @@ -1009,6 +1010,7 @@ RegHolder vc14 = AudioSenderCoach::factory().autoReg( &create< AudioSenderCoachv RegHolder vc15 = AudioSenderCoach::factory().autoReg( &create< AudioSenderCoachv7 >, 15 ); RegHolder vc16 = AudioSenderCoach::factory().autoReg( &create< AudioSenderCoachv7 >, 16 ); RegHolder vc17 = AudioSenderCoach::factory().autoReg( &create< AudioSenderCoachv7 >, 17 ); +RegHolder vc18 = AudioSenderCoach::factory().autoReg( &create< AudioSenderCoachv7 >, 18 ); template< typename Sender > AudioSender::Ptr @@ -1034,5 +1036,6 @@ RegHolder voc14 = AudioSenderOnlineCoach::factory().autoReg( &create< AudioSende RegHolder voc15 = AudioSenderOnlineCoach::factory().autoReg( &create< AudioSenderOnlineCoachv7 >, 15 ); RegHolder voc16 = AudioSenderOnlineCoach::factory().autoReg( &create< AudioSenderOnlineCoachv7 >, 16 ); RegHolder voc17 = AudioSenderOnlineCoach::factory().autoReg( &create< AudioSenderOnlineCoachv7 >, 17 ); +RegHolder voc18 = AudioSenderOnlineCoach::factory().autoReg( &create< AudioSenderOnlineCoachv7 >, 18 ); } } diff --git a/src/bodysender.cpp b/src/bodysender.cpp index 68d9a944..97ef226b 100644 --- a/src/bodysender.cpp +++ b/src/bodysender.cpp @@ -152,11 +152,12 @@ BodySenderPlayerV1::sendNeck() void BodySenderPlayerV1::sendCounts() { - serializer().serializeBodyCounts( transport(), - self().kickCount(), - self().dashCount(), - self().turnCount(), - self().sayCount() ); + serializer().serializeBodyCounts( transport(), self() ); + // serializer().serializeBodyCounts( transport(), + // self().kickCount(), + // self().dashCount(), + // self().turnCount(), + // self().sayCount() ); } /*! @@ -189,14 +190,6 @@ BodySenderPlayerV5::sendNeck() ang ); } -void -BodySenderPlayerV5::sendCounts() -{ - BodySenderPlayerV1::sendCounts(); - serializer().serializeNeckCount( transport(), - self().turnNeckCount() ); -} - /*! //=================================================================== // @@ -251,16 +244,6 @@ BodySenderPlayerV7::~BodySenderPlayerV7() } -void -BodySenderPlayerV7::sendCounts() -{ - BodySenderPlayerV6::sendCounts(); - serializer().serializeBodyCounts( transport(), - self().catchCount(), - self().moveCount(), - self().changeViewCount() ); -} - /*! //=================================================================== // @@ -400,7 +383,33 @@ BodySenderPlayerV14::sendBodyData() serializer().serializeFoul( transport(), self() ); } +/*! +//=================================================================== +// +// CLASS: BodySenderPlayerV14 +// +// DESC: version 14 of the sense body protocol. Added foul charged & card info +// +//=================================================================== +*/ + +BodySenderPlayerV18::BodySenderPlayerV18( const Params & params ) + : BodySenderPlayerV14( params ) +{ + +} + +BodySenderPlayerV18::~BodySenderPlayerV18() +{ + +} +void +BodySenderPlayerV18::sendBodyData() +{ + BodySenderPlayerV14::sendBodyData(); + serializer().serializeFocusPoint( transport(), self() ); +} namespace bodysender { @@ -428,6 +437,7 @@ RegHolder vp14 = BodySenderPlayer::factory().autoReg( &create< BodySenderPlayerV RegHolder vp15 = BodySenderPlayer::factory().autoReg( &create< BodySenderPlayerV14 >, 15 ); RegHolder vp16 = BodySenderPlayer::factory().autoReg( &create< BodySenderPlayerV14 >, 16 ); RegHolder vp17 = BodySenderPlayer::factory().autoReg( &create< BodySenderPlayerV14 >, 17 ); +RegHolder vp18 = BodySenderPlayer::factory().autoReg( &create< BodySenderPlayerV18 >, 18 ); } } diff --git a/src/bodysender.h b/src/bodysender.h index 953d7182..19be5d4b 100644 --- a/src/bodysender.h +++ b/src/bodysender.h @@ -197,8 +197,6 @@ class BodySenderPlayerV1 virtual void sendCounts(); -public: - }; /*! @@ -225,8 +223,6 @@ class BodySenderPlayerV5 virtual void sendNeck() override; - virtual - void sendCounts() override; }; /*! @@ -273,10 +269,6 @@ class BodySenderPlayerV7 virtual ~BodySenderPlayerV7() override; -protected: - virtual - void sendCounts() override; - }; /*! @@ -379,6 +371,30 @@ class BodySenderPlayerV14 }; +/*! +//=================================================================== +// +// CLASS: BodySenderPlayerV18 +// +// DESC: version 18 of the sense body protocol. Added card info +// +//=================================================================== +*/ + +class BodySenderPlayerV18 + : public BodySenderPlayerV14 +{ +public: + BodySenderPlayerV18( const Params & params ); + + virtual + ~BodySenderPlayerV18() override; + +protected: + virtual + void sendBodyData() override; + +}; } #endif diff --git a/src/dispsender.cpp b/src/dispsender.cpp index 49c42583..e2455564 100644 --- a/src/dispsender.cpp +++ b/src/dispsender.cpp @@ -486,6 +486,7 @@ DispSenderMonitorV3::sendShow() serializer().serializePlayerPos( ostr, *p ); serializer().serializePlayerArm( ostr, *p ); serializer().serializePlayerViewMode( ostr, *p ); + serializer().serializePlayerFocusPoint( ostr, *p ); serializer().serializePlayerStamina( ostr, *p ); serializer().serializePlayerFocus( ostr, *p ); serializer().serializePlayerCounts( ostr, *p ); @@ -512,15 +513,15 @@ DispSenderMonitorV3::sendMsg( const BoardType board, } -// /*! -// //=================================================================== -// // -// // CLASS: DispSenderMonitorJSON -// // -// // DESC: version 5 of display protocol. -// // -// //=================================================================== -// */ +/*! +//=================================================================== +// +// CLASS: DispSenderMonitorJSON +// +// DESC: JSON protocol. +// +//=================================================================== +*/ DispSenderMonitorJSON::DispSenderMonitorJSON( const Params & params ) : DispSenderMonitor( params ) @@ -585,6 +586,7 @@ DispSenderMonitorJSON::sendShow() serializer().serializePlayerPos( ostr, *p ); serializer().serializePlayerArm( ostr, *p ); serializer().serializePlayerViewMode( ostr, *p ); + serializer().serializePlayerFocusPoint( ostr, *p ); serializer().serializePlayerStamina( ostr, *p ); serializer().serializePlayerFocus( ostr, *p ); //serializer().serializePlayerCounts( ostr, *p ); @@ -1011,6 +1013,7 @@ DispSenderLoggerV4::sendShow() serializer().serializePlayerPos( transport(), *p ); serializer().serializePlayerArm( transport(), *p ); serializer().serializePlayerViewMode( transport(), *p ); + serializer().serializePlayerFocusPoint( transport(), *p ); serializer().serializePlayerStamina( transport(), *p ); serializer().serializePlayerFocus( transport(), *p ); serializer().serializePlayerCounts( transport(), *p ); @@ -1039,7 +1042,7 @@ DispSenderLoggerV4::sendMsg( const BoardType board, // // CLASS: DispSenderLoggerJSON // -// DESC: version 6 log format +// DESC: JSON log format // //=================================================================== */ @@ -1135,7 +1138,8 @@ RegHolder vm1 = DispSenderMonitor::factory().autoReg( &create< DispSenderMonitor RegHolder vm2 = DispSenderMonitor::factory().autoReg( &create< DispSenderMonitorV2 >, 2 ); RegHolder vm3 = DispSenderMonitor::factory().autoReg( &create< DispSenderMonitorV3 >, 3 ); RegHolder vm4 = DispSenderMonitor::factory().autoReg( &create< DispSenderMonitorV3 >, 4 ); -RegHolder vm5 = DispSenderMonitor::factory().autoReg( &create< DispSenderMonitorJSON >, 5 ); +RegHolder vm5 = DispSenderMonitor::factory().autoReg( &create< DispSenderMonitorV3 >, 5 ); +RegHolder vmjson = DispSenderMonitor::factory().autoReg( &create< DispSenderMonitorJSON >, -1 ); template< typename Sender > @@ -1150,7 +1154,8 @@ RegHolder vl2 = DispSenderLogger::factory().autoReg( &create< DispSenderLoggerV2 RegHolder vl3 = DispSenderLogger::factory().autoReg( &create< DispSenderLoggerV3 >, 3 ); RegHolder vl4 = DispSenderLogger::factory().autoReg( &create< DispSenderLoggerV4 >, 4 ); RegHolder vl5 = DispSenderLogger::factory().autoReg( &create< DispSenderLoggerV4 >, 5 ); -RegHolder vl6 = DispSenderLogger::factory().autoReg( &create< DispSenderLoggerJSON >, 6 ); +RegHolder vl6 = DispSenderLogger::factory().autoReg( &create< DispSenderLoggerV4 >, 6 ); +RegHolder vljson = DispSenderLogger::factory().autoReg( &create< DispSenderLoggerJSON >, -1 ); } } diff --git a/src/fullstatesender.cpp b/src/fullstatesender.cpp index d99c0c94..0c391937 100644 --- a/src/fullstatesender.cpp +++ b/src/fullstatesender.cpp @@ -293,15 +293,16 @@ FullStateSenderPlayerV8::sendSelf() self().angleBodyCommitted() + self().angleNeckCommitted(), arm_vec ); - serializer().serializeFSCounts( transport(), - self().kickCount(), - self().dashCount(), - self().turnCount(), - self().catchCount(), - self().moveCount(), - self().turnNeckCount(), - self().changeViewCount(), - self().sayCount() ); + serializer().serializeFSCounts( transport(), self() ); + // serializer().serializeFSCounts( transport(), + // self().kickCount(), + // self().dashCount(), + // self().turnCount(), + // self().catchCount(), + // self().moveCount(), + // self().turnNeckCount(), + // self().changeViewCount(), + // self().sayCount() ); serializer().serializeArm( transport(), self().arm().getCyclesTillMovable(), self().arm().getCyclesTillExpiry(), @@ -442,6 +443,69 @@ FullStateSenderPlayerV13::sendPlayer( const Player & p ) } +/*! +//=================================================================== +// +// CLASS: FullStateSenderPlayerV18 +// +// DESC: version 13 of the full state protocol. The focus point +// information are added. +// +//=================================================================== +*/ + +FullStateSenderPlayerV18::FullStateSenderPlayerV18( const Params & params ) + : FullStateSenderPlayerV13( params ) +{ + +} + + FullStateSenderPlayerV18::~FullStateSenderPlayerV18() +{ + +} + + +void +FullStateSenderPlayerV18::sendPlayer( const Player & p ) +{ + char side = ( p.team()->side() == LEFT ? 'l' : 'r' ); + serializer().serializeFSPlayerBegin( transport(), + side, + p.unum(), + p.isGoalie(), + p.playerTypeId(), + p.pos().x, + p.pos().y, + p.vel().x, + p.vel().y, + Rad2Deg( p.angleBodyCommitted() ), + Rad2Deg( p.angleNeckCommitted() ) ); + + if ( p.arm().isPointing() ) + { + rcss::geom::Vector2D arm_vec; + p.arm().getRelDest( rcss::geom::Vector2D( p.pos().x, p.pos().y ), + p.angleBodyCommitted() + p.angleNeckCommitted(), + arm_vec ); + serializer().serializeFSPlayerArm( transport(), + arm_vec.getMag(), + arm_vec.getHead() ); + } + + serializer().serializeFSPlayerFocus( transport(), p ); + + serializer().serializeFSPlayerStamina( transport(), + p.stamina(), + p.effort(), + p.recovery(), + p.staminaCapacity() ); + + serializer().serializeFSPlayerState( transport(), p ); + + serializer().serializeFSPlayerEnd( transport() ); +} + /*! //=================================================================== // @@ -476,6 +540,7 @@ RegHolder vp14 = FullStateSenderPlayer::factory().autoReg( &create< FullStateSen RegHolder vp15 = FullStateSenderPlayer::factory().autoReg( &create< FullStateSenderPlayerV13 >, 15 ); RegHolder vp16 = FullStateSenderPlayer::factory().autoReg( &create< FullStateSenderPlayerV13 >, 16 ); RegHolder vp17 = FullStateSenderPlayer::factory().autoReg( &create< FullStateSenderPlayerV13 >, 17 ); +RegHolder vp18 = FullStateSenderPlayer::factory().autoReg( &create< FullStateSenderPlayerV18 >, 18 ); } } diff --git a/src/fullstatesender.h b/src/fullstatesender.h index 6223b047..8c7f1836 100644 --- a/src/fullstatesender.h +++ b/src/fullstatesender.h @@ -294,6 +294,32 @@ class FullStateSenderPlayerV13 void sendPlayer( const Player & p ) override; }; +/*! +//=================================================================== +// +// CLASS: FullStateSenderPlayerV18 +// +// DESC: version 18 of the full state protocol. The focus point or +// information are added. +// +//=================================================================== +*/ + +class FullStateSenderPlayerV18 + : public FullStateSenderPlayerV13 +{ +public: + FullStateSenderPlayerV18( const Params & ); + + virtual + ~FullStateSenderPlayerV18() override; + +protected: + + virtual + void sendPlayer( const Player & p ) override; +}; + } diff --git a/src/heteroplayer.cpp b/src/heteroplayer.cpp index 8509c4e1..b6d0a55d 100644 --- a/src/heteroplayer.cpp +++ b/src/heteroplayer.cpp @@ -122,6 +122,8 @@ HeteroPlayer::HeteroPlayer() PP.catchAreaLengthStretchMax() ); M_catchable_area_l_stretch = tmp_delta; + setDefaultObservationParams(); + // double real_speed_max = ( SP.maxPower() * M_dash_power_rate * M_effort_max ) @@ -232,8 +234,28 @@ HeteroPlayer::setDefault() M_kick_power_rate = SP.kickPowerRate(); M_foul_detect_probability = SP.foulDetectProbability(); M_catchable_area_l_stretch = 1.0; + + // v18 + setDefaultObservationParams(); } +void +HeteroPlayer::setDefaultObservationParams() +{ + double maximum_dist_in_pitch = std::sqrt( std::pow( ServerParam::PITCH_LENGTH, 2 ) + + std::pow( ServerParam::PITCH_WIDTH, 2 ) ); + M_unum_far_length = 20.0; + M_unum_too_far_length = 40.0; + M_team_far_length = maximum_dist_in_pitch; // was 40.0 updated by Nader Zare in 2022-10-13 + M_team_too_far_length = maximum_dist_in_pitch; // was 60.0 updated by Nader Zare in 2022-10-13 + M_player_max_observation_length = maximum_dist_in_pitch; + M_ball_vel_far_length = 20.0; + M_ball_vel_too_far_length = 40.0; + M_ball_max_observation_length = maximum_dist_in_pitch; + M_flag_chg_far_length = 20.0; + M_flag_chg_too_far_length = 40.0; + M_flag_max_observation_length = maximum_dist_in_pitch; +} std::ostream & HeteroPlayer::print( std::ostream & o ) const { @@ -255,7 +277,19 @@ HeteroPlayer::print( std::ostream & o ) const = ( ( playerSpeedMax() * ( 1 - playerDecay() ) ) / dashPowerRate() ) - staminaIncMax(); - o << "\tPower Cons @ max vel = " << power_cons_at_max_vel << std::endl; + o << "\tPower Cons @ max vel = " << power_cons_at_max_vel << '\n'; + o << "\tUnum Far Length = " << unumFarLength() << '\n'; + o << "\tUnum Too Far Length = " << unumTooFarLength() << '\n'; + o << "\tTeam Far Length = " << teamFarLength() << '\n'; + o << "\tTeam Too Far Length = " << teamTooFarLength() << '\n'; + o << "\tPlayer Max Observation Length = " << playerMaxObservationLength() << '\n'; + o << "\tBall Vel Far Length = " << ballVelFarLength() << '\n'; + o << "\tBall Vel Too Far Length = " << ballVelTooFarLength() << '\n'; + o << "\tBall Max Observation Length = " << ballMaxObservationLength() << '\n'; + o << "\tFlag Chg Far Length = " << flagChgFarLength() << '\n'; + o << "\tFlag Chg Too Far Length = " << flagChgTooFarLength() << '\n'; + o << "\tFlag Max Observation Length = " << flagMaxObservationLength() << std::endl; + return o; } @@ -331,6 +365,23 @@ HeteroPlayer::printParamsSExp( std::ostream & o, to_sexp( o, "kick_power_rate", kickPowerRate() ); to_sexp( o, "foul_detect_probability", foulDetectProbability() ); to_sexp( o, "catchable_area_l_stretch", catchAreaLengthStretch() ); + + if ( version < 18 ) + { + return; + } + + to_sexp( o, "unum_far_length", unumFarLength() ); + to_sexp( o, "unum_too_far_length", unumTooFarLength() ); + to_sexp( o, "team_far_length", teamFarLength() ); + to_sexp( o, "team_too_far_length", teamTooFarLength() ); + to_sexp( o, "player_max_observation_length", playerMaxObservationLength() ); + to_sexp( o, "ball_vel_far_length", ballVelFarLength() ); + to_sexp( o, "ball_vel_too_far_length", ballVelTooFarLength() ); + to_sexp( o, "ball_max_observation_length", ballMaxObservationLength() ); + to_sexp( o, "flag_chg_far_length", flagChgFarLength() ); + to_sexp( o, "flag_chg_too_far_length", flagChgTooFarLength() ); + to_sexp( o, "flag_max_observation_length", flagMaxObservationLength() ); } @@ -368,4 +419,29 @@ HeteroPlayer::printParamsJSON( std::ostream & o, o << ','; to_json_member( o, "catchable_area_l_stretch", catchAreaLengthStretch() ); } + if ( version >= 18 ) // 14 > ?? + { + o << ","; + to_json_member( o, "unum_far_length", unumFarLength() ); + o << ","; + to_json_member( o, "unum_too_far_length", unumTooFarLength() ); + o << ","; + to_json_member( o, "team_far_length", teamFarLength() ); + o << ","; + to_json_member( o, "team_too_far_length", teamTooFarLength() ); + o << ","; + to_json_member( o, "player_max_observation_length", playerMaxObservationLength() ); + o << ","; + to_json_member( o, "ball_vel_far_length", ballVelFarLength() ); + o << ","; + to_json_member( o, "ball_vel_too_far_length", ballVelTooFarLength() ); + o << ","; + to_json_member( o, "ball_max_observation_length", ballMaxObservationLength() ); + o << ","; + to_json_member( o, "flag_chg_far_length", flagChgFarLength() ); + o << ","; + to_json_member( o, "flag_chg_too_far_length", flagChgTooFarLength() ); + o << ","; + to_json_member( o, "flag_max_observation_length", flagMaxObservationLength() ); + } } diff --git a/src/heteroplayer.h b/src/heteroplayer.h index e9016937..2795ae93 100644 --- a/src/heteroplayer.h +++ b/src/heteroplayer.h @@ -58,6 +58,18 @@ class HeteroPlayer { double foulDetectProbability() const { return M_foul_detect_probability; } double catchAreaLengthStretch() const { return M_catchable_area_l_stretch; } + double unumFarLength() const { return M_unum_far_length; } + double unumTooFarLength() const { return M_unum_too_far_length; } + double teamFarLength() const { return M_team_far_length; } + double teamTooFarLength() const { return M_team_too_far_length; } + double playerMaxObservationLength() const { return M_player_max_observation_length; } + double ballVelFarLength() const { return M_ball_vel_far_length; } + double ballVelTooFarLength() const { return M_ball_vel_too_far_length; } + double ballMaxObservationLength() const { return M_ball_max_observation_length; } + double flagChgFarLength() const { return M_flag_chg_far_length; } + double flagChgTooFarLength() const { return M_flag_chg_too_far_length; } + double flagMaxObservationLength() const { return M_flag_max_observation_length; } + std::ostream & print( std::ostream & o ) const; player_type_t convertToStruct( int id ) const; @@ -72,6 +84,8 @@ class HeteroPlayer { const double & max ); void setDefault(); + void setDefaultObservationParams(); + double M_player_speed_max; double M_stamina_inc_max; double M_player_decay; @@ -89,6 +103,18 @@ class HeteroPlayer { double M_foul_detect_probability; double M_catchable_area_l_stretch; + // v18 + double M_unum_far_length; + double M_unum_too_far_length; + double M_team_far_length; + double M_team_too_far_length; + double M_player_max_observation_length; + double M_ball_vel_far_length; + double M_ball_vel_too_far_length; + double M_ball_max_observation_length; + double M_flag_chg_far_length; + double M_flag_chg_too_far_length; + double M_flag_max_observation_length; }; inline diff --git a/src/initsendercoach.cpp b/src/initsendercoach.cpp index dca0e40b..595e9628 100644 --- a/src/initsendercoach.cpp +++ b/src/initsendercoach.cpp @@ -222,6 +222,7 @@ RegHolder vc14 = InitSenderOfflineCoach::factory().autoReg( &create< InitSenderO RegHolder vc15 = InitSenderOfflineCoach::factory().autoReg( &create< InitSenderOfflineCoachV8 >, 15 ); RegHolder vc16 = InitSenderOfflineCoach::factory().autoReg( &create< InitSenderOfflineCoachV8 >, 16 ); RegHolder vc17 = InitSenderOfflineCoach::factory().autoReg( &create< InitSenderOfflineCoachV8 >, 17 ); +RegHolder vc18 = InitSenderOfflineCoach::factory().autoReg( &create< InitSenderOfflineCoachV8 >, 18 ); } } diff --git a/src/initsenderlogger.cpp b/src/initsenderlogger.cpp index 8b62a16c..4b1212d3 100644 --- a/src/initsenderlogger.cpp +++ b/src/initsenderlogger.cpp @@ -472,6 +472,45 @@ InitSenderLoggerV5::sendHeader() } +/* +//=================================================================== +// +// InitSenderLoggerV6 +// +//=================================================================== +*/ + +InitSenderLoggerV6::InitSenderLoggerV6( const Params & params ) + : InitSenderLoggerV5( params, + std::shared_ptr< InitSenderCommon > + ( new InitSenderCommonV8( params.M_transport, + params.M_serializer, + params.M_stadium, + 999, // accept all parameters + true ) ) ) // new line +{ + // The version of the common sender has to be "8". + // The client version is set to "999" in order to send all parameters. +} + +InitSenderLoggerV6::InitSenderLoggerV6( const Params & params, + const std::shared_ptr< InitSenderCommon > common ) + : InitSenderLoggerV5( params, common ) +{ + +} + +InitSenderLoggerV6::~InitSenderLoggerV6() +{ + +} + +void +InitSenderLoggerV6::sendHeader() +{ + transport() << "ULG6" << std::endl; +} + /* //=================================================================== // @@ -506,7 +545,7 @@ InitSenderLoggerJSON::~InitSenderLoggerJSON() void InitSenderLoggerJSON::sendHeader() { - transport() << "ULG6\n"; + transport() << "JSON\n"; transport() << "[\n"; transport() << '{' @@ -571,7 +610,10 @@ RegHolder vl2 = InitSenderLogger::factory().autoReg( &create< InitSenderLoggerV2 RegHolder vl3 = InitSenderLogger::factory().autoReg( &create< InitSenderLoggerV3 >, 3 ); RegHolder vl4 = InitSenderLogger::factory().autoReg( &create< InitSenderLoggerV4 >, 4 ); RegHolder vl5 = InitSenderLogger::factory().autoReg( &create< InitSenderLoggerV5 >, 5 ); -RegHolder vl6 = InitSenderLogger::factory().autoReg( &create< InitSenderLoggerJSON >, 6 ); +RegHolder vl7 = InitSenderLogger::factory().autoReg( &create< InitSenderLoggerV6 >, 6 ); + +RegHolder vljson = InitSenderLogger::factory().autoReg( &create< InitSenderLoggerJSON >, -1 ); + } } diff --git a/src/initsenderlogger.h b/src/initsenderlogger.h index d88485b4..4a95cd8e 100644 --- a/src/initsenderlogger.h +++ b/src/initsenderlogger.h @@ -342,6 +342,26 @@ class InitSenderLoggerV5 }; + +class InitSenderLoggerV6 + : public InitSenderLoggerV5 { +public: + InitSenderLoggerV6( const Params & params ); + +protected: + InitSenderLoggerV6( const Params & params, + const std::shared_ptr< InitSenderCommon > common ); + +public: + virtual + ~InitSenderLoggerV6() override; + + virtual + void sendHeader() override; + +}; + + /*! \brief version 6 of the init sender for Logger (JSON format) */ diff --git a/src/initsendermonitor.cpp b/src/initsendermonitor.cpp index 232b3797..21f84ee8 100644 --- a/src/initsendermonitor.cpp +++ b/src/initsendermonitor.cpp @@ -379,7 +379,9 @@ RegHolder v1 = InitSenderMonitor::factory().autoReg( &create< InitSenderMonitorV RegHolder v2 = InitSenderMonitor::factory().autoReg( &create< InitSenderMonitorV2 >, 2 ); RegHolder v3 = InitSenderMonitor::factory().autoReg( &create< InitSenderMonitorV3 >, 3 ); RegHolder v4 = InitSenderMonitor::factory().autoReg( &create< InitSenderMonitorV3 >, 4 ); -RegHolder v5 = InitSenderMonitor::factory().autoReg( &create< InitSenderMonitorJSON >, 5 ); +RegHolder v5 = InitSenderMonitor::factory().autoReg( &create< InitSenderMonitorV3 >, 5 ); +RegHolder vjson = InitSenderMonitor::factory().autoReg( &create< InitSenderMonitorJSON >, -1 ); + } } diff --git a/src/initsenderonlinecoach.cpp b/src/initsenderonlinecoach.cpp index 5cc0100a..e3b8f5aa 100644 --- a/src/initsenderonlinecoach.cpp +++ b/src/initsenderonlinecoach.cpp @@ -301,6 +301,7 @@ RegHolder voc14 = InitSenderOnlineCoach::factory().autoReg( &create< InitSenderO RegHolder voc15 = InitSenderOnlineCoach::factory().autoReg( &create< InitSenderOnlineCoachV8 >, 15 ); RegHolder voc16 = InitSenderOnlineCoach::factory().autoReg( &create< InitSenderOnlineCoachV8 >, 16 ); RegHolder voc17 = InitSenderOnlineCoach::factory().autoReg( &create< InitSenderOnlineCoachV8 >, 17 ); +RegHolder voc18 = InitSenderOnlineCoach::factory().autoReg( &create< InitSenderOnlineCoachV8 >, 18 ); } } diff --git a/src/initsenderplayer.cpp b/src/initsenderplayer.cpp index d26a1d48..875da199 100644 --- a/src/initsenderplayer.cpp +++ b/src/initsenderplayer.cpp @@ -282,6 +282,7 @@ RegHolder vp14 = InitSenderPlayer::factory().autoReg( &create< InitSenderPlayerV RegHolder vp15 = InitSenderPlayer::factory().autoReg( &create< InitSenderPlayerV8 >, 15 ); RegHolder vp16 = InitSenderPlayer::factory().autoReg( &create< InitSenderPlayerV8 >, 16 ); RegHolder vp17 = InitSenderPlayer::factory().autoReg( &create< InitSenderPlayerV8 >, 17 ); +RegHolder vp18 = InitSenderPlayer::factory().autoReg( &create< InitSenderPlayerV8 >, 18 ); } } diff --git a/src/logger.cpp b/src/logger.cpp index 24d7d049..b42edbf1 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -164,11 +164,9 @@ Logger::setSenders( const Stadium & stadium ) } int log_version = ServerParam::instance().gameLogVersion(); - int monitor_version = log_version - 1; - if ( log_version == REC_OLD_VERSION ) - { - monitor_version = 1; - } + int monitor_version = ( log_version == REC_OLD_VERSION ? 1 + : log_version == REC_VERSION_JSON ? REC_VERSION_JSON + : log_version - 1 ); rcss::SerializerMonitor::Creator ser_cre; if ( ! rcss::SerializerMonitor::factory().getCreator( ser_cre, monitor_version ) ) diff --git a/src/monitor.cpp b/src/monitor.cpp index 22b67157..1b165677 100644 --- a/src/monitor.cpp +++ b/src/monitor.cpp @@ -104,7 +104,8 @@ Monitor::parseMsg( char * msg, char * str = msg; if ( str[ len - 1 ] != 0 ) { - if ( version() >= 2.0 ) + if ( version() < 0 + || version() >= 2.0 ) { sendMsg( MSG_BOARD, "(warning message_not_null_terminated)" ); diff --git a/src/object.h b/src/object.h index ba5f4b19..5ea976ff 100644 --- a/src/object.h +++ b/src/object.h @@ -53,6 +53,7 @@ #include #include #include +#include /* *=================================================================== @@ -150,6 +151,16 @@ class PVector { return ( PVector( *this ) -= orig ).r(); } + double distance2 ( const rcss::geom::Vector2D & orig) const + { + return std::pow(this->x - orig.getX(), 2) + std::pow(this->y - orig.getY(), 2); + } + + double distance ( const rcss::geom::Vector2D & orig) const + { + return std::sqrt(this->distance2(orig)); + } + const PVector & rotate( const double ang ) { double c = std::cos( ang ); diff --git a/src/pcombuilder.h b/src/pcombuilder.h index ca49b540..30a086e6 100644 --- a/src/pcombuilder.h +++ b/src/pcombuilder.h @@ -80,6 +80,7 @@ class Builder { virtual void dash( double power, double dir ) = 0; virtual void turn( double moment ) = 0; virtual void turn_neck( double moment ) = 0; + virtual void change_focus( double moment_dist, double moment_dir ) = 0; virtual void kick( double power, double dir ) = 0; virtual void long_kick( double power, double dir ) = 0; virtual void goalieCatch( double dir ) = 0; diff --git a/src/player.cpp b/src/player.cpp index ba291e86..38cb1904 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -123,6 +123,24 @@ NormalizeNeckAngle( const double & p ) Deg2Rad( ServerParam::instance().maxNeckAngle() ) ); } +inline +double +NormalizeFocusAngle( const double & focus_dir_to_neck, + const double & visible_angle ) +{ + const double half_angle = visible_angle * 0.5; + + if ( std::abs( normalize_angle( focus_dir_to_neck ) ) < half_angle ) + { + return focus_dir_to_neck; + } + + return ( std::abs( normalize_angle( -half_angle - focus_dir_to_neck ) ) + < std::abs( normalize_angle( half_angle - focus_dir_to_neck ) ) ) + ? -half_angle + : half_angle; +} + } // end of no-name namespace @@ -183,6 +201,10 @@ Player::Player( Stadium & stadium, M_angle_neck( 0.0 ), M_angle_neck_committed( 0.0 ), // + M_focus_dist( 0.0 ), + M_focus_dir( 0.0 ), + M_focus_point( 0.0, 0.0 ), + // M_ball_collide( false ), M_player_collide( false ), M_post_collide( false ), @@ -202,6 +224,7 @@ Player::Player( Stadium & stadium, M_catch_count( 0 ), M_move_count( 0 ), M_turn_neck_count( 0 ), + M_change_focus_count(0 ), M_change_view_count( 0 ), M_say_count( 0 ), M_arm( ServerParam::instance().pointToBan(), @@ -210,7 +233,10 @@ Player::Player( Stadium & stadium, M_tackle_cycles( 0 ), M_tackle_count( 0 ), M_foul_cycles( 0 ), - M_foul_count( 0 ) + M_foul_count( 0 ), + M_wide_view_angle_noise_term( 1.0 ), + M_normal_view_angle_noise_term( 1.0 ), + M_narrow_view_angle_noise_term( 1.0 ) { assert( team ); @@ -225,6 +251,7 @@ Player::Player( Stadium & stadium, setPlayerType( 0 ); recoverAll(); + updateFocusPoint(); } Player::~Player() @@ -343,6 +370,21 @@ Player::init( const double ver, return true; } + +void +Player::initObservationMode() +{ + if ( version() >= 18 ) + { + synch_see(); + + M_wide_view_angle_noise_term = 1.0; + M_normal_view_angle_noise_term = 0.75; + M_narrow_view_angle_noise_term = 0.5; + } +} + + void Player::setPlayerType( const int id ) { @@ -441,7 +483,6 @@ Player::disable() M_vel.y = 0.0; M_accel.x = 0.0; M_accel.y = 0.0; - if ( connected() ) { RemoteClient::close(); @@ -564,6 +605,20 @@ Player::parseCommand( const char * command ) turn_neck( moment ); } + else if ( ! std::strncmp( buf, "(change_focus ", 11 ) ) + { + double dist = 0.0; + double angle = 0.0; + if ( std::sscanf( buf, " ( change_focus %lf %lf ) %n ", + &dist, &angle, &n_read ) != 1 ) + { + std::cerr << "Error parsing >" << buf << "<\n"; + return false; + } + buf += n_read; + + change_focus( dist, angle ); + } else if ( ! std::strncmp( buf, "(say ", 5 ) ) { buf += 5; @@ -1126,6 +1181,20 @@ Player::turn_neck( double moment ) } } +void +Player::change_focus( double moment_dist, double moment_dir ) +{ + M_focus_dist = rcss::bound( 0.0, + M_focus_dist + moment_dist, + 40.0 ); + M_focus_dir = rcss::bound( -M_visible_angle * 0.5, + normalize_angle( M_focus_dir + Deg2Rad( moment_dir ) ), + +M_visible_angle * 0.5 ); + updateFocusPoint(); + + ++M_change_focus_count; +} + void Player::kick( double power, double dir ) @@ -1623,7 +1692,7 @@ Player::change_view( rcss::pcom::VIEW_WIDTH viewWidth, else { M_visible_angle = DEFAULT_VISIBLE_ANGLE * ( 2.0 / 3.0 ); // == sim_step / send_step - M_visual_send_interval = 1; + M_visual_send_interval = (version() >= 18 ? 1 : 1); } } else if ( viewWidth == rcss::pcom::NORMAL ) @@ -1636,7 +1705,7 @@ Player::change_view( rcss::pcom::VIEW_WIDTH viewWidth, else { M_visible_angle = DEFAULT_VISIBLE_ANGLE * ( 4.0 / 3.0 ); // == 2 * sim_step / send_step - M_visual_send_interval = 2; + M_visual_send_interval = (version() >= 18 ? 1 : 2); } } else if ( viewWidth == rcss::pcom::WIDE ) @@ -1649,7 +1718,7 @@ Player::change_view( rcss::pcom::VIEW_WIDTH viewWidth, else { M_visible_angle = DEFAULT_VISIBLE_ANGLE * ( 6.0 / 3.0 ); // == 3 * sim_step / send_step - M_visual_send_interval = 3; + M_visual_send_interval = (version() >= 18 ? 1 : 3); } } else @@ -1699,7 +1768,7 @@ Player::change_view( rcss::pcom::VIEW_WIDTH viewWidth ) else { M_visible_angle = DEFAULT_VISIBLE_ANGLE * ( 2.0 / 3.0 ); // == sim_step / send_step - M_visual_send_interval = 1; + M_visual_send_interval = (version() >= 18 ? 1 : 1); } } else if ( viewWidth == rcss::pcom::NORMAL ) @@ -1712,7 +1781,7 @@ Player::change_view( rcss::pcom::VIEW_WIDTH viewWidth ) else { M_visible_angle = DEFAULT_VISIBLE_ANGLE * ( 4.0 / 3.0 ); // == 2 * sim_step / send_step - M_visual_send_interval = 2; + M_visual_send_interval = (version() >= 18 ? 1 : 2); } } else if ( viewWidth == rcss::pcom::WIDE ) @@ -1725,7 +1794,7 @@ Player::change_view( rcss::pcom::VIEW_WIDTH viewWidth ) else { M_visible_angle = DEFAULT_VISIBLE_ANGLE * ( 6.0 / 3.0 ); // == 3 * sim_step / send_step - M_visual_send_interval = 3; + M_visual_send_interval = (version() >= 18 ? 1 : 3); } } else @@ -1736,6 +1805,11 @@ Player::change_view( rcss::pcom::VIEW_WIDTH viewWidth ) M_view_width = viewWidth; M_high_quality = true; + M_focus_dir = rcss::bound( -M_visible_angle * 0.5, + M_focus_dir, + +M_visible_angle * 0.5 ); + updateFocusPoint(); + ++M_change_view_count; } @@ -2168,15 +2242,15 @@ Player::synch_see() switch ( M_view_width ) { case rcss::pcom::NARROW: M_visible_angle = DEFAULT_VISIBLE_ANGLE * ( 2.0 / 3.0 ); // == sim_step / send_step - M_visual_send_interval = 1; + M_visual_send_interval = (version() >= 18 ? 1 : 1); break; case rcss::pcom::NORMAL: M_visible_angle = DEFAULT_VISIBLE_ANGLE * ( 4.0 / 3.0 ); // == 2 * sim_step / send_step - M_visual_send_interval = 2; + M_visual_send_interval = (version() >= 18 ? 1 : 2); break; case rcss::pcom::WIDE: M_visible_angle = DEFAULT_VISIBLE_ANGLE * ( 6.0 / 3.0 ); // == 3 * sim_step / send_step - M_visual_send_interval = 3; + M_visual_send_interval = (version() >= 18 ? 1 : 3); break; default: return; @@ -2328,6 +2402,7 @@ Player::turnImpl() { M_angle_body_committed = this->M_angle_body; M_angle_neck_committed = this->M_angle_neck; + updateFocusPoint(); M_vel.assign( 0.0, 0.0 ); M_accel.assign( 0.0, 0.0 ); } @@ -2337,6 +2412,14 @@ Player::updateAngle() { M_angle_body_committed = this->M_angle_body; M_angle_neck_committed = this->M_angle_neck; + updateFocusPoint(); +} + +void +Player::updateFocusPoint() +{ + const double focus_angle = normalize_angle( angleBodyCommitted() + angleNeckCommitted() + focusDir() ); + M_focus_point = pos() + PVector::fromPolar( focusDist(), focus_angle ); } void diff --git a/src/player.h b/src/player.h index 3b231e02..f04353c6 100644 --- a/src/player.h +++ b/src/player.h @@ -29,7 +29,7 @@ #include "pcomparser.h" #include "remoteclient.h" #include "serverparam.h" - +#include "heteroplayer.h" #include class Stadium; @@ -139,12 +139,15 @@ class Player double M_consumed_stamina; // - // body/neck angle + // body/neck angle/focus point // - double M_angle_body; //!< temporal body angle + double M_angle_body; //!< temporary body angle double M_angle_body_committed; - double M_angle_neck; //!< temporal neck angle + double M_angle_neck; //!< temporary neck angle double M_angle_neck_committed; + double M_focus_dist; //!< distance to the focus point from the center of the player + double M_focus_dir; //!< direction to the focus point relative to the neck angle + PVector M_focus_point; //!< the global focus position on the pitch // // collision state @@ -172,6 +175,7 @@ class Player int M_catch_count; int M_move_count; int M_turn_neck_count; + int M_change_focus_count; int M_change_view_count; int M_say_count; @@ -188,6 +192,9 @@ class Player double M_long_kick_power; double M_long_kick_dir; + double M_wide_view_angle_noise_term; + double M_normal_view_angle_noise_term; + double M_narrow_view_angle_noise_term; private: // not used Player() = delete; @@ -201,6 +208,7 @@ class Player bool init( const double ver, const bool goalie ); + void initObservationMode(); bool setSenders(); void setEnable(); @@ -257,7 +265,12 @@ class Player double distQStep() const { #ifndef NEW_QSTEP - return ServerParam::instance().quantizeStep(); + double term = narrowViewAngleNoiseTerm(); + if ( viewWidth() == rcss::pcom::VIEW_WIDTH::NORMAL) + term = normalViewAngleNoiseTerm(); + else if ( viewWidth() == rcss::pcom::VIEW_WIDTH::WIDE) + term = wideViewAngleNoiseTerm(); + return ServerParam::instance().quantizeStep() * term; #else return dist_qstep_player; #endif @@ -266,7 +279,12 @@ class Player double landDistQStep() const { #ifndef NEW_QSTEP - return ServerParam::instance().landmarkQuantizeStep(); + double term = narrowViewAngleNoiseTerm(); + if ( viewWidth() == rcss::pcom::VIEW_WIDTH::NORMAL) + term = normalViewAngleNoiseTerm(); + else if ( viewWidth() == rcss::pcom::VIEW_WIDTH::WIDE) + term = wideViewAngleNoiseTerm(); + return ServerParam::instance().landmarkQuantizeStep() * term; #else return land_qstep_player; #endif @@ -275,7 +293,12 @@ class Player double dirQStep() const { #ifndef NEW_QSTEP - return 0.1; + double term = narrowViewAngleNoiseTerm(); + if ( viewWidth() == rcss::pcom::VIEW_WIDTH::NORMAL) + term = normalViewAngleNoiseTerm(); + else if ( viewWidth() == rcss::pcom::VIEW_WIDTH::WIDE) + term = wideViewAngleNoiseTerm(); + return 0.1 * term; #else return dir_qstep_player; #endif @@ -289,6 +312,7 @@ class Player // void setPlayerType( const int ); void substitute( const int ); + const HeteroPlayer * playerType() const { return M_player_type; } int playerTypeId() const { return M_player_type_id; } bool substituted() const { return M_substituted; } @@ -312,6 +336,9 @@ class Player bool highQuality() const { return M_high_quality; } const double & visibleAngle() const { return M_visible_angle; } rcss::pcom::VIEW_WIDTH viewWidth() const { return M_view_width; } + double wideViewAngleNoiseTerm() const { return M_wide_view_angle_noise_term; } + double normalViewAngleNoiseTerm() const { return M_normal_view_angle_noise_term; } + double narrowViewAngleNoiseTerm() const { return M_narrow_view_angle_noise_term; } // // audio sensor @@ -319,8 +346,18 @@ class Player void decrementHearCapacity( const Player & sender ); bool canHearFullFrom( const Player & sender ) const; + // + // body/sensor state + // const double & angleBodyCommitted() const { return M_angle_body_committed; } const double & angleNeckCommitted() const { return M_angle_neck_committed; } + double focusDist() const { return M_focus_dist; } + double focusDir() const { return M_focus_dir; } + const PVector & focusPoint() const { return M_focus_point; } + + // + // update stamina + // void recoverAll(); void recoverStaminaCapacity(); @@ -328,7 +365,7 @@ class Player void updateCapacity(); // - // stamina + // stamina state // const double & stamina() const { return M_stamina; } const double & recovery() const { return M_recovery; } @@ -355,6 +392,7 @@ class Player int catchCount() const { return M_catch_count; } int moveCount() const { return M_move_count; } int turnNeckCount() const { return M_turn_neck_count; } + int changeFocusCount() const { return M_change_focus_count; } int changeViewCount() const { return M_change_view_count; } int sayCount() const { return M_say_count; } @@ -429,6 +467,9 @@ class Player double maxSpeed() const override; private: + + void updateFocusPoint(); + bool parseCommand( const char * command ); int parseEar( const char * command ); @@ -437,6 +478,7 @@ class Player void dash( double power, double dir ) override; void turn( double moment ) override; void turn_neck( double moment ) override; + void change_focus( double moment_dist, double moment_dir) override; void kick( double power, double dir ) override; void long_kick( double power, double dir ) override; void goalieCatch( double dir ) override; @@ -458,7 +500,6 @@ class Player void clang( int min, int max) override; void ear( bool on, rcss::pcom::TEAM team_side, std::string team_name, rcss::pcom::EAR_MODE mode ) override; void synch_see() override; - }; #endif diff --git a/src/player_command_parser.ypp b/src/player_command_parser.ypp index 81228c3b..77119319 100644 --- a/src/player_command_parser.ypp +++ b/src/player_command_parser.ypp @@ -72,6 +72,7 @@ namespace %token RCSS_PCOM_DASH "dash" %token RCSS_PCOM_TURN "turn" %token RCSS_PCOM_TURN_NECK "turn_neck" +%token RCSS_PCOM_CHANGE_FOCUS "change_focus" %token RCSS_PCOM_KICK "kick" %token RCSS_PCOM_LONG_KICK "long_kick" %token RCSS_PCOM_CATCH "catch" @@ -132,6 +133,7 @@ command_list : command command : dash_com | turn_com | turn_neck_com + | change_focus_com | kick_com | long_kick_com | catch_com @@ -173,6 +175,12 @@ turn_neck_com : RCSS_PCOM_LP RCSS_PCOM_TURN_NECK floating_point_number RCSS_PCOM } ; +change_focus_com : RCSS_PCOM_LP RCSS_PCOM_CHANGE_FOCUS floating_point_number floating_point_number RCSS_PCOM_RP + { + BUILDER.change_focus( $< m_double >3, $< m_double >4 ); + } +; + kick_com : RCSS_PCOM_LP RCSS_PCOM_KICK floating_point_number floating_point_number RCSS_PCOM_RP { BUILDER.kick( $< m_double >3, $< m_double >4 ); diff --git a/src/player_command_tok.lpp b/src/player_command_tok.lpp index 19b1c46c..e03e4218 100644 --- a/src/player_command_tok.lpp +++ b/src/player_command_tok.lpp @@ -54,6 +54,7 @@ EXP ({REAL}|{INT})[eE]{INT} dash { return RCSS_PCOM_DASH; } turn { return RCSS_PCOM_TURN; } turn_neck { return RCSS_PCOM_TURN_NECK; } +change_focus { return RCSS_PCOM_CHANGE_FOCUS; } kick { return RCSS_PCOM_KICK; } long_kick { return RCSS_PCOM_LONG_KICK; } catch { return RCSS_PCOM_CATCH; } diff --git a/src/serializer.h b/src/serializer.h index d54d5220..ab4747c5 100644 --- a/src/serializer.h +++ b/src/serializer.h @@ -333,7 +333,7 @@ class SerializerPlayer virtual void serializeVisualBegin( std::ostream &, - const int ) const + const int /*time*/ ) const { } virtual @@ -396,71 +396,6 @@ class SerializerPlayer << ')'; } - void serializeVisualObject( std::ostream & strm, - const std::string & name, - const double & dist, - const int dir, - const bool tackling ) const - { - strm << " (" << name << ' ' << dist << ' ' << dir; - if ( tackling ) - strm << " t"; - strm << ')'; - } - - void serializeVisualObject( std::ostream & strm, - const std::string & name, - const double & dist, - const int dir, - const int point_dir, - const bool tackling ) const - { - strm << " (" << name << ' ' << dist << ' ' << dir - << ' ' << point_dir; - if ( tackling ) - strm << " t"; - strm << ')'; - } - - void serializeVisualObject( std::ostream & strm, - const std::string & name, - const double & dist, - const int dir, - const double & dist_chg, - const double & dir_chg, - const int body_dir, - const int head_dir, - const bool tackling ) const - { - strm << " (" << name << ' ' << dist << ' ' << dir - << ' ' << dist_chg << ' ' << dir_chg - << ' ' << body_dir << ' ' << head_dir; - if ( tackling ) - strm << " t"; - strm << ')'; - } - - void serializeVisualObject( std::ostream & strm, - const std::string & name, - const double & dist, - const int dir, - const double & dist_chg, - const double & dir_chg, - const int body_dir, - const int head_dir, - const int point_dir, - const bool tackling ) const - { - strm << " (" << name << ' ' << dist << ' ' << dir - << ' ' << dist_chg << ' ' << dir_chg - << ' ' << body_dir << ' ' << head_dir - << ' ' << point_dir; - if ( tackling ) - strm << " t"; - strm << ')'; - } - - virtual void serializeVisualPlayer( std::ostream &, /* strm */ const Player &, /* player */ @@ -503,7 +438,6 @@ class SerializerPlayer const int /* point_dir */ ) const { } - virtual void serializeBodyBegin( std::ostream &, const int ) const @@ -539,17 +473,7 @@ class SerializerPlayer virtual void serializeBodyCounts( std::ostream &, - const int, - const int, - const int, - const int ) const - { } - - virtual - void serializeBodyCounts( std::ostream &, - const int, - const int, - const int ) const + const Player & ) const { } virtual @@ -557,11 +481,6 @@ class SerializerPlayer const int ) const { } - virtual - void serializeNeckCount( std::ostream &, - const int ) const - { } - virtual void serializeArm( std::ostream &, const int, @@ -604,6 +523,11 @@ class SerializerPlayer const Player & ) const { } + virtual + void serializeFocusPoint( std::ostream &, + const Player & ) const + { } + virtual void serializeFSBegin( std::ostream &, const int ) const @@ -626,15 +550,33 @@ class SerializerPlayer virtual void serializeFSCounts( std::ostream &, - const int, - const int, - const int, - const int, - const int, - const int, - const int, - const int ) const - { } + const Player & ) const + { } + + // virtual + // void serializeFSCounts( std::ostream &, + // const int, + // const int, + // const int, + // const int, + // const int, + // const int, + // const int, + // const int ) const + // { } + + // virtual + // void serializeFSCounts( std::ostream &, + // const int, + // const int, + // const int, + // const int, + // const int, + // const int, + // const int, + // const int, + // const int ) const + // { } virtual void serializeFSScore( std::ostream &, @@ -656,18 +598,23 @@ class SerializerPlayer const int, const bool, const int, - const double &, - const double &, - const double &, - const double &, - const double &, - const double & ) const + const double & /* x */, + const double & /* y */, + const double & /* vx */, + const double & /* vy */ , + const double & /* body */ , + const double & /* neck */ ) const + { } + + virtual + void serializeFSPlayerFocus( std::ostream &, + const Player & ) const { } virtual void serializeFSPlayerArm( std::ostream &, - const double &, - const double & ) const + const double & /* point_dist */, + const double & /* point_dir */ ) const { } virtual @@ -780,7 +727,7 @@ class SerializerCoach virtual void serializeVisualBegin( std::ostream &, - const int ) const + const int /*time*/ ) const { } virtual @@ -839,29 +786,27 @@ class SerializerCoach const bool ) const { } - virtual void serializeVisualPlayer( std::ostream &, const Player &, - const std::string &, - const PVector &, - const PVector &, - const int, - const int ) const + const std::string & /*name*/, + const PVector & /*pos*/, + const PVector & /*vel*/, + const int /*body*/, + const int /*neck*/ ) const { } virtual void serializeVisualPlayer( std::ostream &, const Player &, - const std::string &, - const PVector &, - const PVector &, - const int, - const int, - const int ) const + const std::string & /*name*/, + const PVector & /*pos*/, + const PVector & /*vel*/, + const int /*body*/, + const int /*neck*/, + const int /*point_dir*/) const { } - virtual void serializeOKEye( std::ostream &, const bool ) const @@ -1053,7 +998,6 @@ class SerializerOnlineCoach point_dir ); } - }; @@ -1146,6 +1090,10 @@ class SerializerMonitor const Player & ) const { } virtual + void serializePlayerFocusPoint( std::ostream &, + const Player & ) const + { } + virtual void serializePlayerStamina( std::ostream &, const Player & ) const { } diff --git a/src/serializercoachstdv14.cpp b/src/serializercoachstdv14.cpp index 3614920b..eaec2b7c 100644 --- a/src/serializercoachstdv14.cpp +++ b/src/serializercoachstdv14.cpp @@ -138,6 +138,7 @@ RegHolder v14 = SerializerCoach::factory().autoReg( &SerializerCoachStdv14::crea RegHolder v15 = SerializerCoach::factory().autoReg( &SerializerCoachStdv14::create, 15 ); RegHolder v16 = SerializerCoach::factory().autoReg( &SerializerCoachStdv14::create, 16 ); RegHolder v17 = SerializerCoach::factory().autoReg( &SerializerCoachStdv14::create, 17 ); +RegHolder v18 = SerializerCoach::factory().autoReg( &SerializerCoachStdv14::create, 18 ); } } diff --git a/src/serializercommonstdv8.cpp b/src/serializercommonstdv8.cpp index f6d6332e..52d74454 100644 --- a/src/serializercommonstdv8.cpp +++ b/src/serializercommonstdv8.cpp @@ -110,6 +110,7 @@ RegHolder v14 = SerializerCommon::factory().autoReg( &SerializerCommonStdv8::cre RegHolder v15 = SerializerCommon::factory().autoReg( &SerializerCommonStdv8::create, 15 ); RegHolder v16 = SerializerCommon::factory().autoReg( &SerializerCommonStdv8::create, 16 ); RegHolder v17 = SerializerCommon::factory().autoReg( &SerializerCommonStdv8::create, 17 ); +RegHolder v18 = SerializerCommon::factory().autoReg( &SerializerCommonStdv8::create, 18 ); } } diff --git a/src/serializermonitor.cpp b/src/serializermonitor.cpp index 444b7c47..736eab62 100644 --- a/src/serializermonitor.cpp +++ b/src/serializermonitor.cpp @@ -353,6 +353,66 @@ SerializerMonitorStdv4::serializePlayerStamina( std::ostream & os, << player.staminaCapacity() << ')'; } +/* +//=================================================================== +// +// SerializerMonitorStdv5 +// +//=================================================================== +*/ + +SerializerMonitorStdv5::SerializerMonitorStdv5( const SerializerCommon::Ptr common ) + : SerializerMonitorStdv4( common ) +{ + +} + +SerializerMonitorStdv5::~SerializerMonitorStdv5() +{ + +} + +const +SerializerMonitor::Ptr +SerializerMonitorStdv5::create() +{ + SerializerCommon::Creator cre_common; + if ( ! SerializerCommon::factory().getCreator( cre_common, 18 ) ) + { + return SerializerMonitor::Ptr(); + } + + SerializerMonitor::Ptr ptr( new SerializerMonitorStdv5( cre_common() ) ); + return ptr; +} + +void +SerializerMonitorStdv5::serializePlayerCounts( std::ostream & os, + const Player & player ) const +{ + os << " (c " + << player.kickCount() << ' ' + << player.dashCount() << ' ' + << player.turnCount() << ' ' + << player.catchCount() << ' ' + << player.moveCount() << ' ' + << player.turnNeckCount() << ' ' + << player.changeViewCount() << ' ' + << player.sayCount() << ' ' + << player.tackleCount() << ' ' + << player.arm().getCounter() << ' ' + << player.attentiontoCount() << ' ' + << player.changeFocusCount() << ')'; +} + +void +SerializerMonitorStdv5::serializePlayerFocusPoint( std::ostream & os, + const Player & player ) const +{ + os << " (fp " + << Quantize( player.focusDist(), PREC ) << ' ' + << Quantize( Rad2Deg( player.focusDir() ), PREC ) << ')'; +} /* //=================================================================== // @@ -681,6 +741,26 @@ void SerializerMonitorJSON::serializePlayerViewMode( std::ostream & os, } +void +SerializerMonitorJSON::serializePlayerFocusPoint( std::ostream & os, + const Player & player ) const +{ + os << ','; +#ifdef USE_FLAT_STYLE + os << std::quoted( "fdist" ) << ':' << Quantize( player.focusDist(), POS_PREC ) + << ',' + << std::quoted( "fdir" ) << ':' << Quantize( Rad2Deg( player.focusDir() ), DIR_PREC ); +#else + os << std::quoted( "focus_point" ) << ':' + << '{' + << std::quoted( "dist" ) << ':' << Quantize( player.focusDist(), POS_PREC ) + << ',' + << std::quoted( "dir" ) << ':' << Quantize( Rad2Deg( player.focusDir() ), DIR_PREC ); + << '}'; +#endif +} + + void SerializerMonitorJSON::serializePlayerStamina( std::ostream & os, const Player & player ) const @@ -716,7 +796,7 @@ void SerializerMonitorJSON::serializePlayerFocus( std::ostream & os, && player.getFocusTarget() ) { os << ','; -#if 1 +#ifdef USE_FLAT_STYLE os << std::quoted( "fside" ) << ':' << std::quoted( to_string( player.getFocusTarget()->side() ) ) << ',' << std::quoted( "fnum" ) << ':' << player.getFocusTarget()->unum(); @@ -775,6 +855,8 @@ SerializerMonitorJSON::serializePlayerCounts( std::ostream & os, << std::quoted( "pointto" ) << ':' << player.arm().getCounter() << ',' << std::quoted( "attentionto" ) << ':' << player.attentiontoCount() + << ',' + << std::quoted( "change_focus" ) << ':' << player.changeFocusCount() << '}'; #endif } @@ -864,7 +946,9 @@ RegHolder v1 = SerializerMonitor::factory().autoReg( &SerializerMonitorStdv1::cr RegHolder v2 = SerializerMonitor::factory().autoReg( &SerializerMonitorStdv1::create, 2 ); RegHolder v3 = SerializerMonitor::factory().autoReg( &SerializerMonitorStdv3::create, 3 ); RegHolder v4 = SerializerMonitor::factory().autoReg( &SerializerMonitorStdv4::create, 4 ); -RegHolder v5 = SerializerMonitor::factory().autoReg( &SerializerMonitorJSON::create, 5 ); +RegHolder v5 = SerializerMonitor::factory().autoReg( &SerializerMonitorStdv5::create, 5 ); +RegHolder vjson = SerializerMonitor::factory().autoReg( &SerializerMonitorJSON::create, -1 ); + } } diff --git a/src/serializermonitor.h b/src/serializermonitor.h index 19291e95..0c38be96 100644 --- a/src/serializermonitor.h +++ b/src/serializermonitor.h @@ -163,6 +163,35 @@ class SerializerMonitorStdv4 }; +/*! + \class SerializerMonitorStdv5 + \brief class of the version 5 serialization for monitors. Add the focus point information. +*/ +class SerializerMonitorStdv5 + : public SerializerMonitorStdv4 { +protected: + + explicit + SerializerMonitorStdv5( const SerializerCommon::Ptr common ); + +public: + + virtual + ~SerializerMonitorStdv5() override; + + static + const + Ptr create(); + + virtual + void serializePlayerCounts( std::ostream & os, + const Player & player ) const override; + virtual + void serializePlayerFocusPoint( std::ostream & os, + const Player & player ) const override; +}; + + /*! \class SerializerMonitorJSON \brief class of the version 5 serialization for monitors. (JSON format) @@ -238,6 +267,10 @@ class SerializerMonitorJSON void serializePlayerViewMode( std::ostream & os, const Player & player ) const override; + virtual + void serializePlayerFocusPoint( std::ostream & os, + const Player & player ) const override; + virtual void serializePlayerStamina( std::ostream & os, const Player & player ) const override; diff --git a/src/serializeronlinecoachstdv14.cpp b/src/serializeronlinecoachstdv14.cpp index 5c1abce3..50daec3b 100644 --- a/src/serializeronlinecoachstdv14.cpp +++ b/src/serializeronlinecoachstdv14.cpp @@ -64,6 +64,7 @@ RegHolder v14 = SerializerOnlineCoach::factory().autoReg( &SerializerOnlineCoach RegHolder v15 = SerializerOnlineCoach::factory().autoReg( &SerializerOnlineCoachStdv14::create, 15 ); RegHolder v16 = SerializerOnlineCoach::factory().autoReg( &SerializerOnlineCoachStdv14::create, 16 ); RegHolder v17 = SerializerOnlineCoach::factory().autoReg( &SerializerOnlineCoachStdv14::create, 17 ); +RegHolder v18 = SerializerOnlineCoach::factory().autoReg( &SerializerOnlineCoachStdv14::create, 18 ); } } diff --git a/src/serializerplayerstdv1.cpp b/src/serializerplayerstdv1.cpp index 83cc100c..61825f13 100644 --- a/src/serializerplayerstdv1.cpp +++ b/src/serializerplayerstdv1.cpp @@ -26,6 +26,7 @@ #include "serializerplayerstdv1.h" #include "param.h" +#include "player.h" #include @@ -152,27 +153,44 @@ SerializerPlayerStdv1::serializeBodyVelocity( std::ostream & strm, void SerializerPlayerStdv1::serializeBodyCounts( std::ostream & strm, - const int count_kick, - const int count_dash, - const int count_turn, - const int count_say ) const -{ - strm << " (kick " << count_kick << ')' - << " (dash " << count_dash << ')' - << " (turn " << count_turn << ')' - << " (say " << count_say << ')'; -} - -void -SerializerPlayerStdv1::serializeBodyCounts( std::ostream & strm, - const int count_catch, - const int count_move, - const int count_change_view ) const -{ - strm << " (catch " << count_catch << ')' - << " (move " << count_move << ')' - << " (change_view " << count_change_view << ')'; -} + const Player & self ) const +{ + strm << " (kick " << self.kickCount() << ')' + << " (dash " << self.dashCount() << ')' + << " (turn " << self.turnCount() << ')' + << " (say " << self.sayCount() << ')'; +} + +// void +// SerializerPlayerStdv1::serializeBodyCounts( std::ostream & strm, +// const int count_kick, +// const int count_dash, +// const int count_turn, +// const int count_say ) const +// { +// strm << " (kick " << count_kick << ')' +// << " (dash " << count_dash << ')' +// << " (turn " << count_turn << ')' +// << " (say " << count_say << ')'; +// } + +// void +// SerializerPlayerStdv1::serializeBodyCounts( std::ostream & strm, +// const int count_catch, +// const int count_move, +// const int count_change_view ) const +// { +// strm << " (catch " << count_catch << ')' +// << " (move " << count_move << ')' +// << " (change_view " << count_change_view << ')'; +// } + +// void +// SerializerPlayerStdv1::serializeBodyCounts( std::ostream & strm, +// const int count_change_focus ) const +// { +// strm << " (change_focus " << count_change_focus << ')'; +// } void SerializerPlayerStdv1::serializeNeckAngle( std::ostream & strm, @@ -181,13 +199,6 @@ SerializerPlayerStdv1::serializeNeckAngle( std::ostream & strm, strm << " (head_angle " << ang << ')'; } -void -SerializerPlayerStdv1::serializeNeckCount( std::ostream & strm, - const int count_turn_neck ) const -{ - strm << " (turn_neck " << count_turn_neck << ')'; -} - void SerializerPlayerStdv1::serializeArm( std::ostream & strm, const int movable_cycles, @@ -437,8 +448,6 @@ RegHolder v1 = SerializerPlayer::factory().autoReg( &SerializerPlayerStdv1::crea RegHolder v2 = SerializerPlayer::factory().autoReg( &SerializerPlayerStdv1::create, 2 ); RegHolder v3 = SerializerPlayer::factory().autoReg( &SerializerPlayerStdv1::create, 3 ); RegHolder v4 = SerializerPlayer::factory().autoReg( &SerializerPlayerStdv1::create, 4 ); -RegHolder v5 = SerializerPlayer::factory().autoReg( &SerializerPlayerStdv1::create, 5 ); -RegHolder v6 = SerializerPlayer::factory().autoReg( &SerializerPlayerStdv1::create, 6 ); } } diff --git a/src/serializerplayerstdv1.h b/src/serializerplayerstdv1.h index c598f115..b3502db4 100644 --- a/src/serializerplayerstdv1.h +++ b/src/serializerplayerstdv1.h @@ -105,25 +105,12 @@ class SerializerPlayerStdv1 virtual void serializeBodyCounts( std::ostream & strm, - const int count_kick, - const int count_dash, - const int count_turn, - const int count_say ) const override; - - virtual - void serializeBodyCounts( std::ostream & strm, - const int count_catch, - const int count_move, - const int count_change_view ) const override; + const Player & self ) const override; virtual void serializeNeckAngle( std::ostream & strm, const int ang ) const override; - virtual - void serializeNeckCount( std::ostream & strm, - const int count_turn_neck ) const override; - virtual void serializeArm( std::ostream & strm, const int movable_cycles, diff --git a/src/serializerplayerstdv14.cpp b/src/serializerplayerstdv14.cpp index 2ec4e19e..65bb5a7c 100644 --- a/src/serializerplayerstdv14.cpp +++ b/src/serializerplayerstdv14.cpp @@ -44,7 +44,7 @@ void SerializerPlayerStdv14::serializeFoul( std::ostream & strm, const Player & self ) const { - strm << " (foul " + strm << " (foul" << " (charged " << self.foulCycles() << ')'; if ( self.hasRedCard() ) diff --git a/src/serializerplayerstdv18.cpp b/src/serializerplayerstdv18.cpp new file mode 100644 index 00000000..ed02ca7f --- /dev/null +++ b/src/serializerplayerstdv18.cpp @@ -0,0 +1,135 @@ +// -*-c++-*- + +/*************************************************************************** + serializerplayerstdv18.cpp + Class for serializing data to std v14 players + ------------------- + begin : 2022-10-08 + copyright : (C) 2023 by The RoboCup Soccer Server + Maintenance Group. +***************************************************************************/ + +/*************************************************************************** + * * + * 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 3 of the License, or (at your option) any * + * later version. * + * * + ***************************************************************************/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "serializerplayerstdv18.h" + +#include "player.h" + +namespace rcss { + +SerializerPlayerStdv18::SerializerPlayerStdv18( const SerializerCommon::Ptr common ) + : SerializerPlayerStdv14( common ) +{ + +} + +SerializerPlayerStdv18::~SerializerPlayerStdv18() +{ + +} + + +void +SerializerPlayerStdv18::serializeBodyCounts( std::ostream & strm, + const Player & self ) const +{ + SerializerPlayerStdv14::serializeBodyCounts( strm, self ); + + strm << " (change_focus " << self.changeFocusCount() << ')'; +} + + +void +SerializerPlayerStdv18::serializeFSCounts( std::ostream & strm, + const Player & self ) const +{ + strm << " (count " + << self.kickCount() << ' ' + << self.dashCount() << ' ' + << self.turnCount() << ' ' + << self.catchCount() << ' ' + << self.moveCount() << ' ' + << self.turnNeckCount() << ' ' + << self.changeViewCount() << ' ' + << self.sayCount() << ' ' + << self.changeFocusCount() << ')'; +} + + +// void +// SerializerPlayerStdv18::serializeFSCounts( std::ostream & strm, +// const int count_kick, +// const int count_dash, +// const int count_turn, +// const int count_catch, +// const int count_move, +// const int count_turn_neck, +// const int count_change_view, +// const int count_say, +// const int count_change_focus) const +// { +// strm << " (count " +// << count_kick << ' ' +// << count_dash << ' ' +// << count_turn << ' ' +// << count_catch << ' ' +// << count_move << ' ' +// << count_turn_neck << ' ' +// << count_change_view << ' ' +// << count_say << ' ' +// << count_change_focus +// << ')'; +// } + +void +SerializerPlayerStdv18::serializeFocusPoint( std::ostream & strm, + const Player & self ) const +{ + strm << " (focus_point " + << self.focusDist()<< " " + << Rad2Deg( self.focusDir() ); + + strm << ')'; +} + +void +SerializerPlayerStdv18::serializeFSPlayerFocus( std::ostream & strm, + const Player & p ) const + +{ + strm << " (focus_point " + << p.focusDist() << ' ' + << Rad2Deg( p.focusDir() ) + << ')'; +} + +const +SerializerPlayer::Ptr +SerializerPlayerStdv18::create() +{ + SerializerCommon::Creator cre; + if ( ! SerializerCommon::factory().getCreator( cre, 18 ) ) + { + return SerializerPlayer::Ptr(); + } + + SerializerPlayer::Ptr ptr( new SerializerPlayerStdv18( cre() ) ); + return ptr; +} + +namespace { +RegHolder v18 = SerializerPlayer::factory().autoReg( &SerializerPlayerStdv18::create, 18 ); +} + +} diff --git a/src/serializerplayerstdv18.h b/src/serializerplayerstdv18.h new file mode 100644 index 00000000..13c2f3b2 --- /dev/null +++ b/src/serializerplayerstdv18.h @@ -0,0 +1,72 @@ +// -*-c++-*- + +/*************************************************************************** + serializerplayerstdv18.h + Class for serializing data to std v18 players + ------------------- + begin : 2022-10-08 + copyright : (C) 2022 by The RoboCup Soccer Server + Maintenance Group. +***************************************************************************/ + +/*************************************************************************** + * * + * 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 3 of the License, or (at your option) any * + * later version. * + * * + ***************************************************************************/ + +#ifndef SERIALIZERPLAYERSTDV18_H +#define SERIALIZERPLAYERSTDV18_H + +#include "serializerplayerstdv14.h" + +namespace rcss { + +class SerializerPlayerStdv18 + : public SerializerPlayerStdv14 { +protected: + SerializerPlayerStdv18( const SerializerCommon::Ptr common ); + +public: + virtual + ~SerializerPlayerStdv18() override; + + static + const + SerializerPlayer::Ptr create(); + + virtual + void serializeBodyCounts( std::ostream &, + const Player & ) const override; + + virtual + void serializeFSCounts( std::ostream & strm, + const Player & self ) const override; + // virtual + // void serializeFSCounts( std::ostream & strm, + // const int count_kick, + // const int count_dash, + // const int count_turn, + // const int count_catch, + // const int count_move, + // const int count_turn_neck, + // const int count_change_view, + // const int count_say, + // const int count_change_focus) const override; + + virtual + void serializeFocusPoint( std::ostream & strm, + const Player & self ) const override; + + virtual + void serializeFSPlayerFocus( std::ostream & strm, + const Player & p ) const override; + +}; + +} + +#endif diff --git a/src/serializerplayerstdv5.cpp b/src/serializerplayerstdv5.cpp new file mode 100644 index 00000000..ec5001fd --- /dev/null +++ b/src/serializerplayerstdv5.cpp @@ -0,0 +1,72 @@ +// -*-c++-*- + +/*************************************************************************** + serializerplayerstdv5.cpp + Class for serializing data to std v5 players + ------------------- + begin : 2023-01-27 + copyright : (C) 2023 by The RoboCup Soccer Server + Maintenance Group. +***************************************************************************/ + +/*************************************************************************** + * * + * 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 3 of the License, or (at your option) any * + * later version. * + * * + ***************************************************************************/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "serializerplayerstdv5.h" + +#include "player.h" + +namespace rcss { + +SerializerPlayerStdv5::SerializerPlayerStdv5( const SerializerCommon::Ptr common ) + : SerializerPlayerStdv1( common ) +{ + +} + +SerializerPlayerStdv5::~SerializerPlayerStdv5() +{ + +} + + +void +SerializerPlayerStdv5::serializeBodyCounts( std::ostream & strm, + const Player & self ) const +{ + SerializerPlayerStdv1::serializeBodyCounts( strm, self ); + + strm << " (turn_neck " << self.turnNeckCount() << ')'; +} + +const +SerializerPlayer::Ptr +SerializerPlayerStdv5::create() +{ + SerializerCommon::Creator cre; + if ( ! SerializerCommon::factory().getCreator( cre, 5 ) ) + { + return SerializerPlayer::Ptr(); + } + + SerializerPlayer::Ptr ptr( new SerializerPlayerStdv5( cre() ) ); + return ptr; +} + +namespace { +RegHolder v5 = SerializerPlayer::factory().autoReg( &SerializerPlayerStdv5::create, 5 ); +RegHolder v6 = SerializerPlayer::factory().autoReg( &SerializerPlayerStdv5::create, 6 ); + +} + +} diff --git a/src/serializerplayerstdv5.h b/src/serializerplayerstdv5.h new file mode 100644 index 00000000..55ce1899 --- /dev/null +++ b/src/serializerplayerstdv5.h @@ -0,0 +1,51 @@ +// -*-c++-*- + +/*************************************************************************** + serializerplayerstdv5.h + Class for serializing data to std v5 players + ------------------- + begin : 2023-01-27 + copyright : (C) 2023 by The RoboCup Soccer Server + Maintenance Group. +***************************************************************************/ + +/*************************************************************************** + * * + * 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 3 of the License, or (at your option) any * + * later version. * + * * + ***************************************************************************/ + + +#ifndef SERIALIZERPLAYERSTDV5_H +#define SERIALIZERPLAYERSTDV5_H + +#include "serializerplayerstdv1.h" + +namespace rcss { + +class SerializerPlayerStdv5 + : public SerializerPlayerStdv1 { +protected: + explicit + SerializerPlayerStdv5( const SerializerCommon::Ptr common ); + +public: + virtual + ~SerializerPlayerStdv5() override; + + static + const + Ptr create(); + + virtual + void serializeBodyCounts( std::ostream &, + const Player & ) const override; + +}; + +} + +#endif diff --git a/src/serializerplayerstdv7.cpp b/src/serializerplayerstdv7.cpp index 97e723ed..540a72d6 100644 --- a/src/serializerplayerstdv7.cpp +++ b/src/serializerplayerstdv7.cpp @@ -25,12 +25,14 @@ #include "serializerplayerstdv7.h" +#include "player.h" + #include namespace rcss { SerializerPlayerStdv7::SerializerPlayerStdv7( const SerializerCommon::Ptr common ) - : SerializerPlayerStdv1( common ) + : SerializerPlayerStdv5( common ) { } @@ -168,6 +170,17 @@ SerializerPlayerStdv7::serializeChangePlayer( std::ostream & strm, << unum << ' ' << type << ')'; } +void +SerializerPlayerStdv7::serializeBodyCounts( std::ostream & strm, + const Player & self ) const +{ + SerializerPlayerStdv5::serializeBodyCounts( strm, self ); + strm << " (catch " << self.catchCount() << ')' + << " (move " << self.moveCount() << ')' + << " (change_view " << self.changeViewCount() << ')'; +} + + const SerializerPlayer::Ptr SerializerPlayerStdv7::create() diff --git a/src/serializerplayerstdv7.h b/src/serializerplayerstdv7.h index dff8d340..976120b7 100644 --- a/src/serializerplayerstdv7.h +++ b/src/serializerplayerstdv7.h @@ -22,12 +22,12 @@ #ifndef SERIALIZERPLAYERSTDV7_H #define SERIALIZERPLAYERSTDV7_H -#include "serializerplayerstdv1.h" +#include "serializerplayerstdv5.h" namespace rcss { class SerializerPlayerStdv7 - : public SerializerPlayerStdv1 { + : public SerializerPlayerStdv5 { protected: explicit SerializerPlayerStdv7( const SerializerCommon::Ptr common ); @@ -111,6 +111,10 @@ class SerializerPlayerStdv7 const int unum, const int type ) const; + virtual + void serializeBodyCounts( std::ostream &, + const Player & ) const override; + }; } diff --git a/src/serializerplayerstdv8.cpp b/src/serializerplayerstdv8.cpp index 24b92057..47139f3c 100644 --- a/src/serializerplayerstdv8.cpp +++ b/src/serializerplayerstdv8.cpp @@ -219,26 +219,41 @@ SerializerPlayerStdv8::serializeFSPlayerStamina( std::ostream & strm, void SerializerPlayerStdv8::serializeFSCounts( std::ostream & strm, - const int count_kick, - const int count_dash, - const int count_turn, - const int count_catch, - const int count_move, - const int count_turn_neck, - const int count_change_view, - const int count_say ) const + const Player & self ) const { strm << " (count " - << count_kick << ' ' - << count_dash << ' ' - << count_turn << ' ' - << count_catch << ' ' - << count_move << ' ' - << count_turn_neck << ' ' - << count_change_view << ' ' - << count_say << ')'; + << self.kickCount() << ' ' + << self.dashCount() << ' ' + << self.turnCount() << ' ' + << self.catchCount() << ' ' + << self.moveCount() << ' ' + << self.turnNeckCount() << ' ' + << self.changeViewCount() << ' ' + << self.sayCount() << ')'; } +// void +// SerializerPlayerStdv8::serializeFSCounts( std::ostream & strm, +// const int count_kick, +// const int count_dash, +// const int count_turn, +// const int count_catch, +// const int count_move, +// const int count_turn_neck, +// const int count_change_view, +// const int count_say ) const +// { +// strm << " (count " +// << count_kick << ' ' +// << count_dash << ' ' +// << count_turn << ' ' +// << count_catch << ' ' +// << count_move << ' ' +// << count_turn_neck << ' ' +// << count_change_view << ' ' +// << count_say << ')'; +// } + void SerializerPlayerStdv8::serializeServerParamBegin( std::ostream & strm ) const { diff --git a/src/serializerplayerstdv8.h b/src/serializerplayerstdv8.h index d12011b3..023c3ed0 100644 --- a/src/serializerplayerstdv8.h +++ b/src/serializerplayerstdv8.h @@ -135,14 +135,18 @@ class SerializerPlayerStdv8 virtual void serializeFSCounts( std::ostream & strm, - const int count_kick, - const int count_dash, - const int count_turn, - const int count_catch, - const int count_move, - const int count_turn_neck, - const int count_change_view, - const int count_say ) const override; + const Player & self ) const override; + + // virtual + // void serializeFSCounts( std::ostream & strm, + // const int count_kick, + // const int count_dash, + // const int count_turn, + // const int count_catch, + // const int count_move, + // const int count_turn_neck, + // const int count_change_view, + // const int count_say ) const override; virtual void serializeServerParamBegin( std::ostream & strm ) const override; diff --git a/src/stadium.cpp b/src/stadium.cpp index b5168216..60a7e3c9 100644 --- a/src/stadium.cpp +++ b/src/stadium.cpp @@ -628,6 +628,7 @@ Stadium::initPlayer( const char * teamname, player->setEnforceDedicatedPort( version >= 8.0 ); player->sendInit(); + player->initObservationMode(); return player; } @@ -2799,9 +2800,17 @@ Stadium::parseMonitorInit( const char * message, delete mon; return true; } - std::cout << "A new (v" << ver << ") monitor connected." << std::endl; - mon->setEnforceDedicatedPort( ver >= 2.0 ); + if ( ver < 0 ) + { + std::cout << "A new (json) monitor connected." << std::endl; + } + else + { + std::cout << "A new (v" << ver << ") monitor connected." << std::endl; + } + + mon->setEnforceDedicatedPort( ver < 0 || ver >= 2.0 ); M_monitors.push_back( mon ); // send server parameter information to monitor diff --git a/src/types.h b/src/types.h index 91d5c778..37da7382 100644 --- a/src/types.h +++ b/src/types.h @@ -201,8 +201,8 @@ const int REC_VERSION_3 = 3; const int REC_VERSION_4 = 4; const int REC_VERSION_5 = 5; const int REC_VERSION_6 = 6; -const int REC_VERSION_JSON = REC_VERSION_6; -const int DEFAULT_REC_VERSION = REC_VERSION_5; +const int REC_VERSION_JSON = -1; +const int DEFAULT_REC_VERSION = REC_VERSION_6; enum DispInfoMode { NO_INFO = 0, diff --git a/src/visualsendercoach.cpp b/src/visualsendercoach.cpp index ef88fbab..8911d20f 100644 --- a/src/visualsendercoach.cpp +++ b/src/visualsendercoach.cpp @@ -370,6 +370,7 @@ RegHolder vc14 = VisualSenderCoach::factory().autoReg( &create< VisualSenderCoac RegHolder vc15 = VisualSenderCoach::factory().autoReg( &create< VisualSenderCoachV13 >, 15 ); RegHolder vc16 = VisualSenderCoach::factory().autoReg( &create< VisualSenderCoachV13 >, 16 ); RegHolder vc17 = VisualSenderCoach::factory().autoReg( &create< VisualSenderCoachV13 >, 17 ); +RegHolder vc18 = VisualSenderCoach::factory().autoReg( &create< VisualSenderCoachV13 >, 18 ); } } diff --git a/src/visualsenderplayer.cpp b/src/visualsenderplayer.cpp index 2c84c073..c8aabe5b 100644 --- a/src/visualsenderplayer.cpp +++ b/src/visualsenderplayer.cpp @@ -107,20 +107,6 @@ VisualSenderPlayerV1::sendVisual() } 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(); @@ -407,6 +393,7 @@ void VisualSenderPlayerV1::sendHighPlayer( const Player & player ) { const double ang = calcRadDir( player ); + //const double un_quant_dist = calcUnQuantDist( player ); double un_quant_dist = self().pos().distance2( player.pos() ); @@ -873,7 +860,7 @@ VisualSenderPlayerV8::calcPointDir( const Player & player ) // NOTE: This means that 5% of the time it will be outside // of this range. double sigma = self().pos().distance( player.pos() ) - / self().teamTooFarLength(); + / self().playerType()->teamTooFarLength(); // / 60.0; // this should be replaced by the line below. // // / ServerParam::instance().getTeamTooFarLength (); sigma = std::pow( sigma, 4 ); // 4 should be parameterized @@ -1036,6 +1023,304 @@ VisualSenderPlayerV13::~VisualSenderPlayerV13() } +/*! +//=================================================================== +// +// CLASS: VisualSensorPlayerV18 +// +// DESC: Class for the version 13 visual protocol. This version +// introduced the focus point. +// +//=================================================================== +*/ + +VisualSenderPlayerV18::VisualSenderPlayerV18( const Params & params ) + : VisualSenderPlayerV13( params ) +{ + +} + +VisualSenderPlayerV18::~VisualSenderPlayerV18() +{ + +} + +void +VisualSenderPlayerV18::sendLowFlag( const PObject & flag ) +{ + const double ang = calcRadDir( flag ); + const double un_quant_dist = calcUnQuantDist( flag ); + + if ( std::fabs( ang ) < self().visibleAngle() * 0.5 + && un_quant_dist < self().playerType()->flagMaxObservationLength() ) + { + serializer().serializeVisualObject( transport(), + calcName( flag ), + calcDegDir( ang ) ); + } + else if ( un_quant_dist <= self().VISIBLE_DISTANCE ) + { + serializer().serializeVisualObject( transport(), + calcCloseName( flag ), + calcDegDir( ang ) ); + } +} + +void +VisualSenderPlayerV18::sendHighFlag( const PObject & flag ) +{ + const double ang = calcRadDir( flag ); + const double un_quant_dist = calcUnQuantDist( flag ); + const double quant_dist = calcQuantDistFocusPoint( flag, un_quant_dist, self().landDistQStep() ); + + if ( std::fabs( ang ) < self().visibleAngle() * 0.5 + && un_quant_dist < self().playerType()->flagMaxObservationLength() ) + { + double prob = 0.0; + if ( self().playerType()->flagChgTooFarLength() > self().playerType()->flagChgFarLength() ) + { + prob = ( ( quant_dist - self().playerType()->flagChgFarLength() ) + / ( self().playerType()->flagChgTooFarLength() - self().playerType()->flagChgFarLength() ) ); + } + + 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().VISIBLE_DISTANCE ) + { + serializer().serializeVisualObject( transport(), + calcCloseName( flag ), + quant_dist, + calcDegDir( ang ) ); + } +} + + +void +VisualSenderPlayerV18::sendLowBall( const MPObject & ball ) +{ + const double ang = calcRadDir( ball ); + const double un_quant_dist = calcUnQuantDist( ball ); + + if( std::fabs( ang ) < self().visibleAngle() * 0.5 + && un_quant_dist < self().playerType()->ballMaxObservationLength()) + { + serializer().serializeVisualObject( transport(), + calcName( ball ), + calcDegDir( ang ) ); + } + else if( un_quant_dist <= self().VISIBLE_DISTANCE ) + { + serializer().serializeVisualObject( transport(), + calcCloseName( ball ), + calcDegDir( ang ) ); + } +} + + +void +VisualSenderPlayerV18::sendHighBall( const MPObject & ball ) +{ + const double ang = calcRadDir( ball ); + const double un_quant_dist = calcUnQuantDist( ball ); + const double quant_dist = calcQuantDistFocusPoint( ball, + un_quant_dist, + self().distQStep() ); + if ( std::fabs( ang ) < self().visibleAngle() * 0.5 + && un_quant_dist < self().playerType()->ballMaxObservationLength()) + { + double prob = 0.0; + if ( self().playerType()->ballVelTooFarLength() > self().playerType()->ballVelFarLength() ) + { + prob = ( ( quant_dist - self().playerType()->ballVelFarLength() ) + / ( self().playerType()->ballVelTooFarLength() - self().playerType()->ballVelFarLength() ) ); + } + + 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().VISIBLE_DISTANCE ) + { + serializer().serializeVisualObject( transport(), + calcCloseName( ball ), + quant_dist, + calcDegDir( ang ) ); + } +} + + +void +VisualSenderPlayerV18::sendLowPlayer( const Player & player ) +{ + const double ang = calcRadDir( player ); + const double un_quant_dist = calcUnQuantDist( player ); + + if ( std::fabs( ang ) < self().visibleAngle() * 0.5 + && un_quant_dist < self().playerType()->playerMaxObservationLength() ) + { + const double quant_dist = calcQuantDist( un_quant_dist, + self().distQStep() ); + double prob = 0.0; + if ( self().playerType()->teamTooFarLength() > self().playerType()->teamFarLength() ) + { + prob = ( ( quant_dist - self().playerType()->teamFarLength() ) + / ( self().playerType()->teamTooFarLength() - self().playerType()->teamFarLength() ) ); + } + + if ( decide( prob ) ) + { + serializer().serializeVisualObject( transport(), + calcTFarName( player ), + calcDegDir( ang ) ); + } + else + { + prob = 0.0; + if ( self().playerType()->unumTooFarLength() > self().playerType()->unumFarLength() ) + { + prob = ( ( quant_dist - self().playerType()->unumFarLength() ) + / ( self().playerType()->unumTooFarLength() - self().playerType()->unumFarLength() ) ); + } + + if ( decide( prob ) ) + { + serializer().serializeVisualObject( transport(), + calcUFarName( player ), + calcDegDir( ang ) ); + } + else + { + serializer().serializeVisualObject( transport(), + calcPlayerName( player ), + calcDegDir( ang ) ); + } + } + } + else if ( un_quant_dist <= self().VISIBLE_DISTANCE ) + { + serializer().serializeVisualObject( transport(), + calcCloseName( player ), + calcDegDir( ang ) ); + } +} + + +void +VisualSenderPlayerV18::sendHighPlayer( const Player & player ) +{ + const double ang = calcRadDir( player ); + const double un_quant_dist = self().pos().distance( player.pos() ); + const double quant_dist = calcQuantDistFocusPoint( player, + un_quant_dist, + self().distQStep() ); + + if ( std::fabs( ang ) < self().visibleAngle() * 0.5 + && un_quant_dist < self().playerType()->playerMaxObservationLength() ) + { + double prob = 0.0; + if ( self().playerType()->teamTooFarLength() > self().playerType()->teamFarLength() ) + { + prob = ( ( quant_dist - self().playerType()->teamFarLength() ) + / ( self().playerType()->teamTooFarLength() - self().playerType()->teamFarLength() ) ); + } + + if ( decide( prob ) ) + { + // no team information + serializer().serializeVisualObject( transport(), + calcTFarName( player ), + quant_dist, + calcDegDir( ang ) ); + } + else + { + prob = 0.0; + if ( self().playerType()->unumTooFarLength() > self().playerType()->unumFarLength() ) + { + prob = ( ( quant_dist - self().playerType()->unumFarLength() ) + / ( self().playerType()->unumTooFarLength() - self().playerType()->unumFarLength() ) ); + } + + if ( decide( prob ) ) + { + // no unum information + serializePlayer( player, + calcUFarName( player ), + quant_dist, + calcDegDir( ang ) ); + } + else + { + double dist_chg, dir_chg; + calcVel( player.vel(), player.pos(), + un_quant_dist, quant_dist, + dist_chg, dir_chg ); + serializePlayer( player, + calcPlayerName( player ), + quant_dist, + calcDegDir( ang ), + dist_chg, + dir_chg ); + } + } + } + else if ( un_quant_dist <= player.VISIBLE_DISTANCE ) + { + serializer().serializeVisualObject( transport(), + calcCloseName( player ), + quant_dist, + calcDegDir( ang ) ); + } +} + +double +VisualSenderPlayerV18::calcQuantDistFocusPoint( const PObject & obj, + const double unquant_dist, + const double qstep ) +{ + const double dist_focus_point = obj.pos().distance( self().focusPoint() ); + const double quant_dist_focus_point = calcQuantDist( dist_focus_point, qstep ); + + return std::max( 0.0, unquant_dist - ( dist_focus_point - quant_dist_focus_point ) ); +} + + /*! //=================================================================== // @@ -1069,6 +1354,7 @@ RegHolder vp14 = VisualSenderPlayer::factory().autoReg( &create< VisualSenderPla RegHolder vp15 = VisualSenderPlayer::factory().autoReg( &create< VisualSenderPlayerV13 >, 15 ); RegHolder vp16 = VisualSenderPlayer::factory().autoReg( &create< VisualSenderPlayerV13 >, 16 ); RegHolder vp17 = VisualSenderPlayer::factory().autoReg( &create< VisualSenderPlayerV13 >, 17 ); +RegHolder vp18 = VisualSenderPlayer::factory().autoReg( &create< VisualSenderPlayerV18 >, 18 ); } } diff --git a/src/visualsenderplayer.h b/src/visualsenderplayer.h index fe968410..b6dae749 100644 --- a/src/visualsenderplayer.h +++ b/src/visualsenderplayer.h @@ -205,17 +205,23 @@ class VisualSenderPlayerV1 private: void sendFlag( const PObject & obj ) { - (this->*M_send_flag)( obj ); + self().highQuality() + ? sendHighFlag( obj ) + : sendLowFlag( obj ); } void sendBall( const MPObject & obj ) { - (this->*M_send_ball)( obj ); + self().highQuality() + ? sendHighBall( obj ) + : sendLowBall( obj ); } void sendPlayer( const Player & obj ) { - (this->*M_send_player)( obj ); + self().highQuality() + ? sendHighPlayer( obj ) + : sendLowPlayer( obj ); } void serializeLine( const std::string & name, @@ -223,8 +229,9 @@ class VisualSenderPlayerV1 const double & sight_2_line_ang, const double & player_2_line ) { - (this->*M_serialize_line)( name, dir, - sight_2_line_ang, player_2_line ); + self().highQuality() + ? serializeHighLine( name, dir, sight_2_line_ang, player_2_line ) + : serializeLowLine( name, dir, sight_2_line_ang, player_2_line ); } void sendFlags(); @@ -235,16 +242,23 @@ class VisualSenderPlayerV1 void sendLines(); +protected: + virtual void sendLowFlag( const PObject & flag ); + virtual void sendHighFlag( const PObject & flag ); + virtual void sendLowBall( const MPObject & ball ); + virtual void sendHighBall( const MPObject & ball ); + virtual void sendLowPlayer( const Player & player ); + virtual void sendHighPlayer( const Player & player ); bool sendLine( const PObject & line ); @@ -270,6 +284,8 @@ class VisualSenderPlayerV1 return rad2Deg( rad_dir ); } +private: + double calcLineRadDir( const double & line_normal ) const { return normalize_angle( line_normal @@ -285,6 +301,7 @@ class VisualSenderPlayerV1 return calcDegDir( sight_2_line_ang + M_PI*0.5 ); } +protected: double calcUnQuantDist( const PObject & obj ) const { return self().pos().distance( obj.pos() ); @@ -380,14 +397,6 @@ class VisualSenderPlayerV1 : obj.fixedNameFar(); } -private: - void (VisualSenderPlayerV1::*M_send_flag)( const PObject & ); - void (VisualSenderPlayerV1::*M_send_ball)( const MPObject & ); - void (VisualSenderPlayerV1::*M_send_player)( const Player & ); - void (VisualSenderPlayerV1::*M_serialize_line)( const std::string &, - const int, - const double &, - const double & ); }; /*! @@ -621,6 +630,50 @@ class VisualSenderPlayerV13 }; + +/*! +//=================================================================== +// +// CLASS: VisualSensorPlayerV18 +// +// DESC: Class for the version 13 visual protocol. This version +// introduced the focus point. +// +//=================================================================== +*/ + +class VisualSenderPlayerV18 + : public VisualSenderPlayerV13 { +public: + VisualSenderPlayerV18( const Params & params ); + + virtual + ~VisualSenderPlayerV18(); + +protected: + + virtual + void sendLowFlag( const PObject & flag ) override; + virtual + void sendHighFlag( const PObject & flag ) override; + + virtual + void sendLowBall( const MPObject & ball ) override; + virtual + void sendHighBall( const MPObject & ball ) override; + + virtual + void sendLowPlayer( const Player & player ) override; + virtual + void sendHighPlayer( const Player & player ) override; + + virtual + double calcQuantDistFocusPoint( const PObject & obj, + const double unquant_dist, + const double q_step ); + +}; + } #endif From 7de0d1270e78b611f7878e450c03478b1f71f932 Mon Sep 17 00:00:00 2001 From: Hidehisa Akiyama <522630+hidehisaakiyama@users.noreply.github.com> Date: Tue, 7 Mar 2023 13:52:26 +0900 Subject: [PATCH 2/5] Update m4 macros. (#111) * Update m4 macros. * Add ax_cxx_compile_stdcxx_17.m4 --- m4/ax_boost_base.m4 | 16 ++++++++-------- m4/ax_cxx_compile_stdcxx.m4 | 31 +++++++++++++++++++++--------- m4/ax_cxx_compile_stdcxx_17.m4 | 35 ++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 17 deletions(-) create mode 100644 m4/ax_cxx_compile_stdcxx_17.m4 diff --git a/m4/ax_boost_base.m4 b/m4/ax_boost_base.m4 index 519f1c9d..b1fed7a5 100644 --- a/m4/ax_boost_base.m4 +++ b/m4/ax_boost_base.m4 @@ -11,9 +11,9 @@ # Test for the Boost C++ libraries of a particular version (or newer) # # If no path to the installed boost library is given the macro searchs -# under /usr, /usr/local, /opt and /opt/local and evaluates the -# $BOOST_ROOT environment variable. Further documentation is available at -# . +# under /usr, /usr/local, /opt, /opt/local and /opt/homebrew and evaluates +# the $BOOST_ROOT environment variable. Further documentation is available +# at . # # This macro calls: # @@ -33,7 +33,7 @@ # and this notice are preserved. This file is offered as-is, without any # warranty. -#serial 49 +#serial 52 # example boost program (need to pass version) m4_define([_AX_BOOST_BASE_PROGRAM], @@ -114,7 +114,7 @@ AC_DEFUN([_AX_BOOST_BASE_RUNDETECT],[ AS_CASE([${host_cpu}], [x86_64],[libsubdirs="lib64 libx32 lib lib64"], [mips*64*],[libsubdirs="lib64 lib32 lib lib64"], - [ppc64|powerpc64|s390x|sparc64|aarch64|ppc64le|powerpc64le|riscv64|e2k],[libsubdirs="lib64 lib lib64"], + [ppc64|powerpc64|s390x|sparc64|aarch64|ppc64le|powerpc64le|riscv64|e2k|loongarch64],[libsubdirs="lib64 lib lib64"], [libsubdirs="lib"] ) @@ -128,7 +128,7 @@ AC_DEFUN([_AX_BOOST_BASE_RUNDETECT],[ ) dnl first we check the system location for boost libraries - dnl this location ist chosen if boost libraries are installed with the --layout=system option + dnl this location is chosen if boost libraries are installed with the --layout=system option dnl or if you install boost with RPM AS_IF([test "x$_AX_BOOST_BASE_boost_path" != "x"],[ AC_MSG_CHECKING([for boostlib >= $1 ($WANT_BOOST_VERSION) includes in "$_AX_BOOST_BASE_boost_path/include"]) @@ -151,7 +151,7 @@ AC_DEFUN([_AX_BOOST_BASE_RUNDETECT],[ else search_libsubdirs="$multiarch_libsubdir $libsubdirs" fi - for _AX_BOOST_BASE_boost_path_tmp in /usr /usr/local /opt /opt/local ; do + for _AX_BOOST_BASE_boost_path_tmp in /usr /usr/local /opt /opt/local /opt/homebrew ; do if test -d "$_AX_BOOST_BASE_boost_path_tmp/include/boost" && test -r "$_AX_BOOST_BASE_boost_path_tmp/include/boost" ; then for libsubdir in $search_libsubdirs ; do if ls "$_AX_BOOST_BASE_boost_path_tmp/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi @@ -227,7 +227,7 @@ AC_DEFUN([_AX_BOOST_BASE_RUNDETECT],[ fi else if test "x$cross_compiling" != "xyes" ; then - for _AX_BOOST_BASE_boost_path in /usr /usr/local /opt /opt/local ; do + for _AX_BOOST_BASE_boost_path in /usr /usr/local /opt /opt/local /opt/homebrew ; do if test -d "$_AX_BOOST_BASE_boost_path" && test -r "$_AX_BOOST_BASE_boost_path" ; then for i in `ls -d $_AX_BOOST_BASE_boost_path/include/boost-* 2>/dev/null`; do _version_tmp=`echo $i | sed "s#$_AX_BOOST_BASE_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'` diff --git a/m4/ax_cxx_compile_stdcxx.m4 b/m4/ax_cxx_compile_stdcxx.m4 index 51a35054..8edf5152 100644 --- a/m4/ax_cxx_compile_stdcxx.m4 +++ b/m4/ax_cxx_compile_stdcxx.m4 @@ -43,7 +43,7 @@ # and this notice are preserved. This file is offered as-is, without any # warranty. -#serial 14 +#serial 18 dnl This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro dnl (serial version number 13). @@ -104,9 +104,18 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl dnl HP's aCC needs +std=c++11 according to: dnl http://h21007.www2.hp.com/portal/download/files/unprot/aCxx/PDF_Release_Notes/769149-001.pdf dnl Cray's crayCC needs "-h std=c++11" + dnl MSVC needs -std:c++NN for C++17 and later (default is C++14) for alternative in ${ax_cxx_compile_alternatives}; do - for switch in -std=c++${alternative} +std=c++${alternative} "-h std=c++${alternative}"; do - cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch]) + for switch in -std=c++${alternative} +std=c++${alternative} "-h std=c++${alternative}" MSVC; do + if test x"$switch" = xMSVC; then + dnl AS_TR_SH maps both `:` and `=` to `_` so -std:c++17 would collide + dnl with -std=c++17. We suffix the cache variable name with _MSVC to + dnl avoid this. + switch=-std:c++${alternative} + cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_${switch}_MSVC]) + else + cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch]) + fi AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch, $cachevar, [ac_save_CXX="$CXX" @@ -189,7 +198,11 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[ #error "This is not a C++ compiler" -#elif __cplusplus < 201103L +// MSVC always sets __cplusplus to 199711L in older versions; newer versions +// only set it correctly if /Zc:__cplusplus is specified as well as a +// /std:c++NN switch: +// https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/ +#elif __cplusplus < 201103L && !defined _MSC_VER #error "This is not a C++11 compiler" @@ -480,7 +493,7 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_14], [[ #error "This is not a C++ compiler" -#elif __cplusplus < 201402L +#elif __cplusplus < 201402L && !defined _MSC_VER #error "This is not a C++14 compiler" @@ -604,7 +617,7 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_17], [[ #error "This is not a C++ compiler" -#elif __cplusplus < 201703L +#elif __cplusplus < 201703L && !defined _MSC_VER #error "This is not a C++17 compiler" @@ -970,7 +983,7 @@ namespace cxx17 } // namespace cxx17 -#endif // __cplusplus < 201703L +#endif // __cplusplus < 201703L && !defined _MSC_VER ]]) @@ -983,7 +996,7 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_20], [[ #error "This is not a C++ compiler" -#elif __cplusplus < 202002L +#elif __cplusplus < 202002L && !defined _MSC_VER #error "This is not a C++20 compiler" @@ -1000,6 +1013,6 @@ namespace cxx20 } // namespace cxx20 -#endif // __cplusplus < 202002L +#endif // __cplusplus < 202002L && !defined _MSC_VER ]]) diff --git a/m4/ax_cxx_compile_stdcxx_17.m4 b/m4/ax_cxx_compile_stdcxx_17.m4 new file mode 100644 index 00000000..a6834171 --- /dev/null +++ b/m4/ax_cxx_compile_stdcxx_17.m4 @@ -0,0 +1,35 @@ +# ============================================================================= +# https://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_17.html +# ============================================================================= +# +# SYNOPSIS +# +# AX_CXX_COMPILE_STDCXX_17([ext|noext], [mandatory|optional]) +# +# DESCRIPTION +# +# Check for baseline language coverage in the compiler for the C++17 +# standard; if necessary, add switches to CXX and CXXCPP to enable +# support. +# +# This macro is a convenience alias for calling the AX_CXX_COMPILE_STDCXX +# macro with the version set to C++17. The two optional arguments are +# forwarded literally as the second and third argument respectively. +# Please see the documentation for the AX_CXX_COMPILE_STDCXX macro for +# more information. If you want to use this macro, you also need to +# download the ax_cxx_compile_stdcxx.m4 file. +# +# LICENSE +# +# Copyright (c) 2015 Moritz Klammler +# Copyright (c) 2016 Krzesimir Nowak +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 2 + +AX_REQUIRE_DEFINED([AX_CXX_COMPILE_STDCXX]) +AC_DEFUN([AX_CXX_COMPILE_STDCXX_17], [AX_CXX_COMPILE_STDCXX([17], [$1], [$2])]) From 6f1f3b6adf8a3eac0d5eade71ca8ce2f7a4149c5 Mon Sep 17 00:00:00 2001 From: Hidehisa Akiyama <522630+hidehisaakiyama@users.noreply.github.com> Date: Tue, 7 Mar 2023 18:07:53 +0900 Subject: [PATCH 3/5] Update to C++17 and replace boost::filesystem with std::filesystem (#112) * Update to C++17. * Replace boost::filesytem with std::filesystem. * Replace the code of file existence checks with std::filesystem::exists. * Remove ax_boost_filesystem.m4 * Update the settings of CircleCI --- .circleci/config.yml | 6 +- CMakeLists.txt | 2 +- configure.ac | 12 +-- m4/ax_boost_filesystem.m4 | 118 ------------------------------ rcss/conf/parser.cpp | 32 ++++---- rcss/conf/parser.hpp | 7 +- rcss/conf/statushandler.cpp | 2 +- rcss/conf/statushandler.hpp | 4 +- rcss/conf/streamstatushandler.cpp | 4 +- rcss/conf/streamstatushandler.hpp | 2 +- rcss/parser.h | 10 +-- src/csvsaver.cpp | 15 ++-- src/logger.cpp | 22 +++--- src/playerparam.cpp | 17 +++-- src/serverparam.cpp | 20 ++--- 15 files changed, 73 insertions(+), 200 deletions(-) delete mode 100644 m4/ax_boost_filesystem.m4 diff --git a/.circleci/config.yml b/.circleci/config.yml index 9562fd62..845b11b1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,7 @@ version: 2 defaults: &defaults working_directory: /home/circleci/rcssserver docker: - - image: ubuntu:xenial + - image: ubuntu-2004 jobs: build: @@ -16,10 +16,10 @@ jobs: command: apt-get update - run: name: Install dependencies - command: apt-get install g++ build-essential libboost-all-dev bison flex -y + command: apt-get install build-essential flex bison libboost-all-dev -y - run: name: Install autotools libraries - command: apt-get install autoconf -y + command: apt-get install autoconf automake libtool -y - run: name: Generate configure file command: | diff --git a/CMakeLists.txt b/CMakeLists.txt index 41f8eff6..3d86cae0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.5.1) project(RCSSServer VERSION 17.0.1) -set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) if(NOT CMAKE_BUILD_TYPE) diff --git a/configure.ac b/configure.ac index 756b8095..890c2096 100644 --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,7 @@ # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. -AC_PREREQ(2.61) +AC_PREREQ([2.69]) LT_PREREQ([2.2]) AC_INIT([RCSSServer],[17.0.1],[https://github.com/rcsoccersim/],[rcssserver]) @@ -70,15 +70,12 @@ AC_STRUCT_TM AC_TYPE_UINT16_T AC_TYPE_UINT32_T AC_TYPE_UINT8_T +AC_CHECK_TYPES([ptrdiff_t]) AC_CHECK_TYPES([socklen_t], [], [], [ #include #include ]) -AC_CHECK_TYPES([size_t], [], [], [ -#include -#include -]) ################################################## @@ -108,7 +105,7 @@ AC_CHECK_FUNCS([memset], [], [ exit 1 ]) AC_CHECK_FUNCS([floor gethostbyname gettimeofday inet_ntoa memset mkdir pow rint]) -AC_CHECK_FUNCS([socket sqrt strdup strerror]) +AC_CHECK_FUNCS([select socket sqrt strdup strerror]) ################################################## # check flex @@ -191,7 +188,7 @@ AC_SUBST(LIBTOOL_DEPS) # check C++ ################################################## -AX_CXX_COMPILE_STDCXX_14(noext) +AX_CXX_COMPILE_STDCXX_17(noext) ################################################## # check boost @@ -199,7 +196,6 @@ AX_CXX_COMPILE_STDCXX_14(noext) AX_BOOST_BASE([1.32.0]) AX_BOOST_SYSTEM -AX_BOOST_FILESYSTEM CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" #OLDLIBS="$LIBS" diff --git a/m4/ax_boost_filesystem.m4 b/m4/ax_boost_filesystem.m4 deleted file mode 100644 index 12f7bc5e..00000000 --- a/m4/ax_boost_filesystem.m4 +++ /dev/null @@ -1,118 +0,0 @@ -# =========================================================================== -# https://www.gnu.org/software/autoconf-archive/ax_boost_filesystem.html -# =========================================================================== -# -# SYNOPSIS -# -# AX_BOOST_FILESYSTEM -# -# DESCRIPTION -# -# Test for Filesystem library from the Boost C++ libraries. The macro -# requires a preceding call to AX_BOOST_BASE. Further documentation is -# available at . -# -# This macro calls: -# -# AC_SUBST(BOOST_FILESYSTEM_LIB) -# -# And sets: -# -# HAVE_BOOST_FILESYSTEM -# -# LICENSE -# -# Copyright (c) 2009 Thomas Porschberg -# Copyright (c) 2009 Michael Tindal -# Copyright (c) 2009 Roman Rybalko -# -# Copying and distribution of this file, with or without modification, are -# permitted in any medium without royalty provided the copyright notice -# and this notice are preserved. This file is offered as-is, without any -# warranty. - -#serial 28 - -AC_DEFUN([AX_BOOST_FILESYSTEM], -[ - AC_ARG_WITH([boost-filesystem], - AS_HELP_STRING([--with-boost-filesystem@<:@=special-lib@:>@], - [use the Filesystem library from boost - it is possible to specify a certain library for the linker - e.g. --with-boost-filesystem=boost_filesystem-gcc-mt ]), - [ - if test "$withval" = "no"; then - want_boost="no" - elif test "$withval" = "yes"; then - want_boost="yes" - ax_boost_user_filesystem_lib="" - else - want_boost="yes" - ax_boost_user_filesystem_lib="$withval" - fi - ], - [want_boost="yes"] - ) - - if test "x$want_boost" = "xyes"; then - AC_REQUIRE([AC_PROG_CC]) - CPPFLAGS_SAVED="$CPPFLAGS" - CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" - export CPPFLAGS - - LDFLAGS_SAVED="$LDFLAGS" - LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" - export LDFLAGS - - LIBS_SAVED=$LIBS - LIBS="$LIBS $BOOST_SYSTEM_LIB" - export LIBS - - AC_CACHE_CHECK(whether the Boost::Filesystem library is available, - ax_cv_boost_filesystem, - [AC_LANG_PUSH([C++]) - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include ]], - [[using namespace boost::filesystem; - path my_path( "foo/bar/data.txt" ); - return 0;]])], - ax_cv_boost_filesystem=yes, ax_cv_boost_filesystem=no) - AC_LANG_POP([C++]) - ]) - if test "x$ax_cv_boost_filesystem" = "xyes"; then - AC_DEFINE(HAVE_BOOST_FILESYSTEM,,[define if the Boost::Filesystem library is available]) - BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'` - if test "x$ax_boost_user_filesystem_lib" = "x"; then - for libextension in `ls -r $BOOSTLIBDIR/libboost_filesystem* 2>/dev/null | sed 's,.*/lib,,' | sed 's,\..*,,'` ; do - ax_lib=${libextension} - AC_CHECK_LIB($ax_lib, exit, - [BOOST_FILESYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_FILESYSTEM_LIB) link_filesystem="yes"; break], - [link_filesystem="no"]) - done - if test "x$link_filesystem" != "xyes"; then - for libextension in `ls -r $BOOSTLIBDIR/boost_filesystem* 2>/dev/null | sed 's,.*/,,' | sed -e 's,\..*,,'` ; do - ax_lib=${libextension} - AC_CHECK_LIB($ax_lib, exit, - [BOOST_FILESYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_FILESYSTEM_LIB) link_filesystem="yes"; break], - [link_filesystem="no"]) - done - fi - else - for ax_lib in $ax_boost_user_filesystem_lib boost_filesystem-$ax_boost_user_filesystem_lib; do - AC_CHECK_LIB($ax_lib, exit, - [BOOST_FILESYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_FILESYSTEM_LIB) link_filesystem="yes"; break], - [link_filesystem="no"]) - done - - fi - if test "x$ax_lib" = "x"; then - AC_MSG_ERROR(Could not find a version of the Boost::Filesystem library!) - fi - if test "x$link_filesystem" != "xyes"; then - AC_MSG_ERROR(Could not link against $ax_lib !) - fi - fi - - CPPFLAGS="$CPPFLAGS_SAVED" - LDFLAGS="$LDFLAGS_SAVED" - LIBS="$LIBS_SAVED" - fi -]) diff --git a/rcss/conf/parser.cpp b/rcss/conf/parser.cpp index 590dae8a..afebe1b8 100644 --- a/rcss/conf/parser.cpp +++ b/rcss/conf/parser.cpp @@ -35,10 +35,6 @@ #include -#include -#include -#include - // #define BOOST_SPIRIT_DEBUG #if BOOST_VERSION >= 103800 # include @@ -229,22 +225,22 @@ Parser::parse( std::istream & strm, } bool -Parser::parse( const boost::filesystem::path & file ) +Parser::parse( const std::filesystem::path & file ) { return rcss::Parser::parse( file ); } bool -Parser::parseCreateConf( const boost::filesystem::path & conf_name, +Parser::parseCreateConf( const std::filesystem::path & conf_name, const std::string & module_name ) { std::string native_path = conf_name.string(); - boost::filesystem::ifstream conf( conf_name ); + std::ifstream conf( conf_name ); if ( ! conf.is_open() ) { m_builder.creatingConfFile( native_path ); - boost::filesystem::ofstream new_conf( conf_name ); + std::ofstream new_conf( conf_name ); if ( new_conf.is_open() ) { m_builder.createConfFile( new_conf, module_name ); @@ -301,17 +297,17 @@ bool Parser::include( const char * begin, const char * end ) { - std::string incname = cleanString( begin, end ); - boost::filesystem::path path; + const std::string incname = cleanString( begin, end ); + std::filesystem::path path; try { - path = boost::filesystem::path( incname ); + path = incname; } catch ( ... ) { try { - path = boost::filesystem::path( incname ); + path = incname; } catch ( const std::exception & e ) { @@ -323,7 +319,7 @@ Parser::include( const char * begin, } } - boost::filesystem::path full_name; + std::filesystem::path full_name; if ( path.has_root_directory() ) { full_name = path; @@ -335,13 +331,13 @@ Parser::include( const char * begin, || curr_path == "cmd line args" || curr_path == "anonymous stream" ) { - full_name = boost::filesystem::absolute( path ); + full_name = std::filesystem::absolute( path ); } else { try { - boost::filesystem::path branch( curr_path ); + std::filesystem::path branch( curr_path ); branch = branch.parent_path(); full_name = branch / path; } @@ -368,11 +364,11 @@ Parser::include( const char * begin, } } - if ( boost::filesystem::exists( full_name ) ) + if ( std::filesystem::exists( full_name ) ) { - if ( ! boost::filesystem::is_directory( full_name ) ) + if ( ! std::filesystem::is_directory( full_name ) ) { - boost::filesystem::ifstream strm( full_name ); + std::ifstream strm( full_name ); if ( strm.is_open() && strm.good() ) { bool rval = parse( strm, diff --git a/rcss/conf/parser.hpp b/rcss/conf/parser.hpp index 8f443081..cf90efb3 100644 --- a/rcss/conf/parser.hpp +++ b/rcss/conf/parser.hpp @@ -24,8 +24,7 @@ #include -#include - +#include #include #include @@ -62,10 +61,10 @@ class Parser const std::string & name ); /// for parsing a file - bool parse( const boost::filesystem::path & name ); + bool parse( const std::filesystem::path & name ); /// for parsing a file and creating it if it doesn't exist - bool parseCreateConf( const boost::filesystem::path & conf_name, + bool parseCreateConf( const std::filesystem::path & conf_name, const std::string & module_name ); private: diff --git a/rcss/conf/statushandler.cpp b/rcss/conf/statushandler.cpp index 59c7852d..7b5a8f50 100644 --- a/rcss/conf/statushandler.cpp +++ b/rcss/conf/statushandler.cpp @@ -108,7 +108,7 @@ StatusHandler::includeFailed( const std::string &, void StatusHandler::loadFailed( const std::string &, const std::string &, - const std::vector< boost::filesystem::path > &, + const std::vector< std::filesystem::path > &, const std::string &, int ) { diff --git a/rcss/conf/statushandler.hpp b/rcss/conf/statushandler.hpp index 379c95c5..5b96ce01 100644 --- a/rcss/conf/statushandler.hpp +++ b/rcss/conf/statushandler.hpp @@ -25,7 +25,7 @@ #include #include -#include +#include namespace rcss { namespace conf { @@ -88,7 +88,7 @@ class StatusHandler { virtual void loadFailed( const std::string & libname, const std::string & error, - const std::vector< boost::filesystem::path > & avail, + const std::vector< std::filesystem::path > & avail, const std::string & name, int lineno ); }; diff --git a/rcss/conf/streamstatushandler.cpp b/rcss/conf/streamstatushandler.cpp index 0bb19871..5e1d234d 100644 --- a/rcss/conf/streamstatushandler.cpp +++ b/rcss/conf/streamstatushandler.cpp @@ -128,7 +128,7 @@ StreamStatusHandler::includeFailed( const std::string & filename, void StreamStatusHandler::loadFailed( const std::string & libname, const std::string & error, - const std::vector< boost::filesystem::path > & avail, + const std::vector< std::filesystem::path > & avail, const std::string & name, int lineno ) { @@ -141,7 +141,7 @@ StreamStatusHandler::loadFailed( const std::string & libname, else { M_errstrm << name << ": " << lineno << ": error: available modules:\n"; - for( std::vector< boost::filesystem::path >::const_iterator i = avail.begin(); + for( std::vector< std::filesystem::path >::const_iterator i = avail.begin(); i != avail.end(); ++i ) { M_errstrm << "\t" << i->string() << std::endl; diff --git a/rcss/conf/streamstatushandler.hpp b/rcss/conf/streamstatushandler.hpp index 4bfcf80c..2279f612 100644 --- a/rcss/conf/streamstatushandler.hpp +++ b/rcss/conf/streamstatushandler.hpp @@ -78,7 +78,7 @@ class StreamStatusHandler virtual void loadFailed( const std::string & libname, const std::string & error, - const std::vector< boost::filesystem::path > & avail, + const std::vector< std::filesystem::path > & avail, const std::string & name, int lineno ); private: diff --git a/rcss/parser.h b/rcss/parser.h index e180d33e..c230ca89 100644 --- a/rcss/parser.h +++ b/rcss/parser.h @@ -22,12 +22,10 @@ #ifndef PARSER_H #define PARSER_H -#include -#include - #include #include #include +#include namespace rcss { @@ -70,15 +68,15 @@ class Parser { return doParse( strm, errstrm ); } - bool parse( const boost::filesystem::path & file ) + bool parse( const std::filesystem::path & file ) { return parse( file, std::cerr ); } - bool parse( const boost::filesystem::path & file, + bool parse( const std::filesystem::path & file, std::ostream & errstrm ) { - boost::filesystem::ifstream strm( file ); + std::ifstream strm( file ); if( ! strm.is_open() ) { diff --git a/src/csvsaver.cpp b/src/csvsaver.cpp index d041df85..61989262 100644 --- a/src/csvsaver.cpp +++ b/src/csvsaver.cpp @@ -27,15 +27,14 @@ #include "utility.h" -#include -#include - #include #include #include +#include #include #include +#include #ifdef __CYGWIN__ // cygwin is not win32 @@ -94,10 +93,10 @@ CSVSaverParam::init( rcss::conf::Builder * parent ) conf_dir = env_conf_dir; } - boost::filesystem::path conf_path; + std::filesystem::path conf_path; try { - conf_path = boost::filesystem::path( tildeExpand( conf_dir ) ); + conf_path = tildeExpand( conf_dir ); conf_path /= "CSVSaver.conf"; } catch ( std::exception & e ) @@ -199,11 +198,11 @@ void CSVSaver::openResultsFile() { bool new_file = false; - boost::filesystem::path file_path; + std::filesystem::path file_path; try { - file_path = boost::filesystem::path( tildeExpand( CSVSaverParam::instance().filename() ) ); - new_file = ! boost::filesystem::exists( file_path ); + file_path = tildeExpand( CSVSaverParam::instance().filename() ); + new_file = ! std::filesystem::exists( file_path ); } catch ( std::exception & e ) { diff --git a/src/logger.cpp b/src/logger.cpp index b42edbf1..2ef2dbee 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -41,12 +41,10 @@ #include "serializercommonstdv8.h" -#include -#include - #include #include +#include #include namespace { @@ -264,9 +262,9 @@ Logger::openGameLog( const Stadium & stadium ) // create the log directory & file path string try { - boost::filesystem::path game_log( ServerParam::instance().gameLogDir() ); - if ( ! boost::filesystem::exists( game_log ) - && ! boost::filesystem::create_directories( game_log ) ) + std::filesystem::path game_log( ServerParam::instance().gameLogDir() ); + if ( ! std::filesystem::exists( game_log ) + && ! std::filesystem::create_directories( game_log ) ) { std::cerr << __FILE__ << ": " << __LINE__ << ": can't create game log directory " << game_log << std::endl; @@ -352,9 +350,9 @@ Logger::openTextLog() // create the log directory & file path string try { - boost::filesystem::path text_log( ServerParam::instance().textLogDir() ); - if ( ! boost::filesystem::exists( text_log ) - && ! boost::filesystem::create_directories( text_log ) ) + std::filesystem::path text_log( ServerParam::instance().textLogDir() ); + if ( ! std::filesystem::exists( text_log ) + && ! std::filesystem::create_directories( text_log ) ) { std::cerr << __FILE__ << ": " << __LINE__ << ": can't create text log directory " << text_log << std::endl; @@ -424,9 +422,9 @@ Logger::openKawayLog() // create the log directory & file path string try { - boost::filesystem::path kaway_log( ServerParam::instance().kawayLogDir() ); - if ( ! boost::filesystem::exists( kaway_log ) - && ! boost::filesystem::create_directories( kaway_log ) ) + std::filesystem::path kaway_log( ServerParam::instance().kawayLogDir() ); + if ( ! std::filesystem::exists( kaway_log ) + && ! std::filesystem::create_directories( kaway_log ) ) { std::cerr << __FILE__ << ": " << __LINE__ << ": can't create keepaway log directory " << kaway_log << std::endl; diff --git a/src/playerparam.cpp b/src/playerparam.cpp index a5496bb7..9dfe3ced 100644 --- a/src/playerparam.cpp +++ b/src/playerparam.cpp @@ -40,13 +40,12 @@ #include #include -#include - #include #include +#include #include #include - +#include #ifdef HAVE_SYS_PARAM_H #include /* needed for htonl, htons, ... */ @@ -65,6 +64,10 @@ #endif #endif +#ifndef RCSS_WIN +#include // close() +#endif + namespace { inline @@ -180,11 +183,11 @@ PlayerParam::init( rcss::conf::Builder * parent ) conf_dir = env_conf_dir; } - boost::filesystem::path conf_path; + std::filesystem::path conf_path; try { - conf_path = boost::filesystem::path( tildeExpand( conf_dir ) ); + conf_path = tildeExpand( conf_dir ); conf_path /= PlayerParam::PLAYER_CONF; } catch ( std::exception & e ) @@ -227,8 +230,8 @@ void PlayerParam::convertOldConf( const std::string & new_conf ) { #ifndef RCSS_WIN - if ( std::system( ( "ls " + tildeExpand( PlayerParam::OLD_PLAYER_CONF ) + " > /dev/null 2>&1" ).c_str() ) == 0 - && std::system( ( "ls " + tildeExpand( new_conf ) + " > /dev/null 2>&1" ).c_str() ) != 0 + if ( std::filesystem::exists( tildeExpand( PlayerParam::OLD_PLAYER_CONF ) ) + && ! std::filesystem::exists( tildeExpand( new_conf ) ) && std::system( "which awk > /dev/null 2>&1" ) == 0 ) { std::cout << "Trying to convert old configuration file '" diff --git a/src/serverparam.cpp b/src/serverparam.cpp index 7e99a5df..c77e9f04 100644 --- a/src/serverparam.cpp +++ b/src/serverparam.cpp @@ -46,9 +46,7 @@ #include #include -#include -#include - +#include #include #include #include @@ -72,6 +70,10 @@ #endif #endif +#ifndef RCSS_WIN +#include // close() +#endif + namespace { //! Lowest Common Multiple @@ -417,12 +419,12 @@ ServerParam::init( const int & argc, // } // } - boost::filesystem::path conf_path; + std::filesystem::path conf_path; try { - conf_path = boost::filesystem::path( tildeExpand( conf_dir ) ); - if ( ! boost::filesystem::exists( conf_path ) - && ! boost::filesystem::create_directories( conf_path ) ) + conf_path = tildeExpand( conf_dir ); + if ( ! std::filesystem::exists( conf_path ) + && ! std::filesystem::create_directories( conf_path ) ) { std::cerr << "Could not read or create config directory " << conf_path << std::endl; instance().clear(); @@ -505,8 +507,8 @@ void ServerParam::convertOldConf( const std::string & new_conf ) { #ifndef RCSS_WIN - if ( std::system( ( "ls " + tildeExpand( OLD_SERVER_CONF ) + " > /dev/null 2>&1" ).c_str() ) == 0 - && std::system( ( "ls " + tildeExpand( new_conf ) + " > /dev/null 2>&1" ).c_str() ) != 0 + if ( std::filesystem::exists( tildeExpand( OLD_SERVER_CONF ) ) + && ! std::filesystem::exists( tildeExpand( new_conf ) ) && std::system( "which awk > /dev/null 2>&1" ) == 0 ) { std::cout << "Trying to convert old configuration file '" From a94d72463507dbc2779583e6bcf9d9e3578527a2 Mon Sep 17 00:00:00 2001 From: Hidehisa Akiyama <522630+hidehisaakiyama@users.noreply.github.com> Date: Wed, 8 Mar 2023 13:25:34 +0900 Subject: [PATCH 4/5] Remove boost::filesystem from build settings and update shared object versions. (#113) --- CMakeLists.txt | 3 ++- rcss/CMakeLists.txt | 2 +- rcss/clang/CMakeLists.txt | 4 ++-- rcss/clang/Makefile.am | 2 +- rcss/conf/CMakeLists.txt | 6 +++--- rcss/conf/Makefile.am | 2 +- src/CMakeLists.txt | 2 +- 7 files changed, 11 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d86cae0..1b96f6b7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,8 @@ if(ZLIB_FOUND) endif() find_package(BISON REQUIRED) find_package(FLEX REQUIRED) -find_package(Boost COMPONENTS system filesystem REQUIRED) +#find_package(Boost COMPONENTS system filesystem REQUIRED) +find_package(Boost COMPONENTS system REQUIRED) include(GNUInstallDirs) include(CheckIncludeFileCXX) diff --git a/rcss/CMakeLists.txt b/rcss/CMakeLists.txt index ea5eb865..ea4044c1 100644 --- a/rcss/CMakeLists.txt +++ b/rcss/CMakeLists.txt @@ -25,7 +25,7 @@ target_include_directories(RCSSBase target_link_libraries(RCSSBase INTERFACE - Boost::filesystem +# Boost::filesystem ) #install(TARGETS RCSSBase diff --git a/rcss/clang/CMakeLists.txt b/rcss/clang/CMakeLists.txt index 2274b81e..31169b61 100644 --- a/rcss/clang/CMakeLists.txt +++ b/rcss/clang/CMakeLists.txt @@ -71,8 +71,8 @@ target_compile_options(RCSSCLangParser set_target_properties(RCSSCLangParser PROPERTIES - SOVERSION 2 - VERSION 2.1.0 + SOVERSION 18 + VERSION 18.0.0 LIBRARY_OUTPUT_NAME "rcssclangparser" ) diff --git a/rcss/clang/Makefile.am b/rcss/clang/Makefile.am index 85dda2f4..37cb9bba 100644 --- a/rcss/clang/Makefile.am +++ b/rcss/clang/Makefile.am @@ -24,7 +24,7 @@ librcssclangparser_la_SOURCES = \ region.cpp \ rule.cpp -librcssclangparser_la_LDFLAGS = -version-info 3:0:1 +librcssclangparser_la_LDFLAGS = -version-info 18:0:0 # Changed from 2.0.0 to 3.0.1 at 9.3.5 for addition of buildCondList # # 1. Start with version information of `0:0:0' for each libtool library. diff --git a/rcss/conf/CMakeLists.txt b/rcss/conf/CMakeLists.txt index b12a34dd..1d5c3872 100644 --- a/rcss/conf/CMakeLists.txt +++ b/rcss/conf/CMakeLists.txt @@ -10,7 +10,7 @@ add_library(RCSS::ConfParser ALIAS RCSSConfParser) target_link_libraries(RCSSConfParser PUBLIC - Boost::filesystem +# Boost::filesystem PRIVATE Boost::boost ) @@ -33,8 +33,8 @@ target_compile_options(RCSSConfParser set_target_properties(RCSSConfParser PROPERTIES - SOVERSION 3 - VERSION 3.0.0 + SOVERSION 18 + VERSION 18.0.0 LIBRARY_OUTPUT_NAME "rcssconfparser" ) diff --git a/rcss/conf/Makefile.am b/rcss/conf/Makefile.am index 453c15bd..c1c903f2 100644 --- a/rcss/conf/Makefile.am +++ b/rcss/conf/Makefile.am @@ -7,7 +7,7 @@ librcssconfparser_la_SOURCES = \ statushandler.cpp \ streamstatushandler.cpp -librcssconfparser_la_LDFLAGS = -version-info 3:0:0 +librcssconfparser_la_LDFLAGS = -version-info 18:0:0 # 1. Start with version information of `0:0:0' for each libtool library. # # 2. Update the version information only immediately before a public diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 65cbf42d..1bac9502 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -94,7 +94,7 @@ target_link_libraries(RCSSServer RCSS::ConfParser RCSS::Net RCSS::GZ - Boost::filesystem +# Boost::filesystem ZLIB::ZLIB ) From d0c5a3789920739190fb4c2a690a924dcbd39d8b Mon Sep 17 00:00:00 2001 From: Hidehisa Akiyama <522630+hidehisaakiyama@users.noreply.github.com> Date: Wed, 8 Mar 2023 15:08:32 +0900 Subject: [PATCH 5/5] Release/18.0.0 (#114) * Add short descriptions about v18. * Update a major version number. * Update ChangeLog. * Fix the indent width in NEWS. --- CMakeLists.txt | 2 +- ChangeLog | 10 ++++++++++ NEWS | 43 +++++++++++++++++++++++++++++++++++++++++++ configure.ac | 2 +- 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b96f6b7..ac7ddc7c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.5.1) -project(RCSSServer VERSION 17.0.1) +project(RCSSServer VERSION 18.0.0) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) diff --git a/ChangeLog b/ChangeLog index 9674bb55..1ca36dff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2023-03-07 Hidehisa Akiyama + + * CMakeLists.txt: + * NEWS: + * configure.ac: + - update a major version number. Official release 18.0.0 + - update to C++17. + - introduce a new observation model. + - change the version number of JSON-based monitor protocol. + 2022-04-03 Hidehisa Akiyama * CMakeLists.txt: diff --git a/NEWS b/NEWS index bd37b7f2..a43426db 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,46 @@ +[18.0.0] + * Update to C++17. + + * New command: + - "(change_focus DIST_MOMENT DIR_MOMENT)" + All version players can use this command. If the command is + accepted, that player's focus point is moved according to the + given parameters. Details are described below. + + * Change the version number of JSON-based monitor protocol to -1. + And, change the header line of JSON-based game log to "JSON". If + the value of server::game_log_version is -1, the content of the + recorded game log is a JSON array except for the header line. + + * Introduce a new observation model. + + When the players connect with version 18 or higher, the vision + sensor automatically enters the synchronous mode. In addition, + players with version 18 or higher receive a see message every + cycle, regardless of their view width. Instead, the noise in the + observed information varies with the view width. When the + observation information is serialized, the quantize step parameter + is multiplied by the noise term parameter, which depends on the + view width. + + The concept of focus points is introduced. The focus point + represents a position inside a player's view angle, and can be up + to 40.0 meters away from the player's position. The focus point + affects the visual sensor noise model, with the noise of observed + objects increasing as the distance between the focus point and + the object increases. + + The initial position of the focus point is the player's position, + and if a player does not change the focus point position, the + server visual noise model behaves as in server v17. However, a + player can change the position of the focus point by sending a + **change_focus** command. This command takes two parameters, + *dist_moment* and *dir_moment*, and changes the position of the + focus point relative to the player's neck angle. + + See the user manual for more information on the new observation + model. + [17.0.1] * Fix build problems caused by missing headers. diff --git a/configure.ac b/configure.ac index 890c2096..6e33ec4a 100644 --- a/configure.ac +++ b/configure.ac @@ -3,7 +3,7 @@ AC_PREREQ([2.69]) LT_PREREQ([2.2]) -AC_INIT([RCSSServer],[17.0.1],[https://github.com/rcsoccersim/],[rcssserver]) +AC_INIT([RCSSServer],[18.0.0],[https://github.com/rcsoccersim/],[rcssserver]) #AM_INIT_AUTOMAKE([gnu 1.7.2 check-news dist-bzip2 dist-zip]) AM_INIT_AUTOMAKE([gnu 1.7.2 check-news foreign])