diff --git a/binding-mri/audio-binding.cpp b/binding-mri/audio-binding.cpp index 1a098ad..ce301fa 100644 --- a/binding-mri/audio-binding.cpp +++ b/binding-mri/audio-binding.cpp @@ -128,7 +128,6 @@ void audioBindingInit(){ rb_define_singleton_method(module, "play_tag_sounds", RUBY_METHOD_FUNC(rb_audio_playTagSounds), 1); rb_define_singleton_method(module, "stop_tag_sounds", RUBY_METHOD_FUNC(rb_audio_stopTagSounds), -1); - rb_define_singleton_method(module, "unload", RUBY_METHOD_FUNC(rb_audio_unload), 1); rb_define_singleton_method(module, "clear_cache", RUBY_METHOD_FUNC(rb_audio_clearCache), 0); diff --git a/binding-mri/audioplayback-binding.cpp b/binding-mri/audioplayback-binding.cpp index 17f8fd8..2f10af3 100644 --- a/binding-mri/audioplayback-binding.cpp +++ b/binding-mri/audioplayback-binding.cpp @@ -92,6 +92,11 @@ static VALUE rb_playbackGetGroup(VALUE self){ return INT2FIX(pb->getGroup()); } +static VALUE rb_audio_getPath(VALUE self) { + PLAYBACK + return rb_utf8_str_new_cstr(pb->getPath().c_str()); +} + static VALUE rb_playbackSetLoops(VALUE self, VALUE loops){ PLAYBACK pb->setLoops(NUM2INT(loops)); @@ -191,6 +196,8 @@ void audioPlaybackBindingInit(){ rb_define_method(audioplayback_klass, "group=", RUBY_METHOD_FUNC(rb_playbackSetGroup), 1); rb_define_method(audioplayback_klass, "group", RUBY_METHOD_FUNC(rb_playbackGetGroup), 0); + rb_define_method(audioplayback_klass, "path", RUBY_METHOD_FUNC(rb_audio_getPath), 0); + rb_define_method(audioplayback_klass, "loops=", RUBY_METHOD_FUNC(rb_playbackSetLoops), 1); rb_define_method(audioplayback_klass, "loops", RUBY_METHOD_FUNC(rb_playbackGetLoops), 0); rb_define_method(audioplayback_klass, "volume=", RUBY_METHOD_FUNC(rb_playbackSetVolume), 1); diff --git a/scripts/Audio.rb b/scripts/Audio.rb index 66b5723..57eb673 100644 --- a/scripts/Audio.rb +++ b/scripts/Audio.rb @@ -11,6 +11,10 @@ module Audio class << self def bgm_play(path, volume = 100, pitch = 100) + if (@bgm_playback && @bgm_playback.path == path) + return + end + bgm_stop @bgm_pos = 0 @bgm_playback = self.create_sound(path, false, @music_group) diff --git a/scripts/Scene_OF.rb b/scripts/Scene_OF.rb index e69de29..b3d6e42 100644 --- a/scripts/Scene_OF.rb +++ b/scripts/Scene_OF.rb @@ -0,0 +1,40 @@ +#============================================================================== +# ** Scene_Title +#------------------------------------------------------------------------------ +# This class performs title screen processing. +#============================================================================== + +class Scene_Title + + #-------------------------------------------------------------------------- + # * Main Processing + #-------------------------------------------------------------------------- + def main + + # Stop playing ME and BGS + Audio.me_stop + Audio.bgs_stop + + # Execute transition + Graphics.transition(40) + # Main loop + while true + # Update game screen + Graphics.update + # Update input information + Input.update + # only for legacy funcs + Audio.update + # Frame update + update + # Abort loop if screen is changed + if $scene != self + break + end + end + end + + def update + + end +end diff --git a/src/eventthread.cpp b/src/eventthread.cpp index 9a3add5..eda0fee 100644 --- a/src/eventthread.cpp +++ b/src/eventthread.cpp @@ -147,8 +147,9 @@ void EventThread::process(RGSSThreadData &rtData){ SDL_GetWindowPosition(win, &rtData.ethread->winX, &rtData.ethread->winY); while (true) { - if (shState != nullptr) - shState->mainDispatcher().process(); + // TODO: fix main dispatcher segfault + //if (shState != nullptr) + // shState->mainDispatcher().process(); if (!SDL_WaitEvent(&event)) { Debug() << "[EventThread::process] Event error: " << SDL_GetError(); diff --git a/src/sound/audioplayback.cpp b/src/sound/audioplayback.cpp index 887c961..60635ff 100644 --- a/src/sound/audioplayback.cpp +++ b/src/sound/audioplayback.cpp @@ -151,6 +151,12 @@ int AudioPlayback::getGroup() const { return p_group->id; } +const std::string& AudioPlayback::getPath() const{ + if (p_source) + return p_source->getPath(); + return ""; +} + MIX_Track* AudioPlayback::getTrack() const { return p_track; } @@ -224,9 +230,18 @@ bool AudioPlayback::fadeIn(double time, int loops) { if (!p_track || !p_source) return false; - MIX_SetTrackLoops(p_track, loops); + bool result = MIX_SetTrackAudio(p_track, p_source->getAudio()); - return fadeIn(time); + SDL_PropertiesID props = SDL_CreateProperties(); + SDL_SetNumberProperty(props, MIX_PROP_PLAY_FADE_IN_MILLISECONDS_NUMBER, time * 1000.0); + SDL_SetNumberProperty(props, MIX_PROP_PLAY_LOOPS_NUMBER, loops); + if (result) + { + result = MIX_PlayTrack(p_track, props); + } + SDL_DestroyProperties(props); + + return result; } bool AudioPlayback::fadeIn(double time) { diff --git a/src/sound/audioplayback.h b/src/sound/audioplayback.h index 2fd09ae..e09583e 100644 --- a/src/sound/audioplayback.h +++ b/src/sound/audioplayback.h @@ -5,7 +5,7 @@ #include "audiogroup.h" #include "audiosource.h" -constexpr float DEFAULT_FADE_IN = 0.001f; // no more clicks ;lskadfjjkfskljgsf +constexpr float DEFAULT_FADE_IN = 0.0f; class AudioPlayback { @@ -33,6 +33,7 @@ public: void setGroup(int group); int getGroup() const; MIX_Track* getTrack() const; + const std::string& getPath() const; void setLoops(int loops); int getLoops() const;