Ticket #8038: fadefix2.diff

File fadefix2.diff, 2.7 KB (added by eriktorbjorn, 23 years ago)

Improved (?) patch against a September 10 CVS snapshot

  • scummvm/scumm/imuse.cpp

    diff -ur ScummVM-cvs20020910/scummvm/scumm/imuse.cpp ScummVM-cvs20020910+hack/scummvm/scumm/imuse.cpp
    old new  
    170170        int query_param(int param);
    171171
    172172        int fade_vol(byte vol, int time);
     173        bool is_fading_out();
    173174        void sequencer_timer();
    174175};
    175176
     
    185186
    186187        void initialize() {
    187188                active = false;
    188         } void on_timer();
     189        }
     190        void on_timer(bool probe);
     191        byte fading_to();
    189192};
    190193
    191194struct SustainingNotes {
     
    11341137        for (i = ARRAYSIZE(_volume_fader); i != 0; i--, vf++) {
    11351138                if (vf->active) {
    11361139                        _active_volume_faders = true;
    1137                         vf->on_timer();
     1140                        vf->on_timer(false);
    11381141                }
    11391142        }
    11401143}
    11411144
    1142 void VolumeFader::on_timer()
     1145void VolumeFader::on_timer(bool probe)
    11431146{
    11441147        byte newvol;
    11451148
     
    11521155        }
    11531156
    11541157        if (curvol != newvol) {
     1158                curvol = newvol;
    11551159                if (!newvol) {
    1156                         player->clear();
     1160                        if (!probe)
     1161                                player->clear();
    11571162                        active = false;
    11581163                        return;
    11591164                }
    1160                 curvol = newvol;
    1161                 player->set_vol(newvol);
     1165                if (!probe)
     1166                        player->set_vol(newvol);
    11621167        }
    11631168
    11641169        if (!--num_steps) {
     
    11661171        }
    11671172}
    11681173
     1174byte VolumeFader::fading_to()
     1175{
     1176        byte newvol;
     1177        byte orig_curvol;
     1178        uint16 orig_speed_lo_counter, orig_num_steps;
     1179
     1180        if (!active)
     1181                return 127;
     1182
     1183        // It would be so much easier to just store the fade-to volume in a
     1184        // variable, but then we'd have to break savegame compatibility. So
     1185        // instead we do a "dry run" fade.
     1186
     1187        orig_speed_lo_counter = speed_lo_counter;
     1188        orig_num_steps = num_steps;
     1189        orig_curvol = curvol;
     1190
     1191        while (active)
     1192                on_timer(true);
     1193
     1194        active = true;
     1195        newvol = curvol;
     1196
     1197        speed_lo_counter = orig_speed_lo_counter;
     1198        num_steps = orig_num_steps;
     1199        curvol = orig_curvol;
     1200
     1201        return newvol;
     1202}
     1203
    11691204int IMuseInternal::get_sound_status(int sound)
    11701205{
    11711206        int i;
    11721207        Player *player;
    11731208
    11741209        for (i = ARRAYSIZE(_players), player = _players; i != 0; i--, player++) {
    1175                 if (player->_active && player->_id == (uint16)sound)
     1210                if (player->_active && player->_id == (uint16)sound) {
     1211                        // Assume that anyone asking for the sound status is
     1212                        // really asking "is it ok if I start playing this
     1213                        // sound now?" So if the sound is about to fade out,
     1214                        // shut it down and pretend it wasn't playing.
     1215                        if (player->is_fading_out()) {
     1216                                player->clear();
     1217                                continue;
     1218                        }
    11761219                        return 1;
     1220                }
    11771221        }
    11781222        return get_queue_sound_status(sound);
    11791223}
     
    17811825        return 0;
    17821826}
    17831827
     1828bool Player::is_fading_out()
     1829{
     1830        VolumeFader *vf = _se->_volume_fader;
     1831        int i;
     1832
     1833        for (i = 0; i < 8; i++, vf++) {
     1834                if (vf->active && vf->direction < 0 && vf->player == this && vf->fading_to() == 0)
     1835                        return true;
     1836        }
     1837        return false;
     1838}
     1839
    17841840void Player::clear()
    17851841{
    17861842        uninit_seq();