From 7274072a2dab0aa7d3a2f2f356fc32a8f55c3911 Mon Sep 17 00:00:00 2001 From: Vinyl Darkscratch Date: Tue, 4 Apr 2017 02:31:08 -0700 Subject: [PATCH] Add window fade-out on exit --- binding-mri/oneshot-binding.cpp | 12 +++++++++++- scripts/Main.rb | 2 ++ src/eventthread.h | 3 +++ src/graphics.cpp | 2 ++ src/oneshot.cpp | 20 +++++++++++++++++++- src/oneshot.h | 2 ++ 6 files changed, 39 insertions(+), 2 deletions(-) diff --git a/binding-mri/oneshot-binding.cpp b/binding-mri/oneshot-binding.cpp index 1c13dba..11154da 100644 --- a/binding-mri/oneshot-binding.cpp +++ b/binding-mri/oneshot-binding.cpp @@ -64,6 +64,15 @@ RB_METHOD(oneshotAllowExit) return Qnil; } +RB_METHOD(oneshotExiting) +{ + RB_UNUSED_PARAM; + bool exiting; + rb_get_args(argc, argv, "b", &exiting RB_ARG_END); + shState->oneshot().setExiting(exiting); + return Qnil; +} + RB_METHOD(oneshotShake) { RB_UNUSED_PARAM; @@ -122,7 +131,8 @@ void oneshotBindingInit() _rb_define_module_function(module, "textinput", oneshotTextInput); _rb_define_module_function(module, "reset_obscured", oneshotResetObscured); _rb_define_module_function(module, "obscured_cleared?", oneshotObscuredCleared); - _rb_define_module_function(module, "allow_exit", oneshotAllowExit); + _rb_define_module_function(module, "allow_exit", oneshotAllowExit); + _rb_define_module_function(module, "exiting", oneshotExiting); _rb_define_module_function(module, "shake", oneshotShake); _rb_define_module_function(module, "setwinpos", oneshotSetWindowPos); _rb_define_module_function(module, "getwinpos", oneshotGetWindowPos); diff --git a/scripts/Main.rb b/scripts/Main.rb index aa260bd..23afb7e 100644 --- a/scripts/Main.rb +++ b/scripts/Main.rb @@ -25,11 +25,13 @@ begin # Make scene object (title screen) $scene = Scene_Title.new Oneshot.allow_exit false + Oneshot.exiting false # Call main method as long as $scene is effective while $scene != nil $scene.main end # Fade out + Oneshot.exiting true Graphics.transition(20) Oneshot.allow_exit true rescue Errno::ENOENT diff --git a/src/eventthread.h b/src/eventthread.h index 763b728..510d5f4 100644 --- a/src/eventthread.h +++ b/src/eventthread.h @@ -232,6 +232,9 @@ struct RGSSThreadData /* Set when F12 is released */ AtomicFlag rqResetFinish; + /* True if we're currently exiting */ + AtomicFlag exiting; + /* True if exiting is allowed */ AtomicFlag allowExit; diff --git a/src/graphics.cpp b/src/graphics.cpp index e626b71..c612636 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -816,6 +816,8 @@ void Graphics::transition(int duration, simpleShader.setProg(prog); } + if (p->threadData->exiting) SDL_SetWindowOpacity(p->threadData->window, 1.0f - prog); + /* Draw the composed frame to a buffer first * (we need this because we're skipping PingPong) */ FBO::bind(p->transBuffer.fbo); diff --git a/src/oneshot.cpp b/src/oneshot.cpp index 9b7756e..e4be038 100644 --- a/src/oneshot.cpp +++ b/src/oneshot.cpp @@ -232,7 +232,7 @@ struct OneshotPrivate std::string txtYes; std::string txtNo; - //Allow exiting game + bool exiting; bool allowExit; //Alpha texture data for portions of window obscured by screen edges @@ -500,6 +500,7 @@ Oneshot::Oneshot(RGSSThreadData &threadData) : p->winY = 0; p->winPosChanged = false; p->allowExit = true; + p->exiting = false; /******************** * USERNAME/DOCS PATH @@ -763,6 +764,11 @@ bool Oneshot::obscuredCleared() const return p->obscuredCleared; } +bool Oneshot::exiting() const +{ + return p->exiting; +} + bool Oneshot::allowExit() const { return p->allowExit; @@ -774,6 +780,18 @@ void Oneshot::setYesNo(const char *yes, const char *no) p->txtNo = no; } +void Oneshot::setExiting(bool exiting) +{ + if (p->exiting != exiting) { + p->exiting = exiting; + if (exiting) { + threadData.exiting.set(); + } else { + threadData.exiting.clear(); + } + } +} + void Oneshot::setAllowExit(bool allowExit) { if (p->allowExit != allowExit) { diff --git a/src/oneshot.h b/src/oneshot.h index 49b3da2..65c9796 100644 --- a/src/oneshot.h +++ b/src/oneshot.h @@ -104,10 +104,12 @@ public: const std::vector &obscuredMap() const; bool obscuredCleared() const; bool allowExit() const; + bool exiting() const; //Mutators void setYesNo(const char *yes, const char *no); void setWindowPos(int x, int y); + void setExiting(bool exiting); void setAllowExit(bool allowExit); void resetObscured();