ScummVM API documentation
sword1.h
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 modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (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, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef SWORD1_SWORD1_H
23#define SWORD1_SWORD1_H
24
25#include "engines/engine.h"
26#include "common/error.h"
27#include "common/keyboard.h"
28#include "common/rect.h"
29#include "common/util.h"
30#include "common/events.h"
31#include "sword1/sworddefs.h"
32#include "sword1/console.h"
33
35
45namespace Sword1 {
46
47enum SWORD1Action {
48 kActionNone,
49 kActionPause,
50 kActionQuit,
51 kActionMainPanel,
52 kActionEscape
53};
54
55enum ControlPanelMode {
56 CP_NORMAL = 0,
57 CP_DEATHSCREEN,
58 CP_THEEND,
59 CP_NEWGAME
60};
61
62class Screen;
63class Sound;
64class Logic;
65class Mouse;
66class ResMan;
67class ObjectMan;
68class Menu;
69class Control;
70
71struct SystemVars {
72 bool runningFromCd;
73 uint32 currentCD; // starts at zero, then either 1 or 2 depending on section being played
74 uint32 justRestoredGame; // see main() in sword.c & New_screen() in gtm_core.c
75 uint8 controlPanelMode; // 1 death screen version of the control panel, 2 = successful end of game, 3 = force restart
76 uint8 saveGameFlag;
77 int snrStatus;
78 bool wantFade; // when true => fade during scene change, else cut.
79 bool playSpeech;
80 bool textRunning;
81 uint32 speechRunning;
82 bool speechFinished;
83 bool showText;
84 int32 textNumber;
85 uint8 language;
86 bool isDemo;
87 bool isSpanishDemo;
88 Common::Platform platform;
89 Common::Language realLanguage;
90 bool isLangRtl;
91 bool debugMode;
92 bool slowMode;
93 bool fastMode;
94 bool parallaxOn;
95 bool gamePaused;
96 bool displayDebugText;
97 bool displayDebugMouse;
98 bool displayDebugGrid;
99 uint32 framesPerSecondCounter;
100 uint32 gameCycle;
101 bool useWindowsAudioMode; // DOS and Windows use different implementations of the audio driver, each with their own behavior
102};
103
104class SwordEngine : public Engine {
105 friend class SwordConsole;
106 friend class Screen;
107 friend class Control;
108
109public:
110 SwordEngine(OSystem *syst, const ADGameDescription *gameDesc);
111 ~SwordEngine() override;
112 static SystemVars _systemVars;
113 void reinitialize();
114
115 uint32 _features;
116
117 int _inTimer = -1; // Is the timer running?
118 int32 _vbl60HzUSecElapsed = 0; // 60 Hz counter for palette fades
119 int _vblCount = 0; // How many vblCallback calls have been made?
120 int _rate = DEFAULT_FRAME_TIME / 10;
121 int _targetFrameTime = DEFAULT_FRAME_TIME;
122 uint32 _mainLoopFrameCount = 0;
123 uint32 _ticker = 0; // For the frame time shown within the debug text
124
125 bool mouseIsActive();
126
127 static bool isMac() { return _systemVars.platform == Common::kPlatformMacintosh; }
128 static bool isPsx() { return _systemVars.platform == Common::kPlatformPSX; }
129 static bool isWindows() { return _systemVars.platform == Common::kPlatformWindows ; }
130
131 // Used by timer
132 void updateTopMenu();
133 void updateBottomMenu();
134 void fadePaletteStep();
135 void startFadePaletteDown(int speed);
136 void startFadePaletteUp(int speed);
137 void waitForFade();
138 bool screenIsFading();
139 bool fadeDirectionIsUp();
140 void setMenuToTargetState();
141
142 void showDebugInfo();
143
144protected:
145 // Engine APIs
146 Common::Error init();
147 Common::Error go();
148 Common::Error run() override {
149 Common::Error err;
150 err = init();
151 if (err.getCode() != Common::kNoError)
152 return err;
153 return go();
154 }
155 bool hasFeature(EngineFeature f) const override;
156 void syncSoundSettings() override;
157
158 Common::Error loadGameState(int slot) override;
159 bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
160 Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override;
161 bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
162 Common::String getSaveStateName(int slot) const override {
163 return Common::String::format("sword1.%03d", slot);
164 }
165private:
166 void pollInput(uint32 delay);
167 void checkKeys();
168
169 void checkCdFiles();
170 void checkCd();
171 void askForCd();
172
173 void showFileErrorMsg(uint8 type, bool *fileExists);
174 void flagsToBool(bool *dest, uint8 flags);
175
176 void reinitRes(); //Reinits the resources after a GMM load
177
178 void installTimerRoutines();
179 void uninstallTimerRoutines();
180
181 uint8 mainLoop();
182
183 Common::Point _mouseCoord;
184 uint16 _mouseState;
185 Common::KeyState _keyPressed;
186 Common::CustomEventType _customType;
187
188 ResMan *_resMan;
189 ObjectMan *_objectMan;
190 Screen *_screen;
191 Mouse *_mouse;
192 Logic *_logic;
193 Sound *_sound;
194 Menu *_menu;
195 Control *_control;
196 static const uint8 _cdList[TOTAL_SECTIONS];
197 static const CdFile _pcCdFileList[];
198 static const CdFile _macCdFileList[];
199 static const CdFile _psxCdFileList[];
200};
201
202} // End of namespace Sword1
203
204#endif // SWORD1_SWORD1_H
Definition: error.h:81
ErrorCode getCode() const
Definition: error.h:112
Definition: str.h:59
static String format(MSVC_PRINTF const char *fmt,...) GCC_PRINTF(1
Definition: ustr.h:57
Definition: engine.h:149
EngineFeature
Definition: engine.h:282
Definition: system.h:166
Definition: control.h:120
Definition: logic.h:55
Definition: menu.h:65
Definition: mouse.h:70
Definition: objectman.h:33
Definition: resman.h:65
Definition: screen.h:75
Definition: sound.h:109
Definition: console.h:31
Definition: sword1.h:104
Common::String getSaveStateName(int slot) const override
Definition: sword1.h:162
void syncSoundSettings() override
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
bool hasFeature(EngineFeature f) const override
Common::Error run() override
Definition: sword1.h:148
Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave=false) override
Common::Error loadGameState(int slot) override
@ kNoError
No error occurred.
Definition: error.h:48
uint32 CustomEventType
Definition: events.h:212
Language
Definition: language.h:45
Platform
Definition: platform.h:93
Definition: animation.h:38
Definition: advancedDetector.h:164
Definition: keyboard.h:294
Definition: rect.h:144
Definition: atari-screen.h:58
Definition: sworddefs.h:167
Definition: sword1.h:71