-
Notifications
You must be signed in to change notification settings - Fork 1
/
SoundCache.cpp
71 lines (61 loc) · 1.76 KB
/
SoundCache.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* Implementation of SoundCache as declared in SoundCache.h
*
* Author: Skylar Payne
* Date: 7/24/2013
* File: SoundCache.cpp
**/
#include "SoundCache.h"
#include "Logger.h"
/**
* @brief SoundCache::Add adds a sound into the cache
* @param file the sound to add
* @return true if font was successfully added or already added, false otherwise
*/
bool SoundCache::Add(const char *file)
{
SoundMap::iterator it = _Resources.find(file);
if(it != _Resources.end())
{
g_Logger << __FILE__ << ": " << __LINE__ << "-Error: " << file << " already exists in SoundCache\n";
return true;
}
sf::SoundBuffer* newSound = new sf::SoundBuffer();
if(!newSound->loadFromFile(file))
{
delete newSound;
newSound = nullptr;
g_Logger << __FILE__ << ": " << __LINE__ << "-Error: " << file << " failed to load\n";
return false;
}
_Resources[file] = newSound;
g_Logger << __FILE__ << ": " << __LINE__ << "-" << file << " was successfullly added to SoundCache\n";
return true;
}
/**
* @brief SoundCache::Remove removes a sound from the cache
* @param file the sound to remove
*/
void SoundCache::Remove(const char *file)
{
SoundMap::iterator it = _Resources.find(file);
if(it != _Resources.end())
{
_Resources.erase(it);
g_Logger << __FILE__ << ": " << __LINE__ << "-" << file << " was removed from SoundCache\n";
}
}
/**
* @brief SoundCache::Get gets a sound from the cache
* @param file the sound to get
* @return the sound, if found, nullptr otherwise
*/
sf::SoundBuffer* SoundCache::Get(const char *file)
{
SoundMap::iterator it = _Resources.find(file);
if(it == _Resources.end())
{
return nullptr;
}
return _Resources[file];
}