diff options
author | Strangerke | 2011-07-30 15:43:49 +0200 |
---|---|---|
committer | Strangerke | 2011-07-30 15:43:49 +0200 |
commit | b53ffa8f2c31d27ac5a7b3fd48143102be6ff4ff (patch) | |
tree | 3ab435761eb439dd0381bc96eea429792f641852 | |
parent | 8b53899ca7d5ab1599f6bf3e1d4e49746876674b (diff) | |
download | scummvm-rg350-b53ffa8f2c31d27ac5a7b3fd48143102be6ff4ff.tar.gz scummvm-rg350-b53ffa8f2c31d27ac5a7b3fd48143102be6ff4ff.tar.bz2 scummvm-rg350-b53ffa8f2c31d27ac5a7b3fd48143102be6ff4ff.zip |
CGE: Move some conditional defines to variables
-rw-r--r-- | engines/cge/cge.cpp | 62 | ||||
-rw-r--r-- | engines/cge/cge.h | 19 | ||||
-rw-r--r-- | engines/cge/cge_main.cpp | 18 | ||||
-rw-r--r-- | engines/cge/cge_main.h | 12 | ||||
-rw-r--r-- | engines/cge/snail.h | 11 | ||||
-rw-r--r-- | engines/cge/walk.cpp | 6 |
6 files changed, 79 insertions, 49 deletions
diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 116bafcb64..8d2073b66f 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -56,6 +56,49 @@ CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) } +void CGEEngine::initCaveValues() { + if (_isDemo) { + _mini = new byte[16384]; + CAVE_DX = 23; + CAVE_DY = 29; + CAVE_NX = 3; + CAVE_NY = 1; + } else { + _mini = new byte[65536]; + CAVE_DX = 9; + CAVE_DY = 10; + CAVE_NX = 8; + CAVE_NY = 3; + } + CAVE_MAX = CAVE_NX * CAVE_NY; + + if (_isDemo) { + _maxCaveArr[0] = CAVE_MAX; + _maxCaveArr[1] = -1; + _maxCaveArr[2] = -1; + _maxCaveArr[3] = -1; + _maxCaveArr[4] = -1; + } else { + _maxCaveArr[0] = 1; + _maxCaveArr[1] = 8; + _maxCaveArr[2] = 16; + _maxCaveArr[3] = 23; + _maxCaveArr[4] = 24; + }; + + _heroXY = (Hxy *) malloc (sizeof(Hxy) * CAVE_MAX); + for (int i = 0; i < CAVE_MAX; i++) { + _heroXY[i]._x = 0; + _heroXY[i]._y = 0; + } + + _barriers = (Bar *) malloc (sizeof(Bar) * (1 + CAVE_MAX)); + for (int i = 0; i < CAVE_MAX + 1; i++) { + _barriers[i]._horz = 0xFF; + _barriers[i]._vert = 0xFF; + } +} + void CGEEngine::setup() { debugC(1, kCGEDebugEngine, "CGEEngine::setup()"); @@ -109,22 +152,8 @@ void CGEEngine::setup() { _volume[0] = 0; _volume[1] = 0; + initCaveValues(); - if (_isDemo) { - _mini = new byte[16384]; - _maxCaveArr[0] = CAVE_MAX; - _maxCaveArr[1] = -1; - _maxCaveArr[2] = -1; - _maxCaveArr[3] = -1; - _maxCaveArr[4] = -1; - } else { - _mini = new byte[65536]; - _maxCaveArr[0] = 1; - _maxCaveArr[1] = 8; - _maxCaveArr[2] = 16; - _maxCaveArr[3] = 23; - _maxCaveArr[4] = 24; - }; _maxCave = 0; _dark = false; _game = false; @@ -181,6 +210,9 @@ CGEEngine::~CGEEngine() { delete _snail_; delete _hero; delete[] _mini; + + free(_heroXY); + free(_barriers); } Common::Error CGEEngine::run() { diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 835c47cb6e..9d2503a5cf 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -78,6 +78,16 @@ struct SavegameHeader { extern const char *SAVEGAME_STR; #define SAVEGAME_STR_SIZE 11 +struct Bar { + uint8 _horz; + uint8 _vert; +}; + +struct Hxy { + int _x; + int _y; +}; + class CGEEngine : public Engine { private: uint32 _lastFrame, _lastTick; @@ -123,6 +133,14 @@ public: Sprite *_sprK2; Sprite *_sprK3; + uint8 CAVE_DX; + uint8 CAVE_DY; + uint8 CAVE_NX; + uint8 CAVE_NY; + uint16 CAVE_MAX; + Hxy *_heroXY; + Bar *_barriers; + Common::RandomSource _randomSource; byte * _mini; BMP_PTR * _miniShp; @@ -200,6 +218,7 @@ public: void AltCtrlDel(); void postMiniStep(int stp); void showBak(int ref); + void initCaveValues(); void snBackPt(Sprite *spr, int stp); void snBarrier(int cav, int bar, bool horz); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index dc573b8b2f..123501047a 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -99,9 +99,6 @@ static bool _finis = false; int _offUseCount; uint16 *_intStackPtr = false; -Hxy _heroXY[CAVE_MAX] = {{0, 0}}; -Bar _barriers[1 + CAVE_MAX] = { { 0xFF, 0xFF } }; - extern Dac _stdPal[58]; void CGEEngine::syncHeader(Common::Serializer &s) { @@ -120,6 +117,13 @@ void CGEEngine::syncHeader(Common::Serializer &s) { for (i = 0; i < 4; ++i) s.syncAsUint16LE(_flag[i]); + initCaveValues(); + if (s.isLoading()) { + //TODO: Fix the memory leak when the game is already running + _heroXY = (Hxy *) malloc (sizeof(Hxy) * CAVE_MAX); + _barriers = (Bar *) malloc (sizeof(Bar) * (1 + CAVE_MAX)); + } + for (i = 0; i < CAVE_MAX; ++i) { s.syncAsSint16LE(_heroXY[i]._x); s.syncAsUint16LE(_heroXY[i]._y); @@ -145,7 +149,7 @@ void CGEEngine::syncHeader(Common::Serializer &s) { } bool CGEEngine::loadGame(int slotNumber, SavegameHeader *header, bool tiny) { - debugC(1, kCGEDebugEngine, "CGEEngine::loadgame(file, %s)", tiny ? "true" : "false"); + debugC(1, kCGEDebugEngine, "CGEEngine::loadgame(%d, header, %s)", slotNumber, tiny ? "true" : "false"); Common::MemoryReadStream *readStream; SavegameHeader saveHeader; @@ -833,9 +837,9 @@ void System::touch(uint16 mask, int x, int y) { _infoLine->update(NULL); if (y >= kWorldHeight ) { if (x < kButtonX) { // select cave? - if (y >= CAVE_Y && y < CAVE_Y + CAVE_NY * CAVE_DY && - x >= CAVE_X && x < CAVE_X + CAVE_NX * CAVE_DX && !_vm->_game) { - cav = ((y - CAVE_Y) / CAVE_DY) * CAVE_NX + (x - CAVE_X) / CAVE_DX + 1; + if (y >= CAVE_Y && y < CAVE_Y + _vm->CAVE_NY * _vm->CAVE_DY && + x >= CAVE_X && x < CAVE_X + _vm->CAVE_NX * _vm->CAVE_DX && !_vm->_game) { + cav = ((y - CAVE_Y) / _vm->CAVE_DY) * _vm->CAVE_NX + (x - CAVE_X) / _vm->CAVE_DX + 1; if (cav > _vm->_maxCave) cav = 0; } else { diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index d811236485..e3d8d40846 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -39,18 +39,6 @@ namespace CGE { #define CAVE_SX 0 #define CAVE_SY 0 -#ifdef DEMO -#define CAVE_DX 23 -#define CAVE_DY 29 -#define CAVE_NX 3 -#define CAVE_NY 1 -#else -#define CAVE_DX 9 -#define CAVE_DY 10 -#define CAVE_NX 8 -#define CAVE_NY 3 -#endif -#define CAVE_MAX (CAVE_NX * CAVE_NY) #define PAIN (_vm->_flag[0]) #define kInfoX 177 diff --git a/engines/cge/snail.h b/engines/cge/snail.h index ad63f55f36..2b488cd5b2 100644 --- a/engines/cge/snail.h +++ b/engines/cge/snail.h @@ -37,11 +37,6 @@ namespace CGE { #define kSnailFrameDelay (1000 / kSnailFrameRate) #define kDressed 3 -struct Bar { - uint8 _horz; - uint8 _vert; -}; - enum SnCom { kSnLabel, kSnPause, kSnWait, kSnLevel, kSnHide, kSnSay, kSnInf, kSnTime, kSnCave, kSnKill, @@ -86,12 +81,6 @@ private: }; -extern Bar _barriers[]; -extern struct Hxy { - int _x; - int _y; -} _heroXY[]; - } // End of namespace CGE #endif diff --git a/engines/cge/walk.cpp b/engines/cge/walk.cpp index 9bcc2be23d..e2c62513dd 100644 --- a/engines/cge/walk.cpp +++ b/engines/cge/walk.cpp @@ -30,8 +30,6 @@ namespace CGE { -extern Bar _barriers[]; - Walk *_hero; uint8 Cluster::_map[MAP_ZCNT][MAP_XCNT]; @@ -50,8 +48,8 @@ bool Cluster::isValid() const { } bool Cluster::chkBar() const { - assert(_vm->_now <= CAVE_MAX); - return (_a == _barriers[_vm->_now]._horz) && (_b == _barriers[_vm->_now]._vert); + assert(_vm->_now <= _vm->CAVE_MAX); + return (_a == _vm->_barriers[_vm->_now]._horz) && (_b == _vm->_barriers[_vm->_now]._vert); } Cluster XZ(int x, int y) { |