Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more support for direct use of Delegate #1218

Open
DanRStevens opened this issue Feb 12, 2025 · 0 comments
Open

Add more support for direct use of Delegate #1218

DanRStevens opened this issue Feb 12, 2025 · 0 comments

Comments

@DanRStevens
Copy link
Collaborator

DanRStevens commented Feb 12, 2025

Often times Signal is kind of a heavy solution when we only really need a Delegate.

For many uses, only a single handler will ever be used. In such cases, using a full Signal adds bloat. We don't need dispatch to a std::vector of Delegate objects when there is only ever going to be one Delegate. By using Signal we needlessly pay for extra costs, such as extra mental load for the more complicated Signal API, extra memory consumption for the std::vector fields, extra indirection through the Signal object, extra code generation, and extra imports leading to longer compile times.

The extra compile time was noted and illustrated here:
OutpostUniverse/OPHD#1573 (comment)

Additionally, developers can always write a delegate handler function that wraps a Signal object. That provides a way to translate an event allowing only one listener into an event that can host multiple listeners. We lose no real generality by sticking with the simpler Delegate API as the default, and let the developer choose when to pay the extra cost of using Signal.


In order to support this move, we should offer more opportunities to use Delegate directly. If no client code is still using the Signal interface for some component, then it can eventually be reduced to only providing callbacks through a Delegate.

Classes of particular interest:

  • Fade
  • Sprite
  • Mixer

Additionally there is one area that is likely to keep using Signal for the foreseeable future:

  • EventHandler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant