field.cpp
来自「2009 ROBOCUP 仿真2DSERVER 源码」· C++ 代码 · 共 2,481 行 · 第 1/5 页
CPP
2,481 行
if ( side == LEFT ) { holder = M_team_l->teamGraphic( x, y ); } if ( side == RIGHT ) { holder = M_team_r->teamGraphic( x, y ); } if ( ! holder ) { return; }#ifdef HAVE_SSTREAM std::ostringstream data;#else std::ostrstream data;#endif data << "(team_graphic_" << ( side == LEFT ? "l" : "r" ) << " (" << x << " " << y << " " << *holder << ")";#ifndef HAVE_SSTREAM data << std::ends;#endif std::string msg = data.str();#ifndef HAVE_SSTREAM data.freeze( false );#endif for ( MonitorCont::iterator i = M_monitors.begin(); i != M_monitors.end(); ++i ) { (*i)->sendMsg( MSG_BOARD, msg.c_str() ); } M_logger.writeMsgToGameLog( MSG_BOARD, msg.c_str(), true );}voidStadium::move_caught_ball(){ if ( M_ball_catcher ) { // keeps the caught ball infront of the player PVector temp = PVector::fromPolar( M_ball_catcher->size() + ServerParam::instance().ballSize(), M_ball_catcher->angleBodyCommitted() ); M_ball->moveTo( M_ball_catcher->pos() + temp ); }}voidStadium::removeDisconnectedClients(){ for ( PlayerCont::iterator i = M_remote_players.begin(); i != M_remote_players.end(); ) { if ( ! (*i)->connected() ) { (*i)->disable(); removeListener( *i ); i = M_remote_players.erase( i ); } else { ++i; } } for ( OfflineCoachCont::iterator i = M_remote_offline_coaches.begin(); i != M_remote_offline_coaches.end(); ) { if ( ! (*i)->connected() ) { (*i)->disable(); removeListener( *i ); i = M_remote_offline_coaches.erase( i ); } else { ++i; } } for ( OnlineCoachCont::iterator i = M_remote_online_coaches.begin(); i != M_remote_online_coaches.end(); ) { if ( ! (*i)->connected() ) { (*i)->disable(); removeListener( *i ); i = M_remote_online_coaches.erase( i ); } else { ++i; } } for ( MonitorCont::iterator i = M_monitors.begin(); i != M_monitors.end(); ) { if ( ! (*i)->connected() ) { delete *i; i = M_monitors.erase( i ); std::cout << "A monitor disconnected\n"; } else { ++i; } }}voidStadium::sendRefereeAudio( const char * msg ){ std::random_shuffle( M_listeners.begin(), M_listeners.end(), irand ); //rcss::random::UniformRNG::instance() ); // the following should work, but I haven't tested it yet // std::for_each( M_listeners.begin(), M_listeners.end(), // std::bind2nd( std::mem_fun( &rcss::Listener::sendRefereeAudio ), // msg.c_str() ) ); const ListenerCont::iterator end = M_listeners.end(); for ( ListenerCont::iterator it = M_listeners.begin(); it != end; ++it ) { (*it)->sendRefereeAudio( msg ); } M_logger.writeRefereeAudio( msg ); if ( ServerParam::instance().sendComms() ) { char buf[max_message_length_for_display]; snprintf( buf, max_message_length_for_display, "(%s %s)", REFEREE_NAME, msg ); for ( MonitorCont::iterator i = M_monitors.begin(); i != M_monitors.end(); ++i ) { (*i)->sendMsg( MSG_BOARD, buf ); } }}voidStadium::sendPlayerAudio( const Player & player, const char * msg ){ std::random_shuffle( M_listeners.begin(), M_listeners.end(), irand ); //rcss::random::UniformRNG::instance() ); const ListenerCont::iterator end = M_listeners.end(); for ( ListenerCont::iterator it = M_listeners.begin(); it != end; ++it ) { (*it)->sendPlayerAudio( player, msg ); } M_logger.writePlayerAudio( player, msg ); if ( ServerParam::instance().sendComms() ) { char buf[max_message_length_for_display]; snprintf( buf, max_message_length_for_display, "(%s %s)", player.name().c_str(), msg ); // send to monitors for ( Stadium::MonitorCont::iterator i = monitors().begin(); i != monitors().end(); ++i ) { (*i)->sendMsg( MSG_BOARD, buf ); } }}voidStadium::sendCoachAudio( const Coach & coach, const char * msg ){ std::random_shuffle( M_listeners.begin(), M_listeners.end(), irand ); //rcss::random::UniformRNG::instance() ); const ListenerCont::iterator end = M_listeners.end(); for ( ListenerCont::iterator it = M_listeners.begin(); it != end; ++it ) { (*it)->sendCoachAudio( coach, msg ); } M_logger.writeCoachAudio( coach, msg ); if ( ServerParam::instance().sendComms() ) { char buf[max_message_length_for_display]; char format[40]; snprintf( format, 40, "(%%s %%.%ds)", max_message_length_for_display - (MaxMesg - MaxCoachMesg) ); snprintf( buf, max_message_length_for_display, format, ( coach.side() == RIGHT ? OLCOACH_NAME_R : coach.side() == LEFT ? OLCOACH_NAME_L: REFEREE_NAME ), msg ); for ( MonitorCont::iterator i = monitors().begin(); i != monitors().end(); ++i ) { (*i)->sendMsg( MSG_BOARD, buf ); } }}voidStadium::sendCoachStdAudio( const OnlineCoach & coach, const rcss::clang::Msg & msg ){ std::random_shuffle( M_listeners.begin(), M_listeners.end(), irand ); //rcss::random::UniformRNG::instance() ); const ListenerCont::iterator end = M_listeners.end(); for ( ListenerCont::iterator it = M_listeners.begin(); it != end; ++it ) { (*it)->sendCoachStdAudio( msg ); } M_logger.writeCoachStdAudio( coach, msg ); if ( ServerParam::instance().sendComms() ) { std::ostringstream coach_mess; coach_mess << msg.getTimeRecv() << " "; msg.print( coach_mess ); char buf[max_message_length_for_display]; char format[40]; snprintf( format, 40, "(%%s %%.%ds)", max_message_length_for_display - (MaxMesg - MaxCoachMesg)); snprintf( buf, max_message_length_for_display, format, (coach.side() == RIGHT) ? OLCOACH_NAME_R : OLCOACH_NAME_L, coach_mess.str().c_str() ); for ( MonitorCont::iterator i = monitors().begin(); i != monitors().end(); ++i ) { (*i)->sendMsg( MSG_BOARD, buf ); } }}voidStadium::doRecvFromClients(){ timeval tv_start, tv_end; if ( M_logger.isTextLogOpen() && ServerParam::instance().profile() ) { gettimeofday( &tv_start, NULL ); } udp_recv_message(); udp_recv_from_online_coach(); if ( ServerParam::instance().coachMode() || ServerParam::instance().coachWithRefereeMode() ) { udp_recv_from_coach(); } removeDisconnectedClients(); if ( M_logger.isTextLogOpen() && ServerParam::instance().profile() ) { gettimeofday( &tv_end, NULL ); M_logger.writeProfile( tv_start, tv_end, "RECV" ); }}voidStadium::doNewSimulatorStep(){ static timeval tp_old; timeval tp_new, tv_start, tv_end; // th 6.3.00 if ( M_logger.isTextLogOpen() ) { if ( ServerParam::instance().logTimes() ) { // tp_old = tp_new; // write_times displays nonsense at first call, since tp_old is never // initialized. Don't want to handle special exception for first call. gettimeofday( &tp_new, NULL ); M_logger.writeTimes( tp_old, tp_new ); gettimeofday( &tp_old, NULL ); } if ( ServerParam::instance().profile() ) { gettimeofday( &tv_start, NULL ); } } // // step // step(); startTeams(); checkAutoMode(); if ( M_logger.isTextLogOpen() && ServerParam::instance().profile() ) { gettimeofday( &tv_end, NULL ); M_logger.writeProfile( tv_start, tv_end, "SIM" ); }}voidStadium::doSendSenseBody(){ struct timeval tv_start, tv_end; if ( M_logger.isTextLogOpen() && ServerParam::instance().profile() ) { gettimeofday( &tv_start, NULL ); } std::random_shuffle( M_remote_players.begin(), M_remote_players.end(), irand ); //rcss::random::UniformRNG::instance() ); // // send sense_body & fullstate // const PlayerCont::iterator end = M_remote_players.end(); for ( PlayerCont::iterator it = M_remote_players.begin(); it != end; ++it ) { if ( (*it)->state() != DISABLE && (*it)->connected() ) { (*it)->sendBody(); if ( ( (*it)->side() == LEFT && ServerParam::instance().fullstateLeft() ) || ( (*it)->side() == RIGHT && ServerParam::instance().fullstateRight() ) ) { (*it)->sendFullstate(); } } // reset collision flags (*it)->resetCollisionFlags(); } // // send audio message // std::for_each( M_listeners.begin(), M_listeners.end(), rcss::Listener::NewCycle() ); //std::mem_fun( &rcss::Listener::newCycle ) ); // // write profile // if ( M_logger.isTextLogOpen() && ServerParam::instance().profile() ) { gettimeofday( &tv_end, NULL ); M_logger.writeProfile( tv_start, tv_end, "SB" ); }}voidStadium::doSendVisuals(){ struct timeval tv_start, tv_end; if ( M_logger.isTextLogOpen() && ServerParam::instance().profile() ) { gettimeofday( &tv_start, NULL ); } std::random_shuffle( M_remote_players.begin(), M_remote_players.end(), irand ); //rcss::random::UniformRNG::instance() ); const PlayerCont::iterator end = M_remote_players.end(); for ( PlayerCont::iterator it = M_remote_players.begin(); it != end; ++it ) { if ( (*it)->state() != DISABLE && (*it)->connected() ) { (*it)->sendVisual(); } } if ( M_logger.isTextLogOpen() && ServerParam::instance().profile() ) { gettimeofday( &tv_end, NULL ); M_logger.writeProfile( tv_start, tv_end, "VIS" ); }}voidStadium::doSendSynchVisuals(){ struct timeval tv_start, tv_end; // std::cerr << "sendSynchVisuals time=" << time() << std::endl; if ( M_logger.isTextLogOpen() && ServerParam::instance().profile() ) { gettimeofday( &tv_start, NULL ); } std::random_shuffle( M_remote_players.begin(), M_remote_players.end(), irand ); //rcss::random::UniformRNG::instance() ); const PlayerCont::iterator end = M_remote_players.end(); for ( PlayerCont::iterator it = M_remote_players.begin(); it != end; ++it ) { if ( (*it)->state() != DISABLE && (*it)->connected() ) { (*it)->sendSynchVisual(); } } if ( M_logger.isTextLogOpen() && ServerParam::instance().profile() ) { gettimeofday( &tv_end, NULL ); M_logger.writeProfile( tv_start, tv_end, "VIS_S" ); }}voidStadium::doSendCoachMessages(){ struct timeval tv_start, tv_end; if ( M_logger.isTextLogOpen() && ServerParam::instance().profile() ) { gettimeofday( &tv_start, NULL ); } if ( M_coach->assigned() && M_coach->isEyeOn() ) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?