| 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 |
* Routines stripped from med.c for segment selection |
| 23 |
* |
| 24 |
*/ |
| 25 |
|
| 26 |
#include <stdio.h> |
| 27 |
#include <stdlib.h> |
| 28 |
#include <stdarg.h> |
| 29 |
#include <string.h> |
| 30 |
#include "gr.h" |
| 31 |
#include "ui.h" |
| 32 |
#include "u_mem.h" |
| 33 |
#include "inferno.h" |
| 34 |
#include "gameseg.h" |
| 35 |
#include "editor.h" |
| 36 |
#include "editor/esegment.h" |
| 37 |
#include "editor/medmisc.h" |
| 38 |
#include "segment.h" |
| 39 |
#include "object.h" |
| 40 |
#include "medsel.h" |
| 41 |
#include "kdefs.h" |
| 42 |
|
| 43 |
#include "dxxsconf.h" |
| 44 |
#include "compiler-range_for.h" |
| 45 |
|
| 46 |
//find the distance between a segment and a point |
| 47 |
static vm_magnitude compute_dist(const shared_segment &seg, const vms_vector &pos) |
| 48 |
{ |
| 49 |
auto &LevelSharedVertexState = LevelSharedSegmentState.get_vertex_state(); |
| 50 |
auto &Vertices = LevelSharedVertexState.get_vertices(); |
| 51 |
auto &vcvertptr = Vertices.vcptr; |
| 52 |
auto delta{compute_segment_center(vcvertptr, seg)}; |
| 53 |
vm_vec_sub2(delta,pos); |
| 54 |
return vm_vec_mag(delta); |
| 55 |
} |
| 56 |
|
| 57 |
void sort_seg_list(count_segment_array_t &segnumlist,const vms_vector &pos) |
| 58 |
{ |
| 59 |
std::array<fix, MAX_SEGMENTS> dist; |
| 60 |
range_for (const auto &ss, segnumlist) |
| 61 |
dist[ss] = compute_dist(vcsegptr(ss), pos); |
| 62 |
auto predicate = [&dist](count_segment_array_t::const_reference a, count_segment_array_t::const_reference b) { |
| 63 |
return dist[a] < dist[b]; |
| 64 |
}; |
| 65 |
std::sort(segnumlist.begin(), segnumlist.end(), predicate); |
| 66 |
} |
| 67 |
|
| 68 |
int SortSelectedList(void) |
| 69 |
{ |
| 70 |
sort_seg_list(Selected_segs,ConsoleObject->pos); |
| 71 |
editor_status_fmt("%i element selected list sorted.", Selected_segs.size()); |
| 72 |
|
| 73 |
return 1; |
| 74 |
} |
| 75 |
|
| 76 |
int SelectNextFoundSeg(void) |
| 77 |
{ |
| 78 |
auto &LevelSharedVertexState = LevelSharedSegmentState.get_vertex_state(); |
| 79 |
auto &Vertices = LevelSharedVertexState.get_vertices(); |
| 80 |
if (++Found_seg_index >= Found_segs.size()) |
| 81 |
Found_seg_index = 0; |
| 82 |
|
| 83 |
Cursegp = imsegptridx(Found_segs[Found_seg_index]); |
| 84 |
med_create_new_segment_from_cursegp(); |
| 85 |
|
| 86 |
Update_flags |= UF_WORLD_CHANGED; |
| 87 |
|
| 88 |
if (Lock_view_to_cursegp) |
| 89 |
{ |
| 90 |
auto &vcvertptr = Vertices.vcptr; |
| 91 |
set_view_target_from_segment(vcvertptr, Cursegp); |
| 92 |
} |
| 93 |
|
| 94 |
editor_status("Curseg assigned to next found segment."); |
| 95 |
|
| 96 |
return 1; |
| 97 |
} |
| 98 |
|
| 99 |
int SelectPreviousFoundSeg(void) |
| 100 |
{ |
| 101 |
auto &LevelSharedVertexState = LevelSharedSegmentState.get_vertex_state(); |
| 102 |
auto &Vertices = LevelSharedVertexState.get_vertices(); |
| 103 |
if (Found_seg_index > 0) |
| 104 |
Found_seg_index--; |
| 105 |
else |
| 106 |
Found_seg_index = Found_segs.size() - 1; |
| 107 |
|
| 108 |
Cursegp = imsegptridx(Found_segs[Found_seg_index]); |
| 109 |
med_create_new_segment_from_cursegp(); |
| 110 |
|
| 111 |
Update_flags |= UF_WORLD_CHANGED; |
| 112 |
|
| 113 |
if (Lock_view_to_cursegp) |
| 114 |
{ |
| 115 |
auto &vcvertptr = Vertices.vcptr; |
| 116 |
set_view_target_from_segment(vcvertptr, Cursegp); |
| 117 |
} |
| 118 |
|
| 119 |
editor_status("Curseg assigned to previous found segment."); |
| 120 |
|
| 121 |
return 1; |
| 122 |
} |
| 123 |
|