]> icculus.org git repositories - btb/d2x.git/blob - main/paging.c
remove DirectDraw use and Windows mouse stuff made redundant by SDL (lots of WINDOWS...
[btb/d2x.git] / main / paging.c
1 /* $Id: paging.c,v 1.5 2005-08-02 06:13:56 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 for paging in/out textures.
18  *
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include <conf.h>
23 #endif
24
25 //#define PSX_BUILD_TOOLS
26
27 #ifdef RCS
28 static char rcsid[] = "$Id: paging.c,v 1.5 2005-08-02 06:13:56 chris Exp $";
29 #endif
30
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <math.h>
34 #include <string.h>
35
36 #include "pstypes.h"
37 #include "mono.h"
38 #include "inferno.h"
39 #include "segment.h"
40 #include "textures.h"
41 #include "wall.h"
42 #include "object.h"
43 #include "gamemine.h"
44 #include "error.h"
45 #include "gameseg.h"
46 #include "game.h"
47 #include "piggy.h"
48 #include "texmerge.h"
49 #include "polyobj.h"
50 #include "vclip.h"
51 #include "effects.h"
52 #include "fireball.h"
53 #include "weapon.h"
54 #include "palette.h"
55 #include "timer.h"
56 #include "text.h"
57 #include "cntrlcen.h"
58 #include "gauges.h"
59 #include "powerup.h"
60 #include "fuelcen.h"
61 #include "mission.h"
62
63
64 void paging_touch_vclip( vclip * vc )
65 {
66         int i;
67
68         for (i=0; i<vc->num_frames; i++ )       {
69                 PIGGY_PAGE_IN( vc->frames[i] );
70         }
71 }
72
73
74 void paging_touch_wall_effects( int tmap_num )
75 {
76         int i;
77
78         for (i=0;i<Num_effects;i++)     {
79                 if ( Effects[i].changing_wall_texture == tmap_num )     {
80                         paging_touch_vclip( &Effects[i].vc );
81
82                         if (Effects[i].dest_bm_num > -1)
83                                 PIGGY_PAGE_IN( Textures[Effects[i].dest_bm_num] );      //use this bitmap when monitor destroyed
84                         if ( Effects[i].dest_vclip > -1 )
85                                 paging_touch_vclip( &Vclip[Effects[i].dest_vclip] );              //what vclip to play when exploding
86
87                         if ( Effects[i].dest_eclip > -1 )
88                                 paging_touch_vclip( &Effects[Effects[i].dest_eclip].vc ); //what eclip to play when exploding
89
90                         if ( Effects[i].crit_clip > -1 )
91                                 paging_touch_vclip( &Effects[Effects[i].crit_clip].vc ); //what eclip to play when mine critical
92                 }
93
94         }
95 }
96
97 void paging_touch_object_effects( int tmap_num )
98 {
99         int i;
100
101         for (i=0;i<Num_effects;i++)     {
102                 if ( Effects[i].changing_object_texture == tmap_num )   {
103                         paging_touch_vclip( &Effects[i].vc );
104                 }
105         }
106 }
107
108
109 void paging_touch_model( int modelnum )
110 {
111         int i;
112         polymodel *pm = &Polygon_models[modelnum];
113
114         for (i=0;i<pm->n_textures;i++)  {
115                 PIGGY_PAGE_IN( ObjBitmaps[ObjBitmapPtrs[pm->first_texture+i]] );
116                 paging_touch_object_effects( ObjBitmapPtrs[pm->first_texture+i] );
117                 #ifdef PSX_BUILD_TOOLS
118                 // cmp added
119                 paging_touch_object_effects( pm->first_texture+i );
120                 #endif
121         }
122 }
123
124 void paging_touch_weapon( int weapon_type )
125 {
126         // Page in the robot's weapons.
127         
128         if ( (weapon_type < 0) || (weapon_type > N_weapon_types) ) return;
129
130         if ( Weapon_info[weapon_type].picture.index )   {
131                 PIGGY_PAGE_IN( Weapon_info[weapon_type].picture );
132         }               
133         
134         if ( Weapon_info[weapon_type].flash_vclip > -1 )
135                 paging_touch_vclip(&Vclip[Weapon_info[weapon_type].flash_vclip]);
136         if ( Weapon_info[weapon_type].wall_hit_vclip > -1 )
137                 paging_touch_vclip(&Vclip[Weapon_info[weapon_type].wall_hit_vclip]);
138         if ( Weapon_info[weapon_type].damage_radius )   {
139                 // Robot_hit_vclips are actually badass_vclips
140                 if ( Weapon_info[weapon_type].robot_hit_vclip > -1 )
141                         paging_touch_vclip(&Vclip[Weapon_info[weapon_type].robot_hit_vclip]);
142         }
143
144         switch( Weapon_info[weapon_type].render_type )  {
145         case WEAPON_RENDER_VCLIP:
146                 if ( Weapon_info[weapon_type].weapon_vclip > -1 )
147                         paging_touch_vclip( &Vclip[Weapon_info[weapon_type].weapon_vclip] );
148                 break;
149         case WEAPON_RENDER_NONE:
150                 break;
151         case WEAPON_RENDER_POLYMODEL:
152                 paging_touch_model( Weapon_info[weapon_type].model_num );
153                 break;
154         case WEAPON_RENDER_BLOB:
155                 PIGGY_PAGE_IN( Weapon_info[weapon_type].bitmap );
156                 break;
157         }
158 }
159
160
161
162 sbyte super_boss_gate_type_list[13] = {0, 1, 8, 9, 10, 11, 12, 15, 16, 18, 19, 20, 22 };
163
164 void paging_touch_robot( int robot_index )
165 {
166         int i;
167
168         //mprintf((0, "Robot %d loading...", robot_index));
169
170         // Page in robot_index
171         paging_touch_model(Robot_info[robot_index].model_num);
172         if ( Robot_info[robot_index].exp1_vclip_num>-1 )
173                 paging_touch_vclip(&Vclip[Robot_info[robot_index].exp1_vclip_num]);
174         if ( Robot_info[robot_index].exp2_vclip_num>-1 )
175                 paging_touch_vclip(&Vclip[Robot_info[robot_index].exp2_vclip_num]);
176
177         // Page in his weapons
178         paging_touch_weapon( Robot_info[robot_index].weapon_type );
179
180         // A super-boss can gate in robots...
181         if ( Robot_info[robot_index].boss_flag==2 )     {
182                 for (i=0; i<13; i++ )
183                         paging_touch_robot(super_boss_gate_type_list[i]);
184
185                 paging_touch_vclip( &Vclip[VCLIP_MORPHING_ROBOT] );
186         }
187 }
188
189
190 void paging_touch_object( object * obj )
191 {
192         int v;
193
194         switch (obj->render_type) {
195
196                 case RT_NONE:   break;          //doesn't render, like the player
197
198                 case RT_POLYOBJ:
199                         if ( obj->rtype.pobj_info.tmap_override != -1 )
200                                 PIGGY_PAGE_IN( Textures[obj->rtype.pobj_info.tmap_override] );
201                         else
202                                 paging_touch_model(obj->rtype.pobj_info.model_num);
203                         break;
204
205                 case RT_POWERUP:
206                         if ( obj->rtype.vclip_info.vclip_num > -1 ) {
207                                 paging_touch_vclip(&Vclip[obj->rtype.vclip_info.vclip_num]);
208                         }
209                         break;
210
211                 case RT_MORPH:  break;
212
213                 case RT_FIREBALL: break;
214
215                 case RT_WEAPON_VCLIP: break;
216
217                 case RT_HOSTAGE:
218                         paging_touch_vclip(&Vclip[obj->rtype.vclip_info.vclip_num]);
219                         break;
220
221                 case RT_LASER: break;
222         }
223
224         switch (obj->type) {    
225         case OBJ_PLAYER:        
226                 v = get_explosion_vclip(obj, 0);
227                 if ( v > -1 )
228                         paging_touch_vclip(&Vclip[v]);
229                 break;
230         case OBJ_ROBOT:
231                 paging_touch_robot( obj->id );
232                 break;
233         case OBJ_CNTRLCEN:
234                 paging_touch_weapon( CONTROLCEN_WEAPON_NUM );
235                 if (Dead_modelnums[obj->rtype.pobj_info.model_num] != -1)       {
236                         paging_touch_model( Dead_modelnums[obj->rtype.pobj_info.model_num] );
237                 }
238                 break;
239         }
240 }
241
242         
243
244 void paging_touch_side( segment * segp, int sidenum )
245 {
246         int tmap1, tmap2;
247
248         if (!(WALL_IS_DOORWAY(segp,sidenum) & WID_RENDER_FLAG))
249                 return;
250         
251         tmap1 = segp->sides[sidenum].tmap_num;
252         paging_touch_wall_effects(tmap1);
253         tmap2 = segp->sides[sidenum].tmap_num2;
254         if (tmap2 != 0) {
255                 texmerge_get_cached_bitmap( tmap1, tmap2 );
256                 paging_touch_wall_effects( tmap2 & 0x3FFF );
257         } else  {
258                 PIGGY_PAGE_IN( Textures[tmap1] );
259         }
260
261         // PSX STUFF
262         #ifdef PSX_BUILD_TOOLS
263                 // If there is water on the level, then force the water splash into memory
264                 if(!(TmapInfo[tmap1].flags & TMI_VOLATILE) && (TmapInfo[tmap1].flags & TMI_WATER)) {
265                         bitmap_index Splash;
266                         Splash.index = 1098;
267                         PIGGY_PAGE_IN(Splash);
268                         Splash.index = 1099;
269                         PIGGY_PAGE_IN(Splash);
270                         Splash.index = 1100;
271                         PIGGY_PAGE_IN(Splash);
272                         Splash.index = 1101;
273                         PIGGY_PAGE_IN(Splash);
274                         Splash.index = 1102;
275                         PIGGY_PAGE_IN(Splash);
276                 }
277         #endif
278
279 }
280
281 void paging_touch_robot_maker( segment * segp )
282 {
283         segment2        *seg2p = &Segment2s[segp-Segments];
284
285         if ( seg2p->special == SEGMENT_IS_ROBOTMAKER )  {
286                 paging_touch_vclip(&Vclip[VCLIP_MORPHING_ROBOT]);
287                 if (RobotCenters[seg2p->matcen_num].robot_flags != 0) {
288                         int     i;
289                         uint    flags;
290                         int     robot_index;
291
292                         for (i=0;i<2;i++) {
293                                 robot_index = i*32;
294                                 flags = RobotCenters[seg2p->matcen_num].robot_flags[i];
295                                 while (flags) {
296                                         if (flags & 1)  {
297                                                 // Page in robot_index
298                                                 paging_touch_robot( robot_index );
299                                         }
300                                         flags >>= 1;
301                                         robot_index++;
302                                 }
303                         }
304                 }
305         }
306 }
307
308
309 void paging_touch_segment(segment * segp)
310 {
311         int sn;
312         int objnum;
313         segment2        *seg2p = &Segment2s[segp-Segments];
314
315         if ( seg2p->special == SEGMENT_IS_ROBOTMAKER )  
316                 paging_touch_robot_maker(segp);
317
318 //      paging_draw_orb();
319         for (sn=0;sn<MAX_SIDES_PER_SEGMENT;sn++) {
320 //              paging_draw_orb();
321                 paging_touch_side( segp, sn );
322         }
323
324         for (objnum=segp->objects;objnum!=-1;objnum=Objects[objnum].next)       {
325 //              paging_draw_orb();
326                 paging_touch_object( &Objects[objnum] );
327         }
328 }
329
330
331
332 void paging_touch_walls()
333 {
334         int i,j;
335         wclip *anim;
336
337         for (i=0;i<Num_walls;i++) {
338 //              paging_draw_orb();
339                 if ( Walls[i].clip_num > -1 )   {
340                         anim = &WallAnims[Walls[i].clip_num];
341                         for (j=0; j < anim->num_frames; j++ )   {
342                                 PIGGY_PAGE_IN( Textures[anim->frames[j]] );
343                         }
344                 }
345         }
346 }
347
348 void paging_touch_all()
349 {
350         int black_screen;
351         int s;
352         
353         stop_time();
354
355         black_screen = gr_palette_faded_out;
356
357         if ( gr_palette_faded_out )     {
358                 gr_clear_canvas( BM_XRGB(0,0,0) );
359                 gr_palette_load( gr_palette );
360         }
361         
362 //@@    show_boxed_message(TXT_LOADING);
363
364         mprintf(( 0, "Loading all textures in mine..." ));
365         for (s=0; s<=Highest_segment_index; s++)        {
366                 paging_touch_segment( &Segments[s] );
367         }       
368         paging_touch_walls();
369
370         for ( s=0; s < N_powerup_types; s++ )   {
371                 if ( Powerup_info[s].vclip_num > -1 )   
372                         paging_touch_vclip(&Vclip[Powerup_info[s].vclip_num]);
373         }
374
375         for ( s=0; s<N_weapon_types; s++ )      {
376                 paging_touch_weapon(s);
377         }
378
379         for ( s=0; s < N_powerup_types; s++ )   {
380                 if ( Powerup_info[s].vclip_num > -1 )   
381                         paging_touch_vclip(&Vclip[Powerup_info[s].vclip_num]);
382         }
383
384
385         for (s=0; s<MAX_GAUGE_BMS; s++ )        {
386                 if ( Gauges[s].index )  {
387                         PIGGY_PAGE_IN( Gauges[s] );
388                 }
389         }
390         paging_touch_vclip( &Vclip[VCLIP_PLAYER_APPEARANCE] );
391         paging_touch_vclip( &Vclip[VCLIP_POWERUP_DISAPPEARANCE] );
392
393
394 #ifdef PSX_BUILD_TOOLS
395
396         //PSX STUFF
397         paging_touch_walls();
398         for(s=0; s<=Highest_object_index; s++) {
399                 paging_touch_object(&Objects[s]);
400         }
401
402
403         {
404                 char * p;
405                 extern int Current_level_num;
406                 extern ushort GameBitmapXlat[MAX_BITMAP_FILES];
407                 short Used[MAX_BITMAP_FILES];
408                 FILE * fp;
409                 char fname[128];
410                 int i;
411
412                 if (Current_level_num<0)                //secret level
413                         strcpy( fname, Secret_level_names[-Current_level_num-1] );
414                 else                                    //normal level
415                         strcpy( fname, Level_names[Current_level_num-1] );
416                 p = strchr( fname, '.' );
417                 if ( p ) *p = 0;
418                 strcat( fname, ".pag" );
419
420                 fp = fopen( fname, "wt" );
421                 for (i=0; i<MAX_BITMAP_FILES;i++ )      {
422                         Used[i] = 0;
423                 }
424                 for (i=0; i<MAX_BITMAP_FILES;i++ )      {
425                         Used[GameBitmapXlat[i]]++;
426                 }
427
428                 //cmp added so that .damage bitmaps are included for paged-in lights of the current level
429                 for (i=0; i<MAX_TEXTURES;i++) {
430                         if(Textures[i].index > 0 && Textures[i].index < MAX_BITMAP_FILES &&
431                                 Used[Textures[i].index] > 0 &&
432                                 TmapInfo[i].destroyed > 0 && TmapInfo[i].destroyed < MAX_BITMAP_FILES) {
433                                 Used[Textures[TmapInfo[i].destroyed].index] += 1;
434                                 mprintf((0, "HERE %d ", Textures[TmapInfo[i].destroyed].index));
435
436                                 PIGGY_PAGE_IN(Textures[TmapInfo[i].destroyed]);
437
438                         }
439                 }
440
441                 //      Force cockpit to be paged in.
442                 {
443                         bitmap_index bonk;
444                         bonk.index = 109;
445                         PIGGY_PAGE_IN(bonk);
446                 }
447
448                 // Force in the frames for markers
449                 {
450                         bitmap_index bonk2;
451                         bonk2.index = 2014;
452                         PIGGY_PAGE_IN(bonk2);
453                         bonk2.index = 2015;
454                         PIGGY_PAGE_IN(bonk2);
455                         bonk2.index = 2016;
456                         PIGGY_PAGE_IN(bonk2);
457                         bonk2.index = 2017;
458                         PIGGY_PAGE_IN(bonk2);
459                         bonk2.index = 2018;
460                         PIGGY_PAGE_IN(bonk2);
461                 }
462
463                 for (i=0; i<MAX_BITMAP_FILES;i++ )      {
464                         int paged_in = 1;
465                         // cmp debug
466                         //piggy_get_bitmap_name(i,fname);
467
468                         if (GameBitmaps[i].bm_flags & BM_FLAG_PAGED_OUT )
469                                 paged_in = 0;
470
471 //                      if (GameBitmapXlat[i]!=i)
472 //                              paged_in = 0;
473
474                         if ( !Used[i] )
475                                 paged_in = 0;
476                         if ( (i==47) || (i==48) )               // Mark red mplayer ship textures as paged in.
477                                 paged_in = 1;
478         
479                         if ( !paged_in )
480                                 fprintf( fp, "0,\t// Bitmap %d (%s)\n", i, "test\0"); // cmp debug fname );
481                         else
482                                 fprintf( fp, "1,\t// Bitmap %d (%s)\n", i, "test\0"); // cmp debug fname );
483                 }
484
485                 fclose(fp);
486         }
487 #endif
488
489         mprintf(( 0, "done\n" ));
490
491 //@@    clear_boxed_message();
492
493         if ( black_screen )     {
494                 gr_palette_clear();
495                 gr_clear_canvas( BM_XRGB(0,0,0) );
496         }
497         start_time();
498         reset_cockpit();                //force cockpit redraw next time
499
500 }
501