From 733b34febced2e3c10b83abb8109db68f1858b1d Mon Sep 17 00:00:00 2001 From: Joel Teichroeb Date: Sun, 22 May 2011 12:02:20 +0800 Subject: [PATCH] Changed const char * to const Common::String &. --- engines/grim/actor.cpp | 22 +++++++++++----------- engines/grim/actor.h | 6 +++--- engines/grim/bitmap.cpp | 10 +++++----- engines/grim/bitmap.h | 10 +++++----- engines/grim/colormap.cpp | 5 ++--- engines/grim/colormap.h | 4 ++-- engines/grim/costume.cpp | 16 ++++++++-------- engines/grim/costume.h | 4 ++-- engines/grim/font.cpp | 12 +++++------- engines/grim/font.h | 5 ++--- engines/grim/grim.cpp | 4 ++-- engines/grim/grim.h | 2 +- engines/grim/keyframe.cpp | 5 ++--- engines/grim/keyframe.h | 4 ++-- engines/grim/lipsync.cpp | 10 +++------- engines/grim/lipsync.h | 4 ++-- engines/grim/lua/lstate.cpp | 2 +- engines/grim/lua_v1_actor.cpp | 4 ++-- engines/grim/lua_v2.cpp | 28 ++++++++++++++-------------- engines/grim/material.cpp | 4 ++-- engines/grim/material.h | 4 ++-- engines/grim/model.cpp | 2 +- engines/grim/model.h | 2 +- engines/grim/objectstate.cpp | 2 +- engines/grim/objectstate.h | 2 +- engines/grim/resource.cpp | 4 ++-- engines/grim/savegame.cpp | 12 +++++++----- engines/grim/savegame.h | 2 +- engines/grim/scene.cpp | 12 ++++++------ engines/grim/scene.h | 4 ++-- 30 files changed, 100 insertions(+), 107 deletions(-) diff --git a/engines/grim/actor.cpp b/engines/grim/actor.cpp index 4a7d34ce2ab..8b003c10a04 100644 --- a/engines/grim/actor.cpp +++ b/engines/grim/actor.cpp @@ -43,7 +43,7 @@ namespace Grim { int g_winX1, g_winY1, g_winX2, g_winY2; -Actor::Actor(const char *actorName) : +Actor::Actor(const Common::String &actorName) : Object(), _name(actorName), _setName(""), _talkColor(g_grim->getColor(2)), _pos(0, 0, 0), // Some actors don't set walk and turn rates, so we default the // _turnRate so Doug at the cat races can turn and we set the @@ -148,7 +148,7 @@ void Actor::saveState(SaveGame *savedState) const { if (_lipSync) { savedState->writeLEUint32(1); - savedState->writeCharString(_lipSync->getFilename()); + savedState->writeString(_lipSync->getFilename()); } else { savedState->writeLEUint32(0); } @@ -156,7 +156,7 @@ void Actor::saveState(SaveGame *savedState) const { savedState->writeLESint32(_costumeStack.size()); for (Common::List::const_iterator i = _costumeStack.begin(); i != _costumeStack.end(); ++i) { Costume *c = *i; - savedState->writeCharString(c->getFilename()); + savedState->writeString(c->getFilename()); Costume *pc = c->getPreviousCostume(); int depth = 0; while (pc) { @@ -166,7 +166,7 @@ void Actor::saveState(SaveGame *savedState) const { savedState->writeLEUint32(depth); pc = c->getPreviousCostume(); for (int j = 0; j < depth; ++j) { //save the previousCostume hierarchy - savedState->writeCharString(pc->getFilename()); + savedState->writeString(pc->getFilename()); pc = pc->getPreviousCostume(); } c->saveState(savedState); @@ -180,7 +180,7 @@ void Actor::saveState(SaveGame *savedState) const { if (_restCostume) { savedState->writeLEUint32(1); - savedState->writeCharString(_restCostume->getFilename()); + savedState->writeString(_restCostume->getFilename()); } else { savedState->writeLEUint32(0); } @@ -188,7 +188,7 @@ void Actor::saveState(SaveGame *savedState) const { if (_walkCostume) { savedState->writeLEUint32(1); - savedState->writeCharString(_walkCostume->getFilename()); + savedState->writeString(_walkCostume->getFilename()); } else { savedState->writeLEUint32(0); } @@ -198,7 +198,7 @@ void Actor::saveState(SaveGame *savedState) const { if (_turnCostume) { savedState->writeLEUint32(1); - savedState->writeCharString(_turnCostume->getFilename()); + savedState->writeString(_turnCostume->getFilename()); } else { savedState->writeLEUint32(0); } @@ -210,7 +210,7 @@ void Actor::saveState(SaveGame *savedState) const { for (int i = 0; i < 10; ++i) { if (_talkCostume[i]) { savedState->writeLEUint32(1); - savedState->writeCharString(_talkCostume[i]->getFilename()); + savedState->writeString(_talkCostume[i]->getFilename()); } else { savedState->writeLEUint32(0); } @@ -220,7 +220,7 @@ void Actor::saveState(SaveGame *savedState) const { if (_mumbleCostume) { savedState->writeLEUint32(1); - savedState->writeCharString(_mumbleCostume->getFilename()); + savedState->writeString(_mumbleCostume->getFilename()); } else { savedState->writeLEUint32(0); } @@ -1032,7 +1032,7 @@ void Actor::setScale(float scale) { Costume *Actor::findCostume(const char *n) { for (Common::List::iterator i = _costumeStack.begin(); i != _costumeStack.end(); ++i) { - if (scumm_stricmp((*i)->getFilename(), n) == 0) + if ((*i)->getFilename().compareToIgnoreCase(n) == 0) return *i; } @@ -1358,7 +1358,7 @@ void Actor::putInSet(const char *setName) { _setName = setName; } -bool Actor::isInSet(const char *setName) const { +bool Actor::isInSet(const Common::String &setName) const { return _setName == setName; } diff --git a/engines/grim/actor.h b/engines/grim/actor.h index f3639d54f85..395f0d31d39 100644 --- a/engines/grim/actor.h +++ b/engines/grim/actor.h @@ -51,14 +51,14 @@ struct Shadow { class Actor : public Object { public: - Actor(const char *name); + Actor(const Common::String &name); Actor(); ~Actor(); void saveState(SaveGame *savedState) const; bool restoreState(SaveGame *savedState); - const char *getName() const { return _name.c_str(); } + const Common::String &getName() const { return _name; } void setTalkColor(Color *c) { _talkColor = c; } Color *getTalkColor() const { return _talkColor; } @@ -88,7 +88,7 @@ public: float getAngleTo(const Actor &a) const; float getYawTo(Graphics::Vector3d p) const; - bool isInSet(const char *setName) const; + bool isInSet(const Common::String &setName) const; void walkForward(); void setRunning(bool running); void setReflection(float angle) { _reflectionAngle = angle; } diff --git a/engines/grim/bitmap.cpp b/engines/grim/bitmap.cpp index 8780f5228f8..1313aeac0e2 100644 --- a/engines/grim/bitmap.cpp +++ b/engines/grim/bitmap.cpp @@ -89,7 +89,7 @@ char *makeBitmapFromTile(char **bits, int width, int height, int bpp) { return fullImage; } -BitmapData *BitmapData::getBitmapData(const char *fname, const char *data, int len) { +BitmapData *BitmapData::getBitmapData(const Common::String &fname, const char *data, int len) { Common::String str(fname); if (_bitmaps && _bitmaps->contains(str)) { BitmapData *b = (*_bitmaps)[str]; @@ -105,11 +105,11 @@ BitmapData *BitmapData::getBitmapData(const char *fname, const char *data, int l return b; } -BitmapData::BitmapData(const char *fname, const char *data, int len) { +BitmapData::BitmapData(const Common::String &fname, const char *data, int len) { _fname = fname; _refCount = 1; if (len > 4 && memcmp(data, "\x1f\x8b\x08\0", 4) == 0) { - loadTile(fname, data, len); + loadTile(data, len); return; } else if (len < 8 || memcmp(data, "BM F\0\0\0", 8) != 0) { if (gDebugLevel == DEBUG_BITMAPS || gDebugLevel == DEBUG_ERROR || gDebugLevel == DEBUG_ALL) @@ -208,7 +208,7 @@ BitmapData::~BitmapData() { } } -bool BitmapData::loadTile(const char *filename, const char *data, int len) { +bool BitmapData::loadTile(const char *data, int len) { _x = 0; _y = 0; _format = 1; @@ -269,7 +269,7 @@ char *BitmapData::getImageData(int num) const { // Bitmap -Bitmap::Bitmap(const char *fname, const char *data, int len) : +Bitmap::Bitmap(const Common::String &fname, const char *data, int len) : Object() { _data = BitmapData::getBitmapData(fname, data, len); _x = _data->_x; diff --git a/engines/grim/bitmap.h b/engines/grim/bitmap.h index 66e62aba3d8..70abb6add8e 100644 --- a/engines/grim/bitmap.h +++ b/engines/grim/bitmap.h @@ -34,13 +34,13 @@ namespace Grim { // They are automatically deleted if they are not used by any bitmap anymore. class BitmapData { public: - BitmapData(const char *fname, const char *data, int len); + BitmapData(const Common::String &fname, const char *data, int len); BitmapData(const char *data, int w, int h, int bpp, const char *fname); BitmapData(); ~BitmapData(); - bool loadTile(const char *filename, const char *data, int len); + bool loadTile(const char *data, int len); - static BitmapData *getBitmapData(const char *fname, const char *data, int len); + static BitmapData *getBitmapData(const Common::String &fname, const char *data, int len); static Common::HashMap *_bitmaps; char *getImageData(int num) const; @@ -66,11 +66,11 @@ private: class Bitmap : public Object { public: // Construct a bitmap from the given data. - Bitmap(const char *filename, const char *data, int len); + Bitmap(const Common::String &filename, const char *data, int len); Bitmap(const char *data, int width, int height, int bpp, const char *filename); Bitmap(); - const char *getFilename() const { return _data->_fname.c_str(); } + const Common::String &getFilename() const { return _data->_fname; } void draw() const; diff --git a/engines/grim/colormap.cpp b/engines/grim/colormap.cpp index dd43ac126a3..8af22c32752 100644 --- a/engines/grim/colormap.cpp +++ b/engines/grim/colormap.cpp @@ -26,9 +26,8 @@ namespace Grim { // Load a colormap from the given data. -CMap::CMap(const char *fileName, const char *data, int len) : - Object() { - _fname = fileName; +CMap::CMap(const Common::String &fileName, const char *data, int len) : + Object(), _fname(fileName) { if (len < 4 || READ_BE_UINT32(data) != MKTAG('C','M','P',' ')) error("Invalid magic loading colormap"); memcpy(_colors, data + 64, sizeof(_colors)); diff --git a/engines/grim/colormap.h b/engines/grim/colormap.h index 490adb0a8a5..6466ac1b7c4 100644 --- a/engines/grim/colormap.h +++ b/engines/grim/colormap.h @@ -30,10 +30,10 @@ namespace Grim { class CMap : public Object { public: // Load a colormap from the given data. - CMap(const char *fileName, const char *data, int len); + CMap(const Common::String &fileName, const char *data, int len); CMap(); ~CMap(); - const char *getFilename() const { return _fname.c_str(); } + const Common::String &getFilename() const { return _fname; } // The color data, in RGB format char _colors[256 * 3]; diff --git a/engines/grim/costume.cpp b/engines/grim/costume.cpp index f5283b9abad..b80a3d47613 100644 --- a/engines/grim/costume.cpp +++ b/engines/grim/costume.cpp @@ -522,7 +522,7 @@ ColormapComponent::~ColormapComponent() { void ColormapComponent::init() { if (!_parent) warning("No parent to apply colormap object on. CMap: %s, Costume: %s", - _cmap->getFilename(),_cost->getFilename()); + _cmap->getFilename().c_str(), _cost->getFilename().c_str()); } class KeyframeComponent : public Costume::Component { @@ -577,7 +577,7 @@ void KeyframeComponent::setKey(int val) { break; default: if (gDebugLevel == DEBUG_MODEL || gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) - warning("Unknown key %d for keyframe %s", val, _keyf->getFilename()); + warning("Unknown key %d for keyframe %s", val, _keyf->getFilename().c_str()); } } @@ -612,7 +612,7 @@ void KeyframeComponent::update() { break; default: if (gDebugLevel == DEBUG_MODEL || gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) - warning("Unknown repeat mode %d for keyframe %s", _repeatMode, _keyf->getFilename()); + warning("Unknown repeat mode %d for keyframe %s", _repeatMode, _keyf->getFilename().c_str()); } } @@ -625,7 +625,7 @@ void KeyframeComponent::init() { _hier = mc->getHierarchy(); else { if (gDebugLevel == DEBUG_MODEL || gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) - warning("Parent of %s was not a model", _keyf->getFilename()); + warning("Parent of %s was not a model", _keyf->getFilename().c_str()); _hier = NULL; } } @@ -695,13 +695,13 @@ void MaterialComponent::init() { ModelComponent *p = static_cast(_parent); Model *model = p->getModel(); for (int i = 0; i < model->_numMaterials; ++i) { - if (scumm_stricmp(model->_materials[i]->getFilename(), _filename.c_str()) == 0) { + if (_filename.compareToIgnoreCase(model->_materials[i]->getFilename()) == 0) { _mat = model->_materials[i].object(); return; } } } else { - warning("Parent of a MaterialComponent not a ModelComponent. %s %s", _filename.c_str(),_cost->getFilename()); + warning("Parent of a MaterialComponent not a ModelComponent. %s %s", _filename.c_str(), _cost->getFilename().c_str()); _mat = NULL; } } @@ -802,7 +802,7 @@ void SoundComponent::reset() { g_imuse->stopSound(_soundName.c_str()); } -Costume::Costume(const char *fname, const char *data, int len, Costume *prevCost) : +Costume::Costume(const Common::String &fname, const char *data, int len, Costume *prevCost) : Object() { _fname = fname; @@ -1549,7 +1549,7 @@ Costume *Costume::getPreviousCostume() const { void Costume::saveState(SaveGame *state) const { if (_cmap) { state->writeLEUint32(1); - state->writeCharString(_cmap->getFilename()); + state->writeString(_cmap->getFilename()); } else { state->writeLEUint32(0); } diff --git a/engines/grim/costume.h b/engines/grim/costume.h index 03b6fcb197c..bb3a25f5f56 100644 --- a/engines/grim/costume.h +++ b/engines/grim/costume.h @@ -38,7 +38,7 @@ class TextSplitter; class Costume : public Object { public: - Costume(const char *filename, const char *data, int len, Costume *prevCost); + Costume(const Common::String &filename, const char *data, int len, Costume *prevCost); Costume() : Object() { _chores = 0; } void loadGRIM(TextSplitter &ts, Costume *prevCost); @@ -46,7 +46,7 @@ public: virtual ~Costume(); - const char *getFilename() const { return _fname.c_str(); } + const Common::String &getFilename() const { return _fname; } void playChore(const char *name); void playChore(int num); void playChoreLooping(int num); diff --git a/engines/grim/font.cpp b/engines/grim/font.cpp index febe2b43836..c230a98a83f 100644 --- a/engines/grim/font.cpp +++ b/engines/grim/font.cpp @@ -31,9 +31,7 @@ namespace Grim { -Font::Font(const char *filename, const char *data, int len) : Object() { - _fname = filename; - +Font::Font(const Common::String &filename, const char *data, int len) : Object() { _filename = filename; _numChars = READ_LE_UINT32(data); _dataSize = READ_LE_UINT32(data + 4); @@ -48,7 +46,7 @@ Font::Font(const char *filename, const char *data, int len) : Object() { // Read character indexes - are the key/value reversed? _charIndex = new uint16[_numChars]; if (!_charIndex) - error("Could not load font %s. Out of memory", filename); + error("Could not load font %s. Out of memory", _filename.c_str()); for (uint i = 0; i < _numChars; ++i) { _charIndex[i] = READ_LE_UINT16(data + 2 * i); } @@ -58,7 +56,7 @@ Font::Font(const char *filename, const char *data, int len) : Object() { // Read character headers _charHeaders = new CharHeader[_numChars]; if (!_charHeaders) - error("Could not load font %s. Out of memory", filename); + error("Could not load font %s. Out of memory", _filename.c_str()); for (uint i = 0; i < _numChars; ++i) { _charHeaders[i].offset = READ_LE_UINT32(data); _charHeaders[i].width = *(int8 *)(data + 4); @@ -68,7 +66,7 @@ Font::Font(const char *filename, const char *data, int len) : Object() { _charHeaders[i].dataHeight = READ_LE_UINT32(data + 12); int8 overflow = (_charHeaders[i].dataHeight + _charHeaders[i].startingLine) - available_height; if (overflow > 0) { - warning("Font %s, char 0x%02x exceeds font height by %d, increasing font height", filename, i, overflow); + warning("Font %s, char 0x%02x exceeds font height by %d, increasing font height", _filename.c_str(), i, overflow); available_height += overflow; _height += overflow; } @@ -77,7 +75,7 @@ Font::Font(const char *filename, const char *data, int len) : Object() { // Read font data _fontData = new byte[_dataSize]; if (!_fontData) - error("Could not load font %s. Out of memory", filename); + error("Could not load font %s. Out of memory", _filename.c_str()); memcpy(_fontData, data, _dataSize); } diff --git a/engines/grim/font.h b/engines/grim/font.h index 73676dc6231..96c3ac3a8f0 100644 --- a/engines/grim/font.h +++ b/engines/grim/font.h @@ -31,11 +31,11 @@ class SaveGame; class Font : public Object { public: - Font(const char *filename, const char *data, int len); + Font(const Common::String &filename, const char *data, int len); Font(); ~Font(); - Common::String getFilename() const { return _filename; } + const Common::String &getFilename() const { return _filename; } int32 getHeight() { return _height; } int32 getBaseOffsetY() { return _baseOffsetY; } int32 getCharDataWidth(unsigned char c) { return _charHeaders[getCharIndex(c)].dataWidth; } @@ -66,7 +66,6 @@ private: CharHeader *_charHeaders; byte *_fontData; Common::String _filename; - Common::String _fname; }; } // end of namespace Grim diff --git a/engines/grim/grim.cpp b/engines/grim/grim.cpp index 13332bce22b..0fab3d9be61 100644 --- a/engines/grim/grim.cpp +++ b/engines/grim/grim.cpp @@ -1561,7 +1561,7 @@ void GrimEngine::saveBitmaps(SaveGame *state) { for (BitmapListType::iterator i = _bitmaps.begin(); i != _bitmaps.end(); ++i) { state->writeLEUint32(i->_key); Bitmap *b = i->_value; - state->writeCharString(b->getFilename()); + state->writeString(b->getFilename()); state->writeLESint32(b->getCurrentImage()); state->writeLESint32(b->getX()); @@ -1629,7 +1629,7 @@ void GrimEngine::savegameCallback() { Scene *GrimEngine::findScene(const char *name) { // Find scene object for (SceneListType::const_iterator i = scenesBegin(); i != scenesEnd(); ++i) { - if (!strcmp(i->_value->getName(), name)) + if (i->_value->getName() == name) return i->_value; } return NULL; diff --git a/engines/grim/grim.h b/engines/grim/grim.h index 07764cc3422..4b86395c92f 100644 --- a/engines/grim/grim.h +++ b/engines/grim/grim.h @@ -140,7 +140,7 @@ public: void setScene(const char *name); void setScene(Scene *scene); Scene *getCurrScene() { return _currScene; } - const char *getSceneName() const { return _currScene->getName(); } + const Common::String &getSceneName() const { return _currScene->getName(); } void makeCurrentSetup(int num); // Scene registration diff --git a/engines/grim/keyframe.cpp b/engines/grim/keyframe.cpp index 64faac1bd03..77562aa63e5 100644 --- a/engines/grim/keyframe.cpp +++ b/engines/grim/keyframe.cpp @@ -32,9 +32,8 @@ namespace Grim { -KeyframeAnim::KeyframeAnim(const char *fname, const char *data, int len) : - Object() { - _fname = fname; +KeyframeAnim::KeyframeAnim(const Common::String &fname, const char *data, int len) : + Object(), _fname(fname) { if (len >= 4 && READ_BE_UINT32(data) == MKTAG('F','Y','E','K')) loadBinary(data, len); diff --git a/engines/grim/keyframe.h b/engines/grim/keyframe.h index 30487437c75..478f3b5bb88 100644 --- a/engines/grim/keyframe.h +++ b/engines/grim/keyframe.h @@ -29,7 +29,7 @@ namespace Grim { class KeyframeAnim : public Object { public: - KeyframeAnim(const char *filename, const char *data, int len); + KeyframeAnim(const Common::String &filename, const char *data, int len); ~KeyframeAnim(); void loadBinary(const char *data, int len); @@ -37,7 +37,7 @@ public: void animate(Model::HierNode *nodes, float time, int priority1 = 1, int priority2 = 5, float fade = 1) const; float getLength() const { return _numFrames / _fps; } - const char *getFilename() const { return _fname.c_str(); } + const Common::String &getFilename() const { return _fname; } private: Common::String _fname; diff --git a/engines/grim/lipsync.cpp b/engines/grim/lipsync.cpp index 55f3d0573ea..91c2c0b92d9 100644 --- a/engines/grim/lipsync.cpp +++ b/engines/grim/lipsync.cpp @@ -32,14 +32,14 @@ template class ObjectPtr; // A new define that'll be around when theres a configure script :) #undef DEBUG_VERBOSE -LipSync::LipSync(const char *filename, const char *data, int len) : +LipSync::LipSync(const Common::String &filename, const char *data, int len) : Object() { _fname = filename; uint16 readPhoneme; int j; if (READ_BE_UINT32(data) != MKTAG('L','I','P','!')) { - error("Invalid file format in %s", filename); + error("Invalid file format in %s", _fname.c_str()); } else { _numEntries = (len - 8) / 4; @@ -65,7 +65,7 @@ LipSync::LipSync(const char *filename, const char *data, int len) : } if (j >= _animTableSize) { - warning("Unknown phoneme: 0x%X in file %s", readPhoneme, filename); + warning("Unknown phoneme: 0x%X in file %s", readPhoneme, _fname.c_str()); _entries[i].anim = 1; } @@ -106,10 +106,6 @@ int LipSync::getAnim(int pos) { return -1; } -const char *LipSync::getFilename() const { - return _fname.c_str(); -} - const LipSync::PhonemeAnim LipSync::_animTable[] = { {0x005F, 0}, {0x0251, 1}, {0x0061, 1}, {0x00E6, 1}, {0x028C, 8}, {0x0254, 1}, {0x0259, 1}, {0x0062, 6}, {0x02A7, 2}, {0x0064, 2}, diff --git a/engines/grim/lipsync.h b/engines/grim/lipsync.h index a89ffc9100e..1e0db2f0d9d 100644 --- a/engines/grim/lipsync.h +++ b/engines/grim/lipsync.h @@ -29,7 +29,7 @@ namespace Grim { class LipSync : public Object { public: - LipSync(const char *filename, const char *data, int len); + LipSync(const Common::String &filename, const char *data, int len); ~LipSync(); struct LipEntry { @@ -39,7 +39,7 @@ public: int getAnim(int pos); bool isValid() { return _numEntries > 0; } - const char *getFilename() const; + const Common::String &getFilename() const { return _fname; }; private: LipEntry *_entries; diff --git a/engines/grim/lua/lstate.cpp b/engines/grim/lua/lstate.cpp index e74e4898aa8..caec091f937 100644 --- a/engines/grim/lua/lstate.cpp +++ b/engines/grim/lua/lstate.cpp @@ -161,7 +161,7 @@ void callHook(lua_Function func, const char *filename, int32 line) { else if (lua_isuserdata(lua_getparam(i))) { if (lua_tag(lua_getparam(i)) == MKTAG('A','C','T','R')) { Actor *a = g_grim->getActor(lua_getuserdata(lua_getparam(i))); - fprintf(output, "", a->getName()); + fprintf(output, "", a->getName().c_str()); } else if (lua_tag(lua_getparam(i)) == MKTAG('C','O','L','R')) { Color *c = g_grim->getColor(lua_getuserdata(lua_getparam(i))); fprintf(output, "", c->getRed(), c->getGreen(), c->getBlue()); diff --git a/engines/grim/lua_v1_actor.cpp b/engines/grim/lua_v1_actor.cpp index 475ffd8be90..116f0abb7ce 100644 --- a/engines/grim/lua_v1_actor.cpp +++ b/engines/grim/lua_v1_actor.cpp @@ -734,7 +734,7 @@ void L1_GetActorCostume() { return; if (costume) - lua_pushstring(const_cast(costume->getFilename())); + lua_pushstring(costume->getFilename().c_str()); else lua_pushnil(); } @@ -746,7 +746,7 @@ void L1_PopActorCostume() { Actor *actor = getactor(actorObj); if (actor->getCurrentCostume()) { - lua_pushstring(const_cast(actor->getCurrentCostume()->getFilename())); + lua_pushstring(actor->getCurrentCostume()->getFilename().c_str()); actor->popCostume(); } else lua_pushnil(); diff --git a/engines/grim/lua_v2.cpp b/engines/grim/lua_v2.cpp index 87563e3831c..c1a59e8330e 100644 --- a/engines/grim/lua_v2.cpp +++ b/engines/grim/lua_v2.cpp @@ -63,7 +63,7 @@ void L2_DimScreen() { dim = lua_getnumber(dimObj); // FIXME func(dim); - warning("L2_DimScreen: dim: %d", dim); + warning("L2_DimScreen: dim: %f", dim); } void L2_MakeCurrentSetup() { @@ -89,7 +89,7 @@ void L2_SetActorGlobalAlpha() { if (!actor) return; - warning("L2_SetActorGlobalAlpha: actor: %s", actor->getName()); + warning("L2_SetActorGlobalAlpha: actor: %s", actor->getName().c_str()); /* Only when actor has primitives if (!actor->primities) @@ -127,7 +127,7 @@ void L2_RemoveActorFromOverworld() { if (!actor) return; - warning("L2_RemoveActorFromOverworld: actor: %s", actor->getName()); + warning("L2_RemoveActorFromOverworld: actor: %s", actor->getName().c_str()); // FIXME actor->func(); } @@ -141,7 +141,7 @@ void L2_UnloadActor() { if (!actor) return; - warning("L2_UnloadActor: actor: %s", actor->getName()); + warning("L2_UnloadActor: actor: %s", actor->getName().c_str()); // FIXME actor->func(); } @@ -250,7 +250,7 @@ void L2_SetActorSortOrder() { Actor *actor = getactor(actorObj); int mode = (int)lua_getnumber(modeObj); - warning("L2_SetActorSortOrder, actor: %s, mode: %d", actor->getName(), mode); + warning("L2_SetActorSortOrder, actor: %s, mode: %d", actor->getName().c_str(), mode); // FIXME: actor->func(mode); } @@ -269,7 +269,7 @@ void L2_ActorActivateShadow() { const char *plane = "NULL"; if (lua_isstring(planeObj)) plane = lua_getstring(planeObj); - warning("L2_ActorActivateShadow, actor: %s, aquality: %d, plane: %s", actor->getName(), quality, plane); + warning("L2_ActorActivateShadow, actor: %s, aquality: %d, plane: %s", actor->getName().c_str(), quality, plane); // FIXME: implement missing rest part of code } @@ -281,7 +281,7 @@ void L2_ActorStopMoving() { Actor *actor = getactor(actorObj); - warning("L2_ActorStopMoving, actor: %s", actor->getName()); + warning("L2_ActorStopMoving, actor: %s", actor->getName().c_str()); // FIXME: implement missing rest part of code } @@ -293,7 +293,7 @@ void L2_PutActorInOverworld() { Actor *actor = getactor(actorObj); - warning("L2_PutActorInOverworld, actor: %s", actor->getName()); + warning("L2_PutActorInOverworld, actor: %s", actor->getName().c_str()); // FIXME: implement missing func //actor->func(); } @@ -450,7 +450,7 @@ void L2_PlayActorChore() { const char *costumeName = lua_getstring(costumeObj); warning("L2_PlayActorChore: implement opcode actor: %s, chore: %s, costume: %s, mode bool: %d, param: %f", - actor->getName(), choreName, costumeName, (int)mode, param); + actor->getName().c_str(), choreName, costumeName, (int)mode, param); // FIXME. code below is a hack, need proper implementation actor->setCostume(costumeName); Costume *costume = actor->getCurrentCostume(); @@ -472,7 +472,7 @@ static void L2_StopActorChores() { bool p = lua_isnil(paramObj) != 0; // I'm not fully sure about bool logic here //actor->func(p); - warning("L2_StopActorChores: implement opcode... bool param: %d, actor: %s", (int)p, actor->getName()); + warning("L2_StopActorChores: implement opcode... bool param: %d, actor: %s", (int)p, actor->getName().c_str()); } static void L2_SetActorLighting() { @@ -493,17 +493,17 @@ static void L2_SetActorLighting() { if (lightMode != 0) { if (lightMode == 1) { //FIXME actor-> - warning("L2_SetActorLighting: case param 1(LIGHT_FASTDYN), actor: %s", actor->getName()); + warning("L2_SetActorLighting: case param 1(LIGHT_FASTDYN), actor: %s", actor->getName().c_str()); } else if (lightMode == 2) { //FIXME actor-> - warning("L2_SetActorLighting: case param 2(LIGHT_NORMDYN), actor: %s", actor->getName()); + warning("L2_SetActorLighting: case param 2(LIGHT_NORMDYN), actor: %s", actor->getName().c_str()); } else { //FIXME actor-> - warning("L2_SetActorLighting: case param %d(LIGHT_NONE), actor: %s", lightMode, actor->getName()); + warning("L2_SetActorLighting: case param %d(LIGHT_NONE), actor: %s", lightMode, actor->getName().c_str()); } } else { //FIXME actor-> - warning("L2_SetActorLighting: case param 0(LIGHT_STATIC), actor: %s", actor->getName()); + warning("L2_SetActorLighting: case param 0(LIGHT_STATIC), actor: %s", actor->getName().c_str()); } } diff --git a/engines/grim/material.cpp b/engines/grim/material.cpp index 5da8b204d5e..9cceffa9578 100644 --- a/engines/grim/material.cpp +++ b/engines/grim/material.cpp @@ -29,7 +29,7 @@ namespace Grim { -Material::Material(const char *filename, const char *data, int len, CMap *cmap) : +Material::Material(const Common::String &filename, const char *data, int len, CMap *cmap) : Object(), _fname(filename), _cmap(cmap) { if (len < 4 || memcmp(data, "MAT ", 4) != 0) error("invalid magic loading texture"); @@ -50,7 +50,7 @@ Material::Material(const char *filename, const char *data, int len, CMap *cmap) if (_width == 0 || _height == 0) { if (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) - warning("skip load texture: bad texture size (%dx%d) for texture %s", _width, _height, filename); + warning("skip load texture: bad texture size (%dx%d) for texture %s", _width, _height, _fname.c_str()); return; } diff --git a/engines/grim/material.h b/engines/grim/material.h index c81e8d32406..1ea70fadc26 100644 --- a/engines/grim/material.h +++ b/engines/grim/material.h @@ -33,7 +33,7 @@ class Material : public Object { public: Material() { _width = 0; } // Load a texture from the given data. - Material(const char *filename, const char *data, int len, CMap *cmap); + Material(const Common::String &filename, const char *data, int len, CMap *cmap); // Load this texture into the GL context void select() const; @@ -43,7 +43,7 @@ public: int getNumImages() const { return _numImages; } int getCurrentImage() const { return _currImage; } - const char *getFilename() { return _fname.c_str(); } + const Common::String &getFilename() { return _fname; } ~Material(); diff --git a/engines/grim/model.cpp b/engines/grim/model.cpp index 0ed1b7539b8..694c50c4cf3 100644 --- a/engines/grim/model.cpp +++ b/engines/grim/model.cpp @@ -41,7 +41,7 @@ void Sprite::draw() const { g_driver->drawSprite(this); } -Model::Model(const char *filename, const char *data, int len, CMap *cmap) : +Model::Model(const Common::String &filename, const char *data, int len, CMap *cmap) : Object(), _numMaterials(0), _numGeosets(0), _cmap(cmap) { _fname = filename; _headNode = NULL; diff --git a/engines/grim/model.h b/engines/grim/model.h index bb885a581ec..6a330369a95 100644 --- a/engines/grim/model.h +++ b/engines/grim/model.h @@ -47,7 +47,7 @@ struct Sprite { class Model : public Object { public: // Construct a 3D model from the given data. - Model(const char *filename, const char *data, int len, CMap *cmap); + Model(const Common::String &filename, const char *data, int len, CMap *cmap); void loadBinary(const char *&data, CMap *cmap); void loadText(TextSplitter *ts, CMap *cmap); void loadEMI(Common::MemoryReadStream &ms); diff --git a/engines/grim/objectstate.cpp b/engines/grim/objectstate.cpp index 406c39db62b..076f03251c1 100644 --- a/engines/grim/objectstate.cpp +++ b/engines/grim/objectstate.cpp @@ -54,7 +54,7 @@ ObjectState::~ObjectState() { delete _zbitmap; } -const char *ObjectState::getBitmapFilename() const { +const Common::String &ObjectState::getBitmapFilename() const { return _bitmap->getFilename(); } diff --git a/engines/grim/objectstate.h b/engines/grim/objectstate.h index f5f04637dd6..02417775de6 100644 --- a/engines/grim/objectstate.h +++ b/engines/grim/objectstate.h @@ -50,7 +50,7 @@ public: Position getPos() const { return _pos; } void setPos(Position position) { _pos = position; } - const char *getBitmapFilename() const; + const Common::String &getBitmapFilename() const; void setNumber(int val); void draw(); diff --git a/engines/grim/resource.cpp b/engines/grim/resource.cpp index 1124d25396b..8b7d695e690 100644 --- a/engines/grim/resource.cpp +++ b/engines/grim/resource.cpp @@ -449,7 +449,7 @@ KeyframeAnimPtr ResourceLoader::getKeyframe(const char *fname) { filename.toLowercase(); for (Common::List::const_iterator i = _keyframeAnims.begin(); i != _keyframeAnims.end(); ++i) { KeyframeAnim *k = *i; - if (strcmp(filename.c_str(), k->getFilename()) == 0) { + if (filename == k->getFilename()) { return k; } } @@ -478,7 +478,7 @@ LipSyncPtr ResourceLoader::getLipSync(const char *fname) { filename.toLowercase(); for (Common::List::const_iterator i = _lipsyncs.begin(); i != _lipsyncs.end(); ++i) { LipSync *l = *i; - if (strcmp(filename.c_str(), l->getFilename()) == 0) { + if (filename.c_str() == l->getFilename()) { return l; } } diff --git a/engines/grim/savegame.cpp b/engines/grim/savegame.cpp index 22e840f7bbc..125d662dbbd 100644 --- a/engines/grim/savegame.cpp +++ b/engines/grim/savegame.cpp @@ -36,7 +36,7 @@ namespace Grim { int SaveGame::SAVEGAME_VERSION = 14; // Constructor. Should create/open a saved game -SaveGame::SaveGame(const char *filename, bool saving) : +SaveGame::SaveGame(const Common::String &filename, bool saving) : _saving(saving), _currentSection(0) { if (_saving) { _outSaveFile = g_system->getSavefileManager()->openForSaving(filename); @@ -303,7 +303,9 @@ void SaveGame::writeCharString(const char *string) { } void SaveGame::writeString(const Common::String &string) { - writeCharString(string.c_str()); + int32 len = string.size(); + writeLESint32(len); + write(string.c_str(), len); } Graphics::Vector3d SaveGame::readVector3d() { @@ -350,9 +352,9 @@ const char *SaveGame::readCharString() { } Common::String SaveGame::readString() { - const char *str = readCharString(); - Common::String s = str; - delete[] str; + int32 len = readLESint32(); + Common::String s((const char *)&_sectionBuffer[_sectionPtr], len); + _sectionPtr += len; return s; } diff --git a/engines/grim/savegame.h b/engines/grim/savegame.h index d9c38b3fedb..d028a0fb5cc 100644 --- a/engines/grim/savegame.h +++ b/engines/grim/savegame.h @@ -35,7 +35,7 @@ class Color; class SaveGame { public: - SaveGame(const char *filename, bool saving); + SaveGame(const Common::String &filename, bool saving); ~SaveGame(); static int SAVEGAME_VERSION; diff --git a/engines/grim/scene.cpp b/engines/grim/scene.cpp index 649e1e98dd5..328ec96340d 100644 --- a/engines/grim/scene.cpp +++ b/engines/grim/scene.cpp @@ -39,7 +39,7 @@ namespace Grim { int Scene::s_id = 0; -Scene::Scene(const char *sceneName, const char *buf, int len) : +Scene::Scene(const Common::String &sceneName, const char *buf, int len) : _locked(false), _name(sceneName), _enableLights(false) { ++s_id; @@ -193,7 +193,7 @@ void Scene::saveState(SaveGame *savedState) const { savedState->writeString(_name); savedState->writeLESint32(_numCmaps); for (int i = 0; i < _numCmaps; ++i) { - savedState->writeCharString(_cmaps[i]->getFilename()); + savedState->writeString(_cmaps[i]->getFilename()); } savedState->writeLEUint32(_currSetup - _setups); // current setup id savedState->writeLEUint32(_locked); @@ -537,13 +537,13 @@ void Scene::findClosestSector(Graphics::Vector3d p, Sector **sect, Graphics::Vec ObjectState *Scene::findState(const char *filename) { // Check the different state objects for the bitmap for (StateList::iterator i = _states.begin(); i != _states.end(); ++i) { - const char *file = (*i)->getBitmapFilename(); + const Common::String &file = (*i)->getBitmapFilename(); - if (strcmp(file, filename) == 0) + if (file == filename) return *i; - if (scumm_stricmp(file, filename) == 0) { + if (file.compareToIgnoreCase(filename) == 0) { if (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) - warning("State object request '%s' matches object '%s' but is the wrong case", filename, file); + warning("State object request '%s' matches object '%s' but is the wrong case", filename, file.c_str()); return *i; } } diff --git a/engines/grim/scene.h b/engines/grim/scene.h index 7c4092b1a8e..16e0bdc99a4 100644 --- a/engines/grim/scene.h +++ b/engines/grim/scene.h @@ -37,7 +37,7 @@ class CMap; class Scene { public: - Scene(const char *name, const char *buf, int len); + Scene(const Common::String &name, const char *buf, int len); Scene(); ~Scene(); @@ -63,7 +63,7 @@ public: void setSoundParameters(int minVolume, int maxVolume); void getSoundParameters(int *minVolume, int *maxVolume); - const char *getName() const { return _name.c_str(); } + const Common::String &getName() const { return _name; } void setLightEnableState(bool state) { _enableLights = state;