📄 worldmodel.cpp
字号:
if( SS->getSynchMode() == false ) {#ifdef WIN32 //EnterCriticalSection( &mutex_newInfo ); bNewInfo = true; SetEvent ( event_newInfo ); //LeaveCriticalSection( &mutex_newInfo );#else pthread_mutex_lock ( &mutex_newInfo ); bNewInfo = true; pthread_cond_signal ( &cond_newInfo ); pthread_mutex_unlock( &mutex_newInfo );#endif } return true;}/*! This method returns the time of the last sense message \return time of last sense message */// 得到上次获得感觉信息的时间Time WorldModel::getTimeLastSenseMessage( ) const{ return timeLastSenseMessage ;}/*! This method returns the time of the last received sense message. The difference with getTimeLastSenseMessage is that that method returns the last sense message that has been updated in the world model. In most cases these are equal. \return time of last received sense message */// 同上,不同的是上面的函数返回的是已经在世界模型更新过的时间,多数情况来说它们是相等的Time WorldModel::getTimeLastRecvSenseMessage( ) const{ return timeLastRecvSenseMessage ;} /*! This method sets the time of the last sense message. It also send a condition signal to indicate that variable bNewInfo has changed. When main thread is stopped in waitForNewInformation, it is unblocked. \param time sense message has arrived \return true when update was succesful */// 设置上次获得感觉信息的时间bool WorldModel::setTimeLastSenseMessage( Time time ){ timeLastRecvSenseMessage = time; if( SS->getSynchMode() == false ) {#ifdef WIN32 //EnterCriticalSection( &mutex_newInfo ); bNewInfo = true; SetEvent ( event_newInfo ); //LeaveCriticalSection( &mutex_newInfo );#else pthread_mutex_lock ( &mutex_newInfo ); bNewInfo = true; pthread_cond_signal ( &cond_newInfo ); pthread_mutex_unlock( &mutex_newInfo );#endif } return true;}/*! This method returns the time of the last hear message \return time of last hear message */// 得到上次获得听觉信息的时间Time WorldModel::getTimeLastHearMessage( ) const{ return timeLastHearMessage ;}/*! This method sets the time of the last hear message. \param time hear message has arrived \return true when update was succesful */// 设置上次获得听觉信息的时间bool WorldModel::setTimeLastHearMessage( Time time ){ timeLastHearMessage = time; return true;}/*! This method returns the player number of the agent. The player number is the fixed number which is given by the server after initialization. \return player number of this player. */// 返回当前agent的号码,号码是由服务器初始化后给出的int WorldModel::getPlayerNumber( ) const{ return iPlayerNumber;}/*! This method sets the player number of the agent. This value is available in the conformation message sent by the soccerserver after the initialization. \param i new player number of the agent. \return bool indicating whether player number was set. */// 设置当前agent的号码,该号码由初始化时服务器给出的确认信息指定。bool WorldModel::setPlayerNumber( int i ){ iPlayerNumber = i; return true;}/*! This method returns the side of the agent. Note that the side of the agent does not change after half time. \return side (SIDE_LEFT or SIDE_RIGHT) for agent */// 返回当前agent在球场哪边,值得注意的是这个就算过了半场时间也不会改变SideT WorldModel::getSide( ) const{ return sideSide;}/*! This method sets the side of the agent \param s (SIDE_LEFT or SIDE_RIGHT) for agent \return bool indicating whether update was succesful.*/// 设置当前agent在球场哪边,该信息由初始化时服务器给出的确认信息指定。// s : 将球员方向设置成 SIDE_LEFT 或者 SIDE_RIGHT// 返回更新的结果是否是成功bool WorldModel::setSide( SideT s ){ sideSide = s; m_iMultX = (getSide() == SIDE_LEFT ) ? 1 : -1 ; // set the draw info m_iMultY = (getSide() == SIDE_LEFT ) ? -1 : 1 ; // from Logger.C return true;}/*! This method returns the teamname of the agent in this worldmodel \return teamname for the agent in this worldmodel */// 返回当前agent所属球队队名const char* WorldModel::getTeamName( ) const{ return strTeamName ;}/*! This method sets the teamname of the agent. The maximum team name is MAX_TEAM_NAME_LENGTH as defined in Soccertypes.h. \param str teamname for the agent in this worldmodel \return bool indicating whether update was succesful.*/// 设置当前agent所属球队队名bool WorldModel::setTeamName( char * str ){ strcpy( strTeamName, str ); return true;}/*! This method returns the current playmode. This playmode is passed through by the referee. \return current playmode (see SoccerTypes for possibilities) */// 返回当前比赛模式,这个比赛模式是由裁判发出的。PlayModeT WorldModel::getPlayMode( ) const{ return playMode ;}/*! This method sets the play mode of the agent in this worldmodel \param pm for the agent in this worldmodel \return bool indicating whether update was succesful.*/// 设置当前比赛模式,返回是否更新成功bool WorldModel::setPlayMode( PlayModeT pm ){ playMode = pm; if( ( pm == PM_GOAL_KICK_LEFT && getSide() == SIDE_LEFT ) || ( pm == PM_GOAL_KICK_RIGHT && getSide() == SIDE_RIGHT ) ) setTimeLastCatch( getTimeLastSenseMessage() ); return true;}/*! This method returns the goal difference. When this value is below zero, the team of agent is behind, 0 means that the score is currently the same for both teams and a value higher than zero means that you're winning!. \return goal difference */// 返回比分差距(领先的进球数)int WorldModel::getGoalDiff( ) const{ return iGoalDiff;}/*!This method adds one goal to the goal difference. Call this method when your team has scored a goal \return new goal difference */// 增大比分差,我方进球数+1int WorldModel::addOneToGoalDiff( ){ return ++iGoalDiff;}/*!This method subtracts one from the goal difference. Call this method when you're team has conceided a goal \return new goal difference */// 减小比分差,对方进球数+1int WorldModel::subtractOneFromGoalDiff(){ return --iGoalDiff;}/*! This method returns the amount of commands c performed by the agent. This is supplied in the sense_body message. \param c CommandT of which number of commands should be returned. \return amount of commands c performed by the soccerserver. */// 返回当前球员执行指令过 c 的次数,是由 sense_body 信息提供的。// CommandT c : 需要计算执行次数的指令类型int WorldModel::getNrOfCommands( CommandT c ) const{ return iCommandCounters[ (int) c ];}/*! This method sets the number of commands c that were performed by the agent. This is supplied in the sense_body message and can be used to check whether an action is actually performed by the soccer server, since the corresponding counter should be one higher than the previous sense_body message. When this is the case the corresponding index of the PerformedCommands array is set to true. \param c CommandT of which the number of commands should be set. \param i number of commands that are performed of this command \return bool indicating whether update was performed. */// 设置指令 c 被 agent 执行过的次数// 这由sense_body给出,并且可以用于检查命令是否被服务器执行了,因为数值应该比sense_body高// 当确定指令被执行了,队列中指令被执行的标记更改为truebool WorldModel::setNrOfCommands( CommandT c, int i ){ int iIndex = (int) c; // if counter is the same as before, no command is performed, otherwise it is performedCommands[iIndex] = ( iCommandCounters[iIndex] == i ) ? false : true; iCommandCounters [iIndex] = i; return true;}/*! This method returns the time the status of the ball was last checked (coach only). \return server cycle the status of the ball was last checked. */// 返回上次检查球的状态的时间(限教练)Time WorldModel::getTimeCheckBall( ) const{ return timeCheckBall;}/*! This method sets the time the ball was checked for the last time (coach only). \param time server time ball was checked. \return bool indicating whether update was succesfull. */// 设置上次球的状态被检查的时间(限教练)bool WorldModel::setTimeCheckBall( Time time ){ timeCheckBall = time; return true;}/*! This method returns the status of the ball. This value is derived from the check_ball command that can only be used by the coach. The status of the ball corresponds to the server time returned by getTimeCheckBall. \return BallStatus status of the ball. */// 检查球的状态(限教练)BallStatusT WorldModel::getCheckBallStatus( ) const{ return bsCheckBall;}/*! This method sets the status of the ball. The status of the ball corresponds to the server time returned by getTimeCheckBall. This method is only useful for the coach, since only he can sent a check_ball message. \return BallStatus status of the ball. */// 设置球的状态(限教练)bool WorldModel::setCheckBallStatus( BallStatusT bs ){ bsCheckBall = bs; return true;}/*! This method returns a boolean indicating whether the synchronization method indicated we are ready. */// 返回同步方法是否指出我们准备好bool WorldModel::getRecvThink( ){ return m_bRecvThink;}/*! This method returns the string that we want communicate. It can be set during the creation of the action. When the ActHandler sends its actions, it sends this string to the server. \return communication string. */// 生成一个我们想要发送的字串信息。可以在生成球员动作的时候设置。// 当 ActHandler 发送它的动作时,它将这个信息发送到服务器char* WorldModel::getCommunicationString( ){ return m_strCommunicate;}/*! This methods returns the object type of the object that is currently listened to. This information is gathered from a sense message. When this agent says a message, we will definitely hear it. */// 这个方法返回现在听向(listened to)对象的类型// 这个信息是由sense_message所收集到的// 这样该对象所喊出的信息,将被我们清楚的听到ObjectT WorldModel::getObjectFocus( ){ return m_objFocus;}/*! This methods sets the object type of the object that is currently listened to. This information is gathered from a sense message. When this agent says a message, we will definitely hear it. */// 设置关注(listened to)的对象类型bool WorldModel::setObjectFocus( ObjectT obj ){ m_objFocus = obj; return true;}/*! This method sets the string that we want communicate. It can be set during the creation of the action. When the ActHandler sends its actions, it sends this string to the server. \return communication string. */// 设置我们所想要通讯的信息,可以在创建动作的时候设置// 当ActHandler发送动作的时候,它会将这个字串发送到服务器bool WorldModel::setCommunicationString( char *str ){ strncpy( m_strCommunicate, str, MAX_SAY_MSG ); //消息最大长度为10 return true;}/*!This method starts an iteration over an object set g. This method will return the first ObjectT in an ObjectSetT that has a confidence higher than dConf. After this call use the method iterateObjectNext with the same argument to get the other objects that belong to this set. \param iIndex index that should be used in consecutive cycles. \param g ObjectSetT of which the ObjecT should be returned. \param dConf minimum confidence needed for ObjectT to be returned. \return ObjectT that is first in the set g. */// 返回对象集合中第一个可信度超过dConf的物体// index : 被用于顺序的周期的索引(在搜寻中用于标记已搜寻位置的自增变量)// (consecutive:连续不断的/顺序来的)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -