@@ -7,37 +7,38 @@ local symbols = require("dsda.symbols")
77
88-- CONSTANTS
99
10- local MINIMAL_ZOOM = 0.0001 -- ???
11- local ZOOM_FACTOR = 0.01
12- local WHEEL_ZOOM_FACTOR = 10
13- local DRAG_FACTOR = 10
14- local PAN_FACTOR = 10
15- local CHAR_WIDTH = 10
16- local CHAR_HEIGHT = 16
17- local MAP_CLICK_BLOCK = " P1 Fire" -- prevent this input while clicking on map buttons
10+ local FRACBITS <const> = 16
11+ local FRACUNIT <const> = 1 << FRACBITS
12+ local MINIMAL_ZOOM <const> = 0.0001 -- ???
13+ local ZOOM_FACTOR <const> = 0.01
14+ local WHEEL_ZOOM_FACTOR <const> = 10
15+ local DRAG_FACTOR <const> = 10
16+ local PAN_FACTOR <const> = 10
17+ local CHAR_WIDTH <const> = 10
18+ local CHAR_HEIGHT <const> = 16
19+ local MAP_CLICK_BLOCK <const> = " P1 Fire" -- prevent this input while clicking on map buttons
1820
1921-- Map colors (0xAARRGGBB or "name")
2022local MapPrefs = {
21- player = { color = 0xFF60A0FF , radius_min_zoom = 0.00 , text_min_zoom = 0.20 , },
22- enemy = { color = 0xFFFF0000 , radius_min_zoom = 0.00 , text_min_zoom = 0.25 , },
23- enemy_idle = { color = 0xFFAA0000 , radius_min_zoom = 0.00 , text_min_zoom = 0.25 , },
24- -- corpse = { color = 0xAAAAAAAA , radius_min_zoom = 0.00, text_min_zoom = 0.75, },
25- missile = { color = 0xFFFF8000 , radius_min_zoom = 0.00 , text_min_zoom = 0.25 , },
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, },
30- solid = { color = 0xFF505050 , radius_min_zoom = 0.75 , text_min_zoom = false , },
23+ player = { color = 0xff60a0ff , radius_min_zoom = 0.00 , text_min_zoom = 0.20 , },
24+ enemy = { color = 0xffff0000 , radius_min_zoom = 0.00 , text_min_zoom = 0.25 , },
25+ enemy_idle = { color = 0xffaa0000 , radius_min_zoom = 0.00 , text_min_zoom = 0.25 , },
26+ -- corpse = { color = 0xaaaaaaaa , radius_min_zoom = 0.00, text_min_zoom = 0.75, },
27+ missile = { color = 0xffff8000 , radius_min_zoom = 0.00 , text_min_zoom = 0.25 , },
28+ shootable = { color = 0xffaaaaaa , radius_min_zoom = 0.00 , text_min_zoom = 0.50 , },
29+ countitem = { color = 0xffffff00 , radius_min_zoom = 0.00 , text_min_zoom = 1.50 , },
30+ item = { color = 0xff00ff00 , radius_min_zoom = 0.00 , text_min_zoom = 1.50 , },
31+ -- misc = { color = 0xffa0a0a0 , radius_min_zoom = 0.75, text_min_zoom = 1.00, },
32+ solid = { color = 0xff505050 , radius_min_zoom = 0.75 , text_min_zoom = false , },
3133-- inert = { color = 0x80808080, radius_min_zoom = 0.75, text_min_zoom = false, },
32- highlight = { color = 0xFFFF00FF , radius_min_zoom = 0.00 , text_min_zoom = 0.20 , },
34+ highlight = { color = 0xffff00ff , radius_min_zoom = 0.00 , text_min_zoom = 0.20 , },
3335}
3436
3537-- shortcuts
3638
3739local text = gui .text
3840local box = gui .drawBox
3941local drawline = gui .drawLine
40- -- local text = gui.pixelText -- INSANELY SLOW
4142
4243local Globals = structs .globals
4344local MobjType = enums .mobjtype
@@ -116,19 +117,19 @@ end
116117-- GAME/SCREEN CODECS
117118
118119local function decode_x (coord )
119- return math.floor (((coord / 0xffff ) + Pan .x ) * Zoom )
120+ return math.floor (((coord / FRACUNIT ) + Pan .x ) * Zoom )
120121end
121122
122123local function decode_y (coord )
123- return math.floor (((- coord / 0xffff ) + Pan .y ) * Zoom )
124+ return math.floor (((- coord / FRACUNIT ) + Pan .y ) * Zoom )
124125end
125126
126127local function encode_x (coord )
127- return math.floor (((coord / Zoom ) - Pan .x ) * 0xffff )
128+ return math.floor (((coord / Zoom ) - Pan .x ) * FRACUNIT )
128129end
129130
130131local function encode_y (coord )
131- return - math.floor (((coord / Zoom ) - Pan .y ) * 0xffff )
132+ return - math.floor (((coord / Zoom ) - Pan .y ) * FRACUNIT )
132133end
133134
134135-- return value matches passed value (line/vertex tuple/table)
@@ -246,8 +247,8 @@ local function zoom(times, mouseCenter)
246247
247248 zoomCenter .x = (encode_x (mouseCenter and mousePos .x or client .screenwidth ()/ 2 )- zoomCenter .x )
248249 zoomCenter .y = (encode_y (mouseCenter and mousePos .y or client .screenheight ()/ 2 )- zoomCenter .y )
249- Pan .x = Pan .x + zoomCenter .x / 0xffff
250- Pan .y = Pan .y - zoomCenter .y / 0xffff
250+ Pan .x = Pan .x + zoomCenter .x / FRACUNIT
251+ Pan .y = Pan .y - zoomCenter .y / FRACUNIT
251252end
252253
253254local function follow_toggle ()
@@ -419,6 +420,12 @@ local function cached_line_coords(line)
419420 return table.unpack (line ._coords )
420421end
421422
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+
422429local function iterate_players ()
423430 local playercount = 0
424431 local total_killcount = 0
@@ -501,46 +508,90 @@ local function iterate()
501508 -- cached_line_coords gives some length error?
502509 local x1 , y1 , x2 , y2 = game_to_screen (line :coords ())
503510 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" ,
514+ selected_sector .iSectorID ,
515+ selected_sector .floorheight / FRACUNIT ,
516+ selected_sector .ceilingheight / FRACUNIT ,
517+ selected_sector .special
518+ ), 0xff00ffff )
504519 end
505520 end
506521
507522 if closest_line then
508- local x1 , y1 , x2 , y2 = game_to_screen (cached_line_coords (closest_line ))
509- drawline (x1 , y1 , x2 , y2 , 0xffff8800 )
523+ local distances = {}
524+ 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
534+
535+ x1 , y1 , x2 , y2 = game_to_screen (x1 , y1 , x2 , y2 )
536+ 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 )
510546 end
511547
512548 for _ , mobj in pairs (Globals .mobjs :readbulk ()) do
513549 local type = mobj .type
514550 local radius_color , text_color = get_mobj_color (mobj , type )
551+
515552 if radius_color or text_color then -- not hidden
516553 local pos = tuple_to_vertex (game_to_screen (mobj .x , mobj .y ))
517554
518555 if in_range (pos .x , 0 , screenwidth )
519556 and in_range (pos .y , 0 , screenheight )
520557 then
521558 local type = mobj .type
522- local radius = math.floor ((mobj .radius / 0xffff ) * Zoom )
559+ local radius = mobj .radius
560+ local screen_radius = math.floor ((radius / FRACUNIT ) * Zoom )
523561 local index = mobj .index
524- --[[ --
525- local z = mobj.z
526- local tics = mobj.tics
527- local health = mobj.health
528- local sprite = SpriteNumber[mobj.sprite]
529- --]] --
530562
531- if in_range (mousePos .x , pos .x - radius , pos .x + radius )
532- and in_range (mousePos .y , pos .y - radius , pos .y + radius )
563+ if in_range (mousePos .x , pos .x - screen_radius , pos .x + screen_radius )
564+ and in_range (mousePos .y , pos .y - screen_radius , pos .y + screen_radius )
533565 then
534566 radius_color = " white"
535567 text_color = " white"
568+
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 ,
574+ mobj .x / FRACUNIT ,
575+ mobj .y / FRACUNIT ,
576+ mobj .z / FRACUNIT ,
577+ mobj .radius / FRACUNIT ,
578+ mobj .tics ,
579+ mobj .health ,
580+ mobj .reactiontime ,
581+ mobj .threshold
582+ ))
536583 end
537584
538585 if radius_color then
539- box (pos .x - radius , pos .y - radius , pos .x + radius , pos .y + radius , radius_color )
586+ box (
587+ pos .x - screen_radius ,
588+ pos .y - screen_radius ,
589+ pos .x + screen_radius ,
590+ pos .y + screen_radius ,
591+ radius_color )
540592 end
541593
542594 if text_color then
543- -- type = MobjType[type]
544595 text (
545596 pos .x - radius + 1 ,
546597 pos .y - radius ,
@@ -550,26 +601,20 @@ local function iterate()
550601 end
551602 end
552603
553- -- text(50,10,shortest_dist/0xffff )
604+ -- text(50,10,shortest_dist/FRACUNIT )
554605end
555606
556607local function init_mobj_bounds ()
557608 for _ , mobj in pairs (Globals .mobjs :readbulk ()) do
558- local x = mobj .x / 0xffff
559- local y = mobj .y / 0xffff * - 1
609+ local x = mobj .x / FRACUNIT
610+ local y = mobj .y / FRACUNIT * - 1
560611 if x < OB .left then OB .left = x end
561612 if x > OB .right then OB .right = x end
562613 if y < OB .top then OB .top = y end
563614 if y > OB .bottom then OB .bottom = y end
564615 end
565616end
566617
567- local function get_player1_xy ()
568- for _ , player in Globals .iterate_players () do
569- return { x = player .mo .x , y = player .mo .y }
570- end
571- end
572-
573618local function update_zoom ()
574619 local screenwidth = client .screenwidth ()
575620 local screenheight = client .screenheight ()
@@ -600,8 +645,8 @@ local function update_zoom()
600645
601646 screenCenter .x = screenCenter .x - playerPos .x
602647 screenCenter .y = screenCenter .y - playerPos .y
603- Pan .x = Pan .x + screenCenter .x / 0xffff
604- Pan .y = Pan .y - screenCenter .y / 0xffff
648+ Pan .x = Pan .x + screenCenter .x / FRACUNIT
649+ Pan .y = Pan .y - screenCenter .y / FRACUNIT
605650 end
606651
607652 if not Init
0 commit comments