blue-nebula / base

Main repository of Blue Nebula, a fast-paced shooter with a unique parkour system. It is a fork of Red Eclipse and is free software.
https://blue-nebula.org
15 stars 6 forks source link

Rework sounds management #187

Open TheAssassin opened 3 years ago

TheAssassin commented 3 years ago

This PR attempts to rewrite most of the sounds management code. It provides a new template class soundslot_collection, which supports both a map and vector based storage implementation, to efficiently manage map and game sounds. Also, game sounds are now registered in the C++ code so that their registration does no longer rely on matching the order of the registration calls in CubeScript with the enum in the code.

robalni commented 3 years ago

Why do you use a map for gamesounds? I know there is a comment that says that it makes sense to do that but why? If the key is an int that comes from an enum then it feels to me like it should make more sense to use a vector.

TheAssassin commented 3 years ago

We don't fill every slot with a sound, there are many gaps, so using a vector would either require implementing the null object pattern properly, or using pointers to be able to use nullptr to represent gaps. I've first attempted to use a vector at first as well, but I experienced memory issues, and IMO the obvious approach is to use a map. We could optimize on that later on. Performance wise, you don't notice any differences.

Edit: of course, there is std::optional, but a null object is probably the more idiomatic approach.