scummvm/engines/cge/cge.cpp

257 lines
6.3 KiB
C++
Raw Normal View History

2011-06-08 00:01:44 +02:00
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "common/scummsys.h"
#include "common/config-manager.h"
#include "common/debug.h"
#include "common/debug-channels.h"
#include "common/error.h"
#include "common/EventRecorder.h"
#include "common/file.h"
#include "common/fs.h"
#include "engines/util.h"
#include "cge/cge.h"
2011-06-20 23:40:22 +02:00
#include "cge/vga13h.h"
#include "cge/cge_main.h"
#include "cge/talk.h"
#include "cge/text.h"
#include "cge/vol.h"
2011-06-20 23:40:22 +02:00
2011-06-13 11:57:24 +02:00
2011-06-08 00:01:44 +02:00
namespace CGE {
2011-06-13 11:57:24 +02:00
2011-06-08 00:01:44 +02:00
CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription)
2011-07-05 20:51:29 +10:00
: Engine(syst), _gameDescription(gameDescription), _randomSource("cge") {
2011-06-13 11:57:24 +02:00
// Debug/console setup
2011-06-08 00:01:44 +02:00
DebugMan.addDebugChannel(kCGEDebug, "general", "CGE general debug channel");
_isDemo = _gameDescription->flags & ADGF_DEMO;
_startupMode = 1;
_demoText = DEMO_TEXT;
_oldLev = 0;
_jbw = false;
_pocPtr = 0;
}
void CGEEngine::setup() {
// Initialise fields
_lastFrame = 0;
_hero = NULL;
// Create debugger console
2011-06-13 11:57:24 +02:00
_console = new CGEConsole(this);
// Initialise classes that have static members
2011-07-03 16:22:26 +02:00
Vga::init();
VFile::init();
2011-06-29 16:13:17 +02:00
Bitmap::init();
2011-07-03 11:28:22 +02:00
Talk::init();
// Initialise sprite arrays used by game objects
2011-06-30 08:30:23 +02:00
MB[0] = new Bitmap("BRICK", true);
MB[1] = NULL;
2011-06-30 08:30:23 +02:00
HL[0] = new Bitmap("HLINE", true);
HL[1] = NULL;
2011-06-30 08:30:23 +02:00
MC[0] = new Bitmap("MOUSE", true);
MC[1] = new Bitmap("DUMMY", true);
MC[2] = NULL;
2011-06-30 08:30:23 +02:00
PR[0] = new Bitmap("PRESS", true);
PR[1] = NULL;
2011-06-30 08:30:23 +02:00
SP[0] = new Bitmap("SPK_L", true);
SP[1] = new Bitmap("SPK_R", true);
SP[2] = NULL;
2011-06-30 08:30:23 +02:00
LI[0] = new Bitmap("LITE0", true);
LI[1] = new Bitmap("LITE1", true);
LI[2] = new Bitmap("LITE2", true);
LI[3] = new Bitmap("LITE3", true);
LI[4] = NULL;
// Initialise engine objects
_text = new Text(this, progName(), 128);
_vga = new Vga(M13H);
_heart = new Heart;
_sys = new System(this);
_pocLight = new Sprite(this, LI);
for (int i = 0; i < POCKET_NX; i++)
_pocket[i] = new Sprite(this, NULL);
_sprite = new Sprite(this, NULL);
_miniCave = new Sprite(this, NULL);
_shadow = new Sprite(this, NULL);
_horzLine = new Sprite(this, HL);
_infoLine = new InfoLine(this, INFO_W);
_cavLight = new Sprite(this, PR);
_debugLine = new InfoLine(this, SCR_WID);
2011-07-02 18:20:41 +02:00
_snail = new Snail(this, false);
_snail_ = new Snail(this, true);
_mouse = new MOUSE(this);
_keyboard = new Keyboard();
_eventManager = new EventManager();
2011-07-03 11:28:22 +02:00
_offUseCount = atoi(_text->getText(OFF_USE_COUNT));
_music = true;
for (int i = 0; i < POCKET_NX; i++)
_pocref[i] = -1;
_volume[0] = 0;
_volume[1] = 0;
_savTab[0]._ptr = &_now;
_savTab[0]._len = sizeof(_now);
_savTab[0]._flag = true;
_savTab[1]._ptr = &_oldLev;
_savTab[1]._len = sizeof(_oldLev);
_savTab[1]._flag = true;
_savTab[2]._ptr = &_demoText;
_savTab[2]._len = sizeof(_demoText);
_savTab[2]._flag = true;
_savTab[3]._ptr = &_game;
_savTab[3]._len = sizeof(_game);
_savTab[3]._flag = true;
_savTab[4]._ptr = &_game;
_savTab[4]._len = sizeof(_game);
_savTab[4]._flag = true;
_savTab[5]._ptr = &_game;
_savTab[5]._len = sizeof(_game);
_savTab[5]._flag = true;
_savTab[6]._ptr = &_game;
_savTab[6]._len = sizeof(_game);
_savTab[6]._flag = true;
_savTab[7]._ptr = &_game;
_savTab[7]._len = sizeof(_game);
_savTab[7]._flag = true;
_savTab[8]._ptr = &_vga->_mono;
_savTab[8]._len = sizeof(_vga->_mono);
_savTab[8]._flag = false;
_savTab[9]._ptr = &_music;
_savTab[9]._len = sizeof(_music);
_savTab[9]._flag = true;
_savTab[10]._ptr = _volume;
_savTab[10]._len = sizeof(_volume);
_savTab[10]._flag = true;
_savTab[11]._ptr = _flag;
_savTab[11]._len = sizeof(_flag);
_savTab[11]._flag = true;
_savTab[12]._ptr = _heroXY;
// _savTab[12]._len = sizeof(_heroXY); FIXME: illegal sizeof
_savTab[12]._len = 0;
_savTab[12]._flag = true;
_savTab[13]._ptr = _barriers;
// _savTab[13]._len = sizeof(_barriers); FIXME: illegal sizeof
_savTab[13]._len = 0;
_savTab[13]._flag = true;
_savTab[14]._ptr = _pocref;
_savTab[14]._len = sizeof(_pocref);
_savTab[14]._flag = true;
_savTab[15]._ptr = NULL;
_savTab[15]._len = 0;
_savTab[15]._flag = false;
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;
};
_maxCave = 0;
_dark = false;
_game = false;
_now = 1;
_lev = -1;
for (int i = 0; i < 4; i++)
_flag[i] = false;
2011-06-08 00:01:44 +02:00
}
2011-06-13 11:57:24 +02:00
2011-06-08 00:01:44 +02:00
CGEEngine::~CGEEngine() {
debug("CGEEngine::~CGEEngine");
2011-06-13 11:57:24 +02:00
// Call classes with static members to clear them up
2011-07-03 11:28:22 +02:00
Talk::deinit();
2011-06-29 16:13:17 +02:00
Bitmap::deinit();
2011-07-03 16:22:26 +02:00
VFile::deinit();
Vga::deinit();
2011-06-08 00:01:44 +02:00
// Remove all of our debug levels here
DebugMan.clearAllDebugChannels();
2011-07-03 17:14:47 +10:00
delete _console;
// Delete engine objects
delete _sprite;
delete _miniCave;
delete _shadow;
delete _horzLine;
2011-07-03 11:28:22 +02:00
delete _infoLine;
delete _cavLight;
2011-07-03 11:28:22 +02:00
delete _debugLine;
delete MB[0];
delete HL[0];
delete MC[0];
delete MC[1];
delete PR[0];
delete SP[0];
delete SP[1];
delete LI[0];
delete LI[1];
delete LI[2];
delete LI[3];
2011-07-03 11:28:22 +02:00
delete _text;
delete _heart;
delete _pocLight;
delete _keyboard;
delete _mouse;
for (int i = 0; i < POCKET_NX; i++)
delete _pocket[i];
2011-07-02 18:20:41 +02:00
delete _snail;
delete _snail_;
2011-07-03 16:22:26 +02:00
delete _hero;
delete _vga;
delete _sys;
2011-06-08 00:01:44 +02:00
}
2011-06-13 11:57:24 +02:00
2011-06-08 00:01:44 +02:00
Common::Error CGEEngine::run() {
// Initialize graphics using following:
initGraphics(320, 200, false);
2011-06-13 11:57:24 +02:00
// Setup necessary game objects
setup();
2011-06-13 11:57:24 +02:00
2011-06-08 00:01:44 +02:00
// Additional setup.
debug("CGEEngine::init");
2011-06-13 11:57:24 +02:00
cge_main();
2011-06-13 11:57:24 +02:00
2011-06-08 00:01:44 +02:00
return Common::kNoError;
}
2011-06-13 11:57:24 +02:00
2011-06-08 00:01:44 +02:00
} // End of namespace CGE