From 446a01ba09192a132ee9b6e40129161a7ec09be0 Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Tue, 11 Nov 2003 07:43:02 +0000 Subject: Moved low-level keyboard and mouse handling to a new Input class, and renamed the Display class Graphics for no better reason than me liking the phrase "sound and graphics" better than "sound and display". svn-id: r11258 --- sword2/anims.cpp | 4 +- sword2/build_display.cpp | 92 ++++++++++++++++++------------------- sword2/console.cpp | 8 ++-- sword2/controls.cpp | 50 ++++++++++----------- sword2/debug.cpp | 28 ++++++------ sword2/driver/_mouse.cpp | 92 +++++++++++++++++-------------------- sword2/driver/d_draw.cpp | 50 ++++++++++----------- sword2/driver/d_draw.h | 7 +-- sword2/driver/d_sound.cpp | 2 +- sword2/driver/driver96.h | 54 ++++++++++++++++------ sword2/driver/keyboard.cpp | 39 +++++++--------- sword2/driver/menu.cpp | 12 ++--- sword2/driver/palette.cpp | 20 ++++----- sword2/driver/rdwin.cpp | 30 ++++++------- sword2/driver/render.cpp | 31 +++++++------ sword2/driver/sprite.cpp | 20 ++++----- sword2/function.cpp | 50 ++++++++++----------- sword2/icons.cpp | 10 ++--- sword2/layers.cpp | 28 ++++++------ sword2/logic.cpp | 2 +- sword2/maketext.cpp | 4 +- sword2/mouse.cpp | 110 ++++++++++++++++++++++----------------------- sword2/resman.cpp | 64 +++++++++++++------------- sword2/router.cpp | 6 +-- sword2/speech.cpp | 24 +++++----- sword2/sword2.cpp | 31 ++++++------- sword2/sword2.h | 6 ++- sword2/walker.cpp | 2 +- 28 files changed, 441 insertions(+), 435 deletions(-) (limited to 'sword2') diff --git a/sword2/anims.cpp b/sword2/anims.cpp index d8cf28cc73..1e2d9a0263 100644 --- a/sword2/anims.cpp +++ b/sword2/anims.cpp @@ -751,14 +751,14 @@ int32 Logic::fnPlaySequence(int32 *params) { // now clear the screen in case the Sequence was quitted (using ESC) // rather than fading down to black - g_display->clearScene(); + g_graphics->clearScene(); // zero the entire palette in case we're about to fade up! _palEntry pal[256]; memset(pal, 0, 256 * sizeof(_palEntry)); - g_display->setPalette(0, 256, (uint8 *) pal, RDPAL_INSTANT); + g_graphics->setPalette(0, 256, (uint8 *) pal, RDPAL_INSTANT); debug(5, "fnPlaySequence FINISHED"); diff --git a/sword2/build_display.cpp b/sword2/build_display.cpp index 5c51ed5b32..6b187a92d6 100644 --- a/sword2/build_display.cpp +++ b/sword2/build_display.cpp @@ -54,11 +54,11 @@ void Sword2Engine::buildDisplay(void) { // there is a valid screen to run if (_thisScreen.background_layer_id) { // set the scroll position - g_display->setScrollTarget(_thisScreen.scroll_offset_x, _thisScreen.scroll_offset_y); + g_graphics->setScrollTarget(_thisScreen.scroll_offset_x, _thisScreen.scroll_offset_y); // increment the mouse frame - g_display->animateMouse(); + g_graphics->animateMouse(); - g_display->startRenderCycle(); + g_graphics->startRenderCycle(); while (1) { // clear the back buffer, before building up the new @@ -67,7 +67,7 @@ void Sword2Engine::buildDisplay(void) { // FIXME: I'm not convinced that this is needed. Isn't // the whole screen redrawn each time? - // g_display->clearScene(); + // g_graphics->clearScene(); // first background parallax + related anims @@ -76,7 +76,7 @@ void Sword2Engine::buildDisplay(void) { screenLayerTable = (_multiScreenHeader *) ((uint8 *) file + sizeof(_standardHeader)); if (screenLayerTable->bg_parallax[0]) { - g_display->renderParallax(fetchBackgroundParallaxLayer(file, 0), 0); + g_graphics->renderParallax(fetchBackgroundParallaxLayer(file, 0), 0); // release the screen resource before cacheing // the sprites res_man->closeResource(_thisScreen.background_layer_id); @@ -93,7 +93,7 @@ void Sword2Engine::buildDisplay(void) { screenLayerTable = (_multiScreenHeader *) ((uint8 *) file + sizeof(_standardHeader)); if (screenLayerTable->bg_parallax[1]) { - g_display->renderParallax(fetchBackgroundParallaxLayer(file, 1), 1); + g_graphics->renderParallax(fetchBackgroundParallaxLayer(file, 1), 1); // release the screen resource before cacheing // the sprites res_man->closeResource(_thisScreen.background_layer_id); @@ -107,7 +107,7 @@ void Sword2Engine::buildDisplay(void) { // open the screen resource file = res_man->openResource(_thisScreen.background_layer_id); - g_display->renderParallax(fetchBackgroundLayer(file), 2); + g_graphics->renderParallax(fetchBackgroundLayer(file), 2); // release the screen resource res_man->closeResource(_thisScreen.background_layer_id); @@ -125,7 +125,7 @@ void Sword2Engine::buildDisplay(void) { screenLayerTable = (_multiScreenHeader *) ((uint8 *) file + sizeof(_standardHeader)); if (screenLayerTable->fg_parallax[0]) { - g_display->renderParallax(fetchForegroundParallaxLayer(file, 0), 3); + g_graphics->renderParallax(fetchForegroundParallaxLayer(file, 0), 3); // release the screen resource before cacheing // the sprites res_man->closeResource(_thisScreen.background_layer_id); @@ -142,7 +142,7 @@ void Sword2Engine::buildDisplay(void) { screenLayerTable = (_multiScreenHeader *) ((uint8 *) file + sizeof(_standardHeader)); if (screenLayerTable->fg_parallax[1]) { - g_display->renderParallax(fetchForegroundParallaxLayer(file, 1), 4); + g_graphics->renderParallax(fetchForegroundParallaxLayer(file, 1), 4); // release the screen resource before cacheing // the sprites res_man->closeResource(_thisScreen.background_layer_id); @@ -164,11 +164,11 @@ void Sword2Engine::buildDisplay(void) { // menu bar & icons - g_display->processMenu(); + g_graphics->processMenu(); // ready - blit to screen - g_display->updateDisplay(); + g_graphics->updateDisplay(); // update our fps reading @@ -187,7 +187,7 @@ void Sword2Engine::buildDisplay(void) { // If we haven't got time to render again this cycle, // drop out of 'render cycle' while-loop - if (g_display->endRenderCycle()) + if (g_graphics->endRenderCycle()) break; } } @@ -207,24 +207,24 @@ void Sword2Engine::displayMsg(uint8 *text, int time) { debug(2, "DisplayMsg: %s", (char *) text); - if (g_display->getFadeStatus() != RDFADE_BLACK) { - g_display->fadeDown(); - g_display->waitForFade(); + if (g_graphics->getFadeStatus() != RDFADE_BLACK) { + g_graphics->fadeDown(); + g_graphics->waitForFade(); } setMouse(0); setLuggage(0); - g_display->closeMenuImmediately(); - g_display->clearScene(); + g_graphics->closeMenuImmediately(); + g_graphics->clearScene(); text_spr = fontRenderer->makeTextSprite(text, 640, 187, _speechFontId); frame = (_frameHeader *) text_spr->ad; - spriteInfo.x = g_display->_screenWide / 2 - frame->width / 2; + spriteInfo.x = g_graphics->_screenWide / 2 - frame->width / 2; if (!time) - spriteInfo.y = g_display->_screenDeep / 2 - frame->height / 2 - RDMENU_MENUDEEP; + spriteInfo.y = g_graphics->_screenDeep / 2 - frame->height / 2 - RDMENU_MENUDEEP; else spriteInfo.y = 400 - frame->height; spriteInfo.w = frame->width; @@ -237,34 +237,34 @@ void Sword2Engine::displayMsg(uint8 *text, int time) { spriteInfo.data = text_spr->ad + sizeof(_frameHeader); spriteInfo.colourTable = 0; - rv = g_display->drawSprite(&spriteInfo); + rv = g_graphics->drawSprite(&spriteInfo); if (rv) error("Driver Error %.8x (in DisplayMsg)", rv); - memcpy((char *) oldPal, (char *) g_display->_palCopy, 256 * sizeof(_palEntry)); + memcpy((char *) oldPal, (char *) g_graphics->_palCopy, 256 * sizeof(_palEntry)); memset(pal, 0, 256 * sizeof(_palEntry)); pal[187].red = 255; pal[187].green = 255; pal[187].blue = 255; - g_display->setPalette(0, 256, (uint8 *) pal, RDPAL_FADE); + g_graphics->setPalette(0, 256, (uint8 *) pal, RDPAL_FADE); - g_display->fadeUp(); + g_graphics->fadeUp(); memory->freeMemory(text_spr); - g_display->waitForFade(); + g_graphics->waitForFade(); uint32 targetTime = SVM_timeGetTime() + (time * 1000); // Keep the message there even when the user task swaps. - rv = g_display->drawSprite(&spriteInfo); + rv = g_graphics->drawSprite(&spriteInfo); if (rv) error("Driver Error %.8x (in DisplayMsg)", rv); sleepUntil(targetTime); - g_display->setPalette(0, 256, (uint8 *) oldPal, RDPAL_FADE); + g_graphics->setPalette(0, 256, (uint8 *) oldPal, RDPAL_FADE); } // @@ -272,11 +272,11 @@ void Sword2Engine::displayMsg(uint8 *text, int time) { // void Sword2Engine::removeMsg(void) { - g_display->fadeDown(); - g_display->waitForFade(); - g_display->clearScene(); + g_graphics->fadeDown(); + g_graphics->waitForFade(); + g_graphics->clearScene(); - // g_display->fadeUp(); + // g_graphics->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 @@ -385,7 +385,7 @@ void Sword2Engine::processLayer(uint32 layer_number) { layer_number, layer_head->width, layer_head->height); } - rv = g_display->drawSprite(&spriteInfo); + rv = g_graphics->drawSprite(&spriteInfo); if (rv) error("Driver Error %.8x in Process_layer(%d)", rv, layer_number); @@ -511,7 +511,7 @@ void Sword2Engine::processImage(buildit *build_unit) { // } // #endif - rv = g_display->drawSprite(&spriteInfo); + rv = g_graphics->drawSprite(&spriteInfo); if (rv) error("Driver Error %.8x with sprite %s (%d) in processImage", rv, fetchObjectName(build_unit->anim_resource), @@ -761,14 +761,14 @@ void Sword2Engine::startNewPalette(void) { // if the screen is still fading down then wait for black - could // happen when everythings cached into a large memory model - g_display->waitForFade(); + g_graphics->waitForFade(); // open the screen file screenFile = res_man->openResource(_thisScreen.background_layer_id); - g_display->updatePaletteMatchTable((uint8 *) fetchPaletteMatchTable(screenFile)); + g_graphics->updatePaletteMatchTable((uint8 *) fetchPaletteMatchTable(screenFile)); - g_display->setPalette(0, 256, fetchPalette(screenFile), RDPAL_FADE); + g_graphics->setPalette(0, 256, fetchPalette(screenFile), RDPAL_FADE); // indicating that it's a screen palette _lastPaletteRes = 0; @@ -777,7 +777,7 @@ void Sword2Engine::startNewPalette(void) { res_man->closeResource(_thisScreen.background_layer_id); // start fade up - g_display->fadeUp(); + g_graphics->fadeUp(); // reset _thisScreen.new_palette = 0; @@ -811,8 +811,8 @@ int32 Logic::fnFadeDown(int32 *params) { // params: none - if (g_display->getFadeStatus() == RDFADE_NONE) - g_display->fadeDown(); + if (g_graphics->getFadeStatus() == RDFADE_NONE) + g_graphics->fadeDown(); return IR_CONT; } @@ -820,10 +820,10 @@ int32 Logic::fnFadeDown(int32 *params) { int32 Logic::fnFadeUp(int32 *params) { // params: none - g_display->waitForFade(); + g_graphics->waitForFade(); - if (g_display->getFadeStatus() == RDFADE_BLACK) - g_display->fadeUp(); + if (g_graphics->getFadeStatus() == RDFADE_BLACK) + g_graphics->fadeUp(); return IR_CONT; } @@ -888,9 +888,9 @@ void Sword2Engine::setFullPalette(int32 palRes) { file[3] = 0; // not yet in separate palette files - // g_display->updatePaletteMatchTable(file + (256 * 4)); + // g_graphics->updatePaletteMatchTable(file + (256 * 4)); - g_display->setPalette(0, 256, file, RDPAL_INSTANT); + g_graphics->setPalette(0, 256, file, RDPAL_INSTANT); if (palRes != CONTROL_PANEL_PALETTE) { // (James 03sep97) // indicating that it's a separate palette resource @@ -904,9 +904,9 @@ void Sword2Engine::setFullPalette(int32 palRes) { if (_thisScreen.background_layer_id) { // open the screen file file = res_man->openResource(_thisScreen.background_layer_id); - g_display->updatePaletteMatchTable((uint8 *) fetchPaletteMatchTable(file)); + g_graphics->updatePaletteMatchTable((uint8 *) fetchPaletteMatchTable(file)); - g_display->setPalette(0, 256, fetchPalette(file), RDPAL_INSTANT); + g_graphics->setPalette(0, 256, fetchPalette(file), RDPAL_INSTANT); // indicating that it's a screen palette _lastPaletteRes = 0; @@ -928,7 +928,7 @@ int32 Logic::fnChangeShadows(int32 *params) { // if last screen was using a shading mask (see below) if (_vm->_thisScreen.mask_flag) { - uint32 rv = g_display->closeLightMask(); + uint32 rv = g_graphics->closeLightMask(); if (rv) error("Driver Error %.8x [%s line %u]", rv); diff --git a/sword2/console.cpp b/sword2/console.cpp index 722b3d1e5d..e50741fdb9 100644 --- a/sword2/console.cpp +++ b/sword2/console.cpp @@ -144,7 +144,7 @@ void Debugger::postEnter() { g_sound->unpauseMusic(); // Restore old mouse cursor - g_display->drawMouse(); + g_graphics->drawMouse(); } @@ -209,7 +209,7 @@ bool Debugger::Cmd_Start(int argc, const char **argv) { } g_logic->conStart(atoi(argv[1])); - g_display->setPalette(187, 1, pal, RDPAL_INSTANT); + g_graphics->setPalette(187, 1, pal, RDPAL_INSTANT); return true; } @@ -451,14 +451,14 @@ bool Debugger::Cmd_RestoreGame(int argc, const char **argv) { // FIXME: Replace these with a command to modify the graphics detail setting bool Debugger::Cmd_BltFxOn(int argc, const char **argv) { - // g_display->setBltFx(); + // g_graphics->setBltFx(); // DebugPrintf("Blit fx enabled\n"); DebugPrintf("FIXME: The setBltFx() function no longer exists\n"); return true; } bool Debugger::Cmd_BltFxOff(int argc, const char **argv) { - // g_display->clearBltFx(); + // g_graphics->clearBltFx(); // DebugPrintf("Blit fx disabled\n"); DebugPrintf("FIXME: The clearBltFx() function no longer exists\n"); return true; diff --git a/sword2/controls.cpp b/sword2/controls.cpp index 740ade618b..d05e26d44d 100644 --- a/sword2/controls.cpp +++ b/sword2/controls.cpp @@ -43,7 +43,7 @@ namespace Sword2 { #define CHARACTER_OVERLAP 2 // overlap characters by 3 pixels // our fonts start on SPACE character (32) -#define SIZE_OF_CHAR_SET (256 - 32) +#define SIZE_OF_CHAR_SET (256 - 32) Gui *gui; @@ -75,7 +75,7 @@ public: sprite.data = (uint8 *) (head + 1); sprite.w = head->width; sprite.h = head->height; - g_display->createSurface(&sprite, &_glyph[i]._data); + g_graphics->createSurface(&sprite, &_glyph[i]._data); _glyph[i]._width = head->width; _glyph[i]._height = head->height; } @@ -85,7 +85,7 @@ public: ~FontRendererGui() { for (int i = 0; i < SIZE_OF_CHAR_SET; i++) - g_display->deleteSurface(_glyph[i]._data); + g_graphics->deleteSurface(_glyph[i]._data); } void fetchText(int textId, char *buf) { @@ -144,7 +144,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; - g_display->drawSurface(&sprite, _glyph[text[i] - 32]._data); + g_graphics->drawSurface(&sprite, _glyph[text[i] - 32]._data); sprite.x += (_glyph[(int) text[i] - 32]._width - CHARACTER_OVERLAP); } @@ -187,7 +187,7 @@ public: virtual ~Widget() { for (int i = 0; i < _numStates; i++) { if (_surfaces[i]._original) - g_display->deleteSurface(_surfaces[i]._surface); + g_graphics->deleteSurface(_surfaces[i]._surface); } free(_sprites); free(_surfaces); @@ -229,7 +229,7 @@ public: } virtual void paint(Common::Rect *clipRect = NULL) { - g_display->drawSurface(&_sprites[_state], _surfaces[_state]._surface, clipRect); + g_graphics->drawSurface(&_sprites[_state], _surfaces[_state]._surface, clipRect); } virtual void onMouseEnter() {} @@ -292,7 +292,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); - g_display->createSurface(&_sprites[state], &_surfaces[state]._surface); + g_graphics->createSurface(&_sprites[state], &_surfaces[state]._surface); _surfaces[state]._original = true; // Release the anim resource @@ -340,7 +340,7 @@ public: virtual void onAction(Widget *widget, int result = 0) {} virtual void paint() { - g_display->clearScene(); + g_graphics->clearScene(); for (int i = 0; i < _numWidgets; i++) _widgets[i]->paint(); } @@ -363,15 +363,15 @@ int Dialog::run() { while (!_finish) { // So that the menu icons will reach their full size - g_display->processMenu(); - g_display->updateDisplay(); + g_graphics->processMenu(); + g_graphics->updateDisplay(); - int16 newMouseX = g_display->_mouseX; - int16 newMouseY = g_display->_mouseY + 40; + int16 newMouseX = g_input->_mouseX; + int16 newMouseY = g_input->_mouseY + 40; - _mouseEvent *me = MouseEvent(); + _mouseEvent *me = g_input->mouseEvent(); _keyboardEvent ke; - int32 keyboardStatus = ReadKey(&ke); + int32 keyboardStatus = g_input->readKey(&ke); if (keyboardStatus == RD_OK) { if (ke.keycode == 27) @@ -388,7 +388,7 @@ int Dialog::run() { _widgets[i]->onMouseEnter(); if (oldHit && !newHit) _widgets[i]->onMouseExit(); - if (g_display->_mouseX != oldMouseX || g_display->_mouseY != oldMouseY) + if (g_input->_mouseX != oldMouseX || g_input->_mouseY != oldMouseY) _widgets[i]->onMouseMove(newMouseX, newMouseY); if (me) { @@ -786,8 +786,8 @@ public: _musicSlider->setValue(g_sound->getMusicVolume()); _speechSlider->setValue(g_sound->getSpeechVolume()); _fxSlider->setValue(g_sound->getFxVolume()); - _gfxSlider->setValue(g_display->getRenderLevel()); - _gfxPreview->setState(g_display->getRenderLevel()); + _gfxSlider->setValue(g_graphics->getRenderLevel()); + _gfxPreview->setState(g_graphics->getRenderLevel()); } ~OptionsDialog() { @@ -1312,17 +1312,17 @@ void SaveLoadDialog::saveLoadError(char* text) { while (1) { _mouseEvent *me; - g_display->updateDisplay(); + g_graphics->updateDisplay(); - if (KeyWaiting()) { + if (g_input->keyWaiting()) { _keyboardEvent ke; - ReadKey(&ke); + g_input->readKey(&ke); if (ke.keycode == 27) break; } - me = MouseEvent(); + me = g_input->mouseEvent(); if (me && (me->buttons & RD_LEFTBUTTONDOWN)) break; @@ -1383,7 +1383,7 @@ void Gui::writeOptionSettings(void) { ConfMan.set("music_mute", g_sound->isMusicMute()); ConfMan.set("speech_mute", g_sound->isSpeechMute()); ConfMan.set("sfx_mute", g_sound->isFxMute()); - ConfMan.set("gfx_details", g_display->getRenderLevel()); + ConfMan.set("gfx_details", g_graphics->getRenderLevel()); ConfMan.set("nosubtitles", !_subtitles); ConfMan.set("object_labels", _pointerTextSelected); ConfMan.set("reverse_stereo", _stereoReversed); @@ -1432,7 +1432,7 @@ void Gui::restartControl(void) { //in case we were dead - well we're not anymore! DEAD = 0; - g_display->clearScene(); + g_graphics->clearScene(); // restart the game // clear all memory and reset the globals @@ -1466,7 +1466,7 @@ void Gui::restartControl(void) { // fnRegisterFrame) _vm->resetMouseList(); - g_display->closeMenuImmediately(); + g_graphics->closeMenuImmediately(); // FOR THE DEMO - FORCE THE SCROLLING TO BE RESET! // - this is taken from fnInitBackground @@ -1496,7 +1496,7 @@ void Gui::updateGraphicsLevel(int newLevel) { else if (newLevel > 3) newLevel = 3; - g_display->setRenderLevel(newLevel); + g_graphics->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/debug.cpp b/sword2/debug.cpp index 8d96dba103..d4950adc3c 100644 --- a/sword2/debug.cpp +++ b/sword2/debug.cpp @@ -186,14 +186,14 @@ void Debugger::buildDebugText(void) { if (_vm->_mouseTouching) sprintf(buf, "mouse %d,%d (id %d: %s)", - g_display->_mouseX + _vm->_thisScreen.scroll_offset_x, - g_display->_mouseY + _vm->_thisScreen.scroll_offset_y, + g_input->_mouseX + _vm->_thisScreen.scroll_offset_x, + g_input->_mouseY + _vm->_thisScreen.scroll_offset_y, _vm->_mouseTouching, _vm->fetchObjectName(_vm->_mouseTouching)); else sprintf(buf, "mouse %d,%d (not touching)", - g_display->_mouseX + _vm->_thisScreen.scroll_offset_x, - g_display->_mouseY + _vm->_thisScreen.scroll_offset_y); + g_input->_mouseX + _vm->_thisScreen.scroll_offset_x, + g_input->_mouseY + _vm->_thisScreen.scroll_offset_y); makeDebugTextBlock(buf, 0, 30); @@ -319,7 +319,7 @@ void Debugger::drawDebugGraphics(void) { // mouse marker & coords if (_displayMouseMarker) - plotCrossHair(g_display->_mouseX + _vm->_thisScreen.scroll_offset_x, g_display->_mouseY + _vm->_thisScreen.scroll_offset_y, 215); + plotCrossHair(g_input->_mouseX + _vm->_thisScreen.scroll_offset_x, g_input->_mouseY + _vm->_thisScreen.scroll_offset_y, 215); // mouse area rectangle / sprite box rectangle when testing anims @@ -335,20 +335,20 @@ void Debugger::drawDebugGraphics(void) { } void Debugger::plotCrossHair(int16 x, int16 y, uint8 pen) { - g_display->plotPoint(x, y, pen); // driver function + g_graphics->plotPoint(x, y, pen); // driver function - g_display->drawLine(x - 2, y, x - 5, y, pen); // driver function - g_display->drawLine(x + 2, y, x + 5, y, pen); + g_graphics->drawLine(x - 2, y, x - 5, y, pen); // driver function + g_graphics->drawLine(x + 2, y, x + 5, y, pen); - g_display->drawLine(x, y - 2, x, y - 5, pen); - g_display->drawLine(x, y + 2, x, y + 5, pen); + g_graphics->drawLine(x, y - 2, x, y - 5, pen); + g_graphics->drawLine(x, y + 2, x, y + 5, pen); } void Debugger::drawRect(int16 x1, int16 y1, int16 x2, int16 y2, uint8 pen) { - g_display->drawLine(x1, y1, x2, y1, pen); // top edge - g_display->drawLine(x1, y2, x2, y2, pen); // bottom edge - g_display->drawLine(x1, y1, x1, y2, pen); // left edge - g_display->drawLine(x2, y1, x2, y2, pen); // right edge + g_graphics->drawLine(x1, y1, x2, y1, pen); // top edge + g_graphics->drawLine(x1, y2, x2, y2, pen); // bottom edge + g_graphics->drawLine(x1, y1, x1, y2, pen); // left edge + g_graphics->drawLine(x2, y1, x2, y2, pen); // right edge } void Debugger::printCurrentInfo(void) { diff --git a/sword2/driver/_mouse.cpp b/sword2/driver/_mouse.cpp index 8216c5fa07..bce554a3f3 100644 --- a/sword2/driver/_mouse.cpp +++ b/sword2/driver/_mouse.cpp @@ -26,43 +26,59 @@ namespace Sword2 { -#define MAX_MOUSE_EVENTS 16 #define MOUSEFLASHFRAME 6 -static uint8 mouseBacklog = 0; -static uint8 mouseLogPos = 0; -static _mouseEvent mouseLog[MAX_MOUSE_EVENTS]; +/** + * Logs the mouse button event passed in buttons. The button events are + * defined as RD_LEFTBUTTONDOWN, RD_LEFTBUTTONUP, RD_RIGHTBUTTONDOWN and + * RD_RIGHTBUTTONUP. + */ -void Display::resetRenderEngine(void) { - _parallaxScrollX = 0; - _parallaxScrollY = 0; - _scrollX = 0; - _scrollY = 0; +void Input::logMouseEvent(uint16 buttons) { + // We need to leave the one, which is the current event, alone! + if (_mouseBacklog == MAX_MOUSE_EVENTS - 1) + return; + + _mouseLog[(_mouseBacklog + _mouseLogPos) % MAX_MOUSE_EVENTS].buttons = buttons; + _mouseBacklog++; +} + +bool Input::checkForMouseEvents(void) { + return _mouseBacklog != 0; } -// -------------------------------------------------------------------------- -// Logs the mouse button event passed in buttons. The button events are -// defined as RD_LEFTBUTTONDOWN, RD_LEFTBUTTONUP, RD_RIGHTBUTTONDOWN and -// RD_RIGHTBUTTONUP. -// -------------------------------------------------------------------------- +/** + * Get the next pending mouse event. + * @return a pointer to the mouse event, or NULL of there is none + */ -void LogMouseEvent(uint16 buttons) { +_mouseEvent *Input::mouseEvent(void) { _mouseEvent *me; - // We need to leave the one, which is the current event, alone! - if (mouseBacklog == MAX_MOUSE_EVENTS - 1) - return; + if (_mouseBacklog) { + me = &_mouseLog[_mouseLogPos]; + if (++_mouseLogPos == MAX_MOUSE_EVENTS) + _mouseLogPos = 0; - me = &mouseLog[(mouseBacklog + mouseLogPos) % MAX_MOUSE_EVENTS]; - me->buttons = buttons; - mouseBacklog++; + _mouseBacklog--; + return me; + } + + return NULL; +} + +void Graphics::resetRenderEngine(void) { + _parallaxScrollX = 0; + _parallaxScrollY = 0; + _scrollX = 0; + _scrollY = 0; } // FIXME: The original code used 0 for transparency, while our backend uses // 0xFF. That means that parts of the mouse cursor that weren't meant to be // transparent may be now. -void Display::decompressMouse(uint8 *decomp, uint8 *comp, int width, int height, int pitch, int xOff, int yOff) { +void Graphics::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; @@ -87,7 +103,7 @@ void Display::decompressMouse(uint8 *decomp, uint8 *comp, int width, int height, } } -void Display::drawMouse(void) { +void Graphics::drawMouse(void) { if (!_mouseAnim && !_luggageAnim) return; @@ -158,35 +174,11 @@ void Display::drawMouse(void) { g_system->set_mouse_cursor(_mouseData, mouse_width, mouse_height, hotspot_x, hotspot_y); } -/** - * Get the next pending mouse event. - * @return a pointer to the mouse event, or NULL of there is none - */ - -_mouseEvent *MouseEvent(void) { - _mouseEvent *me; - - if (mouseBacklog) { - me = &mouseLog[mouseLogPos]; - if (++mouseLogPos == MAX_MOUSE_EVENTS) - mouseLogPos = 0; - - mouseBacklog--; - return me; - } - - return NULL; -} - -uint8 CheckForMouseEvents(void) { - return mouseBacklog; // return the number of mouse events waiting -} - /** * Animates the current mouse pointer */ -int32 Display::animateMouse(void) { +int32 Graphics::animateMouse(void) { uint8 prevMouseFrame = _mouseFrame; if (!_mouseAnim) @@ -211,7 +203,7 @@ int32 Display::animateMouse(void) { * or not there is a lead-in animation */ -int32 Display::setMouseAnim(uint8 *ma, int32 size, int32 mouseFlash) { +int32 Graphics::setMouseAnim(uint8 *ma, int32 size, int32 mouseFlash) { if (_mouseAnim) { free(_mouseAnim); _mouseAnim = NULL; @@ -251,7 +243,7 @@ int32 Display::setMouseAnim(uint8 *ma, int32 size, int32 mouseFlash) { * @param size the size of the animation data */ -int32 Display::setLuggageAnim(uint8 *ma, int32 size) { +int32 Graphics::setLuggageAnim(uint8 *ma, int32 size) { if (_luggageAnim) { free(_luggageAnim); _luggageAnim = NULL; diff --git a/sword2/driver/d_draw.cpp b/sword2/driver/d_draw.cpp index 8ccb28ab56..1db17dd974 100644 --- a/sword2/driver/d_draw.cpp +++ b/sword2/driver/d_draw.cpp @@ -28,7 +28,7 @@ namespace Sword2 { -Display::Display(int16 width, int16 height) +Graphics::Graphics(int16 width, int16 height) : _iconCount(0), _needFullRedraw(false), _fadeStatus(RDFADE_NONE), _mouseSprite(NULL), _mouseAnim(NULL), _luggageAnim(NULL), _layer(0), _renderAverageTime(60), _lightMask(NULL), @@ -59,11 +59,11 @@ Display::Display(int16 width, int16 height) * @return the graphics detail setting */ -int8 Display::getRenderLevel(void) { +int8 Graphics::getRenderLevel(void) { return _renderLevel; } -void Display::setRenderLevel(int8 level) { +void Graphics::setRenderLevel(int8 level) { _renderLevel = level; switch (_renderLevel) { @@ -92,25 +92,25 @@ void Display::setRenderLevel(int8 level) { * touch the menu areas of the screen. */ -void Display::clearScene(void) { +void Graphics::clearScene(void) { memset(_buffer + MENUDEEP * _screenWide, 0, _screenWide * RENDERDEEP); } void MoviePlayer::openTextObject(_movieTextObject *obj) { if (obj->textSprite) - g_display->createSurface(obj->textSprite, &_textSurface); + g_graphics->createSurface(obj->textSprite, &_textSurface); } void MoviePlayer::closeTextObject(_movieTextObject *obj) { if (_textSurface) { - g_display->deleteSurface(_textSurface); + g_graphics->deleteSurface(_textSurface); _textSurface = NULL; } } void MoviePlayer::drawTextObject(_movieTextObject *obj) { if (obj->textSprite && _textSurface) - g_display->drawSurface(obj->textSprite, _textSurface); + g_graphics->drawSurface(obj->textSprite, _textSurface); } /** @@ -130,14 +130,14 @@ int32 MoviePlayer::play(char *filename, _movieTextObject *text[], uint8 *musicOu uint8 oldPal[1024]; uint8 tmpPal[1024]; - g_display->clearScene(); + g_graphics->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(g_display->_buffer, 0, g_display->_screenWide * MENUDEEP); + memset(g_graphics->_buffer, 0, g_graphics->_screenWide * MENUDEEP); uint8 msg[] = "Cutscene - Press ESC to exit"; mem *data = fontRenderer->makeTextSprite(msg, 640, 255, g_sword2->_speechFontId); @@ -145,16 +145,16 @@ int32 MoviePlayer::play(char *filename, _movieTextObject *text[], uint8 *musicOu _spriteInfo msgSprite; uint8 *msgSurface; - msgSprite.x = g_display->_screenWide / 2 - frame->width / 2; + msgSprite.x = g_graphics->_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); - g_display->createSurface(&msgSprite, &msgSurface); - g_display->drawSurface(&msgSprite, msgSurface); - g_display->deleteSurface(msgSurface); + g_graphics->createSurface(&msgSprite, &msgSurface); + g_graphics->drawSurface(&msgSprite, msgSurface); + g_graphics->deleteSurface(msgSurface); memory->freeMemory(data); // In case the cutscene has a long lead-in, start just before @@ -170,12 +170,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, g_display->_palCopy, 1024); + memcpy(oldPal, g_graphics->_palCopy, 1024); memset(tmpPal, 0, 1024); tmpPal[255 * 4 + 0] = 255; tmpPal[255 * 4 + 1] = 255; tmpPal[255 * 4 + 2] = 255; - g_display->setPalette(0, 256, tmpPal, RDPAL_INSTANT); + g_graphics->setPalette(0, 256, tmpPal, RDPAL_INSTANT); PlayingSoundHandle handle = 0; @@ -186,7 +186,7 @@ int32 MoviePlayer::play(char *filename, _movieTextObject *text[], uint8 *musicOu break; if (frameCounter == text[textCounter]->startFrame) { - g_display->clearScene(); + g_graphics->clearScene(); openTextObject(text[textCounter]); drawTextObject(text[textCounter]); if (text[textCounter]->speech) { @@ -196,17 +196,17 @@ int32 MoviePlayer::play(char *filename, _movieTextObject *text[], uint8 *musicOu if (frameCounter == text[textCounter]->endFrame) { closeTextObject(text[textCounter]); - g_display->clearScene(); + g_graphics->clearScene(); textCounter++; } frameCounter++; - g_display->updateDisplay(); + g_graphics->updateDisplay(); _keyboardEvent ke; - if (ReadKey(&ke) == RD_OK && ke.keycode == 27) { + if (g_input->readKey(&ke) == RD_OK && ke.keycode == 27) { g_sword2->_mixer->stopHandle(handle); skipCutscene = true; break; @@ -221,17 +221,17 @@ int32 MoviePlayer::play(char *filename, _movieTextObject *text[], uint8 *musicOu closeTextObject(text[textCounter]); - g_display->clearScene(); - g_display->setNeedFullRedraw(); + g_graphics->clearScene(); + g_graphics->setNeedFullRedraw(); // HACK: Remove the instructions created above Common::Rect r; - memset(g_display->_buffer, 0, g_display->_screenWide * MENUDEEP); + memset(g_graphics->_buffer, 0, g_graphics->_screenWide * MENUDEEP); r.left = r.top = 0; - r.right = g_display->_screenWide; + r.right = g_graphics->_screenWide; r.bottom = MENUDEEP; - g_display->updateRect(&r); + g_graphics->updateRect(&r); // FIXME: For now, only play the lead-out music for cutscenes // that have subtitles. @@ -239,7 +239,7 @@ int32 MoviePlayer::play(char *filename, _movieTextObject *text[], uint8 *musicOu if (!skipCutscene) g_sound->playLeadOut(musicOut); - g_display->setPalette(0, 256, oldPal, RDPAL_INSTANT); + g_graphics->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 cea1941ad6..f3c0a055ee 100644 --- a/sword2/driver/d_draw.h +++ b/sword2/driver/d_draw.h @@ -76,7 +76,7 @@ typedef struct { bool transparent; } BlockSurface; -class Display { +class Graphics { friend class MoviePlayer; private: @@ -174,15 +174,12 @@ private: int32 decompressRLE16(uint8 *dest, uint8 *source, int32 decompSize, uint8 *colTable); public: - Display(int16 width, int16 height); + Graphics(int16 width, int16 height); // Game screen metrics int16 _screenWide; int16 _screenDeep; - int16 _mouseX; - int16 _mouseY; - uint8 _palCopy[256][4]; int8 getRenderLevel(void); diff --git a/sword2/driver/d_sound.cpp b/sword2/driver/d_sound.cpp index c86a14193a..8235d25934 100644 --- a/sword2/driver/d_sound.cpp +++ b/sword2/driver/d_sound.cpp @@ -248,7 +248,7 @@ void Sound::playLeadOut(uint8 *leadOut) { } while (_fx[i]._handle) { - g_display->updateDisplay(); + g_graphics->updateDisplay(); g_system->delay_msecs(30); } } diff --git a/sword2/driver/driver96.h b/sword2/driver/driver96.h index fde513ba77..4ecf614da9 100644 --- a/sword2/driver/driver96.h +++ b/sword2/driver/driver96.h @@ -273,20 +273,6 @@ extern int32 GetLanguageVersion(uint8 *version); extern int32 SetLanguageVersion(uint8 version); //----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -// Mouse functions - from mouse.c -//----------------------------------------------------------------------------- -extern _mouseEvent *MouseEvent(void); -uint8 CheckForMouseEvents(void); -//----------------------------------------------------------------------------- - -//----------------------------------------------------------------------------- -// Keyboard functions - from keyboard.c -//----------------------------------------------------------------------------- -extern bool KeyWaiting(void); -extern int32 ReadKey(_keyboardEvent *ke); -//----------------------------------------------------------------------------- - //----------------------------------------------------------------------------- // Misc functions - from misc.cpp //----------------------------------------------------------------------------- @@ -295,6 +281,46 @@ 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); +#define MAX_MOUSE_EVENTS 16 + +// Key buffer size +#define MAX_KEY_BUFFER 32 + +class Input { + uint8 _mouseBacklog; + uint8 _mouseLogPos; + _mouseEvent _mouseLog[MAX_MOUSE_EVENTS]; + + void logMouseEvent(uint16 buttons); + + // The number of key presses waiting to be processed. + uint8 _keyBacklog; + + // Index of the next key to read from the buffer. + uint8 _keyLogPos; + + // The keyboard buffer + _keyboardEvent _keyBuffer[MAX_KEY_BUFFER]; + + void writeKey(uint16 ascii, int keycode, int modifiers); + +public: + int16 _mouseX; + int16 _mouseY; + + Input() : + _mouseBacklog(0), _mouseLogPos(0), _keyBacklog(0), + _keyLogPos(0) {}; + + void parseEvents(void); + + _mouseEvent *mouseEvent(void); + bool checkForMouseEvents(void); + + bool keyWaiting(void); + int32 readKey(_keyboardEvent *ev); +}; + } // End of namespace Sword2 #endif diff --git a/sword2/driver/keyboard.cpp b/sword2/driver/keyboard.cpp index d5f5e90f0c..8645f5b10d 100644 --- a/sword2/driver/keyboard.cpp +++ b/sword2/driver/keyboard.cpp @@ -22,22 +22,14 @@ namespace Sword2 { -// Key buffer size -#define MAX_KEY_BUFFER 32 - -uint8 keyBacklog = 0; // The number of key presses waiting to be processed. -uint8 keyPointer = 0; // Index of the next key to read from the buffer. - -_keyboardEvent keyBuffer[MAX_KEY_BUFFER]; // The keyboard buffer - -void WriteKey(uint16 ascii, int keycode, int modifiers) { - if (keyBuffer && keyBacklog < MAX_KEY_BUFFER) { - _keyboardEvent *slot = &keyBuffer[(keyPointer + keyBacklog) % MAX_KEY_BUFFER]; +void Input::writeKey(uint16 ascii, int keycode, int modifiers) { + if (_keyBuffer && _keyBacklog < MAX_KEY_BUFFER) { + _keyboardEvent *slot = &_keyBuffer[(_keyLogPos + _keyBacklog) % MAX_KEY_BUFFER]; slot->ascii = ascii; slot->keycode = keycode; slot->modifiers = modifiers; - keyBacklog++; + _keyBacklog++; } } @@ -45,8 +37,8 @@ void WriteKey(uint16 ascii, int keycode, int modifiers) { * @return true if there is an unprocessed key waiting in the queue */ -bool KeyWaiting(void) { - return keyBacklog != 0; +bool Input::keyWaiting(void) { + return _keyBacklog != 0; } /** @@ -54,24 +46,23 @@ bool KeyWaiting(void) { * @return RD_OK, or an error code to indicate there is no key waiting. */ -int32 ReadKey(_keyboardEvent *ev) { - if (!keyBacklog) +int32 Input::readKey(_keyboardEvent *ev) { + if (!_keyBacklog) return RDERR_NOKEYWAITING; if (ev == NULL) return RDERR_INVALIDPOINTER; - ev->ascii = keyBuffer[keyPointer].ascii; - ev->keycode = keyBuffer[keyPointer].keycode; - ev->modifiers = keyBuffer[keyPointer].modifiers; - - keyPointer++; + ev->ascii = _keyBuffer[_keyLogPos].ascii; + ev->keycode = _keyBuffer[_keyLogPos].keycode; + ev->modifiers = _keyBuffer[_keyLogPos].modifiers; - if (keyPointer == MAX_KEY_BUFFER) - keyPointer = 0; + _keyLogPos++; - keyBacklog--; + if (_keyLogPos == MAX_KEY_BUFFER) + _keyLogPos = 0; + _keyBacklog--; return RD_OK; } diff --git a/sword2/driver/menu.cpp b/sword2/driver/menu.cpp index 54a87c20ac..341fb85de9 100644 --- a/sword2/driver/menu.cpp +++ b/sword2/driver/menu.cpp @@ -29,7 +29,7 @@ namespace Sword2 { #define MENUDEEP 40 #define MAXMENUANIMS 8 -void Display::clearIconArea(int menu, int pocket, Common::Rect *r) { +void Graphics::clearIconArea(int menu, int pocket, Common::Rect *r) { byte *dst; int i; @@ -52,7 +52,7 @@ void Display::clearIconArea(int menu, int pocket, Common::Rect *r) { * system is. */ -void Display::processMenu(void) { +void Graphics::processMenu(void) { byte *src, *dst; uint8 menu; uint8 i, j; @@ -199,7 +199,7 @@ void Display::processMenu(void) { * @return RD_OK, or an error code */ -int32 Display::showMenu(uint8 menu) { +int32 Graphics::showMenu(uint8 menu) { // Check for invalid menu parameter if (menu > RDMENU_BOTTOM) return RDERR_INVALIDMENU; @@ -219,7 +219,7 @@ int32 Display::showMenu(uint8 menu) { * @return RD_OK, or an error code */ -int32 Display::hideMenu(uint8 menu) { +int32 Graphics::hideMenu(uint8 menu) { // Check for invalid menu parameter if (menu > RDMENU_BOTTOM) return RDERR_INVALIDMENU; @@ -237,7 +237,7 @@ int32 Display::hideMenu(uint8 menu) { * This function hides both menus immediately. */ -void Display::closeMenuImmediately(void) { +void Graphics::closeMenuImmediately(void) { Common::Rect r; int i; @@ -266,7 +266,7 @@ void Display::closeMenuImmediately(void) { * @return RD_OK, or an error code */ -int32 Display::setMenuIcon(uint8 menu, uint8 pocket, uint8 *icon) { +int32 Graphics::setMenuIcon(uint8 menu, uint8 pocket, uint8 *icon) { Common::Rect r; // Check for invalid menu parameter. diff --git a/sword2/driver/palette.cpp b/sword2/driver/palette.cpp index aa0f860a62..a4098426b3 100644 --- a/sword2/driver/palette.cpp +++ b/sword2/driver/palette.cpp @@ -26,7 +26,7 @@ namespace Sword2 { -uint8 Display::getMatch(uint8 r, uint8 g, uint8 b) { +uint8 Graphics::getMatch(uint8 r, uint8 g, uint8 b) { int32 diff; int32 min; int16 diffred, diffgreen, diffblue; @@ -67,7 +67,7 @@ uint8 Display::getMatch(uint8 r, uint8 g, uint8 b) { * from the current palCopy */ -void Display::updatePaletteMatchTable(uint8 *data) { +void Graphics::updatePaletteMatchTable(uint8 *data) { if (!data) { int16 red, green, blue; uint8 *p; @@ -101,7 +101,7 @@ void Display::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 Display::quickMatch(uint8 r, uint8 g, uint8 b) { +uint8 Graphics::quickMatch(uint8 r, uint8 g, uint8 b) { return _paletteMatch[((int32) (r >> 2) << 12) + ((int32) (g >> 2) << 6) + (b >> 2)]; } @@ -112,7 +112,7 @@ uint8 Display::quickMatch(uint8 r, uint8 g, uint8 b) { * @param colourTable the new colour entries */ -void Display::setPalette(int16 startEntry, int16 noEntries, uint8 *colourTable, uint8 fadeNow) { +void Graphics::setPalette(int16 startEntry, int16 noEntries, uint8 *colourTable, uint8 fadeNow) { if (noEntries) { memcpy(&_palCopy[startEntry][0], colourTable, noEntries * 4); if (fadeNow == RDPAL_INSTANT) @@ -121,7 +121,7 @@ void Display::setPalette(int16 startEntry, int16 noEntries, uint8 *colourTable, g_system->set_palette((const byte *) _palCopy, 0, 256); } -void Display::dimPalette(void) { +void Graphics::dimPalette(void) { byte *p = (byte *) _palCopy; for (int i = 0; i < 256 * 4; i++) @@ -135,7 +135,7 @@ void Display::dimPalette(void) { * @param time the time it will take the palette to fade up */ -int32 Display::fadeUp(float time) { +int32 Graphics::fadeUp(float time) { if (getFadeStatus() != RDFADE_BLACK && getFadeStatus() != RDFADE_NONE) return RDERR_FADEINCOMPLETE; @@ -151,7 +151,7 @@ int32 Display::fadeUp(float time) { * @param time the time it will take the palette to fade down */ -int32 Display::fadeDown(float time) { +int32 Graphics::fadeDown(float time) { if (getFadeStatus() != RDFADE_BLACK && getFadeStatus() != RDFADE_NONE) return RDERR_FADEINCOMPLETE; @@ -168,18 +168,18 @@ int32 Display::fadeDown(float time) { * (not faded), or RDFADE_BLACK (completely faded down) */ -uint8 Display::getFadeStatus(void) { +uint8 Graphics::getFadeStatus(void) { return _fadeStatus; } -void Display::waitForFade(void) { +void Graphics::waitForFade(void) { while (getFadeStatus() != RDFADE_NONE && getFadeStatus() != RDFADE_BLACK) { updateDisplay(); g_system->delay_msecs(20); } } -void Display::fadeServer(void) { +void Graphics::fadeServer(void) { static int32 previousTime = 0; const byte *newPalette = (const byte *) _fadePalette; int32 currentTime; diff --git a/sword2/driver/rdwin.cpp b/sword2/driver/rdwin.cpp index 911bc1b646..050e8b3021 100644 --- a/sword2/driver/rdwin.cpp +++ b/sword2/driver/rdwin.cpp @@ -20,8 +20,6 @@ #include "common/stdafx.h" #include "sword2/sword2.h" #include "sword2/driver/driver96.h" -#include "sword2/driver/_mouse.h" -#include "sword2/driver/keyboard.h" #include "sword2/driver/d_draw.h" #include "sword2/driver/render.h" #include "sword2/driver/menu.h" @@ -33,29 +31,29 @@ namespace Sword2 { // OSystem Event Handler. Full of cross platform goodness and 99% fat free! // --------------------------------------------------------------------------- -void Sword2Engine::parseEvents() { +void Input::parseEvents(void) { OSystem::Event event; - while (_system->poll_event(&event)) { - switch(event.event_code) { + while (g_system->poll_event(&event)) { + switch (event.event_code) { case OSystem::EVENT_KEYDOWN: - WriteKey(event.kbd.ascii, event.kbd.keycode, event.kbd.flags); + writeKey(event.kbd.ascii, event.kbd.keycode, event.kbd.flags); break; case OSystem::EVENT_MOUSEMOVE: - g_display->_mouseX = event.mouse.x; - g_display->_mouseY = event.mouse.y - MENUDEEP; + _mouseX = event.mouse.x; + _mouseY = event.mouse.y - MENUDEEP; break; case OSystem::EVENT_LBUTTONDOWN: - LogMouseEvent(RD_LEFTBUTTONDOWN); + logMouseEvent(RD_LEFTBUTTONDOWN); break; case OSystem::EVENT_RBUTTONDOWN: - LogMouseEvent(RD_RIGHTBUTTONDOWN); + logMouseEvent(RD_RIGHTBUTTONDOWN); break; case OSystem::EVENT_LBUTTONUP: - LogMouseEvent(RD_LEFTBUTTONUP); + logMouseEvent(RD_LEFTBUTTONUP); break; case OSystem::EVENT_RBUTTONUP: - LogMouseEvent(RD_RIGHTBUTTONUP); + logMouseEvent(RD_RIGHTBUTTONUP); break; case OSystem::EVENT_QUIT: g_sword2->closeGame(); @@ -66,7 +64,7 @@ void Sword2Engine::parseEvents() { } } -void Display::setNeedFullRedraw() { +void Graphics::setNeedFullRedraw() { _needFullRedraw = true; } @@ -75,8 +73,8 @@ void Display::setNeedFullRedraw() { * windows and the interface it provides. */ -void Display::updateDisplay(void) { - g_sword2->parseEvents(); +void Graphics::updateDisplay(void) { + g_input->parseEvents(); fadeServer(); // FIXME: We re-render the entire picture area of the screen for each @@ -95,7 +93,7 @@ void Display::updateDisplay(void) { * Set the window title */ -void Display::setWindowName(const char *windowName) { +void Graphics::setWindowName(const char *windowName) { OSystem::Property prop; prop.caption = windowName; diff --git a/sword2/driver/render.cpp b/sword2/driver/render.cpp index eb58c9b96d..71f01befea 100644 --- a/sword2/driver/render.cpp +++ b/sword2/driver/render.cpp @@ -20,7 +20,6 @@ #include "stdafx.h" #include "sword2/driver/driver96.h" #include "sword2/driver/d_draw.h" -#include "sword2/driver/_mouse.h" #include "sword2/driver/render.h" #include "sword2/driver/menu.h" #include "sword2/sword2.h" @@ -32,13 +31,13 @@ namespace Sword2 { #define BLOCKWBITS 6 #define BLOCKHBITS 6 -void Display::updateRect(Common::Rect *r) { +void Graphics::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 Display::blitBlockSurface(BlockSurface *s, Common::Rect *r, Common::Rect *clip_rect) { +void Graphics::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; @@ -78,7 +77,7 @@ void Display::blitBlockSurface(BlockSurface *s, Common::Rect *r, Common::Rect *c } // UploadRect(r); - g_display->setNeedFullRedraw(); + setNeedFullRedraw(); } // I've made the scaling two separate functions because there were cases from @@ -94,7 +93,7 @@ void Display::blitBlockSurface(BlockSurface *s, Common::Rect *r, Common::Rect *c // 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 Display::squashImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight, byte *src, uint16 srcPitch, uint16 srcWidth, uint16 srcHeight, byte *backbuf) { +void Graphics::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; @@ -189,7 +188,7 @@ void Display::squashImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 ds } } -void Display::stretchImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight, byte *src, uint16 srcPitch, uint16 srcWidth, uint16 srcHeight, byte *backbuf) { +void Graphics::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; @@ -335,7 +334,7 @@ void Display::stretchImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 d * @param colour colour of the point */ -void Display::plotPoint(uint16 x, uint16 y, uint8 colour) { +void Graphics::plotPoint(uint16 x, uint16 y, uint8 colour) { uint8 *buf = _buffer + 40 * RENDERWIDE; int16 newx, newy; @@ -356,7 +355,7 @@ void Display::plotPoint(uint16 x, uint16 y, uint8 colour) { */ // Uses Bressnham's incremental algorithm! -void Display::drawLine(int16 x0, int16 y0, int16 x1, int16 y1, uint8 colour) { +void Graphics::drawLine(int16 x0, int16 y0, int16 x1, int16 y1, uint8 colour) { uint8 *buf = _buffer + 40 * RENDERWIDE; int dx, dy; int dxmod, dymod; @@ -519,7 +518,7 @@ void Display::drawLine(int16 x0, int16 y0, int16 x1, int16 y1, uint8 colour) { * @param h height of the current location */ -void Display::setLocationMetrics(uint16 w, uint16 h) { +void Graphics::setLocationMetrics(uint16 w, uint16 h) { _locationWide = w; _locationDeep = h; } @@ -529,7 +528,7 @@ void Display::setLocationMetrics(uint16 w, uint16 h) { * parallax can be either foreground, background or the main screen. */ -void Display::renderParallax(_parallax *p, int16 l) { +void Graphics::renderParallax(_parallax *p, int16 l) { int16 x, y; Common::Rect r; @@ -575,7 +574,7 @@ void Display::renderParallax(_parallax *p, int16 l) { * Initialises the timers before the render loop is entered. */ -void Display::initialiseRenderCycle(void) { +void Graphics::initialiseRenderCycle(void) { _initialTime = SVM_timeGetTime(); _totalTime = _initialTime + MILLISECSPERCYCLE; } @@ -585,7 +584,7 @@ void Display::initialiseRenderCycle(void) { * render cycle. */ -void Display::startRenderCycle(void) { +void Graphics::startRenderCycle(void) { _scrollXOld = _scrollX; _scrollYOld = _scrollY; @@ -610,7 +609,7 @@ void Display::startRenderCycle(void) { * terminated, or false if it should continue */ -bool Display::endRenderCycle(void) { +bool Graphics::endRenderCycle(void) { static int32 renderTimeLog[4] = { 60, 60, 60, 60 }; static int32 renderCountIndex = 0; int32 time; @@ -668,7 +667,7 @@ bool Display::endRenderCycle(void) { * position in the allotted time. */ -void Display::setScrollTarget(int16 sx, int16 sy) { +void Graphics::setScrollTarget(int16 sx, int16 sy) { _scrollXTarget = sx; _scrollYTarget = sy; } @@ -678,7 +677,7 @@ void Display::setScrollTarget(int16 sx, int16 sy) { * or a NULL pointer in order of background parallax to foreground parallax. */ -int32 Display::initialiseBackgroundLayer(_parallax *p) { +int32 Graphics::initialiseBackgroundLayer(_parallax *p) { uint8 *memchunk; uint8 zeros; uint16 count; @@ -804,7 +803,7 @@ int32 Display::initialiseBackgroundLayer(_parallax *p) { * Should be called once after leaving the room to free up memory. */ -void Display::closeBackgroundLayer(void) { +void Graphics::closeBackgroundLayer(void) { debug(2, "CloseBackgroundLayer"); for (int j = 0; j < MAXLAYERS; j++) { diff --git a/sword2/driver/sprite.cpp b/sword2/driver/sprite.cpp index c7bf74177f..c9e21f6639 100644 --- a/sword2/driver/sprite.cpp +++ b/sword2/driver/sprite.cpp @@ -32,7 +32,7 @@ namespace Sword2 { * @param h height of the sprite */ -void Display::mirrorSprite(uint8 *dst, uint8 *src, int16 w, int16 h) { +void Graphics::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); @@ -49,7 +49,7 @@ void Display::mirrorSprite(uint8 *dst, uint8 *src, int16 w, int16 h) { * @param decompSize the expected size of the decompressed sprite */ -int32 Display::decompressRLE256(uint8 *dest, uint8 *source, int32 decompSize) { +int32 Graphics::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 @@ -129,7 +129,7 @@ int32 Display::decompressRLE256(uint8 *dest, uint8 *source, int32 decompSize) { * Unwinds a run of 16-colour data into 256-colour palette data. */ -void Display::unwindRaw16(uint8 *dest, uint8 *source, uint8 blockSize, uint8 *colTable) { +void Graphics::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 @@ -164,7 +164,7 @@ void Display::unwindRaw16(uint8 *dest, uint8 *source, uint8 blockSize, uint8 *co * @param colTable mapping from the 16 encoded colours to the current palette */ -int32 Display::decompressRLE16(uint8 *dest, uint8 *source, int32 decompSize, uint8 *colTable) { +int32 Graphics::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; @@ -244,7 +244,7 @@ int32 Display::decompressRLE16(uint8 *dest, uint8 *source, int32 decompSize, uin * @return RD_OK, or an error code */ -int32 Display::createSurface(_spriteInfo *s, uint8 **sprite) { +int32 Graphics::createSurface(_spriteInfo *s, uint8 **sprite) { uint8 *newSprite; *sprite = (uint8 *) malloc(s->w * s->h); @@ -288,7 +288,7 @@ int32 Display::createSurface(_spriteInfo *s, uint8 **sprite) { * @param clipRect the clipping rectangle */ -void Display::drawSurface(_spriteInfo *s, uint8 *surface, Common::Rect *clipRect) { +void Graphics::drawSurface(_spriteInfo *s, uint8 *surface, Common::Rect *clipRect) { Common::Rect rd, rs; uint16 x, y, srcPitch; uint8 *src, *dst; @@ -356,7 +356,7 @@ void Display::drawSurface(_spriteInfo *s, uint8 *surface, Common::Rect *clipRect * Destroys a surface. */ -void Display::deleteSurface(uint8 *surface) { +void Graphics::deleteSurface(uint8 *surface) { free(surface); } @@ -381,7 +381,7 @@ void Display::deleteSurface(uint8 *surface) { // FIXME: I'm sure this could be optimized. There's plenty of data copying and // mallocing here. -int32 Display::drawSprite(_spriteInfo *s) { +int32 Graphics::drawSprite(_spriteInfo *s) { uint8 *src, *dst; uint8 *sprite, *newSprite; uint8 *backbuf = NULL; @@ -676,7 +676,7 @@ int32 Display::drawSprite(_spriteInfo *s) { * Opens the light masking sprite for a room. */ -int32 Display::openLightMask(_spriteInfo *s) { +int32 Graphics::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 @@ -699,7 +699,7 @@ int32 Display::openLightMask(_spriteInfo *s) { * Closes the light masking sprite for a room. */ -int32 Display::closeLightMask(void) { +int32 Graphics::closeLightMask(void) { if (!_lightMask) return RDERR_NOTOPEN; diff --git a/sword2/function.cpp b/sword2/function.cpp index ae31b0d911..9cd475d2cf 100644 --- a/sword2/function.cpp +++ b/sword2/function.cpp @@ -266,25 +266,25 @@ int32 Logic::fnFlash(int32 *params) { // what colour? switch (params[0]) { case WHITE: - g_display->setPalette(0, 1, white, RDPAL_INSTANT); + g_graphics->setPalette(0, 1, white, RDPAL_INSTANT); break; case RED: - g_display->setPalette(0, 1, red, RDPAL_INSTANT); + g_graphics->setPalette(0, 1, red, RDPAL_INSTANT); break; case GREEN: - g_display->setPalette(0, 1, green, RDPAL_INSTANT); + g_graphics->setPalette(0, 1, green, RDPAL_INSTANT); break; case BLUE: - g_display->setPalette(0, 1, blue, RDPAL_INSTANT); + g_graphics->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. - g_display->updateDisplay(); + g_graphics->updateDisplay(); g_system->delay_msecs(250); - g_display->setPalette(0, 1, black, RDPAL_INSTANT); + g_graphics->setPalette(0, 1, black, RDPAL_INSTANT); #endif return IR_CONT; @@ -302,19 +302,19 @@ int32 Logic::fnColour(int32 *params) { // what colour? switch (params[0]) { case BLACK: - g_display->setPalette(0, 1, black, RDPAL_INSTANT); + g_graphics->setPalette(0, 1, black, RDPAL_INSTANT); break; case WHITE: - g_display->setPalette(0, 1, white, RDPAL_INSTANT); + g_graphics->setPalette(0, 1, white, RDPAL_INSTANT); break; case RED: - g_display->setPalette(0, 1, red, RDPAL_INSTANT); + g_graphics->setPalette(0, 1, red, RDPAL_INSTANT); break; case GREEN: - g_display->setPalette(0, 1, green, RDPAL_INSTANT); + g_graphics->setPalette(0, 1, green, RDPAL_INSTANT); break; case BLUE: - g_display->setPalette(0, 1, blue, RDPAL_INSTANT); + g_graphics->setPalette(0, 1, blue, RDPAL_INSTANT); break; } #endif @@ -393,17 +393,17 @@ int32 Logic::fnPlayCredits(int32 *params) { g_sound->muteSpeech(true); g_sound->stopMusic(); - memcpy(oldPal, g_display->_palCopy, 1024); + memcpy(oldPal, g_graphics->_palCopy, 1024); memset(tmpPal, 0, 1024); - g_display->waitForFade(); - g_display->fadeDown(); - g_display->waitForFade(); + g_graphics->waitForFade(); + g_graphics->fadeDown(); + g_graphics->waitForFade(); tmpPal[4] = 255; tmpPal[5] = 255; tmpPal[6] = 255; - g_display->setPalette(0, 256, tmpPal, RDPAL_INSTANT); + g_graphics->setPalette(0, 256, tmpPal, RDPAL_INSTANT); // Play the credits music. Is it enough with just one // repetition of it? @@ -416,21 +416,21 @@ int32 Logic::fnPlayCredits(int32 *params) { debug(0, "Credits music length: ~%d ms", music_length); - g_display->closeMenuImmediately(); + g_graphics->closeMenuImmediately(); while (g_sound->musicTimeRemaining()) { - g_display->clearScene(); - g_display->setNeedFullRedraw(); + g_graphics->clearScene(); + g_graphics->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. - g_display->updateDisplay(); + g_graphics->updateDisplay(); _keyboardEvent ke; - if (ReadKey(&ke) == RD_OK && ke.keycode == 27) + if (g_input->readKey(&ke) == RD_OK && ke.keycode == 27) break; g_system->delay_msecs(30); @@ -439,11 +439,11 @@ int32 Logic::fnPlayCredits(int32 *params) { fnStopMusic(NULL); g_sound->restoreMusicState(); - g_display->setPalette(0, 256, oldPal, RDPAL_FADE); - g_display->fadeUp(); - g_display->updateDisplay(); + g_graphics->setPalette(0, 256, oldPal, RDPAL_FADE); + g_graphics->fadeUp(); + g_graphics->updateDisplay(); _vm->buildDisplay(); - g_display->waitForFade(); + g_graphics->waitForFade(); g_sound->muteFx(false); g_sound->muteSpeech(false); diff --git a/sword2/icons.cpp b/sword2/icons.cpp index ced71c1825..e3e9412208 100644 --- a/sword2/icons.cpp +++ b/sword2/icons.cpp @@ -199,16 +199,16 @@ void Sword2Engine::buildMenu(void) { if (icon_coloured) icon += (RDMENU_ICONWIDE * RDMENU_ICONDEEP); - g_display->setMenuIcon(RDMENU_BOTTOM, j, icon); + g_graphics->setMenuIcon(RDMENU_BOTTOM, j, icon); res_man->closeResource(res); } else { // no icon here - g_display->setMenuIcon(RDMENU_BOTTOM, j, NULL); + g_graphics->setMenuIcon(RDMENU_BOTTOM, j, NULL); debug(5, " NULL for %d", j); } } - g_display->showMenu(RDMENU_BOTTOM); + g_graphics->showMenu(RDMENU_BOTTOM); } void Sword2Engine::buildSystemMenu(void) { @@ -236,11 +236,11 @@ void Sword2Engine::buildSystemMenu(void) { if (!DEAD || icon_list[i] != SAVE_ICON) icon += (RDMENU_ICONWIDE * RDMENU_ICONDEEP); - g_display->setMenuIcon(RDMENU_TOP, i, icon); + g_graphics->setMenuIcon(RDMENU_TOP, i, icon); res_man->closeResource(icon_list[i]); } - g_display->showMenu(RDMENU_TOP); + g_graphics->showMenu(RDMENU_TOP); } } // End of namespace Sword2 diff --git a/sword2/layers.cpp b/sword2/layers.cpp index 7bbcd09bb5..3216207a05 100644 --- a/sword2/layers.cpp +++ b/sword2/layers.cpp @@ -69,11 +69,11 @@ int32 Sword2Engine::initBackground(int32 res, int32 new_palette) { #endif // if the screen is still fading down then wait for black - g_display->waitForFade(); + g_graphics->waitForFade(); // if last screen was using a shading mask (see below) if (_thisScreen.mask_flag) { - rv = g_display->closeLightMask(); + rv = g_graphics->closeLightMask(); if (rv) error("Driver Error %.8x", rv); } @@ -82,7 +82,7 @@ int32 Sword2Engine::initBackground(int32 res, int32 new_palette) { // for drivers: close the previous screen if one is open if (_thisScreen.background_layer_id) - g_display->closeBackgroundLayer(); + g_graphics->closeBackgroundLayer(); _thisScreen.background_layer_id = res; _thisScreen.new_palette = new_palette; @@ -104,7 +104,7 @@ int32 Sword2Engine::initBackground(int32 res, int32 new_palette) { debug(5, "res test layers=%d width=%d depth=%d", screen_head->noLayers, screen_head->width, screen_head->height); //initialise the driver back buffer - g_display->setLocationMetrics(screen_head->width, screen_head->height); + g_graphics->setLocationMetrics(screen_head->width, screen_head->height); if (screen_head->noLayers) { for (int i = 0; i < screen_head->noLayers; i++) { @@ -126,7 +126,7 @@ int32 Sword2Engine::initBackground(int32 res, int32 new_palette) { // using the screen size setup the scrolling variables // if layer is larger than physical screen - if (screen_head->width > g_display->_screenWide || screen_head->height > g_display->_screenDeep) { + if (screen_head->width > g_graphics->_screenWide || screen_head->height > g_graphics->_screenDeep) { // switch on scrolling (2 means first time on screen) _thisScreen.scroll_flag = 2; @@ -141,9 +141,9 @@ int32 Sword2Engine::initBackground(int32 res, int32 new_palette) { // calc max allowed offsets (to prevent scrolling off edge) - // MOVE TO NEW_SCREEN in GTM_CORE.C !! // NB. min scroll offsets are both zero - _thisScreen.max_scroll_offset_x = screen_head->width - g_display->_screenWide; + _thisScreen.max_scroll_offset_x = screen_head->width - g_graphics->_screenWide; // 'screenDeep' includes the menu's, so take away 80 pixels - _thisScreen.max_scroll_offset_y = screen_head->height - (g_display->_screenDeep - (RDMENU_MENUDEEP * 2)); + _thisScreen.max_scroll_offset_y = screen_head->height - (g_graphics->_screenDeep - (RDMENU_MENUDEEP * 2)); } else { // layer fits on physical screen - scrolling not required _thisScreen.scroll_flag = 0; // switch off scrolling @@ -153,7 +153,7 @@ int32 Sword2Engine::initBackground(int32 res, int32 new_palette) { // no inter-cycle scroll between new screens (see setScrollTarget in // build display) - g_display->resetRenderEngine(); + g_graphics->resetRenderEngine(); // these are the physical screen coords where the system // will try to maintain George's actual feet coords @@ -177,7 +177,7 @@ int32 Sword2Engine::initBackground(int32 res, int32 new_palette) { spriteInfo.data = fetchShadingMask(file); spriteInfo.colourTable = 0; - rv = g_display->openLightMask(&spriteInfo); + rv = g_graphics->openLightMask(&spriteInfo); if (rv) error("Driver Error %.8x", rv); @@ -221,22 +221,22 @@ void Sword2Engine::setUpBackgroundLayers(void) { for (i = 0; i < 2; i++) { if (screenLayerTable->bg_parallax[i]) - g_display->initialiseBackgroundLayer(fetchBackgroundParallaxLayer(file, i)); + g_graphics->initialiseBackgroundLayer(fetchBackgroundParallaxLayer(file, i)); else - g_display->initialiseBackgroundLayer(NULL); + g_graphics->initialiseBackgroundLayer(NULL); } // Normal backround layer - g_display->initialiseBackgroundLayer(fetchBackgroundLayer(file)); + g_graphics->initialiseBackgroundLayer(fetchBackgroundLayer(file)); // Foreground parallax layers for (i = 0; i < 2; i++) { if (screenLayerTable->fg_parallax[i]) - g_display->initialiseBackgroundLayer(fetchForegroundParallaxLayer(file, i)); + g_graphics->initialiseBackgroundLayer(fetchForegroundParallaxLayer(file, i)); else - g_display->initialiseBackgroundLayer(NULL); + g_graphics->initialiseBackgroundLayer(NULL); } // close the screen file diff --git a/sword2/logic.cpp b/sword2/logic.cpp index be4b7bc60b..e786f24f86 100644 --- a/sword2/logic.cpp +++ b/sword2/logic.cpp @@ -30,7 +30,7 @@ namespace Sword2 { -Logic *g_logic; +Logic *g_logic = NULL; #define LEVEL (_curObjectHub->logic_level) diff --git a/sword2/maketext.cpp b/sword2/maketext.cpp index a8466610ff..40d18b5764 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 = g_display->drawSprite(&spriteInfo); + rv = g_graphics->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" - g_display->setWindowName((char *) textLine); + g_graphics->setWindowName((char *) textLine); // now ok to close the text file res_man->closeResource(TEXT_RES); diff --git a/sword2/mouse.cpp b/sword2/mouse.cpp index 32bb757734..eae9cd1673 100644 --- a/sword2/mouse.cpp +++ b/sword2/mouse.cpp @@ -110,7 +110,7 @@ void Sword2Engine::mouseEngine(void) { systemMenuMouse(); break; case MOUSE_holding: - if (g_display->_mouseY < 400) { + if (_input->_mouseY < 400) { _mouseMode = MOUSE_normal; debug(5, " releasing"); } @@ -135,21 +135,21 @@ void Sword2Engine::systemMenuMouse(void) { }; // can't close when player is dead - if (g_display->_mouseY > 0 && !DEAD) { + if (_input->_mouseY > 0 && !DEAD) { // close menu _mouseMode = MOUSE_normal; - g_display->hideMenu(RDMENU_TOP); + g_graphics->hideMenu(RDMENU_TOP); return; } - me = MouseEvent(); + me = g_input->mouseEvent(); if (me && (me->buttons & RD_LEFTBUTTONDOWN)) { // clicked on a top mouse pointer? - if (g_display->_mouseX >= 24 && g_display->_mouseX < 640 - 24 && g_display->_mouseY < 0) { + if (_input->_mouseX >= 24 && _input->_mouseX < 640 - 24 && _input->_mouseY < 0) { // which are we over? - hit = (g_display->_mouseX - 24) / 40; + hit = (_input->_mouseX - 24) / 40; // no save when dead if (icon_list[hit] == SAVE_ICON && DEAD) @@ -163,7 +163,7 @@ void Sword2Engine::systemMenuMouse(void) { // change all others to grey if (j != hit) { icon = res_man->openResource(icon_list[j]) + sizeof(_standardHeader); - g_display->setMenuIcon(RDMENU_TOP, j, icon); + g_graphics->setMenuIcon(RDMENU_TOP, j, icon); res_man->closeResource(icon_list[j]); } } @@ -188,9 +188,9 @@ void Sword2Engine::systemMenuMouse(void) { // clear the screen & set up the new palette // for the menus - g_display->clearScene(); - g_display->processMenu(); - g_display->resetRenderEngine(); + g_graphics->clearScene(); + g_graphics->processMenu(); + g_graphics->resetRenderEngine(); // call the relevent screen switch (hit) { @@ -214,7 +214,7 @@ void Sword2Engine::systemMenuMouse(void) { // Menu stays open on death screen if (!DEAD) { _mouseMode = MOUSE_normal; - g_display->hideMenu(RDMENU_TOP); + g_graphics->hideMenu(RDMENU_TOP); } else { setMouse(NORMAL_MOUSE_ID); buildSystemMenu(); @@ -223,8 +223,8 @@ void Sword2Engine::systemMenuMouse(void) { // clear the screen & restore the location // palette - g_display->clearScene(); - g_display->processMenu(); + g_graphics->clearScene(); + g_graphics->processMenu(); // reset game palette, but not after a // successful restore or restart! @@ -272,10 +272,10 @@ void Sword2Engine::dragMouse(void) { _mouseEvent *me; uint32 pos; - if (g_display->_mouseY < 400) { + if (_input->_mouseY < 400) { // close menu _mouseMode = MOUSE_normal; - g_display->hideMenu(RDMENU_BOTTOM); + g_graphics->hideMenu(RDMENU_BOTTOM); return; } @@ -284,7 +284,7 @@ void Sword2Engine::dragMouse(void) { // now do the normal click stuff - me = MouseEvent(); + me = g_input->mouseEvent(); // we only care about left clicks when the mouse is over an object // we ignore mouse releases @@ -311,8 +311,8 @@ void Sword2Engine::dragMouse(void) { // these might be required by the action script about // to be run - MOUSE_X = (uint32) g_display->_mouseX + _thisScreen.scroll_offset_x; - MOUSE_Y = (uint32) g_display->_mouseY + _thisScreen.scroll_offset_y; + MOUSE_X = (uint32) _input->_mouseX + _thisScreen.scroll_offset_x; + MOUSE_Y = (uint32) _input->_mouseY + _thisScreen.scroll_offset_y; // for scripts to know what's been clicked (21jan97). // First used for 'room_13_turning_script' in object @@ -326,14 +326,14 @@ void Sword2Engine::dragMouse(void) { // Hide menu - back to normal menu mode - g_display->hideMenu(RDMENU_BOTTOM); + g_graphics->hideMenu(RDMENU_BOTTOM); _mouseMode = MOUSE_normal; } else { // better check for combine/cancel // cancel puts us back in Menu_mouse mode - if (g_display->_mouseX >= 24 && g_display->_mouseX < 640 - 24) { + if (_input->_mouseX >= 24 && _input->_mouseX < 640 - 24) { // which are we over? - pos = (g_display->_mouseX - 24) / 40; + pos = (_input->_mouseX - 24) / 40; //clicked on something - what button? if (_masterMenuList[pos].icon_resource) { @@ -385,14 +385,14 @@ void Sword2Engine::menuMouse(void) { _mouseEvent *me; uint32 pos; - if (g_display->_mouseY < 400) { + if (_input->_mouseY < 400) { // close menu _mouseMode = MOUSE_normal; - g_display->hideMenu(RDMENU_BOTTOM); + g_graphics->hideMenu(RDMENU_BOTTOM); return; } - me = MouseEvent(); + me = g_input->mouseEvent(); // we only care about left clicks when the mouse is over an object // we ignore mouse releases @@ -401,9 +401,9 @@ void Sword2Engine::menuMouse(void) { // there's a mouse event to be processed // now check if we've clicked on an actual icon - if (g_display->_mouseX >= 24 && g_display->_mouseX < 640 - 24) { + if (_input->_mouseX >= 24 && _input->_mouseX < 640 - 24) { // which are we over? - pos = (g_display->_mouseX - 24) / 40; + pos = (_input->_mouseX - 24) / 40; // clicked on something - what button? if (_masterMenuList[pos].icon_resource) { @@ -471,7 +471,7 @@ void Sword2Engine::normalMouse(void) { _mouseEvent *me; // no save in big-object menu lock situation - if (g_display->_mouseY < 0 && !_mouseModeLocked && !OBJECT_HELD) { + if (_input->_mouseY < 0 && !_mouseModeLocked && !OBJECT_HELD) { _mouseMode = MOUSE_system_menu; if (_mouseTouching) { @@ -486,7 +486,7 @@ void Sword2Engine::normalMouse(void) { return; } - if (g_display->_mouseY > 399 && !_mouseModeLocked) { + if (_input->_mouseY > 399 && !_mouseModeLocked) { // 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. @@ -522,7 +522,7 @@ void Sword2Engine::normalMouse(void) { // now do the normal click stuff - me = MouseEvent(); + me = g_input->mouseEvent(); if (_debugger->_definingRectangles) { if (_debugger->_draggingRectangle == 0) { @@ -530,8 +530,8 @@ void Sword2Engine::normalMouse(void) { if (me && (me->buttons & (RD_LEFTBUTTONDOWN | RD_RIGHTBUTTONDOWN))) { // set both (x1,y1) and (x2,y2) to this point - _debugger->_rectX1 = _debugger->_rectX2 = (uint32) g_display->_mouseX + _thisScreen.scroll_offset_x; - _debugger->_rectY1 = _debugger->_rectY2 = (uint32) g_display->_mouseY + _thisScreen.scroll_offset_y; + _debugger->_rectX1 = _debugger->_rectX2 = (uint32) _input->_mouseX + _thisScreen.scroll_offset_x; + _debugger->_rectY1 = _debugger->_rectY2 = (uint32) _input->_mouseY + _thisScreen.scroll_offset_y; _debugger->_draggingRectangle = 1; } } else if (_debugger->_draggingRectangle == 1) { @@ -543,8 +543,8 @@ void Sword2Engine::normalMouse(void) { _debugger->_draggingRectangle = 2; } else { // drag rectangle - _debugger->_rectX2 = (uint32) g_display->_mouseX + _thisScreen.scroll_offset_x; - _debugger->_rectY2 = (uint32) g_display->_mouseY + _thisScreen.scroll_offset_y; + _debugger->_rectX2 = (uint32) _input->_mouseX + _thisScreen.scroll_offset_x; + _debugger->_rectY2 = (uint32) _input->_mouseY + _thisScreen.scroll_offset_y; } } else { // currently locked to avoid knocking out of place @@ -594,8 +594,8 @@ void Sword2Engine::normalMouse(void) { // these might be required by the action script about // to be run - MOUSE_X = (uint32) g_display->_mouseX + _thisScreen.scroll_offset_x; - MOUSE_Y = (uint32) g_display->_mouseY + _thisScreen.scroll_offset_y; + MOUSE_X = (uint32) _input->_mouseX + _thisScreen.scroll_offset_x; + MOUSE_Y = (uint32) _input->_mouseY + _thisScreen.scroll_offset_y; // only left button if (_mouseTouching == EXIT_CLICK_ID && (me->buttons & RD_LEFTBUTTONDOWN)) { @@ -650,7 +650,7 @@ void Sword2Engine::mouseOnOff(void) { // don't detect objects that are hidden behind the menu bars (ie. in // the scrolled-off areas of the screen) - if (g_display->_mouseY < 0 || g_display->_mouseY > 399) { + if (_input->_mouseY < 0 || _input->_mouseY > 399) { pointer_type = 0; _mouseTouching = 0; } else { @@ -747,14 +747,14 @@ void Sword2Engine::setMouse(uint32 res) { // loop if (res == NORMAL_MOUSE_ID) - g_display->setMouseAnim(icon, len, RDMOUSE_NOFLASH); + g_graphics->setMouseAnim(icon, len, RDMOUSE_NOFLASH); else - g_display->setMouseAnim(icon, len, RDMOUSE_FLASH); + g_graphics->setMouseAnim(icon, len, RDMOUSE_FLASH); res_man->closeResource(res); } else { // blank cursor - g_display->setMouseAnim(NULL, 0, 0); + g_graphics->setMouseAnim(NULL, 0, 0); } } @@ -768,11 +768,11 @@ void Sword2Engine::setLuggage(uint32 res) { icon = res_man->openResource(res) + sizeof(_standardHeader); len = res_man->_resList[res]->size - sizeof(_standardHeader); - g_display->setLuggageAnim(icon, len); + g_graphics->setLuggageAnim(icon, len); res_man->closeResource(res); } else - g_display->setLuggageAnim(NULL, 0); + g_graphics->setLuggageAnim(NULL, 0); } uint32 Sword2Engine::checkMouseList(void) { @@ -786,10 +786,10 @@ uint32 Sword2Engine::checkMouseList(void) { // mouse-detection-box if (_mouseList[j].priority == priority && - g_display->_mouseX + _thisScreen.scroll_offset_x >= _mouseList[j].x1 && - g_display->_mouseX + _thisScreen.scroll_offset_x <= _mouseList[j].x2 && - g_display->_mouseY + _thisScreen.scroll_offset_y >= _mouseList[j].y1 && - g_display->_mouseY + _thisScreen.scroll_offset_y <= _mouseList[j].y2) { + _input->_mouseX + _thisScreen.scroll_offset_x >= _mouseList[j].x1 && + _input->_mouseX + _thisScreen.scroll_offset_x <= _mouseList[j].x2 && + _input->_mouseY + _thisScreen.scroll_offset_y >= _mouseList[j].y1 && + _input->_mouseY + _thisScreen.scroll_offset_y <= _mouseList[j].y2) { // record id _mouseTouching = _mouseList[j].id; @@ -965,8 +965,8 @@ void Sword2Engine::createPointerText(uint32 text_id, uint32 pointer_res) { // line reference number _pointerTextBlocNo = fontRenderer->buildNewBloc( - text + 2, g_display->_mouseX + xOffset, - g_display->_mouseY + yOffset, + text + 2, _input->_mouseX + xOffset, + _input->_mouseY + yOffset, POINTER_TEXT_WIDTH, POINTER_TEXT_PEN, RDSPR_TRANS | RDSPR_DISPLAYALIGN, _speechFontId, justification); @@ -1042,7 +1042,7 @@ void Sword2Engine::registerMouse(Object_mouse *ob_mouse) { void Sword2Engine::monitorPlayerActivity(void) { // if there is at least one mouse event outstanding - if (CheckForMouseEvents()) { + if (g_input->checkForMouseEvents()) { // reset activity delay counter _playerActivityDelay = 0; } else { @@ -1062,12 +1062,12 @@ int32 Logic::fnNoHuman(int32 *params) { // dont hide menu in conversations if (TALK_FLAG == 0) - g_display->hideMenu(RDMENU_BOTTOM); + g_graphics->hideMenu(RDMENU_BOTTOM); if (_vm->_mouseMode == MOUSE_system_menu) { // close menu _vm->_mouseMode = MOUSE_normal; - g_display->hideMenu(RDMENU_TOP); + g_graphics->hideMenu(RDMENU_TOP); } // script continue @@ -1110,7 +1110,7 @@ int32 Logic::fnAddHuman(int32 *params) { } // if mouse is over menu area - if (g_display->_mouseY > 399) { + if (g_input->_mouseY > 399) { if (_vm->_mouseMode != MOUSE_holding) { // VITAL - reset things & rebuild the menu _vm->_mouseMode = MOUSE_normal; @@ -1129,7 +1129,7 @@ int32 Logic::fnAddHuman(int32 *params) { // testing logic scripts by simulating an instant Save & // Restore - g_display->setPalette(0, 1, white, RDPAL_INSTANT); + g_graphics->setPalette(0, 1, white, RDPAL_INSTANT); // stops all fx & clears the queue - eg. when leaving a // location @@ -1141,7 +1141,7 @@ int32 Logic::fnAddHuman(int32 *params) { res_man->killAllObjects(false); - g_display->setPalette(0, 1, black, RDPAL_INSTANT); + g_graphics->setPalette(0, 1, black, RDPAL_INSTANT); } return IR_CONT; @@ -1228,7 +1228,7 @@ int32 Logic::fnSetScrollRightMouse(int32 *params) { // Highest priority - ob_mouse->x1 = _vm->_thisScreen.scroll_offset_x + g_display->_screenWide - SCROLL_MOUSE_WIDTH; + ob_mouse->x1 = _vm->_thisScreen.scroll_offset_x + g_graphics->_screenWide - SCROLL_MOUSE_WIDTH; ob_mouse->y1 = 0; ob_mouse->x2 = _vm->_thisScreen.screen_wide - 1; ob_mouse->y2 = _vm->_thisScreen.screen_deep - 1; @@ -1265,7 +1265,7 @@ int32 Logic::fnSetObjectHeld(int32 *params) { int32 Logic::fnRemoveChooser(int32 *params) { // params: none - g_display->hideMenu(RDMENU_BOTTOM); + g_graphics->hideMenu(RDMENU_BOTTOM); return IR_CONT; } diff --git a/sword2/resman.cpp b/sword2/resman.cpp index 340ebf3747..5c0c63e055 100644 --- a/sword2/resman.cpp +++ b/sword2/resman.cpp @@ -1019,28 +1019,28 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) { char buf[1024]; sprintf(buf, "%sClusters\\%s", _cdPath, _resourceFiles[newCluster]); - g_display->waitForFade(); + g_graphics->waitForFade(); - if (g_display->getFadeStatus() != RDFADE_BLACK) { - g_display->fadeDown(); - g_display->waitForFade(); + if (g_graphics->getFadeStatus() != RDFADE_BLACK) { + g_graphics->fadeDown(); + g_graphics->waitForFade(); } - g_display->clearScene(); + g_graphics->clearScene(); _vm->setMouse(0); _vm->setLuggage(0); uint8 *bgfile; bgfile = openResource(2950); // open the screen resource - g_display->initialiseBackgroundLayer(NULL); - g_display->initialiseBackgroundLayer(NULL); - g_display->initialiseBackgroundLayer(_vm->fetchBackgroundLayer(bgfile)); - g_display->initialiseBackgroundLayer(NULL); - g_display->initialiseBackgroundLayer(NULL); - g_display->setPalette(0, 256, _vm->fetchPalette(bgfile), RDPAL_FADE); - - g_display->renderParallax(_vm->fetchBackgroundLayer(bgfile), 2); + g_graphics->initialiseBackgroundLayer(NULL); + g_graphics->initialiseBackgroundLayer(NULL); + g_graphics->initialiseBackgroundLayer(_vm->fetchBackgroundLayer(bgfile)); + g_graphics->initialiseBackgroundLayer(NULL); + g_graphics->initialiseBackgroundLayer(NULL); + g_graphics->setPalette(0, 256, _vm->fetchPalette(bgfile), RDPAL_FADE); + + g_graphics->renderParallax(_vm->fetchBackgroundLayer(bgfile), 2); closeResource(2950); // release the screen resource // Git rid of read-only status, if it is set. @@ -1066,8 +1066,8 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) { frame = (_frameHeader*) text_spr->ad; - textSprite.x = g_display->_screenWide /2 - frame->width / 2; - textSprite.y = g_display->_screenDeep /2 - frame->height / 2 - RDMENU_MENUDEEP; + textSprite.x = g_graphics->_screenWide /2 - frame->width / 2; + textSprite.y = g_graphics->_screenDeep /2 - frame->height / 2 - RDMENU_MENUDEEP; textSprite.w = frame->width; textSprite.h = frame->height; textSprite.scale = 0; @@ -1107,17 +1107,17 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) { int16 textX = textSprite.x; int16 textY = textSprite.y; - g_display->drawSprite(&barSprite); + g_graphics->drawSprite(&barSprite); barSprite.x = barX; barSprite.y = barY; textSprite.data = text_spr->ad + sizeof(_frameHeader); - g_display->drawSprite(&textSprite); + g_graphics->drawSprite(&textSprite); textSprite.x = textX; textSprite.y = textY; - g_display->fadeUp(); - g_display->waitForFade(); + g_graphics->fadeUp(); + g_graphics->waitForFade(); uint32 size = inFile.size(); @@ -1139,19 +1139,19 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) { step = 0; // open the screen resource bgfile = openResource(2950); - g_display->renderParallax(_vm->fetchBackgroundLayer(bgfile), 2); + g_graphics->renderParallax(_vm->fetchBackgroundLayer(bgfile), 2); // release the screen resource closeResource(2950); loadingBar = openResource(2951); frame = _vm->fetchFrameHeader(loadingBar, fr); barSprite.data = (uint8 *) (frame + 1); closeResource(2951); - g_display->drawSprite(&barSprite); + g_graphics->drawSprite(&barSprite); barSprite.x = barX; barSprite.y = barY; textSprite.data = text_spr->ad + sizeof(_frameHeader); - g_display->drawSprite(&textSprite); + g_graphics->drawSprite(&textSprite); textSprite.x = textX; textSprite.y = textY; @@ -1159,7 +1159,7 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) { } else step++; - g_display->updateDisplay(); + g_graphics->updateDisplay(); } while ((read % BUFFERSIZE) == 0); if (read != size) { @@ -1170,11 +1170,11 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) { outFile.close(); memory->freeMemory(text_spr); - g_display->clearScene(); + g_graphics->clearScene(); - g_display->fadeDown(); - g_display->waitForFade(); - g_display->fadeUp(); + g_graphics->fadeDown(); + g_graphics->waitForFade(); + g_graphics->fadeUp(); // Git rid of read-only status. SVM_SetFileAttributes(_resourceFiles[newCluster], FILE_ATTRIBUTE_NORMAL); @@ -1291,8 +1291,8 @@ void ResourceManager::getCd(int cd) { frame = (_frameHeader*) text_spr->ad; - spriteInfo.x = g_display->_screenWide / 2 - frame->width / 2; - spriteInfo.y = g_display->_screenDeep / 2 - frame->height / 2 - RDMENU_MENUDEEP; + spriteInfo.x = g_graphics->_screenWide / 2 - frame->width / 2; + spriteInfo.y = g_graphics->_screenDeep / 2 - frame->height / 2 - RDMENU_MENUDEEP; spriteInfo.w = frame->width; spriteInfo.h = frame->height; spriteInfo.scale = 0; @@ -1330,10 +1330,10 @@ void ResourceManager::getCd(int cd) { } } - g_display->updateDisplay(); + g_graphics->updateDisplay(); - g_display->clearScene(); - g_display->drawSprite(&spriteInfo); // Keep the message there even when the user task swaps. + g_graphics->clearScene(); + g_graphics->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/router.cpp b/sword2/router.cpp index 9be82d80ff..7e84a7e7f0 100644 --- a/sword2/router.cpp +++ b/sword2/router.cpp @@ -2530,7 +2530,7 @@ void Router::plotWalkGrid(void) { // lines for (i = 0; i < _nbars; i++) - g_display->drawLine(_bars[i].x1, _bars[i].y1, _bars[i].x2, _bars[i].y2, 254); + g_graphics->drawLine(_bars[i].x1, _bars[i].y1, _bars[i].x2, _bars[i].y2, 254); // nodes @@ -2540,8 +2540,8 @@ void Router::plotWalkGrid(void) { } void Router::plotCross(int16 x, int16 y, uint8 colour) { - g_display->drawLine(x - 1, y - 1, x + 1, y + 1, colour); - g_display->drawLine(x + 1, y - 1, x - 1, y + 1, colour); + g_graphics->drawLine(x - 1, y - 1, x + 1, y + 1, colour); + g_graphics->drawLine(x + 1, y - 1, x - 1, y + 1, colour); } void Router::loadWalkGrid(void) { diff --git a/sword2/speech.cpp b/sword2/speech.cpp index 6b64558b72..f81c31f4a1 100644 --- a/sword2/speech.cpp +++ b/sword2/speech.cpp @@ -172,17 +172,17 @@ int32 Logic::fnChoose(int32 *params) { if (j < IN_SUBJECT) { debug(5, " ICON res %d for %d", _subjectList[j].res, j); icon = res_man->openResource(_subjectList[j].res) + sizeof(_standardHeader) + RDMENU_ICONWIDE * RDMENU_ICONDEEP; - g_display->setMenuIcon(RDMENU_BOTTOM, (uint8) j, icon); + g_graphics->setMenuIcon(RDMENU_BOTTOM, (uint8) j, icon); res_man->closeResource(_subjectList[j].res); } else { //no icon here debug(5, " NULL for %d", j); - g_display->setMenuIcon(RDMENU_BOTTOM, (uint8) j, NULL); + g_graphics->setMenuIcon(RDMENU_BOTTOM, (uint8) j, NULL); } } // start menus appearing - g_display->showMenu(RDMENU_BOTTOM); + g_graphics->showMenu(RDMENU_BOTTOM); // lets have the mouse pointer back _vm->setMouse(NORMAL_MOUSE_ID); @@ -195,7 +195,7 @@ int32 Logic::fnChoose(int32 *params) { // menu is there - we're just waiting for a click debug(5, "choosing"); - me = MouseEvent(); + me = g_input->mouseEvent(); // we only care about left clicks // we ignore mouse releases @@ -205,9 +205,9 @@ int32 Logic::fnChoose(int32 *params) { // if so then end the choose, highlight only the // chosen, blank the mouse and return the ref code * 8 - if (g_display->_mouseY > 399 && g_display->_mouseX >= 24 && g_display->_mouseX < 640 - 24) { + if (g_input->_mouseY > 399 && g_input->_mouseX >= 24 && g_input->_mouseX < 640 - 24) { //which are we over? - hit = (g_display->_mouseX - 24) / 40; + hit = (g_input->_mouseX - 24) / 40; //clicked on something - what button? if (hit < IN_SUBJECT) { @@ -220,7 +220,7 @@ int32 Logic::fnChoose(int32 *params) { // change all others to grey if (j != hit) { icon = res_man->openResource( _subjectList[j].res ) + sizeof(_standardHeader); - g_display->setMenuIcon(RDMENU_BOTTOM, (uint8) j, icon); + g_graphics->setMenuIcon(RDMENU_BOTTOM, (uint8) j, icon); res_man->closeResource(_subjectList[j].res); } } @@ -279,9 +279,9 @@ int32 Logic::fnEndConversation(int32 *params) { // params: none - g_display->hideMenu(RDMENU_BOTTOM); + g_graphics->hideMenu(RDMENU_BOTTOM); - if (g_display->_mouseY > 399) { + if (g_input->_mouseY > 399) { // will wait for cursor to move off the bottom menu _vm->_mouseMode = MOUSE_holding; debug(5, " holding"); @@ -1233,8 +1233,8 @@ int32 Logic::fnISpeak(int32 *params) { // so that we can go to the options panel while text & speech is // being tested - if (SYSTEM_TESTING_TEXT == 0 || g_display->_mouseY > 0) { - me = MouseEvent(); + if (SYSTEM_TESTING_TEXT == 0 || g_input->_mouseY > 0) { + me = g_input->mouseEvent(); // Note that we now have TWO click-delays - one for LEFT // button, one for RIGHT BUTTON @@ -1258,7 +1258,7 @@ int32 Logic::fnISpeak(int32 *params) { do { // trash anything thats buffered - me = MouseEvent(); + me = g_input->mouseEvent(); } while (me); speechFinished = 1; diff --git a/sword2/sword2.cpp b/sword2/sword2.cpp index a63ceb3169..045b27291f 100644 --- a/sword2/sword2.cpp +++ b/sword2/sword2.cpp @@ -98,8 +98,9 @@ REGISTER_PLUGIN("Broken Sword II", Engine_SWORD2_gameList, Engine_SWORD2_create, namespace Sword2 { Sword2Engine *g_sword2 = NULL; +Input *g_input = NULL; Sound *g_sound = NULL; -Display *g_display = NULL; +Graphics *g_graphics = NULL; Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst) : Engine(syst) { @@ -130,8 +131,9 @@ Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst) g_logic = new Logic(this); fontRenderer = new FontRenderer(); gui = new Gui(this); + g_input = _input = new Input(); g_sound = _sound = new Sound(_mixer); - g_display = _display = new Display(640, 480); + g_graphics = _graphics = new Graphics(640, 480); _debugger = new Debugger(this); _lastPaletteRes = 0; @@ -187,8 +189,9 @@ Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst) Sword2Engine::~Sword2Engine() { free(_targetName); delete _debugger; - delete _display; + delete _graphics; delete _sound; + delete _input; delete gui; delete fontRenderer; delete g_logic; @@ -323,7 +326,7 @@ void Sword2Engine::go() { startGame(); debug(5, "CALLING: initialiseRenderCycle"); - g_display->initialiseRenderCycle(); + _graphics->initialiseRenderCycle(); _renderSkip = false; // Toggled on 'S' key, to render only // 1 in 4 frames, to speed up game @@ -334,7 +337,7 @@ void Sword2Engine::go() { if (_debugger->isAttached()) _debugger->onFrame(); - g_display->updateDisplay(); + _graphics->updateDisplay(); #ifdef _SWORD2_DEBUG // FIXME: If we want this, we should re-work it to use the backend's @@ -356,8 +359,8 @@ void Sword2Engine::go() { } #endif - if (KeyWaiting()) { - ReadKey(&ke); + if (g_input->keyWaiting()) { + g_input->readKey(&ke); char c = toupper(ke.ascii); @@ -476,13 +479,11 @@ void Sword2Engine::startGame(void) { void Sword2Engine::sleepUntil(int32 time) { while ((int32) SVM_timeGetTime() < time) { - parseEvents(); - // Make sure menu animations and fades don't suffer - g_display->processMenu(); - g_display->updateDisplay(); + _graphics->processMenu(); + _graphics->updateDisplay(); - g_system->delay_msecs(10); + _system->delay_msecs(10); } } @@ -496,7 +497,7 @@ void Sword2Engine::pauseGame(void) { // res_man->closeResource(3258); // don't allow Pause while screen fading or while black - if (g_display->getFadeStatus() != RDFADE_NONE) + if (_graphics->getFadeStatus() != RDFADE_NONE) return; pauseAllSound(); @@ -507,7 +508,7 @@ void Sword2Engine::pauseGame(void) { // mouse_mode=MOUSE_normal; // this is the only place allowed to do it this way - g_display->setLuggageAnim(NULL, 0); + _graphics->setLuggageAnim(NULL, 0); // blank cursor setMouse(0); @@ -527,7 +528,7 @@ void Sword2Engine::pauseGame(void) { // dim the palette during the pause if (!_stepOneCycle) - g_display->dimPalette(); + _graphics->dimPalette(); _gamePaused = true; } diff --git a/sword2/sword2.h b/sword2/sword2.h index 624c69c289..271f2315f3 100644 --- a/sword2/sword2.h +++ b/sword2/sword2.h @@ -146,8 +146,9 @@ public: uint32 _features; char *_targetName; // target name for saves + Input *_input; Sound *_sound; - Display *_display; + Graphics *_graphics; Debugger *_debugger; @@ -373,8 +374,9 @@ public: }; extern Sword2Engine *g_sword2; +extern Input *g_input; extern Sound *g_sound; -extern Display *g_display; +extern Graphics *g_graphics; } // End of namespace Sword2 diff --git a/sword2/walker.cpp b/sword2/walker.cpp index e141fb30d8..ca3690a7ff 100644 --- a/sword2/walker.cpp +++ b/sword2/walker.cpp @@ -131,7 +131,7 @@ int32 Logic::fnWalk(int32 *params) { // resource ob_graph->anim_resource = ob_mega->megaset_res; - } else if (EXIT_FADING && g_display->getFadeStatus() == RDFADE_BLACK) { + } else if (EXIT_FADING && g_graphics->getFadeStatus() == RDFADE_BLACK) { // double clicked an exit so quit the walk when screen is black // ok, thats it - back to script and change screen -- cgit v1.2.3