FS2_Open
Open source remastering of the Freespace 2 engine
missionpause.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) Volition, Inc. 1999. All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell
5  * or otherwise commercially exploit the source or things you created based on the
6  * source.
7  *
8 */
9 
10 
11 
12 
14 #include "freespace2/freespace.h"
16 #include "globalincs/alphacolors.h"
17 #include "graphics/font.h"
18 #include "hud/hud.h"
19 #include "hud/hudmessage.h"
20 #include "io/key.h"
21 #include "missionui/missionpause.h"
22 #include "network/multi_pause.h"
23 #include "object/object.h"
24 #include "popup/popup.h"
25 #include "sound/audiostr.h"
26 #include "ui/ui.h"
27 #include "weapon/weapon.h"
28 
29 
30 
31 
32 // ----------------------------------------------------------------------------------------------------------------
33 // PAUSE DEFINES/VARS
34 //
35 
36 // pause bitmap name
38  "PleaseWait",
39  "2_PleaseWait"
40 };
41 
42 // pause bitmap display stuff
44  { // GR_640
45  152, 217, 316, 26
46  },
47  { // GR_1024
48  247, 346, 510, 36
49  }
50 };
51 
52 // pause window objects
62 
63 // if we're already paused
64 int Paused = 0;
65 
66 // background screen (for the chatbox)
68 
69 // saved background screen
71 
72 // if we're in external vie wmode
74 
75 // externs
76 extern int Ai_render_debug_flag;
77 extern int Ai_firing_enabled;
78 extern int physics_paused;
79 extern int ai_paused;
80 extern int last_single_step;
81 extern int game_single_step;
82 
83 // ----------------------------------------------------------------------------------------------------------------
84 // PAUSE FUNCTIONS
85 //
86 
88 {
89  return Pause_type;
90 }
91 
93 {
94  Pause_type = type;
95 }
96 
97 // initialize the pause screen
98 void pause_init()
99 {
100  // if we're already paused. do nothing
101  if ( Paused ) {
102  return;
103  }
104 
106 
107  // pause all weapon sounds
109 
110  if (Pause_type == PAUSE_TYPE_NORMAL) {
112  }
113 
114  // pause all game music
116 
118 
120 
121  Paused = 1;
122 }
123 
124 extern int button_function_demo_valid(int n);
125 extern int button_function(int n);
126 
127 // pause do frame - will handle running multiplayer operations if necessary
128 void pause_do()
129 {
130  int k;
131  const char *pause_str = XSTR("Paused", 767);
132  int str_w, str_h;
133  // next two are for view resetting
134  static int previous_Viewer_mode = -1;
135  static int previous_hud_state = -1;
136 
138 
139  // RENDER A GAME FRAME HERE AS THE BACKGROUND (if normal pause)
140 
141  if(Pause_type == PAUSE_TYPE_NORMAL) {
142  // Fall back to viewer just incase saved screen is invalid
143  if(Pause_saved_screen == -1){
145  }
146  else if(Pause_type == PAUSE_TYPE_NORMAL) {
148  }
149  }
150 
152  if (Pause_background_bitmap >= 0) {
154 
155  // draw the bitmap
157 
158  // draw "Paused" on it
161  gr_get_string_size(&str_w, &str_h, pause_str);
162  gr_string((gr_screen.max_w_unscaled - str_w) / 2, (gr_screen.max_h_unscaled - str_h) / 2, pause_str, GR_RESIZE_MENU);
164  }
165  }
166 
167  if (Pause_type == PAUSE_TYPE_VIEWER) {
168  if (previous_Viewer_mode < 0)
169  previous_Viewer_mode = Viewer_mode;
170 
171  if (previous_hud_state < 0)
172  previous_hud_state = hud_disabled();
173  }
174 
175  // process the ui window here
176  k = Pause_win.process() & ~KEY_DEBUGGED;
177  switch (k)
178  {
179  case KEY_TAB:
180  hud_toggle_draw();
181  break;
182 
183  // view from outside of the ship
184  case KEY_ENTER:
185  if (Pause_type == PAUSE_TYPE_VIEWER) {
187  }
188  break;
189 
190  // view from target
191  case KEY_PADDIVIDE:
192  if (Pause_type == PAUSE_TYPE_VIEWER) {
194  }
195  break;
196 
197  // change target
198  case KEY_PADMULTIPLY:
199  if (Pause_type == PAUSE_TYPE_VIEWER) {
201  }
202  break;
203 
204  case KEY_ESC:
205  case KEY_ALTED + KEY_PAUSE:
206  case KEY_PAUSE:
207  // reset previous view if we happened to be playing around with it during pause
208  if (Pause_type == PAUSE_TYPE_VIEWER) {
209  if (previous_Viewer_mode >= 0) {
210  Viewer_mode = previous_Viewer_mode;
211  }
212 
213  // NOTE remember that hud state is reversed here (0 == on, 1 == off)
214  if ( (previous_hud_state >= 0) && (hud_disabled() != previous_hud_state) ) {
215  hud_set_draw( !previous_hud_state );
216  }
217  }
218 
220  break;
221  } // end switch
222 
223  // draw the background window
224  Pause_win.draw();
225 
226  // a very unique case where we shouldn't be doing the page flip because we're inside of popup code
227  if(!popup_active()){
229  gr_flip();
230  }
231  } else {
232  // this should only be happening in a very unique multiplayer case
233  Int3();
234  }
235 }
236 
237 // close the pause screen
239 {
240  // if we're not paused - do nothing
241  if ( !Paused ) {
242  return;
243  }
244 
246 
247  // unpause all weapon sounds
249 
250  // deinit stuff
251  if(Pause_saved_screen != -1) {
253  Pause_saved_screen = -1;
254  }
255 
256  if (Pause_background_bitmap != -1){
259  }
260 
261  Pause_win.destroy();
262  game_flush();
263 
264  // unpause all the music
266 
267  Paused = 0;
268 }
269 
270 // debug pause init
272 {
273  Pause_win.create( 100,100,400,300, WIN_DIALOG );
274 
275  Pause_physics.create( &Pause_win, NOX("Physics Pause <P>"), 200, 150, physics_paused );
276  Pause_ai.create( &Pause_win, NOX("AI Pause <A>"), 200, 175, ai_paused );
277  #ifndef NDEBUG
278  Pause_ai_render.create( &Pause_win, NOX("AI Render Stuff <R>"), 200, 200, Ai_render_debug_flag);
279  #endif
280  Pause_firing.create( &Pause_win, NOX("AI firing <F>"), 200, 225, Ai_firing_enabled);
281  Pause_external_view_mode_check.create( &Pause_win, NOX("External View <E>"), 200, 250, Pause_external_view_mode);
282  Pause_single_step.create( &Pause_win, NOX("Single Step <S>"), 200, 290, game_single_step );
283  Pause_continue.create( &Pause_win, NOX("Leave Pause"), 200, 350, 200, 40 );
284 
285  Pause_single_step.set_hotkey( KEY_S );
286  Pause_physics.set_hotkey( KEY_P );
287  Pause_ai.set_hotkey( KEY_A );
288  Pause_ai_render.set_hotkey( KEY_R );
289  Pause_firing.set_hotkey( KEY_F );
290  Pause_external_view_mode_check.set_hotkey( KEY_E );
291  Pause_continue.set_hotkey( KEY_ESC );
292 
293  Pause_continue.set_focus();
294 }
295 
296 // debug pause do frame
298 {
299  int key;
300 
301  key = Pause_win.process();
302  if ( Pause_single_step.changed()) {
303  game_single_step = Pause_single_step.checked();
304  }
305 
306  if ( Pause_physics.changed()) {
307  physics_paused = Pause_physics.checked();
308  }
309 
310  if ( Pause_ai.changed()) {
311  ai_paused = Pause_ai.checked();
312  if (ai_paused){
314  }
315  }
316 
317  if ( Pause_ai_render.changed()) {
318  Ai_render_debug_flag = Pause_ai_render.checked();
319  }
320 
321  if ( Pause_firing.changed()) {
322  Ai_firing_enabled = Pause_firing.checked();
323  }
324 
325  if ( Pause_external_view_mode_check.changed()) {
326  Pause_external_view_mode = Pause_external_view_mode_check.checked();
328  HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "External view of player ship.", 182));
329  } else {
330  HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "View from inside player ship.", 183));
331  }
332  }
333 
334  if ( Pause_continue.pressed() || (key == KEY_PAUSE) ) { // Changed, MK, 11/9/97, only Pause break pause.
336  }
337 
338  gr_clear();
339  Pause_win.draw();
340 
341  gr_flip();
342 }
343 
344 // debug pause close
346 {
347  last_single_step = 0; // Make so single step waits a frame before stepping
348  Pause_win.destroy();
349  game_flush();
350 }
void game_flush()
Definition: fredstubs.cpp:83
#define KEY_PADMULTIPLY
Definition: key.h:170
UI_CHECKBOX Pause_external_view_mode_check
int button_function_demo_valid(int n)
void pause_set_type(int type)
#define gr_clear
Definition: 2d.h:749
UI_CHECKBOX Pause_single_step
int Game_mode
Definition: systemvars.cpp:24
int ai_paused
Definition: object.cpp:677
void gr_flip()
Definition: 2d.cpp:2113
int Pause_type
#define GR_RESIZE_MENU
Definition: 2d.h:684
int Pause_external_view_mode
int pause_get_type()
#define gr_restore_screen
Definition: 2d.h:826
void obj_init_all_ships_physics()
Definition: object.cpp:1689
Assert(pm!=NULL)
#define GR_NUM_RESOLUTIONS
Definition: 2d.h:651
__inline void gr_string(int x, int y, const char *string, int resize_mode=GR_RESIZE_FULL)
Definition: 2d.h:769
void hud_toggle_draw()
Definition: hud.cpp:1270
int res
Definition: 2d.h:370
int max_h_unscaled
Definition: 2d.h:361
#define KEY_E
Definition: key.h:86
void set_focus()
Definition: gadget.cpp:321
int physics_paused
Definition: object.cpp:677
int Pause_background_bitmap
int checked()
Definition: checkbox.cpp:186
VIEW_OTHER_SHIP.
void gr_set_color_fast(color *dst)
Definition: 2d.cpp:1197
Definition: ui.h:195
int key
target next
void gr_set_bitmap(int bitmap_num, int alphablend_mode, int bitblt_mode, float alpha)
Definition: 2d.cpp:2105
int max_w_unscaled
Definition: 2d.h:361
#define Int3()
Definition: pstypes.h:292
void HUD_sourced_printf(int source, const char *format,...)
Definition: hudmessage.cpp:571
int bm_release(int handle, int clear_render_targets)
Frees both a bitmap's data and it's associated slot.
Definition: bmpman.cpp:2603
int Ai_firing_enabled
Definition: aicode.cpp:194
VIEW_EXTERNAL.
GLenum type
Definition: Gl.h:1492
#define KEY_A
Definition: key.h:82
void destroy()
Definition: window.cpp:189
UI_WINDOW Pause_win
void weapon_pause_sounds()
Definition: weapons.cpp:7248
#define GM_MULTIPLAYER
Definition: systemvars.h:18
#define gr_save_screen
Definition: 2d.h:825
int pressed()
Definition: button.cpp:325
#define KEY_ENTER
Definition: key.h:125
#define HUD_SOURCE_HIDDEN
Definition: hudmessage.h:23
#define KEY_PAUSE
Definition: key.h:185
UI_CHECKBOX Pause_ai
int button_function(int n)
UI_CHECKBOX Pause_ai_render
#define KEY_R
Definition: key.h:99
void pause_debug_init()
#define KEY_P
Definition: key.h:97
GLclampd n
Definition: Glext.h:7286
int hud_disabled()
Checks if HUD disabled.
Definition: hud.cpp:1306
void hud_set_draw(int draw)
Definition: hud.cpp:1276
const char * XSTR(const char *str, int index)
Definition: localize.cpp:851
int Pause_saved_screen
#define NOX(s)
Definition: pstypes.h:473
void set_hotkey(int keycode)
Definition: gadget.cpp:280
void create(UI_WINDOW *wnd, char *_text, int _x, int _y, int _state)
Definition: checkbox.cpp:16
void weapon_unpause_sounds()
Definition: weapons.cpp:7257
int bm_load(const char *real_filename)
Loads a bitmap so we can draw with it later.
Definition: bmpman.cpp:1119
#define FONT1
Definition: font.h:65
void pause_debug_do()
void create(UI_WINDOW *wnd, char *_text, int _x, int _y, int _w, int _h, int do_repeat=0, int ignore_focus=0)
Definition: button.cpp:26
#define KEY_ESC
Definition: key.h:124
int last_single_step
Definition: fredstubs.cpp:210
#define KEY_ALTED
Definition: key.h:63
#define FONT2
Definition: font.h:66
char * Pause_bmp_name[GR_NUM_RESOLUTIONS]
void pause_init()
void create(int _x, int _y, int _w, int _h, int _flags, int _f_id=-1)
Definition: window.cpp:140
void audiostream_unpause_all(bool via_sexp_or_script=false)
Definition: audiostr.cpp:1990
void pause_close()
int Please_wait_coords[GR_NUM_RESOLUTIONS][4]
Definition: ui.h:584
screen gr_screen
Definition: 2d.cpp:46
void gr_get_string_size(int *w, int *h, const char *text, int len=9999)
Definition: font.cpp:196
int game_single_step
Definition: fredstubs.cpp:209
#define KEY_DEBUGGED
Definition: key.h:65
UI_BUTTON Pause_continue
int Viewer_mode
Definition: systemvars.cpp:28
#define gr_free_screen
Definition: 2d.h:827
color Color_normal
Definition: alphacolors.cpp:28
#define KEY_TAB
Definition: key.h:127
void gr_bitmap(int _x, int _y, int resize_mode)
Definition: 2d.cpp:1303
UI_CHECKBOX Pause_firing
void pause_debug_close()
int Paused
void audiostream_pause_all(bool via_sexp_or_script=false)
Definition: audiostr.cpp:1978
#define WIN_DIALOG
Definition: ui.h:582
void draw()
Definition: window.cpp:220
void gr_set_font(int fontnum)
Definition: font.cpp:566
int Ai_render_debug_flag
Definition: ship.cpp:113
#define KEY_S
Definition: key.h:100
int process(int key_in=-1, int process_mouse=1)
Definition: window.cpp:401
void gameseq_post_event(int event)
UI_CHECKBOX Pause_physics
#define KEY_PADDIVIDE
Definition: key.h:169
void pause_do()
int changed()
Definition: checkbox.cpp:181
#define KEY_F
Definition: key.h:87