diff --git a/binding-mri/audio-binding.cpp b/binding-mri/audio-binding.cpp index 262f5c7..883f958 100644 --- a/binding-mri/audio-binding.cpp +++ b/binding-mri/audio-binding.cpp @@ -86,6 +86,21 @@ RB_METHOD(audio_##entity##Fade) \ return rb_float_new(shState->audio().entity##Pos()); \ } +#define DEF_AUD_PROP_I(PropName) \ + RB_METHOD(audio##Get##PropName) \ + { \ + RB_UNUSED_PARAM; \ + return rb_fix_new(shState->audio().get##PropName()); \ + } \ + RB_METHOD(audio##Set##PropName) \ + { \ + RB_UNUSED_PARAM; \ + int value; \ + rb_get_args(argc, argv, "i", &value RB_ARG_END); \ + shState->audio().set##PropName(value); \ + return rb_fix_new(value); \ + } + DEF_PLAY_STOP_POS( bgm ) DEF_PLAY_STOP_POS( bgs ) @@ -97,6 +112,9 @@ DEF_FADE( me ) DEF_PLAY_STOP( se ) +DEF_AUD_PROP_I(BGM_Volume) +DEF_AUD_PROP_I(SFX_Volume) + RB_METHOD(audioReset) { RB_UNUSED_PARAM; @@ -121,6 +139,11 @@ RB_METHOD(audioReset) #define BIND_POS(entity) \ _rb_define_module_function(module, #entity "_pos", audio_##entity##Pos); +#define INIT_AUD_PROP_BIND(PropName, prop_name_s) \ +{ \ + _rb_define_module_function(module, prop_name_s, audio##Get##PropName); \ + _rb_define_module_function(module, prop_name_s "=", audio##Set##PropName); \ +} void audioBindingInit() @@ -140,4 +163,7 @@ audioBindingInit() BIND_PLAY_STOP( se ) _rb_define_module_function(module, "__reset__", audioReset); + + INIT_AUD_PROP_BIND( BGM_Volume, "bgm_volume" ); + INIT_AUD_PROP_BIND( SFX_Volume, "sfx_volume" ); } diff --git a/binding-mri/graphics-binding.cpp b/binding-mri/graphics-binding.cpp index d8a874e..01bc8e5 100644 --- a/binding-mri/graphics-binding.cpp +++ b/binding-mri/graphics-binding.cpp @@ -202,6 +202,7 @@ DEF_GRA_PROP_I(Brightness) DEF_GRA_PROP_B(Fullscreen) DEF_GRA_PROP_B(ShowCursor) DEF_GRA_PROP_B(Smooth) +DEF_GRA_PROP_B(Frameskip) #define INIT_GRA_PROP_BIND(PropName, prop_name_s) \ { \ @@ -244,4 +245,5 @@ void graphicsBindingInit() INIT_GRA_PROP_BIND( Fullscreen, "fullscreen" ); INIT_GRA_PROP_BIND( ShowCursor, "show_cursor" ); INIT_GRA_PROP_BIND( Smooth, "smooth" ); + INIT_GRA_PROP_BIND( Frameskip, "frameskip" ); } diff --git a/src/audio.cpp b/src/audio.cpp index fbc62c1..827e61c 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -34,10 +34,17 @@ struct AudioPrivate { + int bgm_volume; + int sfx_volume; + AudioStream bgm; AudioStream bgs; AudioStream me; + int current_bgm_volume; + int current_bgs_volume; + int current_me_volume; + SoundEmitter se; SyncPoint &syncPoint; @@ -69,6 +76,11 @@ struct AudioPrivate se(rtData.config), syncPoint(rtData.syncPoint) { + bgm_volume = 100; + sfx_volume = 100; + current_bgm_volume = 100; + current_bgs_volume = 100; + current_me_volume = 100; meWatch.state = MeNotPlaying; meWatch.thread = createSDLThread (this, "audio_mewatch"); @@ -246,6 +258,7 @@ void Audio::bgmPlay(const char *filename, int pitch, float pos) { + p->current_bgm_volume = volume; p->bgm.play(filename, volume, pitch, pos); } @@ -265,6 +278,7 @@ void Audio::bgsPlay(const char *filename, int pitch, float pos) { + p->current_bgs_volume = volume; p->bgs.play(filename, volume, pitch, pos); } @@ -283,6 +297,7 @@ void Audio::mePlay(const char *filename, int volume, int pitch) { + p->current_me_volume = volume; p->me.play(filename, volume, pitch); } @@ -301,7 +316,7 @@ void Audio::sePlay(const char *filename, int volume, int pitch) { - p->se.play(filename, volume, pitch); + p->se.play(filename, (volume*p->sfx_volume)/100, pitch); } void Audio::seStop() @@ -327,4 +342,44 @@ void Audio::reset() p->se.stop(); } +int Audio::getBGM_Volume() const +{ + return p->bgm_volume; +} + +void Audio::setBGM_Volume(int value) +{ + if(value > 100){ + value = 100; + }else if(value < 0){ + value = 0; + } + p->bgm_volume = value; + p->bgm.lockStream(); + p->bgm.setVolume(AudioStream::External, ((float)(p->bgm_volume * p->current_bgm_volume))/10000.0f ); + p->bgm.unlockStream(); + p->me.lockStream(); + p->me.setVolume(AudioStream::External, ((float)(p->bgm_volume * p->current_me_volume))/10000.0f ); + p->me.unlockStream(); +} + +int Audio::getSFX_Volume() const +{ + return p->sfx_volume; +} + +void Audio::setSFX_Volume(int value) +{ + if(value > 100){ + value = 100; + }else if(value < 0){ + value = 0; + } + p->sfx_volume = value; + p->bgs.lockStream(); + p->bgs.setVolume(AudioStream::External, ((float)(p->sfx_volume * p->current_bgs_volume))/10000.0f ); + p->bgs.unlockStream(); + +} + Audio::~Audio() { delete p; } diff --git a/src/audio.h b/src/audio.h index e231fb6..80e10ec 100644 --- a/src/audio.h +++ b/src/audio.h @@ -22,6 +22,8 @@ #ifndef AUDIO_H #define AUDIO_H +#include "util.h" + /* Concerning the 'pos' parameter: * RGSS3 actually doesn't specify a format for this, * it's only implied that it is a numerical value @@ -68,6 +70,10 @@ public: void reset(); + /* Non-standard extension */ + DECL_ATTR( BGM_Volume, int) + DECL_ATTR( SFX_Volume, int) + private: Audio(RGSSThreadData &rtData); ~Audio(); diff --git a/src/graphics.cpp b/src/graphics.cpp index 0f921ef..7ca53c6 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -1046,6 +1046,16 @@ void Graphics::setSmooth(bool value) p->threadData->config.smoothScaling = value; } +bool Graphics::getFrameskip() const +{ + return p->threadData->config.frameSkip; +} + +void Graphics::setFrameskip(bool value) +{ + p->threadData->config.frameSkip = value; +} + bool Graphics::getShowCursor() const { return p->threadData->ethread->getShowCursor(); diff --git a/src/graphics.h b/src/graphics.h index c52f95d..5202b54 100644 --- a/src/graphics.h +++ b/src/graphics.h @@ -63,6 +63,7 @@ public: DECL_ATTR( Fullscreen, bool ) DECL_ATTR( ShowCursor, bool ) DECL_ATTR( Smooth, bool ) + DECL_ATTR( Frameskip, bool ) /* */ Scene *getScreen() const;