Skip to content

Commit 390fe35

Browse files
committed
Initialize SDL joystick subsystems lazily
Should fix performance issues caused by calling functions such as get_controller every frame.
1 parent ea62af6 commit 390fe35

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This project adheres to [Semantic Versioning](https://semver.org/) since version
66
## [Unreleased]
77
### Fixed
88
- Ignore the locale when encoding file paths outside of Windows.
9+
- Fix performance when calling joystick functions.
910

1011
## [16.2.1] - 2023-09-24
1112
### Fixed

tcod/sdl/joystick.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,10 @@ def _touchpad(self) -> bool:
363363

364364
def init() -> None:
365365
"""Initialize SDL's joystick and game controller subsystems."""
366-
tcod.sdl.sys.init(tcod.sdl.sys.Subsystem.JOYSTICK | tcod.sdl.sys.Subsystem.GAMECONTROLLER)
366+
CONTROLLER_SYSTEMS = tcod.sdl.sys.Subsystem.JOYSTICK | tcod.sdl.sys.Subsystem.GAMECONTROLLER
367+
if tcod.sdl.sys.Subsystem(lib.SDL_WasInit(CONTROLLER_SYSTEMS)) == CONTROLLER_SYSTEMS:
368+
return # Already initialized
369+
tcod.sdl.sys.init(CONTROLLER_SYSTEMS)
367370

368371

369372
def _get_number() -> int:

0 commit comments

Comments
 (0)