1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 #include "common/scummsys.h"
23 #include "common/config-manager.h"
24 #include "common/debug.h"
25 #include "common/debug-channels.h"
26 #include "common/error.h"
27 
28 #include "sludge/cursors.h"
29 #include "sludge/event.h"
30 #include "sludge/fonttext.h"
31 #include "sludge/floor.h"
32 #include "sludge/graphics.h"
33 #include "sludge/main_loop.h"
34 #include "sludge/newfatal.h"
35 #include "sludge/people.h"
36 #include "sludge/region.h"
37 #include "sludge/sludge.h"
38 #include "sludge/sound.h"
39 #include "sludge/speech.h"
40 
41 namespace Sludge {
42 
43 SludgeEngine *g_sludge;
44 
getScreenPixelFormat() const45 Graphics::PixelFormat *SludgeEngine::getScreenPixelFormat() const { return _pixelFormat; }
getOrigPixelFormat() const46 Graphics::PixelFormat *SludgeEngine::getOrigPixelFormat() const { return _origFormat; }
47 
SludgeEngine(OSystem * syst,const SludgeGameDescription * gameDesc)48 SludgeEngine::SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc) :
49 		Engine(syst), _gameDescription(gameDesc), _console(nullptr) {
50 
51 	// register your random source
52 	_rnd = new Common::RandomSource("sludge");
53 
54 	// Add debug channels
55 	DebugMan.addDebugChannel(kSludgeDebugFatal, "Script", "Script debug level");
56 	DebugMan.addDebugChannel(kSludgeDebugDataLoad, "Data Load", "Data loading debug level");
57 	DebugMan.addDebugChannel(kSludgeDebugStackMachine, "Stack Machine", "Stack Machine debug level");
58 	DebugMan.addDebugChannel(kSludgeDebugBuiltin, "Built-in", "Built-in debug level");
59 	DebugMan.addDebugChannel(kSludgeDebugGraphics, "Graphics", "Graphics debug level");
60 	DebugMan.addDebugChannel(kSludgeDebugZBuffer, "ZBuffer", "ZBuffer debug level");
61 	DebugMan.addDebugChannel(kSludgeDebugSound, "Sound", "Sound debug level");
62 
63 	DebugMan.enableDebugChannel("Data Load");
64 	DebugMan.enableDebugChannel("Built-in");
65 
66 	// init graphics
67 	_origFormat = new Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0);
68 	_pixelFormat = new Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0);
69 
70 	// Init Strings
71 	launchMe = "";
72 	launchNext = "";
73 	loadNow = "";
74 	gamePath = "";
75 
76 	// Init managers
77 	_fatalMan = new FatalMsgManager();
78 	_peopleMan = new PeopleManager(this);
79 	_resMan = new ResourceManager();
80 	_languageMan = new LanguageManager();
81 	_objMan = new ObjectManager(this);
82 	_gfxMan = new GraphicsManager(this);
83 	_evtMan = new EventManager(this);
84 	_soundMan = new SoundManager();
85 	_txtMan = new TextManager();
86 	_cursorMan = new CursorManager(this);
87 	_speechMan = new SpeechManager(this);
88 	_regionMan = new RegionManager(this);
89 	_floorMan = new FloorManager(this);
90 }
91 
~SludgeEngine()92 SludgeEngine::~SludgeEngine() {
93 
94 	// Dispose resources
95 	delete _rnd;
96 	_rnd = nullptr;
97 
98 	// Remove debug levels
99 	DebugMan.clearAllDebugChannels();
100 
101 	// Dispose console
102 	delete _console;
103 	_console = nullptr;
104 
105 	// Dispose pixel formats
106 	delete _origFormat;
107 	_origFormat = nullptr;
108 	delete _pixelFormat;
109 	_pixelFormat = nullptr;
110 
111 	// Dispose managers
112 	delete _cursorMan;
113 	_cursorMan = nullptr;
114 	delete _txtMan;
115 	_txtMan = nullptr;
116 	delete _soundMan;
117 	_soundMan = nullptr;
118 	delete _evtMan;
119 	_evtMan = nullptr;
120 	delete _gfxMan;
121 	_gfxMan = nullptr;
122 	delete _objMan;
123 	_objMan = nullptr;
124 	delete _languageMan;
125 	_languageMan = nullptr;
126 	delete _resMan;
127 	_resMan = nullptr;
128 	delete _speechMan;
129 	_speechMan = nullptr;
130 	delete _regionMan;
131 	_regionMan = nullptr;
132 	delete _peopleMan;
133 	_peopleMan = nullptr;
134 	delete _floorMan;
135 	_floorMan = nullptr;
136 	delete _fatalMan;
137 	_fatalMan = nullptr;
138 }
139 
run()140 Common::Error SludgeEngine::run() {
141 	// set global variable
142 	g_sludge = this;
143 
144 	// create console
145 	_console = new SludgeConsole(this);
146 
147 	// debug log
148 	main_loop(getGameFile());
149 
150 	return Common::kNoError;
151 }
152 
153 } // End of namespace Sludge
154 
155