scummvm/engines/cge/cge.cpp

221 lines
5.4 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/walk.h"
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-09-14 08:15:30 +02:00
const int CGEEngine::_maxSceneArr[5] = {1, 8, 16, 23, 24};
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-07-20 14:22:56 +02:00
DebugMan.addDebugChannel(kCGEDebugBitmap, "bitmap", "CGE Bitmap debug channel");
DebugMan.addDebugChannel(kCGEDebugFile, "file", "CGE IO debug channel");
DebugMan.addDebugChannel(kCGEDebugEngine, "engine", "CGE Engine debug channel");
_startupMode = 1;
_demoText = kDemo;
_oldLev = 0;
_pocPtr = 0;
_bitmapPalette = NULL;
_quitFlag = false;
_showBoundariesFl = false;
}
2011-09-14 08:15:30 +02:00
void CGEEngine::initSceneValues() {
for (int i = 0; i < kSceneMax; i++) {
2011-09-06 23:14:49 +02:00
_heroXY[i].x = 0;
_heroXY[i].y = 0;
}
2011-09-14 08:15:30 +02:00
for (int i = 0; i < kSceneMax + 1; i++) {
_barriers[i]._horz = 0xFF;
_barriers[i]._vert = 0xFF;
}
}
void CGEEngine::init() {
2011-07-20 14:22:56 +02:00
debugC(1, kCGEDebugEngine, "CGEEngine::setup()");
2011-07-18 18:05:57 +02:00
// Initialise fields
_lastFrame = 0;
_lastTick = 0;
_hero = NULL;
_shadow = NULL;
2011-09-14 08:15:30 +02:00
_miniScene = NULL;
_miniShp = NULL;
_miniShpList = NULL;
_sprite = NULL;
2011-09-14 00:10:59 +02:00
_resman = new ResourceManager();
// Create debugger console
2011-06-13 11:57:24 +02:00
_console = new CGEConsole(this);
// Initialise engine objects
_font = new Font(this, "CGE");
_text = new Text(this, "CGE");
2011-09-17 17:27:05 +02:00
_talk = NULL;
_vga = new Vga(this);
_sys = new System(this);
_pocLight = new PocLight(this);
2011-08-06 22:14:23 +10:00
for (int i = 0; i < kPocketNX; i++)
_pocket[i] = NULL;
_horzLine = new HorizLine(this);
_infoLine = new InfoLine(this, kInfoW);
2011-09-14 08:15:30 +02:00
_sceneLight = new SceneLight(this);
_debugLine = new InfoLine(this, kScrWidth);
_commandHandler = new CommandHandler(this, false);
_commandHandlerTurbo = new CommandHandler(this, true);
_midiPlayer = new MusicPlayer(this);
2011-07-08 08:21:35 +02:00
_mouse = new Mouse(this);
_keyboard = new Keyboard(this);
_eventManager = new EventManager(this);
_fx = new Fx(this, 16); // must precede SOUND!!
_sound = new Sound(this);
_offUseCount = atoi(_text->getText(kOffUseCount));
_music = true;
for (int i = 0; i < kPocketNX; i++)
_pocref[i] = -1;
_volume[0] = 0;
_volume[1] = 0;
2011-09-14 08:15:30 +02:00
initSceneValues();
2011-07-25 19:09:12 +02:00
2011-09-14 08:15:30 +02:00
_maxScene = 0;
2011-07-18 23:14:22 +02:00
_dark = false;
_game = false;
_finis = false;
2011-07-18 23:14:22 +02:00
_now = 1;
_lev = -1;
_recentStep = -2;
for (int i = 0; i < 4; i++)
_flag[i] = false;
_mode = 0;
_soundOk = 1;
_sprTv = NULL;
_gameCase2Cpt = 0;
_offUseCount = 0;
_startGameSlot = ConfMan.hasKey("save_slot") ? ConfMan.getInt("save_slot") : -1;
2011-06-08 00:01:44 +02:00
}
2011-06-13 11:57:24 +02:00
void CGEEngine::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 _vga;
delete _sys;
delete _sprite;
2011-09-14 08:15:30 +02:00
delete _miniScene;
delete _shadow;
delete _horzLine;
2011-07-03 11:28:22 +02:00
delete _infoLine;
2011-09-14 08:15:30 +02:00
delete _sceneLight;
2011-07-03 11:28:22 +02:00
delete _debugLine;
delete _text;
delete _pocLight;
delete _keyboard;
delete _mouse;
delete _eventManager;
delete _sound;
delete _fx;
delete _midiPlayer;
delete _font;
delete _commandHandler;
delete _commandHandlerTurbo;
2011-07-03 16:22:26 +02:00
delete _hero;
2011-09-14 00:10:59 +02:00
delete _resman;
if (_miniShpList) {
for (int i = 0; _miniShpList[i]; ++i)
delete _miniShpList[i];
delete[] _miniShpList;
}
2011-06-08 00:01:44 +02:00
}
2011-06-13 11:57:24 +02:00
CGEEngine::~CGEEngine() {
debugC(1, kCGEDebugEngine, "CGEEngine::~CGEEngine()");
}
2011-06-08 00:01:44 +02:00
Common::Error CGEEngine::run() {
2011-07-20 14:22:56 +02:00
debugC(1, kCGEDebugEngine, "CGEEngine::run()");
2011-07-18 18:05:57 +02:00
if (_gameDescription->flags & ADGF_DEMO) {
warning("Demos of Soltys are not supported.\nPlease get a free version on ScummVM download page");
return Common::kUnsupportedGameidError;
}
2011-06-08 00:01:44 +02:00
// Initialize graphics using following:
initGraphics(320, 200, false);
2011-06-13 11:57:24 +02:00
// Setup necessary game objects
init();
// Run the game
cge_main();
2011-06-13 11:57:24 +02:00
// Remove game objects
deinit();
2011-06-08 00:01:44 +02:00
return Common::kNoError;
}
2011-06-13 11:57:24 +02:00
bool CGEEngine::hasFeature(EngineFeature f) const {
return
(f == kSupportsRTL) ||
(f == kSupportsLoadingDuringRuntime) ||
(f == kSupportsSavingDuringRuntime);
}
bool CGEEngine::canLoadGameStateCurrently() {
return (_startupMode == 0) && _mouse->_active;
}
bool CGEEngine::canSaveGameStateCurrently() {
return (_startupMode == 0) && _mouse->_active &&
_commandHandler->idle() && !_hero->_flags._hide;
}
2011-06-08 00:01:44 +02:00
} // End of namespace CGE