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 * Additional copyright for this file: 8 * Copyright (C) 1994-1998 Revolution Software Ltd. 9 * 10 * This program is free software; you can redistribute it and/or 11 * modify it under the terms of the GNU General Public License 12 * as published by the Free Software Foundation; either version 2 13 * of the License, or (at your option) any later version. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with this program; if not, write to the Free Software 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 23 */ 24 25 #ifndef SWORD2_SWORD2_H 26 #define SWORD2_SWORD2_H 27 28 #define FRAMES_PER_SECOND 12 29 30 // Enable this to make it possible to clear the mouse cursor luggage by 31 // right-clicking. The original didn't do this, but it feels natural to me. 32 // However, I'm afraid that it'll interfer badly with parts of the game, so 33 // for now I'll keep it disabled. 34 35 #define RIGHT_CLICK_CLEARS_LUGGAGE 0 36 37 #include "engines/engine.h" 38 39 #include "common/events.h" 40 #include "common/util.h" 41 #include "common/random.h" 42 #include "sword2/detection.h" 43 44 #define MAX_starts 100 45 #define MAX_description 100 46 47 class OSystem; 48 49 /** 50 * This is the namespace of the Sword2 engine. 51 * 52 * Status of this engine: ??? 53 * 54 * Games using this engine: 55 * - Broken Sword II: The Smoking Mirror 56 */ 57 namespace Sword2 { 58 59 class MemoryManager; 60 class ResourceManager; 61 class Sound; 62 class Screen; 63 class Mouse; 64 class Logic; 65 class FontRenderer; 66 class Gui; 67 class Debugger; 68 69 enum { 70 RD_LEFTBUTTONDOWN = 0x01, 71 RD_LEFTBUTTONUP = 0x02, 72 RD_RIGHTBUTTONDOWN = 0x04, 73 RD_RIGHTBUTTONUP = 0x08, 74 RD_WHEELUP = 0x10, 75 RD_WHEELDOWN = 0x20, 76 RD_KEYDOWN = 0x40 77 }; 78 79 struct MouseEvent { 80 bool pending; 81 uint16 buttons; 82 }; 83 84 struct KeyboardEvent { 85 bool pending; 86 Common::KeyState kbd; 87 }; 88 89 struct StartUp { 90 char description[MAX_description]; 91 92 // id of screen manager object 93 uint32 start_res_id; 94 95 // Tell the manager which startup you want (if there are more than 1) 96 // (i.e more than 1 entrance to a screen and/or separate game boots) 97 uint32 key; 98 }; 99 100 class Sword2Engine : public Engine { 101 private: 102 uint32 _inputEventFilter; 103 104 // The event "buffers" 105 MouseEvent _mouseEvent; 106 KeyboardEvent _keyboardEvent; 107 108 uint32 _bootParam; 109 int32 _saveSlot; 110 111 void getPlayerStructures(); 112 void putPlayerStructures(); 113 114 uint32 saveData(uint16 slotNo, byte *buffer, uint32 bufferSize); 115 uint32 restoreData(uint16 slotNo, byte *buffer, uint32 bufferSize); 116 117 uint32 calcChecksum(byte *buffer, uint32 size); 118 119 uint32 _totalStartups; 120 uint32 _totalScreenManagers; 121 uint32 _startRes; 122 123 bool _useSubtitles; 124 int _gameSpeed; 125 126 // Used to trigger GMM Loading 127 int _gmmLoadSlot; 128 129 StartUp _startList[MAX_starts]; 130 131 // We need these to fetch data from SCREENS.CLU, which is 132 // a resource file with custom format keeping background and 133 // parallax data (which is removed from multiscreen files). 134 byte *fetchPsxBackground(uint32 location); 135 byte *fetchPsxParallax(uint32 location, uint8 level); // level: 0 -> bg, 1 -> fg 136 137 // Original game platform (PC/PSX) 138 static Common::Platform _platform; 139 140 PauseToken _gamePauseToken; 141 142 protected: 143 // Engine APIs 144 Common::Error run() override; 145 bool hasFeature(EngineFeature f) const override; 146 void syncSoundSettings() override; 147 void pauseEngineIntern(bool pause) override; 148 149 public: 150 Sword2Engine(OSystem *syst); 151 ~Sword2Engine() override; 152 153 int getFramesPerSecond(); 154 155 void registerDefaultSettings(); 156 void readSettings(); 157 void writeSettings(); 158 159 void setupPersistentResources(); 160 getSubtitles()161 bool getSubtitles() { return _useSubtitles; } setSubtitles(bool b)162 void setSubtitles(bool b) { _useSubtitles = b; } 163 164 // GMM Loading/Saving 165 Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override; 166 bool canSaveGameStateCurrently() override; 167 Common::Error loadGameState(int slot) override; 168 bool canLoadGameStateCurrently() override; 169 170 uint32 _features; 171 172 MemoryManager *_memory; 173 ResourceManager *_resman; 174 Sound *_sound; 175 Screen *_screen; 176 Mouse *_mouse; 177 Logic *_logic; 178 FontRenderer *_fontRenderer; 179 180 Debugger *_debugger; 181 182 Common::RandomSource _rnd; 183 184 uint32 _speechFontId; 185 uint32 _controlsFontId; 186 uint32 _redFontId; 187 188 uint32 setInputEventFilter(uint32 filter); 189 190 void parseInputEvents(); 191 192 bool checkForMouseEvents(); 193 MouseEvent *mouseEvent(); 194 KeyboardEvent *keyboardEvent(); 195 196 bool _wantSfxDebug; 197 198 int32 _gameCycle; 199 200 #if RIGHT_CLICK_CLEARS_LUGGAGE 201 bool heldIsInInventory(); 202 #endif 203 204 void fetchPalette(byte *screenFile, byte *palBuffer); 205 byte *fetchScreenHeader(byte *screenFile); 206 byte *fetchLayerHeader(byte *screenFile, uint16 layerNo); 207 byte *fetchShadingMask(byte *screenFile); 208 209 byte *fetchAnimHeader(byte *animFile); 210 byte *fetchCdtEntry(byte *animFile, uint16 frameNo); 211 byte *fetchFrameHeader(byte *animFile, uint16 frameNo); 212 byte *fetchBackgroundParallaxLayer(byte *screenFile, int layer); 213 byte *fetchBackgroundLayer(byte *screenFile); 214 byte *fetchForegroundParallaxLayer(byte *screenFile, int layer); 215 byte *fetchTextLine(byte *file, uint32 text_line); 216 bool checkTextLine(byte *file, uint32 text_line); 217 byte *fetchPaletteMatchTable(byte *screenFile); 218 219 uint32 saveGame(uint16 slotNo, const byte *description); 220 uint32 restoreGame(uint16 slotNo); 221 uint32 getSaveDescription(uint16 slotNo, byte *description); 222 bool saveExists(); 223 bool saveExists(uint16 slotNo); 224 uint32 restoreFromBuffer(byte *buffer, uint32 size); 225 virtual Common::String getSaveStateName(int slot) const override; 226 uint32 findBufferSize(); 227 228 void startGame(); 229 void gameCycle(); 230 void restartGame(); 231 232 void sleepUntil(uint32 time); 233 234 void initializeFontResourceFlags(); 235 void initializeFontResourceFlags(uint8 language); 236 237 bool initStartMenu(); 238 void registerStartPoint(int32 key, char *name); 239 getNumStarts()240 uint32 getNumStarts() { return _totalStartups; } getNumScreenManagers()241 uint32 getNumScreenManagers() { return _totalScreenManagers; } getStartList()242 StartUp *getStartList() { return _startList; } 243 244 void runStart(int start); 245 246 // Convenience alias for OSystem::getMillis(). 247 // This is a bit hackish, of course :-). 248 uint32 getMillis(); 249 250 //Used to check wether we are running PSX version isPsx()251 static bool isPsx() { return _platform == Common::kPlatformPSX; } 252 }; 253 254 } // End of namespace Sword2 255 256 #endif 257