Resource Manager (Sounds)

Sound Loading

The Player needs to access sound effects from the resources when jumping.

Adding support to sf::SoundBuffers in the ResourceManager should take a few minutes.

engine/resource_manager.h
// -----
#include <SFML/Audio/SoundBuffer.hpp> // Add: Include sound buffers.

class ResourceManager {
public:
  // -----
  
  // --- Add: Load sound buffer. ---
  /// @brief Loads a sound buffer from the specified file path. If the sound buffer is already loaded, returns the cached instance.
  /// @param filename The relative path to the sound buffer file.
  /// @return A reference to the loaded SFML SoundBuffer. Lifetime is bound to the resource manager instance.
  sf::SoundBuffer& LoadSoundBuffer(const std::filesystem::path& filename);
  // --- End --- 
  
private:
  // -----  
  // --- Add: Cached sound buffers. ---
  /// @brief Cache for loaded sound buffers, mapping file paths to SFML SoundBuffers.
  std::unordered_map<std::filesystem::path, sf::SoundBuffer> sound_buffers_;
  // --- End ---
};

Last updated