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 AGS_GLOBALS_H 24 #define AGS_GLOBALS_H 25 26 #include "ags/shared/ac/game_version.h" 27 #include "ags/shared/util/stdio_compat.h" 28 #include "ags/shared/util/string.h" 29 #include "ags/shared/util/string_types.h" 30 #include "ags/shared/util/version.h" 31 #include "ags/shared/gui/gui_main.h" 32 #include "ags/shared/script/cc_script.h" 33 #include "ags/engine/ac/runtime_defines.h" 34 #include "ags/engine/ac/walk_behind.h" 35 #include "ags/engine/main/engine.h" 36 #include "ags/engine/media/audio/audio_defines.h" 37 #include "ags/engine/script/script.h" 38 #include "ags/engine/script/script_runtime.h" 39 #include "ags/lib/std/array.h" 40 #include "ags/lib/std/chrono.h" 41 #include "ags/lib/std/memory.h" 42 #include "ags/lib/std/set.h" 43 #include "ags/lib/allegro/color.h" 44 #include "ags/lib/allegro/fixed.h" 45 #include "ags/lib/allegro/aintern.h" 46 #include "common/events.h" 47 48 namespace Common { 49 class DumpFile; 50 } 51 52 namespace AGS3 { 53 54 #define MAXCURSORS 20 55 56 using String = AGS::Shared::String; 57 using Version = AGS::Shared::Version; 58 using StringMap = AGS::Shared::StringMap; 59 60 namespace AGS { 61 namespace Shared { 62 63 class AssetManager; 64 class Bitmap; 65 class DebugManager; 66 struct Font; 67 class GUIButton; 68 class GUIInvWindow; 69 class GUILabel; 70 class GUIListBox; 71 class GUISlider; 72 class GUITextBox; 73 struct InteractionVariable; 74 struct PlaneScaling; 75 class RoomStruct; 76 struct Translation; 77 78 } // namespace Shared 79 80 namespace Engine { 81 82 class ConsoleOutputTarget; 83 struct GfxFilterInfo; 84 class IDriverDependantBitmap; 85 class IGfxDriverFactory; 86 class IGraphicsDriver; 87 class LogFile; 88 class MessageBuffer; 89 90 } // namespace Engine 91 } // namespace AGS 92 93 namespace Plugins { 94 namespace Core { 95 class EngineExports; 96 } // namespace Core 97 } // namespace Plugins 98 99 class Navigation; 100 class SplitLines; 101 class SpriteCache; 102 class TTFFontRenderer; 103 class WFNFontRenderer; 104 105 struct ActiveDisplaySetting; 106 struct AGSDeSerializer; 107 struct AGSPlatformDriver; 108 struct AGSStaticObject; 109 struct AmbientSound; 110 struct AnimatingGUIButton; 111 struct CachedActSpsData; 112 struct CCAudioChannel; 113 struct CCAudioClip; 114 struct CCCharacter; 115 struct CCDialog; 116 struct CCDynamicArray; 117 struct CCGUI; 118 struct CCGUIObject; 119 struct CCHotspot; 120 struct ccInstance; 121 struct CCInventory; 122 struct CCObject; 123 struct CCRegion; 124 struct CharacterCache; 125 struct CharacterExtras; 126 struct CharacterInfo; 127 struct color; 128 struct COLOR_MAP; 129 struct CSCIMessage; 130 struct DialogTopic; 131 struct DirtyRects; 132 struct EnginePlugin; 133 struct ExecutingScript; 134 struct EventHappened; 135 struct GameFrameSetup; 136 struct GameSetup; 137 struct GameSetupStruct; 138 struct GameState; 139 struct IAGSEditorDebugger; 140 struct ICCStringClass; 141 struct ManagedObjectPool; 142 struct Mouse; 143 struct MoveList; 144 struct NewControl; 145 struct NonBlockingScriptFunction; 146 struct ObjectCache; 147 struct OnScreenWindow; 148 struct PluginObjectReader; 149 struct Point; 150 struct ResourcePaths; 151 struct RGB_MAP; 152 struct RoomCameraDrawData; 153 struct RoomObject; 154 struct RoomStatus; 155 struct RuntimeScriptValue; 156 struct ScreenOverlay; 157 struct ScriptAudioChannel; 158 struct ScriptDialog; 159 struct ScriptDialogOptionsRendering; 160 struct ScriptDrawingSurface; 161 struct ScriptGUI; 162 struct ScriptHotspot; 163 struct ScriptInvItem; 164 struct ScriptMouse; 165 struct ScriptObject; 166 struct ScriptPosition; 167 struct ScriptRegion; 168 struct ScriptString; 169 struct ScriptSystem; 170 struct SOUNDCLIP; 171 struct SpeechLipSyncLine; 172 struct SpriteListEntry; 173 struct StaticArray; 174 struct StaticGame; 175 struct SystemImports; 176 struct TopBarSettings; 177 struct ViewStruct; 178 179 class Globals { 180 public: 181 /** 182 * @defgroup agsglobals AGS Globals 183 * @ingroup agsengine 184 * @brief Globals for the AGS engine 185 */ 186 187 /** 188 * @defgroup agsallegroglobals Allegro globals 189 * @ingroup agsglobals 190 * @{ 191 */ 192 193 int _errnum = 0; 194 int *_allegro_errno = &_errnum; 195 196 int __color_depth = 0; 197 int __rgb_r_shift_15 = DEFAULT_RGB_R_SHIFT_15; /* truecolor pixel format */ 198 int __rgb_g_shift_15 = DEFAULT_RGB_G_SHIFT_15; 199 int __rgb_b_shift_15 = DEFAULT_RGB_B_SHIFT_15; 200 int __rgb_r_shift_16 = DEFAULT_RGB_R_SHIFT_16; 201 int __rgb_g_shift_16 = DEFAULT_RGB_G_SHIFT_16; 202 int __rgb_b_shift_16 = DEFAULT_RGB_B_SHIFT_16; 203 int __rgb_r_shift_24 = DEFAULT_RGB_R_SHIFT_24; 204 int __rgb_g_shift_24 = DEFAULT_RGB_G_SHIFT_24; 205 int __rgb_b_shift_24 = DEFAULT_RGB_B_SHIFT_24; 206 int __rgb_r_shift_32 = DEFAULT_RGB_R_SHIFT_32; 207 int __rgb_g_shift_32 = DEFAULT_RGB_G_SHIFT_32; 208 int __rgb_b_shift_32 = DEFAULT_RGB_B_SHIFT_32; 209 int __rgb_a_shift_32 = DEFAULT_RGB_A_SHIFT_32; 210 211 RGB_MAP *_rgb_map = nullptr; 212 COLOR_MAP *_color_map = nullptr; 213 int _trans_blend_alpha = 0; 214 int _trans_blend_red = 0; 215 int _trans_blend_green = 0; 216 int _trans_blend_blue = 0; 217 BlenderMode __blender_mode = kRgbToRgbBlender; 218 /* current format information and worker routines */ 219 int _utype = U_UTF8; 220 221 /* default palette structures */ 222 PALETTE _black_palette; 223 PALETTE _current_palette; 224 PALETTE _prev_current_palette; 225 226 volatile int _mouse_x = 0; // X position 227 volatile int _mouse_y = 0; // Y position 228 volatile int _mouse_z = 0; // Mouse wheel vertical 229 volatile int _mouse_b = 0; // Mouse buttons bitflags 230 volatile int _mouse_pos = 0; // X position in upper 16 bits, Y in lower 16 231 volatile int _sys_mouse_x = 0; // mouse x position 232 volatile int _sys_mouse_y = 0; // mouse y position 233 volatile int _sys_mouse_z = 0; // mouse wheel position 234 volatile int _freeze_mouse_flag = 0; 235 236 int _mouse_button_state = 0; 237 int _mouse_accum_button_state = 0; 238 uint32 _mouse_clear_at_time = 0; 239 int _mouse_accum_relx = 0, _mouse_accum_rely = 0; 240 int _wasbutdown = 0, _wasongui = 0; 241 242 /**@}*/ 243 244 /** 245 * @defgroup agsstaticobjectglobals agsstaticobject globals 246 * @ingroup agsglobals 247 * @{ 248 */ 249 250 std::unique_ptr<Shared::AssetManager> *_AssetMgr; 251 252 /**@}*/ 253 254 /** 255 * @defgroup agsplatformdriverglobals agsplatformdriver globals 256 * @ingroup agsglobals 257 * @{ 258 */ 259 260 // We don't have many places where we delay longer than a frame, but where we 261 // do, we should give the audio layer a chance to update. 262 // 16 milliseconds is rough period for 60fps 263 const std::chrono::milliseconds _MaximumDelayBetweenPolling = std::chrono::milliseconds(16); 264 265 /**@}*/ 266 267 /** 268 * @defgroup agspluginglobals agsplugin globals 269 * @ingroup agsglobals 270 * @{ 271 */ 272 273 AGS::Shared::Bitmap *_glVirtualScreenWrap; 274 275 /**@}*/ 276 277 /** 278 * @defgroup agsstaticobjectglobals agsstaticobject globals 279 * @ingroup agsglobals 280 * @{ 281 */ 282 283 AGSStaticObject *_GlobalStaticManager; 284 StaticGame *_GameStaticManager; 285 286 /**@}*/ 287 288 /** 289 * @defgroup agsaudioglobals audio globals 290 * @ingroup agsglobals 291 * @{ 292 */ 293 294 std::array<SOUNDCLIP *> *_audioChannels; 295 std::array<AmbientSound> *_ambient; 296 297 volatile bool _audio_doing_crossfade = false; 298 ScriptAudioChannel *_scrAudioChannel; 299 char _acaudio_buffer[256]; 300 int _reserved_channel_count = 0; 301 302 // This is an indicator of a music played by an old audio system 303 // (to distinguish from the new system API) 304 int _current_music_type = 0; 305 // _G(crossFading) is >0 (channel number of new track), or -1 (old 306 // track fading out, no new track) 307 int _crossFading = 0, _crossFadeVolumePerStep = 0, _crossFadeStep = 0; 308 int _crossFadeVolumeAtStart = 0; 309 SOUNDCLIP *_cachedQueuedMusic = nullptr; 310 311 // Music update is scheduled when the voice speech stops; 312 // we do a small delay before reverting any volume adjustments 313 bool _music_update_scheduled = false; 314 uint32 _music_update_at = 0; 315 316 /**@}*/ 317 318 /** 319 * @defgroup agsbuttonglobals button globals 320 * @ingroup agsglobals 321 * @{ 322 */ 323 324 AnimatingGUIButton *_animbuts; 325 int _numAnimButs = 0; 326 327 /**@}*/ 328 329 /** 330 * @defgroup agscc_dynamicarrayglobals cc_dynamicarray globals 331 * @ingroup agsglobals 332 * @{ 333 */ 334 335 CCDynamicArray *_globalDynamicArray; 336 337 /**@}*/ 338 339 /** 340 * @defgroup agscc_dynamicobjectglobals cc_dynamicobject globals 341 * @ingroup agsglobals 342 * @{ 343 */ 344 345 ICCStringClass *_stringClassImpl = nullptr; 346 347 /**@}*/ 348 349 /** 350 * @defgroup agscc_errorglobals cc_error globals 351 * @ingroup agsglobals 352 * @{ 353 */ 354 355 int _ccError = 0; 356 int _ccErrorLine = 0; 357 String _ccErrorString; 358 String _ccErrorCallStack; 359 bool _ccErrorIsUserError = false; 360 const char *_ccCurScriptName = ""; 361 362 /**@}*/ 363 364 /** 365 * @defgroup agscc_instanceglobals cc_instance globals 366 * @ingroup agsglobals 367 * @{ 368 */ 369 370 ccInstance *_current_instance = nullptr; 371 // [IKM] 2012-10-21: 372 // NOTE: This is temporary solution (*sigh*, one of many) which allows certain 373 // exported functions return value as a RuntimeScriptValue object; 374 // Of 2012-12-20: now used only for plugin exports 375 RuntimeScriptValue *_GlobalReturnValue; 376 Common::DumpFile *_scriptDumpFile = nullptr; 377 378 /**@}*/ 379 380 /** 381 * @defgroup agscc_optionsglobals cc_options globals 382 * @ingroup agsglobals 383 * @{ 384 */ 385 386 int _ccCompOptions; 387 388 /**@}*/ 389 390 /** 391 * @defgroup agscc_scriptglobals cc_script globals 392 * @ingroup agsglobals 393 * @{ 394 */ 395 396 // currently executed line 397 int _currentline = 0; 398 // script file format signature 399 const char *_scfilesig = "SCOM"; 400 401 /**@}*/ 402 403 /** 404 * @defgroup agscc_serializerglobals cc_serializer globals 405 * @ingroup agsglobals 406 * @{ 407 */ 408 409 AGSDeSerializer *_ccUnserializer; 410 411 /**@}*/ 412 413 /** 414 * @defgroup agscharacterglobals character globals 415 * @ingroup agsglobals 416 * @{ 417 */ 418 419 int _use_cdplayer = 0; 420 bool _triedToUseCdAudioCommand = false; 421 int _need_to_stop_cd = 0; 422 423 /**@}*/ 424 425 /** 426 * @defgroup agscharacterglobals character globals 427 * @ingroup agsglobals 428 * @{ 429 */ 430 431 CharacterExtras *_charextra = nullptr; 432 CharacterInfo *_playerchar = nullptr; 433 int32_t _sc_PlayerCharPtr = 0; 434 int _char_lowest_yp = 0; 435 436 // Sierra-style speech settings 437 int _face_talking = -1, _facetalkview = 0, _facetalkwait = 0, _facetalkframe = 0; 438 int _facetalkloop = 0, _facetalkrepeat = 0, _facetalkAllowBlink = 1; 439 int _facetalkBlinkLoop = 0; 440 CharacterInfo *_facetalkchar = nullptr; 441 // Do override default portrait position during QFG4-style speech overlay update 442 bool _facetalk_qfg4_override_placement_x = false; 443 bool _facetalk_qfg4_override_placement_y = false; 444 445 // lip-sync speech settings 446 int _loops_per_character = 0, _text_lips_offset = 0, _char_speaking = -1; 447 int _char_thinking = -1; 448 const char *_text_lips_text = nullptr; 449 SpeechLipSyncLine *_splipsync = nullptr; 450 int _numLipLines = 0, _curLipLine = -1, _curLipLinePhoneme = 0; 451 452 /**@}*/ 453 454 /** 455 * @defgroup agscscdialogglobals cscdialog globals 456 * @ingroup agsglobals 457 * @{ 458 */ 459 460 int _windowbackgroundcolor, _pushbuttondarkcolor; 461 int _pushbuttonlightcolor; 462 int _topwindowhandle = -1; 463 int _cbuttfont = 0; 464 int _acdialog_font = 0; 465 int _smcode = 0; 466 int _controlid = 0; 467 NewControl **_vobjs; 468 OnScreenWindow *_oswi; 469 470 int _windowcount = 0, _curswas = 0; 471 int _win_x = 0, _win_y = 0, _win_width = 0, _win_height = 0; 472 473 /**@}*/ 474 475 /** 476 * @defgroup agsdebugglobals debug globals 477 * @ingroup agsglobals 478 * @{ 479 */ 480 481 int _editor_debugging_enabled = 0; 482 int _editor_debugging_initialized = 0; 483 char _editor_debugger_instance_token[100]; 484 IAGSEditorDebugger *_editor_debugger = nullptr; 485 int _break_on_next_script_step = 0; 486 volatile int _game_paused_in_debugger = 0; 487 488 struct Breakpoint { 489 char scriptName[80] = { 0 }; 490 int lineNumber = 0; 491 }; 492 493 std::vector<Breakpoint> _breakpoints; 494 int _numBreakpoints = 0; 495 496 int _debug_flags = 0; 497 498 String *_debug_line; 499 int _first_debug_line = 0, _last_debug_line = 0, _display_console = 0; 500 501 float _fps; 502 int _display_fps; 503 std::unique_ptr<AGS::Engine::MessageBuffer> *_DebugMsgBuff; 504 std::unique_ptr<AGS::Engine::LogFile> *_DebugLogFile; 505 std::unique_ptr<AGS::Engine::ConsoleOutputTarget> *_DebugConsole; 506 507 /**@}*/ 508 509 /** 510 * @defgroup agsdebugglobals debug globals 511 * @ingroup agsglobals 512 * @{ 513 */ 514 515 AGS::Shared::DebugManager *_DbgMgr; 516 517 /**@}*/ 518 519 /** 520 * @defgroup agsdialogglobals dialog globals 521 * @ingroup agsglobals 522 * @{ 523 */ 524 525 DialogTopic *_dialog = nullptr; 526 ScriptDialogOptionsRendering *_ccDialogOptionsRendering; 527 ScriptDrawingSurface *_dialogOptionsRenderingSurface = nullptr; 528 529 int _said_speech_line = 0; // used while in dialog to track whether screen needs updating 530 int _said_text = 0; 531 int _longestline = 0; 532 // Old dialog support 533 std::vector< std::shared_ptr<unsigned char> > _old_dialog_scripts; 534 std::vector<String> _old_speech_lines; 535 536 /**@}*/ 537 538 /** 539 * @defgroup agsdisplayglobals display globals 540 * @ingroup agsglobals 541 * @{ 542 */ 543 544 int _display_message_aschar = 0; 545 int _source_text_length = -1; 546 547 TopBarSettings *_topBar; 548 struct DisplayVars { 549 int lineheight = 0; // font's height of single line 550 int linespacing = 0; // font's line spacing 551 int fulltxtheight = 0; // total height of all the text 552 } _disp; 553 554 /**@}*/ 555 556 /** 557 * @defgroup agsdrawglobals draw globals 558 * @ingroup agsglobals 559 * @{ 560 */ 561 562 std::vector<RoomCameraDrawData> *_CameraDrawData; 563 std::vector<SpriteListEntry> *_sprlist; 564 std::vector<SpriteListEntry> *_thingsToDrawList; 565 566 AGS::Engine::IGraphicsDriver *_gfxDriver = nullptr; 567 AGS::Engine::IDriverDependantBitmap *_blankImage = nullptr; 568 AGS::Engine::IDriverDependantBitmap *_blankSidebarImage = nullptr; 569 AGS::Engine::IDriverDependantBitmap *_debugConsole = nullptr; 570 571 // actsps is used for temporary storage of the bitamp image 572 // of the latest version of the sprite 573 int _actSpsCount = 0; 574 AGS::Shared::Bitmap **_actsps = nullptr; 575 AGS::Engine::IDriverDependantBitmap **_actspsbmp = nullptr; 576 // temporary cache of walk-behind for this actsps image 577 AGS::Shared::Bitmap **_actspswb = nullptr; 578 AGS::Engine::IDriverDependantBitmap **_actspswbbmp = nullptr; 579 CachedActSpsData *_actspswbcache = nullptr; 580 bool _current_background_is_dirty = false; 581 // Room background sprite 582 AGS::Engine::IDriverDependantBitmap *_roomBackgroundBmp = nullptr; 583 AGS::Shared::Bitmap **_guibg = nullptr; 584 AGS::Engine::IDriverDependantBitmap **_guibgbmp = nullptr; 585 AGS::Shared::Bitmap *_debugConsoleBuffer = nullptr; 586 // whether there are currently remnants of a DisplaySpeech 587 bool _screen_is_dirty = false; 588 AGS::Shared::Bitmap *_raw_saved_screen = nullptr; 589 AGS::Shared::Bitmap **_dynamicallyCreatedSurfaces = nullptr; 590 int _places_r = 3, _places_g = 2, _places_b = 3; 591 color *_palette; 592 COLOR_MAP *_maincoltable; 593 594 /**@}*/ 595 596 /** 597 * @defgroup agsdraw_softwareglobals draw_software globals 598 * @ingroup agsglobals 599 * @{ 600 */ 601 602 // Dirty rects for the game screen background (black screen); 603 // these are used when the room viewport does not cover whole screen, 604 // so that we know when to paint black after mouse cursor and gui. 605 DirtyRects *_BlackRects; 606 Point *_GlobalOffs; 607 // Dirty rects object for the single room camera 608 std::vector<DirtyRects> *_RoomCamRects; 609 // Saved room camera offsets to know if we must invalidate whole surface. 610 // TODO: if we support rotation then we also need to compare full transform! 611 std::vector<std::pair<int, int> > *_RoomCamPositions; 612 613 /**@}*/ 614 615 /** 616 * @defgroup agsengineglobals engine globals 617 * @ingroup agsglobals 618 * @{ 619 */ 620 621 bool _check_dynamic_sprites_at_exit = true; 622 623 /**@}*/ 624 625 /** 626 * @defgroup agsengineglobals engine globals 627 * @ingroup agsglobals 628 * @{ 629 */ 630 631 ResourcePaths *_ResPaths; 632 t_engine_pre_init_callback _engine_pre_init_callback = nullptr; 633 634 /**@}*/ 635 636 /** 637 * @defgroup agsengine_setupglobals engine_setup globals 638 * @ingroup agsglobals 639 * @{ 640 */ 641 642 int _convert_16bit_bgr = 0; 643 644 /**@}*/ 645 646 647 /** 648 * @defgroup agseventglobals event globals 649 * @ingroup agsglobals 650 * @{ 651 */ 652 653 int _in_enters_screen = 0, _done_es_error = 0; 654 int _in_leaves_screen = -1; 655 656 EventHappened *_event; 657 int _numevents = 0; 658 659 const char *_evblockbasename = nullptr; 660 int _evblocknum = 0; 661 662 int _inside_processevent = 0; 663 int _eventClaimed = 0; 664 665 const char *_tsnames[4] = { nullptr, REP_EXEC_NAME, "on_key_press", "on_mouse_click" }; 666 667 /**@}*/ 668 669 /** 670 * @defgroup agsfileglobals file globals 671 * @ingroup agsglobals 672 * @{ 673 */ 674 675 // TODO: the asset path configuration should certainly be revamped at some 676 // point, with uniform method of configuring auxiliary paths and packages. 677 // Installation directory, may contain absolute or relative path 678 String _installDirectory; 679 // Installation directory, containing audio files 680 String _installAudioDirectory; 681 // Installation directory, containing voice-over files 682 String _installVoiceDirectory; 683 684 /**@}*/ 685 686 /** 687 * @defgroup agsfontsglobals fonts globals 688 * @ingroup agsglobals 689 * @{ 690 */ 691 692 std::vector<AGS::Shared::Font> *_fonts; 693 TTFFontRenderer *_ttfRenderer; 694 WFNFontRenderer *_wfnRenderer; 695 SplitLines *_Lines; 696 697 /**@}*/ 698 699 /** 700 * @defgroup agsgameglobals game globals 701 * @ingroup agsglobals 702 * @{ 703 */ 704 705 GameSetupStruct *_game; 706 GameState *_play; 707 SpriteCache *_spriteset; 708 AGS::Shared::RoomStruct *_thisroom; 709 RoomStatus *_troom; // used for non-saveable rooms, eg. intro 710 711 std::vector<AGS::Shared::GUIMain> *_guis; 712 CCGUIObject *_ccDynamicGUIObject; 713 CCCharacter *_ccDynamicCharacter; 714 CCHotspot *_ccDynamicHotspot; 715 CCRegion *_ccDynamicRegion; 716 CCInventory *_ccDynamicInv; 717 CCGUI *_ccDynamicGUI; 718 CCObject *_ccDynamicObject; 719 CCDialog *_ccDynamicDialog; 720 CCAudioClip *_ccDynamicAudioClip; 721 CCAudioChannel *_ccDynamicAudio; 722 ScriptString *_myScriptStringImpl; 723 724 // TODO: IMPORTANT!! 725 // we cannot simply replace these arrays with vectors, or other C++ containers, 726 // until we implement safe management of such containers in script exports 727 // system. Noteably we would need an alternate to StaticArray class to track 728 // access to their elements. 729 ScriptObject *_scrObj; 730 ScriptGUI *_scrGui = nullptr; 731 ScriptHotspot *_scrHotspot; 732 ScriptRegion *_scrRegion; 733 ScriptInvItem *_scrInv; 734 ScriptDialog *_scrDialog = nullptr; 735 ViewStruct *_views = nullptr; 736 CharacterCache *_charcache = nullptr; 737 ObjectCache *_objcache; 738 MoveList *_mls = nullptr; 739 GameSetup *_usetup; 740 AGS::Shared::String _saveGameDirectory; 741 AGS::Shared::String _saveGameParent; 742 AGS::Shared::String _saveGameSuffix; 743 bool _want_exit = false; 744 bool _abort_engine = false; 745 AGSPlatformDriver *_platform = nullptr; 746 747 RoomObject *_objs = nullptr; 748 RoomStatus *_croom = nullptr; 749 750 volatile int _switching_away_from_game = 0; 751 volatile bool _switched_away = false; 752 int _frames_per_second = 40; 753 int _displayed_room = -10, _starting_room = -1; 754 int _in_new_room = 0, _new_room_was = 0; // 1 in new room, 2 first time in new room, 3 loading saved game 755 int _new_room_pos = 0; 756 int _new_room_x = SCR_NO_VALUE, _new_room_y = SCR_NO_VALUE; 757 int _new_room_loop = SCR_NO_VALUE; 758 bool _proper_exit = true; 759 int _our_eip = 0; 760 761 int _oldmouse = 0; 762 GameDataVersion _loaded_game_file_version = kGameVersion_Undefined; 763 int _game_paused = 0; 764 char _pexbuf[STD_BUFFER_SIZE] = { 0 }; 765 unsigned int _load_new_game = 0; 766 int _load_new_game_restore = -1; 767 // TODO: refactor these global vars into function arguments 768 int _getloctype_index = 0, _getloctype_throughgui = 0; 769 char _gamefilenamebuf[200] = { 0 }; 770 int _gameHasBeenRestored = 0; 771 int _oldeip = 0; 772 int _game_update_suspend = 0; 773 bool _new_room_placeonwalkable = false; 774 775 /**@}*/ 776 777 /** 778 * @defgroup agsgame_initglobals game_init globals 779 * @ingroup agsglobals 780 * @{ 781 */ 782 783 StaticArray *_StaticCharacterArray; 784 StaticArray *_StaticObjectArray; 785 StaticArray *_StaticGUIArray; 786 StaticArray *_StaticHotspotArray; 787 StaticArray *_StaticRegionArray; 788 StaticArray *_StaticInventoryArray; 789 StaticArray *_StaticDialogArray; 790 791 /**@}*/ 792 793 /** 794 * @defgroup agsgame_runglobals game_run globals 795 * @ingroup agsglobals 796 * @{ 797 */ 798 799 // Following 3 parameters instruct the engine to run game loops until 800 // certain condition is not fullfilled. 801 int _restrict_until = 0; 802 int _user_disabled_for = 0; 803 const void *_user_disabled_data = nullptr; 804 805 unsigned int _loopcounter = 0; 806 unsigned int _lastcounter = 0; 807 int _numEventsAtStartOfFunction = 0; 808 uint32 _t1 = 0; // timer for FPS 809 int _old_key_shifts = 0; // for saving shift modes 810 811 /**@}*/ 812 813 /** 814 * @defgroup agsgfxfilter_aad3dglobals gfxfilter_aad3d globals 815 * @ingroup agsglobals 816 * @{ 817 */ 818 819 const AGS::Engine::GfxFilterInfo *_aad3dFilterInfo; 820 821 /**@}*/ 822 823 /** 824 * @defgroup agsgfxfilter_allegroglobals gfxfilter_allegro globals 825 * @ingroup agsglobals 826 * @{ 827 */ 828 829 const AGS::Engine::GfxFilterInfo *_allegroFilterInfo; 830 831 /**@}*/ 832 833 /** 834 * @defgroup agsgfxfilter_allegroglobals gfxfilter_allegro globals 835 * @ingroup agsglobals 836 * @{ 837 */ 838 839 const AGS::Engine::GfxFilterInfo *_hqxFilterInfo; 840 841 /**@}*/ 842 843 /** 844 * @defgroup agsgfxfilter_d3dglobals gfxfilter_d3d globals 845 * @ingroup agsglobals 846 * @{ 847 */ 848 849 const AGS::Engine::GfxFilterInfo *_d3dFilterInfo; 850 851 /**@}*/ 852 853 /** 854 * @defgroup agsglobal_dialogglobals global_dialog globals 855 * @ingroup agsglobals 856 * @{ 857 */ 858 859 ScriptPosition *_last_in_dialog_request_script_pos; 860 861 /**@}*/ 862 863 /** 864 * @defgroup agsglobal_objectglobals global_object globals 865 * @ingroup agsglobals 866 * @{ 867 */ 868 869 // Used for deciding whether a char or obj was closer 870 int _obj_lowest_yp = 0; 871 872 /**@}*/ 873 874 /** 875 * @defgroup agsgraphics_modeglobals graphics_mode globals 876 * @ingroup agsglobals 877 * @{ 878 */ 879 880 AGS::Engine::IGfxDriverFactory *_GfxFactory = nullptr; 881 882 // Last saved fullscreen and windowed configs; they are used when switching 883 // between between fullscreen and windowed modes at runtime. 884 // If particular mode is modified, e.g. by script command, related config should be overwritten. 885 ActiveDisplaySetting *_SavedFullscreenSetting; 886 ActiveDisplaySetting *_SavedWindowedSetting; 887 // Current frame scaling setup 888 GameFrameSetup *_CurFrameSetup; 889 // The game-to-screen transformation 890 AGS::Shared::PlaneScaling *_GameScaling; 891 892 /**@}*/ 893 894 /** 895 * @defgroup agsguiglobals gui globals 896 * @ingroup agsglobals 897 * @{ 898 */ 899 900 int _ifacepopped = -1; // currently displayed pop-up GUI (-1 if none) 901 int _mouse_on_iface = -1; // mouse cursor is over this interface 902 int _mouse_ifacebut_xoffs = -1, _mouse_ifacebut_yoffs = -1; 903 int _eip_guinum = 0, _eip_guiobj = 0; 904 905 /**@}*/ 906 907 /** 908 * @defgroup agsguibuttonglobals guibutton globals 909 * @ingroup agsglobals 910 * @{ 911 */ 912 913 std::vector<AGS::Shared::GUIButton> *_guibuts; 914 int _numguibuts = 0; 915 916 /**@}*/ 917 918 /** 919 * @defgroup agsguidialogglobals guidialog globals 920 * @ingroup agsglobals 921 * @{ 922 */ 923 924 // TODO: store drawing surface inside old gui classes instead 925 int _windowPosX = 0, _windowPosY = 0, _windowPosWidth = 0, _windowPosHeight = 0; 926 AGS::Shared::Bitmap *_windowBuffer = nullptr; 927 AGS::Engine::IDriverDependantBitmap *_dialogDDB = nullptr; 928 929 #define MAXSAVEGAMES_20 20 930 int _myscrnwid = 320, _myscrnhit = 200; 931 char *_lpTemp = nullptr, *_lpTemp2 = nullptr; 932 int _numsaves = 0, _toomanygames = 0; 933 int _filenumbers[MAXSAVEGAMES_20]; 934 unsigned long _filedates[MAXSAVEGAMES_20]; 935 char _bufTemp[260], _buffer2[260]; 936 char _buff[200]; 937 CSCIMessage *_smes; 938 939 /**@}*/ 940 941 /** 942 * @defgroup agsguiinvglobals guiinv globals 943 * @ingroup agsglobals 944 * @{ 945 */ 946 947 std::vector<AGS::Shared::GUIInvWindow> *_guiinv; 948 int _numguiinv = 0; 949 950 /**@}*/ 951 952 /** 953 * @defgroup agsguilabelglobals guilabel globals 954 * @ingroup agsglobals 955 * @{ 956 */ 957 958 std::vector<AGS::Shared::GUILabel> *_guilabels; 959 int _numguilabels = 0; 960 961 /**@}*/ 962 963 /** 964 * @defgroup agsguilistboxglobals guilistbox globals 965 * @ingroup agsglobals 966 * @{ 967 */ 968 969 std::vector<AGS::Shared::GUIListBox> *_guilist; 970 int _numguilist = 0; 971 972 /**@}*/ 973 974 /** 975 * @defgroup agsguimainglobals guimain globals 976 * @ingroup agsglobals 977 * @{ 978 */ 979 980 int _guis_need_update = 1; 981 int _all_buttons_disabled = 0, _gui_inv_pic = -1; 982 int _gui_disabled_style = 0; 983 984 /**@}*/ 985 986 /** 987 * @defgroup agsguisliderglobals guislider globals 988 * @ingroup agsglobals 989 * @{ 990 */ 991 992 std::vector<AGS::Shared::GUISlider> *_guislider; 993 int _numguislider = 0; 994 995 /**@}*/ 996 997 /** 998 * @defgroup agsguitextboxglobals guitextbox globals 999 * @ingroup agsglobals 1000 * @{ 1001 */ 1002 1003 std::vector<AGS::Shared::GUITextBox> *_guitext; 1004 int _numguitext = 0; 1005 1006 /**@}*/ 1007 1008 /** 1009 * @defgroup agsinteractionsglobals interactions globals 1010 * @ingroup agsglobals 1011 * @{ 1012 */ 1013 1014 AGS::Shared::InteractionVariable *_globalvars; 1015 int _numGlobalVars = 1; 1016 1017 /**@}*/ 1018 1019 /** 1020 * @defgroup agsinvwindowglobals invwindow globals 1021 * @ingroup agsglobals 1022 * @{ 1023 */ 1024 1025 int _in_inv_screen = 0, _inv_screen_newroom = -1; 1026 1027 /**@}*/ 1028 1029 /** 1030 * @defgroup agslzwglobals lzw globals 1031 * @ingroup agsglobals 1032 * @{ 1033 */ 1034 1035 char *_lzbuffer = nullptr; 1036 int *_node = nullptr; 1037 int _pos = 0; 1038 long _outbytes = 0, _maxsize = 0, _putbytes = 0; 1039 1040 /**@}*/ 1041 1042 /** 1043 * @defgroup agsmainglobals main globals 1044 * @ingroup agsglobals 1045 * @{ 1046 */ 1047 1048 String _appPath; 1049 String _appDirectory; // Needed for library loading 1050 String _cmdGameDataPath; 1051 1052 const char **_global_argv = nullptr; 1053 int _global_argc = 0; 1054 1055 // Startup flags, set from parameters to engine 1056 int _force_window = 0; 1057 int _override_start_room = 0; 1058 bool _justDisplayHelp = false; 1059 bool _justDisplayVersion = false; 1060 bool _justRunSetup = false; 1061 bool _justRegisterGame = false; 1062 bool _justUnRegisterGame = false; 1063 bool _justTellInfo = false; 1064 std::set<String> _tellInfoKeys; 1065 int _loadSaveGameOnStartup = -1; 1066 1067 #if ! AGS_PLATFORM_DEFINES_PSP_VARS 1068 int _psp_video_framedrop = 1; 1069 int _psp_ignore_acsetup_cfg_file = 0; 1070 int _psp_clear_cache_on_room_change = 0; // clear --sprite cache-- when room is unloaded 1071 1072 #if AGS_PLATFORM_SCUMMVM 1073 int _psp_audio_cachesize = 10; 1074 #endif 1075 const char *_psp_game_file_name = ""; 1076 const char *_psp_translation = "default"; 1077 1078 int _psp_gfx_renderer = 0; 1079 int _psp_gfx_scaling = 1; 1080 int _psp_gfx_smoothing = 0; 1081 int _psp_gfx_super_sampling = 1; 1082 int _psp_gfx_smooth_sprites = 0; 1083 #endif 1084 1085 // Current engine version 1086 Version _EngineVersion; 1087 // Lowest savedgame version, accepted by this engine 1088 Version _SavedgameLowestBackwardCompatVersion; 1089 // Lowest engine version, which would accept current savedgames 1090 Version _SavedgameLowestForwardCompatVersion; 1091 1092 /**@}*/ 1093 1094 /** 1095 * @defgroup agsmanagedobjectpoolglobals managedobjectpool globals 1096 * @ingroup agsglobals 1097 * @{ 1098 */ 1099 1100 ManagedObjectPool *_pool; 1101 1102 /**@}*/ 1103 1104 /** 1105 * @defgroup agsmouseglobals mouse globals 1106 * @ingroup agsglobals 1107 * @{ 1108 */ 1109 1110 int8 _currentcursor = 0; 1111 // virtual mouse cursor coordinates 1112 int _mousex = 0, _mousey = 0, _numcurso = -1, _hotx = 0, _hoty = 0; 1113 // real mouse coordinates and bounds 1114 int _real_mouse_x = 0, _real_mouse_y = 0; 1115 int _boundx1 = 0, _boundx2 = 99999, _boundy1 = 0, _boundy2 = 99999; 1116 int _disable_mgetgraphpos = 0; 1117 int8 _ignore_bounds = 0; 1118 AGS::Shared::Bitmap *_mousecurs[MAXCURSORS]; 1119 1120 ScriptMouse *_scmouse; 1121 int _cur_mode = 0, _cur_cursor = 0; 1122 int _mouse_frame = 0, _mouse_delay = 0; 1123 int _lastmx = -1, _lastmy = -1; 1124 int8 _alpha_blend_cursor = 0; 1125 AGS::Shared::Bitmap *_dotted_mouse_cursor = nullptr; 1126 AGS::Engine::IDriverDependantBitmap *_mouseCursor = nullptr; 1127 AGS::Shared::Bitmap *_blank_mouse_cursor = nullptr; 1128 1129 /**@}*/ 1130 1131 /** 1132 * @defgroup agsmousew32globals mousew32 globals 1133 * @ingroup agsglobals 1134 * @{ 1135 */ 1136 1137 int _butwas = 0; 1138 int _hotxwas = 0, _hotywas = 0; 1139 Mouse *_mouse; 1140 1141 /**@}*/ 1142 1143 /** 1144 * @defgroup agsoverlayglobals overlay globals 1145 * @ingroup agsglobals 1146 * @{ 1147 */ 1148 1149 ScreenOverlay *_screenover; 1150 int _is_complete_overlay = 0; 1151 int _numscreenover = 0; 1152 1153 /**@}*/ 1154 1155 /** 1156 * @defgroup agsquitglobals quit globals 1157 * @ingroup agsglobals 1158 * @{ 1159 */ 1160 1161 PluginObjectReader *_pluginReaders; 1162 int _numPluginReaders = 0; 1163 1164 /**@}*/ 1165 1166 /** 1167 * @defgroup agsquitglobals quit globals 1168 * @ingroup agsglobals 1169 * @{ 1170 */ 1171 1172 bool _handledErrorInEditor = false; 1173 char _return_to_roomedit[30] = { '\0' }; 1174 char _return_to_room[150] = { '\0' }; 1175 char _quit_message[256] = { '\0' }; 1176 1177 /**@}*/ 1178 1179 /** 1180 * @defgroup agsroomglobals room globals 1181 * @ingroup agsglobals 1182 * @{ 1183 */ 1184 1185 RGB_MAP *_rgb_table; // for 256-col antialiasing 1186 int _new_room_flags = 0; 1187 int _gs_to_newroom = -1; 1188 int _bg_just_changed = 0; 1189 1190 /**@}*/ 1191 1192 /** 1193 * @defgroup agsroute_finder_implglobals route_finder_impl globals 1194 * @ingroup agsglobals 1195 * @{ 1196 */ 1197 1198 int32_t *_navpoints; 1199 Navigation *_nav; 1200 int _num_navpoints = 0; 1201 fixed _move_speed_x = 0, _move_speed_y = 0; 1202 AGS::Shared::Bitmap *_wallscreen = nullptr; 1203 int _lastcx = 0, _lastcy = 0; 1204 1205 /**@}*/ 1206 1207 /** 1208 * @defgroup agsscreenglobals screen globals 1209 * @ingroup agsglobals 1210 * @{ 1211 */ 1212 1213 // Screenshot made in the last room, used during some of the transition effects 1214 AGS::Shared::Bitmap *_saved_viewport_bitmap = nullptr; 1215 color *_old_palette; 1216 1217 /**@}*/ 1218 1219 /** 1220 * @defgroup agsscriptglobal script globals 1221 * @ingroup agsglobals 1222 * @{ 1223 */ 1224 1225 ExecutingScript *_scripts; 1226 ExecutingScript *_curscript = nullptr; 1227 1228 PScript *_gamescript; 1229 PScript *_dialogScriptsScript; 1230 ccInstance *_gameinst = nullptr, *_roominst = nullptr; 1231 ccInstance *_dialogScriptsInst = nullptr; 1232 ccInstance *_gameinstFork = nullptr, *_roominstFork = nullptr; 1233 1234 int _num_scripts = 0; 1235 int _post_script_cleanup_stack = 0; 1236 1237 int _inside_script = 0, _in_graph_script = 0; 1238 int _no_blocking_functions = 0; // set to 1 while in rep_Exec_always 1239 1240 NonBlockingScriptFunction *_repExecAlways; 1241 NonBlockingScriptFunction *_lateRepExecAlways; 1242 NonBlockingScriptFunction *_getDialogOptionsDimensionsFunc; 1243 NonBlockingScriptFunction *_renderDialogOptionsFunc; 1244 NonBlockingScriptFunction *_getDialogOptionUnderCursorFunc; 1245 NonBlockingScriptFunction *_runDialogOptionMouseClickHandlerFunc; 1246 NonBlockingScriptFunction *_runDialogOptionKeyPressHandlerFunc; 1247 NonBlockingScriptFunction *_runDialogOptionRepExecFunc; 1248 1249 ScriptSystem *_scsystem; 1250 1251 std::vector<PScript> *_scriptModules; 1252 std::vector<ccInstance *> *_moduleInst; 1253 std::vector<ccInstance *> *_moduleInstFork; 1254 std::vector<RuntimeScriptValue> *_moduleRepExecAddr; 1255 int _numScriptModules = 0; 1256 1257 // TODO: find out if these extra arrays are really necessary. This may be remains from the 1258 // time when the symbol import table was holding raw pointers to char array. 1259 std::vector<String> *_characterScriptObjNames; 1260 String *_objectScriptObjNames; 1261 std::vector<String> *_guiScriptObjNames; 1262 1263 /**@}*/ 1264 1265 /** 1266 * @defgroup agsscript_runtimeglobals script_runtime globals 1267 * @ingroup agsglobals 1268 * @{ 1269 */ 1270 1271 new_line_hook_type _new_line_hook = nullptr; 1272 int _maxWhileLoops = 0; 1273 ccInstance *_loadedInstances[MAX_LOADED_INSTANCES]; 1274 1275 /**@}*/ 1276 1277 /** 1278 * @defgroup agsstringglobals string globals 1279 * @ingroup agsglobals 1280 * @{ 1281 */ 1282 1283 int _MAXSTRLEN = MAX_MAXSTRLEN; 1284 1285 /**@}*/ 1286 1287 /** 1288 * @defgroup agssystemimportsglobals systemimports globals 1289 * @ingroup agsglobals 1290 * @{ 1291 */ 1292 1293 SystemImports *_simp; 1294 SystemImports *_simp_for_plugin; 1295 1296 /**@}*/ 1297 1298 /** 1299 * @defgroup agssys_eventsglobals sys_events globals 1300 * @ingroup agsglobals 1301 * @{ 1302 */ 1303 1304 Plugins::Core::EngineExports *_engineExports; 1305 Common::Array<EnginePlugin> *_plugins; 1306 int _pluginsWantingDebugHooks = 0; 1307 long _pl_file_handle = -1; 1308 AGS::Shared::Stream *_pl_file_stream = nullptr; 1309 1310 int _pluginSimulatedClick = -1; 1311 int _mouse_z_was = 0; 1312 1313 /**@}*/ 1314 1315 /** 1316 * @defgroup agstimerglobals timer globals 1317 * @ingroup agsglobals 1318 * @{ 1319 */ 1320 1321 std::chrono::microseconds _tick_duration = std::chrono::microseconds(1000000LL / 40); 1322 bool _framerate_maxed = false; 1323 1324 uint32 _last_tick_time = 0; // AGS_Clock::now(); 1325 uint32 _next_frame_timestamp = 0; // AGS_Clock::now(); 1326 1327 /**@}*/ 1328 1329 /** 1330 * @defgroup agstranslationglobals translation globals 1331 * @ingroup agsglobals 1332 * @{ 1333 */ 1334 1335 AGS::Shared::Translation *_trans; 1336 StringMap *_transtree = nullptr; 1337 String _trans_name, _trans_filename; 1338 long _lang_offs_start = 0; 1339 char _transFileName[MAX_PATH_SZ] = { 0 }; 1340 std::vector<uint16> _wcsbuf; // widechar buffer 1341 std::vector<char> _mbbuf; // utf8 buffer 1342 1343 /**@}*/ 1344 1345 /** 1346 * @defgroup agswalkableareaglobals walkablearea globals 1347 * @ingroup agsglobals 1348 * @{ 1349 */ 1350 1351 AGS::Shared::Bitmap *_walkareabackup = nullptr, *_walkable_areas_temp = nullptr; 1352 1353 /**@}*/ 1354 1355 /** 1356 * @defgroup agswalkbehindglobals walkbehind globals 1357 * @ingroup agsglobals 1358 * @{ 1359 */ 1360 1361 char *_walkBehindExists = nullptr; // whether a WB area is in this column 1362 int *_walkBehindStartY = nullptr, *_walkBehindEndY = nullptr; 1363 int8 _noWalkBehindsAtAll = 0; 1364 int _walkBehindLeft[MAX_WALK_BEHINDS], _walkBehindTop[MAX_WALK_BEHINDS]; 1365 int _walkBehindRight[MAX_WALK_BEHINDS], _walkBehindBottom[MAX_WALK_BEHINDS]; 1366 AGS::Engine::IDriverDependantBitmap *_walkBehindBitmap[MAX_WALK_BEHINDS]; 1367 int _walkBehindsCachedForBgNum = 0; 1368 WalkBehindMethodEnum _walkBehindMethod = DrawOverCharSprite; 1369 int _walk_behind_baselines_changed = 0; 1370 1371 /**@}*/ 1372 1373 /** 1374 * @defgroup agswordsdictionaryglobals wordsdictionary globals 1375 * @ingroup agsglobals 1376 * @{ 1377 */ 1378 1379 const char *_passwencstring = "Avis Durgan"; 1380 1381 /**@}*/ 1382 1383 public: 1384 Globals(); 1385 ~Globals(); 1386 }; 1387 1388 extern Globals *g_globals; 1389 1390 // Macro for accessing a globals member 1391 #define _G(FIELD) (::AGS3::g_globals->_##FIELD) 1392 // Macro for accessing a globals member that was an object in the original, 1393 // but is a pointer to the object in ScummVM, so that we don't need to 1394 // provide the full class/struct definition here in the header file 1395 #define _GP(FIELD) (*::AGS3::g_globals->_##FIELD) 1396 1397 } // namespace AGS3 1398 1399 #endif 1400