about summary refs log tree commit diff stats
path: root/data/maps/the_shop
Commit message (Expand)AuthorAgeFilesLines
* Added keyholder sanityStar Rauchenberger2025-09-021-0/+1
* Changed how door location names are formattedStar Rauchenberger2025-08-301-1/+0
* Converted puzzle symbols to an enumStar Rauchenberger2025-08-201-22/+22
* Maps have display names nowStar Rauchenberger2025-08-201-0/+1
* Added the_shopStar Rauchenberger2025-08-182-0/+201
a id='n14' href='#n14'>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
72
73

























































                                                                                 




                                            


        

                                                      




                                                   
#ifndef MIXER_H_6DF82000
#define MIXER_H_6DF82000

#include <SDL_mixer.h>
#include <memory>
#include <stdexcept>
#include <map>
#include <string>

class mix_error : public std::logic_error {
public:

  mix_error() : std::logic_error(Mix_GetError())
  {
  }
};

class mix_wrapper {
public:

  mix_wrapper()
  {
    if (Mix_Init(0) != 0) {
      mix_error ex;
      Mix_Quit();

    	throw ex;
    }

    if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024) != 0) {
      mix_error ex;
      Mix_Quit();

    	throw ex;
    }
  }

  ~mix_wrapper()
  {
    Mix_CloseAudio();
    Mix_Quit();
  }
};

class chunk_deleter {
public:

  void operator()(Mix_Chunk* chunk) {
    Mix_FreeChunk(chunk);
  }
};

using chunk_ptr = std::unique_ptr<Mix_Chunk, chunk_deleter>;

// MUST create the Renderer first!
class Mixer {
public:

  void playSound(std::string_view filename);

  int loopSound(std::string_view filename);

  void stopChannel(int channel);

private:

  Mix_Chunk* getChunkByFilename(std::string filename);

  mix_wrapper mix_;
  std::map<std::string, chunk_ptr> sounds_;
};

#endif /* end of include guard: MIXER_H_6DF82000 */