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/fullscrn.c $
21 * $Revision: 1.73 $
22 * $Author: dc $
23 * $Date: 1994/11/22 20:16:55 $
24 */
25
26 #define __FULLSCRN_SRC
27
28 #include "ShockBitmap.h"
29 #include "Prefs.h"
30
31 #include "fullscrn.h"
32 #include "colors.h"
33 #include "criterr.h"
34 #include "cybstrng.h"
35 #include "frflags.h"
36 #include "frprotox.h"
37 #include "FrUtils.h"
38 #include "gameloop.h"
39 #include "gr2ss.h"
40 #include "hud.h"
41 #include "input.h"
42 #include "invent.h"
43 #include "mainloop.h"
44 #include "mfdext.h"
45 #include "miscqvar.h"
46 #include "objprop.h"
47 #include "otrip.h"
48 #include "palfx.h"
49 #include "rendtool.h"
50 #include "sideicon.h"
51 #include "status.h"
52 #include "textmaps.h"
53 #include "tools.h"
54 #include "wares.h"
55
56 #include "game_screen.h" // was screen.h?
57 #include "Shock.h"
58
59 #ifdef NOT_YET // KLC stereo
60
61 #include <config.h>
62
63 #ifdef STEREO_SUPPORT
64 #include <inp6d.h>
65 #include <i6dvideo.h>
66 #endif
67
68 #endif // NOT_YET
69
70 // -------
71 // GLOBALS
72 // -------
73 uchar fullscrn_vitals = TRUE;
74 uchar fullscrn_icons = TRUE;
75
76 extern uchar inp6d_stereo_active;
77 extern uchar inp6d_stereo;
78
79 #ifdef SVGA_SUPPORT
80 grs_screen *svga_screen = NULL;
81 frc *svga_render_context = NULL;
82 short svga_mode_data[] = {GRM_320x200x8, GRM_320x400x8, GRM_640x400x8, GRM_640x480x8, GRM_1024x768x8, GRM_320x200x8};
83 char mickey_stupid[][2] = {{16, 8}, {16, 4}, {3, 1}, {2, 1}, {3, 1}, {16, 8}};
84 short mode_id = 3; // KLC - start off in 640x480 in Mac version old - short mode_id=0;
85 #endif
86
87 #ifdef GADGET
88 #include <gadgets.h>
89 Gadget *fullroot_gadget;
90 #endif
91 uiSlab fullscreen_slab;
92
93 #define CFG_TIME_VAR "time_passes"
94
95 extern void status_bio_update_screenmode();
96 extern void mouse_unconstrain(void);
97 extern void olh_svga_deal(void);
98 extern void inv_change_fullscreen(uchar on);
99 extern void mfd_change_fullscreen(uchar on);
100 extern void game_redrop_rad(int rad_mod);
101 void change_svga_cursors();
102 void change_svga_screen_mode();
103
104 LGRegion fullroot_region_data, fullview_region_data;
105 LGRegion *fullroot_region = &fullroot_region_data; // DUH
106
107 short base_mouse_xr, base_mouse_yr, base_mouse_thresh;
108
fullscreen_init(void)109 errtype fullscreen_init(void) {
110 extern void init_posture_meters(LGRegion *, bool);
111 extern errtype wrapper_create_mouse_region(LGRegion *);
112 extern LGRect fscrn_rect;
113
114 generic_reg_init(TRUE, fullroot_region, NULL, &fullscreen_slab, main_kb_callback, NULL);
115
116 // Full-screen 3d view region
117 fullview_region = &fullview_region_data;
118 region_create(fullroot_region, fullview_region, &fscrn_rect, 1, 0, REG_USER_CONTROLLED | AUTODESTROY_FLAG, NULL,
119 NULL, NULL, NULL);
120
121 install_motion_mouse_handler(fullview_region, NULL);
122 install_motion_keyboard_handler(fullroot_region);
123
124 wrapper_create_mouse_region(fullview_region);
125 create_invent_region(fullview_region, &pagebutton_region_full, &inventory_region_full);
126 init_posture_meters(fullview_region, TRUE);
127 screen_init_mfd(TRUE);
128 screen_init_side_icons(fullview_region);
129
130 // mouse_get_rate(&base_mouse_xr, &base_mouse_yr, &base_mouse_thresh);
131 // base_mouse_xr = 16;
132 // base_mouse_yr = 8;
133 // base_mouse_thresh = 100;
134 base_mouse_xr = 8;
135 base_mouse_yr = 4;
136 base_mouse_thresh = 100;
137
138 full_visible = FULL_INVENT_MASK | FULL_L_MFD_MASK | FULL_R_MFD_MASK;
139
140 return (OK);
141 }
142
143 // Draw all relevant overlays
fullscreen_overlay()144 errtype fullscreen_overlay() {
145 extern char last_message[128];
146 extern void mfd_draw_button_panel(ubyte mfd_id);
147 extern void fullscreen_refresh_mfd(ubyte mfd_id);
148 extern void inv_update_fullscreen(uchar full);
149 extern uchar game_paused;
150
151 if (!global_fullmap->cyber) {
152 mfd_draw_button_panel(MFD_RIGHT);
153 mfd_draw_button_panel(MFD_LEFT);
154 }
155 fullscreen_refresh_mfd(MFD_RIGHT);
156 if (global_fullmap->cyber)
157 full_visible &= ~FULL_MFD_MASK(MFD_LEFT);
158 fullscreen_refresh_mfd(MFD_LEFT);
159 if (!game_paused)
160 inv_update_fullscreen((full_visible & FULL_INVENT_MASK) != 0);
161 if (fullscrn_vitals) {
162 extern void update_meters(bool);
163 status_vitals_update(TRUE);
164 if (!global_fullmap->cyber)
165 update_meters(TRUE);
166 }
167 if ((!global_fullmap->cyber) && (fullscrn_icons))
168 side_icon_expose_all();
169
170 // KLC uiSetCursor();
171
172 return (OK);
173 }
174
175 // Set all appropriate things to convert us to full screen mode
176
change_svga_cursors()177 void change_svga_cursors() {
178 ObjID old_obj;
179
180 extern errtype make_options_cursor(void);
181 extern void reload_motion_cursors(uchar cyber);
182 extern void free_cursor_bitmaps();
183 extern void alloc_cursor_bitmaps(void);
184 extern errtype biohelp_load_cursor();
185 extern errtype load_misc_cursors();
186
187 extern int last_side_icon;
188 extern int last_invent_cnum;
189 extern int last_mfd_cnum[NUM_MFDS];
190 extern short object_on_cursor;
191 short temp;
192
193 ss_set_hack_mode(2, &temp);
194
195 // KLC - not needed free_options_cursor();
196 make_options_cursor();
197 old_obj = object_on_cursor;
198 if (old_obj != OBJ_NULL) {
199 pop_cursor_object();
200 push_cursor_object(old_obj);
201 }
202 free_cursor_bitmaps();
203 alloc_cursor_bitmaps();
204 reload_motion_cursors(global_fullmap->cyber);
205 last_side_icon = -1;
206 last_invent_cnum = -1;
207 last_mfd_cnum[0] = -1;
208 last_mfd_cnum[1] = -1;
209
210 biohelp_load_cursor();
211 load_misc_cursors();
212
213 ss_set_hack_mode(0, &temp);
214 }
215
change_svga_screen_mode()216 void change_svga_screen_mode() {
217 extern errtype inventory_update_screen_mode();
218 extern errtype mfd_update_screen_mode();
219 extern void view360_update_screen_mode();
220 extern void amap_pixratio_set(fix ratio);
221 extern uchar redraw_paused;
222 extern bool DoubleSize;
223
224 uchar cur_pal[768];
225 uchar *s_table;
226 short cur_w, cur_h, cur_m;
227 short mx, my;
228 uchar mode_change = FALSE;
229 short temp;
230
231 if (convert_use_mode != mode_id)
232 mode_change = TRUE;
233 if (mode_change) {
234 int retval = -1;
235
236 ui_mouse_get_xy(&mx, &my);
237 // gr_get_pal(0,256,&cur_pal[0]);
238 s_table = gr_get_light_tab();
239
240 uiHideMouse(NULL);
241
242 while (retval == -1) {
243 /*KLC for stereo support
244 if (mode_id == 5)
245 cur_m = i6d_ss->scr_mode;
246 else
247 */
248 cur_m = svga_mode_data[mode_id];
249 retval = gr_set_mode(cur_m, TRUE);
250 if (retval == -1) {
251 mode_id = (mode_id + 1) % 5;
252 }
253 }
254 convert_use_mode = mode_id;
255 cur_w = grd_mode_cap.w;
256 cur_h = grd_mode_cap.h;
257
258 INFO("Changing screen mode to %i x %i", cur_w, cur_h);
259
260 // CRASHES!
261 /*if (svga_screen!=NULL)
262 gr_free_screen(svga_screen);*/
263
264 extern void ChangeScreenSize(int w, int h);
265 ChangeScreenSize(cur_w, cur_h);
266
267 svga_screen = gr_alloc_screen(cur_w, cur_h);
268 gr_set_screen(svga_screen);
269 } else {
270 cur_w = grd_mode_cap.w;
271 cur_h = grd_mode_cap.h;
272 }
273 // calculate new pixel ratio for automap; force 1 for 320x200
274 // KLC - we're never 320x200 amap_pixratio_set(svga_mode_data[mode_id]==GRM_320x200x8?FIX_UNIT:0);
275 // amap_pixratio_set(0);
276
277 amap_pixratio_set(svga_mode_data[mode_id] == GRM_320x200x8 ? FIX_UNIT : 0);
278
279 if (svga_render_context != NULL) {
280 fr_free_view(svga_render_context);
281 }
282 if (full_game_3d) {
283 svga_render_context = fr_place_view(FR_NEWVIEW, FR_DEFCAM, offscreenDrawSurface->pixels,
284 FR_DOUBLEB_MASK | FR_WINDOWD_MASK, 0, 0, 0, 0, cur_w, cur_h);
285 } else {
286 svga_render_context = fr_place_view(
287 FR_NEWVIEW, FR_DEFCAM, offscreenDrawSurface->pixels, FR_DOUBLEB_MASK | FR_WINDOWD_MASK | FR_CURVIEW_STRT, 0,
288 0, SCONV_X(SCREEN_VIEW_X), SCONV_Y(SCREEN_VIEW_Y), SCONV_X(SCREEN_VIEW_WIDTH), SCONV_Y(SCREEN_VIEW_HEIGHT));
289 }
290
291 fr_use_global_detail(svga_render_context);
292 _current_fr_context = svga_render_context;
293 if (full_game_3d)
294 _current_view = fullview_region;
295 else
296 _current_view = mainview_region;
297 _current_3d_flag = DEMOVIEW_UPDATE;
298 fr_set_view(_current_fr_context);
299
300 // Recompute zoom!
301 // ss_recompute_zoom(_current_fr_context,old_mode);
302
303 chg_set_flg(DEMOVIEW_UPDATE);
304 if (mode_change) {
305 if (mode_id == 0)
306 game_redrop_rad(0);
307 else
308 game_redrop_rad(2 + mode_id);
309
310 ss_mouse_convert(&mx, &my, FALSE);
311 /*KLC leave out until stereo view is needed
312 if (mode_id == 5) // hack hack stereo hack
313 {
314 switch(i6d_device)
315 {
316 case I6D_CTM:
317 temp_sz.x = 320;
318 temp_sz.y = 200;
319 break;
320 case I6D_VFX1:
321 temp_sz.x = i6d_ss->scr_w / 2;
322 temp_sz.y = i6d_ss->scr_h;
323 break;
324 }
325 uiUpdateScreenSize(temp_sz);
326 }
327 else
328 */
329 uiUpdateScreenSize(UI_DETECT_SCREEN_SIZE);
330 // KLC - Can't do this on Mac, can we? mouse_put_xy(mx,my);
331 // KLC - don't need this. Mac sets this globally.
332 // mouse_set_rate(mickey_stupid[mode_id][0],mickey_stupid[mode_id][1],2);
333 // gr_set_pal(0,256,&cur_pal[0]);
334 gr_set_light_tab(s_table);
335 uiShowMouse(NULL);
336 }
337 if (full_game_3d) {
338 static_change_copy();
339 mfd_change_fullscreen(TRUE);
340 }
341 status_bio_update_screenmode();
342 ss_set_hack_mode(2, &temp);
343 inventory_update_screen_mode();
344 mfd_update_screen_mode();
345 view360_update_screen_mode();
346 ss_set_hack_mode(0, &temp);
347 olh_svga_deal();
348
349 change_svga_cursors();
350 // KLC gamma_dealfunc(QUESTVAR_GET(GAMMACOR_QVAR));
351 gamma_dealfunc(gShockPrefs.doGamma);
352 redraw_paused = TRUE;
353 }
354
fullscreen_start()355 void fullscreen_start() {
356 extern LGRegion *pagebutton_region;
357 extern LGRegion *inventory_region;
358 extern void draw_page_buttons(uchar full);
359 extern uchar inp6d_headset;
360
361 // Hey, we don't need to hide here because the mouse already gets hidden by fooscreen_exit
362 // uiHideMouse(NULL);
363 HotkeyContext = DEMO_CONTEXT;
364 full_game_3d = TRUE;
365 uiSetCurrentSlab(&fullscreen_slab);
366
367 inventory_region = inventory_region_full;
368 pagebutton_region = pagebutton_region_full;
369 #ifdef GADGET
370 _current_root = fullroot_gadget;
371 #endif
372
373 #ifdef STEREO_SUPPORT
374 if (inp6d_stereo)
375 mode_id = 5;
376 #endif
377 change_svga_screen_mode();
378
379 inv_change_fullscreen(TRUE);
380 // mouse_unconstrain();
381 player_struct.hardwarez_status[CPTRIP(FULLSCR_HARD_TRIPLE)] |= WARE_ON;
382 string_message_info(REF_STR_FSMode);
383 mfd_force_update();
384 draw_page_buttons(TRUE);
385 #ifdef STEREO_SUPPORT
386 if (inp6d_stereo) {
387 // uchar cur_pal[768];
388 // gr_get_pal(0,256,&cur_pal[0]);
389 // uiHideMouse(NULL);
390 // gr_set_mode(i6d_ss->scr_mode,TRUE);
391 // gr_set_pal(0,256,&cur_pal[0]);
392 if (i6d_ss->scr_mode == grd_mode) {
393 i6d_ss->stereo_screen = grd_screen->c;
394 i6_video(I6VID_SET_MODE, i6d_ss);
395 if (i6_video(I6VID_STR_SETUP, i6d_ss)) {
396 Warning(("Stereo setup failed"));
397 i6_video(I6VID_CLEAR_MODE, i6d_ss);
398 inp6d_stereo_active = FALSE;
399 } else
400 inp6d_stereo_active = TRUE;
401 }
402 }
403 #endif
404 #ifdef PALFX_FADES
405 // if (pal_fx_on) palfx_fade_up(FALSE);
406 #endif
407 // KLC uiShowMouse(NULL);
408
409 CaptureMouse(true);
410
411 extern void SetMotionCursorForMouseXY(void);
412 SetMotionCursorForMouseXY();
413 }
414
415 // Restore all appropriate things to put us back in normal
416 // screen mode
fullscreen_exit()417 void fullscreen_exit() {
418 #ifdef SVGA_SUPPORT
419 uchar cur_pal[768];
420 extern grs_screen *cit_screen;
421 uchar *s_table;
422 #endif
423
424 #ifdef STEREO_SUPPORT
425 if (mode_id == 5)
426 mode_id = 0;
427 if (inp6d_stereo_active) {
428 i6_video(I6VID_CLEAR_MODE, i6d_ss);
429 inp6d_stereo_active = FALSE;
430 }
431 #endif
432 uiHideMouse(NULL);
433
434 #ifdef SVGA_SUPPORT
435 if ((_new_mode != GAME_LOOP) && (_new_mode != FULLSCREEN_LOOP)) {
436 s_table = gr_get_light_tab();
437 gr_get_pal(0, 256, &cur_pal[0]);
438 gr_set_mode(GRM_320x200x8, TRUE);
439 gr_set_screen(cit_screen);
440 convert_use_mode = 0;
441 // KLC change_svga_cursors();
442 // KLC status_bio_update_screenmode();
443 }
444 #endif
445 if (_new_mode == -1)
446 return;
447 full_game_3d = FALSE;
448 mfd_change_fullscreen(FALSE);
449 inv_change_fullscreen(FALSE);
450 player_struct.hardwarez_status[CPTRIP(FULLSCR_HARD_TRIPLE)] &= ~WARE_ON;
451 hud_unset(HUD_MSGLINE);
452
453 /* KLC
454 #ifdef SVGA_SUPPORT
455 if ((_new_mode != GAME_LOOP) && (_new_mode != FULLSCREEN_LOOP))
456 {
457 gr_set_pal(0,256,&cur_pal[0]);
458 gr_set_light_tab(s_table);
459 }
460 #endif
461 */
462 }
463
464 // pushes a region down below the view
full_lower_region(LGRegion * r)465 errtype full_lower_region(LGRegion *r) {
466 errtype retval;
467 region_begin_sequence();
468 retval = region_move(r, r->r->ul.x, r->r->ul.y, 0);
469 region_end_sequence(FALSE);
470 return (retval);
471 }
472
473 // pulls a region up above the view
full_raise_region(LGRegion * r)474 errtype full_raise_region(LGRegion *r) {
475 errtype retval;
476 region_begin_sequence();
477 retval = region_move(r, r->r->ul.x, r->r->ul.y, 2);
478 region_end_sequence(FALSE);
479 return (retval);
480 }
481