Skip to content

Commit

Permalink
Merge pull request scp-fs2open#6332 from Goober5000/movie_hooks
Browse files Browse the repository at this point in the history
add pre-movie hook
  • Loading branch information
Goober5000 authored Oct 28, 2024
2 parents 79a9acb + 66bf2ae commit 89e5460
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 28 deletions.
19 changes: 6 additions & 13 deletions code/cutscene/cutscenes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,32 +354,25 @@ static const char* Text_lines[MAX_TEXT_LINES];

void cutscenes_screen_play()
{
char name[MAX_FILENAME_LEN]; // *full_name
int which_cutscene;

Assert((Selected_line >= 0) && (Selected_line < (int) Cutscene_list.size()));
which_cutscene = Cutscene_list[Selected_line];

strcpy_s(name, Cutscenes[which_cutscene].filename);
// full_name = cf_add_ext(name, NOX(".mve"));
Assertion(SCP_vector_inbounds(Cutscene_list, Selected_line), "Selected line %d is out of range!", Selected_line);
int which_cutscene = Cutscene_list[Selected_line];

main_hall_stop_music(true);
main_hall_stop_ambient();
auto rval = movie::play(name);
auto rval = movie::play(Cutscenes[which_cutscene].filename, true);
main_hall_start_music();

if (!rval)
{
char str[256];
SCP_string str;

if (Cmdline_nomovies)
strcpy_s(str, XSTR("Movies are currently disabled.", 1574));
str = XSTR("Movies are currently disabled.", 1574);
else
sprintf(str, XSTR("Unable to play movie %s.", 204), Cutscenes[which_cutscene].name);

popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, str);
popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, str.c_str());
}

}

void cutscenes_screen_scroll_line_up()
Expand Down
25 changes: 18 additions & 7 deletions code/cutscene/movie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "io/key.h"
#include "mod_table/mod_table.h"
#include "network/multi.h"
#include "scripting/global_hooks.h"

extern int Game_mode;
extern int Is_standalone;
Expand Down Expand Up @@ -272,12 +273,22 @@ void movie_display_loop(Player* player, PlaybackState* state) {

namespace movie {
// Play one movie
bool play(const char* name) {
bool play(const char* filename, bool via_tech_room = false)
{
if (scripting::hooks::OnMovieAboutToPlay->isActive())
{
auto paramList = scripting::hook_param_list(scripting::hook_param("Filename", 's', filename), scripting::hook_param("ViaTechRoom", 'b', via_tech_room));
bool skip = scripting::hooks::OnMovieAboutToPlay->isOverride(paramList);
scripting::hooks::OnMovieAboutToPlay->run(paramList);
if (skip)
return false;
}

// mark the movie as viewable to the player when in a campaign
// do this before anything else so that we're sure the movie is available
// to the player even if it's not going to play right now
if (Game_mode & GM_CAMPAIGN_MODE) {
cutscene_mark_viewable(name);
cutscene_mark_viewable(filename);
}

if (Cmdline_nomovies || Is_standalone) {
Expand Down Expand Up @@ -306,7 +317,7 @@ bool play(const char* name) {
// clear third buffer (may not be one, but that's ok)
gr_clear();

auto player = cutscene::Player::newPlayer(name);
auto player = cutscene::Player::newPlayer(filename);
if (player) {
PlaybackState state;
initialize_player_state(player.get(), &state);
Expand All @@ -316,7 +327,7 @@ bool play(const char* name) {
player->stopPlayback();
} else {
// uh-oh, movie is invalid... Abory, Retry, Fail?
mprintf(("MOVIE ERROR: Found invalid movie! (%s)\n", name));
mprintf(("MOVIE ERROR: Found invalid movie! (%s)\n", filename));
}

Movie_active = false;
Expand All @@ -327,9 +338,9 @@ bool play(const char* name) {
return true;
}

void play_two(const char* name1, const char* name2) {
if (play(name1)) {
play(name2);
void play_two(const char* filename1, const char* filename2) {
if (play(filename1)) {
play(filename2);
}
}
}
4 changes: 2 additions & 2 deletions code/cutscene/movie.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

namespace movie {

bool play(const char* name);
bool play(const char* filename, bool via_tech_room = false);

void play_two(const char* name1, const char* name2);
void play_two(const char* filename1, const char* filename2);

}

Expand Down
1 change: 0 additions & 1 deletion code/mission/missioncampaign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,6 @@ void mission_campaign_maybe_play_movie(int type)
return;

movie::play(filename); //Play the movie!
cutscene_mark_viewable( filename );
}

/**
Expand Down
1 change: 0 additions & 1 deletion code/missionui/missionscreencommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ void common_maybe_play_cutscene(int movie_type, bool restart_music, int music)
common_music_close();
music_off = true;
movie::play(The_mission.cutscenes[i].filename); //Play the movie!
cutscene_mark_viewable( The_mission.cutscenes[i].filename );
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions code/scripting/global_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@ const std::shared_ptr<Hook<>> OnSplashEnd = Hook<>::Factory("On Splash End",
"Executed just after the splash screen fades out.",
{});

const std::shared_ptr<Hook<>> OnIntroAboutToPlay = Hook<>::Factory("On Intro About To Play",
const std::shared_ptr<OverridableHook<>> OnIntroAboutToPlay = OverridableHook<>::Factory("On Intro About To Play",
"Executed just before the intro movie is played.",
{});

const std::shared_ptr<OverridableHook<>> OnMovieAboutToPlay = OverridableHook<>::Factory("On Movie About To Play",
"Executed just before any cutscene movie is played.",
{
{"Filename", "string", "The filename of the movie that is about to play."},
{"ViaTechRoom", "boolean", "Whether the movie player was invoked through the tech room."},
});

const std::shared_ptr<OverridableHook<>> OnStateStart = OverridableHook<>::Factory("On State Start",
"Executed whenever a new state is entered.",
{
{
{"OldState", "gamestate", "The gamestate that was executing."},
{"NewState", "gamestate", "The gamestate that will be executing."}
});
Expand Down
3 changes: 2 additions & 1 deletion code/scripting/global_hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ namespace hooks {

extern const std::shared_ptr<Hook<>> OnGameInit;
extern const std::shared_ptr<Hook<>> OnSplashEnd;
extern const std::shared_ptr<Hook<>> OnIntroAboutToPlay;
extern const std::shared_ptr<OverridableHook<>> OnIntroAboutToPlay;
extern const std::shared_ptr<OverridableHook<>> OnMovieAboutToPlay;
//The On State Start hook previously used to pass OldState to the conditions, but no semantically sensible condition read the value, so we pretend it has no local condition
extern const std::shared_ptr<OverridableHook<>> OnStateStart;

Expand Down
4 changes: 3 additions & 1 deletion freespace2/freespace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6850,11 +6850,13 @@ int game_main(int argc, char *argv[])
output_sexps("sexps.html");
}

bool skip_intro = false;
if (scripting::hooks::OnIntroAboutToPlay->isActive()) {
skip_intro = scripting::hooks::OnIntroAboutToPlay->isOverride();
scripting::hooks::OnIntroAboutToPlay->run();
}

if (!Is_standalone) {
if (!Is_standalone && !skip_intro) {
movie::play("intro.mve");
}

Expand Down

0 comments on commit 89e5460

Please sign in to comment.