MCPcopy Create free account
hub / github.com/HailToDodongo/pyrite64 / debugDrawLine

Function debugDrawLine

n64/engine/src/debug/debugDraw.cpp:42–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40 std::vector<Line> lines{};
41
42 void debugDrawLine(surface_t *fb, int px0, int py0, int px1, int py1, uint16_t color)
43 {
44 int width = fb->width;
45 int height = fb->height;
46 if((px0 > width + 200) || (px1 > width + 200) ||
47 (py0 > height + 200) || (py1 > height + 200)) {
48 return;
49 }
50
51 float pos[2]{(float)px0, (float)py0};
52 int dx = px1 - px0;
53 int dy = py1 - py0;
54 int steps = abs(dx) > abs(dy) ? abs(dx) : abs(dy);
55 if(steps <= 0 || steps > 1000)return;
56 float xInc = dx / (float)steps;
57 float yInc = dy / (float)steps;
58
59 if(surface_get_format(fb) == FMT_RGBA16)
60 {
61 uint16_t *buff = (uint16_t*)fb->buffer;
62 for(int i=0; i<steps; ++i)
63 {
64 if((i%3 != 0) && pos[1] >= 0 && pos[1] < height && pos[0] >= 0 && pos[0] < width) {
65 buff[(int)pos[1] * width + (int)pos[0]] = color;
66 }
67 pos[0] += xInc;
68 pos[1] += yInc;
69 }
70 } else
71 {
72 uint32_t col32 = color_to_packed32(color_from_packed16(color));
73 uint32_t *buff = (uint32_t*)fb->buffer;
74 for(int i=0; i<steps; ++i)
75 {
76 if((i%3 != 0) && pos[1] >= 0 && pos[1] < height && pos[0] >= 0 && pos[0] < width) {
77 buff[(int)pos[1] * width + (int)pos[0]] = col32;
78 }
79 pos[0] += xInc;
80 pos[1] += yInc;
81 }
82 }
83 }
84}
85
86void P64::Debug::init() {

Callers 1

drawMethod · 0.85

Calls 1

absFunction · 0.85

Tested by

no test coverage detected