diff --git a/common/debug.cpp b/common/debug.cpp index f51c17f1848..c18bfb7521d 100644 --- a/common/debug.cpp +++ b/common/debug.cpp @@ -50,6 +50,20 @@ #define fflush(file) DS::std_fflush(file) #endif +namespace Common { + +namespace { + +static enDebugLevels gDebugLevel = DEBUG_NONE; + +} + +enDebugLevels getDebugLevel() { + return gDebugLevel; +} + +} // End of namespace Common + #ifndef DISABLE_TEXT_CONSOLE static void debugHelper(const char *s, va_list va, bool caret = true) { @@ -90,7 +104,7 @@ void debug(const char *s, ...) { void debug(int level, const char *s, ...) { va_list va; - if (level > gDebugLevel) + if (level > Common::getDebugLevel()) return; va_start(va, s); @@ -213,4 +227,3 @@ const char *debug_descriptions[] = { "Chore debug messages will be printed", "All debug messages will be printed", }; - diff --git a/common/debug.h b/common/debug.h index 2b6ba3d9d69..e116a8b1463 100644 --- a/common/debug.h +++ b/common/debug.h @@ -25,10 +25,6 @@ #include "common/sys.h" -namespace Common { - class String; -} - #ifndef COMMON_DEBUG_H #define COMMON_DEBUG_H @@ -46,13 +42,16 @@ enum enDebugLevels { DEBUG_CHORES, DEBUG_ALL }; -extern enDebugLevels gDebugLevel; + +namespace Common { + class String; + + enDebugLevels getDebugLevel(); +} + extern const char *debug_levels[]; extern const char *debug_descriptions[]; -// Hacky toggles for experimental / debug code (defined/set in main.cpp) -extern bool SHOWFPS_GLOBAL; - void error(const char *fmt, ...); #ifdef DISABLE_TEXT_CONSOLE diff --git a/engines/grim/actor.cpp b/engines/grim/actor.cpp index b733762ab8d..5df88a9aa4b 100644 --- a/engines/grim/actor.cpp +++ b/engines/grim/actor.cpp @@ -31,6 +31,8 @@ #include "engines/grim/smush/smush.h" #include "engines/grim/imuse/imuse.h" +namespace Grim { + int g_winX1, g_winY1, g_winX2, g_winY2; Actor::Actor(const char *name) : @@ -456,11 +458,11 @@ void Actor::popCostume() { else newCost = _costumeStack.back(); if (!newCost) { - if (gDebugLevel == DEBUG_NORMAL || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_NORMAL || Common::getDebugLevel() == DEBUG_ALL) printf("Popped (freed) the last costume for an actor.\n"); } } else { - if (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("Attempted to pop (free) a costume when the stack is empty!"); } } @@ -730,3 +732,4 @@ void Actor::clearShadowPlanes() { } } +} // end of namespace Grim diff --git a/engines/grim/actor.h b/engines/grim/actor.h index 1c3cd3a8ceb..9145d238c0c 100644 --- a/engines/grim/actor.h +++ b/engines/grim/actor.h @@ -30,6 +30,8 @@ #include "engines/grim/resource.h" #include "engines/grim/vector3d.h" +namespace Grim { + class TextObject; class Sector; @@ -229,4 +231,6 @@ private: friend class GrimEngine; }; +} // end of namespace Grim + #endif diff --git a/engines/grim/bitmap.cpp b/engines/grim/bitmap.cpp index 4465a061b08..9c725380622 100644 --- a/engines/grim/bitmap.cpp +++ b/engines/grim/bitmap.cpp @@ -28,13 +28,15 @@ #include "engines/grim/bitmap.h" #include "engines/grim/gfx_base.h" +namespace Grim { + static void decompress_codec3(const char *compressed, char *result); Bitmap::Bitmap(const char *filename, const char *data, int len) : Resource(filename) { if (len < 8 || memcmp(data, "BM F\0\0\0", 8) != 0) { - if (gDebugLevel == DEBUG_BITMAPS || gDebugLevel == DEBUG_ERROR || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_BITMAPS || Common::getDebugLevel() == DEBUG_ERROR || Common::getDebugLevel() == DEBUG_ALL) error("Invalid magic loading bitmap"); } @@ -84,7 +86,7 @@ Bitmap::Bitmap(const char *filename, const char *data, int len) : Bitmap::Bitmap(const char *data, int width, int height, const char *filename) : Resource(filename) { - if (gDebugLevel == DEBUG_BITMAPS || gDebugLevel == DEBUG_NORMAL || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_BITMAPS || Common::getDebugLevel() == DEBUG_NORMAL || Common::getDebugLevel() == DEBUG_ALL) printf("New bitmap loaded: %s\n", filename); strcpy(_filename, filename); _currImage = 1; @@ -169,3 +171,5 @@ static void decompress_codec3(const char *compressed, char *result) { } } } + +} // end of namespace Grim diff --git a/engines/grim/bitmap.h b/engines/grim/bitmap.h index 586e9052e63..96885777164 100644 --- a/engines/grim/bitmap.h +++ b/engines/grim/bitmap.h @@ -28,6 +28,8 @@ #include "engines/grim/resource.h" +namespace Grim { + class Bitmap : public Resource { public: // Construct a bitmap from the given data. @@ -66,4 +68,6 @@ public: char _filename[32]; }; +} // end of namespace Grim + #endif diff --git a/engines/grim/cmd_line.cpp b/engines/grim/cmd_line.cpp index 6a8b73f43b4..517c64f1d28 100644 --- a/engines/grim/cmd_line.cpp +++ b/engines/grim/cmd_line.cpp @@ -28,6 +28,8 @@ #include "engines/grim/cmd_line.h" #include "engines/grim/version.h" +namespace Grim { + #define DETECTOR_TESTING_HACK static const char USAGE_STRING[] = @@ -422,3 +424,5 @@ bool processSettings(Common::String &command, Common::StringMap &settings) { return true; } + +} // end of namespace Grim diff --git a/engines/grim/cmd_line.h b/engines/grim/cmd_line.h index 9591b07a000..4f15ee391c1 100644 --- a/engines/grim/cmd_line.h +++ b/engines/grim/cmd_line.h @@ -28,8 +28,12 @@ #include "common/config-manager.h" +namespace Grim { + void registerDefaults(); Common::String parseCommandLine(Common::StringMap &settings, int argc, char **argv); bool processSettings(Common::String &command, Common::StringMap &settings); +} // end of namespace Grim + #endif diff --git a/engines/grim/color.h b/engines/grim/color.h index c01abc5ce99..924371dc05f 100644 --- a/engines/grim/color.h +++ b/engines/grim/color.h @@ -28,6 +28,8 @@ #include "common/sys.h" +namespace Grim { + class Color { public: byte _vals[3]; @@ -57,4 +59,6 @@ public: } }; +} // end of namespace Grim + #endif diff --git a/engines/grim/colormap.h b/engines/grim/colormap.h index dcbd5e94d03..9360fc60cdb 100644 --- a/engines/grim/colormap.h +++ b/engines/grim/colormap.h @@ -30,6 +30,8 @@ #include "engines/grim/resource.h" +namespace Grim { + class CMap : public Resource { public: // Load a colormap from the given data. @@ -43,4 +45,6 @@ public: char _colors[256 * 3]; }; +} // end of namespace Grim + #endif diff --git a/engines/grim/costume.cpp b/engines/grim/costume.cpp index 6b8e5e44d46..4982bc53090 100644 --- a/engines/grim/costume.cpp +++ b/engines/grim/costume.cpp @@ -36,6 +36,8 @@ #include "engines/grim/imuse/imuse.h" +namespace Grim { + // A costume in the Residual/GrimE engine consists of a set of // components, and a set of chores. Each component represents an // on-screen object, or a keyframe animation, or a sound effect; each @@ -187,14 +189,14 @@ void BitmapComponent::setKey(int val) { // bitmaps were not loading with the scene. This was because they were requested // as a different case then they were stored (tu_0_dorcu_door_open versus // TU_0_DORCU_door_open), which was causing problems in the string comparison. - if (gDebugLevel == DEBUG_BITMAPS || gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_BITMAPS || Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("Missing scene bitmap: %s", bitmap); /* In case you feel like drawing the missing bitmap anyway... // Assume that all objects the scene file forgot about are OBJSTATE_STATE class state = new ObjectState(0, ObjectState::OBJSTATE_STATE, bitmap, NULL, true); if (!state) { - if (gDebugLevel == DEBUG_BITMAPS || gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_BITMAPS || Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("Couldn't find bitmap %s in current scene", _filename.c_str()); return; } @@ -236,7 +238,7 @@ void ModelComponent::init() { // Get the default colormap if we haven't found // a valid colormap if (!cmap) { - if (gDebugLevel == DEBUG_MODEL || gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_MODEL || Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("No colormap specified for %s, using %s", _filename.c_str(), DEFAULT_COLORMAP); cmap = g_resourceloader->loadColormap(DEFAULT_COLORMAP); @@ -258,7 +260,7 @@ void ModelComponent::init() { if (mc) mc->node()->addChild(_hier); - else if (gDebugLevel == DEBUG_MODEL || gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + else if (Common::getDebugLevel() == DEBUG_MODEL || Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("Parent of model %s wasn't a mesh", _filename.c_str()); } } @@ -437,7 +439,7 @@ void KeyframeComponent::setKey(int val) { _active = false; break; default: - if (gDebugLevel == DEBUG_MODEL || gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_MODEL || Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("Unknown key %d for keyframe %s", val, _keyf->filename()); } } @@ -472,7 +474,7 @@ void KeyframeComponent::update() { _currTime = animLength; break; default: - if (gDebugLevel == DEBUG_MODEL || gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_MODEL || Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("Unknown repeat mode %d for keyframe %s", _repeatMode, _keyf->filename()); } } @@ -484,7 +486,7 @@ void KeyframeComponent::init() { if (mc) _hier = mc->hierarchy(); else { - if (gDebugLevel == DEBUG_MODEL || gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_MODEL || Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("Parent of %s was not a model", _keyf->filename()); _hier = NULL; } @@ -502,7 +504,7 @@ void MeshComponent::init() { if (mc) _node = mc->hierarchy() + _num; else { - if (gDebugLevel == DEBUG_MODEL || gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_MODEL || Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("Parent of mesh %d was not a model", _num); _node = NULL; } @@ -525,7 +527,7 @@ MaterialComponent::MaterialComponent(Costume::Component *parent, int parentID, c Costume::Component(parent, parentID, tag), _filename(filename), _num(0) { - if (gDebugLevel == DEBUG_MODEL || gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_MODEL || Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("Constructing MaterialComponent %s", filename); } @@ -534,7 +536,7 @@ void MaterialComponent::init() { if (!cmap) { // Use the default colormap if we're still drawing a blank - if (gDebugLevel == DEBUG_MODEL || gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_MODEL || Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("MaterialComponent::init on %s", _filename.c_str()); cmap = g_resourceloader->loadColormap(DEFAULT_COLORMAP); @@ -615,7 +617,7 @@ void SoundComponent::setKey(int val) { g_imuse->setHookId(_soundName.c_str(), 0x80); break; default: - if (gDebugLevel == DEBUG_MODEL || gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_MODEL || Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("Unknown key %d for sound %s", val, _soundName.c_str()); } } @@ -700,7 +702,7 @@ Costume::Costume(const char *filename, const char *data, int len, Costume *prevC _chores[id]._length = length; _chores[id]._numTracks = tracks; memcpy(_chores[id]._name, name, 32); - if (gDebugLevel == DEBUG_ALL || gDebugLevel == DEBUG_CHORES) + if (Common::getDebugLevel() == DEBUG_ALL || Common::getDebugLevel() == DEBUG_CHORES) printf("Loaded chore: %s\n", name); } @@ -927,7 +929,7 @@ Model::HierNode *Costume::getModelNodes() { void Costume::playChoreLooping(int num) { if (num < 0 || num >= _numChores) { - if (gDebugLevel == DEBUG_CHORES || gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_CHORES || Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("Requested chore number %d is outside the range of chores (0-%d)!", num, _numChores); return; } @@ -936,7 +938,7 @@ void Costume::playChoreLooping(int num) { void Costume::playChore(int num) { if (num < 0 || num >= _numChores) { - if (gDebugLevel == DEBUG_CHORES || gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_CHORES || Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("Requested chore number %d is outside the range of chores (0-%d)!", num, _numChores); return; } @@ -1018,3 +1020,5 @@ void Costume::setPosRotate(Vector3d pos, float pitch, float yaw, float roll) { _matrix._pos = pos; _matrix._rot.buildFromPitchYawRoll(pitch, yaw, roll); } + +} // end of namespace Grim diff --git a/engines/grim/costume.h b/engines/grim/costume.h index 81d31d18d0b..25137f2b051 100644 --- a/engines/grim/costume.h +++ b/engines/grim/costume.h @@ -28,6 +28,8 @@ #include "engines/grim/model.h" +namespace Grim { + #define DEFAULT_COLORMAP "item.cmp" typedef uint32 tag32; @@ -151,4 +153,6 @@ private: Matrix4 _matrix; }; +} // end of namespace Grim + #endif diff --git a/engines/grim/font.cpp b/engines/grim/font.cpp index 052b4b4a423..f77eb4e457b 100644 --- a/engines/grim/font.cpp +++ b/engines/grim/font.cpp @@ -1,4 +1,4 @@ -/* Residual - Virtual machine to run LucasArts' 3D adventure games +/* Residual - Virtual machine to run LucasArts' 3D adventure games * * Residual is the legal property of its developers, whose names * are too numerous to list here. Please refer to the AUTHORS @@ -27,6 +27,8 @@ #include "engines/grim/font.h" +namespace Grim { + Font::Font(const char *filename, const char *data, int /*len*/) : Resource(filename) { @@ -99,7 +101,7 @@ uint16 Font::getCharIndex(unsigned char c) { if (_charIndex[i] == c2) return i; } - if (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("The requsted character (code 0x%x) does not correspond to anything in the font data!", c2); // If we couldn't find the character then default to // the first character in the font so that something @@ -205,3 +207,5 @@ const uint8 Font::emerFont[][13] = { {0x00, 0x00, 0xf0, 0x18, 0x18, 0x18, 0x1c, 0x0f, 0x1c, 0x18, 0x18, 0x18, 0xf0}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x8f, 0xf1, 0x60, 0x00, 0x00, 0x00} }; + +} // end of namespace Grim diff --git a/engines/grim/font.h b/engines/grim/font.h index 3e9901ac3ee..e832a5bbd05 100644 --- a/engines/grim/font.h +++ b/engines/grim/font.h @@ -28,6 +28,8 @@ #include "engines/grim/resource.h" +namespace Grim { + class Font : public Resource { public: Font(const char *filename, const char *data, int len); @@ -64,4 +66,6 @@ private: byte *_fontData; }; +} // end of namespace Grim + #endif diff --git a/engines/grim/gfx_base.h b/engines/grim/gfx_base.h index 18d04d7b7fe..7beaa2a55a8 100644 --- a/engines/grim/gfx_base.h +++ b/engines/grim/gfx_base.h @@ -30,6 +30,8 @@ #include "engines/grim/scene.h" #include "engines/grim/primitives.h" +namespace Grim { + struct Shadow; class GfxBase { @@ -119,4 +121,6 @@ protected: extern GfxBase *g_driver; +} // end of namespace Grim + #endif diff --git a/engines/grim/gfx_opengl.cpp b/engines/grim/gfx_opengl.cpp index 7402ff31421..8f5f2c69f69 100644 --- a/engines/grim/gfx_opengl.cpp +++ b/engines/grim/gfx_opengl.cpp @@ -34,6 +34,8 @@ #ifdef USE_OPENGL +namespace Grim { + GfxOpenGL::GfxOpenGL() { _storedDisplay = NULL; _emergFont = 0; @@ -1125,4 +1127,6 @@ void GfxOpenGL::drawPolygon(PrimitiveObject *primitive) { glEnable(GL_LIGHTING); } +} // end of namespace Grim + #endif diff --git a/engines/grim/gfx_opengl.h b/engines/grim/gfx_opengl.h index e2ba7b6eb85..efe09930abd 100644 --- a/engines/grim/gfx_opengl.h +++ b/engines/grim/gfx_opengl.h @@ -37,6 +37,8 @@ #include #endif +namespace Grim { + class GfxOpenGL : public GfxBase { public: GfxOpenGL(); @@ -119,4 +121,6 @@ private: #endif +} // end of namespace Grim + #endif diff --git a/engines/grim/gfx_tinygl.cpp b/engines/grim/gfx_tinygl.cpp index f5756e25835..0aecf451a19 100644 --- a/engines/grim/gfx_tinygl.cpp +++ b/engines/grim/gfx_tinygl.cpp @@ -32,6 +32,8 @@ #include "engines/grim/font.h" #include "engines/grim/gfx_tinygl.h" +namespace Grim { + // below funcs lookAt, transformPoint and tgluProject are from Mesa glu sources static void lookAt(TGLfloat eyex, TGLfloat eyey, TGLfloat eyez, TGLfloat centerx, TGLfloat centery, TGLfloat centerz, TGLfloat upx, TGLfloat upy, TGLfloat upz) { @@ -898,3 +900,5 @@ void GfxTinyGL::drawPolygon(PrimitiveObject *primitive) { WRITE_LE_UINT16(dst + 640 * y + x, c); } } + +} // end of namespace Grim diff --git a/engines/grim/gfx_tinygl.h b/engines/grim/gfx_tinygl.h index 92e9d7de565..4f096638cbb 100644 --- a/engines/grim/gfx_tinygl.h +++ b/engines/grim/gfx_tinygl.h @@ -30,6 +30,8 @@ #include "graphics/tinygl/zgl.h" +namespace Grim { + class GfxTinyGL : public GfxBase { public: GfxTinyGL(); @@ -110,4 +112,6 @@ private: byte *_storedDisplay; }; +} // end of namespace Grim + #endif diff --git a/engines/grim/grim.cpp b/engines/grim/grim.cpp index a787cdd0ca1..e7a8c2bdd26 100644 --- a/engines/grim/grim.cpp +++ b/engines/grim/grim.cpp @@ -34,6 +34,8 @@ #include "engines/grim/imuse/imuse.h" +namespace Grim { + // Entries in the system.controls table const ControlDescriptor controls[] = { @@ -805,7 +807,7 @@ void GrimEngine::setSceneLock(const char *name, bool lockStatus) { Scene *scene = findScene(name); if (!scene) { - if (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("Scene object '%s' not found in list!", name); return; } @@ -863,3 +865,5 @@ float GrimEngine::getControlAxis(int num) { bool GrimEngine::getControlState(int num) { return _controlsState[num]; } + +} // end of namespace Grim diff --git a/engines/grim/grim.h b/engines/grim/grim.h index 3e973da7e18..34de14efc2d 100644 --- a/engines/grim/grim.h +++ b/engines/grim/grim.h @@ -28,6 +28,8 @@ #include "engines/grim/textobject.h" +namespace Grim { + class Actor; class SaveGame; @@ -39,6 +41,8 @@ class SaveGame; extern int g_flags; +extern bool SHOWFPS_GLOBAL; + #define GF_DEMO 1 struct ControlDescriptor { @@ -278,4 +282,6 @@ enum { extern const ControlDescriptor controls[]; +} // end of namespace Grim + #endif diff --git a/engines/grim/imuse/imuse.cpp b/engines/grim/imuse/imuse.cpp index f2ee75ebd18..395612c67c4 100644 --- a/engines/grim/imuse/imuse.cpp +++ b/engines/grim/imuse/imuse.cpp @@ -30,6 +30,8 @@ #include "engines/grim/imuse/imuse.h" +namespace Grim { + Imuse *g_imuse = NULL; extern uint16 imuseDestTable[]; @@ -319,7 +321,7 @@ void Imuse::switchToNextRegion(Track *track) { assert(track); if (track->trackId >= MAX_IMUSE_TRACKS) { - if (gDebugLevel == DEBUG_IMUSE || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_IMUSE || Common::getDebugLevel() == DEBUG_ALL) printf("Imuse::switchToNextRegion(): fadeTrack end: soundName:%s\n", track->soundName); flushTrack(track); return; @@ -328,7 +330,7 @@ void Imuse::switchToNextRegion(Track *track) { int numRegions = _sound->getNumRegions(track->soundDesc); if (++track->curRegion == numRegions) { - if (gDebugLevel == DEBUG_IMUSE || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_IMUSE || Common::getDebugLevel() == DEBUG_ALL) printf("Imuse::switchToNextRegion(): end of tracks: soundName:%s\n", track->soundName); flushTrack(track); return; @@ -339,7 +341,7 @@ void Imuse::switchToNextRegion(Track *track) { if (jumpId == -1) jumpId = _sound->getJumpIdByRegionAndHookId(soundDesc, track->curRegion, 0); if (jumpId != -1) { - if (gDebugLevel == DEBUG_IMUSE || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_IMUSE || Common::getDebugLevel() == DEBUG_ALL) printf("Imuse::switchToNextRegion(): JUMP: soundName:%s\n", track->soundName); int region = _sound->getRegionIdByJumpId(soundDesc, jumpId); assert(region != -1); @@ -362,8 +364,10 @@ void Imuse::switchToNextRegion(Track *track) { track->curHookId = 0; } - if (gDebugLevel == DEBUG_IMUSE || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_IMUSE || Common::getDebugLevel() == DEBUG_ALL) printf("Imuse::switchToNextRegion(): REGION %d: soundName:%s\n", (int)track->curRegion, track->soundName); track->dataOffset = _sound->getRegionOffset(soundDesc, track->curRegion); track->regionOffset = 0; } + +} // end of namespace Grim diff --git a/engines/grim/imuse/imuse.h b/engines/grim/imuse/imuse.h index 5fcf07ee603..1ea163e3c65 100644 --- a/engines/grim/imuse/imuse.h +++ b/engines/grim/imuse/imuse.h @@ -28,6 +28,8 @@ #include "engines/grim/imuse/imuse_track.h" +namespace Grim { + #define MAX_IMUSE_TRACKS 16 #define MAX_IMUSE_FADETRACKS 16 @@ -108,4 +110,6 @@ public: extern Imuse *g_imuse; +} // end of namespace Grim + #endif diff --git a/engines/grim/imuse/imuse_mcmp_mgr.cpp b/engines/grim/imuse/imuse_mcmp_mgr.cpp index 2a4bc0ce250..7e1e975d8f5 100644 --- a/engines/grim/imuse/imuse_mcmp_mgr.cpp +++ b/engines/grim/imuse/imuse_mcmp_mgr.cpp @@ -29,6 +29,8 @@ #include "engines/grim/imuse/imuse_mcmp_mgr.h" +namespace Grim { + uint16 imuseDestTable[5786]; McmpMgr::McmpMgr() { @@ -155,3 +157,5 @@ int32 McmpMgr::decompressSample(int32 offset, int32 size, byte **comp_final) { return final_size; } + +} // end of namespace Grim diff --git a/engines/grim/imuse/imuse_mcmp_mgr.h b/engines/grim/imuse/imuse_mcmp_mgr.h index 80e820f008f..ff2ae7df414 100644 --- a/engines/grim/imuse/imuse_mcmp_mgr.h +++ b/engines/grim/imuse/imuse_mcmp_mgr.h @@ -26,6 +26,8 @@ #ifndef MCMP_MGR_H #define MCMP_MGR_H +namespace Grim { + class McmpMgr { private: @@ -54,4 +56,6 @@ public: int32 decompressSample(int32 offset, int32 size, byte **comp_final); }; +} // end of namespace Grim + #endif diff --git a/engines/grim/imuse/imuse_music.cpp b/engines/grim/imuse/imuse_music.cpp index 22cd4d11772..a4897db549b 100644 --- a/engines/grim/imuse/imuse_music.cpp +++ b/engines/grim/imuse/imuse_music.cpp @@ -26,6 +26,8 @@ #include "engines/grim/imuse/imuse.h" #include "engines/grim/imuse/imuse_tables.h" +namespace Grim { + void Imuse::setMusicState(int stateId) { int l, num = -1; @@ -40,7 +42,7 @@ void Imuse::setMusicState(int stateId) { } assert(num != -1); - if (gDebugLevel == DEBUG_IMUSE || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_IMUSE || Common::getDebugLevel() == DEBUG_ALL) printf("Imuse::setMusicState(): SoundId %d, filename: %s\n", _stateMusicTable[l].soundId, _stateMusicTable[l].filename); if (_curMusicState == num) @@ -71,7 +73,7 @@ int Imuse::setMusicSequence(int seqId) { assert(num != -1); - if (gDebugLevel == DEBUG_IMUSE || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_IMUSE || Common::getDebugLevel() == DEBUG_ALL) printf("Imuse::setMusicSequence(): SoundId %d, filename: %s\n", _seqMusicTable[l].soundId, _seqMusicTable[l].filename); if (_curMusicSeq == num) @@ -158,3 +160,5 @@ void Imuse::playMusic(const ImuseTable *table, int atribPos, bool sequence) { } } } + +} // end of namespace Grim diff --git a/engines/grim/imuse/imuse_script.cpp b/engines/grim/imuse/imuse_script.cpp index a08a1489d05..24ad97381ed 100644 --- a/engines/grim/imuse/imuse_script.cpp +++ b/engines/grim/imuse/imuse_script.cpp @@ -25,6 +25,8 @@ #include "engines/grim/imuse/imuse.h" +namespace Grim { + void Imuse::flushTrack(Track *track) { track->toBeRemoved = true; @@ -73,25 +75,25 @@ void Imuse::refreshScripts() { } void Imuse::startVoice(const char *soundName, int volume, int pan) { - if (gDebugLevel == DEBUG_IMUSE || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_IMUSE || Common::getDebugLevel() == DEBUG_ALL) printf("Imuse::startVoice(): SoundName %s, vol:%d, pan:%d\n", soundName, volume, pan); startSound(soundName, IMUSE_VOLGRP_VOICE, 0, volume, pan, 127, NULL); } void Imuse::startMusic(const char *soundName, int hookId, int volume, int pan) { - if (gDebugLevel == DEBUG_IMUSE || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_IMUSE || Common::getDebugLevel() == DEBUG_ALL) printf("Imuse::startMusic(): SoundName %s, hookId:%d, vol:%d, pan:%d\n", soundName, hookId, volume, pan); startSound(soundName, IMUSE_VOLGRP_MUSIC, hookId, volume, pan, 126, NULL); } void Imuse::startMusicWithOtherPos(const char *soundName, int hookId, int volume, int pan, Track *otherTrack) { - if (gDebugLevel == DEBUG_IMUSE || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_IMUSE || Common::getDebugLevel() == DEBUG_ALL) printf("Imuse::startMusicWithOtherPos(): SoundName %s, hookId:%d, vol:%d, pan:%d\n", soundName, hookId, volume, pan); startSound(soundName, IMUSE_VOLGRP_MUSIC, hookId, volume, pan, 126, otherTrack); } void Imuse::startSfx(const char *soundName, int priority) { - if (gDebugLevel == DEBUG_IMUSE || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_IMUSE || Common::getDebugLevel() == DEBUG_ALL) printf("Imuse::startSfx(): SoundName %s, priority:%d\n", soundName, priority); startSound(soundName, IMUSE_VOLGRP_SFX, 0, 127, 0, priority, NULL); } @@ -103,7 +105,7 @@ int32 Imuse::getPosIn60HzTicks(const char *soundName) { getTrack = findTrack(soundName); // Warn the user if the track was not found if (getTrack == NULL) { - if (gDebugLevel == DEBUG_IMUSE || gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_IMUSE || Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("Sound '%s' could not be found to get ticks!", soundName); return false; } @@ -138,7 +140,7 @@ bool Imuse::getSoundStatus(const char *soundName) { if (track == NULL || !g_system->getMixer()->isSoundHandleActive(track->handle)) { // This debug warning should be "light" since this function gets called // on occassion to see if a sound has stopped yet - if (gDebugLevel == DEBUG_IMUSE || gDebugLevel == DEBUG_NORMAL || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_IMUSE || Common::getDebugLevel() == DEBUG_NORMAL || Common::getDebugLevel() == DEBUG_ALL) printf("Sound '%s' could not be found to get status, assume inactive.\n", soundName); return false; } @@ -147,14 +149,14 @@ bool Imuse::getSoundStatus(const char *soundName) { void Imuse::stopSound(const char *soundName) { Common::StackLock lock(_mutex); - if (gDebugLevel == DEBUG_IMUSE || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_IMUSE || Common::getDebugLevel() == DEBUG_ALL) printf("Imuse::stopSound(): SoundName %s\n", soundName); Track *removeTrack = NULL; removeTrack = findTrack(soundName); // Warn the user if the track was not found if (removeTrack == NULL) { - if (gDebugLevel == DEBUG_IMUSE || gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_IMUSE || Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("Sound track '%s' could not be found to stop!", soundName); return; } @@ -163,7 +165,7 @@ void Imuse::stopSound(const char *soundName) { void Imuse::stopAllSounds() { Common::StackLock lock(_mutex); - if (gDebugLevel == DEBUG_IMUSE || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_IMUSE || Common::getDebugLevel() == DEBUG_ALL) printf("Imuse::stopAllSounds()\n"); for (int l = 0; l < MAX_IMUSE_TRACKS + MAX_IMUSE_FADETRACKS; l++) { @@ -181,3 +183,5 @@ void Imuse::stopAllSounds() { void Imuse::pause(bool p) { _pause = p; } + +} // end of namespace Grim diff --git a/engines/grim/imuse/imuse_sndmgr.cpp b/engines/grim/imuse/imuse_sndmgr.cpp index 9373a409213..e504524a45d 100644 --- a/engines/grim/imuse/imuse_sndmgr.cpp +++ b/engines/grim/imuse/imuse_sndmgr.cpp @@ -30,6 +30,8 @@ #include "engines/grim/imuse/imuse_sndmgr.h" #include "engines/grim/imuse/imuse_mcmp_mgr.h" +namespace Grim { + ImuseSndMgr::ImuseSndMgr() { for (int l = 0; l < MAX_IMUSE_SOUNDS; l++) { memset(&_sounds[l], 0, sizeof(SoundDesc)); @@ -338,3 +340,5 @@ int32 ImuseSndMgr::getDataFromRegion(SoundDesc *sound, int region, byte **buf, i return size; } + +} // end of namespace Grim diff --git a/engines/grim/imuse/imuse_sndmgr.h b/engines/grim/imuse/imuse_sndmgr.h index dcbf938f5d1..921c39053c5 100644 --- a/engines/grim/imuse/imuse_sndmgr.h +++ b/engines/grim/imuse/imuse_sndmgr.h @@ -29,6 +29,8 @@ #include "sound/mixer.h" #include "sound/audiostream.h" +namespace Grim { + class McmpMgr; class Block; @@ -114,4 +116,6 @@ public: int32 getDataFromRegion(SoundDesc *sound, int region, byte **buf, int32 offset, int32 size); }; +} // end of namespace Grim + #endif diff --git a/engines/grim/imuse/imuse_tables.cpp b/engines/grim/imuse/imuse_tables.cpp index 1e5455552c7..3a9c3129eff 100644 --- a/engines/grim/imuse/imuse_tables.cpp +++ b/engines/grim/imuse/imuse_tables.cpp @@ -27,6 +27,8 @@ #include "engines/grim/imuse/imuse_tables.h" +namespace Grim { + ImuseTable grimStateMusicTable[] = { {0, 1000, 0, 0, 60, 127, 0, ""}, {0, 1999, 0, 0, 60, 127, 0, ""}, @@ -288,3 +290,5 @@ ImuseTable grimDemoSeqMusicTable[] = { {3, 2100, 0, 0, 60, 127, 0, "Rope Climb.IMC"}, {0, -1, 0, 0, 0, 0, 0, ""} }; + +} // end of namespace Grim diff --git a/engines/grim/imuse/imuse_tables.h b/engines/grim/imuse/imuse_tables.h index b166e10b3ae..6ad9800aa36 100644 --- a/engines/grim/imuse/imuse_tables.h +++ b/engines/grim/imuse/imuse_tables.h @@ -26,6 +26,8 @@ #ifndef IMUSE_TABLES_H #define IMUSE_TABLES_H +namespace Grim { + struct ImuseTable { byte opcode; int16 soundId; @@ -37,4 +39,6 @@ struct ImuseTable { char filename[32]; }; +} // end of namespace Grim + #endif diff --git a/engines/grim/imuse/imuse_track.cpp b/engines/grim/imuse/imuse_track.cpp index 60ec77329c2..340dc9b2cce 100644 --- a/engines/grim/imuse/imuse_track.cpp +++ b/engines/grim/imuse/imuse_track.cpp @@ -25,6 +25,8 @@ #include "engines/grim/imuse/imuse.h" +namespace Grim { + int Imuse::allocSlot(int priority) { int l, lowest_priority = 127; int trackId = -1; @@ -78,7 +80,7 @@ bool Imuse::startSound(const char *soundName, int volGroupId, int hookId, int vo for (i = 0; i < MAX_IMUSE_TRACKS + MAX_IMUSE_FADETRACKS; i++) { // Filenames are case insensitive, see findTrack if (!strcasecmp(_track[i]->soundName, soundName)) { - if (gDebugLevel == DEBUG_IMUSE || gDebugLevel == DEBUG_NORMAL || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_IMUSE || Common::getDebugLevel() == DEBUG_NORMAL || Common::getDebugLevel() == DEBUG_ALL) printf("Imuse::startSound(): Track '%s' already playing.\n", soundName); return true; } @@ -377,3 +379,5 @@ Track *Imuse::cloneToFadeOutTrack(Track *track, int fadeDelay) { return fadeTrack; } + +} // end of namespace Grim diff --git a/engines/grim/imuse/imuse_track.h b/engines/grim/imuse/imuse_track.h index 7ee7d499d46..6aa9baa3bcc 100644 --- a/engines/grim/imuse/imuse_track.h +++ b/engines/grim/imuse/imuse_track.h @@ -28,6 +28,8 @@ #include "engines/grim/imuse/imuse_sndmgr.h" +namespace Grim { + enum { kFlagUnsigned = 1 << 0, kFlag16Bits = 1 << 1, @@ -88,4 +90,6 @@ struct Track { } }; +} // end of namespace Grim + #endif diff --git a/engines/grim/internal_version.h b/engines/grim/internal_version.h index 65ea4a696a8..b42bead534b 100644 --- a/engines/grim/internal_version.h +++ b/engines/grim/internal_version.h @@ -1 +1,6 @@ + +namespace Grim { + #define RESIDUAL_VERSION "0.0.6svn" + +} // end of namespace Grim diff --git a/engines/grim/keyframe.cpp b/engines/grim/keyframe.cpp index ffc3c878820..987d74666e7 100644 --- a/engines/grim/keyframe.cpp +++ b/engines/grim/keyframe.cpp @@ -28,6 +28,8 @@ #include "engines/grim/keyframe.h" #include "engines/grim/textsplit.h" +namespace Grim { + KeyframeAnim::KeyframeAnim(const char *filename, const char *data, int len) : Resource(filename) { @@ -42,7 +44,7 @@ KeyframeAnim::KeyframeAnim(const char *filename, const char *data, int len) : void KeyframeAnim::loadBinary(const char *data, int len) { // First four bytes are the FYEK Keyframe identifier code // Next 36 bytes are the filename - if (gDebugLevel == DEBUG_NORMAL || gDebugLevel == DEBUG_ALL) { + if (Common::getDebugLevel() == DEBUG_NORMAL || Common::getDebugLevel() == DEBUG_ALL) { char filebuf[37]; memcpy(filebuf, data + 4, 36); @@ -90,7 +92,7 @@ void KeyframeAnim::loadBinary(const char *data, int len) { // else is still wrong but it should now load correctly in // all cases if (nodeNum >= _numJoints) { - if (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) { + if (Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) { warning("A node number was greater than the maximum number of nodes (%d/%d)", nodeNum, _numJoints); } return; @@ -251,3 +253,5 @@ void KeyframeAnim::KeyframeNode::animate(Model::HierNode &node, float frame, int // node } + +} // end of namespace Grim diff --git a/engines/grim/keyframe.h b/engines/grim/keyframe.h index 9b3cf2dfa4e..a22e5e0a96a 100644 --- a/engines/grim/keyframe.h +++ b/engines/grim/keyframe.h @@ -28,6 +28,8 @@ #include "engines/grim/model.h" +namespace Grim { + class KeyframeAnim : public Resource { public: KeyframeAnim(const char *filename, const char *data, int len); @@ -74,4 +76,6 @@ private: KeyframeNode **_nodes; }; +} // end of namespace Grim + #endif diff --git a/engines/grim/lab.cpp b/engines/grim/lab.cpp index 1765c091554..2b1d2022e4d 100644 --- a/engines/grim/lab.cpp +++ b/engines/grim/lab.cpp @@ -29,6 +29,8 @@ #include "engines/grim/lab.h" #include "engines/grim/lua/lua.h" +namespace Grim { + static int sortCallback(const void *entry1, const void *entry2) { return strcasecmp(((Lab::LabEntry *)entry1)->filename, ((Lab::LabEntry *)entry2)->filename); } @@ -156,3 +158,5 @@ void Lab::close() { _entries = NULL; _numEntries = 0; } + +} // end of namespace Grim diff --git a/engines/grim/lab.h b/engines/grim/lab.h index 48216bc49fd..21664ebbfc1 100644 --- a/engines/grim/lab.h +++ b/engines/grim/lab.h @@ -28,12 +28,14 @@ #include "common/str.h" -class LuaFile; - namespace Common { class File; } +namespace Grim { + +class LuaFile; + class Block { public: Block(const char *data, int len) : _data(data), _len(len) {} @@ -78,4 +80,6 @@ private: LabEntry *findFilename(const char *filename) const; }; +} // end of namespace Grim + #endif diff --git a/engines/grim/lipsync.cpp b/engines/grim/lipsync.cpp index 472ef23b3c6..c8f60af9697 100644 --- a/engines/grim/lipsync.cpp +++ b/engines/grim/lipsync.cpp @@ -27,6 +27,8 @@ #include "engines/grim/lipsync.h" +namespace Grim { + // A new define that'll be around when theres a configure script :) #undef DEBUG_VERBOSE @@ -111,3 +113,5 @@ const LipSync::PhonemeAnim LipSync::_animTable[] = { }; const int LipSync::_animTableSize = sizeof(LipSync::_animTable) / sizeof(LipSync::_animTable[0]); + +} // end of namespace Grim diff --git a/engines/grim/lipsync.h b/engines/grim/lipsync.h index 41f474a191f..f19ea072e5d 100644 --- a/engines/grim/lipsync.h +++ b/engines/grim/lipsync.h @@ -28,6 +28,8 @@ #include "engines/grim/resource.h" +namespace Grim { + class LipSync : public Resource { public: LipSync(const char *filename, const char *data, int len); @@ -54,5 +56,7 @@ private: static const int _animTableSize; }; +} // end of namespace Grim + #endif diff --git a/engines/grim/localize.cpp b/engines/grim/localize.cpp index 613608b8e8d..7f0ae98d7b8 100644 --- a/engines/grim/localize.cpp +++ b/engines/grim/localize.cpp @@ -30,6 +30,8 @@ #include "engines/grim/localize.h" #include "engines/grim/grim.h" +namespace Grim { + Localizer *g_localizer = NULL; static int sortCallback(const void *entry1, const void *entry2) { @@ -123,3 +125,5 @@ Localizer::~Localizer() { delete[] _entries[i].translation; } } + +} // end of namespace Grim diff --git a/engines/grim/localize.h b/engines/grim/localize.h index e8c589c45e8..cc8cac74082 100644 --- a/engines/grim/localize.h +++ b/engines/grim/localize.h @@ -28,6 +28,8 @@ #include "common/array.h" +namespace Grim { + class Localizer { public: Common::String localize(const char *str) const; @@ -47,4 +49,6 @@ private: extern Localizer *g_localizer; +} // end of namespace Grim + #endif diff --git a/engines/grim/lua.cpp b/engines/grim/lua.cpp index 03602b0d8c3..8ff0cd70621 100644 --- a/engines/grim/lua.cpp +++ b/engines/grim/lua.cpp @@ -38,6 +38,8 @@ #include "engines/grim/lua/lauxlib.h" #include "engines/grim/imuse/imuse.h" +namespace Grim { + extern Imuse *g_imuse; Common::StringList g_listfiles; @@ -178,11 +180,11 @@ static Costume *get_costume(Actor *a, int param, const char *called_from) { Costume *result; if (lua_isnil(lua_getparam(param))) { result = a->currentCostume(); - if (!result && (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL)) + if (!result && (Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL)) warning("Actor %s has no costume [%s]", a->name(), called_from); } else { result = a->findCostume(lua_getstring(lua_getparam(param))); - if (!result && (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL)) + if (!result && (Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL)) warning("Actor %s has no costume %s [%s]", a->name(), lua_getstring(lua_getparam(param)), called_from); } return result; @@ -202,7 +204,7 @@ static void new_dofile() { // Debugging message functions static void PrintDebug() { - if (gDebugLevel == DEBUG_NORMAL || gDebugLevel == DEBUG_ALL) { + if (Common::getDebugLevel() == DEBUG_NORMAL || Common::getDebugLevel() == DEBUG_ALL) { Common::String msg("Debug: "); msg += Common::String(luaL_check_string(1)) + "\n"; printf(msg.c_str()); @@ -210,7 +212,7 @@ static void PrintDebug() { } static void PrintError() { - if (gDebugLevel == DEBUG_ERROR || gDebugLevel == DEBUG_ALL) { + if (Common::getDebugLevel() == DEBUG_ERROR || Common::getDebugLevel() == DEBUG_ALL) { Common::String msg("Error: "); msg += Common::String(luaL_check_string(1)) + "\n"; printf(msg.c_str()); @@ -218,7 +220,7 @@ static void PrintError() { } static void PrintWarning() { - if (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) { + if (Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) { Common::String msg("Warning: "); msg += Common::String(luaL_check_string(1)) + "\n"; printf(msg.c_str()); @@ -403,12 +405,12 @@ static void SetActorWalkChore() { int chore = lua_getnumber(lua_getparam(2)); Costume *costume = get_costume(act, 3, "SetActorWalkChore"); if (!costume) { - if (gDebugLevel == DEBUG_CHORES || gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_CHORES || Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("SetActorWalkChore() could not find the requested costume, attempting to load..."); act->pushCostume(lua_getstring(lua_getparam(3))); costume = get_costume(act, 3, "SetActorWalkChore"); if (!costume) { - if (gDebugLevel == DEBUG_CHORES || gDebugLevel == DEBUG_ERROR || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_CHORES || Common::getDebugLevel() == DEBUG_ERROR || Common::getDebugLevel() == DEBUG_ALL) error("SetActorWalkChore() could not find the requested costume!"); return; } @@ -513,7 +515,7 @@ static void GetActorYawToPoint() { } else if (lua_istable(param2)) { yawVector = tableToVector(param2); } else { - if (gDebugLevel == DEBUG_ERROR || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_ERROR || Common::getDebugLevel() == DEBUG_ALL) error("Unhandled data type for GetActorYawToPoint!"); lua_pushnil(); return; @@ -659,7 +661,7 @@ static void GetActorNodeLocation() { lua_pushnil(); lua_pushnil(); lua_pushnil(); - if (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("GetActorNodeLocation() when actor has no costume (which means no nodes)!"); return; } @@ -668,7 +670,7 @@ static void GetActorNodeLocation() { lua_pushnil(); lua_pushnil(); lua_pushnil(); - if (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("GetActorNodeLocation() when actor has no nodes!"); return; } @@ -760,7 +762,7 @@ static void GetActorCostume() { c = act->currentCostume(); if (!c) { lua_pushnil(); - if (gDebugLevel == DEBUG_NORMAL || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_NORMAL || Common::getDebugLevel() == DEBUG_ALL) printf("GetActorCostume() on '%s' when actor has no costume!", act->name()); return; } @@ -790,7 +792,7 @@ static void PlayActorChore() { num = lua_getnumber(lua_getparam(2)); cost = get_costume(act, 3, "playActorChore"); if (!cost) { - if (gDebugLevel == DEBUG_CHORES || gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_CHORES || Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("Actor costume not found, unable to perform chore."); return; } @@ -816,7 +818,7 @@ static void CompleteActorChore() { num = lua_getnumber(lua_getparam(2)); cost = get_costume(act, 3, "completeActorChore"); if (!cost) { - if (gDebugLevel == DEBUG_CHORES || gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_CHORES || Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("Actor costume not found, unable to perform chore."); return; } @@ -896,7 +898,7 @@ static void IsActorChoring() { else if (lua_isstring(param2)) result = cost->isChoring(lua_getstring(param2), excludeLooping); else { - if (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("IsActorChoring: LUA Parameter 2 is of unhandled type!"); } @@ -959,7 +961,7 @@ static void ActorLookAt() { if (lua_isnumber(y)) act->setLookAtRate(lua_getnumber(y)); } else { - if (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("ActorLookAt: Don't know what to look at!"); return; } @@ -991,7 +993,7 @@ static void TurnActorTo() { y = destActor->pos().y(); z = destActor->pos().z(); } else { - if (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("TurnActorTo() parameter type not understood"); return; } @@ -1097,7 +1099,7 @@ static void RotateVector() { lua_pushnumber(vec2.z()); lua_settable(); } else { - if (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("RotateVector() parameter type not understood!"); // This will likely cause a crash since LUA is expecting // a table out of this function @@ -1123,7 +1125,7 @@ static void SetActorPitch() { act->setRot(pitch, act->yaw(), act->roll()); } else { - if (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("SetActorPitch() parameter type not understood!"); return; } @@ -1176,7 +1178,7 @@ static void SetActorFollowBoxes() { act = check_actor(1); mode = !lua_isnil(lua_getparam(2)); - if (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("SetActorFollowBoxes() not implemented"); // that is not walkbox walking, but temporary hack // act->enableWalkbox(mode); @@ -1431,7 +1433,7 @@ static void SayLine() { paramObj = lua_getparam(paramId++); } while (!lua_isnil(paramObj)); if (msg.empty()) { - if (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("SayLine: Did not find a message ID!"); return; } @@ -1491,7 +1493,7 @@ static void GetPointSector() { result = NULL; } if (!result) { - if (gDebugLevel == DEBUG_ERROR || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_ERROR || Common::getDebugLevel() == DEBUG_ALL) error("GetPointSector() passed an unhandled type or failed to find any matching sector!"); lua_pushnil(); lua_pushnil(); @@ -1554,7 +1556,7 @@ static void MakeSectorActive() { sectorName = lua_getparam(1); visible = !lua_isnil(lua_getparam(2)); // FIXME: This happens on initial load. Are we initting something in the wrong order? - if (!g_grim->currScene() && (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL)) { + if (!g_grim->currScene() && (Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL)) { warning("!!!! Trying to call MakeSectorActive without a scene!"); return; } @@ -1584,7 +1586,7 @@ static void MakeSectorActive() { return; } } - } else if (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL){ + } else if (Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL){ warning("MakeSectorActive Parameter is not a sector ID or Name"); return; } else @@ -1612,7 +1614,7 @@ static void MakeCurrentSet() { const char *name; name = luaL_check_string(1); - if (gDebugLevel == DEBUG_NORMAL || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_NORMAL || Common::getDebugLevel() == DEBUG_ALL) printf("Entered new scene '%s'.\n", name); g_grim->setScene(name); } @@ -1655,7 +1657,7 @@ static void GetCurrentSetup() { name = luaL_check_string(1); scene = g_grim->findScene(name); if (!scene) { - if (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("GetCurrentSetup() Requested scene (%s) is not loaded!", name); lua_pushnil(); return; @@ -1674,7 +1676,7 @@ static void GetShrinkPos() { lua_pushnumber(x); lua_pushnumber(y); lua_pushnumber(z); - if (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("Stub function GetShrinkPos(%g,%g,%g,%g) called", x, y, z, r); } @@ -1703,10 +1705,10 @@ static void ImStartSound() { } else { // Allow soft failing when loading sounds, hard failing when not if (priority == 127) { - if (gDebugLevel == DEBUG_IMUSE || gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_IMUSE || Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("ImStartSound failed to load '%s'", soundName); } else { - if (gDebugLevel == DEBUG_IMUSE || gDebugLevel == DEBUG_ERROR || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_IMUSE || Common::getDebugLevel() == DEBUG_ERROR || Common::getDebugLevel() == DEBUG_ALL) error("ImStartSound failed to start '%s'", soundName); } lua_pushnil(); @@ -1736,7 +1738,7 @@ static void ImSetVoiceEffect() { const char *effectName; effectName = luaL_check_string(1); - if (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("ImSetVoiceEffect(%s) Voice effects are not yet supported", effectName); } @@ -1780,7 +1782,7 @@ static void ImSetParam() { break; default: lua_pushnil(); - if (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("ImSetParam() Unimplemented %d, %d", param, value); } } @@ -1800,7 +1802,7 @@ void ImGetParam() { break; default: lua_pushnil(); - if (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("ImGetParam() Unimplemented %d", param); } } @@ -2924,17 +2926,17 @@ static void ForceRefresh() { } static void JustLoaded() { - if (gDebugLevel == DEBUG_ERROR || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_ERROR || Common::getDebugLevel() == DEBUG_ALL) error("OPCODE USAGE VERIFICATION: JustLoaded"); } static void PlaySound() { - if (gDebugLevel == DEBUG_ERROR || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_ERROR || Common::getDebugLevel() == DEBUG_ALL) error("OPCODE USAGE VERIFICATION: PlaySound"); } static void SetEmergencyFont() { - if (gDebugLevel == DEBUG_ERROR || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_ERROR || Common::getDebugLevel() == DEBUG_ALL) error("OPCODE USAGE VERIFICATION: SetEmergencyFont"); } @@ -3666,7 +3668,7 @@ int bundle_dofile(const char *filename) { delete b; // Don't print warnings on Scripts\foo.lua, // d:\grimFandango\Scripts\foo.lua - if (!strstr(filename, "Scripts\\") && (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL)) + if (!strstr(filename, "Scripts\\") && (Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL)) warning("Cannot find script %s", filename); return 2; @@ -3695,7 +3697,7 @@ lua_Object getTableFunction(lua_Object table, const char *name) { } if (!lua_isfunction(handler)) { - if (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("Invalid event handler %s", name); return LUA_NOOBJECT; } @@ -3807,3 +3809,5 @@ lua_Object getEventHandler(const char *name) { lua_Object system_table = lua_getglobal("system"); return getTableFunction(system_table, name); } + +} // end of namespace Grim diff --git a/engines/grim/lua.h b/engines/grim/lua.h index c12a16a34b3..bbe22f1629a 100644 --- a/engines/grim/lua.h +++ b/engines/grim/lua.h @@ -30,6 +30,8 @@ class Vector3d; +namespace Grim { + // Register Residual builtin functions and structures void register_lua(); @@ -60,4 +62,6 @@ Vector3d tableToVector(lua_Object table); // get a function stored in a table lua_Object getTableFunction(lua_Object table, const char *name); +} // end of namespace Grim + #endif diff --git a/engines/grim/lua/lapi.cpp b/engines/grim/lua/lapi.cpp index 565f7997c58..50e55ec7bae 100644 --- a/engines/grim/lua/lapi.cpp +++ b/engines/grim/lua/lapi.cpp @@ -21,6 +21,8 @@ #include "engines/grim/lua/lvm.h" +namespace Grim { + char lua_ident[] = "$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n" "$Autores: " LUA_AUTHORS " $"; @@ -492,4 +494,6 @@ lua_Object lua_setfallback(const char *name, lua_CFunction fallback) { return put_luaObjectonTop(); } +} // end of namespace Grim + #endif diff --git a/engines/grim/lua/lapi.h b/engines/grim/lua/lapi.h index 00d6e56b817..5a2de3c56ba 100644 --- a/engines/grim/lua/lapi.h +++ b/engines/grim/lua/lapi.h @@ -11,9 +11,13 @@ #include "engines/grim/lua/lua.h" #include "engines/grim/lua/lobject.h" +namespace Grim { + TObject *luaA_Address(lua_Object o); void luaA_pushobject(TObject *o); void luaA_packresults(); int32 luaA_passresults(); +} // end of namespace Grim + #endif diff --git a/engines/grim/lua/lauxlib.cpp b/engines/grim/lua/lauxlib.cpp index 93e87cd0d72..0fc6e3eb6d5 100644 --- a/engines/grim/lua/lauxlib.cpp +++ b/engines/grim/lua/lauxlib.cpp @@ -15,6 +15,8 @@ #include "engines/grim/lua/luadebug.h" #include "engines/grim/lua/lmem.h" +namespace Grim { + void luaL_argerror(int32 numarg, const char *extramsg) { const char *funcname; lua_getobjname(lua_stackedfunction(0), &funcname); @@ -101,3 +103,4 @@ void luaL_verror(const char *fmt, ...) { lua_error(buff); } +} // end of namespace Grim diff --git a/engines/grim/lua/lauxlib.h b/engines/grim/lua/lauxlib.h index 77d2a6b7e1b..d9ccfbb91ff 100644 --- a/engines/grim/lua/lauxlib.h +++ b/engines/grim/lua/lauxlib.h @@ -11,6 +11,7 @@ #include "engines/grim/lua/lua.h" +namespace Grim { struct luaL_reg { const char *name; @@ -47,5 +48,6 @@ int32 luaL_newbuffer(int32 size); void luaL_oldbuffer(int32 old); char *luaL_buffer(); +} // end of namespace Grim #endif diff --git a/engines/grim/lua/lbuffer.cpp b/engines/grim/lua/lbuffer.cpp index 90df8b493c2..acb8375ef71 100644 --- a/engines/grim/lua/lbuffer.cpp +++ b/engines/grim/lua/lbuffer.cpp @@ -9,6 +9,7 @@ #include "engines/grim/lua/lmem.h" #include "engines/grim/lua/lstate.h" +namespace Grim { /*------------------------------------------------------- ** Auxiliary buffer @@ -62,3 +63,4 @@ char *luaL_buffer() { return L->Mbuffbase; } +} // end of namespace Grim diff --git a/engines/grim/lua/lbuiltin.cpp b/engines/grim/lua/lbuiltin.cpp index 4f633463f14..50c1f45cefd 100644 --- a/engines/grim/lua/lbuiltin.cpp +++ b/engines/grim/lua/lbuiltin.cpp @@ -19,6 +19,7 @@ #include "engines/grim/lua/ltm.h" #include "engines/grim/lua/lua.h" +namespace Grim { static void pushstring(TaggedString *s) { TObject o; @@ -508,3 +509,4 @@ void luaB_predefine() { lua_setglobal("_VERSION"); } +} // end of namespace Grim diff --git a/engines/grim/lua/lbuiltin.h b/engines/grim/lua/lbuiltin.h index 78e39398592..d5bde86a644 100644 --- a/engines/grim/lua/lbuiltin.h +++ b/engines/grim/lua/lbuiltin.h @@ -7,6 +7,10 @@ #ifndef lbuiltin_h #define lbuiltin_h +namespace Grim { + void luaB_predefine(); +} // end of namespace Grim + #endif diff --git a/engines/grim/lua/ldo.cpp b/engines/grim/lua/ldo.cpp index 7d16d88f074..24bd4e6c4ae 100644 --- a/engines/grim/lua/ldo.cpp +++ b/engines/grim/lua/ldo.cpp @@ -23,6 +23,8 @@ #include "common/file.h" +namespace Grim { + #ifndef STACK_LIMIT #define STACK_LIMIT 6000 #endif @@ -453,3 +455,5 @@ int32 lua_dobuffer(const char *buff, int32 size, const char *name) { status = do_main(&z, buff[0] == ID_CHUNK); return status; } + +} // end of namespace Grim diff --git a/engines/grim/lua/ldo.h b/engines/grim/lua/ldo.h index b6fe1c3724a..a4cc450459b 100644 --- a/engines/grim/lua/ldo.h +++ b/engines/grim/lua/ldo.h @@ -11,6 +11,7 @@ #include "engines/grim/lua/lobject.h" #include "engines/grim/lua/lstate.h" +namespace Grim { #define MULT_RET 255 @@ -41,5 +42,6 @@ void luaD_gcIM(TObject *o); void luaD_travstack(int32 (*fn)(TObject *)); void luaD_checkstack(int32 n); +} // end of namespace Grim #endif diff --git a/engines/grim/lua/lfunc.cpp b/engines/grim/lua/lfunc.cpp index edaf379d4f0..a5fa7dac523 100644 --- a/engines/grim/lua/lfunc.cpp +++ b/engines/grim/lua/lfunc.cpp @@ -10,6 +10,8 @@ #include "engines/grim/lua/lmem.h" #include "engines/grim/lua/lstate.h" +namespace Grim { + #define gcsizeproto(p) 5 /* approximate "weight" for a prototype */ #define gcsizeclosure(c) 1 /* approximate "weight" for a closure */ @@ -86,3 +88,4 @@ char *luaF_getlocalname (TProtoFunc *func, int32 local_number, int32 line) { return varname; } +} // end of namespace Grim diff --git a/engines/grim/lua/lfunc.h b/engines/grim/lua/lfunc.h index c513a0fbbe7..1c37f063206 100644 --- a/engines/grim/lua/lfunc.h +++ b/engines/grim/lua/lfunc.h @@ -10,6 +10,7 @@ #include "engines/grim/lua/lobject.h" +namespace Grim { TProtoFunc *luaF_newproto(); Closure *luaF_newclosure(int32 nelems); @@ -18,5 +19,6 @@ void luaF_freeclosure(Closure *l); char *luaF_getlocalname (TProtoFunc *func, int32 local_number, int32 line); +} // end of namespace Grim #endif diff --git a/engines/grim/lua/lgc.cpp b/engines/grim/lua/lgc.cpp index 38148c8c226..e78e8bb0f8e 100644 --- a/engines/grim/lua/lgc.cpp +++ b/engines/grim/lua/lgc.cpp @@ -16,6 +16,8 @@ #include "engines/grim/lua/ltm.h" #include "engines/grim/lua/lua.h" +namespace Grim { + static int32 markobject (TObject *o); /* @@ -253,3 +255,4 @@ void luaC_checkGC() { lua_collectgarbage(0); } +} // end of namespace Grim diff --git a/engines/grim/lua/lgc.h b/engines/grim/lua/lgc.h index b2240923817..82d09f72a05 100644 --- a/engines/grim/lua/lgc.h +++ b/engines/grim/lua/lgc.h @@ -10,6 +10,7 @@ #include "lobject.h" +namespace Grim { void luaC_checkGC(); TObject* luaC_getref(int32 ref); @@ -17,5 +18,6 @@ int32 luaC_ref(TObject *o, int32 lock); void luaC_hashcallIM(Hash *l); void luaC_strcallIM(TaggedString *l); +} // end of namespace Grim #endif diff --git a/engines/grim/lua/liolib.cpp b/engines/grim/lua/liolib.cpp index 779127559f0..81701c995a4 100644 --- a/engines/grim/lua/liolib.cpp +++ b/engines/grim/lua/liolib.cpp @@ -21,13 +21,16 @@ #if defined(UNIX) || defined(__SYMBIAN32__) #include -#include #endif +#include + #ifdef _WIN32 #include #endif +namespace Grim { + #define CLOSEDTAG 2 #define IOTAG 1 @@ -442,3 +445,5 @@ void lua_iolibclose() { delete g_stdout; delete g_stderr; } + +} // end of namespace Grim diff --git a/engines/grim/lua/llex.cpp b/engines/grim/lua/llex.cpp index aa924e29412..cbd239b7f70 100644 --- a/engines/grim/lua/llex.cpp +++ b/engines/grim/lua/llex.cpp @@ -16,6 +16,7 @@ #include "engines/grim/lua/luadebug.h" #include "engines/grim/lua/lzio.h" +namespace Grim { int32 lua_debug = 0; @@ -439,3 +440,4 @@ fraction: } } +} // end of namespace Grim diff --git a/engines/grim/lua/llex.h b/engines/grim/lua/llex.h index 0b78327d40b..ccdf961238a 100644 --- a/engines/grim/lua/llex.h +++ b/engines/grim/lua/llex.h @@ -10,6 +10,8 @@ #include "engines/grim/lua/lobject.h" #include "engines/grim/lua/lzio.h" +namespace Grim { + #define MAX_IFS 5 // "ifstate" keeps the state of each nested $if the lexical is dealing with. @@ -34,4 +36,6 @@ void luaX_init(); void luaX_setinput(ZIO *z); char *luaX_lasttoken(); +} // end of namespace Grim + #endif diff --git a/engines/grim/lua/lmathlib.cpp b/engines/grim/lua/lmathlib.cpp index 3f543e4549b..26a74aa185a 100644 --- a/engines/grim/lua/lmathlib.cpp +++ b/engines/grim/lua/lmathlib.cpp @@ -9,6 +9,8 @@ #include "engines/grim/lua/lua.h" #include "engines/grim/lua/lualib.h" +namespace Grim { + #ifndef LOCAL_PI #define LOCAL_PI (3.14159265358979323846) #endif @@ -149,3 +151,4 @@ void lua_mathlibopen() { lua_setglobal("PI"); } +} // end of namespace Grim diff --git a/engines/grim/lua/lmem.cpp b/engines/grim/lua/lmem.cpp index b741c30bd7e..4f551fdd75a 100644 --- a/engines/grim/lua/lmem.cpp +++ b/engines/grim/lua/lmem.cpp @@ -9,6 +9,8 @@ #include "engines/grim/lua/lstate.h" #include "engines/grim/lua/lua.h" +namespace Grim { + int32 luaM_growaux(void **block, int32 nelems, int32 size, const char *errormsg, int32 limit) { if (nelems >= limit) lua_error(errormsg); @@ -85,3 +87,5 @@ void *luaM_realloc(void *block, int32 size) { } #endif + +} // end of namespace Grim diff --git a/engines/grim/lua/lmem.h b/engines/grim/lua/lmem.h index 19b7dccbbbb..98e301cea27 100644 --- a/engines/grim/lua/lmem.h +++ b/engines/grim/lua/lmem.h @@ -9,6 +9,8 @@ #include "common/sys.h" +namespace Grim { + // memory error messages #define codeEM "code size overflow" #define constantEM "constant table overflow" @@ -31,6 +33,7 @@ extern int32 numblocks; extern int32 totalmem; #endif +} // end of namespace Grim #endif diff --git a/engines/grim/lua/lobject.cpp b/engines/grim/lua/lobject.cpp index 17a38244453..4f71be577c4 100644 --- a/engines/grim/lua/lobject.cpp +++ b/engines/grim/lua/lobject.cpp @@ -7,6 +7,8 @@ #include "engines/grim/lua/lobject.h" #include "engines/grim/lua/lua.h" +namespace Grim { + const char *luaO_typenames[] = { // ORDER LUA_T "userdata", "number", "string", "table", "function", "function", "task", "nil", "function", "mark", "mark", "mark", "line", NULL @@ -75,3 +77,5 @@ void luaO_insertlist(GCnode *root, GCnode *node) { root->next = node; node->marked = 0; } + +} // end of namespace Grim diff --git a/engines/grim/lua/lobject.h b/engines/grim/lua/lobject.h index 86eedd1831f..da4bd3c33b3 100644 --- a/engines/grim/lua/lobject.h +++ b/engines/grim/lua/lobject.h @@ -9,6 +9,8 @@ #include "engines/grim/lua/lua.h" +namespace Grim { + #ifdef LUA_DEBUG #include "engines/grim/lua/lauxlib.h" #define LUA_INTERNALERROR(s) luaL_verror("INTERNAL ERROR - %s [%s:%d]", (s), __FILE__, __LINE__) @@ -143,4 +145,6 @@ void luaO_insertlist(GCnode *root, GCnode *node); #define luaO_memup(d, s, n) memmove(d, s, n) #define luaO_memdown(d, s, n) memmove(d, s, n) +} // end of namespace Grim + #endif diff --git a/engines/grim/lua/lopcodes.h b/engines/grim/lua/lopcodes.h index 7115376acef..7417748ce02 100644 --- a/engines/grim/lua/lopcodes.h +++ b/engines/grim/lua/lopcodes.h @@ -7,6 +7,8 @@ #ifndef lopcodes_h #define lopcodes_h +namespace Grim { + /* ** NOTICE: variants of the same opcode must be consecutive: First, those ** with byte parameter, then with built-in parameters, and last with @@ -174,4 +176,6 @@ typedef enum { #define LFIELDS_PER_FLUSH 64 // lists (SETLIST) #define ZEROVARARG 64 +} // end of namespace Grim + #endif diff --git a/engines/grim/lua/lparser.h b/engines/grim/lua/lparser.h index f48bc6054a1..4089cf59613 100644 --- a/engines/grim/lua/lparser.h +++ b/engines/grim/lua/lparser.h @@ -10,9 +10,13 @@ #include "lobject.h" #include "lzio.h" +namespace Grim { + void luaY_codedebugline(int32 line); TProtoFunc *luaY_parser(ZIO *z); void luaY_error(char *s); void luaY_syntaxerror(char *s, char *token); +} // end of namespace Grim + #endif diff --git a/engines/grim/lua/lrestore.cpp b/engines/grim/lua/lrestore.cpp index 658e9d52f6f..2179b6e57ff 100644 --- a/engines/grim/lua/lrestore.cpp +++ b/engines/grim/lua/lrestore.cpp @@ -15,6 +15,8 @@ #include "engines/grim/lua/lstring.h" #include "engines/grim/lua/lua.h" +namespace Grim { + RestoreCallback restoreCallbackPtr = NULL; static void restoreObjectValue(TObject *object, RestoreSint32 restoreSint32, RestoreUint32 restoreUint32) { @@ -580,3 +582,5 @@ void lua_Restore(RestoreStream restoreStream, RestoreSint32 restoreSint32, Resto printf("lua_Restore() finished.\n"); } + +} // end of namespace Grim diff --git a/engines/grim/lua/lsave.cpp b/engines/grim/lua/lsave.cpp index 4f8eab8c56d..7290c7e05a5 100644 --- a/engines/grim/lua/lsave.cpp +++ b/engines/grim/lua/lsave.cpp @@ -15,6 +15,8 @@ #include "engines/grim/lua/lstring.h" #include "engines/grim/lua/lua.h" +namespace Grim { + PointerId makeIdFromPointer(void *ptr) { PointerId pointer; @@ -425,3 +427,5 @@ void lua_Save(SaveStream saveStream, SaveSint32 saveSint32, SaveUint32 saveUint3 printf("lua_Save() finished.\n"); } + +} // end of namespace Grim diff --git a/engines/grim/lua/lstate.cpp b/engines/grim/lua/lstate.cpp index ec9dc9531ac..5ba927595cd 100644 --- a/engines/grim/lua/lstate.cpp +++ b/engines/grim/lua/lstate.cpp @@ -23,6 +23,8 @@ #include "engines/grim/lua/lualib.h" #include "engines/grim/lua/luadebug.h" +namespace Grim { + LState *lua_state = NULL; int32 globalTaskSerialId; @@ -141,7 +143,7 @@ void lua_open() { luaT_init(); luaB_predefine(); luaL_addlibtolist(stdErrorRimFunc, (sizeof(stdErrorRimFunc) / sizeof(stdErrorRimFunc[0]))); - if (gDebugLevel == DEBUG_LUA || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_LUA || Common::getDebugLevel() == DEBUG_ALL) lua_callhook = callHook; } @@ -220,3 +222,5 @@ struct lua_Task *luaI_newtask() { result->id = globalTaskSerialId++; return result; } + +} // end of namespace Grim diff --git a/engines/grim/lua/lstate.h b/engines/grim/lua/lstate.h index d52cebcc32f..ed47a57e7e8 100644 --- a/engines/grim/lua/lstate.h +++ b/engines/grim/lua/lstate.h @@ -11,6 +11,8 @@ #include +namespace Grim { + #define MAX_C_BLOCKS 10 #define GARBAGE_BLOCK 150 @@ -120,4 +122,6 @@ void luaI_switchtask(lua_Task *t); // Create a new task and switch to it lua_Task *luaI_newtask(); +} // end of namespace Grim + #endif diff --git a/engines/grim/lua/lstring.cpp b/engines/grim/lua/lstring.cpp index 32f59727b12..ce346e99c9e 100644 --- a/engines/grim/lua/lstring.cpp +++ b/engines/grim/lua/lstring.cpp @@ -12,6 +12,7 @@ #include "engines/grim/lua/lstring.h" #include "engines/grim/lua/lua.h" +namespace Grim { #define gcsizestring(l) (1 + (l / 64)) // "weight" for a string with length 'l' @@ -241,3 +242,4 @@ int32 luaS_globaldefined(const char *name) { return ts->globalval.ttype != LUA_T_NIL; } +} // end of namespace Grim diff --git a/engines/grim/lua/lstring.h b/engines/grim/lua/lstring.h index e50f94b0428..1124b9e6949 100644 --- a/engines/grim/lua/lstring.h +++ b/engines/grim/lua/lstring.h @@ -10,6 +10,7 @@ #include "engines/grim/lua/lobject.h" +namespace Grim { void luaS_init(); TaggedString *luaS_createudata(void *udata, int32 tag); @@ -26,4 +27,6 @@ void luaS_freeall(); extern TaggedString EMPTY; #define NUM_HASHS 61 +} // end of namespace Grim + #endif diff --git a/engines/grim/lua/lstrlib.cpp b/engines/grim/lua/lstrlib.cpp index 5d9f41e4e0d..63afbfa70b0 100644 --- a/engines/grim/lua/lstrlib.cpp +++ b/engines/grim/lua/lstrlib.cpp @@ -9,6 +9,8 @@ #include "engines/grim/lua/lua.h" #include "engines/grim/lua/lualib.h" +namespace Grim { + static void addnchar(const char *s, int32 n) { char *b = luaL_openspace(n); strncpy(b, s, n); @@ -488,3 +490,5 @@ static struct luaL_reg strlib[] = { void strlib_open() { luaL_openlib(strlib, (sizeof(strlib) / sizeof(strlib[0]))); } + +} // end of namespace Grim diff --git a/engines/grim/lua/lstx.cpp b/engines/grim/lua/lstx.cpp index 5bae35d3024..491694fb668 100644 --- a/engines/grim/lua/lstx.cpp +++ b/engines/grim/lua/lstx.cpp @@ -10,6 +10,22 @@ by GNU Bison version 1.25 // generated by using command: bison -o lstx.c -p luaY_ -d lua.stx // removed platform depend not used code, formated code too +#include "engines/grim/lua/lauxlib.h" +#include "engines/grim/lua/ldo.h" +#include "engines/grim/lua/lfunc.h" +#include "engines/grim/lua/llex.h" +#include "engines/grim/lua/lmem.h" +#include "engines/grim/lua/lopcodes.h" +#include "engines/grim/lua/lparser.h" +#include "engines/grim/lua/lstate.h" +#include "engines/grim/lua/lstring.h" +#include "engines/grim/lua/lua.h" +#include "engines/grim/lua/luadebug.h" +#include "engines/grim/lua/lzio.h" + +namespace Grim { + + #define YYBISON 1 /* Identify Bison output. */ #define yyparse luaY_parse @@ -54,20 +70,6 @@ by GNU Bison version 1.25 */ -#include "engines/grim/lua/lauxlib.h" -#include "engines/grim/lua/ldo.h" -#include "engines/grim/lua/lfunc.h" -#include "engines/grim/lua/llex.h" -#include "engines/grim/lua/lmem.h" -#include "engines/grim/lua/lopcodes.h" -#include "engines/grim/lua/lparser.h" -#include "engines/grim/lua/lstate.h" -#include "engines/grim/lua/lstring.h" -#include "engines/grim/lua/lua.h" -#include "engines/grim/lua/luadebug.h" -#include "engines/grim/lua/lzio.h" - - int luaY_parse (void); @@ -1493,4 +1495,4 @@ yyerrhandle: goto yynewstate; } - +} // end of namespace Grim diff --git a/engines/grim/lua/lstx.h b/engines/grim/lua/lstx.h index e7793c8469c..541543c3109 100644 --- a/engines/grim/lua/lstx.h +++ b/engines/grim/lua/lstx.h @@ -1,12 +1,14 @@ -typedef union -{ - int vInt; - float vReal; - char *pChar; - long vLong; - TaggedString *pTStr; - TProtoFunc *pFunc; +namespace Grim { + +typedef union { + int vInt; + float vReal; + char *pChar; + long vLong; + TaggedString *pTStr; + TProtoFunc *pFunc; } YYSTYPE; + #define WRONGTOKEN 258 #define NIL 259 #define IF 260 @@ -37,3 +39,5 @@ typedef union extern YYSTYPE luaY_lval; + +} // end of namespace Grim diff --git a/engines/grim/lua/ltable.cpp b/engines/grim/lua/ltable.cpp index 3933a3dfd9d..8612daf516d 100644 --- a/engines/grim/lua/ltable.cpp +++ b/engines/grim/lua/ltable.cpp @@ -11,6 +11,8 @@ #include "engines/grim/lua/ltable.h" #include "engines/grim/lua/lua.h" +namespace Grim { + #define gcsize(n) (1 + (n / 16)) #define nuse(t) ((t)->nuse) #define nodevector(t) ((t)->node) @@ -232,3 +234,5 @@ Node *luaH_next(TObject *o, TObject *r) { return hashnext(t, i + 1); } } + +} // end of namespace Grim diff --git a/engines/grim/lua/ltable.h b/engines/grim/lua/ltable.h index 98cc9b15cbd..a8810d67caf 100644 --- a/engines/grim/lua/ltable.h +++ b/engines/grim/lua/ltable.h @@ -9,6 +9,8 @@ #include "engines/grim/lua/lobject.h" +namespace Grim { + #define node(t, i) (&(t)->node[i]) #define ref(n) (&(n)->ref) #define val(n) (&(n)->val) @@ -22,4 +24,6 @@ Node *luaH_next(TObject *o, TObject *r); Node *hashnodecreate(int32 nhash); int32 present(Hash *t, TObject *key); +} // end of namespace Grim + #endif diff --git a/engines/grim/lua/ltask.cpp b/engines/grim/lua/ltask.cpp index 44010625a60..0219bd145bf 100644 --- a/engines/grim/lua/ltask.cpp +++ b/engines/grim/lua/ltask.cpp @@ -5,6 +5,8 @@ #include "ldo.h" #include "lvm.h" +namespace Grim { + void pause_scripts() { lua_Task *t; @@ -287,3 +289,5 @@ void lua_runtasks() { luaI_switchtask(old_task); } } + +} // end of namespace Grim diff --git a/engines/grim/lua/ltask.h b/engines/grim/lua/ltask.h index cd79f1a674e..0f10b0953bc 100644 --- a/engines/grim/lua/ltask.h +++ b/engines/grim/lua/ltask.h @@ -4,6 +4,8 @@ #include "engines/grim/lua/lua.h" #include "engines/grim/lua/lstate.h" +namespace Grim { + extern int32 task_tag; void start_script(); @@ -15,4 +17,6 @@ void unpause_scripts(); void find_script(); void break_here(); +} // end of namespace Grim + #endif diff --git a/engines/grim/lua/ltm.cpp b/engines/grim/lua/ltm.cpp index c348ec63c55..46c4fb1af48 100644 --- a/engines/grim/lua/ltm.cpp +++ b/engines/grim/lua/ltm.cpp @@ -10,7 +10,9 @@ #include "engines/grim/lua/lobject.h" #include "engines/grim/lua/lstate.h" #include "engines/grim/lua/ltm.h" +#include "engines/grim/lua/lapi.h" +namespace Grim { const char *luaT_eventname[] = { // ORDER IM "gettable", "settable", "index", "getglobal", "setglobal", "add", @@ -149,8 +151,6 @@ const char *luaT_travtagmethods(int32 (*fn)(TObject *)) { */ #ifdef LUA_COMPAT2_5 -#include "lapi.h" - void errorFB() { lua_Object o = lua_getparam(1); if (lua_isstring(o)) @@ -227,5 +227,7 @@ void luaT_setfallback() { lua_pushcfunction(replace); } +} // end of namespace Grim + #endif diff --git a/engines/grim/lua/ltm.h b/engines/grim/lua/ltm.h index 810c5098c85..e9d9bed1938 100644 --- a/engines/grim/lua/ltm.h +++ b/engines/grim/lua/ltm.h @@ -11,6 +11,8 @@ #include "engines/grim/lua/lobject.h" #include "engines/grim/lua/lstate.h" +namespace Grim { + /* * WARNING: if you change the order of this enumeration, * grep "ORDER IM" @@ -58,4 +60,6 @@ const char *luaT_travtagmethods(int32 (*fn)(TObject *)); void luaT_setfallback(); // only if LUA_COMPAT2_5 +} // end of namespace Grim + #endif diff --git a/engines/grim/lua/lua.h b/engines/grim/lua/lua.h index a135d968b68..3f6cc5d18c5 100644 --- a/engines/grim/lua/lua.h +++ b/engines/grim/lua/lua.h @@ -13,6 +13,15 @@ #ifndef lua_h #define lua_h +namespace Common { + class String; + class SeekableReadStream; + class WriteStream; + class File; +} + +namespace Grim { + #define LUA_VERSION "Lua 3.1 (alpha)" #define LUA_COPYRIGHT "Copyright (C) 1994-1998 TeCGraf, PUC-Rio" #define LUA_AUTHORS "W. Celes, R. Ierusalimschy & L. H. de Figueiredo" @@ -32,13 +41,6 @@ struct PointerId { PointerId makeIdFromPointer(void *ptr); void *makePointerFromId(PointerId ptr); -namespace Common { - class String; - class SeekableReadStream; - class WriteStream; - class File; -} - class LuaFile { public: Common::String _name; @@ -185,7 +187,6 @@ lua_Object lua_setfallback(const char *event, lua_CFunction fallback); #endif -#endif /****************************************************************************** * Copyright (c) 1994-1998 TeCGraf, PUC-Rio. All rights reserved. @@ -220,3 +221,7 @@ lua_Object lua_setfallback(const char *event, lua_CFunction fallback); * Luiz Henrique de Figueiredo at TeCGraf, PUC-Rio. * This implementation contains no third-party code. ******************************************************************************/ + +} // end of namespace Grim + +#endif diff --git a/engines/grim/lua/luadebug.h b/engines/grim/lua/luadebug.h index 9cfcabf35b1..0d1d0fd2db5 100644 --- a/engines/grim/lua/luadebug.h +++ b/engines/grim/lua/luadebug.h @@ -11,6 +11,8 @@ #include "engines/grim/lua/lua.h" +namespace Grim { + typedef lua_Object lua_Function; typedef void (*lua_LHFunction)(int32 line); @@ -28,5 +30,7 @@ extern lua_LHFunction lua_linehook; extern lua_CHFunction lua_callhook; extern int32 lua_debug; +} // end of namespace Grim + #endif diff --git a/engines/grim/lua/lualib.h b/engines/grim/lua/lualib.h index bcd0e936acc..00b3c4efa8b 100644 --- a/engines/grim/lua/lualib.h +++ b/engines/grim/lua/lualib.h @@ -10,6 +10,8 @@ #include "engines/grim/lua/lua.h" +namespace Grim { + void lua_iolibopen(); void lua_strlibopen(); void lua_mathlibopen(); @@ -25,5 +27,7 @@ void lua_iolibclose(); int32 luaI_singlematch(int32 c, const char *p, const char **ep); +} // end of namespace Grim + #endif diff --git a/engines/grim/lua/lundump.cpp b/engines/grim/lua/lundump.cpp index 82e0a646d03..e72db6e5583 100644 --- a/engines/grim/lua/lundump.cpp +++ b/engines/grim/lua/lundump.cpp @@ -10,6 +10,8 @@ #include "engines/grim/lua/lstring.h" #include "engines/grim/lua/lundump.h" +namespace Grim { + static float conv_float(const byte *data) { const byte *udata = data; byte fdata[4]; @@ -182,3 +184,5 @@ TProtoFunc *luaU_undump1(ZIO *Z) { luaL_verror("%s is not a Lua binary file", zname(Z)); return NULL; } + +} // end of namespace Grim diff --git a/engines/grim/lua/lundump.h b/engines/grim/lua/lundump.h index c695fdf6731..b3a80071f1b 100644 --- a/engines/grim/lua/lundump.h +++ b/engines/grim/lua/lundump.h @@ -10,6 +10,8 @@ #include "engines/grim/lua/lobject.h" #include "engines/grim/lua/lzio.h" +namespace Grim { + #define ID_CHUNK 27 // ESC #define ID_FUNCTION '#' #define ID_END '$' @@ -24,6 +26,8 @@ TProtoFunc* luaU_undump1(ZIO* Z); // load one chunk +} // end of namespace Grim + #endif diff --git a/engines/grim/lua/lvm.cpp b/engines/grim/lua/lvm.cpp index 6705294905d..31066272661 100644 --- a/engines/grim/lua/lvm.cpp +++ b/engines/grim/lua/lvm.cpp @@ -18,6 +18,8 @@ #include "engines/grim/lua/luadebug.h" #include "engines/grim/lua/lvm.h" +namespace Grim { + #define skip_word(pc) (pc += 2) #define get_word(pc) ((*((pc) + 1) << 8)|(*(pc))) #define next_word(pc) (pc += 2, get_word(pc - 2)) @@ -710,3 +712,4 @@ setline: } } +} // end of namespace Grim diff --git a/engines/grim/lua/lvm.h b/engines/grim/lua/lvm.h index e586fdb814d..f693d629c6a 100644 --- a/engines/grim/lua/lvm.h +++ b/engines/grim/lua/lvm.h @@ -11,6 +11,7 @@ #include "engines/grim/lua/ldo.h" #include "engines/grim/lua/lobject.h" +namespace Grim { #define tonumber(o) ((ttype(o) != LUA_T_NUMBER) && (luaV_tonumber(o) != 0)) #define tostring(o) ((ttype(o) != LUA_T_STRING) && (luaV_tostring(o) != 0)) @@ -26,4 +27,6 @@ void luaV_setglobal(TaggedString *ts); StkId luaV_execute(CallInfo *ci); void luaV_closure(int32 nelems); +} // end of namespace Grim + #endif diff --git a/engines/grim/lua/lzio.cpp b/engines/grim/lua/lzio.cpp index 38709e845c4..1e118e7903f 100644 --- a/engines/grim/lua/lzio.cpp +++ b/engines/grim/lua/lzio.cpp @@ -9,6 +9,8 @@ #include "common/file.h" +namespace Grim { + int32 zgeteoz(ZIO *) { return EOZ; } @@ -37,3 +39,5 @@ int32 zread (ZIO *z, void *b, int32 n) { } return 0; } + +} // end of namespace Grim diff --git a/engines/grim/lua/lzio.h b/engines/grim/lua/lzio.h index 59ce2a6ba2d..058cf13ed1e 100644 --- a/engines/grim/lua/lzio.h +++ b/engines/grim/lua/lzio.h @@ -14,6 +14,8 @@ namespace Common { class File; } +namespace Grim { + // For Lua only #define zopen luaZ_mopen @@ -41,5 +43,6 @@ struct zio { byte buffer[ZBSIZE]; // buffer }; +} // end of namespace Grim #endif diff --git a/engines/grim/main.cpp b/engines/grim/main.cpp index 22085ef3928..8d291b3e3fe 100644 --- a/engines/grim/main.cpp +++ b/engines/grim/main.cpp @@ -41,9 +41,10 @@ #endif #include "engines/grim/gfx_tinygl.h" +namespace Grim { + // Hacky global toggles for experimental/debug code bool SHOWFPS_GLOBAL, TINYGL_GLOBAL; -enDebugLevels gDebugLevel = DEBUG_NONE; static bool g_lua_initialized = false; GfxBase *g_driver = NULL; @@ -83,11 +84,11 @@ extern "C" int residual_main(int argc, char *argv[]) { // soonest possible moment to ensure debug output starts early on, if // requested. if (settings.contains("debuglevel")) { - gDebugLevel = (enDebugLevels)strtol(settings["debuglevel"].c_str(), 0, 10); - printf("Debuglevel (from command line): %d\n", gDebugLevel); +// Common::getDebugLevel() = (enDebugLevels)strtol(settings["debuglevel"].c_str(), 0, 10); + printf("Debuglevel (from command line): %d\n", Common::getDebugLevel()); settings.erase("debuglevel"); // This option should not be passed to ConfMan. - } else if (ConfMan.hasKey("debuglevel")) - gDebugLevel = (enDebugLevels)ConfMan.getInt("debuglevel"); + }// else if (ConfMan.hasKey("debuglevel")) +// Common::getDebugLevel() = (enDebugLevels)ConfMan.getInt("debuglevel"); if (settings.contains("debugflags")) { specialDebug = settings["debugflags"]; @@ -213,3 +214,5 @@ void quit() { Common::ConfigManager::destroy(); Common::SearchManager::destroy(); } + +} // end of namespace Grim diff --git a/engines/grim/material.cpp b/engines/grim/material.cpp index aefb75c03ac..cb75e28c758 100644 --- a/engines/grim/material.cpp +++ b/engines/grim/material.cpp @@ -28,6 +28,8 @@ #include "engines/grim/material.h" #include "engines/grim/gfx_base.h" +namespace Grim { + Material::Material(const char *filename, const char *data, int len, const CMap &cmap) : Resource(filename), _cmap((CMap *) &cmap) { if (len < 4 || memcmp(data, "MAT ", 4) != 0) @@ -39,7 +41,7 @@ Material::Material(const char *filename, const char *data, int len, const CMap & _height = READ_LE_UINT32(data + 80 + _numImages * 40); if (_width == 0 || _height == 0) { - if (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("skip load texture: bad texture size (%dx%d) for texture %s", _width, _height, filename); return; } @@ -60,3 +62,5 @@ Material::~Material() { return; g_driver->destroyMaterial(this); } + +} // end of namespace Grim diff --git a/engines/grim/material.h b/engines/grim/material.h index f5c8eff4ed8..5d37b90eadf 100644 --- a/engines/grim/material.h +++ b/engines/grim/material.h @@ -28,6 +28,8 @@ #include "engines/grim/resource.h" +namespace Grim { + class Material : public Resource { public: // Load a texture from the given data. @@ -51,4 +53,6 @@ public: void *_textures; }; +} // end of namespace Grim + #endif diff --git a/engines/grim/matrix3.h b/engines/grim/matrix3.h index c01cda9ef37..ddc81062781 100644 --- a/engines/grim/matrix3.h +++ b/engines/grim/matrix3.h @@ -29,7 +29,7 @@ #include "engines/grim/vector3d.h" // matrix 3 is a rotation matrix -class Matrix3{ +class Matrix3 { public: Vector3d _right; Vector3d _up; diff --git a/engines/grim/model.cpp b/engines/grim/model.cpp index 6cb163d2017..7ddbcbe5b02 100644 --- a/engines/grim/model.cpp +++ b/engines/grim/model.cpp @@ -31,6 +31,8 @@ #include "engines/grim/textsplit.h" #include "engines/grim/gfx_base.h" +namespace Grim { + Model::Model(const char *filename, const char *data, int len, const CMap &cmap) : Resource(filename), _numMaterials(0), _numGeosets(0) { @@ -330,7 +332,7 @@ void Model::loadText(TextSplitter &ts, const CMap &cmap) { _rootHierNode[num]._totalWeight = 1; } - if (!ts.eof() && (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL)) + if (!ts.eof() && (Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL)) warning("Unexpected junk at end of model text"); } @@ -361,7 +363,7 @@ void Model::Mesh::loadText(TextSplitter &ts, ResPtr *materials) { // In data001/rope_scale.3do, the shadow line is missing if (sscanf(ts.currentLine(), "shadow %d", &_shadow) < 1) { _shadow = 0; - if (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("Missing shadow directive in model"); } else ts.nextLine(); @@ -516,3 +518,5 @@ void Model::Face::draw(float *vertices, float *vertNormals, float *textureVerts) _material->select(); g_driver->drawModelFace(this, vertices, vertNormals, textureVerts); } + +} // end of namespace Grim diff --git a/engines/grim/model.h b/engines/grim/model.h index 4a59b38e471..94f6c671b4e 100644 --- a/engines/grim/model.h +++ b/engines/grim/model.h @@ -29,6 +29,8 @@ #include "engines/grim/resource.h" #include "engines/grim/matrix4.h" +namespace Grim { + class TextSplitter; class Model : public Resource { @@ -137,4 +139,6 @@ public: HierNode *_rootHierNode; }; +} // end of namespace Grim + #endif diff --git a/engines/grim/objectstate.cpp b/engines/grim/objectstate.cpp index 8b4314f830a..f746c5492ab 100644 --- a/engines/grim/objectstate.cpp +++ b/engines/grim/objectstate.cpp @@ -25,6 +25,8 @@ #include "engines/grim/objectstate.h" +namespace Grim { + ObjectState::ObjectState(int setupID, ObjectState::Position pos, const char *bitmap, const char *zbitmap, bool visible) : _setupID(setupID), _pos(pos) { _bitmap = g_resourceloader->loadBitmap(bitmap); @@ -44,3 +46,5 @@ ObjectState::~ObjectState() { if (_zbitmap) g_resourceloader->uncache(_zbitmap->getFilename()); } + +} // end of namespace Grim diff --git a/engines/grim/objectstate.h b/engines/grim/objectstate.h index f219065a6ae..85dab6211c5 100644 --- a/engines/grim/objectstate.h +++ b/engines/grim/objectstate.h @@ -28,6 +28,8 @@ #include "engines/grim/bitmap.h" +namespace Grim { + class ObjectState { public: enum Position { @@ -68,4 +70,6 @@ private: ResPtr _bitmap, _zbitmap; }; +} // end of namespace Grim + #endif diff --git a/engines/grim/primitives.cpp b/engines/grim/primitives.cpp index f537ca7bb63..ea6d5537f25 100644 --- a/engines/grim/primitives.cpp +++ b/engines/grim/primitives.cpp @@ -26,6 +26,8 @@ #include "engines/grim/gfx_base.h" #include "engines/grim/primitives.h" +namespace Grim { + PrimitiveObject::PrimitiveObject() { memset(&_color, 0, sizeof(Color)); _filled = false; @@ -106,3 +108,5 @@ void PrimitiveObject::setPos(int x, int y) { } } } + +} // end of namespace Grim diff --git a/engines/grim/primitives.h b/engines/grim/primitives.h index 0cb9e314cde..e9f63007a8e 100644 --- a/engines/grim/primitives.h +++ b/engines/grim/primitives.h @@ -30,6 +30,8 @@ #include "engines/grim/color.h" +namespace Grim { + class PrimitiveObject { public: PrimitiveObject(); @@ -66,4 +68,6 @@ private: Bitmap *_bitmap; }; +} // end of namespace Grim + #endif diff --git a/engines/grim/registry.cpp b/engines/grim/registry.cpp index 328788f4cf4..69b9b263f31 100644 --- a/engines/grim/registry.cpp +++ b/engines/grim/registry.cpp @@ -26,6 +26,8 @@ #include "engines/grim/registry.h" #include "engines/grim/cmd_line.h" +namespace Grim { + Registry *g_registry = NULL; // SpewOnError @@ -206,3 +208,5 @@ void Registry::save() { _dirty = false; } + +} // end of namespace Grim diff --git a/engines/grim/registry.h b/engines/grim/registry.h index 61233c329ad..90ef0358a31 100644 --- a/engines/grim/registry.h +++ b/engines/grim/registry.h @@ -28,6 +28,8 @@ #include "common/str.h" +namespace Grim { + class Registry { public: const char *get(const char *key, const char *defval) const; @@ -66,4 +68,6 @@ private: extern Registry *g_registry; +} // end of namespace Grim + #endif diff --git a/engines/grim/resource.cpp b/engines/grim/resource.cpp index b91a222708e..03136b836a1 100644 --- a/engines/grim/resource.cpp +++ b/engines/grim/resource.cpp @@ -31,6 +31,8 @@ #include "engines/grim/grim.h" #include "engines/grim/lipsync.h" +namespace Grim { + ResourceLoader *g_resourceloader = NULL; ResourceLoader::ResourceLoader() { @@ -172,7 +174,7 @@ Bitmap *ResourceLoader::loadBitmap(const char *filename) { Block *b = getFileBlock(filename); if (!b) { // Grim sometimes asks for non-existant bitmaps (eg, ha_overhead) - if (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("Could not find bitmap %s", filename); return NULL; } @@ -270,7 +272,7 @@ LipSync *ResourceLoader::loadLipSync(const char *filename) { Block *b = getFileBlock(filename); if (!b) { - if (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("Could not find lipsync file %s", filename); result = NULL; } else { @@ -346,3 +348,5 @@ void ResourceLoader::uncache(const char *filename) { } } } + +} // end of namespace Grim diff --git a/engines/grim/resource.h b/engines/grim/resource.h index b5db4c7586f..9d3010d23ae 100644 --- a/engines/grim/resource.h +++ b/engines/grim/resource.h @@ -30,7 +30,7 @@ #include "engines/grim/lab.h" -#include +namespace Grim { class Bitmap; class CMap; @@ -145,4 +145,6 @@ inline void Resource::deref() { } } +} // end of namespace Grim + #endif diff --git a/engines/grim/savegame.cpp b/engines/grim/savegame.cpp index 24e99032925..561dae6f429 100644 --- a/engines/grim/savegame.cpp +++ b/engines/grim/savegame.cpp @@ -28,6 +28,8 @@ #include "engines/grim/savegame.h" +namespace Grim { + #define SAVEGAME_HEADERTAG 'RSAV' #define SAVEGAME_FOOTERTAG 'ESAV' #define SAVEGAME_VERSION 1 @@ -225,3 +227,5 @@ void SaveGame::writeByte(byte data) { _sectionBuffer[_sectionSize] = data; _sectionSize++; } + +} // end of namespace Grim diff --git a/engines/grim/savegame.h b/engines/grim/savegame.h index 1b8710bab89..d2153ef7742 100644 --- a/engines/grim/savegame.h +++ b/engines/grim/savegame.h @@ -28,6 +28,8 @@ #include "common/savefile.h" +namespace Grim { + class SaveGame { public: SaveGame(const char *filename, bool saving); @@ -57,4 +59,6 @@ protected: byte *_sectionBuffer; }; +} // end of namespace Grim + #endif diff --git a/engines/grim/scene.cpp b/engines/grim/scene.cpp index 313f358b971..019465940b4 100644 --- a/engines/grim/scene.cpp +++ b/engines/grim/scene.cpp @@ -30,6 +30,8 @@ #include "engines/grim/imuse/imuse.h" +namespace Grim { + Scene::Scene(const char *name, const char *buf, int len) : _locked(false), _name(name), _enableLights(false) { TextSplitter ts(buf, len); @@ -120,10 +122,10 @@ void Scene::Setup::load(TextSplitter &ts) { ts.scanString(" background %256s", 1, buf); _bkgndBm = g_resourceloader->loadBitmap(buf); if (!_bkgndBm) { - if (gDebugLevel == DEBUG_BITMAPS || gDebugLevel == DEBUG_ERROR || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_BITMAPS || Common::getDebugLevel() == DEBUG_ERROR || Common::getDebugLevel() == DEBUG_ALL) printf("Unable to load scene bitmap: %s\n", buf); } else { - if (gDebugLevel == DEBUG_BITMAPS || gDebugLevel == DEBUG_NORMAL || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_BITMAPS || Common::getDebugLevel() == DEBUG_NORMAL || Common::getDebugLevel() == DEBUG_ALL) printf("Loaded scene bitmap: %s\n", buf); } @@ -135,7 +137,7 @@ void Scene::Setup::load(TextSplitter &ts) { // Don't even try to load if it's the "none" bitmap if (strcmp(buf, ".lbm") != 0) { _bkgndZBm = g_resourceloader->loadBitmap(buf); - if (gDebugLevel == DEBUG_BITMAPS || gDebugLevel == DEBUG_NORMAL || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_BITMAPS || Common::getDebugLevel() == DEBUG_NORMAL || Common::getDebugLevel() == DEBUG_ALL) printf("Loading scene z-buffer bitmap: %s\n", buf); } } @@ -262,7 +264,7 @@ ObjectState *Scene::findState(const char *filename) { if (strcmp(file, filename) == 0) return *i; if (strcasecmp(file, filename) == 0) { - if (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("State object request '%s' matches object '%s' but is the wrong case!", filename, file); return *i; } @@ -304,3 +306,5 @@ void Scene::moveObjectStateToLast(ObjectState *s) { _states.remove(s); _states.push_back(s); } + +} // end of namespace Grim diff --git a/engines/grim/scene.h b/engines/grim/scene.h index db243a1e20b..a1e19f653a5 100644 --- a/engines/grim/scene.h +++ b/engines/grim/scene.h @@ -30,6 +30,8 @@ #include "engines/grim/walkplane.h" #include "engines/grim/objectstate.h" +namespace Grim { + // The Lua code calls this a "set". class Scene { @@ -135,4 +137,6 @@ private: StateList _states; }; +} // end of namespace Grim + #endif diff --git a/engines/grim/smush/blocky16.cpp b/engines/grim/smush/blocky16.cpp index e4001ea56fb..ab06cbe55ee 100644 --- a/engines/grim/smush/blocky16.cpp +++ b/engines/grim/smush/blocky16.cpp @@ -28,6 +28,8 @@ #include "engines/grim/smush/blocky16.h" +namespace Grim { + #if defined(SYSTEM_NEED_ALIGNMENT) #define COPY_4X1_LINE(dst, src) \ @@ -825,3 +827,5 @@ void Blocky16::decode(byte *dst, const byte *src) { } _prevSeqNb = seq_nb; } + +} // end of namespace Grim diff --git a/engines/grim/smush/blocky16.h b/engines/grim/smush/blocky16.h index efe04921c0a..59912911434 100644 --- a/engines/grim/smush/blocky16.h +++ b/engines/grim/smush/blocky16.h @@ -28,6 +28,8 @@ #include "common/sys.h" +namespace Grim { + class Blocky16 { private: @@ -61,4 +63,6 @@ public: void decode(byte *dst, const byte *src); }; +} // end of namespace Grim + #endif diff --git a/engines/grim/smush/smush.cpp b/engines/grim/smush/smush.cpp index 25042f15e5b..0fa2826d8f9 100644 --- a/engines/grim/smush/smush.cpp +++ b/engines/grim/smush/smush.cpp @@ -30,6 +30,8 @@ #include "engines/grim/smush/smush.h" #include "engines/grim/grim.h" +namespace Grim { + #define SMUSH_LOOPMOVIE(x) (x & 0x000001) #define SMUSH_ALTSPEED(x) (x & 0x000004) @@ -174,12 +176,12 @@ void Smush::handleFrame() { // MakeAnim animation type 'Bl16' parameters: 6000;8000;100;0;0;0;0;0;2;0; // Lola engine room (loops a limited number of times?): // MakeAnim animation type 'Bl16' parameters: 6000;8000;90;1;0;0;0;0;2;0; - if (gDebugLevel == DEBUG_SMUSH || gDebugLevel == DEBUG_NORMAL || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_SMUSH || Common::getDebugLevel() == DEBUG_NORMAL || Common::getDebugLevel() == DEBUG_ALL) printf("Announcement data: %s\n", anno); // It looks like the announcement data is actually for setting some of the // header parameters, not for any looping purpose } else { - if (gDebugLevel == DEBUG_SMUSH || gDebugLevel == DEBUG_NORMAL || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_SMUSH || Common::getDebugLevel() == DEBUG_NORMAL || Common::getDebugLevel() == DEBUG_ALL) printf("Announcement header not understood: %s\n", anno); } delete[] anno; @@ -202,7 +204,7 @@ void Smush::handleFrame() { else handleWave(frame + pos + 8 + 4, decompressed_size); pos += READ_BE_UINT32(frame + pos + 4) + 8; - } else if (gDebugLevel == DEBUG_SMUSH || gDebugLevel == DEBUG_ERROR || gDebugLevel == DEBUG_ALL) { + } else if (Common::getDebugLevel() == DEBUG_SMUSH || Common::getDebugLevel() == DEBUG_ERROR || Common::getDebugLevel() == DEBUG_ALL) { error("Smush::handleFrame() unknown tag"); } } while (pos < size); @@ -241,7 +243,7 @@ void Smush::handleFramesHeader() { _freq = READ_LE_UINT32(f_header + pos + 8); _channels = READ_LE_UINT32(f_header + pos + 12); pos += 20; - } else if (gDebugLevel == DEBUG_SMUSH || gDebugLevel == DEBUG_ERROR || gDebugLevel == DEBUG_ALL){ + } else if (Common::getDebugLevel() == DEBUG_SMUSH || Common::getDebugLevel() == DEBUG_ERROR || Common::getDebugLevel() == DEBUG_ALL){ error("Smush::handleFramesHeader() unknown tag"); } } while (pos < size); @@ -281,7 +283,7 @@ bool Smush::setupAnim(const char *file, int x, int y) { _speed = READ_LE_UINT32(s_header + 14); flags = READ_LE_UINT16(s_header + 18); // Output information for checking out the flags - if (gDebugLevel == DEBUG_SMUSH || gDebugLevel == DEBUG_NORMAL || gDebugLevel == DEBUG_ALL) { + if (Common::getDebugLevel() == DEBUG_SMUSH || Common::getDebugLevel() == DEBUG_NORMAL || Common::getDebugLevel() == DEBUG_ALL) { printf("SMUSH Flags:"); for (int i = 0; i < 16; i++) printf(" %d", (flags & (1 << i)) != 0); @@ -311,7 +313,7 @@ void Smush::stop() { bool Smush::play(const char *filename, int x, int y) { deinit(); - if (gDebugLevel == DEBUG_SMUSH) + if (Common::getDebugLevel() == DEBUG_SMUSH) printf("Playing video '%s'.\n", filename); // Load the video @@ -340,7 +342,7 @@ struct SavePos *zlibFile::getPos() { uint32 position = _handle->pos(); if (position == ((uint32) -1)) { - if (gDebugLevel == DEBUG_SMUSH || gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_SMUSH || Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("zlibFile::open() unable to find start position! %m"); return NULL; } @@ -381,7 +383,7 @@ bool zlibFile::open(const char *filename) { memset(_inBuf, 0, BUFFER_SIZE); if (_handle) { - if (gDebugLevel == DEBUG_SMUSH || gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_SMUSH || Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("zlibFile::open() File %s already opened", filename); return false; } @@ -391,7 +393,7 @@ bool zlibFile::open(const char *filename) { _handle = g_resourceloader->openNewStreamFile(filename); if (!_handle->isOpen()) { - if (gDebugLevel == DEBUG_SMUSH || gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_SMUSH || Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("zlibFile::open() zlibFile %s not found", filename); return false; } @@ -405,7 +407,7 @@ bool zlibFile::open(const char *filename) { // Xtra & Comment if (flags & 0x04 || flags & 0x10) { - if (gDebugLevel == DEBUG_SMUSH || gDebugLevel == DEBUG_ERROR || gDebugLevel == DEBUG_ALL) { + if (Common::getDebugLevel() == DEBUG_SMUSH || Common::getDebugLevel() == DEBUG_ERROR || Common::getDebugLevel() == DEBUG_ALL) { error("zlibFile::open() Unsupported header flag"); } return false; @@ -425,7 +427,7 @@ bool zlibFile::open(const char *filename) { _stream.zfree = NULL; _stream.opaque = Z_NULL; - if (inflateInit2(&_stream, -15) != Z_OK && (gDebugLevel == DEBUG_SMUSH || gDebugLevel == DEBUG_ERROR || gDebugLevel == DEBUG_ALL)) + if (inflateInit2(&_stream, -15) != Z_OK && (Common::getDebugLevel() == DEBUG_SMUSH || Common::getDebugLevel() == DEBUG_ERROR || Common::getDebugLevel() == DEBUG_ALL)) error("zlibFile::open() inflateInit2 failed"); _stream.next_in = NULL; @@ -456,7 +458,7 @@ uint32 zlibFile::read(void *ptr, uint32 len) { bool fileEOF = false; if (!_handle->isOpen()) { - if (gDebugLevel == DEBUG_SMUSH || gDebugLevel == DEBUG_ERROR || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_SMUSH || Common::getDebugLevel() == DEBUG_ERROR || Common::getDebugLevel() == DEBUG_ALL) error("zlibFile::read() File is not open!"); return 0; } @@ -482,19 +484,19 @@ uint32 zlibFile::read(void *ptr, uint32 len) { if (result == Z_STREAM_END) { // EOF // "Stream end" is zlib's way of saying that it's done after the current call, // so as long as no calls are made after we've received this message we're OK - if (gDebugLevel == DEBUG_SMUSH || gDebugLevel == DEBUG_NORMAL || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_SMUSH || Common::getDebugLevel() == DEBUG_NORMAL || Common::getDebugLevel() == DEBUG_ALL) printf("zlibFile::read() Stream ended\n"); _fileDone = true; break; } if (result == Z_DATA_ERROR) { - if (gDebugLevel == DEBUG_SMUSH || gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_SMUSH || Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("zlibFile::read() Decompression error"); _fileDone = true; break; } if (result != Z_OK || fileEOF) { - if (gDebugLevel == DEBUG_SMUSH || gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + if (Common::getDebugLevel() == DEBUG_SMUSH || Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("zlibFile::read() Unknown decomp result: %d/%d", result, fileEOF); _fileDone = true; break; @@ -535,3 +537,4 @@ uint32 zlibFile::readUint32BE() { return (b << 16) | a; } +} // end of namespace Grim diff --git a/engines/grim/smush/smush.h b/engines/grim/smush/smush.h index 03b8b1044d3..b1502660634 100644 --- a/engines/grim/smush/smush.h +++ b/engines/grim/smush/smush.h @@ -37,6 +37,8 @@ #include "sound/mixer.h" #include "sound/audiostream.h" +namespace Grim { + struct SavePos { uint32 filePos; z_stream streamBuf; @@ -122,4 +124,6 @@ private: extern Smush *g_smush; +} // end of namespace Grim + #endif diff --git a/engines/grim/smush/vima.cpp b/engines/grim/smush/vima.cpp index 11bf1c1e6e7..61d4f5fdf3f 100644 --- a/engines/grim/smush/vima.cpp +++ b/engines/grim/smush/vima.cpp @@ -25,6 +25,8 @@ #include "common/endian.h" +namespace Grim { + static int16 imcTable1[] = { 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, @@ -196,3 +198,5 @@ void decompressVima(const byte *src, int16 *dest, int destLen, uint16 *destTable } } } + +} // end of namespace Grim diff --git a/engines/grim/textobject.cpp b/engines/grim/textobject.cpp index 8a218e63dbe..72c5bae303c 100644 --- a/engines/grim/textobject.cpp +++ b/engines/grim/textobject.cpp @@ -25,6 +25,8 @@ #include "engines/grim/textobject.h" +namespace Grim { + Common::String parseMsgText(const char *msg, char *msgId); TextObjectDefaults sayLineDefaults; @@ -247,9 +249,11 @@ void TextObject::draw() { x = 0; g_driver->drawTextBitmap(x, height + y, _textObjectHandle[i]); - } else if (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) + } else if (Common::getDebugLevel() == DEBUG_WARN || Common::getDebugLevel() == DEBUG_ALL) warning("TextObject::draw: Unknown justification code (%d)!", _justify); height += _font->getHeight(); } } + +} // end of namespace Grim diff --git a/engines/grim/textobject.h b/engines/grim/textobject.h index 6ec3301b6f3..f209147069c 100644 --- a/engines/grim/textobject.h +++ b/engines/grim/textobject.h @@ -29,6 +29,8 @@ #include "engines/grim/font.h" #include "engines/grim/gfx_base.h" +namespace Grim { + struct TextObjectDefaults { Color fgColor; int x, y; @@ -101,4 +103,6 @@ protected: GfxBase::TextObjectHandle **_textObjectHandle; }; +} // end of namespace Grim + #endif diff --git a/engines/grim/textsplit.cpp b/engines/grim/textsplit.cpp index abd5dccff8e..da05b931a07 100644 --- a/engines/grim/textsplit.cpp +++ b/engines/grim/textsplit.cpp @@ -27,6 +27,8 @@ #include "engines/grim/textsplit.h" +namespace Grim { + // FIXME: Replace this with a proper parser (this is just too dodgy :) int residual_vsscanf(const char *str, int field_count, const char *format, va_list ap) { unsigned int f01 = va_arg(ap, long); @@ -160,3 +162,5 @@ void TextSplitter::TextLines::setData(char *data, int length) { memcpy(_lineData, data, _lineLength); _lineData[_lineLength - 1] = 0; } + +} // end of namespace Grim diff --git a/engines/grim/textsplit.h b/engines/grim/textsplit.h index a30cc42877b..99a085e8fec 100644 --- a/engines/grim/textsplit.h +++ b/engines/grim/textsplit.h @@ -26,6 +26,8 @@ #ifndef TEXTSPLIT_HH #define TEXTSPLIT_HH +namespace Grim { + // A utility class to help in parsing the text-format files. Splits // the text data into lines, skipping comments, trailing whitespace, // and empty lines. Also folds everything to lowercase. @@ -80,4 +82,6 @@ private: void processLine(); }; +} // end of namespace Grim + #endif diff --git a/engines/grim/version.cpp b/engines/grim/version.cpp index 556de91636d..1f5fa62d3e0 100644 --- a/engines/grim/version.cpp +++ b/engines/grim/version.cpp @@ -21,6 +21,8 @@ #include "engines/grim/internal_version.h" #include "engines/grim/version.h" +namespace Grim { + const char *gResidualVersion = RESIDUAL_VERSION; const char *gResidualBuildDate = __DATE__ " " __TIME__; const char *gResidualVersionDate = RESIDUAL_VERSION " (" __DATE__ " " __TIME__ ")"; @@ -47,3 +49,4 @@ const char *gResidualFeatures = "" #endif ; +} // end of namespace Grim diff --git a/engines/grim/version.h b/engines/grim/version.h index 40f20604531..a2c6d4ee187 100644 --- a/engines/grim/version.h +++ b/engines/grim/version.h @@ -20,10 +20,14 @@ #ifndef BASE_VERSION_H #define BASE_VERSION_H +namespace Grim { + extern const char *gResidualVersion; // e.g. "0.0.6" extern const char *gResidualBuildDate; // e.g. "2008-06-15" extern const char *gResidualVersionDate; // e.g. "0.0.6 (2008-06-15)" extern const char *gResidualFullVersion; // e.g. "Residual 0.0.6 (2008-06-15)" extern const char *gResidualFeatures; // e.g. "ALSA MPEG2 zLib" +} // end of namespace Grim + #endif diff --git a/engines/grim/walkplane.cpp b/engines/grim/walkplane.cpp index b69ecd971f7..b28624bc946 100644 --- a/engines/grim/walkplane.cpp +++ b/engines/grim/walkplane.cpp @@ -28,6 +28,8 @@ #include "engines/grim/walkplane.h" #include "engines/grim/textsplit.h" +namespace Grim { + void Sector::load(TextSplitter &ts) { // float height = 12345.f; // Yaz: this is in the original code... char buf[256]; @@ -61,7 +63,7 @@ void Sector::load(TextSplitter &ts) { _type = 0x4000; else if (strstr(buf, "chernobyl")) _type = 0x8000; - else if (gDebugLevel == DEBUG_ERROR || gDebugLevel == DEBUG_ALL) + else if (Common::getDebugLevel() == DEBUG_ERROR || Common::getDebugLevel() == DEBUG_ALL) error("Unknown sector type '%s' in room setup", buf); ts.scanString(" default visibility %256s", 1, buf); @@ -122,7 +124,7 @@ bool Sector::isPointInSector(Vector3d point) const { } if (!heightOK) { /* Use this for debugging problems at height interfaces - if (gDebugLevel == DEBUG_NORMAL || gDebugLevel == DEBUG_ALL) { + if (Common::getDebugLevel() == DEBUG_NORMAL || Common::getDebugLevel() == DEBUG_ALL) { printf("Rejected trigger due to height: %s (%f)\n", _name.c_str(), _height); printf("Actor Z: %f\n", point.z()); for (int i = 0; i < _numVertices; i++) @@ -227,3 +229,5 @@ void Sector::getExitInfo(Vector3d start, Vector3d dir, Vector3d edgeNormal(result->edgeDir.y(), -result->edgeDir.x(), 0); result->exitPoint = start + (dot(_vertices[i] - start, edgeNormal) / dot(dir, edgeNormal)) * dir; } + +} // end of namespace Grim diff --git a/engines/grim/walkplane.h b/engines/grim/walkplane.h index 08b48e6f291..2d2f3fc71b1 100644 --- a/engines/grim/walkplane.h +++ b/engines/grim/walkplane.h @@ -30,6 +30,8 @@ #include "engines/grim/vector3d.h" +namespace Grim { + class TextSplitter; class Sector { @@ -75,4 +77,7 @@ private: Vector3d _normal; }; + +} // end of namespace Grim + #endif