Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions addons/godot_rl_agents/controller/ai_controller_2d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ enum ControlModes {

@export_group("Multi-policy mode options")
## Allows you to set certain agents to use different policies.
## Changing has no effect with default SB3 training. Works with Rllib example.
## Tutorial: https://github.com/edbeeching/godot_rl_agents/blob/main/docs/TRAINING_MULTIPLE_POLICIES.md
## Works with Rllib example (one Python server) and SB3 (one Python server per policy)
## RLlib tutorial: https://github.com/edbeeching/godot_rl_agents/blob/main/docs/TRAINING_MULTIPLE_POLICIES.md
@export var policy_name: String = "shared_policy"

var onnx_model: ONNXModel
Expand All @@ -42,7 +42,7 @@ var _player: Node2D


func _ready():
add_to_group("AGENT")
add_to_group(policy_name)


func init(player: Node2D):
Expand Down
6 changes: 3 additions & 3 deletions addons/godot_rl_agents/controller/ai_controller_3d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ enum ControlModes {

@export_group("Multi-policy mode options")
## Allows you to set certain agents to use different policies.
## Changing has no effect with default SB3 training. Works with Rllib example.
## Tutorial: https://github.com/edbeeching/godot_rl_agents/blob/main/docs/TRAINING_MULTIPLE_POLICIES.md
## Works with Rllib example (one Python server) and SB3 (one Python server per policy)
## RLlib tutorial: https://github.com/edbeeching/godot_rl_agents/blob/main/docs/TRAINING_MULTIPLE_POLICIES.md
@export var policy_name: String = "shared_policy"

var onnx_model: ONNXModel
Expand All @@ -42,7 +42,7 @@ var _player: Node3D


func _ready():
add_to_group("AGENT")
add_to_group(policy_name)


func init(player: Node3D):
Expand Down
21 changes: 18 additions & 3 deletions addons/godot_rl_agents/sync.gd
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ enum ControlModes {
## Whether the inference will be deterministic (NOTE: Only applies to discrete actions in onnx inference mode)
@export var deterministic_inference := true

@export_group("Multi-server mode options")
## Policy name of the AI-controllers that are assigned to this sync node
@export var policy_name: String = "shared_policy"
## When not empty then this value overrides the TCP port (only needed for 'Training' control mode)
@export var tcp_port_override : String = ""

# Onnx model stored for each requested path
var onnx_models: Dictionary

Expand All @@ -26,6 +32,7 @@ var onnx_models: Dictionary
const MAJOR_VERSION := "0"
const MINOR_VERSION := "7"
const DEFAULT_PORT := "11008"
const DEFAULT_PORT_OFFSET := "0"
const DEFAULT_SEED := "1"
var stream: StreamPeerTCP = null
var connected = false
Expand Down Expand Up @@ -360,7 +367,8 @@ func _set_agent_mode(agent: Node):


func _get_agents():
all_agents = get_tree().get_nodes_in_group("AGENT")
all_agents = get_tree().get_nodes_in_group(policy_name)
assert (not all_agents.is_empty(), "No AI-controllers found. Check group name: " + policy_name)
for agent in all_agents:
_set_agent_mode(agent)

Expand Down Expand Up @@ -447,7 +455,7 @@ func connect_to_server():

# "localhost" was not working on windows VM, had to use the IP
var ip = "127.0.0.1"
var port = _get_port()
var port = _get_port() + _get_port_offset()
var connect = stream.connect_to_host(ip, port)
stream.set_no_delay(true) # TODO check if this improves performance or not
stream.poll()
Expand Down Expand Up @@ -479,7 +487,14 @@ func _get_speedup():


func _get_port():
return args.get("port", DEFAULT_PORT).to_int()
if not tcp_port_override.is_empty():
return str(tcp_port_override).to_int()
else:
return args.get("port", DEFAULT_PORT).to_int()


func _get_port_offset():
return args.get("port_offset", DEFAULT_PORT_OFFSET).to_int()


func _set_seed():
Expand Down