]> icculus.org git repositories - taylor/freespace2.git/blob - src/missionui/missionpause.cpp
deal with timestamp issue when calculating submodel rotation
[taylor/freespace2.git] / src / missionui / missionpause.cpp
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
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/MissionUI/MissionPause.cpp $
11  * $Revision$
12  * $Date$
13  * $Author$
14  * 
15  *
16  * $Log$
17  * Revision 1.5  2004/09/20 01:31:44  theoddone33
18  * GCC 3.4 fixes.
19  *
20  * Revision 1.4  2003/05/25 02:30:43  taylor
21  * Freespace 1 support
22  *
23  * Revision 1.3  2002/06/09 04:41:23  relnev
24  * added copyright header
25  *
26  * Revision 1.2  2002/05/07 03:16:46  theoddone33
27  * The Great Newline Fix
28  *
29  * Revision 1.1.1.1  2002/05/03 03:28:10  root
30  * Initial import.
31  *
32  * 
33  * 7     7/29/99 10:48p Dave
34  * Multiplayer pause screen.
35  * 
36  * 6     6/29/99 7:39p Dave
37  * Lots of small bug fixes.
38  * 
39  * 5     6/09/99 2:17p Dave
40  * Fixed up pleasewait bitmap rendering.
41  * 
42  *
43  * $NoKeywords: $
44  */
45
46 #include "missionpause.h"
47 #include "ui.h"
48 #include "multi_pause.h"
49 #include "popup.h"
50 #include "2d.h"
51 #include "bmpman.h"
52 #include "key.h"
53 #include "audiostr.h"
54 #include "gamesequence.h"
55 #include "freespace.h"
56 #include "hud.h"
57 #include "object.h"
58 #include "font.h"
59 #include "alphacolors.h"
60 #include "beam.h"
61 #include "mainhallmenu.h"
62
63 // ----------------------------------------------------------------------------------------------------------------
64 // PAUSE DEFINES/VARS
65 //
66
67 // pause bitmap name
68 const char *Pause_bmp_name[GR_NUM_RESOLUTIONS] = {
69 #ifdef MAKE_FS1
70         "Pause",
71 #else
72         "PleaseWait",
73 #endif
74         "2_PleaseWait"
75 };
76
77 // pause bitmap display stuff
78 int Please_wait_coords[GR_NUM_RESOLUTIONS][4] = {
79         { // GR_640
80 #ifdef MAKE_FS1
81                 96, 205, 447, 70
82 #else
83                 152, 217, 316, 26
84 #endif
85         },
86         { // GR_1024
87                 247, 346, 510, 36
88         }       
89 };
90
91 const char *Pause_multi_fname[GR_NUM_RESOLUTIONS] = {
92         "MPPause",
93         "2_MPPause"
94 };
95 const char *Pause_multi_mask[GR_NUM_RESOLUTIONS] = {
96         "MPPause-m",
97         "2_MPPause-m"
98 };
99
100 // pause window objects
101 UI_WINDOW Pause_win;
102 UI_CHECKBOX Pause_single_step;
103 UI_CHECKBOX Pause_physics;
104 UI_CHECKBOX Pause_ai;
105 UI_CHECKBOX Pause_ai_render;
106 UI_CHECKBOX Pause_firing;
107 UI_CHECKBOX Pause_external_view_mode_check;
108 UI_BUTTON Pause_continue;
109
110 // if we're already paused
111 int Paused = 0;
112
113 // background screen (for the chatbox)
114 int Pause_background_bitmap = -1;
115
116 // saved background screen
117 int Pause_saved_screen = -1;
118
119 // if we're in external vie wmode
120 int Pause_external_view_mode = 0;
121
122 // externs
123 extern int Player_attacking_enabled;
124 extern int Ai_render_debug_flag;
125 extern int Ai_firing_enabled;
126 extern int physics_paused;
127 extern int ai_paused;
128 extern int last_single_step;
129 extern int game_single_step;
130
131 // ----------------------------------------------------------------------------------------------------------------
132 // PAUSE FUNCTIONS
133 //
134
135 // initialize the pause screen
136 void pause_init(int multi)
137 {
138         // if we're already paused. do nothing
139         if ( Paused ) {
140                 return;
141         }       
142
143         // pause all beam weapon sounds
144         beam_pause_sounds();
145
146         if(!(Game_mode & GM_STANDALONE_SERVER)){
147                 Pause_saved_screen = gr_save_screen();
148
149                 // pause all game music
150                 audiostream_pause_all();
151                 main_hall_stop_ambient();
152
153                 //JAS: REMOVED CALL TO SET INTERFACE PALETTE TO GET RID OF SCREEN CLEAR WHEN PAUSING
154                 //common_set_interface_palette();  // set the interface palette
155                 Pause_win.create(0, 0, gr_screen.max_w, gr_screen.max_h, 0);    
156
157                 if (multi) {
158                         Pause_win.set_mask_bmap(Pause_multi_mask[gr_screen.res]);
159                         Pause_background_bitmap = bm_load(Pause_multi_fname[gr_screen.res]);
160
161                         multi_pause_init(&Pause_win);           
162                 } else {
163                         Pause_background_bitmap = bm_load(Pause_bmp_name[gr_screen.res]);
164                 }
165         } else {
166                 multi_pause_init(NULL);
167         }
168
169         Paused = 1;
170 }
171
172 // pause do frame - will handle running multiplayer operations if necessary
173 void pause_do(int multi)
174 {
175         int k;
176 #ifndef MAKE_FS1
177         const char *pause_str = XSTR("Paused", 767);
178         int str_w, str_h;
179 #endif
180
181         if(Game_mode & GM_STANDALONE_SERVER){
182                 multi_pause_do();
183         } else {                
184                 //      RENDER A GAME FRAME HERE AS THE BACKGROUND
185                 gr_restore_screen(Pause_saved_screen);
186                 if (Pause_background_bitmap >= 0) {
187                         gr_set_bitmap(Pause_background_bitmap, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1);
188                         if(multi){
189                                 gr_bitmap(0,0);
190                         } else {
191                                 // draw the bitmap
192                                 gr_bitmap(Please_wait_coords[gr_screen.res][0], Please_wait_coords[gr_screen.res][1]);
193
194 #ifndef MAKE_FS1
195                                 // draw "Paused" on it
196                                 gr_set_color_fast(&Color_normal);
197                                 gr_set_font(FONT2);
198                                 gr_get_string_size(&str_w, &str_h, pause_str);
199                                 gr_string((gr_screen.max_w - str_w) / 2, (gr_screen.max_h - str_h) / 2, pause_str);
200                                 gr_set_font(FONT1);
201 #endif
202                         }
203                 }
204         
205                 // the multi paused screen will do its own window processing
206                 if (multi) {
207                         multi_pause_do();
208                 }
209                 // otherwise process the ui window here
210                 else {
211                         k = Pause_win.process() & ~KEY_DEBUGGED;
212                         switch (k) {                    
213                         case SDLK_ESCAPE:
214                         case SDLK_PAUSE:
215                                 gameseq_post_event(GS_EVENT_PREVIOUS_STATE);            
216                                 break;
217                         }       // end switch
218                 }
219         
220                 // draw the background window
221                 Pause_win.draw();               
222
223                 // a very unique case where we shouldn't be doing the page flip because we're inside of popup code
224                 if(!popup_active()){
225                         gr_flip();
226                 } else {
227                         // this should only be happening in a very unique multiplayer case
228                         SDL_assert(Game_mode & GM_MULTIPLAYER);
229                 }
230         }
231 }
232
233 // close the pause screen
234 void pause_close(int multi)
235 {
236         // if we're not paused - do nothing
237         if ( !Paused ) {
238                 return;
239         }
240
241         // unpause all beam weapon sounds
242         beam_unpause_sounds();
243
244         // deinit stuff
245         if(Game_mode & GM_STANDALONE_SERVER){
246                 multi_pause_close();
247         } else {
248                 gr_free_screen(Pause_saved_screen);     
249
250                 if (Pause_background_bitmap){
251                         bm_unload(Pause_background_bitmap);
252                 }
253
254                 Pause_win.destroy();            
255                 game_flush();
256                 if (multi) {
257                         multi_pause_close();
258                 }
259
260                 // unpause all the music
261                 audiostream_unpause_all();              
262         }
263
264         Paused = 0;
265 }
266
267 // debug pause init
268 void pause_debug_init()
269 {
270         Pause_win.create( 100,100,400,300, WIN_DIALOG );
271
272         Pause_physics.create( &Pause_win, NOX("Physics Pause <P>"), 200, 150, physics_paused );
273         Pause_ai.create( &Pause_win, NOX("AI Pause <A>"), 200, 175, ai_paused );
274         #ifndef NDEBUG
275         Pause_ai_render.create( &Pause_win, NOX("AI Render Stuff <R>"), 200, 200, Ai_render_debug_flag);
276         #endif
277         Pause_firing.create( &Pause_win, NOX("AI firing <F>"), 200, 225, Ai_firing_enabled);
278         Pause_external_view_mode_check.create( &Pause_win, NOX("External View <E>"), 200, 250, Pause_external_view_mode);
279         Pause_single_step.create( &Pause_win, NOX("Single Step <S>"), 200, 290, game_single_step );
280         Pause_continue.create( &Pause_win, NOX("Leave Pause"), 200, 350, 200, 40 );
281
282         Pause_single_step.set_hotkey( SDLK_s );
283         Pause_physics.set_hotkey( SDLK_p );
284         Pause_ai.set_hotkey( SDLK_a );
285         Pause_ai_render.set_hotkey( SDLK_r );
286         Pause_firing.set_hotkey( SDLK_f );
287         Pause_external_view_mode_check.set_hotkey( SDLK_e );
288         Pause_continue.set_hotkey( SDLK_ESCAPE );
289
290         Pause_continue.set_focus();
291 }
292
293 // debug pause do frame
294 void pause_debug_do()
295 {
296         int key;
297
298         key = Pause_win.process();
299         if ( Pause_single_step.changed())       {
300                 game_single_step = Pause_single_step.checked();
301         }
302
303         if ( Pause_physics.changed())   {
304                 physics_paused = Pause_physics.checked();
305         }
306
307         if ( Pause_ai.changed())        {
308                 ai_paused = Pause_ai.checked();
309                 if (ai_paused){
310                         obj_init_all_ships_physics();
311                 }
312         }
313
314         if ( Pause_ai_render.changed()) {
315                 Ai_render_debug_flag = Pause_ai_render.checked();
316         }
317
318         if ( Pause_firing.changed())    {
319                 Ai_firing_enabled = Pause_firing.checked();
320         }
321
322         if ( Pause_external_view_mode_check.changed())  {
323                 Pause_external_view_mode = Pause_external_view_mode_check.checked();
324                 if (Pause_external_view_mode){
325                         HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "External view of player ship.", 182));
326                 } else {
327                         HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "View from inside player ship.", 183));
328                 }
329         }
330
331         if ( Pause_continue.pressed() || (key == SDLK_PAUSE) )  {       //      Changed, MK, 11/9/97, only Pause break pause.
332                 gameseq_post_event(GS_EVENT_PREVIOUS_STATE);
333         }
334
335         gr_clear();
336         Pause_win.draw();
337
338         gr_flip();
339 }
340
341 // debug pause close
342 void pause_debug_close()
343 {
344         last_single_step = 0;   // Make so single step waits a frame before stepping
345         Pause_win.destroy();
346         game_flush();
347 }
348