dolphin icon indicating copy to clipboard operation
dolphin copied to clipboard

Common: Make HookableEvent use non-static data.

Open jordan-woyak opened this issue 11 months ago • 3 comments

This makes Common::HookableEvent into a normal object rather than each event being a unique type with static storage.

The video events for now exist inside a struct accessible from System::GetVideoEvents(). I've also, for now, added a global GetVideoEvents() function for places that don't have a system reference readily available. I'm open to suggestions on doing it differently.

Register and Trigger calls are unfortunately much more verbose, but that's how removing globals goes.

In future PRs I plan to rectify all of our duplicate "callback" implementations, replacing them with HookableEvent. HookableEvent's EventHook handle has automatic callback removal on destruction, which these others do not. e.g. ControllerInterface::RegisterDevicesChangedCallback, Config::AddConfigChangedCallback, Core::AddOnStateChangedCallback, are there more?

I'm also thinking there might be some future situations more cleanly implemented with additional HookableEvents rather than having unrelated subsystems talk to each other.

jordan-woyak avatar May 03 '25 09:05 jordan-woyak

This now also eliminates the usage of Common/StringLiteral.h I think freebsd/macos build bots were having struggles with that, but maybe OatmealDome knows more? Edit: whelp, freebsd/macos builds are still struggling..

jordan-woyak avatar Jun 14 '25 01:06 jordan-woyak

This looks reasonable to me and I always appreciate less global state.

Are the event and hook names used for anything in Release mode? I'm only seeing the debug log prints. Not tragic but maybe ifdef the members out then?

AdmiralCurtiss avatar Jun 15 '25 21:06 AdmiralCurtiss

Are the event and hook names used for anything in Release mode? I'm only seeing the debug log prints. Not tragic but maybe ifdef the members out then?

Good point. I've now disabled those members in non-debug builds.

jordan-woyak avatar Jun 15 '25 23:06 jordan-woyak

If you add e3e0b0ab6477c6b4018e46c6cba2ce1a9c6d6fa4 to this PR the macos/freebsd builds don't fail anymore: #13199.

Dentomologist avatar Sep 04 '25 22:09 Dentomologist

I've added f1410314bdde6cd7be8bb62faf2e3c2c4858be30 to https://github.com/dolphin-emu/dolphin/pull/13199 which converts the new HookableEvents added to AchievementManager since this PR was made.

I have an upcoming PR that crashes when Dolphin exits due to static deinitialization issues in HookableEvent. That crash is fixed by cherry-picking this PR, so let me know if there's anything else I can do to help with this.

Dentomologist avatar Oct 31 '25 00:10 Dentomologist

I've added f141031 to #13199 which converts the new HookableEvents added to AchievementManager since this PR was made.

I have an upcoming PR that crashes when Dolphin exits due to static deinitialization issues in HookableEvent. That crash is fixed by cherry-picking this PR, so let me know if there's anything else I can do to help with this.

Okie, thanks, I'll get this PR cleaned up.

jordan-woyak avatar Oct 31 '25 00:10 jordan-woyak