From 0f3b10ddcd0639f06458af7e9c65d8e7a827956b Mon Sep 17 00:00:00 2001 From: Jesse Talavera Date: Tue, 5 Mar 2024 13:40:19 -0500 Subject: [PATCH] Refactor the session and environment --- src/libretro/callback/environment.py | 880 +-------------------------- src/libretro/session.py | 241 +++++++- 2 files changed, 238 insertions(+), 883 deletions(-) diff --git a/src/libretro/callback/environment.py b/src/libretro/callback/environment.py index f20bc16..1630552 100644 --- a/src/libretro/callback/environment.py +++ b/src/libretro/callback/environment.py @@ -2,839 +2,14 @@ from typing import * from .._libretro import * -from ..defs import Rotation, PixelFormat, EnvironmentCall, SerializationQuirks +from ..defs import Rotation, PixelFormat, EnvironmentCall -class EnvironmentCallbacks(Protocol): +class EnvironmentCallback(Protocol): @abstractmethod - def environment(self, cmd: int, data: c_void_p) -> bool: ... - - def set_rotation(self, rotation: Rotation | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_ROTATION``. - - Parameters: - rotation: The rotation to set. - - Returns: - ``True`` if the rotation was set, - ``False`` if the environment call is not supported. - """ - return False - - def get_overscan(self, overscan: c_bool | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_OVERSCAN``. - """ - return False - - def get_can_dupe(self, can_dupe: c_bool | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_CAN_DUPE``. - """ - return False - - def set_message(self, message: retro_message | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_MESSAGE``. - - Parameters: - message: The message to set. - - Returns: - ``True`` if the message was set, - ``False`` if the environment call is not supported. - """ - return False - - def shutdown(self) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SHUTDOWN``. - - Returns: - ``True`` if the core is scheduled to be shut down, - ``False`` if the environment call is not supported. - """ - return False - - def set_performance_level(self, level: int | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL``. - - Parameters: - level: The performance level to set. - - Returns: - ``True`` if the performance level was set, - ``False`` if the environment call is not supported. - """ - return False - - def get_system_directory(self, directory: c_char_p | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY``. - """ - return False - - def set_pixel_format(self, pixel_format: PixelFormat | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_PIXEL_FORMAT``. - - Parameters: - pixel_format: The pixel format to set. - - Returns: - ``True`` if the pixel format was set, - ``False`` if the environment call is not supported. - """ - return False - - def set_input_descriptors(self, descriptors: Sequence[retro_input_descriptor] | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS``. - - Parameters: - descriptors: The input descriptors to set. - May include a sentinel with a ``None`` description. - - Returns: - ``True`` if the input descriptors were set, - ``False`` if the environment call is not supported. - """ - return False - - def set_keyboard_callback(self, callback: retro_keyboard_callback | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK``. - - Parameters: - callback: The keyboard callback to set. - - Returns: - ``True`` if the keyboard callback was set, - ``False`` if the environment call is not supported. - """ - return False - - def set_disk_control_interface(self, interface: retro_disk_control_callback | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE``. - - Parameters: - interface: The disk control interface to set. - - Returns: - ``True`` if the disk control interface was set, - ``False`` if the environment call is not supported. - """ - return False - - def set_hw_render(self, callback: retro_hw_render_callback | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_HW_RENDER``. - - Parameters: - callback: The hardware render callback to set. - Modifies it in-place. - - Returns: - ``True`` if the hardware render callback was set, - ``False`` if the environment call is not supported. - """ - return False - - def get_variable(self, variable: retro_variable | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_VARIABLE``. - - Parameters: - variable: The variable to get. - Modifies it in-place. - - Returns: - ``True`` if the variable was retrieved, - ``False`` if the environment call is not supported. - """ - return False - - def set_variables(self, variables: Sequence[retro_variable] | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_VARIABLES``. - """ - return False - - def get_variable_update(self, update: c_bool | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE``. - """ - return False - - def set_support_no_game(self, support: c_bool | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_SUPPORT_NO_GAME``. - - Parameters: - support: Whether to support no-content. - - Returns: - ``True`` if the support was set, - ``False`` if the environment call is not supported. - """ - return False - - def get_libretro_path(self, path: c_char_p | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_LIBRETRO_PATH``. - - Returns: - The path to the libretro core, - or ``None`` if the environment call is not supported. - """ - return False - - def set_frame_time_callback(self, callback: retro_frame_time_callback | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_FRAME_TIME_CALLBACK``. - - Parameters: - callback: The frame time callback to set. - - Returns: - ``True`` if the frame time callback was set, - ``False`` if the environment call is not supported. - """ - return False - - def set_audio_callback(self, callback: retro_audio_callback | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_AUDIO_CALLBACK``. - - Parameters: - callback: The audio callback to set. - - Returns: - ``True`` if the audio callback was set, - ``False`` if the environment call is not supported. - """ - return False - - def get_rumble_interface(self, interface: retro_rumble_interface | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE``. - """ - return False - - def get_input_device_capabilities(self, caps: c_uint64 | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_INPUT_DEVICE_CAPABILITIES``. - """ - return False - - def get_sensor_interface(self, interface: retro_sensor_interface | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_SENSOR_INTERFACE``. - - Returns: - The sensor interface, - or ``None`` if the environment call is not supported. - """ - return False - - def get_camera_interface(self, interface: retro_camera_callback | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_CAMERA_INTERFACE``. - - Returns: - The camera interface, - or ``None`` if the environment call is not supported. - """ - return False - - def get_log_interface(self, interface: retro_log_callback | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_LOG_INTERFACE``. - - Returns: - The log interface, - or ``None`` if the environment call is not supported. - """ - return False - - def get_perf_interface(self, interface: retro_perf_callback | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_PERF_INTERFACE``. - - Returns: - The performance interface, - or ``None`` if the environment call is not supported. - """ - return False - - def get_location_interface(self) -> retro_location_callback | None: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_LOCATION_INTERFACE``. - - Returns: - The location interface, - or ``None`` if the environment call is not supported. - """ - return None - - def get_core_assets_directory(self, directory: c_char_p | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_CORE_ASSETS_DIRECTORY``. - - Returns: - The path to the core's assets directory, - or ``None`` if the environment call is not supported. - """ - return None - - @final - def get_content_directory(self, directory: c_char_p | None) -> bool: - return self.get_core_assets_directory(directory) - - def get_save_directory(self, directory: c_char_p | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY``. - - Returns: - The path to the save directory, - or ``None`` if the environment call is not supported. - """ - return None - - def set_system_av_info(self, info: retro_system_av_info | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_SYSTEM_AV_INFO``. - - Parameters: - info: The system AV info to set. - - Returns: - ``True`` if the system AV info was set, - ``False`` if the environment call is not supported. - """ - return False - - def set_proc_address_callback(self, callback: retro_get_proc_address_interface | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_PROC_ADDRESS_CALLBACK``. - - Parameters: - callback: The proc address callback to set. - - Returns: - ``True`` if the proc address callback was set, - ``False`` if the environment call is not supported. - """ - return False - - def set_subsystem_info(self, info: Sequence[retro_subsystem_info] | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_SUBSYSTEM_INFO``. - - Parameters: - info: The subsystem info to set. - May include a sentinel with a ``None`` description. - - Returns: - ``True`` if the subsystem info was set, - ``False`` if the environment call is not supported. - """ - return False - - def set_controller_info(self, info: retro_controller_info | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_CONTROLLER_INFO``. - - Parameters: - info: The controller info to set. - May include a sentinel with a ``None`` description. - - Returns: - ``True`` if the controller info was set, - ``False`` if the environment call is not supported. - """ - return False - - def set_memory_maps(self, maps: retro_memory_map | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_MEMORY_MAPS``. - - Parameters: - maps: The memory maps to set. - - Returns: - ``True`` if the memory maps were set, - ``False`` if the environment call is not supported. - """ - return False - - def set_geometry(self, geometry: retro_game_geometry | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_GEOMETRY``. - - Parameters: - geometry: The game geometry to set. - - Returns: - ``True`` if the game geometry was set, - ``False`` if the environment call is not supported. - """ - return False - - def get_username(self, username: c_char_p | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_USERNAME``. - - Returns: - The username, - or ``None`` if the environment call is not supported. - """ - return False - - def get_language(self, language: POINTER(enum_retro_language) | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_LANGUAGE``. - - Returns: - The language, - or ``None`` if the environment call is not supported. - """ - return False - - def get_current_software_framebuffer(self, framebuffer: retro_framebuffer | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_CURRENT_SOFTWARE_FRAMEBUFFER``. - - Parameters: - framebuffer: The framebuffer to get. - Modifies it in-place. - - Returns: - ``True`` if the framebuffer was retrieved, - ``False`` if the environment call is not supported. - """ - return False - - def get_hw_render_interface(self) -> retro_hw_render_interface | None: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_HW_RENDER_INTERFACE``. - - Returns: - The hardware render interface, - or ``None`` if the environment call is not supported. - """ - return None - - def set_support_achievements(self, support: bool | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_SUPPORT_ACHIEVEMENTS``. - - Parameters: - support: Whether to support achievements. - - Returns: - ``True`` if the support was set, - ``False`` if the environment call is not supported. - """ - return False - - def set_hw_render_context_negotiation_interface(self, interface: retro_hw_render_context_negotiation_interface | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_HW_RENDER_CONTEXT_NEGOTIATION_INTERFACE``. - - Parameters: - interface: The hardware render context negotiation interface to set. - - Returns: - ``True`` if the hardware render context negotiation interface was set, - ``False`` if the environment call is not supported. - """ - return False - - def set_serialization_quirks(self, quirks: SerializationQuirks) -> SerializationQuirks | None: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_SERIALIZATION_QUIRKS``. - - Parameters: - quirks: The serialization quirks to set. - - Returns: - The original serialization quirks with all unrecognized flags set to zero, - or ``None`` if the environment call is not supported. - """ - return None - - def set_hw_shared_context(self) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_HW_SHARED_CONTEXT``. - - Returns: - ``True`` if the hardware shared context was set, - ``False`` if the environment call is not supported. - """ - return False - - def get_vfs_interface(self) -> retro_vfs_interface | None: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_VFS_INTERFACE``. - - Returns: - The VFS interface, - or ``None`` if the environment call is not supported. - """ - return None - - def get_led_interface(self) -> retro_led_interface | None: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_LED_INTERFACE``. - - Returns: - The LED interface, - or ``None`` if the environment call is not supported. - """ - return None - - def get_audio_video_enable(self) -> int | None: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_AUDIO_VIDEO_ENABLE``. - - Returns: - The audio/video enable state, - or ``None`` if the environment call is not supported. - """ - return None - - def get_midi_interface(self) -> retro_midi_interface | None: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_MIDI_INTERFACE``. - - Returns: - The MIDI interface, - or ``None`` if the environment call is not supported. - """ - return None - - def get_fastforwarding(self) -> bool | None: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_FASTFORWARDING``. - - Returns: - ``True`` if fastforwarding is enabled, - ``False`` if it's disabled, - or ``None`` if the environment call is not supported. - """ - return None - - def get_target_refresh_rate(self) -> float | None: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_TARGET_REFRESH_RATE``. - - Returns: - The target refresh rate, - or ``None`` if the environment call is not supported. - """ - return None - - def get_input_bitmasks(self) -> bool | None: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_INPUT_BITMASKS``. - - Returns: - ``True`` if input bitmasks are enabled, - ``False`` if they're disabled, - or ``None`` if the environment call is not supported. - """ - return None - - def get_core_options_version(self) -> int | None: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_CORE_OPTIONS_VERSION``. - - Returns: - The core options version, - or ``None`` if the environment call is not supported. - """ - return None - - def set_core_options(self, options: Sequence[retro_core_option_definition] | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_CORE_OPTIONS``. - - Parameters: - options: The core options to set. - May include a sentinel with a ``None`` key. - - Returns: - ``True`` if the core options were set, - ``False`` if the environment call is not supported. - """ - return False - - def set_core_options_intl(self, options: retro_core_options_intl | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_CORE_OPTIONS_INTL``. - - Parameters: - options: The international core options to set. - - Returns: - ``True`` if the international core options were set, - ``False`` if the environment call is not supported. - """ - return False - - def set_core_options_display(self, options: retro_core_option_display | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY``. - - Parameters: - options: The display core options to set. - - Returns: - ``True`` if the display core options were set, - ``False`` if the environment call is not supported. - """ - return False - - def get_preferred_hw_render(self, rendere: enum_retro_hw_context_type | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_PREFERRED_HW_RENDER``. - - Returns: - The preferred hardware render, - or ``None`` if the environment call is not supported. - """ - return None - - def get_disk_control_interface_version(self) -> int | None: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_DISK_CONTROL_INTERFACE_VERSION``. - - Returns: - The disk control interface version, - or ``None`` if the environment call is not supported. - """ - return None - - def set_disk_control_ext_interface(self, interface: retro_disk_control_ext_callback | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_DISK_CONTROL_EXT_INTERFACE``. - - Parameters: - interface: The disk control extended interface to set. - - Returns: - ``True`` if the disk control extended interface was set, - ``False`` if the environment call is not supported. - """ - return False - - def get_message_interface_version(self) -> int | None: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_MESSAGE_INTERFACE_VERSION``. - - Returns: - The message interface version, - or ``None`` if the environment call is not supported. - """ - return None - - def set_message_ext(self, message: retro_message_ext | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_MESSAGE_EXT``. - - Parameters: - message: The extended message to set. - - Returns: - ``True`` if the extended message was set, - ``False`` if the environment call is not supported. - """ - return False - - def get_input_max_users(self, users: c_uint | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_INPUT_MAX_USERS``. - - Returns: - The maximum number of users, - or ``None`` if the environment call is not supported. - """ - return False - - def set_audio_buffer_status_callback(self, callback: retro_audio_buffer_status_callback | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_AUDIO_BUFFER_STATUS_CALLBACK``. - - Parameters: - callback: The audio buffer status callback to set. - - Returns: - ``True`` if the audio buffer status callback was set, - ``False`` if the environment call is not supported. - """ - return False - - def set_minimum_audio_latency(self, latency: int | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_MINIMUM_AUDIO_LATENCY``. - - Parameters: - latency: The minimum audio latency to set. - - Returns: - ``True`` if the minimum audio latency was set, - ``False`` if the environment call is not supported. - """ - return False - - def set_fastforwarding_override(self, override: retro_fastforwarding_override | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_FASTFORWARDING_OVERRIDE``. - - Parameters: - override: The fastforwarding override to set. - - Returns: - ``True`` if the fastforwarding override was set, - ``False`` if the environment call is not supported. - """ - return False - - def set_content_info_override(self, info: Sequence[retro_system_content_info_override] | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_CONTENT_INFO_OVERRIDE``. - - Parameters: - info: The content info override to set. - May include a sentinel with a ``None`` path. - - Returns: - ``True`` if the content info override was set, - ``False`` if the environment call is not supported. - """ - return False - - def get_game_info_ext(self) -> Sequence[retro_game_info_ext] | None: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_GAME_INFO_EXT``. - - Returns: - The extended game info, - or ``None`` if the environment call is not supported. - """ - return None - - def set_core_options_v2(self, options: retro_core_options_v2 | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_CORE_OPTIONS_V2``. - - Parameters: - options: The core options to set. - - Returns: - ``True`` if the core options were set, - ``False`` if the environment call is not supported. - """ - return False - - def set_core_options_v2_intl(self, options: retro_core_options_v2_intl | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_CORE_OPTIONS_V2_INTL``. - - Parameters: - options: The international core options to set. - - Returns: - ``True`` if the international core options were set, - ``False`` if the environment call is not supported. - """ - return False - - def set_core_options_update_display_callback(self, callback: retro_core_options_update_display_callback | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_CORE_OPTIONS_UPDATE_DISPLAY_CALLBACK``. - - Parameters: - callback: The core options update display callback to set. - - Returns: - ``True`` if the core options update display callback was set, - ``False`` if the environment call is not supported. - """ - return False - - def set_variable(self, variable: retro_variable | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_VARIABLE``. - - Parameters: - variable: The variable to set. - - Returns: - ``True`` if the variable was set, - ``False`` if the environment call is not supported. - """ - return False - - def get_throttle_state(self, state: retro_throttle_state | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_THROTTLE_STATE``. - """ - return False - - def get_savestate_context(self, context: enum_retro_savestate_context | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_SAVESTATE_CONTEXT``. - """ - return False - - def get_hw_render_context_negotiation_interface_support(self, interface: retro_hw_render_context_negotiation_interface) -> bool | None: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_HW_RENDER_CONTEXT_NEGOTIATION_INTERFACE_SUPPORT``. - - Returns: - ``True`` if the hardware render context negotiation interface is supported, - ``False`` if it isn't, - or ``None`` if the environment call is not supported. - """ - return None - - def get_jit_capable(self, capable: c_bool | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_JIT_CAPABLE``. - """ - return False - - def get_microphone_interface(self, interface: POINTER(retro_microphone_interface) | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_MICROPHONE_INTERFACE``. - """ - return False - - def get_device_power(self, power: POINTER(retro_device_power) | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_DEVICE_POWER``. - """ - return False - - def set_netpacket_interface(self, interface: retro_netpacket_callback | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_SET_NETPACKET_INTERFACE``. - """ - return False - - def get_playlist_directory(self, directory: c_char_p | None) -> bool: - """ - Equivalent to ``RETRO_ENVIRONMENT_GET_PLAYLIST_DIRECTORY``. - """ - return False - - -def environment_callback(env: EnvironmentCallbacks) -> retro_environment_t: + def environment(self, cmd: EnvironmentCall, data: c_void_p) -> bool: ... + +def environment_callback(env: EnvironmentCallback) -> retro_environment_t: def callback(cmd: int, data: c_void_p) -> bool: match cmd: case EnvironmentCall.SetRotation: @@ -953,8 +128,8 @@ def callback(cmd: int, data: c_void_p) -> bool: return False case EnvironmentCall.GetLogInterface: - # TODO: Implement - return False + ptr = cast(data, POINTER(retro_log_callback)) + return env.get_log_interface(ptr.contents if ptr else None) case EnvironmentCall.GetPerfInterface: # TODO: Implement @@ -1194,44 +369,3 @@ def callback(cmd: int, data: c_void_p) -> bool: return False return callback - -class Environment(EnvironmentCallbacks): - def __init__(self): - self.rotation: Rotation | None = Rotation.NONE - self.overscan: bool | None = False - self.can_dupe: bool | None = False - self.support_no_game: bool | None = False - self._env = environment_callback(self) - - def environment(self, cmd: int, data: c_void_p) -> bool: - return self._env(cmd, data) - - def set_rotation(self, rotation: Rotation | None) -> bool: - if self.rotation is None: - return False - - if rotation is not None: - self.rotation = rotation - - return True - - def get_overscan(self, overscan: c_bool | None) -> bool: - if self.overscan is None: - return False - - if overscan is not None: - overscan.value = self.overscan - - return True - - def set_support_no_game(self, support: c_bool | None) -> bool: - if support is not None: - self.support_no_game = support - - return True - - def set_proc_address_callback(self, callback: retro_get_proc_address_interface | None) -> bool: - if callback is not None: - self.proc_address_callback = callback - - return True diff --git a/src/libretro/session.py b/src/libretro/session.py index 700004c..7b5f262 100644 --- a/src/libretro/session.py +++ b/src/libretro/session.py @@ -1,11 +1,13 @@ +from ctypes import * from typing import * from ._libretro import retro_game_info from .core import Core from .callback.audio import AudioCallbacks, AudioState -from libretro.callback.environment import EnvironmentCallbacks, Environment +from .callback.environment import EnvironmentCallback from .callback.input import InputCallbacks, GeneratorInputState from .callback.video import VideoCallbacks, SoftwareVideoState +from .defs import * class SpecialContent(NamedTuple): @@ -13,14 +15,14 @@ class SpecialContent(NamedTuple): content: Sequence[str] -class Session: +class Session(EnvironmentCallback): + def __init__( self, core: Core | str, audio: AudioCallbacks, input_state: InputCallbacks, video: VideoCallbacks, - environment: EnvironmentCallbacks, content: str | SpecialContent | None = None, ): if core is None: @@ -34,7 +36,6 @@ def __init__( self._audio = audio self._input = input_state self._video = video - self._environment = environment self._content = content def __enter__(self): @@ -43,7 +44,7 @@ def __enter__(self): self._core.set_audio_sample_batch(self._audio.audio_sample_batch) self._core.set_input_poll(self._input.poll) self._core.set_input_state(self._input.state) - self._core.set_environment(self._environment.environment) + self._core.set_environment(self.environment) self._core.init() loaded: bool = False @@ -85,9 +86,231 @@ def input(self) -> InputCallbacks: def video(self) -> VideoCallbacks: return self._video - @property - def environment(self) -> EnvironmentCallbacks: - return self._environment + def environment(self, cmd: EnvironmentCall, data: c_void_p) -> bool: + match cmd: + case EnvironmentCall.SetRotation: + # TODO: Implement + pass + case EnvironmentCall.GetOverscan: + # TODO: Implement + pass + case EnvironmentCall.GetCanDupe: + # TODO: Implement + pass + case EnvironmentCall.SetMessage: + # TODO: Implement + pass + case EnvironmentCall.Shutdown: + # TODO: Implement + pass + case EnvironmentCall.SetPerformanceLevel: + # TODO: Implement + pass + case EnvironmentCall.GetSystemDirectory: + # TODO: Implement + pass + case EnvironmentCall.SetPixelFormat: + # TODO: Implement + pass + case EnvironmentCall.SetInputDescriptors: + # TODO: Implement + pass + case EnvironmentCall.SetKeyboardCallback: + # TODO: Implement + pass + case EnvironmentCall.SetDiskControlInterface: + # TODO: Implement + pass + case EnvironmentCall.GetVariable: + # TODO: Implement + pass + case EnvironmentCall.SetVariables: + # TODO: Implement + pass + case EnvironmentCall.GetVariableUpdate: + # TODO: Implement + pass + case EnvironmentCall.SetSupportNoGame: + # TODO: Implement + pass + case EnvironmentCall.GetLibretroPath: + # TODO: Implement + pass + case EnvironmentCall.SetFrameTimeCallback: + # TODO: Implement + pass + case EnvironmentCall.SetAudioCallback: + # TODO: Implement + pass + case EnvironmentCall.GetRumbleInterface: + # TODO: Implement + pass + case EnvironmentCall.GetInputDeviceCapabilities: + # TODO: Implement + pass + case EnvironmentCall.GetSensorInterface: + # TODO: Implement + pass + case EnvironmentCall.GetCameraInterface: + # TODO: Implement + pass + case EnvironmentCall.GetLogInterface: + # TODO: Implement + pass + case EnvironmentCall.GetPerfInterface: + # TODO: Implement + pass + case EnvironmentCall.GetLocationInterface: + # TODO: Implement + pass + case EnvironmentCall.GetCoreAssetsDirectory: + # TODO: Implement + pass + case EnvironmentCall.GetSaveDirectory: + # TODO: Implement + pass + case EnvironmentCall.SetSystemAvInfo: + # TODO: Implement + pass + case EnvironmentCall.SetProcAddressCallback: + # TODO: Implement + pass + case EnvironmentCall.SetSubsystemInfo: + # TODO: Implement + pass + case EnvironmentCall.SetControllerInfo: + # TODO: Implement + pass + case EnvironmentCall.SetMemoryMaps: + # TODO: Implement + pass + case EnvironmentCall.SetGeometry: + # TODO: Implement + pass + case EnvironmentCall.GetUsername: + # TODO: Implement + pass + case EnvironmentCall.GetLanguage: + # TODO: Implement + pass + case EnvironmentCall.GetCurrentSoftwareFramebuffer: + # TODO: Implement + pass + case EnvironmentCall.GetHwRenderInterface: + # TODO: Implement + pass + case EnvironmentCall.SetSupportAchievements: + # TODO: Implement + pass + case EnvironmentCall.SetHwRenderContextNegotiationInterface: + # TODO: Implement + pass + case EnvironmentCall.SetSerializationQuirks: + # TODO: Implement + pass + case EnvironmentCall.SetHwSharedContext: + # TODO: Implement + pass + case EnvironmentCall.GetVfsInterface: + # TODO: Implement + pass + case EnvironmentCall.GetLedInterface: + # TODO: Implement + pass + case EnvironmentCall.GetAudioVideoEnable: + # TODO: Implement + pass + case EnvironmentCall.GetMidiInterface: + # TODO: Implement + pass + case EnvironmentCall.GetFastForwarding: + # TODO: Implement + pass + case EnvironmentCall.GetTargetRefreshRate: + # TODO: Implement + pass + case EnvironmentCall.GetCoreOptionsVersion: + # TODO: Implement + pass + case EnvironmentCall.SetCoreOptions: + # TODO: Implement + pass + case EnvironmentCall.SetCoreOptionsIntl: + # TODO: Implement + pass + case EnvironmentCall.SetCoreOptionsDisplay: + # TODO: Implement + pass + case EnvironmentCall.GetPreferredHwRender: + # TODO: Implement + pass + case EnvironmentCall.GetDiskControlInterfaceVersion: + # TODO: Implement + pass + case EnvironmentCall.SetDiskControlExtInterface: + # TODO: Implement + pass + case EnvironmentCall.GetMessageInterfaceVersion: + # TODO: Implement + pass + case EnvironmentCall.SetMessageExt: + # TODO: Implement + pass + case EnvironmentCall.SetAudioBufferStatusCallback: + # TODO: Implement + pass + case EnvironmentCall.SetMinimumAudioLatency: + # TODO: Implement + pass + case EnvironmentCall.SetFastForwardingOverride: + # TODO: Implement + pass + case EnvironmentCall.SetContentInfoOverride: + # TODO: Implement + pass + case EnvironmentCall.GetGameInfoExt: + # TODO: Implement + pass + case EnvironmentCall.SetCoreOptionsV2: + # TODO: Implement + pass + case EnvironmentCall.SetCoreOptionsV2Intl: + # TODO: Implement + pass + case EnvironmentCall.SetCoreOptionsUpdateDisplayCallback: + # TODO: Implement + pass + case EnvironmentCall.SetVariable: + # TODO: Implement + pass + case EnvironmentCall.GetThrottleState: + # TODO: Implement + pass + case EnvironmentCall.GetSaveStateContext: + # TODO: Implement + pass + case EnvironmentCall.GetHwRenderContextNegotiationInterfaceSupport: + # TODO: Implement + pass + case EnvironmentCall.GetJitCapable: + # TODO: Implement + pass + case EnvironmentCall.GetMicrophoneInterface: + # TODO: Implement + pass + case EnvironmentCall.GetDevicePower: + # TODO: Implement + pass + case EnvironmentCall.SetNetpacketInterface: + # TODO: Implement + pass + case EnvironmentCall.GetPlaylistDirectory: + # TODO: Implement + pass + case _: + return False + # TODO: Define a way to override certain calls + return False def default_session( @@ -96,7 +319,6 @@ def default_session( audio: AudioCallbacks | None = None, input_state: InputCallbacks | None = None, video: VideoCallbacks | None = None, - environment: EnvironmentCallbacks | None = None, ) -> Session: """ Returns a Session with default state objects. @@ -107,6 +329,5 @@ def default_session( audio=audio or AudioState(), input_state=input_state or GeneratorInputState(), video=video or SoftwareVideoState(), - environment=environment or Environment(), content=content ) \ No newline at end of file