From 2554ced5e970301e46f1b8035975762447b900f2 Mon Sep 17 00:00:00 2001 From: Robert Göffringmann Date: Sat, 20 Dec 2003 20:20:53 +0000 Subject: fixed crashes after restoring a savegame, added fnSetPaletteToFade and changed speech code to distinguish between CD1 and CD2. (now needs SPEECH1.CLU and SPEECH2.CLU) svn-id: r11789 --- sword1/control.cpp | 7 +++ sword1/logic.cpp | 9 +-- sword1/screen.cpp | 9 ++- sword1/screen.h | 1 + sword1/sound.cpp | 45 +++++++++----- sword1/sound.h | 5 +- sword1/staticres.cpp | 170 +++++++++++++++++++++++++++++++++++++++++++++++++++ sword1/sword1.cpp | 15 ++++- sword1/sword1.h | 18 +----- 9 files changed, 233 insertions(+), 46 deletions(-) (limited to 'sword1') diff --git a/sword1/control.cpp b/sword1/control.cpp index 56377033ec..cdeb194709 100644 --- a/sword1/control.cpp +++ b/sword1/control.cpp @@ -603,12 +603,19 @@ void SwordControl::doRestore(void) { } uint32 playerSize = (sizeof(BsObject) - 12000) / 4; uint32 *playerRaw = (uint32*)_objMan->fetchObject(PLAYER); + BsObject *cpt = _objMan->fetchObject(PLAYER); for (uint32 cnt = 0; cnt < playerSize; cnt++) { *playerRaw = *(uint32*)bufPos; playerRaw++; bufPos += 4; } free(_restoreBuf); + SwordLogic::_scriptVars[CHANGE_DIR] = cpt->o_dir; + SwordLogic::_scriptVars[CHANGE_X] = cpt->o_xcoord; + SwordLogic::_scriptVars[CHANGE_Y] = cpt->o_ycoord; + SwordLogic::_scriptVars[CHANGE_STANCE] = STAND; + SwordLogic::_scriptVars[CHANGE_PLACE] = cpt->o_place; + SwordEngine::_systemVars.justRestoredGame = 1; } void SwordControl::delay(uint32 msecs) { diff --git a/sword1/logic.cpp b/sword1/logic.cpp index 2717c6b1ba..076138646d 100644 --- a/sword1/logic.cpp +++ b/sword1/logic.cpp @@ -856,8 +856,8 @@ int SwordLogic::fnFadeDown(BsObject *cpt, int32 id, int32 speed, int32 d, int32 } int SwordLogic::fnFadeUp(BsObject *cpt, int32 id, int32 speed, int32 d, int32 e, int32 f, int32 z, int32 x) { - warning("fnFadeUp speed = %d", speed); - _screen->fadeUpPalette(); + //warning("fnFadeUp speed = %d", speed); + //_screen->fadeUpPalette(); return SCRIPT_CONT; } @@ -878,10 +878,7 @@ int SwordLogic::fnSetWholePalette(BsObject *cpt, int32 id, int32 spritePal, int3 } int SwordLogic::fnSetFadeTargetPalette(BsObject *cpt, int32 id, int32 spritePal, int32 d, int32 e, int32 f, int32 z, int32 x) { - uint8 *pal = (uint8*)_resMan->openFetchRes(spritePal); - pal[0] = pal[1] = pal[2] = 0; - _resMan->resClose(spritePal); - warning("fnSetFadeTargetPalette(xx, %d, %X, %d)", id, spritePal, d); + _screen->fnSetPalette(0, 184, spritePal, true); return SCRIPT_CONT; } diff --git a/sword1/screen.cpp b/sword1/screen.cpp index 2386c760db..4075aebeb8 100644 --- a/sword1/screen.cpp +++ b/sword1/screen.cpp @@ -109,6 +109,8 @@ void SwordScreen::fnSetPalette(uint8 start, uint16 length, uint32 id, bool fadeU if (fadeUp) { _fadingStep = 1; _fadingDirection = FADE_UP; + memset(_currentPalette, 0, 256 * 4); + _system->set_palette(_currentPalette, 0, 256); } else _system->set_palette(_targetPalette, start, length); } @@ -121,10 +123,8 @@ void SwordScreen::updateScreen(void) { if (SwordLogic::_scriptVars[NEW_PALETTE]) { _fadingStep = 1; _fadingDirection = FADE_UP; - memcpy(_targetPalette, _resMan->openFetchRes(_roomDefTable[_currentScreen].palettes[0]), 184 * 3); // set colours 0-183 for background palette - _resMan->resClose(_roomDefTable[_currentScreen].palettes[0]); - memcpy(_targetPalette + 184 * 3, _resMan->openFetchRes(_roomDefTable[_currentScreen].palettes[1]), 72 * 3); // set colours 184-255 for sprite palette - george, icons & menubar - _resMan->resClose(_roomDefTable[_currentScreen].palettes[1]); + fnSetPalette(0, 184, _roomDefTable[_currentScreen].palettes[0], true); + fnSetPalette(184, 72, _roomDefTable[_currentScreen].palettes[1], true); SwordLogic::_scriptVars[NEW_PALETTE] = 0; } if (_fadingStep) { @@ -223,7 +223,6 @@ void SwordScreen::updateScreen(void) { void SwordScreen::newScreen(uint32 screen) { // set sizes and scrolling, initialize/load screengrid, force screen refresh - // force palette fadeup? _currentScreen = screen; _scrnSizeX = _roomDefTable[screen].sizeX; _scrnSizeY = _roomDefTable[screen].sizeY; diff --git a/sword1/screen.h b/sword1/screen.h index bef314791b..e3b5c52c5b 100644 --- a/sword1/screen.h +++ b/sword1/screen.h @@ -81,6 +81,7 @@ public: void fadeDownPalette(void); void fadeUpPalette(void); void fnSetPalette(uint8 start, uint16 length, uint32 id, bool fadeUp); + //void fnSetFadeTargetPalette(uint32 id); bool stillFading(void); void updateScreen(void); diff --git a/sword1/sound.cpp b/sword1/sound.cpp index ea83e27815..b7f6c4d1df 100644 --- a/sword1/sound.cpp +++ b/sword1/sound.cpp @@ -24,6 +24,7 @@ #include "common/util.h" #include "resman.h" #include "logic.h" +#include "sword1.h" #define SOUND_SPEECH_ID 1 #define SPEECH_FLAGS (SoundMixer::FLAG_16BITS | SoundMixer::FLAG_AUTOFREE | SoundMixer::FLAG_LITTLE_ENDIAN) @@ -33,8 +34,8 @@ SwordSound::SwordSound(const char *searchPath, SoundMixer *mixer, ResMan *pResMa _mixer = mixer; _resMan = pResMan; _cowHeader = NULL; - initCowSystem(); _endOfQueue = 0; + _currentCowFile = 0; } int SwordSound::addToQueue(int32 fxNo) { @@ -107,25 +108,22 @@ bool SwordSound::amISpeaking(void) { return true; } -void SwordSound::clearAllFx(void) { - warning("Stub: SwordSound::clearAllFx()"); -} - -void SwordSound::closeCowSysten(void) { - warning("stub: SwordSound::closeCowSystem()"); -} - bool SwordSound::speechFinished(void) { - //warning("stub: SwordSound::speechFinished()"); - //return true; return (_speechHandle == 0); } +void SwordSound::newScreen(uint32 screen) { + if (_currentCowFile != SwordEngine::_systemVars.currentCD) { + if (_currentCowFile) + closeCowSystem(); + initCowSystem(); + } +} + void SwordSound::quitScreen(void) { // stop all running SFX while (_endOfQueue) fnStopFx(_fxQueue[0].id); - // I don't think that we even have to start SFX here. } void SwordSound::playSample(QueueElement *elem) { @@ -216,9 +214,13 @@ void SwordSound::stopSpeech(void) { } void SwordSound::initCowSystem(void) { - _cowFile.open("SPEECH.CLU"); - if (_cowFile.isOpen() == false) - _cowFile.open("speech/SPEECH.CLU"); + char cowName[25]; + sprintf(cowName, "SPEECH%d.CLU", SwordEngine::_systemVars.currentCD); + _cowFile.open(cowName); + if (!_cowFile.isOpen()) { + sprintf(cowName, "speech/SPEECH%d.CLU", SwordEngine::_systemVars.currentCD); + _cowFile.open(cowName); + } if (_cowFile.isOpen()) { _cowHeaderSize = _cowFile.readUint32LE(); _cowHeader = (uint32*)malloc(_cowHeaderSize); @@ -226,6 +228,17 @@ void SwordSound::initCowSystem(void) { error("Unexpected cow header size %d", _cowHeaderSize); for (uint32 cnt = 0; cnt < (_cowHeaderSize / 4) - 1; cnt++) _cowHeader[cnt] = _cowFile.readUint32LE(); + _currentCowFile = SwordEngine::_systemVars.currentCD; } else - warning("SwordSound::initCowSystem: Can't open SPEECH.CLU"); + warning("SwordSound::initCowSystem: Can't open SPEECH%d.CLU", SwordEngine::_systemVars.currentCD); +} + +void SwordSound::closeCowSystem(void) { + if (_cowFile.isOpen()) + _cowFile.close(); + if (_cowHeader) + free(_cowHeader); + _cowHeader = NULL; + _currentCowFile = NULL; } + diff --git a/sword1/sound.h b/sword1/sound.h index d139d15ab3..0f1510dc32 100644 --- a/sword1/sound.h +++ b/sword1/sound.h @@ -57,6 +57,7 @@ class SwordSound { public: SwordSound(const char *searchPath, SoundMixer *mixer, ResMan *pResMan); ~SwordSound(void); + void newScreen(uint32 screen); void quitScreen(void); bool startSpeech(uint16 roomNo, uint16 localNo); // this should work more or less. @@ -66,7 +67,6 @@ public: bool amISpeaking(void); // this is supposed to return if the sounddata is near the ending or very silent... void fnStopFx(int32 fxNo); - void clearAllFx(void); int addToQueue(int32 fxNo); void engine(void); @@ -74,12 +74,13 @@ public: private: void playSample(QueueElement *elem); void initCowSystem(void); - void closeCowSysten(void); + void closeCowSystem(void); uint32 uncompressedSize(uint8 *data); uint32 expandSpeech(void *src, void *dest, uint32 srcSize); File _cowFile; uint32 *_cowHeader; uint32 _cowHeaderSize; + uint8 _currentCowFile; PlayingSoundHandle _speechHandle, _fxHandle; Common::RandomSource _rnd; diff --git a/sword1/staticres.cpp b/sword1/staticres.cpp index 0a7460ca91..ed88d3eb42 100644 --- a/sword1/staticres.cpp +++ b/sword1/staticres.cpp @@ -27,6 +27,176 @@ #include "menu.h" #include "music.h" #include "sound.h" +#include "sword1.h" + +const uint8 SwordEngine::_cdList[TOTAL_SECTIONS] = { + 0, // 0 inventory + + 1, // 1 PARIS 1 + 1, // 2 + 1, // 3 + 1, // 4 + 1, // 5 + 1, // 6 + 1, // 7 + 1, // 8 + + 1, // 9 PARIS 2 + 1, // 10 + 1, // 11 + 1, // 12 + 1, // 13 + 1, // 14 + 1, // 15 + 1, // 16 + 1, // 17 + 1, // 18 + + 2, // 19 IRELAND + 2, // 20 + 2, // 21 + 2, // 22 + 2, // 23 + 2, // 24 + 2, // 25 + 2, // 26 + + 1, // 27 PARIS 3 + 1, // 28 + 1, // 29 + 1, // 30 - Heart Monitor + 1, // 31 + 1, // 32 + 1, // 33 + 1, // 34 + 1, // 35 + + 1, // 36 PARIS 4 + 1, // 37 + 1, // 38 + 1, // 39 + 1, // 40 + 1, // 41 + 1, // 42 + 1, // 43 + 0, // 44 + + 2, // 45 SYRIA + 1, // 46 PARIS 4 + 2, // 47 + 1, // 48 PARIS 4 + 2, // 49 + 2, // 50 + 0, // 51 + 0, // 52 + 2, // 53 + 2, // 54 + 2, // 55 + + 2, // 56 SPAIN + 2, // 57 + 2, // 58 + 2, // 59 + 2, // 60 + 2, // 61 + 2, // 62 + + 2, // 63 NIGHT TRAIN + 0, // 64 + 2, // 65 + 2, // 66 + 2, // 67 + 0, // 68 + 2, // 69 + 0, // 70 + + 2, // 71 SCOTLAND + 2, // 72 + 2, // 73 + 2, // 74 END SEQUENCE IN SECRET_CRYPT + 2, // 75 + 2, // 76 + 2, // 77 + 2, // 78 + 2, // 79 + + 1, // 80 PARIS MAP + + 1, // 81 Full-screen for "Asstair" in Paris2 + + 2, // 82 Full-screen BRITMAP in sc55 (Syrian Cave) + 0, // 83 + 0, // 84 + 0, // 85 + + 1, // 86 EUROPE MAP + 1, // 87 fudged in for normal window (sc48) + 1, // 88 fudged in for filtered window (sc48) + 0, // 89 + + 0, // 90 PHONE SCREEN + 0, // 91 ENVELOPE SCREEN + 1, // 92 fudged in for George close-up surprised in sc17 wardrobe + 1, // 93 fudged in for George close-up inquisitive in sc17 wardrobe + 1, // 94 fudged in for George close-up in sc29 sarcophagus + 1, // 95 fudged in for George close-up in sc29 sarcophagus + 1, // 96 fudged in for chalice close-up from sc42 + 0, // 97 + 0, // 98 + 0, // 99 MESSAGE SCREEN (BLANK) + + 0, // 100 + 0, // 101 + 0, // 102 + 0, // 103 + 0, // 104 + 0, // 105 + 0, // 106 + 0, // 107 + 0, // 108 + 0, // 109 + + 0, // 110 + 0, // 111 + 0, // 112 + 0, // 113 + 0, // 114 + 0, // 115 + 0, // 116 + 0, // 117 + 0, // 118 + 0, // 119 + + 0, // 120 + 0, // 121 + 0, // 122 + 0, // 123 + 0, // 124 + 0, // 125 + 0, // 126 + 0, // 127 + 0, // 128 GEORGE'S GAME SECTION + 0, // 129 NICO'S TEXT - on both CD's + + 0, // 130 + 1, // 131 BENOIR'S TEXT - on CD1 + 0, // 132 + 1, // 133 ROSSO'S TEXT - on CD1 + 0, // 134 + 0, // 135 + 0, // 136 + 0, // 137 + 0, // 138 + 0, // 139 + + 0, // 140 + 0, // 141 + 0, // 142 + 0, // 143 + 0, // 144 + 1, // 145 MOUE'S TEXT - on CD1 + 1, // 146 ALBERT'S TEXT - on CD1 +}; const MenuObject SwordMenu::_objectDefs[TOTAL_pockets + 1] = { { // 0 can't use diff --git a/sword1/sword1.cpp b/sword1/sword1.cpp index ae33153869..025ff7aeb0 100644 --- a/sword1/sword1.cpp +++ b/sword1/sword1.cpp @@ -1065,16 +1065,27 @@ void SwordEngine::go(void) { } while (true); } +void SwordEngine::checkCd(void) { + uint8 needCd = _cdList[SwordLogic::_scriptVars[NEW_SCREEN]]; + if (needCd == 0) { + if (_systemVars.currentCD == 0) + _systemVars.currentCD = 1; + } else + _systemVars.currentCD = needCd; +} + void SwordEngine::mainLoop(void) { uint32 newTime, frameTime; bool wantControlPanel = false; do { // do we need the section45-hack from sword.c here? - // todo: ensure right cd is inserted + checkCd(); + _screen->newScreen(SwordLogic::_scriptVars[NEW_SCREEN]); _logic->newScreen(SwordLogic::_scriptVars[NEW_SCREEN]); + _sound->newScreen(SwordLogic::_scriptVars[NEW_SCREEN]); SwordLogic::_scriptVars[SCREEN] = SwordLogic::_scriptVars[NEW_SCREEN]; - // let swordSound start room sfx + do { _music->stream(); frameTime = _system->get_msecs(); diff --git a/sword1/sword1.h b/sword1/sword1.h index 581cac2e53..fa3d866454 100644 --- a/sword1/sword1.h +++ b/sword1/sword1.h @@ -24,6 +24,7 @@ #include "common/util.h" #include "sound/mixer.h" #include "base/gameDetector.h" +#include "sworddefs.h" class SwordScreen; class SwordSound; @@ -41,26 +42,12 @@ struct SystemVars { uint32 justRestoredGame; // see main() in sword.c & New_screen() in gtm_core.c uint32 gamePaused; // 1 when paused uint32 rate; // game rate => what's this for? - //uint32 textNumber; // holds last text_no displayed => I think it was only for debugging - //uint32 endOfQ; // next available slot in sound fx queue - //uint8 debug; // toggles tdebug file - //uint8 saveGameFlag; // controls save game loop 0=off 1=save game 2=restore game 3=restart 4=quit to dos uint8 deathScreenFlag; // 1 death screen version of the control panel, 2 = successful end of game, 3 = force restart bool forceRestart; uint8 playSpeech; uint8 showText; - //uint8 snrStatus; - // ^=> move into SwordControl... or whatever it will be. - //uint8 displayText; // toggles debug text display on "t" - //uint8 displayGrid; // toggles debug grid display on "g" - //uint8 displayMouse; // toggles debug mouse display on "m" - //uint8 framesPerSecond; // toggles one frame pre second mode on "1" - //uint8 writingPCXs; // writing a PCX every frame on "f" - //int16 parallaxOn; I think we don't need this. uint8 language; - //int32 currentMusic; - //uint32 gameCycle; }; class SwordEngine : public Engine { @@ -76,8 +63,8 @@ private: void delay(uint amount); void initialize(void); + void checkCd(void); void mainLoop(void); - void fnCheckCd(uint32 newScreen); void startPositions(int32 startNumber); uint16 _mouseX, _mouseY, _mouseState; @@ -95,4 +82,5 @@ private: SwordSound *_sound; SwordMenu *_menu; SwordMusic *_music; + static const uint8 _cdList[TOTAL_SECTIONS]; }; -- cgit v1.2.3