Codechange: Use template specialisation and instantiation for BaseMedia methods.

Specialisations seem to be the correct way to specialise, rather than redefining the base template.

This removes a macro which instantiated methods individually.
This commit is contained in:
Peter Nelson
2025-03-26 18:11:55 +00:00
committed by Peter Nelson
parent 3375dc3095
commit 529fb88325
7 changed files with 78 additions and 96 deletions

View File

@@ -90,7 +90,7 @@ static bool SetBankSource(MixerChannel *mc, SoundEntry *sound, SoundID sound_id)
void InitializeSound()
{
Debug(misc, 1, "Loading sound effects...");
OpenBankFile(BaseSounds::GetUsedSet()->files->filename);
OpenBankFile(BaseSounds::GetUsedSet()->files[0].filename);
}
@@ -247,28 +247,28 @@ void SndPlayFx(SoundID sound)
StartSound(sound, 0.5, UINT8_MAX);
}
INSTANTIATE_BASE_MEDIA_METHODS(BaseMedia<SoundsSet>, SoundsSet)
/** Names corresponding to the sound set's files */
static const char * const _sound_file_names[] = { "samples" };
static const std::string_view _sound_file_names[] = { "samples" };
template <>
/* static */ std::span<const std::string_view> BaseSet<SoundsSet>::GetFilenames()
{
return _sound_file_names;
}
template <class T>
/* static */ const char * const *BaseSet<T>::file_names = _sound_file_names;
template <class Tbase_set>
/* static */ const char *BaseMedia<Tbase_set>::GetExtension()
template <>
/* static */ const char *BaseMedia<SoundsSet>::GetExtension()
{
return ".obs"; // OpenTTD Base Sounds
}
template <class Tbase_set>
/* static */ bool BaseMedia<Tbase_set>::DetermineBestSet()
template <>
/* static */ bool BaseMedia<SoundsSet>::DetermineBestSet()
{
if (BaseMedia<Tbase_set>::used_set != nullptr) return true;
if (BaseMedia<SoundsSet>::used_set != nullptr) return true;
const Tbase_set *best = nullptr;
for (const Tbase_set *c = BaseMedia<Tbase_set>::available_sets; c != nullptr; c = c->next) {
const SoundsSet *best = nullptr;
for (const SoundsSet *c = BaseMedia<SoundsSet>::available_sets; c != nullptr; c = c->next) {
/* Skip unusable sets */
if (c->GetNumMissing() != 0) continue;
@@ -281,7 +281,8 @@ template <class Tbase_set>
}
}
BaseMedia<Tbase_set>::used_set = best;
return BaseMedia<Tbase_set>::used_set != nullptr;
BaseMedia<SoundsSet>::used_set = best;
return BaseMedia<SoundsSet>::used_set != nullptr;
}
template class BaseMedia<SoundsSet>;