From 8b42d65a7e922a9b9241ebe509968331fe958fb6 Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Wed, 15 Oct 2003 06:40:31 +0000 Subject: Dumped most of the remaining "driver" code into a new "Display" class. This touches a lot of the code, of course, and adds yet another global variable (temporarily, I hope), but everything still seems to work. Knock on wood. svn-id: r10806 --- sword2/driver/_mouse.cpp | 162 ++++++++------------ sword2/driver/_mouse.h | 4 - sword2/driver/d_draw.cpp | 158 ++++++++------------ sword2/driver/d_draw.h | 202 ++++++++++++++++++++++++- sword2/driver/d_sound.cpp | 2 +- sword2/driver/driver96.h | 101 +------------ sword2/driver/menu.cpp | 164 +++++++++----------- sword2/driver/palette.cpp | 142 +++++++----------- sword2/driver/palette.h | 5 - sword2/driver/rdwin.cpp | 39 ++--- sword2/driver/rdwin.h | 2 - sword2/driver/render.cpp | 371 +++++++++++++++++++--------------------------- sword2/driver/render.h | 14 -- sword2/driver/sprite.cpp | 140 +++++++++-------- 14 files changed, 683 insertions(+), 823 deletions(-) (limited to 'sword2/driver') diff --git a/sword2/driver/_mouse.cpp b/sword2/driver/_mouse.cpp index abf1137186..4681249d83 100644 --- a/sword2/driver/_mouse.cpp +++ b/sword2/driver/_mouse.cpp @@ -29,49 +29,15 @@ namespace Sword2 { #define MAX_MOUSE_EVENTS 16 #define MOUSEFLASHFRAME 6 -#if !defined(__GNUC__) - #pragma START_PACK_STRUCTS -#endif - -struct _mouseAnim { - uint8 runTimeComp; // type of runtime compression used for the - // frame data - uint8 noAnimFrames; // number of frames in the anim - int8 xHotSpot; - int8 yHotSpot; - uint8 mousew; - uint8 mouseh; -} GCC_PACK; - -#if !defined(__GNUC__) - #pragma END_PACK_STRUCTS -#endif - -int16 mousex; -int16 mousey; - static uint8 mouseBacklog = 0; static uint8 mouseLogPos = 0; -static uint8 mouseFrame; -static uint8 *mouseSprite = NULL; -static _mouseAnim *mouseAnim = NULL; -static _mouseAnim *luggageAnim = NULL; static _mouseEvent mouseLog[MAX_MOUSE_EVENTS]; -static int32 *mouseOffsets; -static int32 *luggageOffset; - -// This is the maximum mouse cursor size in the SDL backend - -#define MAX_MOUSE_W 80 -#define MAX_MOUSE_H 80 -byte _mouseData[MAX_MOUSE_W * MAX_MOUSE_H]; - -void ResetRenderEngine(void) { - parallaxScrollx = 0; - parallaxScrolly = 0; - scrollx = 0; - scrolly = 0; +void Display::resetRenderEngine(void) { + _parallaxScrollX = 0; + _parallaxScrollY = 0; + _scrollX = 0; + _scrollY = 0; } // -------------------------------------------------------------------------- @@ -96,7 +62,7 @@ void LogMouseEvent(uint16 buttons) { // 0xFF. That means that parts of the mouse cursor that weren't meant to be // transparent may be now. -int32 DecompressMouse(uint8 *decomp, uint8 *comp, int width, int height, int pitch, int xOff = 0, int yOff = 0) { +void Display::decompressMouse(uint8 *decomp, uint8 *comp, int width, int height, int pitch, int xOff, int yOff) { int32 size = width * height; int32 i = 0; int x = 0; @@ -119,12 +85,10 @@ int32 DecompressMouse(uint8 *decomp, uint8 *comp, int width, int height, int pit i += *comp++; } } - - return RD_OK; } -void DrawMouse(void) { - if (!mouseAnim && !luggageAnim) +void Display::drawMouse(void) { + if (!_mouseAnim && !_luggageAnim) return; // When an object is used in the game, the mouse cursor should be a @@ -140,27 +104,27 @@ void DrawMouse(void) { int deltaX = 0; int deltaY = 0; - if (mouseAnim) { - hotspot_x = mouseAnim->xHotSpot; - hotspot_y = mouseAnim->yHotSpot; - mouse_width = mouseAnim->mousew; - mouse_height = mouseAnim->mouseh; + if (_mouseAnim) { + hotspot_x = _mouseAnim->xHotSpot; + hotspot_y = _mouseAnim->yHotSpot; + mouse_width = _mouseAnim->mousew; + mouse_height = _mouseAnim->mouseh; } - if (luggageAnim) { - if (!mouseAnim) { - hotspot_x = luggageAnim->xHotSpot; - hotspot_y = luggageAnim->yHotSpot; + if (_luggageAnim) { + if (!_mouseAnim) { + hotspot_x = _luggageAnim->xHotSpot; + hotspot_y = _luggageAnim->yHotSpot; } - if (luggageAnim->mousew > mouse_width) - mouse_width = luggageAnim->mousew; - if (luggageAnim->mouseh > mouse_height) - mouse_height = luggageAnim->mouseh; + if (_luggageAnim->mousew > mouse_width) + mouse_width = _luggageAnim->mousew; + if (_luggageAnim->mouseh > mouse_height) + mouse_height = _luggageAnim->mouseh; } - if (mouseAnim && luggageAnim) { - deltaX = mouseAnim->xHotSpot - luggageAnim->xHotSpot; - deltaY = mouseAnim->yHotSpot - luggageAnim->yHotSpot; + if (_mouseAnim && _luggageAnim) { + deltaX = _mouseAnim->xHotSpot - _luggageAnim->xHotSpot; + deltaY = _mouseAnim->yHotSpot - _luggageAnim->yHotSpot; } assert(deltaX >= 0); @@ -184,12 +148,12 @@ void DrawMouse(void) { memset(_mouseData, 0xFF, mouse_width * mouse_height); - if (luggageAnim) - DecompressMouse(_mouseData, (uint8 *) luggageAnim + READ_LE_UINT32(luggageOffset), luggageAnim->mousew, - luggageAnim->mouseh, mouse_width, deltaX, deltaY); + if (_luggageAnim) + decompressMouse(_mouseData, (uint8 *) _luggageAnim + READ_LE_UINT32(_luggageOffset), _luggageAnim->mousew, + _luggageAnim->mouseh, mouse_width, deltaX, deltaY); - if (mouseAnim) - DecompressMouse(_mouseData, mouseSprite, mouseAnim->mousew, mouseAnim->mouseh, mouse_width); + if (_mouseAnim) + decompressMouse(_mouseData, _mouseSprite, _mouseAnim->mousew, _mouseAnim->mouseh, mouse_width); g_system->set_mouse_cursor(_mouseData, mouse_width, mouse_height, hotspot_x, hotspot_y); } @@ -222,19 +186,19 @@ uint8 CheckForMouseEvents(void) { * Animates the current mouse pointer */ -int32 AnimateMouse(void) { - uint8 prevMouseFrame = mouseFrame; +int32 Display::animateMouse(void) { + uint8 prevMouseFrame = _mouseFrame; - if (!mouseAnim) + if (!_mouseAnim) return RDERR_UNKNOWN; - if (++mouseFrame == mouseAnim->noAnimFrames) - mouseFrame = MOUSEFLASHFRAME; + if (++_mouseFrame == _mouseAnim->noAnimFrames) + _mouseFrame = MOUSEFLASHFRAME; - mouseSprite = (uint8 *) mouseAnim + READ_LE_UINT32(mouseOffsets + mouseFrame); + _mouseSprite = (uint8 *) _mouseAnim + READ_LE_UINT32(_mouseOffsets + _mouseFrame); - if (mouseFrame != prevMouseFrame) - DrawMouse(); + if (_mouseFrame != prevMouseFrame) + drawMouse(); return RD_OK; } @@ -247,32 +211,32 @@ int32 AnimateMouse(void) { * or not there is a lead-in animation */ -int32 SetMouseAnim(uint8 *ma, int32 size, int32 mouseFlash) { - if (mouseAnim) { - free(mouseAnim); - mouseAnim = NULL; +int32 Display::setMouseAnim(uint8 *ma, int32 size, int32 mouseFlash) { + if (_mouseAnim) { + free(_mouseAnim); + _mouseAnim = NULL; } if (ma) { if (mouseFlash == RDMOUSE_FLASH) - mouseFrame = 0; + _mouseFrame = 0; else - mouseFrame = MOUSEFLASHFRAME; + _mouseFrame = MOUSEFLASHFRAME; - mouseAnim = (_mouseAnim *) malloc(size); - if (!mouseAnim) + _mouseAnim = (struct _mouseAnim *) malloc(size); + if (!_mouseAnim) return RDERR_OUTOFMEMORY; - memcpy((uint8 *) mouseAnim, ma, size); - mouseOffsets = (int32 *) ((uint8 *) mouseAnim + sizeof(_mouseAnim)); + memcpy((uint8 *) _mouseAnim, ma, size); + _mouseOffsets = (int32 *) ((uint8 *) _mouseAnim + sizeof(struct _mouseAnim)); - AnimateMouse(); - DrawMouse(); + animateMouse(); + drawMouse(); g_system->show_mouse(true); } else { - if (luggageAnim) - DrawMouse(); + if (_luggageAnim) + drawMouse(); else g_system->show_mouse(false); } @@ -287,27 +251,27 @@ int32 SetMouseAnim(uint8 *ma, int32 size, int32 mouseFlash) { * @param size the size of the animation data */ -int32 SetLuggageAnim(uint8 *ma, int32 size) { - if (luggageAnim) { - free(luggageAnim); - luggageAnim = NULL; +int32 Display::setLuggageAnim(uint8 *ma, int32 size) { + if (_luggageAnim) { + free(_luggageAnim); + _luggageAnim = NULL; } if (ma) { - luggageAnim = (_mouseAnim *) malloc(size); - if (!luggageAnim) + _luggageAnim = (struct _mouseAnim *) malloc(size); + if (!_luggageAnim) return RDERR_OUTOFMEMORY; - memcpy((uint8 *) luggageAnim, ma, size); - luggageOffset = (int32 *) ((uint8 *) luggageAnim + sizeof(_mouseAnim)); + memcpy((uint8 *) _luggageAnim, ma, size); + _luggageOffset = (int32 *) ((uint8 *) _luggageAnim + sizeof(struct _mouseAnim)); - AnimateMouse(); - DrawMouse(); + animateMouse(); + drawMouse(); g_system->show_mouse(true); } else { - if (mouseAnim) - DrawMouse(); + if (_mouseAnim) + drawMouse(); else g_system->show_mouse(false); } diff --git a/sword2/driver/_mouse.h b/sword2/driver/_mouse.h index ba48eb251c..00cd46a0f3 100644 --- a/sword2/driver/_mouse.h +++ b/sword2/driver/_mouse.h @@ -22,11 +22,7 @@ namespace Sword2 { -extern int16 mousex; // Mouse x coordinate -extern int16 mousey; // Mouse y coordinate - extern void LogMouseEvent(uint16 buttons); -extern int32 DrawMouse(void); } // End of namespace Sword2 diff --git a/sword2/driver/d_draw.cpp b/sword2/driver/d_draw.cpp index f01c2314e1..963e5a79d4 100644 --- a/sword2/driver/d_draw.cpp +++ b/sword2/driver/d_draw.cpp @@ -30,118 +30,90 @@ namespace Sword2 { -byte *lpBackBuffer; +Display::Display(int16 width, int16 height) + : _iconCount(0), _needFullRedraw(false), _fadeStatus(RDFADE_NONE), + _mouseSprite(NULL), _mouseAnim(NULL), _luggageAnim(NULL), + _layer(0), _renderAverageTime(60), _lightMask(NULL), + _screenWide(width), _screenDeep(height) { -// Game screen metrics -int16 screenDeep; -int16 screenWide; + int i, j; -// Scroll variables. scrollx and scrolly hold the current scroll position, + _buffer = (byte *) malloc(width * height); + if (!_buffer) + error("Could not initialise display"); -int16 scrollx; -int16 scrolly; - -int32 renderCaps = 0; - -/** - * Initialise the display with the sizes passed in. - * @return RD_OK, or an error code if the display cannot be set up. - */ - -int32 InitialiseDisplay(int16 width, int16 height) { g_system->init_size(width, height); - screenWide = width; - screenDeep = height; - - lpBackBuffer = (byte *) malloc(screenWide * screenDeep); - if (!lpBackBuffer) - return RDERR_OUTOFMEMORY; - - return RD_OK; -} - -// FIXME: Clean up this mess. I don't want to add any new flags, but some of -// them should be renamed. Or maybe we should abandon the whole renderCaps -// thing and simply check the numeric value of the graphics quality setting -// instead. - -// Note that SetTransFx() actually clears a bit. That's intentional. - -void SetTransFx(void) { - renderCaps &= ~RDBLTFX_ALLHARDWARE; -} - -void ClearTransFx(void) { - renderCaps |= RDBLTFX_ALLHARDWARE; -} + for (i = 0; i < ARRAYSIZE(_blockSurfaces); i++) + _blockSurfaces[i] = NULL; -/** - * Sets the edge blend and arithmetic stretching effects. - */ + for (i = 0; i < 2; i++) { + for (j = 0; j < RDMENU_MAXPOCKETS; j++) { + _icons[i][j] = NULL; + _pocketStatus[i][j] = 0; + } -void SetBltFx(void) { - renderCaps |= (RDBLTFX_EDGEBLEND | RDBLTFX_ARITHMETICSTRETCH); + _menuStatus[i] = RDMENU_HIDDEN; + } } /** - * Clears the edge blend and arithmetic stretching effects. + * @return the graphics detail setting */ -void ClearBltFx(void) { - renderCaps &= ~(RDBLTFX_EDGEBLEND | RDBLTFX_ARITHMETICSTRETCH); +int8 Display::getRenderLevel(void) { + return _renderLevel; } -void SetShadowFx(void) { - renderCaps |= RDBLTFX_SHADOWBLEND; -} - -void ClearShadowFx(void) { - renderCaps &= ~RDBLTFX_SHADOWBLEND; +void Display::setRenderLevel(int8 level) { + _renderLevel = level; + + switch (_renderLevel) { + case 0: + // Lowest setting: no fancy stuff + _renderCaps = 0; + break; + case 1: + // Medium-low setting: transparency-blending + _renderCaps = RDBLTFX_SPRITEBLEND; + break; + case 2: + // Medium-high setting: transparency-blending + shading + _renderCaps = RDBLTFX_SPRITEBLEND | RDBLTFX_SHADOWBLEND; + break; + case 3: + // Highest setting: transparency-blending + shading + + // edge-blending + improved stretching + _renderCaps = RDBLTFX_SPRITEBLEND | RDBLTFX_SHADOWBLEND | RDBLTFX_EDGEBLEND; + break; + } } -/** - * @return the graphics detail setting - */ - -int32 GetRenderType(void) { - if (renderCaps & RDBLTFX_ALLHARDWARE) - return 0; - - if (renderCaps & (RDBLTFX_EDGEBLEND | RDBLTFX_ARITHMETICSTRETCH)) - return 3; - - if (renderCaps & RDBLTFX_SHADOWBLEND) - return 2; - - return 1; -} /** * Fill the screen buffer with palette colour zero. Note that it does not * touch the menu areas of the screen. */ -int32 EraseBackBuffer( void ) { - memset(lpBackBuffer + MENUDEEP * screenWide, 0, screenWide * RENDERDEEP); - return RD_OK; +void Display::clearScene(void) { + memset(_buffer + MENUDEEP * _screenWide, 0, _screenWide * RENDERDEEP); } void MoviePlayer::openTextObject(_movieTextObject *obj) { if (obj->textSprite) - CreateSurface(obj->textSprite, &_textSurface); + g_display->createSurface(obj->textSprite, &_textSurface); } void MoviePlayer::closeTextObject(_movieTextObject *obj) { if (_textSurface) { - DeleteSurface(_textSurface); + g_display->deleteSurface(_textSurface); _textSurface = NULL; } } void MoviePlayer::drawTextObject(_movieTextObject *obj) { if (obj->textSprite && _textSurface) - DrawSurface(obj->textSprite, _textSurface); + g_display->drawSurface(obj->textSprite, _textSurface); } /** @@ -161,14 +133,14 @@ int32 MoviePlayer::play(char *filename, _movieTextObject *text[], uint8 *musicOu uint8 oldPal[1024]; uint8 tmpPal[1024]; - EraseBackBuffer(); + g_display->clearScene(); // HACK: Draw instructions // // I'm using the the menu area, because that's unlikely to be // touched by anything else during the cutscene. - memset(lpBackBuffer, 0, screenWide * MENUDEEP); + memset(g_display->_buffer, 0, g_display->_screenWide * MENUDEEP); uint8 msg[] = "Cutscene - Press ESC to exit"; mem *data = fontRenderer.makeTextSprite(msg, 640, 255, g_sword2->_speechFontId); @@ -176,16 +148,16 @@ int32 MoviePlayer::play(char *filename, _movieTextObject *text[], uint8 *musicOu _spriteInfo msgSprite; uint8 *msgSurface; - msgSprite.x = screenWide / 2 - frame->width / 2; + msgSprite.x = g_display->_screenWide / 2 - frame->width / 2; msgSprite.y = RDMENU_MENUDEEP / 2 - frame->height / 2; msgSprite.w = frame->width; msgSprite.h = frame->height; msgSprite.type = RDSPR_DISPLAYALIGN | RDSPR_NOCOMPRESSION | RDSPR_TRANS; msgSprite.data = data->ad + sizeof(_frameHeader); - CreateSurface(&msgSprite, &msgSurface); - DrawSurface(&msgSprite, msgSurface); - DeleteSurface(msgSurface); + g_display->createSurface(&msgSprite, &msgSurface); + g_display->drawSurface(&msgSprite, msgSurface); + g_display->deleteSurface(msgSurface); memory.freeMemory(data); // In case the cutscene has a long lead-in, start just before @@ -201,12 +173,12 @@ int32 MoviePlayer::play(char *filename, _movieTextObject *text[], uint8 *musicOu // The text should probably be colored the same as the rest of // the in-game text. - memcpy(oldPal, palCopy, 1024); + memcpy(oldPal, g_display->_palCopy, 1024); memset(tmpPal, 0, 1024); tmpPal[255 * 4 + 0] = 255; tmpPal[255 * 4 + 1] = 255; tmpPal[255 * 4 + 2] = 255; - BS2_SetPalette(0, 256, tmpPal, RDPAL_INSTANT); + g_display->setPalette(0, 256, tmpPal, RDPAL_INSTANT); PlayingSoundHandle handle = 0; @@ -217,7 +189,7 @@ int32 MoviePlayer::play(char *filename, _movieTextObject *text[], uint8 *musicOu break; if (frameCounter == text[textCounter]->startFrame) { - EraseBackBuffer(); + g_display->clearScene(); openTextObject(text[textCounter]); drawTextObject(text[textCounter]); if (text[textCounter]->speech) { @@ -227,13 +199,13 @@ int32 MoviePlayer::play(char *filename, _movieTextObject *text[], uint8 *musicOu if (frameCounter == text[textCounter]->endFrame) { closeTextObject(text[textCounter]); - EraseBackBuffer(); + g_display->clearScene(); textCounter++; } frameCounter++; - ServiceWindows(); + g_display->updateDisplay(); _keyboardEvent ke; @@ -252,17 +224,17 @@ int32 MoviePlayer::play(char *filename, _movieTextObject *text[], uint8 *musicOu closeTextObject(text[textCounter]); - EraseBackBuffer(); - SetNeedRedraw(); + g_display->clearScene(); + g_display->setNeedFullRedraw(); // HACK: Remove the instructions created above Common::Rect r; - memset(lpBackBuffer, 0, screenWide * MENUDEEP); + memset(g_display->_buffer, 0, g_display->_screenWide * MENUDEEP); r.left = r.top = 0; - r.right = screenWide; + r.right = g_display->_screenWide; r.bottom = MENUDEEP; - UploadRect(&r); + g_display->updateRect(&r); // FIXME: For now, only play the lead-out music for cutscenes // that have subtitles. @@ -270,7 +242,7 @@ int32 MoviePlayer::play(char *filename, _movieTextObject *text[], uint8 *musicOu if (!skipCutscene) g_sound->playLeadOut(musicOut); - BS2_SetPalette(0, 256, oldPal, RDPAL_INSTANT); + g_display->setPalette(0, 256, oldPal, RDPAL_INSTANT); } // Lead-in and lead-out music are, as far as I can tell, only used for diff --git a/sword2/driver/d_draw.h b/sword2/driver/d_draw.h index a169b922e2..4d0c1d71e2 100644 --- a/sword2/driver/d_draw.h +++ b/sword2/driver/d_draw.h @@ -24,7 +24,40 @@ namespace Sword2 { -extern byte *lpBackBuffer; +// This is the maximum mouse cursor size in the SDL backend + +#define MAX_MOUSE_W 80 +#define MAX_MOUSE_H 80 + +#define RENDERAVERAGETOTAL 4 + +#define BLOCKWIDTH 64 +#define BLOCKHEIGHT 64 +#define MAXLAYERS 5 + +#define PALTABLESIZE 64 * 64 * 64 + +// Maximum scaled size of a sprite +#define SCALE_MAXWIDTH 512 +#define SCALE_MAXHEIGHT 512 + +#if !defined(__GNUC__) + #pragma START_PACK_STRUCTS +#endif + +struct _mouseAnim { + uint8 runTimeComp; // type of runtime compression used for the + // frame data + uint8 noAnimFrames; // number of frames in the anim + int8 xHotSpot; + int8 yHotSpot; + uint8 mousew; + uint8 mouseh; +} GCC_PACK; + +#if !defined(__GNUC__) + #pragma END_PACK_STRUCTS +#endif class MoviePlayer { private: @@ -38,6 +71,173 @@ public: int32 play(char *filename, _movieTextObject *text[], uint8 *musicOut); }; +typedef struct { + byte data[BLOCKWIDTH * BLOCKHEIGHT]; + bool transparent; +} BlockSurface; + +class Display { + friend class MoviePlayer; + +private: + byte *_buffer; + + int32 _renderCaps; + int8 _renderLevel; + + uint8 _menuStatus[2]; + byte *_icons[2][RDMENU_MAXPOCKETS]; + uint8 _pocketStatus[2][RDMENU_MAXPOCKETS]; + + uint8 _iconCount; + + bool _needFullRedraw; + + uint8 _paletteMatch[PALTABLESIZE]; + + uint8 _fadePalette[256][4]; + uint8 _fadeStatus; + + int32 _fadeStartTime; + int32 _fadeTotalTime; + + byte _mouseData[MAX_MOUSE_W * MAX_MOUSE_H]; + + uint8 _mouseFrame; + uint8 *_mouseSprite; + struct _mouseAnim *_mouseAnim; + struct _mouseAnim *_luggageAnim; + int32 *_mouseOffsets; + int32 *_luggageOffset; + + // Scroll variables. _scrollX and _scrollY hold the current scroll + // position, and _scrollXTarget and _scrollYTarget are the target + // position for the end of the game cycle. + + int16 _scrollX; + int16 _scrollY; + + int16 _scrollXTarget; + int16 _scrollYTarget; + int16 _scrollXOld; + int16 _scrollYOld; + + int16 _parallaxScrollX; // current x offset to link a sprite to the + // parallax layer + int16 _parallaxScrollY; // current y offset to link a sprite to the + // parallax layer + int16 _locationWide; + int16 _locationDeep; + + uint16 _layer; + + int32 _initialTime; + int32 _startTime; + int32 _totalTime; + int32 _renderAverageTime; + int32 _framesPerGameCycle; + bool _renderTooSlow; + + uint8 _xBlocks[MAXLAYERS]; + uint8 _yBlocks[MAXLAYERS]; + + // An array of sub-blocks, one for each of the parallax layers. + + BlockSurface **_blockSurfaces[MAXLAYERS]; + + uint16 _xScale[SCALE_MAXWIDTH]; + uint16 _yScale[SCALE_MAXHEIGHT]; + + uint8 *_lightMask; + + void clearIconArea(int menu, int pocket, Common::Rect *r); + + void decompressMouse(uint8 *decomp, uint8 *comp, int width, int height, int pitch, int xOff = 0, int yOff = 0); + void drawMouse(void); + + uint8 getMatch(uint8 r, uint8 g, uint8 b); + void fadeServer(void); + + void squashImage(byte *dst, uint16 dstPitch, uint16 dstWidth, + uint16 dstHeight, byte *src, uint16 srcPitch, uint16 srcWidth, + uint16 srcHeight, byte *backbuf); + void stretchImage(byte *dst, uint16 dstPitch, uint16 dstWidth, + uint16 dstHeight, byte *src, uint16 srcPitch, uint16 srcWidth, + uint16 srcHeight, byte *backbuf); + + void updateRect(Common::Rect *r); + + void blitBlockSurface(BlockSurface *s, Common::Rect *r, Common::Rect *clip_rect); + + void mirrorSprite(uint8 *dst, uint8 *src, int16 w, int16 h); + int32 decompressRLE256(uint8 *dest, uint8 *source, int32 decompSize); + void unwindRaw16(uint8 *dest, uint8 *source, uint8 blockSize, uint8 *colTable); + int32 decompressRLE16(uint8 *dest, uint8 *source, int32 decompSize, uint8 *colTable); + +public: + Display(int16 width, int16 height); + + // Game screen metrics + int16 _screenWide; + int16 _screenDeep; + + int16 _mouseX; + int16 _mouseY; + + uint8 _palCopy[256][4]; + + int8 getRenderLevel(void); + void setRenderLevel(int8 level); + + void clearScene(void); + + void processMenu(void); + int32 showMenu(uint8 menu); + int32 hideMenu(uint8 menu); + int32 setMenuIcon(uint8 menu, uint8 pocket, uint8 *icon); + void closeMenuImmediately(void); + + void updateDisplay(void); + void setWindowName(const char *windowName); + void setNeedFullRedraw(void); + + void setPalette(int16 startEntry, int16 noEntries, uint8 *palette, uint8 setNow); + void updatePaletteMatchTable(uint8 *data); + uint8 quickMatch(uint8 r, uint8 g, uint8 b); + int32 fadeUp(float time = 0.75); + int32 fadeDown(float time = 0.75); + uint8 getFadeStatus(void); + void dimPalette(void); + void waitForFade(void); + + int32 setMouseAnim(uint8 *ma, int32 size, int32 mouseFlash); + int32 setLuggageAnim(uint8 *la, int32 size); + int32 animateMouse(void); + + void resetRenderEngine(void); + + void setScrollTarget(int16 sx, int16 sy); + void initialiseRenderCycle(void); + void startRenderCycle(void); + bool endRenderCycle(void); + void renderParallax(_parallax *p, int16 layer); + void setLocationMetrics(uint16 w, uint16 h); + int32 initialiseBackgroundLayer(_parallax *p); + void closeBackgroundLayer(void); + +#ifdef _SWORD2_DEBUG + void plotPoint(uint16 x, uint16 y, uint8 colour); + void drawLine(int16 x1, int16 y1, int16 x2, int16 y2, uint8 colour); +#endif + + int32 createSurface(_spriteInfo *s, uint8 **surface); + void drawSurface(_spriteInfo *s, uint8 *surface, Common::Rect *clipRect = NULL); + void deleteSurface(uint8 *surface); + int32 drawSprite(_spriteInfo *s); + int32 openLightMask(_spriteInfo *s); + int32 closeLightMask(void); +}; + } // End of namespace Sword2 #endif diff --git a/sword2/driver/d_sound.cpp b/sword2/driver/d_sound.cpp index cb018b89e7..69ec2fe8e0 100644 --- a/sword2/driver/d_sound.cpp +++ b/sword2/driver/d_sound.cpp @@ -245,7 +245,7 @@ void Sound::playLeadOut(uint8 *leadOut) { } while (_fx[i]._handle) { - ServiceWindows(); + g_display->updateDisplay(); g_system->delay_msecs(30); } } diff --git a/sword2/driver/driver96.h b/sword2/driver/driver96.h index 3f49a84961..2e56e39cc8 100644 --- a/sword2/driver/driver96.h +++ b/sword2/driver/driver96.h @@ -176,18 +176,9 @@ namespace Sword2 { #define RDPAL_INSTANT 1 //Blitting FX defines -#define RDBLTFX_MOUSEBLT 0x01 -#define RDBLTFX_FGPARALLAX 0x02 -#define RDBLTFX_ARITHMETICSTRETCH 0x04 -#define RDBLTFX_EDGEBLEND 0x08 -#define RDBLTFX_SHADOWBLEND 0x10 -#define RDBLTFX_FLATALPHA 0x20 -#define RDBLTFX_GRADEDALPHA 0x40 -#define RDBLTFX_ALLHARDWARE 0x80 - -// Maximum scaled size of a sprite -#define SCALE_MAXWIDTH 512 -#define SCALE_MAXHEIGHT 512 +#define RDBLTFX_SPRITEBLEND 0x01 +#define RDBLTFX_SHADOWBLEND 0x02 +#define RDBLTFX_EDGEBLEND 0x04 // // Structure definitions @@ -275,29 +266,6 @@ typedef struct { // ------------------- // -//----------------------------------------------------------------------------- -// Display functions - from d_draw.c -//----------------------------------------------------------------------------- -extern int32 InitialiseDisplay(int16 width, int16 height); -extern int32 EraseBackBuffer(void); -extern void SetTransFx(void); -extern void ClearTransFx(void); -extern void SetBltFx(void); -extern void ClearBltFx(void); -extern void ClearShadowFx(void); -extern void SetShadowFx(void); -extern int32 GetRenderType(void); -extern int32 PlaySmacker(char *filename, _movieTextObject *textObjects[], uint8 *musicOut); -//----------------------------------------------------------------------------- - -//----------------------------------------------------------------------------- -// Windows OS functions - from rdwin.c -//----------------------------------------------------------------------------- -extern int32 CloseAppWindow(void); -extern int32 ServiceWindows(void); -extern void SetWindowName(const char *windowName); -//----------------------------------------------------------------------------- - //----------------------------------------------------------------------------- // Language functions - from language.c //----------------------------------------------------------------------------- @@ -305,28 +273,11 @@ extern int32 GetLanguageVersion(uint8 *version); extern int32 SetLanguageVersion(uint8 version); //----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -// Palette functions - from palette.c -//----------------------------------------------------------------------------- -extern int32 BS2_SetPalette(int16 startEntry, int16 noEntries, uint8 *palette, uint8 setNow); -extern int32 UpdatePaletteMatchTable(uint8 *data); -extern uint8 QuickMatch(uint8 r, uint8 g, uint8 b); -extern int32 FadeUp(float time); -extern int32 FadeDown(float time); -extern uint8 GetFadeStatus(void); -extern int32 DimPalette(void); -extern void WaitForFade(void); -//----------------------------------------------------------------------------- - //----------------------------------------------------------------------------- // Mouse functions - from mouse.c //----------------------------------------------------------------------------- extern _mouseEvent *MouseEvent(void); -extern int32 SetMouseAnim(uint8 *ma, int32 size, int32 mouseFlash); -extern int32 SetLuggageAnim(uint8 *la, int32 size); -extern int32 AnimateMouse(void); -uint8 CheckForMouseEvents(void); // (James23july97) -extern void ResetRenderEngine(void); +uint8 CheckForMouseEvents(void); //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -336,42 +287,6 @@ extern bool KeyWaiting(void); extern int32 ReadKey(_keyboardEvent *ke); //----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -// Sprite functions - from sprite.c -//----------------------------------------------------------------------------- -extern int32 DrawSprite(_spriteInfo *s); -extern int32 CreateSurface(_spriteInfo *s, uint8 **surface); -extern void DrawSurface(_spriteInfo *s, uint8 *surface, Common::Rect *clipRect = NULL); -extern void DeleteSurface(uint8 *surface); -extern int32 OpenLightMask(_spriteInfo *s); -extern int32 CloseLightMask(void); -//----------------------------------------------------------------------------- - -//----------------------------------------------------------------------------- -// Screen drawing and scrolling function - from render.c -//----------------------------------------------------------------------------- -extern int32 SetScrollTarget(int16 sx, int16 sy); -extern int32 InitialiseRenderCycle(void); -extern int32 StartRenderCycle(void); -extern int32 EndRenderCycle(bool *end); -extern int32 RenderParallax(_parallax *p, int16 layer); -extern int32 SetLocationMetrics(uint16 w, uint16 h); -extern int32 PlotPoint(uint16 x, uint16 y, uint8 colour); -extern int32 DrawLine(int16 x1, int16 y1, int16 x2, int16 y2, uint8 colour); -extern int32 InitialiseBackgroundLayer(_parallax *p); -extern int32 CloseBackgroundLayer(void); -//----------------------------------------------------------------------------- - -//----------------------------------------------------------------------------- -// Menubar control and drawing functions - from menu.c -//----------------------------------------------------------------------------- -extern int32 ProcessMenu(void); -extern int32 ShowMenu(uint8 menu); -extern int32 HideMenu(uint8 menu); -extern int32 SetMenuIcon(uint8 menu, uint8 pocket, uint8 *icon); -extern uint8 GetMenuStatus(uint8 menu); -extern int32 CloseMenuImmediately(void); - //----------------------------------------------------------------------------- // Misc functions - from misc.cpp //----------------------------------------------------------------------------- @@ -380,14 +295,6 @@ extern void SVM_SetFileAttributes(char *file, uint32 atrib); extern void SVM_DeleteFile(char *file); extern int32 SVM_GetVolumeInformation(char *cdPath, char *sCDName, uint32 maxPath, uint8 *, uint32 *dwMaxCompLength, uint32 *dwFSFlags, uint8 *, uint32 a); -//----------------------------------------------------------------------------- -extern int16 screenWide; // Width of the screen display -extern int16 screenDeep; // Height of the screen display -extern int16 mousex; // Mouse screen x coordinate -extern int16 mousey; // Mouse screen y coordinate -extern int32 renderCaps; // Flags which determine how to render the scene. -extern uint8 palCopy[256][4]; // Current palette. - } // End of namespace Sword2 #endif diff --git a/sword2/driver/menu.cpp b/sword2/driver/menu.cpp index 983113d54b..06bbcd8044 100644 --- a/sword2/driver/menu.cpp +++ b/sword2/driver/menu.cpp @@ -29,23 +29,7 @@ namespace Sword2 { #define MENUDEEP 40 #define MAXMENUANIMS 8 -static uint8 menuStatus[2] = { - RDMENU_HIDDEN, RDMENU_HIDDEN -}; - -static byte *icons[2][RDMENU_MAXPOCKETS] = { - { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, - { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } -}; - -static uint8 pocketStatus[2][RDMENU_MAXPOCKETS] = { - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } -}; - -static uint8 iconCount = 0; - -void ClearIconArea(int menu, int pocket, Common::Rect *r) { +void Display::clearIconArea(int menu, int pocket, Common::Rect *r) { byte *dst; int i; @@ -54,11 +38,11 @@ void ClearIconArea(int menu, int pocket, Common::Rect *r) { r->left = RDMENU_ICONSTART + pocket * (RDMENU_ICONWIDE + RDMENU_ICONSPACING); r->right = r->left + RDMENU_ICONWIDE; - dst = lpBackBuffer + r->top * screenWide + r->left; + dst = _buffer + r->top * _screenWide + r->left; for (i = 0; i < RDMENU_ICONDEEP; i++) { memset(dst, 0, RDMENU_ICONWIDE); - dst += screenWide; + dst += _screenWide; } } @@ -68,7 +52,7 @@ void ClearIconArea(int menu, int pocket, Common::Rect *r) { * system is. */ -int32 ProcessMenu(void) { +void Display::processMenu(void) { byte *src, *dst; uint8 menu; uint8 i, j; @@ -90,84 +74,84 @@ int32 ProcessMenu(void) { delta = 250; frameCount = 1; } else { - frameCount = (uint8) ((iconCount + 8) * delta / 750); - lastTime += frameCount * 750 / (iconCount + 8); + frameCount = (uint8) ((_iconCount + 8) * delta / 750); + lastTime += frameCount * 750 / (_iconCount + 8); } } while (frameCount-- > 0) { for (menu = RDMENU_TOP; menu <= RDMENU_BOTTOM; menu++) { - if (menuStatus[menu] == RDMENU_OPENING) { + if (_menuStatus[menu] == RDMENU_OPENING) { // The menu is opening, so process it here complete = 1; // Propagate the animation from the first icon. for (i = RDMENU_MAXPOCKETS - 1; i > 0; i--) { - pocketStatus[menu][i] = pocketStatus[menu][i - 1]; - if (pocketStatus[menu][i] != MAXMENUANIMS) + _pocketStatus[menu][i] = _pocketStatus[menu][i - 1]; + if (_pocketStatus[menu][i] != MAXMENUANIMS) complete = 0; } - if (pocketStatus[menu][i] != MAXMENUANIMS) + if (_pocketStatus[menu][i] != MAXMENUANIMS) complete = 0; // ... and animate the first icon - if (pocketStatus[menu][0] != MAXMENUANIMS) - pocketStatus[menu][0]++; + if (_pocketStatus[menu][0] != MAXMENUANIMS) + _pocketStatus[menu][0]++; // Check to see if the menu is fully open if (complete) - menuStatus[menu] = RDMENU_SHOWN; - } else if (menuStatus[menu] == RDMENU_CLOSING) { + _menuStatus[menu] = RDMENU_SHOWN; + } else if (_menuStatus[menu] == RDMENU_CLOSING) { // The menu is closing, so process it here complete = 1; // Propagate the animation from the first icon. for (i = RDMENU_MAXPOCKETS - 1; i > 0; i--) { - if (icons[menu][i] && pocketStatus[menu][i] != 0 && pocketStatus[menu][i - 1] == 0) { - ClearIconArea(menu, i, &r1); - UploadRect(&r1); + if (_icons[menu][i] && _pocketStatus[menu][i] != 0 && _pocketStatus[menu][i - 1] == 0) { + clearIconArea(menu, i, &r1); + updateRect(&r1); } - pocketStatus[menu][i] = pocketStatus[menu][i - 1]; - if (pocketStatus[menu][i] != 0) + _pocketStatus[menu][i] = _pocketStatus[menu][i - 1]; + if (_pocketStatus[menu][i] != 0) complete = 0; } - if (pocketStatus[menu][i] != 0) + if (_pocketStatus[menu][i] != 0) complete = 0; // ... and animate the first icon - if (pocketStatus[menu][0] != 0) { - pocketStatus[menu][0]--; + if (_pocketStatus[menu][0] != 0) { + _pocketStatus[menu][0]--; - if (pocketStatus[menu][0] == 0) { - ClearIconArea(menu, 0, &r1); - UploadRect(&r1); + if (_pocketStatus[menu][0] == 0) { + clearIconArea(menu, 0, &r1); + updateRect(&r1); } } // Check to see if the menu is fully closed if (complete) - menuStatus[menu] = RDMENU_HIDDEN; + _menuStatus[menu] = RDMENU_HIDDEN; } } } // Does the menu need to be drawn? for (menu = RDMENU_TOP; menu <= RDMENU_BOTTOM; menu++) { - if (menuStatus[menu] != RDMENU_HIDDEN) { + if (_menuStatus[menu] != RDMENU_HIDDEN) { // Draw the menu here. curx = RDMENU_ICONSTART + RDMENU_ICONWIDE / 2; cury = (MENUDEEP / 2) + (RENDERDEEP + MENUDEEP) * menu; for (i = 0; i < RDMENU_MAXPOCKETS; i++) { - if (icons[menu][i]) { + if (_icons[menu][i]) { // Since we no longer clear the screen // after each frame we need to clear // the icon area. - ClearIconArea(menu, i, &r1); + clearIconArea(menu, i, &r1); - if (pocketStatus[menu][i] == MAXMENUANIMS) { + if (_pocketStatus[menu][i] == MAXMENUANIMS) { xoff = (RDMENU_ICONWIDE / 2); r2.left = curx - xoff; r2.right = r2.left + RDMENU_ICONWIDE; @@ -175,30 +159,30 @@ int32 ProcessMenu(void) { r2.top = cury - yoff; r2.bottom = r2.top + RDMENU_ICONDEEP; } else { - xoff = (RDMENU_ICONWIDE / 2) * pocketStatus[menu][i] / MAXMENUANIMS; + xoff = (RDMENU_ICONWIDE / 2) * _pocketStatus[menu][i] / MAXMENUANIMS; r2.left = curx - xoff; r2.right = curx + xoff; - yoff = (RDMENU_ICONDEEP / 2) * pocketStatus[menu][i] / MAXMENUANIMS; + yoff = (RDMENU_ICONDEEP / 2) * _pocketStatus[menu][i] / MAXMENUANIMS; r2.top = cury - yoff; r2.bottom = cury + yoff; } if (xoff != 0 && yoff != 0) { - dst = lpBackBuffer + r2.top * screenWide + r2.left; - src = icons[menu][i]; + dst = _buffer + r2.top * _screenWide + r2.left; + src = _icons[menu][i]; - if (pocketStatus[menu][i] != MAXMENUANIMS) { - SquashImage( - dst, screenWide, r2.right - r2.left, r2.bottom - r2.top, + if (_pocketStatus[menu][i] != MAXMENUANIMS) { + squashImage( + dst, _screenWide, r2.right - r2.left, r2.bottom - r2.top, src, RDMENU_ICONWIDE, RDMENU_ICONWIDE, RDMENU_ICONDEEP, NULL); } else { for (j = 0; j < RDMENU_ICONDEEP; j++) { memcpy(dst, src, RDMENU_ICONWIDE); src += RDMENU_ICONWIDE; - dst += screenWide; + dst += _screenWide; } } - UploadRect(&r1); + updateRect(&r1); } } curx += (RDMENU_ICONSPACING + RDMENU_ICONWIDE); @@ -207,8 +191,6 @@ int32 ProcessMenu(void) { } } } - - return RD_OK; } /** @@ -217,17 +199,17 @@ int32 ProcessMenu(void) { * @return RD_OK, or an error code */ -int32 ShowMenu(uint8 menu) { +int32 Display::showMenu(uint8 menu) { // Check for invalid menu parameter if (menu > RDMENU_BOTTOM) return RDERR_INVALIDMENU; // Check that the menu is not currently shown, or in the process of // being shown. - if (menuStatus[menu] == RDMENU_SHOWN || menuStatus[menu] == RDMENU_OPENING) + if (_menuStatus[menu] == RDMENU_SHOWN || _menuStatus[menu] == RDMENU_OPENING) return RDERR_INVALIDCOMMAND; - menuStatus[menu] = RDMENU_OPENING; + _menuStatus[menu] = RDMENU_OPENING; return RD_OK; } @@ -237,17 +219,17 @@ int32 ShowMenu(uint8 menu) { * @return RD_OK, or an error code */ -int32 HideMenu(uint8 menu) { +int32 Display::hideMenu(uint8 menu) { // Check for invalid menu parameter if (menu > RDMENU_BOTTOM) return RDERR_INVALIDMENU; // Check that the menu is not currently hidden, or in the process of // being hidden. - if (menuStatus[menu] == RDMENU_HIDDEN || menuStatus[menu] == RDMENU_CLOSING) + if (_menuStatus[menu] == RDMENU_HIDDEN || _menuStatus[menu] == RDMENU_CLOSING) return RDERR_INVALIDCOMMAND; - menuStatus[menu] = RDMENU_CLOSING; + _menuStatus[menu] = RDMENU_CLOSING; return RD_OK; } @@ -255,26 +237,25 @@ int32 HideMenu(uint8 menu) { * This function hides both menus immediately. */ -int32 CloseMenuImmediately(void) { +void Display::closeMenuImmediately(void) { Common::Rect r; int i; - menuStatus[0] = RDMENU_HIDDEN; - menuStatus[1] = RDMENU_HIDDEN; + _menuStatus[0] = RDMENU_HIDDEN; + _menuStatus[1] = RDMENU_HIDDEN; for (i = 0; i < RDMENU_MAXPOCKETS; i++) { - if (icons[0][i]) { - ClearIconArea(0, i, &r); - UploadRect(&r); + if (_icons[0][i]) { + clearIconArea(0, i, &r); + updateRect(&r); } - if (icons[1][i]) { - ClearIconArea(1, i, &r); - UploadRect(&r); + if (_icons[1][i]) { + clearIconArea(1, i, &r); + updateRect(&r); } } - memset(pocketStatus, 0, sizeof(uint8) * 2 * RDMENU_MAXPOCKETS); - return RD_OK; + memset(_pocketStatus, 0, sizeof(uint8) * 2 * RDMENU_MAXPOCKETS); } /** @@ -285,11 +266,9 @@ int32 CloseMenuImmediately(void) { * @return RD_OK, or an error code */ -int32 SetMenuIcon(uint8 menu, uint8 pocket, uint8 *icon) { +int32 Display::setMenuIcon(uint8 menu, uint8 pocket, uint8 *icon) { Common::Rect r; - debug(5, "stub SetMenuIcon( %d, %d )", menu, pocket); - // Check for invalid menu parameter. if (menu > RDMENU_BOTTOM) return RDERR_INVALIDMENU; @@ -299,33 +278,24 @@ int32 SetMenuIcon(uint8 menu, uint8 pocket, uint8 *icon) { return RDERR_INVALIDPOCKET; // If there is an icon in the requested menu/pocket, clear it out. - if (icons[menu][pocket]) { - iconCount--; - free(icons[menu][pocket]); - icons[menu][pocket] = NULL; - ClearIconArea(menu, pocket, &r); - UploadRect(&r); + if (_icons[menu][pocket]) { + _iconCount--; + free(_icons[menu][pocket]); + _icons[menu][pocket] = NULL; + clearIconArea(menu, pocket, &r); + updateRect(&r); } // Only put the icon in the pocket if it is not NULL if (icon != NULL) { - iconCount++; - icons[menu][pocket] = (uint8 *) malloc(RDMENU_ICONWIDE * RDMENU_ICONDEEP); - if (icons[menu][pocket] == NULL) + _iconCount++; + _icons[menu][pocket] = (uint8 *) malloc(RDMENU_ICONWIDE * RDMENU_ICONDEEP); + if (_icons[menu][pocket] == NULL) return RDERR_OUTOFMEMORY; - memcpy(icons[menu][pocket], icon, RDMENU_ICONWIDE * RDMENU_ICONDEEP); + memcpy(_icons[menu][pocket], icon, RDMENU_ICONWIDE * RDMENU_ICONDEEP); } - return RD_OK; -} -/** - * @return The status of the menu - */ - -uint8 GetMenuStatus(uint8 menu) { - if (menu > RDMENU_BOTTOM) - return RDMENU_HIDDEN; - return menuStatus[menu]; + return RD_OK; } } // End of namespace Sword2 diff --git a/sword2/driver/palette.cpp b/sword2/driver/palette.cpp index c08f0ac14e..480c0de0a5 100644 --- a/sword2/driver/palette.cpp +++ b/sword2/driver/palette.cpp @@ -20,54 +20,31 @@ #include "stdafx.h" #include "common/util.h" #include "base/engine.h" +#include "bs2/sword2.h" #include "bs2/driver/d_draw.h" #include "bs2/driver/driver96.h" -#include "bs2/sword2.h" namespace Sword2 { -#define PALTABLESIZE 64 * 64 * 64 - -uint8 palCopy[256][4]; - -static uint8 fadePalette[256][4]; -static uint8 paletteMatch[PALTABLESIZE]; -static uint8 fadeStatus = RDFADE_NONE; - -static int32 fadeStartTime; -static int32 fadeTotalTime; - -// -------------------------------------------------------------------------- -// int32 RestorePalette(void) -// -// This function restores the palette, and should be called whenever the -// screen mode changes, or something like that. -// -------------------------------------------------------------------------- - -int32 RestorePalette(void) { - g_system->set_palette((const byte *) palCopy, 0, 256); - return RD_OK; -} - -uint8 GetMatch(uint8 r, uint8 g, uint8 b) { +uint8 Display::getMatch(uint8 r, uint8 g, uint8 b) { int32 diff; int32 min; int16 diffred, diffgreen, diffblue; int16 i; uint8 minIndex; - diffred = palCopy[0][0] - r; - diffgreen = palCopy[0][1] - g; - diffblue = palCopy[0][2] - b; + diffred = _palCopy[0][0] - r; + diffgreen = _palCopy[0][1] - g; + diffblue = _palCopy[0][2] - b; diff = diffred * diffred + diffgreen * diffgreen + diffblue * diffblue; min = diff; minIndex = 0; if (diff > 0) { for (i = 1; i < 256; i++) { - diffred = palCopy[i][0] - r; - diffgreen = palCopy[i][1] - g; - diffblue = palCopy[i][2] - b; + diffred = _palCopy[i][0] - r; + diffgreen = _palCopy[i][1] - g; + diffblue = _palCopy[i][2] - b; diff = diffred * diffred + diffgreen * diffgreen + diffblue * diffblue; if (diff < min) { @@ -90,7 +67,7 @@ uint8 GetMatch(uint8 r, uint8 g, uint8 b) { * from the current palCopy */ -int32 UpdatePaletteMatchTable(uint8 *data) { +void Display::updatePaletteMatchTable(uint8 *data) { if (!data) { int16 red, green, blue; uint8 *p; @@ -99,20 +76,18 @@ int32 UpdatePaletteMatchTable(uint8 *data) { // FIXME: Does this case ever happen? - p = &paletteMatch[0]; + p = &_paletteMatch[0]; for (red = 0; red < 256; red += 4) { for (green = 0; green < 256; green += 4) { for (blue = 0; blue < 256; blue += 4) { - *p++ = GetMatch((uint8) red, (uint8) green, (uint8) blue); + *p++ = getMatch((uint8) red, (uint8) green, (uint8) blue); } } } } else { // The provided data is the new palette match table - memcpy(paletteMatch, data, PALTABLESIZE); + memcpy(_paletteMatch, data, PALTABLESIZE); } - - return RD_OK; } /** @@ -126,8 +101,8 @@ int32 UpdatePaletteMatchTable(uint8 *data) { // FIXME: This used to be inlined - probably a good idea - but the // linker complained when I tried to use it in sprite.cpp. -uint8 QuickMatch(uint8 r, uint8 g, uint8 b) { - return paletteMatch[((int32) (r >> 2) << 12) + ((int32) (g >> 2) << 6) + (b >> 2)]; +uint8 Display::quickMatch(uint8 r, uint8 g, uint8 b) { + return _paletteMatch[((int32) (r >> 2) << 12) + ((int32) (g >> 2) << 6) + (b >> 2)]; } /** @@ -137,27 +112,22 @@ uint8 QuickMatch(uint8 r, uint8 g, uint8 b) { * @param colourTable the new colour entries */ -int32 BS2_SetPalette(int16 startEntry, int16 noEntries, uint8 *colourTable, uint8 fadeNow) { - if (noEntries == 0) { - RestorePalette(); - return RD_OK; - } - - memcpy(&palCopy[startEntry][0], colourTable, noEntries * 4); - if (fadeNow == RDPAL_INSTANT) - g_system->set_palette((byte *) palCopy, startEntry, noEntries); - - return RD_OK; +void Display::setPalette(int16 startEntry, int16 noEntries, uint8 *colourTable, uint8 fadeNow) { + if (noEntries) { + memcpy(&_palCopy[startEntry][0], colourTable, noEntries * 4); + if (fadeNow == RDPAL_INSTANT) + g_system->set_palette((const byte *) _palCopy, startEntry, noEntries); + } else + g_system->set_palette((const byte *) _palCopy, 0, 256); } -int32 DimPalette(void) { - byte *p = (byte *) palCopy; +void Display::dimPalette(void) { + byte *p = (byte *) _palCopy; for (int i = 0; i < 256 * 4; i++) p[i] /= 2; g_system->set_palette(p, 0, 256); - return RD_OK; } /** @@ -165,13 +135,13 @@ int32 DimPalette(void) { * @param time the time it will take the palette to fade up */ -int32 FadeUp(float time) { - if (fadeStatus != RDFADE_BLACK && fadeStatus != RDFADE_NONE) +int32 Display::fadeUp(float time) { + if (getFadeStatus() != RDFADE_BLACK && getFadeStatus() != RDFADE_NONE) return RDERR_FADEINCOMPLETE; - fadeTotalTime = (int32) (time * 1000); - fadeStatus = RDFADE_UP; - fadeStartTime = SVM_timeGetTime(); + _fadeTotalTime = (int32) (time * 1000); + _fadeStatus = RDFADE_UP; + _fadeStartTime = SVM_timeGetTime(); return RD_OK; } @@ -181,13 +151,13 @@ int32 FadeUp(float time) { * @param time the time it will take the palette to fade down */ -int32 FadeDown(float time) { - if (fadeStatus != RDFADE_BLACK && fadeStatus != RDFADE_NONE) +int32 Display::fadeDown(float time) { + if (getFadeStatus() != RDFADE_BLACK && getFadeStatus() != RDFADE_NONE) return RDERR_FADEINCOMPLETE; - fadeTotalTime = (int32) (time * 1000); - fadeStatus = RDFADE_DOWN; - fadeStartTime = SVM_timeGetTime(); + _fadeTotalTime = (int32) (time * 1000); + _fadeStatus = RDFADE_DOWN; + _fadeStartTime = SVM_timeGetTime(); return RD_OK; } @@ -198,20 +168,20 @@ int32 FadeDown(float time) { * (not faded), or RDFADE_BLACK (completely faded down) */ -uint8 GetFadeStatus(void) { - return fadeStatus; +uint8 Display::getFadeStatus(void) { + return _fadeStatus; } -void WaitForFade(void) { - while (GetFadeStatus() != RDFADE_NONE && GetFadeStatus() != RDFADE_BLACK) { - ServiceWindows(); +void Display::waitForFade(void) { + while (getFadeStatus() != RDFADE_NONE && getFadeStatus() != RDFADE_BLACK) { + updateDisplay(); g_system->delay_msecs(20); } } -void FadeServer() { +void Display::fadeServer(void) { static int32 previousTime = 0; - const byte *newPalette = (const byte *) fadePalette; + const byte *newPalette = (const byte *) _fadePalette; int32 currentTime; int16 fadeMultiplier; int16 i; @@ -221,7 +191,7 @@ void FadeServer() { // actually update the screen. // If we're not in the process of fading, do nothing. - if (fadeStatus != RDFADE_UP && fadeStatus != RDFADE_DOWN) + if (getFadeStatus() != RDFADE_UP && getFadeStatus() != RDFADE_DOWN) return; // I don't know if this is necessary, but let's limit how often the @@ -232,28 +202,28 @@ void FadeServer() { previousTime = currentTime; - if (fadeStatus == RDFADE_UP) { - if (currentTime >= fadeStartTime + fadeTotalTime) { - fadeStatus = RDFADE_NONE; - newPalette = (const byte *) palCopy; + if (getFadeStatus() == RDFADE_UP) { + if (currentTime >= _fadeStartTime + _fadeTotalTime) { + _fadeStatus = RDFADE_NONE; + newPalette = (const byte *) _palCopy; } else { - fadeMultiplier = (int16) (((int32) (currentTime - fadeStartTime) * 256) / fadeTotalTime); + fadeMultiplier = (int16) (((int32) (currentTime - _fadeStartTime) * 256) / _fadeTotalTime); for (i = 0; i < 256; i++) { - fadePalette[i][0] = (palCopy[i][0] * fadeMultiplier) >> 8; - fadePalette[i][1] = (palCopy[i][1] * fadeMultiplier) >> 8; - fadePalette[i][2] = (palCopy[i][2] * fadeMultiplier) >> 8; + _fadePalette[i][0] = (_palCopy[i][0] * fadeMultiplier) >> 8; + _fadePalette[i][1] = (_palCopy[i][1] * fadeMultiplier) >> 8; + _fadePalette[i][2] = (_palCopy[i][2] * fadeMultiplier) >> 8; } } } else { - if (currentTime >= fadeStartTime + fadeTotalTime) { - fadeStatus = RDFADE_BLACK; - memset(fadePalette, 0, sizeof(fadePalette)); + if (currentTime >= _fadeStartTime + _fadeTotalTime) { + _fadeStatus = RDFADE_BLACK; + memset(_fadePalette, 0, sizeof(_fadePalette)); } else { - fadeMultiplier = (int16) (((int32) (fadeTotalTime - (currentTime - fadeStartTime)) * 256) / fadeTotalTime); + fadeMultiplier = (int16) (((int32) (_fadeTotalTime - (currentTime - _fadeStartTime)) * 256) / _fadeTotalTime); for (i = 0; i < 256; i++) { - fadePalette[i][0] = (palCopy[i][0] * fadeMultiplier) >> 8; - fadePalette[i][1] = (palCopy[i][1] * fadeMultiplier) >> 8; - fadePalette[i][2] = (palCopy[i][2] * fadeMultiplier) >> 8; + _fadePalette[i][0] = (_palCopy[i][0] * fadeMultiplier) >> 8; + _fadePalette[i][1] = (_palCopy[i][1] * fadeMultiplier) >> 8; + _fadePalette[i][2] = (_palCopy[i][2] * fadeMultiplier) >> 8; } } } diff --git a/sword2/driver/palette.h b/sword2/driver/palette.h index 705cbe9030..34de190bd6 100644 --- a/sword2/driver/palette.h +++ b/sword2/driver/palette.h @@ -22,11 +22,6 @@ namespace Sword2 { -extern uint8 paletteMatch[64*64*64]; - -extern int32 RestorePalette(void); -extern void FadeServer(); - } // End of namespace Sword2 #endif diff --git a/sword2/driver/rdwin.cpp b/sword2/driver/rdwin.cpp index 6d63521ce7..2f12e6c9fa 100644 --- a/sword2/driver/rdwin.cpp +++ b/sword2/driver/rdwin.cpp @@ -44,8 +44,8 @@ void Sword2Engine::parseEvents() { WriteKey(event.kbd.ascii, event.kbd.keycode, event.kbd.flags); break; case OSystem::EVENT_MOUSEMOVE: - mousex = event.mouse.x; - mousey = event.mouse.y - MENUDEEP; + g_display->_mouseX = event.mouse.x; + g_display->_mouseY = event.mouse.y - MENUDEEP; break; case OSystem::EVENT_LBUTTONDOWN: LogMouseEvent(RD_LEFTBUTTONDOWN); @@ -61,7 +61,6 @@ void Sword2Engine::parseEvents() { break; case OSystem::EVENT_QUIT: Close_game(); - CloseAppWindow(); break; default: break; @@ -69,24 +68,8 @@ void Sword2Engine::parseEvents() { } } -/** - * Quit the game. - */ - -int32 CloseAppWindow(void) { - warning("stub CloseAppWindow"); -/* - DestroyWindow(hwnd); -*/ - // just quit for now - g_system->quit(); - return RD_OK; -} - -static bool _needRedraw = false; - -void SetNeedRedraw() { - _needRedraw = true; +void Display::setNeedFullRedraw() { + _needFullRedraw = true; } /** @@ -94,29 +77,27 @@ void SetNeedRedraw() { * windows and the interface it provides. */ -int32 ServiceWindows(void) { +void Display::updateDisplay(void) { g_sword2->parseEvents(); - FadeServer(); + fadeServer(); // FIXME: We re-render the entire picture area of the screen for each // frame, which is pretty horrible. - if (_needRedraw) { - g_system->copy_rect(lpBackBuffer + MENUDEEP * screenWide, screenWide, 0, MENUDEEP, screenWide, screenDeep - 2 * MENUDEEP); - _needRedraw = false; + if (_needFullRedraw) { + g_system->copy_rect(_buffer + MENUDEEP * _screenWide, _screenWide, 0, MENUDEEP, _screenWide, _screenDeep - 2 * MENUDEEP); + _needFullRedraw = false; } // We still need to update because of fades, menu animations, etc. g_system->update_screen(); - - return RD_OK; } /** * Set the window title */ -void SetWindowName(const char *windowName) { +void Display::setWindowName(const char *windowName) { OSystem::Property prop; prop.caption = windowName; diff --git a/sword2/driver/rdwin.h b/sword2/driver/rdwin.h index b0a483fe1a..4fbbf33a35 100644 --- a/sword2/driver/rdwin.h +++ b/sword2/driver/rdwin.h @@ -22,8 +22,6 @@ namespace Sword2 { -extern void SetNeedRedraw(void); - } // End of namespace Sword2 #endif diff --git a/sword2/driver/render.cpp b/sword2/driver/render.cpp index 9718106963..a8e13fd45a 100644 --- a/sword2/driver/render.cpp +++ b/sword2/driver/render.cpp @@ -28,60 +28,18 @@ namespace Sword2 { -#define MILLISECSPERCYCLE 83 - -// Scroll variables. scrollx and scrolly hold the current scroll position, -// and scrollxTarget and scrollyTarget are the target position for the end -// of the game cycle. - -extern int16 scrollx; -extern int16 scrolly; -int16 parallaxScrollx; -int16 parallaxScrolly; -int16 locationWide; -int16 locationDeep; - -static int16 scrollxTarget; -static int16 scrollyTarget; -static int16 scrollxOld; -static int16 scrollyOld; -static uint16 layer = 0; - -#define RENDERAVERAGETOTAL 4 - -static int32 renderCountIndex = 0; -static int32 renderTimeLog[RENDERAVERAGETOTAL] = { 60, 60, 60, 60 }; -static int32 initialTime; -static int32 startTime; -static int32 totalTime; -static int32 renderAverageTime = 60; -static int32 framesPerGameCycle; -static int32 renderTooSlow; - -#define BLOCKWIDTH 64 -#define BLOCKHEIGHT 64 -#define BLOCKWBITS 6 -#define BLOCKHBITS 6 -#define MAXLAYERS 5 - -static uint8 xblocks[MAXLAYERS]; -static uint8 yblocks[MAXLAYERS]; - -// blockSurfaces stores an array of sub-blocks for each of the parallax layers. - -typedef struct { - byte data[BLOCKWIDTH * BLOCKHEIGHT]; - bool transparent; -} BlockSurface; - -static BlockSurface **blockSurfaces[MAXLAYERS] = { 0, 0, 0, 0, 0 }; - -void UploadRect(Common::Rect *r) { - g_system->copy_rect(lpBackBuffer + r->top * screenWide + r->left, - screenWide, r->left, r->top, r->right - r->left, r->bottom - r->top); +#define MILLISECSPERCYCLE 83 + +#define BLOCKWBITS 6 +#define BLOCKHBITS 6 + +void Display::updateRect(Common::Rect *r) { + g_system->copy_rect(_buffer + r->top * _screenWide + r->left, + _screenWide, r->left, r->top, r->right - r->left, + r->bottom - r->top); } -void BlitBlockSurface(BlockSurface *s, Common::Rect *r, Common::Rect *clip_rect) { +void Display::blitBlockSurface(BlockSurface *s, Common::Rect *r, Common::Rect *clip_rect) { if (r->top > clip_rect->bottom || r->left > clip_rect->right || r->bottom <= clip_rect->top || r->right <= clip_rect->left) return; @@ -100,7 +58,7 @@ void BlitBlockSurface(BlockSurface *s, Common::Rect *r, Common::Rect *clip_rect) if (r->right > clip_rect->right) r->right = clip_rect->right; - byte *dst = lpBackBuffer + r->top * screenWide + r->left; + byte *dst = _buffer + r->top * _screenWide + r->left; int i, j; if (s->transparent) { @@ -110,23 +68,20 @@ void BlitBlockSurface(BlockSurface *s, Common::Rect *r, Common::Rect *clip_rect) dst[j] = src[j]; } src += BLOCKWIDTH; - dst += screenWide; + dst += _screenWide; } } else { for (i = 0; i < r->bottom - r->top; i++) { memcpy(dst, src, r->right - r->left); src += BLOCKWIDTH; - dst += screenWide; + dst += _screenWide; } } // UploadRect(r); - SetNeedRedraw(); + g_display->setNeedFullRedraw(); } -static uint16 xScale[SCALE_MAXWIDTH]; -static uint16 yScale[SCALE_MAXHEIGHT]; - // I've made the scaling two separate functions because there were cases from // DrawSprite() where it wasn't obvious if the sprite should grow or shrink, // which caused crashes. @@ -140,7 +95,7 @@ static uint16 yScale[SCALE_MAXHEIGHT]; // be drawn. This is only used at the highest graphics detail setting (and not // always even then) and is used to help anti-alias the image. -void SquashImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight, byte *src, uint16 srcPitch, uint16 srcWidth, uint16 srcHeight, byte *backbuf) { +void Display::squashImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight, byte *src, uint16 srcPitch, uint16 srcWidth, uint16 srcHeight, byte *backbuf) { int32 ince, incne, d; int16 x, y; @@ -150,7 +105,7 @@ void SquashImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight, incne = 2 * (dstWidth - srcWidth); d = 2 * dstWidth - srcWidth; x = y = 0; - xScale[y] = x; + _xScale[y] = x; while (x < srcWidth) { if (d <= 0) { @@ -161,7 +116,7 @@ void SquashImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight, x++; y++; } - xScale[y] = x; + _xScale[y] = x; } // Work out the y-scale @@ -170,7 +125,7 @@ void SquashImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight, incne = 2 * (dstHeight - srcHeight); d = 2 * dstHeight - srcHeight; x = y = 0; - yScale[y] = x; + _yScale[y] = x; while (x < srcHeight) { if (d <= 0) { @@ -181,7 +136,7 @@ void SquashImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight, x++; y++; } - yScale[y] = x; + _yScale[y] = x; } // Copy the image (with or without anti-aliasing) @@ -198,19 +153,19 @@ void SquashImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight, int blue = 0; int i, j; - for (j = yScale[y]; j < yScale[y + 1]; j++) { - for (i = xScale[x]; i < xScale[x + 1]; i++) { + for (j = _yScale[y]; j < _yScale[y + 1]; j++) { + for (i = _xScale[x]; i < _xScale[x + 1]; i++) { p = src[j * srcPitch + i]; if (p) { - red += palCopy[p][0]; - green += palCopy[p][1]; - blue += palCopy[p][2]; + red += _palCopy[p][0]; + green += _palCopy[p][1]; + blue += _palCopy[p][2]; p1 = p; spriteCount++; } else { - red += palCopy[backbuf[x]][0]; - green += palCopy[backbuf[x]][1]; - blue += palCopy[backbuf[x]][2]; + red += _palCopy[backbuf[x]][0]; + green += _palCopy[backbuf[x]][1]; + blue += _palCopy[backbuf[x]][2]; } count++; } @@ -220,22 +175,22 @@ void SquashImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight, else if (spriteCount == 1) dst[x] = p1; else - dst[x] = QuickMatch((uint8) (red / count), (uint8) (green / count), (uint8) (blue / count)); + dst[x] = quickMatch((uint8) (red / count), (uint8) (green / count), (uint8) (blue / count)); } dst += dstPitch; - backbuf += screenWide; + backbuf += _screenWide; } } else { for (y = 0; y < dstHeight; y++) { for (x = 0; x < dstWidth; x++) { - dst[x] = src[yScale[y] * srcPitch + xScale[x]]; + dst[x] = src[_yScale[y] * srcPitch + _xScale[x]]; } dst += dstPitch; } } } -void StretchImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight, byte *src, uint16 srcPitch, uint16 srcWidth, uint16 srcHeight, byte *backbuf) { +void Display::stretchImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight, byte *src, uint16 srcPitch, uint16 srcWidth, uint16 srcHeight, byte *backbuf) { byte *origDst = dst; int32 ince, incne, d; int16 x, y, i, j, k; @@ -246,7 +201,7 @@ void StretchImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight, incne = 2 * (srcWidth - dstWidth); d = 2 * srcWidth - dstWidth; x = y = 0; - xScale[y] = x; + _xScale[y] = x; while (x < dstWidth) { if (d <= 0) { @@ -256,7 +211,7 @@ void StretchImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight, d += incne; x++; y++; - xScale[y] = x; + _xScale[y] = x; } } @@ -266,7 +221,7 @@ void StretchImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight, incne = 2 * (srcHeight - dstHeight); d = 2 * srcHeight - dstHeight; x = y = 0; - yScale[y] = x; + _yScale[y] = x; while (x < dstHeight) { if (d <= 0) { d += ince; @@ -275,17 +230,17 @@ void StretchImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight, d += incne; x++; y++; - yScale[y] = x; + _yScale[y] = x; } } // Copy the image for (y = 0; y < srcHeight; y++) { - for (j = yScale[y]; j < yScale[y + 1]; j++) { + for (j = _yScale[y]; j < _yScale[y + 1]; j++) { k = 0; for (x = 0; x < srcWidth; x++) { - for (i = xScale[x]; i < xScale[x + 1]; i++) { + for (i = _xScale[x]; i < _xScale[x + 1]; i++) { dst[k++] = src[y * srcPitch + x]; } } @@ -342,16 +297,16 @@ void StretchImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight, count++; if (count) { - int red = palCopy[pt[0]][0] << 2; - int green = palCopy[pt[0]][1] << 2; - int blue = palCopy[pt[0]][2] << 2; + int red = _palCopy[pt[0]][0] << 2; + int green = _palCopy[pt[0]][1] << 2; + int blue = _palCopy[pt[0]][2] << 2; for (i = 1; i < 5; i++) { - red += palCopy[pt[i]][0]; - green += palCopy[pt[i]][1]; - blue += palCopy[pt[i]][2]; + red += _palCopy[pt[i]][0]; + green += _palCopy[pt[i]][1]; + blue += _palCopy[pt[i]][2]; } - *dst++ = QuickMatch((uint8) (red >> 3), (uint8) (green >> 3), (uint8) (blue >> 3)); + *dst++ = quickMatch((uint8) (red >> 3), (uint8) (green >> 3), (uint8) (blue >> 3)); } else *dst++ = 0; src++; @@ -373,27 +328,7 @@ void StretchImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight, } } -int32 RestoreBackgroundLayer(_parallax *p, int16 l) -{ - int16 oldLayer = layer; - - debug(2, "RestoreBackgroundLayer %d", l); - - layer = l; - if (blockSurfaces[l]) { - for (int i = 0; i < xblocks[l] * yblocks[l]; i++) { - if (blockSurfaces[l][i]) - free(blockSurfaces[l][i]); - } - - free(blockSurfaces[l]); - blockSurfaces[l] = NULL; - } - InitialiseBackgroundLayer(p); - layer = oldLayer; - return RD_OK; -} - +#ifdef _SWORD2_DEBUG /** * Plots a point relative to the top left corner of the screen. This is only * used for debugging. @@ -402,17 +337,15 @@ int32 RestoreBackgroundLayer(_parallax *p, int16 l) * @param colour colour of the point */ -int32 PlotPoint(uint16 x, uint16 y, uint8 colour) { - uint8 *buf = lpBackBuffer + 40 * RENDERWIDE; +void Display::plotPoint(uint16 x, uint16 y, uint8 colour) { + uint8 *buf = _buffer + 40 * RENDERWIDE; int16 newx, newy; - newx = x - scrollx; - newy = y - scrolly; + newx = x - _scrollX; + newy = y - _scrollY; if (newx >= 0 && newx < RENDERWIDE && newy >= 0 && newy < RENDERDEEP) buf[newy * RENDERWIDE + newx] = colour; - - return RD_OK; } /** @@ -425,8 +358,8 @@ int32 PlotPoint(uint16 x, uint16 y, uint8 colour) { */ // Uses Bressnham's incremental algorithm! -int32 DrawLine(int16 x0, int16 y0, int16 x1, int16 y1, uint8 colour) { - uint8 *buf = lpBackBuffer + 40 * RENDERWIDE; +void Display::drawLine(int16 x0, int16 y0, int16 x1, int16 y1, uint8 colour) { + uint8 *buf = _buffer + 40 * RENDERWIDE; int dx, dy; int dxmod, dymod; int ince, incne; @@ -434,10 +367,10 @@ int32 DrawLine(int16 x0, int16 y0, int16 x1, int16 y1, uint8 colour) { int x, y; int addTo; - x1 -= scrollx; - y1 -= scrolly; - x0 -= scrollx; - y0 -= scrolly; + x1 -= _scrollX; + y1 -= _scrollY; + x0 -= _scrollX; + y0 -= _scrollY; // Lock the surface if we're rendering to the back buffer. @@ -579,9 +512,8 @@ int32 DrawLine(int16 x0, int16 y0, int16 x1, int16 y1, uint8 colour) { } } } - - return RD_OK; } +#endif /** * This function tells the driver the size of the background screen for the @@ -590,11 +522,9 @@ int32 DrawLine(int16 x0, int16 y0, int16 x1, int16 y1, uint8 colour) { * @param h height of the current location */ -int32 SetLocationMetrics(uint16 w, uint16 h) { - locationWide = w; - locationDeep = h; - - return RD_OK; +void Display::setLocationMetrics(uint16 w, uint16 h) { + _locationWide = w; + _locationDeep = h; } /** @@ -602,45 +532,43 @@ int32 SetLocationMetrics(uint16 w, uint16 h) { * parallax can be either foreground, background or the main screen. */ -int32 RenderParallax(_parallax *p, int16 l) { +void Display::renderParallax(_parallax *p, int16 l) { int16 x, y; Common::Rect r; - if (locationWide == screenWide) + if (_locationWide == _screenWide) x = 0; else - x = ((int32) ((p->w - screenWide) * scrollx) / (int32) (locationWide - screenWide)); + x = ((int32) ((p->w - _screenWide) * _scrollX) / (int32) (_locationWide - _screenWide)); - if (locationDeep == (screenDeep - MENUDEEP * 2)) + if (_locationDeep == _screenDeep - MENUDEEP * 2) y = 0; else - y = ((int32) ((p->h - (screenDeep - MENUDEEP * 2)) * scrolly) / (int32) (locationDeep - (screenDeep - MENUDEEP * 2))); + y = ((int32) ((p->h - (_screenDeep - MENUDEEP * 2)) * _scrollY) / (int32) (_locationDeep - (_screenDeep - MENUDEEP * 2))); Common::Rect clip_rect; // Leave enough space for the top and bottom menues clip_rect.left = 0; - clip_rect.right = screenWide; + clip_rect.right = _screenWide; clip_rect.top = MENUDEEP; - clip_rect.bottom = screenDeep - MENUDEEP; + clip_rect.bottom = _screenDeep - MENUDEEP; - for (int j = 0; j < yblocks[l]; j++) { - for (int i = 0; i < xblocks[l]; i++) { - if (blockSurfaces[l][i + j * xblocks[l]]) { + for (int j = 0; j < _yBlocks[l]; j++) { + for (int i = 0; i < _xBlocks[l]; i++) { + if (_blockSurfaces[l][i + j * _xBlocks[l]]) { r.left = i * BLOCKWIDTH - x; r.right = r.left + BLOCKWIDTH; r.top = j * BLOCKHEIGHT - y + 40; r.bottom = r.top + BLOCKHEIGHT; - BlitBlockSurface(blockSurfaces[l][i + j * xblocks[l]], &r, &clip_rect); + blitBlockSurface(_blockSurfaces[l][i + j * _xBlocks[l]], &r, &clip_rect); } } } - parallaxScrollx = scrollx - x; - parallaxScrolly = scrolly - y; - - return RD_OK; + _parallaxScrollX = _scrollX - x; + _parallaxScrollY = _scrollY - y; } // Uncomment this when benchmarking the drawing routines. @@ -650,10 +578,9 @@ int32 RenderParallax(_parallax *p, int16 l) { * Initialises the timers before the render loop is entered. */ -int32 InitialiseRenderCycle(void) { - initialTime = SVM_timeGetTime(); - totalTime = initialTime + MILLISECSPERCYCLE; - return RD_OK; +void Display::initialiseRenderCycle(void) { + _initialTime = SVM_timeGetTime(); + _totalTime = _initialTime + MILLISECSPERCYCLE; } /** @@ -661,24 +588,23 @@ int32 InitialiseRenderCycle(void) { * render cycle. */ -int32 StartRenderCycle(void) { - scrollxOld = scrollx; - scrollyOld = scrolly; +void Display::startRenderCycle(void) { + _scrollXOld = _scrollX; + _scrollYOld = _scrollY; - startTime = SVM_timeGetTime(); + _startTime = SVM_timeGetTime(); - if (startTime + renderAverageTime >= totalTime) { - scrollx = scrollxTarget; - scrolly = scrollyTarget; - renderTooSlow = 1; + if (_startTime + _renderAverageTime >= _totalTime) { + _scrollX = _scrollXTarget; + _scrollY = _scrollYTarget; + _renderTooSlow = true; } else { - scrollx = (int16) (scrollxOld + ((scrollxTarget - scrollxOld) * (startTime - initialTime + renderAverageTime)) / (totalTime - initialTime)); - scrolly = (int16) (scrollyOld + ((scrollyTarget - scrollyOld) * (startTime - initialTime + renderAverageTime)) / (totalTime - initialTime)); - renderTooSlow = 0; + _scrollX = (int16) (_scrollXOld + ((_scrollXTarget - _scrollXOld) * (_startTime - _initialTime + _renderAverageTime)) / (_totalTime - _initialTime)); + _scrollY = (int16) (_scrollYOld + ((_scrollYTarget - _scrollYOld) * (_startTime - _initialTime + _renderAverageTime)) / (_totalTime - _initialTime)); + _renderTooSlow = false; } - framesPerGameCycle = 0; - return RD_OK; + _framesPerGameCycle = 0; } /** @@ -687,52 +613,56 @@ int32 StartRenderCycle(void) { * terminated, or false if it should continue */ -int32 EndRenderCycle(bool *end) { +bool Display::endRenderCycle(void) { + static int32 renderTimeLog[4] = { 60, 60, 60, 60 }; + static int32 renderCountIndex = 0; int32 time; time = SVM_timeGetTime(); - renderTimeLog[renderCountIndex] = time - startTime; - startTime = time; - renderAverageTime = (renderTimeLog[0] + renderTimeLog[1] + renderTimeLog[2] + renderTimeLog[3]) >> 2; + renderTimeLog[renderCountIndex] = time - _startTime; + _startTime = time; + _renderAverageTime = (renderTimeLog[0] + renderTimeLog[1] + renderTimeLog[2] + renderTimeLog[3]) >> 2; - framesPerGameCycle++; + _framesPerGameCycle++; if (++renderCountIndex == RENDERAVERAGETOTAL) renderCountIndex = 0; - if (renderTooSlow) { - *end = true; - InitialiseRenderCycle(); - } else if (startTime + renderAverageTime >= totalTime) { - *end = true; - totalTime += MILLISECSPERCYCLE; - initialTime = time; + if (_renderTooSlow) { + initialiseRenderCycle(); + return true; + } + + if (_startTime + _renderAverageTime >= _totalTime) { + _totalTime += MILLISECSPERCYCLE; + _initialTime = time; + return true; + } + #ifdef LIMIT_FRAME_RATE - } else if (scrollxTarget == scrollx && scrollyTarget == scrolly) { + if (_scrollXTarget == _scrollX && _scrollYTarget == _scrollY) { // If we have already reached the scroll target sleep for the // rest of the render cycle. - *end = true; - sleepUntil(totalTime); - initialTime = SVM_timeGetTime(); - totalTime += MILLISECSPERCYCLE; + sleepUntil(_totalTime); + _initialTime = SVM_timeGetTime(); + _totalTime += MILLISECSPERCYCLE; + return true; + } #endif - } else { - *end = false; - // This is an attempt to ensure that we always reach the scroll - // target. Otherwise the game frequently tries to pump out new - // interpolation frames without ever getting anywhere. + // This is an attempt to ensure that we always reach the scroll target. + // Otherwise the game frequently tries to pump out new interpolation + // frames without ever getting anywhere. - if (ABS(scrollx - scrollxTarget) <= 1 && ABS(scrolly - scrollyTarget) <= 1) { - scrollx = scrollxTarget; - scrolly = scrollyTarget; - } else { - scrollx = (int16) (scrollxOld + ((scrollxTarget - scrollxOld) * (startTime - initialTime + renderAverageTime)) / (totalTime - initialTime)); - scrolly = (int16) (scrollyOld + ((scrollyTarget - scrollyOld) * (startTime - initialTime + renderAverageTime)) / (totalTime - initialTime)); - } + if (ABS(_scrollX - _scrollXTarget) <= 1 && ABS(_scrollY - _scrollYTarget) <= 1) { + _scrollX = _scrollXTarget; + _scrollY = _scrollYTarget; + } else { + _scrollX = (int16) (_scrollXOld + ((_scrollXTarget - _scrollXOld) * (_startTime - _initialTime + _renderAverageTime)) / (_totalTime - _initialTime)); + _scrollY = (int16) (_scrollYOld + ((_scrollYTarget - _scrollYOld) * (_startTime - _initialTime + _renderAverageTime)) / (_totalTime - _initialTime)); } - return RD_OK; + return false; } /** @@ -741,11 +671,9 @@ int32 EndRenderCycle(bool *end) { * position in the allotted time. */ -int32 SetScrollTarget(int16 sx, int16 sy) { - scrollxTarget = sx; - scrollyTarget = sy; - - return RD_OK; +void Display::setScrollTarget(int16 sx, int16 sy) { + _scrollXTarget = sx; + _scrollYTarget = sy; } /** @@ -753,7 +681,7 @@ int32 SetScrollTarget(int16 sx, int16 sy) { * or a NULL pointer in order of background parallax to foreground parallax. */ -int32 InitialiseBackgroundLayer(_parallax *p) { +int32 Display::initialiseBackgroundLayer(_parallax *p) { uint8 *memchunk; uint8 zeros; uint16 count; @@ -764,29 +692,29 @@ int32 InitialiseBackgroundLayer(_parallax *p) { _parallaxLine line; uint8 *pLine; - debug(2, "InitialiseBackgroundLayer"); + debug(2, "initialiseBackgroundLayer"); // This function is called to re-initialise the layers if they have // been lost. We know this if the layers have already been assigned. - if (layer == MAXLAYERS) - CloseBackgroundLayer(); + if (_layer == MAXLAYERS) + closeBackgroundLayer(); if (!p) { - layer++; + _layer++; return RD_OK; } - xblocks[layer] = (p->w + BLOCKWIDTH - 1) >> BLOCKWBITS; - yblocks[layer] = (p->h + BLOCKHEIGHT - 1) >> BLOCKHBITS; + _xBlocks[_layer] = (p->w + BLOCKWIDTH - 1) >> BLOCKWBITS; + _yBlocks[_layer] = (p->h + BLOCKHEIGHT - 1) >> BLOCKHBITS; - blockSurfaces[layer] = (BlockSurface **) calloc(xblocks[layer] * yblocks[layer], sizeof(BlockSurface *)); - if (!blockSurfaces[layer]) + _blockSurfaces[_layer] = (BlockSurface **) calloc(_xBlocks[_layer] * _yBlocks[_layer], sizeof(BlockSurface *)); + if (!_blockSurfaces[_layer]) return RDERR_OUTOFMEMORY; // Decode the parallax layer into a large chunk of memory - memchunk = (uint8 *) malloc(xblocks[layer] * BLOCKWIDTH * yblocks[layer] * BLOCKHEIGHT); + memchunk = (uint8 *) malloc(_xBlocks[_layer] * BLOCKWIDTH * _yBlocks[_layer] * BLOCKHEIGHT); if (!memchunk) return RDERR_OUTOFMEMORY; @@ -835,11 +763,11 @@ int32 InitialiseBackgroundLayer(_parallax *p) { // Now create the surfaces! - for (i = 0; i < xblocks[layer] * yblocks[layer]; i++) { + for (i = 0; i < _xBlocks[_layer] * _yBlocks[_layer]; i++) { bool block_has_data = false; bool block_is_transparent = false; - data = memchunk + (p->w * BLOCKHEIGHT * (i / xblocks[layer])) + BLOCKWIDTH * (i % xblocks[layer]); + data = memchunk + (p->w * BLOCKHEIGHT * (i / _xBlocks[_layer])) + BLOCKWIDTH * (i % _xBlocks[_layer]); for (j = 0; j < BLOCKHEIGHT; j++) { for (k = 0; k < BLOCKWIDTH; k++) { @@ -853,24 +781,24 @@ int32 InitialiseBackgroundLayer(_parallax *p) { // Only assign a surface to the block if it contains data. if (block_has_data) { - blockSurfaces[layer][i] = (BlockSurface *) malloc(sizeof(BlockSurface)); + _blockSurfaces[_layer][i] = (BlockSurface *) malloc(sizeof(BlockSurface)); // Copy the data into the surfaces. - dst = blockSurfaces[layer][i]->data; + dst = _blockSurfaces[_layer][i]->data; for (j = 0; j < BLOCKHEIGHT; j++) { memcpy(dst, data, BLOCKWIDTH); data += p->w; dst += BLOCKWIDTH; } - blockSurfaces[layer][i]->transparent = block_is_transparent; + _blockSurfaces[_layer][i]->transparent = block_is_transparent; } else - blockSurfaces[layer][i] = NULL; + _blockSurfaces[_layer][i] = NULL; } free(memchunk); - layer++; + _layer++; return RD_OK; } @@ -879,21 +807,20 @@ int32 InitialiseBackgroundLayer(_parallax *p) { * Should be called once after leaving the room to free up memory. */ -int32 CloseBackgroundLayer(void) { +void Display::closeBackgroundLayer(void) { debug(2, "CloseBackgroundLayer"); for (int j = 0; j < MAXLAYERS; j++) { - if (blockSurfaces[j]) { - for (int i = 0; i < xblocks[j] * yblocks[j]; i++) - if (blockSurfaces[j][i]) - free(blockSurfaces[j][i]); - free(blockSurfaces[j]); - blockSurfaces[j] = NULL; + if (_blockSurfaces[j]) { + for (int i = 0; i < _xBlocks[j] * _yBlocks[j]; i++) + if (_blockSurfaces[j][i]) + free(_blockSurfaces[j][i]); + free(_blockSurfaces[j]); + _blockSurfaces[j] = NULL; } } - layer = 0; - return RD_OK; + _layer = 0; } } // End of namespace Sword2 diff --git a/sword2/driver/render.h b/sword2/driver/render.h index f438ede23c..7fef5d9b72 100644 --- a/sword2/driver/render.h +++ b/sword2/driver/render.h @@ -33,20 +33,6 @@ typedef struct { uint16 offset; } _parallaxLine; -extern int16 scrollx; // current x offset into background of display -extern int16 scrolly; // current y offset into background of display -extern int16 parallaxScrollx; // current x offset to link a sprite to the - // parallax layer -extern int16 parallaxScrolly; // current y offset to link a sprite to the - // parallax layer -extern int16 locationWide; -extern int16 locationDeep; - -void SquashImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight, byte *src, uint16 srcPitch, uint16 srcWidth, uint16 srcHeight, byte *backbuf); -void StretchImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight, byte *src, uint16 srcPitch, uint16 srcWidth, uint16 srcHeight, byte *backbuf); - -void UploadRect(Common::Rect *r); - } // End of namespace Sword2 #endif diff --git a/sword2/driver/sprite.cpp b/sword2/driver/sprite.cpp index c2da022430..65aefcd6c7 100644 --- a/sword2/driver/sprite.cpp +++ b/sword2/driver/sprite.cpp @@ -27,8 +27,6 @@ namespace Sword2 { -static uint8 *lightMask = 0; - /** * This function takes a sprite and creates a mirror image of it. * @param dst destination buffer @@ -37,17 +35,13 @@ static uint8 *lightMask = 0; * @param h height of the sprite */ -int32 MirrorSprite(uint8 *dst, uint8 *src, int16 w, int16 h) { - int16 x, y; - - for (y = 0; y < h; y++) { - for (x = 0; x < w; x++) { +void Display::mirrorSprite(uint8 *dst, uint8 *src, int16 w, int16 h) { + for (int y = 0; y < h; y++) { + for (int x = 0; x < w; x++) { *dst++ = *(src + w - x - 1); } src += w; } - - return RD_OK; } /** @@ -58,7 +52,7 @@ int32 MirrorSprite(uint8 *dst, uint8 *src, int16 w, int16 h) { * @param decompSize the expected size of the decompressed sprite */ -int32 DecompressRLE256(uint8 *dest, uint8 *source, int32 decompSize) { +int32 Display::decompressRLE256(uint8 *dest, uint8 *source, int32 decompSize) { // PARAMETERS: // source points to the start of the sprite data for input // decompSize gives size of decompressed data in bytes @@ -138,7 +132,7 @@ int32 DecompressRLE256(uint8 *dest, uint8 *source, int32 decompSize) { * Unwinds a run of 16-colour data into 256-colour palette data. */ -void UnwindRaw16(uint8 *dest, uint8 *source, uint8 blockSize, uint8 *colTable) { +void Display::unwindRaw16(uint8 *dest, uint8 *source, uint8 blockSize, uint8 *colTable) { // for each pair of pixels while (blockSize > 1) { // 1st colour = number in table at position given by upper @@ -173,7 +167,7 @@ void UnwindRaw16(uint8 *dest, uint8 *source, uint8 blockSize, uint8 *colTable) { * @param colTable mapping from the 16 encoded colours to the current palette */ -int32 DecompressRLE16(uint8 *dest, uint8 *source, int32 decompSize, uint8 *colTable) { +int32 Display::decompressRLE16(uint8 *dest, uint8 *source, int32 decompSize, uint8 *colTable) { uint8 headerByte; // block header byte uint8 *endDest = dest + decompSize; // pointer to byte after end of decomp buffer int32 rv; @@ -223,7 +217,7 @@ int32 DecompressRLE16(uint8 *dest, uint8 *source, int32 decompSize, uint8 *colTa // copy the next 'headerByte' pixels from source to // destination (NB. 2 pixels per byte) - UnwindRaw16(dest, source, headerByte, colTable); + unwindRaw16(dest, source, headerByte, colTable); // increment destination pointer to just after this // block @@ -253,7 +247,7 @@ int32 DecompressRLE16(uint8 *dest, uint8 *source, int32 decompSize, uint8 *colTa * @return RD_OK, or an error code */ -int32 CreateSurface(_spriteInfo *s, uint8 **sprite) { +int32 Display::createSurface(_spriteInfo *s, uint8 **sprite) { uint8 *newSprite; *sprite = (uint8 *) malloc(s->w * s->h); @@ -264,12 +258,12 @@ int32 CreateSurface(_spriteInfo *s, uint8 **sprite) { memcpy(*sprite, s->data, s->w * s->h); } else { if ((s->type >> 8) == (RDSPR_RLE16 >> 8)) { - if (DecompressRLE16(*sprite, s->data, s->w * s->h, s->colourTable)) { + if (decompressRLE16(*sprite, s->data, s->w * s->h, s->colourTable)) { free(*sprite); return RDERR_DECOMPRESSION; } } else { - if (DecompressRLE256(*sprite, s->data, s->w * s->h)) { + if (decompressRLE256(*sprite, s->data, s->w * s->h)) { free(*sprite); return RDERR_DECOMPRESSION; } @@ -281,7 +275,7 @@ int32 CreateSurface(_spriteInfo *s, uint8 **sprite) { free(*sprite); return RDERR_OUTOFMEMORY; } - MirrorSprite(newSprite, *sprite, s->w, s->h); + mirrorSprite(newSprite, *sprite, s->w, s->h); free(*sprite); *sprite = newSprite; } @@ -297,7 +291,7 @@ int32 CreateSurface(_spriteInfo *s, uint8 **sprite) { * @param clipRect the clipping rectangle */ -void DrawSurface(_spriteInfo *s, uint8 *surface, Common::Rect *clipRect) { +void Display::drawSurface(_spriteInfo *s, uint8 *surface, Common::Rect *clipRect) { Common::Rect rd, rs; uint16 x, y, srcPitch; uint8 *src, *dst; @@ -313,8 +307,8 @@ void DrawSurface(_spriteInfo *s, uint8 *surface, Common::Rect *clipRect) { rd.top = s->y; rd.left = s->x; } else { - rd.top = s->y - scrolly; - rd.left = s->x - scrollx; + rd.top = s->y - _scrollY; + rd.left = s->x - _scrollX; } rd.right = rd.left + rs.right; @@ -344,7 +338,7 @@ void DrawSurface(_spriteInfo *s, uint8 *surface, Common::Rect *clipRect) { } src = surface + rs.top * srcPitch + rs.left; - dst = lpBackBuffer + screenWide * rd.top + rd.left; + dst = _buffer + _screenWide * rd.top + rd.left; // Surfaces are always transparent. @@ -354,18 +348,18 @@ void DrawSurface(_spriteInfo *s, uint8 *surface, Common::Rect *clipRect) { dst[x] = src[x]; } src += srcPitch; - dst += screenWide; + dst += _screenWide; } - UploadRect(&rd); - SetNeedRedraw(); + updateRect(&rd); + setNeedFullRedraw(); } /** * Destroys a surface. */ -void DeleteSurface(uint8 *surface) { +void Display::deleteSurface(uint8 *surface) { free(surface); } @@ -390,7 +384,7 @@ void DeleteSurface(uint8 *surface) { // FIXME: I'm sure this could be optimized. There's plenty of data copying and // mallocing here. -int32 DrawSprite(_spriteInfo *s) { +int32 Display::drawSprite(_spriteInfo *s) { uint8 *src, *dst; uint8 *sprite, *newSprite; uint8 *backbuf = NULL; @@ -414,12 +408,12 @@ int32 DrawSprite(_spriteInfo *s) { if (!sprite) return RDERR_OUTOFMEMORY; if ((s->type >> 8) == (RDSPR_RLE16 >> 8)) { - if (DecompressRLE16(sprite, s->data, s->w * s->h, s->colourTable)) { + if (decompressRLE16(sprite, s->data, s->w * s->h, s->colourTable)) { free(sprite); return RDERR_DECOMPRESSION; } } else { - if (DecompressRLE256(sprite, s->data, s->w * s->h)) { + if (decompressRLE256(sprite, s->data, s->w * s->h)) { free(sprite); return RDERR_DECOMPRESSION; } @@ -433,7 +427,7 @@ int32 DrawSprite(_spriteInfo *s) { free(sprite); return RDERR_OUTOFMEMORY; } - MirrorSprite(newSprite, sprite, s->w, s->h); + mirrorSprite(newSprite, sprite, s->w, s->h); if (freeSprite) free(sprite); sprite = newSprite; @@ -445,8 +439,8 @@ int32 DrawSprite(_spriteInfo *s) { // ----------------------------------------------------------------- if (!(s->type & RDSPR_DISPLAYALIGN)) { - s->x += parallaxScrollx; - s->y += parallaxScrolly; + s->x += _parallaxScrollX; + s->y += _parallaxScrollY; } s->y += 40; @@ -474,8 +468,8 @@ int32 DrawSprite(_spriteInfo *s) { rd.left = s->x; if (!(s->type & RDSPR_DISPLAYALIGN)) { - rd.top -= scrolly; - rd.left -= scrollx; + rd.top -= _scrollY; + rd.left -= _scrollX; } rd.right = rd.left + rs.right; @@ -515,8 +509,8 @@ int32 DrawSprite(_spriteInfo *s) { // ----------------------------------------------------------------- if (scale != 256) { - if ((renderCaps & RDBLTFX_ARITHMETICSTRETCH) && !clipped) - backbuf = lpBackBuffer + screenWide * rd.top + rd.left; + if ((_renderCaps & RDBLTFX_EDGEBLEND) && !clipped) + backbuf = _buffer + _screenWide * rd.top + rd.left; if (s->scaledWidth > SCALE_MAXWIDTH || s->scaledHeight > SCALE_MAXHEIGHT) { @@ -533,14 +527,14 @@ int32 DrawSprite(_spriteInfo *s) { } if (scale < 256) { - SquashImage(newSprite, s->scaledWidth, s->scaledWidth, s->scaledHeight, sprite, s->w, s->w, s->h, backbuf); + squashImage(newSprite, s->scaledWidth, s->scaledWidth, s->scaledHeight, sprite, s->w, s->w, s->h, backbuf); } else { if (s->scale > 512) { if (freeSprite) free(sprite); return RDERR_INVALIDSCALING; } - StretchImage(newSprite, s->scaledWidth, s->scaledWidth, s->scaledHeight, sprite, s->w, s->w, s->h, backbuf); + stretchImage(newSprite, s->scaledWidth, s->scaledWidth, s->scaledHeight, sprite, s->w, s->w, s->h, backbuf); } if (freeSprite) @@ -557,7 +551,7 @@ int32 DrawSprite(_spriteInfo *s) { // and which is used to simulate light and shadows. Scaled sprites // (actors, presumably) are always affected. - if ((renderCaps & RDBLTFX_SHADOWBLEND) && lightMask && (scale != 256 || (s->type & RDSPR_SHADOW))) { + if ((_renderCaps & RDBLTFX_SHADOWBLEND) && _lightMask && (scale != 256 || (s->type & RDSPR_SHADOW))) { uint8 *lightMap; if (!freeSprite) { @@ -568,19 +562,19 @@ int32 DrawSprite(_spriteInfo *s) { } src = sprite + rs.top * srcPitch + rs.left; - lightMap = lightMask + (rd.top + scrolly - 40) * locationWide + rd.left + scrollx; + lightMap = _lightMask + (rd.top + _scrollY - 40) * _locationWide + rd.left + _scrollX; for (i = 0; i < rs.height(); i++) { for (j = 0; j < rs.width(); j++) { if (src[j] && lightMap[j]) { - uint8 r = ((32 - lightMap[j]) * palCopy[src[j]][0]) >> 5; - uint8 g = ((32 - lightMap[j]) * palCopy[src[j]][1]) >> 5; - uint8 b = ((32 - lightMap[j]) * palCopy[src[j]][2]) >> 5; - src[j] = QuickMatch(r, g, b); + uint8 r = ((32 - lightMap[j]) * _palCopy[src[j]][0]) >> 5; + uint8 g = ((32 - lightMap[j]) * _palCopy[src[j]][1]) >> 5; + uint8 b = ((32 - lightMap[j]) * _palCopy[src[j]][2]) >> 5; + src[j] = quickMatch(r, g, b); } } src += srcPitch; - lightMap += locationWide; + lightMap += _locationWide; } } @@ -589,17 +583,17 @@ int32 DrawSprite(_spriteInfo *s) { // ----------------------------------------------------------------- src = sprite + rs.top * srcPitch + rs.left; - dst = lpBackBuffer + screenWide * rd.top + rd.left; + dst = _buffer + _screenWide * rd.top + rd.left; if (s->type & RDSPR_BLEND) { - if (renderCaps & RDBLTFX_ALLHARDWARE) { + if (!(_renderCaps & RDBLTFX_SPRITEBLEND)) { for (i = 0; i < rs.height(); i++) { for (j = 0; j < rs.width(); j++) { if (src[j] && ((i & 1) == (j & 1))) dst[j] = src[j]; } src += srcPitch; - dst += screenWide; + dst += _screenWide; } } else { if (s->blend & 0x01) { @@ -607,14 +601,14 @@ int32 DrawSprite(_spriteInfo *s) { for (i = 0; i < rs.height(); i++) { for (j = 0; j < rs.width(); j++) { if (src[j]) { - uint8 r = (palCopy[src[j]][0] * red + palCopy[dst[j]][0] * (8 - red)) >> 3; - uint8 g = (palCopy[src[j]][1] * red + palCopy[dst[j]][1] * (8 - red)) >> 3; - uint8 b = (palCopy[src[j]][2] * red + palCopy[dst[j]][2] * (8 - red)) >> 3; - dst[j] = QuickMatch(r, g, b); + uint8 r = (_palCopy[src[j]][0] * red + _palCopy[dst[j]][0] * (8 - red)) >> 3; + uint8 g = (_palCopy[src[j]][1] * red + _palCopy[dst[j]][1] * (8 - red)) >> 3; + uint8 b = (_palCopy[src[j]][2] * red + _palCopy[dst[j]][2] * (8 - red)) >> 3; + dst[j] = quickMatch(r, g, b); } } src += srcPitch; - dst += screenWide; + dst += _screenWide; } } else if (s->blend & 0x02) { debug(2, "DrawSprite: s->blend & 0x02"); @@ -631,20 +625,20 @@ int32 DrawSprite(_spriteInfo *s) { // Does anyone know where this case was used // anyway? - red = palCopy[s->blend >> 8][0]; - green = palCopy[s->blend >> 8][0]; - blue = palCopy[s->blend >> 8][0]; + red = _palCopy[s->blend >> 8][0]; + green = _palCopy[s->blend >> 8][0]; + blue = _palCopy[s->blend >> 8][0]; for (i = 0; i < rs.height(); i++) { for (j = 0; j < rs.width(); j++) { if (src[j]) { - uint8 r = (src[j] * red + (16 - src[j]) * palCopy[dst[j]][0]) >> 4; - uint8 g = (src[j] * green + (16 - src[j]) * palCopy[dst[j]][1]) >> 4; - uint8 b = (src[j] * blue + (16 - src[j]) * palCopy[dst[j]][2]) >> 4; - dst[j] = QuickMatch(r, g, b); + uint8 r = (src[j] * red + (16 - src[j]) * _palCopy[dst[j]][0]) >> 4; + uint8 g = (src[j] * green + (16 - src[j]) * _palCopy[dst[j]][1]) >> 4; + uint8 b = (src[j] * blue + (16 - src[j]) * _palCopy[dst[j]][2]) >> 4; + dst[j] = quickMatch(r, g, b); } } src += srcPitch; - dst += screenWide; + dst += _screenWide; } } else { warning("DrawSprite: Invalid blended sprite"); @@ -661,13 +655,13 @@ int32 DrawSprite(_spriteInfo *s) { dst[j] = src[j]; } src += srcPitch; - dst += screenWide; + dst += _screenWide; } } else { for (i = 0; i < rs.height(); i++) { memcpy(dst, src, rs.width()); src += srcPitch; - dst += screenWide; + dst += _screenWide; } } } @@ -675,8 +669,8 @@ int32 DrawSprite(_spriteInfo *s) { if (freeSprite) free(sprite); - // UploadRect(&rd); - SetNeedRedraw(); + // updateRect(&rd); + setNeedFullRedraw(); return RD_OK; } @@ -685,20 +679,20 @@ int32 DrawSprite(_spriteInfo *s) { * Opens the light masking sprite for a room. */ -int32 OpenLightMask(_spriteInfo *s) { +int32 Display::openLightMask(_spriteInfo *s) { // FIXME: The light mask is only needed on higher graphics detail // settings, so to save memory we could simply ignore it on lower // settings. But then we need to figure out how to ensure that it // is properly loaded if the user changes the settings in mid-game. - if (lightMask) + if (_lightMask) return RDERR_NOTCLOSED; - lightMask = (uint8 *) malloc(s->w * s->h); - if (!lightMask) + _lightMask = (uint8 *) malloc(s->w * s->h); + if (!_lightMask) return RDERR_OUTOFMEMORY; - if (DecompressRLE256(lightMask, s->data, s->w * s->h)) + if (decompressRLE256(_lightMask, s->data, s->w * s->h)) return RDERR_DECOMPRESSION; return RD_OK; @@ -708,12 +702,12 @@ int32 OpenLightMask(_spriteInfo *s) { * Closes the light masking sprite for a room. */ -int32 CloseLightMask(void) { - if (!lightMask) +int32 Display::closeLightMask(void) { + if (!_lightMask) return RDERR_NOTOPEN; - free(lightMask); - lightMask = 0; + free(_lightMask); + _lightMask = NULL; return RD_OK; } -- cgit v1.2.3