lib/Game/RaycastFOV.xs

filter: Statementstmt 100% 96 / 96 Branchbran 68.9% 91 / 132 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 82.0% 187 / 228 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/Game/RaycastFOV.pm ↑ Summary
1 #define PERL_NO_GET_CONTEXT
2  
3 #include "EXTERN.h"
4 #include "perl.h"
5 #include "XSUB.h"
6  
7 #include "ppport.h"
8  
9 #include "math.h"
10  
11 #define CALLTWOUP \
12 ENTER; \
13 SAVETMPS; \
14 PUSHMARK(SP); \
15 EXTEND(SP, 2)
16 #define TWOUPDONE \
17 FREETMPS; \
18 LEAVE
19 #define CIRCLECB(x, y) \
20 do { \
21 key = Perl_form(aTHX_ "%d,%d", x, y); \
22 len = strlen(key); \
23 if(!hv_exists(seen, key, len)) { \
24 hv_store(seen, key, len, &PL_sv_yes, 0); \
25 PUSHMARK(SP); \
26 EXTEND(SP, 2); \
27 mPUSHs(newSViv(x)); \
28 mPUSHs(newSViv(y)); \
29 PUTBACK; \
30 call_sv(callback, G_DISCARD); \
31 SPAGAIN; \
32 } \
33 } while (0)
34  
35 MODULE = Game::RaycastFOV PACKAGE = Game::RaycastFOV
36 PROTOTYPES: ENABLE
37  
38 void
39 bypair (callback, ...)
40 SV *callback;
41 PREINIT:
42 int answer, i;
43 SV *x, *y;
44 PROTOTYPE: &@
45 PPCODE:
46 3 ▶ if (!(items & 1)) croak("uneven number of arguments");
Branch: 1 branch
BranchTrueFalseTotal
if (!(items & 1)) croak("uneven number of arguments"); 1 2 3
47 2 dSP;
48 4 ▶ for (i = 1; i < items; i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i < items; i += 2) { 3 1 4
49 3 x = ST(i);
50 3 y = ST(i + 1);
51 3 ▶ CALLTWOUP;
Branch: 2 branches
BranchTrueFalseTotal
CALLTWOUP; 0 3 3
CALLTWOUP; 0 3 3
52 3 PUSHs(x);
53 3 PUSHs(y);
54 3 PUTBACK;
55 3 call_sv(callback, G_SCALAR);
56 3 SPAGAIN;
57 3 answer = POPi;
58 3 ▶ TWOUPDONE;
Branch: 1 branch
BranchTrueFalseTotal
TWOUPDONE; 3 0 3
59 3 ▶ if (answer == -1) break;
Branch: 1 branch
BranchTrueFalseTotal
if (answer == -1) break; 1 2 3
60 }
61  
62 void
63 bypairall (callback, ...)
64 SV *callback;
65 PREINIT:
66 int i;
67 SV *x, *y;
68 PROTOTYPE: &@
69 PPCODE:
70 5 ▶ if (!(items & 1)) croak("uneven number of arguments");
Branch: 1 branch
BranchTrueFalseTotal
if (!(items & 1)) croak("uneven number of arguments"); 1 4 5
71 4 dSP;
72 47 ▶ for (i = 1; i < items; i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i < items; i += 2) { 43 4 47
73 43 x = ST(i);
74 43 y = ST(i + 1);
75 43 ▶ CALLTWOUP;
Branch: 2 branches
BranchTrueFalseTotal
CALLTWOUP; 0 43 43
CALLTWOUP; 0 43 43
76 43 PUSHs(x);
77 43 PUSHs(y);
78 43 PUTBACK;
79 43 call_sv(callback, G_DISCARD);
80 43 SPAGAIN;
81 43 ▶ TWOUPDONE;
Branch: 1 branch
BranchTrueFalseTotal
TWOUPDONE; 0 43 43
82 }
83  
84 void
85 circle (callback, int x0, int y0, int radius)
86 SV *callback;
87 PREINIT:
88 char *key;
89 int f, ddF_x, ddF_y, x, y;
90 HV* seen;
91 STRLEN len;
92 PROTOTYPE: &$$$
93 PPCODE:
94 4 dSP;
95 4 ENTER;
96 4 SAVETMPS;
97 4 sv_2mortal((SV *)(seen = newHV()));
98 4 f = 1 - radius;
99 4 ddF_x = 0;
100 4 ddF_y = -2 * radius;
101 4 x = 0;
102 4 y = radius;
103 4 ▶ CIRCLECB(x0, y0 + radius);
Branch: 3 branches
BranchTrueFalseTotal
CIRCLECB(x0, y0 + radius); 4 0 4
CIRCLECB(x0, y0 + radius); 0 4 4
CIRCLECB(x0, y0 + radius); 0 4 4
104 4 ▶ CIRCLECB(x0, y0 - radius);
Branch: 3 branches
BranchTrueFalseTotal
CIRCLECB(x0, y0 - radius); 4 0 4
CIRCLECB(x0, y0 - radius); 0 4 4
CIRCLECB(x0, y0 - radius); 0 4 4
105 4 ▶ CIRCLECB(x0 + radius, y0);
Branch: 3 branches
BranchTrueFalseTotal
CIRCLECB(x0 + radius, y0); 4 0 4
CIRCLECB(x0 + radius, y0); 0 4 4
CIRCLECB(x0 + radius, y0); 0 4 4
106 4 ▶ CIRCLECB(x0 - radius, y0);
Branch: 3 branches
BranchTrueFalseTotal
CIRCLECB(x0 - radius, y0); 4 0 4
CIRCLECB(x0 - radius, y0); 0 4 4
CIRCLECB(x0 - radius, y0); 0 4 4
107 9 ▶ while (x < y) {
Branch: 1 branch
BranchTrueFalseTotal
while (x < y) { 5 4 9
108 5 ▶ if (f >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (f >= 0) { 4 1 5
109 4 y--;
110 4 ddF_y += 2;
111 4 f += ddF_y;
112 }
113 5 x++;
114 5 ddF_x += 2;
115 5 f += ddF_x + 1;
116 5 ▶ CIRCLECB(x0 + x, y0 + y);
Branch: 3 branches
BranchTrueFalseTotal
CIRCLECB(x0 + x, y0 + y); 1 4 5
CIRCLECB(x0 + x, y0 + y); 0 1 1
CIRCLECB(x0 + x, y0 + y); 0 1 1
117 5 ▶ CIRCLECB(x0 - x, y0 + y);
Branch: 3 branches
BranchTrueFalseTotal
CIRCLECB(x0 - x, y0 + y); 1 4 5
CIRCLECB(x0 - x, y0 + y); 0 1 1
CIRCLECB(x0 - x, y0 + y); 0 1 1
118 5 ▶ CIRCLECB(x0 + x, y0 - y);
Branch: 3 branches
BranchTrueFalseTotal
CIRCLECB(x0 + x, y0 - y); 1 4 5
CIRCLECB(x0 + x, y0 - y); 0 1 1
CIRCLECB(x0 + x, y0 - y); 0 1 1
119 5 ▶ CIRCLECB(x0 - x, y0 - y);
Branch: 3 branches
BranchTrueFalseTotal
CIRCLECB(x0 - x, y0 - y); 1 4 5
CIRCLECB(x0 - x, y0 - y); 0 1 1
CIRCLECB(x0 - x, y0 - y); 0 1 1
120 5 ▶ CIRCLECB(x0 + y, y0 + x);
Branch: 3 branches
BranchTrueFalseTotal
CIRCLECB(x0 + y, y0 + x); 1 4 5
CIRCLECB(x0 + y, y0 + x); 0 1 1
CIRCLECB(x0 + y, y0 + x); 0 1 1
121 5 ▶ CIRCLECB(x0 - y, y0 + x);
Branch: 3 branches
BranchTrueFalseTotal
CIRCLECB(x0 - y, y0 + x); 1 4 5
CIRCLECB(x0 - y, y0 + x); 0 1 1
CIRCLECB(x0 - y, y0 + x); 0 1 1
122 5 ▶ CIRCLECB(x0 + y, y0 - x);
Branch: 3 branches
BranchTrueFalseTotal
CIRCLECB(x0 + y, y0 - x); 1 4 5
CIRCLECB(x0 + y, y0 - x); 0 1 1
CIRCLECB(x0 + y, y0 - x); 0 1 1
123 5 ▶ CIRCLECB(x0 - y, y0 - x);
Branch: 3 branches
BranchTrueFalseTotal
CIRCLECB(x0 - y, y0 - x); 1 4 5
CIRCLECB(x0 - y, y0 - x); 0 1 1
CIRCLECB(x0 - y, y0 - x); 0 1 1
124 }
125 4 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 4 0 4
126 4 LEAVE;
127  
128 void
129 line (callback, int x0, int y0, int x1, int y1)
130 SV *callback;
131 PREINIT:
132 int answer, dx, dy, err, e2, sx, sy;
133 PROTOTYPE: &$$$$
134 PPCODE:
135 43 dSP;
136 43 dx = abs(x1 - x0);
137 43 dy = abs(y1 - y0);
138 43 ▶ sx = x0 < x1 ? 1 : -1;
Branch: 1 branch
BranchTrueFalseTotal
sx = x0 < x1 ? 1 : -1; 18 25 43
139 43 ▶ sy = y0 < y1 ? 1 : -1;
Branch: 1 branch
BranchTrueFalseTotal
sy = y0 < y1 ? 1 : -1; 18 25 43
140 43 ▶ err = (dx > dy ? dx : -dy) / 2;
Branch: 1 branch
BranchTrueFalseTotal
err = (dx > dy ? dx : -dy) / 2; 25 18 43
141 while (1) {
142 104 ▶ CALLTWOUP;
Branch: 2 branches
BranchTrueFalseTotal
CALLTWOUP; 0 104 104
CALLTWOUP; 0 104 104
143 104 mPUSHs(newSViv(x0));
144 104 mPUSHs(newSViv(y0));
145 104 PUTBACK;
146 104 call_sv(callback, G_SCALAR);
147 104 SPAGAIN;
148 104 answer = POPi;
149 104 ▶ TWOUPDONE;
Branch: 1 branch
BranchTrueFalseTotal
TWOUPDONE; 104 0 104
150 104 ▶ if (answer == -1 || (x0 == x1 && y0 == y1)) break;
Branch: 3 branches
BranchTrueFalseTotal
if (answer == -1 || (x0 == x1 && y0 == y1)) break; 79 25 104
if (answer == -1 || (x0 == x1 && y0 == y1)) break; 26 53 79
if (answer == -1 || (x0 == x1 && y0 == y1)) break; 8 18 26
151 61 e2 = err;
152 61 ▶ if (e2 > -dx) {
Branch: 1 branch
BranchTrueFalseTotal
if (e2 > -dx) { 41 20 61
153 41 err -= dy;
154 41 x0 += sx;
155 }
156 61 ▶ if (e2 < dy) {
Branch: 1 branch
BranchTrueFalseTotal
if (e2 < dy) { 40 21 61
157 40 err += dx;
158 40 y0 += sy;
159 }
160 }
161  
162 void
163 sub_circle (callback, long x0, long y0, unsigned long radius, double swing, double angle, double max_angle)
164 SV *callback;
165 PREINIT:
166 char *key;
167 long newx, newy;
168 HV* seen;
169 STRLEN len;
170 PROTOTYPE: &$$$$$$
171 PPCODE:
172 3 dSP;
173 3 sv_2mortal((SV *)(seen = newHV()));
174 648 ▶ while (angle < max_angle) {
Branch: 1 branch
BranchTrueFalseTotal
while (angle < max_angle) { 645 3 648
175 645 newx = x0 + lrint(radius * cos(angle));
176 645 newy = y0 + lrint(radius * sin(angle));
177 645 key = Perl_form(aTHX_ "%ld,%ld", newx, newy);
178 645 len = strlen(key);
179 645 ▶ if(!hv_exists(seen, key, len)) {
Branch: 1 branch
BranchTrueFalseTotal
if(!hv_exists(seen, key, len)) { 24 621 645
180 24 hv_store(seen, key, len, &PL_sv_yes, 0);
181 24 ▶ CALLTWOUP;
Branch: 2 branches
BranchTrueFalseTotal
CALLTWOUP; 0 24 24
CALLTWOUP; 0 24 24
182 24 mPUSHs(newSViv(newx));
183 24 mPUSHs(newSViv(newy));
184 24 PUTBACK;
185 24 call_sv(callback, G_DISCARD);
186 24 SPAGAIN;
187 24 ▶ TWOUPDONE;
Branch: 1 branch
BranchTrueFalseTotal
TWOUPDONE; 24 0 24
188 }
189 645 angle += swing;
190 }
« blib/lib/Game/RaycastFOV.pm ↑ Summary