| 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 "editor.h" |
| 28 |
#include "editor/esegment.h" |
| 29 |
#include "kdefs.h" |
| 30 |
#include "compiler-range_for.h" |
| 31 |
|
| 32 |
// Assign CurrentTexture to Curside in *Cursegp |
| 33 |
int AssignTexture(void) |
| 34 |
{ |
| 35 |
autosave_mine( mine_filename ); |
| 36 |
undo_status[Autosave_count] = "Assign Texture UNDONE."; |
| 37 |
|
| 38 |
const auto t1 = build_texture1_value(CurrentTexture); |
| 39 |
Cursegp->unique_segment::sides[Curside].tmap_num = t1; |
| 40 |
New_segment.unique_segment::sides[Curside].tmap_num = t1; |
| 41 |
Update_flags |= UF_WORLD_CHANGED; |
| 42 |
|
| 43 |
return 1; |
| 44 |
} |
| 45 |
|
| 46 |
// Assign CurrentTexture to Curside in *Cursegp |
| 47 |
int AssignTexture2(void) |
| 48 |
{ |
| 49 |
autosave_mine( mine_filename ); |
| 50 |
undo_status[Autosave_count] = "Assign Texture 2 UNDONE."; |
| 51 |
|
| 52 |
const unique_segment &useg = *Cursegp; |
| 53 |
auto &uside = useg.sides[Curside]; |
| 54 |
const auto tmap_num2 = uside.tmap_num2; |
| 55 |
const auto ctexnum{CurrentTexture}; |
| 56 |
texture2_value newtexnum; |
| 57 |
texture2_rotation_high orient; |
| 58 |
if (ctexnum == get_texture_index(tmap_num2)) |
| 59 |
{ |
| 60 |
orient = get_texture_rotation_high(tmap_num2); |
| 61 |
++ orient; |
| 62 |
} else { |
| 63 |
orient = texture2_rotation_high::Normal; |
| 64 |
} |
| 65 |
newtexnum = build_texture2_value(ctexnum, orient); |
| 66 |
|
| 67 |
Cursegp->unique_segment::sides[Curside].tmap_num2 = newtexnum; |
| 68 |
New_segment.unique_segment::sides[Curside].tmap_num2 = newtexnum; |
| 69 |
|
| 70 |
Update_flags |= UF_WORLD_CHANGED; |
| 71 |
|
| 72 |
return 1; |
| 73 |
} |
| 74 |
|
| 75 |
int ClearTexture2(void) |
| 76 |
{ |
| 77 |
autosave_mine( mine_filename ); |
| 78 |
undo_status[Autosave_count] = "Clear Texture 2 UNDONE."; |
| 79 |
|
| 80 |
Cursegp->unique_segment::sides[Curside].tmap_num2 = texture2_value::None; |
| 81 |
New_segment.unique_segment::sides[Curside].tmap_num2 = texture2_value::None; |
| 82 |
|
| 83 |
Update_flags |= UF_WORLD_CHANGED; |
| 84 |
|
| 85 |
return 1; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
// -------------------------------------------------------------------------------------------------- |
| 90 |
// Propagate textures from Cursegp through Curside. |
| 91 |
// If uv_flag !0, then only propagate uv coordinates (if 0, then propagate textures as well) |
| 92 |
// If move_flag !0, then move forward to new segment after propagation, else don't |
| 93 |
static int propagate_textures_common(int uv_flag, int move_flag) |
| 94 |
{ |
| 95 |
autosave_mine( mine_filename ); |
| 96 |
undo_status[Autosave_count] = "Propagate Textures UNDONE."; |
| 97 |
const auto c = Cursegp->children[Curside]; |
| 98 |
if (IS_CHILD(c)) |
| 99 |
med_propagate_tmaps_to_segments(Cursegp, vmsegptridx(c), uv_flag); |
| 100 |
|
| 101 |
if (move_flag) |
| 102 |
SelectCurrentSegForward(); |
| 103 |
|
| 104 |
Update_flags |= UF_WORLD_CHANGED; |
| 105 |
|
| 106 |
return 1; |
| 107 |
} |
| 108 |
|
| 109 |
// Propagate texture maps from current segment, through current side |
| 110 |
int PropagateTextures(void) |
| 111 |
{ |
| 112 |
return propagate_textures_common(0, 0); |
| 113 |
} |
| 114 |
|
| 115 |
// Propagate texture maps from current segment, through current side |
| 116 |
int PropagateTexturesUVs(void) |
| 117 |
{ |
| 118 |
return propagate_textures_common(-1, 0); |
| 119 |
} |
| 120 |
|
| 121 |
// Propagate texture maps from current segment, through current side |
| 122 |
// And move to that segment. |
| 123 |
int PropagateTexturesMove(void) |
| 124 |
{ |
| 125 |
return propagate_textures_common(0, 1); |
| 126 |
} |
| 127 |
|
| 128 |
// Propagate uv coordinate from current segment, through current side |
| 129 |
// And move to that segment. |
| 130 |
int PropagateTexturesMoveUVs(void) |
| 131 |
{ |
| 132 |
return propagate_textures_common(-1, 1); |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
// ------------------------------------------------------------------------------------- |
| 137 |
static int is_selected_segment(segnum_t segnum) |
| 138 |
{ |
| 139 |
return Selected_segs.contains(segnum); |
| 140 |
} |
| 141 |
|
| 142 |
// ------------------------------------------------------------------------------------- |
| 143 |
// Auxiliary function for PropagateTexturesSelected. |
| 144 |
// Recursive parse. |
| 145 |
static void pts_aux(const vmsegptridx_t sp, visited_segment_bitarray_t &visited) |
| 146 |
{ |
| 147 |
visited[sp] = true; |
| 148 |
|
| 149 |
range_for (const auto c, sp->children) |
| 150 |
{ |
| 151 |
if (IS_CHILD(c)) |
| 152 |
{ |
| 153 |
const auto &&csegp = sp.absolute_sibling(c); |
| 154 |
while (!visited[c] && is_selected_segment(c)) |
| 155 |
{ |
| 156 |
med_propagate_tmaps_to_segments(sp, csegp, 0); |
| 157 |
pts_aux(csegp, visited); |
| 158 |
} |
| 159 |
} |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
// ------------------------------------------------------------------------------------- |
| 164 |
// Propagate texture maps from current segment recursively exploring all children, to all segments in Selected_list |
| 165 |
// until a segment not in Selected_list is reached. |
| 166 |
int PropagateTexturesSelected(void) |
| 167 |
{ |
| 168 |
autosave_mine( mine_filename ); |
| 169 |
undo_status[Autosave_count] = "Propogate Textures Selected UNDONE."; |
| 170 |
|
| 171 |
visited_segment_bitarray_t visited; |
| 172 |
visited[Cursegp] = true; |
| 173 |
|
| 174 |
pts_aux(Cursegp, visited); |
| 175 |
|
| 176 |
Update_flags |= UF_WORLD_CHANGED; |
| 177 |
|
| 178 |
return 1; |
| 179 |
} |
| 180 |
|