Simplify Descent2 briefing removal of carriage returns

Read the entire buffer at once, then remove the carriage returns and set
a null terminator.  This reduces the number of calls to PHYSFS_read from
len to 1.
This commit is contained in:
Kp 2020-02-26 05:07:34 +00:00
parent d4c48d80b5
commit 9db512a9d6

View file

@ -599,21 +599,17 @@ static int load_screen_text(const d_fname &filename, std::unique_ptr<char[]> &bu
len = PHYSFS_fileLength(tfile);
buf = make_unique<char[]>(len + 1);
#if defined(DXX_BUILD_DESCENT_I)
PHYSFS_read(tfile, buf.get(), 1, len);
#if defined(DXX_BUILD_DESCENT_I)
const auto endbuf = &buf[len];
#elif defined(DXX_BUILD_DESCENT_II)
for (int x=0, i=0; i < len; i++, x++) {
PHYSFS_read(tfile, &buf[x], 1, 1);
if (buf[x] == 13)
x--;
}
const auto endbuf = std::remove(&buf[0], &buf[len], 13);
#endif
*endbuf = 0;
if (have_binary)
decode_text(buf.get(), len);
buf[len] = '\0';
return (1);
}