1 /* $Id: paging.c,v 1.5 2005-08-02 06:13:56 chris Exp $ */
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.
17 * Routines for paging in/out textures.
25 //#define PSX_BUILD_TOOLS
28 static char rcsid[] = "$Id: paging.c,v 1.5 2005-08-02 06:13:56 chris Exp $";
64 void paging_touch_vclip( vclip * vc )
68 for (i=0; i<vc->num_frames; i++ ) {
69 PIGGY_PAGE_IN( vc->frames[i] );
74 void paging_touch_wall_effects( int tmap_num )
78 for (i=0;i<Num_effects;i++) {
79 if ( Effects[i].changing_wall_texture == tmap_num ) {
80 paging_touch_vclip( &Effects[i].vc );
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
87 if ( Effects[i].dest_eclip > -1 )
88 paging_touch_vclip( &Effects[Effects[i].dest_eclip].vc ); //what eclip to play when exploding
90 if ( Effects[i].crit_clip > -1 )
91 paging_touch_vclip( &Effects[Effects[i].crit_clip].vc ); //what eclip to play when mine critical
97 void paging_touch_object_effects( int tmap_num )
101 for (i=0;i<Num_effects;i++) {
102 if ( Effects[i].changing_object_texture == tmap_num ) {
103 paging_touch_vclip( &Effects[i].vc );
109 void paging_touch_model( int modelnum )
112 polymodel *pm = &Polygon_models[modelnum];
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
119 paging_touch_object_effects( pm->first_texture+i );
124 void paging_touch_weapon( int weapon_type )
126 // Page in the robot's weapons.
128 if ( (weapon_type < 0) || (weapon_type > N_weapon_types) ) return;
130 if ( Weapon_info[weapon_type].picture.index ) {
131 PIGGY_PAGE_IN( Weapon_info[weapon_type].picture );
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]);
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] );
149 case WEAPON_RENDER_NONE:
151 case WEAPON_RENDER_POLYMODEL:
152 paging_touch_model( Weapon_info[weapon_type].model_num );
154 case WEAPON_RENDER_BLOB:
155 PIGGY_PAGE_IN( Weapon_info[weapon_type].bitmap );
162 sbyte super_boss_gate_type_list[13] = {0, 1, 8, 9, 10, 11, 12, 15, 16, 18, 19, 20, 22 };
164 void paging_touch_robot( int robot_index )
168 //mprintf((0, "Robot %d loading...", robot_index));
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]);
177 // Page in his weapons
178 paging_touch_weapon( Robot_info[robot_index].weapon_type );
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]);
185 paging_touch_vclip( &Vclip[VCLIP_MORPHING_ROBOT] );
190 void paging_touch_object( object * obj )
194 switch (obj->render_type) {
196 case RT_NONE: break; //doesn't render, like the player
199 if ( obj->rtype.pobj_info.tmap_override != -1 )
200 PIGGY_PAGE_IN( Textures[obj->rtype.pobj_info.tmap_override] );
202 paging_touch_model(obj->rtype.pobj_info.model_num);
206 if ( obj->rtype.vclip_info.vclip_num > -1 ) {
207 paging_touch_vclip(&Vclip[obj->rtype.vclip_info.vclip_num]);
211 case RT_MORPH: break;
213 case RT_FIREBALL: break;
215 case RT_WEAPON_VCLIP: break;
218 paging_touch_vclip(&Vclip[obj->rtype.vclip_info.vclip_num]);
221 case RT_LASER: break;
226 v = get_explosion_vclip(obj, 0);
228 paging_touch_vclip(&Vclip[v]);
231 paging_touch_robot( obj->id );
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] );
244 void paging_touch_side( segment * segp, int sidenum )
248 if (!(WALL_IS_DOORWAY(segp,sidenum) & WID_RENDER_FLAG))
251 tmap1 = segp->sides[sidenum].tmap_num;
252 paging_touch_wall_effects(tmap1);
253 tmap2 = segp->sides[sidenum].tmap_num2;
255 texmerge_get_cached_bitmap( tmap1, tmap2 );
256 paging_touch_wall_effects( tmap2 & 0x3FFF );
258 PIGGY_PAGE_IN( Textures[tmap1] );
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)) {
267 PIGGY_PAGE_IN(Splash);
269 PIGGY_PAGE_IN(Splash);
271 PIGGY_PAGE_IN(Splash);
273 PIGGY_PAGE_IN(Splash);
275 PIGGY_PAGE_IN(Splash);
281 void paging_touch_robot_maker( segment * segp )
283 segment2 *seg2p = s2s2(segp);
285 if ( seg2p->special == SEGMENT_IS_ROBOTMAKER ) {
286 paging_touch_vclip(&Vclip[VCLIP_MORPHING_ROBOT]);
287 if (RobotCenters[seg2p->matcen_num].robot_flags != 0) {
294 flags = RobotCenters[seg2p->matcen_num].robot_flags[i];
297 // Page in robot_index
298 paging_touch_robot( robot_index );
309 void paging_touch_segment(segment * segp)
313 segment2 *seg2p = s2s2(segp);
315 if ( seg2p->special == SEGMENT_IS_ROBOTMAKER )
316 paging_touch_robot_maker(segp);
318 // paging_draw_orb();
319 for (sn=0;sn<MAX_SIDES_PER_SEGMENT;sn++) {
320 // paging_draw_orb();
321 paging_touch_side( segp, sn );
324 for (objnum=segp->objects;objnum!=-1;objnum=Objects[objnum].next) {
325 // paging_draw_orb();
326 paging_touch_object( &Objects[objnum] );
332 void paging_touch_walls()
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]] );
348 void paging_touch_all()
355 black_screen = gr_palette_faded_out;
357 if ( gr_palette_faded_out ) {
358 gr_clear_canvas( BM_XRGB(0,0,0) );
359 gr_palette_load( gr_palette );
362 //@@ show_boxed_message(TXT_LOADING);
364 mprintf(( 0, "Loading all textures in mine..." ));
365 for (s=0; s<=Highest_segment_index; s++) {
366 paging_touch_segment( &Segments[s] );
368 paging_touch_walls();
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]);
375 for ( s=0; s<N_weapon_types; s++ ) {
376 paging_touch_weapon(s);
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]);
385 for (s=0; s<MAX_GAUGE_BMS; s++ ) {
386 if ( Gauges[s].index ) {
387 PIGGY_PAGE_IN( Gauges[s] );
390 paging_touch_vclip( &Vclip[VCLIP_PLAYER_APPEARANCE] );
391 paging_touch_vclip( &Vclip[VCLIP_POWERUP_DISAPPEARANCE] );
394 #ifdef PSX_BUILD_TOOLS
397 paging_touch_walls();
398 for(s=0; s<=Highest_object_index; s++) {
399 paging_touch_object(&Objects[s]);
405 extern int Current_level_num;
406 extern ushort GameBitmapXlat[MAX_BITMAP_FILES];
407 short Used[MAX_BITMAP_FILES];
412 if (Current_level_num<0) //secret level
413 strcpy( fname, Secret_level_names[-Current_level_num-1] );
415 strcpy( fname, Level_names[Current_level_num-1] );
416 p = strchr( fname, '.' );
418 strcat( fname, ".pag" );
420 fp = fopen( fname, "wt" );
421 for (i=0; i<MAX_BITMAP_FILES;i++ ) {
424 for (i=0; i<MAX_BITMAP_FILES;i++ ) {
425 Used[GameBitmapXlat[i]]++;
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));
436 PIGGY_PAGE_IN(Textures[TmapInfo[i].destroyed]);
441 // Force cockpit to be paged in.
448 // Force in the frames for markers
452 PIGGY_PAGE_IN(bonk2);
454 PIGGY_PAGE_IN(bonk2);
456 PIGGY_PAGE_IN(bonk2);
458 PIGGY_PAGE_IN(bonk2);
460 PIGGY_PAGE_IN(bonk2);
463 for (i=0; i<MAX_BITMAP_FILES;i++ ) {
466 //piggy_get_bitmap_name(i,fname);
468 if (GameBitmaps[i].bm_flags & BM_FLAG_PAGED_OUT )
471 // if (GameBitmapXlat[i]!=i)
476 if ( (i==47) || (i==48) ) // Mark red mplayer ship textures as paged in.
480 fprintf( fp, "0,\t// Bitmap %d (%s)\n", i, "test\0"); // cmp debug fname );
482 fprintf( fp, "1,\t// Bitmap %d (%s)\n", i, "test\0"); // cmp debug fname );
489 mprintf(( 0, "done\n" ));
491 //@@ clear_boxed_message();
493 if ( black_screen ) {
495 gr_clear_canvas( BM_XRGB(0,0,0) );
498 reset_cockpit(); //force cockpit redraw next time