The game no longer refuses to play sounds greater than 100
This commit is contained in:
@@ -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.
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user