Skip to content

Commit 0fde190

Browse files
committed
doom lua:
- fix sector selection when hilite is off - draw block with intercept - 2 intercept buttons - adjustable intercept limit in config
1 parent cc8a170 commit 0fde190

2 files changed

Lines changed: 113 additions & 56 deletions

File tree

Assets/Lua/Doom/doom.lua

Lines changed: 60 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ end
130130
local function line_handler()
131131
if not ShowMap then return end
132132

133-
local closestLine
133+
local closestLine, selectedSector
134134
local player = select(2, next(Players)) -- first present player only for now
135135
local mousePos = client.transformPoint(Mouse.X, Mouse.Y)
136136
local gameMousePos = screen_to_game(mousePos)
@@ -318,41 +318,67 @@ local function tracked_handler()
318318
end
319319

320320
local function draw_grid()
321-
if ShowMap and ShowGrid then
322-
local size = GRID_SIZE * FRACUNIT
323-
local step = GRID_SIZE * Zoom
324-
local bmorg = game_to_screen(BlockmapOrigin)
325-
local bmend = game_to_screen(BlockmapEnd)
326-
local start = { x = bmorg.x, y = bmend.y }
327-
local stop = { x = bmend.x, y = bmorg.y }
321+
if not (ShowMap and ShowGrid) then return end
322+
323+
local size = GRID_SIZE * FRACUNIT
324+
local step = GRID_SIZE * Zoom
325+
local bmorg = game_to_screen(BlockmapOrigin)
326+
local bmend = game_to_screen(BlockmapEnd)
327+
local start = { x = bmorg.x, y = bmend.y }
328+
local stop = { x = bmend.x, y = bmorg.y }
329+
330+
for x = start.x, stop.x-1, step do
331+
drawline(x, start.y, x, stop.y, MapPrefs.grid.color)
332+
end
333+
for y = start.y, stop.y-1, step do
334+
drawline(start.x, y, stop.x, y, MapPrefs.grid.color)
335+
end
336+
337+
-- due to step being float in screen coords, we can't avoid rounding error
338+
-- so final 2 lines won't match grid size and sometimes won't even be drawn
339+
-- so we draw them separately where they "should be"
340+
-- while embracing the rounding error of all the rest
341+
-- since drawing them all perfectly is too complicated
342+
drawline(stop.x, start.y, stop.x, stop.y, MapPrefs.grid.color)
343+
drawline(start.x, stop.y, stop.x, stop.y, MapPrefs.grid.color)
344+
345+
for block,timer in pairs(MapBlocks) do
346+
local forecolor
347+
local backcolor
348+
local delta = timer - Framecount
328349

329-
for x = start.x, stop.x-1, step do
330-
drawline(x, start.y, x, stop.y, MapPrefs.grid.color)
331-
end
332-
for y = start.y, stop.y-1, step do
333-
drawline(start.x, y, stop.x, y, MapPrefs.grid.color)
350+
-- red or grey with dynamically reduced alpha
351+
if delta == FADEOUT_TIMER - 1 then
352+
forecolor = 0xffff0000
353+
backcolor = 0x33ff0000
354+
else
355+
forecolor = 0x88888888
356+
backcolor = (math.floor(0x88 / FADEOUT_TIMER * delta) << 24) | 0x888888
334357
end
335358

336-
-- due to step being float in screen coords, we can't avoid rounding error
337-
-- so final 2 lines won't match grid size and sometimes won't even be drawn
338-
-- so we draw them separately where they "should be"
339-
-- while embracing the rounding error of all the rest
340-
-- since drawing them all perfectly is too complicated
341-
drawline(stop.x, start.y, stop.x, stop.y, MapPrefs.grid.color)
342-
drawline(start.x, stop.y, stop.x, stop.y, MapPrefs.grid.color)
359+
if delta > 0 then
360+
local origin = game_to_screen(BlockmapOrigin)
361+
local x = origin.x + block % BlockmapWidth * GRID_SIZE * Zoom
362+
local y = origin.y - math.floor(block / BlockmapWidth) * GRID_SIZE * Zoom
363+
-- positioning precision is a bit higher than of the overall grid
364+
-- so it may look off at some zoom levels
365+
box(x, y, x + GRID_SIZE * Zoom, y - GRID_SIZE * Zoom, forecolor, backcolor)
366+
else
367+
MapBlocks[block] = nil
368+
end
343369
end
344370
end
345371

346372
local function draw_tracelines()
347373
if not ShowMap then return end
348374

349-
for k,v in pairs(DivLines) do
375+
for key,timer in pairs(DivLines) do
350376
local color
351377
local i = 0
352378
local line = {}
353-
local delta = v - Framecount
379+
local delta = timer - Framecount
354380

355-
for token in string.gmatch(k, "([^%s]+)") do
381+
for token in string.gmatch(key, "([^%s]+)") do
356382
line[i] = tonumber(token)
357383
i = i + 1
358384
end
@@ -367,7 +393,7 @@ local function draw_tracelines()
367393
local x1, y1, x2, y2 = game_to_screen(line[0], line[1], line[2], line[3])
368394
drawline(x1, y1, x2, y2, color)
369395
else
370-
DivLines[k] = nil
396+
DivLines[key] = nil
371397
end
372398
end
373399
end
@@ -442,15 +468,16 @@ local function make_buttons()
442468
elseif LineCrossLog == LineLogType.ALL then crossName = " ALL"
443469
end
444470

445-
make_button(-170, h*1, "Log Use " ..useName, function() cycle_log_types(true ) end)
446-
make_button(-170, h*2, "Log Cross " ..crossName, function() cycle_log_types(false) end)
447-
make_button(-170, h*3, "Log P_Random "..(RNGLog and " ON" or "OFF"), prandom_toggle)
448-
make_button(-170, h*4, "Log Interc. "..(InterceptLog and " ON" or "OFF"),intercept_toggle)
449-
make_button(-110, h*5, "Map " ..(ShowMap and " ON" or "OFF"), map_toggle)
450-
make_button(-110, h*6, "Grid " ..(ShowGrid and " ON" or "OFF"), grid_toggle)
451-
make_button(-110, h*7, "Hilite " ..(Hilite and " ON" or "OFF"), hilite_toggle)
452-
make_button(-110, h*8, "Follow " ..(Follow and " ON" or "OFF"), follow_toggle)
453-
make_button(-110, h*9, "Reset View", reset_view)
471+
make_button(-170, h*1, "Log Use " ..useName, function() cycle_log_types(true ) end)
472+
make_button(-170, h*2, "Log Cross " ..crossName, function() cycle_log_types(false) end)
473+
make_button(-170, h*3, "Log P_Random "..(RNGLog and " ON" or "OFF"), prandom_log)
474+
make_button(-170, h*4, "Log Interc. "..(InterceptLog and " ON" or "OFF"), intercept_log)
475+
make_button(-170, h*5, "Show Interc. "..(InterceptShow and " ON" or "OFF"),intercept_show)
476+
make_button(-110, h*6, "Map " ..(ShowMap and " ON" or "OFF"), map_show)
477+
make_button(-110, h*7, "Grid " ..(ShowGrid and " ON" or "OFF"), grid_show)
478+
make_button(-110, h*8, "Hilite " ..(Hilite and " ON" or "OFF"), hilite_toggle)
479+
make_button(-110, h*9, "Follow " ..(Follow and " ON" or "OFF"), follow_toggle)
480+
make_button(-110, h*10,"Reset View", reset_view)
454481

455482
Input = input.get()
456483

Assets/Lua/Doom/doom.misc.lua

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ PADDING_WIDTH = 240
2323
PRANDOM_ALL_IN_ONE = 49
2424
GRID_SIZE = 128
2525
FADEOUT_TIMER = 20
26+
MAXIMUM_INTERCEPTS = 128
2627
MAP_CLICK_BLOCK = "P1 Fire" -- prevent this input while clicking on map buttons
2728
SETTINGS_FILENAME = "doom.settings.lua"
2829

@@ -84,6 +85,7 @@ LineCrossLog = LineLogType.NONE
8485
BlockmapWidth = 0
8586
InterceptPtr = 0
8687
InterceptLog = false
88+
InterceptShow = false
8789
RNGLog = false
8890
Framecount = 0
8991
LastFramecount = -1
@@ -102,12 +104,13 @@ LastInput = nil
102104

103105

104106
-- saved to config
105-
Zoom = 1
106-
Follow = false
107-
Hilite = false
108-
ShowMap = true
109-
ShowGrid = true
110-
Angle = AngleType.BYTE
107+
Zoom = 1
108+
Follow = false
109+
Hilite = false
110+
ShowMap = true
111+
ShowGrid = true
112+
Angle = AngleType.BYTE
113+
InterceptLimit = MAXIMUM_INTERCEPTS
111114
Tracked = {
112115
[TrackedType.THING ] = TrackedEntity.new("thing" ),
113116
[TrackedType.LINE ] = TrackedEntity.new("line" ),
@@ -126,6 +129,7 @@ Players = {}
126129
Config = {}
127130
PRandomInfo = {}
128131
DivLines = {}
132+
MapBlocks = {}
129133
GUITexts = {}
130134
-- map object positions bounds
131135
OB = {
@@ -189,39 +193,39 @@ function hilite_toggle()
189193
Hilite = not Hilite
190194
end
191195

192-
function map_toggle()
196+
function map_show()
193197
ShowMap = not ShowMap
194198
end
195199

196-
function grid_toggle()
200+
function grid_show()
197201
ShowGrid = not ShowGrid
198202
end
199203

200-
function intercept_toggle()
201-
InterceptLog = not InterceptLog
204+
local function hook_intercepts()
202205
local name = "Intercepts"
203206

204-
if InterceptLog then
207+
if InterceptLog or InterceptShow then
205208
doom.on_intercept(function(block)
206209
local intercept_p = Globals.intercept_p
207210

208-
if ShowMap and ShowGrid then
211+
if ShowMap and InterceptShow then
212+
-- fetch traceline while at it
209213
local divline = Globals.trace
210214
local key = string.format(
211215
"%d %d %d %d",
212216
divline.x, divline.y,
213217
divline.x + divline.dx,
214218
divline.y + divline.dy
215219
)
216-
if not DivLines[key] then DivLines[key] = Framecount + FADEOUT_TIMER end
217-
220+
DivLines[key] = Framecount + FADEOUT_TIMER
221+
end
222+
223+
if intercept_p ~= InterceptPtr then
218224
-- new intercept was just added
219-
if intercept_p ~= InterceptPtr then
220-
local org = game_to_screen(BlockmapOrigin)
221-
local x = org.x+( block % BlockmapWidth )*128*Zoom
222-
local y = org.y-(math.floor(block / BlockmapWidth)+1)*128*Zoom
223-
-- box(x, y, x+128*Zoom, y+128*Zoom, "red", 0x40ff0000)
224-
InterceptPtr = intercept_p
225+
InterceptPtr = intercept_p
226+
227+
if ShowMap and ShowGrid and InterceptShow then
228+
MapBlocks[block] = Framecount + FADEOUT_TIMER
225229
end
226230
end
227231

@@ -231,7 +235,25 @@ function intercept_toggle()
231235
end
232236
end
233237

234-
function prandom_toggle()
238+
function intercept_log()
239+
if Globals.compatibility_level < 7 then
240+
InterceptLog = not InterceptLog
241+
hook_intercepts()
242+
243+
if InterceptLog then
244+
print("Logging intercepts beyond " .. MAXIMUM_INTERCEPTS .. "...")
245+
end
246+
else
247+
print("Boom fixed intercept overflow! No point in logging it.")
248+
end
249+
end
250+
251+
function intercept_show()
252+
InterceptShow = not InterceptShow
253+
hook_intercepts()
254+
end
255+
256+
function prandom_log()
235257
RNGLog = not RNGLog
236258
local name = "PRandom"
237259

@@ -676,6 +698,9 @@ function settings_read()
676698
-- ANGLE TYPE
677699
Angle = Config.Angle or AngleType.BYTE
678700

701+
-- INTERCEPTS
702+
InterceptLimit = Config.InterceptLimit or MAXIMUM_INTERCEPTS
703+
679704
-- MAP STATE
680705
if not Config.Zoom
681706
or not Config.PanX
@@ -740,6 +765,10 @@ function settings_write()
740765
file:write("Angle = " .. Angle .. "\n")
741766
file:write("\n")
742767

768+
-- INTERCEPTS
769+
file:write("InterceptLimit = " .. InterceptLimit .. "\n")
770+
file:write("\n")
771+
743772
-- MAP STATE
744773
file:write( "Zoom = " .. Zoom .. "\n")
745774
file:write( "PanX = " .. Pan.x .. "\n")
@@ -856,8 +885,9 @@ end
856885

857886
function clear_cache()
858887
reset_view()
859-
Lines = nil
860-
DivLines = {}
888+
Lines = nil
889+
DivLines = {}
890+
MapBlocks = {}
861891
Tracked = {
862892
[TrackedType.THING ] = TrackedEntity.new("thing" ),
863893
[TrackedType.LINE ] = TrackedEntity.new("line" ),

0 commit comments

Comments
 (0)