@@ -19,16 +19,16 @@ local MAP_CLICK_BLOCK = "P1 Fire" -- prevent this input while clicking on map
1919-- Map colors (0xAARRGGBB or "name")
2020local MapPrefs = {
2121 player = { color = 0xFF60A0FF , radius_min_zoom = 0.00 , text_min_zoom = 0.20 , },
22- enemy = { color = 0xFFF00000 , radius_min_zoom = 0.00 , text_min_zoom = 0.25 , },
22+ enemy = { color = 0xFFFF0000 , radius_min_zoom = 0.00 , text_min_zoom = 0.25 , },
2323 enemy_idle = { color = 0xFFAA0000 , radius_min_zoom = 0.00 , text_min_zoom = 0.25 , },
24- corpse = { color = 0x80AA0000 , radius_min_zoom = 0.00 , text_min_zoom = 0.30 , },
24+ -- corpse = { color = 0xAAAAAAAA , radius_min_zoom = 0.00, text_min_zoom = 0.75 , },
2525 missile = { color = 0xFFFF8000 , radius_min_zoom = 0.00 , text_min_zoom = 0.25 , },
26- shootable = { color = 0xFFFFDD00 , radius_min_zoom = 0.00 , text_min_zoom = 0.50 , },
27- countitem = { color = 0xFF8060FF , radius_min_zoom = 0.00 , text_min_zoom = 1.50 , },
28- item = { color = 0xFF8060FF , radius_min_zoom = 0.00 , text_min_zoom = 1.50 , },
29- misc = { color = 0xFFA0A0A0 , radius_min_zoom = 0.75 , text_min_zoom = 1.00 , },
26+ shootable = { color = 0xFFAAAAAA , radius_min_zoom = 0.00 , text_min_zoom = 0.50 , },
27+ countitem = { color = 0xFFFFFF00 , radius_min_zoom = 0.00 , text_min_zoom = 1.50 , },
28+ item = { color = 0xFF00FF00 , radius_min_zoom = 0.00 , text_min_zoom = 1.50 , },
29+ -- misc = { color = 0xFFA0A0A0, radius_min_zoom = 0.75, text_min_zoom = 1.00, },
3030 solid = { color = 0xFF505050 , radius_min_zoom = 0.75 , text_min_zoom = false , },
31- inert = { color = 0x80808080 , radius_min_zoom = 0.75 , text_min_zoom = false , },
31+ -- inert = { color = 0x80808080, radius_min_zoom = 0.75, text_min_zoom = false, },
3232 highlight = { color = 0xFFFF00FF , radius_min_zoom = 0.00 , text_min_zoom = 0.20 , },
3333}
3434
@@ -48,6 +48,7 @@ local MobjFlags = enums.mobjflags
4848-- TOP LEVEL VARIABLES
4949
5050local Zoom = 1
51+ local Follow = false
5152local Init = true
5253
5354-- tables
@@ -71,7 +72,8 @@ local LastScreenSize = {
7172local LastMouse = {
7273 x = 0 ,
7374 y = 0 ,
74- wheel = 0
75+ wheel = 0 ,
76+ left = false
7577}
7678local LastFramecount = - 1
7779local LastEpisode
@@ -194,17 +196,6 @@ local function in_range(var, minimum, maximum)
194196 return var >= minimum and var <= maximum
195197end
196198
197- local function reset_view ()
198- OB = {
199- top = math.maxinteger ,
200- left = math.maxinteger ,
201- bottom = math.mininteger ,
202- right = math.mininteger
203- }
204- Init = true
205- update_zoom ()
206- end
207-
208199local function pan_left (divider )
209200 Pan .x = Pan .x + PAN_FACTOR / Zoom / (divider or 2 )
210201end
@@ -228,6 +219,8 @@ local function zoom(times, mouseCenter)
228219 local direction = 1
229220 times = times or 1
230221
222+ if Follow then mouseCenter = false end
223+
231224 if times < 0 then
232225 direction = - 1
233226 times = - times
@@ -256,6 +249,12 @@ local function zoom(times, mouseCenter)
256249 Pan .y = Pan .y - zoomCenter .y / 0xffff
257250end
258251
252+ local function follow_toggle ()
253+ if Mouse .Left and not LastMouse .left then
254+ Follow = not Follow
255+ end
256+ end
257+
259258-- helper to get squared distance (avoids sqrt for comparison)
260259function dist_sq (p1 , p2 )
261260 return (p1 .x - p2 .x )^ 2 + (p1 .y - p2 .y )^ 2
@@ -363,11 +362,6 @@ local function get_mobj_color(mobj, mobjtype)
363362 return radius_color , text_color
364363end
365364
366- local function clear_cache ()
367- Lines = nil
368- reset_view ()
369- end
370-
371365local function init_cache ()
372366 if Lines then return end
373367
@@ -456,48 +450,18 @@ local function iterate()
456450
457451 local closest_line
458452 local selected_sector
459- local mouse = input .getmouse ()
460- local mousePos = client .transformPoint (mouse .X , mouse .Y )
453+ local mousePos = client .transformPoint (Mouse .X , Mouse .Y )
461454 local gameMousePos = screen_to_game (mousePos )
462455 local screenwidth = client .screenwidth ()
463456 local screenheight = client .screenheight ()
464457 local shortest_dist = math.maxinteger
465458
466- for _ , mobj in pairs (Globals .mobjs :readbulk ()) do
467- local type = mobj .type
468- local radius_color , text_color = get_mobj_color (mobj , type )
469- if radius_color or text_color then -- not hidden
470- local pos = tuple_to_vertex (game_to_screen (mobj .x , mobj .y ))
471-
472- if in_range (pos .x , 0 , screenwidth )
473- and in_range (pos .y , 0 , screenheight )
474- then
475- local type = mobj .type
476- local radius = math.floor ((mobj .radius / 0xffff ) * Zoom )
477- local index = mobj .index
478- --[[ --
479- local z = mobj.z
480- local tics = mobj.tics
481- local health = mobj.health
482- local sprite = SpriteNumber[mobj.sprite]
483- --]] --
484- if text_color then
485- -- type = MobjType[type]
486- text (pos .x , pos .y , string.format (" %d" , index ), text_color )
487- end
488- if radius_color then
489- box (pos .x - radius , pos .y - radius , pos .x + radius , pos .y + radius , radius_color )
490- end
491- end
492- end
493- end
494-
495459 for i , line in ipairs (Lines ) do
496- local color = 0xffcccccc
460+ local color = 0xffffffff
497461 local x1 , y1 , x2 , y2 = game_to_screen (cached_line_coords (line ))
498462 local special = line .special
499463
500- if special ~= 0 then color = 0xffcc00ff end
464+ if special ~= 0 then color = 0xffff00ff end
501465
502466 drawline (x1 , y1 , x2 , y2 , color ) -- no speedup from doing range check
503467
@@ -542,6 +506,35 @@ local function iterate()
542506 local x1 , y1 , x2 , y2 = game_to_screen (cached_line_coords (closest_line ))
543507 drawline (x1 , y1 , x2 , y2 , 0xffff8800 )
544508 end
509+
510+ for _ , mobj in pairs (Globals .mobjs :readbulk ()) do
511+ local type = mobj .type
512+ local radius_color , text_color = get_mobj_color (mobj , type )
513+ if radius_color or text_color then -- not hidden
514+ local pos = tuple_to_vertex (game_to_screen (mobj .x , mobj .y ))
515+
516+ if in_range (pos .x , 0 , screenwidth )
517+ and in_range (pos .y , 0 , screenheight )
518+ then
519+ local type = mobj .type
520+ local radius = math.floor ((mobj .radius / 0xffff ) * Zoom )
521+ local index = mobj .index
522+ --[[ --
523+ local z = mobj.z
524+ local tics = mobj.tics
525+ local health = mobj.health
526+ local sprite = SpriteNumber[mobj.sprite]
527+ --]] --
528+ if text_color then
529+ -- type = MobjType[type]
530+ text (pos .x , pos .y , string.format (" %d" , index ), text_color )
531+ end
532+ if radius_color then
533+ box (pos .x - radius , pos .y - radius , pos .x + radius , pos .y + radius , radius_color )
534+ end
535+ end
536+ end
537+ end
545538
546539-- text(50,10,shortest_dist/0xffff)
547540end
@@ -557,13 +550,18 @@ local function init_mobj_bounds()
557550 end
558551end
559552
560- function update_zoom ()
561- local mouse = input .getmouse ()
562- local mousePos = client .transformPoint (mouse .X , mouse .Y )
563- local mouseWheel = math.floor (mouse .Wheel / 120 )
564- local deltaX = mousePos .x - LastMouse .x
565- local deltaY = mousePos .y - LastMouse .y
566- local deltaWheel = mouseWheel - LastMouse .wheel
553+ local function get_player1_xy ()
554+ for _ , player in Globals .iterate_players () do
555+ return { x = player .mo .x , y = player .mo .y }
556+ end
557+ end
558+
559+ local function update_zoom ()
560+ local mousePos = client .transformPoint (Mouse .X , Mouse .Y )
561+ local mouseWheel = math.floor (Mouse .Wheel / 120 )
562+ local deltaX = mousePos .x - LastMouse .x
563+ local deltaY = mousePos .y - LastMouse .y
564+ local deltaWheel = mouseWheel - LastMouse .wheel
567565
568566 if deltaWheel ~= 0 then zoom (deltaWheel * WHEEL_ZOOM_FACTOR , true ) end
569567
@@ -575,9 +573,21 @@ function update_zoom()
575573
576574 LastMouse .x = mousePos .x
577575 LastMouse .y = mousePos .y
578- LastMouse .left = mouse .Left
579576 LastMouse .wheel = mouseWheel
580577
578+ if Follow and Globals .gamestate == 0 then
579+ local playerPos = get_player1_xy ()
580+ local screenCenter = screen_to_game ({
581+ x = client .screenwidth ()/ 2 ,
582+ y = client .screenheight ()/ 2
583+ })
584+
585+ screenCenter .x = screenCenter .x - playerPos .x
586+ screenCenter .y = screenCenter .y - playerPos .y
587+ Pan .x = Pan .x + screenCenter .x / 0xffff
588+ Pan .y = Pan .y - screenCenter .y / 0xffff
589+ end
590+
581591 if not Init
582592 and LastScreenSize .w == client .screenwidth ()
583593 and LastScreenSize .h == client .screenheight ()
@@ -602,6 +612,22 @@ function update_zoom()
602612 end
603613end
604614
615+ local function reset_view ()
616+ OB = {
617+ top = math.maxinteger ,
618+ left = math.maxinteger ,
619+ bottom = math.mininteger ,
620+ right = math.mininteger
621+ }
622+ Init = true
623+ update_zoom ()
624+ end
625+
626+ local function clear_cache ()
627+ Lines = nil
628+ reset_view ()
629+ end
630+
605631local function make_button (x , y , name , func )
606632 local boxWidth = CHAR_WIDTH
607633 local boxHeight = CHAR_HEIGHT
@@ -616,12 +642,11 @@ local function make_button(x, y, name, func)
616642
617643 local textX = x + boxWidth / 2 - textWidth / 2
618644 local textY = y + boxHeight / 2 - textHeight / 2 - boxHeight
619- local mouse = input .getmouse ()
620- local mousePos = client .transformPoint (mouse .X , mouse .Y )
645+ local mousePos = client .transformPoint (Mouse .X , Mouse .Y )
621646
622647 if in_range (mousePos .x , x , x + boxWidth )
623648 and in_range (mousePos .y , y - boxHeight , y ) then
624- if mouse .Left then
649+ if Mouse .Left then
625650 suppress_click_input ()
626651 colorIndex = 3
627652 func ()
@@ -633,13 +658,15 @@ local function make_button(x, y, name, func)
633658end
634659
635660local function make_buttons ()
636- make_button ( 10 , client .screenheight ()- 70 , " Zoom \n In " , function () zoom ( 1 ) end )
637- make_button ( 10 , client .screenheight ()- 10 , " Zoom \n Out " , function () zoom (- 1 ) end )
638- make_button ( 80 , client .screenheight ()- 40 , " Pan \n Left " , pan_left )
639- make_button (150 , client .screenheight ()- 70 , " Pan \n Up " , pan_up )
640- make_button (150 , client .screenheight ()- 10 , " Pan \n Down " , pan_down )
641- make_button (220 , client .screenheight ()- 40 , " Pan \n Right " , pan_right )
661+ make_button ( 10 , client .screenheight ()- 40 , " + " , function () zoom ( 1 ) end )
662+ make_button ( 10 , client .screenheight ()- 10 , " - " , function () zoom (- 1 ) end )
663+ make_button ( 40 , client .screenheight ()- 24 , " < " , pan_left )
664+ make_button ( 64 , client .screenheight ()- 40 , " ^ " , pan_up )
665+ make_button ( 64 , client .screenheight ()- 10 , " v " , pan_down )
666+ make_button ( 88 , client .screenheight ()- 24 , " > " , pan_right )
642667 make_button (300 , client .screenheight ()- 10 , " Reset\n View" , reset_view )
668+ make_button (118 , client .screenheight ()- 10 ,
669+ string.format (" Follow\n %s" , Follow and " ON" or " OFF" ), follow_toggle )
643670end
644671
645672-- Additional types that are not identifiable by flags alone
728755
729756while true do
730757 local framecount = emu .framecount ()
731- local paused = client .ispaused ()
758+ local paused = client .ispaused ()
759+ Mouse = input .getmouse ()
732760
733761 local episode , map = Globals .gameepisode , Globals .gamemap
734762 if episode ~= LastEpisode or map ~= LastMap then
@@ -750,17 +778,17 @@ while true do
750778 gui .clearGraphics ()
751779 -- while onframestart isn't called
752780 make_buttons ()
753- update_zoom ()
754781 end
755782
783+ update_zoom ()
784+
756785 -- workaround: prevent multiple execution per frame because of emu.yield(), except when paused
757- if framecount ~= LastFramecount or paused then
786+ if ( framecount ~= LastFramecount or paused ) and Globals . gamestate == 0 then
758787 iterate ()
759- iterate_players ()
788+ LastMouse .left = Mouse .Left
789+ -- iterate_players()
760790 end
761791
762- update_zoom ()
763-
764792 --[[ --
765793 text(10, client.screenheight()-170, string.format(
766794 "Zoom: %.4f\nPanX: %s\nPanY: %s",
0 commit comments