You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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
The text was updated successfully, but these errors were encountered:
Often times
Signal
is kind of a heavy solution when we only really need aDelegate
.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 astd::vector
ofDelegate
objects when there is only ever going to be oneDelegate
. By usingSignal
we needlessly pay for extra costs, such as extra mental load for the more complicatedSignal
API, extra memory consumption for thestd::vector
fields, extra indirection through theSignal
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 simplerDelegate
API as the default, and let the developer choose when to pay the extra cost of usingSignal
.In order to support this move, we should offer more opportunities to use
Delegate
directly. If no client code is still using theSignal
interface for some component, then it can eventually be reduced to only providing callbacks through aDelegate
.Classes of particular interest:
Fade
Sprite
Mixer
Additionally there is one area that is likely to keep using
Signal
for the foreseeable future:EventHandler
The text was updated successfully, but these errors were encountered: