home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / main / paging.c < prev    next >
Text File  |  1998-06-08  |  13KB  |  483 lines

  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-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  12. */
  13. /*
  14.  * $Source: f:/miner/source/main/rcs/paging.c $
  15.  * $Revision: 2.5 $
  16.  * $Author: john $
  17.  * $Date: 1995/10/07 13:18:21 $
  18.  * 
  19.  * Routines for paging in/out textures.
  20.  * 
  21.  * $Log: paging.c $
  22.  * Revision 2.5  1995/10/07  13:18:21  john
  23.  * Added PSX debugging stuff that builds .PAG files.
  24.  * 
  25.  * Revision 2.4  1995/08/24  13:40:03  john
  26.  * Added code to page in vclip for powerup disapperance and to 
  27.  * fix bug that made robot makers not page in the correct bot
  28.  * textures.
  29.  * 
  30.  * Revision 2.3  1995/07/26  12:09:19  john
  31.  * Made code that pages in weapon_info->robot_hit_vclip not
  32.  * page in unless it is a badass weapon.  Took out old functionallity
  33.  * of using this if no robot exp1_vclip, since all robots have these.
  34.  * 
  35.  * Revision 2.2  1995/07/24  13:22:11  john
  36.  * Made sure everything gets paged in at the
  37.  * level start.  Fixed bug with robot effects not
  38.  * getting paged in correctly.
  39.  * 
  40.  * Revision 2.1  1995/05/12  15:50:16  allender
  41.  * fix to check effects dest_bm_num > -1 before paging in
  42.  * 
  43.  * Revision 2.0  1995/02/27  11:27:39  john
  44.  * New version 2.0, which has no anonymous unions, builds with
  45.  * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
  46.  * 
  47.  * Revision 1.18  1995/02/22  14:12:28  allender
  48.  * remove anonyous union from object structure
  49.  * 
  50.  * Revision 1.17  1995/02/11  22:54:15  john
  51.  * Made loading for pig not show up for demos.
  52.  * 
  53.  * Revision 1.16  1995/02/11  22:37:04  john
  54.  * Made cockpit redraw.
  55.  * 
  56.  * Revision 1.15  1995/01/28  16:29:35  john
  57.  * *** empty log message ***
  58.  * 
  59.  * Revision 1.14  1995/01/27  17:16:18  john
  60.  * Added code to page in all the weapons.
  61.  * 
  62.  * Revision 1.13  1995/01/24  21:51:22  matt
  63.  * Clear the boxed message to fix a mem leakage
  64.  * 
  65.  * Revision 1.12  1995/01/23  13:00:46  john
  66.  * Added hostage vclip paging.
  67.  * 
  68.  * Revision 1.11  1995/01/23  12:29:52  john
  69.  * Added code to page in eclip on robots, dead control center,
  70.  * gauges bitmaps, and weapon pictures.
  71.  * 
  72.  * Revision 1.10  1995/01/21  12:54:15  adam
  73.  * *** empty log message ***
  74.  * 
  75.  * Revision 1.9  1995/01/21  12:41:29  adam
  76.  * changed orb to loading box
  77.  * 
  78.  * Revision 1.8  1995/01/18  15:09:02  john
  79.  * Added start/stop time around paging.
  80.  * Made paging clear screen around globe.
  81.  * 
  82.  * Revision 1.7  1995/01/18  10:37:00  john
  83.  * Added code to page in exploding monitors.
  84.  * 
  85.  * Revision 1.6  1995/01/17  19:03:35  john
  86.  * Added cool spinning orb during loading.
  87.  * 
  88.  * Revision 1.5  1995/01/17  14:49:26  john
  89.  * Paged in weapons.
  90.  * 
  91.  * Revision 1.4  1995/01/17  12:14:07  john
  92.  * Made walls, object explosion vclips load at level start.
  93.  * 
  94.  * Revision 1.3  1995/01/15  13:23:24  john
  95.  * First working version
  96.  * 
  97.  * Revision 1.2  1995/01/15  11:56:45  john
  98.  * Working version of paging.
  99.  * 
  100.  * Revision 1.1  1995/01/15  11:33:37  john
  101.  * Initial revision
  102.  * 
  103.  * 
  104.  */
  105.  
  106.  
  107. #pragma off (unreferenced)
  108. static char rcsid[] = "$Id: paging.c 2.5 1995/10/07 13:18:21 john Exp $";
  109. #pragma on (unreferenced)
  110.  
  111.  
  112. #include <stdio.h>
  113. #include <stdlib.h>
  114. #include <math.h>
  115. #include <string.h>
  116.  
  117. #include "mono.h"
  118. #include "inferno.h"
  119. #include "segment.h"
  120. #include "textures.h"
  121. #include "wall.h"
  122. #include "object.h"
  123. #include "gamemine.h"
  124. #include "error.h"
  125. #include "gameseg.h"
  126. #include "game.h"
  127. #include "piggy.h"
  128. #include "texmerge.h"
  129. #include "polyobj.h"
  130. #include "vclip.h"
  131. #include "effects.h"
  132. #include "fireball.h"
  133. #include "weapon.h"
  134. #include "palette.h"
  135. #include "timer.h"
  136. #include "text.h"
  137. #include "cntrlcen.h"
  138. #include "gauges.h"
  139. #include "powerup.h"
  140. #include "fuelcen.h"
  141.  
  142. void paging_touch_vclip( vclip * vc )
  143. {
  144.     int i;
  145.  
  146.     for (i=0; i<vc->num_frames; i++ )    {
  147.         PIGGY_PAGE_IN( vc->frames[i] );
  148.     }
  149. }
  150.  
  151. void paging_touch_wall_effects( int tmap_num )
  152. {
  153.     int i;
  154.  
  155.     for (i=0;i<Num_effects;i++)    {
  156.         if ( Effects[i].changing_wall_texture == tmap_num )    {
  157.             paging_touch_vclip( &Effects[i].vc );
  158.  
  159.             if (Effects[i].dest_bm_num > -1)
  160.                 PIGGY_PAGE_IN( Textures[Effects[i].dest_bm_num] );    //use this bitmap when monitor destroyed
  161.             if ( Effects[i].dest_vclip > -1 )
  162.                 paging_touch_vclip( &Vclip[Effects[i].dest_vclip] );          //what vclip to play when exploding
  163.  
  164.             if ( Effects[i].dest_eclip > -1 )
  165.                 paging_touch_vclip( &Effects[Effects[i].dest_eclip].vc ); //what eclip to play when exploding
  166.  
  167.             if ( Effects[i].crit_clip > -1 )
  168.                 paging_touch_vclip( &Effects[Effects[i].crit_clip].vc ); //what eclip to play when mine critical
  169.         }
  170.  
  171.     }
  172. }
  173.  
  174. void paging_touch_object_effects( int tmap_num )
  175. {
  176.     int i;
  177.  
  178.     for (i=0;i<Num_effects;i++)    {
  179.         if ( Effects[i].changing_object_texture == tmap_num )    {
  180.             paging_touch_vclip( &Effects[i].vc );
  181.         }
  182.     }
  183. }
  184.  
  185.  
  186. void paging_touch_model( int modelnum )
  187. {
  188.     int i;
  189.     polymodel *pm = &Polygon_models[modelnum];
  190.  
  191.     for (i=0;i<pm->n_textures;i++)    {
  192.         PIGGY_PAGE_IN( ObjBitmaps[ObjBitmapPtrs[pm->first_texture+i]] );
  193.         paging_touch_object_effects( ObjBitmapPtrs[pm->first_texture+i] );
  194.         //paging_touch_object_effects( pm->first_texture+i );
  195.     }
  196. }
  197.  
  198. void paging_touch_weapon( int weapon_type )
  199. {
  200.     // Page in the robot's weapons.
  201.     
  202.     if ( (weapon_type < 0) || (weapon_type > N_weapon_types) ) return;
  203.  
  204.     if ( Weapon_info[weapon_type].picture.index )    {
  205.         PIGGY_PAGE_IN( Weapon_info[weapon_type].picture );
  206.     }        
  207.     
  208.     if ( Weapon_info[weapon_type].flash_vclip > -1 )
  209.         paging_touch_vclip(&Vclip[Weapon_info[weapon_type].flash_vclip]);
  210.     if ( Weapon_info[weapon_type].wall_hit_vclip > -1 )
  211.         paging_touch_vclip(&Vclip[Weapon_info[weapon_type].wall_hit_vclip]);
  212.     if ( Weapon_info[weapon_type].damage_radius )    {
  213.         // Robot_hit_vclips are actually badass_vclips
  214.         if ( Weapon_info[weapon_type].robot_hit_vclip > -1 )
  215.             paging_touch_vclip(&Vclip[Weapon_info[weapon_type].robot_hit_vclip]);
  216.     }
  217.  
  218.     switch( Weapon_info[weapon_type].render_type )    {
  219.     case WEAPON_RENDER_VCLIP:
  220.         if ( Weapon_info[weapon_type].weapon_vclip > -1 )
  221.             paging_touch_vclip( &Vclip[Weapon_info[weapon_type].weapon_vclip] );
  222.         break;
  223.     case WEAPON_RENDER_NONE:
  224.         break;
  225.     case WEAPON_RENDER_POLYMODEL:
  226.         paging_touch_model( Weapon_info[weapon_type].model_num );
  227.         break;
  228.     case WEAPON_RENDER_BLOB:
  229.         PIGGY_PAGE_IN( Weapon_info[weapon_type].bitmap );
  230.         break;
  231.     }
  232. }
  233.  
  234.  
  235.  
  236. byte super_boss_gate_type_list[13] = {0, 1, 8, 9, 10, 11, 12, 15, 16, 18, 19, 20, 22 };
  237.  
  238. void paging_touch_robot( int robot_index )
  239. {
  240.     int i;
  241.     // Page in robot_index
  242.     paging_touch_model(Robot_info[robot_index].model_num);
  243.     if ( Robot_info[robot_index].exp1_vclip_num>-1 )
  244.         paging_touch_vclip(&Vclip[Robot_info[robot_index].exp1_vclip_num]);
  245.     if ( Robot_info[robot_index].exp2_vclip_num>-1 )
  246.         paging_touch_vclip(&Vclip[Robot_info[robot_index].exp2_vclip_num]);
  247.  
  248.     // Page in his weapons
  249.     paging_touch_weapon( Robot_info[robot_index].weapon_type );
  250.  
  251.     // A super-boss can gate in robots...
  252.     if ( Robot_info[robot_index].boss_flag==2 )    {
  253.         for (i=0; i<13; i++ )
  254.             paging_touch_robot(super_boss_gate_type_list[i]);
  255.  
  256.         paging_touch_vclip( &Vclip[VCLIP_MORPHING_ROBOT] );
  257.     }
  258. }
  259.  
  260.  
  261. void paging_touch_object( object * obj )
  262. {
  263.     int v;
  264.  
  265.     switch (obj->render_type) {
  266.  
  267.         case RT_NONE:    break;        //doesn't render, like the player
  268.  
  269.         case RT_POLYOBJ:
  270.             paging_touch_model(obj->rtype.pobj_info.model_num);
  271.             break;
  272.  
  273.         case RT_POWERUP: 
  274.             if ( obj->rtype.vclip_info.vclip_num > -1 )
  275.                 paging_touch_vclip(&Vclip[obj->rtype.vclip_info.vclip_num]);
  276.             break;
  277.  
  278.         case RT_MORPH:    break;
  279.  
  280.         case RT_FIREBALL: break;
  281.  
  282.         case RT_WEAPON_VCLIP: break;
  283.  
  284.         case RT_HOSTAGE: 
  285.             paging_touch_vclip(&Vclip[obj->rtype.vclip_info.vclip_num]);
  286.             break;
  287.  
  288.         case RT_LASER: break;
  289.      }
  290.  
  291.     switch (obj->type) {    
  292.     case OBJ_PLAYER:    
  293.         v = get_explosion_vclip(obj, 0);
  294.         if ( v > -1 )
  295.             paging_touch_vclip(&Vclip[v]);
  296.         break;
  297.     case OBJ_ROBOT:
  298.         paging_touch_robot( obj->id );
  299.         break;
  300.     case OBJ_CNTRLCEN:
  301.         paging_touch_weapon( CONTROLCEN_WEAPON_NUM );
  302.         if (Dead_modelnums[obj->rtype.pobj_info.model_num] != -1)    {
  303.             paging_touch_model( Dead_modelnums[obj->rtype.pobj_info.model_num] );
  304.         }
  305.         break;
  306.     }
  307. }
  308.  
  309.     
  310.  
  311. void paging_touch_side( segment * segp, int sidenum )
  312. {
  313.     int tmap1, tmap2;
  314.  
  315.     if (!(WALL_IS_DOORWAY(segp,sidenum) & WID_RENDER_FLAG))
  316.         return;
  317.     
  318.     tmap1 = segp->sides[sidenum].tmap_num;
  319.     paging_touch_wall_effects(tmap1);
  320.     tmap2 = segp->sides[sidenum].tmap_num2;
  321.     if (tmap2 != 0)    {
  322.         texmerge_get_cached_bitmap( tmap1, tmap2 );
  323.         paging_touch_wall_effects( tmap2 & 0x3FFF );
  324.     } else    {
  325.         PIGGY_PAGE_IN( Textures[tmap1] );
  326.     }
  327.  
  328. }
  329.  
  330. void paging_touch_robot_maker( segment * segp )
  331. {
  332.     if ( segp->special == SEGMENT_IS_ROBOTMAKER )    {
  333.         paging_touch_vclip(&Vclip[VCLIP_MORPHING_ROBOT]);
  334.         if (RobotCenters[segp->matcen_num].robot_flags != 0) {
  335.             uint    flags;
  336.             int    robot_index;
  337.  
  338.             robot_index = 0;
  339.             flags = RobotCenters[segp->matcen_num].robot_flags;
  340.             while (flags) {
  341.                 if (flags & 1)    {
  342.                     // Page in robot_index
  343.                     paging_touch_robot( robot_index );
  344.                 }
  345.                 flags >>= 1;
  346.                 robot_index++;
  347.             }
  348.         }
  349.     }
  350. }
  351.  
  352.  
  353. void paging_touch_segment(segment * segp)
  354. {
  355.     int sn;
  356.     int objnum;
  357.  
  358.     if ( segp->special == SEGMENT_IS_ROBOTMAKER )    
  359.         paging_touch_robot_maker(segp);
  360.  
  361. //    paging_draw_orb();
  362.     for (sn=0;sn<MAX_SIDES_PER_SEGMENT;sn++) {
  363. //        paging_draw_orb();
  364.         paging_touch_side( segp, sn );
  365.     }
  366.  
  367.     for (objnum=segp->objects;objnum!=-1;objnum=Objects[objnum].next)    {
  368. //        paging_draw_orb();
  369.         paging_touch_object( &Objects[objnum] );
  370.     }
  371. }
  372.  
  373.  
  374.  
  375. void paging_touch_walls()
  376. {
  377.     int i,j;
  378.     wclip *anim;
  379.  
  380.     for (i=0;i<Num_walls;i++) {
  381. //        paging_draw_orb();
  382.         if ( Walls[i].clip_num > -1 )    {
  383.             anim = &WallAnims[Walls[i].clip_num];
  384.             for (j=0; j < anim->num_frames; j++ )    {
  385.                 PIGGY_PAGE_IN( Textures[anim->frames[j]] );
  386.             }
  387.         }
  388.     }
  389. }
  390.  
  391.  
  392. void paging_touch_all()
  393. {
  394.     int black_screen;
  395.     int s;
  396.     
  397.     stop_time();
  398.  
  399.     black_screen = gr_palette_faded_out;
  400.  
  401.     if ( gr_palette_faded_out )    {
  402.         gr_clear_canvas( 0 );
  403.         gr_palette_load( gr_palette );
  404.     }
  405.     
  406.     show_boxed_message(TXT_LOADING);
  407.  
  408.     mprintf(( 0, "Loading all textures in mine..." ));
  409.     for (s=0; s<=Highest_segment_index; s++)    {
  410.         paging_touch_segment( &Segments[s] );
  411.     }    
  412.     paging_touch_walls();
  413.  
  414.     for ( s=0; s < N_powerup_types; s++ )    {
  415.         if ( Powerup_info[s].vclip_num > -1 )    
  416.             paging_touch_vclip(&Vclip[Powerup_info[s].vclip_num]);
  417.     }
  418.  
  419.     for ( s=0; s<N_weapon_types; s++ )    {
  420.         paging_touch_weapon(s);
  421.     }
  422.  
  423.     for ( s=0; s < N_powerup_types; s++ )    {
  424.         if ( Powerup_info[s].vclip_num > -1 )    
  425.             paging_touch_vclip(&Vclip[Powerup_info[s].vclip_num]);
  426.     }
  427.  
  428.  
  429.     for (s=0; s<MAX_GAUGE_BMS; s++ )    {
  430.         if ( Gauges[s].index )    {
  431.             PIGGY_PAGE_IN( Gauges[s] );
  432.         }
  433.     }
  434.     paging_touch_vclip( &Vclip[VCLIP_PLAYER_APPEARANCE] );
  435.     paging_touch_vclip( &Vclip[VCLIP_POWERUP_DISAPPEARANCE] );
  436.  
  437.     mprintf(( 0, "done\n" ));
  438.  
  439.     clear_boxed_message();
  440.  
  441.     if ( black_screen )    {
  442.         gr_palette_clear();
  443.         gr_clear_canvas( 0 );
  444.     }
  445.     start_time();
  446.     reset_cockpit();        //force cockpit redraw next time
  447.  
  448. #ifdef PSX_BUILD_TOOLS
  449.     {
  450.         extern int Current_level_num;
  451.         extern ushort GameBitmapXlat[MAX_BITMAP_FILES];
  452.         FILE * fp;
  453.         char fname[128];
  454.         int i;
  455.  
  456.         if ( Current_level_num < 0 )
  457.             sprintf( fname, "levels%d.pag", -Current_level_num );
  458.         else    
  459.             sprintf( fname, "level%02d.pag", Current_level_num );
  460.         fp = fopen( fname, "wt" );
  461.         for (i=0; i<MAX_BITMAP_FILES;i++ )    {
  462.             int paged_in = 1;
  463.             piggy_get_bitmap_name(i,fname);
  464.  
  465.             if (GameBitmaps[i].bm_flags & BM_FLAG_PAGED_OUT) 
  466.                 paged_in = 0;
  467.             if (GameBitmapXlat[i]!=i)
  468.                 paged_in = 0;
  469.             if ( (i==47) || (i==48) )        // Mark red mplayer ship textures as paged in.
  470.                 paged_in = 1;
  471.     
  472.             if ( !paged_in )
  473.                 fprintf( fp, "0,\t// Bitmap %d (%s)\n", i, fname );
  474.             else
  475.                 fprintf( fp, "1,\t// Bitmap %d (%s)\n", i, fname );
  476.         }
  477.         fclose(fp);
  478.     }
  479. #endif
  480.  
  481. }
  482. 
  483.