dxx-rebirth/similar/editor/ksegsel.cpp

234 lines
6.4 KiB
C++
Raw Normal View History

2006-03-20 16:43:15 +00:00
/*
2014-06-01 17:55:23 +00:00
* Portions of this file are copyright Rebirth contributors and licensed as
* described in COPYING.txt.
* Portions of this file are copyright Parallax Software and licensed
* according to the Parallax license below.
* See COPYING.txt for license details.
2006-03-20 16:43:15 +00:00
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
2006-03-20 16:43:15 +00:00
COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
*/
2006-03-20 16:43:15 +00:00
/*
*
* Functions for selecting segments
*
*/
2015-04-22 02:44:31 +00:00
#include <utility>
2006-03-20 16:43:15 +00:00
#include <string.h>
#include "editor/editor.h"
2013-03-16 03:10:55 +00:00
#include "editor/esegment.h"
2013-09-24 01:59:09 +00:00
#include "editor/medmisc.h"
#include "gameseg.h"
#include "kdefs.h"
#include "compiler-range_for.h"
#include "d_range.h"
2006-03-20 16:43:15 +00:00
2015-04-22 02:44:31 +00:00
__attribute_warn_unused_result
static vmsegptridx_t get_any_attached_segment(const vmsegptridx_t curseg_num, const uint_fast32_t skipside)
2015-04-22 02:44:31 +00:00
{
range_for (const uint_fast32_t s, xrange(MAX_SIDES_PER_SEGMENT))
2015-04-22 02:44:31 +00:00
{
if (unlikely(s == skipside))
continue;
const auto child = curseg_num->children[s];
if (IS_CHILD(child))
return curseg_num.absolute_sibling(child);
2015-04-22 02:44:31 +00:00
}
return curseg_num;
}
__attribute_warn_unused_result
static vmsegptridx_t get_previous_segment(const vmsegptridx_t curseg_num, const uint_fast32_t curside)
2015-04-22 02:44:31 +00:00
{
const auto side_child = curseg_num->children[Side_opposite[curside]];
if (IS_CHILD(side_child))
return curseg_num.absolute_sibling(side_child);
2015-04-22 02:44:31 +00:00
// no segment on opposite face, connect to anything
return get_any_attached_segment(curseg_num, curside);
}
2006-03-20 16:43:15 +00:00
// ---------------------------------------------------------------------------------------
// Select previous segment.
// If there is a connection on the side opposite to the current side, then choose that segment.
// If there is no connecting segment on the opposite face, try any segment.
2015-04-22 02:44:31 +00:00
__attribute_warn_unused_result
static std::pair<vmsegptridx_t, uint_fast32_t> get_previous_segment_side(const vmsegptridx_t curseg_num, const uint_fast32_t curside)
2006-03-20 16:43:15 +00:00
{
2015-04-22 02:44:31 +00:00
const auto &newseg_num = get_previous_segment(curseg_num, curside);
2006-03-20 16:43:15 +00:00
// Now make Curside point at the segment we just left (unless we couldn't leave it).
2015-04-22 02:44:31 +00:00
return {newseg_num, newseg_num == curseg_num ? curside : find_connect_side(curseg_num, newseg_num)};
2006-03-20 16:43:15 +00:00
}
// --------------------------------------------------------------------------------------
// Select next segment.
// If there is a connection on the current side, then choose that segment.
// If there is no connecting segment on the current side, try any segment.
2015-05-09 17:38:58 +00:00
__attribute_warn_unused_result
static std::pair<vmsegptridx_t, uint_fast32_t> get_next_segment_side(const vmsegptridx_t curseg_num, uint_fast32_t curside)
2006-03-20 16:43:15 +00:00
{
2015-05-09 17:38:58 +00:00
const auto side_child = curseg_num->children[curside];
if (IS_CHILD(side_child))
{
const auto &&newseg_num = curseg_num.absolute_sibling(side_child);
2006-03-20 16:43:15 +00:00
// Find out what side we came in through and favor side opposite that
2015-05-09 17:38:58 +00:00
const auto newside = Side_opposite[find_connect_side(curseg_num, newseg_num)];
2006-03-20 16:43:15 +00:00
// If there is nothing attached on the side opposite to what we came in (*newside), pick any other side
2015-05-09 17:38:58 +00:00
if (!IS_CHILD(newseg_num->children[newside]))
range_for (const uint_fast32_t s, xrange(MAX_SIDES_PER_SEGMENT))
2015-05-09 17:38:58 +00:00
{
const auto cseg = newseg_num->children[s];
if (cseg != curseg_num && IS_CHILD(cseg))
return {newseg_num, s};
}
return {newseg_num, newside};
}
else
{
return {curseg_num, curside};
2006-03-20 16:43:15 +00:00
}
}
// ---------- select current segment ----------
int SelectCurrentSegForward()
{
auto &LevelSharedVertexState = LevelSharedSegmentState.get_vertex_state();
auto &Vertices = LevelSharedVertexState.get_vertices();
2015-05-09 17:38:58 +00:00
const auto p = get_next_segment_side(Cursegp,Curside);
const auto &newseg_num = p.first;
2006-03-20 16:43:15 +00:00
2015-05-09 17:38:58 +00:00
if (newseg_num != Cursegp)
{
Cursegp = newseg_num;
const auto &newside = p.second;
2006-03-20 16:43:15 +00:00
Curside = newside;
Update_flags |= UF_ED_STATE_CHANGED;
if (Lock_view_to_cursegp)
2018-12-30 00:43:57 +00:00
{
auto &vcvertptr = Vertices.vcptr;
set_view_target_from_segment(vcvertptr, Cursegp);
2018-12-30 00:43:57 +00:00
}
2006-03-20 16:43:15 +00:00
med_create_new_segment_from_cursegp();
mine_changed = 1;
}
return 1;
}
// -------------------------------------------------------------------------------------
int SelectCurrentSegBackward()
{
auto &LevelSharedVertexState = LevelSharedSegmentState.get_vertex_state();
auto &Vertices = LevelSharedVertexState.get_vertices();
2015-04-22 02:44:31 +00:00
const auto &p = get_previous_segment_side(Cursegp,Curside);
Cursegp = p.first;
Curside = p.second;
2006-03-20 16:43:15 +00:00
if (Lock_view_to_cursegp)
2018-12-30 00:43:57 +00:00
{
auto &vcvertptr = Vertices.vcptr;
set_view_target_from_segment(vcvertptr, Cursegp);
2018-12-30 00:43:57 +00:00
}
2006-03-20 16:43:15 +00:00
Update_flags |= UF_ED_STATE_CHANGED;
mine_changed = 1;
med_create_new_segment_from_cursegp();
return 1;
}
// ---------- select next/previous side on current segment ----------
int SelectNextSide()
{
if (++Curside >= MAX_SIDES_PER_SEGMENT)
Curside = 0;
Update_flags |= UF_ED_STATE_CHANGED;
mine_changed = 1;
return 1;
}
int SelectPrevSide()
{
if (--Curside < 0)
Curside = MAX_SIDES_PER_SEGMENT-1;
Update_flags |= UF_ED_STATE_CHANGED;
mine_changed = 1;
return 1;
}
// ---------- Copy current segment and side to marked segment and side ----------
int CopySegToMarked()
{
autosave_mine(mine_filename);
2015-04-02 02:36:56 +00:00
undo_status[Autosave_count] = "Mark Segment UNDONE.";
2006-03-20 16:43:15 +00:00
Markedsegp = Cursegp;
Markedside = Curside;
Update_flags |= UF_ED_STATE_CHANGED;
mine_changed = 1;
return 1;
}
// ---------- select absolute face on segment ----------
int SelectBottom()
{
Curside = WBOTTOM;
Update_flags |= UF_ED_STATE_CHANGED;
mine_changed = 1;
return 1;
}
int SelectFront()
{
Curside = WFRONT;
Update_flags |= UF_ED_STATE_CHANGED;
mine_changed = 1;
return 1;
}
int SelectTop()
{
Curside = WTOP;
Update_flags |= UF_ED_STATE_CHANGED;
mine_changed = 1;
return 1;
}
int SelectBack()
{
Curside = WBACK;
Update_flags |= UF_ED_STATE_CHANGED;
mine_changed = 1;
return 1;
}
int SelectLeft()
{
Curside = WLEFT;
Update_flags |= UF_ED_STATE_CHANGED;
mine_changed = 1;
return 1;
}
int SelectRight()
{
Curside = WRIGHT;
Update_flags |= UF_ED_STATE_CHANGED;
mine_changed = 1;
return 1;
}