@@ -16,6 +16,7 @@ local DRAG_FACTOR <const> = 10
1616local PAN_FACTOR <const> = 10
1717local CHAR_WIDTH <const> = 10
1818local CHAR_HEIGHT <const> = 16
19+ local PADDING_WIDTH <const> = 240
1920local MAP_CLICK_BLOCK <const> = " P1 Fire" -- prevent this input while clicking on map buttons
2021
2122-- Map colors (0xAARRGGBB or "name")
@@ -51,6 +52,7 @@ local MobjFlags = enums.mobjflags
5152local Zoom = 1
5253local Follow = false
5354local Init = true
55+ local Players = {}
5456
5557-- tables
5658
@@ -77,11 +79,12 @@ local LastMouse = {
7779 left = false
7880}
7981local LastFramecount = - 1
80- local LastEpisode
81- local LastMap
8282
8383-- forward declarations
8484
85+ local LastEpisode
86+ local LastMap
87+
8588local Lines
8689local PlayerTypes
8790local EnemyTypes
@@ -91,7 +94,7 @@ local InertTypes
9194
9295-- gui.defaultPixelFont("fceux")
9396gui .use_surface (" client" )
94- client .SetClientExtraPadding (240 , 0 , 0 , 0 )
97+ client .SetClientExtraPadding (PADDING_WIDTH , 0 , 0 , 0 )
9598
9699-- TYPE CONVERTERS
97100
@@ -420,19 +423,20 @@ local function cached_line_coords(line)
420423 return table.unpack (line ._coords )
421424end
422425
423- local function get_player1_xy ()
424- for _ , player in Globals .iterate_players () do
425- return { x = player .mo .x , y = player .mo .y }
426- end
427- end
428-
429426local function iterate_players ()
427+ --[[ --
430428 local playercount = 0
431429 local total_killcount = 0
432430 local total_itemcount = 0
433431 local total_secretcount = 0
434432 local stats = " HP Armr Kill Item Secr\n"
433+ --]] --
435434 for i , player in Globals :iterate_players () do
435+ Players [i ] = {
436+ x = player .mo .x ,
437+ y = player .mo .y
438+ }
439+ --[[ --
436440 playercount = playercount + 1
437441 local killcount = player.killcount
438442 local itemcount = player.itemcount
@@ -444,11 +448,14 @@ local function iterate_players()
444448
445449 stats = string.format("%s P%i %4i %4i %4i %4i %4i\n",
446450 stats, i, player.health, player.armorpoints1, killcount, itemcount, secretcount)
451+ --]] --
447452 end
453+ --[[ --
448454 if playercount > 1 then
449455 stats = string.format("%s %-12s %4i %4i %4i\n", stats, "All", total_killcount, total_itemcount, total_secretcount)
450456 end
451- gui .text (0 , 0 , stats , nil , " topright" )
457+ text(0, 0, stats, nil, "topright")
458+ --]] --
452459end
453460
454461local function iterate ()
@@ -458,6 +465,7 @@ local function iterate()
458465
459466 local closest_line
460467 local selected_sector
468+ local texts = {}
461469 local mousePos = client .transformPoint (Mouse .X , Mouse .Y )
462470 local gameMousePos = screen_to_game (mousePos )
463471 local screenwidth = client .screenwidth ()
@@ -507,42 +515,34 @@ local function iterate()
507515 for _ , line in ipairs (selected_sector .lines ) do
508516 -- cached_line_coords gives some length error?
509517 local x1 , y1 , x2 , y2 = game_to_screen (line :coords ())
510- gui .drawLine (x1 , y1 , x2 , y2 , 0xff00ffff )
511-
512- gui .text (0 , 30 , string.format (
513- " SECTOR\n id: %d\n flr: %.2f\n ceil: %.2f\n spec: %d" ,
518+ drawline (x1 , y1 , x2 , y2 , 0xff00ffff )
519+ texts .sector = string.format (
520+ " SECTOR %d spec: %d\n flo: %.2f ceil: %.2f" ,
514521 selected_sector .iSectorID ,
522+ selected_sector .special ,
515523 selected_sector .floorheight / FRACUNIT ,
516- selected_sector .ceilingheight / FRACUNIT ,
517- selected_sector .special
518- ), 0xff00ffff )
524+ selected_sector .ceilingheight / FRACUNIT )
519525 end
520526 end
521527
522528 if closest_line then
523- local distances = {}
524529 local x1 , y1 , x2 , y2 = cached_line_coords (closest_line )
525- local pos = get_player1_xy ()
526-
527- for i , player in structs .globals .iterate_players () do
528- distances [i ] = math.floor (distancePointToLineSegment (
529- { x = pos .x / FRACUNIT , y = pos .y / FRACUNIT },
530- { x = x1 / FRACUNIT , y = y1 / FRACUNIT },
531- { x = x2 / FRACUNIT , y = y2 / FRACUNIT }
532- ))
533- end
530+ local pos = select (2 , next (Players ))
531+ local distance = distance_from_line (
532+ { x = pos .x / FRACUNIT , y = pos .y / FRACUNIT },
533+ { x = x1 / FRACUNIT , y = y1 / FRACUNIT },
534+ { x = x2 / FRACUNIT , y = y2 / FRACUNIT }
535+ )
534536
535537 x1 , y1 , x2 , y2 = game_to_screen (x1 , y1 , x2 , y2 )
536538 drawline (x1 , y1 , x2 , y2 , 0xffff8800 )
537- gui .text (0 , 120 , string.format (
538- " LINEDEF\n id: %d\n v1x: %.0f\n v1y: %.0f\n v2x: %.0f\n v2y: %.0f\n dist: %d" ,
539- closest_line .iLineID ,
540- closest_line .v1 .x / FRACUNIT ,
541- closest_line .v1 .y / FRACUNIT ,
542- closest_line .v2 .x / FRACUNIT ,
543- closest_line .v2 .y / FRACUNIT ,
544- distances [1 ]
545- ), 0xffff8800 )
539+ texts .line = string.format (
540+ " LINEDEF %d dist: %.0f\n v1 x: %5d y: %5d\n v2 x: %5d y: %5d" ,
541+ closest_line .iLineID , distance ,
542+ math.floor (closest_line .v1 .x / FRACUNIT ),
543+ math.floor (closest_line .v1 .y / FRACUNIT ),
544+ math.floor (closest_line .v2 .x / FRACUNIT ),
545+ math.floor (closest_line .v2 .y / FRACUNIT ))
546546 end
547547
548548 for _ , mobj in pairs (Globals .mobjs :readbulk ()) do
@@ -566,20 +566,18 @@ local function iterate()
566566 radius_color = " white"
567567 text_color = " white"
568568
569- gui .text (0 , 240 , string.format (
570- " THING (%s)\n id: %d\n x: %.5f\n y: %.5f\n z: %.2f\n " ..
571- " rad: %.0f\n tics: %d\n hp: %d\n rt: %d\n thre: %d" ,
572- MobjType [type ],
573- mobj .index ,
569+ texts .thing = string.format (
570+ " THING %d (%s)\n x: %.5f\n y: %.5f\n z: %.2f" ..
571+ " rad: %.0f\n tics: %d hp: %d\n rt: %d thre: %d" ,
572+ mobj .index , MobjType [type ],
574573 mobj .x / FRACUNIT ,
575574 mobj .y / FRACUNIT ,
576575 mobj .z / FRACUNIT ,
577576 mobj .radius / FRACUNIT ,
578577 mobj .tics ,
579578 mobj .health ,
580579 mobj .reactiontime ,
581- mobj .threshold
582- ))
580+ mobj .threshold )
583581 end
584582
585583 if radius_color then
@@ -593,14 +591,20 @@ local function iterate()
593591
594592 if text_color then
595593 text (
596- pos .x - radius + 1 ,
597- pos .y - radius ,
594+ pos .x - screen_radius + 1 ,
595+ pos .y - screen_radius ,
598596 string.format (" %d" , index ), text_color )
599597 end
600598 end
601599 end
602600 end
603601
602+ box (0 , 0 , PADDING_WIDTH , screenheight , 0xb0000000 , 0xb0000000 )
603+
604+ if texts .thing then text (10 , 208 , texts .thing ) end
605+ if texts .line then text (10 , 314 , texts .line , 0xffff8800 ) end
606+ if texts .sector then text (10 , 370 , texts .sector , 0xff00ffff ) end
607+
604608-- text(50,10,shortest_dist/FRACUNIT)
605609end
606610
@@ -637,14 +641,14 @@ local function update_zoom()
637641 LastMouse .wheel = mouseWheel
638642
639643 if Follow and Globals .gamestate == 0 then
640- local playerPos = get_player1_xy ( )
644+ local player = select ( 2 , next ( Players ) )
641645 local screenCenter = screen_to_game ({
642646 x = screenwidth / 2 ,
643647 y = screenheight / 2
644648 })
645649
646- screenCenter .x = screenCenter .x - playerPos .x
647- screenCenter .y = screenCenter .y - playerPos .y
650+ screenCenter .x = screenCenter .x - player .x
651+ screenCenter .y = screenCenter .y - player .y
648652 Pan .x = Pan .x + screenCenter .x / FRACUNIT
649653 Pan .y = Pan .y - screenCenter .y / FRACUNIT
650654 end
@@ -856,9 +860,9 @@ while true do
856860
857861 -- workaround: prevent multiple execution per frame because of emu.yield(), except when paused
858862 if (framecount ~= LastFramecount or paused ) and Globals .gamestate == 0 then
863+ iterate_players ()
859864 iterate ()
860- LastMouse .left = Mouse .Left
861- -- iterate_players()
865+ LastMouse .left = Mouse .Left
862866 end
863867
864868 --[[ --
0 commit comments