ScummVM
glk.h
Go to the documentation of this file.
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 
23 #ifndef GLK_GLK_H
24 #define GLK_GLK_H
25 
26 #include "common/scummsys.h"
27 #include "common/random.h"
28 #include "common/system.h"
29 #include "common/serializer.h"
30 #include "engines/engine.h"
31 #include "glk/glk_types.h"
32 #include "glk/streams.h"
33 #include "glk/pc_speaker.h"
34 
35 namespace Glk {
36 
37 class Clipboard;
38 class Blorb;
39 class Conf;
40 class Events;
41 class Pictures;
42 class Screen;
43 class Selection;
44 class Sounds;
45 class Streams;
46 class Windows;
47 
49  kDebugCore = 1 << 0,
50  kDebugScripts = 1 << 1,
51  kDebugGraphics = 1 << 2,
52  kDebugSound = 1 << 3
53 };
54 
55 
56 #define GLK_SAVEGAME_VERSION 1
57 
65 };
66 
70 class GlkEngine : public Engine {
71 private:
75  void initialize();
76 protected:
82  bool _quitFlag;
83 
84  // Engine APIs
85  Common::Error run() override;
86 
90  bool hasFeature(EngineFeature f) const override;
91 
95  virtual void initGraphicsMode();
96 
100  virtual Screen *createScreen();
101 
105  virtual void runGame() = 0;
106 public:
119 
120  gidispatch_rock_t(*gli_register_obj)(void *obj, uint objclass);
121  void(*gli_unregister_obj)(void *obj, uint objclass, gidispatch_rock_t objrock);
122  gidispatch_rock_t(*gli_register_arr)(void *array, uint len, const char *typecode);
123  void(*gli_unregister_arr)(void *array, uint len, const char *typecode, gidispatch_rock_t objrock);
124 public:
125  GlkEngine(OSystem *syst, const GlkGameDescription &gameDesc);
126  ~GlkEngine() override;
127 
131  bool canLoadGameStateCurrently() override {
132  return true;
133  }
134 
138  bool canSaveGameStateCurrently() override {
139  return true;
140  }
141 
146 
150  virtual InterpreterType getInterpreterType() const = 0;
151 
156 
160  const Common::String &getGameMD5() const { return _gameDescription._md5; }
161 
166 
171 
175  const Common::String &getTargetName() const {
176  return _targetName;
177  }
178 
183  return Common::String::format("%s.%.3u", getTargetName().c_str(), slot);
184  }
185 
190 
195 
199  Common::Error loadGameState(int slot) override;
200 
204  Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override;
205 
210 
216 
220  void syncSoundSettings() override;
221 
225  void beep();
226 
231 
236 
240  void quitGame() {
241  _quitFlag = true;
243  }
244 
248  bool shouldQuit() const {
249  return _quitFlag || Engine::shouldQuit();
250  }
251 };
252 
253 extern GlkEngine *g_vm;
254 
255 } // End of namespace Glk
256 
257 #endif
Glk::GlkEngine::getOptions
uint getOptions() const
Returns any options returned with the game's detection entry.
Definition: glk.h:170
Common::Language
Language
List of game language.
Definition: language.h:35
Glk::GlkEngine::beep
void beep()
Generate a beep.
Definition: glk.cpp:263
Common::SeekableReadStream
Interface for a seekable & readable data stream.
Definition: stream.h:569
Glk
Contains the necessary data structures andfunctions for adding to andreferring to the ID table(a very...
Definition: adrift.cpp:28
Glk::Level9::f
FILE * f
Definition: level9_main.cpp:155
Glk::GlkEngine::writeGameData
virtual Common::Error writeGameData(Common::WriteStream *ws)=0
Save the game.
scummsys.h
Engine
Definition: engine.h:60
Glk::GlkEngine::canLoadGameStateCurrently
bool canLoadGameStateCurrently() override
Returns true if a savegame can be loaded.
Definition: glk.h:131
Glk::GlkEngine::createScreen
virtual Screen * createScreen()
Create the screen.
Definition: glk.cpp:99
Glk::GlkEngine::loadGame
Common::Error loadGame()
Prompt the user for a savegame to load, and then load it.
Definition: glk.cpp:159
streams.h
Glk::Events
Events manager.
Definition: events.h:163
Glk::Screen
Screen surface class.
Definition: screen.h:44
Glk::GlkEngine::_pictures
Pictures * _pictures
Definition: glk.h:111
Glk::Streams
Streams manager.
Definition: streams.h:580
Glk::Pictures
Pictures manager.
Definition: picture.h:89
Engine::shouldQuit
static bool shouldQuit()
Return whether the ENGINE should quit respectively should return to the launcher.
Definition: engine.cpp:791
Glk::GlkEngine::shouldQuit
bool shouldQuit() const
Returns true if the game should be quit.
Definition: glk.h:248
Glk::TADS::max
static uint max
Definition: os_buffer.cpp:52
Glk::GlkEngine::_windows
Windows * _windows
Definition: glk.h:116
Glk::Conf
Engine configuration.
Definition: conf.h:35
Common::String
Simple string class for ScummVM.
Definition: str.h:49
Glk::GlkGameDescription::_gameId
Common::String _gameId
Definition: glk.h:59
Glk::GlkEngine::getGameID
const Common::String & getGameID() const
Returns the game's Id.
Definition: glk.h:155
Glk::g_vm
GlkEngine * g_vm
Definition: glk.cpp:47
Common::Error
An Error instance pairs an error code with string description providing more details about the error.
Definition: error.h:77
Glk::GlkGameDescription::_filename
Common::String _filename
Definition: glk.h:62
Glk::GlkEngine::_gameFile
Common::File _gameFile
Definition: glk.h:80
Glk::GlkEngine::loadGameState
Common::Error loadGameState(int slot) override
Load a savegame from a given slot.
Definition: glk.cpp:184
Glk::Blorb
Blorb file manager.
Definition: blorb.h:83
Glk::GlkEngine::getRandomNumber
uint getRandomNumber(uint max)
Get a random number.
Definition: glk.h:230
Screen
Screen class.
Definition: default_display_client.h:79
Glk::gidispatch_rock_t
Definition: glk_types.h:225
Glk::kDebugGraphics
Definition: glk.h:51
Glk::GlkEngine::gli_register_arr
gidispatch_rock_t(* gli_register_arr)(void *array, uint len, const char *typecode)
Definition: glk.h:122
Glk::GlkGameDescription::_platform
Common::Platform _platform
Definition: glk.h:61
Glk::GlkEngine::hasFeature
bool hasFeature(EngineFeature f) const override
Returns true whether a given feature is supported by the engine.
Definition: detection.cpp:163
Glk::GlkGameDescription::_options
uint _options
Definition: glk.h:64
Common::RandomSource
Simple random number generator.
Definition: random.h:36
Glk::kDebugScripts
Definition: glk.h:50
Glk::GlkGameDescription::_md5
Common::String _md5
Definition: glk.h:63
random.h
Glk::GlkGameDescription::_language
Common::Language _language
Definition: glk.h:60
Glk::GlkEngine::_loadSaveSlot
int _loadSaveSlot
Definition: glk.h:79
Glk::kDebugSound
Definition: glk.h:52
Glk::GlkEngine::_screen
Screen * _screen
Definition: glk.h:112
Engine::EngineFeature
EngineFeature
A feature in this context means an ability of the engine which can be either available or not.
Definition: engine.h:124
Glk::GlkEngine::_pcSpeaker
PCSpeaker * _pcSpeaker
Definition: glk.h:81
Glk::GlkEngine::_random
Common::RandomSource _random
Definition: glk.h:78
Glk::GlkEngine::_streams
Streams * _streams
Definition: glk.h:114
Glk::GlkEngine::quitGame
void quitGame()
Flags to quit the game.
Definition: glk.h:240
Glk::GlkEngine::runGame
virtual void runGame()=0
Main game loop for the individual interpreters.
Glk::GlkEngine::getTargetName
const Common::String & getTargetName() const
Return the game engine's target name.
Definition: glk.h:175
Engine::quitGame
static void quitGame()
Request the engine to quit.
Definition: engine.cpp:784
pc_speaker.h
Glk::GlkDebugChannels
GlkDebugChannels
Definition: glk.h:48
Common::RandomSource::getRandomNumber
uint getRandomNumber(uint max)
Generates a random unsigned integer in the interval [0, max].
Definition: random.cpp:46
Common::String::format
static String format(const char *fmt,...) GCC_PRINTF(1
Print formatted data into a String object.
Definition: str.cpp:641
Glk::GlkEngine::_conf
Conf * _conf
Definition: glk.h:109
Glk::GlkEngine::readSaveData
virtual Common::Error readSaveData(Common::SeekableReadStream *rs)=0
Load a savegame from the passed Quetzal file chunk stream.
serializer.h
Glk::GlkEngine::_events
Events * _events
Definition: glk.h:110
Glk::GlkEngine::setRandomNumberSeed
void setRandomNumberSeed(uint seed)
Set a random number seed.
Definition: glk.h:235
Glk::Clipboard
Acts as interface to and from the system's clipboard storage.
Definition: selection.h:41
uint
unsigned int uint
Definition: scummsys.h:440
Glk::GlkEngine::getLanguage
Common::Language getLanguage() const
Returns the language.
Definition: glk.h:145
Glk::GlkEngine::saveGame
Common::Error saveGame()
Prompt the user to save their game, and then save it.
Definition: glk.cpp:171
Glk::InterpreterType
InterpreterType
List of the different sub-engines the engine will likely eventually support.
Definition: glk_types.h:37
Glk::Sounds
Sound manager.
Definition: sound.h:100
Common::RandomSource::setSeed
void setSeed(uint32 seed)
Definition: random.cpp:42
Glk::GlkEngine::GlkEngine
GlkEngine(OSystem *syst, const GlkGameDescription &gameDesc)
Definition: glk.cpp:49
Common::WriteStream
Generic interface for a writable data stream.
Definition: stream.h:65
Glk::GlkEngine::initGraphicsMode
virtual void initGraphicsMode()
Setup the video mode.
Definition: glk.cpp:103
Glk::GlkEngine::_blorb
Blorb * _blorb
Definition: glk.h:107
Glk::kDebugCore
Definition: glk.h:49
Glk::GlkEngine::_selection
Selection * _selection
Definition: glk.h:113
Glk::GlkEngine::getFilename
const Common::String & getFilename() const
Returns the primary filename for the game.
Definition: glk.h:165
Glk::GlkEngine::_quitFlag
bool _quitFlag
Definition: glk.h:82
Glk::Selection
Overall manager for selecting areas on the screen, copying to/from the clipboard, and managing hyperl...
Definition: selection.h:101
Common::Platform
Platform
List of game platforms.
Definition: platform.h:38
Glk::Windows
Main windows manager.
Definition: windows.h:51
glk_types.h
Glk::GlkEngine::_sounds
Sounds * _sounds
Definition: glk.h:115
Glk::GlkEngine::gli_unregister_obj
void(* gli_unregister_obj)(void *obj, uint objclass, gidispatch_rock_t objrock)
Definition: glk.h:121
Glk::PCSpeaker
Definition: pc_speaker.h:34
Glk::GlkEngine::_clipboard
Clipboard * _clipboard
Definition: glk.h:108
Graphics::desc
static const BdfFontData desc
Definition: consolefont.cpp:5852
Glk::GlkEngine::initialize
void initialize()
Handles basic initialization.
Definition: glk.cpp:79
system.h
Glk::GlkEngine::saveGameState
Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave=false) override
Save the game to a given slot.
Definition: glk.cpp:231
Common::File
TODO: vital to document this core class properly!!! For both users and implementors.
Definition: file.h:39
Glk::GlkEngine::gli_register_obj
gidispatch_rock_t(* gli_register_obj)(void *obj, uint objclass)
Definition: glk.h:120
OSystem
Interface for ScummVM backends.
Definition: system.h:114
Glk::GlkEngine::getInterpreterType
virtual InterpreterType getInterpreterType() const =0
Returns the running interpreter type.
Glk::GlkEngine::_terminated
bool _terminated
Definition: glk.h:118
Glk::GlkEngine::_copySelect
bool _copySelect
Definition: glk.h:117
engine.h
Engine::_targetName
const Common::String _targetName
Definition: engine.h:73
Glk::GlkEngine::gli_unregister_arr
void(* gli_unregister_arr)(void *array, uint len, const char *typecode, gidispatch_rock_t objrock)
Definition: glk.h:123
HDB::seed
AIStateDef seed[]
Definition: ai-init.cpp:558
Glk::GlkEngine::syncSoundSettings
void syncSoundSettings() override
Updates sound settings.
Definition: glk.cpp:256
Glk::GlkEngine
Base class for the different interpreters.
Definition: glk.h:70
Glk::GlkEngine::getSaveName
Common::String getSaveName(uint slot) const
Return the filename for a given save slot.
Definition: glk.h:182
Glk::GlkEngine::run
Common::Error run() override
Init the engine and start its main loop.
Definition: glk.cpp:119
Glk::GlkGameDescription
Definition: glk.h:58
Glk::GlkEngine::canSaveGameStateCurrently
bool canSaveGameStateCurrently() override
Returns true if the game can be saved.
Definition: glk.h:138
Glk::GlkEngine::~GlkEngine
~GlkEngine() override
Definition: glk.cpp:65
Glk::GlkEngine::getGameMD5
const Common::String & getGameMD5() const
Returns the game's md5.
Definition: glk.h:160
Glk::GlkEngine::_gameDescription
const GlkGameDescription _gameDescription
Definition: glk.h:77