Subversion Repositories Games.Descent

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Portions of this file are copyright Rebirth contributors and licensed as
  3.  * described in COPYING.txt.
  4.  * Portions of this file are copyright Parallax Software and licensed
  5.  * according to the Parallax license below.
  6.  * See COPYING.txt for license details.
  7.  
  8. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  9. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  10. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  11. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  12. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  13. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  14. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  15. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  16. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
  17. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  18. */
  19.  
  20. /*
  21.  *
  22.  * Texture map key bindings.
  23.  *
  24.  */
  25.  
  26. #include <string.h>
  27. #include "inferno.h"
  28. #include "editor.h"
  29. #include "editor/esegment.h"
  30. #include "kdefs.h"
  31. #include "compiler-range_for.h"
  32.  
  33. //      Assign CurrentTexture to Curside in *Cursegp
  34. int AssignTexture(void)
  35. {
  36.    autosave_mine( mine_filename );
  37.         undo_status[Autosave_count] = "Assign Texture UNDONE.";
  38.  
  39.         Cursegp->unique_segment::sides[Curside].tmap_num = CurrentTexture;
  40.  
  41.         New_segment.unique_segment::sides[Curside].tmap_num = CurrentTexture;
  42.  
  43. //      propagate_light_intensity(Cursegp, Curside, CurrentTexture, 0);
  44.                                                                                                                                                                          
  45.         Update_flags |= UF_WORLD_CHANGED;
  46.  
  47.         return 1;
  48. }
  49.  
  50. //      Assign CurrentTexture to Curside in *Cursegp
  51. int AssignTexture2(void)
  52. {
  53.         int texnum, orient, ctexnum, newtexnum;
  54.  
  55.    autosave_mine( mine_filename );
  56.         undo_status[Autosave_count] = "Assign Texture 2 UNDONE.";
  57.  
  58.         {
  59.                 const unique_segment &useg = *Cursegp;
  60.                 auto &uside = useg.sides[Curside];
  61.                 const auto tmap_num2 = uside.tmap_num2;
  62.                 texnum = tmap_num2 & 0x3FFF;
  63.                 orient = ((tmap_num2 & 0xC000) >> 14) & 3;
  64.         }
  65.         ctexnum = CurrentTexture;
  66.        
  67.         if ( ctexnum == texnum )        {
  68.                 orient = (orient+1) & 3;
  69.                 newtexnum = (orient<<14) | texnum;
  70.         } else {
  71.                 newtexnum = ctexnum;
  72.         }
  73.  
  74.         Cursegp->unique_segment::sides[Curside].tmap_num2 = newtexnum;
  75.         New_segment.unique_segment::sides[Curside].tmap_num2 = newtexnum;
  76.  
  77.         Update_flags |= UF_WORLD_CHANGED;
  78.  
  79.         return 1;
  80. }
  81.  
  82. int ClearTexture2(void)
  83. {
  84.    autosave_mine( mine_filename );
  85.         undo_status[Autosave_count] = "Clear Texture 2 UNDONE.";
  86.  
  87.         Cursegp->unique_segment::sides[Curside].tmap_num2 = 0;
  88.  
  89.         New_segment.unique_segment::sides[Curside].tmap_num2 = 0;
  90.  
  91.         Update_flags |= UF_WORLD_CHANGED;
  92.  
  93.         return 1;
  94. }
  95.  
  96.  
  97. //      --------------------------------------------------------------------------------------------------
  98. //      Propagate textures from Cursegp through Curside.
  99. //      If uv_flag !0, then only propagate uv coordinates (if 0, then propagate textures as well)
  100. //      If move_flag !0, then move forward to new segment after propagation, else don't
  101. static int propagate_textures_common(int uv_flag, int move_flag)
  102. {
  103.    autosave_mine( mine_filename );
  104.         undo_status[Autosave_count] = "Propagate Textures UNDONE.";
  105.         const auto c = Cursegp->children[Curside];
  106.         if (IS_CHILD(c))
  107.                 med_propagate_tmaps_to_segments(Cursegp, vmsegptridx(c), uv_flag);
  108.  
  109.         if (move_flag)
  110.                 SelectCurrentSegForward();
  111.  
  112.         Update_flags |= UF_WORLD_CHANGED;
  113.  
  114.         return 1;
  115. }
  116.  
  117. //      Propagate texture maps from current segment, through current side
  118. int PropagateTextures(void)
  119. {
  120.         return propagate_textures_common(0, 0);
  121. }
  122.  
  123. //      Propagate texture maps from current segment, through current side
  124. int PropagateTexturesUVs(void)
  125. {
  126.         return propagate_textures_common(-1, 0);
  127. }
  128.  
  129. //      Propagate texture maps from current segment, through current side
  130. // And move to that segment.
  131. int PropagateTexturesMove(void)
  132. {
  133.         return propagate_textures_common(0, 1);
  134. }
  135.  
  136. //      Propagate uv coordinate from current segment, through current side
  137. // And move to that segment.
  138. int PropagateTexturesMoveUVs(void)
  139. {
  140.         return propagate_textures_common(-1, 1);
  141. }
  142.  
  143.  
  144. //      -------------------------------------------------------------------------------------
  145. static int is_selected_segment(segnum_t segnum)
  146. {
  147.         return Selected_segs.contains(segnum);
  148. }
  149.  
  150. //      -------------------------------------------------------------------------------------
  151. //      Auxiliary function for PropagateTexturesSelected.
  152. //      Recursive parse.
  153. static void pts_aux(const vmsegptridx_t sp, visited_segment_bitarray_t &visited)
  154. {
  155.         visited[sp] = true;
  156.  
  157.         range_for (const auto c, sp->children)
  158.         {
  159.                 if (IS_CHILD(c))
  160.                 {
  161.                         const auto &&csegp = sp.absolute_sibling(c);
  162.                         while (!visited[c] && is_selected_segment(c))
  163.                         {
  164.                                 med_propagate_tmaps_to_segments(sp, csegp, 0);
  165.                                 pts_aux(csegp, visited);
  166.                         }
  167.                 }
  168.         }
  169. }
  170.  
  171. //      -------------------------------------------------------------------------------------
  172. //      Propagate texture maps from current segment recursively exploring all children, to all segments in Selected_list
  173. //      until a segment not in Selected_list is reached.
  174. int PropagateTexturesSelected(void)
  175. {
  176.    autosave_mine( mine_filename );
  177.         undo_status[Autosave_count] = "Propogate Textures Selected UNDONE.";
  178.  
  179.         visited_segment_bitarray_t visited;
  180.         visited[Cursegp] = true;
  181.  
  182.         pts_aux(Cursegp, visited);
  183.  
  184.         Update_flags |= UF_WORLD_CHANGED;
  185.  
  186.         return 1;
  187. }
  188.  
  189.