From 201bec665a672ace6cf97f194b71cbb83de1b49c Mon Sep 17 00:00:00 2001 From: Virx Date: Sun, 14 Sep 2025 18:58:38 -0400 Subject: [PATCH 1/2] Update `rlbot_flatbuffers` to v0.18 --- pyproject.toml | 4 ++-- rlbot/interface.py | 9 ++++----- rlbot/managers/bot.py | 30 ++++++++---------------------- rlbot/managers/hivemind.py | 28 +++++++--------------------- rlbot/managers/match.py | 13 ++++++------- rlbot/managers/rendering.py | 3 +-- rlbot/managers/script.py | 13 ++++++------- rlbot/utils/__init__.py | 4 +--- rlbot/utils/gateway.py | 5 ++--- rlbot/version.py | 2 +- 10 files changed, 38 insertions(+), 73 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2372924..2cfdce7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,7 +8,7 @@ description = "A high performance Python interface for communicating with RLBot dynamic = ["version"] requires-python = ">= 3.11" dependencies = [ - "rlbot_flatbuffers~=0.17.0", + "rlbot_flatbuffers~=0.18.2", "psutil==7.*", ] readme = "README.md" @@ -26,7 +26,7 @@ version = {attr = "rlbot.version.__version__"} [dependency-groups] dev = [ - "ruff>=0.12.5", + "ruff>=0.13.0", "toml>=0.10.2", ] diff --git a/rlbot/interface.py b/rlbot/interface.py index a00c8d9..bc934de 100644 --- a/rlbot/interface.py +++ b/rlbot/interface.py @@ -5,7 +5,6 @@ from pathlib import Path from socket import IPPROTO_TCP, TCP_NODELAY, socket from threading import Thread -from typing import Optional from rlbot import flat from rlbot.utils.logging import get_logger @@ -46,13 +45,13 @@ class SocketRelay: Callable[[flat.ControllableTeamInfo], None] ] = [] rendering_status_handlers: list[Callable[[flat.RenderingStatus], None]] = [] - raw_handlers: list[Callable[[flat.CoreMessage], None]] = [] + raw_handlers: list[Callable[[flat.CorePacket], None]] = [] def __init__( self, agent_id: str, connection_timeout: float = 120, - logger: Optional[logging.Logger] = None, + logger: logging.Logger | None = None, ): self.agent_id = agent_id self.connection_timeout = connection_timeout @@ -272,12 +271,12 @@ def handle_incoming_message(self, incoming_message: bytes) -> MsgHandlingResult: Returns True if the message was NOT a shutdown request """ - flatbuffer = flat.CorePacket.unpack(incoming_message).message + flatbuffer = flat.CorePacket.unpack(incoming_message) for raw_handler in self.raw_handlers: raw_handler(flatbuffer) - match flatbuffer.item: + match flatbuffer.message: case flat.DisconnectSignal(): return MsgHandlingResult.TERMINATED case flat.GamePacket() as packet: diff --git a/rlbot/managers/bot.py b/rlbot/managers/bot.py index 43e6984..57eae8f 100644 --- a/rlbot/managers/bot.py +++ b/rlbot/managers/bot.py @@ -1,6 +1,5 @@ import os from traceback import print_exc -from typing import Optional from rlbot import flat from rlbot.interface import ( @@ -13,8 +12,6 @@ from rlbot.utils import fill_desired_game_state from rlbot.utils.logging import DEFAULT_LOGGER, get_logger -WARNED_SPAWN_ID_DEPRECATED = False - class Bot: """ @@ -32,17 +29,6 @@ class Bot: name: str = "" player_id: int = 0 - @property - def spawn_id(self) -> int: - global WARNED_SPAWN_ID_DEPRECATED - if not WARNED_SPAWN_ID_DEPRECATED: - WARNED_SPAWN_ID_DEPRECATED = True - self.logger.warning( - "'spawn_id' getter accessed, which is deprecated in favor of 'player_id'." - ) - - return self.player_id - match_config = flat.MatchConfiguration() """ Contains info about what map you're on, game mode, mutators, etc. @@ -63,10 +49,10 @@ def spawn_id(self) -> int: _has_field_info = False _has_player_mapping = False - _latest_packet: Optional[flat.GamePacket] = None + _latest_packet: flat.GamePacket | None = None _latest_prediction = flat.BallPrediction() - def __init__(self, default_agent_id: Optional[str] = None): + def __init__(self, default_agent_id: str | None = None): agent_id = os.environ.get("RLBOT_AGENT_ID") or default_agent_id if agent_id is None: @@ -107,7 +93,7 @@ def _try_initialize(self): return for player in self.match_config.player_configurations: - match player.variety.item: + match player.variety: case flat.CustomBot(name): if player.player_id == self.player_id: self.name = name @@ -253,7 +239,7 @@ def rendering_status_update(self, update: flat.RenderingStatus): def update_rendering_status( self, status: bool, - index: Optional[int] = None, + index: int | None = None, is_bot: bool = True, ): """ @@ -274,7 +260,7 @@ def handle_match_comm( index: int, team: int, content: bytes, - display: Optional[str], + display: str | None, team_only: bool, ): """ @@ -284,7 +270,7 @@ def handle_match_comm( """ def send_match_comm( - self, content: bytes, display: Optional[str] = None, team_only: bool = False + self, content: bytes, display: str | None = None, team_only: bool = False ): """ Emits a match communication message to other bots and scripts. @@ -307,7 +293,7 @@ def set_game_state( self, balls: dict[int, flat.DesiredBallState] = {}, cars: dict[int, flat.DesiredCarState] = {}, - match_info: Optional[flat.DesiredMatchInfo] = None, + match_info: flat.DesiredMatchInfo | None = None, commands: list[str] = [], ): """ @@ -319,7 +305,7 @@ def set_game_state( game_state = fill_desired_game_state(balls, cars, match_info, commands) self._game_interface.send_msg(game_state) - def set_loadout(self, loadout: flat.PlayerLoadout, index: Optional[int] = None): + def set_loadout(self, loadout: flat.PlayerLoadout, index: int | None = None): """ Sets the loadout of a bot. Can be used to select or generate a loadout for the match when called inside `initialize`. diff --git a/rlbot/managers/hivemind.py b/rlbot/managers/hivemind.py index 311ac25..9af78b2 100644 --- a/rlbot/managers/hivemind.py +++ b/rlbot/managers/hivemind.py @@ -1,7 +1,6 @@ import os from logging import Logger from traceback import print_exc -from typing import Optional from rlbot import flat from rlbot.interface import ( @@ -14,8 +13,6 @@ from rlbot.utils import fill_desired_game_state from rlbot.utils.logging import DEFAULT_LOGGER, get_logger -WARNED_SPAWN_ID_DEPRECATED = False - class Hivemind: """ @@ -34,17 +31,6 @@ class Hivemind: names: list[str] = [] player_ids: list[int] = [] - @property - def spawn_ids(self) -> list[int]: - global WARNED_SPAWN_ID_DEPRECATED - if not WARNED_SPAWN_ID_DEPRECATED: - WARNED_SPAWN_ID_DEPRECATED = True - self._logger.warning( - "'spawn_id' getter accessed, which is deprecated in favor of 'player_id'." - ) - - return self.player_ids - match_config = flat.MatchConfiguration() """ Contains info about what map you're on, game mode, mutators, etc. @@ -65,10 +51,10 @@ def spawn_ids(self) -> list[int]: _has_field_info = False _has_player_mapping = False - _latest_packet: Optional[flat.GamePacket] = None + _latest_packet: flat.GamePacket | None = None _latest_prediction = flat.BallPrediction() - def __init__(self, default_agent_id: Optional[str] = None): + def __init__(self, default_agent_id: str | None = None): agent_id = os.environ.get("RLBOT_AGENT_ID") or default_agent_id if agent_id is None: @@ -110,7 +96,7 @@ def _try_initialize(self): # 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: + match player.variety: case flat.CustomBot(name): if player.player_id == player_id: self.names.append(name) @@ -251,7 +237,7 @@ def rendering_status_update(self, update: flat.RenderingStatus): def update_rendering_status( self, status: bool, - index: Optional[int] = None, + index: int | None = None, is_bot: bool = True, ): """ @@ -283,7 +269,7 @@ def handle_match_comm( index: int, team: int, content: bytes, - display: Optional[str], + display: str | None, team_only: bool, ): """ @@ -296,7 +282,7 @@ def send_match_comm( self, index: int, content: bytes, - display: Optional[str] = None, + display: str | None = None, team_only: bool = False, ): """ @@ -320,7 +306,7 @@ def set_game_state( self, balls: dict[int, flat.DesiredBallState] = {}, cars: dict[int, flat.DesiredCarState] = {}, - match_info: Optional[flat.DesiredMatchInfo] = None, + match_info: flat.DesiredMatchInfo | None = None, commands: list[str] = [], ): """ diff --git a/rlbot/managers/match.py b/rlbot/managers/match.py index fdaf125..ba4ea7b 100644 --- a/rlbot/managers/match.py +++ b/rlbot/managers/match.py @@ -1,6 +1,5 @@ from pathlib import Path from time import sleep -from typing import Optional import psutil @@ -17,14 +16,14 @@ class MatchManager: """ logger = DEFAULT_LOGGER - packet: Optional[flat.GamePacket] = None - rlbot_server_process: Optional[psutil.Process] = None + packet: flat.GamePacket | None = None + rlbot_server_process: psutil.Process | None = None rlbot_server_port = RLBOT_SERVER_PORT initialized = False def __init__( self, - main_executable_path: Optional[Path] = None, + main_executable_path: Path | None = None, main_executable_name: str = MAIN_EXECUTABLE_NAME, ): self.main_executable_path = main_executable_path @@ -76,7 +75,7 @@ def connect( wants_ball_predictions: bool, close_between_matches: bool = True, rlbot_server_ip: str = RLBOT_SERVER_IP, - rlbot_server_port: Optional[int] = None, + rlbot_server_port: int | None = None, ): """ Connects to the RLBot server specifying the given settings. @@ -109,7 +108,7 @@ def connect_and_run( wants_ball_predictions: bool, close_between_matches: bool = True, rlbot_server_ip: str = RLBOT_SERVER_IP, - rlbot_server_port: Optional[int] = None, + rlbot_server_port: int | None = None, background_thread: bool = False, ): """ @@ -184,7 +183,7 @@ def set_game_state( self, balls: dict[int, flat.DesiredBallState] = {}, cars: dict[int, flat.DesiredCarState] = {}, - match_info: Optional[flat.DesiredMatchInfo] = None, + match_info: flat.DesiredMatchInfo | None = None, commands: list[str] = [], ): """ diff --git a/rlbot/managers/rendering.py b/rlbot/managers/rendering.py index 963bd18..8eef087 100644 --- a/rlbot/managers/rendering.py +++ b/rlbot/managers/rendering.py @@ -1,7 +1,6 @@ import math from collections.abc import Callable, Sequence from contextlib import contextmanager -from typing import Optional from rlbot import flat from rlbot.interface import SocketRelay @@ -51,7 +50,7 @@ class Renderer: _logger = get_logger("renderer") _used_group_ids: set[int] = set() - _group_id: Optional[int] = None + _group_id: int | None = None _current_renders: list[flat.RenderMessage] = [] _default_color = white diff --git a/rlbot/managers/script.py b/rlbot/managers/script.py index 8aea134..a3f09f7 100644 --- a/rlbot/managers/script.py +++ b/rlbot/managers/script.py @@ -1,6 +1,5 @@ import os from traceback import print_exc -from typing import Optional from rlbot import flat from rlbot.interface import ( @@ -35,10 +34,10 @@ class Script: _has_match_settings = False _has_field_info = False - _latest_packet: Optional[flat.GamePacket] = None + _latest_packet: flat.GamePacket | None = None _latest_prediction = flat.BallPrediction() - def __init__(self, default_agent_id: Optional[str] = None): + def __init__(self, default_agent_id: str | None = None): agent_id = os.environ.get("RLBOT_AGENT_ID") or default_agent_id if agent_id is None: @@ -200,7 +199,7 @@ def rendering_status_update(self, update: flat.RenderingStatus): def update_rendering_status( self, status: bool, - index: Optional[int] = None, + index: int | None = None, is_bot: bool = False, ): """ @@ -221,7 +220,7 @@ def handle_match_comm( index: int, team: int, content: bytes, - display: Optional[str], + display: str | None, team_only: bool, ): """ @@ -231,7 +230,7 @@ def handle_match_comm( """ def send_match_comm( - self, content: bytes, display: Optional[str] = None, team_only: bool = False + self, content: bytes, display: str | None = None, team_only: bool = False ): """ Emits a match communication message to other bots and scripts. @@ -254,7 +253,7 @@ def set_game_state( self, balls: dict[int, flat.DesiredBallState] = {}, cars: dict[int, flat.DesiredCarState] = {}, - match_info: Optional[flat.DesiredMatchInfo] = None, + match_info: flat.DesiredMatchInfo | None = None, commands: list[str] = [], ): """ diff --git a/rlbot/utils/__init__.py b/rlbot/utils/__init__.py index c478c2e..86e683e 100644 --- a/rlbot/utils/__init__.py +++ b/rlbot/utils/__init__.py @@ -1,12 +1,10 @@ -from typing import Optional - from rlbot import flat def fill_desired_game_state( balls: dict[int, flat.DesiredBallState] = {}, cars: dict[int, flat.DesiredCarState] = {}, - match_info: Optional[flat.DesiredMatchInfo] = None, + match_info: flat.DesiredMatchInfo | None = None, commands: list[str] = [], ) -> flat.DesiredGameState: """ diff --git a/rlbot/utils/gateway.py b/rlbot/utils/gateway.py index d0ace75..1df3e37 100644 --- a/rlbot/utils/gateway.py +++ b/rlbot/utils/gateway.py @@ -3,7 +3,6 @@ import stat import subprocess from pathlib import Path -from typing import Optional import psutil @@ -17,7 +16,7 @@ def find_main_executable_path( main_executable_path: Path, main_executable_name: str -) -> tuple[Path, Optional[Path]]: +) -> tuple[Path, Path | None]: main_executable_path = main_executable_path.absolute().resolve() # check if the path is directly to the main executable @@ -88,7 +87,7 @@ def launch( def find_server_process( main_executable_name: str, -) -> tuple[Optional[psutil.Process], int]: +) -> tuple[psutil.Process | None, int]: logger = DEFAULT_LOGGER for proc in psutil.process_iter(): try: diff --git a/rlbot/version.py b/rlbot/version.py index 1a64d22..57b560f 100644 --- a/rlbot/version.py +++ b/rlbot/version.py @@ -1 +1 @@ -__version__ = "2.0.0-beta.48" +__version__ = "2.0.0-beta.49" From 3fc04a94633d5ea5ee421975e5a9d953870e4cd8 Mon Sep 17 00:00:00 2001 From: Virx Date: Sat, 20 Sep 2025 14:46:26 -0400 Subject: [PATCH 2/2] Fix render test --- tests/render_test/render.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/render_test/render.py b/tests/render_test/render.py index 9487bcd..3582d67 100644 --- a/tests/render_test/render.py +++ b/tests/render_test/render.py @@ -25,7 +25,7 @@ def handle_packet(self, packet: flat.GamePacket): radius = 0 if len(packet.balls) > 0: - match packet.balls[0].shape.item: + match packet.balls[0].shape: case flat.SphereShape() | flat.CylinderShape() as shape: radius = shape.diameter / 2 case flat.BoxShape() as shape: