Skip to content

Commit

Permalink
add pre-movie hook
Browse files Browse the repository at this point in the history
Add an `$On Movie About To Play:` hook to match `$On Intro About To Play:`.  Also make the two hooks overridable, since that might be useful.

Additionally, change a few (nonexhaustive) `name` parameters to `filename` to make it clearer that the string is a filename.
  • Loading branch information
Goober5000 committed Aug 29, 2024
1 parent c59a967 commit a13d018
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 26 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);
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)
{
if (scripting::hooks::OnMovieAboutToPlay->isActive())
{
auto paramList = scripting::hook_param_list(scripting::hook_param("Filename", 's', filename));
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);

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

}

Expand Down
10 changes: 8 additions & 2 deletions code/scripting/global_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@ 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."},
});

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 @@ -6848,11 +6848,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 a13d018

Please sign in to comment.