projects
/
supertux.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
96b4e53
)
Fade out and pause music on death and resume on restart of level, fixes #1064
author
Tobias Markus
<tobbi@mozilla-uk.org>
Mon, 16 Mar 2015 20:51:35 +0000
(21:51 +0100)
committer
Tobias Markus
<tobbi@mozilla-uk.org>
Mon, 16 Mar 2015 20:52:31 +0000
(21:52 +0100)
src/audio/sound_manager.cpp
patch
|
blob
|
history
src/audio/sound_manager.hpp
patch
|
blob
|
history
src/audio/stream_sound_source.cpp
patch
|
blob
|
history
src/audio/stream_sound_source.hpp
patch
|
blob
|
history
src/object/player.cpp
patch
|
blob
|
history
src/supertux/game_session.cpp
patch
|
blob
|
history
src/supertux/game_session.hpp
patch
|
blob
|
history
src/supertux/sector.cpp
patch
|
blob
|
history
src/supertux/sector.hpp
patch
|
blob
|
history
diff --git
a/src/audio/sound_manager.cpp
b/src/audio/sound_manager.cpp
index
3d38f6c
..
ace96c1
100644
(file)
--- a/
src/audio/sound_manager.cpp
+++ b/
src/audio/sound_manager.cpp
@@
-301,19
+301,25
@@
SoundManager::play_music(const std::string& filename, bool fade)
}
void
}
void
-SoundManager::pause_music()
+SoundManager::pause_music(
float fadetime
)
{
{
- if(music_source)
- {
+ if(fadetime > 0) {
+ if(music_source
+ && music_source->get_fade_state() != StreamSoundSource::FadingPause)
+ music_source->set_fading(StreamSoundSource::FadingPause, fadetime);
+ } else {
music_source->pause();
}
}
void
music_source->pause();
}
}
void
-SoundManager::resume_music()
+SoundManager::resume_music(
float fadetime
)
{
{
- if(music_source)
- {
+ if(fadetime > 0) {
+ if(music_source
+ && music_source->get_fade_state() != StreamSoundSource::FadingResume)
+ music_source->set_fading(StreamSoundSource::FadingResume, fadetime);
+ } else {
music_source->resume();
}
}
music_source->resume();
}
}
diff --git
a/src/audio/sound_manager.hpp
b/src/audio/sound_manager.hpp
index
801b029
..
7056b0d
100644
(file)
--- a/
src/audio/sound_manager.hpp
+++ b/
src/audio/sound_manager.hpp
@@
-64,8
+64,8
@@
public:
void enable_music(bool music_enabled);
void play_music(const std::string& filename, bool fade = false);
void enable_music(bool music_enabled);
void play_music(const std::string& filename, bool fade = false);
- void pause_music();
- void resume_music();
+ void pause_music(
float fadetime = 0
);
+ void resume_music(
float fadetime = 0
);
void stop_music(float fadetime = 0);
bool is_music_enabled() { return music_enabled; }
void stop_music(float fadetime = 0);
bool is_music_enabled() { return music_enabled; }
diff --git
a/src/audio/stream_sound_source.cpp
b/src/audio/stream_sound_source.cpp
index
e813b7d
..
e51a2e5
100644
(file)
--- a/
src/audio/stream_sound_source.cpp
+++ b/
src/audio/stream_sound_source.cpp
@@
-79,7
+79,7
@@
StreamSoundSource::update()
play();
}
play();
}
- if(fade_state == FadingOn) {
+ if(fade_state == FadingOn
|| fade_state == FadingResume
) {
float time = real_time - fade_start_time;
if(time >= fade_time) {
set_gain(1.0);
float time = real_time - fade_start_time;
if(time >= fade_time) {
set_gain(1.0);
@@
-87,10
+87,13
@@
StreamSoundSource::update()
} else {
set_gain(time / fade_time);
}
} else {
set_gain(time / fade_time);
}
- } else if(fade_state == FadingOff) {
+ } else if(fade_state == FadingOff
|| fade_state == FadingPause
) {
float time = real_time - fade_start_time;
if(time >= fade_time) {
float time = real_time - fade_start_time;
if(time >= fade_time) {
- stop();
+ if(fade_state == FadingOff)
+ stop();
+ else
+ pause();
fade_state = NoFading;
} else {
set_gain( (fade_time-time) / fade_time);
fade_state = NoFading;
} else {
set_gain( (fade_time-time) / fade_time);
diff --git
a/src/audio/stream_sound_source.hpp
b/src/audio/stream_sound_source.hpp
index
d840066
..
9e8ac9a
100644
(file)
--- a/
src/audio/stream_sound_source.hpp
+++ b/
src/audio/stream_sound_source.hpp
@@
-29,7
+29,7
@@
public:
void set_sound_file(std::unique_ptr<SoundFile> newfile);
void set_sound_file(std::unique_ptr<SoundFile> newfile);
- enum FadeState { NoFading, FadingOn, FadingOff };
+ enum FadeState { NoFading, FadingOn, FadingOff
, FadingPause, FadingResume
};
void set_fading(FadeState state, float fadetime);
FadeState get_fade_state() const
void set_fading(FadeState state, float fadetime);
FadeState get_fade_state() const
diff --git
a/src/object/player.cpp
b/src/object/player.cpp
index
ce1c8ce
..
93c1094
100644
(file)
--- a/
src/object/player.cpp
+++ b/
src/object/player.cpp
@@
-1526,7
+1526,7
@@
Player::kill(bool completely)
// TODO: need nice way to handle players dying in co-op mode
Sector::current()->effect->fade_out(3.0);
// TODO: need nice way to handle players dying in co-op mode
Sector::current()->effect->fade_out(3.0);
- SoundManager::current()->
stop
_music(3.0);
+ SoundManager::current()->
pause
_music(3.0);
}
}
}
}
diff --git
a/src/supertux/game_session.cpp
b/src/supertux/game_session.cpp
index
57e48e4
..
da864e2
100644
(file)
--- a/
src/supertux/game_session.cpp
+++ b/
src/supertux/game_session.cpp
@@
-82,7
+82,7
@@
GameSession::GameSession(const std::string& levelfile_, Savegame& savegame, Stat
}
int
}
int
-GameSession::restart_level()
+GameSession::restart_level(
bool after_death
)
{
PlayerStatus* currentStatus = m_savegame.get_player_status();
coins_at_start = currentStatus->coins;
{
PlayerStatus* currentStatus = m_savegame.get_player_status();
coins_at_start = currentStatus->coins;
@@
-130,9
+130,13
@@
GameSession::restart_level()
ScreenManager::current()->pop_screen();
return (-1);
}
ScreenManager::current()->pop_screen();
return (-1);
}
-
- SoundManager::current()->stop_music();
- currentsector->play_music(LEVEL_MUSIC);
+ if(after_death == true) {
+ currentsector->resume_music();
+ }
+ else {
+ SoundManager::current()->stop_music();
+ currentsector->play_music(LEVEL_MUSIC);
+ }
if(capture_file != "") {
int newSeed=0; // next run uses a new seed
if(capture_file != "") {
int newSeed=0; // next run uses a new seed
@@
-371,7
+375,7
@@
GameSession::check_end_conditions()
if(end_sequence && end_sequence->is_done()) {
finish(true);
} else if (!end_sequence && tux->is_dead()) {
if(end_sequence && end_sequence->is_done()) {
finish(true);
} else if (!end_sequence && tux->is_dead()) {
- restart_level();
+ restart_level(
true
);
}
}
}
}
diff --git
a/src/supertux/game_session.hpp
b/src/supertux/game_session.hpp
index
4609f8b
..
0499e2d
100644
(file)
--- a/
src/supertux/game_session.hpp
+++ b/
src/supertux/game_session.hpp
@@
-79,7
+79,7
@@
public:
* resources for the current level/world
*/
std::string get_working_directory();
* resources for the current level/world
*/
std::string get_working_directory();
- int restart_level();
+ int restart_level(
bool after_death = false
);
void toggle_pause();
void abort_level();
void toggle_pause();
void abort_level();
diff --git
a/src/supertux/sector.cpp
b/src/supertux/sector.cpp
index
c9879c9
..
146db5a
100644
(file)
--- a/
src/supertux/sector.cpp
+++ b/
src/supertux/sector.cpp
@@
-1497,6
+1497,12
@@
Sector::play_music(MusicType type)
}
}
}
}
+void
+Sector::resume_music()
+{
+ SoundManager::current()->resume_music(1.5f);
+}
+
MusicType
Sector::get_music_type()
{
MusicType
Sector::get_music_type()
{
diff --git
a/src/supertux/sector.hpp
b/src/supertux/sector.hpp
index
885a817
..
e21d1d4
100644
(file)
--- a/
src/supertux/sector.hpp
+++ b/
src/supertux/sector.hpp
@@
-108,6
+108,7
@@
public:
bool inside(const Rectf& rectangle) const;
void play_music(MusicType musictype);
bool inside(const Rectf& rectangle) const;
void play_music(MusicType musictype);
+ void resume_music();
MusicType get_music_type();
int get_active_bullets()
MusicType get_music_type();
int get_active_bullets()