1 /* 2 3 Copyright (C) 2015-2018 Night Dive Studios, LLC. 4 5 This program is free software: you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation, either version 3 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 */ 19 #ifndef __MAINLOOP_H 20 #define __MAINLOOP_H 21 22 #include "gameloop.h" 23 #include "frtypesx.h" 24 25 #define QUIT_LOOP -1 26 #define GAME_LOOP 0 27 #define FULLSCREEN_LOOP 1 28 #define EDIT_LOOP 2 29 #define CYBER_LOOP 3 30 #define SETUP_LOOP 4 31 #define MWORK_LOOP 5 32 #define CUTSCENE_LOOP 6 33 #define SVGA_LOOP 7 34 #define AUTOMAP_LOOP 8 35 36 #define ML 0x1000 37 #define GL 0x1100 38 #define EL 0x1200 39 #define CL 0x1400 40 #define SL 0x1800 41 #define WL 0x2000 42 #define FL 0x2100 43 #define AL 0x2200 44 45 #define ML_CHG_MASK 0xF000u /* mask for main loop bits in change_flag */ 46 #define ML_CHG_BASE 0x1000u /* mask for single main loop bit of change_flag */ 47 #define LL_CHG_MASK 0x0FFFu /* mask for local loop bits of change_flag */ 48 #define LL_CHG_BASE 0x0001u /* mask for single local loop bit out of change_flag */ 49 50 #define chg_set_flg(x) (_change_flag |= x) 51 #define chg_get_flg(x) (_change_flag & x) 52 #define chg_unset_flg(x) (_change_flag &= ~(x)) 53 54 #define chg_set_sta(x) (_static_change |= x) 55 #define chg_get_sta(x) (_static_change & x) 56 #define chg_unset_sta(x) (_static_change &= ~(x)) 57 58 #define GL_CHG_1 (ML_CHG_BASE << 0u) 59 #define GL_CHG_2 (ML_CHG_BASE << 1u) 60 #define GL_CHG_3 (ML_CHG_BASE << 2u) 61 #define GL_CHG_LOOP (ML_CHG_BASE << 3u) 62 63 void mainloop(int argc, char *argv[]); 64 void loopmode_switch(short *cmode); 65 errtype static_change_copy(); 66 void loopmode_exit(short loopmode); 67 void loopmode_enter(short loopmode); 68 69 #ifdef __MAINLOOP_SRC 70 frc *_current_fr_context; 71 short _current_loop = SETUP_LOOP; /* which loop we currently are */ 72 short _current_3d_flag = DEMOVIEW_UPDATE; 73 LGRegion *_current_view = NULL; 74 uint _change_flag = 0; /* change flags for loop */ 75 uint _static_change = 0; /* current static changes */ 76 short _new_mode = 0; /* mode to change to, if any */ 77 short _last_mode = 0; /* last mode, if you want to change back to it */ 78 uchar time_passes = TRUE; 79 uchar saves_allowed = FALSE; 80 uchar physics_running = TRUE; 81 uchar ai_on = TRUE; 82 uchar anim_on = TRUE; 83 uchar player_invulnerable = FALSE; 84 uchar player_immortal = FALSE; 85 uchar always_render = FALSE; 86 uchar pal_fx_on = TRUE; 87 88 #else // NOT _MAINLOOP_SRC 89 90 extern short _current_loop; // which loop we currently are 91 extern short _current_3d_flag; 92 extern frc *_current_fr_context; 93 #ifdef GADGET 94 extern Gadget *_current_root; 95 #endif 96 extern uint _change_flag; // change flags for loop 97 extern uint _static_change; // current static changes 98 extern short _new_mode; // mode to change to, if any 99 extern short _last_mode; // last mode we were in, to switch back to 100 extern uchar player_invulnerable; 101 extern uchar player_immortal; 102 extern uchar physics_running; 103 extern uchar ai_on; 104 extern uchar anim_on; 105 extern uchar always_render; 106 extern uchar saves_allowed; 107 extern uchar time_passes; 108 extern uchar pal_fx_on; 109 extern LGRegion *_current_view; 110 #endif 111 112 #define loopLine(num, code_line) code_line 113 114 #define localChanges (_change_flag & LL_CHG_MASK) 115 #define globalChanges (_change_flag & ML_CHG_MASK) 116 117 #endif 118