ScummVM API documentation
qd_game_dispatcher.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#ifndef QDENGINE_QDCORE_QD_GAME_DISPATCHER_H
24#define QDENGINE_QDCORE_QD_GAME_DISPATCHER_H
25
26#include "qdengine/parser/xml_fwd.h"
27#include "qdengine/system/input/mouse_input.h"
28#include "qdengine/system/graphics/gr_screen_region.h"
29#include "qdengine/qdcore/qd_camera_mode.h"
30#include "qdengine/qdcore/qd_object_list_container.h"
31#include "qdengine/qdcore/qd_game_dispatcher_base.h"
32#include "qdengine/qdcore/qd_resource_dispatcher.h"
33#include "qdengine/qdcore/qd_screen_text_dispatcher.h"
34#include "qdengine/qdcore/qd_interface_dispatcher.h"
35#include "qdengine/qdcore/qd_inventory.h"
36#include "qdengine/qdcore/qd_font_info.h"
37#include "qdengine/qdcore/qd_file_owner.h"
38#include "qdengine/qdcore/util/WinVideo.h"
39
40namespace QDEngine {
41
42class grFont;
43class qdGameDispatcher : public qdGameDispatcherBase, public qdResourceDispatcher<qdNamedObject>, public qdFileOwner {
44public:
46 enum {
49 };
50
52 enum {
53 EXIT_FLAG = 0x01,
54 RESTART_FLAG = 0x02,
55 OBJECT_CLICK_FLAG = 0x04,
56 DIALOG_CLICK_FLAG = 0x08,
57 FULLSCREEN_REDRAW_FLAG = 0x10,
58 SKIP_REDRAW_FLAG = 0x20,
59 MAIN_MENU_FLAG = 0x40,
60 INTRO_MODE_FLAG = 0x80,
61 CLICK_FAILED_FLAG = 0x100,
62 OBJECT_CLICK_FAILED_FLAG = 0x200,
63 CLICK_WAS_FAILED_FLAG = 0x400,
64 OBJECT_CLICK_WAS_FAILED_FLAG = 0x800,
65 LOAD_GAME_FLAG = 0x1000,
66 SAVE_GAME_FLAG = 0x2000,
67 FADE_IN_FLAG = 0x4000,
68 FADE_OUT_FLAG = 0x8000,
69 NEXT_FRAME_FLAG = 0x10000
70 };
71
72 qdGameDispatcher();
73 ~qdGameDispatcher();
74
75 int named_object_type() const {
76 return QD_NAMED_OBJECT_DISPATCHER;
77 }
78
79 qdGameObjectMouse *mouse_object() {
80 return _mouse_obj;
81 }
82 qdGameObjectMouse const *mouse_object() const {
83 return _mouse_obj;
84 }
85 bool drop_mouse_object();
86
87 int CD_count() const;
88
89 int resource_compression() const {
90 return _resource_compression;
91 }
92 void set_resource_compression(int compression) {
93 _resource_compression = compression;
94 }
95
96 void request_file_package(const qdFileOwner &file_owner) const;
97 Common::Path find_file(const Common::Path &file_name, const qdFileOwner &file_owner) const;
98 void startup_check() const;
99
100 qdLoadingProgressFnc set_scene_loading_progress_callback(qdLoadingProgressFnc p, void *dp = 0) {
101 qdLoadingProgressFnc old_fnc = _scene_loading_progress_fnc;
102 _scene_loading_progress_fnc = p;
103 _scene_loading_progress_data = dp;
104
105 return old_fnc;
106 }
107
108 qdLoadingProgressFnc get_scene_loading_progress_callback() {
109 return _scene_loading_progress_fnc;
110 }
111
112 void *get_scene_loading_progress_data() {
113 return _scene_loading_progress_data;
114 }
115
116 void set_time(int tm) {
117 _timer = tm;
118 }
119 int get_time() const {
120 return _timer;
121 }
122
123 bool start_intro_videos();
124
125 void quant();
126 void quant(float dt);
127 void pre_redraw();
128 void redraw();
129 void post_redraw();
130
131 void update_time();
132
133 bool mouse_handler(int x, int y, mouseDispatcher::mouseEvent ev);
134 bool keyboard_handler(Common::KeyCode vkey, bool event);
135
136 bool add_game_end(qdGameEnd *p);
137 bool rename_game_end(qdGameEnd *p, const char *name);
138 bool remove_game_end(qdGameEnd *p);
139 qdGameEnd *get_game_end(const char *name);
140 bool is_game_end_in_list(const char *name);
141 bool is_game_end_in_list(qdGameEnd *p);
142
143 bool add_counter(qdCounter *p);
144 bool rename_counter(qdCounter *p, const char *name);
145 bool remove_counter(qdCounter *p);
146 qdCounter *get_counter(const char *name);
147 bool is_counter_in_list(const char *name);
148 bool is_counter_in_list(qdCounter *p);
149
150 bool add_minigame(qdMiniGame *p);
151 bool rename_minigame(qdMiniGame *p, const char *name);
152 bool remove_minigame(const char *name);
153 bool remove_minigame(qdMiniGame *p);
154 qdMiniGame *get_minigame(const char *name);
155 bool is_minigame_in_list(const char *name);
156 bool is_minigame_in_list(qdMiniGame *p);
157
158 void set_mouse_click_state(const qdGameObjectState *p) {
159 _mouse_click_state = p;
160 }
161
162 bool add_inventory(qdInventory *p) {
163 if (_inventories.add_object(p)) {
164 p->set_owner(this);
165 return 1;
166 }
167 return 0;
168 }
169 bool remove_inventory(const char *name) {
170 return _inventories.remove_object(name);
171 }
172 bool remove_inventory(qdInventory *p) {
173 return _inventories.remove_object(p);
174 }
175 qdInventory *get_inventory(const char *name) {
176 return _inventories.get_object(name);
177 }
178 bool is_inventory_in_list(const char *name) {
179 return _inventories.is_in_list(name);
180 }
181 bool is_inventory_in_list(qdInventory *p) {
182 return _inventories.is_in_list(p);
183 }
184 bool rename_inventory(qdInventory *p, const char *name);
185
186 const qdInventoryCellType *add_inventory_cell_type(const qdInventoryCellType &tp) {
187 //проверяем уникальность идентификатора, вставляемого типа
188 assert(find_inventory_cell_type(tp.type()) == _inventory_cell_types.end());
189 _inventory_cell_types.push_back(tp);
190
191 return &_inventory_cell_types.back();
192 }
193 bool remove_inventory_cell_type(int type) {
194 typedef qdInventoryCellTypeVector::iterator i_t;
195 i_t res = find_inventory_cell_type(type);
196 if (res != _inventory_cell_types.end()) {
197 _inventory_cell_types.erase(res);
198 return true;
199 }
200 return false;
201 }
202 const qdInventoryCellType *get_inventory_cell_type(int type) const {
203 typedef qdInventoryCellTypeVector::const_iterator ci_t;
204 ci_t res = find_inventory_cell_type(type);
205 if (res != _inventory_cell_types.end())
206 return &*res;
207 return NULL;
208 }
209 int get_unique_inventory_cell_type() const {
210 if (_inventory_cell_types.empty()) return 0;
211 return _inventory_cell_types.back().type() + 1;
212 }
213 bool set_inventory_cell_type(const qdInventoryCellType &tp) {
214 typedef qdInventoryCellTypeVector::iterator i_t;
215 i_t res = find_inventory_cell_type(tp.type());
216 if (res != _inventory_cell_types.end()) {
217 *res = tp;
218 return true;
219 }
220 return false;
221 }
222 const qdInventoryCellTypeVector &inventory_cell_types() const {
223 return _inventory_cell_types;
224 }
225
226 qdInventoryCellTypeVector &not_const_inventory_cell_types() {
227 return _inventory_cell_types;
228 }
229
231
238 bool remove_font_info(qdFontInfo *fi);
239 bool rename_font_info(qdFontInfo *fi, char const *name);
240
241 const qdFontInfo *get_font_info(int type) const;
242 int get_unique_font_info_type() const;
243 bool set_font_info(const qdFontInfo &fi);
244 const qdFontInfoList &fonts_list() const {
245 return _fonts.get_list();
246 }
247
248 int default_font() const {
249 return _default_font;
250 }
251 void set_default_font(int font) {
252 _default_font = font;
253 }
254
255 bool toggle_inventory(bool state);
256 bool toggle_inventory() {
257 if (!_cur_inventory) return toggle_inventory(true);
258 else return toggle_inventory(false);
259 }
260 bool put_to_inventory(qdGameObjectAnimated *p);
261 bool remove_from_inventory(qdGameObjectAnimated *p);
262 bool is_in_inventory(const qdGameObjectAnimated *p) const;
263 bool is_on_mouse(const qdGameObjectAnimated *p) const;
264
265 const qdInventory *cur_inventory() const {
266 return _cur_inventory;
267 }
268
269 bool add_video(qdVideo *p, qdVideo const *before = NULL);
270 bool remove_video(const char *name);
271 bool remove_video(qdVideo *p);
272 qdVideo *get_video(const char *name);
273 bool is_video_in_list(const char *name);
274 bool is_video_in_list(qdVideo *p);
275 bool rename_video(qdVideo *p, const char *name);
276
277 bool add_trigger_chain(qdTriggerChain *p);
278 bool remove_trigger_chain(const char *name);
279 bool remove_trigger_chain(qdTriggerChain *p);
280 qdTriggerChain *get_trigger_chain(const char *name);
281 bool is_trigger_chain_in_list(const char *name);
282 bool is_trigger_chain_in_list(qdTriggerChain *p);
283 bool rename_trigger_chain(qdTriggerChain *p, const char *name);
284
285 bool add_scene(qdGameScene *p);
286 bool rename_scene(qdGameScene *p, const char *name);
287 bool remove_scene(qdGameScene *p);
288 qdGameScene *get_scene(const char *name);
289 bool is_scene_in_list(const char *name);
290 bool is_scene_in_list(const qdGameScene *p);
291
292 bool add_global_object(qdGameObject *p);
293 bool rename_global_object(qdGameObject *p, const char *name);
294 bool remove_global_object(const char *name);
295 bool remove_global_object(qdGameObject *p);
296 qdGameObject *get_global_object(const char *name);
297 bool is_global_object_in_list(const char *name);
298 bool is_global_object_in_list(qdGameObject *p);
299
300 bool merge_global_objects(qdGameObject *obj = NULL);
301 bool split_global_objects(qdGameObject *obj = NULL);
302 bool update_walk_state(const char *object_name, qdGameObjectState *p);
303 qdGameObjectState *get_walk_state(const char *object_name);
304
305 // Управление видеовставками
306 bool play_video(const char *vid_name);
307 bool play_video(qdVideo *p);
308 bool pause_video();
309 bool stop_video();
310 bool close_video();
311 bool is_video_finished();
312 bool is_video_playing() {
313 if (!_cur_video) return false;
314 return true;
315 }
316
317 void continueVideo();
318 bool is_video_playing(qdVideo *p) {
319 return (_cur_video == p);
320 }
321
322 bool play_music_track(const qdMusicTrack *p, bool interface_mode = false);
323 const qdMusicTrack *current_music() const {
324 return _cur_music_track;
325 }
326 bool stop_music();
327
328 bool select_scene(const char *s_name);
329 bool select_scene(qdGameScene *sp, bool resources_flag = true);
330
335
336 void set_next_scene(qdGameScene *p) {
337 _next_scene = p;
338 }
339
340 int load_resources();
341 void free_resources();
342 int get_resources_size();
343
344 void load_script(const char *fname);
345 void load_script(const xml::tag *p);
346 bool save_script(Common::SeekableWriteStream &fh) const;
347 bool save_script(const char *fname) const;
348
352 bool save_save(Common::WriteStream *stream) const;
353
354 bool save_game(int slot_id) const;
355
357 bool init();
358
359 bool init_triggers();
360 bool reset_triggers();
361
362 const qdVideoList &video_list() const {
363 return _videos.get_list();
364 }
365 const qdTriggerChainList &trigger_chain_list() const {
366 return _trigger_chains.get_list();
367 }
368 const qdGameObjectList &global_object_list() const {
369 return _global_objects.get_list();
370 }
371 const qdInventoryList &inventory_list() const {
372 return _inventories.get_list();
373 }
374 const qdMiniGameList &minigame_list() const {
375 return _minigames.get_list();
376 }
377 const qdGameEndList &game_end_list() const {
378 return _game_ends.get_list();
379 }
380 const qdGameSceneList &scene_list() const {
381 return _scenes.get_list();
382 }
383 const qdCounterList &counter_list() const {
384 return _counters.get_list();
385 }
386
387 qdGameScene *get_active_scene() const {
388 return _cur_scene;
389 }
390
391 qdSound *get_sound(const char *name);
392 qdAnimation *get_animation(const char *name);
393 qdAnimationSet *get_animation_set(const char *name);
394 qdGameObject *get_object(const char *name);
395 qdGameObjectMoving *get_active_personage();
396 qdNamedObject *get_named_object(const qdNamedObjectReference *ref);
397
398 qdScaleInfo *get_scale_info(const char *p);
399
400 bool check_condition(qdCondition *cnd);
401
402 void pause();
403 void resume();
404 bool is_paused() {
405 return _is_paused;
406 }
407
408 bool is_gameplay_paused() {
409 return _is_gameplay_paused;
410 }
411
412 void pause_gameplay(bool pause) { _is_gameplay_paused = pause; }
413
414 bool restart();
415
416 qdScreenTextDispatcher &screen_texts_dispatcher() {
417 return _screen_texts;
418 }
419
420 bool toggle_main_menu() {
421 return toggle_main_menu(!_interface_dispatcher.is_active());
422 }
423 bool toggle_main_menu(bool state, const char *screen_name = NULL);
424 bool has_main_menu() const {
425 return _interface_dispatcher.has_main_menu();
426 }
427 bool is_main_menu_exit_enabled() const;
428
429 void set_game_end(const qdGameEnd *p) {
430 _game_end = p;
431 }
432 bool end_game(const qdGameEnd *p);
433
434 bool add_redraw_region(const grScreenRegion &reg);
435
437 void toggle_exit() {
438 set_flag(EXIT_FLAG);
439 }
441 bool need_exit() const {
442 return check_flag(EXIT_FLAG);
443 }
444
447 set_flag(RESTART_FLAG);
448 }
450 bool need_restart() const {
451 return check_flag(RESTART_FLAG);
452 }
453
454 void toggle_full_redraw() {
455 set_flag(FULLSCREEN_REDRAW_FLAG);
456 }
457 bool need_full_redraw() const {
458 return check_flag(FULLSCREEN_REDRAW_FLAG);
459 }
460
461 static void set_dispatcher(qdGameDispatcher *p);
462 static qdGameDispatcher *get_dispatcher() {
463 return _dispatcher;
464 }
465
467 const char *startup_scene() const {
468 return _startup_scene.c_str();
469 }
471
474 void set_startup_scene(const char *name) {
475 if (name)
476 _startup_scene = name;
477 else
478 _startup_scene.clear();
479 }
481 bool has_startup_scene() const {
482 return !_startup_scene.empty();
483 }
484
485 bool game_screenshot(Graphics::Surface &thumb) const;
486
487 void set_game_title(const char *p) {
488 _game_title = p;
489 }
490 const char *game_title() const {
491 return _game_title.c_str();
492 }
493
494 void set_texts_database(const Common::Path &file_name) {
495 _texts_database = file_name;
496 }
497 const Common::Path texts_database() const {
498 return _texts_database;
499 }
500
501 void set_cd_key(const char *key) {
502 _cd_key = key;
503 }
504 const char *cd_key() const {
505 return _cd_key.c_str();
506 }
507
508 bool add_dialog_state(qdGameObjectState *p);
509
510 const Vect2f &mouse_cursor_pos() const {
511 return _mouse_cursor_pos;
512 }
513
514 bool is_autosave_slot(int save_slot) {
515 return save_slot == _autosave_slot;
516 }
517
518 void set_auto_save(int save_slot) {
519 set_flag(SAVE_GAME_FLAG);
520 _autosave_slot = save_slot;
521 }
522 void set_auto_load(int save_slot) {
523 set_flag(LOAD_GAME_FLAG);
524 _autosave_slot = save_slot;
525 }
526
527 static grFont *create_font(int font_idx);
528 static void free_font(grFont *fnt);
529
532 const qdFontInfo *find_font_info(int type) const;
533 const grFont *find_font(int type) const;
534
535 bool set_fade(bool fade_in, float duration);
536
537 bool write_resource_stats(const char *file_name) const;
538
539 int hall_of_fame_size() const {
540 return _hall_of_fame_size;
541 }
542 void set_hall_of_fame_size(int size) {
543 _hall_of_fame_size = size;
544 }
545
546 const char *hall_of_fame_player_name(int place) const;
547 void set_hall_of_fame_player_name(int place, const char *name);
548
549 int hall_of_fame_player_score(int place) const;
550
551 bool is_hall_of_fame_updated(int place) const;
552
553 bool has_hall_of_fame() const {
554 return _hall_of_fame_size != 0;
555 }
556 bool load_hall_of_fame();
557 bool save_hall_of_fame() const;
558 bool add_hall_of_fame_entry(int score);
559
560private:
561
562 int _timer;
563
564 bool _is_paused;
565 bool _is_gameplay_paused = false;
566
567 bool _enable_file_packages;
569 int _resource_compression;
570
572 int _hall_of_fame_size;
573 struct HallOfFameEntry {
574 Common::String _player_name;
575 int _score;
576
577 bool _updated;
578
579 HallOfFameEntry() {
580 _score = 0;
581 _updated = false;
582 }
583 };
584
585 typedef Std::vector<HallOfFameEntry> HallOfFame;
586 HallOfFame _hall_of_fame;
587
588 qdInterfaceDispatcher _interface_dispatcher;
589
590 winVideo _video_player;
591 qdVideo *_cur_video;
592 qdObjectListContainer<qdVideo> _videos;
593
594 qdObjectListContainer<qdGameObject> _global_objects;
595 qdObjectListContainer<qdTriggerChain> _trigger_chains;
596 qdObjectListContainer<qdInventory> _inventories;
597 qdObjectListContainer<qdGameEnd> _game_ends;
598 qdObjectListContainer<qdGameScene> _scenes;
599 qdObjectListContainer<qdCounter> _counters;
600
601 qdGameScene *_cur_scene;
602 bool _scene_saved;
603 int _autosave_slot;
604
606 const qdGameEnd *_game_end;
607
608 qdObjectListContainer<qdMiniGame> _minigames;
609
610 qdInventory *_cur_inventory;
611 qdInventoryCellTypeVector _inventory_cell_types;
613 qdObjectListContainer<qdFontInfo> _fonts;
614
616 int _default_font;
617
618 qdGameObjectMouse *_mouse_obj;
619 qdGameObjectAnimated *_mouse_click_obj;
620 const qdGameObjectState *_mouse_click_state;
621 qdAnimation *_mouse_animation;
622 Vect2f _mouse_cursor_pos;
623
624 typedef Std::vector<qdGameObjectState *> dialog_states_container_t;
625 dialog_states_container_t _dialog_states;
626 dialog_states_container_t _dialog_states_last;
627
628 qdScreenTextDispatcher _screen_texts;
629
630 Common::String _startup_scene;
631
633 Common::Path _texts_database;
634
636 Common::String _game_title;
637
638 Common::String _cd_key;
639
640 void *_scene_loading_progress_data;
641 qdLoadingProgressFnc _scene_loading_progress_fnc;
642
643 qdGameScene *_next_scene;
644
645 bool _interface_music_mode;
646 const qdMusicTrack *_cur_music_track;
647 const qdMusicTrack *_cur_interface_music_track;
648
649 float _fade_timer;
650 float _fade_duration;
651
652 qdCameraMode _default_camera_mode;
653
654 static qdGameDispatcher *_dispatcher;
655
656 bool init_inventories();
657
658 qdInventoryCellTypeVector::iterator find_inventory_cell_type(int type) {
659 return Common::find(_inventory_cell_types.begin(),
660 _inventory_cell_types.end(), type);
661 }
662
663 qdInventoryCellTypeVector::const_iterator find_inventory_cell_type(int type) const {
664 return Common::find(_inventory_cell_types.begin(), _inventory_cell_types.end(), type);
665 }
666
667 void redraw(const grScreenRegion &reg);
668 void redraw_scene(bool draw_interface = true);
669
671 bool update_ingame_interface();
672
674 bool update_hall_of_fame_names();
675};
676
677qdGameDispatcher *qd_get_game_dispatcher();
678
679} // namespace QDEngine
680
681#endif // QDENGINE_QDCORE_QD_GAME_DISPATCHER_H
iterator end()
Definition: array.h:380
iterator erase(iterator pos)
Definition: array.h:329
T & back()
Definition: array.h:230
void push_back(const T &element)
Definition: array.h:181
bool empty() const
Definition: array.h:352
Definition: path.h:52
Definition: stream.h:745
Definition: stream.h:351
Definition: str.h:59
Definition: stream.h:77
Definition: gr_font.h:34
mouseEvent
События.
Definition: mouse_input.h:41
Definition: qd_file_owner.h:27
Шрифт
Definition: qd_font_info.h:36
Definition: qd_game_dispatcher_base.h:79
Definition: qd_game_dispatcher.h:43
bool activate_trigger_links(const qdNamedObject *p)
Делает активными все линки, идущие от объекта в триггерах.
int named_object_type() const
Возвращает тип объекта.
Definition: qd_game_dispatcher.h:75
@ TEXT_SET_DIALOGS
Фразы диалогов, отображаемые в данный момент на экране
Definition: qd_game_dispatcher.h:48
void set_startup_scene(const char *name)
Устанавливает имя стартовой сцены игры.
Definition: qd_game_dispatcher.h:474
void toggle_restart()
Ставит флаг, что надо перезапустить игру.
Definition: qd_game_dispatcher.h:446
bool deactivate_scene_triggers(const qdGameScene *p)
Делает неактивными все триггера сцены.
const char * startup_scene() const
Возвращает имя стартовой сцены игры.
Definition: qd_game_dispatcher.h:467
bool need_exit() const
Возвращает true, если надо выйти из игры.
Definition: qd_game_dispatcher.h:441
bool init()
Инициализация данных, вызывается один раз сразу после загрузки скрипта.
qdFontInfo * find_font_info(int type)
Поиск шрифтов
bool load_save(Common::SeekableReadStream *fh)
Загрузка данных из сэйва.
bool save_save(Common::WriteStream *stream) const
Запись данных в сэйв.
bool has_startup_scene() const
Возвращает true, если задана стартовая сцена игры.
Definition: qd_game_dispatcher.h:481
void toggle_exit()
Ставит флаг, что надо выйти из игры.
Definition: qd_game_dispatcher.h:437
bool add_font_info(qdFontInfo *fi)
Операции со шрифтами
bool need_restart() const
Возвращает true, если надо перезапустить игру.
Definition: qd_game_dispatcher.h:450
Mouse.
Definition: qd_game_object_mouse.h:34
Сцена.
Definition: qd_game_scene.h:47
bool has_main_menu() const
Возвращает true, если установлено имя экрана с главным меню игры.
Definition: qd_interface_dispatcher.h:125
const char * name() const
Возвращает имя объекта.
Definition: qd_named_object_base.h:40
Поименованный объект.
Definition: qd_named_object.h:70
void set_owner(qdNamedObject *p)
Устанавливает владельца объекта.
Definition: qd_named_object.h:86
bool check_flag(int fl) const
Возвращает true, если установлен флаг fl.
Definition: qd_named_object.h:99
void set_flag(int fl)
Устанавливает флаг.
Definition: qd_named_object.h:91
Диспетчер ресурсов.
Definition: qd_resource_dispatcher.h:32
XML тег.
Definition: xml_tag.h:33
Definition: list.h:39
In find(In first, In last, const T &v)
Definition: algorithm.h:225
Базовый класс для игровых ресурсов.
Definition: console.h:28
Definition: surface.h:67