Ticket #8058: cd-timer2.diff

File cd-timer2.diff, 4.8 KB (added by eriktorbjorn, 22 years ago)

Updated patch against a September 20 CVS snapshot

  • scummvm/scumm/saveload.cpp

    diff -ur ScummVM-cvs20020920/scummvm/scumm/saveload.cpp ScummVM-cvs20020920+hack/scummvm/scumm/saveload.cpp
    old new  
    159159
    160160        initBGBuffers(_scrHeight);
    161161
     162        if ((_features & GF_AUDIOTRACKS) && _vars[VAR_MI1_TIMER] > 0)
     163                _sound->startCDTimer();
     164
    162165        CHECK_HEAP debug(1, "State loaded from '%s'", filename);
    163166
    164167
  • scummvm/scumm/scummvm.cpp

    diff -ur ScummVM-cvs20020920/scummvm/scumm/scummvm.cpp ScummVM-cvs20020920+hack/scummvm/scumm/scummvm.cpp
    old new  
    340340
    341341int Scumm::scummLoop(int delta)
    342342{
    343         static int counter = 0;
    344 
    345343#ifndef _WIN32_WCE
    346344        if (_debugger)
    347345                _debugger->on_frame();
     
    380378        _vars[VAR_MOUSE_Y] = mouse.y;
    381379        _vars[VAR_DEBUGMODE] = _debugMode;
    382380
    383         if (_features & GF_AUDIOTRACKS) {               
    384                 if (delta) {
    385                         if (delta == 1) {
    386                                 // Better sync with the Loom CD intro
    387                                 _vars[VAR_MI1_TIMER]++;
    388                         } else if (++counter != 2)
    389                                 _vars[VAR_MI1_TIMER] += 5;
    390                         else {
    391                                 counter = 0;
    392                                 _vars[VAR_MI1_TIMER] += 6;
    393                         }                               
    394                 }
     381        if (_features & GF_AUDIOTRACKS) {
     382                _vars[VAR_MI1_TIMER] = _sound->readCDTimer();
    395383        } else if (_features & GF_OLD256) {
    396384
    397385                if(tempMusic == 3) {
  • scummvm/scumm/sound.cpp

    diff -ur ScummVM-cvs20020920/scummvm/scumm/sound.cpp ScummVM-cvs20020920+hack/scummvm/scumm/sound.cpp
    old new  
    667667
    668668        _soundsPaused = pause;
    669669        _scumm->_mixer->pause(pause);   
     670
     671        if ((_scumm->_features & GF_AUDIOTRACKS) && _scumm->_vars[_scumm->VAR_MI1_TIMER] > 0) {
     672                if (pause)
     673                        stopCDTimer();
     674                else
     675                        startCDTimer();
     676        }
     677               
    670678}
    671679
    672680int Sound::startSfxSound(File *file, int file_size) {
     
    10281036        return -1;
    10291037}
    10301038
     1039// We use a real timer in an attempt to get better sync with CD tracks. This is
     1040// necessary for games like Loom CD.
     1041
     1042static void cd_timer_handler(void *ptr)
     1043{
     1044        Scumm *scumm = (Scumm *) ptr;
     1045
     1046        // Maybe I could simply update _vars[VAR_MI1_TIMER] directly here, but
     1047        // I don't feel comfortable just doing that from what might be a
     1048        // separate thread. If someone tells me it's safe, I'll make the
     1049        // change right away.
     1050       
     1051        // FIXME: Turn off the timer when it's no longer needed. In theory, it
     1052        // should be possible to check with pollCD(), but since CD sound isn't
     1053        // properly restarted when reloading a saved game, I don't dare to.
     1054
     1055        scumm->_sound->_cd_timer_value += 6;
     1056}
     1057
     1058int Sound::readCDTimer()
     1059{
     1060        return _cd_timer_value;
     1061}
     1062
     1063void Sound::startCDTimer()
     1064{
     1065        int timer_interval;
     1066
     1067        // The timer interval has been tuned for Loom CD and the Monkey 1
     1068        // intro. I have to use 100 for Loom, or there will be a nasty stutter
     1069        // when Chaos first appears, and I have to use 101 for Monkey 1 or the
     1070        // intro music will be cut short.
     1071
     1072        if (_scumm->_gameId == GID_LOOM256)
     1073                timer_interval = 100;
     1074        else
     1075                timer_interval = 101;
     1076
     1077        _scumm->_timer->releaseProcedure(&cd_timer_handler);
     1078        _cd_timer_value = _scumm->_vars[_scumm->VAR_MI1_TIMER];
     1079        _scumm->_timer->installProcedure(&cd_timer_handler, timer_interval);
     1080}
     1081
     1082void Sound::stopCDTimer()
     1083{
     1084        _scumm->_timer->releaseProcedure(&cd_timer_handler);
     1085}
     1086
    10311087void Sound::playCDTrack(int track, int num_loops, int start, int delay)
    10321088{
    10331089#ifdef COMPRESSED_SOUND_FILE
    10341090        if (playMP3CDTrack(track, num_loops, start, delay) == -1)
    10351091#endif
    10361092                _scumm->_system->play_cdrom(track, num_loops, start, delay);
     1093
     1094        // Start the timer after starting the track. Starting an MP3 track is
     1095        // almost instantaneous, but a CD player may take some time. Hopefully
     1096        // play_cdrom() will block during that delay.
     1097
     1098        startCDTimer();
    10371099}
    10381100
    10391101void Sound::stopCD()
    10401102{
     1103        stopCDTimer();
    10411104#ifdef COMPRESSED_SOUND_FILE
    10421105        if (stopMP3CD() == -1)
    10431106#endif
  • scummvm/scumm/sound.h

    diff -ur ScummVM-cvs20020920/scummvm/scumm/sound.h ScummVM-cvs20020920+hack/scummvm/scumm/sound.h
    old new  
    2323
    2424#include "scummsys.h"
    2525#include "sound/mixer.h"
     26#include "common/timer.h"
    2627
    2728class Scumm;
    2829class File;
     
    8889
    8990#endif
    9091
     92        int _cd_timer_value;
    9193        bool _soundsPaused;
    9294        int16 _sound_volume_master, _sound_volume_music, _sound_volume_sfx;
    9395        byte _sfxMode;
     
    124126        int playSfxSound(void *sound, uint32 size, uint rate, bool isUnsigned);
    125127        int playSfxSound_MP3(void *sound, uint32 size);
    126128
     129        int readCDTimer();
     130        void startCDTimer();
     131        void stopCDTimer();
     132
    127133        void playCDTrack(int track, int num_loops, int start, int delay);
    128134        void stopCD();
    129135        int pollCD();