From 62f596821e7c1e8c696cb3e4190822b33aa1a98c Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sun, 7 Jun 2009 17:07:07 +0000 Subject: SCI: Objectified Song struct 'a bit' svn-id: r41344 --- engines/sci/sfx/core.cpp | 2 +- engines/sci/sfx/songlib.cpp | 59 ++++++++++++++++++++++++++++----------------- engines/sci/sfx/songlib.h | 27 +++++++++++---------- 3 files changed, 52 insertions(+), 36 deletions(-) (limited to 'engines') diff --git a/engines/sci/sfx/core.cpp b/engines/sci/sfx/core.cpp index 57561672d3..572da29c0d 100644 --- a/engines/sci/sfx/core.cpp +++ b/engines/sci/sfx/core.cpp @@ -824,7 +824,7 @@ void SfxState::sfx_add_song(SongIterator *it, int priority, SongHandle handle, i } - song = song_new(handle, it, priority); + song = new Song(handle, it, priority); song->_resourceNum = number; song->_hold = 0; song->_loops = 0; diff --git a/engines/sci/sfx/songlib.cpp b/engines/sci/sfx/songlib.cpp index 8fafe4a7f3..2572dc01f5 100644 --- a/engines/sci/sfx/songlib.cpp +++ b/engines/sci/sfx/songlib.cpp @@ -31,27 +31,42 @@ namespace Sci { #define debug_stream stderr -Song *song_new(SongHandle handle, SongIterator *it, int priority) { - Song *retval; - retval = (Song *)malloc(sizeof(Song)); - -#ifdef SATISFY_PURIFY - memset(retval, 0, sizeof(Song)); -#endif - - retval->_handle = handle; - retval->_priority = priority; - retval->_next = NULL; - retval->_delay = 0; - retval->_wakeupTime = Audio::Timestamp(); - retval->_it = it; - retval->_status = SOUND_STATUS_STOPPED; - retval->_nextPlaying = NULL; - retval->_nextStopping = NULL; - retval->_restoreBehavior = RESTORE_BEHAVIOR_CONTINUE; - retval->_restoreTime = 0; +Song::Song() { + _handle = 0; + _priority = 0; + _status = SOUND_STATUS_STOPPED; - return retval; + _restoreBehavior = RESTORE_BEHAVIOR_CONTINUE; + _restoreTime = 0; + + _loops = 0; + _hold = 0; + + _it = 0; + _delay = 0; + + _next = NULL; + _nextPlaying = NULL; + _nextStopping = NULL; +} + +Song::Song(SongHandle handle, SongIterator *it, int priority) { + _handle = handle; + _priority = priority; + _status = SOUND_STATUS_STOPPED; + + _restoreBehavior = RESTORE_BEHAVIOR_CONTINUE; + _restoreTime = 0; + + _loops = 0; + _hold = 0; + + _it = it; + _delay = 0; + + _next = NULL; + _nextPlaying = NULL; + _nextStopping = NULL; } void SongLibrary::addSong(Song *song) { @@ -90,7 +105,7 @@ void SongLibrary::freeSounds() { delete song->_it; song->_it = NULL; next = song->_next; - free(song); + delete song; } *_lib = NULL; } @@ -154,7 +169,7 @@ int SongLibrary::removeSong(SongHandle handle) { retval = goner->_status; delete goner->_it; - free(goner); + delete goner; return retval; } diff --git a/engines/sci/sfx/songlib.h b/engines/sci/sfx/songlib.h index f9caedeefb..55c3ddf4fd 100644 --- a/engines/sci/sfx/songlib.h +++ b/engines/sci/sfx/songlib.h @@ -50,7 +50,8 @@ enum RESTORE_BEHAVIOR { RESTORE_BEHAVIOR_RESTART /* continue it from where it was */ }; -struct Song { +class Song { +public: SongHandle _handle; int _resourceNum; /**