Debian Codegraph @

components/tracing.lua

raw symbols SCIP
1 local gl = require 'gl'
2
3 local tracers = {}
4
5 local function in_debug_mode()
6 return game.debug_keys.key_held(string.byte('`'))
7 end
8
9 function trace_line(from, to)
10 if in_debug_mode() then
11 table.insert(tracers, game.actors.new_generic('line_trace', function ()
12 function draw()
13 gl.glBegin(gl.GL_LINES)
14 gl.glColor4d(1, 1, 1, 0.3)
15 gl.glVertex2d(from.x, from.y)
16 gl.glColor4d(0, 0, 0, 0)
17 gl.glVertex2d(to.x, to.y)
18 gl.glEnd()
19 gl.glColor3d(1, 1, 1)
20 end
21 end))
22 end
23 end
24
25 function trace_bar(pos, progress)
26 if in_debug_mode() then
27 table.insert(tracers, game.actors.new_generic('arrow_trace', function ()
28 function draw()
29 local left = -10 + pos.x
30 local right = 10 + pos.x
31 local bottom = -1 + pos.y
32 local top = 1 + pos.y
33 local mid = left + (right - left) * progress
34 gl.glBegin(gl.GL_QUADS)
35 gl.glColor3d(1, 0, 0)
36 gl.glVertex2d(left, bottom)
37 gl.glVertex2d(right, bottom)
38 gl.glVertex2d(right, top)
39 gl.glVertex2d(left, top)
40 gl.glColor3d(0, 1, 0)
41 gl.glVertex2d(left, bottom)
42 gl.glVertex2d(mid, bottom)
43 gl.glVertex2d(mid, top)
44 gl.glVertex2d(left, top)
45 gl.glEnd()
46 gl.glColor3d(1, 1, 1)
47 end
48 end))
49 end
50 end
51
52 game.actors.new_generic('tracer_cleanup', function ()
53 function update_setup()
54 for i = 1, #tracers do
55 tracers[i].dead = true
56 tracers[i] = nil
57 end
58 end
59 end)