diff options
author | Strangerke | 2011-09-09 18:24:11 +0200 |
---|---|---|
committer | Strangerke | 2011-09-09 18:24:11 +0200 |
commit | 4848683e56b1466a7dabbbecb7bb1bf7e4c857a7 (patch) | |
tree | 6807de0d4279f07cf8428db4c94e5aa38b1fdb82 | |
parent | 8dc4cb40d91477103086da729350ba847e13cb04 (diff) | |
download | scummvm-rg350-4848683e56b1466a7dabbbecb7bb1bf7e4c857a7.tar.gz scummvm-rg350-4848683e56b1466a7dabbbecb7bb1bf7e4c857a7.tar.bz2 scummvm-rg350-4848683e56b1466a7dabbbecb7bb1bf7e4c857a7.zip |
CGE: Remove some static variables from fileIO
-rw-r--r-- | engines/cge/bitmap.cpp | 2 | ||||
-rw-r--r-- | engines/cge/cge.cpp | 6 | ||||
-rw-r--r-- | engines/cge/cge_main.cpp | 13 | ||||
-rw-r--r-- | engines/cge/fileio.cpp | 56 | ||||
-rw-r--r-- | engines/cge/fileio.h | 20 | ||||
-rw-r--r-- | engines/cge/general.cpp | 9 | ||||
-rw-r--r-- | engines/cge/general.h | 2 | ||||
-rw-r--r-- | engines/cge/sound.cpp | 2 | ||||
-rw-r--r-- | engines/cge/text.cpp | 2 | ||||
-rw-r--r-- | engines/cge/vga13h.cpp | 2 |
10 files changed, 42 insertions, 72 deletions
diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index fee9eeeea1..cd440e08b4 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -49,7 +49,7 @@ Bitmap::Bitmap(const char *fname) : _m(NULL), _v(NULL), _map(0) { char pat[kMaxPath]; forceExt(pat, fname, ".VBM"); - if (VFile::exist(pat)) { + if (_cat->exist(pat)) { VFile file(pat); if ((file._error == 0) && (!loadVBM(&file))) error("Bad VBM [%s]", fname); diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 944413471b..d5d21726b1 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -79,12 +79,13 @@ void CGEEngine::init() { _miniShp = NULL; _miniShpList = NULL; _sprite = NULL; + _dat = new Dat(); + _cat = new BtFile(kCatName, XCrypt); // Create debugger console _console = new CGEConsole(this); // Initialise classes that have static members - VFile::init(); Bitmap::init(); Talk::init(); Cluster::init(this); @@ -143,7 +144,6 @@ void CGEEngine::deinit() { // Call classes with static members to clear them up Talk::deinit(); Bitmap::deinit(); - VFile::deinit(); Cluster::init(this); // Remove all of our debug levels here @@ -172,6 +172,8 @@ void CGEEngine::deinit() { delete _snail; delete _snail_; delete _hero; + delete _dat; + delete _cat; if (_miniShpList) { for (int i = 0; _miniShpList[i]; ++i) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index e3f0e610bd..f837788edf 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -72,6 +72,9 @@ Snail *_snail_; Fx *_fx; Sound *_sound; +Dat *_dat; +BtFile *_cat; + // 0.75 - 17II95 - full sound support // 0.76 - 18II95 - small MiniEMS in DEMO, // unhide CavLight in SNLEVEL @@ -1033,7 +1036,7 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int char line[kLineMax]; mergeExt(line, fname, kSprExt); - if (VFile::exist(line)) { // sprite description file exist + if (_cat->exist(line)) { // sprite description file exist VFile sprf(line); if (sprf._error) error("Bad SPR [%s]", line); @@ -1343,7 +1346,7 @@ void CGEEngine::runGame() { if (!_music) _midiPlayer.killMidi(); - if (VFile::exist("MINI.SPR")) { + if (_cat->exist("MINI.SPR")) { _miniShp = new BitmapPtr[2]; _miniShp[0] = _miniShp[1] = NULL; @@ -1361,7 +1364,7 @@ void CGEEngine::runGame() { if (_hero) { expandSprite(_hero); _hero->gotoxy(_heroXY[_now - 1].x, _heroXY[_now - 1].y); - if (VFile::exist("00SHADOW.SPR")) { + if (_cat->exist("00SHADOW.SPR")) { loadSprite("00SHADOW", -1, 0, _hero->_x + 14, _hero->_y + 51); delete _shadow; if ((_shadow = _sprite) != NULL) { @@ -1430,7 +1433,7 @@ void CGEEngine::movie(const char *ext) { char fn[12]; sprintf(fn, "CGE.%s", (*ext == '.') ? ext +1 : ext); - if (VFile::exist(fn)) { + if (_cat->exist(fn)) { loadScript(fn); expandSprite(_vga->_spareQ->locate(999)); feedSnail(_vga->_showQ->locate(999), kTake); @@ -1537,7 +1540,7 @@ void CGEEngine::cge_main() { if (!_mouse->_exist) error("%s", _text->getText(kTextNoMouse)); - if (!kSavegame0File::exist(kSavegame0Name)) + if (!_cat->exist(kSavegame0Name)) _mode = 2; _debugLine->_flags._hide = true; diff --git a/engines/cge/fileio.cpp b/engines/cge/fileio.cpp index 7fc981070d..30d291d16b 100644 --- a/engines/cge/fileio.cpp +++ b/engines/cge/fileio.cpp @@ -35,19 +35,6 @@ namespace CGE { -Dat *VFile::_dat = NULL; -BtFile *VFile::_cat = NULL; -VFile *VFile::_recent = NULL; - -uint16 XCrypt(void *buf, uint16 siz, uint16 seed) { - byte *b = static_cast<byte *>(buf); - - for (uint16 i = 0; i < siz; i++) - *b++ ^= seed; - - return seed; -} - /*----------------------------------------------------------------------- * IOHand *-----------------------------------------------------------------------*/ @@ -91,10 +78,6 @@ long IoHand::size() { return _file->size(); } -bool IoHand::exist(const char *name) { - return Common::File::exists(name); -} - /*----------------------------------------------------------------------- * IoBuf *-----------------------------------------------------------------------*/ @@ -215,10 +198,7 @@ int IoBuf::read() { /*----------------------------------------------------------------------- * CFile *-----------------------------------------------------------------------*/ -uint16 CFile::_maxLineLen = kLineMaxSize; - -CFile::CFile(const char *name, Crypt *crypt) - : IoBuf(name, crypt) { +CFile::CFile(const char *name, Crypt *crypt) : IoBuf(name, crypt) { debugC(1, kCGEDebugFile, "CFile::CFile(%s, crypt)", name); } @@ -344,6 +324,13 @@ BtKeypack *BtFile::find(const char *key) { return NULL; } +bool BtFile::exist(const char *name) { + debugC(1, kCGEDebugFile, "BtFile::exist(%s)", name); + + return scumm_stricmp(find(name)->_key, name) == 0; +} + + /*----------------------------------------------------------------------- * Dat *-----------------------------------------------------------------------*/ @@ -354,19 +341,6 @@ Dat::Dat(): _file(kDatName, XCrypt) { /*----------------------------------------------------------------------- * VFile *-----------------------------------------------------------------------*/ -void VFile::init() { - debugC(1, kCGEDebugFile, "VFile::init()"); - - _dat = new Dat(); - _cat = new BtFile(kCatName, XCrypt); - _recent = NULL; -} - -void VFile::deinit() { - delete _dat; - delete _cat; -} - VFile::VFile(const char *name) : IoBuf(NULL) { debugC(3, kCGEDebugFile, "VFile::VFile(%s)", name); @@ -379,23 +353,12 @@ VFile::VFile(const char *name) : IoBuf(NULL) { } VFile::~VFile() { - if (_recent == this) - _recent = NULL; -} - -bool VFile::exist(const char *name) { - debugC(1, kCGEDebugFile, "VFile::exist(%s)", name); - - return scumm_stricmp(_cat->find(name)->_key, name) == 0; } void VFile::readBuf() { debugC(3, kCGEDebugFile, "VFile::readBuf()"); - if (_recent != this) { - _dat->_file.seek(_bufMark + _lim); - _recent = this; - } + _dat->_file.seek(_bufMark + _lim); _bufMark = _dat->_file.mark(); long n = _endMark - _bufMark; if (n > kBufferSize) @@ -419,7 +382,6 @@ long VFile::size() { long VFile::seek(long pos) { debugC(1, kCGEDebugFile, "VFile::seek(%ld)", pos); - _recent = NULL; _lim = 0; return (_bufMark = _begMark + pos); } diff --git a/engines/cge/fileio.h b/engines/cge/fileio.h index dc9c74ecf9..6465c8e8f8 100644 --- a/engines/cge/fileio.h +++ b/engines/cge/fileio.h @@ -72,7 +72,6 @@ public: IoHand(const char *name, Crypt crypt); IoHand(Crypt *crypt); virtual ~IoHand(); - static bool exist(const char *name); uint16 read(void *buf, uint16 len); long mark(); long size(); @@ -98,7 +97,6 @@ public: class CFile : public IoBuf { public: - static uint16 _maxLineLen; CFile(const char *name, Crypt *crpt); virtual ~CFile(); long mark(); @@ -109,7 +107,7 @@ struct BtPage { Header _header; union { // dummy filler to make proper size of union - uint8 _data[kBtSize - 4 /*sizeof(Hea) */]; + uint8 _data[kBtSize - 4]; /* 4 is the size of struct Header */ // inner version of data: key + word-sized page link Inner _inner[kBtInnerCount]; // leaf version of data: key + all user data @@ -131,22 +129,17 @@ public: BtFile(const char *name, Crypt *crpt); virtual ~BtFile(); BtKeypack *find(const char *key); + bool exist(const char *name); }; class Dat { - friend class VFile; - CFile _file; public: Dat(); - bool read(long org, uint16 len, uint8 *buf); + CFile _file; }; class VFile : public IoBuf { private: - static Dat *_dat; - static BtFile *_cat; - static VFile *_recent; - long _begMark; long _endMark; @@ -155,15 +148,14 @@ public: VFile(const char *name); ~VFile(); - static void init(); - static void deinit(); - static bool exist(const char *name); - static const char *next(); long mark(); long size(); long seek(long pos); }; +extern Dat *_dat; +extern BtFile *_cat; + } // End of namespace CGE #endif diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index ec98db705e..c93cc1292b 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -31,6 +31,15 @@ namespace CGE { +uint16 XCrypt(void *buf, uint16 siz, uint16 seed) { + byte *b = static_cast<byte *>(buf); + + for (uint16 i = 0; i < siz; i++) + *b++ ^= seed; + + return seed; +} + char *mergeExt(char *buf, const char *name, const char *ext) { strcpy(buf, name); char *dot = strrchr(buf, '.'); diff --git a/engines/cge/general.h b/engines/cge/general.h index 8c0432b763..8f997c9ae2 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -47,11 +47,13 @@ struct Dac { typedef uint16 Crypt(void *buf, uint16 siz, uint16 seed); +uint16 XCrypt(void *buf, uint16 siz, uint16 seed); int takeEnum(const char **tab, const char *text); uint16 chkSum(void *m, uint16 n); char *mergeExt(char *buf, const char *name, const char *ext); char *forceExt(char *buf, const char *name, const char *ext); int newRandom(int range); + } // End of namespace CGE #endif diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index d8a9b7831e..a7b2d34b0b 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -215,7 +215,7 @@ void MusicPlayer::killMidi() { void MusicPlayer::loadMidi(int ref) { // Work out the filename and check the given MIDI file exists Common::String filename = Common::String::format("%.2d.MID", ref); - if (!VFile::exist(filename.c_str())) + if (!_cat->exist(filename.c_str())) return; // Stop any currently playing MIDI file diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 3d67dd9445..25af8eccfc 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -40,7 +40,7 @@ Talk *_talk = NULL; Text::Text(CGEEngine *vm, const char *fname, int size) : _vm(vm) { _cache = new Handler[size]; mergeExt(_fileName, fname, kSayExt); - if (!VFile::exist(_fileName)) + if (!_cat->exist(_fileName)) error("No talk (%s)\n", _fileName); for (_size = 0; _size < size; _size++) { diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index d4643a32e1..727cc72e39 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -226,7 +226,7 @@ Sprite *Sprite::expand() { Snail::Com *nea = NULL; Snail::Com *tak = NULL; mergeExt(fname, _file, kSprExt); - if (VFile::exist(fname)) { // sprite description file exist + if (_cat->exist(fname)) { // sprite description file exist VFile sprf(fname); if (!(sprf._error==0)) error("Bad SPR [%s]", fname); |