Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef SOUNDSOURCE_HPP_INCLUDED
00016 #define SOUNDSOURCE_HPP_INCLUDED
00017
00018 #include <map>
00019
00020 #include "generic_event.hpp"
00021 #include "map_location.hpp"
00022 #include "savegame_config.hpp"
00023
00024 class config;
00025 class display;
00026
00027 namespace soundsource {
00028
00029 class sourcespec;
00030 class manager;
00031
00032
00033
00034
00035
00036
00037 class positional_source {
00038 unsigned int last_played_;
00039 int min_delay_;
00040 int chance_;
00041 int loops_;
00042 const unsigned int id_;
00043 int range_;
00044 int faderange_;
00045 bool check_fogged_;
00046 bool check_shrouded_;
00047 std::string files_;
00048 std::vector<map_location> locations_;
00049
00050
00051
00052 static unsigned int last_id;
00053
00054 public:
00055
00056
00057
00058
00059
00060
00061 positional_source(const sourcespec &spec);
00062 ~positional_source();
00063
00064 bool is_global();
00065
00066 void update(unsigned int time, const display &disp);
00067 void update_positions(unsigned int time, const display &disp);
00068
00069 int calculate_volume(const map_location &loc, const display &disp);
00070
00071
00072
00073
00074
00075 void write_config(config& cfg) const;
00076 };
00077
00078 class manager : public events::observer, public savegame::savegame_config {
00079
00080 typedef std::map<std::string, positional_source *> positional_source_map;
00081 typedef positional_source_map::iterator positional_source_iterator;
00082 typedef positional_source_map::const_iterator positional_source_const_iterator;
00083
00084 positional_source_map sources_;
00085 const display &disp_;
00086
00087 public:
00088 manager(const display &disp);
00089 ~manager();
00090
00091
00092 void handle_generic_event(const std::string &event_name);
00093
00094
00095 void add(const sourcespec &source);
00096 void remove(const std::string &id);
00097 void update();
00098
00099
00100 void update_positions();
00101
00102
00103
00104
00105
00106 void write_sourcespecs(config& cfg) const;
00107
00108 config to_config() const;
00109 };
00110
00111
00112
00113
00114
00115
00116 class sourcespec
00117 {
00118 const std::string id_;
00119 const std::string files_;
00120
00121 int min_delay_;
00122 int chance_;
00123
00124 int loops_;
00125 int range_;
00126 int faderange_;
00127 bool check_fogged_;
00128 bool check_shrouded_;
00129
00130 std::vector<map_location> locations_;
00131
00132 public:
00133
00134 sourcespec(const std::string& id, const std::string& files, int min_delay, int chance) :
00135 id_(id),
00136 files_(files),
00137 min_delay_(min_delay),
00138 chance_(chance),
00139 loops_(0),
00140 range_(3),
00141 faderange_(14),
00142 check_fogged_(false),
00143 check_shrouded_(false),
00144 locations_()
00145 {}
00146
00147
00148 sourcespec(const config& cfg);
00149
00150
00151
00152
00153
00154 void write(config& cfg) const;
00155
00156 int loops() const { return loops_; }
00157
00158 void set_loops(int value) {
00159 loops_ = value;
00160 }
00161
00162 bool check_fogged() const { return check_fogged_; }
00163 bool check_shrouded() const { return check_shrouded_; }
00164
00165 void set_check_fogged(bool value) {
00166 check_fogged_ = value;
00167 }
00168
00169 void set_check_shrouded(bool value) {
00170 check_shrouded_ = value;
00171 }
00172
00173 const std::vector<map_location>& get_locations() const {
00174 return locations_;
00175 }
00176
00177 int full_range() const { return range_; }
00178
00179 void set_full_range(int value) {
00180 range_ = value;
00181 }
00182
00183 int fade_range() const { return faderange_; }
00184
00185 void set_fade_range(int value) {
00186 faderange_ = value;
00187 }
00188
00189 int minimum_delay() const { return min_delay_; }
00190
00191 void set_minimum_delay(int value) {
00192 min_delay_ = value;
00193 }
00194
00195 int chance() const { return chance_; }
00196
00197 void set_chance(int value) {
00198 chance_ = value;
00199 }
00200
00201 const std::string& id() const { return id_; }
00202
00203 const std::string& files() const { return files_; }
00204 };
00205
00206 }
00207
00208 #endif