Skip to content

Commit 9f9c17c

Browse files
committed
doom lua: allow disabling highlight mode
gives slight speedup and cleaner environment
1 parent 7207ae0 commit 9f9c17c

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

Assets/Lua/Doom/doom.lua

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ local MobjFlags = enums.mobjflags
5353

5454
local Zoom = 1
5555
local Follow = false
56+
local Hilite = false
5657
local Init = true
5758
local Players = {}
5859

@@ -274,6 +275,12 @@ local function follow_toggle()
274275
end
275276
end
276277

278+
local function hilite_toggle()
279+
if Mouse.Left and not LastMouse.left then
280+
Hilite = not Hilite
281+
end
282+
end
283+
277284
-- helper to get squared distance (avoids sqrt for comparison)
278285
function dist_sq(p1, p2)
279286
return (p1.x - p2.x)^2 + (p1.y - p2.y)^2
@@ -522,16 +529,18 @@ local function iterate()
522529

523530
drawline(x1, y1, x2, y2, color) -- no speedup from doing range check
524531

525-
x1, y1, x2, y2 = cached_line_coords(line)
526-
527-
local dist = distance_from_line(
528-
gameMousePos,
529-
tuple_to_vertex(x1, y1),
530-
tuple_to_vertex(x2, y2))
531-
532-
if math.abs(dist) < shortest_dist then
533-
shortest_dist = math.abs(dist)
534-
closest_line = line
532+
if Hilite then
533+
x1, y1, x2, y2 = cached_line_coords(line)
534+
535+
local dist = distance_from_line(
536+
gameMousePos,
537+
tuple_to_vertex(x1, y1),
538+
tuple_to_vertex(x2, y2))
539+
540+
if math.abs(dist) < shortest_dist then
541+
shortest_dist = math.abs(dist)
542+
closest_line = line
543+
end
535544
end
536545
end
537546

@@ -625,7 +634,8 @@ local function iterate()
625634
local radius = mobj.radius
626635
local screen_radius = math.floor((radius / FRACUNIT) * Zoom)
627636

628-
if in_range(mousePos.x, pos.x - screen_radius, pos.x + screen_radius)
637+
if Hilite
638+
and in_range(mousePos.x, pos.x - screen_radius, pos.x + screen_radius)
629639
and in_range(mousePos.y, pos.y - screen_radius, pos.y + screen_radius)
630640
and mousePos.x > PADDING_WIDTH and not CurrentPrompt
631641
then
@@ -922,9 +932,9 @@ local function add_entity(type)
922932
end
923933

924934
local function make_buttons()
925-
make_button(-315, 30, "Add Thing", function() add_entity("thing" ) end)
926-
make_button(-210, 30, "Add Line", function() add_entity("line" ) end)
927935
make_button(-115, 30, "Add Sector", function() add_entity("sector") end)
936+
make_button(-210, 30, "Add Line", function() add_entity("line" ) end)
937+
make_button(-315, 30, "Add Thing", function() add_entity("thing" ) end)
928938
make_button( 10, -40, "+", function() zoom ( 1 ) end)
929939
make_button( 10, -10, "-", function() zoom (-1 ) end)
930940
make_button( 40, -24, "<", pan_left )
@@ -933,7 +943,9 @@ local function make_buttons()
933943
make_button( 88, -24, ">", pan_right )
934944
make_button( 118, -40, "Reset View", reset_view )
935945
make_button( 118, -10,
936-
string.format("Follow %s", Follow and "ON " or "OFF"), follow_toggle)
946+
string.format("Follow %s", Follow and "ON " or "OFF"), follow_toggle)
947+
make_button(-460, 30,
948+
string.format("Highlight %s", Hilite and "ON " or "OFF"), hilite_toggle)
937949

938950
if CurrentPrompt then
939951
input_prompt()

0 commit comments

Comments
 (0)