Skip to content

Commit

Permalink
improved video playback
Browse files Browse the repository at this point in the history
- added sound playback interface to mve player
- refactored mve player
- rescale video to window resolution
- removed self modifying code
- logo screen is not skipped if video is cancelled
  • Loading branch information
klei1984 committed Oct 19, 2023
1 parent 7306e62 commit 6a11fcb
Show file tree
Hide file tree
Showing 6 changed files with 2,047 additions and 258 deletions.
9 changes: 6 additions & 3 deletions src/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,10 @@ void menu_draw_logo(ResourceID resource_id, int32_t time_limit) {
WindowManager_FadeIn(500);

time_stamp = timer_get();
while (timer_elapsed_time(time_stamp) < time_limit && get_input() == -1) {
while (timer_elapsed_time(time_stamp) < time_limit) {
if (get_input() > 0 || (mouse_get_buttons() & (MOUSE_PRESS_LEFT | MOUSE_PRESS_RIGHT))) {
break;
}
}

WindowManager_ClearWindow();
Expand Down Expand Up @@ -984,8 +987,8 @@ int32_t Menu_LoadPlanetMinimap(int32_t planet_index, uint8_t* buffer, int32_t wi
WindowManager_ColorPalette = Color_GetColorPalette();

for (int32_t i = 0; i < sizeof(palette); i += PALETTE_STRIDE) {
palette[i / PALETTE_STRIDE] = Color_MapColor(WindowManager_ColorPalette, palette[i],
palette[i + 1], palette[i + 2], true);
palette[i / PALETTE_STRIDE] =
Color_MapColor(WindowManager_ColorPalette, palette[i], palette[i + 1], palette[i + 2], true);
}

for (int32_t i = 0; i < map_dimensions.x; ++i) {
Expand Down
43 changes: 36 additions & 7 deletions src/movie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ static int32_t movie_run(ResourceID resource_id, int32_t mode);

static uint32_t movie_music_level;

static uint8_t* gfx_buf;

void* mve_cb_alloc(size_t size) { return malloc(size); }

void mve_cb_free(void* p) { free(p); }
Expand All @@ -55,6 +57,7 @@ int32_t mve_cb_ctl(void) {

if (input > 0 || (mouse_get_buttons() & (MOUSE_PRESS_LEFT | MOUSE_PRESS_RIGHT))) {
result = 1;

} else {
result = 0;
}
Expand All @@ -64,7 +67,25 @@ int32_t mve_cb_ctl(void) {

void movie_cb_show_frame(uint8_t* buffer, int32_t bufw, int32_t bufh, int32_t sx, int32_t sy, int32_t w, int32_t h,
int32_t dstx, int32_t dsty) {
Svga_Blit(buffer, bufw, bufh, sx, sy, w, h, dstx, dsty);
const int32_t window_width = Svga_GetScreenWidth();
const int32_t window_height = Svga_GetScreenHeight();

const float scale_w = static_cast<float>(window_width) / bufw;
const float scale_h = static_cast<float>(window_height) / bufh;
const float scale = (scale_h >= scale_w) ? scale_w : scale_h;

int32_t frame_width = scale * bufw;
int32_t frame_height = scale * bufh;

frame_width = std::min(frame_width, window_width);
frame_height = std::min(frame_height, window_height);

const int32_t frame_offset_x = (window_width - frame_width) / 2;
const int32_t frame_offset_y = (window_height - frame_height) / 2;

cscale(buffer, bufw, bufh, bufw, gfx_buf, frame_width, frame_height, window_width);

Svga_Blit(gfx_buf, window_width, window_height, 0, 0, frame_width, frame_height, frame_offset_x, frame_offset_y);
}

void movie_cb_set_palette(uint8_t* p, int32_t start, int32_t count) {
Expand Down Expand Up @@ -102,7 +123,7 @@ static void movie_init_palette(void) {

int32_t movie_run(ResourceID resource_id, int32_t mode) {
FILE* fp;
char result;
int32_t result;
char path[PATH_MAX];
char* file_name;
uint8_t* palette;
Expand Down Expand Up @@ -148,9 +169,16 @@ int32_t movie_run(ResourceID resource_id, int32_t mode) {
MVE_rmFastMode(1);
}

MVE_sfSVGA(640, 480, 640, 0, nullptr, 0, 0, nullptr, 0);
const int32_t gfx_buf_size = Svga_GetScreenWidth() * Svga_GetScreenHeight();

gfx_buf = (uint8_t*)malloc(Svga_GetScreenWidth() * Svga_GetScreenHeight());

memset(gfx_buf, 0, gfx_buf_size);

if (!MVE_rmUnprotect() && !MVE_rmPrepMovie(fp, -1, -1, 0)) {
MVE_sfSVGA(Svga_GetScreenWidth(), Svga_GetScreenHeight(), Svga_GetScreenWidth(), 0, nullptr, 0, 0, nullptr,
0);

if (!MVE_rmPrepMovie(fp, -1, -1, 0)) {
int32_t aborted = 0;
int32_t frame_index = 0;

Expand All @@ -160,14 +188,15 @@ int32_t movie_run(ResourceID resource_id, int32_t mode) {
result = 1;
}

frame_index++;

SDL_Delay(33);
++frame_index;
}

MVE_rmEndMovie();
}

free(gfx_buf);
gfx_buf = NULL;

MVE_ReleaseMem();

Color_SetColorPalette(palette);
Expand Down
2 changes: 2 additions & 0 deletions src/movie.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@

#include "enums.hpp"

extern "C" {
int32_t Movie_PlayOemLogo(void);
int32_t Movie_PlayIntro(void);
int32_t Movie_Play(ResourceID resource_id);
}

#endif /* MOVIE_HPP */
Loading

0 comments on commit 6a11fcb

Please sign in to comment.