📄 serializermonitor.cpp
字号:
// -*-c++-*-/*************************************************************************** serializermonitor.cpp Class for serializing data to monitors ------------------- begin : 2007-11-22 copyright : (C) 2007 by The RoboCup Soccer Server Maintenance Group. email : sserver-admin@lists.sourceforge.net***************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU LGPL as published by the Free Software * * Foundation; either version 2 of the License, or (at your option) any * * later version. * * * ***************************************************************************/#ifdef HAVE_CONFIG_H#include <config.h>#endif#include "serializermonitor.h"#include "param.h"#include "utility.h"#include "object.h"#include "player.h"#include "team.h"namespace rcss {/*//===================================================================//// SerializerMonitor////===================================================================*/SerializerMonitor::FactoryHolder &SerializerMonitor::factory(){ static FactoryHolder rval; return rval;}SerializerMonitor::SerializerMonitor( const SerializerCommon & common ) : Serializer( common ){}SerializerMonitor::~SerializerMonitor(){}/*//===================================================================//// SerializerMonitorStdv1////===================================================================*/SerializerMonitorStdv1::SerializerMonitorStdv1( const SerializerCommon & common ) : SerializerMonitor( common ){}SerializerMonitorStdv1::~SerializerMonitorStdv1(){}constSerializerMonitorStdv1 *SerializerMonitorStdv1::instance(){ rcss::SerializerCommon::Creator cre_common; if ( ! rcss::SerializerCommon::factory().getCreator( cre_common, 8 ) ) { return NULL; } static SerializerMonitorStdv1 ser( cre_common() ); return &ser;}/*//===================================================================//// SerializerMonitorStdv3////===================================================================*/const double SerializerMonitorStdv3::PREC = 0.0001;const double SerializerMonitorStdv3::DPREC = 0.001;SerializerMonitorStdv3::SerializerMonitorStdv3( const SerializerCommon & common ) : SerializerMonitorStdv1( common ){}SerializerMonitorStdv3::~SerializerMonitorStdv3(){}constSerializerMonitorStdv3 *SerializerMonitorStdv3::instance(){ rcss::SerializerCommon::Creator cre_common; if ( ! rcss::SerializerCommon::factory().getCreator( cre_common, 8 ) ) { return NULL; } static SerializerMonitorStdv3 ser( cre_common() ); return &ser;}voidSerializerMonitorStdv3::serializeTeam( std::ostream & os, const int time, const Team & team_l, const Team & team_r ) const{ os << "(team " << time << ' ' << ( team_l.name().empty() ? "null" : team_l.name().c_str() ) << ' ' << ( team_r.name().empty() ? "null" : team_r.name().c_str() ) << ' ' << team_l.point() << ' ' << team_r.point(); if ( team_l.penaltyTaken() > 0 || team_r.penaltyTaken() > 0 ) { os << ' ' << team_l.penaltyPoint() << ' ' << team_l.penaltyTaken() - team_l.penaltyPoint() << ' ' << team_r.penaltyPoint() << ' ' << team_r.penaltyTaken() - team_r.penaltyPoint(); } os << ')';}voidSerializerMonitorStdv3::serializePlayMode( std::ostream & os, const int time, const PlayMode pmode ) const{ static const char * playmode_strings[] = PLAYMODE_STRINGS; os << "(playmode " << time << ' ' << playmode_strings[pmode] << ')';}voidSerializerMonitorStdv3::serializeShowBegin( std::ostream & os, const int time ) const{ os << "(show " << time;}voidSerializerMonitorStdv3::serializeShowEnd( std::ostream & os ) const{ os << ')';}voidSerializerMonitorStdv3::serializePlayModeId( std::ostream & os, const PlayMode pmode ) const{ os << " (pm " << pmode << ')';}voidSerializerMonitorStdv3::serializeScore( std::ostream & os, const Team & team_l, const Team & team_r ) const{ os << " (tm" << ' ' << ( team_l.name().empty() ? "null" : team_l.name().c_str() ) << ' ' << ( team_r.name().empty() ? "null" : team_r.name().c_str() ) << ' ' << team_l.point() << ' ' << team_r.point(); if ( team_l.penaltyTaken() > 0 || team_r.penaltyTaken() > 0 ) { os << ' ' << team_l.penaltyPoint() << ' ' << team_l.penaltyTaken() - team_l.penaltyPoint() << ' ' << team_r.penaltyPoint() << ' ' << team_r.penaltyTaken() - team_r.penaltyPoint(); } os << ')';}voidSerializerMonitorStdv3::serializeBall( std::ostream & os, const Ball & ball ) const{ os << " (" << BALL_NAME_SHORT << ' ' << Quantize( ball.pos().x, PREC ) << ' ' << Quantize( ball.pos().y, PREC ) << ' ' << Quantize( ball.vel().x, PREC ) << ' ' << Quantize( ball.vel().y, PREC ) << ')';}voidSerializerMonitorStdv3:: serializePlayerBegin( std::ostream & os, const Player & player ) const{ os << " (" << '(' << SideStr( player.side() ) << ' ' << player.unum() << ')' << ' ' << player.playerTypeId() << ' ' << std::hex << std::showbase << player.state() << std::dec << std::noshowbase;}voidSerializerMonitorStdv3::serializePlayerEnd( std::ostream & os ) const{ os << ')';}voidSerializerMonitorStdv3::serializePlayerPos( std::ostream & os, const Player & player ) const{ os << ' ' << Quantize( player.pos().x, PREC ) << ' ' << Quantize( player.pos().y, PREC ) << ' ' << Quantize( player.vel().x, PREC ) << ' ' << Quantize( player.vel().y, PREC ) << ' ' << Quantize( Rad2Deg( player.angleBodyCommitted() ), DPREC ) << ' ' << Quantize( Rad2Deg( player.angleNeckCommitted() ), DPREC );}voidSerializerMonitorStdv3::serializePlayerArm( std::ostream & os, const Player & player ) const{ if ( player.arm().isPointing() ) { os << ' ' << Quantize( player.arm().dest().getX(), PREC ) << ' ' << Quantize( player.arm().dest().getY(), PREC );// rcss::geom::Vector2D arm_dest;// if ( player.arm().getRelDest( rcss::geom::Vector2D( player.pos().x,// player.pos().y ),// 0.0,// arm_dest ) )// {// os << ' ' << Quantize( arm_dest.getMag(), PREC )// << ' ' << Quantize( Rad2Deg( arm_dest.getHead() ), DPREC );// } }}voidSerializerMonitorStdv3::serializePlayerViewMode( std::ostream & os, const Player & player ) const{ os << " (v " << ( player.highquality() ? "h " : "l " ) << Quantize( Rad2Deg( player.visibleAngle() ), DPREC ) << ')';}voidSerializerMonitorStdv3::serializePlayerStamina( std::ostream & os, const Player & player ) const{ os << " (s " << player.stamina() << ' ' << player.effort() << ' ' << player.recovery() << ')';}voidSerializerMonitorStdv3::serializePlayerFocus( std::ostream & os, const Player & player ) const{ if ( player.state() != DISABLE && player.getFocusTarget() != NULL ) { os << " (f " << SideStr( player.getFocusTarget()->side() ) << ' ' << player.getFocusTarget()->unum() << ')'; }}voidSerializerMonitorStdv3::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() << ')';}voidSerializerMonitorStdv3::serializeTeamGraphic( std::ostream & os, const int x, const int y, const char * msg ) const{ os << "(team_graphic " << x << ' ' << y << " \"" << msg << "\")";}/*//===================================================================//// SerializerMonitorStdv4////===================================================================*/SerializerMonitorStdv4::SerializerMonitorStdv4( const SerializerCommon & common ) : SerializerMonitorStdv3( common ){}SerializerMonitorStdv4::~SerializerMonitorStdv4(){}constSerializerMonitorStdv4 *SerializerMonitorStdv4::instance(){ rcss::SerializerCommon::Creator cre_common; if ( ! rcss::SerializerCommon::factory().getCreator( cre_common, 13 ) ) { return NULL; } static SerializerMonitorStdv4 ser( cre_common() ); return &ser;}voidSerializerMonitorStdv4::serializePlayerStamina( std::ostream & os, const Player & player ) const{ os << " (s " << player.stamina() << ' ' << player.effort() << ' ' << player.recovery() << ' ' << player.staminaCapacity() << ')';}namespace {constSerializerMonitor *create1(){ return SerializerMonitorStdv1::instance();}constSerializerMonitor *create3(){ return SerializerMonitorStdv3::instance();}constSerializerMonitor *create4(){ return SerializerMonitorStdv4::instance();}RegHolder v1 = SerializerMonitor::factory().autoReg( &create1, 1 );RegHolder v2 = SerializerMonitor::factory().autoReg( &create1, 2 );RegHolder v3 = SerializerMonitor::factory().autoReg( &create3, 3 );RegHolder v4 = SerializerMonitor::factory().autoReg( &create4, 4 );}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -