PAGING.C 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  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. #pragma off (unreferenced)
  106. static char rcsid[] = "$Id: paging.c 2.5 1995/10/07 13:18:21 john Exp $";
  107. #pragma on (unreferenced)
  108. #include <stdio.h>
  109. #include <stdlib.h>
  110. #include <math.h>
  111. #include <string.h>
  112. #include "mono.h"
  113. #include "inferno.h"
  114. #include "segment.h"
  115. #include "textures.h"
  116. #include "wall.h"
  117. #include "object.h"
  118. #include "gamemine.h"
  119. #include "error.h"
  120. #include "gameseg.h"
  121. #include "game.h"
  122. #include "piggy.h"
  123. #include "texmerge.h"
  124. #include "polyobj.h"
  125. #include "vclip.h"
  126. #include "effects.h"
  127. #include "fireball.h"
  128. #include "weapon.h"
  129. #include "palette.h"
  130. #include "timer.h"
  131. #include "text.h"
  132. #include "cntrlcen.h"
  133. #include "gauges.h"
  134. #include "powerup.h"
  135. #include "fuelcen.h"
  136. void paging_touch_vclip( vclip * vc )
  137. {
  138. int i;
  139. for (i=0; i<vc->num_frames; i++ ) {
  140. PIGGY_PAGE_IN( vc->frames[i] );
  141. }
  142. }
  143. void paging_touch_wall_effects( int tmap_num )
  144. {
  145. int i;
  146. for (i=0;i<Num_effects;i++) {
  147. if ( Effects[i].changing_wall_texture == tmap_num ) {
  148. paging_touch_vclip( &Effects[i].vc );
  149. if (Effects[i].dest_bm_num > -1)
  150. PIGGY_PAGE_IN( Textures[Effects[i].dest_bm_num] ); //use this bitmap when monitor destroyed
  151. if ( Effects[i].dest_vclip > -1 )
  152. paging_touch_vclip( &Vclip[Effects[i].dest_vclip] ); //what vclip to play when exploding
  153. if ( Effects[i].dest_eclip > -1 )
  154. paging_touch_vclip( &Effects[Effects[i].dest_eclip].vc ); //what eclip to play when exploding
  155. if ( Effects[i].crit_clip > -1 )
  156. paging_touch_vclip( &Effects[Effects[i].crit_clip].vc ); //what eclip to play when mine critical
  157. }
  158. }
  159. }
  160. void paging_touch_object_effects( int tmap_num )
  161. {
  162. int i;
  163. for (i=0;i<Num_effects;i++) {
  164. if ( Effects[i].changing_object_texture == tmap_num ) {
  165. paging_touch_vclip( &Effects[i].vc );
  166. }
  167. }
  168. }
  169. void paging_touch_model( int modelnum )
  170. {
  171. int i;
  172. polymodel *pm = &Polygon_models[modelnum];
  173. for (i=0;i<pm->n_textures;i++) {
  174. PIGGY_PAGE_IN( ObjBitmaps[ObjBitmapPtrs[pm->first_texture+i]] );
  175. paging_touch_object_effects( ObjBitmapPtrs[pm->first_texture+i] );
  176. //paging_touch_object_effects( pm->first_texture+i );
  177. }
  178. }
  179. void paging_touch_weapon( int weapon_type )
  180. {
  181. // Page in the robot's weapons.
  182. if ( (weapon_type < 0) || (weapon_type > N_weapon_types) ) return;
  183. if ( Weapon_info[weapon_type].picture.index ) {
  184. PIGGY_PAGE_IN( Weapon_info[weapon_type].picture );
  185. }
  186. if ( Weapon_info[weapon_type].flash_vclip > -1 )
  187. paging_touch_vclip(&Vclip[Weapon_info[weapon_type].flash_vclip]);
  188. if ( Weapon_info[weapon_type].wall_hit_vclip > -1 )
  189. paging_touch_vclip(&Vclip[Weapon_info[weapon_type].wall_hit_vclip]);
  190. if ( Weapon_info[weapon_type].damage_radius ) {
  191. // Robot_hit_vclips are actually badass_vclips
  192. if ( Weapon_info[weapon_type].robot_hit_vclip > -1 )
  193. paging_touch_vclip(&Vclip[Weapon_info[weapon_type].robot_hit_vclip]);
  194. }
  195. switch( Weapon_info[weapon_type].render_type ) {
  196. case WEAPON_RENDER_VCLIP:
  197. if ( Weapon_info[weapon_type].weapon_vclip > -1 )
  198. paging_touch_vclip( &Vclip[Weapon_info[weapon_type].weapon_vclip] );
  199. break;
  200. case WEAPON_RENDER_NONE:
  201. break;
  202. case WEAPON_RENDER_POLYMODEL:
  203. paging_touch_model( Weapon_info[weapon_type].model_num );
  204. break;
  205. case WEAPON_RENDER_BLOB:
  206. PIGGY_PAGE_IN( Weapon_info[weapon_type].bitmap );
  207. break;
  208. }
  209. }
  210. byte super_boss_gate_type_list[13] = {0, 1, 8, 9, 10, 11, 12, 15, 16, 18, 19, 20, 22 };
  211. void paging_touch_robot( int robot_index )
  212. {
  213. int i;
  214. // Page in robot_index
  215. paging_touch_model(Robot_info[robot_index].model_num);
  216. if ( Robot_info[robot_index].exp1_vclip_num>-1 )
  217. paging_touch_vclip(&Vclip[Robot_info[robot_index].exp1_vclip_num]);
  218. if ( Robot_info[robot_index].exp2_vclip_num>-1 )
  219. paging_touch_vclip(&Vclip[Robot_info[robot_index].exp2_vclip_num]);
  220. // Page in his weapons
  221. paging_touch_weapon( Robot_info[robot_index].weapon_type );
  222. // A super-boss can gate in robots...
  223. if ( Robot_info[robot_index].boss_flag==2 ) {
  224. for (i=0; i<13; i++ )
  225. paging_touch_robot(super_boss_gate_type_list[i]);
  226. paging_touch_vclip( &Vclip[VCLIP_MORPHING_ROBOT] );
  227. }
  228. }
  229. void paging_touch_object( object * obj )
  230. {
  231. int v;
  232. switch (obj->render_type) {
  233. case RT_NONE: break; //doesn't render, like the player
  234. case RT_POLYOBJ:
  235. paging_touch_model(obj->rtype.pobj_info.model_num);
  236. break;
  237. case RT_POWERUP:
  238. if ( obj->rtype.vclip_info.vclip_num > -1 )
  239. paging_touch_vclip(&Vclip[obj->rtype.vclip_info.vclip_num]);
  240. break;
  241. case RT_MORPH: break;
  242. case RT_FIREBALL: break;
  243. case RT_WEAPON_VCLIP: break;
  244. case RT_HOSTAGE:
  245. paging_touch_vclip(&Vclip[obj->rtype.vclip_info.vclip_num]);
  246. break;
  247. case RT_LASER: break;
  248. }
  249. switch (obj->type) {
  250. case OBJ_PLAYER:
  251. v = get_explosion_vclip(obj, 0);
  252. if ( v > -1 )
  253. paging_touch_vclip(&Vclip[v]);
  254. break;
  255. case OBJ_ROBOT:
  256. paging_touch_robot( obj->id );
  257. break;
  258. case OBJ_CNTRLCEN:
  259. paging_touch_weapon( CONTROLCEN_WEAPON_NUM );
  260. if (Dead_modelnums[obj->rtype.pobj_info.model_num] != -1) {
  261. paging_touch_model( Dead_modelnums[obj->rtype.pobj_info.model_num] );
  262. }
  263. break;
  264. }
  265. }
  266. void paging_touch_side( segment * segp, int sidenum )
  267. {
  268. int tmap1, tmap2;
  269. if (!(WALL_IS_DOORWAY(segp,sidenum) & WID_RENDER_FLAG))
  270. return;
  271. tmap1 = segp->sides[sidenum].tmap_num;
  272. paging_touch_wall_effects(tmap1);
  273. tmap2 = segp->sides[sidenum].tmap_num2;
  274. if (tmap2 != 0) {
  275. texmerge_get_cached_bitmap( tmap1, tmap2 );
  276. paging_touch_wall_effects( tmap2 & 0x3FFF );
  277. } else {
  278. PIGGY_PAGE_IN( Textures[tmap1] );
  279. }
  280. }
  281. void paging_touch_robot_maker( segment * segp )
  282. {
  283. if ( segp->special == SEGMENT_IS_ROBOTMAKER ) {
  284. paging_touch_vclip(&Vclip[VCLIP_MORPHING_ROBOT]);
  285. if (RobotCenters[segp->matcen_num].robot_flags != 0) {
  286. uint flags;
  287. int robot_index;
  288. robot_index = 0;
  289. flags = RobotCenters[segp->matcen_num].robot_flags;
  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. void paging_touch_segment(segment * segp)
  302. {
  303. int sn;
  304. int objnum;
  305. if ( segp->special == SEGMENT_IS_ROBOTMAKER )
  306. paging_touch_robot_maker(segp);
  307. // paging_draw_orb();
  308. for (sn=0;sn<MAX_SIDES_PER_SEGMENT;sn++) {
  309. // paging_draw_orb();
  310. paging_touch_side( segp, sn );
  311. }
  312. for (objnum=segp->objects;objnum!=-1;objnum=Objects[objnum].next) {
  313. // paging_draw_orb();
  314. paging_touch_object( &Objects[objnum] );
  315. }
  316. }
  317. void paging_touch_walls()
  318. {
  319. int i,j;
  320. wclip *anim;
  321. for (i=0;i<Num_walls;i++) {
  322. // paging_draw_orb();
  323. if ( Walls[i].clip_num > -1 ) {
  324. anim = &WallAnims[Walls[i].clip_num];
  325. for (j=0; j < anim->num_frames; j++ ) {
  326. PIGGY_PAGE_IN( Textures[anim->frames[j]] );
  327. }
  328. }
  329. }
  330. }
  331. void paging_touch_all()
  332. {
  333. int black_screen;
  334. int s;
  335. stop_time();
  336. black_screen = gr_palette_faded_out;
  337. if ( gr_palette_faded_out ) {
  338. gr_clear_canvas( 0 );
  339. gr_palette_load( gr_palette );
  340. }
  341. show_boxed_message(TXT_LOADING);
  342. mprintf(( 0, "Loading all textures in mine..." ));
  343. for (s=0; s<=Highest_segment_index; s++) {
  344. paging_touch_segment( &Segments[s] );
  345. }
  346. paging_touch_walls();
  347. for ( s=0; s < N_powerup_types; s++ ) {
  348. if ( Powerup_info[s].vclip_num > -1 )
  349. paging_touch_vclip(&Vclip[Powerup_info[s].vclip_num]);
  350. }
  351. for ( s=0; s<N_weapon_types; s++ ) {
  352. paging_touch_weapon(s);
  353. }
  354. for ( s=0; s < N_powerup_types; s++ ) {
  355. if ( Powerup_info[s].vclip_num > -1 )
  356. paging_touch_vclip(&Vclip[Powerup_info[s].vclip_num]);
  357. }
  358. for (s=0; s<MAX_GAUGE_BMS; s++ ) {
  359. if ( Gauges[s].index ) {
  360. PIGGY_PAGE_IN( Gauges[s] );
  361. }
  362. }
  363. paging_touch_vclip( &Vclip[VCLIP_PLAYER_APPEARANCE] );
  364. paging_touch_vclip( &Vclip[VCLIP_POWERUP_DISAPPEARANCE] );
  365. mprintf(( 0, "done\n" ));
  366. clear_boxed_message();
  367. if ( black_screen ) {
  368. gr_palette_clear();
  369. gr_clear_canvas( 0 );
  370. }
  371. start_time();
  372. reset_cockpit(); //force cockpit redraw next time
  373. #ifdef PSX_BUILD_TOOLS
  374. {
  375. extern int Current_level_num;
  376. extern ushort GameBitmapXlat[MAX_BITMAP_FILES];
  377. FILE * fp;
  378. char fname[128];
  379. int i;
  380. if ( Current_level_num < 0 )
  381. sprintf( fname, "levels%d.pag", -Current_level_num );
  382. else
  383. sprintf( fname, "level%02d.pag", Current_level_num );
  384. fp = fopen( fname, "wt" );
  385. for (i=0; i<MAX_BITMAP_FILES;i++ ) {
  386. int paged_in = 1;
  387. piggy_get_bitmap_name(i,fname);
  388. if (GameBitmaps[i].bm_flags & BM_FLAG_PAGED_OUT)
  389. paged_in = 0;
  390. if (GameBitmapXlat[i]!=i)
  391. paged_in = 0;
  392. if ( (i==47) || (i==48) ) // Mark red mplayer ship textures as paged in.
  393. paged_in = 1;
  394. if ( !paged_in )
  395. fprintf( fp, "0,\t// Bitmap %d (%s)\n", i, fname );
  396. else
  397. fprintf( fp, "1,\t// Bitmap %d (%s)\n", i, fname );
  398. }
  399. fclose(fp);
  400. }
  401. #endif
  402. }
  403.