Ticket #8058: cd-timer2.diff
File cd-timer2.diff, 4.8 KB (added by , 22 years ago) |
---|
-
scummvm/scumm/saveload.cpp
diff -ur ScummVM-cvs20020920/scummvm/scumm/saveload.cpp ScummVM-cvs20020920+hack/scummvm/scumm/saveload.cpp
old new 159 159 160 160 initBGBuffers(_scrHeight); 161 161 162 if ((_features & GF_AUDIOTRACKS) && _vars[VAR_MI1_TIMER] > 0) 163 _sound->startCDTimer(); 164 162 165 CHECK_HEAP debug(1, "State loaded from '%s'", filename); 163 166 164 167 -
scummvm/scumm/scummvm.cpp
diff -ur ScummVM-cvs20020920/scummvm/scumm/scummvm.cpp ScummVM-cvs20020920+hack/scummvm/scumm/scummvm.cpp
old new 340 340 341 341 int Scumm::scummLoop(int delta) 342 342 { 343 static int counter = 0;344 345 343 #ifndef _WIN32_WCE 346 344 if (_debugger) 347 345 _debugger->on_frame(); … … 380 378 _vars[VAR_MOUSE_Y] = mouse.y; 381 379 _vars[VAR_DEBUGMODE] = _debugMode; 382 380 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(); 395 383 } else if (_features & GF_OLD256) { 396 384 397 385 if(tempMusic == 3) { -
scummvm/scumm/sound.cpp
diff -ur ScummVM-cvs20020920/scummvm/scumm/sound.cpp ScummVM-cvs20020920+hack/scummvm/scumm/sound.cpp
old new 667 667 668 668 _soundsPaused = pause; 669 669 _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 670 678 } 671 679 672 680 int Sound::startSfxSound(File *file, int file_size) { … … 1028 1036 return -1; 1029 1037 } 1030 1038 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 1042 static 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 1058 int Sound::readCDTimer() 1059 { 1060 return _cd_timer_value; 1061 } 1062 1063 void 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 1082 void Sound::stopCDTimer() 1083 { 1084 _scumm->_timer->releaseProcedure(&cd_timer_handler); 1085 } 1086 1031 1087 void Sound::playCDTrack(int track, int num_loops, int start, int delay) 1032 1088 { 1033 1089 #ifdef COMPRESSED_SOUND_FILE 1034 1090 if (playMP3CDTrack(track, num_loops, start, delay) == -1) 1035 1091 #endif 1036 1092 _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(); 1037 1099 } 1038 1100 1039 1101 void Sound::stopCD() 1040 1102 { 1103 stopCDTimer(); 1041 1104 #ifdef COMPRESSED_SOUND_FILE 1042 1105 if (stopMP3CD() == -1) 1043 1106 #endif -
scummvm/scumm/sound.h
diff -ur ScummVM-cvs20020920/scummvm/scumm/sound.h ScummVM-cvs20020920+hack/scummvm/scumm/sound.h
old new 23 23 24 24 #include "scummsys.h" 25 25 #include "sound/mixer.h" 26 #include "common/timer.h" 26 27 27 28 class Scumm; 28 29 class File; … … 88 89 89 90 #endif 90 91 92 int _cd_timer_value; 91 93 bool _soundsPaused; 92 94 int16 _sound_volume_master, _sound_volume_music, _sound_volume_sfx; 93 95 byte _sfxMode; … … 124 126 int playSfxSound(void *sound, uint32 size, uint rate, bool isUnsigned); 125 127 int playSfxSound_MP3(void *sound, uint32 size); 126 128 129 int readCDTimer(); 130 void startCDTimer(); 131 void stopCDTimer(); 132 127 133 void playCDTrack(int track, int num_loops, int start, int delay); 128 134 void stopCD(); 129 135 int pollCD();