diff options
31 files changed, 944 insertions, 1137 deletions
diff --git a/sword2/anims.cpp b/sword2/anims.cpp index c49e4e48f7..49e51ba243 100644 --- a/sword2/anims.cpp +++ b/sword2/anims.cpp @@ -776,14 +776,14 @@ int32 FN_play_sequence(int32 *params) { // now clear the screen in case the Sequence was quitted (using ESC) // rather than fading down to black - EraseBackBuffer(); + g_display->clearScene(); // zero the entire palette in case we're about to fade up! - _palEntry pal[256]; + _palEntry pal[256]; memset(pal, 0, 256 * sizeof(_palEntry)); - BS2_SetPalette(0, 256, (uint8 *) pal, RDPAL_INSTANT); + g_display->setPalette(0, 256, (uint8 *) pal, RDPAL_INSTANT); debug(5, "FN_play_sequence FINISHED"); diff --git a/sword2/build_display.cpp b/sword2/build_display.cpp index a4c14d663d..c0cfb46080 100644 --- a/sword2/build_display.cpp +++ b/sword2/build_display.cpp @@ -108,7 +108,6 @@ void Send_fore_par1_frames(void); // --------------------------------------------------------------------------- void Build_display(void) { - bool end; #ifdef _SWORD2_DEBUG uint8 pal[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0 }; #endif @@ -133,25 +132,21 @@ void Build_display(void) { // there is a valid screen to run if (!console_status && this_screen.background_layer_id) { // set the scroll position - SetScrollTarget(this_screen.scroll_offset_x, this_screen.scroll_offset_y); + g_display->setScrollTarget(this_screen.scroll_offset_x, this_screen.scroll_offset_y); // increment the mouse frame - AnimateMouse(); + g_display->animateMouse(); - StartRenderCycle(); + g_display->startRenderCycle(); while (1) { - // START OF RENDER CYCLE - - // --------------------------------------------------- // clear the back buffer, before building up the new // screen from the back forwards // FIXME: I'm not convinced that this is needed. Isn't // the whole screen redrawn each time? - // EraseBackBuffer(); + // g_display->clearScene(); - // --------------------------------------------------- // first background parallax + related anims // open the screen resource @@ -159,7 +154,7 @@ void Build_display(void) { screenLayerTable = (_multiScreenHeader *) ((uint8 *) file + sizeof(_standardHeader)); if (screenLayerTable->bg_parallax[0]) { - RenderParallax(FetchBackgroundParallaxLayer(file, 0), 0); + g_display->renderParallax(FetchBackgroundParallaxLayer(file, 0), 0); // release the screen resource before cacheing // the sprites res_man.close(this_screen.background_layer_id); @@ -169,7 +164,6 @@ void Build_display(void) { res_man.close(this_screen.background_layer_id); } - // --------------------------------------------------- // second background parallax + related anims // open the screen resource @@ -177,7 +171,7 @@ void Build_display(void) { screenLayerTable = (_multiScreenHeader *) ((uint8 *) file + sizeof(_standardHeader)); if (screenLayerTable->bg_parallax[1]) { - RenderParallax(FetchBackgroundParallaxLayer(file, 1), 1); + g_display->renderParallax(FetchBackgroundParallaxLayer(file, 1), 1); // release the screen resource before cacheing // the sprites res_man.close(this_screen.background_layer_id); @@ -187,16 +181,14 @@ void Build_display(void) { res_man.close(this_screen.background_layer_id); } - // --------------------------------------------------- // normal backround layer (just the one!) // open the screen resource file = res_man.open(this_screen.background_layer_id); - RenderParallax(FetchBackgroundLayer(file), 2); + g_display->renderParallax(FetchBackgroundLayer(file), 2); // release the screen resource res_man.close(this_screen.background_layer_id); - // --------------------------------------------------- // sprites & layers Send_back_frames(); // background sprites @@ -204,7 +196,6 @@ void Build_display(void) { Send_sort_frames(); // sorted sprites & layers Send_fore_frames(); // foreground sprites - // --------------------------------------------------- // first foreground parallax + related anims // open the screen resource @@ -212,7 +203,7 @@ void Build_display(void) { screenLayerTable = (_multiScreenHeader *) ((uint8 *) file + sizeof(_standardHeader)); if (screenLayerTable->fg_parallax[0]) { - RenderParallax(FetchForegroundParallaxLayer(file, 0), 3); + g_display->renderParallax(FetchForegroundParallaxLayer(file, 0), 3); // release the screen resource before cacheing // the sprites res_man.close(this_screen.background_layer_id); @@ -222,7 +213,6 @@ void Build_display(void) { res_man.close(this_screen.background_layer_id); } - //---------------------------------------------------- // second foreground parallax + related anims // open the screen resource @@ -230,7 +220,7 @@ void Build_display(void) { screenLayerTable = (_multiScreenHeader *) ((uint8 *) file + sizeof(_standardHeader)); if (screenLayerTable->fg_parallax[1]) { - RenderParallax(FetchForegroundParallaxLayer(file, 1), 4); + g_display->renderParallax(FetchForegroundParallaxLayer(file, 1), 4); // release the screen resource before cacheing // the sprites res_man.close(this_screen.background_layer_id); @@ -240,29 +230,24 @@ void Build_display(void) { res_man.close(this_screen.background_layer_id); } - // --------------------------------------------------- // walkgrid, mouse & player markers & mouse area // rectangle Draw_debug_graphics(); - // --------------------------------------------------- // text blocks // speech blocks and headup debug text fontRenderer.printTextBlocs(); - // --------------------------------------------------- // menu bar & icons - ProcessMenu(); + g_display->processMenu(); - // --------------------------------------------------- // ready - blit to screen - ServiceWindows(); + g_display->updateDisplay(); - //---------------------------------------------------- // update our fps reading frameCount++; @@ -273,20 +258,16 @@ void Build_display(void) { cycleTime = SVM_timeGetTime() + 1000; } - // --------------------------------------------------- - // check if we've got time to render the screen again + // Check if we've got time to render the screen again // this cycle (so drivers can smooth out the scrolling // in between normal game cycles) - - EndRenderCycle(&end); - - // if we haven't got time to render again this cycle, + // + // If we haven't got time to render again this cycle, // drop out of 'render cycle' while-loop - if (end) - break; - // --------------------------------------------------- - } // END OF RENDER CYCLE + if (g_display->endRenderCycle()) + break; + } } #ifdef _SWORD2_DEBUG else if (console_status) { @@ -302,13 +283,13 @@ void Build_display(void) { spriteInfo.data = console_sprite->ad; spriteInfo.colourTable = 0; - rv = DrawSprite(&spriteInfo); + rv = g_display->drawSprite(&spriteInfo); if (rv) error("Driver Error %.8x (drawing console)", rv); } else{ StartConsole(); // force the palette - BS2_SetPalette(0, 3, pal, RDPAL_INSTANT); + g_display->setPalette(0, 3, pal, RDPAL_INSTANT); Print_to_console("no valid screen?"); } #endif @@ -329,24 +310,24 @@ void DisplayMsg(uint8 *text, int time) { warning("DisplayMsg: %s", (char *) text); - if (GetFadeStatus() != RDFADE_BLACK) { - FadeDown((float) 0.75); - WaitForFade(); + if (g_display->getFadeStatus() != RDFADE_BLACK) { + g_display->fadeDown(); + g_display->waitForFade(); } Set_mouse(0); Set_luggage(0); - CloseMenuImmediately(); - EraseBackBuffer(); + g_display->closeMenuImmediately(); + g_display->clearScene(); text_spr = fontRenderer.makeTextSprite(text, 640, 187, g_sword2->_speechFontId); frame = (_frameHeader *) text_spr->ad; - spriteInfo.x = screenWide / 2 - frame->width / 2; + spriteInfo.x = g_display->_screenWide / 2 - frame->width / 2; if (!time) - spriteInfo.y = screenDeep / 2 - frame->height / 2 - RDMENU_MENUDEEP; + spriteInfo.y = g_display->_screenDeep / 2 - frame->height / 2 - RDMENU_MENUDEEP; else spriteInfo.y = 400 - frame->height; spriteInfo.w = frame->width; @@ -359,33 +340,34 @@ void DisplayMsg(uint8 *text, int time) { spriteInfo.data = text_spr->ad + sizeof(_frameHeader); spriteInfo.colourTable = 0; - rv = DrawSprite(&spriteInfo); + rv = g_display->drawSprite(&spriteInfo); if (rv) error("Driver Error %.8x (in DisplayMsg)", rv); - memcpy((char *) oldPal, (char *) palCopy, 256 * sizeof(_palEntry)); + memcpy((char *) oldPal, (char *) g_display->_palCopy, 256 * sizeof(_palEntry)); memset(pal, 0, 256 * sizeof(_palEntry)); pal[187].red = 255; pal[187].green = 255; pal[187].blue = 255; - BS2_SetPalette(0, 256, (uint8 *) pal, RDPAL_FADE); + g_display->setPalette(0, 256, (uint8 *) pal, RDPAL_FADE); - FadeUp((float) 0.75); + g_display->fadeUp(); memory.freeMemory(text_spr); - WaitForFade(); + g_display->waitForFade(); uint32 targetTime = SVM_timeGetTime() + (time * 1000); - rv = DrawSprite(&spriteInfo); // Keep the message there even when the user task swaps. + // Keep the message there even when the user task swaps. + rv = g_display->drawSprite(&spriteInfo); if (rv) error("Driver Error %.8x (in DisplayMsg)", rv); sleepUntil(targetTime); - BS2_SetPalette(0, 256, (uint8 *) oldPal, RDPAL_FADE); + g_display->setPalette(0, 256, (uint8 *) oldPal, RDPAL_FADE); } // --------------------------------------------------------------------------- @@ -394,13 +376,13 @@ void DisplayMsg(uint8 *text, int time) { // void RemoveMsg(void) { - FadeDown((float) 0.75); + g_display->fadeDown(); - WaitForFade(); + g_display->waitForFade(); - EraseBackBuffer(); + g_display->clearScene(); - // FadeUp((float) 0.75); + // g_display->fadeUp(); // removed by JEL (08oct97) to prevent "eye" smacker corruption when // restarting game from CD2 and also to prevent palette flicker when // restoring game to a different CD since the "insert CD" message uses @@ -516,7 +498,7 @@ void Process_layer(uint32 layer_number) { #endif //------------------------------------------ - rv = DrawSprite(&spriteInfo); + rv = g_display->drawSprite(&spriteInfo); if (rv) error("Driver Error %.8x in Process_layer(%d)", rv, layer_number); @@ -559,7 +541,7 @@ void Process_image(buildit *build_unit) { // but the same compression can be decompressed using the // RLE256 routines! - // NOTE: If this restriction refers to DrawSprite(), I don't + // NOTE: If this restriction refers to drawSprite(), I don't // think we have it any more. But I'm not sure. if (build_unit->scale || anim_head->blend || build_unit->shadingFlag) @@ -649,7 +631,7 @@ void Process_image(buildit *build_unit) { // } // #endif - rv = DrawSprite(&spriteInfo); + rv = g_display->drawSprite(&spriteInfo); if (rv) error("Driver Error %.8x with sprite %s (%d) in Process_image", rv, FetchObjectName(build_unit->anim_resource), @@ -933,14 +915,14 @@ void Start_new_palette(void) { // if the screen is still fading down then wait for black - could // happen when everythings cached into a large memory model - WaitForFade(); + g_display->waitForFade(); // open the screen file screenFile = res_man.open(this_screen.background_layer_id); - UpdatePaletteMatchTable((uint8 *) FetchPaletteMatchTable(screenFile)); + g_display->updatePaletteMatchTable((uint8 *) FetchPaletteMatchTable(screenFile)); - BS2_SetPalette(0, 256, FetchPalette(screenFile), RDPAL_FADE); + g_display->setPalette(0, 256, FetchPalette(screenFile), RDPAL_FADE); // indicating that it's a screen palette lastPaletteRes = 0; @@ -949,8 +931,7 @@ void Start_new_palette(void) { res_man.close(this_screen.background_layer_id); // start fade up - // FadeUp((float) 1.75); - FadeUp((float) 0.75); + g_display->fadeUp(); // reset this_screen.new_palette = 0; @@ -980,17 +961,17 @@ int32 FN_fade_down(int32 *params) { // NONE means up! can only be called when screen is fully faded up - // multiple calls wont have strange effects - if (GetFadeStatus() == RDFADE_NONE) - FadeDown((float) 0.75); + if (g_display->getFadeStatus() == RDFADE_NONE) + g_display->fadeDown(); return IR_CONT; } int32 FN_fade_up(int32 *params) { - WaitForFade(); + g_display->waitForFade(); - if (GetFadeStatus() == RDFADE_BLACK) - FadeUp((float) 0.75); + if (g_display->getFadeStatus() == RDFADE_BLACK) + g_display->fadeUp(); return IR_CONT; } @@ -1076,9 +1057,9 @@ void SetFullPalette(int32 palRes) { file[3] = 0; // not yet in separate palette files - // UpdatePaletteMatchTable(file + (256 * 4)); + // g_display->updatePaletteMatchTable(file + (256 * 4)); - BS2_SetPalette(0, 256, file, RDPAL_INSTANT); + g_display->setPalette(0, 256, file, RDPAL_INSTANT); if (palRes != CONTROL_PANEL_PALETTE) { // (James 03sep97) // indicating that it's a separate palette resource @@ -1092,9 +1073,9 @@ void SetFullPalette(int32 palRes) { if (this_screen.background_layer_id) { // open the screen file file = res_man.open(this_screen.background_layer_id); - UpdatePaletteMatchTable((uint8 *) FetchPaletteMatchTable(file)); + g_display->updatePaletteMatchTable((uint8 *) FetchPaletteMatchTable(file)); - BS2_SetPalette(0, 256, FetchPalette(file), RDPAL_INSTANT); + g_display->setPalette(0, 256, FetchPalette(file), RDPAL_INSTANT); // indicating that it's a screen palette lastPaletteRes = 0; @@ -1115,7 +1096,7 @@ int32 FN_change_shadows(int32 *params) { // if last screen was using a shading mask (see below) if (this_screen.mask_flag) { - rv = CloseLightMask(); + rv = g_display->closeLightMask(); if (rv) error("Driver Error %.8x [%s line %u]", rv); diff --git a/sword2/console.cpp b/sword2/console.cpp index bd43cf6662..e69fa7a772 100644 --- a/sword2/console.cpp +++ b/sword2/console.cpp @@ -164,7 +164,7 @@ void Init_console(void) { con_width = screenWide; //max across // Force a palatte for the console. - BS2_SetPalette(CON_PEN, 1, white, RDPAL_INSTANT); + g_display->setPalette(CON_PEN, 1, white, RDPAL_INSTANT); console_sprite = memory.alloc(con_width * (CON_lines * con_chr_height), MEM_float, UID_con_sprite); @@ -213,7 +213,7 @@ uint32 Tconsole(uint32 mode) { StartConsole(); while (1) { - ServiceWindows(); + g_display->updateDisplay(); if (breakOut) break; @@ -460,7 +460,7 @@ uint32 Parse_user_input(void) { case 18: // S (same as START) Con_start(&input[1][0]); // force the palette - BS2_SetPalette(187, 1, pal, RDPAL_INSTANT); + g_display->setPalette(187, 1, pal, RDPAL_INSTANT); return 0; case 9: // INFO displayDebugText = 1 - displayDebugText; @@ -729,7 +729,7 @@ void Con_help(void) { Build_display(); do { - ServiceWindows(); + g_display->updateDisplay(); } while (!KeyWaiting()); ReadKey(&c); @@ -803,8 +803,8 @@ void Con_fatal_error(const char *format, ...) { char buf[150]; uint8 white[4] = { 255, 255, 255, 0 }; - // set text colour in case screen is faded down! (James 05mar97) - BS2_SetPalette(CON_PEN, 1, white, RDPAL_INSTANT); + // set text colour in case screen is faded down! + g_display->setPalette(CON_PEN, 1, white, RDPAL_INSTANT); va_start(arg_ptr,format); _vsnprintf(buf, 150, format, arg_ptr); @@ -912,7 +912,7 @@ void Con_list_savegames(void) { Build_display(); do { - ServiceWindows(); + g_display->updateDisplay(); } while (!KeyWaiting()); ReadKey(&c); diff --git a/sword2/controls.cpp b/sword2/controls.cpp index 80e1226645..78de6dbf3b 100644 --- a/sword2/controls.cpp +++ b/sword2/controls.cpp @@ -74,7 +74,7 @@ public: sprite.data = (uint8 *) (head + 1); sprite.w = head->width; sprite.h = head->height; - CreateSurface(&sprite, &_glyph[i]._data); + g_display->createSurface(&sprite, &_glyph[i]._data); _glyph[i]._width = head->width; _glyph[i]._height = head->height; } @@ -84,7 +84,7 @@ public: ~FontRendererGui() { for (int i = 0; i < SIZE_OF_CHAR_SET; i++) - DeleteSurface(_glyph[i]._data); + g_display->deleteSurface(_glyph[i]._data); } void fetchText(int textId, char *buf) { @@ -143,7 +143,7 @@ void FontRendererGui::drawText(char *text, int x, int y, int alignment) { sprite.w = _glyph[text[i] - 32]._width; sprite.h = _glyph[text[i] - 32]._height; - DrawSurface(&sprite, _glyph[text[i] - 32]._data); + g_display->drawSurface(&sprite, _glyph[text[i] - 32]._data); sprite.x += (_glyph[(int) text[i] - 32]._width - CHARACTER_OVERLAP); } @@ -186,7 +186,7 @@ public: virtual ~Widget() { for (int i = 0; i < _numStates; i++) { if (_surfaces[i]._original) - DeleteSurface(_surfaces[i]._surface); + g_display->deleteSurface(_surfaces[i]._surface); } free(_sprites); free(_surfaces); @@ -228,7 +228,7 @@ public: } virtual void paint(Common::Rect *clipRect = NULL) { - DrawSurface(&_sprites[_state], _surfaces[_state]._surface, clipRect); + g_display->drawSurface(&_sprites[_state], _surfaces[_state]._surface, clipRect); } virtual void onMouseEnter() {} @@ -291,7 +291,7 @@ void Widget::createSurfaceImage(int state, uint32 res, int x, int y, uint32 pc) // Points to just after frame header, ie. start of sprite data _sprites[state].data = (uint8 *) (frame_head + 1); - CreateSurface(&_sprites[state], &_surfaces[state]._surface); + g_display->createSurface(&_sprites[state], &_surfaces[state]._surface); _surfaces[state]._original = true; // Release the anim resource @@ -339,7 +339,7 @@ public: virtual void onAction(Widget *widget, int result = 0) {} virtual void paint() { - EraseBackBuffer(); + g_display->clearScene(); for (int i = 0; i < _numWidgets; i++) _widgets[i]->paint(); } @@ -362,12 +362,11 @@ int Dialog::run() { while (!_finish) { // So that the menu icons will reach their full size - ProcessMenu(); + g_display->processMenu(); + g_display->updateDisplay(); - ServiceWindows(); - - int16 newMouseX = mousex; - int16 newMouseY = mousey + 40; + int16 newMouseX = g_display->_mouseX; + int16 newMouseY = g_display->_mouseY + 40; _mouseEvent *me = MouseEvent(); _keyboardEvent ke; @@ -388,7 +387,7 @@ int Dialog::run() { _widgets[i]->onMouseEnter(); if (oldHit && !newHit) _widgets[i]->onMouseExit(); - if (mousex != oldMouseX || mousey != oldMouseY) + if (g_display->_mouseX != oldMouseX || g_display->_mouseY != oldMouseY) _widgets[i]->onMouseMove(newMouseX, newMouseY); if (me) { @@ -788,8 +787,8 @@ public: _musicSlider->setValue(g_sound->getMusicVolume()); _speechSlider->setValue(g_sound->getSpeechVolume()); _fxSlider->setValue(g_sound->getFxVolume()); - _gfxSlider->setValue(GetRenderType()); - _gfxPreview->setState(GetRenderType()); + _gfxSlider->setValue(g_display->getRenderLevel()); + _gfxPreview->setState(g_display->getRenderLevel()); } ~OptionsDialog() { @@ -901,7 +900,7 @@ int32 OptionsDialog::writeOptionSettings(void) { buff[3] = g_sound->isMusicMute(); buff[4] = g_sound->isSpeechMute(); buff[5] = g_sound->isFxMute(); - buff[6] = GetRenderType(); + buff[6] = g_display->getRenderLevel(); buff[7] = gui._subtitles; buff[8] = gui._pointerTextSelected; buff[9] = gui._stereoReversed; @@ -1352,7 +1351,7 @@ void SaveLoadDialog::saveLoadError(char* text) { while (1) { _mouseEvent *me; - ServiceWindows(); + g_display->updateDisplay(); if (KeyWaiting()) { _keyboardEvent ke; @@ -1396,7 +1395,6 @@ void Gui::quitControl(void) { // close engine systems down Close_game(); - CloseAppWindow(); exit(0); } @@ -1410,13 +1408,13 @@ void Gui::restartControl(void) { return; } - // Stop music instantly! (James 22aug97) + // Stop music instantly! Kill_music(); //in case we were dead - well we're not anymore! DEAD = 0; - EraseBackBuffer(); + g_display->clearScene(); // restart the game // clear all memory and reset the globals @@ -1450,9 +1448,9 @@ void Gui::restartControl(void) { // FN_register_frame) Reset_mouse_list(); - CloseMenuImmediately(); + g_display->closeMenuImmediately(); - // FOR THE DEMO - FORCE THE SCROLLING TO BE RESET! (James29may97) + // FOR THE DEMO - FORCE THE SCROLLING TO BE RESET! // - this is taken from FN_init_background // switch on scrolling (2 means first time on screen) @@ -1525,33 +1523,7 @@ void Gui::optionControl(void) { } void Gui::updateGraphicsLevel(uint8 newLevel) { - switch (newLevel) { - case 0: - // Lowest setting: no graphics fx - ClearTransFx(); - ClearShadowFx(); - ClearBltFx(); - break; - case 1: - // Medium-low setting: transparency-blending - SetTransFx(); - ClearShadowFx(); - ClearBltFx(); - break; - case 2: - // Medium-high setting: transparency-blending + shading - SetTransFx(); - SetShadowFx(); - ClearBltFx(); - break; - case 3: - // Highest setting: transparency-blending + shading + - // edge-blending + improved stretching - SetTransFx(); - SetShadowFx(); - SetBltFx(); - break; - } + g_display->setRenderLevel(newLevel); // update our global variable - which needs to be checked when dimming // the palette in PauseGame() in sword2.cpp (since palette-matching 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 @@ -276,29 +267,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 //----------------------------------------------------------------------------- extern int32 GetLanguageVersion(uint8 *version); @@ -306,27 +274,10 @@ 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); //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -337,42 +288,6 @@ 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 //----------------------------------------------------------------------------- extern uint32 SVM_timeGetTime(void); @@ -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; } diff --git a/sword2/function.cpp b/sword2/function.cpp index b3040eff75..4a250892b4 100644 --- a/sword2/function.cpp +++ b/sword2/function.cpp @@ -31,7 +31,7 @@ #include "bs2/protocol.h" #include "bs2/resman.h" #include "bs2/sound.h" -#include "bs2/sword2.h" // for CloseGame() +#include "bs2/sword2.h" namespace Sword2 { @@ -269,25 +269,25 @@ int32 FN_flash(int32 *params) { // what colour? switch (params[0]) { case WHITE: - BS2_SetPalette(0, 1, white, RDPAL_INSTANT); + g_display->setPalette(0, 1, white, RDPAL_INSTANT); break; case RED: - BS2_SetPalette(0, 1, red, RDPAL_INSTANT); + g_display->setPalette(0, 1, red, RDPAL_INSTANT); break; case GREEN: - BS2_SetPalette(0, 1, green, RDPAL_INSTANT); + g_display->setPalette(0, 1, green, RDPAL_INSTANT); break; case BLUE: - BS2_SetPalette(0, 1, blue, RDPAL_INSTANT); + g_display->setPalette(0, 1, blue, RDPAL_INSTANT); break; } // There used to be a busy-wait loop here, so I don't know how long // the delay was meant to be. Probably doesn't matter much. - ServiceWindows(); + g_display->updateDisplay(); g_system->delay_msecs(250); - BS2_SetPalette(0, 1, black, RDPAL_INSTANT); + g_display->setPalette(0, 1, black, RDPAL_INSTANT); #endif return IR_CONT; @@ -305,19 +305,19 @@ int32 FN_colour(int32 *params) { // what colour? switch (params[0]) { case BLACK: - BS2_SetPalette(0, 1, black, RDPAL_INSTANT); + g_display->setPalette(0, 1, black, RDPAL_INSTANT); break; case WHITE: - BS2_SetPalette(0, 1, white, RDPAL_INSTANT); + g_display->setPalette(0, 1, white, RDPAL_INSTANT); break; case RED: - BS2_SetPalette(0, 1, red, RDPAL_INSTANT); + g_display->setPalette(0, 1, red, RDPAL_INSTANT); break; case GREEN: - BS2_SetPalette(0, 1, green, RDPAL_INSTANT); + g_display->setPalette(0, 1, green, RDPAL_INSTANT); break; case BLUE: - BS2_SetPalette(0, 1, blue, RDPAL_INSTANT); + g_display->setPalette(0, 1, blue, RDPAL_INSTANT); break; } #endif @@ -396,17 +396,17 @@ int32 FN_play_credits(int32 *params) { g_sound->muteSpeech(1); g_sound->stopMusic(); - memcpy(oldPal, palCopy, 1024); + memcpy(oldPal, g_display->_palCopy, 1024); memset(tmpPal, 0, 1024); - WaitForFade(); - FadeDown(0.75); - WaitForFade(); + g_display->waitForFade(); + g_display->fadeDown(); + g_display->waitForFade(); tmpPal[4] = 255; tmpPal[5] = 255; tmpPal[6] = 255; - BS2_SetPalette(0, 256, tmpPal, RDPAL_INSTANT); + g_display->setPalette(0, 256, tmpPal, RDPAL_INSTANT); // Play the credits music. Is it enough with just one // repetition of it? @@ -419,17 +419,17 @@ int32 FN_play_credits(int32 *params) { debug(0, "Credits music length: ~%d ms", music_length); - CloseMenuImmediately(); + g_display->closeMenuImmediately(); while (g_sound->musicTimeRemaining()) { - EraseBackBuffer(); - SetNeedRedraw(); + g_display->clearScene(); + g_display->setNeedFullRedraw(); // FIXME: Draw the credits text. The actual text // messages are stored in credits.clu, and I'm guessing // that credits.bmp or font.clu may be the font. - ServiceWindows(); + g_display->updateDisplay(); _keyboardEvent ke; @@ -442,11 +442,11 @@ int32 FN_play_credits(int32 *params) { FN_stop_music(NULL); g_sound->restoreMusicState(); - BS2_SetPalette(0, 256, oldPal, RDPAL_FADE); - FadeUp(0.75); - ServiceWindows(); + g_display->setPalette(0, 256, oldPal, RDPAL_FADE); + g_display->fadeUp(); + g_display->updateDisplay(); Build_display(); - WaitForFade(); + g_display->waitForFade(); g_sound->muteFx(0); g_sound->muteSpeech(0); @@ -457,7 +457,6 @@ int32 FN_play_credits(int32 *params) { if (g_sword2->_gameId == GID_SWORD2_DEMO) { Close_game(); // close engine systems down - CloseAppWindow(); exit(0); // quit the game } diff --git a/sword2/icons.cpp b/sword2/icons.cpp index f0b8a23e10..8de09452a1 100644 --- a/sword2/icons.cpp +++ b/sword2/icons.cpp @@ -18,6 +18,7 @@ */ #include "stdafx.h" +#include "bs2/sword2.h" #include "bs2/driver/driver96.h" #include "bs2/defs.h" #include "bs2/icons.h" @@ -207,23 +208,22 @@ void Build_menu(void) { if (icon_coloured) icon += (RDMENU_ICONWIDE * RDMENU_ICONDEEP); - SetMenuIcon(RDMENU_BOTTOM, j, icon); + g_display->setMenuIcon(RDMENU_BOTTOM, j, icon); res_man.close(res); } else { // no icon here - SetMenuIcon(RDMENU_BOTTOM, j, NULL); + g_display->setMenuIcon(RDMENU_BOTTOM, j, NULL); debug(5, " NULL for %d", j); } } - ShowMenu(RDMENU_BOTTOM); + g_display->showMenu(RDMENU_BOTTOM); } void Build_system_menu(void) { // start a fresh top system menu uint8 *icon; - int j; uint32 icon_list[5] = { OPTIONS_ICON, @@ -236,7 +236,7 @@ void Build_system_menu(void) { // build them all high in full colour - when one is clicked on all the // rest will grey out - for (j = 0; j < ARRAYSIZE(icon_list); j++) { + for (int j = 0; j < ARRAYSIZE(icon_list); j++) { icon = res_man.open(icon_list[j]) + sizeof(_standardHeader); // The only case when an icon is grayed is when the player @@ -245,11 +245,11 @@ void Build_system_menu(void) { if (!DEAD || icon_list[j] != SAVE_ICON) icon += (RDMENU_ICONWIDE * RDMENU_ICONDEEP); - SetMenuIcon(RDMENU_TOP, j, icon); + g_display->setMenuIcon(RDMENU_TOP, j, icon); res_man.close(icon_list[j]); } - ShowMenu(RDMENU_TOP); + g_display->showMenu(RDMENU_TOP); } } // End of namespace Sword2 diff --git a/sword2/layers.cpp b/sword2/layers.cpp index 9ce4b1dfa1..24e71a666e 100644 --- a/sword2/layers.cpp +++ b/sword2/layers.cpp @@ -26,6 +26,7 @@ // up to 2 foreground parallax layers #include "stdafx.h" +#include "bs2/sword2.h" #include "bs2/build_display.h" #include "bs2/debug.h" #include "bs2/header.h" @@ -67,11 +68,11 @@ int32 FN_init_background(int32 *params) { #endif // if the screen is still fading down then wait for black - WaitForFade(); + g_display->waitForFade(); // if last screen was using a shading mask (see below) if (this_screen.mask_flag) { - rv = CloseLightMask(); + rv = g_display->closeLightMask(); if (rv) error("Driver Error %.8x", rv); } @@ -80,7 +81,7 @@ int32 FN_init_background(int32 *params) { // for drivers: close the previous screen if one is open if (this_screen.background_layer_id) - CloseBackgroundLayer(); + g_display->closeBackgroundLayer(); this_screen.background_layer_id = params[0]; // set the res id this_screen.new_palette = params[1]; // yes or no - palette is taken from layer file @@ -102,7 +103,7 @@ int32 FN_init_background(int32 *params) { debug(5, "res test layers=%d width=%d depth=%d", screen_head->noLayers, screen_head->width, screen_head->height); //initialise the driver back buffer - SetLocationMetrics(screen_head->width, screen_head->height); + g_display->setLocationMetrics(screen_head->width, screen_head->height); if (screen_head->noLayers) { for (int i = 0; i < screen_head->noLayers; i++) { @@ -124,7 +125,7 @@ int32 FN_init_background(int32 *params) { // using the screen size setup the scrolling variables // if layer is larger than physical screen - if (screen_head->width > screenWide || screen_head->height > screenDeep) { + if (screen_head->width > g_display->_screenWide || screen_head->height > g_display->_screenDeep) { // switch on scrolling (2 means first time on screen) this_screen.scroll_flag = 2; @@ -139,9 +140,9 @@ int32 FN_init_background(int32 *params) { // calc max allowed offsets (to prevent scrolling off edge) - // MOVE TO NEW_SCREEN in GTM_CORE.C !! // NB. min scroll offsets are both zero - this_screen.max_scroll_offset_x = screen_head->width-screenWide; + this_screen.max_scroll_offset_x = screen_head->width - g_display->_screenWide; // 'screenDeep' includes the menu's, so take away 80 pixels - this_screen.max_scroll_offset_y = screen_head->height - (screenDeep - (RDMENU_MENUDEEP * 2)); + this_screen.max_scroll_offset_y = screen_head->height - (g_display->_screenDeep - (RDMENU_MENUDEEP * 2)); } else { // layer fits on physical screen - scrolling not required this_screen.scroll_flag = 0; // switch off scrolling @@ -151,7 +152,7 @@ int32 FN_init_background(int32 *params) { // no inter-cycle scroll between new screens (see setScrollTarget in // build display) - ResetRenderEngine(); + g_display->resetRenderEngine(); // these are the physical screen coords where the system // will try to maintain George's actual feet coords @@ -175,7 +176,7 @@ int32 FN_init_background(int32 *params) { spriteInfo.data = FetchShadingMask(file); spriteInfo.colourTable = 0; - rv = OpenLightMask(&spriteInfo); + rv = g_display->openLightMask(&spriteInfo); if (rv) error("Driver Error %.8x", rv); @@ -219,22 +220,22 @@ void SetUpBackgroundLayers(void) { for (i = 0; i < 2; i++) { if (screenLayerTable->bg_parallax[i]) - InitialiseBackgroundLayer(FetchBackgroundParallaxLayer(file, i)); + g_display->initialiseBackgroundLayer(FetchBackgroundParallaxLayer(file, i)); else - InitialiseBackgroundLayer(NULL); + g_display->initialiseBackgroundLayer(NULL); } // Normal backround layer - InitialiseBackgroundLayer(FetchBackgroundLayer(file)); + g_display->initialiseBackgroundLayer(FetchBackgroundLayer(file)); // Foreground parallax layers for (i = 0; i < 2; i++) { if (screenLayerTable->fg_parallax[i]) - InitialiseBackgroundLayer(FetchForegroundParallaxLayer(file, i)); + g_display->initialiseBackgroundLayer(FetchForegroundParallaxLayer(file, i)); else - InitialiseBackgroundLayer(NULL); + g_display->initialiseBackgroundLayer(NULL); } // close the screen file diff --git a/sword2/logic.cpp b/sword2/logic.cpp index 4dc4123f77..d173767a37 100644 --- a/sword2/logic.cpp +++ b/sword2/logic.cpp @@ -18,6 +18,7 @@ */ #include "stdafx.h" +#include "bs2/sword2.h" #include "bs2/build_display.h" #include "bs2/console.h" #include "bs2/debug.h" @@ -347,8 +348,8 @@ uint32 logic::examineRunList(void) { Build_display(); do { - ServiceWindows(); - } while(!KeyWaiting()); + g_display->updateDisplay(); + } while (!KeyWaiting()); // kill the key we just pressed ReadKey(&ke); diff --git a/sword2/maketext.cpp b/sword2/maketext.cpp index 92ed4147b5..669429415f 100644 --- a/sword2/maketext.cpp +++ b/sword2/maketext.cpp @@ -525,7 +525,7 @@ void FontRenderer::printTextBlocs(void) { spriteInfo.data = _blocList[j].text_mem->ad + sizeof(_frameHeader); spriteInfo.colourTable = 0; - rv = DrawSprite(&spriteInfo); + rv = g_display->drawSprite(&spriteInfo); if (rv) error("Driver Error %.8x in Print_text_blocs", rv); } @@ -603,7 +603,7 @@ void Sword2Engine::initialiseFontResourceFlags(void) { // GERMAN: "Baphomet's Fluch II" // default: "Some game or other, part 86" - SetWindowName((char *) textLine); + g_display->setWindowName((char *) textLine); // now ok to close the text file res_man.close(TEXT_RES); diff --git a/sword2/mem_view.cpp b/sword2/mem_view.cpp index ae2c5142ac..cd4fec02ad 100644 --- a/sword2/mem_view.cpp +++ b/sword2/mem_view.cpp @@ -18,6 +18,7 @@ */ #include "stdafx.h" +#include "bs2/sword2.h" #include "bs2/build_display.h" #include "bs2/console.h" #include "bs2/header.h" @@ -102,8 +103,8 @@ void MemoryManager::displayMemory(void) { Build_display(); do { - ServiceWindows(); - } while(!KeyWaiting()); + g_display->updateDisplay(); + } while (!KeyWaiting()); ReadKey(&ke); //kill the key we just pressed if (ke.keycode == 27) //ESC diff --git a/sword2/mouse.cpp b/sword2/mouse.cpp index c429baf6c4..86e3b1184a 100644 --- a/sword2/mouse.cpp +++ b/sword2/mouse.cpp @@ -157,7 +157,7 @@ void Mouse_engine(void) { System_menu_mouse(); break; case MOUSE_holding: - if (mousey < 400) { + if (g_display->_mouseY < 400) { mouse_mode = MOUSE_normal; debug(5, " releasing"); } @@ -182,10 +182,10 @@ void System_menu_mouse(void) { }; // can't close when player is dead - if (mousey > 0 && !DEAD) { + if (g_display->_mouseY > 0 && !DEAD) { // close menu mouse_mode = MOUSE_normal; - HideMenu(RDMENU_TOP); + g_display->hideMenu(RDMENU_TOP); return; } @@ -194,9 +194,9 @@ void System_menu_mouse(void) { if (me && (me->buttons & RD_LEFTBUTTONDOWN)) { // clicked on a top mouse pointer? - if (mousex >= 24 && mousex < 640 - 24 && mousey < 0) { + if (g_display->_mouseX >= 24 && g_display->_mouseX < 640 - 24 && g_display->_mouseY < 0) { // which are we over? - hit = (mousex - 24) / 40; + hit = (g_display->_mouseX - 24) / 40; // no save when dead if (icon_list[hit] == SAVE_ICON && DEAD) @@ -210,7 +210,7 @@ void System_menu_mouse(void) { // change all others to grey if (j != hit) { icon = res_man.open(icon_list[j]) + sizeof(_standardHeader); - SetMenuIcon(RDMENU_TOP, j, icon); + g_display->setMenuIcon(RDMENU_TOP, j, icon); res_man.close( icon_list[j] ); } } @@ -235,9 +235,9 @@ void System_menu_mouse(void) { // clear the screen & set up the new palette // for the menus - EraseBackBuffer(); - ProcessMenu(); - ResetRenderEngine(); + g_display->clearScene(); + g_display->processMenu(); + g_display->resetRenderEngine(); // call the relevent screen switch (hit) { @@ -261,7 +261,7 @@ void System_menu_mouse(void) { // Menu stays open on death screen if (!DEAD) { mouse_mode = MOUSE_normal; - HideMenu(RDMENU_TOP); + g_display->hideMenu(RDMENU_TOP); } else { Set_mouse(NORMAL_MOUSE_ID); Build_system_menu(); @@ -270,8 +270,8 @@ void System_menu_mouse(void) { // clear the screen & restore the location // palette - EraseBackBuffer(); - ProcessMenu(); + g_display->clearScene(); + g_display->processMenu(); // reset game palette, but not after a // successful restore or restart! @@ -319,10 +319,10 @@ void Drag_mouse(void) { _mouseEvent *me; uint32 pos; - if (mousey < 400 && !menu_status) { + if (g_display->_mouseY < 400 && !menu_status) { // close menu mouse_mode = MOUSE_normal; - HideMenu(RDMENU_BOTTOM); + g_display->hideMenu(RDMENU_BOTTOM); return; } @@ -358,8 +358,8 @@ void Drag_mouse(void) { // these might be required by the action script about // to be run - MOUSE_X = (uint32) mousex + this_screen.scroll_offset_x; - MOUSE_Y = (uint32) mousey + this_screen.scroll_offset_y; + MOUSE_X = (uint32) g_display->_mouseX + this_screen.scroll_offset_x; + MOUSE_Y = (uint32) g_display->_mouseY + this_screen.scroll_offset_y; // for scripts to know what's been clicked (21jan97). // First used for 'room_13_turning_script' in object @@ -373,14 +373,14 @@ void Drag_mouse(void) { // Hide menu - back to normal menu mode - HideMenu(RDMENU_BOTTOM); + g_display->hideMenu(RDMENU_BOTTOM); mouse_mode = MOUSE_normal; } else { // better check for combine/cancel // cancel puts us back in Menu_mouse mode - if (mousex >= 24 && mousex < 640 - 24) { + if (g_display->_mouseX >= 24 && g_display->_mouseX < 640 - 24) { // which are we over? - pos = (mousex - 24) / 40; + pos = (g_display->_mouseX - 24) / 40; //clicked on something - what button? if (master_menu_list[pos].icon_resource) { @@ -432,10 +432,10 @@ void Menu_mouse(void) { _mouseEvent *me; uint32 pos; - if (mousey < 400 && !menu_status) { + if (g_display->_mouseY < 400 && !menu_status) { // close menu mouse_mode = MOUSE_normal; - HideMenu(RDMENU_BOTTOM); + g_display->hideMenu(RDMENU_BOTTOM); return; } @@ -448,9 +448,9 @@ void Menu_mouse(void) { // there's a mouse event to be processed // now check if we've clicked on an actual icon - if (mousex >= 24 && mousex < 640 - 24) { + if (g_display->_mouseX >= 24 && g_display->_mouseX < 640 - 24) { // which are we over? - pos = (mousex - 24) / 40; + pos = (g_display->_mouseX - 24) / 40; // clicked on something - what button? if (master_menu_list[pos].icon_resource) { @@ -518,7 +518,7 @@ void Normal_mouse(void) { _mouseEvent *me; // no save in big-object menu lock situation - if (mousey < 0 && !menu_status && !mouse_mode_locked && !OBJECT_HELD) { + if (g_display->_mouseY < 0 && !menu_status && !mouse_mode_locked && !OBJECT_HELD) { mouse_mode = MOUSE_system_menu; if (mouse_touching) { @@ -533,7 +533,7 @@ void Normal_mouse(void) { return; } - if (mousey > 399 && !menu_status && !mouse_mode_locked) { + if (g_display->_mouseY > 399 && !menu_status && !mouse_mode_locked) { // If an object is being held, i.e. if the mouse cursor has a // luggage, we should be use dragging mode instead of inventory // menu mode. @@ -578,8 +578,8 @@ void Normal_mouse(void) { if (me && (me->buttons & (RD_LEFTBUTTONDOWN | RD_RIGHTBUTTONDOWN))) { // set both (x1,y1) and (x2,y2) to this point - rect_x1 = rect_x2 = (uint32) mousex + this_screen.scroll_offset_x; - rect_y1 = rect_y2 = (uint32) mousey + this_screen.scroll_offset_y; + rect_x1 = rect_x2 = (uint32) g_display->_mouseX + this_screen.scroll_offset_x; + rect_y1 = rect_y2 = (uint32) g_display->_mouseY + this_screen.scroll_offset_y; draggingRectangle = 1; } } else if (draggingRectangle == 1) { @@ -591,8 +591,8 @@ void Normal_mouse(void) { draggingRectangle = 2; } else { // drag rectangle - rect_x2 = (uint32) mousex + this_screen.scroll_offset_x; - rect_y2 = (uint32) mousey + this_screen.scroll_offset_y; + rect_x2 = (uint32) g_display->_mouseX + this_screen.scroll_offset_x; + rect_y2 = (uint32) g_display->_mouseY + this_screen.scroll_offset_y; } } else { // currently locked to avoid knocking out of place @@ -642,8 +642,8 @@ void Normal_mouse(void) { } // these might be required by the action script about to be run - MOUSE_X = (uint32) mousex + this_screen.scroll_offset_x; - MOUSE_Y = (uint32) mousey + this_screen.scroll_offset_y; + MOUSE_X = (uint32) g_display->_mouseX + this_screen.scroll_offset_x; + MOUSE_Y = (uint32) g_display->_mouseY + this_screen.scroll_offset_y; // only left button if (mouse_touching == EXIT_CLICK_ID && (me->buttons & RD_LEFTBUTTONDOWN)) { @@ -701,7 +701,7 @@ void Mouse_on_off(void) { // don't detect objects that are hidden behind the menu bars (ie. in // the scrolled-off areas of the screen) - if (mousey < 0 || mousey > 399) { + if (g_display->_mouseY < 0 || g_display->_mouseY > 399) { pointer_type = 0; mouse_touching = 0; } else { @@ -799,14 +799,14 @@ void Set_mouse(uint32 res) { // loop if (res == NORMAL_MOUSE_ID) - SetMouseAnim(icon, len, RDMOUSE_NOFLASH); + g_display->setMouseAnim(icon, len, RDMOUSE_NOFLASH); else - SetMouseAnim(icon, len, RDMOUSE_FLASH); + g_display->setMouseAnim(icon, len, RDMOUSE_FLASH); res_man.close(res); } else { // blank cursor - SetMouseAnim(NULL, 0, 0); + g_display->setMouseAnim(NULL, 0, 0); } } @@ -820,11 +820,11 @@ void Set_luggage(uint32 res) { icon = res_man.open(res) + sizeof(_standardHeader); len = res_man._resList[res]->size - sizeof(_standardHeader); - SetLuggageAnim(icon, len); + g_display->setLuggageAnim(icon, len); res_man.close(res); } else - SetLuggageAnim(NULL, 0); + g_display->setLuggageAnim(NULL, 0); } uint32 Check_mouse_list(void) { @@ -838,10 +838,10 @@ uint32 Check_mouse_list(void) { // mouse-detection-box if (mouse_list[j].priority == priority && - mousex + this_screen.scroll_offset_x >= mouse_list[j].x1 && - mousex + this_screen.scroll_offset_x <= mouse_list[j].x2 && - mousey + this_screen.scroll_offset_y >= mouse_list[j].y1 && - mousey + this_screen.scroll_offset_y <= mouse_list[j].y2) { + g_display->_mouseX + this_screen.scroll_offset_x >= mouse_list[j].x1 && + g_display->_mouseX + this_screen.scroll_offset_x <= mouse_list[j].x2 && + g_display->_mouseY + this_screen.scroll_offset_y >= mouse_list[j].y1 && + g_display->_mouseY + this_screen.scroll_offset_y <= mouse_list[j].y2) { // record id mouse_touching = mouse_list[j].id; @@ -1017,7 +1017,8 @@ void CreatePointerText(uint32 textId, uint32 pointerRes) { // line reference number pointer_text_bloc_no = fontRenderer.buildNewBloc( - text + 2, mousex + xOffset, mousey + yOffset, + text + 2, g_display->_mouseX + xOffset, + g_display->_mouseY + yOffset, POINTER_TEXT_WIDTH, POINTER_TEXT_PEN, RDSPR_TRANS | RDSPR_DISPLAYALIGN, g_sword2->_speechFontId, justification); @@ -1054,12 +1055,12 @@ int32 FN_no_human(int32 *params) { // dont hide menu in conversations if (TALK_FLAG == 0) - HideMenu(RDMENU_BOTTOM); + g_display->hideMenu(RDMENU_BOTTOM); if (mouse_mode == MOUSE_system_menu) { // close menu mouse_mode = MOUSE_normal; - HideMenu(RDMENU_TOP); + g_display->hideMenu(RDMENU_TOP); } // script continue @@ -1117,7 +1118,7 @@ int32 FN_add_human(int32 *params) { } // if mouse is over menu area - if (mousey > 399) { + if (g_display->_mouseY > 399) { if (mouse_mode != MOUSE_holding) { // VITAL - reset things & rebuild the menu mouse_mode = MOUSE_normal; @@ -1292,7 +1293,7 @@ int32 FN_set_scroll_right_mouse(int32 *params) { // Highest priority - ob_mouse->x1 = this_screen.scroll_offset_x + screenWide - SCROLL_MOUSE_WIDTH; + ob_mouse->x1 = this_screen.scroll_offset_x + g_display->_screenWide - SCROLL_MOUSE_WIDTH; ob_mouse->y1 = 0; ob_mouse->x2 = this_screen.screen_wide - 1; ob_mouse->y2 = this_screen.screen_deep - 1; @@ -1327,7 +1328,7 @@ int32 FN_set_object_held(int32 *params) { // appropriate to keep it displayed int32 FN_remove_chooser(int32 *params) { - HideMenu(RDMENU_BOTTOM); + g_display->hideMenu(RDMENU_BOTTOM); return IR_CONT; } @@ -1336,8 +1337,8 @@ int32 FN_disable_menu(int32 *params) { mouse_mode_locked = 1; mouse_mode = MOUSE_normal; - HideMenu(RDMENU_TOP); - HideMenu(RDMENU_BOTTOM); + g_display->hideMenu(RDMENU_TOP); + g_display->hideMenu(RDMENU_BOTTOM); return IR_CONT; } diff --git a/sword2/resman.cpp b/sword2/resman.cpp index b6db4f0361..cf910676b2 100644 --- a/sword2/resman.cpp +++ b/sword2/resman.cpp @@ -18,6 +18,7 @@ */ #include "stdafx.h" +#include "bs2/sword2.h" #include "bs2/driver/driver96.h" #include "bs2/build_display.h" #include "bs2/console.h" @@ -32,7 +33,6 @@ #include "bs2/protocol.h" #include "bs2/resman.h" #include "bs2/sound.h" // for Clear_fx_queue() called from cacheNewCluster() -#include "bs2/sword2.h" // for CloseGame() #include "bs2/router.h" namespace Sword2 { @@ -961,8 +961,8 @@ void ResourceManager::killAll(uint8 wantInfo) { Build_display(); do { - ServiceWindows(); - } while(!KeyWaiting()); + g_display->updateDisplay(); + } while (!KeyWaiting()); ReadKey(&ke); if (ke.keycode == 27) @@ -1033,8 +1033,8 @@ void ResourceManager::killAllObjects(uint8 wantInfo) { Build_display(); do { - ServiceWindows(); - } while(!KeyWaiting()); + g_display->updateDisplay(); + } while (!KeyWaiting()); ReadKey(&ke); //kill the key we just pressed @@ -1106,28 +1106,28 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) { char buf[1024]; sprintf(buf, "%sClusters\\%s", _cdPath, _resourceFiles[newCluster]); - WaitForFade(); + g_display->waitForFade(); - if (GetFadeStatus() != RDFADE_BLACK) { - FadeDown((float) 0.75); - WaitForFade(); + if (g_display->getFadeStatus() != RDFADE_BLACK) { + g_display->fadeDown(); + g_display->waitForFade(); } - EraseBackBuffer(); + g_display->clearScene(); Set_mouse(0); - Set_luggage(0); //tw28Aug + Set_luggage(0); uint8 *bgfile; bgfile = res_man.open(2950); // open the screen resource - InitialiseBackgroundLayer(NULL); - InitialiseBackgroundLayer(NULL); - InitialiseBackgroundLayer(FetchBackgroundLayer(bgfile)); - InitialiseBackgroundLayer(NULL); - InitialiseBackgroundLayer(NULL); - BS2_SetPalette(0, 256, FetchPalette(bgfile), RDPAL_FADE); - - RenderParallax(FetchBackgroundLayer(bgfile), 2); + g_display->initialiseBackgroundLayer(NULL); + g_display->initialiseBackgroundLayer(NULL); + g_display->initialiseBackgroundLayer(FetchBackgroundLayer(bgfile)); + g_display->initialiseBackgroundLayer(NULL); + g_display->initialiseBackgroundLayer(NULL); + g_display->setPalette(0, 256, FetchPalette(bgfile), RDPAL_FADE); + + g_display->renderParallax(FetchBackgroundLayer(bgfile), 2); res_man.close(2950); // release the screen resource // Git rid of read-only status, if it is set. @@ -1153,8 +1153,8 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) { frame = (_frameHeader*) text_spr->ad; - textSprite.x = screenWide /2 - frame->width / 2; - textSprite.y = screenDeep /2 - frame->height / 2 - RDMENU_MENUDEEP; + textSprite.x = g_display->_screenWide /2 - frame->width / 2; + textSprite.y = g_display->_screenDeep /2 - frame->height / 2 - RDMENU_MENUDEEP; textSprite.w = frame->width; textSprite.h = frame->height; textSprite.scale = 0; @@ -1194,18 +1194,17 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) { int16 textX = textSprite.x; int16 textY = textSprite.y; - DrawSprite(&barSprite); + g_display->drawSprite(&barSprite); barSprite.x = barX; barSprite.y = barY; textSprite.data = text_spr->ad + sizeof(_frameHeader); - DrawSprite(&textSprite); + g_display->drawSprite(&textSprite); textSprite.x = textX; textSprite.y = textY; - FadeUp((float) 0.75); - - WaitForFade(); + g_display->fadeUp(); + g_display->waitForFade(); uint32 size = inFile.size(); @@ -1227,19 +1226,19 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) { step = 0; // open the screen resource bgfile = res_man.open(2950); - RenderParallax(FetchBackgroundLayer(bgfile), 2); + g_display->renderParallax(FetchBackgroundLayer(bgfile), 2); // release the screen resource res_man.close(2950); loadingBar = res_man.open(2951); frame = FetchFrameHeader(loadingBar, fr); barSprite.data = (uint8 *) (frame + 1); res_man.close(2951); - DrawSprite(&barSprite); + g_display->drawSprite(&barSprite); barSprite.x = barX; barSprite.y = barY; textSprite.data = text_spr->ad + sizeof(_frameHeader); - DrawSprite(&textSprite); + g_display->drawSprite(&textSprite); textSprite.x = textX; textSprite.y = textY; @@ -1247,7 +1246,7 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) { } else step++; - ServiceWindows(); + g_display->updateDisplay(); } while ((read % BUFFERSIZE) == 0); if (read != size) { @@ -1258,11 +1257,11 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) { outFile.close(); memory.freeMemory(text_spr); - EraseBackBuffer(); + g_display->clearScene(); - FadeDown((float) 0.75); - WaitForFade(); - FadeUp((float) 0.75); + g_display->fadeDown(); + g_display->waitForFade(); + g_display->fadeUp(); // Git rid of read-only status. SVM_SetFileAttributes(_resourceFiles[newCluster], FILE_ATTRIBUTE_NORMAL); @@ -1379,8 +1378,8 @@ void ResourceManager::getCd(int cd) { frame = (_frameHeader*) text_spr->ad; - spriteInfo.x = screenWide / 2 - frame->width / 2; - spriteInfo.y = screenDeep / 2 - frame->height / 2 - RDMENU_MENUDEEP; + spriteInfo.x = g_display->_screenWide / 2 - frame->width / 2; + spriteInfo.y = g_display->_screenDeep / 2 - frame->height / 2 - RDMENU_MENUDEEP; spriteInfo.w = frame->width; spriteInfo.h = frame->height; spriteInfo.scale = 0; @@ -1418,10 +1417,10 @@ void ResourceManager::getCd(int cd) { } } - ServiceWindows(); + g_display->updateDisplay(); - EraseBackBuffer(); - DrawSprite(&spriteInfo); // Keep the message there even when the user task swaps. + g_display->clearScene(); + g_display->drawSprite(&spriteInfo); // Keep the message there even when the user task swaps. spriteInfo.y = oldY; // Drivers change the y co-ordinate, don't know why... spriteInfo.x = oldX; } while (!done); diff --git a/sword2/speech.cpp b/sword2/speech.cpp index b09f46155d..42ac9ef551 100644 --- a/sword2/speech.cpp +++ b/sword2/speech.cpp @@ -220,17 +220,17 @@ int32 FN_choose(int32 *params) { if (j < IN_SUBJECT) { debug(5, " ICON res %d for %d", subject_list[j].res, j); icon = res_man.open(subject_list[j].res) + sizeof(_standardHeader) + RDMENU_ICONWIDE * RDMENU_ICONDEEP; - SetMenuIcon(RDMENU_BOTTOM, (uint8) j, icon); + g_display->setMenuIcon(RDMENU_BOTTOM, (uint8) j, icon); res_man.close(subject_list[j].res); } else { //no icon here debug(5, " NULL for %d", j); - SetMenuIcon(RDMENU_BOTTOM, (uint8) j, NULL); + g_display->setMenuIcon(RDMENU_BOTTOM, (uint8) j, NULL); } } // start menus appearing - ShowMenu(RDMENU_BOTTOM); + g_display->showMenu(RDMENU_BOTTOM); // lets have the mouse pointer back Set_mouse(NORMAL_MOUSE_ID); @@ -253,9 +253,9 @@ int32 FN_choose(int32 *params) { // if so then end the choose, highlight only the // chosen, blank the mouse and return the ref code * 8 - if (mousey > 399 && mousex >= 24 && mousex < 640 - 24) { + if (g_display->_mouseY > 399 && g_display->_mouseX >= 24 && g_display->_mouseX < 640 - 24) { //which are we over? - hit = (mousex - 24) / 40; + hit = (g_display->_mouseX - 24) / 40; //clicked on something - what button? if (hit < IN_SUBJECT) { @@ -268,7 +268,7 @@ int32 FN_choose(int32 *params) { // change all others to grey if (j != hit) { icon = res_man.open( subject_list[j].res ) + sizeof(_standardHeader); - SetMenuIcon(RDMENU_BOTTOM, (uint8) j, icon); + g_display->setMenuIcon(RDMENU_BOTTOM, (uint8) j, icon); res_man.close(subject_list[j].res); } } @@ -338,9 +338,9 @@ int32 FN_end_conversation(int32 *params) { debug(5, "FN_end_conversation"); - HideMenu(RDMENU_BOTTOM); + g_display->hideMenu(RDMENU_BOTTOM); - if (mousey > 399) { + if (g_display->_mouseY > 399) { // will wait for cursor to move off the bottom menu mouse_mode = MOUSE_holding; debug(5, " holding"); @@ -1302,7 +1302,7 @@ int32 FN_i_speak(int32 *params) { #ifdef _SWORD2_DEBUG // so that we can go to the options panel while text & speech is // being tested - if (SYSTEM_TESTING_TEXT == 0 || mousey > 0) { + if (SYSTEM_TESTING_TEXT == 0 || g_display->_mouseY > 0) { #endif me = MouseEvent(); diff --git a/sword2/startup.cpp b/sword2/startup.cpp index bf9eb31b51..1e32086529 100644 --- a/sword2/startup.cpp +++ b/sword2/startup.cpp @@ -196,8 +196,8 @@ uint32 Con_print_start_menu(void) { do { // Service windows - ServiceWindows(); - } while(!KeyWaiting()); + g_display->updateDisplay(); + } while (!KeyWaiting()); // kill the key we just pressed ReadKey(&ke); diff --git a/sword2/sword2.cpp b/sword2/sword2.cpp index d4cadde9de..06de398c66 100644 --- a/sword2/sword2.cpp +++ b/sword2/sword2.cpp @@ -96,6 +96,7 @@ uint8 stepOneCycle = 0; // for use while game paused Sword2Engine *g_sword2 = NULL; Sound *g_sound = NULL; +Display *g_display = NULL; Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst) : Engine(detector, syst) { @@ -120,11 +121,13 @@ Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst) _mixer->setMusicVolume(256); g_sound = _sound = new Sound(_mixer); + g_display = _display = new Display(640, 480); } Sword2Engine::~Sword2Engine() { free(_targetName); delete _sound; + delete _display; } void Sword2Engine::errorString(const char *buf1, char *buf2) { @@ -199,7 +202,6 @@ int32 Sword2Engine::InitialiseGame(void) { void Close_game() { debug(5, "Close_game() STARTING:"); - EraseBackBuffer(); // Stop music instantly! Kill_music(); @@ -207,6 +209,8 @@ void Close_game() { // free the memory again memory.exit(); res_man.exit(); + + g_system->quit(); } int32 GameCycle(void) { @@ -250,8 +254,6 @@ int32 GameCycle(void) { } void Sword2Engine::go() { - uint32 rv; - uint8 breakOut = 0; _keyboardEvent ke; // Call the application "Revolution" until the resource manager is @@ -262,21 +264,12 @@ void Sword2Engine::go() { // manager until a window has been created as any errors are displayed // via a window, thus time becomes a loop. - debug(5, "CALLING: InitialiseDisplay"); - rv = InitialiseDisplay(640, 480); - - if (rv != RD_OK) { - // ReportDriverError(rv); - CloseAppWindow(); - return; - } - debug(5, "CALLING: readOptionSettings"); gui.readOptionSettings(); debug(5, "CALLING: InitialiseGame"); if (InitialiseGame()) { - CloseAppWindow(); + Close_game(); return; } @@ -291,11 +284,11 @@ void Sword2Engine::go() { } else Start_game(); - debug(5, "CALLING: InitialiseRenderCycle"); - InitialiseRenderCycle(); + debug(5, "CALLING: initialiseRenderCycle"); + g_display->initialiseRenderCycle(); while (1) { - ServiceWindows(); + g_display->updateDisplay(); #ifdef _SWORD2_DEBUG // FIXME: If we want this, we should re-work it to use the backend's @@ -304,10 +297,6 @@ void Sword2Engine::go() { // GrabScreenShot(); #endif - // if we are closing down the game, break out of main game loop - if (breakOut) - break; - #ifdef _SWORD2_DEBUG if (console_status) { if (One_console()) { @@ -408,7 +397,6 @@ void Sword2Engine::go() { } Close_game(); //close engine systems down - CloseAppWindow(); return; //quit the game } @@ -465,8 +453,8 @@ void sleepUntil(int32 time) { g_sword2->parseEvents(); // Make sure menu animations and fades don't suffer - ProcessMenu(); - ServiceWindows(); + g_display->processMenu(); + g_display->updateDisplay(); g_system->delay_msecs(10); } @@ -481,8 +469,8 @@ void PauseGame(void) { // now ok to close the text file // res_man.close(3258); - // don't allow Pause while screen fading or while black (James 03sep97) - if (GetFadeStatus() != RDFADE_NONE) + // don't allow Pause while screen fading or while black + if (g_display->getFadeStatus() != RDFADE_NONE) return; PauseAllSound(); @@ -492,8 +480,8 @@ void PauseGame(void) { // mouse_mode=MOUSE_normal; - //this is the only place allowed to do it this way - SetLuggageAnim(NULL, 0); + // this is the only place allowed to do it this way + g_display->setLuggageAnim(NULL, 0); // blank cursor Set_mouse(0); @@ -513,7 +501,7 @@ void PauseGame(void) { // dim the palette during the pause (James26jun97) if (stepOneCycle == 0) - DimPalette(); + g_display->dimPalette(); gamePaused = 1; } diff --git a/sword2/sword2.h b/sword2/sword2.h index a8a7354491..08147152a2 100644 --- a/sword2/sword2.h +++ b/sword2/sword2.h @@ -26,6 +26,7 @@ #include "common/rect.h" #include "common/str.h" #include "bs2/driver/d_sound.h" +#include "bs2/driver/d_draw.h" enum BSGameId { GID_SWORD2 = GID_SWORD2_FIRST, @@ -77,6 +78,7 @@ public: byte _gameId; char *_targetName; // target name for saves Sound *_sound; + Display *_display; Common::RandomSource _rnd; uint32 _speechFontId; @@ -90,6 +92,7 @@ public: extern Sword2Engine *g_sword2; extern Sound *g_sound; +extern Display *g_display; } // End of namespace Sword2 diff --git a/sword2/walker.cpp b/sword2/walker.cpp index 9122b48555..b5095bd66c 100644 --- a/sword2/walker.cpp +++ b/sword2/walker.cpp @@ -23,6 +23,7 @@ // on them #include "stdafx.h" +#include "bs2/sword2.h" #include "bs2/console.h" #include "bs2/defs.h" #include "bs2/events.h" @@ -137,7 +138,7 @@ int32 FN_walk(int32 *params) { // resource ob_graph->anim_resource = ob_mega->megaset_res; - } else if (EXIT_FADING && GetFadeStatus() == RDFADE_BLACK) { + } else if (EXIT_FADING && g_display->getFadeStatus() == RDFADE_BLACK) { // double clicked an exit so quit the walk when screen is black // ok, thats it - back to script and change screen |