ScummVM API documentation
ags_platform_driver.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 //=============================================================================
23 //
24 // AGS Cross-Platform Header
25 //
26 //=============================================================================
27 
28 #ifndef AGS_ENGINE_PLATFORM_BASE_AGS_PLATFORM_DRIVER_H
29 #define AGS_ENGINE_PLATFORM_BASE_AGS_PLATFORM_DRIVER_H
30 
31 #include "common/std/vector.h"
32 #include "ags/engine/ac/date_time.h"
33 #include "ags/engine/ac/path_helper.h"
34 #include "ags/shared/debugging/output_handler.h"
35 #include "ags/shared/util/geometry.h"
36 #include "ags/shared/util/ini_util.h"
37 #include "ags/lib/allegro/error.h"
38 
39 namespace AGS3 {
40 
41 namespace AGS {
42 namespace Shared {
43 class Stream;
44 } // namespace Shared
45 
46 namespace Engine {
47 struct DisplayMode;
48 } // namespace Engine
49 } // namespace AGS
50 
51 using namespace AGS; // FIXME later
52 
53 enum eScriptSystemOSID {
54  eOS_DOS = 1,
55  eOS_Win,
56  eOS_Linux,
57  eOS_Mac,
58  eOS_Android,
59  eOS_iOS,
60  eOS_PSP,
61  eOS_Web
62 };
63 
64 enum SetupReturnValue {
65  kSetup_Cancel,
66  kSetup_Done,
67  kSetup_RunGame
68 };
69 
71 // be used as a output target for logging system
73  virtual ~AGSPlatformDriver() { instance = nullptr; }
74 
75  // Called at the creation of the platform driver
76  virtual void MainInit() { };
77  // Called right before the formal backend init
78  virtual void PreBackendInit() { };
79  // Called right after the formal backend init
80  virtual void PostBackendInit() { };
81  // Called right before the backend is deinitialized
82  virtual void PreBackendExit() { };
83  // Called right after the backend is deinitialized
84  virtual void PostBackendExit() { };
85 
86  virtual void Delay(int millis);
87  virtual void DisplayAlert(const char *, ...) = 0;
88  virtual void AttachToParentConsole();
89  virtual int GetLastSystemError();
90  // Optionally fill in config tree from the platform-specific config source
91  virtual void ReadConfiguration(Shared::ConfigTree & /*cfg*/) {}
92  // Get root directory for storing per-game shared data
93  virtual FSLocation GetAllUsersDataDirectory() {
94  return FSLocation(".");
95  }
96  // Get root directory for storing per-game saved games
97  virtual FSLocation GetUserSavedgamesDirectory() {
98  return FSLocation(".");
99  }
100  // Get root directory for storing per-game user configuration files
101  virtual FSLocation GetUserConfigDirectory() {
102  return FSLocation(".");
103  }
104  // Get directory for storing all-games user configuration files
105  virtual FSLocation GetUserGlobalConfigDirectory() {
106  return FSLocation(".");
107  }
108  // Get default directory for program output (logs)
109  virtual FSLocation GetAppOutputDirectory() {
110  return FSLocation(".");
111  }
112  // Tells whether it's not permitted to write to the local directory (cwd, or game dir),
113  // and only specified user/app directories should be used.
114  // FIXME: this is a part of a hotfix, review uses of this function later.
115  virtual bool IsLocalDirRestricted() { return true; }
116  // Returns array of characters illegal to use in file names
117  virtual const char *GetIllegalFileChars() {
118  return "\\/";
119  }
120  virtual const char *GetDiskWriteAccessTroubleshootingText();
121  virtual const char *GetGraphicsTroubleshootingText() {
122  return "";
123  }
124  virtual uint64_t GetDiskFreeSpaceMB(const Shared::String &path) = 0;
125  virtual const char *GetNoMouseErrorString() = 0;
126  // Tells whether build is capable of controlling mouse movement properly
127  virtual bool IsMouseControlSupported(bool windowed) {
128  return false;
129  }
130  // Tells whether this platform's backend library deals with mouse cursor
131  // virtual->real coordinate transformation itself (otherwise AGS engine should do it)
132  virtual bool IsBackendResponsibleForMouseScaling() {
133  return false;
134  }
135  virtual const char *GetAllegroFailUserHint();
136  virtual eScriptSystemOSID GetSystemOSID() = 0;
137  virtual void GetSystemTime(ScriptDateTime *);
138  virtual void PlayVideo(const char *name, int skip, int flags);
139  virtual void InitialiseAbufAtStartup();
140  virtual void PostAllegroInit(bool windowed);
141  virtual void PostAllegroExit() = 0;
142  virtual const char *GetBackendFailUserHint() {
143  return nullptr;
144  }
145  virtual void FinishedUsingGraphicsMode();
146  virtual SetupReturnValue RunSetup(const Shared::ConfigTree &cfg_in, Shared::ConfigTree &cfg_out);
147  virtual void SetGameWindowIcon();
148  // Formats message and writes to standard platform's output;
149  // Always adds trailing '\n' after formatted string
150  virtual void WriteStdOut(const char *fmt, ...);
151  // Formats message and writes to platform's error output;
152  // Always adds trailing '\n' after formatted string
153  virtual void WriteStdErr(const char *fmt, ...);
154  // Display a text in a message box with a "warning" icon.
155  // Platforms which do not support this should do nothing.
156  virtual void DisplayMessageBox(const char *text) = 0;
157  virtual void YieldCPU();
158  // Called when the game window is being switch out from
159  virtual void DisplaySwitchOut();
160  // Called when the game window is being switch back to
161  virtual void DisplaySwitchIn();
162  // Called when the application is being paused completely (e.g. when player alt+tabbed from it).
163  // This function should suspend any platform-specific realtime processing.
164  virtual void PauseApplication();
165  // Called when the application is being resumed.
166  virtual void ResumeApplication();
167  // Returns a list of supported display modes
168  virtual void GetSystemDisplayModes(std::vector<Engine::DisplayMode> &dms);
169  // Switch to system fullscreen mode; store previous mode parameters
170  virtual bool EnterFullscreenMode(const Engine::DisplayMode &dm);
171  // Return back to the mode was before switching to fullscreen
172  virtual bool ExitFullscreenMode();
173  // Adjust application window's parameters to suit fullscreen mode
174  virtual void AdjustWindowStyleForFullscreen();
175  // Adjust application window's parameters to suit windowed mode
176  virtual void AdjustWindowStyleForWindowed();
177  virtual int ConvertKeycodeToScanCode(int keyCode);
178  // Adjust window's * client size * to ensure it is in the supported limits
179  virtual Size ValidateWindowSize(const Size &sz, bool borderless) const;
180 
181  virtual int InitializeCDPlayer() = 0; // return 0 on success
182  virtual int CDPlayerCommand(int cmdd, int datt) = 0;
183  virtual void ShutdownCDPlayer() = 0;
184 
185  // Returns command line argument in a UTF-8 format
186  virtual Common::String GetCommandArg(size_t arg_index);
187 
188  virtual bool LockMouseToWindow();
189  virtual void UnlockMouse();
190 
191  static AGSPlatformDriver *GetDriver();
192 
193  // Store command line arguments for the future use
194  void SetCommandArgs(const char *const argv[], size_t argc);
195 
196  // Set whether PrintMessage should output to stdout or stderr
197  void SetOutputToErr(bool on) {
198  _logToStdErr = on;
199  }
200  // Set whether DisplayAlert is allowed to show modal GUIs on some systems;
201  // it will print to either stdout or stderr otherwise, depending on above flag
202  void SetGUIMode(bool on) {
203  _guiMode = on;
204  }
205 
206  //-----------------------------------------------
207  // IOutputHandler implementation
208  //-----------------------------------------------
209  // Writes to the standard platform's output, prepending "AGS: " prefix to the message
210  void PrintMessage(const AGS::Shared::DebugMessage &msg) override;
211 
212 protected:
213  // TODO: this is a quick solution for IOutputHandler implementation
214  // logging either to stdout or stderr. Normally there should be
215  // separate implementation, one for each kind of output, but
216  // with both going through PlatformDriver need to figure a better
217  // design first.
218  bool _logToStdErr = false;
219  // Defines whether engine is allowed to display important warnings
220  // and errors by showing a message box kind of GUI.
221  bool _guiMode = false;
222 
223  const char *const *_cmdArgs = nullptr;
224  size_t _cmdArgCount = 0u;
225 
226 private:
227  static AGSPlatformDriver *instance;
228 };
229 
230 #if defined (AGS_HAS_CD_AUDIO)
231 int cd_player_init();
232 int cd_player_control(int cmdd, int datt);
233 #endif
234 
235 // [IKM] What is a need to have this global var if you can get AGSPlatformDriver
236 // instance by calling AGSPlatformDriver::GetDriver()?
237 
238 
239 } // namespace AGS3
240 
241 #endif
Definition: achievements_tables.h:27
Definition: vector.h:39
Definition: str.h:59
Definition: path_helper.h:55
Definition: gfx_defines.h:60
Definition: output_handler.h:39
Definition: ags_platform_driver.h:70
Definition: string.h:62
Definition: geometry.h:148
Definition: script_date_time.h:29
Definition: map.h:40
Definition: output_handler.h:55
Definition: engine.h:144
Definition: ags.h:40