2012-08-13 19:20:40 +02:00
|
|
|
/*
|
2019-08-03 19:43:48 +02:00
|
|
|
* This software is licensed under the terms of the MIT License.
|
2017-02-11 04:52:08 +01:00
|
|
|
* See COPYING for further information.
|
2012-08-13 19:20:40 +02:00
|
|
|
* ---
|
2019-01-23 21:10:43 +01:00
|
|
|
* Copyright (c) 2011-2019, Lukas Weber <laochailan@web.de>.
|
2019-07-03 20:00:56 +02:00
|
|
|
* Copyright (c) 2012-2019, Andrei Alexeyev <akari@taisei-project.org>.
|
2012-08-13 19:20:40 +02:00
|
|
|
*/
|
|
|
|
|
2017-11-25 20:45:11 +01:00
|
|
|
#include "taisei.h"
|
|
|
|
|
2012-08-13 19:20:40 +02:00
|
|
|
#include "transition.h"
|
|
|
|
#include "menu/ingamemenu.h"
|
|
|
|
#include "global.h"
|
|
|
|
|
2017-02-24 22:58:27 +01:00
|
|
|
Transition transition;
|
2012-08-13 19:20:40 +02:00
|
|
|
|
2023-04-07 07:49:15 +02:00
|
|
|
static CallChain swap_cc(CallChain *pcc, CallChain newcc) {
|
|
|
|
CallChain cc = *pcc;
|
|
|
|
*pcc = newcc;
|
|
|
|
return cc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CallChain pop_cc(CallChain *pcc) {
|
|
|
|
return swap_cc(pcc, NO_CALLCHAIN);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void run_cc(CallChain *pcc, bool canceled) {
|
|
|
|
CallChain cc = pop_cc(pcc);
|
|
|
|
run_call_chain(&cc, (void*)(uintptr_t)canceled);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void swap_cc_withcancel(CallChain *pcc, CallChain newcc) {
|
|
|
|
CallChain oldcc = swap_cc(pcc, newcc);
|
|
|
|
run_cc(&oldcc, true);
|
|
|
|
}
|
|
|
|
|
2017-02-25 14:23:22 +01:00
|
|
|
void TransFadeBlack(double fade) {
|
|
|
|
fade_out(fade);
|
2017-02-11 04:52:08 +01:00
|
|
|
}
|
|
|
|
|
2017-02-25 14:23:22 +01:00
|
|
|
void TransFadeWhite(double fade) {
|
2018-07-23 19:07:59 +02:00
|
|
|
colorfill(fade, fade, fade, fade);
|
2012-08-13 19:20:40 +02:00
|
|
|
}
|
|
|
|
|
2017-02-25 14:23:22 +01:00
|
|
|
void TransLoader(double fade) {
|
2018-07-23 19:07:59 +02:00
|
|
|
r_color4(fade, fade, fade, fade);
|
2018-02-06 07:19:25 +01:00
|
|
|
fill_screen("loading");
|
2018-04-12 16:08:48 +02:00
|
|
|
r_color4(1, 1, 1, 1);
|
2012-08-18 09:44:38 +02:00
|
|
|
}
|
|
|
|
|
2017-02-25 14:23:22 +01:00
|
|
|
void TransEmpty(double fade) { }
|
2017-02-24 22:58:27 +01:00
|
|
|
|
|
|
|
static bool popq(void) {
|
|
|
|
if(transition.queued.rule) {
|
2017-02-25 14:23:22 +01:00
|
|
|
transition.rule2 = transition.rule;
|
2017-02-24 22:58:27 +01:00
|
|
|
transition.rule = transition.queued.rule;
|
2017-02-25 14:23:22 +01:00
|
|
|
|
|
|
|
if(transition.state == TRANS_IDLE || transition.rule2 == transition.rule) {
|
|
|
|
transition.rule2 = NULL;
|
|
|
|
}
|
|
|
|
|
2017-02-24 22:58:27 +01:00
|
|
|
transition.dur1 = transition.queued.dur1;
|
|
|
|
transition.dur2 = transition.queued.dur2;
|
2023-04-07 07:49:15 +02:00
|
|
|
swap_cc_withcancel(&transition.cc, transition.queued.cc);
|
|
|
|
transition.queued.cc = NO_CALLCHAIN;
|
2017-02-24 22:58:27 +01:00
|
|
|
transition.queued.rule = NULL;
|
|
|
|
|
|
|
|
if(transition.dur1 <= 0) {
|
|
|
|
transition.fade = 1.0;
|
|
|
|
transition.state = TRANS_FADE_OUT;
|
|
|
|
} else {
|
|
|
|
transition.state = TRANS_FADE_IN;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-04-07 05:47:47 +02:00
|
|
|
static void setq(TransitionRule rule, int dur1, int dur2, CallChain cc) {
|
2017-02-24 22:58:27 +01:00
|
|
|
transition.queued.rule = rule;
|
|
|
|
transition.queued.dur1 = dur1;
|
|
|
|
transition.queued.dur2 = dur2;
|
2023-04-07 07:49:15 +02:00
|
|
|
swap_cc_withcancel(&transition.queued.cc, cc);
|
2017-02-24 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2023-04-07 05:47:47 +02:00
|
|
|
void set_transition(TransitionRule rule, int dur1, int dur2, CallChain cc) {
|
2017-02-24 22:58:27 +01:00
|
|
|
static bool initialized = false;
|
|
|
|
|
|
|
|
if(!rule) {
|
2012-08-14 17:56:53 +02:00
|
|
|
return;
|
2017-02-24 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2023-04-07 05:47:47 +02:00
|
|
|
setq(rule, dur1, dur2, cc);
|
2017-02-24 22:58:27 +01:00
|
|
|
|
|
|
|
if(!initialized) {
|
|
|
|
popq();
|
|
|
|
initialized = true;
|
2017-02-25 14:23:22 +01:00
|
|
|
transition.rule2 = NULL;
|
2017-02-24 22:58:27 +01:00
|
|
|
}
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2017-02-24 22:58:27 +01:00
|
|
|
if(transition.state == TRANS_IDLE || rule == transition.rule) {
|
|
|
|
popq();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-26 13:17:48 +01:00
|
|
|
static bool check_transition(void) {
|
2017-02-24 22:58:27 +01:00
|
|
|
if(transition.state == TRANS_IDLE) {
|
2017-02-26 13:17:48 +01:00
|
|
|
return false;
|
2017-02-24 22:58:27 +01:00
|
|
|
}
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2017-02-24 22:58:27 +01:00
|
|
|
if(!transition.rule) {
|
|
|
|
transition.state = TRANS_IDLE;
|
2017-02-26 13:17:48 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void draw_transition(void) {
|
|
|
|
if(!check_transition()) {
|
2017-02-24 22:58:27 +01:00
|
|
|
return;
|
|
|
|
}
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2017-02-25 14:23:22 +01:00
|
|
|
transition.rule(transition.fade);
|
|
|
|
|
|
|
|
if(transition.rule2 && transition.rule2 != transition.rule) {
|
|
|
|
transition.rule2(transition.fade);
|
|
|
|
}
|
2017-02-26 13:17:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void update_transition(void) {
|
|
|
|
if(!check_transition()) {
|
|
|
|
return;
|
|
|
|
}
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2017-02-24 22:58:27 +01:00
|
|
|
if(transition.state == TRANS_FADE_IN) {
|
|
|
|
transition.fade = approach(transition.fade, 1.0, 1.0/transition.dur1);
|
|
|
|
if(transition.fade == 1.0) {
|
|
|
|
transition.state = TRANS_FADE_OUT;
|
2023-04-07 07:49:15 +02:00
|
|
|
popq();
|
|
|
|
run_cc(&transition.cc, false);
|
2017-02-24 22:58:27 +01:00
|
|
|
}
|
|
|
|
} else if(transition.state == TRANS_FADE_OUT) {
|
|
|
|
transition.fade = transition.dur2 ? approach(transition.fade, 0.0, 1.0/transition.dur2) : 0.0;
|
|
|
|
if(transition.fade == 0.0) {
|
|
|
|
transition.state = TRANS_IDLE;
|
|
|
|
popq();
|
|
|
|
}
|
|
|
|
}
|
2012-08-13 19:20:40 +02:00
|
|
|
}
|