taisei/src/transition.c

159 lines
3.3 KiB
C
Raw Normal View History

2012-08-13 19:20:40 +02:00
/*
* This software is licensed under the terms of the MIT-License
* See COPYING for further information.
2012-08-13 19:20:40 +02:00
* ---
2018-01-04 18:14:31 +01:00
* Copyright (c) 2011-2018, Lukas Weber <laochailan@web.de>.
* Copyright (c) 2012-2018, Andrei Alexeyev <akari@alienslab.net>.
2012-08-13 19:20:40 +02:00
*/
#include "taisei.h"
2012-08-13 19:20:40 +02:00
#include "transition.h"
#include "menu/ingamemenu.h"
#include "global.h"
Transition transition;
2012-08-13 19:20:40 +02:00
2017-02-25 14:23:22 +01:00
void TransFadeBlack(double fade) {
fade_out(fade);
}
2017-02-25 14:23:22 +01:00
void TransFadeWhite(double fade) {
Premultiplied alpha (#133) * WIP premultiplied alpha * WIP color API rework (doesn't build yet; lots of things left to convert) * convert everything remaining to new Color api except stage*_event.c files * convert the stages to new Color api. builds & runs now; still many rendering errors * fix the bullet shader for premultiplied alpha * fix masterspark, graphs and stage 1 fog clouds * fix marisa_b and most of spellcards * Add deprecation warnings for BLEND_ADD and PFLAG_DRAWADD * fix a segfault in stage 6 undo accidental earlier change * fix text_hud.frag.glsl * fix scuttle bg and remaining stage3 BLEND_ADDs * fix marisa laser opacity * hacky fix for myon The old implementation relied on alpha being stored inside p->color. In premul alpha this doesn’t work and functions like color_set_opacity can’t solve this i think. So I tried messing around with it until it looked somewhat similar. * fix marisa_b stars * remove color_set_opacity i overlooked * more plrmode blending changes * fixup additive blending in stage 1 * various premultiplied alpha fixups for bosses and enemies * stage 2 premul alpha fixups * stage 4 premul alpha fixups * stage 5 premul alpha fixups * stage 6 premul alpha fixups * make lasers also use the PMA blend mode * remove PFLAG_DRAWADD and PFLAG_DRAWSUB * fix remaining PMA issues in menus * lame extraspell bg workaround * fix item alpha * make marisaA lasers look somewhat like in master * fix marisaA bomb background fadeout * fixup various r_color4 calls * fix myon * remove dead code * fix use of BLEND_ADD in player death effect * fix myon shot trails (broken on master as well) * fix myon shot fade-in * extend the sprite shaders custom parameter to a vec4 * fix youmuB stuff and make it look somewhat better. the code looks even worse though.
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) {
Premultiplied alpha (#133) * WIP premultiplied alpha * WIP color API rework (doesn't build yet; lots of things left to convert) * convert everything remaining to new Color api except stage*_event.c files * convert the stages to new Color api. builds & runs now; still many rendering errors * fix the bullet shader for premultiplied alpha * fix masterspark, graphs and stage 1 fog clouds * fix marisa_b and most of spellcards * Add deprecation warnings for BLEND_ADD and PFLAG_DRAWADD * fix a segfault in stage 6 undo accidental earlier change * fix text_hud.frag.glsl * fix scuttle bg and remaining stage3 BLEND_ADDs * fix marisa laser opacity * hacky fix for myon The old implementation relied on alpha being stored inside p->color. In premul alpha this doesn’t work and functions like color_set_opacity can’t solve this i think. So I tried messing around with it until it looked somewhat similar. * fix marisa_b stars * remove color_set_opacity i overlooked * more plrmode blending changes * fixup additive blending in stage 1 * various premultiplied alpha fixups for bosses and enemies * stage 2 premul alpha fixups * stage 4 premul alpha fixups * stage 5 premul alpha fixups * stage 6 premul alpha fixups * make lasers also use the PMA blend mode * remove PFLAG_DRAWADD and PFLAG_DRAWSUB * fix remaining PMA issues in menus * lame extraspell bg workaround * fix item alpha * make marisaA lasers look somewhat like in master * fix marisaA bomb background fadeout * fixup various r_color4 calls * fix myon * remove dead code * fix use of BLEND_ADD in player death effect * fix myon shot trails (broken on master as well) * fix myon shot fade-in * extend the sprite shaders custom parameter to a vec4 * fix youmuB stuff and make it look somewhat better. the code looks even worse though.
2018-07-23 19:07:59 +02:00
r_color4(fade, fade, fade, fade);
fill_screen("loading");
r_color4(1, 1, 1, 1);
2012-08-18 09:44:38 +02:00
}
2017-02-25 14:23:22 +01:00
void TransMenu(double fade) {
Premultiplied alpha (#133) * WIP premultiplied alpha * WIP color API rework (doesn't build yet; lots of things left to convert) * convert everything remaining to new Color api except stage*_event.c files * convert the stages to new Color api. builds & runs now; still many rendering errors * fix the bullet shader for premultiplied alpha * fix masterspark, graphs and stage 1 fog clouds * fix marisa_b and most of spellcards * Add deprecation warnings for BLEND_ADD and PFLAG_DRAWADD * fix a segfault in stage 6 undo accidental earlier change * fix text_hud.frag.glsl * fix scuttle bg and remaining stage3 BLEND_ADDs * fix marisa laser opacity * hacky fix for myon The old implementation relied on alpha being stored inside p->color. In premul alpha this doesn’t work and functions like color_set_opacity can’t solve this i think. So I tried messing around with it until it looked somewhat similar. * fix marisa_b stars * remove color_set_opacity i overlooked * more plrmode blending changes * fixup additive blending in stage 1 * various premultiplied alpha fixups for bosses and enemies * stage 2 premul alpha fixups * stage 4 premul alpha fixups * stage 5 premul alpha fixups * stage 6 premul alpha fixups * make lasers also use the PMA blend mode * remove PFLAG_DRAWADD and PFLAG_DRAWSUB * fix remaining PMA issues in menus * lame extraspell bg workaround * fix item alpha * make marisaA lasers look somewhat like in master * fix marisaA bomb background fadeout * fixup various r_color4 calls * fix myon * remove dead code * fix use of BLEND_ADD in player death effect * fix myon shot trails (broken on master as well) * fix myon shot fade-in * extend the sprite shaders custom parameter to a vec4 * fix youmuB stuff and make it look somewhat better. the code looks even worse though.
2018-07-23 19:07:59 +02:00
r_color4(fade, fade, fade, fade);
fill_screen("menu/mainmenubg");
r_color4(1, 1, 1, 1);
}
2017-02-25 14:23:22 +01:00
void TransMenuDark(double fade) {
Premultiplied alpha (#133) * WIP premultiplied alpha * WIP color API rework (doesn't build yet; lots of things left to convert) * convert everything remaining to new Color api except stage*_event.c files * convert the stages to new Color api. builds & runs now; still many rendering errors * fix the bullet shader for premultiplied alpha * fix masterspark, graphs and stage 1 fog clouds * fix marisa_b and most of spellcards * Add deprecation warnings for BLEND_ADD and PFLAG_DRAWADD * fix a segfault in stage 6 undo accidental earlier change * fix text_hud.frag.glsl * fix scuttle bg and remaining stage3 BLEND_ADDs * fix marisa laser opacity * hacky fix for myon The old implementation relied on alpha being stored inside p->color. In premul alpha this doesn’t work and functions like color_set_opacity can’t solve this i think. So I tried messing around with it until it looked somewhat similar. * fix marisa_b stars * remove color_set_opacity i overlooked * more plrmode blending changes * fixup additive blending in stage 1 * various premultiplied alpha fixups for bosses and enemies * stage 2 premul alpha fixups * stage 4 premul alpha fixups * stage 5 premul alpha fixups * stage 6 premul alpha fixups * make lasers also use the PMA blend mode * remove PFLAG_DRAWADD and PFLAG_DRAWSUB * fix remaining PMA issues in menus * lame extraspell bg workaround * fix item alpha * make marisaA lasers look somewhat like in master * fix marisaA bomb background fadeout * fixup various r_color4 calls * fix myon * remove dead code * fix use of BLEND_ADD in player death effect * fix myon shot trails (broken on master as well) * fix myon shot fade-in * extend the sprite shaders custom parameter to a vec4 * fix youmuB stuff and make it look somewhat better. the code looks even worse though.
2018-07-23 19:07:59 +02:00
r_color4(fade * 0.3, fade * 0.3, fade * 0.3, fade);
fill_screen("menu/mainmenubg");
r_color4(1, 1, 1, 1);
}
2017-02-25 14:23:22 +01:00
void TransEmpty(double fade) { }
static bool popq(void) {
if(transition.queued.rule) {
2017-02-25 14:23:22 +01:00
transition.rule2 = transition.rule;
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;
}
transition.dur1 = transition.queued.dur1;
transition.dur2 = transition.queued.dur2;
transition.callback = transition.queued.callback;
transition.arg = transition.queued.arg;
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;
}
static void setq(TransitionRule rule, int dur1, int dur2, TransitionCallback cb, void *arg) {
transition.queued.rule = rule;
transition.queued.dur1 = dur1;
transition.queued.dur2 = dur2;
transition.queued.callback = cb;
transition.queued.arg = arg;
}
static void call_callback(void) {
if(transition.callback) {
transition.callback(transition.arg);
transition.callback = NULL;
}
}
void set_transition_callback(TransitionRule rule, int dur1, int dur2, TransitionCallback cb, void *arg) {
static bool initialized = false;
if(!rule) {
2012-08-14 17:56:53 +02:00
return;
}
setq(rule, dur1, dur2, cb, arg);
if(!initialized) {
popq();
initialized = true;
2017-02-25 14:23:22 +01:00
transition.rule2 = NULL;
}
if(transition.state == TRANS_IDLE || rule == transition.rule) {
popq();
}
}
void set_transition(TransitionRule rule, int dur1, int dur2) {
set_transition_callback(rule, dur1, dur2, NULL, NULL);
2012-08-13 19:20:40 +02:00
}
2017-02-26 13:17:48 +01:00
static bool check_transition(void) {
if(transition.state == TRANS_IDLE) {
2017-02-26 13:17:48 +01:00
return false;
}
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()) {
return;
}
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;
}
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;
call_callback();
2017-02-25 14:23:22 +01:00
if(popq()) {
call_callback();
}
}
} 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
}