diff options
author | David Corrales | 2007-06-23 18:51:33 +0000 |
---|---|---|
committer | David Corrales | 2007-06-23 18:51:33 +0000 |
commit | cacd7a28fd51d960947de88abbf30c487e66529d (patch) | |
tree | f3baa59853bfb307e452b86b9d93c4737b1fa6ab /engines/sword1 | |
parent | 0ac96302fe9c04df79cb01a77d19535b45fe2db0 (diff) | |
parent | 90c2210dae8c91fa8babc6b05564e15c9d445d18 (diff) | |
download | scummvm-rg350-cacd7a28fd51d960947de88abbf30c487e66529d.tar.gz scummvm-rg350-cacd7a28fd51d960947de88abbf30c487e66529d.tar.bz2 scummvm-rg350-cacd7a28fd51d960947de88abbf30c487e66529d.zip |
Merged the FSNode branch with trunk r27031:27680
svn-id: r27681
Diffstat (limited to 'engines/sword1')
-rw-r--r-- | engines/sword1/animation.cpp | 4 | ||||
-rw-r--r-- | engines/sword1/control.cpp | 70 | ||||
-rw-r--r-- | engines/sword1/control.h | 7 | ||||
-rw-r--r-- | engines/sword1/music.cpp | 15 | ||||
-rw-r--r-- | engines/sword1/sword1.cpp | 14 | ||||
-rw-r--r-- | engines/sword1/sword1.h | 3 |
6 files changed, 61 insertions, 52 deletions
diff --git a/engines/sword1/animation.cpp b/engines/sword1/animation.cpp index d66db9347d..d54968daeb 100644 --- a/engines/sword1/animation.cpp +++ b/engines/sword1/animation.cpp @@ -295,7 +295,7 @@ void MoviePlayer::play(void) { handleScreenChanged(); break; case Common::EVENT_KEYDOWN: - if (event.kbd.keycode == 27) { + if (event.kbd.keycode == Common::KEYCODE_ESCAPE) { _snd->stopHandle(_bgSoundHandle); terminated = true; } @@ -410,7 +410,7 @@ bool MoviePlayerDXA::load(uint32 id) { snprintf(filename, sizeof(filename), "%s.dxa", sequenceList[id]); if (loadFile(filename)) { // The Broken Sword games always use external audio tracks. - if (_fd.readUint32BE() != MKID_BE('NULL')) + if (_fd->readUint32BE() != MKID_BE('NULL')) return false; _frameWidth = getWidth(); _frameHeight = getHeight(); diff --git a/engines/sword1/control.cpp b/engines/sword1/control.cpp index e40db20f37..1ebfaedb2e 100644 --- a/engines/sword1/control.cpp +++ b/engines/sword1/control.cpp @@ -204,7 +204,7 @@ void Control::askForCd(void) { _system->copyRectToScreen(_screenBuf, 640, 0, 0, 640, 480); } delay(300); - if (_keyPressed) { + if (_keyPressed.keycode) { if (!Common::File::exists(fName)) { memset(_screenBuf, 0, 640 * 480); renderText(_lStrings[STR_INCORRECT_CD], 320, 230, TEXT_CENTER); @@ -224,7 +224,8 @@ void Control::askForCd(void) { uint8 Control::runPanel(void) { _mouseDown = false; _restoreBuf = NULL; - _keyPressed = _numButtons = 0; + _keyPressed.reset(); + _numButtons = 0; _screenBuf = (uint8*)malloc(640 * 480); memset(_screenBuf, 0, 640 * 480); _system->copyRectToScreen(_screenBuf, 640, 0, 0, 640, 480); @@ -283,7 +284,7 @@ uint8 Control::runPanel(void) { _cursorVisible = false; _cursorTick = 0; } - if (_keyPressed) + if (_keyPressed.keycode) handleSaveKey(_keyPressed); else if (_cursorVisible != visible) showSavegameNames(); @@ -328,10 +329,9 @@ uint8 Control::getClicks(uint8 mode, uint8 *retVal) { } uint8 flag = 0; - if (_keyPressed == 27) + if (_keyPressed.keycode == Common::KEYCODE_ESCAPE) flag = kButtonCancel; - // 3 is num keypad Enter on Macs. See FR #1273746 - else if (_keyPressed == '\r' || _keyPressed == '\n' || _keyPressed == 3) + else if (_keyPressed.keycode == Common::KEYCODE_RETURN || _keyPressed.keycode == Common::KEYCODE_KP_ENTER) flag = kButtonOk; if (flag) { @@ -622,9 +622,9 @@ bool Control::getConfirm(const uint8 *title) { buttons[0]->draw(); buttons[1]->draw(); delay(1000 / 12); - if (_keyPressed == 27) + if (_keyPressed.keycode == Common::KEYCODE_ESCAPE) retVal = 2; - else if (_keyPressed == '\r' || _keyPressed == '\n') + else if (_keyPressed.keycode == Common::KEYCODE_RETURN || _keyPressed.keycode == Common::KEYCODE_KP_ENTER) retVal = 1; if (_mouseState & BS1L_BUTTON_DOWN) { if (buttons[0]->wasClicked(_mouseX, _mouseY)) @@ -649,7 +649,7 @@ bool Control::getConfirm(const uint8 *title) { return retVal == 1; } -bool Control::keyAccepted(uint8 key) { +bool Control::keyAccepted(uint16 ascii) { // this routine needs changes for Czech keys... No idea how to do that, though. // FIXME: It is not a good idea to put non-ASCII chars into a C source file, // since there is no way to specify which encoding you are using. @@ -658,22 +658,22 @@ bool Control::keyAccepted(uint8 key) { // do not at all specify which encoding keyboard events use, so this // check here is probably not portable anyway... static const char allowedSpecials[] = "éèáàúùäöüÄÖÜß,.:-()?! \"\'"; - if (((key >= 'A') && (key <= 'Z')) || - ((key >= 'a') && (key <= 'z')) || - ((key >= '0') && (key <= '9')) || - strchr(allowedSpecials, key)) + if (((ascii >= 'A') && (ascii <= 'Z')) || + ((ascii >= 'a') && (ascii <= 'z')) || + ((ascii >= '0') && (ascii <= '9')) || + strchr(allowedSpecials, ascii)) return true; else return false; } -void Control::handleSaveKey(uint8 key) { +void Control::handleSaveKey(Common::KeyState kbd) { if (_selectedSavegame < 255) { uint8 len = strlen((char*)_saveNames[_selectedSavegame]); - if ((key == 8) && len) // backspace + if ((kbd.keycode == Common::KEYCODE_BACKSPACE) && len) // backspace _saveNames[_selectedSavegame][len - 1] = '\0'; - else if (keyAccepted(key) && (len < 31)) { - _saveNames[_selectedSavegame][len] = key; + else if (keyAccepted(kbd.ascii) && (len < 31)) { + _saveNames[_selectedSavegame][len] = kbd.ascii; _saveNames[_selectedSavegame][len + 1] = '\0'; } showSavegameNames(); @@ -700,6 +700,9 @@ void Control::readSavegameDescriptions(void) { inf = _saveFileMan->openForLoading("SAVEGAME.INF"); _saveScrollPos = _saveFiles = 0; _selectedSavegame = 255; + for (uint8 cnt = 0; cnt < 64; cnt++) { + memset(_saveNames[cnt], 0, sizeof(_saveNames[cnt])); + } if (inf) { uint8 curFileNum = 0; uint8 ch; @@ -707,20 +710,18 @@ void Control::readSavegameDescriptions(void) { uint8 pos = 0; do { ch = inf->readByte(); - if ((ch == 10) || (ch == 255)) - _saveNames[curFileNum][pos] = '\0'; - else - _saveNames[curFileNum][pos] = ch; - pos++; - } while ((ch != 10) && (ch != 255)); - curFileNum++; - } while (ch != 255); + if (pos < sizeof(_saveNames[curFileNum]) - 1) { + if ((ch == 10) || (ch == 255) || (inf->eos())) + _saveNames[curFileNum][pos++] = '\0'; + else if (ch >= 32) + _saveNames[curFileNum][pos++] = ch; + } + } while ((ch != 10) && (ch != 255) && (!inf->eos())); + if (_saveNames[curFileNum][0] != 0) + curFileNum++; + } while ((ch != 255) && (!inf->eos())); _saveFiles = curFileNum; - for (uint8 cnt = _saveFiles; cnt < 64; cnt++) - _saveNames[cnt][0] = '\0'; - } else - for (uint8 cnt = 0; cnt < 64; cnt++) - _saveNames[cnt][0] = '\0'; + } delete inf; } @@ -1036,7 +1037,7 @@ void Control::delay(uint32 msecs) { uint32 now = _system->getMillis(); uint32 endTime = now + msecs; - _keyPressed = 0; //reset + _keyPressed.reset(); _mouseState = 0; do { @@ -1044,12 +1045,7 @@ void Control::delay(uint32 msecs) { while (eventMan->pollEvent(event)) { switch (event.type) { case Common::EVENT_KEYDOWN: - - // Make sure backspace works right (this fixes a small issue on OS X) - if (event.kbd.keycode == 8) - _keyPressed = 8; - else - _keyPressed = (byte)event.kbd.ascii; + _keyPressed = event.kbd; // we skip the rest of the delay and return immediately // to handle keyboard input return; diff --git a/engines/sword1/control.h b/engines/sword1/control.h index 89ea7199b6..1825350170 100644 --- a/engines/sword1/control.h +++ b/engines/sword1/control.h @@ -27,6 +27,7 @@ #define SWORD1_CONTROL_H #include "common/scummsys.h" +#include "common/events.h" #include "sword1/sworddefs.h" class OSystem; @@ -118,8 +119,8 @@ private: void saveNameSelect(uint8 id, bool saving); bool saveToFile(void); bool restoreFromFile(void); - bool keyAccepted(uint8 key); - void handleSaveKey(uint8 key); + bool keyAccepted(uint16 ascii); + void handleSaveKey(Common::KeyState kbd); void renderVolumeBar(uint8 id, uint8 volL, uint8 volR); uint16 getTextWidth(const uint8 *str); @@ -141,7 +142,7 @@ private: Sound *_sound; uint8 *_font, *_redFont; uint8 *_screenBuf; - uint8 _keyPressed; + Common::KeyState _keyPressed; void delay(uint32 msecs); uint16 _mouseX, _mouseY, _mouseState; bool _mouseDown; diff --git a/engines/sword1/music.cpp b/engines/sword1/music.cpp index 67a390802b..ebff7f9929 100644 --- a/engines/sword1/music.cpp +++ b/engines/sword1/music.cpp @@ -31,6 +31,7 @@ #include "sword1/music.h" #include "sound/aiff.h" +#include "sound/flac.h" #include "sound/mixer.h" #include "sound/mp3.h" #include "sound/vorbis.h" @@ -201,7 +202,19 @@ int AiffAudioStream::readBuffer(int16 *buffer, const int numSamples) { bool MusicHandle::play(const char *fileBase, bool loop) { char fileName[30]; stop(); - + +#ifdef USE_FLAC + if (!_audioSource) { + sprintf(fileName, "%s.flac", fileBase); + if (_file.open(fileName)) + _audioSource = Audio::makeFlacStream(&_file, false, 0, 0, loop ? 0 : 1); + } + if (!_audioSource) { + sprintf(fileName, "%s.fla", fileBase); + if (_file.open(fileName)) + _audioSource = Audio::makeFlacStream(&_file, false, 0, 0, loop ? 0 : 1); + } +#endif #ifdef USE_VORBIS if (!_audioSource) { sprintf(fileName, "%s.ogg", fileBase); diff --git a/engines/sword1/sword1.cpp b/engines/sword1/sword1.cpp index db978cd33e..d899d25df5 100644 --- a/engines/sword1/sword1.cpp +++ b/engines/sword1/sword1.cpp @@ -635,7 +635,7 @@ void SwordEngine::checkCd(void) { uint8 SwordEngine::mainLoop(void) { uint8 retCode = 0; - _keyPressed = 0; + _keyPressed.reset(); while ((retCode == 0) && (!_systemVars.engineQuit)) { // do we need the section45-hack from sword.c here? @@ -678,12 +678,14 @@ uint8 SwordEngine::mainLoop(void) { // The control panel is triggered by F5 or ESC. // FIXME: This is a very strange way of detecting F5... - else if (((_keyPressed == 63 || _keyPressed == 27) && (Logic::_scriptVars[MOUSE_STATUS] & 1)) || (_systemVars.controlPanelMode)) { + else if (((_keyPressed.keycode == Common::KEYCODE_F5 || _keyPressed.keycode == Common::KEYCODE_ESCAPE) + && (Logic::_scriptVars[MOUSE_STATUS] & 1)) || (_systemVars.controlPanelMode)) { retCode = _control->runPanel(); if (!retCode) _screen->fullRefresh(); } - _mouseState = _keyPressed = 0; + _mouseState = 0; + _keyPressed.reset(); } while ((Logic::_scriptVars[SCREEN] == Logic::_scriptVars[NEW_SCREEN]) && (retCode == 0) && (!_systemVars.engineQuit)); if ((retCode == 0) && (Logic::_scriptVars[SCREEN] != 53) && _systemVars.wantFade && (!_systemVars.engineQuit)) { @@ -712,11 +714,7 @@ void SwordEngine::delay(int32 amount) { //copied and mutilated from sky.cpp while (_eventMan->pollEvent(event)) { switch (event.type) { case Common::EVENT_KEYDOWN: - // Make sure backspace works right (this fixes a small issue on OS X) - if (event.kbd.keycode == 8) - _keyPressed = 8; - else - _keyPressed = (uint8)event.kbd.ascii; + _keyPressed = event.kbd; break; case Common::EVENT_MOUSEMOVE: _mouseX = event.mouse.x; diff --git a/engines/sword1/sword1.h b/engines/sword1/sword1.h index 1ced01d6ef..7065b5498a 100644 --- a/engines/sword1/sword1.h +++ b/engines/sword1/sword1.h @@ -27,6 +27,7 @@ #define SWORD1_H #include "engines/engine.h" +#include "common/events.h" #include "common/util.h" #include "sword1/sworddefs.h" @@ -92,7 +93,7 @@ private: uint8 mainLoop(void); uint16 _mouseX, _mouseY, _mouseState; - uint8 _keyPressed; + Common::KeyState _keyPressed; ResMan *_resMan; ObjectMan *_objectMan; |