Skip to content

Commit

Permalink
Initialize SDL joystick subsystems lazily
Browse files Browse the repository at this point in the history
Should fix performance issues caused by calling functions such as
get_controller every frame.
  • Loading branch information
HexDecimal committed Jan 16, 2024
1 parent ea62af6 commit 390fe35
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@ This project adheres to [Semantic Versioning](https://semver.org/) since version
## [Unreleased]
### Fixed
- Ignore the locale when encoding file paths outside of Windows.
- Fix performance when calling joystick functions.

## [16.2.1] - 2023-09-24
### Fixed
Expand Down
5 changes: 4 additions & 1 deletion tcod/sdl/joystick.py
Expand Up @@ -363,7 +363,10 @@ def _touchpad(self) -> bool:

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


def _get_number() -> int:
Expand Down

0 comments on commit 390fe35

Please sign in to comment.