diff options
author | Robert Göffringmann | 2003-12-28 23:24:03 +0000 |
---|---|---|
committer | Robert Göffringmann | 2003-12-28 23:24:03 +0000 |
commit | e9766658b666dfe5065ccb5f27549f0719b16cda (patch) | |
tree | 1083411aca1741dedc6d8269ac267d6c31e73e4f /sword1 | |
parent | 2548df9cf8ae51a55a7959ca24741a9f8ceb8414 (diff) | |
download | scummvm-rg350-e9766658b666dfe5065ccb5f27549f0719b16cda.tar.gz scummvm-rg350-e9766658b666dfe5065ccb5f27549f0719b16cda.tar.bz2 scummvm-rg350-e9766658b666dfe5065ccb5f27549f0719b16cda.zip |
this fixes the remaining glitches
svn-id: r12004
Diffstat (limited to 'sword1')
-rw-r--r-- | sword1/control.cpp | 20 | ||||
-rw-r--r-- | sword1/control.h | 6 | ||||
-rw-r--r-- | sword1/logic.cpp | 5 | ||||
-rw-r--r-- | sword1/mouse.cpp | 2 | ||||
-rw-r--r-- | sword1/music.cpp | 2 | ||||
-rw-r--r-- | sword1/screen.cpp | 2 | ||||
-rw-r--r-- | sword1/sound.cpp | 29 | ||||
-rw-r--r-- | sword1/sound.h | 10 | ||||
-rw-r--r-- | sword1/sword1.cpp | 7 |
9 files changed, 60 insertions, 23 deletions
diff --git a/sword1/control.cpp b/sword1/control.cpp index 360b7707ba..12f2d37ba6 100644 --- a/sword1/control.cpp +++ b/sword1/control.cpp @@ -31,6 +31,7 @@ #include "sword1.h" #include "common/util.h" #include "mouse.h" +#include "music.h" #define SAVEFILE_WRITE true #define SAVEFILE_READ false @@ -144,11 +145,12 @@ void ControlButton::setSelected(uint8 selected) { draw(); } -SwordControl::SwordControl(ResMan *pResMan, ObjectMan *pObjMan, OSystem *system, SwordMouse *pMouse, const char *savePath) { +SwordControl::SwordControl(ResMan *pResMan, ObjectMan *pObjMan, OSystem *system, SwordMouse *pMouse, SwordMusic *pMusic, const char *savePath) { _resMan = pResMan; _objMan = pObjMan; _system = system; _mouse = pMouse; + _music = pMusic; strcpy(_savePath, savePath); } @@ -173,8 +175,10 @@ uint8 SwordControl::runPanel(void) { bool fullRefresh = false; _mouse->controlPanel(true); uint8 retVal = CONTROL_NOTHING_DONE; + _music->startMusic(61, 1); do { + _music->stream(); if (newMode) { mode = newMode; fullRefresh = true; @@ -214,6 +218,7 @@ uint8 SwordControl::runPanel(void) { _system->copy_rect(_screenBuf, 640, 0, 0, 640, 480); free(_screenBuf); _mouse->controlPanel(false); + _music->startMusic(SwordLogic::_scriptVars[CURRENT_MUSIC], 1); return retVal; } @@ -306,7 +311,7 @@ void SwordControl::setupMainPanel(void) { } if (SwordEngine::_systemVars.deathScreenFlag == 2) // end of game - renderText(_lStrings[STR_THE_END], 480, 188, TEXT_RIGHT_ALIGN); + renderText(_lStrings[STR_THE_END], 480, 188 + 40, TEXT_RIGHT_ALIGN); if (SwordEngine::_systemVars.deathScreenFlag == 0) { // normal panel renderText(_lStrings[STR_SAVE], 180, 188 + 40, TEXT_LEFT_ALIGN); @@ -321,7 +326,7 @@ void SwordControl::setupMainPanel(void) { } else { renderText(_lStrings[STR_RESTORE], 285, 224 + 40, TEXT_LEFT_ALIGN); if (SwordEngine::_systemVars.deathScreenFlag == 3) // just started game - renderText(_lStrings[STR_START], 285, 260, TEXT_LEFT_ALIGN); + renderText(_lStrings[STR_START], 285, 260 + 40, TEXT_LEFT_ALIGN); else renderText(_lStrings[STR_RESTART], 285, 260 + 40, TEXT_LEFT_ALIGN); renderText(_lStrings[STR_QUIT], 285, 296 + 40, TEXT_LEFT_ALIGN); @@ -543,7 +548,7 @@ void SwordControl::renderText(const char *str, uint16 x, uint16 y, uint8 mode) { while (*str) { uint8 *dst = _screenBuf + y * SCREEN_WIDTH + destX; - FrameHeader *chSpr = _resMan->fetchFrame(_font, *str - 32); + FrameHeader *chSpr = _resMan->fetchFrame(_font, ((uint8)*str) - 32); uint8 *sprData = (uint8*)chSpr + sizeof(FrameHeader); for (uint16 cnty = 0; cnty < FROM_LE_16(chSpr->height); cnty++) { for (uint16 cntx = 0; cntx < FROM_LE_16(chSpr->width); cntx++) { @@ -563,7 +568,6 @@ void SwordControl::renderVolumeBar(uint8 id) { } -// I can hardly believe this is all it takes for loading and saving... void SwordControl::saveGameToFile(uint8 slot) { char fName[15]; uint16 cnt; @@ -703,9 +707,9 @@ void SwordControl::delay(uint32 msecs) { } const ButtonInfo SwordControl::_deathButtons[3] = { - {250, 224, SR_BUTTON, BUTTON_RESTORE_PANEL }, - {250, 260, SR_BUTTON, BUTTON_RESTART }, - {250, 296, SR_BUTTON, BUTTON_QUIT } + {250, 224 + 40, SR_BUTTON, BUTTON_RESTORE_PANEL }, + {250, 260 + 40, SR_BUTTON, BUTTON_RESTART }, + {250, 296 + 40, SR_BUTTON, BUTTON_QUIT } }; const ButtonInfo SwordControl::_panelButtons[8] = { diff --git a/sword1/control.h b/sword1/control.h index a2b0d36f1f..677ca869e3 100644 --- a/sword1/control.h +++ b/sword1/control.h @@ -29,7 +29,7 @@ class ObjectMan; class ResMan; class OSystem; class SwordMouse; -class SwordEngine; +class SwordMusic; #define MAX_BUTTONS 16 @@ -63,7 +63,7 @@ struct ButtonInfo { class SwordControl { public: - SwordControl(ResMan *pResMan, ObjectMan *pObjMan, OSystem *system, SwordMouse *pMouse, const char *savePath); + SwordControl(ResMan *pResMan, ObjectMan *pObjMan, OSystem *system, SwordMouse *pMouse, SwordMusic *pMusic, const char *savePath); ~SwordControl(void); uint8 runPanel(void); void doRestore(void); @@ -113,7 +113,7 @@ private: ResMan *_resMan; OSystem *_system; SwordMouse *_mouse; - SwordEngine *_engine; + SwordMusic *_music; char _savePath[256]; uint8 *_font; uint32 _fontId; diff --git a/sword1/logic.cpp b/sword1/logic.cpp index 7d8bd64602..43fcf4eb94 100644 --- a/sword1/logic.cpp +++ b/sword1/logic.cpp @@ -864,12 +864,11 @@ 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) { - _scriptVars[NEW_PALETTE] = 1; + _screen->fadeUpPalette(); return SCRIPT_CONT; } int SwordLogic::fnCheckFade(BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x) { - _scriptVars[RETURN_VALUE] = (uint8)_screen->stillFading(); return SCRIPT_CONT; } @@ -901,7 +900,7 @@ int SwordLogic::fnSetPaletteToCut(BsObject *cpt, int32 id, int32 c, int32 d, int int SwordLogic::fnPlaySequence(BsObject *cpt, int32 id, int32 sequenceId, int32 d, int32 e, int32 f, int32 z, int32 x) { warning("fnPlaySequence(%d) called", sequenceId); - _scriptVars[NEW_PALETTE] = 1; + //_scriptVars[NEW_PALETTE] = 1; /* the logic usually calls fnFadeDown before playing the sequence, so we have to set NEW_PALETTE now to force a palette refresh */ return SCRIPT_CONT; diff --git a/sword1/mouse.cpp b/sword1/mouse.cpp index e4a78f151c..a55cc395d7 100644 --- a/sword1/mouse.cpp +++ b/sword1/mouse.cpp @@ -134,7 +134,7 @@ void SwordMouse::engine(uint16 x, uint16 y, uint16 eventFlags) { uint16 clicked = 0; if (y > 40) { for (uint16 priority = 0; (priority < 10) && (!touchedId); priority++) { - for (uint16 cnt = 0; cnt < _numObjs; cnt++) { + for (uint16 cnt = 0; (cnt < _numObjs) && (!touchedId); cnt++) { if ((_objList[cnt].compact->o_priority == priority) && (SwordLogic::_scriptVars[MOUSE_X] >= (uint32)_objList[cnt].compact->o_mouse_x1) && (SwordLogic::_scriptVars[MOUSE_X] <= (uint32)_objList[cnt].compact->o_mouse_x2) && diff --git a/sword1/music.cpp b/sword1/music.cpp index 9fe8347376..154cf2f6e9 100644 --- a/sword1/music.cpp +++ b/sword1/music.cpp @@ -130,7 +130,7 @@ void SwordMusic::mixer(int16 *buf, uint32 len) { void SwordMusic::stream(void) { // make sure we've got enough samples in buffer. - if ((_smpInBuf < 4 * SAMPLERATE) && _playing) { + if ((_smpInBuf < 4 * SAMPLERATE) && _playing && _musicFile.isOpen()) { _system->lock_mutex(_mutex); uint32 loadTotal = BUFSIZE - _smpInBuf; while (uint32 doLoad = loadTotal) { diff --git a/sword1/screen.cpp b/sword1/screen.cpp index 85708bc34f..b452e83037 100644 --- a/sword1/screen.cpp +++ b/sword1/screen.cpp @@ -86,7 +86,7 @@ void SwordScreen::fadeDownPalette(void) { } void SwordScreen::fadeUpPalette(void) { - _fadingStep = 15; + _fadingStep = 1; _fadingDirection = FADE_UP; } diff --git a/sword1/sound.cpp b/sword1/sound.cpp index ec5a6e2a09..e92b818f85 100644 --- a/sword1/sound.cpp +++ b/sword1/sound.cpp @@ -105,7 +105,8 @@ void SwordSound::fnStopFx(int32 fxNo) { } bool SwordSound::amISpeaking(void) { - return true; + _waveVolPos++; + return _waveVolume[_waveVolPos - 1]; } bool SwordSound::speechFinished(void) { @@ -202,6 +203,7 @@ int16 *SwordSound::uncompressSpeech(uint32 index, uint32 cSize, uint32 *size) { } free(fBuf); *size = resSize * 2; + calcWaveVolume(dstData, resSize); return dstData; } else { free(fBuf); @@ -211,6 +213,31 @@ int16 *SwordSound::uncompressSpeech(uint32 index, uint32 cSize, uint32 *size) { } } +void SwordSound::calcWaveVolume(int16 *data, uint32 length) { + int16 *blkPos = data + 918; + for (uint32 cnt = 0; cnt < WAVE_VOL_TAB_LENGTH; cnt++) + _waveVolume[cnt] = false; + _waveVolPos = 0; + for (uint32 blkCnt = 1; blkCnt < length / 918; blkCnt++) { + if (blkCnt >= WAVE_VOL_TAB_LENGTH) { + warning("Wave vol tab too small."); + return; + } + int32 average = 0; + for (uint32 cnt = 0; cnt < 918; cnt++) + average += blkPos[cnt]; + average /= 918; + uint32 diff = 0; + for (uint32 cnt = 0; cnt < 918; cnt++) { + int16 smpDiff = *blkPos - average; + diff += (uint32)ABS(smpDiff); + blkPos++; + } + if (diff > WAVE_VOL_THRESHOLD) + _waveVolume[blkCnt - 1] = true; + } +} + void SwordSound::stopSpeech(void) { _mixer->stopID(SOUND_SPEECH_ID); } diff --git a/sword1/sound.h b/sword1/sound.h index 340a54b6ef..975d3df256 100644 --- a/sword1/sound.h +++ b/sword1/sound.h @@ -52,6 +52,8 @@ struct FxDef { class SoundMixer; class ResMan; +#define WAVE_VOL_TAB_LENGTH 480 +#define WAVE_VOL_THRESHOLD 190000 //120000 class SwordSound { public: @@ -60,11 +62,10 @@ public: void newScreen(uint32 screen); void quitScreen(void); - bool startSpeech(uint16 roomNo, uint16 localNo); // this should work more or less. - // Maybe we'll need a delay of 3 gameCycles. + bool startSpeech(uint16 roomNo, uint16 localNo); bool speechFinished(void); void stopSpeech(); - bool amISpeaking(void); // this is supposed to return if the sounddata is near the ending or very silent... + bool amISpeaking(void); void fnStopFx(int32 fxNo); int addToQueue(int32 fxNo); @@ -77,6 +78,9 @@ private: void closeCowSystem(void); int16 *uncompressSpeech(uint32 index, uint32 cSize, uint32 *size); + void calcWaveVolume(int16 *data, uint32 length); + bool _waveVolume[WAVE_VOL_TAB_LENGTH]; + uint16 _waveVolPos; File _cowFile; uint32 *_cowHeader; uint32 _cowHeaderSize; diff --git a/sword1/sword1.cpp b/sword1/sword1.cpp index 16318f4956..21c4287364 100644 --- a/sword1/sword1.cpp +++ b/sword1/sword1.cpp @@ -148,7 +148,7 @@ void SwordEngine::initialize(void) { _logic->initialize(); _objectMan->initialize(); _mouse->initialize(); - _control = new SwordControl(_resMan, _objectMan, _system, _mouse, getSavePath()); + _control = new SwordControl(_resMan, _objectMan, _system, _mouse, _music, getSavePath()); } void SwordEngine::reinitialize(void) { @@ -1023,6 +1023,7 @@ void SwordEngine::startPositions(int32 startNumber) { compact = (BsObject*)_objectMan->fetchObject(PLAYER); _logic->fnEnterSection(compact, PLAYER, startNumber, 0, 0, 0, 0, 0); // (automatically opens the compact resource for that section) _systemVars.deathScreenFlag = 0; + _systemVars.wantFade = true; } void SwordEngine::go(void) { @@ -1055,6 +1056,8 @@ void SwordEngine::go(void) { reinitialize(); if (action == CONTROL_GAME_RESTORED) _control->doRestore(); + else if (action == CONTROL_RESTART_GAME) + startPositions(1); _systemVars.forceRestart = false; _systemVars.deathScreenFlag = 0; } while (true); @@ -1108,7 +1111,7 @@ uint8 SwordEngine::mainLoop(void) { if (_systemVars.forceRestart) retCode = CONTROL_RESTART_GAME; - else if (_keyPressed == 63) { + else if (((_keyPressed == 63) && (SwordLogic::_scriptVars[MOUSE_STATUS] & 1)) || (_systemVars.deathScreenFlag)) { retCode = _control->runPanel(); if (!retCode) _screen->refreshPalette(); |