refactor: Init should return instance
Description
Init currently return void while it can be chained if the Future Soloud is returned.
Thanks for this unique lib!
Hi @Solido,
Thank you so much for your feedback and for trying out the lib!
I’ll look into implementing this in the next update. If you have any other thoughts or suggestions, feel free to share them.
Hey @Solido, thanks for the suggestion! I'm really glad you're looking into this package, and I'm looking forward to what you'll build with it. Big fan of your projects.
Normally, I'd be all in with your suggestion, but for simplicity, I'll try to push back a little bit.
SoLoud, like many audio libraries, is a singleton. Both in C++ and, therefore, also in Dart. I realize it would be better to instance the library, but that's currently not supported and probably never will. Just to be clear, I don't think that it's impossible to have independent instances of SoLoud in Dart, but it's just something that's rarely needed (at least in gamedev) and yet quite hard and labor-intensive for us to do well.
Given that, I think it would be kind of "lying" if we gave developers an instance from init() or (preferrably) from a constructor (such as SoLoud()). Such API would suggest that there are more instances to be had.
Instead, we opted for SoLoud.instance to make it absolutely clear, through the API, that there's only that one singleton. And then, init() can only ever return that one instance.
If you feel dirty using a singleton (understandable), you can go the route I'm generally taking, and creating a facade. (Example using another audio lib.)
Hello @filiph!
To clarify Singleton is, at least to me, a proper way to model sound engine. I should clarify that this is only for expressivity purpose that I'm asking as I want to chain calls, totally OK if it's the same instance that's send back because there's only be one call for the setup.
Here's what I'm writing
await SoLoud.instance.init();
$soloud.value = SoloudAdapter(SoLoud.instance);
Vs what 'I think' it can be
$soloud.value = SoloudAdapter(await SoLoud.init());
The fact that I call Soloud makes it clear, thanks to the uppercase, that's it's an single instance. Just a different grammar approach :) but I get your explanation.
Once presentable, I'll be VERY HAPPY to share with you and Marco!