From 94aeca96637f20322cf2a120abdbbbcd7227baef Mon Sep 17 00:00:00 2001 From: Joel Teichroeb Date: Thu, 5 Apr 2012 15:20:30 -0700 Subject: [PATCH] GRIM: Remove tag from the pool template --- engines/grim/actor.cpp | 5 +- engines/grim/actor.h | 4 +- engines/grim/bitmap.cpp | 9 +-- engines/grim/bitmap.h | 4 +- engines/grim/costume/chore.h | 5 +- engines/grim/emi/lua_v2_sound.cpp | 3 +- engines/grim/font.cpp | 4 +- engines/grim/font.h | 5 +- engines/grim/objectstate.cpp | 4 +- engines/grim/objectstate.h | 4 +- engines/grim/pool.h | 118 ++++++++++++++---------------- engines/grim/primitives.cpp | 3 +- engines/grim/primitives.h | 4 +- engines/grim/set.cpp | 5 +- engines/grim/set.h | 4 +- engines/grim/textobject.cpp | 4 +- engines/grim/textobject.h | 4 +- 17 files changed, 94 insertions(+), 95 deletions(-) diff --git a/engines/grim/actor.cpp b/engines/grim/actor.cpp index 0827306287e..682db9e2c0f 100644 --- a/engines/grim/actor.cpp +++ b/engines/grim/actor.cpp @@ -63,7 +63,7 @@ void Actor::restoreStaticState(SaveGame *state) { } Actor::Actor(const Common::String &actorName) : - PoolObject(), _name(actorName), _setName(""), + _name(actorName), _setName(""), _talkColor(255, 255, 255), _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 @@ -98,8 +98,7 @@ Actor::Actor(const Common::String &actorName) : } } -Actor::Actor() : - PoolObject() { +Actor::Actor() { _shadowArray = new Shadow[5]; _running = false; diff --git a/engines/grim/actor.h b/engines/grim/actor.h index ce4731b7fba..500ce162b54 100644 --- a/engines/grim/actor.h +++ b/engines/grim/actor.h @@ -63,7 +63,7 @@ struct Shadow { * * @short Actor represents a 3D character on screen. */ -class Actor : public PoolObject { +class Actor : public PoolObject { public: enum CollisionMode { CollisionOff = 0, @@ -87,6 +87,8 @@ public: */ ~Actor(); + static int32 getStaticTag() { return MKTAG('A', 'C', 'T', 'R'); } + /** * Saves the actor state. * diff --git a/engines/grim/bitmap.cpp b/engines/grim/bitmap.cpp index 27d04127c73..e28be1661c3 100644 --- a/engines/grim/bitmap.cpp +++ b/engines/grim/bitmap.cpp @@ -389,20 +389,17 @@ const Graphics::PixelBuffer &BitmapData::getImageData(int num) const { // Bitmap -Bitmap::Bitmap(const Common::String &fname) : - PoolObject() { +Bitmap::Bitmap(const Common::String &fname) { _data = BitmapData::getBitmapData(fname); _currImage = 1; } -Bitmap::Bitmap(const Graphics::PixelBuffer &buf, int w, int h, const char *fname) : - PoolObject() { +Bitmap::Bitmap(const Graphics::PixelBuffer &buf, int w, int h, const char *fname) { _data = new BitmapData(buf, w, h, fname); _currImage = 1; } -Bitmap::Bitmap() : - PoolObject() { +Bitmap::Bitmap() { _data = new BitmapData(); } diff --git a/engines/grim/bitmap.h b/engines/grim/bitmap.h index 79303017a4a..9fcb8122aa8 100644 --- a/engines/grim/bitmap.h +++ b/engines/grim/bitmap.h @@ -106,7 +106,7 @@ public: Graphics::PixelBuffer *_data; }; -class Bitmap : public PoolObject { +class Bitmap : public PoolObject { public: /** * Construct a bitmap from the given data. @@ -119,6 +119,8 @@ public: Bitmap(const Graphics::PixelBuffer &buf, int width, int height, const char *filename); Bitmap(); + static int32 getStaticTag() { return MKTAG('V', 'B', 'U', 'F'); } + static Bitmap *create(const Common::String &filename); const Common::String &getFilename() const { return _data->_fname; } diff --git a/engines/grim/costume/chore.h b/engines/grim/costume/chore.h index 6e2331b9f60..7d80b96776e 100644 --- a/engines/grim/costume/chore.h +++ b/engines/grim/costume/chore.h @@ -87,9 +87,10 @@ private: friend class EMICostume; }; -class PoolChore : public PoolObject, public Chore { +class PoolChore : public PoolObject, public Chore { public: - virtual int getId() { return PoolObject::getId(); } + virtual int getId() { return PoolObject::getId(); } + static int32 getStaticTag() { return MKTAG('C', 'H', 'O', 'R'); } }; } // end of namespace Grim diff --git a/engines/grim/emi/lua_v2_sound.cpp b/engines/grim/emi/lua_v2_sound.cpp index bc041579828..24d9bacdb55 100644 --- a/engines/grim/emi/lua_v2_sound.cpp +++ b/engines/grim/emi/lua_v2_sound.cpp @@ -179,9 +179,10 @@ void Lua_V2::ImFlushStack() { warning("Lua_V2::ImFlushStack: implement opcode"); } -class PoolSound : public PoolObject{ +class PoolSound : public PoolObject{ public: PoolSound(const Common::String &filename); + static int32 getStaticTag() { return MKTAG('A', 'I', 'F', 'F'); } AIFFTrack *track; }; diff --git a/engines/grim/font.cpp b/engines/grim/font.cpp index 8c009845f09..2ff5e5cd433 100644 --- a/engines/grim/font.cpp +++ b/engines/grim/font.cpp @@ -32,13 +32,13 @@ namespace Grim { Font::Font(const Common::String &filename, Common::SeekableReadStream *data) : - PoolObject(), _userData(NULL), + _userData(NULL), _fontData(NULL), _charHeaders(NULL), _charIndex(NULL) { load(filename, data); } Font::Font() : - PoolObject(), _userData(NULL), + _userData(NULL), _fontData(NULL), _charHeaders(NULL), _charIndex(NULL) { diff --git a/engines/grim/font.h b/engines/grim/font.h index cf23b63d5b2..d02b0ba9d6e 100644 --- a/engines/grim/font.h +++ b/engines/grim/font.h @@ -33,11 +33,14 @@ namespace Grim { class SaveGame; -class Font : public PoolObject { +class Font : public PoolObject { public: Font(const Common::String &filename, Common::SeekableReadStream *data); Font(); ~Font(); + + static int32 getStaticTag() { return MKTAG('F', 'O', 'N', 'T'); } + void load(const Common::String &filename, Common::SeekableReadStream *data); const Common::String &getFilename() const { return _filename; } diff --git a/engines/grim/objectstate.cpp b/engines/grim/objectstate.cpp index 12fc72712ab..a0fe6ccda68 100644 --- a/engines/grim/objectstate.cpp +++ b/engines/grim/objectstate.cpp @@ -28,7 +28,7 @@ namespace Grim { ObjectState::ObjectState(int setup, ObjectState::Position position, const char *bitmap, const char *zbitmap, bool transparency) : - PoolObject(), _setupID(setup), _pos(position), _visibility(false) { + _setupID(setup), _pos(position), _visibility(false) { _bitmap = Bitmap::create(bitmap); if (zbitmap) { @@ -38,7 +38,7 @@ ObjectState::ObjectState(int setup, ObjectState::Position position, const char * } ObjectState::ObjectState() : - PoolObject(), _bitmap(NULL), _zbitmap(NULL) { + _bitmap(NULL), _zbitmap(NULL) { } diff --git a/engines/grim/objectstate.h b/engines/grim/objectstate.h index 8ec1e42a1c4..b922d6b784d 100644 --- a/engines/grim/objectstate.h +++ b/engines/grim/objectstate.h @@ -32,7 +32,7 @@ namespace Grim { class SaveGame; -class ObjectState : public PoolObject { +class ObjectState : public PoolObject { public: enum Position { OBJSTATE_BACKGROUND = 0, @@ -45,6 +45,8 @@ public: ObjectState(); ~ObjectState(); + static int32 getStaticTag() { return MKTAG('S', 'T', 'A', 'T'); } + void saveState(SaveGame *savedState) const; bool restoreState(SaveGame *savedState); diff --git a/engines/grim/pool.h b/engines/grim/pool.h index 835756352f7..809ea85b618 100644 --- a/engines/grim/pool.h +++ b/engines/grim/pool.h @@ -18,7 +18,7 @@ public: virtual int32 getTag() const = 0; }; -template +template class PoolObject : public PoolObjectBase { public: class Pool { @@ -118,8 +118,7 @@ public: virtual ~PoolObject(); int getId() const; - int32 getTag() const; - static int32 getTagStatic(); + virtual int32 getTag() const { return T::getStaticTag(); } static Pool &getPool(); @@ -144,24 +143,24 @@ private: friend class Ptr; }; -template -bool operator==(T *obj, const typename PoolObject::Ptr &ptr) { +template +bool operator==(T *obj, const typename PoolObject::Ptr &ptr) { return obj == ptr._obj; } -template -bool operator!=(T *obj, const typename PoolObject::Ptr &ptr) { +template +bool operator!=(T *obj, const typename PoolObject::Ptr &ptr) { return obj != ptr._obj; } -template -int PoolObject::s_id = 0; +template +int PoolObject::s_id = 0; -template -typename PoolObject::Pool *PoolObject::s_pool = NULL; +template +typename PoolObject::Pool *PoolObject::s_pool = NULL; -template -PoolObject::PoolObject() { +template +PoolObject::PoolObject() { ++s_id; _id = s_id; @@ -171,8 +170,8 @@ PoolObject::PoolObject() { s_pool->addObject(static_cast(this)); } -template -PoolObject::~PoolObject() { +template +PoolObject::~PoolObject() { s_pool->removeObject(_id); for (typename Common::List::iterator i = _pointers.begin(); i != _pointers.end(); ++i) { @@ -180,105 +179,94 @@ PoolObject::~PoolObject() { } } -template -void PoolObject::setId(int id) { +template +void PoolObject::setId(int id) { _id = id; if (id > s_id) { s_id = id; } } -template -int PoolObject::getId() const { +template +int PoolObject::getId() const { return _id; } -template -typename PoolObject::Pool &PoolObject::getPool() { +template +typename PoolObject::Pool &PoolObject::getPool() { if (!s_pool) { s_pool = new Pool(); } return *s_pool; } -template -int32 PoolObject::getTag() const { - return tag; -} - -template -int32 PoolObject::getTagStatic() { - return tag; -} - /** * @class Pool */ -template -PoolObject::Pool::Pool() : +template +PoolObject::Pool::Pool() : _restoring(false) { - } -template -PoolObject::Pool::~Pool() { - PoolObject::s_pool = NULL; +template +PoolObject::Pool::~Pool() { + PoolObject::s_pool = NULL; } -template -void PoolObject::Pool::addObject(T *obj) { +template +void PoolObject::Pool::addObject(T *obj) { if (!_restoring) { _map.setVal(obj->_id, obj); } } -template -void PoolObject::Pool::removeObject(int32 id) { +template +void PoolObject::Pool::removeObject(int32 id) { _map.erase(id); } -template -T *PoolObject::Pool::getObject(int32 id) { +template +T *PoolObject::Pool::getObject(int32 id) { return _map.getVal(id, NULL); } -template -typename PoolObject::Pool::iterator PoolObject::Pool::begin() { +template +typename PoolObject::Pool::iterator PoolObject::Pool::begin() { return iterator(_map.begin()); } -template -typename PoolObject::Pool::const_iterator PoolObject::Pool::begin() const { +template +typename PoolObject::Pool::const_iterator PoolObject::Pool::begin() const { return const_iterator(_map.begin()); } -template -typename PoolObject::Pool::iterator PoolObject::Pool::end() { +template +typename PoolObject::Pool::iterator PoolObject::Pool::end() { return iterator(_map.end()); } -template -typename PoolObject::Pool::const_iterator PoolObject::Pool::end() const { +template +typename PoolObject::Pool::const_iterator PoolObject::Pool::end() const { return const_iterator(_map.end()); } -template -int PoolObject::Pool::getSize() const { +template +int PoolObject::Pool::getSize() const { return _map.size(); } -template -void PoolObject::Pool::deleteObjects() { +template +void PoolObject::Pool::deleteObjects() { while (!_map.empty()) { delete *begin(); } delete this; } -template -void PoolObject::Pool::saveObjects(SaveGame *state) { - state->beginSection(tag); +template +void PoolObject::Pool::saveObjects(SaveGame *state) { + state->beginSection(T::getStaticTag()); T::saveStaticState(state); @@ -293,9 +281,9 @@ void PoolObject::Pool::saveObjects(SaveGame *state) { state->endSection(); } -template -void PoolObject::Pool::restoreObjects(SaveGame *state) { - state->beginSection(tag); +template +void PoolObject::Pool::restoreObjects(SaveGame *state) { + state->beginSection(T::getStaticTag()); T::restoreStaticState(state); @@ -322,8 +310,8 @@ void PoolObject::Pool::restoreObjects(SaveGame *state) { state->endSection(); } -template -typename PoolObject::Ptr &PoolObject::Ptr::operator=(T *obj) { +template +typename PoolObject::Ptr &PoolObject::Ptr::operator=(T *obj) { if (_obj) { _obj->removePointer(this); } @@ -335,8 +323,8 @@ typename PoolObject::Ptr &PoolObject::Ptr::operator=(T *obj) { return *this; } -template -typename PoolObject::Ptr &PoolObject::Ptr::operator=(const Ptr &ptr) { +template +typename PoolObject::Ptr &PoolObject::Ptr::operator=(const Ptr &ptr) { if (_obj) { _obj->removePointer(this); } diff --git a/engines/grim/primitives.cpp b/engines/grim/primitives.cpp index 64df42dfe06..380b1e08bc0 100644 --- a/engines/grim/primitives.cpp +++ b/engines/grim/primitives.cpp @@ -28,8 +28,7 @@ namespace Grim { -PrimitiveObject::PrimitiveObject() : - PoolObject() { +PrimitiveObject::PrimitiveObject() { _filled = false; _type = 0; } diff --git a/engines/grim/primitives.h b/engines/grim/primitives.h index fcc8f89bd07..676051c8659 100644 --- a/engines/grim/primitives.h +++ b/engines/grim/primitives.h @@ -32,11 +32,13 @@ namespace Grim { class SaveGame; -class PrimitiveObject : public PoolObject { +class PrimitiveObject : public PoolObject { public: PrimitiveObject(); ~PrimitiveObject(); + static int32 getStaticTag() { return MKTAG('P', 'R', 'I', 'M'); } + typedef enum { RECTANGLE = 1, LINE, diff --git a/engines/grim/set.cpp b/engines/grim/set.cpp index 5e696a464ce..a9dd7e87bab 100644 --- a/engines/grim/set.cpp +++ b/engines/grim/set.cpp @@ -39,7 +39,7 @@ namespace Grim { Set::Set(const Common::String &sceneName, Common::SeekableReadStream *data) : - PoolObject(), _locked(false), _name(sceneName), _enableLights(false) { + _locked(false), _name(sceneName), _enableLights(false) { char header[7]; data->read(header, 7); @@ -52,8 +52,7 @@ Set::Set(const Common::String &sceneName, Common::SeekableReadStream *data) : } } -Set::Set() : - PoolObject(), _cmaps(NULL) { +Set::Set() : _cmaps(NULL) { } diff --git a/engines/grim/set.h b/engines/grim/set.h index c537b2ae5d6..06bafc8b591 100644 --- a/engines/grim/set.h +++ b/engines/grim/set.h @@ -38,12 +38,14 @@ class SaveGame; class CMap; class Light; -class Set : public PoolObject { +class Set : public PoolObject { public: Set(const Common::String &name, Common::SeekableReadStream *data); Set(); ~Set(); + static int32 getStaticTag() { return MKTAG('S', 'E', 'T', ' '); } + void loadText(TextSplitter &ts); void loadBinary(Common::SeekableReadStream *data); diff --git a/engines/grim/textobject.cpp b/engines/grim/textobject.cpp index b09e0e9a111..81faf85256e 100644 --- a/engines/grim/textobject.cpp +++ b/engines/grim/textobject.cpp @@ -37,14 +37,14 @@ TextObjectCommon::TextObjectCommon() : } TextObject::TextObject(bool blastDraw, bool isSpeech) : - PoolObject(), TextObjectCommon(), _numberLines(1), + TextObjectCommon(), _numberLines(1), _maxLineWidth(0), _lines(0), _userData(0), _created(false) { _blastDraw = blastDraw; _isSpeech = isSpeech; } TextObject::TextObject() : - PoolObject(), TextObjectCommon(), _maxLineWidth(0), _lines(NULL) { + TextObjectCommon(), _maxLineWidth(0), _lines(NULL) { } diff --git a/engines/grim/textobject.h b/engines/grim/textobject.h index 7d86c1bb402..d11f1c99c3a 100644 --- a/engines/grim/textobject.h +++ b/engines/grim/textobject.h @@ -76,13 +76,15 @@ class TextObjectDefaults : public TextObjectCommon { }; -class TextObject : public PoolObject, +class TextObject : public PoolObject, public TextObjectCommon { public: TextObject(bool blastDraw, bool isSpeech = false); TextObject(); ~TextObject(); + static int32 getStaticTag() { return MKTAG('T', 'E', 'X', 'T'); } + void setDefaults(TextObjectDefaults *defaults); void setText(const Common::String &text); void reset();