Skip to content

Commit

Permalink
Release 0.1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseTG committed Jun 7, 2024
1 parent dfb7b35 commit 8a2e091
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 12 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
> breaking changes may be introduced
> at any time without warning.
## [0.1.9] - 2024-06-07

### Fixed

- Remove some methods or other constructs that were added in Python 3.12,
to ensure compatibility with Python 3.11.

## [0.1.8] - 2024-06-05

### Fixed
Expand Down
4 changes: 3 additions & 1 deletion src/libretro/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
# TODO: Add a CorePhase enum that's updated when entering/leaving each phase.
# (Some envcalls can only be called in certain phases, so this would be useful for error checking.)

_REGION_MEMBERS = Region.__members__.values()


class CoreInterface(Protocol):
"""
Expand Down Expand Up @@ -639,7 +641,7 @@ def get_region(self) -> Region | int:
or as a plain ``int`` if not.
"""
region: int = self._core.retro_get_region()
return Region(region) if region in Region else region
return Region(region) if region in _REGION_MEMBERS else region

def get_memory_data(self, id: int) -> c_void_p | None:
"""
Expand Down
4 changes: 3 additions & 1 deletion src/libretro/drivers/environment/dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

EnvironmentCallbackFunction = Callable[[c_void_p], bool]

_ENVCALL_MEMBERS = EnvironmentCall.__members__.values()


class DictEnvironmentDriver(
EnvironmentDriver, Mapping[EnvironmentCall, EnvironmentCallbackFunction]
Expand All @@ -33,7 +35,7 @@ def __iter__(self) -> KeysView[EnvironmentCall]:

@override
def environment(self, cmd: int, data: c_void_p) -> bool:
if cmd not in EnvironmentCall:
if cmd not in _ENVCALL_MEMBERS:
return False

envcall = EnvironmentCall(cmd)
Expand Down
22 changes: 15 additions & 7 deletions src/libretro/drivers/input/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@

from .driver import InputDriver

# Needed for Python 3.11 compatibility,
# as "int() in MyIntEnumSubclass" wasn't available until Python 3.12
_DEVICEID_ANALOG_MEMBERS = DeviceIdAnalog.__members__.values()
_DEVICEID_JOYPAD_MEMBERS = DeviceIdJoypad.__members__.values()
_DEVICEID_LIGHTGUN_MEMBERS = DeviceIdLightgun.__members__.values()
_DEVICEID_MOUSE_MEMBERS = DeviceIdMouse.__members__.values()
_KEY_MEMBERS = Key.__members__.values()


@dataclass(order=True, slots=True)
class Point:
Expand Down Expand Up @@ -279,7 +287,7 @@ def _lookup_port_state(
InputDevice.JOYPAD,
_,
id,
) if id in DeviceIdJoypad:
) if id in _DEVICEID_JOYPAD_MEMBERS:
# When asking for a specific joypad button,
# return 1 (True) if its pressed and 0 (False) if not
# NOTE: id in DeviceInJoypad is perfectly valid
Expand Down Expand Up @@ -327,15 +335,15 @@ def _lookup_port_state(
InputDevice.ANALOG,
DeviceIndexAnalog.LEFT,
id,
) if (id in DeviceIdAnalog):
) if id in _DEVICEID_ANALOG_MEMBERS:
analog_state: AnalogState
return analog_state.lstick[id]
case (
AnalogState() as analog_state,
InputDevice.ANALOG,
DeviceIndexAnalog.RIGHT,
id,
) if (id in DeviceIdAnalog):
) if id in _DEVICEID_ANALOG_MEMBERS:
analog_state: AnalogState
return analog_state.rstick[id]
case AnalogState(), _, _, _:
Expand All @@ -349,7 +357,7 @@ def _lookup_port_state(
InputDevice.MOUSE,
_,
id,
) if id in DeviceIdMouse:
) if id in _DEVICEID_MOUSE_MEMBERS:
# When asking for a specific mouse button,
# return 1 (True) if its pressed and 0 (False) if not
mouse_state: MouseState
Expand Down Expand Up @@ -382,7 +390,7 @@ def _lookup_port_state(
InputDevice.KEYBOARD,
_,
id,
) if id in Key:
) if id in _KEY_MEMBERS:
# KeyboardState overloads __getitem__ to return True for pressed keys
# and False for unpressed or invalid keys.
return keyboard_state[id]
Expand All @@ -391,7 +399,7 @@ def _lookup_port_state(
return 0

# Yielding a Key value will expose it as a key press on the keyboard device.
case Key(key), InputDevice.KEYBOARD, _, id if key == id and id in Key:
case Key(key), InputDevice.KEYBOARD, _, id if key == id and id in _KEY_MEMBERS:
return 1
case Key(_), _, _, _: # When yielding a Key in all other cases, return 0
return 0
Expand All @@ -400,7 +408,7 @@ def _lookup_port_state(
# with all other devices defaulting to 0.
# Index is ignored.
case LightGunState() as light_gun_state, InputDevice.LIGHTGUN, _, id if (
id in DeviceIdLightgun
id in _DEVICEID_LIGHTGUN_MEMBERS
):
light_gun_state: LightGunState
return light_gun_state[id]
Expand Down
7 changes: 5 additions & 2 deletions src/libretro/drivers/vfs/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
retro_vfs_write_t,
)

_VFS_SEEK_POSITION_MEMBERS = VfsSeekPosition.__members__.values()
_VFS_MKDIR_RESULT_MEMBERS = VfsMkdirResult.__members__.values()


@runtime_checkable
class FileHandle(Protocol):
Expand Down Expand Up @@ -292,7 +295,7 @@ def __seek(self, stream: POINTER(retro_vfs_file_handle), offset: int, whence: in
assert isinstance(offset, int)
assert isinstance(whence, int)

if whence not in VfsSeekPosition:
if whence not in _VFS_SEEK_POSITION_MEMBERS:
return -1

try:
Expand Down Expand Up @@ -473,7 +476,7 @@ def __mkdir(self, path: bytes) -> int:
try:
ok = self.mkdir(path)

if ok not in VfsMkdirResult:
if ok not in _VFS_MKDIR_RESULT_MEMBERS:
raise TypeError(
f"Expected mkdir to return a VfsMkdirResult, got: {type(ok).__name__}"
)
Expand Down
3 changes: 2 additions & 1 deletion src/libretro/drivers/video/opengl/moderngl.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from copy import deepcopy
from importlib import resources
from sys import modules
from typing import final, override
from typing import final

import moderngl

Expand All @@ -30,6 +30,7 @@
)
from OpenGL import GL

from libretro._typing import override
from libretro.api.av import retro_game_geometry, retro_system_av_info
from libretro.api.video import (
HardwareContext,
Expand Down

0 comments on commit 8a2e091

Please sign in to comment.