From 4751516279bd910fef4d27826335145af070599b Mon Sep 17 00:00:00 2001 From: Joel Teichroeb Date: Fri, 13 May 2011 17:55:14 -0700 Subject: [PATCH 1/2] Cleaned up dependencies between files. --- engines/grim/actor.cpp | 2 ++ engines/grim/actor.h | 11 ++++++----- engines/grim/bitmap.h | 1 - engines/grim/color.h | 1 - engines/grim/colormap.h | 26 ++++---------------------- engines/grim/costume.cpp | 4 +++- engines/grim/costume.h | 9 +++++---- engines/grim/font.cpp | 1 + engines/grim/font.h | 1 - engines/grim/gfx_base.cpp | 1 + engines/grim/gfx_base.h | 4 ++-- engines/grim/gfx_opengl.cpp | 2 ++ engines/grim/gfx_tinygl.cpp | 2 ++ engines/grim/grim.cpp | 4 ++++ engines/grim/grim.h | 14 +++++++++++--- engines/grim/imuse/imuse_mcmp_mgr.cpp | 1 + engines/grim/imuse/imuse_sndmgr.cpp | 1 + engines/grim/keyframe.cpp | 1 + engines/grim/keyframe.h | 1 - engines/grim/lipsync.cpp | 1 + engines/grim/lipsync.h | 1 - engines/grim/lua_v1.cpp | 3 +++ engines/grim/lua_v1_graphics.cpp | 4 ++++ engines/grim/lua_v1_sound.cpp | 2 ++ engines/grim/lua_v1_text.cpp | 2 ++ engines/grim/lua_v2.cpp | 2 +- engines/grim/material.cpp | 1 + engines/grim/material.h | 6 +++--- engines/grim/model.cpp | 1 + engines/grim/model.h | 8 ++++---- engines/grim/object.h | 10 ++++++---- engines/grim/objectstate.cpp | 25 +++++++++++++++++++++++++ engines/grim/objectstate.h | 26 ++++---------------------- engines/grim/primitives.cpp | 5 +++-- engines/grim/primitives.h | 7 +++---- engines/grim/resource.cpp | 4 +++- engines/grim/resource.h | 5 ++++- engines/grim/scene.cpp | 4 +++- engines/grim/scene.h | 3 ++- engines/grim/smush/smush.cpp | 2 ++ engines/grim/textobject.cpp | 15 +++++++++++++++ engines/grim/textobject.h | 16 +++------------- 42 files changed, 141 insertions(+), 99 deletions(-) diff --git a/engines/grim/actor.cpp b/engines/grim/actor.cpp index bbd0a37a798..66d80ce6c40 100644 --- a/engines/grim/actor.cpp +++ b/engines/grim/actor.cpp @@ -39,6 +39,8 @@ #include "engines/grim/smush/video.h" #include "engines/grim/imuse/imuse.h" #include "engines/grim/lua.h" +#include "engines/grim/resource.h" +#include "engines/grim/savegame.h" namespace Grim { diff --git a/engines/grim/actor.h b/engines/grim/actor.h index 8824b291674..c99ae5f1ed6 100644 --- a/engines/grim/actor.h +++ b/engines/grim/actor.h @@ -27,15 +27,16 @@ #define GRIM_ACTOR_H #include "engines/grim/object.h" -#include "engines/grim/color.h" -#include "engines/grim/resource.h" -#include "engines/grim/savegame.h" #include "graphics/vector3d.h" namespace Grim { class TextObject; class Sector; +class Costume; +class LipSync; +class Font; +class Color; typedef Common::List SectorListType; @@ -192,7 +193,7 @@ private: float _scale; bool _lookingMode; Common::String _talkSoundName; - LipSyncPtr _lipSync; + ObjectPtr _lipSync; Common::List _costumeStack; // Variables for gradual turning @@ -228,7 +229,7 @@ private: Shadow *_shadowArray; int _activeShadowSlot; - static FontPtr _sayLineFont; + static ObjectPtr _sayLineFont; TextObject *_sayLineText; // Validate a yaw angle then set it appropriately diff --git a/engines/grim/bitmap.h b/engines/grim/bitmap.h index 61058a1e055..fd8e93eab7a 100644 --- a/engines/grim/bitmap.h +++ b/engines/grim/bitmap.h @@ -26,7 +26,6 @@ #ifndef GRIM_BITMAP_H #define GRIM_BITMAP_H -#include "engines/grim/resource.h" #include "engines/grim/object.h" namespace Grim { diff --git a/engines/grim/color.h b/engines/grim/color.h index 27e2de801f3..6d8235915aa 100644 --- a/engines/grim/color.h +++ b/engines/grim/color.h @@ -27,7 +27,6 @@ #define GRIM_COLOR_H #include "common/scummsys.h" -#include "engines/grim/savegame.h" #include "engines/grim/object.h" namespace Grim { diff --git a/engines/grim/colormap.h b/engines/grim/colormap.h index dc510304b34..651845fa24a 100644 --- a/engines/grim/colormap.h +++ b/engines/grim/colormap.h @@ -26,9 +26,6 @@ #ifndef GRIM_COLORMAP_H #define GRIM_COLORMAP_H -#include "common/endian.h" - -#include "engines/grim/resource.h" #include "engines/grim/object.h" namespace Grim { @@ -36,31 +33,16 @@ namespace Grim { class CMap : public Object { public: // Load a colormap from the given data. - CMap(const char *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)); - } - CMap() : Object() {} - ~CMap() { - if (g_resourceloader) - g_resourceloader->uncacheColormap(this); - } + CMap(const char *fileName, const char *data, int len); + CMap(); + ~CMap(); const char *getFilename() const { return _fname.c_str(); } // The color data, in RGB format char _colors[256 * 3]; Common::String _fname; - bool operator==(const CMap &c) const { - if (_fname != c._fname) { - return false; - } - - return true; - } + bool operator==(const CMap &c) const; }; } // end of namespace Grim diff --git a/engines/grim/costume.cpp b/engines/grim/costume.cpp index 55bd493687f..220e641c3c8 100644 --- a/engines/grim/costume.cpp +++ b/engines/grim/costume.cpp @@ -36,6 +36,8 @@ #include "engines/grim/material.h" #include "engines/grim/lua.h" #include "engines/grim/lipsync.h" +#include "engines/grim/resource.h" +#include "engines/grim/savegame.h" #include "engines/grim/imuse/imuse.h" @@ -149,7 +151,7 @@ public: protected: Common::String _filename; - ModelPtr _obj; + ObjectPtr _obj; Model::HierNode *_hier; Graphics::Matrix4 _matrix; }; diff --git a/engines/grim/costume.h b/engines/grim/costume.h index 384403e8595..5b58b00f522 100644 --- a/engines/grim/costume.h +++ b/engines/grim/costume.h @@ -28,9 +28,8 @@ #include "common/memstream.h" -#include "engines/grim/model.h" #include "engines/grim/object.h" -#include "engines/grim/colormap.h" +#include "engines/grim/model.h" namespace Grim { @@ -38,6 +37,8 @@ namespace Grim { typedef uint32 tag32; +class TextSplitter; + class Costume : public Object { public: Costume(const char *filename, const char *data, int len, Costume *prevCost); @@ -101,7 +102,7 @@ public: virtual ~Component() { } protected: - CMapPtr _cmap, _previousCmap; + ObjectPtr _cmap, _previousCmap; tag32 _tag; int _parentID; bool _visible; @@ -183,7 +184,7 @@ private: friend class Costume; }; - CMapPtr _cmap; + ObjectPtr _cmap; int _numChores; Chore *_chores; Graphics::Matrix4 _matrix; diff --git a/engines/grim/font.cpp b/engines/grim/font.cpp index ad8fec336a0..7a132b99427 100644 --- a/engines/grim/font.cpp +++ b/engines/grim/font.cpp @@ -30,6 +30,7 @@ #include "engines/grim/font.h" #include "engines/grim/lua.h" #include "engines/grim/colormap.h" +#include "engines/grim/resource.h" namespace Grim { diff --git a/engines/grim/font.h b/engines/grim/font.h index 903606c139d..87f9dadf22a 100644 --- a/engines/grim/font.h +++ b/engines/grim/font.h @@ -26,7 +26,6 @@ #ifndef GRIM_FONT_H #define GRIM_FONT_H -#include "engines/grim/resource.h" #include "engines/grim/object.h" namespace Grim { diff --git a/engines/grim/gfx_base.cpp b/engines/grim/gfx_base.cpp index 7d8226ae484..460d343bd17 100644 --- a/engines/grim/gfx_base.cpp +++ b/engines/grim/gfx_base.cpp @@ -25,6 +25,7 @@ #include "engines/grim/gfx_base.h" #include "engines/grim/savegame.h" +#include "engines/grim/colormap.h" namespace Grim { diff --git a/engines/grim/gfx_base.h b/engines/grim/gfx_base.h index 1d26e0a39b9..2bea8e9af81 100644 --- a/engines/grim/gfx_base.h +++ b/engines/grim/gfx_base.h @@ -26,15 +26,15 @@ #ifndef GRIM_GFX_BASE_H #define GRIM_GFX_BASE_H -#include "engines/grim/colormap.h" #include "engines/grim/model.h" #include "engines/grim/scene.h" -#include "engines/grim/primitives.h" namespace Grim { struct Shadow; class SaveGame; +class BitmapData; +class PrimitiveObject; class GfxBase { public: diff --git a/engines/grim/gfx_opengl.cpp b/engines/grim/gfx_opengl.cpp index 3d1d58f7008..d1b672014f8 100644 --- a/engines/grim/gfx_opengl.cpp +++ b/engines/grim/gfx_opengl.cpp @@ -39,6 +39,8 @@ #include "engines/grim/gfx_opengl.h" #include "engines/grim/grim.h" #include "engines/grim/lipsync.h" +#include "engines/grim/bitmap.h" +#include "engines/grim/primitives.h" #ifdef USE_OPENGL diff --git a/engines/grim/gfx_tinygl.cpp b/engines/grim/gfx_tinygl.cpp index 9c7ee1ecddf..e0eac57d976 100644 --- a/engines/grim/gfx_tinygl.cpp +++ b/engines/grim/gfx_tinygl.cpp @@ -33,6 +33,8 @@ #include "engines/grim/gfx_tinygl.h" #include "engines/grim/grim.h" #include "engines/grim/lipsync.h" +#include "engines/grim/bitmap.h" +#include "engines/grim/primitives.h" namespace Grim { diff --git a/engines/grim/grim.cpp b/engines/grim/grim.cpp index 4f84669ae44..42ca1c7020a 100644 --- a/engines/grim/grim.cpp +++ b/engines/grim/grim.cpp @@ -61,6 +61,10 @@ #include "engines/grim/costume.h" #include "engines/grim/material.h" #include "engines/grim/lipsync.h" +#include "engines/grim/lab.h" +#include "engines/grim/bitmap.h" +#include "engines/grim/font.h" +#include "engines/grim/primitives.h" #include "engines/grim/lua/lualib.h" diff --git a/engines/grim/grim.h b/engines/grim/grim.h index 7d9a53becfc..69ddb53db9b 100644 --- a/engines/grim/grim.h +++ b/engines/grim/grim.h @@ -28,12 +28,22 @@ #include "engines/engine.h" +#include "common/str-array.h" +#include "common/hashmap.h" + #include "engines/grim/textobject.h" namespace Grim { class Actor; class SaveGame; +class Bitmap; +class Font; +class Color; +class ObjectState; +class Scene; +class TextObject; +class PrimitiveObject; enum enDebugLevels { DEBUG_NONE, DEBUG_NORMAL, DEBUG_WARN, DEBUG_ERROR, DEBUG_LUA, DEBUG_BITMAPS, DEBUG_MODEL, DEBUG_STUB, @@ -236,9 +246,7 @@ public: Common::StringArray _listFiles; Common::StringArray::const_iterator _listFilesIter; - TextObjectDefaults _sayLineDefaults; - TextObjectDefaults _printLineDefaults; - TextObjectDefaults _blastTextDefaults; + TextObjectDefaults _sayLineDefaults, _printLineDefaults, _blastTextDefaults; private: diff --git a/engines/grim/imuse/imuse_mcmp_mgr.cpp b/engines/grim/imuse/imuse_mcmp_mgr.cpp index 6ad0bc79bf9..2fb343f6228 100644 --- a/engines/grim/imuse/imuse_mcmp_mgr.cpp +++ b/engines/grim/imuse/imuse_mcmp_mgr.cpp @@ -27,6 +27,7 @@ #include "engines/grim/grim.h" #include "engines/grim/colormap.h" +#include "engines/grim/resource.h" #include "engines/grim/imuse/imuse_mcmp_mgr.h" diff --git a/engines/grim/imuse/imuse_sndmgr.cpp b/engines/grim/imuse/imuse_sndmgr.cpp index 8cd15c85c2b..0e61c4a7102 100644 --- a/engines/grim/imuse/imuse_sndmgr.cpp +++ b/engines/grim/imuse/imuse_sndmgr.cpp @@ -27,6 +27,7 @@ #include "engines/grim/grim.h" #include "engines/grim/resource.h" +#include "engines/grim/lab.h" #include "engines/grim/colormap.h" #include "engines/grim/imuse/imuse_sndmgr.h" diff --git a/engines/grim/keyframe.cpp b/engines/grim/keyframe.cpp index b436d2f7497..9a76942ab77 100644 --- a/engines/grim/keyframe.cpp +++ b/engines/grim/keyframe.cpp @@ -31,6 +31,7 @@ #include "engines/grim/keyframe.h" #include "engines/grim/textsplit.h" #include "engines/grim/colormap.h" +#include "engines/grim/resource.h" namespace Grim { diff --git a/engines/grim/keyframe.h b/engines/grim/keyframe.h index 35f16ec98bb..b35c9fdb225 100644 --- a/engines/grim/keyframe.h +++ b/engines/grim/keyframe.h @@ -26,7 +26,6 @@ #ifndef GRIM_KEYFRAME_H #define GRIM_KEYFRAME_H -#include "engines/grim/model.h" #include "engines/grim/object.h" namespace Grim { diff --git a/engines/grim/lipsync.cpp b/engines/grim/lipsync.cpp index b75051f163d..25de24e30ea 100644 --- a/engines/grim/lipsync.cpp +++ b/engines/grim/lipsync.cpp @@ -26,6 +26,7 @@ #include "common/endian.h" #include "engines/grim/lipsync.h" +#include "engines/grim/resource.h" namespace Grim { diff --git a/engines/grim/lipsync.h b/engines/grim/lipsync.h index e33e2eeb755..d01cbfa9d39 100644 --- a/engines/grim/lipsync.h +++ b/engines/grim/lipsync.h @@ -26,7 +26,6 @@ #ifndef GRIM_LIPSYNC_H #define GRIM_LIPSYNC_H -#include "engines/grim/resource.h" #include "engines/grim/object.h" namespace Grim { diff --git a/engines/grim/lua_v1.cpp b/engines/grim/lua_v1.cpp index 9f36d573381..47fdd17c58d 100644 --- a/engines/grim/lua_v1.cpp +++ b/engines/grim/lua_v1.cpp @@ -37,6 +37,9 @@ #include "engines/grim/colormap.h" #include "engines/grim/grim.h" #include "engines/grim/savegame.h" +#include "engines/grim/resource.h" +#include "engines/grim/bitmap.h" +#include "engines/grim/font.h" #include "engines/grim/lua/lauxlib.h" #include "engines/grim/lua/luadebug.h" diff --git a/engines/grim/lua_v1_graphics.cpp b/engines/grim/lua_v1_graphics.cpp index fe3c66f0bb6..32f2263fcac 100644 --- a/engines/grim/lua_v1_graphics.cpp +++ b/engines/grim/lua_v1_graphics.cpp @@ -30,6 +30,10 @@ #include "engines/grim/grim.h" #include "engines/grim/lua.h" +#include "engines/grim/resource.h" +#include "engines/grim/colormap.h" +#include "engines/grim/bitmap.h" +#include "engines/grim/primitives.h" #include "engines/grim/smush/video.h" diff --git a/engines/grim/lua_v1_sound.cpp b/engines/grim/lua_v1_sound.cpp index 26f5870f897..0af79692df2 100644 --- a/engines/grim/lua_v1_sound.cpp +++ b/engines/grim/lua_v1_sound.cpp @@ -27,6 +27,8 @@ #include "engines/grim/lua.h" #include "engines/grim/actor.h" #include "engines/grim/lipsync.h" +#include "engines/grim/savegame.h" +#include "engines/grim/colormap.h" #include "engines/grim/imuse/imuse.h" diff --git a/engines/grim/lua_v1_text.cpp b/engines/grim/lua_v1_text.cpp index 83536459215..a62f4625b08 100644 --- a/engines/grim/lua_v1_text.cpp +++ b/engines/grim/lua_v1_text.cpp @@ -31,6 +31,8 @@ #include "engines/grim/localize.h" #include "engines/grim/actor.h" #include "engines/grim/lipsync.h" +#include "engines/grim/savegame.h" +#include "engines/grim/colormap.h" #include "engines/grim/imuse/imuse.h" diff --git a/engines/grim/lua_v2.cpp b/engines/grim/lua_v2.cpp index 0c536e1b1d4..f17c99cd7b0 100644 --- a/engines/grim/lua_v2.cpp +++ b/engines/grim/lua_v2.cpp @@ -118,7 +118,7 @@ void L2_PlayActorChore() { const char *choreName = lua_getstring(choreObj); const char *costumeName = lua_getstring(costumeObj); - warning("L2_PlayActorChore: implement opcode actor: %s, chore: %s, costume: %s, mode bool: %d, param: %f", + warning("L2_PlayActorChore: implement opcode actor: %s, chore: %s, costume: %s, mode bool: %d, param: %f", actor->getName(), choreName, costumeName, (int)mode, param); // FIXME. code below is a hack, need proper implementation actor->setCostume(costumeName); diff --git a/engines/grim/material.cpp b/engines/grim/material.cpp index 87322f7638a..8f734a43b98 100644 --- a/engines/grim/material.cpp +++ b/engines/grim/material.cpp @@ -28,6 +28,7 @@ #include "engines/grim/grim.h" #include "engines/grim/material.h" #include "engines/grim/gfx_base.h" +#include "engines/grim/resource.h" namespace Grim { diff --git a/engines/grim/material.h b/engines/grim/material.h index 9da3b01d324..95d2c8efb08 100644 --- a/engines/grim/material.h +++ b/engines/grim/material.h @@ -26,12 +26,12 @@ #ifndef GRIM_MATERIAL_H #define GRIM_MATERIAL_H -#include "engines/grim/resource.h" #include "engines/grim/object.h" -#include "engines/grim/colormap.h" namespace Grim { +class CMAp; + class Material : public Object { public: Material() { _width = 0; } @@ -52,7 +52,7 @@ public: Common::String _fname; - const CMapPtr _cmap; + const ObjectPtr _cmap; int _numImages, _currImage; int _width, _height; void *_textures; diff --git a/engines/grim/model.cpp b/engines/grim/model.cpp index b3075550ce8..30a5a913851 100644 --- a/engines/grim/model.cpp +++ b/engines/grim/model.cpp @@ -32,6 +32,7 @@ #include "engines/grim/textsplit.h" #include "engines/grim/gfx_base.h" #include "engines/grim/lipsync.h" +#include "engines/grim/resource.h" namespace Grim { diff --git a/engines/grim/model.h b/engines/grim/model.h index 94e3d80758e..fdcc68454fa 100644 --- a/engines/grim/model.h +++ b/engines/grim/model.h @@ -27,14 +27,14 @@ #define GRIM_MODEL_H #include "common/memstream.h" - -#include "engines/grim/resource.h" #include "engines/grim/object.h" #include "graphics/matrix4.h" namespace Grim { class TextSplitter; +class Material; +class CMap; class Model : public Object { public: @@ -49,7 +49,7 @@ public: ~Model(); Common::String _fname; - CMapPtr _cmap; + ObjectPtr _cmap; struct Geoset; struct Mesh; @@ -139,7 +139,7 @@ public: int _numMaterials; char (*_materialNames)[32]; - MaterialPtr *_materials; + ObjectPtr *_materials; Graphics::Vector3d _insertOffset; int _numGeosets; Geoset *_geosets; diff --git a/engines/grim/object.h b/engines/grim/object.h index 84a2cd00536..9eabc5eae63 100644 --- a/engines/grim/object.h +++ b/engines/grim/object.h @@ -85,8 +85,9 @@ public: ObjectPtr(T *obj) : _obj(obj) { if (obj) { - _obj->reference(); - addPointer(obj); + Object *o = (Object *)_obj; + o->reference(); + addPointer(o); } } ObjectPtr(const ObjectPtr &ptr) : Pointer() { @@ -95,8 +96,9 @@ public: } ~ObjectPtr() { if (_obj) { - rmPointer(_obj); - _obj->dereference(); + Object *o = (Object *)_obj; + rmPointer(o); + o->dereference(); } } diff --git a/engines/grim/objectstate.cpp b/engines/grim/objectstate.cpp index 9cdf78a1bee..5e2a758b00c 100644 --- a/engines/grim/objectstate.cpp +++ b/engines/grim/objectstate.cpp @@ -28,6 +28,8 @@ #include "engines/grim/lua.h" #include "engines/grim/grim.h" #include "engines/grim/colormap.h" +#include "engines/grim/resource.h" +#include "engines/grim/bitmap.h" namespace Grim { @@ -55,6 +57,29 @@ ObjectState::~ObjectState() { delete _zbitmap; } +const char *ObjectState::getBitmapFilename() const { + return _bitmap->getFilename(); +} + +void ObjectState::setNumber(int val) { + if (val) { + assert(_bitmap); + _bitmap->setNumber(val); + if (_zbitmap) + _zbitmap->setNumber(val); + } + + _visibility = val != 0; +} +void ObjectState::draw() { + if (!_visibility) + return; + assert(_bitmap); + _bitmap->draw(); + if (_zbitmap) + _zbitmap->draw(); +} + void ObjectState::saveState(SaveGame *savedState) const { savedState->writeLESint32(_visibility); savedState->writeLEUint32(_setupID); diff --git a/engines/grim/objectstate.h b/engines/grim/objectstate.h index dbeea13f7c3..8c231e07808 100644 --- a/engines/grim/objectstate.h +++ b/engines/grim/objectstate.h @@ -26,12 +26,12 @@ #ifndef GRIM_OSTATE_H #define GRIM_OSTATE_H -#include "engines/grim/bitmap.h" #include "engines/grim/object.h" namespace Grim { class SaveGame; +class Bitmap; class ObjectState : public Object { public: @@ -53,28 +53,10 @@ public: Position getPos() const { return _pos; } void setPos(Position position) { _pos = position; } - const char *getBitmapFilename() const { - return _bitmap->getFilename(); - } + const char *getBitmapFilename() const; - void setNumber(int val) { - if (val) { - assert(_bitmap); - _bitmap->setNumber(val); - if (_zbitmap) - _zbitmap->setNumber(val); - } - - _visibility = val != 0; - } - void draw() { - if (!_visibility) - return; - assert(_bitmap); - _bitmap->draw(); - if (_zbitmap) - _zbitmap->draw(); - } + void setNumber(int val); + void draw(); private: diff --git a/engines/grim/primitives.cpp b/engines/grim/primitives.cpp index ea4d9ffda3c..1eae699df3b 100644 --- a/engines/grim/primitives.cpp +++ b/engines/grim/primitives.cpp @@ -29,6 +29,7 @@ #include "engines/grim/lua.h" #include "engines/grim/colormap.h" #include "engines/grim/grim.h" +#include "engines/grim/bitmap.h" namespace Grim { @@ -42,7 +43,7 @@ PrimitiveObject::PrimitiveObject() : PrimitiveObject::~PrimitiveObject() { if (_bitmap && _type == 2) - delete _bitmap.object(); + delete _bitmap; } void PrimitiveObject::saveState(SaveGame *savedState) const { @@ -127,7 +128,7 @@ void PrimitiveObject::draw() { if (_type == RECTANGLE) g_driver->drawRectangle(this); else if (_type == BITMAP) - g_driver->drawBitmap(_bitmap.object()); + g_driver->drawBitmap(_bitmap); else if (_type == LINE) g_driver->drawLine(this); else if (_type == POLYGON) diff --git a/engines/grim/primitives.h b/engines/grim/primitives.h index d4c103af7c3..d217e3a7776 100644 --- a/engines/grim/primitives.h +++ b/engines/grim/primitives.h @@ -28,11 +28,10 @@ #include "common/rect.h" -#include "engines/grim/color.h" - namespace Grim { class SaveGame; +class Bitmap; class PrimitiveObject : public Object { public: @@ -60,7 +59,7 @@ public: bool isFilled() { return _filled; } void draw(); bool isBitmap() { return _type == BITMAP; } - Bitmap *getBitmapHandle() { assert(_bitmap); return _bitmap.object(); } + Bitmap *getBitmapHandle() { assert(_bitmap); return _bitmap; } void saveState(SaveGame *state) const; bool restoreState(SaveGame *state); @@ -69,7 +68,7 @@ private: Color *_color; bool _filled; int _type; - BitmapPtr _bitmap; + Bitmap *_bitmap; friend class GrimEngine; }; diff --git a/engines/grim/resource.cpp b/engines/grim/resource.cpp index 49026bb74c8..9ed38153a9d 100644 --- a/engines/grim/resource.cpp +++ b/engines/grim/resource.cpp @@ -32,7 +32,9 @@ #include "engines/grim/lipsync.h" #include "engines/grim/savegame.h" #include "engines/grim/actor.h" - +#include "engines/grim/lab.h" +#include "engines/grim/bitmap.h" +#include "engines/grim/font.h" namespace Grim { diff --git a/engines/grim/resource.h b/engines/grim/resource.h index 725bd197667..4ea5478684c 100644 --- a/engines/grim/resource.h +++ b/engines/grim/resource.h @@ -27,8 +27,8 @@ #define GRIM_RESOURCE_H #include "common/archive.h" +#include "common/file.h" -#include "engines/grim/lab.h" #include "engines/grim/object.h" namespace Grim { @@ -43,6 +43,9 @@ class Model; class LipSync; class TrackedObject; class SaveGame; +class Block; +class LuaFile; +class Lab; typedef ObjectPtr MaterialPtr; typedef ObjectPtr BitmapPtr; diff --git a/engines/grim/scene.cpp b/engines/grim/scene.cpp index 98d079dd897..15498ebf779 100644 --- a/engines/grim/scene.cpp +++ b/engines/grim/scene.cpp @@ -33,6 +33,8 @@ #include "engines/grim/grim.h" #include "engines/grim/savegame.h" #include "engines/grim/lua.h" +#include "engines/grim/resource.h" +#include "engines/grim/bitmap.h" #include "engines/grim/imuse/imuse.h" @@ -83,7 +85,7 @@ void Scene::loadText(TextSplitter &ts){ ts.expectString("section: colormaps"); ts.scanString(" numcolormaps %d", 1, &_numCmaps); - _cmaps = new CMapPtr[_numCmaps]; + _cmaps = new ObjectPtr[_numCmaps]; char cmap_name[256]; for (int i = 0; i < _numCmaps; i++) { ts.scanString(" colormap %256s", 1, cmap_name); diff --git a/engines/grim/scene.h b/engines/grim/scene.h index a32040ddf1c..7ccf2f9aae6 100644 --- a/engines/grim/scene.h +++ b/engines/grim/scene.h @@ -36,6 +36,7 @@ namespace Common { namespace Grim { class SaveGame; +class CMap; class Scene { public: @@ -130,7 +131,7 @@ private: Common::String _name; int _numCmaps; - CMapPtr *_cmaps; + ObjectPtr *_cmaps; int _numSetups, _numLights, _numSectors, _numObjectStates; bool _enableLights; Sector **_sectors; diff --git a/engines/grim/smush/smush.cpp b/engines/grim/smush/smush.cpp index ae10a492bb8..7d7cefa623f 100644 --- a/engines/grim/smush/smush.cpp +++ b/engines/grim/smush/smush.cpp @@ -43,6 +43,8 @@ #include "engines/grim/grim.h" #include "engines/grim/colormap.h" +#include "engines/grim/resource.h" +#include "engines/grim/savegame.h" namespace Grim { diff --git a/engines/grim/textobject.cpp b/engines/grim/textobject.cpp index c07ea5b2b1f..667f285fa2a 100644 --- a/engines/grim/textobject.cpp +++ b/engines/grim/textobject.cpp @@ -28,6 +28,7 @@ #include "engines/grim/savegame.h" #include "engines/grim/lua.h" #include "engines/grim/colormap.h" +#include "engines/grim/font.h" namespace Grim { @@ -301,6 +302,20 @@ void TextObject::createBitmap() { _created = true; } +void TextObject::subBaseOffsetY() { + if (_font) + _y -= _font->getBaseOffsetY(); + else + _y -= 5; +} + +int TextObject::getBaseOffsetY() { + if (_font) + return _font->getBaseOffsetY(); + else + return 5; +} + void TextObject::destroyBitmap() { _created = false; if (_textObjectHandle) { diff --git a/engines/grim/textobject.h b/engines/grim/textobject.h index 6543db268d0..185296a3799 100644 --- a/engines/grim/textobject.h +++ b/engines/grim/textobject.h @@ -26,12 +26,12 @@ #ifndef GRIM_TEXTOBJECT_H #define GRIM_TEXTOBJECT_H -#include "engines/grim/font.h" #include "engines/grim/gfx_base.h" namespace Grim { class SaveGame; +class Font; struct TextObjectDefaults { Color *fgColor; @@ -55,18 +55,8 @@ public: void setText(const char *text); void setX(int x) { _x = x; } void setY(int y) { _y = y; } - void subBaseOffsetY() { - if (_font) - _y -= _font->getBaseOffsetY(); - else - _y -= 5; - } - int getBaseOffsetY() { - if (_font) - return _font->getBaseOffsetY(); - else - return 5; - } + void subBaseOffsetY(); + int getBaseOffsetY(); void setWidth(int width) { _width = width; } void setHeight(int height) { _height = height; } void setFGColor(Color *fgColor) { _fgColor = fgColor; } From fa9b21c21f3e5fdc8d0f8625b4a3e06ed1289f15 Mon Sep 17 00:00:00 2001 From: Joel Teichroeb Date: Fri, 13 May 2011 18:00:27 -0700 Subject: [PATCH 2/2] Added a seperate cpp file for color map. --- engines/grim/colormap.cpp | 55 +++++++++++++++++++++++++++++++++++++++ engines/grim/module.mk | 1 + 2 files changed, 56 insertions(+) create mode 100644 engines/grim/colormap.cpp diff --git a/engines/grim/colormap.cpp b/engines/grim/colormap.cpp new file mode 100644 index 00000000000..398c6c70f0d --- /dev/null +++ b/engines/grim/colormap.cpp @@ -0,0 +1,55 @@ +/* Residual - A 3D game interpreter + * + * Residual is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + * + * $URL$ + * $Id$ + * + */ + +#include "engines/grim/colormap.h" +#include "engines/grim/resource.h" + +namespace Grim { + +// Load a colormap from the given data. +CMap::CMap(const char *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)); +} +CMap::CMap() : Object() {} +CMap::~CMap() { + if (g_resourceloader) + g_resourceloader->uncacheColormap(this); +} + +bool CMap::operator==(const CMap &c) const { + if (_fname != c._fname) { + return false; + } + + return true; +} + + +} // end of namespace Grim + diff --git a/engines/grim/module.mk b/engines/grim/module.mk index 7427741aaf3..182bb762e44 100644 --- a/engines/grim/module.mk +++ b/engines/grim/module.mk @@ -41,6 +41,7 @@ MODULE_OBJS := \ actor.o \ bitmap.o \ costume.o \ + colormap.o \ detection.o \ font.o \ gfx_base.o \