GodotCLient

class godot_gym_api.godot_client.GodotClient(protobuf_message_module: module, engine_address: Tuple[str, int], chunk_size: int = 65536)

Bases: object

Simulator engine client class.

The class sends actions for RL-agent to a Godot app and gets current state from the Godot app. The class establish a persistent TCP connection. The class sends requests in form of JSON-files. The class recieve data in form of Protobuf messages.

ACTION_KEY = 'action'
AGENT_KEY = 'agent'
CONFIG_KEY = 'config'
ENVIRONMENT_KEY = 'environment'
OBSERVATION_KEY = 'observation'
RESET_KEY = 'reset'
WORLD_KEY = 'world'
__init__(protobuf_message_module: module, engine_address: Tuple[str, int], chunk_size: int = 65536) None

Initialize Godot Client.

Parameters:
  • protobuf_message_module (ModuleType) – A module to load protobuf message from.

  • engine_address (Tuple[str, int]) – Tuple of (IP-address, port).

  • chunk_size (int) – Size of the chunk to receive response from engine.

_connect_to_server() None

Repeatedly try to establish a connection to Godot app.

_get_data_from_stream() bytes

Read data from TCP stream.

Returns:

Raw data from TCP stream.

Return type:

bytes

_get_protobuf(raw_value: bytes) Any

Parse bytes to restore Protobuf message.

Parameters:

raw_value (bytes) – Raw data from TCP stream.

Returns:

Restored Protobuf message.

Return type:

Any

_get_response() Dict[str, Any]

Read response from Godot app.

The method can accept only Protobuf messages as Godot response.

Returns:

Received Protobuf message with Agent and World observations.

Return type:

Dict[str, Any]

configure(config: Dict[str, Any]) None

Request engine to set configuration.

Parameters:

config (Dict[str, Any]) – Configuration to be set.

request(request: Dict[str, Any]) Dict[str, Any]

Send request to Godot app and get response.

Parameters:

request (Dict[str, Any]) – Request.

Returns:

Response.

Return type:

Dict[str, Any]

reset(requested_observation: Dict[str, Any]) Dict[str, Any]

Request Godot app to reset environment.

Parameters:

requested_observation (Dict[str, Any]) – Requested observations from World and Agent.

Returns:

Initial observation.

Return type:

Dict[str, Any]

step(action: Any, requested_observation: Dict[str, Any]) Dict[str, Any]

Request engine to perform given action and return new observations.

Parameters:
  • action (Any) – Action to perform by Agent.

  • requested_observation (Dict[str, Any]) – Requested observations from World and Agent.

Returns:

New observation.

Return type:

Dict[str, Any]