diff options
author | Alyssa Milburn | 2012-08-25 00:31:00 +0200 |
---|---|---|
committer | Alyssa Milburn | 2012-08-25 10:08:10 +0200 |
commit | b14a616f3f7f667946f617facd301369a0996582 (patch) | |
tree | 32f5916d3c9e1d8d7beae7613e06845dbba3f399 /engines/tony | |
parent | b77306bfcc26d17b1fca71360d1fcbd2ebdbe0ee (diff) | |
download | scummvm-rg350-b14a616f3f7f667946f617facd301369a0996582.tar.gz scummvm-rg350-b14a616f3f7f667946f617facd301369a0996582.tar.bz2 scummvm-rg350-b14a616f3f7f667946f617facd301369a0996582.zip |
TONY: Get rid of RMString.
Diffstat (limited to 'engines/tony')
-rw-r--r-- | engines/tony/loc.cpp | 12 | ||||
-rw-r--r-- | engines/tony/loc.h | 10 | ||||
-rw-r--r-- | engines/tony/utils.cpp | 342 | ||||
-rw-r--r-- | engines/tony/utils.h | 60 |
4 files changed, 18 insertions, 406 deletions
diff --git a/engines/tony/loc.cpp b/engines/tony/loc.cpp index 9fba2dd51a..e767584e9b 100644 --- a/engines/tony/loc.cpp +++ b/engines/tony/loc.cpp @@ -145,7 +145,7 @@ void RMPattern::updateCoord() { void RMPattern::stopSfx(RMSfx *sfx) { for (int i = 0; i < _nSlots; i++) { if (_slots[i]._type == SOUND) { - if (sfx[_slots[i]._data]._name[0] == '_') + if (!sfx[_slots[i]._data]._name.empty() && sfx[_slots[i]._data]._name[0] == '_') sfx[_slots[i]._data].stop(); else if (GLOBALS._bSkipSfxNoLoop) sfx[_slots[i]._data].stop(); @@ -182,7 +182,7 @@ int RMPattern::init(RMSfx *sfx, bool bPlayP0, byte *bFlag) { for (i = 0; i < _nSlots; i++) { if (_slots[i]._type == SOUND) { if (i == 0) { - if (sfx[_slots[i]._data]._name[0] == '_') { + if (!sfx[_slots[i]._data]._name.empty() && sfx[_slots[i]._data]._name[0] == '_') { sfx[_slots[i]._data].setVolume(_slots[i].pos()._x); sfx[_slots[i]._data].play(true); } else { @@ -193,12 +193,12 @@ int RMPattern::init(RMSfx *sfx, bool bPlayP0, byte *bFlag) { if (bPlayP0) { sfx[_slots[i]._data].setVolume(_slots[i].pos()._x); sfx[_slots[i]._data].play(); - } else if (sfx[_slots[i]._data]._name[0] == '_') { + } else if (!sfx[_slots[i]._data]._name.empty() && sfx[_slots[i]._data]._name[0] == '_') { sfx[_slots[i]._data].setVolume(_slots[i].pos()._x); sfx[_slots[i]._data].play(true); } } else { - if (_bLoop && sfx[_slots[i]._data]._name[0] == '_') { + if (_bLoop && !sfx[_slots[i]._data]._name.empty() && sfx[_slots[i]._data]._name[0] == '_') { sfx[_slots[i]._data].setVolume(_slots[i].pos()._x); sfx[_slots[i]._data].play(true); } @@ -253,7 +253,7 @@ int RMPattern::update(uint32 hEndPattern, byte &bFlag, RMSfx *sfx) { if (sfx != NULL) { sfx[_slots[_nCurSlot]._data].setVolume(_slots[_nCurSlot].pos()._x); - if (sfx[_slots[_nCurSlot]._data]._name[0] != '_') + if (sfx[_slots[_nCurSlot]._data]._name.empty() || sfx[_slots[_nCurSlot]._data]._name[0] != '_') sfx[_slots[_nCurSlot]._data].play(false); else sfx[_slots[_nCurSlot]._data].play(true); @@ -729,7 +729,7 @@ void RMItem::setPattern(int nPattern, bool bPlayP0) { // Look for the sound effect for pattern 0 if (bPlayP0) { for (int i = 0; i < _nSfx; i++) { - if (strcmp(_sfx[i]._name, "p0") == 0) + if (_sfx[i]._name == "p0") _sfx[i].play(); } } diff --git a/engines/tony/loc.h b/engines/tony/loc.h index f8a795cc42..acfbd45cdb 100644 --- a/engines/tony/loc.h +++ b/engines/tony/loc.h @@ -71,7 +71,7 @@ public: */ class RMSfx { public: - RMString _name; + Common::String _name; FPSfx *_fx; bool _bPlayingLoop; @@ -126,7 +126,7 @@ public: }; public: - RMString _name; + Common::String _name; private: int _speed; @@ -174,7 +174,7 @@ private: */ class RMSprite : public RMGfxTask { public: - RMString _name; + Common::String _name; RMRect _rcBox; protected: @@ -200,7 +200,7 @@ public: */ class RMItem : public RMGfxTask { public: - RMString _name; + Common::String _name; protected: int _z; @@ -527,7 +527,7 @@ public: */ class RMLocation : public RMGfxTaskSetPrior { public: - RMString _name; // Name + Common::String _name; // Name private: RMColorMode _cmode; // Color mode diff --git a/engines/tony/utils.cpp b/engines/tony/utils.cpp index 54a2209659..8dc1f5d615 100644 --- a/engines/tony/utils.cpp +++ b/engines/tony/utils.cpp @@ -32,356 +32,26 @@ namespace Tony { -/****************************************************************************\ -* RMString methods -\****************************************************************************/ - -/** - * Constructor - */ -RMString::RMString() { - _string = NULL; - _length = 0; - _realLength = 0; -} - -/** - * Destructor - */ -RMString::~RMString() { - if (_string != NULL) - delete[] _string; -} - -/** - * Copy constructor - */ -RMString::RMString(const RMString &str) { - // Use the overloaded '=' when copying - _string = NULL; - _length = 0; - _realLength = 0; - *this = str; -} - -/** - * Constructor from a char * - */ -RMString::RMString(const char *str) { - // Use the overloaded '=' when copying - _string = NULL; - _length = 0; - _realLength = 0; - *this = str; -} - -/** - * Constructor with a single passed character - */ -RMString::RMString(const int ch) { - // Use the overloaded '=' when copying - _string = NULL; - _length = 0; - _realLength = 0; - *this = ch; -} - -/** - * Returns the length of the string - * @returns Length - */ -int RMString::length() const { - return _length; -} - -/** - * Gets the character at the given index - * @param nIndex Position of the character to return - * @returns Character - */ -char RMString::getAt(int nIndex) { - assert(nIndex < _length); - return _string[nIndex]; -} - -/** - * Sets the character at the given index - * @param nIndex Position of the character to change - * @param c Character - */ -void RMString::setAt(int nIndex, char c) { - assert(nIndex < _length); - _string[nIndex] = c; -} - -/** - * Overloaded square brackets operator for accessing characters within the string - * @param nIndex Position of the charactre to reference - * @params Reference to the character - */ -char &RMString::operator[](int nIndex) { - assert(nIndex < _length); - return _string[nIndex]; -} - -/** - * Copies a string - * @param str String to copy - * @returns Reference to our string - */ -const RMString &RMString::operator=(const RMString &str) { - // Set the new length - _length = str._length; - - // If the source is empty, then destroy the current string buffer - if (_length == 0) { - if (_realLength > 0) { - delete[] _string; - _string = NULL; - _realLength = 0; - } - } else { - // Resize if necessary - resize(_length + 1); - - // Copy the string - Common::copy(str._string, str._string + _length + 1, _string); - } - - return *this; -} - -/** - * Copies a char * string - * @param str String to copy - * @returns Reference to our string - */ -const RMString &RMString::operator=(const char *str) { - // If the source is empty, then destroy the current string buffer - if (str == NULL) { - if (_realLength > 0) { - delete[] _string; - _string = NULL; - _realLength = _length = 0; - } - } else { - // Calculate the new length - _length = strlen(str); - - // Resize if necessary - resize(_length + 1); - - // Copy the string - Common::copy(str, str + _length + 1, _string); - } - - return *this; -} - -/** - * Forms a string from a passed character - * @param ch Character to copy - * @returns Reference to our string - */ -const RMString &RMString::operator=(const int ch) { - if (ch == '\0') { - // Destroy the current string - if (_realLength > 0) { - delete [] _string; - _string = NULL; - _length = _realLength = 0; - } - } else { - // Resize if necessary - resize(2); - - _string[0] = ch; - _string[1] = '\0'; - _length = 1; - } - - return *this; -} - -/** - * Concatenate a string into the current one - * @param str String to concatenate - * @param size Length of the string - */ -void RMString::connect(const char *str, int size) { - if (size > 0) { - // Calculate the new lenght - int nlen = _length + size; - - // Resize - resize(nlen + 1, true); - - // Linkage with '\0' - Common::copy(str, str + size + 1, _string + _length); - - // Save the new length - _length = nlen; - } -} - -/** - * Concatenate a string - * @param str String to concatenate - * @returns Reference to our string - */ -const RMString &RMString::operator+=(RMString &str) { - connect(str, str.length()); - return *this; -} - -/** - * Concatenate a string - * @param str String to concatenate - * @returns Reference to our string - */ -const RMString &RMString::operator+=(const char *str) { - connect(str, strlen(str)); - return *this; -} - -/** - * Concatenate a character - * @param ch Character to concatenate - * @returns Reference to our string - */ -const RMString &RMString::operator+=(const int ch) { - char str[2]; - - // Create a simple string buffer to hold the single character - str[0] = ch; - str[1] = '\0'; - - connect(str, 1); - return *this; -} - -/** - * Casts a string as char * - * @returns char * reference to string - */ -RMString::operator char *() const { - return _string; -} - -/** - * Resize a string as necessary - * @param size New size necessary (in bytes) - * @param bMaintain If true we must keep the original string, - if false we can destroy. - */ -void RMString::resize(int size, bool bMantain) { - if (_realLength == 0) { - _string = new char[size]; - _realLength = size; - } else if (size > _realLength) { - if (bMantain) { - char *app; - - app = new char[size]; - Common::copy(_string, _string + _length + 1, app); - delete[] _string; - _string = app; - } else { - delete[] _string; - _string = new char[size]; - } - } -} - -/** - * Compacts the string to occupy less memory if possible. - */ -void RMString::compact() { - if (_realLength + 1 > _length) { - char *app; - - app = new char[_length + 1]; - Common::copy(_string, _string + _length + 1, app); - - delete[] _string; - _string = app; - } -} - -/** - * Operator to concatenate two strings - */ -RMString operator+(const RMString &str1, const RMString &str2) { - RMString ret(str1); - - return (ret += str2); -} - -/** - * Operator to concatenate a character to a string - */ -RMString operator+(RMString &str, const int ch) { - RMString ret(str); - - return (ret += ch); -} - -RMString operator+(const int ch, RMString &str) { - RMString ret(ch); - - return (ret += str); -} - -/** - * Operator to concatenate a char * string to an RMString - */ -RMString operator+(RMString &str, const char *s) { - RMString ret(str); - - return (ret += s); -} - -RMString operator+(const char *s, RMString &str) { - RMString ret(s); - - return (ret += str); -} - /** * Extracts a string from a data stream * @param df data stream * @param var String */ -RMDataStream &operator>>(RMDataStream &df, RMString &var) { +RMDataStream &operator>>(RMDataStream &df, Common::String &var) { uint8 len; int i; df >> len; - var.resize(len + 1); - var._length = len + 1; - for (i = 0; i < len; i++) - df >> var[i]; - - var[i] = '\0'; - var._length = len; + for (i = 0; i < len; i++) { + char c; + df >> c; + var += c; + } return df; } -/** - * Formats a string - */ -void RMString::format(const char *str, ...) { - static char buf[2048]; - va_list argList; - - va_start(argList, str); - vsprintf(buf, str, argList); - va_end(argList); - *this = buf; -} - /****************************************************************************\ * RMFileStreamSlow Methods \****************************************************************************/ diff --git a/engines/tony/utils.h b/engines/tony/utils.h index f755a57c39..50b18d8aa7 100644 --- a/engines/tony/utils.h +++ b/engines/tony/utils.h @@ -145,65 +145,7 @@ public: friend RMFileStreamSlow &operator>>(RMFileStreamSlow &df, uint32 &var); }; -/** - * String class - */ -class RMString { -private: - char *_string; - int _length; - int _realLength; - -public: - RMString(); - ~RMString(); - - // Assignment constructors - RMString(const RMString &str); - RMString(const char *str); - RMString(const int ch); - - // General methods - int length() const; - void compact(); - - // Access characters within string - char getAt(int nIndex); - void setAt(int nIndex, char c); - char &operator[](int nIndex); - - // String cast - operator char *() const; - - // String assignments - const RMString &operator=(const RMString &str); - const RMString &operator=(const char *str); - const RMString &operator=(const int ch); - - // String concatenation - const RMString &operator+=(RMString &str); - const RMString &operator+=(const char *str); - const RMString &operator+=(const int ch); - - // Concatentation of string or character - friend RMString operator+(const RMString &str1, const RMString &str2); - - friend RMString operator+(RMString &str, const int ch); - friend RMString operator+(const int ch, RMString &str); - - friend RMString operator+(RMString &str, const char *s); - friend RMString operator+(const char *s, RMString &str); - - // Extraction from data streams - friend RMDataStream &operator>>(RMDataStream &df, RMString &var); - - // String formatting - void format(const char *str, ...); - -private: - void resize(int size, bool bMantain = false); - void connect(const char *str, int size); -}; +RMDataStream &operator>>(RMDataStream &df, Common::String &var); /** * Point class |