Subversion Repositories Games.Descent

Rev

Details | Last modification | View Log | RSS feed

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