Skip to content

Commit

Permalink
Engine: reimplement screen transitions as GameStates
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-mogilko committed Feb 29, 2024
1 parent 1bc3245 commit 12b07c2
Show file tree
Hide file tree
Showing 8 changed files with 538 additions and 331 deletions.
15 changes: 9 additions & 6 deletions Common/ac/gamestructdefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,15 @@
#define PORTRAIT_XPOSITION 3

// Room transition style
#define FADE_NORMAL 0
#define FADE_INSTANT 1
#define FADE_DISSOLVE 2
#define FADE_BOXOUT 3
#define FADE_CROSSFADE 4
#define FADE_LAST 4 // this should equal the last one
enum ScreenTransitionStyle
{
kScrTran_Fade = 0,
kScrTran_Instant = 1,
kScrTran_Dissolve = 2,
kScrTran_Boxout = 3,
kScrTran_Crossfade = 4,
kNumScrTransitions
};

// Legacy font flags
//#define FFLG_LEGACY_NOSCALE 0x01 // TODO: is this from legacy format, ever used?
Expand Down
2 changes: 1 addition & 1 deletion Engine/ac/dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ bool get_custom_dialog_options_dimensions(int dlgnum)
#define DLG_OPTION_PARSER 99

// Dialog options state
class DialogOptions : GameState
class DialogOptions : public GameState
{
public:
DialogOptions(int _dlgnum, bool _runGameLoopsInBackground);
Expand Down
60 changes: 1 addition & 59 deletions Engine/ac/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,65 +206,7 @@ void process_event(const EventHappened *evp) {
}
else if (evp->type==EV_FADEIN)
{
// TODO: move most of this code into a separate function,
// see current_fade_out_effect() for example

debug_script_log("Transition-in in room %d", displayed_room);

// determine the transition style
int theTransition = play.fade_effect;

if (play.next_screen_transition >= 0) {
// a one-off transition was selected, so use it
theTransition = play.next_screen_transition;
play.next_screen_transition = -1;
}

if (pl_run_plugin_hooks(AGSE_TRANSITIONIN, 0))
{
play.screen_is_faded_out = 0; // mark screen as clear
return;
}

if (play.fast_forward)
{
play.screen_is_faded_out = 0; // mark screen as clear
return;
}

const bool ignore_transition = (play.screen_tint > 0);
if (((theTransition == FADE_CROSSFADE) || (theTransition == FADE_DISSOLVE)) &&
(saved_viewport_bitmap == nullptr) && !ignore_transition)
{
// transition type was not crossfade/dissolve when the screen faded out,
// but it is now when the screen fades in (Eg. a save game was restored
// with a different setting). Therefore just fade normally.
screen_effect_fade(false, 5);
theTransition = FADE_NORMAL;
}

if ((theTransition == FADE_INSTANT) || ignore_transition)
{
set_palette_range(palette, 0, 255, 0);
}
else if (theTransition == FADE_NORMAL)
{
screen_effect_fade(true, 5);
}
else if (theTransition == FADE_BOXOUT)
{
screen_effect_box(true, get_fixed_pixel_size(16));
}
else if (theTransition == FADE_CROSSFADE)
{
screen_effect_crossfade();
}
else if (theTransition == FADE_DISSOLVE)
{
screen_effect_dissolve();
}

play.screen_is_faded_out = 0; // mark screen as clear
current_fade_in_effect();
}
else if (evp->type == EV_IFACECLICK)
{
Expand Down
8 changes: 4 additions & 4 deletions Engine/ac/global_screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ void FadeOut(int sppd) {
// FIXME: we have to sync audio here explicitly, because FadeOut
// does not call any game update function while it works
sync_audio_playback();
screen_effect_fade(false, sppd);
run_fade_out_effect(kScrTran_Fade, sppd);
sync_audio_playback();
}

void SetScreenTransition(int newtrans) {
if ((newtrans < 0) || (newtrans > FADE_LAST))
if ((newtrans < 0) || (newtrans >= kNumScrTransitions))
quit("!SetScreenTransition: invalid transition type");

play.fade_effect = newtrans;
Expand All @@ -156,7 +156,7 @@ void SetScreenTransition(int newtrans) {
}

void SetNextScreenTransition(int newtrans) {
if ((newtrans < 0) || (newtrans > FADE_LAST))
if ((newtrans < 0) || (newtrans >= kNumScrTransitions))
quit("!SetNextScreenTransition: invalid transition type");

play.next_screen_transition = newtrans;
Expand All @@ -183,6 +183,6 @@ void FadeIn(int sppd) {
// FIXME: we have to sync audio here explicitly, because FadeIn
// does not call any game update function while it works
sync_audio_playback();
screen_effect_fade(true, sppd);
run_fade_in_effect(kScrTran_Fade, sppd);
sync_audio_playback();
}
2 changes: 1 addition & 1 deletion Engine/ac/invwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ struct DisplayInvItem {
int sprnum;
};

class InventoryScreen : GameState
class InventoryScreen : public GameState
{
public:
InventoryScreen();
Expand Down
Loading

0 comments on commit 12b07c2

Please sign in to comment.