From 1053cb532bd2a99dfb0d8acb1b8f796775eb9709 Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 6 May 2023 19:26:19 +0000 Subject: [PATCH] Use std::span for MovieFileRead --- d2x-rebirth/libmve/mvelib.cpp | 9 ++++----- d2x-rebirth/libmve/mvelib.h | 3 ++- d2x-rebirth/main/movie.cpp | 5 +++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/d2x-rebirth/libmve/mvelib.cpp b/d2x-rebirth/libmve/mvelib.cpp index 8f0315099..5efb7d84a 100644 --- a/d2x-rebirth/libmve/mvelib.cpp +++ b/d2x-rebirth/libmve/mvelib.cpp @@ -318,7 +318,7 @@ static int _mvefile_read_header(const MVEFILE *movie) return 0; /* check the file is long enough */ - if (!MovieFileRead(movie->stream.get(), buffer, 26)) + if (!MovieFileRead(movie->stream.get(), buffer)) return 0; /* check the signature */ @@ -359,19 +359,18 @@ static int _mvefile_fetch_next_chunk(MVEFILE *movie) return 0; /* fail if we can't read the next segment descriptor */ - if (!MovieFileRead(movie->stream.get(), buffer, 4)) + if (!MovieFileRead(movie->stream.get(), buffer)) return 0; /* pull out the next length */ length = _mve_get_short(buffer); /* make sure we've got sufficient space */ - _mvefile_set_buffer_size(movie, length); + movie->cur_chunk.resize(length); /* read the chunk */ - if (!MovieFileRead(movie->stream.get(), &movie->cur_chunk[0], length)) + if (!MovieFileRead(movie->stream.get(), movie->cur_chunk)) return 0; - movie->cur_chunk.resize(length); movie->next_segment = 0; return 1; diff --git a/d2x-rebirth/libmve/mvelib.h b/d2x-rebirth/libmve/mvelib.h index 9eb8bca08..8cc7b7f0b 100644 --- a/d2x-rebirth/libmve/mvelib.h +++ b/d2x-rebirth/libmve/mvelib.h @@ -13,6 +13,7 @@ #include "libmve.h" #include +#include #include #include "dxxsconf.h" #include @@ -142,4 +143,4 @@ void mve_reset(MVESTREAM *movie); */ int mve_play_next_chunk(MVESTREAM &movie); -unsigned int MovieFileRead(SDL_RWops *handle, void *buf, unsigned count); +unsigned MovieFileRead(SDL_RWops *handle, std::span buf); diff --git a/d2x-rebirth/main/movie.cpp b/d2x-rebirth/main/movie.cpp index 631d7af42..1ceb3bdcd 100644 --- a/d2x-rebirth/main/movie.cpp +++ b/d2x-rebirth/main/movie.cpp @@ -116,9 +116,10 @@ struct movie_pause_window : window } -unsigned int MovieFileRead(SDL_RWops *const handle, void *buf, unsigned int count) +unsigned MovieFileRead(SDL_RWops *const handle, const std::span buf) { - const unsigned numread = SDL_RWread(handle, buf, 1, count); + const auto count = buf.size(); + const auto numread = SDL_RWread(handle, buf.data(), 1, count); return (numread == count); }