diff options
53 files changed, 1230 insertions, 1455 deletions
diff --git a/sword2/anims.cpp b/sword2/anims.cpp index e7e0c82521..51eefcfbe4 100644 --- a/sword2/anims.cpp +++ b/sword2/anims.cpp @@ -23,21 +23,11 @@ // DON'T TOUCH! // --------------------------------------------------------------------------- -#include "stdafx.h" +#include "common/stdafx.h" +#include "common/file.h" #include "sword2/sword2.h" -#include "sword2/driver/driver96.h" -#include "sword2/driver/d_draw.h" -#include "sword2/console.h" -#include "sword2/controls.h" // for 'subtitles' #include "sword2/defs.h" -#include "sword2/header.h" #include "sword2/interpreter.h" -#include "sword2/logic.h" -#include "sword2/maketext.h" // for makeTextSprite used by fnPlaySequence ultimately -#include "sword2/object.h" -#include "sword2/protocol.h" -#include "sword2/resman.h" -#include "sword2/sound.h" // for Speech stuff. namespace Sword2 { @@ -97,8 +87,8 @@ int32 Logic::animate(int32 *params, bool reverse) { // read the main parameters - ob_logic = (Object_logic *) memory->intToPtr(params[0]); - ob_graphic = (Object_graphic *) memory->intToPtr(params[1]); + ob_logic = (Object_logic *) _vm->_memory->intToPtr(params[0]); + ob_graphic = (Object_graphic *) _vm->_memory->intToPtr(params[1]); if (ob_logic->looping == 0) { // This is the start of the anim - set up the first frame @@ -114,11 +104,11 @@ int32 Logic::animate(int32 *params, bool reverse) { // if the resource number is within range & it's not // a null resource - if (res_man->Res_check_valid(res)) { + if (_resman->Res_check_valid(res)) { // Open the resource. Can close it immediately. // We've got a pointer to the header. - head = (_standardHeader *) res_man->openResource(res); - res_man->closeResource(res); + head = (_standardHeader *) _resman->openResource(res); + _resman->closeResource(res); // if it's not an animation file if (head->fileType != ANIMATION_FILE) { @@ -144,17 +134,17 @@ int32 Logic::animate(int32 *params, bool reverse) { #ifdef _SWORD2_DEBUG // check that we haven't been passed a zero resource number if (res == 0) - error("animate: %s (id %d) passed zero anim resource", FetchObjectName(ID), ID); + error("animate: %s (id %d) passed zero anim resource", _vm->fetchObjectName(ID), ID); #endif // open anim file - anim_file = res_man->openResource(res); + anim_file = _vm->_resman->openResource(res); #ifdef _SWORD2_DEBUG // check this this resource is actually an animation file! head = (_standardHeader *) anim_file; if (head->fileType != ANIMATION_FILE) - error("animate: %s (%d) is not an anim!", FetchObjectName(res), res); + error("animate: %s (%d) is not an anim!", _vm->fetchObjectName(res), res); #endif // point to anim header @@ -163,7 +153,7 @@ int32 Logic::animate(int32 *params, bool reverse) { /* #ifdef _SWORD2_DEBUG // check there's at least one frame if (anim_head->noAnimFrames == 0) - error("animate: %s (%d) has zero frame count!", FetchObjectName(res), res); + error("animate: %s (%d) has zero frame count!", _vm->fetchObjectName(res), res); #endif */ // now running an anim, looping back to this 'FN' call again @@ -187,7 +177,7 @@ int32 Logic::animate(int32 *params, bool reverse) { // frame of the anim. // open anim file and point to anim header - anim_file = res_man->openResource(ob_graphic->anim_resource); + anim_file = _vm->_resman->openResource(ob_graphic->anim_resource); anim_head = _vm->fetchAnimHeader(anim_file); if (reverse) @@ -207,7 +197,7 @@ int32 Logic::animate(int32 *params, bool reverse) { } // close the anim file - res_man->closeResource(ob_graphic->anim_resource); + _vm->_resman->closeResource(ob_graphic->anim_resource); // check if we want the script to loop back & call this function again return ob_logic->looping ? IR_REPEAT : IR_STOP; @@ -227,11 +217,11 @@ int32 Logic::megaTableAnimate(int32 *params, bool reverse) { // if this is the start of the anim, read the anim table to get the // appropriate anim resource - ob_logic = (Object_logic *) memory->intToPtr(params[0]); + ob_logic = (Object_logic *) _vm->_memory->intToPtr(params[0]); if (ob_logic->looping == 0) { - ob_mega = (Object_mega *) memory->intToPtr(params[2]); - anim_table = (uint32 *) memory->intToPtr(params[3]); + ob_mega = (Object_mega *) _vm->_memory->intToPtr(params[2]); + anim_table = (uint32 *) _vm->_memory->intToPtr(params[3]); // appropriate anim resource is in 'table[direction]' pars[2] = anim_table[ob_mega->current_dir]; @@ -266,18 +256,18 @@ int32 Logic::fnSetFrame(int32 *params) { #ifdef _SWORD2_DEBUG // check that we haven't been passed a zero resource number if (res == 0) - error("fnSetFrame: %s (id %d) passed zero anim resource", FetchObjectName(ID), ID); + error("fnSetFrame: %s (id %d) passed zero anim resource", _vm->fetchObjectName(ID), ID); #endif // open the resource (& check it's valid) - anim_file = res_man->openResource(res); + anim_file = _vm->_resman->openResource(res); #ifdef _SWORD2_DEBUG // check this this resource is actually an animation file! head = (_standardHeader *) anim_file; if (head->fileType != ANIMATION_FILE) - error("fnSetFrame: %s (%d) is not an anim!", FetchObjectName(res), res); + error("fnSetFrame: %s (%d) is not an anim!", _vm->fetchObjectName(res), res); #endif // set up pointer to the animation header @@ -286,12 +276,12 @@ int32 Logic::fnSetFrame(int32 *params) { /* #ifdef _SWORD2_DEBUG // check there's at least one frame if (anim_head->noAnimFrames == 0) - error("fnSetFrame: %s (%d) has zero frame count!", FetchObjectName(res), res); + error("fnSetFrame: %s (%d) has zero frame count!", _vm->fetchObjectName(res), res); #endif */ // set up anim resource in graphic object - ob_graphic = (Object_graphic *) memory->intToPtr(params[0]); + ob_graphic = (Object_graphic *) _vm->_memory->intToPtr(params[0]); ob_graphic->anim_resource = res; if (params[2]) @@ -301,14 +291,14 @@ int32 Logic::fnSetFrame(int32 *params) { // Close the anim file and drop out of script - res_man->closeResource(ob_graphic->anim_resource); + _vm->_resman->closeResource(ob_graphic->anim_resource); return IR_CONT; } int32 Logic::fnNoSprite(int32 *params) { // params: 0 pointer to object's graphic structure - Object_graphic *ob_graphic = (Object_graphic *) memory->intToPtr(params[0]); + Object_graphic *ob_graphic = (Object_graphic *) _vm->_memory->intToPtr(params[0]); // remove previous status (but don't affect the shading upper-word) ob_graphic->type &= 0xffff0000; @@ -321,7 +311,7 @@ int32 Logic::fnNoSprite(int32 *params) { int32 Logic::fnBackPar0Sprite(int32 *params) { // params: 0 pointer to object's graphic structure - Object_graphic *ob_graphic = (Object_graphic *) memory->intToPtr(params[0]); + Object_graphic *ob_graphic = (Object_graphic *) _vm->_memory->intToPtr(params[0]); // remove previous status (but don't affect the shading upper-word) ob_graphic->type &= 0xffff0000; @@ -334,7 +324,7 @@ int32 Logic::fnBackPar0Sprite(int32 *params) { int32 Logic::fnBackPar1Sprite(int32 *params) { // params: 0 pointer to object's graphic structure - Object_graphic *ob_graphic = (Object_graphic *) memory->intToPtr(params[0]); + Object_graphic *ob_graphic = (Object_graphic *) _vm->_memory->intToPtr(params[0]); // remove previous status (but don't affect the shading upper-word) ob_graphic->type &= 0xffff0000; @@ -347,7 +337,7 @@ int32 Logic::fnBackPar1Sprite(int32 *params) { int32 Logic::fnBackSprite(int32 *params) { // params: 0 pointer to object's graphic structure - Object_graphic *ob_graphic = (Object_graphic *) memory->intToPtr(params[0]); + Object_graphic *ob_graphic = (Object_graphic *) _vm->_memory->intToPtr(params[0]); // remove previous status (but don't affect the shading upper-word) ob_graphic->type &= 0xffff0000; @@ -360,7 +350,7 @@ int32 Logic::fnBackSprite(int32 *params) { int32 Logic::fnSortSprite(int32 *params) { // params: 0 pointer to object's graphic structure - Object_graphic *ob_graphic = (Object_graphic *) memory->intToPtr(params[0]); + Object_graphic *ob_graphic = (Object_graphic *) _vm->_memory->intToPtr(params[0]); // remove previous status (but don't affect the shading upper-word) ob_graphic->type &= 0xffff0000; @@ -373,7 +363,7 @@ int32 Logic::fnSortSprite(int32 *params) { int32 Logic::fnForeSprite(int32 *params) { // params: 0 pointer to object's graphic structure - Object_graphic *ob_graphic = (Object_graphic *) memory->intToPtr(params[0]); + Object_graphic *ob_graphic = (Object_graphic *) _vm->_memory->intToPtr(params[0]); // remove previous status (but don't affect the shading upper-word) ob_graphic->type &= 0xffff0000; @@ -386,7 +376,7 @@ int32 Logic::fnForeSprite(int32 *params) { int32 Logic::fnForePar0Sprite(int32 *params) { // params: 0 pointer to object's graphic structure - Object_graphic *ob_graphic = (Object_graphic *) memory->intToPtr(params[0]); + Object_graphic *ob_graphic = (Object_graphic *) _vm->_memory->intToPtr(params[0]); // remove previous status (but don't affect the shading upper-word) ob_graphic->type &= 0xffff0000; @@ -399,7 +389,7 @@ int32 Logic::fnForePar0Sprite(int32 *params) { int32 Logic::fnForePar1Sprite(int32 *params) { // params: 0 pointer to object's graphic structure - Object_graphic *ob_graphic = (Object_graphic *) memory->intToPtr(params[0]); + Object_graphic *ob_graphic = (Object_graphic *) _vm->_memory->intToPtr(params[0]); // remove previous status (but don't affect the shading upper-word) ob_graphic->type &= 0xffff0000; @@ -412,7 +402,7 @@ int32 Logic::fnForePar1Sprite(int32 *params) { int32 Logic::fnShadedSprite(int32 *params) { // params: 0 pointer to object's graphic structure - Object_graphic *ob_graphic = (Object_graphic *) memory->intToPtr(params[0]); + Object_graphic *ob_graphic = (Object_graphic *) _vm->_memory->intToPtr(params[0]); // remove previous status (but don't affect the shading upper-word) ob_graphic->type &= 0x0000ffff; @@ -428,7 +418,7 @@ int32 Logic::fnShadedSprite(int32 *params) { int32 Logic::fnUnshadedSprite(int32 *params) { // params: 0 pointer to object's graphic structure - Object_graphic *ob_graphic = (Object_graphic *) memory->intToPtr(params[0]); + Object_graphic *ob_graphic = (Object_graphic *) _vm->_memory->intToPtr(params[0]); // remove previous status (but don't affect the shading upper-word) ob_graphic->type &= 0x0000ffff; @@ -494,11 +484,11 @@ void Logic::createSequenceSpeech(_movieTextObject *sequenceText[]) { local_text = _sequenceTextList[line].textNumber & 0xffff; // open text resource & get the line - text = _vm->fetchTextLine(res_man->openResource(text_res), local_text); + text = _vm->fetchTextLine(_vm->_resman->openResource(text_res), local_text); wavId = (int32) READ_LE_UINT16(text); // now ok to close the text file - res_man->closeResource(text_res); + _vm->_resman->closeResource(text_res); // 1st word of text line is the official line number debug(5,"(%d) SEQUENCE TEXT: %s", READ_LE_UINT16(text), text + 2); @@ -510,7 +500,7 @@ void Logic::createSequenceSpeech(_movieTextObject *sequenceText[]) { _sequenceTextList[line].speech_mem = NULL; sequenceText[line]->speech = NULL; - if (!g_sound->isSpeechMute()) { + if (!_vm->_sound->isSpeechMute()) { // speech is selected, so try that first // set up path to speech cluster @@ -520,13 +510,13 @@ void Logic::createSequenceSpeech(_movieTextObject *sequenceText[]) { File fp; - sprintf(speechFile, "speech%d.clu", res_man->whichCd()); + sprintf(speechFile, "speech%d.clu", _vm->_resman->whichCd()); if (fp.open(speechFile)) fp.close(); else strcpy(speechFile, "speech.clu"); - _sequenceTextList[line].speechBufferSize = g_sound->preFetchCompSpeech((char *) speechFile, wavId, &_sequenceTextList[line].speech_mem); + _sequenceTextList[line].speechBufferSize = _vm->_sound->preFetchCompSpeech((char *) speechFile, wavId, &_sequenceTextList[line].speech_mem); if (_sequenceTextList[line].speechBufferSize) { // ok, we've got speech! speechRunning = true; @@ -535,9 +525,9 @@ void Logic::createSequenceSpeech(_movieTextObject *sequenceText[]) { // if we want subtitles, or speech failed to load - if (gui->_subtitles || !speechRunning) { + if (_vm->_gui->_subtitles || !speechRunning) { // open text resource & get the line - text = _vm->fetchTextLine(res_man->openResource(text_res), local_text); + text = _vm->fetchTextLine(_vm->_resman->openResource(text_res), local_text); // make the sprite // 'text+2' to skip the first 2 bytes which form the // line reference number @@ -548,10 +538,10 @@ void Logic::createSequenceSpeech(_movieTextObject *sequenceText[]) { // When rendering text over a sequence we need a // different colour for the border. - _sequenceTextList[line].text_mem = fontRenderer->makeTextSprite(text + 2, 600, 255, _vm->_speechFontId, 1); + _sequenceTextList[line].text_mem = _vm->_fontRenderer->makeTextSprite(text + 2, 600, 255, _vm->_speechFontId, 1); // ok to close the text resource now - res_man->closeResource(text_res); + _vm->_resman->closeResource(text_res); } else { _sequenceTextList[line].text_mem = NULL; sequenceText[line]->textSprite = NULL; @@ -569,7 +559,7 @@ void Logic::createSequenceSpeech(_movieTextObject *sequenceText[]) { // if we've made a text sprite for this line... if (_sequenceTextList[line].text_mem) { - memory->lockMemory(_sequenceTextList[line].text_mem); + _vm->_memory->lockMemory(_sequenceTextList[line].text_mem); // now fill out the _spriteInfo structure in the // _movieTextObjectStructure @@ -608,7 +598,7 @@ void Logic::clearSequenceSpeech(_movieTextObject *sequenceText[]) { // free up the mem block containing this text sprite if (_sequenceTextList[line].text_mem) - memory->freeMemory(_sequenceTextList[line].text_mem); + _vm->_memory->freeMemory(_sequenceTextList[line].text_mem); // free up the mem block containing this speech sample if (_sequenceTextList[line].speech_mem) @@ -628,7 +618,7 @@ int32 Logic::fnSmackerLeadIn(int32 *params) { // params: 0 id of lead-in music - leadIn = res_man->openResource(params[0]); + leadIn = _vm->_resman->openResource(params[0]); #ifdef _SWORD2_DEBUG header = (_standardHeader *) leadIn; @@ -638,12 +628,12 @@ int32 Logic::fnSmackerLeadIn(int32 *params) { leadIn += sizeof(_standardHeader); // wav data gets copied to sound memory - rv = g_sound->playFx(0, leadIn, 0, 0, RDSE_FXLEADIN); + rv = _vm->_sound->playFx(0, leadIn, 0, 0, RDSE_FXLEADIN); if (rv) debug(5, "SFX ERROR: playFx() returned %.8x", rv); - res_man->closeResource(params[0]); + _vm->_resman->closeResource(params[0]); // fade out any music that is currently playing fnStopMusic(NULL); @@ -680,17 +670,17 @@ int32 Logic::fnPlaySequence(int32 *params) { // of computer games" - but at the very least we want to show the // cutscene subtitles, so I removed them. - debug(5, "fnPlaySequence(\"%s\");", (const char *) memory->intToPtr(params[0])); + debug(5, "fnPlaySequence(\"%s\");", (const char *) _vm->_memory->intToPtr(params[0])); #ifdef _SWORD2_DEBUG // check that the name paseed from script is 8 chars or less - if (strlen((const char *) memory->intToPtr(params[0])) > 8) + if (strlen((const char *) _vm->_memory->intToPtr(params[0])) > 8) error("Sequence filename too long"); #endif // add the appropriate file extension & play it - sprintf(filename, "%s.smk", (const char *) memory->intToPtr(params[0])); + sprintf(filename, "%s.smk", (const char *) _vm->_memory->intToPtr(params[0])); // Write to walkthrough file (zebug0.txt) debug(5, "PLAYING SEQUENCE \"%s\"", filename); @@ -703,7 +693,7 @@ int32 Logic::fnPlaySequence(int32 *params) { // open the lead-out music resource, if there is one if (_smackerLeadOut) { - leadOut = res_man->openResource(_smackerLeadOut); + leadOut = _vm->_resman->openResource(_smackerLeadOut); #ifdef _SWORD2_DEBUG header = (_standardHeader *) leadOut; @@ -720,9 +710,9 @@ int32 Logic::fnPlaySequence(int32 *params) { fnStopMusic(NULL); // pause sfx during sequence, except the one used for lead-in music - g_sound->pauseFxForSequence(); + _vm->_sound->pauseFxForSequence(); - MoviePlayer player; + MoviePlayer player(_vm); if (_sequenceTextLines && !(_vm->_features & GF_DEMO)) rv = player.play(filename, sequenceSpeechArray, leadOut); @@ -730,12 +720,12 @@ int32 Logic::fnPlaySequence(int32 *params) { rv = player.play(filename, NULL, leadOut); // unpause sound fx again, in case we're staying in same location - g_sound->unpauseFx(); + _vm->_sound->unpauseFx(); // close the lead-out music resource if (_smackerLeadOut) { - res_man->closeResource(_smackerLeadOut); + _vm->_resman->closeResource(_smackerLeadOut); _smackerLeadOut = 0; } @@ -751,14 +741,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_graphics->clearScene(); + _vm->_graphics->clearScene(); // zero the entire palette in case we're about to fade up! _palEntry pal[256]; memset(pal, 0, 256 * sizeof(_palEntry)); - g_graphics->setPalette(0, 256, (uint8 *) pal, RDPAL_INSTANT); + _vm->_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 32be4bdb81..25de2b0a14 100644 --- a/sword2/build_display.cpp +++ b/sword2/build_display.cpp @@ -21,20 +21,10 @@ // BUILD_DISPLAY.CPP like the old spr_engi but slightly more aptly named // --------------------------------------------------------------------------- -#include "stdafx.h" +#include "common/stdafx.h" #include "sword2/sword2.h" -#include "sword2/debug.h" -#include "sword2/build_display.h" -#include "sword2/console.h" #include "sword2/defs.h" #include "sword2/interpreter.h" -#include "sword2/layers.h" -#include "sword2/logic.h" -#include "sword2/maketext.h" -#include "sword2/mouse.h" -#include "sword2/object.h" -#include "sword2/protocol.h" -#include "sword2/resman.h" namespace Sword2 { @@ -54,11 +44,11 @@ void Sword2Engine::buildDisplay(void) { // there is a valid screen to run if (_thisScreen.background_layer_id) { // set the scroll position - g_graphics->setScrollTarget(_thisScreen.scroll_offset_x, _thisScreen.scroll_offset_y); + _graphics->setScrollTarget(_thisScreen.scroll_offset_x, _thisScreen.scroll_offset_y); // increment the mouse frame - g_graphics->animateMouse(); + _graphics->animateMouse(); - g_graphics->startRenderCycle(); + _graphics->startRenderCycle(); while (1) { // clear the back buffer, before building up the new @@ -67,49 +57,49 @@ void Sword2Engine::buildDisplay(void) { // FIXME: I'm not convinced that this is needed. Isn't // the whole screen redrawn each time? - // g_graphics->clearScene(); + // _graphics->clearScene(); // first background parallax + related anims // open the screen resource - file = res_man->openResource(_thisScreen.background_layer_id); + file = _resman->openResource(_thisScreen.background_layer_id); screenLayerTable = (_multiScreenHeader *) ((uint8 *) file + sizeof(_standardHeader)); if (screenLayerTable->bg_parallax[0]) { - g_graphics->renderParallax(fetchBackgroundParallaxLayer(file, 0), 0); + _graphics->renderParallax(fetchBackgroundParallaxLayer(file, 0), 0); // release the screen resource before cacheing // the sprites - res_man->closeResource(_thisScreen.background_layer_id); + _resman->closeResource(_thisScreen.background_layer_id); sendBackPar0Frames(); } else { // release the screen resource - res_man->closeResource(_thisScreen.background_layer_id); + _resman->closeResource(_thisScreen.background_layer_id); } // second background parallax + related anims // open the screen resource - file = res_man->openResource(_thisScreen.background_layer_id); + file = _resman->openResource(_thisScreen.background_layer_id); screenLayerTable = (_multiScreenHeader *) ((uint8 *) file + sizeof(_standardHeader)); if (screenLayerTable->bg_parallax[1]) { - g_graphics->renderParallax(fetchBackgroundParallaxLayer(file, 1), 1); + _graphics->renderParallax(fetchBackgroundParallaxLayer(file, 1), 1); // release the screen resource before cacheing // the sprites - res_man->closeResource(_thisScreen.background_layer_id); + _resman->closeResource(_thisScreen.background_layer_id); sendBackPar1Frames(); } else { // release the screen resource - res_man->closeResource(_thisScreen.background_layer_id); + _resman->closeResource(_thisScreen.background_layer_id); } // normal backround layer (just the one!) // open the screen resource - file = res_man->openResource(_thisScreen.background_layer_id); - g_graphics->renderParallax(fetchBackgroundLayer(file), 2); + file = _resman->openResource(_thisScreen.background_layer_id); + _graphics->renderParallax(fetchBackgroundLayer(file), 2); // release the screen resource - res_man->closeResource(_thisScreen.background_layer_id); + _resman->closeResource(_thisScreen.background_layer_id); // sprites & layers @@ -121,35 +111,35 @@ void Sword2Engine::buildDisplay(void) { // first foreground parallax + related anims // open the screen resource - file = res_man->openResource(_thisScreen.background_layer_id); + file = _resman->openResource(_thisScreen.background_layer_id); screenLayerTable = (_multiScreenHeader *) ((uint8 *) file + sizeof(_standardHeader)); if (screenLayerTable->fg_parallax[0]) { - g_graphics->renderParallax(fetchForegroundParallaxLayer(file, 0), 3); + _graphics->renderParallax(fetchForegroundParallaxLayer(file, 0), 3); // release the screen resource before cacheing // the sprites - res_man->closeResource(_thisScreen.background_layer_id); + _resman->closeResource(_thisScreen.background_layer_id); sendForePar0Frames(); } else { // release the screen resource - res_man->closeResource(_thisScreen.background_layer_id); + _resman->closeResource(_thisScreen.background_layer_id); } // second foreground parallax + related anims // open the screen resource - file = res_man->openResource(_thisScreen.background_layer_id); + file = _resman->openResource(_thisScreen.background_layer_id); screenLayerTable = (_multiScreenHeader *) ((uint8 *) file + sizeof(_standardHeader)); if (screenLayerTable->fg_parallax[1]) { - g_graphics->renderParallax(fetchForegroundParallaxLayer(file, 1), 4); + _graphics->renderParallax(fetchForegroundParallaxLayer(file, 1), 4); // release the screen resource before cacheing // the sprites - res_man->closeResource(_thisScreen.background_layer_id); + _resman->closeResource(_thisScreen.background_layer_id); sendForePar1Frames(); } else { // release the screen resource - res_man->closeResource(_thisScreen.background_layer_id); + _resman->closeResource(_thisScreen.background_layer_id); } // walkgrid, mouse & player markers & mouse area @@ -160,15 +150,15 @@ void Sword2Engine::buildDisplay(void) { // text blocks // speech blocks and headup debug text - fontRenderer->printTextBlocs(); + _fontRenderer->printTextBlocs(); // menu bar & icons - g_graphics->processMenu(); + _graphics->processMenu(); // ready - blit to screen - g_graphics->updateDisplay(); + _graphics->updateDisplay(); // update our fps reading @@ -187,7 +177,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_graphics->endRenderCycle()) + if (_graphics->endRenderCycle()) break; } } @@ -207,24 +197,24 @@ void Sword2Engine::displayMsg(uint8 *text, int time) { debug(2, "DisplayMsg: %s", (char *) text); - if (g_graphics->getFadeStatus() != RDFADE_BLACK) { - g_graphics->fadeDown(); - g_graphics->waitForFade(); + if (_graphics->getFadeStatus() != RDFADE_BLACK) { + _graphics->fadeDown(); + _graphics->waitForFade(); } setMouse(0); setLuggage(0); - g_graphics->closeMenuImmediately(); - g_graphics->clearScene(); + _graphics->closeMenuImmediately(); + _graphics->clearScene(); - text_spr = fontRenderer->makeTextSprite(text, 640, 187, _speechFontId); + text_spr = _fontRenderer->makeTextSprite(text, 640, 187, _speechFontId); frame = (_frameHeader *) text_spr->ad; - spriteInfo.x = g_graphics->_screenWide / 2 - frame->width / 2; + spriteInfo.x = _graphics->_screenWide / 2 - frame->width / 2; if (!time) - spriteInfo.y = g_graphics->_screenDeep / 2 - frame->height / 2 - RDMENU_MENUDEEP; + spriteInfo.y = _graphics->_screenDeep / 2 - frame->height / 2 - RDMENU_MENUDEEP; else spriteInfo.y = 400 - frame->height; spriteInfo.w = frame->width; @@ -237,29 +227,29 @@ void Sword2Engine::displayMsg(uint8 *text, int time) { spriteInfo.data = text_spr->ad + sizeof(_frameHeader); spriteInfo.colourTable = 0; - rv = g_graphics->drawSprite(&spriteInfo); + rv = _graphics->drawSprite(&spriteInfo); if (rv) error("Driver Error %.8x (in DisplayMsg)", rv); - memcpy((char *) oldPal, (char *) g_graphics->_palCopy, 256 * sizeof(_palEntry)); + memcpy((char *) oldPal, (char *) _graphics->_palCopy, 256 * sizeof(_palEntry)); memset(pal, 0, 256 * sizeof(_palEntry)); pal[187].red = 255; pal[187].green = 255; pal[187].blue = 255; - g_graphics->setPalette(0, 256, (uint8 *) pal, RDPAL_FADE); + _graphics->setPalette(0, 256, (uint8 *) pal, RDPAL_FADE); - g_graphics->fadeUp(); + _graphics->fadeUp(); - memory->freeMemory(text_spr); + _memory->freeMemory(text_spr); - g_graphics->waitForFade(); + _graphics->waitForFade(); uint32 targetTime = _system->get_msecs() + (time * 1000); sleepUntil(targetTime); - g_graphics->setPalette(0, 256, (uint8 *) oldPal, RDPAL_FADE); + _graphics->setPalette(0, 256, (uint8 *) oldPal, RDPAL_FADE); } // @@ -267,11 +257,11 @@ void Sword2Engine::displayMsg(uint8 *text, int time) { // void Sword2Engine::removeMsg(void) { - g_graphics->fadeDown(); - g_graphics->waitForFade(); - g_graphics->clearScene(); + _graphics->fadeDown(); + _graphics->waitForFade(); + _graphics->clearScene(); - // g_graphics->fadeUp(); + // _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 @@ -351,7 +341,7 @@ void Sword2Engine::processLayer(uint32 layer_number) { uint32 current_layer_area = 0; // file points to 1st byte in the layer file - file = res_man->openResource(_thisScreen.background_layer_id); + file = _resman->openResource(_thisScreen.background_layer_id); // point to layer header layer_head = fetchLayerHeader(file,layer_number); @@ -380,11 +370,11 @@ void Sword2Engine::processLayer(uint32 layer_number) { layer_number, layer_head->width, layer_head->height); } - rv = g_graphics->drawSprite(&spriteInfo); + rv = _graphics->drawSprite(&spriteInfo); if (rv) error("Driver Error %.8x in Process_layer(%d)", rv, layer_number); - res_man->closeResource(_thisScreen.background_layer_id); + _resman->closeResource(_thisScreen.background_layer_id); } void Sword2Engine::processImage(buildit *build_unit) { @@ -399,7 +389,7 @@ void Sword2Engine::processImage(buildit *build_unit) { uint32 current_sprite_area = 0; // open anim resource file & point to base - file = res_man->openResource(build_unit->anim_resource); + file = _resman->openResource(build_unit->anim_resource); anim_head = fetchAnimHeader(file); cdt_entry = fetchCdtEntry(file, build_unit->anim_pc); @@ -506,14 +496,14 @@ void Sword2Engine::processImage(buildit *build_unit) { // } // #endif - rv = g_graphics->drawSprite(&spriteInfo); + rv = _graphics->drawSprite(&spriteInfo); if (rv) error("Driver Error %.8x with sprite %s (%d) in processImage", rv, fetchObjectName(build_unit->anim_resource), build_unit->anim_resource); // release the anim resource - res_man->closeResource(build_unit->anim_resource); + _resman->closeResource(build_unit->anim_resource); } void Sword2Engine::resetRenderLists(void) { @@ -571,11 +561,11 @@ void Sword2Engine::registerFrame(int32 *params, buildit *build_unit) { // open animation file & set up the necessary pointers - ob_graph = (Object_graphic *) memory->intToPtr(params[1]); + ob_graph = (Object_graphic *) _memory->intToPtr(params[1]); assert(ob_graph->anim_resource); - file = res_man->openResource(ob_graph->anim_resource); + file = _resman->openResource(ob_graph->anim_resource); anim_head = fetchAnimHeader(file); cdt_entry = fetchCdtEntry(file, ob_graph->anim_pc); @@ -609,7 +599,7 @@ void Sword2Engine::registerFrame(int32 *params, buildit *build_unit) { if (cdt_entry->frameType & FRAME_OFFSET) { // param 2 is pointer to mega structure - ob_mega = (Object_mega *) memory->intToPtr(params[2]); + ob_mega = (Object_mega *) _memory->intToPtr(params[2]); // calc scale at which to print the sprite, based on feet // y-coord & scaling constants (NB. 'scale' is actually @@ -650,7 +640,7 @@ void Sword2Engine::registerFrame(int32 *params, buildit *build_unit) { if (params[0]) { // passed a mouse structure, so add to the _mouseList - ob_mouse = (Object_mouse *) memory->intToPtr(params[0]); + ob_mouse = (Object_mouse *) _memory->intToPtr(params[0]); // only if 'pointer' isn't NULL if (ob_mouse->pointer) { @@ -685,7 +675,7 @@ void Sword2Engine::registerFrame(int32 *params, buildit *build_unit) { } // close animation file - res_man->closeResource(ob_graph->anim_resource); + _resman->closeResource(ob_graph->anim_resource); } int32 Logic::fnRegisterFrame(int32 *params) { @@ -701,7 +691,7 @@ int32 Logic::fnRegisterFrame(int32 *params) { } int32 Sword2Engine::registerFrame(int32 *params) { - Object_graphic *ob_graph = (Object_graphic *) memory->intToPtr(params[1]); + Object_graphic *ob_graph = (Object_graphic *) _memory->intToPtr(params[1]); // check low word for sprite type switch (ob_graph->type & 0x0000ffff) { @@ -756,23 +746,23 @@ 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_graphics->waitForFade(); + _graphics->waitForFade(); // open the screen file - screenFile = res_man->openResource(_thisScreen.background_layer_id); + screenFile = _resman->openResource(_thisScreen.background_layer_id); - g_graphics->updatePaletteMatchTable((uint8 *) fetchPaletteMatchTable(screenFile)); + _graphics->updatePaletteMatchTable((uint8 *) fetchPaletteMatchTable(screenFile)); - g_graphics->setPalette(0, 256, fetchPalette(screenFile), RDPAL_FADE); + _graphics->setPalette(0, 256, fetchPalette(screenFile), RDPAL_FADE); // indicating that it's a screen palette _lastPaletteRes = 0; // close screen file - res_man->closeResource(_thisScreen.background_layer_id); + _resman->closeResource(_thisScreen.background_layer_id); // start fade up - g_graphics->fadeUp(); + _graphics->fadeUp(); // reset _thisScreen.new_palette = 0; @@ -783,7 +773,7 @@ int32 Logic::fnUpdatePlayerStats(int32 *params) { // params: 0 pointer to mega structure - Object_mega *ob_mega = (Object_mega *) memory->intToPtr(params[0]); + Object_mega *ob_mega = (Object_mega *) _vm->_memory->intToPtr(params[0]); _vm->_thisScreen.player_feet_x = ob_mega->feet_x; _vm->_thisScreen.player_feet_y = ob_mega->feet_y; @@ -806,8 +796,8 @@ int32 Logic::fnFadeDown(int32 *params) { // params: none - if (g_graphics->getFadeStatus() == RDFADE_NONE) - g_graphics->fadeDown(); + if (_vm->_graphics->getFadeStatus() == RDFADE_NONE) + _vm->_graphics->fadeDown(); return IR_CONT; } @@ -815,10 +805,10 @@ int32 Logic::fnFadeDown(int32 *params) { int32 Logic::fnFadeUp(int32 *params) { // params: none - g_graphics->waitForFade(); + _vm->_graphics->waitForFade(); - if (g_graphics->getFadeStatus() == RDFADE_BLACK) - g_graphics->fadeUp(); + if (_vm->_graphics->getFadeStatus() == RDFADE_BLACK) + _vm->_graphics->fadeUp(); return IR_CONT; } @@ -867,7 +857,7 @@ void Sword2Engine::setFullPalette(int32 palRes) { // non-zero: set palette to this separate palette file if (palRes) { // open the palette file - head = (_standardHeader *) res_man->openResource(palRes); + head = (_standardHeader *) _resman->openResource(palRes); assert(head->fileType == PALETTE_FILE); @@ -883,9 +873,9 @@ void Sword2Engine::setFullPalette(int32 palRes) { file[3] = 0; // not yet in separate palette files - // g_graphics->updatePaletteMatchTable(file + (256 * 4)); + // _graphics->updatePaletteMatchTable(file + (256 * 4)); - g_graphics->setPalette(0, 256, file, RDPAL_INSTANT); + _graphics->setPalette(0, 256, file, RDPAL_INSTANT); if (palRes != CONTROL_PANEL_PALETTE) { // (James 03sep97) // indicating that it's a separate palette resource @@ -893,21 +883,21 @@ void Sword2Engine::setFullPalette(int32 palRes) { } // close palette file - res_man->closeResource(palRes); + _resman->closeResource(palRes); } else { // 0: set palette to current screen palette if (_thisScreen.background_layer_id) { // open the screen file - file = res_man->openResource(_thisScreen.background_layer_id); - g_graphics->updatePaletteMatchTable((uint8 *) fetchPaletteMatchTable(file)); + file = _resman->openResource(_thisScreen.background_layer_id); + _graphics->updatePaletteMatchTable((uint8 *) fetchPaletteMatchTable(file)); - g_graphics->setPalette(0, 256, fetchPalette(file), RDPAL_INSTANT); + _graphics->setPalette(0, 256, fetchPalette(file), RDPAL_INSTANT); // indicating that it's a screen palette _lastPaletteRes = 0; // close screen file - res_man->closeResource(_thisScreen.background_layer_id); + _resman->closeResource(_thisScreen.background_layer_id); } else error("setFullPalette(0) called, but no current screen available!"); } @@ -923,7 +913,7 @@ int32 Logic::fnChangeShadows(int32 *params) { // if last screen was using a shading mask (see below) if (_vm->_thisScreen.mask_flag) { - uint32 rv = g_graphics->closeLightMask(); + uint32 rv = _vm->_graphics->closeLightMask(); if (rv) error("Driver Error %.8x [%s line %u]", rv); diff --git a/sword2/console.cpp b/sword2/console.cpp index de7cf085e4..0533cf26d5 100644 --- a/sword2/console.cpp +++ b/sword2/console.cpp @@ -17,33 +17,14 @@ * $Header$ */ -#include "stdafx.h" +#include "common/stdafx.h" #include "sword2/sword2.h" -#include "sword2/console.h" -#include "sword2/debug.h" #include "sword2/defs.h" -#include "sword2/logic.h" -#include "sword2/maketext.h" -#include "sword2/mouse.h" -#include "sword2/protocol.h" -#include "sword2/resman.h" -#include "sword2/save_rest.h" -#include "sword2/startup.h" #include "common/debugger.cpp" namespace Sword2 { -void Debugger::varGet(int var) { - Debug_Printf("%d\n", VAR(var)); -} - -void Debugger::varSet(int var, int val) { - Debug_Printf("was %d, ", VAR(var)); - VAR(var) = val; - Debug_Printf("now %d\n", VAR(var)); -} - Debugger::Debugger(Sword2Engine *vm) : Common::Debugger<Debugger>() { _vm = vm; @@ -130,22 +111,31 @@ Debugger::Debugger(Sword2Engine *vm) DCmd_Register("polish", &Debugger::Cmd_Polish); } +void Debugger::varGet(int var) { + Debug_Printf("%d\n", VAR(var)); +} + +void Debugger::varSet(int var, int val) { + Debug_Printf("was %d, ", VAR(var)); + VAR(var) = val; + Debug_Printf("now %d\n", VAR(var)); +} + void Debugger::preEnter() { // Pause sound output - g_sound->pauseFx(); - g_sound->pauseSpeech(); - g_sound->pauseMusic(); + _vm->_sound->pauseFx(); + _vm->_sound->pauseSpeech(); + _vm->_sound->pauseMusic(); } void Debugger::postEnter() { // Resume previous sound state - g_sound->unpauseFx(); - g_sound->unpauseSpeech(); - g_sound->unpauseMusic(); + _vm->_sound->unpauseFx(); + _vm->_sound->unpauseSpeech(); + _vm->_sound->unpauseMusic(); // Restore old mouse cursor - g_graphics->drawMouse(); - + _vm->_graphics->drawMouse(); } /////////////////////////////////////////////////// @@ -181,7 +171,7 @@ bool Debugger::Cmd_Help(int argc, const char **argv) { } bool Debugger::Cmd_Mem(int argc, const char **argv) { - memory->displayMemory(); + _vm->_memory->displayMemory(); return true; } @@ -191,7 +181,7 @@ bool Debugger::Cmd_Tony(int argc, const char **argv) { } bool Debugger::Cmd_Res(int argc, const char **argv) { - res_man->printConsoleClusters(); + _vm->_resman->printConsoleClusters(); return true; } @@ -209,7 +199,7 @@ bool Debugger::Cmd_Start(int argc, const char **argv) { } _vm->_logic->conStart(atoi(argv[1])); - g_graphics->setPalette(187, 1, pal, RDPAL_INSTANT); + _vm->_graphics->setPalette(187, 1, pal, RDPAL_INSTANT); return true; } @@ -261,7 +251,7 @@ bool Debugger::Cmd_ResLook(int argc, const char **argv) { if (argc != 2) DebugPrintf("Usage: %s number\n", argv[0]); else - res_man->examine(atoi(argv[1])); + _vm->_resman->examine(atoi(argv[1])); return true; } @@ -279,13 +269,13 @@ bool Debugger::Cmd_Kill(int argc, const char **argv) { if (argc != 2) DebugPrintf("Usage: %s number\n", argv[0]); else - res_man->kill(atoi(argv[1])); + _vm->_resman->kill(atoi(argv[1])); return true; } bool Debugger::Cmd_Nuke(int argc, const char **argv) { DebugPrintf("Killing all resources except variable file and player object\n"); - res_man->killAll(true); + _vm->_resman->killAll(true); return true; } @@ -318,7 +308,7 @@ bool Debugger::Cmd_Rect(int argc, const char **argv) { } bool Debugger::Cmd_Clear(int argc, const char **argv) { - res_man->killAllObjects(true); + _vm->_resman->killAllObjects(true); return true; } @@ -451,14 +441,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_graphics->setBltFx(); + // _vm->_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_graphics->clearBltFx(); + // _vm->_graphics->clearBltFx(); // DebugPrintf("Blit fx disabled\n"); DebugPrintf("FIXME: The clearBltFx() function no longer exists\n"); return true; @@ -466,9 +456,9 @@ bool Debugger::Cmd_BltFxOff(int argc, const char **argv) { bool Debugger::Cmd_TimeOn(int argc, const char **argv) { if (argc == 2) - _startTime = g_system->get_msecs() - atoi(argv[1]) * 1000; + _startTime = _vm->_system->get_msecs() - atoi(argv[1]) * 1000; else if (_startTime == 0) - _startTime = g_system->get_msecs(); + _startTime = _vm->_system->get_msecs(); _displayTime = true; DebugPrintf("Timer display on\n"); return true; diff --git a/sword2/console.h b/sword2/console.h index b7189fb327..cfc13c0f30 100644 --- a/sword2/console.h +++ b/sword2/console.h @@ -28,8 +28,6 @@ namespace Sword2 { -class Sword2Engine; - class Debugger : public Common::Debugger<Debugger> { private: void varGet(int var); diff --git a/sword2/controls.cpp b/sword2/controls.cpp index f95f08db88..0e4ad72049 100644 --- a/sword2/controls.cpp +++ b/sword2/controls.cpp @@ -17,27 +17,10 @@ * $Header$ */ -#include "stdafx.h" +#include "common/stdafx.h" #include "common/config-manager.h" -#include "sword2/driver/driver96.h" -#include "sword2/build_display.h" -#include "sword2/console.h" -#include "sword2/controls.h" -#include "sword2/defs.h" -#include "sword2/header.h" -#include "sword2/interpreter.h" -#include "sword2/layers.h" -#include "sword2/logic.h" -#include "sword2/maketext.h" // for font resource variables -#include "sword2/mouse.h" -#include "sword2/protocol.h" -#include "sword2/resman.h" -#include "sword2/router.h" -#include "sword2/save_rest.h" -#include "sword2/sound.h" #include "sword2/sword2.h" - -namespace Sword2 { +#include "sword2/defs.h" #define MAX_STRING_LEN 64 // 20 was too low; better to be safe ;) #define CHARACTER_OVERLAP 2 // overlap characters by 3 pixels @@ -45,80 +28,180 @@ namespace Sword2 { // our fonts start on SPACE character (32) #define SIZE_OF_CHAR_SET (256 - 32) -Gui *gui; +#define MAX_WIDGETS 25 + +namespace Sword2 { -enum { - kAlignLeft, - kAlignRight, - kAlignCenter +class Widget; + +/** + * Base class for all dialogs. + */ + +class Dialog { +private: + int _numWidgets; + Widget *_widgets[MAX_WIDGETS]; + bool _finish; + int _result; + +public: + Gui *_gui; + + Dialog(Gui *gui); + virtual ~Dialog(); + + void registerWidget(Widget *widget); + + virtual void paint(); + virtual void setResult(int result); + + int run(); + + virtual void onAction(Widget *widget, int result = 0) {} }; +/** + * Base class for all widgets. + */ + +class Widget { +protected: + Dialog *_parent; + + _spriteInfo *_sprites; + + struct WidgetSurface { + uint8 *_surface; + bool _original; + }; + + WidgetSurface *_surfaces; + int _numStates; + int _state; + + Common::Rect _hitRect; + +public: + Widget(Dialog *parent, int states); + + virtual ~Widget(); + + void createSurfaceImage(int state, uint32 res, int x, int y, uint32 pc); + void linkSurfaceImage(Widget *from, int state, int x, int y); + + void createSurfaceImages(uint32 res, int x, int y); + void linkSurfaceImages(Widget *from, int x, int y); + + void setHitRect(int x, int y, int width, int height); + bool isHit(int16 x, int16 y); + + void setState(int state); + int getState(); + + virtual void paint(Common::Rect *clipRect = NULL); + + virtual void onMouseEnter() {} + virtual void onMouseExit() {} + virtual void onMouseMove(int x, int y) {} + virtual void onMouseDown(int x, int y) {} + virtual void onMouseUp(int x, int y) {} + virtual void onKey(_keyboardEvent *ke) {} + virtual void onTick() {} + + virtual void releaseMouse(int x, int y) {} +}; + +/** + * This class is used to draw text in dialogs, buttons, etc. + */ + class FontRendererGui { private: + Gui *_gui; + struct Glyph { uint8 *_data; int _width; int _height; - } _glyph[SIZE_OF_CHAR_SET]; + }; + + Glyph _glyph[SIZE_OF_CHAR_SET]; + int _fontId; public: - FontRendererGui(int fontId) : _fontId(fontId) { - uint8 *font = res_man->openResource(fontId); - _frameHeader *head; - _spriteInfo sprite; - - sprite.type = RDSPR_NOCOMPRESSION | RDSPR_TRANS; - - for (int i = 0; i < SIZE_OF_CHAR_SET; i++) { - head = (_frameHeader *) g_sword2->fetchFrameHeader(font, i); - sprite.data = (uint8 *) (head + 1); - sprite.w = head->width; - sprite.h = head->height; - g_graphics->createSurface(&sprite, &_glyph[i]._data); - _glyph[i]._width = head->width; - _glyph[i]._height = head->height; - } + enum { + kAlignLeft, + kAlignRight, + kAlignCenter + }; - res_man->closeResource(fontId); - } + FontRendererGui(Gui *gui, int fontId); + ~FontRendererGui(); - ~FontRendererGui() { - for (int i = 0; i < SIZE_OF_CHAR_SET; i++) - g_graphics->deleteSurface(_glyph[i]._data); - } + void fetchText(int textId, char *buf); - void fetchText(int textId, char *buf) { - uint8 *data = g_sword2->fetchTextLine(res_man->openResource(textId / SIZE), textId & 0xffff); - int i; + int getTextWidth(char *text); + int getTextWidth(int textId); - for (i = 0; data[i + 2]; i++) { - if (buf) - buf[i] = data[i + 2]; - } - - buf[i] = 0; - res_man->closeResource(textId / SIZE); - } + void drawText(char *text, int x, int y, int alignment = kAlignLeft); + void drawText(int textId, int x, int y, int alignment = kAlignLeft); +}; - int getTextWidth(char *text) { - int textWidth = 0; +FontRendererGui::FontRendererGui(Gui *gui, int fontId) + : _gui(gui), _fontId(fontId) { + uint8 *font = _gui->_vm->_resman->openResource(fontId); + _frameHeader *head; + _spriteInfo sprite; - for (int i = 0; text[i]; i++) - textWidth += (_glyph[text[i] - 32]._width - CHARACTER_OVERLAP); - return textWidth; + sprite.type = RDSPR_NOCOMPRESSION | RDSPR_TRANS; + + for (int i = 0; i < SIZE_OF_CHAR_SET; i++) { + head = (_frameHeader *) _gui->_vm->fetchFrameHeader(font, i); + sprite.data = (uint8 *) (head + 1); + sprite.w = head->width; + sprite.h = head->height; + _gui->_vm->_graphics->createSurface(&sprite, &_glyph[i]._data); + _glyph[i]._width = head->width; + _glyph[i]._height = head->height; } - int getTextWidth(int textId) { - char text[MAX_STRING_LEN]; + _gui->_vm->_resman->closeResource(fontId); +} + +FontRendererGui::~FontRendererGui() { + for (int i = 0; i < SIZE_OF_CHAR_SET; i++) + _gui->_vm->_graphics->deleteSurface(_glyph[i]._data); +} + +void FontRendererGui::fetchText(int textId, char *buf) { + uint8 *data = _gui->_vm->fetchTextLine(_gui->_vm->_resman->openResource(textId / SIZE), textId & 0xffff); + int i; - fetchText(textId, text); - return getTextWidth(text); + for (i = 0; data[i + 2]; i++) { + if (buf) + buf[i] = data[i + 2]; } + + buf[i] = 0; + _gui->_vm->_resman->closeResource(textId / SIZE); +} - void drawText(char *text, int x, int y, int alignment = kAlignLeft); - void drawText(int textId, int x, int y, int alignment = kAlignLeft); -}; +int FontRendererGui::getTextWidth(char *text) { + int textWidth = 0; + + for (int i = 0; text[i]; i++) + textWidth += (_glyph[text[i] - 32]._width - CHARACTER_OVERLAP); + return textWidth; +} + +int FontRendererGui::getTextWidth(int textId) { + char text[MAX_STRING_LEN]; + + fetchText(textId, text); + return getTextWidth(text); +} void FontRendererGui::drawText(char *text, int x, int y, int alignment) { _spriteInfo sprite; @@ -144,7 +227,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_graphics->drawSurface(&sprite, _glyph[text[i] - 32]._data); + _gui->_vm->_graphics->drawSurface(&sprite, _glyph[text[i] - 32]._data); sprite.x += (_glyph[(int) text[i] - 32]._width - CHARACTER_OVERLAP); } @@ -157,91 +240,127 @@ void FontRendererGui::drawText(int textId, int x, int y, int alignment) { drawText(text, x, y, alignment); } -class Dialog; +// +// Dialog class functions +// -typedef struct Surface { - uint8 *_surface; - bool _original; -} WidgetSurface; +Dialog::Dialog(Gui *gui) + : _numWidgets(0), _finish(false), _result(0), _gui(gui) { + _gui->_vm->setFullPalette(CONTROL_PANEL_PALETTE); +} -class Widget { -protected: - Dialog *_parent; +Dialog::~Dialog() { + for (int i = 0; i < _numWidgets; i++) + delete _widgets[i]; +} - _spriteInfo *_sprites; - WidgetSurface *_surfaces; - int _numStates; - int _state; +void Dialog::registerWidget(Widget *widget) { + if (_numWidgets < MAX_WIDGETS) + _widgets[_numWidgets++] = widget; +} - Common::Rect _hitRect; +void Dialog::paint() { + _gui->_vm->_graphics->clearScene(); + for (int i = 0; i < _numWidgets; i++) + _widgets[i]->paint(); +} -public: - Widget(Dialog *parent, int states) : - _parent(parent), _numStates(states), _state(0) { - _sprites = (_spriteInfo *) calloc(states, sizeof(_spriteInfo)); - _surfaces = (WidgetSurface *) calloc(states, sizeof(WidgetSurface)); +void Dialog::setResult(int result) { + _result = result; + _finish = true; +} - _hitRect.left = _hitRect.right = _hitRect.top = _hitRect.bottom = -1; - } +int Dialog::run() { + int i; - virtual ~Widget() { - for (int i = 0; i < _numStates; i++) { - if (_surfaces[i]._original) - g_graphics->deleteSurface(_surfaces[i]._surface); - } - free(_sprites); - free(_surfaces); - } + paint(); - void createSurfaceImage(int state, uint32 res, int x, int y, uint32 pc); - void linkSurfaceImage(Widget *from, int state, int x, int y); + int16 oldMouseX = -1; + int16 oldMouseY = -1; - void createSurfaceImages(uint32 res, int x, int y) { - for (int i = 0; i < _numStates; i++) - createSurfaceImage(i, res, x, y, i); - } + while (!_finish) { + // So that the menu icons will reach their full size + _gui->_vm->_graphics->processMenu(); + _gui->_vm->_graphics->updateDisplay(); - void linkSurfaceImages(Widget *from, int x, int y) { - for (int i = 0; i < from->_numStates; i++) - linkSurfaceImage(from, i, x, y); - } + int16 newMouseX = _gui->_vm->_input->_mouseX; + int16 newMouseY = _gui->_vm->_input->_mouseY + 40; - void setHitRect(int x, int y, int width, int height) { - _hitRect.left = x; - _hitRect.right = x + width; - _hitRect.top = y; - _hitRect.bottom = y + height; - } + _mouseEvent *me = _gui->_vm->_input->mouseEvent(); + _keyboardEvent ke; + int32 keyboardStatus = _gui->_vm->_input->readKey(&ke); - bool isHit(int16 x, int16 y) { - return _hitRect.left >= 0 && _hitRect.contains(x, y); - } + if (keyboardStatus == RD_OK) { + if (ke.keycode == 27) + setResult(0); + else if (ke.keycode == '\n' || ke.keycode == '\r') + setResult(1); + } - void setState(int state) { - if (state != _state) { - _state = state; - paint(); + for (i = 0; i < _numWidgets; i++) { + bool oldHit = _widgets[i]->isHit(oldMouseX, oldMouseY); + bool newHit = _widgets[i]->isHit(newMouseX, newMouseY); + + if (!oldHit && newHit) + _widgets[i]->onMouseEnter(); + if (oldHit && !newHit) + _widgets[i]->onMouseExit(); + if (_gui->_vm->_input->_mouseX != oldMouseX || _gui->_vm->_input->_mouseY != oldMouseY) + _widgets[i]->onMouseMove(newMouseX, newMouseY); + + if (me) { + switch (me->buttons) { + case RD_LEFTBUTTONDOWN: + if (newHit) + _widgets[i]->onMouseDown(newMouseX, newMouseY); + break; + case RD_LEFTBUTTONUP: + if (newHit) + _widgets[i]->onMouseUp(newMouseX, newMouseY); + // So that slider widgets will know + // when the user releases the mouse + // button, even if the cursor is + // outside of the slider's hit area. + _widgets[i]->releaseMouse(newMouseX, newMouseY); + break; + } + } + + if (keyboardStatus == RD_OK) + _widgets[i]->onKey(&ke); + + _widgets[i]->onTick(); } - } - int getState() { - return _state; - } + oldMouseX = newMouseX; + oldMouseY = newMouseY; - virtual void paint(Common::Rect *clipRect = NULL) { - g_graphics->drawSurface(&_sprites[_state], _surfaces[_state]._surface, clipRect); + _gui->_vm->_system->delay_msecs(20); } - virtual void onMouseEnter() {} - virtual void onMouseExit() {} - virtual void onMouseMove(int x, int y) {} - virtual void onMouseDown(int x, int y) {} - virtual void onMouseUp(int x, int y) {} - virtual void onKey(_keyboardEvent *ke) {} - virtual void onTick() {} + return _result; +} - virtual void releaseMouse(int x, int y) {} -}; +// +// Widget functions +// + +Widget::Widget(Dialog *parent, int states) + : _parent(parent), _numStates(states), _state(0) { + _sprites = (_spriteInfo *) calloc(states, sizeof(_spriteInfo)); + _surfaces = (WidgetSurface *) calloc(states, sizeof(WidgetSurface)); + + _hitRect.left = _hitRect.right = _hitRect.top = _hitRect.bottom = -1; +} + +Widget::~Widget() { + for (int i = 0; i < _numStates; i++) { + if (_surfaces[i]._original) + _parent->_gui->_vm->_graphics->deleteSurface(_surfaces[i]._surface); + } + free(_sprites); + free(_surfaces); +} void Widget::createSurfaceImage(int state, uint32 res, int x, int y, uint32 pc) { uint8 *file, *colTablePtr = NULL; @@ -251,11 +370,11 @@ void Widget::createSurfaceImage(int state, uint32 res, int x, int y, uint32 pc) uint32 spriteType = RDSPR_TRANS; // open anim resource file, point to base - file = res_man->openResource(res); + file = _parent->_gui->_vm->_resman->openResource(res); - anim_head = g_sword2->fetchAnimHeader(file); - cdt_entry = g_sword2->fetchCdtEntry(file, pc); - frame_head = g_sword2->fetchFrameHeader(file, pc); + anim_head = _parent->_gui->_vm->fetchAnimHeader(file); + cdt_entry = _parent->_gui->_vm->fetchCdtEntry(file, pc); + frame_head = _parent->_gui->_vm->fetchFrameHeader(file, pc); // If the frame is flipped. (Only really applicable to frames using // offsets.) @@ -292,11 +411,11 @@ 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_graphics->createSurface(&_sprites[state], &_surfaces[state]._surface); + _parent->_gui->_vm->_graphics->createSurface(&_sprites[state], &_surfaces[state]._surface); _surfaces[state]._original = true; // Release the anim resource - res_man->closeResource(res); + _parent->_gui->_vm->_resman->closeResource(res); }; void Widget::linkSurfaceImage(Widget *from, int state, int x, int y) { @@ -312,122 +431,50 @@ void Widget::linkSurfaceImage(Widget *from, int state, int x, int y) { _surfaces[state]._original = false; }; -#define MAX_WIDGETS 25 - -class Dialog { -private: - int _numWidgets; - Widget *_widgets[MAX_WIDGETS]; - bool _finish; - int _result; - -public: - Dialog() : _numWidgets(0), _finish(false), _result(0) { - g_sword2->setFullPalette(CONTROL_PANEL_PALETTE); - } - - virtual ~Dialog() { - for (int i = 0; i < _numWidgets; i++) - delete _widgets[i]; - } +void Widget::createSurfaceImages(uint32 res, int x, int y) { + for (int i = 0; i < _numStates; i++) + createSurfaceImage(i, res, x, y, i); +} - void registerWidget(Widget *widget) { - if (_numWidgets < MAX_WIDGETS) { - _widgets[_numWidgets++] = widget; - } - } +void Widget::linkSurfaceImages(Widget *from, int x, int y) { + for (int i = 0; i < from->_numStates; i++) + linkSurfaceImage(from, i, x, y); +} - virtual void onAction(Widget *widget, int result = 0) {} +void Widget::setHitRect(int x, int y, int width, int height) { + _hitRect.left = x; + _hitRect.right = x + width; + _hitRect.top = y; + _hitRect.bottom = y + height; +} - virtual void paint() { - g_graphics->clearScene(); - for (int i = 0; i < _numWidgets; i++) - _widgets[i]->paint(); - } +bool Widget::isHit(int16 x, int16 y) { + return _hitRect.left >= 0 && _hitRect.contains(x, y); +} - virtual void setResult(int result) { - _result = result; - _finish = true; +void Widget::setState(int state) { + if (state != _state) { + _state = state; + paint(); } +} - int run(); -}; - -int Dialog::run() { - int i; - - paint(); - - int16 oldMouseX = -1; - int16 oldMouseY = -1; - - while (!_finish) { - // So that the menu icons will reach their full size - g_graphics->processMenu(); - g_graphics->updateDisplay(); - - int16 newMouseX = g_input->_mouseX; - int16 newMouseY = g_input->_mouseY + 40; - - _mouseEvent *me = g_input->mouseEvent(); - _keyboardEvent ke; - int32 keyboardStatus = g_input->readKey(&ke); - - if (keyboardStatus == RD_OK) { - if (ke.keycode == 27) - setResult(0); - else if (ke.keycode == '\n' || ke.keycode == '\r') - setResult(1); - } - - for (i = 0; i < _numWidgets; i++) { - bool oldHit = _widgets[i]->isHit(oldMouseX, oldMouseY); - bool newHit = _widgets[i]->isHit(newMouseX, newMouseY); - - if (!oldHit && newHit) - _widgets[i]->onMouseEnter(); - if (oldHit && !newHit) - _widgets[i]->onMouseExit(); - if (g_input->_mouseX != oldMouseX || g_input->_mouseY != oldMouseY) - _widgets[i]->onMouseMove(newMouseX, newMouseY); - - if (me) { - switch (me->buttons) { - case RD_LEFTBUTTONDOWN: - if (newHit) - _widgets[i]->onMouseDown(newMouseX, newMouseY); - break; - case RD_LEFTBUTTONUP: - if (newHit) - _widgets[i]->onMouseUp(newMouseX, newMouseY); - // So that slider widgets will know - // when the user releases the mouse - // button, even if the cursor is - // outside of the slider's hit area. - _widgets[i]->releaseMouse(newMouseX, newMouseY); - break; - } - } - - if (keyboardStatus == RD_OK) - _widgets[i]->onKey(&ke); - - _widgets[i]->onTick(); - } - - oldMouseX = newMouseX; - oldMouseY = newMouseY; - - g_system->delay_msecs(20); - } +int Widget::getState() { + return _state; +} - return _result; +void Widget::paint(Common::Rect *clipRect) { + _parent->_gui->_vm->_graphics->drawSurface(&_sprites[_state], _surfaces[_state]._surface, clipRect); } +/** + * Standard button class. + */ + class Button : public Widget { public: - Button(Dialog *parent, int x, int y, int w, int h) : - Widget(parent, 2) { + Button(Dialog *parent, int x, int y, int w, int h) + : Widget(parent, 2) { setHitRect(x, y, w, h); } @@ -447,13 +494,18 @@ public: } }; +/** + * Scroll buttons are used to scroll the savegame list. The difference between + * this and a normal button is that we want this to repeat. + */ + class ScrollButton : public Widget { private: uint32 _holdCounter; public: - ScrollButton(Dialog *parent, int x, int y, int w, int h) : - Widget(parent, 2), _holdCounter(0) { + ScrollButton(Dialog *parent, int x, int y, int w, int h) + : Widget(parent, 2), _holdCounter(0) { setHitRect(x, y, w, h); } @@ -480,15 +532,20 @@ public: } }; +/** + * A switch is a button that changes state when clicked, and keeps that state + * until clicked again. + */ + class Switch : public Widget { private: bool _holding, _value; int _upState, _downState; public: - Switch(Dialog *parent, int x, int y, int w, int h) : - Widget(parent, 2), _holding(false), - _value(false), _upState(0), _downState(1) { + Switch(Dialog *parent, int x, int y, int w, int h) + : Widget(parent, 2), _holding(false), _value(false), + _upState(0), _downState(1) { setHitRect(x, y, w, h); } @@ -537,6 +594,10 @@ public: } }; +/** + * A slider is used to specify a value within a pre-defined range. + */ + class Slider : public Widget { private: Widget *_background; @@ -555,10 +616,10 @@ private: public: Slider(Dialog *parent, Widget *background, int max, - int x, int y, int w, int h, Widget *base = NULL) : - Widget(parent, 1), _background(background), - _dragging(false), _value(0), _targetValue(0), - _maxValue(max) { + int x, int y, int w, int h, Widget *base = NULL) + : Widget(parent, 1), _background(background), + _dragging(false), _value(0), _targetValue(0), + _maxValue(max) { setHitRect(x, y, w, h); if (base) @@ -654,9 +715,12 @@ public: } }; +/** + * A "mini" dialog is basically a yes/no question. + */ + class MiniDialog : public Dialog { private: - Sword2Engine *_vm; int _textId; FontRendererGui *_fr; Widget *_panel; @@ -664,8 +728,9 @@ private: Button *_cancelButton; public: - MiniDialog(int fontId, uint32 textId) : _textId(textId) { - _fr = new FontRendererGui(fontId); + MiniDialog(Gui *gui, uint32 textId) + : Dialog(gui), _textId(textId) { + _fr = new FontRendererGui(_gui, _gui->_vm->_controlsFontId); _panel = new Widget(this, 1); _panel->createSurfaceImages(1996, 203, 104); @@ -688,7 +753,7 @@ public: virtual void paint() { Dialog::paint(); - _fr->drawText(_textId, 310, 134, kAlignCenter); + _fr->drawText(_textId, 310, 134, FontRendererGui::kAlignCenter); _fr->drawText(149618688, 270, 214); // ok _fr->drawText(149618689, 270, 276); // cancel } @@ -701,6 +766,10 @@ public: } }; +/** + * The game settings dialog. + */ + class OptionsDialog : public Dialog { private: FontRendererGui *_fr; @@ -720,8 +789,8 @@ private: Button *_cancelButton; public: - OptionsDialog() { - _fr = new FontRendererGui(g_sword2->_controlsFontId); + OptionsDialog(Gui *gui) : Dialog(gui) { + _fr = new FontRendererGui(gui, gui->_vm->_controlsFontId); _panel = new Widget(this, 1); _panel->createSurfaceImages(3405, 0, 40); @@ -776,19 +845,19 @@ public: registerWidget(_okButton); registerWidget(_cancelButton); - gui->readOptionSettings(); + _gui->readOptionSettings(); - _objectLabelsSwitch->setValue(gui->_pointerTextSelected); - _subtitlesSwitch->setValue(gui->_subtitles); - _reverseStereoSwitch->setValue(gui->_stereoReversed); - _musicSwitch->setValue(!g_sound->isMusicMute()); - _speechSwitch->setValue(!g_sound->isSpeechMute()); - _fxSwitch->setValue(!g_sound->isFxMute()); - _musicSlider->setValue(g_sound->getMusicVolume()); - _speechSlider->setValue(g_sound->getSpeechVolume()); - _fxSlider->setValue(g_sound->getFxVolume()); - _gfxSlider->setValue(g_graphics->getRenderLevel()); - _gfxPreview->setState(g_graphics->getRenderLevel()); + _objectLabelsSwitch->setValue(_gui->_pointerTextSelected); + _subtitlesSwitch->setValue(_gui->_subtitles); + _reverseStereoSwitch->setValue(_gui->_stereoReversed); + _musicSwitch->setValue(!_gui->_vm->_sound->isMusicMute()); + _speechSwitch->setValue(!_gui->_vm->_sound->isSpeechMute()); + _fxSwitch->setValue(!_gui->_vm->_sound->isFxMute()); + _musicSlider->setValue(_gui->_vm->_sound->getMusicVolume()); + _speechSlider->setValue(_gui->_vm->_sound->getSpeechVolume()); + _fxSlider->setValue(_gui->_vm->_sound->getFxVolume()); + _gfxSlider->setValue(_gui->_vm->_graphics->getRenderLevel()); + _gfxPreview->setState(_gui->_vm->_graphics->getRenderLevel()); } ~OptionsDialog() { @@ -817,9 +886,9 @@ public: } // Options - _fr->drawText(149618698, 321, 55, kAlignCenter); + _fr->drawText(149618698, 321, 55, FontRendererGui::kAlignCenter); // Subtitles - _fr->drawText(149618699, 500, 103, kAlignRight); + _fr->drawText(149618699, 500, 103, FontRendererGui::kAlignRight); // Object labels _fr->drawText(149618700, 299 - maxWidth, 103); // Music volume @@ -833,9 +902,9 @@ public: // Graphics quality _fr->drawText(149618705, 299 - maxWidth, 341); // Ok - _fr->drawText(149618688, 193, 382, kAlignRight); + _fr->drawText(149618688, 193, 382, FontRendererGui::kAlignRight); // Cancel - _fr->drawText(149618689, 385, 382, kAlignRight); + _fr->drawText(149618689, 385, 382, FontRendererGui::kAlignRight); } virtual void onAction(Widget *widget, int result = 0) { @@ -843,10 +912,10 @@ public: // we need to update music volume immediately. if (widget == _musicSwitch) { - g_sound->muteMusic(result != 0); + _gui->_vm->_sound->muteMusic(result != 0); } else if (widget == _musicSlider) { - g_sound->setMusicVolume(result); - g_sound->muteMusic(result == 0); + _gui->_vm->_sound->setMusicVolume(result); + _gui->_vm->_sound->muteMusic(result == 0); _musicSwitch->setValue(result != 0); } else if (widget == _speechSlider) { _speechSwitch->setValue(result != 0); @@ -854,33 +923,35 @@ public: _fxSwitch->setValue(result != 0); } else if (widget == _gfxSlider) { _gfxPreview->setState(result); - gui->updateGraphicsLevel(result); + _gui->updateGraphicsLevel(result); } else if (widget == _okButton) { - gui->_subtitles = _subtitlesSwitch->getValue(); - gui->_pointerTextSelected = _objectLabelsSwitch->getValue(); - gui->_stereoReversed = _reverseStereoSwitch->getValue(); + _gui->_subtitles = _subtitlesSwitch->getValue(); + _gui->_pointerTextSelected = _objectLabelsSwitch->getValue(); + _gui->_stereoReversed = _reverseStereoSwitch->getValue(); // Apply the changes - g_sound->muteMusic(!_musicSwitch->getValue()); - g_sound->muteSpeech(!_speechSwitch->getValue()); - g_sound->muteFx(!_fxSwitch->getValue()); - g_sound->setMusicVolume(_musicSlider->getValue()); - g_sound->setSpeechVolume(_speechSlider->getValue()); - g_sound->setFxVolume(_fxSlider->getValue()); - g_sound->buildPanTable(gui->_stereoReversed); + _gui->_vm->_sound->muteMusic(!_musicSwitch->getValue()); + _gui->_vm->_sound->muteSpeech(!_speechSwitch->getValue()); + _gui->_vm->_sound->muteFx(!_fxSwitch->getValue()); + _gui->_vm->_sound->setMusicVolume(_musicSlider->getValue()); + _gui->_vm->_sound->setSpeechVolume(_speechSlider->getValue()); + _gui->_vm->_sound->setFxVolume(_fxSlider->getValue()); + _gui->_vm->_sound->buildPanTable(_gui->_stereoReversed); - gui->updateGraphicsLevel(_gfxSlider->getValue()); + _gui->updateGraphicsLevel(_gfxSlider->getValue()); - gui->writeOptionSettings(); + _gui->writeOptionSettings(); setResult(1); } else if (widget == _cancelButton) { // Revert the changes - gui->readOptionSettings(); + _gui->readOptionSettings(); setResult(0); } } }; +// FIXME: Move these into some class + enum { kSaveDialog, kLoadDialog @@ -902,9 +973,8 @@ private: bool _editable; public: - Slot(Dialog *parent, int x, int y, int w, int h) : - Widget(parent, 2), _clickable(false), - _editable(false) { + Slot(Dialog *parent, int x, int y, int w, int h) + : Widget(parent, 2), _clickable(false), _editable(false) { setHitRect(x, y, w, h); _text[0] = 0; } @@ -988,8 +1058,6 @@ public: class SaveLoadDialog : public Dialog { private: - Sword2Engine *_vm; - int _mode, _selectedSlot; char _editBuffer[SAVE_DESCRIPTION_LEN]; int _editPos, _firstPos; @@ -1009,15 +1077,15 @@ private: void saveLoadError(char *text); public: - SaveLoadDialog(Sword2Engine *vm, int mode) - : _vm(vm), _mode(mode), _selectedSlot(-1) { + SaveLoadDialog(Gui *gui, int mode) + : Dialog(gui), _mode(mode), _selectedSlot(-1) { int i; // FIXME: The "control font" and the "red font" are currently // always the same font, so one should be eliminated. - _fr1 = new FontRendererGui(_vm->_controlsFontId); - _fr2 = new FontRendererGui(_vm->_redFontId); + _fr1 = new FontRendererGui(_gui, _gui->_vm->_controlsFontId); + _fr2 = new FontRendererGui(_gui, _gui->_vm->_redFontId); _panel = new Widget(this, 1); _panel->createSurfaceImages(2016, 0, 40); @@ -1074,13 +1142,13 @@ public: void updateSlots() { for (int i = 0; i < 8; i++) { - Slot *slot = _slotButton[(gui->_baseSlot + i) % 8]; + Slot *slot = _slotButton[(_gui->_baseSlot + i) % 8]; FontRendererGui *fr; uint8 description[SAVE_DESCRIPTION_LEN]; slot->setY(72 + i * 36); - if (gui->_baseSlot + i == _selectedSlot) { + if (_gui->_baseSlot + i == _selectedSlot) { slot->setEditable(_mode == kSaveDialog); slot->setState(1); fr = _fr2; @@ -1090,11 +1158,11 @@ public: fr = _fr1; } - if (_vm->getSaveDescription(gui->_baseSlot + i, description) == SR_OK) { - slot->setText(fr, gui->_baseSlot + i, (char *) description); + if (_gui->_vm->getSaveDescription(_gui->_baseSlot + i, description) == SR_OK) { + slot->setText(fr, _gui->_baseSlot + i, (char *) description); slot->setClickable(true); } else { - slot->setText(fr, gui->_baseSlot + i, NULL); + slot->setText(fr, _gui->_baseSlot + i, NULL); slot->setClickable(_mode == kSaveDialog); } @@ -1107,29 +1175,29 @@ public: virtual void onAction(Widget *widget, int result = 0) { if (widget == _zupButton) { - if (gui->_baseSlot > 0) { - if (gui->_baseSlot >= 8) - gui->_baseSlot -= 8; + if (_gui->_baseSlot > 0) { + if (_gui->_baseSlot >= 8) + _gui->_baseSlot -= 8; else - gui->_baseSlot = 0; + _gui->_baseSlot = 0; updateSlots(); } } else if (widget == _upButton) { - if (gui->_baseSlot > 0) { - gui->_baseSlot--; + if (_gui->_baseSlot > 0) { + _gui->_baseSlot--; updateSlots(); } } else if (widget == _downButton) { - if (gui->_baseSlot < 92) { - gui->_baseSlot++; + if (_gui->_baseSlot < 92) { + _gui->_baseSlot++; updateSlots(); } } else if (widget == _zdownButton) { - if (gui->_baseSlot < 92) { - if (gui->_baseSlot <= 84) - gui->_baseSlot += 8; + if (_gui->_baseSlot < 92) { + if (_gui->_baseSlot <= 84) + _gui->_baseSlot += 8; else - gui->_baseSlot = 92; + _gui->_baseSlot = 92; updateSlots(); } } else if (widget == _okButton) { @@ -1187,7 +1255,7 @@ public: } } else { if (result == kSelectSlot) - _selectedSlot = gui->_baseSlot + (slot->getY() - 72) / 35; + _selectedSlot = _gui->_baseSlot + (slot->getY() - 72) / 35; else if (result == kDeselectSlot) _selectedSlot = -1; @@ -1215,7 +1283,7 @@ public: // but I doubt that will make any noticeable difference. slot->paint(); - _fr2->drawText(_editBuffer, 130, 78 + (_selectedSlot - gui->_baseSlot) * 36); + _fr2->drawText(_editBuffer, 130, 78 + (_selectedSlot - _gui->_baseSlot) * 36); } virtual void paint() { @@ -1251,7 +1319,7 @@ public: _editBuffer[_editPos] = 0; - uint32 rv = _vm->saveGame(_selectedSlot, (uint8 *) &_editBuffer[_firstPos]); + uint32 rv = _gui->_vm->saveGame(_selectedSlot, (uint8 *) &_editBuffer[_firstPos]); if (rv != SR_OK) { uint32 textId; @@ -1265,11 +1333,11 @@ public: break; } - saveLoadError((char *) (g_sword2->fetchTextLine(res_man->openResource(textId / SIZE), textId & 0xffff) + 2)); + saveLoadError((char *) (_gui->_vm->fetchTextLine(_gui->_vm->_resman->openResource(textId / SIZE), textId & 0xffff) + 2)); result = 0; } } else { - uint32 rv = _vm->restoreGame(_selectedSlot); + uint32 rv = _gui->_vm->restoreGame(_selectedSlot); if (rv != SR_OK) { uint32 textId; @@ -1286,20 +1354,20 @@ public: break; } - saveLoadError((char *) (g_sword2->fetchTextLine(res_man->openResource(textId / SIZE), textId & 0xffff) + 2)); + saveLoadError((char *) (_gui->_vm->fetchTextLine(_gui->_vm->_resman->openResource(textId / SIZE), textId & 0xffff) + 2)); result = 0; } else { // Prime system with a game cycle // Reset the graphic 'buildit' list before a // new logic list (see fnRegisterFrame) - _vm->resetRenderLists(); + _gui->_vm->resetRenderLists(); // Reset the mouse hot-spot list (see // fnRegisterMouse and fnRegisterFrame) - _vm->resetMouseList(); + _gui->_vm->resetMouseList(); - if (_vm->_logic->processSession()) + if (_gui->_vm->_logic->processSession()) error("restore 1st cycle failed??"); } } @@ -1310,31 +1378,31 @@ public: void SaveLoadDialog::saveLoadError(char* text) { // Print a message on screen. Second parameter is duration. - g_sword2->displayMsg((uint8 *) text, 0); + _gui->_vm->displayMsg((uint8 *) text, 0); // Wait for ESC or mouse click while (1) { _mouseEvent *me; - g_graphics->updateDisplay(); + _gui->_vm->_graphics->updateDisplay(); - if (g_input->keyWaiting()) { + if (_gui->_vm->_input->keyWaiting()) { _keyboardEvent ke; - g_input->readKey(&ke); + _gui->_vm->_input->readKey(&ke); if (ke.keycode == 27) break; } - me = g_input->mouseEvent(); + me = _gui->_vm->_input->mouseEvent(); if (me && (me->buttons & RD_LEFTBUTTONDOWN)) break; - g_system->delay_msecs(20); + _gui->_vm->_system->delay_msecs(20); } // Remove the message. - g_sword2->removeMsg(); + _gui->_vm->removeMsg(); } Gui::Gui(Sword2Engine *vm) : _vm(vm), _baseSlot(0) { @@ -1371,23 +1439,23 @@ void Gui::readOptionSettings(void) { updateGraphicsLevel((uint8) ConfMan.getInt("gfx_details")); - g_sound->setMusicVolume((16 * ConfMan.getInt("music_volume")) / 255); - g_sound->setSpeechVolume((14 * ConfMan.getInt("speech_volume")) / 255); - g_sound->setFxVolume((14 * ConfMan.getInt("sfx_volume")) / 255); - g_sound->muteMusic(ConfMan.getBool("music_mute")); - g_sound->muteSpeech(ConfMan.getBool("speech_mute")); - g_sound->muteFx(ConfMan.getBool("sfx_mute")); - g_sound->buildPanTable(_stereoReversed); + _vm->_sound->setMusicVolume((16 * ConfMan.getInt("music_volume")) / 255); + _vm->_sound->setSpeechVolume((14 * ConfMan.getInt("speech_volume")) / 255); + _vm->_sound->setFxVolume((14 * ConfMan.getInt("sfx_volume")) / 255); + _vm->_sound->muteMusic(ConfMan.getBool("music_mute")); + _vm->_sound->muteSpeech(ConfMan.getBool("speech_mute")); + _vm->_sound->muteFx(ConfMan.getBool("sfx_mute")); + _vm->_sound->buildPanTable(_stereoReversed); } void Gui::writeOptionSettings(void) { - ConfMan.set("music_volume", _musicVolume[g_sound->getMusicVolume()]); - ConfMan.set("speech_volume", _soundVolume[g_sound->getSpeechVolume()]); - ConfMan.set("sfx_volume", _soundVolume[g_sound->getFxVolume()]); - 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_graphics->getRenderLevel()); + ConfMan.set("music_volume", _musicVolume[_vm->_sound->getMusicVolume()]); + ConfMan.set("speech_volume", _soundVolume[_vm->_sound->getSpeechVolume()]); + ConfMan.set("sfx_volume", _soundVolume[_vm->_sound->getFxVolume()]); + ConfMan.set("music_mute", _vm->_sound->isMusicMute()); + ConfMan.set("speech_mute", _vm->_sound->isSpeechMute()); + ConfMan.set("sfx_mute", _vm->_sound->isFxMute()); + ConfMan.set("gfx_details", _vm->_graphics->getRenderLevel()); ConfMan.set("nosubtitles", !_subtitles); ConfMan.set("object_labels", _pointerTextSelected); ConfMan.set("reverse_stereo", _stereoReversed); @@ -1399,17 +1467,17 @@ uint32 Gui::restoreControl(void) { // returns 0 for no restore // 1 for restored ok - SaveLoadDialog loadDialog(_vm, kLoadDialog); + SaveLoadDialog loadDialog(this, kLoadDialog); return loadDialog.run(); } void Gui::saveControl(void) { - SaveLoadDialog saveDialog(_vm, kSaveDialog); + SaveLoadDialog saveDialog(this, kSaveDialog); saveDialog.run(); } void Gui::quitControl(void) { - MiniDialog quitDialog(_vm->_controlsFontId, 149618692); + MiniDialog quitDialog(this, 149618692); if (quitDialog.run()) _vm->closeGame(); @@ -1418,7 +1486,7 @@ void Gui::quitControl(void) { void Gui::restartControl(void) { uint32 temp_demo_flag; - MiniDialog restartDialog(_vm->_controlsFontId, 149618693); + MiniDialog restartDialog(this, 149618693); if (!restartDialog.run()) return; @@ -1431,19 +1499,19 @@ void Gui::restartControl(void) { // In case we were dead - well we're not anymore! DEAD = 0; - g_graphics->clearScene(); + _vm->_graphics->clearScene(); // Restart the game. Clear all memory and reset the globals temp_demo_flag = DEMO; // Remove all resources from memory, including player object and // global variables - res_man->removeAll(); + _vm->_resman->removeAll(); // Reopen global variables resource & send address to interpreter - // it won't be moving - _vm->_logic->setGlobalInterpreterVariables((int32 *) (res_man->openResource(1) + sizeof(_standardHeader))); - res_man->closeResource(1); + _vm->_logic->setGlobalInterpreterVariables((int32 *) (_vm->_resman->openResource(1) + sizeof(_standardHeader))); + _vm->_resman->closeResource(1); DEMO = temp_demo_flag; @@ -1463,7 +1531,7 @@ void Gui::restartControl(void) { // fnRegisterFrame) _vm->resetMouseList(); - g_graphics->closeMenuImmediately(); + _vm->_graphics->closeMenuImmediately(); // FOR THE DEMO - FORCE THE SCROLLING TO BE RESET! // - this is taken from fnInitBackground @@ -1479,7 +1547,7 @@ void Gui::restartControl(void) { } void Gui::optionControl(void) { - OptionsDialog optionsDialog; + OptionsDialog optionsDialog(this); optionsDialog.run(); return; @@ -1491,7 +1559,7 @@ void Gui::updateGraphicsLevel(int newLevel) { else if (newLevel > 3) newLevel = 3; - g_graphics->setRenderLevel(newLevel); + _vm->_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/controls.h b/sword2/controls.h index 169667cbbb..2b7675862e 100644 --- a/sword2/controls.h +++ b/sword2/controls.h @@ -26,12 +26,12 @@ class Sword2Engine; class Gui { private: - Sword2Engine *_vm; - int _musicVolume[17]; int _soundVolume[15]; public: + Sword2Engine *_vm; + int _baseSlot; uint8 _currentGraphicsLevel; @@ -51,8 +51,6 @@ public: void updateGraphicsLevel(int newLevel); }; -extern Gui *gui; - } // End of namespace Sword2 #endif diff --git a/sword2/credits.h b/sword2/credits.h deleted file mode 100644 index 913c0cec16..0000000000 --- a/sword2/credits.h +++ /dev/null @@ -1,32 +0,0 @@ -/* Copyright (C) 1994-2003 Revolution Software Ltd - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Header$ - */ - -#ifndef _CREDITS_H -#define _CREDITS_H - -#include "sword2/driver/driver96.h" - -namespace Sword2 { - -// int32 __declspec( dllexport ) Credits(_drvDrawStatus *pDrawStatus, _drvSoundStatus *pSoundStatus, const char *cdPath, BOOL smoke, BOOL *pAppFocus, _drvKeyStatus *pKeyStatus); -//int32 Credits(_drvDrawStatus *pDrawStatus, _drvSoundStatus *pSoundStatus, const char *cdPath, BOOL smoke, BOOL *pAppFocus, _drvKeyStatus *pKeyStatus); - -} // End of namespace Sword2 - -#endif diff --git a/sword2/debug.cpp b/sword2/debug.cpp index 669a2dc94c..f8eb726403 100644 --- a/sword2/debug.cpp +++ b/sword2/debug.cpp @@ -17,21 +17,9 @@ * $Header$ */ -#include "stdafx.h" -#include "sword2/driver/driver96.h" +#include "common/stdafx.h" #include "sword2/sword2.h" -#include "sword2/debug.h" -#include "sword2/console.h" #include "sword2/defs.h" -#include "sword2/layers.h" -#include "sword2/logic.h" -#include "sword2/maketext.h" -#include "sword2/mouse.h" -#include "sword2/protocol.h" -#include "sword2/resman.h" -#include "sword2/router.h" // for plotWalkGrid() -#include "sword2/speech.h" // for '_officialTextNumber' - // and '_speechScriptWaiting' namespace Sword2 { @@ -40,7 +28,7 @@ void Debugger::clearDebugTextBlocks(void) { while (blockNo < MAX_DEBUG_TEXT_BLOCKS && _debugTextBlocks[blockNo] > 0) { // kill the system text block - fontRenderer->killTextBloc(_debugTextBlocks[blockNo]); + _vm->_fontRenderer->killTextBloc(_debugTextBlocks[blockNo]); // clear this element of our array of block numbers _debugTextBlocks[blockNo] = 0; @@ -57,7 +45,7 @@ void Debugger::makeDebugTextBlock(char *text, int16 x, int16 y) { assert(blockNo < MAX_DEBUG_TEXT_BLOCKS); - _debugTextBlocks[blockNo] = fontRenderer->buildNewBloc((uint8 *) text, x, y, 640 - x, 0, RDSPR_DISPLAYALIGN, CONSOLE_FONT_ID, NO_JUSTIFICATION); + _debugTextBlocks[blockNo] = _vm->_fontRenderer->buildNewBloc((uint8 *) text, x, y, 640 - x, 0, RDSPR_DISPLAYALIGN, CONSOLE_FONT_ID, NO_JUSTIFICATION); } void Debugger::buildDebugText(void) { @@ -120,7 +108,7 @@ void Debugger::buildDebugText(void) { // debug info at top of screen - enabled/disabled as one complete unit if (_displayTime) { - int32 time = g_system->get_msecs(); + int32 time = _vm->_system->get_msecs(); if ((time - _startTime) / 1000 >= 10000) _startTime = time; @@ -186,14 +174,14 @@ void Debugger::buildDebugText(void) { if (_vm->_mouseTouching) sprintf(buf, "mouse %d,%d (id %d: %s)", - g_input->_mouseX + _vm->_thisScreen.scroll_offset_x, - g_input->_mouseY + _vm->_thisScreen.scroll_offset_y, + _vm->_input->_mouseX + _vm->_thisScreen.scroll_offset_x, + _vm->_input->_mouseY + _vm->_thisScreen.scroll_offset_y, _vm->_mouseTouching, _vm->fetchObjectName(_vm->_mouseTouching)); else sprintf(buf, "mouse %d,%d (not touching)", - g_input->_mouseX + _vm->_thisScreen.scroll_offset_x, - g_input->_mouseY + _vm->_thisScreen.scroll_offset_y); + _vm->_input->_mouseX + _vm->_thisScreen.scroll_offset_x, + _vm->_input->_mouseY + _vm->_thisScreen.scroll_offset_y); makeDebugTextBlock(buf, 0, 30); @@ -280,7 +268,7 @@ void Debugger::buildDebugText(void) { showVarPos = 115; // y-coord for first showVar // res 1 is the global variables resource - varTable = (int32 *) (res_man->openResource(1) + sizeof(_standardHeader)); + varTable = (int32 *) (_vm->_resman->openResource(1) + sizeof(_standardHeader)); for (showVarNo = 0; showVarNo < MAX_SHOWVARS; showVarNo++) { varNo = _showVar[showVarNo]; // get variable number @@ -295,12 +283,12 @@ void Debugger::buildDebugText(void) { } } - res_man->closeResource(1); // close global variables resource + _vm->_resman->closeResource(1); // close global variables resource // memory indicator - this should come last, to show all the // sprite blocks above! - memory->memoryString(buf); + _vm->_memory->memoryString(buf); makeDebugTextBlock(buf, 0, 0); } } @@ -319,7 +307,7 @@ void Debugger::drawDebugGraphics(void) { // mouse marker & coords if (_displayMouseMarker) - plotCrossHair(g_input->_mouseX + _vm->_thisScreen.scroll_offset_x, g_input->_mouseY + _vm->_thisScreen.scroll_offset_y, 215); + plotCrossHair(_vm->_input->_mouseX + _vm->_thisScreen.scroll_offset_x, _vm->_input->_mouseY + _vm->_thisScreen.scroll_offset_y, 215); // mouse area rectangle / sprite box rectangle when testing anims @@ -335,20 +323,20 @@ void Debugger::drawDebugGraphics(void) { } void Debugger::plotCrossHair(int16 x, int16 y, uint8 pen) { - g_graphics->plotPoint(x, y, pen); // driver function + _vm->_graphics->plotPoint(x, y, pen); - g_graphics->drawLine(x - 2, y, x - 5, y, pen); // driver function - g_graphics->drawLine(x + 2, y, x + 5, y, pen); + _vm->_graphics->drawLine(x - 2, y, x - 5, y, pen); + _vm->_graphics->drawLine(x + 2, y, x + 5, y, pen); - g_graphics->drawLine(x, y - 2, x, y - 5, pen); - g_graphics->drawLine(x, y + 2, x, y + 5, pen); + _vm->_graphics->drawLine(x, y - 2, x, y - 5, pen); + _vm->_graphics->drawLine(x, y + 2, x, y + 5, pen); } void Debugger::drawRect(int16 x1, int16 y1, int16 x2, int16 y2, uint8 pen) { - 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 + _vm->_graphics->drawLine(x1, y1, x2, y1, pen); // top edge + _vm->_graphics->drawLine(x1, y2, x2, y2, pen); // bottom edge + _vm->_graphics->drawLine(x1, y1, x1, y2, pen); // left edge + _vm->_graphics->drawLine(x2, y1, x2, y2, pen); // right edge } void Debugger::printCurrentInfo(void) { diff --git a/sword2/defs.h b/sword2/defs.h index aa8f9d3c99..2275a02901 100644 --- a/sword2/defs.h +++ b/sword2/defs.h @@ -20,16 +20,13 @@ #ifndef DEFS #define DEFS -#include "sword2/header.h" -#include "sword2/resman.h" - #define SIZE 0x10000 // 65536 items per section #define NuSIZE 0xffff // & with this // global variable references // NB. 4 * <number from linc's Global Variables list> -#define VAR(n) (*(uint32 *) (res_man->_resList[1]->ad + sizeof(_standardHeader) + 4 * (n))) +#define VAR(n) (*(uint32 *) (g_sword2->_resman->_resList[1]->ad + sizeof(_standardHeader) + 4 * (n))) #define ID VAR(0) #define RESULT VAR(1) diff --git a/sword2/driver/_mouse.cpp b/sword2/driver/_mouse.cpp index bce554a3f3..d516c81093 100644 --- a/sword2/driver/_mouse.cpp +++ b/sword2/driver/_mouse.cpp @@ -17,11 +17,7 @@ * $Header$ */ -#include "stdafx.h" -#include "sword2/driver/driver96.h" -#include "sword2/driver/d_draw.h" -#include "sword2/driver/render.h" -#include "sword2/driver/menu.h" +#include "common/stdafx.h" #include "sword2/sword2.h" namespace Sword2 { @@ -171,7 +167,7 @@ void Graphics::drawMouse(void) { 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); + _vm->_system->set_mouse_cursor(_mouseData, mouse_width, mouse_height, hotspot_x, hotspot_y); } /** @@ -225,12 +221,12 @@ int32 Graphics::setMouseAnim(uint8 *ma, int32 size, int32 mouseFlash) { animateMouse(); drawMouse(); - g_system->show_mouse(true); + _vm->_system->show_mouse(true); } else { if (_luggageAnim) drawMouse(); else - g_system->show_mouse(false); + _vm->_system->show_mouse(false); } return RD_OK; @@ -260,12 +256,12 @@ int32 Graphics::setLuggageAnim(uint8 *ma, int32 size) { animateMouse(); drawMouse(); - g_system->show_mouse(true); + _vm->_system->show_mouse(true); } else { if (_mouseAnim) drawMouse(); else - g_system->show_mouse(false); + _vm->_system->show_mouse(false); } return RD_OK; diff --git a/sword2/driver/d_draw.cpp b/sword2/driver/d_draw.cpp index 1db17dd974..ca1ed7b9ab 100644 --- a/sword2/driver/d_draw.cpp +++ b/sword2/driver/d_draw.cpp @@ -17,22 +17,18 @@ * $Header$ */ -#include "stdafx.h" -#include "sound/mixer.h" +#include "common/stdafx.h" #include "sword2/sword2.h" -#include "sword2/driver/driver96.h" -#include "sword2/driver/d_draw.h" +#include "sword2/driver/menu.h" #include "sword2/driver/render.h" -#include "sword2/header.h" // HACK: For cutscenes instruction message -#include "sword2/maketext.h" // HACK: For cutscenes instruction message namespace Sword2 { -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), - _screenWide(width), _screenDeep(height) { +Graphics::Graphics(Sword2Engine *vm, int16 width, int16 height) + : _vm(vm), _iconCount(0), _needFullRedraw(false), + _fadeStatus(RDFADE_NONE), _mouseSprite(NULL), _mouseAnim(NULL), + _luggageAnim(NULL), _layer(0), _renderAverageTime(60), + _lightMask(NULL), _screenWide(width), _screenDeep(height) { int i, j; @@ -40,7 +36,7 @@ Graphics::Graphics(int16 width, int16 height) if (!_buffer) error("Could not initialise display"); - g_system->init_size(width, height); + _vm->_system->init_size(width, height); for (i = 0; i < ARRAYSIZE(_blockSurfaces); i++) _blockSurfaces[i] = NULL; @@ -98,19 +94,19 @@ void Graphics::clearScene(void) { void MoviePlayer::openTextObject(_movieTextObject *obj) { if (obj->textSprite) - g_graphics->createSurface(obj->textSprite, &_textSurface); + _vm->_graphics->createSurface(obj->textSprite, &_textSurface); } void MoviePlayer::closeTextObject(_movieTextObject *obj) { if (_textSurface) { - g_graphics->deleteSurface(_textSurface); + _vm->_graphics->deleteSurface(_textSurface); _textSurface = NULL; } } void MoviePlayer::drawTextObject(_movieTextObject *obj) { if (obj->textSprite && _textSurface) - g_graphics->drawSurface(obj->textSprite, _textSurface); + _vm->_graphics->drawSurface(obj->textSprite, _textSurface); } /** @@ -130,32 +126,32 @@ int32 MoviePlayer::play(char *filename, _movieTextObject *text[], uint8 *musicOu uint8 oldPal[1024]; uint8 tmpPal[1024]; - g_graphics->clearScene(); + _vm->_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_graphics->_buffer, 0, g_graphics->_screenWide * MENUDEEP); + memset(_vm->_graphics->_buffer, 0, _vm->_graphics->_screenWide * MENUDEEP); uint8 msg[] = "Cutscene - Press ESC to exit"; - mem *data = fontRenderer->makeTextSprite(msg, 640, 255, g_sword2->_speechFontId); + mem *data = _vm->_fontRenderer->makeTextSprite(msg, 640, 255, _vm->_speechFontId); _frameHeader *frame = (_frameHeader *) data->ad; _spriteInfo msgSprite; uint8 *msgSurface; - msgSprite.x = g_graphics->_screenWide / 2 - frame->width / 2; + msgSprite.x = _vm->_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_graphics->createSurface(&msgSprite, &msgSurface); - g_graphics->drawSurface(&msgSprite, msgSurface); - g_graphics->deleteSurface(msgSurface); - memory->freeMemory(data); + _vm->_graphics->createSurface(&msgSprite, &msgSurface); + _vm->_graphics->drawSurface(&msgSprite, msgSurface); + _vm->_graphics->deleteSurface(msgSurface); + _vm->_memory->freeMemory(data); // In case the cutscene has a long lead-in, start just before // the first line of text. @@ -170,12 +166,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_graphics->_palCopy, 1024); + memcpy(oldPal, _vm->_graphics->_palCopy, 1024); memset(tmpPal, 0, 1024); tmpPal[255 * 4 + 0] = 255; tmpPal[255 * 4 + 1] = 255; tmpPal[255 * 4 + 2] = 255; - g_graphics->setPalette(0, 256, tmpPal, RDPAL_INSTANT); + _vm->_graphics->setPalette(0, 256, tmpPal, RDPAL_INSTANT); PlayingSoundHandle handle = 0; @@ -186,28 +182,28 @@ int32 MoviePlayer::play(char *filename, _movieTextObject *text[], uint8 *musicOu break; if (frameCounter == text[textCounter]->startFrame) { - g_graphics->clearScene(); + _vm->_graphics->clearScene(); openTextObject(text[textCounter]); drawTextObject(text[textCounter]); if (text[textCounter]->speech) { - g_sword2->_mixer->playRaw(&handle, text[textCounter]->speech, text[textCounter]->speechBufferSize, 22050, SoundMixer::FLAG_16BITS); + _vm->_mixer->playRaw(&handle, text[textCounter]->speech, text[textCounter]->speechBufferSize, 22050, SoundMixer::FLAG_16BITS); } } if (frameCounter == text[textCounter]->endFrame) { closeTextObject(text[textCounter]); - g_graphics->clearScene(); + _vm->_graphics->clearScene(); textCounter++; } frameCounter++; - g_graphics->updateDisplay(); + _vm->_graphics->updateDisplay(); _keyboardEvent ke; - if (g_input->readKey(&ke) == RD_OK && ke.keycode == 27) { - g_sword2->_mixer->stopHandle(handle); + if (_vm->_input->readKey(&ke) == RD_OK && ke.keycode == 27) { + _vm->_mixer->stopHandle(handle); skipCutscene = true; break; } @@ -216,38 +212,38 @@ int32 MoviePlayer::play(char *filename, _movieTextObject *text[], uint8 *musicOu // frame rate the original movies had, or even if it // was constant, but this seems to work reasonably. - g_system->delay_msecs(90); + _vm->_system->delay_msecs(90); } closeTextObject(text[textCounter]); - g_graphics->clearScene(); - g_graphics->setNeedFullRedraw(); + _vm->_graphics->clearScene(); + _vm->_graphics->setNeedFullRedraw(); // HACK: Remove the instructions created above Common::Rect r; - memset(g_graphics->_buffer, 0, g_graphics->_screenWide * MENUDEEP); + memset(_vm->_graphics->_buffer, 0, _vm->_graphics->_screenWide * MENUDEEP); r.left = r.top = 0; - r.right = g_graphics->_screenWide; + r.right = _vm->_graphics->_screenWide; r.bottom = MENUDEEP; - g_graphics->updateRect(&r); + _vm->_graphics->updateRect(&r); // FIXME: For now, only play the lead-out music for cutscenes // that have subtitles. if (!skipCutscene) - g_sound->playLeadOut(musicOut); + _vm->_sound->playLeadOut(musicOut); - g_graphics->setPalette(0, 256, oldPal, RDPAL_INSTANT); + _vm->_graphics->setPalette(0, 256, oldPal, RDPAL_INSTANT); } // Lead-in and lead-out music are, as far as I can tell, only used for // the animated cut-scenes, so this seems like a good place to close // both of them. - g_sound->closeFx(-1); - g_sound->closeFx(-2); + _vm->_sound->closeFx(-1); + _vm->_sound->closeFx(-2); return RD_OK; } diff --git a/sword2/driver/d_draw.h b/sword2/driver/d_draw.h index f3c0a055ee..387ffdb355 100644 --- a/sword2/driver/d_draw.h +++ b/sword2/driver/d_draw.h @@ -20,7 +20,7 @@ #ifndef D_DRAW_H #define D_DRAW_H -#include "sword2/driver/driver96.h" +#include "common/rect.h" namespace Sword2 { @@ -61,13 +61,15 @@ struct _mouseAnim { class MoviePlayer { private: + Sword2Engine *_vm; + uint8 *_textSurface; void openTextObject(_movieTextObject *obj); void closeTextObject(_movieTextObject *obj); void drawTextObject(_movieTextObject *obj); public: - MoviePlayer() : _textSurface(NULL) {} + MoviePlayer(Sword2Engine *vm) : _vm(vm), _textSurface(NULL) {} int32 play(char *filename, _movieTextObject *text[], uint8 *musicOut); }; @@ -80,6 +82,8 @@ class Graphics { friend class MoviePlayer; private: + Sword2Engine *_vm; + byte *_buffer; int32 _renderCaps; @@ -174,7 +178,7 @@ private: int32 decompressRLE16(uint8 *dest, uint8 *source, int32 decompSize, uint8 *colTable); public: - Graphics(int16 width, int16 height); + Graphics(Sword2Engine *vm, int16 width, int16 height); // Game screen metrics int16 _screenWide; diff --git a/sword2/driver/d_sound.cpp b/sword2/driver/d_sound.cpp index 8235d25934..89b6bece76 100644 --- a/sword2/driver/d_sound.cpp +++ b/sword2/driver/d_sound.cpp @@ -32,13 +32,9 @@ // Does anyone who can run the original interpreter have any // opinions on this? -#include "stdafx.h" -#include "sound/audiostream.h" -#include "sound/mixer.h" -#include "sound/rate.h" +#include "common/stdafx.h" +#include "common/file.h" #include "sword2/sword2.h" -#include "sword2/driver/driver96.h" -#include "sword2/driver/d_sound.h" namespace Sword2 { @@ -119,8 +115,9 @@ static void premix_proc(void *param, int16 *data, uint len) { ((Sound *) param)->fxServer(data, len); } -Sound::Sound(SoundMixer *mixer) { - _mutex = g_system->create_mutex(); +Sound::Sound(Sword2Engine *vm) { + _vm = vm; + _mutex = _vm->_system->create_mutex(); _soundOn = false; _speechStatus = false; @@ -133,21 +130,20 @@ Sound::Sound(SoundMixer *mixer) { _musicVol = 16; _musicMuted = 0; - _mixer = mixer; memset(_fx, 0, sizeof(_fx)); _soundHandleSpeech = 0; _soundOn = true; - _converter = makeRateConverter(_music[0].getRate(), _mixer->getOutputRate(), _music[0].isStereo(), false); + _converter = makeRateConverter(_music[0].getRate(), _vm->_mixer->getOutputRate(), _music[0].isStereo(), false); - _mixer->setupPremix(premix_proc, this); + _vm->_mixer->setupPremix(premix_proc, this); } Sound::~Sound() { if (_mutex) - g_system->delete_mutex(_mutex); + _vm->_system->delete_mutex(_mutex); } // -------------------------------------------------------------------------- @@ -248,8 +244,8 @@ void Sound::playLeadOut(uint8 *leadOut) { } while (_fx[i]._handle) { - g_graphics->updateDisplay(); - g_system->delay_msecs(30); + _vm->_graphics->updateDisplay(); + _vm->_system->delay_msecs(30); } } @@ -418,7 +414,7 @@ int32 Sound::playCompSpeech(const char *filename, uint32 speechid, uint8 vol, in uint32 flags = SoundMixer::FLAG_16BITS | SoundMixer::FLAG_AUTOFREE; - _mixer->playRaw(&_soundHandleSpeech, data16, bufferSize, 22050, flags, -1, volume, p); + _vm->_mixer->playRaw(&_soundHandleSpeech, data16, bufferSize, 22050, flags, -1, volume, p); _speechStatus = true; } @@ -437,7 +433,7 @@ int32 Sound::stopSpeech(void) { return RD_OK; if (_speechStatus) { - g_engine->_mixer->stopHandle(_soundHandleSpeech); + _vm->_mixer->stopHandle(_soundHandleSpeech); _speechStatus = false; return RD_OK; } @@ -474,7 +470,7 @@ void Sound::setSpeechVolume(uint8 volume) { _speechVol = volume; if (_soundHandleSpeech != 0 && !_speechMuted && getSpeechStatus() == RDSE_SAMPLEPLAYING) { - g_engine->_mixer->setChannelVolume(_soundHandleSpeech, 16 * _speechVol); + _vm->_mixer->setChannelVolume(_soundHandleSpeech, 16 * _speechVol); } } @@ -498,7 +494,7 @@ void Sound::muteSpeech(bool mute) { if (getSpeechStatus() == RDSE_SAMPLEPLAYING) { byte volume = mute ? 0 : 16 * _speechVol; - g_engine->_mixer->setChannelVolume(_soundHandleSpeech, volume); + _vm->_mixer->setChannelVolume(_soundHandleSpeech, volume); } } @@ -517,7 +513,7 @@ bool Sound::isSpeechMute(void) { void Sound::pauseSpeech(void) { if (getSpeechStatus() == RDSE_SAMPLEPLAYING) { _speechPaused = true; - g_engine->_mixer->pauseHandle(_soundHandleSpeech, true); + _vm->_mixer->pauseHandle(_soundHandleSpeech, true); } } @@ -528,7 +524,7 @@ void Sound::pauseSpeech(void) { void Sound::unpauseSpeech(void) { if (_speechPaused) { _speechPaused = false; - g_engine->_mixer->pauseHandle(_soundHandleSpeech, false); + _vm->_mixer->pauseHandle(_soundHandleSpeech, false); } } @@ -664,7 +660,7 @@ int32 Sound::playFx(int32 id, uint8 *data, uint8 vol, int8 pan, uint8 type) { byte volume = _fxMuted ? 0 : vol * _fxVol; int8 p = _panTable[pan + 16]; - g_engine->_mixer->playRaw(&_fx[i]._handle, _fx[i]._buf, _fx[i]._bufSize, _fx[i]._rate, _fx[i]._flags, -1, volume, p); + _vm->_mixer->playRaw(&_fx[i]._handle, _fx[i]._buf, _fx[i]._bufSize, _fx[i]._rate, _fx[i]._flags, -1, volume, p); } else { if (type == RDSE_FXLEADIN || type == RDSE_FXLEADOUT) { if (type == RDSE_FXLEADIN) @@ -685,7 +681,7 @@ int32 Sound::playFx(int32 id, uint8 *data, uint8 vol, int8 pan, uint8 type) { byte volume = _musicMuted ? 0 : musicVolTable[_musicVol]; - g_engine->_mixer->playRaw(&_fx[i]._handle, _fx[i]._buf, _fx[i]._bufSize, _fx[i]._rate, _fx[i]._flags, -1, volume, 0); + _vm->_mixer->playRaw(&_fx[i]._handle, _fx[i]._buf, _fx[i]._bufSize, _fx[i]._rate, _fx[i]._flags, -1, volume, 0); } else { hr = openFx(id, data); if (hr != RD_OK) { @@ -708,7 +704,7 @@ int32 Sound::playFx(int32 id, uint8 *data, uint8 vol, int8 pan, uint8 type) { byte volume = _fxMuted ? 0 : vol * _fxVol; int8 p = _panTable[pan + 16]; - g_engine->_mixer->playRaw(&_fx[i]._handle, _fx[i]._buf, _fx[i]._bufSize, _fx[i]._rate, _fx[i]._flags, -1, volume, p); + _vm->_mixer->playRaw(&_fx[i]._handle, _fx[i]._buf, _fx[i]._bufSize, _fx[i]._rate, _fx[i]._flags, -1, volume, p); } } } @@ -735,8 +731,8 @@ int32 Sound::setFxIdVolumePan(int32 id, uint8 vol, int8 pan) { _fx[i]._volume = vol; if (!_fxMuted) { - g_engine->_mixer->setChannelVolume(_fx[i]._handle, _fx[i]._volume * _fxVol); - g_engine->_mixer->setChannelPan(_fx[i]._handle, _panTable[pan + 16]); + _vm->_mixer->setChannelVolume(_fx[i]._handle, _fx[i]._volume * _fxVol); + _vm->_mixer->setChannelPan(_fx[i]._handle, _panTable[pan + 16]); } return RD_OK; @@ -750,7 +746,7 @@ int32 Sound::setFxIdVolume(int32 id, uint8 vol) { _fx[i]._volume = vol; if (!_fxMuted) - g_engine->_mixer->setChannelVolume(_fx[i]._handle, vol * _fxVol); + _vm->_mixer->setChannelVolume(_fx[i]._handle, vol * _fxVol); return RD_OK; } @@ -766,7 +762,7 @@ void Sound::clearAllFx(void) { for (int i = 0; i < MAXFX; i++) { if (_fx[i]._id && _fx[i]._id != -1 && _fx[i]._id != -2) { - g_engine->_mixer->stopHandle(_fx[i]._handle); + _vm->_mixer->stopHandle(_fx[i]._handle); _fx[i]._id = 0; _fx[i]._paused = false; if (_fx[i]._buf != NULL) { @@ -797,7 +793,7 @@ int32 Sound::closeFx(int32 id) { if (i == MAXFX) return RDERR_FXNOTOPEN; - g_engine->_mixer->stopHandle(_fx[i]._handle); + _vm->_mixer->stopHandle(_fx[i]._handle); _fx[i]._id = 0; _fx[i]._paused = false; if (_fx[i]._buf != NULL) { @@ -814,7 +810,7 @@ void Sound::pauseFx(void) { if (!_fxPaused) { for (int i = 0; i < MAXFX; i++) { if (_fx[i]._id) { - g_engine->_mixer->pauseHandle(_fx[i]._handle, true); + _vm->_mixer->pauseHandle(_fx[i]._handle, true); _fx[i]._paused = true; } else _fx[i]._paused = false; @@ -827,7 +823,7 @@ void Sound::pauseFxForSequence(void) { if (!_fxPaused) { for (int i = 0; i < MAXFX; i++) { if (_fx[i]._id && _fx[i]._id != -2) { - g_engine->_mixer->pauseHandle(_fx[i]._handle, true); + _vm->_mixer->pauseHandle(_fx[i]._handle, true); _fx[i]._paused = true; } else { _fx[i]._paused = false; @@ -841,7 +837,7 @@ void Sound::unpauseFx(void) { if (_fxPaused) { for (int i = 0; i < MAXFX; i++) { if (_fx[i]._paused && _fx[i]._id) { - g_engine->_mixer->pauseHandle(_fx[i]._handle, false); + _vm->_mixer->pauseHandle(_fx[i]._handle, false); } } _fxPaused = false; @@ -871,7 +867,7 @@ void Sound::setFxVolume(uint8 volume) { // Now update the volume of any fxs playing for (int i = 0; i < MAXFX; i++) { if (_fx[i]._id && !_fxMuted) - g_engine->_mixer->setChannelVolume(_fx[i]._handle, _fx[i]._volume * _fxVol); + _vm->_mixer->setChannelVolume(_fx[i]._handle, _fx[i]._volume * _fxVol); } } @@ -889,7 +885,7 @@ void Sound::muteFx(bool mute) { if (_fx[i]._id) { byte volume = mute ? 0 : _fx[i]._volume * _fxVol; - g_engine->_mixer->setChannelVolume(_fx[i]._handle, volume); + _vm->_mixer->setChannelVolume(_fx[i]._handle, volume); } } } diff --git a/sword2/driver/d_sound.h b/sword2/driver/d_sound.h index 8e7fab18c4..842c44d9ff 100644 --- a/sword2/driver/d_sound.h +++ b/sword2/driver/d_sound.h @@ -23,7 +23,6 @@ #include "sound/audiostream.h" #include "sound/mixer.h" #include "sound/rate.h" -#include "common/file.h" namespace Sword2 { @@ -71,7 +70,7 @@ public: class Sound { private: - SoundMixer *_mixer; + Sword2Engine *_vm; OSystem::MutexRef _mutex; RateConverter *_converter; @@ -100,7 +99,7 @@ private: void updateCompSampleStreaming(int16 *data, uint len); public: - Sound(SoundMixer *mixer); + Sound(Sword2Engine *vm); ~Sound(); void fxServer(int16 *data, uint len); int32 playCompSpeech(const char *filename, uint32 speechid, uint8 vol, int8 pan); diff --git a/sword2/driver/driver96.h b/sword2/driver/driver96.h index 89f9725532..5f769ec4f3 100644 --- a/sword2/driver/driver96.h +++ b/sword2/driver/driver96.h @@ -20,13 +20,10 @@ #ifndef DRIVER96_H #define DRIVER96_H -#include "common/scummsys.h" -#include "base/engine.h" // for warning() -#include "common/system.h" -#include "common/rect.h" - namespace Sword2 { +class Sword2Engine; + // // Defines // ------- @@ -282,6 +279,9 @@ extern int32 SetLanguageVersion(uint8 version); #define MAX_KEY_BUFFER 32 class Input { +private: + Sword2Engine *_vm; + uint8 _mouseBacklog; uint8 _mouseLogPos; _mouseEvent _mouseLog[MAX_MOUSE_EVENTS]; @@ -303,8 +303,8 @@ public: int16 _mouseX; int16 _mouseY; - Input() : - _mouseBacklog(0), _mouseLogPos(0), _keyBacklog(0), + Input(Sword2Engine *vm) : + _vm(vm), _mouseBacklog(0), _mouseLogPos(0), _keyBacklog(0), _keyLogPos(0) {}; void parseEvents(void); diff --git a/sword2/driver/keyboard.cpp b/sword2/driver/keyboard.cpp index 8645f5b10d..5ddf303fc8 100644 --- a/sword2/driver/keyboard.cpp +++ b/sword2/driver/keyboard.cpp @@ -17,8 +17,8 @@ * $Header$ */ -#include "stdafx.h" -#include "sword2/driver/driver96.h" +#include "common/stdafx.h" +#include "sword2/sword2.h" namespace Sword2 { diff --git a/sword2/driver/language.cpp b/sword2/driver/language.cpp index 67bb4e8cc1..af09ef43e7 100644 --- a/sword2/driver/language.cpp +++ b/sword2/driver/language.cpp @@ -17,8 +17,8 @@ * $Header$ */ -#include "stdafx.h" -#include "sword2/driver/driver96.h" +#include "common/stdafx.h" +#include "sword2/sword2.h" namespace Sword2 { diff --git a/sword2/driver/menu.cpp b/sword2/driver/menu.cpp index bbcd63668a..c70b11f83d 100644 --- a/sword2/driver/menu.cpp +++ b/sword2/driver/menu.cpp @@ -17,11 +17,8 @@ * $Header$ */ -#include "stdafx.h" -#include "common/rect.h" -#include "sword2/driver/driver96.h" -#include "sword2/driver/menu.h" -#include "sword2/driver/d_draw.h" +#include "common/stdafx.h" +#include "sword2/sword2.h" #include "sword2/driver/render.h" namespace Sword2 { @@ -65,10 +62,10 @@ void Graphics::processMenu(void) { static int32 lastTime = 0; if (lastTime == 0) { - lastTime = g_system->get_msecs(); + lastTime = _vm->_system->get_msecs(); frameCount = 1; } else { - delta = g_system->get_msecs() - lastTime; + delta = _vm->_system->get_msecs() - lastTime; if (delta > 250) { lastTime += delta; delta = 250; diff --git a/sword2/driver/palette.cpp b/sword2/driver/palette.cpp index 4b69fbc48c..3cfa4bc580 100644 --- a/sword2/driver/palette.cpp +++ b/sword2/driver/palette.cpp @@ -17,12 +17,10 @@ * $Header$ */ -#include "stdafx.h" -#include "common/util.h" -#include "base/engine.h" +#include "common/stdafx.h" +// #include "common/util.h" +// #include "base/engine.h" #include "sword2/sword2.h" -#include "sword2/driver/d_draw.h" -#include "sword2/driver/driver96.h" namespace Sword2 { @@ -116,9 +114,9 @@ void Graphics::setPalette(int16 startEntry, int16 noEntries, uint8 *colourTable, if (noEntries) { memcpy(&_palCopy[startEntry][0], colourTable, noEntries * 4); if (fadeNow == RDPAL_INSTANT) - g_system->set_palette((const byte *) _palCopy, startEntry, noEntries); + _vm->_system->set_palette((const byte *) _palCopy, startEntry, noEntries); } else - g_system->set_palette((const byte *) _palCopy, 0, 256); + _vm->_system->set_palette((const byte *) _palCopy, 0, 256); } void Graphics::dimPalette(void) { @@ -127,7 +125,7 @@ void Graphics::dimPalette(void) { for (int i = 0; i < 256 * 4; i++) p[i] /= 2; - g_system->set_palette(p, 0, 256); + _vm->_system->set_palette(p, 0, 256); } /** @@ -141,7 +139,7 @@ int32 Graphics::fadeUp(float time) { _fadeTotalTime = (int32) (time * 1000); _fadeStatus = RDFADE_UP; - _fadeStartTime = g_system->get_msecs(); + _fadeStartTime = _vm->_system->get_msecs(); return RD_OK; } @@ -157,7 +155,7 @@ int32 Graphics::fadeDown(float time) { _fadeTotalTime = (int32) (time * 1000); _fadeStatus = RDFADE_DOWN; - _fadeStartTime = g_system->get_msecs(); + _fadeStartTime = _vm->_system->get_msecs(); return RD_OK; } @@ -175,7 +173,7 @@ uint8 Graphics::getFadeStatus(void) { void Graphics::waitForFade(void) { while (getFadeStatus() != RDFADE_NONE && getFadeStatus() != RDFADE_BLACK) { updateDisplay(); - g_system->delay_msecs(20); + _vm->_system->delay_msecs(20); } } @@ -196,7 +194,7 @@ void Graphics::fadeServer(void) { // I don't know if this is necessary, but let's limit how often the // palette is updated, just to be safe. - currentTime = g_system->get_msecs(); + currentTime = _vm->_system->get_msecs(); if (currentTime - previousTime <= 25) return; @@ -228,7 +226,7 @@ void Graphics::fadeServer(void) { } } - g_system->set_palette(newPalette, 0, 256); + _vm->_system->set_palette(newPalette, 0, 256); } } // End of namespace Sword2 diff --git a/sword2/driver/rdwin.cpp b/sword2/driver/rdwin.cpp index 050e8b3021..4442c79c3d 100644 --- a/sword2/driver/rdwin.cpp +++ b/sword2/driver/rdwin.cpp @@ -19,11 +19,7 @@ #include "common/stdafx.h" #include "sword2/sword2.h" -#include "sword2/driver/driver96.h" -#include "sword2/driver/d_draw.h" -#include "sword2/driver/render.h" #include "sword2/driver/menu.h" -#include "sword2/driver/d_sound.h" namespace Sword2 { @@ -34,7 +30,7 @@ namespace Sword2 { void Input::parseEvents(void) { OSystem::Event event; - while (g_system->poll_event(&event)) { + while (_vm->_system->poll_event(&event)) { switch (event.event_code) { case OSystem::EVENT_KEYDOWN: writeKey(event.kbd.ascii, event.kbd.keycode, event.kbd.flags); @@ -56,7 +52,7 @@ void Input::parseEvents(void) { logMouseEvent(RD_RIGHTBUTTONUP); break; case OSystem::EVENT_QUIT: - g_sword2->closeGame(); + _vm->closeGame(); break; default: break; @@ -74,19 +70,19 @@ void Graphics::setNeedFullRedraw() { */ void Graphics::updateDisplay(void) { - g_input->parseEvents(); + _vm->_input->parseEvents(); fadeServer(); // FIXME: We re-render the entire picture area of the screen for each // frame, which is pretty horrible. if (_needFullRedraw) { - g_system->copy_rect(_buffer + MENUDEEP * _screenWide, _screenWide, 0, MENUDEEP, _screenWide, _screenDeep - 2 * MENUDEEP); + _vm->_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(); + _vm->_system->update_screen(); } /** @@ -97,7 +93,7 @@ void Graphics::setWindowName(const char *windowName) { OSystem::Property prop; prop.caption = windowName; - g_system->property(OSystem::PROP_SET_WINDOW_CAPTION, &prop); + _vm->_system->property(OSystem::PROP_SET_WINDOW_CAPTION, &prop); } } // End of namespace Sword2 diff --git a/sword2/driver/render.cpp b/sword2/driver/render.cpp index 0fb3598d69..8beceddc51 100644 --- a/sword2/driver/render.cpp +++ b/sword2/driver/render.cpp @@ -17,12 +17,10 @@ * $Header$ */ -#include "stdafx.h" -#include "sword2/driver/driver96.h" -#include "sword2/driver/d_draw.h" -#include "sword2/driver/render.h" -#include "sword2/driver/menu.h" +#include "common/stdafx.h" #include "sword2/sword2.h" +#include "sword2/driver/menu.h" +#include "sword2/driver/render.h" namespace Sword2 { @@ -32,7 +30,7 @@ namespace Sword2 { #define BLOCKHBITS 6 void Graphics::updateRect(Common::Rect *r) { - g_system->copy_rect(_buffer + r->top * _screenWide + r->left, + _vm->_system->copy_rect(_buffer + r->top * _screenWide + r->left, _screenWide, r->left, r->top, r->right - r->left, r->bottom - r->top); } @@ -575,7 +573,7 @@ void Graphics::renderParallax(_parallax *p, int16 l) { */ void Graphics::initialiseRenderCycle(void) { - _initialTime = g_system->get_msecs(); + _initialTime = _vm->_system->get_msecs(); _totalTime = _initialTime + MILLISECSPERCYCLE; } @@ -588,7 +586,7 @@ void Graphics::startRenderCycle(void) { _scrollXOld = _scrollX; _scrollYOld = _scrollY; - _startTime = g_system->get_msecs(); + _startTime = _vm->_system->get_msecs(); if (_startTime + _renderAverageTime >= _totalTime) { _scrollX = _scrollXTarget; @@ -614,7 +612,7 @@ bool Graphics::endRenderCycle(void) { static int32 renderCountIndex = 0; int32 time; - time = g_system->get_msecs(); + time = _vm->_system->get_msecs(); renderTimeLog[renderCountIndex] = time - _startTime; _startTime = time; _renderAverageTime = (renderTimeLog[0] + renderTimeLog[1] + renderTimeLog[2] + renderTimeLog[3]) >> 2; @@ -639,8 +637,8 @@ bool Graphics::endRenderCycle(void) { if (_scrollXTarget == _scrollX && _scrollYTarget == _scrollY) { // If we have already reached the scroll target sleep for the // rest of the render cycle. - g_sword2->sleepUntil(_totalTime); - _initialTime = g_system->get_msecs(); + _vm->sleepUntil(_totalTime); + _initialTime = _vm->_system->get_msecs(); _totalTime += MILLISECSPERCYCLE; return true; } diff --git a/sword2/driver/sprite.cpp b/sword2/driver/sprite.cpp index c9e21f6639..2e3f75c950 100644 --- a/sword2/driver/sprite.cpp +++ b/sword2/driver/sprite.cpp @@ -17,10 +17,8 @@ * $Header$ */ -#include "stdafx.h" -#include "sword2/driver/driver96.h" -#include "sword2/driver/d_draw.h" -#include "sword2/driver/render.h" +#include "common/stdafx.h" +#include "sword2/sword2.h" namespace Sword2 { diff --git a/sword2/events.cpp b/sword2/events.cpp index 8da448fdb4..621a8be2d5 100644 --- a/sword2/events.cpp +++ b/sword2/events.cpp @@ -17,14 +17,10 @@ * $Header$ */ -#include "stdafx.h" +#include "common/stdafx.h" #include "sword2/sword2.h" -#include "sword2/console.h" -#include "sword2/debug.h" #include "sword2/defs.h" #include "sword2/interpreter.h" -#include "sword2/logic.h" -#include "sword2/object.h" namespace Sword2 { @@ -185,7 +181,7 @@ int32 Logic::fnPauseForEvent(int32 *params) { // params: 0 pointer to object's logic structure // 1 number of game-cycles to pause - Object_logic *ob_logic = (Object_logic *) memory->intToPtr(params[0]); + Object_logic *ob_logic = (Object_logic *) _vm->_memory->intToPtr(params[0]); // first, check for an event diff --git a/sword2/function.cpp b/sword2/function.cpp index 9cd475d2cf..c812ac4375 100644 --- a/sword2/function.cpp +++ b/sword2/function.cpp @@ -17,19 +17,10 @@ * $Header$ */ -#include "stdafx.h" -#include "sword2/driver/driver96.h" -#include "sword2/build_display.h" -#include "sword2/credits.h" -#include "sword2/debug.h" +#include "common/stdafx.h" +#include "sword2/sword2.h" #include "sword2/defs.h" #include "sword2/interpreter.h" -#include "sword2/layers.h" // for '_thisScreen' structure -#include "sword2/logic.h" -#include "sword2/protocol.h" -#include "sword2/resman.h" -#include "sword2/sound.h" -#include "sword2/sword2.h" namespace Sword2 { @@ -97,8 +88,8 @@ int32 Logic::fnPreLoad(int32 *params) { // params: 0 resource to preload - res_man->openResource(params[0]); - res_man->closeResource(params[0]); + _vm->_resman->openResource(params[0]); + _vm->_resman->closeResource(params[0]); return IR_CONT; } @@ -148,7 +139,7 @@ int32 Logic::fnPause(int32 *params) { // NB. Pause-value of 0 causes script to continue, 1 causes a 1-cycle // quit, 2 gives 2 cycles, etc. - Object_logic *ob_logic = (Object_logic *) memory->intToPtr(params[0]); + Object_logic *ob_logic = (Object_logic *) _vm->_memory->intToPtr(params[0]); if (ob_logic->looping == 0) { // start the pause @@ -177,7 +168,7 @@ int32 Logic::fnRandomPause(int32 *params) { // 1 minimum number of game-cycles to pause // 2 maximum number of game-cycles to pause - Object_logic *ob_logic = (Object_logic *) memory->intToPtr(params[0]); + Object_logic *ob_logic = (Object_logic *) _vm->_memory->intToPtr(params[0]); int32 pars[2]; if (ob_logic->looping == 0) { @@ -202,7 +193,7 @@ int32 Logic::fnPassGraph(int32 *params) { // params: 0 pointer to a graphic structure (might not need this?) - memcpy(&_vm->_engineGraph, memory->intToPtr(params[0]), sizeof(Object_graphic)); + memcpy(&_vm->_engineGraph, _vm->_memory->intToPtr(params[0]), sizeof(Object_graphic)); // makes no odds return IR_CONT; @@ -218,7 +209,7 @@ int32 Logic::fnPassMega(int32 *params) { // params: 0 pointer to a mega structure - memcpy(&_vm->_engineMega, memory->intToPtr(params[0]), sizeof(Object_mega)); + memcpy(&_vm->_engineMega, _vm->_memory->intToPtr(params[0]), sizeof(Object_mega)); // makes no odds return IR_CONT; @@ -233,7 +224,7 @@ int32 Logic::fnSetValue(int32 *params) { // params: 0 pointer to object's mega structure // 1 value to set it to - Object_mega *ob_mega = (Object_mega *) memory->intToPtr(params[0]); + Object_mega *ob_mega = (Object_mega *) _vm->_memory->intToPtr(params[0]); ob_mega->megaset_res = params[1]; @@ -266,25 +257,25 @@ int32 Logic::fnFlash(int32 *params) { // what colour? switch (params[0]) { case WHITE: - g_graphics->setPalette(0, 1, white, RDPAL_INSTANT); + _vm->_graphics->setPalette(0, 1, white, RDPAL_INSTANT); break; case RED: - g_graphics->setPalette(0, 1, red, RDPAL_INSTANT); + _vm->_graphics->setPalette(0, 1, red, RDPAL_INSTANT); break; case GREEN: - g_graphics->setPalette(0, 1, green, RDPAL_INSTANT); + _vm->_graphics->setPalette(0, 1, green, RDPAL_INSTANT); break; case BLUE: - g_graphics->setPalette(0, 1, blue, RDPAL_INSTANT); + _vm->_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_graphics->updateDisplay(); - g_system->delay_msecs(250); - g_graphics->setPalette(0, 1, black, RDPAL_INSTANT); + _vm->_graphics->updateDisplay(); + _vm->_system->delay_msecs(250); + _vm->_graphics->setPalette(0, 1, black, RDPAL_INSTANT); #endif return IR_CONT; @@ -302,19 +293,19 @@ int32 Logic::fnColour(int32 *params) { // what colour? switch (params[0]) { case BLACK: - g_graphics->setPalette(0, 1, black, RDPAL_INSTANT); + _vm->_graphics->setPalette(0, 1, black, RDPAL_INSTANT); break; case WHITE: - g_graphics->setPalette(0, 1, white, RDPAL_INSTANT); + _vm->_graphics->setPalette(0, 1, white, RDPAL_INSTANT); break; case RED: - g_graphics->setPalette(0, 1, red, RDPAL_INSTANT); + _vm->_graphics->setPalette(0, 1, red, RDPAL_INSTANT); break; case GREEN: - g_graphics->setPalette(0, 1, green, RDPAL_INSTANT); + _vm->_graphics->setPalette(0, 1, green, RDPAL_INSTANT); break; case BLUE: - g_graphics->setPalette(0, 1, blue, RDPAL_INSTANT); + _vm->_graphics->setPalette(0, 1, blue, RDPAL_INSTANT); break; } #endif @@ -335,8 +326,8 @@ int32 Logic::fnDisplayMsg(int32 *params) { // +2 to skip the encoded text number in the first 2 chars; 3 is // duration in seconds - _vm->displayMsg(_vm->fetchTextLine(res_man->openResource(text_res), local_text) + 2, 3); - res_man->closeResource(text_res); + _vm->displayMsg(_vm->fetchTextLine(_vm->_resman->openResource(text_res), local_text) + 2, 3); + _vm->_resman->closeResource(text_res); _vm->removeMsg(); return IR_CONT; @@ -351,20 +342,20 @@ int32 Logic::fnResetGlobals(int32 *params) { int32 size; uint32 *globals; - size = res_man->fetchLen(1); + size = _vm->_resman->fetchLen(1); size -= sizeof(_standardHeader); debug(5, "globals size: %d", size); - globals = (uint32 *) ((uint8 *) res_man->openResource(1) + sizeof(_standardHeader)); + globals = (uint32 *) ((uint8 *) _vm->_resman->openResource(1) + sizeof(_standardHeader)); // blank each global variable memset(globals, 0, size); - res_man->closeResource(1); + _vm->_resman->closeResource(1); // all objects but george - res_man->killAllObjects(false); + _vm->_resman->killAllObjects(false); // FOR THE DEMO - FORCE THE SCROLLING TO BE RESET! // - this is taken from fnInitBackground @@ -387,23 +378,23 @@ int32 Logic::fnPlayCredits(int32 *params) { int32 music_length; int32 pars[2]; - g_sound->saveMusicState(); + _vm->_sound->saveMusicState(); - g_sound->muteFx(true); - g_sound->muteSpeech(true); - g_sound->stopMusic(); + _vm->_sound->muteFx(true); + _vm->_sound->muteSpeech(true); + _vm->_sound->stopMusic(); - memcpy(oldPal, g_graphics->_palCopy, 1024); + memcpy(oldPal, _vm->_graphics->_palCopy, 1024); memset(tmpPal, 0, 1024); - g_graphics->waitForFade(); - g_graphics->fadeDown(); - g_graphics->waitForFade(); + _vm->_graphics->waitForFade(); + _vm->_graphics->fadeDown(); + _vm->_graphics->waitForFade(); tmpPal[4] = 255; tmpPal[5] = 255; tmpPal[6] = 255; - g_graphics->setPalette(0, 256, tmpPal, RDPAL_INSTANT); + _vm->_graphics->setPalette(0, 256, tmpPal, RDPAL_INSTANT); // Play the credits music. Is it enough with just one // repetition of it? @@ -412,41 +403,41 @@ int32 Logic::fnPlayCredits(int32 *params) { pars[1] = FX_SPOT; fnPlayMusic(pars); - music_length = 1000 * g_sound->musicTimeRemaining(); + music_length = 1000 * _vm->_sound->musicTimeRemaining(); debug(0, "Credits music length: ~%d ms", music_length); - g_graphics->closeMenuImmediately(); + _vm->_graphics->closeMenuImmediately(); - while (g_sound->musicTimeRemaining()) { - g_graphics->clearScene(); - g_graphics->setNeedFullRedraw(); + while (_vm->_sound->musicTimeRemaining()) { + _vm->_graphics->clearScene(); + _vm->_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_graphics->updateDisplay(); + _vm->_graphics->updateDisplay(); _keyboardEvent ke; - if (g_input->readKey(&ke) == RD_OK && ke.keycode == 27) + if (_vm->_input->readKey(&ke) == RD_OK && ke.keycode == 27) break; - g_system->delay_msecs(30); + _vm->_system->delay_msecs(30); } fnStopMusic(NULL); - g_sound->restoreMusicState(); + _vm->_sound->restoreMusicState(); - g_graphics->setPalette(0, 256, oldPal, RDPAL_FADE); - g_graphics->fadeUp(); - g_graphics->updateDisplay(); + _vm->_graphics->setPalette(0, 256, oldPal, RDPAL_FADE); + _vm->_graphics->fadeUp(); + _vm->_graphics->updateDisplay(); _vm->buildDisplay(); - g_graphics->waitForFade(); + _vm->_graphics->waitForFade(); - g_sound->muteFx(false); - g_sound->muteSpeech(false); + _vm->_sound->muteFx(false); + _vm->_sound->muteSpeech(false); } if (_vm->_features & GF_DEMO) { diff --git a/sword2/header.h b/sword2/header.h index 817852f444..9c6f3b4f78 100644 --- a/sword2/header.h +++ b/sword2/header.h @@ -20,8 +20,6 @@ #ifndef _HEADER #define _HEADER -#include "common/scummsys.h" - namespace Sword2 { //---------------------------------------------------------- diff --git a/sword2/icons.cpp b/sword2/icons.cpp index 48750ea890..34cf0280a1 100644 --- a/sword2/icons.cpp +++ b/sword2/icons.cpp @@ -17,14 +17,10 @@ * $Header$ */ -#include "stdafx.h" +#include "common/stdafx.h" #include "sword2/sword2.h" -#include "sword2/driver/driver96.h" #include "sword2/defs.h" -#include "sword2/icons.h" #include "sword2/interpreter.h" -#include "sword2/logic.h" -#include "sword2/mouse.h" namespace Sword2 { @@ -34,7 +30,7 @@ int32 Logic::fnAddMenuObject(int32 *params) { assert(_vm->_totalTemp < TOTAL_engine_pockets); // copy the structure to our in-the-engine list - memcpy(&_vm->_tempList[_vm->_totalTemp], memory->intToPtr(params[0]), sizeof(menu_object)); + memcpy(&_vm->_tempList[_vm->_totalTemp], _vm->_memory->intToPtr(params[0]), sizeof(menu_object)); _vm->_totalTemp++; // script continue @@ -87,9 +83,9 @@ void Sword2Engine::buildMenu(void) { // Call menu builder script which will register all carried menu // objects. Run the 'build_menu' script in the 'menu_master' object - head = res_man->openResource(MENU_MASTER_OBJECT); + head = _resman->openResource(MENU_MASTER_OBJECT); _logic->runScript((char*) head, (char*) head, &null_pc); - res_man->closeResource(MENU_MASTER_OBJECT); + _resman->closeResource(MENU_MASTER_OBJECT); // Compare new with old. Anything in master thats not in new gets // removed from master - if found in new too, remove from temp @@ -191,7 +187,7 @@ void Sword2Engine::buildMenu(void) { icon_coloured = true; } - icon = res_man->openResource(_masterMenuList[j].icon_resource) + sizeof(_standardHeader); + icon = _resman->openResource(_masterMenuList[j].icon_resource) + sizeof(_standardHeader); // The coloured icon is stored directly after the // greyed out one. @@ -199,16 +195,16 @@ void Sword2Engine::buildMenu(void) { if (icon_coloured) icon += (RDMENU_ICONWIDE * RDMENU_ICONDEEP); - g_graphics->setMenuIcon(RDMENU_BOTTOM, j, icon); - res_man->closeResource(res); + _graphics->setMenuIcon(RDMENU_BOTTOM, j, icon); + _resman->closeResource(res); } else { // no icon here - g_graphics->setMenuIcon(RDMENU_BOTTOM, j, NULL); + _graphics->setMenuIcon(RDMENU_BOTTOM, j, NULL); debug(5, " NULL for %d", j); } } - g_graphics->showMenu(RDMENU_BOTTOM); + _graphics->showMenu(RDMENU_BOTTOM); } void Sword2Engine::buildSystemMenu(void) { @@ -228,7 +224,7 @@ void Sword2Engine::buildSystemMenu(void) { // rest will grey out for (int i = 0; i < ARRAYSIZE(icon_list); i++) { - icon = res_man->openResource(icon_list[i]) + sizeof(_standardHeader); + icon = _resman->openResource(icon_list[i]) + sizeof(_standardHeader); // The only case when an icon is grayed is when the player // is dead. Then SAVE is not available. @@ -236,11 +232,11 @@ void Sword2Engine::buildSystemMenu(void) { if (!DEAD || icon_list[i] != SAVE_ICON) icon += (RDMENU_ICONWIDE * RDMENU_ICONDEEP); - g_graphics->setMenuIcon(RDMENU_TOP, i, icon); - res_man->closeResource(icon_list[i]); + _graphics->setMenuIcon(RDMENU_TOP, i, icon); + _resman->closeResource(icon_list[i]); } - g_graphics->showMenu(RDMENU_TOP); + _graphics->showMenu(RDMENU_TOP); } } // End of namespace Sword2 diff --git a/sword2/icons.h b/sword2/icons.h index 05084aad0f..01abc59203 100644 --- a/sword2/icons.h +++ b/sword2/icons.h @@ -20,8 +20,6 @@ #ifndef _ICONS #define _ICONS -#include "sword2/object.h" - #define MENU_MASTER_OBJECT 44 #define TOTAL_subjects (375 - 256 + 1) // the speech subject bar #define TOTAL_engine_pockets (15 + 10) // +10 for overflow diff --git a/sword2/interpreter.cpp b/sword2/interpreter.cpp index c35e6eb954..d8550c9fe8 100644 --- a/sword2/interpreter.cpp +++ b/sword2/interpreter.cpp @@ -17,11 +17,9 @@ * $Header$ */ -#include "stdafx.h" -#include "sword2/driver/driver96.h" -#include "sword2/console.h" +#include "common/stdafx.h" +#include "sword2/sword2.h" #include "sword2/interpreter.h" -#include "sword2/logic.h" namespace Sword2 { @@ -353,8 +351,8 @@ int Logic::runScript(char *scriptData, char *objectData, uint32 *offset) { case CP_PUSH_LOCAL_ADDR: // push the address of a local variable Read16ip(parameter); - debug(5, "Push address of local variable %d (%x)", parameter, memory->ptrToInt((const uint8 *) (variables + parameter))); - PUSHONSTACK(memory->ptrToInt((uint8 *) (variables + parameter))); + debug(5, "Push address of local variable %d (%x)", parameter, _vm->_memory->ptrToInt((const uint8 *) (variables + parameter))); + PUSHONSTACK(_vm->_memory->ptrToInt((uint8 *) (variables + parameter))); break; case CP_PUSH_INT32: // Push a long word value on to the stack @@ -589,14 +587,14 @@ int Logic::runScript(char *scriptData, char *objectData, uint32 *offset) { Read8ip(parameter); // ip points to the string - PUSHONSTACK(memory->ptrToInt((const uint8 *) (code + ip))); + PUSHONSTACK(_vm->_memory->ptrToInt((const uint8 *) (code + ip))); ip += (parameter + 1); break; case CP_PUSH_DEREFERENCED_STRUCTURE: // Push the address of a dereferenced structure Read32ip(parameter); - debug(5, "Push address of far variable (%x)", memory->ptrToInt((const uint8 *) (objectData + sizeof(int32) + sizeof(_standardHeader) + sizeof(_object_hub) + parameter))); - PUSHONSTACK(memory->ptrToInt((const uint8 *) (objectData + sizeof(int32) + sizeof(_standardHeader) + sizeof(_object_hub) + parameter))); + debug(5, "Push address of far variable (%x)", _vm->_memory->ptrToInt((const uint8 *) (objectData + sizeof(int32) + sizeof(_standardHeader) + sizeof(_object_hub) + parameter))); + PUSHONSTACK(_vm->_memory->ptrToInt((const uint8 *) (objectData + sizeof(int32) + sizeof(_standardHeader) + sizeof(_object_hub) + parameter))); break; case OP_GTTHANE: // '>=' diff --git a/sword2/layers.cpp b/sword2/layers.cpp index 3216207a05..9da7507506 100644 --- a/sword2/layers.cpp +++ b/sword2/layers.cpp @@ -25,16 +25,8 @@ // 3 normal sorted layers // up to 2 foreground parallax layers -#include "stdafx.h" +#include "common/stdafx.h" #include "sword2/sword2.h" -#include "sword2/build_display.h" -#include "sword2/debug.h" -#include "sword2/header.h" -#include "sword2/layers.h" -#include "sword2/logic.h" -#include "sword2/protocol.h" -#include "sword2/resman.h" -#include "sword2/sound.h" // for clearFxQueue() called from fnInitBackground() namespace Sword2 { @@ -69,11 +61,11 @@ int32 Sword2Engine::initBackground(int32 res, int32 new_palette) { #endif // if the screen is still fading down then wait for black - g_graphics->waitForFade(); + _graphics->waitForFade(); // if last screen was using a shading mask (see below) if (_thisScreen.mask_flag) { - rv = g_graphics->closeLightMask(); + rv = _graphics->closeLightMask(); if (rv) error("Driver Error %.8x", rv); } @@ -82,7 +74,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_graphics->closeBackgroundLayer(); + _graphics->closeBackgroundLayer(); _thisScreen.background_layer_id = res; _thisScreen.new_palette = new_palette; @@ -92,7 +84,7 @@ int32 Sword2Engine::initBackground(int32 res, int32 new_palette) { // each cycle // file points to 1st byte in the layer file - file = res_man->openResource(_thisScreen.background_layer_id); + file = _resman->openResource(_thisScreen.background_layer_id); screen_head = fetchScreenHeader(file); @@ -104,7 +96,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_graphics->setLocationMetrics(screen_head->width, screen_head->height); + _graphics->setLocationMetrics(screen_head->width, screen_head->height); if (screen_head->noLayers) { for (int i = 0; i < screen_head->noLayers; i++) { @@ -126,7 +118,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_graphics->_screenWide || screen_head->height > g_graphics->_screenDeep) { + if (screen_head->width > _graphics->_screenWide || screen_head->height > _graphics->_screenDeep) { // switch on scrolling (2 means first time on screen) _thisScreen.scroll_flag = 2; @@ -141,9 +133,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_graphics->_screenWide; + _thisScreen.max_scroll_offset_x = screen_head->width - _graphics->_screenWide; // 'screenDeep' includes the menu's, so take away 80 pixels - _thisScreen.max_scroll_offset_y = screen_head->height - (g_graphics->_screenDeep - (RDMENU_MENUDEEP * 2)); + _thisScreen.max_scroll_offset_y = screen_head->height - (_graphics->_screenDeep - (RDMENU_MENUDEEP * 2)); } else { // layer fits on physical screen - scrolling not required _thisScreen.scroll_flag = 0; // switch off scrolling @@ -153,7 +145,7 @@ int32 Sword2Engine::initBackground(int32 res, int32 new_palette) { // no inter-cycle scroll between new screens (see setScrollTarget in // build display) - g_graphics->resetRenderEngine(); + _graphics->resetRenderEngine(); // these are the physical screen coords where the system // will try to maintain George's actual feet coords @@ -177,7 +169,7 @@ int32 Sword2Engine::initBackground(int32 res, int32 new_palette) { spriteInfo.data = fetchShadingMask(file); spriteInfo.colourTable = 0; - rv = g_graphics->openLightMask(&spriteInfo); + rv = _graphics->openLightMask(&spriteInfo); if (rv) error("Driver Error %.8x", rv); @@ -189,7 +181,7 @@ int32 Sword2Engine::initBackground(int32 res, int32 new_palette) { } // close the screen file - res_man->closeResource(_thisScreen.background_layer_id); + _resman->closeResource(_thisScreen.background_layer_id); setUpBackgroundLayers(); @@ -211,7 +203,7 @@ void Sword2Engine::setUpBackgroundLayers(void) { // open resource & set pointers to headers // file points to 1st byte in the layer file - file = res_man->openResource(_thisScreen.background_layer_id); + file = _resman->openResource(_thisScreen.background_layer_id); screen_head = fetchScreenHeader(file); @@ -221,26 +213,26 @@ void Sword2Engine::setUpBackgroundLayers(void) { for (i = 0; i < 2; i++) { if (screenLayerTable->bg_parallax[i]) - g_graphics->initialiseBackgroundLayer(fetchBackgroundParallaxLayer(file, i)); + _graphics->initialiseBackgroundLayer(fetchBackgroundParallaxLayer(file, i)); else - g_graphics->initialiseBackgroundLayer(NULL); + _graphics->initialiseBackgroundLayer(NULL); } // Normal backround layer - g_graphics->initialiseBackgroundLayer(fetchBackgroundLayer(file)); + _graphics->initialiseBackgroundLayer(fetchBackgroundLayer(file)); // Foreground parallax layers for (i = 0; i < 2; i++) { if (screenLayerTable->fg_parallax[i]) - g_graphics->initialiseBackgroundLayer(fetchForegroundParallaxLayer(file, i)); + _graphics->initialiseBackgroundLayer(fetchForegroundParallaxLayer(file, i)); else - g_graphics->initialiseBackgroundLayer(NULL); + _graphics->initialiseBackgroundLayer(NULL); } // close the screen file - res_man->closeResource(_thisScreen.background_layer_id); + _resman->closeResource(_thisScreen.background_layer_id); } } diff --git a/sword2/logic.cpp b/sword2/logic.cpp index 7814407084..9b65a76e53 100644 --- a/sword2/logic.cpp +++ b/sword2/logic.cpp @@ -17,16 +17,10 @@ * $Header$ */ -#include "stdafx.h" +#include "common/stdafx.h" #include "sword2/sword2.h" #include "sword2/defs.h" -#include "sword2/build_display.h" -#include "sword2/console.h" -#include "sword2/debug.h" #include "sword2/interpreter.h" -#include "sword2/logic.h" -#include "sword2/router.h" // for clearWalkGridList() -#include "sword2/sound.h" namespace Sword2 { @@ -57,7 +51,7 @@ int Logic::processSession(void) { // processing on the current list while (_pc != 0xffffffff) { - head = (_standardHeader*) res_man->openResource(run_list); + head = (_standardHeader*) _vm->_resman->openResource(run_list); if (head->fileType != RUN_LIST) error("Logic_engine %d not a run_list", run_list); @@ -71,7 +65,7 @@ int Logic::processSession(void) { // release the list again so it can float in memory - at this // point not one thing should be locked - res_man->closeResource(run_list); + _vm->_resman->closeResource(run_list); debug(5, "%d", ID); @@ -81,7 +75,7 @@ int Logic::processSession(void) { return 0; } - head = (_standardHeader*) res_man->openResource(ID); + head = (_standardHeader*) _vm->_resman->openResource(ID); if (head->fileType != GAME_OBJECT) error("Logic_engine %d not an object", ID); @@ -127,7 +121,7 @@ int Logic::processSession(void) { raw_data_ad = (char*) head; - far_head = (_standardHeader*) res_man->openResource(script / SIZE); + far_head = (_standardHeader*) _vm->_resman->openResource(script / SIZE); if (far_head->fileType != GAME_OBJECT && far_head->fileType != SCREEN_MANAGER) error("Logic_engine %d not a far object (its a %d)", script / SIZE, far_head->fileType); @@ -142,7 +136,7 @@ int Logic::processSession(void) { ret = runScript(raw_script_ad, raw_data_ad, &_curObjectHub->script_pc[LEVEL]); // close foreign object again - res_man->closeResource(script / SIZE); + _vm->_resman->closeResource(script / SIZE); // reset to us for service script raw_script_ad = raw_data_ad; @@ -198,7 +192,7 @@ int Logic::processSession(void) { // and that's it so close the object resource - res_man->closeResource(ID); + _vm->_resman->closeResource(ID); } // leaving a room so remove all ids that must reboot correctly @@ -336,17 +330,17 @@ void Logic::examineRunList(void) { if (_currentRunList) { // open and lock in place - game_object_list = (uint32 *) (res_man->openResource(_currentRunList) + sizeof(_standardHeader)); + game_object_list = (uint32 *) (_vm->_resman->openResource(_currentRunList) + sizeof(_standardHeader)); Debug_Printf("Runlist number %d\n", _currentRunList); for (int i = 0; game_object_list[i]; i++) { - file_header = (_standardHeader *) res_man->openResource(game_object_list[i]); + file_header = (_standardHeader *) _vm->_resman->openResource(game_object_list[i]); Debug_Printf("%d %s\n", game_object_list[i], file_header->name); - res_man->closeResource(game_object_list[i]); + _vm->_resman->closeResource(game_object_list[i]); } - res_man->closeResource(_currentRunList); + _vm->_resman->closeResource(_currentRunList); } else Debug_Printf("No run list set\n"); } @@ -427,7 +421,7 @@ int32 Logic::fnAddToKillList(int32 *params) { void Logic::processKillList(void) { for (uint32 i = 0; i < _kills; i++) - res_man->remove(_objectKillList[i]); + _vm->_resman->remove(_objectKillList[i]); _kills = 0; } diff --git a/sword2/logic.h b/sword2/logic.h index 0b4a99433b..2ed33dc45b 100644 --- a/sword2/logic.h +++ b/sword2/logic.h @@ -22,7 +22,6 @@ #ifndef _LOGIC #define _LOGIC -#include "sword2/driver/driver96.h" #include "sword2/header.h" #include "sword2/memory.h" #include "sword2/router.h" @@ -189,7 +188,7 @@ public: memset(_subjectList, 0, sizeof(_subjectList)); memset(_eventList, 0, sizeof(_eventList)); memset(_syncList, 0, sizeof(_syncList)); - _router = new Router(); + _router = new Router(_vm); setupOpcodes(); initStartMenu(); } diff --git a/sword2/maketext.cpp b/sword2/maketext.cpp index 40d18b5764..54329ba284 100644 --- a/sword2/maketext.cpp +++ b/sword2/maketext.cpp @@ -46,22 +46,12 @@ #define LAST_CHAR 255 // last character in character set #define DUD 64 // the first "chequered flag" (dud) symbol in // our character set is in the '@' position -#include "stdafx.h" -#include "sword2/driver/driver96.h" -#include "sword2/console.h" -#include "sword2/debug.h" -#include "sword2/defs.h" // for SPEECH_FONT_ID & CONSOLE_FONT_ID -#include "sword2/header.h" -#include "sword2/maketext.h" -#include "sword2/memory.h" -#include "sword2/protocol.h" // for fetchFrameHeader() -#include "sword2/resman.h" +#include "common/stdafx.h" #include "sword2/sword2.h" +#include "sword2/defs.h" namespace Sword2 { -FontRenderer *fontRenderer; - // info for each line of words in the output text sprite mem* FontRenderer::makeTextSprite(uint8 *sentence, uint16 maxWidth, uint8 pen, uint32 fontRes, uint8 border) { @@ -94,7 +84,7 @@ mem* FontRenderer::makeTextSprite(uint8 *sentence, uint16 maxWidth, uint8 pen, u // allocate memory for array of lineInfo structures - line = memory->allocMemory(MAX_LINES * sizeof(LineInfo), MEM_locked, UID_temp); + line = _vm->_memory->allocMemory(MAX_LINES * sizeof(LineInfo), MEM_locked, UID_temp); // get details of sentence breakdown into array of LineInfo structures // and get the no of lines involved @@ -107,7 +97,7 @@ mem* FontRenderer::makeTextSprite(uint8 *sentence, uint16 maxWidth, uint8 pen, u textSprite = buildTextSprite(sentence, fontRes, pen, (LineInfo *) line->ad, noOfLines); // free up the lineInfo array now - memory->freeMemory(line); + _vm->_memory->freeMemory(line); return textSprite; } @@ -220,7 +210,7 @@ mem* FontRenderer::buildTextSprite(uint8 *sentence, uint32 fontRes, uint8 pen, L // allocate memory for sprite, and lock it ready for use // NB. 'textSprite' is the given pointer to the handle to be used - textSprite = memory->allocMemory(sizeof(_frameHeader) + sizeOfSprite, MEM_locked, UID_text_sprite); + textSprite = _vm->_memory->allocMemory(sizeof(_frameHeader) + sizeOfSprite, MEM_locked, UID_text_sprite); // the handle (*textSprite) now points to UNMOVABLE memory block // set up the frame header @@ -244,7 +234,7 @@ mem* FontRenderer::buildTextSprite(uint8 *sentence, uint32 fontRes, uint8 pen, L memset(linePtr, NO_COL, sizeOfSprite); // open font file - charSet = res_man->openResource(fontRes); + charSet = _vm->_resman->openResource(fontRes); // fill sprite with characters, one line at a time @@ -278,10 +268,10 @@ mem* FontRenderer::buildTextSprite(uint8 *sentence, uint32 fontRes, uint8 pen, L } // close font file - res_man->closeResource(fontRes); + _vm->_resman->closeResource(fontRes); // unlock the sprite memory block, so it's movable - memory->floatMemory(textSprite); + _vm->_memory->floatMemory(textSprite); return textSprite; } @@ -295,14 +285,14 @@ uint16 FontRenderer::charWidth(uint8 ch, uint32 fontRes) { uint16 width; // open font file - charSet = res_man->openResource(fontRes); + charSet = _vm->_resman->openResource(fontRes); // move to approp. sprite (header) charFrame = findChar(ch, charSet); width = charFrame->width; // close font file - res_man->closeResource(fontRes); + _vm->_resman->closeResource(fontRes); // return its width return width; @@ -317,14 +307,14 @@ uint16 FontRenderer::charHeight(uint32 fontRes) { uint16 height; // open font file - charSet = res_man->openResource(fontRes); + charSet = _vm->_resman->openResource(fontRes); // assume all chars the same height, i.e. FIRST_CHAR is as good as any charFrame = findChar(FIRST_CHAR, charSet); height = charFrame->height; // close font file - res_man->closeResource(fontRes); + _vm->_resman->closeResource(fontRes); // return its height return height; @@ -525,7 +515,7 @@ void FontRenderer::printTextBlocs(void) { spriteInfo.data = _blocList[j].text_mem->ad + sizeof(_frameHeader); spriteInfo.colourTable = 0; - rv = g_graphics->drawSprite(&spriteInfo); + rv = _vm->_graphics->drawSprite(&spriteInfo); if (rv) error("Driver Error %.8x in Print_text_blocs", rv); } @@ -538,7 +528,7 @@ void FontRenderer::killTextBloc(uint32 bloc_number) { if (_blocList[bloc_number].text_mem) { // release the floating memory and mark it as free - memory->freeMemory(_blocList[bloc_number].text_mem); + _vm->_memory->freeMemory(_blocList[bloc_number].text_mem); _blocList[bloc_number].text_mem = 0; } else { // illegal kill - stop the system @@ -564,7 +554,7 @@ void Sword2Engine::initialiseFontResourceFlags(void) { uint8 language; // open the text resource - textFile = res_man->openResource(TEXT_RES); + textFile = _resman->openResource(TEXT_RES); // If language is Polish or Finnish it requires alternate fonts. // Otherwise, use regular fonts @@ -603,10 +593,10 @@ void Sword2Engine::initialiseFontResourceFlags(void) { // GERMAN: "Baphomet's Fluch II" // default: "Some game or other, part 86" - g_graphics->setWindowName((char *) textLine); + _graphics->setWindowName((char *) textLine); // now ok to close the text file - res_man->closeResource(TEXT_RES); + _resman->closeResource(TEXT_RES); } // called from the above function, and also from console.cpp diff --git a/sword2/maketext.h b/sword2/maketext.h index 41d0151810..5b870a37bc 100644 --- a/sword2/maketext.h +++ b/sword2/maketext.h @@ -57,7 +57,6 @@ #ifndef _MAKETEXT_H #define _MAKETEXT_H -#include "sword2/memory.h" #include "sword2/debug.h" // Output colour for character border - should be be black but note that we @@ -108,6 +107,7 @@ typedef struct { class FontRenderer { private: + Sword2Engine *_vm; TextBloc _blocList[MAX_text_blocs]; // layout variables - these used to be defines, but now we're dealing @@ -128,7 +128,7 @@ private: void copyChar(_frameHeader *charPtr, uint8 *spritePtr, uint16 spriteWidth, uint8 pen); public: - FontRenderer() { + FontRenderer(Sword2Engine *vm) : _vm(vm) { for (int i = 0; i < MAX_text_blocs; i++) _blocList[i].text_mem = NULL; } @@ -141,8 +141,6 @@ public: uint32 buildNewBloc(uint8 *ascii, int16 x, int16 y, uint16 width, uint8 pen, uint32 type, uint32 fontRes, uint8 justification); }; -extern FontRenderer *fontRenderer; - } // End of namespace Sword2 #endif diff --git a/sword2/mem_view.cpp b/sword2/mem_view.cpp index 80081023b5..abf5379098 100644 --- a/sword2/mem_view.cpp +++ b/sword2/mem_view.cpp @@ -17,19 +17,11 @@ * $Header$ */ -#include "stdafx.h" +#include "common/stdafx.h" #include "sword2/sword2.h" -#include "sword2/build_display.h" -#include "sword2/console.h" -#include "sword2/header.h" -#include "sword2/memory.h" -#include "sword2/resman.h" namespace Sword2 { -// has to be global because a local in Fetch_mem_owner is destroyed on exit -char buf[50]; - void MemoryManager::displayMemory(void) { int pass, found_end, k, j, free = 0; _standardHeader *file_header; @@ -44,9 +36,9 @@ void MemoryManager::displayMemory(void) { j = _baseMemBlock; do { if (_memList[j].uid < 65536) { - file_header = (_standardHeader*) res_man->openResource(_memList[j].uid); + file_header = (_standardHeader*) _vm->_resman->openResource(_memList[j].uid); // close immediately so give a true count - res_man->closeResource(_memList[j].uid); + _vm->_resman->closeResource(_memList[j].uid); debug(5, "view %d", _memList[j].uid); @@ -73,10 +65,10 @@ void MemoryManager::displayMemory(void) { _memList[j].size / 1024, (_memList[j].size * 100) / _totalFreeMemory, _memList[j].uid, - res_man->fetchCluster(_memList[j].uid), + _vm->_resman->fetchCluster(_memList[j].uid), file_header->name, - res_man->fetchAge(_memList[j].uid), - res_man->fetchCount(_memList[j].uid)); + _vm->_resman->fetchAge(_memList[j].uid), + _vm->_resman->fetchCount(_memList[j].uid)); } else Debug_Printf(" %d is an illegal resource\n", _memList[j].uid); } else { @@ -100,6 +92,8 @@ void MemoryManager::displayMemory(void) { } const char *MemoryManager::fetchOwner(uint32 uid) { + static char buf[50]; + switch (uid) { case UID_memman: return "MEMMAN"; @@ -160,7 +154,7 @@ void MemoryManager::memoryString(char *string) { sprintf(string, "locked(%u)+float(%u)+free(%u) = %u/%u blocks (%u%% used)(cur %uk)", mem_locked, mem_floating, mem_free, blocksUsed, MAX_mem_blocks, - percent, (res_man->fetchUsage() / 1024)); + percent, (_vm->_resman->fetchUsage() / 1024)); } } // End of namespace Sword2 diff --git a/sword2/memory.cpp b/sword2/memory.cpp index 908bea1dba..e23f8eb402 100644 --- a/sword2/memory.cpp +++ b/sword2/memory.cpp @@ -34,21 +34,16 @@ // MemMan v1.1 -#include "stdafx.h" -#include "sword2/driver/driver96.h" -#include "sword2/debug.h" -#include "sword2/memory.h" -#include "sword2/resman.h" +#include "common/stdafx.h" +#include "sword2/sword2.h" namespace Sword2 { -MemoryManager *memory; - #define MEMORY_POOL (1024 * 12000) // #define MEMDEBUG 1 -MemoryManager::MemoryManager(void) { +MemoryManager::MemoryManager(Sword2Engine *vm) : _vm(vm) { uint32 j; uint8 *memory_base; @@ -56,12 +51,10 @@ MemoryManager::MemoryManager(void) { _totalFreeMemory = MEMORY_POOL; - // malloc memory and adjust for long boundaries memory_base = (uint8 *) malloc(_totalFreeMemory); - if (!memory_base) { //could not grab the memory - error("Init_memory_manager() couldn't malloc %d bytes", _totalFreeMemory); - } + if (!memory_base) + error("MemoryManager: couldn't malloc %d bytes", _totalFreeMemory); // the original malloc address _freeMemman = memory_base; @@ -501,7 +494,7 @@ mem *MemoryManager::allocMemory(uint32 size, uint32 type, uint32 unique_id) { while (virtualDefrag(size)) { // trash the oldest closed resource - if (!res_man->helpTheAgedOut()) { + if (!_vm->_resman->helpTheAgedOut()) { error("alloc ran out of memory: size=%d type=%d unique_id=%d", size, type, unique_id); } } diff --git a/sword2/memory.h b/sword2/memory.h index 51c203265f..57f972185e 100644 --- a/sword2/memory.h +++ b/sword2/memory.h @@ -66,6 +66,8 @@ enum { class MemoryManager { private: + Sword2Engine *_vm; + // Address of init malloc to be freed later uint8 *_freeMemman; @@ -92,7 +94,7 @@ public: mem _memList[MAX_mem_blocks]; uint32 _baseMemBlock; - MemoryManager(void); + MemoryManager(Sword2Engine *vm); ~MemoryManager(void); int32 ptrToInt(const uint8 *p); @@ -108,8 +110,6 @@ public: void memoryString(char *string); }; -extern MemoryManager *memory; - } // End of namespace Sword2 #endif diff --git a/sword2/mouse.cpp b/sword2/mouse.cpp index 5d1fc65dcd..fc4f9ad98d 100644 --- a/sword2/mouse.cpp +++ b/sword2/mouse.cpp @@ -17,23 +17,10 @@ * $Header$ */ -#include "stdafx.h" -#include "sword2/driver/driver96.h" -#include "sword2/build_display.h" -#include "sword2/console.h" -#include "sword2/controls.h" +#include "common/stdafx.h" +#include "sword2/sword2.h" #include "sword2/defs.h" -#include "sword2/icons.h" #include "sword2/interpreter.h" -#include "sword2/logic.h" -#include "sword2/layers.h" -#include "sword2/maketext.h" -#include "sword2/mouse.h" -#include "sword2/object.h" -#include "sword2/protocol.h" -#include "sword2/resman.h" -#include "sword2/sound.h" -#include "sword2/sword2.h" namespace Sword2 { @@ -180,9 +167,9 @@ void Sword2Engine::systemMenuMouse(void) { for (int i = 0; i < ARRAYSIZE(icon_list); i++) { if (i != hit) { - icon = res_man->openResource(icon_list[i]) + sizeof(_standardHeader); + icon = _resman->openResource(icon_list[i]) + sizeof(_standardHeader); _graphics->setMenuIcon(RDMENU_TOP, i, icon); - res_man->closeResource(icon_list[i]); + _resman->closeResource(icon_list[i]); } } @@ -211,19 +198,19 @@ void Sword2Engine::systemMenuMouse(void) { switch (hit) { case 0: - gui->optionControl(); + _gui->optionControl(); break; case 1: - gui->quitControl(); + _gui->quitControl(); break; case 2: - gui->saveControl(); + _gui->saveControl(); break; case 3: - gui->restoreControl(); + _gui->restoreControl(); break; case 4: - gui->restartControl(); + _gui->restartControl(); break; } @@ -773,8 +760,8 @@ void Sword2Engine::setMouse(uint32 res) { _mousePointerRes = res; if (res) { - icon = res_man->openResource(res) + sizeof(_standardHeader); - len = res_man->_resList[res]->size - sizeof(_standardHeader); + icon = _resman->openResource(res) + sizeof(_standardHeader); + len = _resman->_resList[res]->size - sizeof(_standardHeader); // don't pulse the normal pointer - just do the regular anim // loop @@ -784,7 +771,7 @@ void Sword2Engine::setMouse(uint32 res) { else _graphics->setMouseAnim(icon, len, RDMOUSE_FLASH); - res_man->closeResource(res); + _resman->closeResource(res); } else { // blank cursor _graphics->setMouseAnim(NULL, 0, 0); @@ -798,12 +785,12 @@ void Sword2Engine::setLuggage(uint32 res) { _realLuggageItem = res; if (res) { - icon = res_man->openResource(res) + sizeof(_standardHeader); - len = res_man->_resList[res]->size - sizeof(_standardHeader); + icon = _resman->openResource(res) + sizeof(_standardHeader); + len = _resman->_resList[res]->size - sizeof(_standardHeader); _graphics->setLuggageAnim(icon, len); - res_man->closeResource(res); + _resman->closeResource(res); } else _graphics->setLuggageAnim(NULL, 0); } @@ -862,7 +849,7 @@ void Sword2Engine::createPointerText(uint32 text_id, uint32 pointer_res) { int16 xOffset, yOffset; uint8 justification; - if (!gui->_pointerTextSelected || !text_id) + if (!_gui->_pointerTextSelected || !text_id) return; // Check what the pointer is, to set offsets correctly for text @@ -992,12 +979,12 @@ void Sword2Engine::createPointerText(uint32 text_id, uint32 pointer_res) { local_text = text_id & 0xffff; // open text file & get the line - text = fetchTextLine(res_man->openResource(text_res), local_text); + text = fetchTextLine(_resman->openResource(text_res), local_text); // 'text+2' to skip the first 2 bytes which form the // line reference number - _pointerTextBlocNo = fontRenderer->buildNewBloc( + _pointerTextBlocNo = _fontRenderer->buildNewBloc( text + 2, _input->_mouseX + xOffset, _input->_mouseY + yOffset, POINTER_TEXT_WIDTH, POINTER_TEXT_PEN, @@ -1005,12 +992,12 @@ void Sword2Engine::createPointerText(uint32 text_id, uint32 pointer_res) { _speechFontId, justification); // now ok to close the text file - res_man->closeResource(text_res); + _resman->closeResource(text_res); } void Sword2Engine::clearPointerText(void) { if (_pointerTextBlocNo) { - fontRenderer->killTextBloc(_pointerTextBlocNo); + _fontRenderer->killTextBloc(_pointerTextBlocNo); _pointerTextBlocNo = 0; } } @@ -1090,12 +1077,12 @@ int32 Logic::fnNoHuman(int32 *params) { // dont hide menu in conversations if (TALK_FLAG == 0) - g_graphics->hideMenu(RDMENU_BOTTOM); + _vm->_graphics->hideMenu(RDMENU_BOTTOM); if (_vm->_mouseMode == MOUSE_system_menu) { // close menu _vm->_mouseMode = MOUSE_normal; - g_graphics->hideMenu(RDMENU_TOP); + _vm->_graphics->hideMenu(RDMENU_TOP); } // script continue @@ -1138,7 +1125,7 @@ int32 Logic::fnAddHuman(int32 *params) { } // if mouse is over menu area - if (g_input->_mouseY > 399) { + if (_vm->_input->_mouseY > 399) { if (_vm->_mouseMode != MOUSE_holding) { // VITAL - reset things & rebuild the menu _vm->_mouseMode = MOUSE_normal; @@ -1157,7 +1144,7 @@ int32 Logic::fnAddHuman(int32 *params) { // testing logic scripts by simulating an instant Save & // Restore - g_graphics->setPalette(0, 1, white, RDPAL_INSTANT); + _vm->_graphics->setPalette(0, 1, white, RDPAL_INSTANT); // stops all fx & clears the queue - eg. when leaving a // location @@ -1167,9 +1154,9 @@ int32 Logic::fnAddHuman(int32 *params) { // Trash all object resources so they load in fresh & restart // their logic scripts - res_man->killAllObjects(false); + _vm->_resman->killAllObjects(false); - g_graphics->setPalette(0, 1, black, RDPAL_INSTANT); + _vm->_graphics->setPalette(0, 1, black, RDPAL_INSTANT); } return IR_CONT; @@ -1184,7 +1171,7 @@ int32 Logic::fnRegisterMouse(int32 *params) { // params: 0 pointer to Object_mouse or 0 for no write to mouse // list - _vm->registerMouse((Object_mouse *) memory->intToPtr(params[0])); + _vm->registerMouse((Object_mouse *) _vm->_memory->intToPtr(params[0])); return IR_CONT; } @@ -1209,7 +1196,7 @@ int32 Logic::fnRegisterPointerText(int32 *params) { int32 Logic::fnInitFloorMouse(int32 *params) { // params: 0 pointer to object's mouse structure - Object_mouse *ob_mouse = (Object_mouse *) memory->intToPtr(params[0]); + Object_mouse *ob_mouse = (Object_mouse *) _vm->_memory->intToPtr(params[0]); // floor is always lowest priority @@ -1228,7 +1215,7 @@ int32 Logic::fnInitFloorMouse(int32 *params) { int32 Logic::fnSetScrollLeftMouse(int32 *params) { // params: 0 pointer to object's mouse structure - Object_mouse *ob_mouse = (Object_mouse *) memory->intToPtr(params[0]); + Object_mouse *ob_mouse = (Object_mouse *) _vm->_memory->intToPtr(params[0]); // Highest priority @@ -1252,11 +1239,11 @@ int32 Logic::fnSetScrollLeftMouse(int32 *params) { int32 Logic::fnSetScrollRightMouse(int32 *params) { // params: 0 pointer to object's mouse structure - Object_mouse *ob_mouse = (Object_mouse *) memory->intToPtr(params[0]); + Object_mouse *ob_mouse = (Object_mouse *) _vm->_memory->intToPtr(params[0]); // Highest priority - ob_mouse->x1 = _vm->_thisScreen.scroll_offset_x + g_graphics->_screenWide - SCROLL_MOUSE_WIDTH; + ob_mouse->x1 = _vm->_thisScreen.scroll_offset_x + _vm->_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; @@ -1293,7 +1280,7 @@ int32 Logic::fnSetObjectHeld(int32 *params) { int32 Logic::fnRemoveChooser(int32 *params) { // params: none - g_graphics->hideMenu(RDMENU_BOTTOM); + _vm->_graphics->hideMenu(RDMENU_BOTTOM); return IR_CONT; } diff --git a/sword2/mouse.h b/sword2/mouse.h index 08a6d0dedb..5faf52b396 100644 --- a/sword2/mouse.h +++ b/sword2/mouse.h @@ -20,8 +20,6 @@ #ifndef MOUSE_H #define MOUSE_H -#include "sword2/object.h" - #define TOTAL_mouse_list 50 namespace Sword2 { diff --git a/sword2/protocol.cpp b/sword2/protocol.cpp index 39ecb39827..e8b43b5eca 100644 --- a/sword2/protocol.cpp +++ b/sword2/protocol.cpp @@ -17,14 +17,8 @@ * $Header$ */ -#include "stdafx.h" +#include "common/stdafx.h" #include "sword2/sword2.h" -#include "sword2/console.h" -#include "sword2/defs.h" -#include "sword2/header.h" -#include "sword2/memory.h" -#include "sword2/protocol.h" -#include "sword2/resman.h" namespace Sword2 { @@ -223,8 +217,8 @@ uint8 Sword2Engine::checkTextLine(uint8 *file, uint32 text_line) { uint8 *Sword2Engine::fetchObjectName(int32 resourceId) { _standardHeader *header; - header = (_standardHeader *) res_man->openResource(resourceId); - res_man->closeResource(resourceId); + header = (_standardHeader *) _resman->openResource(resourceId); + _resman->closeResource(resourceId); // note this pointer is no longer valid, but it should be ok until // another resource is opened! diff --git a/sword2/resman.cpp b/sword2/resman.cpp index 0bc3c2b5dc..09adf8b461 100644 --- a/sword2/resman.cpp +++ b/sword2/resman.cpp @@ -17,23 +17,10 @@ * $Header$ */ -#include "stdafx.h" +#include "common/stdafx.h" +#include "common/file.h" #include "sword2/sword2.h" -#include "sword2/driver/driver96.h" -#include "sword2/build_display.h" -#include "sword2/console.h" -#include "sword2/debug.h" #include "sword2/defs.h" -#include "sword2/header.h" -#include "sword2/interpreter.h" -#include "sword2/logic.h" -#include "sword2/maketext.h" -#include "sword2/memory.h" -#include "sword2/mouse.h" // for system setMouse & setLuggage routines -#include "sword2/protocol.h" -#include "sword2/resman.h" -#include "sword2/sound.h" // for clearFxQueue() called from cacheNewCluster() -#include "sword2/router.h" namespace Sword2 { @@ -53,8 +40,6 @@ namespace Sword2 { #define BUFFERSIZE 4096 -ResourceManager *res_man; // declare the object global - // --------------------------------------------------------------------------- // // @@ -107,7 +92,7 @@ ResourceManager::ResourceManager(Sword2Engine *vm) { end = file.size(); //get some space for the incoming resource file - soon to be trashed - temp = memory->allocMemory(end, MEM_locked, UID_temp); + temp = _vm->_memory->allocMemory(end, MEM_locked, UID_temp); if (file.read(temp->ad, end) != end) { file.close(); @@ -191,6 +176,8 @@ ResourceManager::ResourceManager(Sword2Engine *vm) { _cdTab[j] = cdInf[i].cd; } + delete cdInf; + debug(5, "%d resources in %d cluster files", _totalResFiles, _totalClusters); for (j = 0; j < _totalClusters; j++) debug(5, "filename of cluster %d: -%s", j, _resourceFiles[j]); @@ -208,7 +195,7 @@ ResourceManager::ResourceManager(Sword2Engine *vm) { } _resTime = 1; //cannot start at 0 - memory->freeMemory(temp); //get that memory back + _vm->_memory->freeMemory(temp); //get that memory back } ResourceManager::~ResourceManager(void) { @@ -487,7 +474,7 @@ uint8 *ResourceManager::openResource(uint32 res) { // ok, we know the length so try and allocate the memory // if it can't then old files will be ditched until it works - _resList[res] = memory->allocMemory(len, MEM_locked, res); + _resList[res] = _vm->_memory->allocMemory(len, MEM_locked, res); // now load the file // hurray, load it in. @@ -512,7 +499,7 @@ uint8 *ResourceManager::openResource(uint32 res) { // pass the address of the mem & lock the memory too // might be locked already (if count > 1) - memory->lockMemory(_resList[res]); + _vm->_memory->lockMemory(_resList[res]); return (uint8 *) _resList[res]->ad; } @@ -592,7 +579,7 @@ void ResourceManager::closeResource(uint32 res) { //if noone has the file open then unlock and allow to float if (!_count[res]) { // pass the address of the mem - memory->floatMemory(_resList[res]); + _vm->_memory->floatMemory(_resList[res]); } } @@ -682,7 +669,7 @@ uint32 ResourceManager::helpTheAgedOut(void) { // trash this old resource _age[oldest_res] = 0; // effectively gone from _resList - memory->freeMemory(_resList[oldest_res]); // release the memory too + _vm->_memory->freeMemory(_resList[oldest_res]); // release the memory too return _resList[oldest_res]->size; // return bytes freed } @@ -817,7 +804,7 @@ void ResourceManager::kill(int res) { if (!_count[res]) { if (_age[res]) { _age[res] = 0; // effectively gone from _resList - memory->freeMemory(_resList[res]); // release the memory too + _vm->_memory->freeMemory(_resList[res]); // release the memory too Debug_Printf("Trashed %d\n", res); } else Debug_Printf("%d not in memory\n", res); @@ -828,7 +815,7 @@ void ResourceManager::kill(int res) { void ResourceManager::remove(uint32 res) { if (_age[res]) { _age[res] = 0; // effectively gone from _resList - memory->freeMemory(_resList[res]); // release the memory too + _vm->_memory->freeMemory(_resList[res]); // release the memory too debug(5, " - Trashing %d", res); } else debug(5, "remove(%d) not even in memory!", res); @@ -841,16 +828,16 @@ void ResourceManager::removeAll(void) { int j; uint32 res; - j = memory->_baseMemBlock; + j = _vm->_memory->_baseMemBlock; do { - if (memory->_memList[j].uid < 65536) { // a resource - res = memory->_memList[j].uid; + if (_vm->_memory->_memList[j].uid < 65536) { // a resource + res = _vm->_memory->_memList[j].uid; _age[res] = 0; // effectively gone from _resList - memory->freeMemory(_resList[res]); // release the memory too + _vm->_memory->freeMemory(_resList[res]); // release the memory too } - j = memory->_memList[j].child; + j = _vm->_memory->_memList[j].child; } while (j != -1); } @@ -864,11 +851,11 @@ void ResourceManager::killAll(bool wantInfo) { uint32 nuked = 0; _standardHeader *header; - j = memory->_baseMemBlock; + j = _vm->_memory->_baseMemBlock; do { - if (memory->_memList[j].uid < 65536) { // a resource - res = memory->_memList[j].uid; + if (_vm->_memory->_memList[j].uid < 65536) { // a resource + res = _vm->_memory->_memList[j].uid; // not the global vars which are assumed to be open in // memory & not the player object! @@ -877,7 +864,7 @@ void ResourceManager::killAll(bool wantInfo) { closeResource(res); _age[res] = 0; // effectively gone from _resList - memory->freeMemory(_resList[res]); // release the memory too + _vm->_memory->freeMemory(_resList[res]); // release the memory too nuked++; // if this was called from the console, @@ -887,7 +874,7 @@ void ResourceManager::killAll(bool wantInfo) { } } } - j = memory->_memList[j].child; + j = _vm->_memory->_memList[j].child; } while (j != -1); // if this was called from the console @@ -914,11 +901,11 @@ void ResourceManager::killAllObjects(bool wantInfo) { uint32 nuked = 0; _standardHeader *header; - j = memory->_baseMemBlock; + j = _vm->_memory->_baseMemBlock; do { - if (memory->_memList[j].uid < 65536) { // a resource - res = memory->_memList[j].uid; + if (_vm->_memory->_memList[j].uid < 65536) { // a resource + res = _vm->_memory->_memList[j].uid; //not the global vars which are assumed to be open in // memory & not the player object! if (res != 1 && res != CUR_PLAYER_ID) { @@ -927,7 +914,7 @@ void ResourceManager::killAllObjects(bool wantInfo) { if (header->fileType == GAME_OBJECT) { _age[res] = 0; // effectively gone from _resList - memory->freeMemory(_resList[res]); // release the memory too + _vm->_memory->freeMemory(_resList[res]); // release the memory too nuked++; // if this was called from the console @@ -938,7 +925,7 @@ void ResourceManager::killAllObjects(bool wantInfo) { } } } - j = memory->_memList[j].child; + j = _vm->_memory->_memList[j].child; } while (j != -1); // if this was called from the console @@ -974,15 +961,15 @@ void ResourceManager::getCd(int cd) { _keyboardEvent ke; _mouseEvent *me; - me = g_input->mouseEvent(); + me = _vm->_input->mouseEvent(); if (me && (me->buttons & (RD_LEFTBUTTONDOWN | RD_RIGHTBUTTONDOWN))) break; - if (g_input->readKey(&ke) == RD_OK) + if (_vm->_input->readKey(&ke) == RD_OK) break; - g_graphics->updateDisplay(); - g_system->delay_msecs(50); + _vm->_graphics->updateDisplay(); + _vm->_system->delay_msecs(50); } _vm->removeMsg(); diff --git a/sword2/resman.h b/sword2/resman.h index d2e14d7130..5738f4c78c 100644 --- a/sword2/resman.h +++ b/sword2/resman.h @@ -20,8 +20,6 @@ #ifndef RESMAN_H #define RESMAN_H -#include "sword2/memory.h" - namespace Sword2 { #define MAX_res_files 20 @@ -102,8 +100,6 @@ private: uint8 _cdTab[MAX_res_files]; // Location of each cluster. }; -extern ResourceManager *res_man; // declare the object global - } // End of namespace Sword2 #endif diff --git a/sword2/router.cpp b/sword2/router.cpp index 7e84a7e7f0..3ea8a2ff97 100644 --- a/sword2/router.cpp +++ b/sword2/router.cpp @@ -73,18 +73,9 @@ * ****************************************************************************/ -#include "stdafx.h" -#include "sword2/driver/driver96.h" +#include "common/stdafx.h" #include "sword2/sword2.h" -#include "sword2/console.h" -#include "sword2/debug.h" #include "sword2/defs.h" -#include "sword2/header.h" -#include "sword2/interpreter.h" -#include "sword2/memory.h" -#include "sword2/object.h" -#include "sword2/resman.h" -#include "sword2/router.h" namespace Sword2 { @@ -115,7 +106,7 @@ void Router::allocateRouteMem(void) { if (_routeSlots[slotNo]) freeRouteMem(); - _routeSlots[slotNo] = memory->allocMemory(sizeof(_walkData) * O_WALKANIM_SIZE, MEM_locked, UID_walk_anim); + _routeSlots[slotNo] = _vm->_memory->allocMemory(sizeof(_walkData) * O_WALKANIM_SIZE, MEM_locked, UID_walk_anim); // 12000 bytes were used for this in Sword1 mega compacts, based on // 20 bytes per '_walkData' frame @@ -133,14 +124,14 @@ void Router::allocateRouteMem(void) { _walkData* Router::lockRouteMem(void) { uint8 slotNo = returnSlotNo(ID); - memory->lockMemory(_routeSlots[slotNo]); + _vm->_memory->lockMemory(_routeSlots[slotNo]); return (_walkData *) _routeSlots[slotNo]->ad; } void Router::floatRouteMem(void) { uint8 slotNo = returnSlotNo(ID); - memory->floatMemory(_routeSlots[slotNo]); + _vm->_memory->floatMemory(_routeSlots[slotNo]); } void Router::freeRouteMem(void) { @@ -148,7 +139,7 @@ void Router::freeRouteMem(void) { // free the mem block pointed to from this entry of _routeSlots[] - memory->freeMemory(_routeSlots[slotNo]); + _vm->_memory->freeMemory(_routeSlots[slotNo]); _routeSlots[slotNo] = NULL; } @@ -157,7 +148,7 @@ void Router::freeAllRouteMem(void) { if (_routeSlots[i]) { // free the mem block pointed to from this entry of // _routeSlots[] - memory->freeMemory(_routeSlots[i]); + _vm->_memory->freeMemory(_routeSlots[i]); _routeSlots[i] = NULL; } } @@ -2530,7 +2521,7 @@ void Router::plotWalkGrid(void) { // lines for (i = 0; i < _nbars; i++) - g_graphics->drawLine(_bars[i].x1, _bars[i].y1, _bars[i].x2, _bars[i].y2, 254); + _vm->_graphics->drawLine(_bars[i].x1, _bars[i].y1, _bars[i].x2, _bars[i].y2, 254); // nodes @@ -2540,8 +2531,8 @@ void Router::plotWalkGrid(void) { } void Router::plotCross(int16 x, int16 y, uint8 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); + _vm->_graphics->drawLine(x - 1, y - 1, x + 1, y + 1, colour); + _vm->_graphics->drawLine(x + 1, y - 1, x - 1, y + 1, colour); } void Router::loadWalkGrid(void) { @@ -2559,7 +2550,7 @@ void Router::loadWalkGrid(void) { for (int i = 0; i < MAX_WALKGRIDS; i++) { if (_walkGridList[i]) { // open walk grid file - fPolygrid = res_man->openResource(_walkGridList[i]); + fPolygrid = _vm->_resman->openResource(_walkGridList[i]); fPolygrid += sizeof(_standardHeader); memmove((uint8 *) &floorHeader, fPolygrid, sizeof(_walkGridHeader)); fPolygrid += sizeof(_walkGridHeader); @@ -2601,7 +2592,7 @@ void Router::loadWalkGrid(void) { } // close walk grid file - res_man->closeResource(_walkGridList[i]); + _vm->_resman->closeResource(_walkGridList[i]); // increment counts of total bars & nodes in whole // walkgrid diff --git a/sword2/router.h b/sword2/router.h index f75d82bdba..adf6978f6f 100644 --- a/sword2/router.h +++ b/sword2/router.h @@ -20,9 +20,6 @@ #ifndef _ROUTER_H #define _ROUTER_H -#include "sword2/memory.h" -#include "sword2/object.h" - // This used to be a variable, but it was never set. Actually, it wasn't even // initialised! // @@ -31,6 +28,8 @@ // // #define FORCE_SLIDY +#include "sword2/object.h" + namespace Sword2 { #if !defined(__GNUC__) @@ -103,6 +102,8 @@ typedef struct { class Router { private: + Sword2Engine *_vm; + // stores pointers to mem blocks containing routes created & used by // megas (NULL if slot not in use) mem *_routeSlots[TOTAL_ROUTE_SLOTS]; @@ -214,9 +215,9 @@ private: void plotCross(int16 x, int16 y, uint8 colour); public: - Router() : - _nExtraBars(0), _nExtraNodes(0), _diagonalx(0), - _diagonaly(0) { + Router(Sword2Engine *vm) + : _vm(vm), _nExtraBars(0), _nExtraNodes(0), _diagonalx(0), + _diagonaly(0) { memset(_routeSlots, 0, sizeof(_routeSlots)); memset(_bars, 0, sizeof(_bars)); memset(_node, 0, sizeof(_node)); diff --git a/sword2/save_rest.cpp b/sword2/save_rest.cpp index 2c19335406..57ca7fcd32 100644 --- a/sword2/save_rest.cpp +++ b/sword2/save_rest.cpp @@ -26,21 +26,10 @@ // // --------------------------------------------------------------------------- -#include "stdafx.h" +#include "common/stdafx.h" #include "sword2/sword2.h" -#include "sword2/driver/driver96.h" -#include "sword2/console.h" #include "sword2/defs.h" -#include "sword2/interpreter.h" // for IR_CONT, etc -#include "sword2/layers.h" -#include "sword2/logic.h" -#include "sword2/memory.h" -#include "sword2/object.h" -#include "sword2/protocol.h" -#include "sword2/resman.h" -#include "sword2/router.h" -#include "sword2/save_rest.h" -#include "sword2/sound.h" +#include "sword2/interpreter.h" namespace Sword2 { @@ -105,7 +94,7 @@ uint32 Sword2Engine::saveGame(uint16 slotNo, uint8 *desc) { // allocate the savegame buffer bufferSize = findBufferSize(); - saveBufferMem = memory->allocMemory(bufferSize, MEM_locked, UID_savegame_buffer); + saveBufferMem = _memory->allocMemory(bufferSize, MEM_locked, UID_savegame_buffer); fillSaveBuffer(saveBufferMem, bufferSize, desc); @@ -116,7 +105,7 @@ uint32 Sword2Engine::saveGame(uint16 slotNo, uint8 *desc) { // free the buffer - memory->freeMemory(saveBufferMem); + _memory->freeMemory(saveBufferMem); return errorCode; } @@ -125,38 +114,38 @@ uint32 Sword2Engine::saveGame(uint16 slotNo, uint8 *desc) { uint32 Sword2Engine::findBufferSize(void) { // size of savegame header + size of global variables - return sizeof(g_header) + res_man->fetchLen(1); + return sizeof(_saveGameHeader) + _resman->fetchLen(1); } void Sword2Engine::fillSaveBuffer(mem *buffer, uint32 size, uint8 *desc) { uint8 *varsRes; - // set up the g_header + // set up the _saveGameHeader // 'checksum' gets filled in last of all // player's description of savegame - strcpy(g_header.description, (char *) desc); + strcpy(_saveGameHeader.description, (char *) desc); // length of global variables resource - g_header.varLength = res_man->fetchLen(1); + _saveGameHeader.varLength = _resman->fetchLen(1); // resource id of current screen file - g_header.screenId = _thisScreen.background_layer_id; + _saveGameHeader.screenId = _thisScreen.background_layer_id; // resource id of current run-list - g_header.runListId = _logic->getRunList(); + _saveGameHeader.runListId = _logic->getRunList(); // those scroll position control things - g_header.feet_x = _thisScreen.feet_x; - g_header.feet_y = _thisScreen.feet_y; + _saveGameHeader.feet_x = _thisScreen.feet_x; + _saveGameHeader.feet_y = _thisScreen.feet_y; // id of currently looping music (or zero) - g_header.music_id = _loopingMusicId; + _saveGameHeader.music_id = _loopingMusicId; // object hub - memcpy(&g_header.player_hub, res_man->openResource(CUR_PLAYER_ID) + sizeof(_standardHeader), sizeof(_object_hub)); - res_man->closeResource(CUR_PLAYER_ID); + memcpy(&_saveGameHeader.player_hub, _resman->openResource(CUR_PLAYER_ID) + sizeof(_standardHeader), sizeof(_object_hub)); + _resman->closeResource(CUR_PLAYER_ID); // logic, graphic & mega structures // copy the 4 essential player object structures into the header @@ -165,42 +154,42 @@ void Sword2Engine::fillSaveBuffer(mem *buffer, uint32 size, uint8 *desc) { // copy the header to the buffer #ifdef SCUMM_BIG_ENDIAN - convertHeaderEndian(g_header); + convertHeaderEndian(_saveGameHeader); #endif // copy the header to the savegame buffer - memcpy(buffer->ad, &g_header, sizeof(g_header)); + memcpy(buffer->ad, &_saveGameHeader, sizeof(_saveGameHeader)); // copy the global variables to the buffer // open variables resource - varsRes = res_man->openResource(1); + varsRes = _resman->openResource(1); // copy that to the buffer, following the header - memcpy(buffer->ad + sizeof(g_header), varsRes, FROM_LE_32(g_header.varLength)); + memcpy(buffer->ad + sizeof(_saveGameHeader), varsRes, FROM_LE_32(_saveGameHeader.varLength)); #ifdef SCUMM_BIG_ENDIAN - uint32 *globalVars = (uint32 *) (buffer->ad + sizeof(g_header) + sizeof(_standardHeader)); - const uint numVars = (FROM_LE_32(g_header.varLength) - sizeof(_standardHeader)) / 4; + uint32 *globalVars = (uint32 *) (buffer->ad + sizeof(_saveGameHeader) + sizeof(_standardHeader)); + const uint numVars = (FROM_LE_32(_saveGameHeader.varLength) - sizeof(_standardHeader)) / 4; for (uint i = 0; i < numVars; i++) globalVars[i] = SWAP_BYTES_32(globalVars[i]); #endif // close variables resource - res_man->closeResource(1); + _resman->closeResource(1); // set the checksum & copy that to the buffer - g_header.checksum = TO_LE_32(calcChecksum((buffer->ad) + sizeof(g_header.checksum), size - sizeof(g_header.checksum))); - memcpy(buffer->ad, &g_header.checksum, sizeof(g_header.checksum)); + _saveGameHeader.checksum = TO_LE_32(calcChecksum((buffer->ad) + sizeof(_saveGameHeader.checksum), size - sizeof(_saveGameHeader.checksum))); + memcpy(buffer->ad, &_saveGameHeader.checksum, sizeof(_saveGameHeader.checksum)); } uint32 Sword2Engine::saveData(uint16 slotNo, uint8 *buffer, uint32 bufferSize) { char saveFileName[MAX_FILENAME_LEN]; uint32 itemsWritten; SaveFile *out; - SaveFileManager *mgr = g_system->get_savefile_manager(); + SaveFileManager *mgr = _system->get_savefile_manager(); // construct filename sprintf(saveFileName, "%s.%.3d", _targetName, slotNo); @@ -235,7 +224,7 @@ uint32 Sword2Engine::restoreGame(uint16 slotNo) { // allocate the savegame buffer bufferSize = findBufferSize(); - saveBufferMem = memory->allocMemory(bufferSize, MEM_locked, UID_savegame_buffer); + saveBufferMem = _memory->allocMemory(bufferSize, MEM_locked, UID_savegame_buffer); // read the savegame file into our buffer @@ -253,7 +242,7 @@ uint32 Sword2Engine::restoreGame(uint16 slotNo) { // loading in the new screen & runlist } else { // because restoreFromBuffer would have freed it - memory->freeMemory(saveBufferMem); + _memory->freeMemory(saveBufferMem); } return errorCode; @@ -262,7 +251,7 @@ uint32 Sword2Engine::restoreGame(uint16 slotNo) { uint32 Sword2Engine::restoreData(uint16 slotNo, uint8 *buffer, uint32 bufferSize) { char saveFileName[MAX_FILENAME_LEN]; SaveFile *in; - SaveFileManager *mgr = g_system->get_savefile_manager(); + SaveFileManager *mgr = _system->get_savefile_manager(); uint32 itemsRead; // construct filename @@ -306,16 +295,16 @@ uint32 Sword2Engine::restoreFromBuffer(mem *buffer, uint32 size) { int32 pars[2]; // get a copy of the header from the savegame buffer - memcpy(&g_header, buffer->ad, sizeof(g_header)); + memcpy(&_saveGameHeader, buffer->ad, sizeof(_saveGameHeader)); #ifdef SCUMM_BIG_ENDIAN - convertHeaderEndian(g_header); + convertHeaderEndian(_saveGameHeader); #endif // Calc checksum & check that aginst the value stored in the header - if (g_header.checksum != calcChecksum(buffer->ad + sizeof(g_header.checksum), size - sizeof(g_header.checksum))) { - memory->freeMemory(buffer); + if (_saveGameHeader.checksum != calcChecksum(buffer->ad + sizeof(_saveGameHeader.checksum), size - sizeof(_saveGameHeader.checksum))) { + _memory->freeMemory(buffer); // error: incompatible save-data - can't use! return SR_ERR_INCOMPATIBLE; @@ -329,8 +318,8 @@ uint32 Sword2Engine::restoreFromBuffer(mem *buffer, uint32 size) { // shorter than the current expected length // if header contradicts actual current size of global variables - if (g_header.varLength != res_man->fetchLen(1)) { - memory->freeMemory(buffer); + if (_saveGameHeader.varLength != _resman->fetchLen(1)) { + _memory->freeMemory(buffer); // error: incompatible save-data - can't use! return SR_ERR_INCOMPATIBLE; @@ -340,7 +329,7 @@ uint32 Sword2Engine::restoreFromBuffer(mem *buffer, uint32 size) { // trash all resources from memory except player object & global // variables - res_man->killAll(false); + _resman->killAll(false); // clean out the system kill list (no more objects to kill) _logic->resetKillList(); @@ -348,9 +337,9 @@ uint32 Sword2Engine::restoreFromBuffer(mem *buffer, uint32 size) { // get player character data from savegame buffer // object hub is just after the standard header - memcpy(res_man->openResource(CUR_PLAYER_ID) + sizeof(_standardHeader), &g_header.player_hub, sizeof(_object_hub)); + memcpy(_resman->openResource(CUR_PLAYER_ID) + sizeof(_standardHeader), &_saveGameHeader.player_hub, sizeof(_object_hub)); - res_man->closeResource(CUR_PLAYER_ID); + _resman->closeResource(CUR_PLAYER_ID); // fill in the 4 essential player object structures from the header putPlayerStructures(); @@ -358,27 +347,27 @@ uint32 Sword2Engine::restoreFromBuffer(mem *buffer, uint32 size) { // get variables resource from the savegame buffer // open variables resource - varsRes = res_man->openResource(1); + varsRes = _resman->openResource(1); // copy that to the buffer, following the header - memcpy(varsRes, buffer->ad + sizeof(g_header), g_header.varLength ); + memcpy(varsRes, buffer->ad + sizeof(_saveGameHeader), _saveGameHeader.varLength ); #ifdef SCUMM_BIG_ENDIAN uint32 *globalVars = (uint32 *) (varsRes + sizeof(_standardHeader)); - const uint numVars = (g_header.varLength - sizeof(_standardHeader)) / 4; + const uint numVars = (_saveGameHeader.varLength - sizeof(_standardHeader)) / 4; for (uint i = 0; i < numVars; i++) globalVars[i] = SWAP_BYTES_32(globalVars[i]); #endif // close variables resource - res_man->closeResource(1); + _resman->closeResource(1); // free it now, rather than in RestoreGame, to unblock memory before // new screen & runlist loaded - memory->freeMemory(buffer); + _memory->freeMemory(buffer); - pars[0] = g_header.screenId; + pars[0] = _saveGameHeader.screenId; pars[1] = 1; _logic->fnInitBackground(pars); @@ -389,11 +378,11 @@ uint32 Sword2Engine::restoreFromBuffer(mem *buffer, uint32 size) { // these need setting after the defaults get set in fnInitBackground // remember that these can change through the game, so need saving & // restoring too - _thisScreen.feet_x = g_header.feet_x; - _thisScreen.feet_y = g_header.feet_y; + _thisScreen.feet_x = _saveGameHeader.feet_x; + _thisScreen.feet_y = _saveGameHeader.feet_y; // start the new run list - _logic->expressChangeSession(g_header.runListId); + _logic->expressChangeSession(_saveGameHeader.runListId); // Force in the new scroll position, so unsightly scroll-catch-up does // not occur when screen first draws after returning from restore panel @@ -401,8 +390,8 @@ uint32 Sword2Engine::restoreFromBuffer(mem *buffer, uint32 size) { // set '_thisScreen's record of player position // - ready for setScrolling() - _thisScreen.player_feet_x = g_header.mega.feet_x; - _thisScreen.player_feet_y = g_header.mega.feet_y; + _thisScreen.player_feet_x = _saveGameHeader.mega.feet_x; + _thisScreen.player_feet_y = _saveGameHeader.mega.feet_y; // if this screen is wide, recompute the scroll offsets now if (_thisScreen.scroll_flag) @@ -411,11 +400,11 @@ uint32 Sword2Engine::restoreFromBuffer(mem *buffer, uint32 size) { // Any music required will be started after we've returned from // Restore_control() - see System_menu() in mouse.cpp! - _loopingMusicId = g_header.music_id; + _loopingMusicId = _saveGameHeader.music_id; // Write to walkthrough file (zebug0.txt) - debug(5, "RESTORED GAME \"%s\"", g_header.description); + debug(5, "RESTORED GAME \"%s\"", _saveGameHeader.description); // game restored ok return SR_OK; @@ -425,9 +414,9 @@ uint32 Sword2Engine::restoreFromBuffer(mem *buffer, uint32 size) { uint32 Sword2Engine::getSaveDescription(uint16 slotNo, uint8 *description) { char saveFileName[MAX_FILENAME_LEN]; - _savegameHeader dummy; + SaveGameHeader dummy; SaveFile *in; - SaveFileManager *mgr = g_system->get_savefile_manager(); + SaveFileManager *mgr = _system->get_savefile_manager(); // construct filename sprintf(saveFileName, "%s.%.3d", _targetName, slotNo); @@ -439,7 +428,7 @@ uint32 Sword2Engine::getSaveDescription(uint16 slotNo, uint8 *description) { } // read header - in->read(&dummy, sizeof(_savegameHeader)); + in->read(&dummy, sizeof(dummy)); delete in; delete mgr; @@ -449,7 +438,7 @@ uint32 Sword2Engine::getSaveDescription(uint16 slotNo, uint8 *description) { bool Sword2Engine::saveExists(uint16 slotNo) { char saveFileName[MAX_FILENAME_LEN]; - SaveFileManager *mgr = g_system->get_savefile_manager(); + SaveFileManager *mgr = _system->get_savefile_manager(); SaveFile *in; // construct filename @@ -475,14 +464,14 @@ void Sword2Engine::getPlayerStructures(void) { char *raw_script_ad; _standardHeader *head; - head = (_standardHeader*) res_man->openResource(CUR_PLAYER_ID); + head = (_standardHeader*) _resman->openResource(CUR_PLAYER_ID); if (head->fileType != GAME_OBJECT) error("incorrect CUR_PLAYER_ID=%d", CUR_PLAYER_ID); raw_script_ad = (char *) head; _logic->runScript(raw_script_ad, raw_script_ad, &null_pc); - res_man->closeResource(CUR_PLAYER_ID); + _resman->closeResource(CUR_PLAYER_ID); } void Sword2Engine::putPlayerStructures(void) { @@ -494,7 +483,7 @@ void Sword2Engine::putPlayerStructures(void) { char *raw_script_ad; _standardHeader *head; - head = (_standardHeader*) res_man->openResource(CUR_PLAYER_ID); + head = (_standardHeader*) _resman->openResource(CUR_PLAYER_ID); if (head->fileType != GAME_OBJECT) error("incorrect CUR_PLAYER_ID=%d", CUR_PLAYER_ID); @@ -513,7 +502,7 @@ void Sword2Engine::putPlayerStructures(void) { // which megaset was the player at the time of saving? - switch (g_header.mega.megaset_res) { + switch (_saveGameHeader.mega.megaset_res) { case 36: // GeoMega: null_pc = 9; // script no.9 - 'player_is_george' break; @@ -532,7 +521,7 @@ void Sword2Engine::putPlayerStructures(void) { } _logic->runScript(raw_script_ad, raw_script_ad, &null_pc); - res_man->closeResource(CUR_PLAYER_ID); + _resman->closeResource(CUR_PLAYER_ID); } uint32 Sword2Engine::calcChecksum(uint8 *buffer, uint32 size) { @@ -557,9 +546,9 @@ int32 Logic::fnPassPlayerSaveData(int32 *params) { // copy from player object to savegame header - memcpy(&_vm->g_header.logic, memory->intToPtr(params[0]), sizeof(Object_logic)); - memcpy(&_vm->g_header.graphic, memory->intToPtr(params[1]), sizeof(Object_graphic)); - memcpy(&_vm->g_header.mega, memory->intToPtr(params[2]), sizeof(Object_mega)); + memcpy(&_vm->_saveGameHeader.logic, _vm->_memory->intToPtr(params[0]), sizeof(Object_logic)); + memcpy(&_vm->_saveGameHeader.graphic, _vm->_memory->intToPtr(params[1]), sizeof(Object_graphic)); + memcpy(&_vm->_saveGameHeader.mega, _vm->_memory->intToPtr(params[2]), sizeof(Object_mega)); // makes no odds return IR_CONT; @@ -573,17 +562,17 @@ int32 Logic::fnGetPlayerSaveData(int32 *params) { // 1 pointer to object's graphic structure // 2 pointer to object's mega structure - Object_logic *ob_logic = (Object_logic *) memory->intToPtr(params[0]); - Object_graphic *ob_graphic = (Object_graphic *) memory->intToPtr(params[1]); - Object_mega *ob_mega = (Object_mega *) memory->intToPtr(params[2]); + Object_logic *ob_logic = (Object_logic *) _vm->_memory->intToPtr(params[0]); + Object_graphic *ob_graphic = (Object_graphic *) _vm->_memory->intToPtr(params[1]); + Object_mega *ob_mega = (Object_mega *) _vm->_memory->intToPtr(params[2]); int32 pars[3]; // copy from savegame header to player object - memcpy((uint8 *) ob_logic, &_vm->g_header.logic, sizeof(Object_logic)); - memcpy((uint8 *) ob_graphic, &_vm->g_header.graphic, sizeof(Object_graphic)); - memcpy((uint8 *) ob_mega, &_vm->g_header.mega, sizeof(Object_mega)); + memcpy((uint8 *) ob_logic, &_vm->_saveGameHeader.logic, sizeof(Object_logic)); + memcpy((uint8 *) ob_graphic, &_vm->_saveGameHeader.graphic, sizeof(Object_graphic)); + memcpy((uint8 *) ob_mega, &_vm->_saveGameHeader.mega, sizeof(Object_mega)); // any walk-data must be cleared - the player will be set to stand if // he was walking when saved diff --git a/sword2/scroll.cpp b/sword2/scroll.cpp index 4caf606f7d..e030ee59ce 100644 --- a/sword2/scroll.cpp +++ b/sword2/scroll.cpp @@ -17,15 +17,10 @@ * $Header$ */ -#include "stdafx.h" +#include "common/stdafx.h" #include "sword2/sword2.h" -#include "sword2/driver/driver96.h" -#include "sword2/debug.h" #include "sword2/defs.h" -#include "sword2/header.h" #include "sword2/interpreter.h" -#include "sword2/layers.h" -#include "sword2/logic.h" namespace Sword2 { diff --git a/sword2/sound.cpp b/sword2/sound.cpp index 04fcca7696..195b2b2176 100644 --- a/sword2/sound.cpp +++ b/sword2/sound.cpp @@ -27,16 +27,11 @@ // // --------------------------------------------------------------------------- -#include "stdafx.h" +#include "common/stdafx.h" +#include "common/file.h" #include "sword2/sword2.h" -#include "sword2/console.h" -#include "sword2/defs.h" // for RESULT +#include "sword2/defs.h" #include "sword2/interpreter.h" -#include "sword2/logic.h" -#include "sword2/protocol.h" // for fetchObjectName() for debugging fnPlayFx -#include "sword2/resman.h" -#include "sword2/sound.h" -#include "sword2/sword2.h" namespace Sword2 { @@ -72,7 +67,7 @@ void Sword2Engine::processFxQueue(void) { break; case FX_SPOT2: // Once the Fx has finished remove it from the queue. - if (g_sound->isFxOpen(i + 1)) + if (_sound->isFxOpen(i + 1)) _fxQueue[i].resource = 0; break; } @@ -90,12 +85,12 @@ void Sword2Engine::triggerFx(uint8 j) { if (_fxQueue[j].type == FX_SPOT) { // load in the sample - data = res_man->openResource(_fxQueue[j].resource); + data = _resman->openResource(_fxQueue[j].resource); data += sizeof(_standardHeader); // wav data gets copied to sound memory - rv = g_sound->playFx(id, data, _fxQueue[j].volume, _fxQueue[j].pan, RDSE_FXSPOT); + rv = _sound->playFx(id, data, _fxQueue[j].volume, _fxQueue[j].pan, RDSE_FXSPOT); // release the sample - res_man->closeResource(_fxQueue[j].resource); + _resman->closeResource(_fxQueue[j].resource); } else { // random & looped fx are already loaded into sound memory // by fnPlayFx() @@ -103,10 +98,10 @@ void Sword2Engine::triggerFx(uint8 j) { if (_fxQueue[j].type == FX_RANDOM) { // Not looped - rv = g_sound->playFx(id, NULL, _fxQueue[j].volume, _fxQueue[j].pan, RDSE_FXSPOT); + rv = _sound->playFx(id, NULL, _fxQueue[j].volume, _fxQueue[j].pan, RDSE_FXSPOT); } else { // Looped - rv = g_sound->playFx(id, NULL, _fxQueue[j].volume, _fxQueue[j].pan, RDSE_FXLOOP); + rv = _sound->playFx(id, NULL, _fxQueue[j].volume, _fxQueue[j].pan, RDSE_FXLOOP); } } @@ -118,7 +113,7 @@ void Sword2Engine::triggerFx(uint8 j) { void Sword2Engine::clearFxQueue(void) { // stop all fx & remove the samples from sound memory - g_sound->clearAllFx(); + _sound->clearAllFx(); // clean out the queue initFxQueue(); @@ -126,19 +121,19 @@ void Sword2Engine::clearFxQueue(void) { void Sword2Engine::killMusic(void) { _loopingMusicId = 0; // clear the 'looping' flag - g_sound->stopMusic(); + _sound->stopMusic(); } void Sword2Engine::pauseAllSound(void) { - g_sound->pauseMusic(); - g_sound->pauseSpeech(); - g_sound->pauseFx(); + _sound->pauseMusic(); + _sound->pauseSpeech(); + _sound->pauseFx(); } void Sword2Engine::unpauseAllSound(void) { - g_sound->unpauseMusic(); - g_sound->unpauseSpeech(); - g_sound->unpauseFx(); + _sound->unpauseMusic(); + _sound->unpauseSpeech(); + _sound->unpauseFx(); } // called from script only @@ -212,26 +207,26 @@ int32 Logic::fnPlayFx(int32 *params) { if (_vm->_fxQueue[j].type == FX_SPOT) { // "pre-load" the sample; this gets it into memory - data = res_man->openResource(_vm->_fxQueue[j].resource); + data = _vm->_resman->openResource(_vm->_fxQueue[j].resource); #ifdef _SWORD2_DEBUG - header = (_standardHeader*) data; + header = (_standardHeader *) data; if (header->fileType != WAV_FILE) error("fnPlayFx given invalid resource"); #endif // but then releases it to "age" out if the space is needed - res_man->closeResource(_vm->_fxQueue[j].resource); + _vm->_resman->closeResource(_vm->_fxQueue[j].resource); } else { // random & looped fx id = (uint32) j + 1; // because 0 is not a valid id // load in the sample - data = res_man->openResource(_vm->_fxQueue[j].resource); + data = _vm->_resman->openResource(_vm->_fxQueue[j].resource); #ifdef _SWORD2_DEBUG - header = (_standardHeader*)data; + header = (_standardHeader *) data; if (header->fileType != WAV_FILE) error("fnPlayFx given invalid resource"); #endif @@ -239,13 +234,13 @@ int32 Logic::fnPlayFx(int32 *params) { data += sizeof(_standardHeader); // copy it to sound memory, using position in queue as 'id' - rv = g_sound->openFx(id, data); + rv = _vm->_sound->openFx(id, data); if (rv) debug(5, "SFX ERROR: openFx() returned %.8x", rv); // release the sample - res_man->closeResource(_vm->_fxQueue[j].resource); + _vm->_resman->closeResource(_vm->_fxQueue[j].resource); } if (_vm->_fxQueue[j].type == FX_LOOP) { @@ -278,7 +273,7 @@ int32 Logic::fnSetFxVolAndPan(int32 *params) { // setFxIdVolumePan(int32 id, uint8 vol, uint8 pan); // driver fx_id is 1 + <pos in queue> - g_sound->setFxIdVolumePan(1 + params[0], params[1], params[2]); + _vm->_sound->setFxIdVolumePan(1 + params[0], params[1], params[2]); return IR_CONT; } @@ -290,7 +285,7 @@ int32 Logic::fnSetFxVol(int32 *params) { // 1 new volume (0..16) // SetFxIdVolume(int32 id, uint8 vol); - g_sound->setFxIdVolume(1 + params[0], params[1]); + _vm->_sound->setFxIdVolume(1 + params[0], params[1]); return IR_CONT; } @@ -311,7 +306,7 @@ int32 Logic::fnStopFx(int32 *params) { id = (uint32) j + 1; // because 0 is not a valid id // stop fx & remove sample from sound memory - rv = g_sound->closeFx(id); + rv = _vm->_sound->closeFx(id); if (rv) debug(5, "SFX ERROR: closeFx() returned %.8x", rv); @@ -374,14 +369,14 @@ int32 Logic::fnPlayMusic(int32 *params) { } else { File f; - sprintf(filename, "music%d.clu", res_man->whichCd()); + sprintf(filename, "music%d.clu", _vm->_resman->whichCd()); if (f.open(filename)) f.close(); else strcpy(filename, "music.clu"); } - rv = g_sound->streamCompMusic(filename, params[0], loopFlag); + rv = _vm->_sound->streamCompMusic(filename, params[0], loopFlag); if (rv) debug(5, "ERROR: streamCompMusic(%s, %d, %d) returned error 0x%.8x", filename, params[0], loopFlag, rv); @@ -395,7 +390,7 @@ int32 Logic::fnStopMusic(int32 *params) { // params: none _vm->_loopingMusicId = 0; // clear the 'looping' flag - g_sound->stopMusic(); + _vm->_sound->stopMusic(); return IR_CONT; } @@ -406,7 +401,7 @@ int32 Logic::fnCheckMusicPlaying(int32 *params) { // or 0 if no music playing // in seconds, rounded up to the nearest second - RESULT = g_sound->musicTimeRemaining(); + RESULT = _vm->_sound->musicTimeRemaining(); return IR_CONT; } diff --git a/sword2/speech.cpp b/sword2/speech.cpp index f81c31f4a1..2c1999bc81 100644 --- a/sword2/speech.cpp +++ b/sword2/speech.cpp @@ -17,23 +17,11 @@ * $Header$ */ -#include "stdafx.h" +#include "common/stdafx.h" +#include "common/file.h" #include "sword2/sword2.h" -#include "sword2/console.h" -#include "sword2/controls.h" // for 'subtitles' & 'speechSelected' -#include "sword2/debug.h" #include "sword2/defs.h" #include "sword2/interpreter.h" -#include "sword2/layers.h" // for 'this_screen' -#include "sword2/logic.h" -#include "sword2/maketext.h" -#include "sword2/memory.h" -#include "sword2/mouse.h" -#include "sword2/object.h" -#include "sword2/protocol.h" -#include "sword2/resman.h" -#include "sword2/sound.h" -#include "sword2/speech.h" namespace Sword2 { @@ -171,18 +159,18 @@ int32 Logic::fnChoose(int32 *params) { for (j = 0; j < 15; j++) { 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_graphics->setMenuIcon(RDMENU_BOTTOM, (uint8) j, icon); - res_man->closeResource(_subjectList[j].res); + icon = _vm->_resman->openResource(_subjectList[j].res) + sizeof(_standardHeader) + RDMENU_ICONWIDE * RDMENU_ICONDEEP; + _vm->_graphics->setMenuIcon(RDMENU_BOTTOM, (uint8) j, icon); + _vm->_resman->closeResource(_subjectList[j].res); } else { //no icon here debug(5, " NULL for %d", j); - g_graphics->setMenuIcon(RDMENU_BOTTOM, (uint8) j, NULL); + _vm->_graphics->setMenuIcon(RDMENU_BOTTOM, (uint8) j, NULL); } } // start menus appearing - g_graphics->showMenu(RDMENU_BOTTOM); + _vm->_graphics->showMenu(RDMENU_BOTTOM); // lets have the mouse pointer back _vm->setMouse(NORMAL_MOUSE_ID); @@ -195,7 +183,7 @@ int32 Logic::fnChoose(int32 *params) { // menu is there - we're just waiting for a click debug(5, "choosing"); - me = g_input->mouseEvent(); + me = _vm->_input->mouseEvent(); // we only care about left clicks // we ignore mouse releases @@ -205,9 +193,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_input->_mouseY > 399 && g_input->_mouseX >= 24 && g_input->_mouseX < 640 - 24) { + if (_vm->_input->_mouseY > 399 && _vm->_input->_mouseX >= 24 && _vm->_input->_mouseX < 640 - 24) { //which are we over? - hit = (g_input->_mouseX - 24) / 40; + hit = (_vm->_input->_mouseX - 24) / 40; //clicked on something - what button? if (hit < IN_SUBJECT) { @@ -219,9 +207,9 @@ int32 Logic::fnChoose(int32 *params) { // change all others to grey if (j != hit) { - icon = res_man->openResource( _subjectList[j].res ) + sizeof(_standardHeader); - g_graphics->setMenuIcon(RDMENU_BOTTOM, (uint8) j, icon); - res_man->closeResource(_subjectList[j].res); + icon = _vm->_resman->openResource( _subjectList[j].res ) + sizeof(_standardHeader); + _vm->_graphics->setMenuIcon(RDMENU_BOTTOM, (uint8) j, icon); + _vm->_resman->closeResource(_subjectList[j].res); } } @@ -279,9 +267,9 @@ int32 Logic::fnEndConversation(int32 *params) { // params: none - g_graphics->hideMenu(RDMENU_BOTTOM); + _vm->_graphics->hideMenu(RDMENU_BOTTOM); - if (g_input->_mouseY > 399) { + if (_vm->_input->_mouseY > 399) { // will wait for cursor to move off the bottom menu _vm->_mouseMode = MOUSE_holding; debug(5, " holding"); @@ -290,7 +278,7 @@ int32 Logic::fnEndConversation(int32 *params) { TALK_FLAG = 0; // in-case DC forgets // restart george's base script - // LLogic.totalRestart(); + // totalRestart(); //drop out without saving pc and go around again return IR_CONT; @@ -314,7 +302,7 @@ int32 Logic::fnTheyDo(int32 *params) { int32 target = params[0]; // request status of target - head = (_standardHeader*) res_man->openResource(target); + head = (_standardHeader *) _vm->_resman->openResource(target); if (head->fileType != GAME_OBJECT) error("fnTheyDo %d not an object", target); @@ -323,7 +311,7 @@ int32 Logic::fnTheyDo(int32 *params) { // call the base script - this is the graphic/mouse service call runScript(raw_script_ad, raw_script_ad, &null_pc); - res_man->closeResource(target); + _vm->_resman->closeResource(target); // result is 1 for waiting, 0 for busy @@ -376,7 +364,7 @@ int32 Logic::fnTheyDoWeWait(int32 *params) { // ok, see if the target is busy - we must request this info from the // target object - head = (_standardHeader*) res_man->openResource(target); + head = (_standardHeader *) _vm->_resman->openResource(target); if (head->fileType != GAME_OBJECT) error("fnTheyDoWeWait %d not an object", target); @@ -385,9 +373,9 @@ int32 Logic::fnTheyDoWeWait(int32 *params) { // call the base script - this is the graphic/mouse service call runScript(raw_script_ad, raw_script_ad, &null_pc); - res_man->closeResource(target); + _vm->_resman->closeResource(target); - ob_logic = (Object_logic *) memory->intToPtr(params[0]); + ob_logic = (Object_logic *) _vm->_memory->intToPtr(params[0]); if (!INS_COMMAND && RESULT == 1 && ob_logic->looping == 0) { // first time so set up targets command if target is waiting @@ -456,7 +444,7 @@ int32 Logic::fnWeWait(int32 *params) { int32 target = params[0]; // request status of target - head = (_standardHeader*) res_man->openResource(target); + head = (_standardHeader *) _vm->_resman->openResource(target); if (head->fileType != GAME_OBJECT) error("fnWeWait: %d not an object", target); @@ -465,7 +453,7 @@ int32 Logic::fnWeWait(int32 *params) { // call the base script - this is the graphic/mouse service call runScript(raw_script_ad, raw_script_ad, &null_pc); - res_man->closeResource(target); + _vm->_resman->closeResource(target); // result is 1 for waiting, 0 for busy @@ -498,13 +486,13 @@ int32 Logic::fnTimedWait(int32 *params) { _standardHeader *head; int32 target = params[1]; - ob_logic = (Object_logic *) memory->intToPtr(params[0]); + ob_logic = (Object_logic *) _vm->_memory->intToPtr(params[0]); if (!ob_logic->looping) ob_logic->looping = params[2]; // first time in // request status of target - head = (_standardHeader*) res_man->openResource(target); + head = (_standardHeader *) _vm->_resman->openResource(target); if (head->fileType != GAME_OBJECT) error("fnTimedWait %d not an object", target); @@ -513,7 +501,7 @@ int32 Logic::fnTimedWait(int32 *params) { // call the base script - this is the graphic/mouse service call runScript(raw_script_ad, raw_script_ad, &null_pc); - res_man->closeResource(target); + _vm->_resman->closeResource(target); // result is 1 for waiting, 0 for busy @@ -580,7 +568,7 @@ int32 Logic::fnSpeechProcess(int32 *params) { int32 pars[9]; int32 ret; - ob_speech = (Object_speech *) memory->intToPtr(params[1]); + ob_speech = (Object_speech *) _vm->_memory->intToPtr(params[1]); debug(5, " SP"); @@ -896,8 +884,8 @@ int32 Logic::fnISpeak(int32 *params) { // set up the pointers which we know we'll always need - ob_logic = (Object_logic *) memory->intToPtr(params[S_OB_LOGIC]); - ob_graphic = (Object_graphic *) memory->intToPtr(params[S_OB_GRAPHIC]); + ob_logic = (Object_logic *) _vm->_memory->intToPtr(params[S_OB_LOGIC]); + ob_graphic = (Object_graphic *) _vm->_memory->intToPtr(params[S_OB_GRAPHIC]); // FIRST TIME ONLY: create the text, load the wav, set up the anim, // etc. @@ -906,7 +894,7 @@ int32 Logic::fnISpeak(int32 *params) { // New fudge to wait for smacker samples to finish // since they can over-run into the game - if (g_sound->getSpeechStatus() != RDSE_SAMPLEFINISHED) + if (_vm->_sound->getSpeechStatus() != RDSE_SAMPLEFINISHED) return IR_REPEAT; // New fudge for 'fx' subtitles @@ -914,7 +902,7 @@ int32 Logic::fnISpeak(int32 *params) { // for this line either, then just quit back to script right // now! - if (gui->_subtitles == 0 && wantSpeechForLine(params[S_WAV]) == 0) + if (_vm->_gui->_subtitles == 0 && wantSpeechForLine(params[S_WAV]) == 0) return IR_CONT; if (cycle_skip == 0) { @@ -947,14 +935,14 @@ int32 Logic::fnISpeak(int32 *params) { // if the resource number is within range & it's not // a null resource - if (res_man->checkValid(text_res)) { + if (_vm->_resman->checkValid(text_res)) { // open the resource - head = (_standardHeader*) res_man->openResource(text_res); + head = (_standardHeader *) _vm->_resman->openResource(text_res); if (head->fileType == TEXT_FILE) { // if it's not an animation file // if line number is out of range - if (_vm->checkTextLine((uint8*) head, local_text) == 0) { + if (_vm->checkTextLine((uint8 *) head, local_text) == 0) { // line number out of range RESULT = 2; } @@ -964,7 +952,7 @@ int32 Logic::fnISpeak(int32 *params) { } // close the resource - res_man->closeResource(text_res); + _vm->_resman->closeResource(text_res); if (RESULT) return IR_CONT; @@ -984,11 +972,11 @@ int32 Logic::fnISpeak(int32 *params) { local_text = params[S_TEXT] & 0xffff; // open text file & get the line - text = _vm->fetchTextLine(res_man->openResource(text_res), local_text); + text = _vm->fetchTextLine(_vm->_resman->openResource(text_res), local_text); _officialTextNumber = READ_LE_UINT16(text); // now ok to close the text file - res_man->closeResource(text_res); + _vm->_resman->closeResource(text_res); // prevent dud lines from appearing while testing text & speech // since these will not occur in the game anyway @@ -1039,10 +1027,10 @@ int32 Logic::fnISpeak(int32 *params) { // use this direction table to derive the anim // NB. ASSUMES WE HAVE A MEGA OBJECT!! - ob_mega = (Object_mega *) memory->intToPtr(params[S_OB_MEGA]); + ob_mega = (Object_mega *) _vm->_memory->intToPtr(params[S_OB_MEGA]); // pointer to anim table - anim_table = (int32 *) memory->intToPtr(params[S_DIR_TABLE]); + anim_table = (int32 *) _vm->_memory->intToPtr(params[S_DIR_TABLE]); // appropriate anim resource is in 'table[direction]' _animId = anim_table[ob_mega->current_dir]; @@ -1077,7 +1065,7 @@ int32 Logic::fnISpeak(int32 *params) { // if speech is selected, and this line is allowed speech // (not if it's an fx subtitle!) - if (!g_sound->isSpeechMute() && wantSpeechForLine(_officialTextNumber)) { + if (!_vm->_sound->isSpeechMute() && wantSpeechForLine(_officialTextNumber)) { // if the wavId paramter is zero because not yet // compiled into speech command, we can still get it // from the 1st 2 chars of the text line @@ -1111,7 +1099,7 @@ int32 Logic::fnISpeak(int32 *params) { if (text_res != currentTextResource && params[S_WAV]) { // ensure correct CD is in for this // wavId - // GetCorrectCdForSpeech(params[S_WAV]); + // getCorrectCdForSpeech(params[S_WAV]); currentTextResource = text_res; } } @@ -1123,7 +1111,7 @@ int32 Logic::fnISpeak(int32 *params) { File fp; - sprintf(speechFile, "speech%d.clu", res_man->whichCd()); + sprintf(speechFile, "speech%d.clu", _vm->_resman->whichCd()); if (fp.open(speechFile)) fp.close(); @@ -1131,7 +1119,7 @@ int32 Logic::fnISpeak(int32 *params) { strcpy(speechFile, "speech.clu"); // Load speech but don't start playing yet - rv = g_sound->playCompSpeech(speechFile, params[S_WAV], SPEECH_VOLUME, speech_pan); + rv = _vm->_sound->playCompSpeech(speechFile, params[S_WAV], SPEECH_VOLUME, speech_pan); if (rv == RD_OK) { // ok, we've got something to play // (2 means not playing yet - see below) @@ -1139,14 +1127,14 @@ int32 Logic::fnISpeak(int32 *params) { // set it playing now (we might want to do // this next cycle, don't know yet) - g_sound->unpauseSpeech(); + _vm->_sound->unpauseSpeech(); } else { debug(5, "ERROR: PlayCompSpeech(speechFile=\"%s\", wav=%d (res=%d pos=%d)) returned %.8x", speechFile, params[S_WAV], text_res, local_text, rv); } } // if we want subtitles, or speech failed to load - if (gui->_subtitles || speechRunning == 0) { + if (_vm->_gui->_subtitles || speechRunning == 0) { // then we're going to show the text textRunning = 1; @@ -1166,7 +1154,7 @@ int32 Logic::fnISpeak(int32 *params) { ob_graphic->anim_pc++; // open the anim file - anim_file = res_man->openResource(ob_graphic->anim_resource); + anim_file = _vm->_resman->openResource(ob_graphic->anim_resource); anim_head = _vm->fetchAnimHeader(anim_file); if (!_speechAnimType) { @@ -1179,7 +1167,7 @@ int32 Logic::fnISpeak(int32 *params) { // if playing a sample if (!_unpauseZone) { // if we're at a quiet bit - if (g_sound->amISpeaking() == RDSE_QUIET) { + if (_vm->_sound->amISpeaking() == RDSE_QUIET) { // restart from frame 0 // ('closed mouth' frame) ob_graphic->anim_pc = 0; @@ -1196,7 +1184,7 @@ int32 Logic::fnISpeak(int32 *params) { } // close the anim file - res_man->closeResource(ob_graphic->anim_resource); + _vm->_resman->closeResource(ob_graphic->anim_resource); } else if (_speechAnimType) { // Placed here so we actually display the last frame of the // anim. @@ -1212,7 +1200,7 @@ int32 Logic::fnISpeak(int32 *params) { if (speechRunning == 1) { if (!_unpauseZone) { // has it finished? - if (g_sound->getSpeechStatus() == RDSE_SAMPLEFINISHED) + if (_vm->_sound->getSpeechStatus() == RDSE_SAMPLEFINISHED) speechFinished = 1; } else _unpauseZone--; @@ -1233,8 +1221,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_input->_mouseY > 0) { - me = g_input->mouseEvent(); + if (SYSTEM_TESTING_TEXT == 0 || _vm->_input->_mouseY > 0) { + me = _vm->_input->mouseEvent(); // Note that we now have TWO click-delays - one for LEFT // button, one for RIGHT BUTTON @@ -1258,7 +1246,7 @@ int32 Logic::fnISpeak(int32 *params) { do { // trash anything thats buffered - me = g_input->mouseEvent(); + me = _vm->_input->mouseEvent(); } while (me); speechFinished = 1; @@ -1266,7 +1254,7 @@ int32 Logic::fnISpeak(int32 *params) { // if speech sample playing if (speechRunning) { // halt the sample prematurely - g_sound->stopSpeech(); + _vm->_sound->stopSpeech(); } } } @@ -1280,7 +1268,7 @@ int32 Logic::fnISpeak(int32 *params) { // if there is text if (_speechTextBlocNo) { // kill the text block - fontRenderer->killTextBloc(_speechTextBlocNo); + _vm->_fontRenderer->killTextBloc(_speechTextBlocNo); _speechTextBlocNo = 0; } @@ -1358,7 +1346,7 @@ void Logic::locateTalker(int32 *params) { // build_display.cpp // open animation file & set up the necessary pointers - file = res_man->openResource(_animId); + file = _vm->_resman->openResource(_animId); anim_head = _vm->fetchAnimHeader(file); @@ -1373,7 +1361,7 @@ void Logic::locateTalker(int32 *params) { if (cdt_entry->frameType & FRAME_OFFSET) { // this may be NULL - ob_mega = (Object_mega *) memory->intToPtr(params[S_OB_MEGA]); + ob_mega = (Object_mega *) _vm->_memory->intToPtr(params[S_OB_MEGA]); // calc scale at which to print the sprite, based on // feet y-coord & scaling constants (NB. 'scale' is @@ -1410,7 +1398,7 @@ void Logic::locateTalker(int32 *params) { _textY -= _vm->_thisScreen.scroll_offset_y; // release the anim resource - res_man->closeResource(_animId); + _vm->_resman->closeResource(_animId); } } @@ -1446,7 +1434,7 @@ void Logic::formText(int32 *params) { // text if (params[S_TEXT]) { - ob_speech = (Object_speech *) memory->intToPtr(params[S_OB_SPEECH]); + ob_speech = (Object_speech *) _vm->_memory->intToPtr(params[S_OB_SPEECH]); // establish the max width allowed for this text sprite @@ -1464,19 +1452,19 @@ void Logic::formText(int32 *params) { local_text = params[S_TEXT] & 0xffff; // open text file & get the line - text = _vm->fetchTextLine(res_man->openResource(text_res), local_text); + text = _vm->fetchTextLine(_vm->_resman->openResource(text_res), local_text); // 'text + 2' to skip the first 2 bytes which form the line // reference number - _speechTextBlocNo = fontRenderer->buildNewBloc( + _speechTextBlocNo = _vm->_fontRenderer->buildNewBloc( text + 2, _textX, _textY, textWidth, ob_speech->pen, RDSPR_TRANS | RDSPR_DISPLAYALIGN, _vm->_speechFontId, POSITION_AT_CENTRE_OF_BASE); // now ok to close the text file - res_man->closeResource(text_res); + _vm->_resman->closeResource(text_res); // set speech duration, in case not using wav // no. of cycles = (no. of chars) + 30 @@ -1506,7 +1494,7 @@ void Logic::getCorrectCdForSpeech(int32 wavId) { // if we specifically need CD1 or CD2 (ie. it's not on both) // then check it's there (& ask for it if it's not there) if (cd == 1 || cd == 2) - res_man->getCd(cd); + _vm->_resman->getCd(cd); } #endif diff --git a/sword2/startup.cpp b/sword2/startup.cpp index c215e6cab4..d8ccd12089 100644 --- a/sword2/startup.cpp +++ b/sword2/startup.cpp @@ -17,24 +17,8 @@ * $Header$ */ -#include "stdafx.h" -#include "sword2/sword2.h" // for CloseGame() -#include "sword2/build_display.h" -#include "sword2/console.h" -#include "sword2/debug.h" -#include "sword2/defs.h" -#include "sword2/header.h" -#include "sword2/interpreter.h" -#include "sword2/logic.h" -#include "sword2/maketext.h" // for Kill_text_bloc() -#include "sword2/memory.h" -#include "sword2/mouse.h" -#include "sword2/object.h" -#include "sword2/resman.h" -#include "sword2/router.h" -#include "sword2/sound.h" -#include "sword2/speech.h" // for '_speechTextBlocNo' - so that speech text can be cleared when running a new start-script -#include "sword2/startup.h" +#include "common/stdafx.h" +#include "sword2/sword2.h" namespace Sword2 { @@ -117,17 +101,17 @@ uint32 Logic::initStartMenu(void) { // - need to check in case un-built sections included in // start list - if (res_man->checkValid(_startRes)) { + if (_vm->_resman->checkValid(_startRes)) { debug(5, "- resource %d ok", _startRes); - raw_script = (char *) res_man->openResource(_startRes); + raw_script = (char *) _vm->_resman->openResource(_startRes); null_pc = 0; runScript(raw_script, raw_script, &null_pc); - res_man->closeResource(_startRes); + _vm->_resman->closeResource(_startRes); } else debug(5, "- resource %d invalid", _startRes); } - memory->freeMemory(temp); + _vm->_memory->freeMemory(temp); return 1; } @@ -141,7 +125,7 @@ int32 Logic::fnRegisterStartPoint(int32 *params) { error("ERROR: _startList full"); // +1 to allow for NULL terminator - if (strlen((const char *) memory->intToPtr(params[1])) + 1 > MAX_description) + if (strlen((const char *) _vm->_memory->intToPtr(params[1])) + 1 > MAX_description) error("ERROR: startup description too long"); #endif @@ -152,7 +136,7 @@ int32 Logic::fnRegisterStartPoint(int32 *params) { // the correct start _startList[_totalStartups].key = params[0]; - strcpy(_startList[_totalStartups].description, (const char *) memory->intToPtr(params[1])); + strcpy(_startList[_totalStartups].description, (const char *) _vm->_memory->intToPtr(params[1])); // point to next _totalStartups++; @@ -195,8 +179,8 @@ void Logic::conStart(int start) { fnStopMusic(NULL); // halt the sample prematurely - g_sound->unpauseSpeech(); - g_sound->stopSpeech(); + _vm->_sound->unpauseSpeech(); + _vm->_sound->stopSpeech(); // clean out all resources & flags, ready for a total // restart @@ -204,27 +188,27 @@ void Logic::conStart(int start) { // remove all resources from memory, including player // object & global variables - res_man->removeAll(); + _vm->_resman->removeAll(); // reopen global variables resource & send address to // interpreter - it won't be moving - setGlobalInterpreterVariables((int32 *) (res_man->openResource(1) + sizeof(_standardHeader))); - res_man->closeResource(1); + setGlobalInterpreterVariables((int32 *) (_vm->_resman->openResource(1) + sizeof(_standardHeader))); + _vm->_resman->closeResource(1); // free all the route memory blocks from previous game _router->freeAllRouteMem(); // if there was speech text, kill the text block if (_speechTextBlocNo) { - fontRenderer->killTextBloc(_speechTextBlocNo); + _vm->_fontRenderer->killTextBloc(_speechTextBlocNo); _speechTextBlocNo = 0; } // set the key // Open George - raw_data_ad = (char *) res_man->openResource(8); - raw_script = (char *) res_man->openResource(_startList[start].start_res_id); + raw_data_ad = (char *) _vm->_resman->openResource(8); + raw_script = (char *) _vm->_resman->openResource(_startList[start].start_res_id); // denotes script to run null_pc = _startList[start].key & 0xffff; @@ -232,10 +216,10 @@ void Logic::conStart(int start) { Debug_Printf("Running start %d\n", start); runScript(raw_script, raw_data_ad, &null_pc); - res_man->closeResource(_startList[start].start_res_id); + _vm->_resman->closeResource(_startList[start].start_res_id); // Close George - res_man->closeResource(8); + _vm->_resman->closeResource(8); // make sure thre's a mouse, in case restarting while // mouse not available diff --git a/sword2/sword2.cpp b/sword2/sword2.cpp index b55bfad139..d6bce469ad 100644 --- a/sword2/sword2.cpp +++ b/sword2/sword2.cpp @@ -17,32 +17,13 @@ * $Header$ */ -#include "stdafx.h" +#include "common/stdafx.h" #include "backends/fs/fs.h" #include "base/gameDetector.h" #include "base/plugins.h" #include "common/config-manager.h" #include "sword2/sword2.h" -#include "sword2/driver/driver96.h" #include "sword2/defs.h" -#include "sword2/build_display.h" -#include "sword2/console.h" -#include "sword2/controls.h" -#include "sword2/credits.h" -#include "sword2/debug.h" -#include "sword2/header.h" -#include "sword2/interpreter.h" -#include "sword2/layers.h" -#include "sword2/logic.h" -#include "sword2/maketext.h" -#include "sword2/memory.h" -#include "sword2/mouse.h" -#include "sword2/protocol.h" -#include "sword2/resman.h" -#include "sword2/save_rest.h" -#include "sword2/sound.h" -#include "sword2/speech.h" -#include "sword2/startup.h" #ifdef _WIN32_WCE extern bool isSmartphone(void); @@ -98,9 +79,6 @@ 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; -Graphics *g_graphics = NULL; Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst) : Engine(syst) { @@ -126,14 +104,14 @@ Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst) // get some falling RAM and put it in your pocket, never let it slip // away - memory = new MemoryManager(); - res_man = new ResourceManager(this); + _memory = new MemoryManager(this); + _resman = new ResourceManager(this); _logic = new Logic(this); - fontRenderer = new FontRenderer(); - gui = new Gui(this); - g_input = _input = new Input(); - g_sound = _sound = new Sound(_mixer); - g_graphics = _graphics = new Graphics(640, 480); + _fontRenderer = new FontRenderer(this); + _gui = new Gui(this); + _input = new Input(this); + _sound = new Sound(this); + _graphics = new Graphics(this, 640, 480); _debugger = new Debugger(this); _lastPaletteRes = 0; @@ -192,11 +170,11 @@ Sword2Engine::~Sword2Engine() { delete _graphics; delete _sound; delete _input; - delete gui; - delete fontRenderer; + delete _gui; + delete _fontRenderer; delete _logic; - delete res_man; - delete memory; + delete _resman; + delete _memory; } void Sword2Engine::errorString(const char *buf1, char *buf2) { @@ -223,9 +201,9 @@ int32 Sword2Engine::InitialiseGame(void) { // initialise global script variables // res 1 is the globals list - file = res_man->openResource(1); + file = _resman->openResource(1); debug(5, "CALLING: SetGlobalInterpreterVariables"); - _logic->setGlobalInterpreterVariables((int32 * ) (file + sizeof(_standardHeader))); + _logic->setGlobalInterpreterVariables((int32 *) (file + sizeof(_standardHeader))); // DON'T CLOSE VARIABLES RESOURCE - KEEP IT OPEN AT VERY START OF // MEMORY SO IT CAN'T MOVE! @@ -233,7 +211,7 @@ int32 Sword2Engine::InitialiseGame(void) { // DON'T CLOSE PLAYER OBJECT RESOURCE - KEEP IT OPEN IN MEMORY SO IT // CAN'T MOVE! - file = res_man->openResource(8); + file = _resman->openResource(8); // Set up font resource variables for this language version @@ -257,7 +235,7 @@ int32 Sword2Engine::InitialiseGame(void) { void Sword2Engine::closeGame(void) { // Stop music instantly! killMusic(); - g_system->quit(); + _system->quit(); } void Sword2Engine::gameCycle(void) { @@ -291,7 +269,7 @@ void Sword2Engine::gameCycle(void) { processFxQueue(); // update age and calculate previous cycle memory usage - res_man->nextCycle(); + _resman->nextCycle(); } void Sword2Engine::go() { @@ -306,7 +284,7 @@ void Sword2Engine::go() { // via a window, thus time becomes a loop. debug(5, "CALLING: readOptionSettings"); - gui->readOptionSettings(); + _gui->readOptionSettings(); debug(5, "CALLING: InitialiseGame"); if (InitialiseGame()) { @@ -319,7 +297,7 @@ void Sword2Engine::go() { restoreGame(_saveSlot); else { // show restore menu setMouse(NORMAL_MOUSE_ID); - if (!gui->restoreControl()) + if (!_gui->restoreControl()) startGame(); } } else @@ -359,8 +337,8 @@ void Sword2Engine::go() { } #endif - if (g_input->keyWaiting()) { - g_input->readKey(&ke); + if (_input->keyWaiting()) { + _input->readKey(&ke); char c = toupper(ke.ascii); @@ -458,19 +436,19 @@ void Sword2Engine::startGame(void) { uint32 null_pc = 1; // open george object, ready for start script to reference - raw_data_ad = (char *) res_man->openResource(8); + raw_data_ad = (char *) _resman->openResource(8); // open the ScreenManager object - raw_script = (char *) res_man->openResource(screen_manager_id); + raw_script = (char *) _resman->openResource(screen_manager_id); // run the start script now (because no console) _logic->runScript(raw_script, raw_data_ad, &null_pc); // close the ScreenManager object - res_man->closeResource(screen_manager_id); + _resman->closeResource(screen_manager_id); // close george - res_man->closeResource(8); + _resman->closeResource(8); debug(5, "startGame() DONE."); } @@ -491,10 +469,10 @@ void Sword2Engine::pauseGame(void) { // uint8 *text; // open text file & get the line "PAUSED" - // text = FetchTextLine(res_man->openResource(3258), 449); - // pause_text_bloc_no = Build_new_block(text + 2, 320, 210, 640, 184, RDSPR_TRANS | RDSPR_DISPLAYALIGN, SPEECH_FONT_ID, POSITION_AT_CENTRE_OF_BASE); + // text = fetchTextLine(_resman->openResource(3258), 449); + // pause_text_bloc_no = _fontRenderer->buildNewBloc(text + 2, 320, 210, 640, 184, RDSPR_TRANS | RDSPR_DISPLAYALIGN, SPEECH_FONT_ID, POSITION_AT_CENTRE_OF_BASE); // now ok to close the text file - // res_man->closeResource(3258); + // _resman->closeResource(3258); // don't allow Pause while screen fading or while black if (_graphics->getFadeStatus() != RDFADE_NONE) @@ -519,8 +497,8 @@ void Sword2Engine::pauseGame(void) { // if level at max, turn down because palette-matching won't work // when dimmed - if (gui->_currentGraphicsLevel == 3) { - gui->updateGraphicsLevel(2); + if (_gui->_currentGraphicsLevel == 3) { + _gui->updateGraphicsLevel(2); _graphicsLevelFudged = true; } @@ -535,7 +513,7 @@ void Sword2Engine::pauseGame(void) { void Sword2Engine::unpauseGame(void) { // removed "PAUSED" from screen - // Kill_text_bloc(pause_text_bloc_no); + // _fontRenderer->killTextBloc(pause_text_bloc_no); if (OBJECT_HELD && _realLuggageItem) setLuggage(_realLuggageItem); @@ -547,7 +525,7 @@ void Sword2Engine::unpauseGame(void) { // If graphics level at max, turn up again if (_graphicsLevelFudged) { - gui->updateGraphicsLevel(3); + _gui->updateGraphicsLevel(3); _graphicsLevelFudged = false; } diff --git a/sword2/sword2.h b/sword2/sword2.h index 13ce8b5a55..df3ee91bd7 100644 --- a/sword2/sword2.h +++ b/sword2/sword2.h @@ -21,23 +21,22 @@ #define _SWORD2 #include "base/engine.h" -#include "common/file.h" -#include "common/map.h" -#include "common/rect.h" -#include "common/str.h" +#include "sword2/driver/driver96.h" +#include "sword2/driver/d_sound.h" +#include "sword2/driver/d_draw.h" #include "sword2/build_display.h" #include "sword2/console.h" -#include "sword2/header.h" +#include "sword2/controls.h" #include "sword2/icons.h" #include "sword2/layers.h" #include "sword2/logic.h" +#include "sword2/maketext.h" #include "sword2/memory.h" #include "sword2/mouse.h" #include "sword2/object.h" +#include "sword2/resman.h" #include "sword2/save_rest.h" #include "sword2/sound.h" -#include "sword2/driver/d_sound.h" -#include "sword2/driver/d_draw.h" class GameDetector; @@ -137,10 +136,14 @@ public: uint32 _features; char *_targetName; // target name for saves + MemoryManager *_memory; + ResourceManager *_resman; Input *_input; Sound *_sound; Graphics *_graphics; Logic *_logic; + FontRenderer *_fontRenderer; + Gui *_gui; Debugger *_debugger; @@ -281,7 +284,7 @@ public: // savegame file header - struct _savegameHeader { + struct SaveGameHeader { // sum of all bytes in file, excluding this uint32 uint32 checksum; @@ -304,7 +307,7 @@ public: Object_mega mega; }; - _savegameHeader g_header; + SaveGameHeader _saveGameHeader; uint32 saveGame(uint16 slotNo, uint8 *description); uint32 restoreGame(uint16 slotNo); @@ -366,9 +369,6 @@ public: }; extern Sword2Engine *g_sword2; -extern Input *g_input; -extern Sound *g_sound; -extern Graphics *g_graphics; } // End of namespace Sword2 diff --git a/sword2/sync.cpp b/sword2/sync.cpp index 72248416bf..cf54f093fd 100644 --- a/sword2/sync.cpp +++ b/sword2/sync.cpp @@ -17,13 +17,10 @@ * $Header$ */ -#include "stdafx.h" -#include "common/util.h" +#include "common/stdafx.h" #include "sword2/sword2.h" -#include "sword2/debug.h" #include "sword2/defs.h" #include "sword2/interpreter.h" -#include "sword2/logic.h" namespace Sword2 { diff --git a/sword2/tony_gsdk.cpp b/sword2/tony_gsdk.cpp index e7bd7cdd59..31c6dbf616 100644 --- a/sword2/tony_gsdk.cpp +++ b/sword2/tony_gsdk.cpp @@ -19,11 +19,9 @@ // general odds and ends -#include "stdafx.h" +#include "common/stdafx.h" +#include "common/file.h" #include "sword2/sword2.h" -#include "sword2/driver/driver96.h" -#include "sword2/debug.h" -#include "sword2/memory.h" namespace Sword2 { @@ -41,7 +39,7 @@ uint32 Sword2Engine::readFile(const char *name, mem **membloc, uint32 uid) { size = fh.size(); // reserve enough floating memory for the file - *membloc = memory->allocMemory(size, MEM_float, uid); + *membloc = _memory->allocMemory(size, MEM_float, uid); if (fh.read((*membloc)->ad, size) != size) { debug(5, "Read_file read fail %d", name); diff --git a/sword2/walker.cpp b/sword2/walker.cpp index ca3690a7ff..0fea2a7d24 100644 --- a/sword2/walker.cpp +++ b/sword2/walker.cpp @@ -22,15 +22,10 @@ // script functions for moving megas about the place & also for keeping tabs // on them -#include "stdafx.h" +#include "common/stdafx.h" #include "sword2/sword2.h" -#include "sword2/console.h" #include "sword2/defs.h" #include "sword2/interpreter.h" -#include "sword2/logic.h" -#include "sword2/object.h" -#include "sword2/protocol.h" -#include "sword2/router.h" namespace Sword2 { @@ -60,9 +55,9 @@ int32 Logic::fnWalk(int32 *params) { // get the parameters - ob_logic = (Object_logic *) memory->intToPtr(params[0]); - ob_graph = (Object_graphic *) memory->intToPtr(params[1]); - ob_mega = (Object_mega *) memory->intToPtr(params[2]); + ob_logic = (Object_logic *) _vm->_memory->intToPtr(params[0]); + ob_graph = (Object_graphic *) _vm->_memory->intToPtr(params[1]); + ob_mega = (Object_mega *) _vm->_memory->intToPtr(params[2]); target_x = (int16) params[4]; target_y = (int16) params[5]; @@ -88,7 +83,7 @@ int32 Logic::fnWalk(int32 *params) { if (params[6] < 0 || params[6] > 8) error("Invalid direction (%d) in fnWalk", params[6]); - ob_walkdata = (Object_walkdata *) memory->intToPtr(params[3]); + ob_walkdata = (Object_walkdata *) _vm->_memory->intToPtr(params[3]); ob_mega->walk_pc = 0; // always @@ -131,7 +126,7 @@ int32 Logic::fnWalk(int32 *params) { // resource ob_graph->anim_resource = ob_mega->megaset_res; - } else if (EXIT_FADING && g_graphics->getFadeStatus() == RDFADE_BLACK) { + } else if (EXIT_FADING && _vm->_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 @@ -170,7 +165,7 @@ int32 Logic::fnWalk(int32 *params) { if (checkEventWaiting()) { if (walkAnim[walk_pc].step == 0 && walkAnim[walk_pc + 1].step == 1) { // at the beginning of a step - ob_walkdata = (Object_walkdata *) memory->intToPtr(params[3]); + ob_walkdata = (Object_walkdata *) _vm->_memory->intToPtr(params[3]); _router->earlySlowOut(ob_mega, ob_walkdata); } } @@ -255,11 +250,11 @@ int32 Logic::fnWalkToAnim(int32 *params) { // if this is the start of the walk, read anim file to get start coords - ob_logic = (Object_logic *) memory->intToPtr(params[0]); + ob_logic = (Object_logic *) _vm->_memory->intToPtr(params[0]); if (ob_logic->looping == 0) { // open anim file - anim_file = res_man->openResource(params[4]); + anim_file = _vm->_resman->openResource(params[4]); // point to animation header anim_head = _vm->fetchAnimHeader( anim_file ); @@ -269,7 +264,7 @@ int32 Logic::fnWalkToAnim(int32 *params) { pars[6] = anim_head->feetStartDir; // target_dir // close anim file - res_man->closeResource(params[4]); + _vm->_resman->closeResource(params[4]); // if start coords not yet set in anim header, use the standby // coords (which should be set beforehand in the script) @@ -320,13 +315,13 @@ int32 Logic::fnTurn(int32 *params) { // if this is the start of the turn, get the mega's current feet // coords + the required direction - ob_logic = (Object_logic *) memory->intToPtr(params[0]); + ob_logic = (Object_logic *) _vm->_memory->intToPtr(params[0]); if (ob_logic->looping == 0) { if (params[4] < 0 || params[4] > 7) error("Invalid direction (%d) in fnTurn", params[4]); - ob_mega = (Object_mega *) memory->intToPtr(params[2]); + ob_mega = (Object_mega *) _vm->_memory->intToPtr(params[2]); pars[4] = ob_mega->feet_x; pars[5] = ob_mega->feet_y; @@ -367,8 +362,8 @@ int32 Logic::fnStandAt(int32 *params) { // set up pointers to the graphic & mega structure - ob_graph = (Object_graphic *) memory->intToPtr(params[0]); - ob_mega = (Object_mega *) memory->intToPtr(params[1]); + ob_graph = (Object_graphic *) _vm->_memory->intToPtr(params[0]); + ob_mega = (Object_mega *) _vm->_memory->intToPtr(params[1]); // set up the stand frame & set the mega's new direction @@ -394,7 +389,7 @@ int32 Logic::fnStand(int32 *params) { // 1 pointer to object's mega structure // 2 target direction - Object_mega *ob_mega = (Object_mega *) memory->intToPtr(params[1]); + Object_mega *ob_mega = (Object_mega *) _vm->_memory->intToPtr(params[1]); int32 pars[5]; pars[0] = params[0]; @@ -423,7 +418,7 @@ int32 Logic::fnStandAfterAnim(int32 *params) { // open the anim file & set up a pointer to the animation header // open anim file - anim_file = res_man->openResource(params[2]); + anim_file = _vm->_resman->openResource(params[2]); anim_head = _vm->fetchAnimHeader(anim_file); // set up the parameter list for fnWalkTo() @@ -450,7 +445,7 @@ int32 Logic::fnStandAfterAnim(int32 *params) { error("Invalid direction (%d) in fnStandAfterAnim", pars[4]); // close the anim file - res_man->closeResource(params[2]); + _vm->_resman->closeResource(params[2]); // call fnStandAt() with target coords set to anim end position return fnStandAt(pars); @@ -470,7 +465,7 @@ int32 Logic::fnStandAtAnim(int32 *params) { // open the anim file & set up a pointer to the animation header // open anim file - anim_file = res_man->openResource(params[2]); + anim_file = _vm->_resman->openResource(params[2]); anim_head = _vm->fetchAnimHeader(anim_file); // set up the parameter list for fnWalkTo() @@ -497,7 +492,7 @@ int32 Logic::fnStandAtAnim(int32 *params) { error("Invalid direction (%d) in fnStandAfterAnim", pars[4]); // close the anim file - res_man->closeResource(params[2]); + _vm->_resman->closeResource(params[2]); // call fnStandAt() with target coords set to anim end position return fnStandAt(pars); @@ -556,10 +551,10 @@ int32 Logic::fnFaceXY(int32 *params) { // if this is the start of the turn, get the mega's current feet // coords + the required direction - ob_logic = (Object_logic *) memory->intToPtr(params[0]); + ob_logic = (Object_logic *) _vm->_memory->intToPtr(params[0]); if (ob_logic->looping == 0) { - ob_mega = (Object_mega *) memory->intToPtr(params[2]); + ob_mega = (Object_mega *) _vm->_memory->intToPtr(params[2]); pars[4] = ob_mega->feet_x; pars[5] = ob_mega->feet_y; @@ -591,12 +586,12 @@ int32 Logic::fnFaceMega(int32 *params) { Object_mega *ob_mega; _standardHeader *head; - ob_mega = (Object_mega *) memory->intToPtr(params[2]); - ob_logic = (Object_logic *) memory->intToPtr(params[0]); + ob_mega = (Object_mega *) _vm->_memory->intToPtr(params[2]); + ob_logic = (Object_logic *) _vm->_memory->intToPtr(params[0]); if (ob_logic->looping == 0) { // get targets info - head = (_standardHeader *) res_man->openResource(params[4]); + head = (_standardHeader *) _vm->_resman->openResource(params[4]); if (head->fileType != GAME_OBJECT) error("fnFaceMega %d not an object", params[4]); @@ -606,7 +601,7 @@ int32 Logic::fnFaceMega(int32 *params) { //call the base script - this is the graphic/mouse service call runScript(raw_script_ad, raw_script_ad, &null_pc); - res_man->closeResource(params[4]); + _vm->_resman->closeResource(params[4]); // engineMega is now the Object_mega of mega we want to turn // to face @@ -647,8 +642,8 @@ int32 Logic::fnWalkToTalkToMega(int32 *params) { int mega_separation = params[5]; _standardHeader *head; - ob_logic = (Object_logic *) memory->intToPtr(params[0]); - ob_mega = (Object_mega *) memory->intToPtr(params[2]); + ob_logic = (Object_logic *) _vm->_memory->intToPtr(params[0]); + ob_mega = (Object_mega *) _vm->_memory->intToPtr(params[2]); pars[0] = params[0]; // standard stuff pars[1] = params[1]; @@ -658,7 +653,7 @@ int32 Logic::fnWalkToTalkToMega(int32 *params) { // not been here before so decide where to walk-to if (!ob_logic->looping) { // first request the targets info - head = (_standardHeader *) res_man->openResource(params[4]); + head = (_standardHeader *) _vm->_resman->openResource(params[4]); if (head->fileType != GAME_OBJECT) error("fnWalkToTalkToMega %d not an object", params[4]); @@ -669,7 +664,7 @@ int32 Logic::fnWalkToTalkToMega(int32 *params) { // call runScript(raw_script_ad, raw_script_ad, &null_pc); - res_man->closeResource(params[4]); + _vm->_resman->closeResource(params[4]); // engineMega is now the Object_mega of mega we want to // route to @@ -737,8 +732,8 @@ int32 Logic::fnAddWalkGrid(int32 *params) { _router->addWalkGrid(params[0]); // Touch the grid, getting it into memory. - res_man->openResource(params[0]); - res_man->closeResource(params[0]); + _vm->_resman->openResource(params[0]); + _vm->_resman->closeResource(params[0]); return IR_CONT; } @@ -771,7 +766,7 @@ int32 Logic::fnSetScaling(int32 *params) { // where s is system scale, which itself is (256 * actual_scale) ie. // s == 128 is half size - Object_mega *ob_mega = (Object_mega *) memory->intToPtr(params[0]); + Object_mega *ob_mega = (Object_mega *) _vm->_memory->intToPtr(params[0]); ob_mega->scale_a = params[1]; ob_mega->scale_b = params[2]; |