The game no longer refuses to play sounds greater than 100

This commit is contained in:
2015-09-25 21:51:47 -04:00
parent 67cf73e593
commit 371459d1b2
3 changed files with 26 additions and 3 deletions

View File

@@ -133,6 +133,7 @@ namespace ResMgr {
/// @tparam type The type of the resource to fetch.
/// @param name The key of the resource to fetch (usually the filename without an extension).
/// @return A smart pointer to the fetched resource.
/// @throw xResMgrErr if the resource could not be found or there was an error loading it.
template<typename type> std::shared_ptr<type> get(std::string name) {
if(resPool<type>::resources().find(name) != resPool<type>::resources().end()) {
if(resPool<type>::pathFound().find(name) != resPool<type>::pathFound().end()) {
@@ -166,6 +167,30 @@ namespace ResMgr {
return get<type>(name);
}
/// Check if a resource with the given name exists.
/// Calling this causes the path to be remembered, same as with get<type>(std::string).
/// @tparam type The type of the resource to fetch.
/// @param name The key of the resource to fetch (usually the filename without an extension).
/// @return True if it exists, false otherwise.
template<typename type> bool have(std::string name) {
if(resPool<type>::resources().find(name) != resPool<type>::resources().end())
return true;
resLoader<type> load;
return resPool<type>::find(name, load.file_ext).is_absolute();
}
/// Check if a resource with the given numerical ID exists
/// In order for this to work, an ID map function must have first been set with setIdMapFn().
/// @tparam type The type of the resource to fetch.
/// @param id The numerical ID of the resource to fetch.
/// @throw xResMgrErr if the ID map function returned an empty string.
/// @throw std::bad_function_call if the ID map function was not set
template<typename type> bool have(int id) {
std::string name = resPool<type>::mapFn()(id);
if(name == "") throw xResMgrErr("Invalid resource ID.");
return have<type>(name);
}
/// Push a new path onto the path resolution stack
/// @tparam type The type of resource the path applies to.
/// @param path The path at which resources of this type may be found.

View File

@@ -73,7 +73,7 @@ void play_sound(short which, short how_many_times) { // if < 0, play asynch
std::shared_ptr<sf::SoundBuffer> sndhandle;
if(!play_sounds || how_many_times == 0) return;
if(abs(which) > NUM_SOUNDS) {
if(abs(which) >= 100 && !ResMgr::have<SoundRsrc>(abs(which))) {
std::cerr << "Error: Sound #" << abs(which) << " does not exist." << std::endl;
return;
}

View File

@@ -11,8 +11,6 @@
#include <SFML/Audio.hpp>
const int NUM_SOUNDS = 100;
typedef unsigned short snd_num_t;
void init_snd_tool();
bool sound_going(snd_num_t which_s);