home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / main / ktmap.c < prev    next >
C/C++ Source or Header  |  1998-06-08  |  7KB  |  271 lines

  1. /*
  2.  * $Source: f:/miner/source/main/editor/rcs/ktmap.c $
  3.  * $Revision: 2.0 $
  4.  * $Author: john $
  5.  * $Date: 1995/02/27 11:35:37 $
  6.  * 
  7.  * Texture map key bindings.
  8.  * 
  9.  * $Log: ktmap.c $
  10.  * Revision 2.0  1995/02/27  11:35:37  john
  11.  * Version 2.0! No anonymous unions, Watcom 10.0, with no need
  12.  * for bitmaps.tbl.
  13.  * 
  14.  * Revision 1.26  1994/08/25  21:57:12  mike
  15.  * IS_CHILD stuff.
  16.  * 
  17.  * Revision 1.25  1994/08/03  10:32:41  mike
  18.  * Texture map stretching.
  19.  * 
  20.  * Revision 1.24  1994/05/14  17:17:35  matt
  21.  * Got rid of externs in source (non-header) files
  22.  * 
  23.  * Revision 1.23  1994/04/28  10:48:38  yuan
  24.  * Fixed undo message for Clear Texture.
  25.  * 
  26.  * Revision 1.22  1994/04/22  17:45:42  john
  27.  * MAde top 2 bits of paste-ons pick the 
  28.  * orientation of the bitmap.
  29.  * 
  30.  * Revision 1.21  1994/04/01  14:36:08  yuan
  31.  * Fixed propogate function so you can propogate and move.
  32.  * 
  33.  * Revision 1.20  1994/03/19  17:22:08  yuan
  34.  * Wall system implemented until specific features need to be added...
  35.  * (Needs to be hammered on though.)
  36.  * 
  37.  * Revision 1.19  1994/02/14  12:06:12  mike
  38.  * change segment data structure.
  39.  * 
  40.  * Revision 1.18  1994/01/25  17:58:47  yuan
  41.  * Added ambient lighting, and also added fixing bogus segments
  42.  * functions to the editor... (they don't work fully... need to
  43.  * check out seguvs.c
  44.  * 
  45.  * Revision 1.17  1994/01/24  11:54:52  yuan
  46.  * Checking everything in
  47.  * 
  48.  * Revision 1.16  1994/01/18  16:05:57  yuan
  49.  * Added clear texture 2 function (shift 0)
  50.  * 
  51.  * Revision 1.15  1994/01/18  10:15:01  yuan
  52.  * added texture stuff
  53.  * 
  54.  * Revision 1.14  1993/12/06  19:33:57  yuan
  55.  * Fixed autosave stuff so that undo restores Cursegp and
  56.  * Markedsegp
  57.  * 
  58.  * Revision 1.13  1993/12/02  12:39:39  matt
  59.  * Removed extra includes
  60.  * 
  61.  * Revision 1.12  1993/11/28  17:31:34  mike
  62.  * Use new segment data structure.
  63.  * 
  64.  * Revision 1.11  1993/11/12  16:38:37  mike
  65.  * Change call to med_propagate_tmaps_to_segments to include new uv_only_flag parameter.
  66.  * 
  67.  * Revision 1.10  1993/11/11  15:53:30  yuan
  68.  * Fixed undo display message
  69.  * 
  70.  * Revision 1.9  1993/11/08  19:13:46  yuan
  71.  * Added Undo command (not working yet)
  72.  * 
  73.  * Revision 1.8  1993/11/05  17:32:48  john
  74.  * added funcs
  75.  * .,
  76.  * 
  77.  * Revision 1.7  1993/11/02  10:31:08  mike
  78.  * Add PropagateTexturesSelected.
  79.  * 
  80.  * Revision 1.6  1993/10/29  11:43:15  mike
  81.  * Write PropagateTextures
  82.  * 
  83.  * Revision 1.5  1993/10/25  13:26:39  mike
  84.  * Force redraw whenever a texture map is assigned.
  85.  * 
  86.  * Revision 1.4  1993/10/15  17:42:53  mike
  87.  * Make AssignTexture also assign texture maps to New_segment.
  88.  * 
  89.  * Revision 1.3  1993/10/15  13:10:24  mike
  90.  * Adapt AssignTexture to new segment structure.
  91.  * 
  92.  * Revision 1.2  1993/10/14  18:09:17  mike
  93.  * Debug code for AssignTexture and comment out code.
  94.  * 
  95.  * Revision 1.1  1993/10/14  14:01:49  mike
  96.  * Initial revision
  97.  * 
  98.  * 
  99.  */
  100.  
  101.  
  102. #pragma off (unreferenced)
  103. static char rcsid[] = "$Id: ktmap.c 2.0 1995/02/27 11:35:37 john Exp $";
  104. #pragma on (unreferenced)
  105.  
  106. #include <string.h>
  107.  
  108. #include "inferno.h"
  109. #include "editor.h"
  110. #include "mono.h"
  111. #include "kdefs.h"
  112.  
  113. //    Assign CurrentTexture to Curside in *Cursegp
  114. int AssignTexture(void)
  115. {
  116.    autosave_mine( mine_filename );
  117.    strcpy(undo_status[Autosave_count], "Assign Texture UNDONE.");
  118.  
  119.     Cursegp->sides[Curside].tmap_num = CurrentTexture;
  120.  
  121.     New_segment.sides[Curside].tmap_num = CurrentTexture;
  122.  
  123. //    propagate_light_intensity(Cursegp, Curside, CurrentTexture, 0); 
  124.                                                                                      
  125.     Update_flags |= UF_WORLD_CHANGED;
  126.  
  127.     return 1;
  128. }
  129.  
  130. //    Assign CurrentTexture to Curside in *Cursegp
  131. int AssignTexture2(void)
  132. {
  133.     int texnum, orient, ctexnum, newtexnum;
  134.  
  135.    autosave_mine( mine_filename );
  136.    strcpy(undo_status[Autosave_count], "Assign Texture 2 UNDONE.");
  137.  
  138.     texnum = Cursegp->sides[Curside].tmap_num2 & 0x3FFF;
  139.     orient = ((Cursegp->sides[Curside].tmap_num2 & 0xC000) >> 14) & 3;
  140.     ctexnum = CurrentTexture;
  141.     
  142.     if ( ctexnum == texnum )    {
  143.         orient = (orient+1) & 3;
  144.         newtexnum = (orient<<14) | texnum;
  145.     } else {
  146.         newtexnum = ctexnum;
  147.     }
  148.  
  149.     Cursegp->sides[Curside].tmap_num2 = newtexnum;
  150.     New_segment.sides[Curside].tmap_num2 = newtexnum;
  151.  
  152.     Update_flags |= UF_WORLD_CHANGED;
  153.  
  154.     return 1;
  155. }
  156.  
  157. int ClearTexture2(void)
  158. {
  159.    autosave_mine( mine_filename );
  160.    strcpy(undo_status[Autosave_count], "Clear Texture 2 UNDONE.");
  161.  
  162.     Cursegp->sides[Curside].tmap_num2 = 0;
  163.  
  164.     New_segment.sides[Curside].tmap_num2 = 0;
  165.  
  166.     Update_flags |= UF_WORLD_CHANGED;
  167.  
  168.     return 1;
  169. }
  170.  
  171.  
  172. //    --------------------------------------------------------------------------------------------------
  173. //    Propagate textures from Cursegp through Curside.
  174. //    If uv_flag !0, then only propagate uv coordinates (if 0, then propagate textures as well)
  175. //    If move_flag !0, then move forward to new segment after propagation, else don't
  176. int propagate_textures_common(int uv_flag, int move_flag)
  177. {
  178.    autosave_mine( mine_filename );
  179.    strcpy(undo_status[Autosave_count], "Propogate Textures UNDONE.");
  180.     
  181.     if (IS_CHILD(Cursegp->children[Curside]))
  182.         med_propagate_tmaps_to_segments(Cursegp, &Segments[Cursegp->children[Curside]], uv_flag);
  183.  
  184.     if (move_flag)
  185.         SelectCurrentSegForward();
  186.  
  187.     Update_flags |= UF_WORLD_CHANGED;
  188.  
  189.     return 1;
  190. }
  191.  
  192. //    Propagate texture maps from current segment, through current side
  193. int PropagateTextures(void)
  194. {
  195.     return propagate_textures_common(0, 0);
  196. }
  197.  
  198. //    Propagate texture maps from current segment, through current side
  199. int PropagateTexturesUVs(void)
  200. {
  201.     return propagate_textures_common(-1, 0);
  202. }
  203.  
  204. //    Propagate texture maps from current segment, through current side
  205. // And move to that segment.
  206. int PropagateTexturesMove(void)
  207. {
  208.     return propagate_textures_common(0, 1);
  209. }
  210.  
  211. //    Propagate uv coordinate from current segment, through current side
  212. // And move to that segment.
  213. int PropagateTexturesMoveUVs(void)
  214. {
  215.     return propagate_textures_common(-1, 1);
  216. }
  217.  
  218.  
  219. //    -------------------------------------------------------------------------------------
  220. int is_selected_segment(int segnum)
  221. {
  222.     int    i;
  223.  
  224.     for (i=0; i<N_selected_segs; i++)
  225.         if (Selected_segs[i] == segnum)
  226.             return 1;
  227.  
  228.     return 0;
  229.  
  230. }
  231.  
  232. //    -------------------------------------------------------------------------------------
  233. //    Auxiliary function for PropagateTexturesSelected.
  234. //    Recursive parse.
  235. void pts_aux(segment *sp)
  236. {
  237.     int        side;
  238.  
  239.     Been_visited[sp-Segments] = 1;
  240.  
  241.     for (side=0; side<MAX_SIDES_PER_SEGMENT; side++) {
  242.         if (IS_CHILD(sp->children[side])) {
  243.             while ((!Been_visited[sp->children[side]]) && is_selected_segment(sp->children[side])) {
  244.                 med_propagate_tmaps_to_segments(sp,&Segments[sp->children[side]],0);
  245.                 pts_aux(&Segments[sp->children[side]]);
  246.             }
  247.         }
  248.     }
  249. }
  250.  
  251. //    -------------------------------------------------------------------------------------
  252. //    Propagate texture maps from current segment recursively exploring all children, to all segments in Selected_list
  253. //    until a segment not in Selected_list is reached.
  254. int PropagateTexturesSelected(void)
  255. {
  256.     int        i;
  257.  
  258.    autosave_mine( mine_filename );
  259.    strcpy(undo_status[Autosave_count], "Propogate Textures Selected UNDONE.");
  260.  
  261.     for (i=0; i<MAX_SEGMENTS; i++) Been_visited[i] = 0;    //clear visited list
  262.     Been_visited[Cursegp-Segments] = 1;
  263.  
  264.     pts_aux(Cursegp);
  265.  
  266.     Update_flags |= UF_WORLD_CHANGED;
  267.  
  268.     return 1;
  269. }
  270.  
  271.