about summary refs log tree commit diff stats
path: root/data/maps/the_orb/connections.txtpb
blob: 62a764330deb8cd2aa712b3a4c73af2b6e7a811c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
connections {
  from_room: "Main Area"
  to_room: "O Room"
  door { name: "O Puzzles" }
}
connections {
  from_room: "Main Area"
  to_room: "R Room"
  door { name: "R Puzzles" }
}
connections {
  from_room: "Main Area"
  to_room: "B Room"
  door { name: "B Puzzles" }
}
connections {
  from_room: "B Room"
  to_room: "Main Area"
  oneway: true
}
">
#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 */