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