Made it possible to specify fading distance for a soundsource.

Removed specification of default value for full_range from game events code.
This commit is contained in:
Karol Nowak 2008-03-16 13:56:13 +00:00
parent f2b701c996
commit 9f342c90e1
3 changed files with 23 additions and 6 deletions

View file

@ -1605,6 +1605,7 @@ void event_handler::handle_event_command(const queued_event& event_info,
std::string y = cfg["y"];
std::string loop = cfg["loop"];
std::string full_range = cfg["full_range"];
std::string fade_range = cfg["fade_range"];
assert(state_of_game != NULL);
@ -1620,7 +1621,14 @@ void event_handler::handle_event_command(const queued_event& event_info,
soundsource::sourcespec spec(id, sounds, lexical_cast_default<int>(delay, 1000), lexical_cast_default<int>(chance, 100));
spec.loop(lexical_cast_default<int>(loop, 0));
spec.full_range(lexical_cast_default<int>(full_range, 1));
if(!full_range.empty()) {
spec.full_range(lexical_cast<int>(full_range));
}
if(!fade_range.empty()) {
spec.fade_range(lexical_cast<int>(fade_range));
}
if(play_fogged.empty()) {
spec.check_fog(true);

View file

@ -103,10 +103,11 @@ void manager::add_location(const std::string &id, const gamemap::location &loc)
positional_source::positional_source(const sourcespec &spec)
: _last_played(0), _min_delay(spec.min_delay), _chance(spec.chance), _loops(spec.loops),
_id(last_id++), _range(spec.range), _check_fogged(spec.check_fogged), _files(spec.files),
_locations(spec.locations)
_id(last_id++), _range(spec.range), _faderange(spec.faderange),
_check_fogged(spec.check_fogged), _files(spec.files), _locations(spec.locations)
{
assert(_range > 0);
assert(_faderange > 0);
}
void positional_source::update(unsigned int time, const display &disp)
@ -164,6 +165,7 @@ void positional_source::update_positions(unsigned int time, const display &disp)
int positional_source::calculate_volume(const gamemap::location &loc, const display &disp)
{
assert(_range > 0);
assert(_faderange > 0);
SDL_Rect area = disp.map_area();
gamemap::location center = disp.hex_clicked_on(area.x + area.w / 2, area.y + area.h / 2);
@ -173,8 +175,7 @@ int positional_source::calculate_volume(const gamemap::location &loc, const disp
return 0;
}
int calced = static_cast<int>(( ( (distance - _range) / (double) _range) * DISTANCE_SILENT));
return calced;
return static_cast<int>(( ( (distance - _range) / (double) _faderange) * DISTANCE_SILENT));
}
void positional_source::add_location(const gamemap::location &loc)

View file

@ -42,6 +42,7 @@ class positional_source {
unsigned int _loops;
const unsigned int _id;
unsigned int _range;
unsigned int _faderange;
bool _check_fogged;
std::string _files;
std::vector<gamemap::location> _locations;
@ -106,13 +107,15 @@ class sourcespec {
int loops;
int range;
int faderange;
bool check_fogged;
std::vector<gamemap::location> locations;
public:
sourcespec(const std::string &id_, const std::string &files_, int min_delay_, int chance_)
: id(id_), files(files_), min_delay(min_delay_), chance(chance_), loops(0), check_fogged(false)
: id(id_), files(files_), min_delay(min_delay_), chance(chance_), loops(0),
range(1), faderange(range), check_fogged(false)
{
}
@ -136,6 +139,11 @@ public:
return *this;
}
sourcespec& fade_range(int range_) {
faderange = range_;
return *this;
}
friend class manager;
friend class positional_source;
};