Thunderbots Project
Loading...
Searching...
No Matches
World Class Referencefinal

#include <world.h>

Public Member Functions

 World (const Field &field, const Ball &ball, const Team &friendly_team, const Team &enemy_team, unsigned int buffer_size=20)
 
 World (const TbotsProto::World &world_proto)
 
void updateBall (const Ball &new_ball)
 
void updateFriendlyTeamState (const Team &new_friendly_team_data)
 
void updateEnemyTeamState (const Team &new_enemy_team_data)
 
void updateRefereeCommand (const RefereeCommand &command)
 
void updateRefereeCommand (const RefereeCommand &command, Point ball_placement_point)
 
void updateRefereeStage (const RefereeStage &stage)
 
const Fieldfield () const
 
const Ballball () const
 
const TeamfriendlyTeam () const
 
const TeamenemyTeam () const
 
const GameStategameState () const
 
void updateGameState (const GameState &game_state)
 
void updateGameStateBall (const Ball &ball)
 
const RefereeStage & getRefereeStage () const
 
const Timestamp getMostRecentTimestamp () const
 
void updateTimestamp (Timestamp timestamp)
 
void setTeamWithPossession (TeamPossession possession)
 
TeamPossession getTeamWithPossession () const
 
bool operator== (const World &other) const
 
bool operator!= (const World &other) const
 
void setDribbleDisplacement (const std::optional< Segment > &displacement)
 
const std::optional< Segment > & getDribbleDisplacement () const
 

Static Public Attributes

static constexpr unsigned int REFEREE_COMMAND_BUFFER_SIZE = 3
 

Detailed Description

The world object describes the entire state of the world, which for us is all the information we have about the field, robots, and ball. The world object acts as a convenient way to pass all this information around to modules that may need it.

WARNING: This class should never hold any data that is pointed to anywhere else. This means no raw pointers, no shared pointers, no shared references. This is because in some cases we copy World's over multiple threads where having a shared member between multiple instances of a World on multiple threads could result in data corruption that would lead to absurdly hard to track bugs. YOU HAVE BEEN WARNED.

Constructor & Destructor Documentation

◆ World() [1/2]

World ( const Field field,
const Ball ball,
const Team friendly_team,
const Team enemy_team,
unsigned int  buffer_size = 20 
)
explicit

Creates a new world.

Parameters
fieldthe field for the world
ballthe ball for the world
friendly_teamthe friendly team for the world
enemy_teamthe enemy_team for the world

◆ World() [2/2]

World ( const TbotsProto::World &  world_proto)
explicit

Creates a new world based on the TbotsProto::World protobuf representation.

Parameters
world_protoThe TbotsProto::World protobuf which this world should be based on

Member Function Documentation

◆ ball()

const Ball & ball ( ) const

Returns a const reference to the Ball in the world

Returns
a const reference to the Ball in the world

◆ enemyTeam()

const Team & enemyTeam ( ) const

Returns a const reference to the Enemy Team in the world

Returns
a const reference to the Enemy Team in the world

◆ field()

const Field & field ( ) const

Returns a const reference to the Field in the world

Returns
a const reference to the Field in the world

◆ friendlyTeam()

const Team & friendlyTeam ( ) const

Returns a const reference to the Friendly Team in the world

Returns
a const reference to the Friendly Team in the world

◆ gameState()

const GameState & gameState ( ) const

Returns a const reference to the Game State

Returns
a const reference to the Game State

◆ getDribbleDisplacement()

const std::optional< Segment > & getDribbleDisplacement ( ) const

Gets a segment representing the displacement of the ball (in metres) due to the friendly team continuously dribbling the ball across the field.

  • The start point of the segment is the point on the field where the friendly team started dribbling the ball.
  • The end point of the segment is the current position of the ball.
  • The length of the segment is the distance between where the friendly team started dribbling the ball and where the ball is now.

If the friendly team does not have possession over the ball, std::nullopt is returned.

Returns
A segment representing the displacement of the ball (in metres) due to the friendly team continuously dribbling the ball

◆ getMostRecentTimestamp()

const Timestamp getMostRecentTimestamp ( ) const

Returns the most recent timestamp value of all timestamped member objects of the world

Returns
the most recent timestamp value of all timestamped member objects of the world

◆ getRefereeStage()

const RefereeStage & getRefereeStage ( ) const

Returns the current referee stage

Returns
the current referee stage

◆ getTeamWithPossession()

TeamPossession getTeamWithPossession ( ) const

Gets the team with possession

Returns
The team with possession

◆ operator!=()

bool operator!= ( const World other) const

Defines the inequality operator for a World.

Parameters
otherThe world to compare against for inequality
Returns
True if the other world is not equal to this world and false otherwise

◆ operator==()

bool operator== ( const World other) const

Defines the equality operator for a World. Worlds are equal if their field, ball friendly_team, enemy_team and game_state are equal. The last update timestamp and histories are not part of the equality.

Parameters
otherThe world to compare against for equality
Returns
True if the other robot is equal to this world, and false otherwise

◆ setDribbleDisplacement()

void setDribbleDisplacement ( const std::optional< Segment > &  displacement)

Sets the segment representing the displacement of the ball (in metres) due to the friendly team continuously dribbling the ball across the field.

See also
getDribbleDisplacement for details
Parameters
distancethe displacement of the ball

◆ setTeamWithPossession()

void setTeamWithPossession ( TeamPossession  possession)

Sets the team with possession

Parameters
possessionThe team with possession

◆ updateBall()

void updateBall ( const Ball new_ball)

Updates the state of the ball in the world with the new ball data

Parameters
new_ballA Ball containing new ball information

◆ updateEnemyTeamState()

void updateEnemyTeamState ( const Team new_enemy_team_data)

Updates the state of the enemy team in the world with the new team data

Parameters
new_enemy_team_msgThe message containing new enemy team information

◆ updateFriendlyTeamState()

void updateFriendlyTeamState ( const Team new_friendly_team_data)

Updates the state of the friendly team in the world with the new team data

Parameters
new_friendly_team_msgThe message containing new friendly team information

◆ updateGameState()

void updateGameState ( const GameState game_state)

Updates the current Game State

Parameters
game_statethe game state to update with

◆ updateGameStateBall()

void updateGameStateBall ( const Ball ball)

Updates the ball inside of game state

Parameters
ballthe ball to update with

◆ updateRefereeCommand() [1/2]

void updateRefereeCommand ( const RefereeCommand &  command)

Updates the referee command

Parameters
commandthe command sent by the referee

◆ updateRefereeCommand() [2/2]

void updateRefereeCommand ( const RefereeCommand &  command,
Point  ball_placement_point 
)

Updates the referee command

Parameters
commandthe command sent by the referee
ball_placement_pointball placement point

◆ updateRefereeStage()

void updateRefereeStage ( const RefereeStage &  stage)

Updates the referee stage

Parameters
stagethe stage sent by the referee

◆ updateTimestamp()

void updateTimestamp ( Timestamp  timestamp)

Updates the last update timestamp

Parameters
timestampThe last time this World was updated
Exceptions
std::invalid_argumentif timestamp is older than the current last update timestamp

The documentation for this class was generated from the following files: