00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef SOUNDSOURCE_HPP_INCLUDED
00015 #define SOUNDSOURCE_HPP_INCLUDED
00016
00017 #include <map>
00018 #include <string>
00019 #include <vector>
00020
00021 #include "generic_event.hpp"
00022 #include "map.hpp"
00023
00024 class display;
00025
00026 namespace soundsource {
00027
00028 class sourcespec;
00029 class manager;
00030
00031
00032
00033
00034
00035
00036 class positional_source {
00037 friend class manager;
00038
00039 unsigned int _last_played;
00040 unsigned int _min_delay;
00041 unsigned int _chance;
00042 unsigned int _loops;
00043 const unsigned int _id;
00044 unsigned int _range;
00045 unsigned int _faderange;
00046 bool _check_fogged;
00047 std::string _files;
00048 std::vector<gamemap::location> _locations;
00049
00050
00051
00052 static unsigned int last_id;
00053
00054
00055
00056
00057
00058
00059
00060 positional_source(const sourcespec &spec);
00061 ~positional_source();
00062
00063 void update(unsigned int time, const display &disp);
00064 void update_positions(unsigned int time, const display &disp);
00065
00066 void add_location(const gamemap::location &loc);
00067 void remove_location(const gamemap::location &loc);
00068 void replace_location(const gamemap::location &oldloc, const gamemap::location &newloc);
00069
00070 int calculate_volume(const gamemap::location &loc, const display &disp);
00071 };
00072
00073 class manager : public events::observer {
00074
00075 typedef std::map<std::string, positional_source *> positional_source_map;
00076 typedef positional_source_map::iterator positional_source_iterator;
00077
00078 positional_source_map _sources;
00079 const display &_disp;
00080
00081
00082 void update_positions();
00083
00084 public:
00085 manager(const display &disp);
00086 ~manager();
00087
00088
00089 void handle_generic_event(const std::string &event_name);
00090
00091
00092 void add(const sourcespec &source);
00093 void remove(const std::string &id);
00094 void update();
00095
00096 void add_location(const std::string &id, const gamemap::location &loc);
00097 };
00098
00099
00100
00101
00102 class sourcespec {
00103 const std::string &id;
00104 const std::string &files;
00105
00106 int min_delay;
00107 int chance;
00108
00109 int loops;
00110 int range;
00111 int faderange;
00112 bool check_fogged;
00113
00114 std::vector<gamemap::location> locations;
00115
00116 public:
00117 sourcespec(const std::string &id_, const std::string &files_, int min_delay_, int chance_)
00118 : id(id_), files(files_), min_delay(min_delay_), chance(chance_), loops(0),
00119 range(1), faderange(range), check_fogged(false)
00120 {
00121 }
00122
00123 sourcespec& loop(int loops_) {
00124 loops = loops_;
00125 return *this;
00126 }
00127
00128 sourcespec& check_fog(bool fogged) {
00129 check_fogged = fogged;
00130 return *this;
00131 }
00132
00133 sourcespec& location(const gamemap::location &loc) {
00134 locations.push_back(loc);
00135 return *this;
00136 }
00137
00138 sourcespec& full_range(int range_) {
00139 range = maximum<int>(1, range_);
00140 return *this;
00141 }
00142
00143 sourcespec& fade_range(int range_) {
00144 faderange = range_;
00145 return *this;
00146 }
00147
00148 friend class manager;
00149 friend class positional_source;
00150 };
00151
00152 }
00153
00154 #endif