int PlayMusicQueued(int musnum) { // Just get the queue size if (musnum < 0) return play.music_queue_size; if ((IsMusicPlaying() == 0) && (play.music_queue_size == 0)) { newmusic(musnum); return 0; } if (play.music_queue_size >= MAX_QUEUED_MUSIC) { debug_script_log("Too many queued music, cannot add %d", musnum); return 0; } if ((play.music_queue_size > 0) && (play.music_queue[play.music_queue_size - 1] >= QUEUED_MUSIC_REPEAT)) { quit("!PlayMusicQueued: cannot queue music after a repeating tune has been queued"); } if (play.music_repeat) { debug_script_log("Queuing music %d to loop", musnum); musnum += QUEUED_MUSIC_REPEAT; } else { debug_script_log("Queuing music %d", musnum); } play.music_queue[play.music_queue_size] = musnum; play.music_queue_size++; if (play.music_queue_size == 1) { clear_music_cache(); cachedQueuedMusic = load_music_from_disk(musnum, (play.music_repeat > 0)); } return play.music_queue_size; }
// Final processing after successfully restoring from save HSaveError DoAfterRestore(const PreservedParams &pp, const RestoredData &r_data) { // Preserve whether the music vox is available play.separate_music_lib = pp.MusicVOX; // If they had the vox when they saved it, but they don't now if ((pp.SpeechVOX < 0) && (play.want_speech >= 0)) play.want_speech = (-play.want_speech) - 1; // If they didn't have the vox before, but now they do else if ((pp.SpeechVOX >= 0) && (play.want_speech < 0)) play.want_speech = (-play.want_speech) - 1; // recache queued clips for (int i = 0; i < play.new_music_queue_size; ++i) { play.new_music_queue[i].cachedClip = NULL; } // restore these to the ones retrieved from the save game const size_t dynsurf_num = Math::Min((size_t)MAX_DYNAMIC_SURFACES, r_data.DynamicSurfaces.size()); for (size_t i = 0; i < dynsurf_num; ++i) { dynamicallyCreatedSurfaces[i] = r_data.DynamicSurfaces[i]; } for (int i = 0; i < game.numgui; ++i) export_gui_controls(i); update_gui_zorder(); if (create_global_script()) { return new SavegameError(kSvgErr_GameObjectInitFailed, String::FromFormat("Unable to recreate global script: %s", ccErrorString.GetCStr())); } // read the global data into the newly created script if (r_data.GlobalScript.Data.get()) memcpy(gameinst->globaldata, r_data.GlobalScript.Data.get(), Math::Min((size_t)gameinst->globaldatasize, r_data.GlobalScript.Len)); // restore the script module data for (int i = 0; i < numScriptModules; ++i) { if (r_data.ScriptModules[i].Data.get()) memcpy(moduleInst[i]->globaldata, r_data.ScriptModules[i].Data.get(), Math::Min((size_t)moduleInst[i]->globaldatasize, r_data.ScriptModules[i].Len)); } setup_player_character(game.playercharacter); // Save some parameters to restore them after room load int gstimer=play.gscript_timer; int oldx1 = play.mboundx1, oldx2 = play.mboundx2; int oldy1 = play.mboundy1, oldy2 = play.mboundy2; // disable the queue momentarily int queuedMusicSize = play.music_queue_size; play.music_queue_size = 0; update_polled_stuff_if_runtime(); // load the room the game was saved in if (displayed_room >= 0) load_new_room(displayed_room, NULL); update_polled_stuff_if_runtime(); play.gscript_timer=gstimer; // restore the correct room volume (they might have modified // it with SetMusicVolume) thisroom.Options.MusicVolume = r_data.RoomVolume; Mouse::SetMoveLimit(Rect(oldx1, oldy1, oldx2, oldy2)); set_cursor_mode(r_data.CursorMode); set_mouse_cursor(r_data.CursorID); if (r_data.CursorMode == MODE_USE) SetActiveInventory(playerchar->activeinv); // ensure that the current cursor is locked spriteset.Precache(game.mcurs[r_data.CursorID].pic); #if (ALLEGRO_DATE > 19990103) set_window_title(play.game_name); #endif update_polled_stuff_if_runtime(); if (displayed_room >= 0) { for (int i = 0; i < MAX_ROOM_BGFRAMES; ++i) { if (r_data.RoomBkgScene[i]) { thisroom.BgFrames[i].Graphic = r_data.RoomBkgScene[i]; } } in_new_room=3; // don't run "enters screen" events // now that room has loaded, copy saved light levels in for (size_t i = 0; i < MAX_ROOM_REGIONS; ++i) { thisroom.Regions[i].Light = r_data.RoomLightLevels[i]; thisroom.Regions[i].Tint = r_data.RoomTintLevels[i]; } generate_light_table(); for (size_t i = 0; i < MAX_WALK_AREAS + 1; ++i) { thisroom.WalkAreas[i].ScalingFar = r_data.RoomZoomLevels1[i]; thisroom.WalkAreas[i].ScalingNear = r_data.RoomZoomLevels2[i]; } on_background_frame_change(); } gui_disabled_style = convert_gui_disabled_style(game.options[OPT_DISABLEOFF]); // restore the queue now that the music is playing play.music_queue_size = queuedMusicSize; if (play.digital_master_volume >= 0) System_SetVolume(play.digital_master_volume); // Run audio clips on channels // these two crossfading parameters have to be temporarily reset const int cf_in_chan = play.crossfading_in_channel; const int cf_out_chan = play.crossfading_out_channel; play.crossfading_in_channel = 0; play.crossfading_out_channel = 0; // NOTE: channels are array of MAX_SOUND_CHANNELS+1 size for (int i = 0; i <= MAX_SOUND_CHANNELS; ++i) { const RestoredData::ChannelInfo &chan_info = r_data.AudioChans[i]; if (chan_info.ClipID < 0) continue; if (chan_info.ClipID >= game.audioClipCount) { return new SavegameError(kSvgErr_GameObjectInitFailed, String::FromFormat("Invalid audio clip index: %d (clip count: %d).", chan_info.ClipID, game.audioClipCount)); } play_audio_clip_on_channel(i, &game.audioClips[chan_info.ClipID], chan_info.Priority, chan_info.Repeat, chan_info.Pos); if (channels[i] != NULL) { channels[i]->set_volume_direct(chan_info.VolAsPercent, chan_info.Vol); channels[i]->set_speed(chan_info.Speed); channels[i]->set_panning(chan_info.Pan); channels[i]->panningAsPercentage = chan_info.PanAsPercent; } } if ((cf_in_chan > 0) && (channels[cf_in_chan] != NULL)) play.crossfading_in_channel = cf_in_chan; if ((cf_out_chan > 0) && (channels[cf_out_chan] != NULL)) play.crossfading_out_channel = cf_out_chan; // If there were synced audio tracks, the time taken to load in the // different channels will have thrown them out of sync, so re-time it // NOTE: channels are array of MAX_SOUND_CHANNELS+1 size for (int i = 0; i <= MAX_SOUND_CHANNELS; ++i) { int pos = r_data.AudioChans[i].Pos; if ((pos > 0) && (channels[i] != NULL) && (channels[i]->done == 0)) { channels[i]->seek(pos); } } // TODO: investigate loop range for (int i = 1; i < MAX_SOUND_CHANNELS; ++i) { if (r_data.DoAmbient[i]) PlayAmbientSound(i, r_data.DoAmbient[i], ambient[i].vol, ambient[i].x, ambient[i].y); } for (int i = 0; i < game.numgui; ++i) { guibg[i] = BitmapHelper::CreateBitmap(guis[i].Width, guis[i].Height, game.GetColorDepth()); guibg[i] = ReplaceBitmapWithSupportedFormat(guibg[i]); } recreate_overlay_ddbs(); guis_need_update = 1; play.ignore_user_input_until_time = 0; update_polled_stuff_if_runtime(); pl_run_plugin_hooks(AGSE_POSTRESTOREGAME, 0); if (displayed_room < 0) { // the restart point, no room was loaded load_new_room(playerchar->room, playerchar); playerchar->prevroom = -1; first_room_initialization(); } if ((play.music_queue_size > 0) && (cachedQueuedMusic == NULL)) { cachedQueuedMusic = load_music_from_disk(play.music_queue[0], 0); } // test if the playing music was properly loaded if (current_music_type > 0) { if (crossFading > 0 && !channels[crossFading] || crossFading <= 0 && !channels[SCHAN_MUSIC]) { current_music_type = 0; } } set_game_speed(r_data.FPS); return HSaveError::None(); }