]> icculus.org git repositories - btb/d2x.git/blob - main/credits.c
remove all the redundant Polygon Acceleration stuff (include/pa_enabl.h)
[btb/d2x.git] / main / credits.c
1 /* $Id: credits.c,v 1.13 2005-07-30 01:50:17 chris Exp $ */
2 /*
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
13 */
14
15 /*
16  *
17  * Routines to display the credits.
18  *
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include <conf.h>
23 #endif
24
25 #ifdef RCS
26 static char rcsid[] = "$Id: credits.c,v 1.13 2005-07-30 01:50:17 chris Exp $";
27 #endif
28
29 #ifdef WINDOWS
30 #include "desw.h"
31 #endif
32
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <stdarg.h>
37 #include <ctype.h>
38
39 #include "error.h"
40 #include "pstypes.h"
41 #include "gr.h"
42 #include "mono.h"
43 #include "key.h"
44 #include "palette.h"
45 #include "game.h"
46 #include "gamepal.h"
47 #include "timer.h"
48
49 #include "newmenu.h"
50 #include "gamefont.h"
51 #ifdef NETWORK
52 #include "network.h"
53 #endif
54 #include "iff.h"
55 #include "pcx.h"
56 #include "u_mem.h"
57 #include "mouse.h"
58 #include "joy.h"
59 #include "screens.h"
60 #include "digi.h"
61
62 #include "cfile.h"
63 #include "text.h"
64 #include "songs.h"
65 #include "menu.h"  // for MenuHires
66
67 #define ROW_SPACING (MenuHires?26:11)
68 #define NUM_LINES_HIRES 21
69 #define NUM_LINES (MenuHires?NUM_LINES_HIRES:20)
70
71 ubyte fade_values[200] = { 1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,8,9,9,10,10,
72 11,11,12,12,12,13,13,14,14,15,15,15,16,16,17,17,17,18,18,19,19,19,20,20,
73 20,21,21,22,22,22,23,23,23,24,24,24,24,25,25,25,26,26,26,26,27,27,27,27,
74 28,28,28,28,28,29,29,29,29,29,29,30,30,30,30,30,30,30,30,30,31,31,31,31,
75 31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,30,30,30,30,30,
76 30,30,30,30,29,29,29,29,29,29,28,28,28,28,28,27,27,27,27,26,26,26,26,25,
77 25,25,24,24,24,24,23,23,23,22,22,22,21,21,20,20,20,19,19,19,18,18,17,17,
78 17,16,16,15,15,15,14,14,13,13,12,12,12,11,11,10,10,9,9,8,8,8,7,7,6,6,5,
79 5,4,4,3,3,2,2,1 };
80
81 ubyte fade_values_hires[480] = { 1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,5,5,5,
82 5,5,5,6,6,6,6,6,7,7,7,7,7,8,8,8,8,8,9,9,9,9,9,10,10,10,10,10,10,11,11,11,11,11,12,12,12,12,12,12,
83 13,13,13,13,13,14,14,14,14,14,14,15,15,15,15,15,15,16,16,16,16,16,17,17,17,17,17,17,18,18,
84 18,18,18,18,18,19,19,19,19,19,19,20,20,20,20,20,20,20,21,21,21,21,21,21,22,22,22,22,22,22,
85 22,22,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,25,25,25,25,25,25,25,25,25,26,26,26,26,
86 26,26,26,26,26,27,27,27,27,27,27,27,27,27,27,28,28,28,28,28,28,28,28,28,28,28,28,29,29,29,
87 29,29,29,29,29,29,29,29,29,29,29,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
88 30,30,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,
89 31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,30,30,30,
90 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,29,29,29,29,29,29,29,29,29,29,29,29,
91 29,29,28,28,28,28,28,28,28,28,28,28,28,28,27,27,27,27,27,27,27,27,27,27,26,26,26,26,26,26,
92 26,26,26,25,25,25,25,25,25,25,25,25,24,24,24,24,24,24,24,24,23,23,23,23,23,23,23,22,22,22,
93 22,22,22,22,22,21,21,21,21,21,21,20,20,20,20,20,20,20,19,19,19,19,19,19,18,18,18,18,18,18,
94 18,17,17,17,17,17,17,16,16,16,16,16,15,15,15,15,15,15,14,14,14,14,14,14,13,13,13,13,13,12,
95 12,12,12,12,12,11,11,11,11,11,10,10,10,10,10,10,9,9,9,9,9,8,8,8,8,8,7,7,7,7,7,6,6,6,6,6,5,5,5,5,
96 5,5,4,4,4,4,4,3,3,3,3,3,2,2,2,2,2,1,1};
97
98 extern ubyte *gr_bitblt_fade_table;
99
100 grs_font * header_font;
101 grs_font * title_font;
102 grs_font * names_font;
103
104 #ifdef SHAREWARE
105 #define ALLOWED_CHAR 'S'
106 #else
107 #define ALLOWED_CHAR 'R'
108 #endif
109
110 #ifdef RELEASE
111 #define CREDITS_BACKGROUND_FILENAME (MenuHires?"\x01starsb.pcx":"\x01stars.pcx")        //only read from hog file
112 #else
113 #define CREDITS_BACKGROUND_FILENAME (MenuHires?"starsb.pcx":"stars.pcx")
114 #endif
115
116 typedef struct box {
117         int left, top, width, height;
118 } box;
119
120 #define CREDITS_FILE    (cfexist("mcredits.tex")?"mcredits.tex":cfexist("ocredits.tex")?"ocredits.tex":"credits.tex")
121
122 //if filename passed is NULL, show normal credits
123 void credits_show(char *credits_filename)
124 {
125         int i, j, l, done;
126         CFILE * file;
127         char buffer[NUM_LINES_HIRES][80];
128         grs_bitmap backdrop;
129         ubyte backdrop_palette[768];
130         int pcx_error;
131         int buffer_line = 0;
132         fix last_time;
133 //      fix time_delay = 4180;                  // ~ F1_0 / 12.9
134 //      fix time_delay = 1784;
135         fix time_delay = 2800;
136         int first_line_offset,extra_inc=0;
137         int have_bin_file = 0;
138         char * tempp;
139         char filename[32];
140
141 WIN(int credinit = 0;)
142
143         box dirty_box[NUM_LINES_HIRES];
144         grs_canvas *CreditsOffscreenBuf=NULL;
145
146         WINDOS(
147                 dd_grs_canvas *save_canv,
148                 grs_canvas *save_canv
149         );
150
151         WINDOS(
152                 save_canv = dd_grd_curcanv,
153                 save_canv = grd_curcanv
154         );
155
156         // Clear out all tex buffer lines.
157         for (i=0; i<NUM_LINES; i++ )
158         {
159                 buffer[i][0] = 0;
160                 dirty_box[i].left = dirty_box[i].top = dirty_box[i].width = dirty_box[i].height = 0;
161         }
162
163
164         sprintf(filename, "%s", CREDITS_FILE);
165         have_bin_file = 0;
166         if (credits_filename) {
167                 strcpy(filename,credits_filename);
168                 have_bin_file = 1;
169         }
170         file = cfopen( filename, "rb" );
171         if (file == NULL) {
172                 char nfile[32];
173                 
174                 if (credits_filename)
175                         return;         //ok to not find special filename
176
177                 tempp = strchr(filename, '.');
178                 *tempp = '\0';
179                 sprintf(nfile, "%s.txb", filename);
180                 file = cfopen(nfile, "rb");
181                 if (file == NULL)
182                         Error("Missing CREDITS.TEX and CREDITS.TXB file\n");
183                 have_bin_file = 1;
184         }
185
186         set_screen_mode(SCREEN_MENU);
187
188         WIN(DEFINE_SCREEN(NULL));
189
190 #ifdef WINDOWS
191 CreditsPaint:
192 #endif
193         gr_use_palette_table( "credits.256" );
194 #ifdef OGL
195         gr_palette_load(gr_palette);
196 #endif
197         header_font = gr_init_font( MenuHires?"font1-1h.fnt":"font1-1.fnt" );
198         title_font = gr_init_font( MenuHires?"font2-3h.fnt":"font2-3.fnt" );
199         names_font = gr_init_font( MenuHires?"font2-2h.fnt":"font2-2.fnt" );
200         backdrop.bm_data=NULL;
201
202 //MWA  Made backdrop bitmap linear since it should always be.  the current canvas may not
203 //MWA  be linear, so we can't rely on grd_curcanv->cv_bitmap->bm_type.
204
205         pcx_error = pcx_read_bitmap(CREDITS_BACKGROUND_FILENAME,&backdrop, BM_LINEAR,backdrop_palette);
206         if (pcx_error != PCX_ERROR_NONE)                {
207                 cfclose(file);
208                 return;
209         }
210
211         songs_play_song( SONG_CREDITS, 1 );
212
213         gr_remap_bitmap_good( &backdrop,backdrop_palette, -1, -1 );
214
215 WINDOS(
216         dd_gr_set_current_canvas(NULL), 
217         gr_set_current_canvas(NULL)
218 );
219 WIN(DDGRLOCK(dd_grd_curcanv));
220         gr_bitmap(0,0,&backdrop);
221 WIN(DDGRUNLOCK(dd_grd_curcanv));
222         gr_update();
223         gr_palette_fade_in( gr_palette, 32, 0 );
224
225 //      Create a new offscreen buffer for the credits screen
226 //MWA  Let's be a little smarter about this and check the VR_offscreen buffer
227 //MWA  for size to determine if we can use that buffer.  If the game size
228 //MWA  matches what we need, then lets save memory.
229
230 #ifndef WINDOWS
231         if (MenuHires && VR_offscreen_buffer->cv_w == 640)      {
232                 CreditsOffscreenBuf = VR_offscreen_buffer;
233         }
234         else if (MenuHires)     {
235                 CreditsOffscreenBuf = gr_create_canvas(640,480);
236         }
237         else {
238                 CreditsOffscreenBuf = gr_create_canvas(320,200);
239         }
240 #else
241         CreditsOffscreenBuf = gr_create_canvas(640,480);
242 #endif                          
243
244         if (!CreditsOffscreenBuf)
245                 Error("Not enough memory to allocate Credits Buffer.");
246
247         //gr_clear_canvas(BM_XRGB(0,0,0));
248         key_flush();
249
250 #ifdef WINDOWS
251         if (!credinit)  
252 #endif
253         {
254                 last_time = timer_get_fixed_seconds();
255                 done = 0;
256                 first_line_offset = 0;
257         }
258
259         WIN(credinit = 1);
260
261         while( 1 )      {
262                 int k;
263
264                 do {
265                         buffer_line = (buffer_line+1) % NUM_LINES;
266 get_line:;
267                         if (cfgets( buffer[buffer_line], 80, file ))    {
268                                 char *p;
269                                 if (have_bin_file) // is this a binary tbl file
270                                         decode_text_line (buffer[buffer_line]);
271                                 p = buffer[buffer_line];
272                                 if (p[0] == ';')
273                                         goto get_line;
274
275                                 if (p[0] == '%')
276                                 {
277                                         if (p[1] == ALLOWED_CHAR)
278                                                 strcpy(p,p+2);
279                                         else
280                                                 goto get_line;
281                                 }
282
283                         } else  {
284                                 //fseek( file, 0, SEEK_SET);
285                                 buffer[buffer_line][0] = 0;
286                                 done++;
287                         }
288                 } while (extra_inc--);
289                 extra_inc = 0;
290
291                 for (i=0; i<ROW_SPACING; i += (MenuHires?2:1) ) {
292                         int y;
293
294                         y = first_line_offset - i;
295
296                         gr_set_current_canvas(CreditsOffscreenBuf);
297                 
298                         gr_bitmap(0,0,&backdrop);
299
300                         for (j=0; j<NUM_LINES; j++ )    {
301                                 char *s;
302
303                                 l = (buffer_line + j + 1 ) %  NUM_LINES;
304                                 s = buffer[l];
305
306                                 if ( s[0] == '!' ) {
307                                         s++;
308                                 } else if ( s[0] == '$' )       {
309                                         grd_curcanv->cv_font = header_font;
310                                         s++;
311                                 } else if ( s[0] == '*' )       {
312                                         grd_curcanv->cv_font = title_font;
313                                         s++;
314                                 } else
315                                         grd_curcanv->cv_font = names_font;
316
317                                 gr_bitblt_fade_table = (MenuHires?fade_values_hires:fade_values);
318
319                                 tempp = strchr( s, '\t' );
320                                 if ( tempp )    {
321                                 //      Wacky Credits thing
322                                         int w, h, aw, w2, x1, x2;
323
324                                         *tempp = 0;
325                                         gr_get_string_size( s, &w, &h, &aw );
326                                         x1 = ((MenuHires?320:160)-w)/2;
327                                         gr_printf( x1 , y, s );
328                                         gr_get_string_size( &tempp[1], &w2, &h, &aw );
329                                         x2 = (MenuHires?320:160)+(((MenuHires?320:160)-w2)/2);
330                                         gr_printf( x2, y, &tempp[1] );
331
332                                         dirty_box[j].left = ((MenuHires?320:160)-w)/2;
333                                         dirty_box[j].top = y;
334                                         dirty_box[j].width =(x2+w2)-x1;
335                                         dirty_box[j].height = h;
336
337                                         *tempp = '\t';
338                 
339                                 } else {
340                                 // Wacky Fast Credits thing
341                                         int w, h, aw;
342
343                                         gr_get_string_size( s, &w, &h, &aw);
344                                         dirty_box[j].width = w;
345                                 dirty_box[j].height = h;
346                                 dirty_box[j].top = y;
347                                 dirty_box[j].left = ((MenuHires?640:320) - w) / 2;
348
349                                         gr_printf( 0x8000, y, s );
350                                 }
351                                 gr_bitblt_fade_table = NULL;
352                                 if (buffer[l][0] == '!')
353                                         y += ROW_SPACING/2;
354                                 else
355                                         y += ROW_SPACING;
356                         }
357
358                         {       // Wacky Fast Credits Thing
359                                 box     *new_box;
360                                 grs_bitmap *tempbmp;
361
362                                 for (j=0; j<NUM_LINES; j++ )
363                                 {
364                                         new_box = &dirty_box[j];
365
366                                         tempbmp = &(CreditsOffscreenBuf->cv_bitmap);
367
368                                 WIN(DDGRSCREENLOCK);
369                                         gr_bm_bitblt( new_box->width + 1, new_box->height +4,
370                                                                 new_box->left, new_box->top, new_box->left, new_box->top,
371                                                                 tempbmp, &(grd_curscreen->sc_canvas.cv_bitmap) );
372                                 WIN(DDGRSCREENUNLOCK);
373                                 }
374
375 #ifndef OGL
376                                 for (j=0; j<NUM_LINES; j++ )
377                                 {
378                                         new_box = &dirty_box[j];
379
380                                         tempbmp = &(CreditsOffscreenBuf->cv_bitmap);
381
382                                         gr_bm_bitblt(   new_box->width
383                                                                         ,new_box->height+2
384                                                                         ,new_box->left
385                                                                         ,new_box->top
386                                                                         ,new_box->left
387                                                                         ,new_box->top
388                                                                         ,&backdrop
389                                                                         ,tempbmp );
390                                 }
391                                 
392 #endif
393                         gr_update();
394                                 
395                         }
396
397 //              Wacky Fast Credits thing doesn't need this (it's done above)
398 //@@            WINDOS(
399 //@@                    dd_gr_blt_notrans(CreditsOffscreenBuf, 0,0,0,0, dd_grd_screencanv, 0,0,0,0),
400 //@@                    gr_bm_ubitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(CreditsOffscreenBuf->cv_bitmap), &(grd_curscreen->sc_canvas.cv_bitmap) );
401 //@@            );
402
403 //                      mprintf( ( 0, "Fr = %d", (timer_get_fixed_seconds() - last_time) ));
404                         while( timer_get_fixed_seconds() < last_time+time_delay );
405                         last_time = timer_get_fixed_seconds();
406                 
407                 #ifdef WINDOWS
408                         {
409                                 MSG msg;
410
411                                 DoMessageStuff(&msg);
412
413                                 if (_RedrawScreen) {
414                                         _RedrawScreen = FALSE;
415
416                                         gr_close_font(header_font);
417                                         gr_close_font(title_font);
418                                         gr_close_font(names_font);
419
420                                         d_free(backdrop.bm_data);
421                                         gr_free_canvas(CreditsOffscreenBuf);
422                 
423                                         goto CreditsPaint;
424                                 }
425
426                                 DDGRRESTORE;
427                         }
428                 #endif
429
430                         //see if redbook song needs to be restarted
431                         songs_check_redbook_repeat();
432
433                         k = key_inkey();
434
435                         #ifndef NDEBUG
436                         if (k == KEY_BACKSP) {
437                                 Int3();
438                                 k=0;
439                         }
440                         #endif
441
442 //                      {
443 //                              fix ot = time_delay;
444 //                              time_delay += (keyd_pressed[KEY_X] - keyd_pressed[KEY_Z])*100;
445 //                              if (ot!=time_delay)     {
446 //                                      mprintf( (0, "[%x] ", time_delay ));
447 //                              }
448 //                      }
449
450                         if (k == KEY_PRINT_SCREEN) {
451                                 save_screen_shot(0);
452                                 k = 0;
453                         }
454
455                         if ((k>0)||(done>NUM_LINES))    {
456                                         gr_close_font(header_font);
457                                         gr_close_font(title_font);
458                                         gr_close_font(names_font);
459                                         gr_palette_fade_out( gr_palette, 32, 0 );
460                                         gr_use_palette_table( DEFAULT_PALETTE );
461                                         d_free(backdrop.bm_data);
462                                         cfclose(file);
463                                 WINDOS(
464                                         dd_gr_set_current_canvas(save_canv),
465                                         gr_set_current_canvas(save_canv)
466                                 );
467                                         songs_play_song( SONG_TITLE, 1 );
468
469                                 #ifdef WINDOWS
470                                         gr_free_canvas(CreditsOffscreenBuf);
471                                 #else                                   
472                                         if (CreditsOffscreenBuf != VR_offscreen_buffer)
473                                                 gr_free_canvas(CreditsOffscreenBuf);
474                                 #endif
475
476                                 WIN(DEFINE_SCREEN(Menu_pcx_name));
477                         
478                                 return;
479                         }
480                 }
481
482                 if (buffer[(buffer_line + 1 ) %  NUM_LINES][0] == '!') {
483                         first_line_offset -= ROW_SPACING-ROW_SPACING/2;
484                         if (first_line_offset <= -ROW_SPACING) {
485                                 first_line_offset += ROW_SPACING;
486                                 extra_inc++;
487                         }
488                 }
489         }
490
491 }