-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added music, persistent music between scenes
- Loading branch information
Showing
18 changed files
with
137 additions
and
17 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#pragma once | ||
#include <cassert> | ||
#include "MusicHolder.hpp" | ||
|
||
MusicHolder* MusicHolder::m_s_Instance = nullptr; | ||
|
||
MusicHolder::MusicHolder() { | ||
// if m_s_Instance != nullptr; game will exit | ||
assert(m_s_Instance == nullptr); | ||
m_s_Instance = this; | ||
} | ||
|
||
Music& MusicHolder::GetMusic(const std::string &filename) { | ||
// get a reference to m_Font via m_s_instance | ||
auto& m = m_s_Instance -> m_Music; | ||
// auto equivalent to map<string, Font> | ||
// create an iterator to hold a key-value pair (kvp) and search for a required kvp using the passed in filename | ||
auto keyValuePair = m.find(filename); | ||
// auto equivalent to map<string, Font>::iterator | ||
|
||
// match? | ||
if (keyValuePair != m.end()) { | ||
// match. | ||
// return the font; second part of kvp | ||
return keyValuePair -> second; | ||
} | ||
else { | ||
// no match. | ||
// create a new key value pair using the filename | ||
auto& music = m[filename]; | ||
// load texture from a file | ||
music.openFromFile(filename); | ||
return music; | ||
} | ||
} | ||
|
||
void MusicHolder::StopAll() { | ||
for (auto &itr : m_s_Instance -> m_Music) { | ||
itr.second.stop(); | ||
} | ||
} | ||
|
||
void MusicHolder::PauseAll() { | ||
for (auto &itr : m_s_Instance -> m_Music) { | ||
itr.second.pause(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#pragma once | ||
|
||
#include <SFML/Audio.hpp> | ||
#include <map> | ||
|
||
using namespace sf; | ||
|
||
class MusicHolder { | ||
private: | ||
// map container from STL, holds string-Font key-pair | ||
std::map<std::string, Music> m_Music; | ||
// pointer of the same type as the class - one and only instance | ||
static MusicHolder* m_s_Instance; | ||
|
||
public: | ||
MusicHolder(); | ||
static Music& GetMusic(std::string const& filename); | ||
static void StopAll(); | ||
static void PauseAll(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters