From 21eab0e58283fb83e9432ffb3fe0f7ecfa10ed6b Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Thu, 8 Jun 2023 23:01:09 +0800 Subject: [PATCH] sync pyglet add module define --- Difficult_Rocket/main.py | 2 +- libs/pyglet/input/win32/xinput.py | 29 ++++++++++++++++++----------- nuitka-win.ps1 | 2 +- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/Difficult_Rocket/main.py b/Difficult_Rocket/main.py index 71619ff..00645f5 100644 --- a/Difficult_Rocket/main.py +++ b/Difficult_Rocket/main.py @@ -98,7 +98,7 @@ class Game(Options): def init_mods(self) -> None: """验证/加载 mod""" - print(self) + self.mod_module = [] mods = [] mod_path = Path(DR_runtime.mod_path) if not mod_path.exists(): diff --git a/libs/pyglet/input/win32/xinput.py b/libs/pyglet/input/win32/xinput.py index 0e41e6b..73e4958 100644 --- a/libs/pyglet/input/win32/xinput.py +++ b/libs/pyglet/input/win32/xinput.py @@ -506,21 +506,27 @@ class XInputDeviceManager(EventDispatcher): if device.xinput_state.dwPacketNumber == device.packet_number: continue - for button, name in controller_api_to_pyglet.items(): - device.controls[name].value = device.xinput_state.Gamepad.wButtons & button - - device.controls['lefttrigger'].value = device.xinput_state.Gamepad.bLeftTrigger - device.controls['righttrigger'].value = device.xinput_state.Gamepad.bRightTrigger - device.controls['leftx'].value = device.xinput_state.Gamepad.sThumbLX - device.controls['lefty'].value = device.xinput_state.Gamepad.sThumbLY - device.controls['rightx'].value = device.xinput_state.Gamepad.sThumbRX - device.controls['righty'].value = device.xinput_state.Gamepad.sThumbRY - - device.packet_number = device.xinput_state.dwPacketNumber + # Post in main thread to avoid potential GL state issues + pyglet.app.platform_event_loop.post_event(self, '_on_state_change', device) self._dev_lock.release() time.sleep(polling_rate) + @staticmethod + def _on_state_change(device): + # Handler to ensure Controller events are dispatched in the main thread. + # The _get_state method dispatches this by posting to the platform event loop. + for button, name in controller_api_to_pyglet.items(): + device.controls[name].value = device.xinput_state.Gamepad.wButtons & button + + device.controls['lefttrigger'].value = device.xinput_state.Gamepad.bLeftTrigger + device.controls['righttrigger'].value = device.xinput_state.Gamepad.bRightTrigger + device.controls['leftx'].value = device.xinput_state.Gamepad.sThumbLX + device.controls['lefty'].value = device.xinput_state.Gamepad.sThumbLY + device.controls['rightx'].value = device.xinput_state.Gamepad.sThumbRX + device.controls['righty'].value = device.xinput_state.Gamepad.sThumbRY + device.packet_number = device.xinput_state.dwPacketNumber + def on_connect(self, device): """A device was connected.""" @@ -530,6 +536,7 @@ class XInputDeviceManager(EventDispatcher): XInputDeviceManager.register_event_type('on_connect') XInputDeviceManager.register_event_type('on_disconnect') +XInputDeviceManager.register_event_type('_on_state_change') _device_manager = XInputDeviceManager() diff --git a/nuitka-win.ps1 b/nuitka-win.ps1 index 82594fe..ca1be12 100644 --- a/nuitka-win.ps1 +++ b/nuitka-win.ps1 @@ -26,7 +26,7 @@ $arg += @("--msvc=latest") $arg += @("--clang") $arg += @("--lto=no") # 包配置 -$arg += @("--nofollow-import-to=objprint,pillow,PIL,cffi") +$arg += @("--nofollow-import-to=objprint,pillow,PIL,cffi,pydoc") $arg += @("--follow-import-to=pyglet") # 数据配置 $arg += @("--include-data-dir=./libs/fonts=./libs/fonts")