diff --git a/rlbot/interface.py b/rlbot/interface.py index aba08f0..a4ffda4 100644 --- a/rlbot/interface.py +++ b/rlbot/interface.py @@ -134,7 +134,7 @@ def start_match(self, match_config: Path | flat.MatchConfiguration): flatbuffer = settings case _: raise ValueError( - "Expected MatchSettings or path to match settings toml file" + "Expected MatchConfiguration or path to match config toml file" ) self.send_msg(flatbuffer) @@ -243,21 +243,6 @@ def handle_incoming_messages(self, blocking: bool = False) -> MsgHandlingResult: try: self.socket.setblocking(blocking) incoming_message = self.read_message() - try: - return self.handle_incoming_message(incoming_message) - except flat.InvalidFlatbuffer as e: - self.logger.error( - "Error while unpacking message (%s bytes): %s", - len(incoming_message), - e, - ) - return MsgHandlingResult.TERMINATED - except Exception as e: - self.logger.error( - "Unexpected error while handling message of type: %s", - e, - ) - return MsgHandlingResult.TERMINATED except BlockingIOError: # No incoming messages and blocking==False return MsgHandlingResult.NO_INCOMING_MSGS @@ -265,10 +250,26 @@ def handle_incoming_messages(self, blocking: bool = False) -> MsgHandlingResult: self.logger.error("SocketRelay disconnected unexpectedly!") return MsgHandlingResult.TERMINATED + try: + return self.handle_incoming_message(incoming_message) + except flat.InvalidFlatbuffer as e: + self.logger.error( + "Error while unpacking message (%s bytes): %s", + len(incoming_message), + e, + ) + return MsgHandlingResult.TERMINATED + except Exception as e: + self.logger.error( + "Unexpected error while handling message of type: %s", + e, + ) + return MsgHandlingResult.TERMINATED + def handle_incoming_message(self, incoming_message: bytes) -> MsgHandlingResult: """ Handles a messages by passing it to the relevant handlers. - Returns True if the message was NOT a shutdown request (i.e. NONE). + Returns True if the message was NOT a shutdown request """ flatbuffer = flat.CorePacket.unpack(incoming_message).message diff --git a/rlbot/managers/bot.py b/rlbot/managers/bot.py index f5279c2..43e6984 100644 --- a/rlbot/managers/bot.py +++ b/rlbot/managers/bot.py @@ -106,6 +106,19 @@ def _try_initialize(self): # Not ready to initialize return + for player in self.match_config.player_configurations: + match player.variety.item: + case flat.CustomBot(name): + if player.player_id == self.player_id: + self.name = name + self.logger = get_logger(self.name) + break + else: # else block runs if break was not hit + self.logger.warning( + "Bot with agent id '%s' did not find itself in the match configuration", + self._game_interface.agent_id, + ) + try: self.initialize() except Exception as e: @@ -125,20 +138,6 @@ def _handle_match_config(self, match_config: flat.MatchConfiguration): match_config.enable_rendering == flat.DebugRendering.OnByDefault ) - # Search match settings for our name - for player in self.match_config.player_configurations: - match player.variety.item: - case flat.CustomBot(name): - if player.player_id == self.player_id: - self.name = name - self.logger = get_logger(self.name) - break - else: # else block runs if break was not hit - self.logger.warning( - "Bot with agent id '%s' did not find itself in the match settings", - self._game_interface.agent_id, - ) - self._try_initialize() def _handle_field_info(self, field_info: flat.FieldInfo): @@ -259,7 +258,7 @@ def update_rendering_status( ): """ Requests the server to update the status of the ability for this bot to render. - Will be ignored if rendering has been set to AlwaysOff in the match settings. + Will be ignored if rendering has been set to AlwaysOff in the match configuration. If the status is successfully updated, the `self.rendering_status_update` method will be called which will update `self.renderer.can_render`. - `status`: `True` to enable rendering, `False` to disable. @@ -281,7 +280,7 @@ def handle_match_comm( """ Called when a match communication message is received. See `send_match_comm`. - NOTE: Messages from scripts will have `team == 2` and the index will be its index in the match settings. + NOTE: Messages from scripts will have `team == 2` and the index will be its index in the match configuration. """ def send_match_comm( @@ -331,7 +330,7 @@ def set_loadout(self, loadout: flat.PlayerLoadout, index: Optional[int] = None): def initialize(self): """ - Called when the bot is ready for initialization. Field info, match settings, name, index, and team are + Called when the bot is ready for initialization. Field info, match configuration, name, index, and team are fully loaded at this point, and will not return garbage data unlike in `__init__`. """ diff --git a/rlbot/managers/hivemind.py b/rlbot/managers/hivemind.py index ef8ba4a..311ac25 100644 --- a/rlbot/managers/hivemind.py +++ b/rlbot/managers/hivemind.py @@ -107,6 +107,22 @@ def _try_initialize(self): ): return + # Search match configuration for our spawn ids + for player_id in self.player_ids: + for player in self.match_config.player_configurations: + match player.variety.item: + case flat.CustomBot(name): + if player.player_id == player_id: + self.names.append(name) + self.loggers.append(get_logger(name)) + break + else: # else block runs if break was not hit + self._logger.warning( + "Hivemind with agent id '%s' did not find itself in the match configuration for player id %s", + self._game_interface.agent_id, + player_id, + ) + try: self.initialize() except Exception as e: @@ -125,16 +141,6 @@ def _handle_match_config(self, match_config: flat.MatchConfiguration): self.match_config = match_config self._has_match_settings = True - # Search match settings for our spawn ids - for player_id in self.player_ids: - for player in self.match_config.player_configurations: - match player.variety.item: - case flat.CustomBot(name): - if player.player_id == player_id: - self.names.append(name) - self.loggers.append(get_logger(name)) - break - self._try_initialize() def _handle_field_info(self, field_info: flat.FieldInfo): @@ -250,7 +256,7 @@ def update_rendering_status( ): """ Requests the server to update the status of the ability for this bot to render. - Will be ignored if rendering has been set to AlwaysOff in the match settings. + Will be ignored if rendering has been set to AlwaysOff in the match configuration. If the status is successfully updated, the `self.rendering_status_update` method will be called which will update `self.renderer.can_render`. - `status`: `True` to enable rendering, `False` to disable. @@ -283,7 +289,7 @@ def handle_match_comm( """ Called when a match communication message is received. See `send_match_comm`. - NOTE: Messages from scripts will have `team == 2` and the index will be its index in the match settings. + NOTE: Messages from scripts will have `team == 2` and the index will be its index in the match configuration. """ def send_match_comm( @@ -337,7 +343,7 @@ def set_loadout(self, loadout: flat.PlayerLoadout, index: int): def initialize(self): """ - Called when the bot is ready for initialization. Field info, match settings, name, index, and team are + Called when the bot is ready for initialization. Field info, match configuration, name, index, and team are fully loaded at this point, and will not return garbage data unlike in `__init__`. """ diff --git a/rlbot/managers/match.py b/rlbot/managers/match.py index e666de5..d6e3692 100644 --- a/rlbot/managers/match.py +++ b/rlbot/managers/match.py @@ -108,7 +108,7 @@ def start_match( ensure_server_started: bool = True, ): """ - Starts a match using the given match settings or a path to a match settings toml file. + Starts a match using the given match configuration or a path to a match config toml file. Connection is automatically established if missing. Call `connect` if you want this process to receive match communication or ball prediction messages. """ diff --git a/rlbot/managers/script.py b/rlbot/managers/script.py index 2c7b747..8aea134 100644 --- a/rlbot/managers/script.py +++ b/rlbot/managers/script.py @@ -75,6 +75,17 @@ def _try_initialize(self): self.logger = get_logger(self.name) + for i, script in enumerate(self.match_config.script_configurations): + if script.agent_id == self._game_interface.agent_id: + self.index = i + self.name = script.name + break + else: # else block runs if break was not hit + self.logger.warning( + "Script with agent id '%s' did not find itself in the match configuration", + self._game_interface.agent_id, + ) + try: self.initialize() except Exception as e: @@ -96,17 +107,6 @@ def _handle_match_config(self, match_config: flat.MatchConfiguration): match_config.enable_rendering == flat.DebugRendering.OnByDefault ) - for i, script in enumerate(match_config.script_configurations): - if script.agent_id == self._game_interface.agent_id: - self.index = i - self.name = script.name - break - else: # else block runs if break was not hit - self.logger.warning( - "Script with agent id '%s' did not find itself in the match settings", - self._game_interface.agent_id, - ) - self._try_initialize() def _handle_field_info(self, field_info: flat.FieldInfo): @@ -205,7 +205,7 @@ def update_rendering_status( ): """ Requests the server to update the status of the ability for this bot to render. - Will be ignored if rendering has been set to AlwaysOff in the match settings. + Will be ignored if rendering has been set to AlwaysOff in the match configuration. If the status is successfully updated, the `self.rendering_status_update` method will be called which will update `self.renderer.can_render`. - `status`: `True` to enable rendering, `False` to disable. @@ -227,7 +227,7 @@ def handle_match_comm( """ Called when a match communication message is received. See `send_match_comm`. - NOTE: Messages from scripts will have `team == 2` and the index will be its index in the match settings. + NOTE: Messages from scripts will have `team == 2` and the index will be its index in the match configuration. """ def send_match_comm( @@ -276,7 +276,7 @@ def set_loadout(self, loadout: flat.PlayerLoadout, index: int): def initialize(self): """ - Called when the script is ready for initialization. Field info, match settings, name, and index are + Called when the script is ready for initialization. Field info, match configuration, name, and index are fully loaded at this point, and will not return garbage data unlike in `__init__`. """ diff --git a/rlbot/utils/maps.py b/rlbot/utils/maps.py index 405b8e0..689e6ce 100644 --- a/rlbot/utils/maps.py +++ b/rlbot/utils/maps.py @@ -71,7 +71,6 @@ "EstadioVida_Dusk": "ff_dusk_p", "Mannfield_Dusk": "eurostadium_dusk_p", "Farmstead_Pitched": "farm_grs_p", - "Farmstead_Upsidedown": "farm_hw_p", "Wasteland_Pitched": "wasteland_grs_p", "Neotokyo_Hacked": "neotokyo_hax_p", "AquaDome_Shallows": "Underwater_GRS_P", @@ -84,6 +83,7 @@ "FuturaGarden": "UF_Day_P", "DFHStadium_Anniversary": "stadium_10a_p", "Holyfield": "Labs_Holyfield_Space_P", + "DriftWoods_Night": "woods_night_p" } STANDARD_MAPS = [ @@ -138,4 +138,5 @@ "Neotokyo_Arcade", "FuturaGarden", "DFHStadium_Anniversary", + "DriftWoods_Night" ] diff --git a/rlbot/version.py b/rlbot/version.py index 07f103d..5a6dd25 100644 --- a/rlbot/version.py +++ b/rlbot/version.py @@ -1 +1 @@ -__version__ = "2.0.0-beta.46" +__version__ = "2.0.0-beta.47" diff --git a/tests/render_test/render.py b/tests/render_test/render.py index 3b543ea..9487bcd 100644 --- a/tests/render_test/render.py +++ b/tests/render_test/render.py @@ -1,5 +1,3 @@ -from email.policy import default - from rlbot import flat from rlbot.flat import BallAnchor, CarAnchor, Color, RenderAnchor, Vector3 from rlbot.managers import Script