From ab6aa3f28066e8f23f0aefcfade8f9b0b14bb251 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Fri, 12 Mar 2021 23:34:08 +0000 Subject: [PATCH] Migrate SetFlaskHeight away from gpBuffer Also renames to `DrawFlaskTop` and makes it static. --- Source/control.cpp | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/Source/control.cpp b/Source/control.cpp index 98e2c0e21..c673a22b6 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -597,30 +597,23 @@ void DrawPanelBox(CelOutputBuffer out, int x, int y, int w, int h, int sx, int s /** * Draws a section of the empty flask cel on top of the panel to create the illusion * of the flask getting empty. This function takes a cel and draws a - * horizontal stripe of height (max-min) onto the back buffer. + * horizontal stripe of height (max-min) onto the given buffer. + * @param out Target buffer. + * @param sx Buffer coordinate + * @param sy Buffer coordinate * @param pCelBuff Buffer of the empty flask cel. - * @param min Top of the flask cel section to draw. - * @param max Bottom of the flask cel section to draw. - * @param sx Back buffer coordinate - * @param sy Back buffer coordinate + * @param y0 Top of the flask cel section to draw. + * @param y1 Bottom of the flask cel section to draw. */ -void SetFlaskHeight(BYTE *pCelBuff, int min, int max, int sx, int sy) +static void DrawFlaskTop(CelOutputBuffer out, int sx, int sy, BYTE *pCelBuff, int y0, int y1) { - int nSrcOff, nDstOff, w; + const std::size_t kSrcWidth = 88; - assert(gpBuffer); - - nSrcOff = 88 * min; - nDstOff = sx + BUFFER_WIDTH * sy; - w = max - min; - - BYTE *src, *dst; - - src = &pCelBuff[nSrcOff]; - dst = &gpBuffer[nDstOff]; + const BYTE *src = &pCelBuff[kSrcWidth * y0]; + BYTE *dst = out.at(sx, sy); - for (; w; w--, src += 88, dst += BUFFER_WIDTH) - memcpy(dst, src, 88); + for (int h = y1 - y0; h != 0; --h, src += kSrcWidth, dst += out.line_width) + memcpy(dst, src, kSrcWidth); } /** @@ -698,7 +691,7 @@ void UpdateLifeFlask(CelOutputBuffer out) else if (filled < 0) filled = 0; if (filled != 69) - SetFlaskHeight(pLifeBuff, 16, 85 - filled, 96 + PANEL_X, PANEL_Y); + DrawFlaskTop(out, 96 + PANEL_X, PANEL_Y, pLifeBuff, 16, 85 - filled); if (filled != 0) DrawPanelBox(out, 96, 85 - filled, 88, filled, 96 + PANEL_X, PANEL_Y + 69 - filled); } @@ -755,7 +748,7 @@ void UpdateManaFlask(CelOutputBuffer out) if (filled > 69) filled = 69; if (filled != 69) - SetFlaskHeight(pManaBuff, 16, 85 - filled, PANEL_X + 464, PANEL_Y); + DrawFlaskTop(out, PANEL_X + 464, PANEL_Y, pManaBuff, 16, 85 - filled); if (filled != 0) DrawPanelBox(out, 464, 85 - filled, 88, filled, PANEL_X + 464, PANEL_Y + 69 - filled);