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