Skip to content

Commit

Permalink
Added SoundLibrary.
Browse files Browse the repository at this point in the history
  • Loading branch information
afritz1 committed Nov 16, 2024
1 parent 181a9ce commit ba9093c
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
2 changes: 2 additions & 0 deletions OpenTESArena/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ SET(TES_AUDIO
"${SRC_ROOT}/Audio/MusicLibrary.h"
"${SRC_ROOT}/Audio/MusicUtils.cpp"
"${SRC_ROOT}/Audio/MusicUtils.h"
"${SRC_ROOT}/Audio/SoundLibrary.cpp"
"${SRC_ROOT}/Audio/SoundLibrary.h"
"${SRC_ROOT}/Audio/WildMidi.cpp"
"${SRC_ROOT}/Audio/WildMidi.h")

Expand Down
70 changes: 70 additions & 0 deletions OpenTESArena/src/Audio/SoundLibrary.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include <algorithm>

#include "SoundLibrary.h"
#include "../Assets/ArenaSoundName.h"

#include "components/debug/Debug.h"

void SoundLibrary::init()
{
// @todo: remove ArenaSoundName and load from SoundDefinitions.txt instead, which would allow new VOC files
const char *soundFilenames[] =
{
// Combat.
ArenaSoundName::ArrowFire,
ArenaSoundName::ArrowHit,
ArenaSoundName::Bash,
ArenaSoundName::BodyFall,
ArenaSoundName::Clank,
ArenaSoundName::EnemyHit,
ArenaSoundName::FemaleDie,
ArenaSoundName::MaleDie,
ArenaSoundName::NHit,
ArenaSoundName::PlayerHit,
ArenaSoundName::Swish,

// Crime.
ArenaSoundName::Halt,
ArenaSoundName::StopThief,

// Fanfare.
ArenaSoundName::Fanfare1,
ArenaSoundName::Fanfare2,

// Movement.
ArenaSoundName::DirtLeft,
ArenaSoundName::DirtRight,
ArenaSoundName::MudLeft,
ArenaSoundName::MudRight,
ArenaSoundName::SnowLeft,
ArenaSoundName::SnowRight,
ArenaSoundName::Splash,
ArenaSoundName::Swim,

// Spells.
ArenaSoundName::Burst,
ArenaSoundName::Explode,
ArenaSoundName::SlowBall,

// Weather.
ArenaSoundName::Thunder
};

for (const char *filename : soundFilenames)
{
this->filenames.emplace_back(std::string(filename));
}

std::sort(this->filenames.begin(), this->filenames.end());
}

int SoundLibrary::getFilenameCount() const
{
return static_cast<int>(this->filenames.size());
}

const char *SoundLibrary::getFilename(int index) const
{
DebugAssertIndex(this->filenames, index);
return this->filenames[index].c_str();
}
21 changes: 21 additions & 0 deletions OpenTESArena/src/Audio/SoundLibrary.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef SOUND_LIBRARY_H
#define SOUND_LIBRARY_H

#include <string>
#include <vector>

#include "components/utilities/Singleton.h"

// Stores all sounds available from game data.
class SoundLibrary : public Singleton<SoundLibrary>
{
private:
std::vector<std::string> filenames;
public:
void init();

int getFilenameCount() const;
const char *getFilename(int index) const;
};

#endif
3 changes: 3 additions & 0 deletions OpenTESArena/src/Game/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "../Assets/TextAssetLibrary.h"
#include "../Assets/TextureManager.h"
#include "../Audio/MusicLibrary.h"
#include "../Audio/SoundLibrary.h"
#include "../Collision/Physics.h"
#include "../Collision/PhysicsBodyActivationListener.h"
#include "../Collision/PhysicsContactListener.h"
Expand Down Expand Up @@ -354,6 +355,8 @@ bool Game::init()
return false;
}

SoundLibrary::getInstance().init();

const std::string musicLibraryPath = audioDataPath + "MusicDefinitions.txt";
if (!MusicLibrary::getInstance().init(musicLibraryPath.c_str()))
{
Expand Down

0 comments on commit ba9093c

Please sign in to comment.