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 /*
20 * $Source: r:/prj/cit/src/RCS/gameloop.c $
21 * $Revision: 1.32 $
22 * $Author: dc $
23 * $Date: 1994/11/19 20:35:51 $
24 */
25
26 #include <string.h>
27
28 #include "mainloop.h"
29 #include "wares.h"
30 #include "hud.h"
31 #include "ai.h"
32 #include "physics.h"
33 #include "gamesys.h"
34 #include "gametime.h"
35 #include "status.h"
36 #include "render.h"
37 #include "musicai.h"
38 #include "MacTune.h"
39 #include "newmfd.h"
40 #include "faketime.h"
41 #include "invent.h"
42 #include "grenades.h"
43 #include "damage.h"
44 #include "effect.h"
45 #include "fullscrn.h"
46 #include "tools.h"
47 #include "olhext.h"
48
49 #include "gamescr.h"
50 #include "gamestrn.h"
51 #include "cybstrng.h"
52 #include "colors.h"
53 #include "gr2ss.h"
54 #include "game_screen.h"
55
56 #include "Prefs.h"
57
58 // ----------
59 // GLOBALS
60 // ----------
61 uchar redraw_paused = TRUE;
62
63 // ----------
64 // PROTOTYPES
65 // ----------
66 void draw_pause_string(void);
67
68 long pal_frame = 0;
69
70 //------------------------------------------------------------------
draw_pause_string(void)71 void draw_pause_string(void) {
72 LGRect r;
73 short w, h, nw, nh;
74
75 gr_set_fcolor(RED_BASE + 4);
76 gr_set_font((grs_font *)ResGet(RES_citadelFont));
77 gr_string_size(get_string(REF_STR_Pause, NULL, 0), &w, &h);
78 nw = SCREEN_VIEW_X + (SCREEN_VIEW_WIDTH - w) / 2;
79 nh = SCREEN_VIEW_Y + (SCREEN_VIEW_HEIGHT - h) / 2;
80 RECT_FILL(&r, nw, nh, nw + w, nh + h);
81 gr2ss_override = OVERRIDE_ALL;
82 uiHideMouse(&r);
83 ss_string(get_string(REF_STR_Pause, NULL, 0), nw, nh);
84 uiShowMouse(&r);
85 }
86
87 //------------------------------------------------------------------
game_loop(void)88 void game_loop(void) {
89 extern void update_meters(bool);
90 extern errtype check_cspace_death();
91 extern uchar game_paused;
92 extern void sound_frame_update(void);
93 // temp
94 // extern char saveArray[16];
95 // if (memcmp(0, saveArray, 16))
96 // Debugger();
97
98 // Handle paused game state
99 if (game_paused) {
100 if (redraw_paused) {
101 TRACE("%s: Drawing pause!", __FUNCTION__);
102 draw_pause_string();
103 redraw_paused = FALSE;
104 }
105 // KLC - does nothing! loopLine(GL|0x1D,synchronous_update());
106 if (music_on)
107 loopLine(GL|0x1C, mlimbs_do_ai());
108 /*if (pal_fx_on)
109 loopLine(GL|0x1E, palette_advance_all_fx(* (long *) 0x16a)); // TickCount()*/
110 }
111
112 // If we're not paused...
113
114 else {
115 loopLine(GL | 0x10, update_state(time_passes)); // move game time
116
117 if (time_passes) {
118 TRACE("%s: ai_run", __FUNCTION__);
119 loopLine(GL | 0x12, ai_run());
120
121 TRACE("%s: gamesys_run", __FUNCTION__);
122 loopLine(GL | 0x13, gamesys_run());
123
124 TRACE("%s: advance_animations", __FUNCTION__);
125 loopLine(GL | 0x14, advance_animations());
126 }
127 TRACE("%s: wares_update", __FUNCTION__);
128 loopLine(GL | 0x16, wares_update());
129
130 TRACE("%s: message_clear_check", __FUNCTION__);
131 loopLine(GL | 0x1D, message_clear_check()); // This could be done more cleverly with change flags...
132
133 if (localChanges) {
134 TRACE("%s: render_run", __FUNCTION__);
135 loopLine(GL | 0x1A, render_run());
136
137 TRACE("%s: status_vitals_update", __FUNCTION__);
138 loopLine(GL | 0x17, if (!full_game_3d) status_vitals_update(FALSE));
139 /*KLC - no longer needed
140 if (_change_flag&ANIM_UPDATE)
141 {
142 loopLine(GL|0x19, AnimRecur());
143 chg_unset_flg(ANIM_UPDATE);
144 }
145 */
146
147 if (full_game_3d && ((_change_flag & INVENTORY_UPDATE) || (_change_flag & MFD_UPDATE)))
148 _change_flag |= DEMOVIEW_UPDATE;
149 if (_change_flag & INVENTORY_UPDATE) {
150 TRACE("%s: INVENTORY_UPDATE", __FUNCTION__);
151 chg_unset_flg(INVENTORY_UPDATE);
152 loopLine(GL | 0x1B, inventory_draw());
153 }
154 if (_change_flag & MFD_UPDATE) {
155 TRACE("%s: MFD_UPDATE", __FUNCTION__);
156 chg_unset_flg(MFD_UPDATE);
157 loopLine(GL | 0x18, mfd_update());
158 }
159
160 if (_change_flag & DEMOVIEW_UPDATE) {
161 // KLC - does nothing!
162 // if (sfx_on || music_on)
163 // loopLine(GL|0x1D, synchronous_update());
164 chg_unset_flg(DEMOVIEW_UPDATE);
165 }
166 }
167 if (!full_game_3d) {
168 TRACE("%s: update_meters", __FUNCTION__);
169 loopLine(GL | 0x19, update_meters(FALSE));
170 }
171 if (!full_game_3d && olh_overlay_on) {
172 TRACE("%s: olh_overlay", __FUNCTION__);
173 olh_overlay();
174 }
175
176 TRACE("%s: physics_run", __FUNCTION__);
177 loopLine(GL | 0x15, physics_run());
178 {
179 if (!olh_overlay_on && olh_active && !global_fullmap->cyber) {
180 TRACE("%s: olh_scan_objects", __FUNCTION__);
181 olh_scan_objects();
182 }
183 }
184 // KLC - does nothing! loopLine(GL|0x1D,synchronous_update());
185 if (sfx_on || music_on) {
186 TRACE("%s: sound_frame_update", __FUNCTION__);
187 loopLine(GL | 0x1C, mlimbs_do_ai());
188 loopLine(GL | 0x1E, sound_frame_update());
189 }
190
191 if (pal_fx_on) {
192 loopLine(GL | 0x1F, palette_advance_all_fx(*tmd_ticks));
193
194 gamma_dealfunc(gShockPrefs.doGamma);
195 }
196
197 TRACE("%s: destroy_destroyed_objects", __FUNCTION__);
198 loopLine(GL | 0x20, destroy_destroyed_objects());
199 loopLine(GL | 0x21, check_cspace_death());
200 }
201 }
202