| 1 |
|
| /* |
| 2 |
|
| * Terrain.xs - the XS door over pt_engine.c for Physics::Terrain. |
| 3 |
|
| * |
| 4 |
|
| * At the top of the dist, not under lib/, for the reason Struct::Codec's |
| 5 |
|
| * Codec.xs gives: an XSMULTI build's export list and Strawberry's import |
| 6 |
|
| * library rule never agree on a name. |
| 7 |
|
| * |
| 8 |
|
| * The engine is perl-free and every method Perl sees is an XSUB here: an |
| 9 |
|
| * object is a blessed scalar holding the state's address, and this file only |
| 10 |
|
| * turns option hashes into pt_opts, input logs into pt_input arrays, and an |
| 11 |
|
| * outcome back into the plain hashes and arrays the prototype's fixtures use. |
| 12 |
|
| * Every SV built here is owned by the structure it goes into, and the one |
| 13 |
|
| * returned is a fresh reference xsubpp mortalises itself. |
| 14 |
|
| */ |
| 15 |
|
| |
| 16 |
|
| #define PERL_NO_GET_CONTEXT |
| 17 |
|
| #include "EXTERN.h" |
| 18 |
|
| #include "perl.h" |
| 19 |
|
| #include "XSUB.h" |
| 20 |
|
| |
| 21 |
|
| #include "pt_abi.h" |
| 22 |
|
| |
| 23 |
|
| #define PT (pt_abi_table()) |
| 24 |
|
| |
| 25 |
827713 |
| static struct pt_state *pt_self(pTHX_ SV *sv, const char *who) { |
| 26 |
827713 |
▶ | if (!sv || !SvROK(sv) || !sv_derived_from(sv, "Physics::Terrain")) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!sv || !SvROK(sv) || !sv_derived_from(sv, "Physics::Terrain")) |
827713 |
0 |
827713 |
| if (!sv || !SvROK(sv) || !sv_derived_from(sv, "Physics::Terrain")) |
827713 |
0 |
827713 |
| if (!sv || !SvROK(sv) || !sv_derived_from(sv, "Physics::Terrain")) |
0 |
827713 |
827713 |
|
| 27 |
0 |
| croak("Physics::Terrain::%s: not a Physics::Terrain object", who); |
| 28 |
827713 |
| return INT2PTR(struct pt_state *, SvUV(SvRV(sv))); |
| 29 |
|
| } |
| 30 |
|
| |
| 31 |
402 |
| static struct pt_snapshot *pt_snap(pTHX_ SV *sv, const char *who) { |
| 32 |
402 |
▶ | if (!sv || !SvROK(sv) || !sv_derived_from(sv, "Physics::Terrain::Snapshot")) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!sv || !SvROK(sv) || !sv_derived_from(sv, "Physics::Terrain::Snapshot")) |
402 |
0 |
402 |
| if (!sv || !SvROK(sv) || !sv_derived_from(sv, "Physics::Terrain::Snapshot")) |
402 |
0 |
402 |
| if (!sv || !SvROK(sv) || !sv_derived_from(sv, "Physics::Terrain::Snapshot")) |
0 |
402 |
402 |
|
| 33 |
0 |
| croak("Physics::Terrain::%s: not a Physics::Terrain::Snapshot object", who); |
| 34 |
402 |
| return INT2PTR(struct pt_snapshot *, SvUV(SvRV(sv))); |
| 35 |
|
| } |
| 36 |
|
| |
| 37 |
1156 |
| static SV *pt_wrap(pTHX_ void *p, const char *class) { |
| 38 |
1156 |
| SV *inner = newSV(0); |
| 39 |
|
| SV *rv; |
| 40 |
1156 |
| sv_setuv(inner, PTR2UV(p)); |
| 41 |
1156 |
| rv = newRV_noinc(inner); |
| 42 |
1156 |
| sv_bless(rv, gv_stashpv(class, GV_ADD)); |
| 43 |
1156 |
| return rv; |
| 44 |
|
| } |
| 45 |
|
| |
| 46 |
24287 |
| static SV **pt_fetch(pTHX_ HV *hv, const char *key) { |
| 47 |
24287 |
| return hv_fetch(hv, key, (I32) strlen(key), 0); |
| 48 |
|
| } |
| 49 |
18887 |
| static IV pt_int(pTHX_ HV *hv, const char *key, IV dflt) { |
| 50 |
18887 |
| SV **v = pt_fetch(aTHX_ hv, key); |
| 51 |
18887 |
▶ | return v && SvOK(*v) ? SvIV(*v) : dflt; |
Branch: 2 branches
| Branch | True | False | Total |
| return v && SvOK(*v) ? SvIV(*v) : dflt; |
5150 |
13737 |
18887 |
| return v && SvOK(*v) ? SvIV(*v) : dflt; |
5150 |
0 |
5150 |
|
| 52 |
|
| } |
| 53 |
1913 |
| static AV *pt_array(pTHX_ HV *hv, const char *key) { |
| 54 |
1913 |
| SV **v = pt_fetch(aTHX_ hv, key); |
| 55 |
1913 |
▶ | if (v && SvROK(*v) && SvTYPE(SvRV(*v)) == SVt_PVAV) return (AV *) SvRV(*v); |
Branch: 3 branches
| Branch | True | False | Total |
| if (v && SvROK(*v) && SvTYPE(SvRV(*v)) == SVt_PVAV) return (AV *) SvRV(*v); |
1135 |
778 |
1913 |
| if (v && SvROK(*v) && SvTYPE(SvRV(*v)) == SVt_PVAV) return (AV *) SvRV(*v); |
1135 |
0 |
1135 |
| if (v && SvROK(*v) && SvTYPE(SvRV(*v)) == SVt_PVAV) return (AV *) SvRV(*v); |
1135 |
0 |
1135 |
|
| 56 |
778 |
| return NULL; |
| 57 |
|
| } |
| 58 |
957 |
| static HV *pt_hash(pTHX_ HV *hv, const char *key) { |
| 59 |
957 |
| SV **v = pt_fetch(aTHX_ hv, key); |
| 60 |
957 |
▶ | if (v && SvROK(*v) && SvTYPE(SvRV(*v)) == SVt_PVHV) return (HV *) SvRV(*v); |
Branch: 3 branches
| Branch | True | False | Total |
| if (v && SvROK(*v) && SvTYPE(SvRV(*v)) == SVt_PVHV) return (HV *) SvRV(*v); |
617 |
340 |
957 |
| if (v && SvROK(*v) && SvTYPE(SvRV(*v)) == SVt_PVHV) return (HV *) SvRV(*v); |
617 |
0 |
617 |
| if (v && SvROK(*v) && SvTYPE(SvRV(*v)) == SVt_PVHV) return (HV *) SvRV(*v); |
617 |
0 |
617 |
|
| 61 |
340 |
| return NULL; |
| 62 |
|
| } |
| 63 |
18312 |
| static IV pt_row_int(pTHX_ AV *row, I32 i, IV dflt) { |
| 64 |
18312 |
| SV **v = av_fetch(row, i, 0); |
| 65 |
18312 |
▶ | return v && SvOK(*v) ? SvIV(*v) : dflt; |
Branch: 2 branches
| Branch | True | False | Total |
| return v && SvOK(*v) ? SvIV(*v) : dflt; |
17696 |
616 |
18312 |
| return v && SvOK(*v) ? SvIV(*v) : dflt; |
17696 |
0 |
17696 |
|
| 66 |
|
| } |
| 67 |
1573 |
| static const char *pt_str(pTHX_ HV *hv, const char *key) { |
| 68 |
1573 |
| SV **v = pt_fetch(aTHX_ hv, key); |
| 69 |
2390 |
▶ | return v && SvOK(*v) ? SvPV_nolen(*v) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| return v && SvOK(*v) ? SvPV_nolen(*v) : NULL; |
817 |
756 |
1573 |
| return v && SvOK(*v) ? SvPV_nolen(*v) : NULL; |
817 |
0 |
817 |
|
| 70 |
|
| } |
| 71 |
|
| |
| 72 |
|
| /* {tick, weapon, angle, power} into a pt_shot; returns the tick, or -1 for no shot */ |
| 73 |
971 |
| static IV pt_read_shot(pTHX_ SV *sv, struct pt_shot *out) { |
| 74 |
|
| HV *hv; |
| 75 |
971 |
▶ | if (!sv || !SvOK(sv)) return -1; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!sv || !SvOK(sv)) return -1; |
971 |
0 |
971 |
| if (!sv || !SvOK(sv)) return -1; |
0 |
971 |
971 |
|
| 76 |
971 |
▶ | if (!SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVHV) croak("Physics::Terrain: a shot is a hash of weapon, angle, power and tick"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVHV) croak("Physics::Terrain: a shot is a hash of weapon, angle, power and tick"); |
971 |
0 |
971 |
| if (!SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVHV) croak("Physics::Terrain: a shot is a hash of weapon, angle, power and tick"); |
0 |
971 |
971 |
|
| 77 |
971 |
| hv = (HV *) SvRV(sv); |
| 78 |
971 |
| out->weapon = (int32_t) pt_int(aTHX_ hv, "weapon", 0); |
| 79 |
971 |
| out->angle = (int32_t) pt_int(aTHX_ hv, "angle", 0); |
| 80 |
971 |
| out->power = (int32_t) pt_int(aTHX_ hv, "power", 0); |
| 81 |
971 |
| return pt_int(aTHX_ hv, "tick", 0); |
| 82 |
|
| } |
| 83 |
|
| |
| 84 |
3386 |
| static int pt_op_code(const char *name) { |
| 85 |
3386 |
▶ | if (strEQ(name, "fill")) return PT_OP_FILL; |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(name, "fill")) return PT_OP_FILL; |
2837 |
549 |
3386 |
|
| 86 |
549 |
▶ | if (strEQ(name, "clear")) return PT_OP_CLEAR; |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(name, "clear")) return PT_OP_CLEAR; |
530 |
19 |
549 |
|
| 87 |
19 |
▶ | if (strEQ(name, "slope")) return PT_OP_SLOPE; |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(name, "slope")) return PT_OP_SLOPE; |
16 |
3 |
19 |
|
| 88 |
3 |
▶ | if (strEQ(name, "disc")) return PT_OP_DISC; |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(name, "disc")) return PT_OP_DISC; |
1 |
2 |
3 |
|
| 89 |
2 |
▶ | if (strEQ(name, "platform")) return PT_OP_PLATFORM; |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(name, "platform")) return PT_OP_PLATFORM; |
1 |
1 |
2 |
|
| 90 |
1 |
| return -1; |
| 91 |
|
| } |
| 92 |
|
| |
| 93 |
|
| /* [['fill', x0, y0, x1, y1], ...] into pt_sculpt; the caller frees */ |
| 94 |
1340 |
| static struct pt_sculpt *pt_read_sculpt(pTHX_ AV *ops, int32_t *count) { |
| 95 |
|
| struct pt_sculpt *out; |
| 96 |
|
| I32 n, i; |
| 97 |
1340 |
▶ | n = ops ? av_len(ops) + 1 : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| n = ops ? av_len(ops) + 1 : 0; |
1340 |
0 |
1340 |
|
| 98 |
1340 |
| *count = n; |
| 99 |
1340 |
▶ | Newxz(out, n ? n : 1, struct pt_sculpt); |
Branch: 1 branch
| Branch | True | False | Total |
| Newxz(out, n ? n : 1, struct pt_sculpt); |
1313 |
27 |
1340 |
|
| 100 |
4725 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
3386 |
1339 |
4725 |
|
| 101 |
3386 |
| SV **rp = av_fetch(ops, i, 0); |
| 102 |
|
| AV *row; |
| 103 |
|
| SV **nm; |
| 104 |
|
| int code; |
| 105 |
3386 |
▶ | if (!rp || !SvROK(*rp) || SvTYPE(SvRV(*rp)) != SVt_PVAV) { Safefree(out); croak("Physics::Terrain: sculpt op %d is not an array", (int) i); } |
Branch: 3 branches
| Branch | True | False | Total |
| if (!rp || !SvROK(*rp) || SvTYPE(SvRV(*rp)) != SVt_PVAV) { Safefree(out); croak("Physics::Terrain: sculpt op %d is not an array", (int) i); } |
3386 |
0 |
3386 |
| if (!rp || !SvROK(*rp) || SvTYPE(SvRV(*rp)) != SVt_PVAV) { Safefree(out); croak("Physics::Terrain: sculpt op %d is not an array", (int) i); } |
3386 |
0 |
3386 |
| if (!rp || !SvROK(*rp) || SvTYPE(SvRV(*rp)) != SVt_PVAV) { Safefree(out); croak("Physics::Terrain: sculpt op %d is not an array", (int) i); } |
0 |
3386 |
3386 |
|
| 106 |
3386 |
| row = (AV *) SvRV(*rp); |
| 107 |
3386 |
| nm = av_fetch(row, 0, 0); |
| 108 |
6772 |
▶ | code = nm && SvOK(*nm) ? pt_op_code(SvPV_nolen(*nm)) : -1; |
Branch: 2 branches
| Branch | True | False | Total |
| code = nm && SvOK(*nm) ? pt_op_code(SvPV_nolen(*nm)) : -1; |
3386 |
0 |
3386 |
| code = nm && SvOK(*nm) ? pt_op_code(SvPV_nolen(*nm)) : -1; |
3386 |
0 |
3386 |
|
| 109 |
3386 |
▶ | if (code < 0) { Safefree(out); croak("Physics::Terrain: sculpt op %d has no known name", (int) i); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (code < 0) { Safefree(out); croak("Physics::Terrain: sculpt op %d has no known name", (int) i); } |
1 |
3385 |
3386 |
|
| 110 |
3385 |
| out[i].op = code; |
| 111 |
3385 |
| out[i].a = (int32_t) pt_row_int(aTHX_ row, 1, 0); |
| 112 |
3385 |
| out[i].b = (int32_t) pt_row_int(aTHX_ row, 2, 0); |
| 113 |
3385 |
| out[i].c = (int32_t) pt_row_int(aTHX_ row, 3, 0); |
| 114 |
3385 |
| out[i].d = (int32_t) pt_row_int(aTHX_ row, 4, 0); |
| 115 |
|
| } |
| 116 |
1339 |
| return out; |
| 117 |
|
| } |
| 118 |
|
| |
| 119 |
617 |
| static void pt_read_gen(pTHX_ HV *gen, struct pt_gen *g) { |
| 120 |
617 |
| const char *profile = pt_str(aTHX_ gen, "profile"); |
| 121 |
617 |
| g->profile = -1; |
| 122 |
617 |
▶ | if (profile) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (profile) { |
617 |
0 |
617 |
|
| 123 |
617 |
▶ | if (strEQ(profile, "flat")) g->profile = PT_GEN_FLAT; |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(profile, "flat")) g->profile = PT_GEN_FLAT; |
58 |
559 |
617 |
|
| 124 |
559 |
▶ | else if (strEQ(profile, "empty")) g->profile = PT_GEN_EMPTY; |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(profile, "empty")) g->profile = PT_GEN_EMPTY; |
559 |
0 |
559 |
|
| 125 |
0 |
▶ | else if (strEQ(profile, "noise")) g->profile = PT_GEN_NOISE; |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(profile, "noise")) g->profile = PT_GEN_NOISE; |
0 |
0 |
0 |
|
| 126 |
0 |
| else croak("Physics::Terrain: unknown generator profile %s", profile); |
| 127 |
|
| } |
| 128 |
617 |
| g->W = (int32_t) pt_int(aTHX_ gen, "W", 0); |
| 129 |
617 |
| g->H = (int32_t) pt_int(aTHX_ gen, "H", 0); |
| 130 |
617 |
| g->coarse = (int32_t) pt_int(aTHX_ gen, "coarse", 0); |
| 131 |
617 |
| g->fine = (int32_t) pt_int(aTHX_ gen, "fine", 0); |
| 132 |
617 |
| g->cave = (int32_t) pt_int(aTHX_ gen, "cave", 0); |
| 133 |
617 |
| g->threshold = (int32_t) pt_int(aTHX_ gen, "threshold", 0); |
| 134 |
617 |
| g->bias_scale = (int32_t) pt_int(aTHX_ gen, "biasScale", 0); |
| 135 |
617 |
| g->bias_offset = (int32_t) pt_int(aTHX_ gen, "biasOffset", 0); |
| 136 |
617 |
| g->cave_lo = (int32_t) pt_int(aTHX_ gen, "caveLo", 0); |
| 137 |
617 |
| g->cave_hi = (int32_t) pt_int(aTHX_ gen, "caveHi", 0); |
| 138 |
617 |
| g->cave_top = (int32_t) pt_int(aTHX_ gen, "caveTop", 0); |
| 139 |
617 |
| g->cave_bottom = (int32_t) pt_int(aTHX_ gen, "caveBottom", 0); |
| 140 |
617 |
| g->platform = (int32_t) pt_int(aTHX_ gen, "platform", 0); |
| 141 |
617 |
| g->headroom = (int32_t) pt_int(aTHX_ gen, "headroom", 0); |
| 142 |
617 |
| g->floor = (int32_t) pt_int(aTHX_ gen, "floor", -1); |
| 143 |
617 |
| } |
| 144 |
|
| |
| 145 |
7247 |
| static AV *pt_body_av(pTHX_ const struct pt_body *b) { |
| 146 |
7247 |
| AV *row = newAV(); |
| 147 |
7247 |
| av_push(row, newSViv(b->seat)); av_push(row, newSViv(b->x)); av_push(row, newSViv(b->y)); |
| 148 |
7247 |
| av_push(row, newSViv(b->vx)); av_push(row, newSViv(b->vy)); av_push(row, newSViv(b->mode)); |
| 149 |
7247 |
| av_push(row, newSViv(b->alive)); av_push(row, newSViv(b->facing)); |
| 150 |
7247 |
| return row; |
| 151 |
|
| } |
| 152 |
|
| |
| 153 |
1520642 |
| static HV *pt_body_hv(pTHX_ const struct pt_body *b, IV index) { |
| 154 |
1520642 |
| HV *hv = newHV(); |
| 155 |
1520642 |
| (void) hv_stores(hv, "index", newSViv(index)); |
| 156 |
1520642 |
| (void) hv_stores(hv, "seat", newSViv(b->seat)); |
| 157 |
1520642 |
| (void) hv_stores(hv, "k", newSViv(b->k)); |
| 158 |
1520642 |
| (void) hv_stores(hv, "x", newSViv(b->x)); |
| 159 |
1520642 |
| (void) hv_stores(hv, "y", newSViv(b->y)); |
| 160 |
1520642 |
| (void) hv_stores(hv, "vx", newSViv(b->vx)); |
| 161 |
1520642 |
| (void) hv_stores(hv, "vy", newSViv(b->vy)); |
| 162 |
1520642 |
| (void) hv_stores(hv, "mode", newSViv(b->mode)); |
| 163 |
1520642 |
| (void) hv_stores(hv, "hp", newSViv(b->hp)); |
| 164 |
1520642 |
| (void) hv_stores(hv, "alive", newSViv(b->alive)); |
| 165 |
1520642 |
| (void) hv_stores(hv, "facing", newSViv(b->facing)); |
| 166 |
1520642 |
| return hv; |
| 167 |
|
| } |
| 168 |
|
| |
| 169 |
|
| /* the trace rows for one side, grouped by who into a sparse array of lists */ |
| 170 |
1942 |
| static AV *pt_trace_av(pTHX_ const struct pt_trace *rows, int32_t n, int with_weapon) { |
| 171 |
1942 |
| AV *out = newAV(); |
| 172 |
|
| int32_t i; |
| 173 |
265132 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
263190 |
1942 |
265132 |
|
| 174 |
263190 |
| SV **slot = av_fetch(out, rows[i].who, 1); |
| 175 |
|
| AV *list, *row; |
| 176 |
263190 |
▶ | if (!slot) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!slot) continue; |
0 |
263190 |
263190 |
|
| 177 |
263190 |
▶ | if (!SvROK(*slot)) { list = newAV(); sv_setsv(*slot, sv_2mortal(newRV_noinc((SV *) list))); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvROK(*slot)) { list = newAV(); sv_setsv(*slot, sv_2mortal(newRV_noinc((SV *) list))); } |
2342 |
260848 |
263190 |
|
| 178 |
260848 |
| else list = (AV *) SvRV(*slot); |
| 179 |
263190 |
| row = newAV(); |
| 180 |
263190 |
| av_push(row, newSViv(rows[i].tick)); av_push(row, newSViv(rows[i].x)); av_push(row, newSViv(rows[i].y)); |
| 181 |
263190 |
▶ | if (with_weapon && rows[i].weapon != -1) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (with_weapon && rows[i].weapon != -1) { |
106970 |
156220 |
263190 |
| if (with_weapon && rows[i].weapon != -1) { |
1256 |
105714 |
106970 |
|
| 182 |
1256 |
▶ | const struct pt_weapon *w = rows[i].weapon >= 0 ? (PT->weapon_get)(rows[i].weapon) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| const struct pt_weapon *w = rows[i].weapon >= 0 ? (PT->weapon_get)(rows[i].weapon) : NULL; |
1021 |
235 |
1256 |
|
| 183 |
1256 |
▶ | av_push(row, w && w->id ? newSVpv(w->id, 0) : newSV(0)); |
Branch: 2 branches
| Branch | True | False | Total |
| av_push(row, w && w->id ? newSVpv(w->id, 0) : newSV(0)); |
1021 |
235 |
1256 |
| av_push(row, w && w->id ? newSVpv(w->id, 0) : newSV(0)); |
1021 |
0 |
1021 |
|
| 184 |
|
| } |
| 185 |
263190 |
| av_push(list, newRV_noinc((SV *) row)); |
| 186 |
|
| } |
| 187 |
1942 |
| return out; |
| 188 |
|
| } |
| 189 |
|
| |
| 190 |
971 |
| static SV *pt_outcome_sv(pTHX_ struct pt_outcome *o) { |
| 191 |
971 |
| HV *hv = newHV(), *shot, *end; |
| 192 |
|
| AV *list, *row, *health; |
| 193 |
|
| int32_t i; |
| 194 |
|
| const char *err; |
| 195 |
971 |
| (void) hv_stores(hv, "engine", newSViv(1)); |
| 196 |
971 |
| (void) hv_stores(hv, "seed", newSVuv(o->seed)); |
| 197 |
971 |
| (void) hv_stores(hv, "active", newSViv(o->active)); |
| 198 |
971 |
| (void) hv_stores(hv, "wind", newSViv(o->wind)); |
| 199 |
971 |
| (void) hv_stores(hv, "ticks", newSViv(o->ticks)); |
| 200 |
971 |
| (void) hv_stores(hv, "settledAt", newSViv(o->settled_at)); |
| 201 |
971 |
| err = (PT->error_name)(o->error); |
| 202 |
971 |
▶ | (void) hv_stores(hv, "error", err ? newSVpv(err, 0) : newSV(0)); |
Branch: 1 branch
| Branch | True | False | Total |
| (void) hv_stores(hv, "error", err ? newSVpv(err, 0) : newSV(0)); |
2 |
969 |
971 |
|
| 203 |
971 |
▶ | if (o->has_shot) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (o->has_shot) { |
957 |
14 |
971 |
|
| 204 |
957 |
| shot = newHV(); |
| 205 |
957 |
| (void) hv_stores(shot, "tick", newSViv(o->shot_tick)); |
| 206 |
957 |
| (void) hv_stores(shot, "weapon", newSViv(o->shot.weapon)); |
| 207 |
957 |
| (void) hv_stores(shot, "angle", newSViv(o->shot.angle)); |
| 208 |
957 |
| (void) hv_stores(shot, "power", newSViv(o->shot.power)); |
| 209 |
957 |
| (void) hv_stores(hv, "shot", newRV_noinc((SV *) shot)); |
| 210 |
14 |
| } else (void) hv_stores(hv, "shot", newSV(0)); |
| 211 |
971 |
| list = newAV(); |
| 212 |
3087 |
▶ | for (i = 0; i < o->ninputs; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < o->ninputs; i++) { |
2116 |
971 |
3087 |
|
| 213 |
2116 |
| row = newAV(); av_push(row, newSViv(o->inputs[i].tick)); av_push(row, newSViv(o->inputs[i].bits)); |
| 214 |
2116 |
| av_push(list, newRV_noinc((SV *) row)); |
| 215 |
|
| } |
| 216 |
971 |
| (void) hv_stores(hv, "inputs", newRV_noinc((SV *) list)); |
| 217 |
971 |
| list = newAV(); |
| 218 |
6807 |
▶ | for (i = 0; i < o->nevents; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < o->nevents; i++) { |
5836 |
971 |
6807 |
|
| 219 |
5836 |
| row = newAV(); |
| 220 |
5836 |
| av_push(row, newSViv(o->events[i].tick)); av_push(row, newSVpv((PT->event_name)(o->events[i].kind), 0)); |
| 221 |
5836 |
| av_push(row, newSViv(o->events[i].a)); av_push(row, newSViv(o->events[i].b)); |
| 222 |
5836 |
| av_push(list, newRV_noinc((SV *) row)); |
| 223 |
|
| } |
| 224 |
971 |
| (void) hv_stores(hv, "events", newRV_noinc((SV *) list)); |
| 225 |
971 |
| list = newAV(); |
| 226 |
2042 |
▶ | for (i = 0; i < o->ncraters; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < o->ncraters; i++) { |
1071 |
971 |
2042 |
|
| 227 |
1071 |
| row = newAV(); av_push(row, newSViv(o->craters[i].x)); av_push(row, newSViv(o->craters[i].y)); av_push(row, newSViv(o->craters[i].r)); |
| 228 |
1071 |
| av_push(list, newRV_noinc((SV *) row)); |
| 229 |
|
| } |
| 230 |
971 |
| (void) hv_stores(hv, "craters", newRV_noinc((SV *) list)); |
| 231 |
|
| { |
| 232 |
971 |
| HV *trace = newHV(); |
| 233 |
971 |
| (void) hv_stores(trace, "bodies", newRV_noinc((SV *) pt_trace_av(aTHX_ o->trace_bodies, o->ntrace_bodies, 0))); |
| 234 |
971 |
| (void) hv_stores(trace, "shots", newRV_noinc((SV *) pt_trace_av(aTHX_ o->trace_shots, o->ntrace_shots, 1))); |
| 235 |
971 |
| (void) hv_stores(hv, "trace", newRV_noinc((SV *) trace)); |
| 236 |
|
| } |
| 237 |
971 |
| list = newAV(); |
| 238 |
5744 |
▶ | for (i = 0; i < o->nladder; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < o->nladder; i++) { |
4773 |
971 |
5744 |
|
| 239 |
4773 |
| row = newAV(); av_push(row, newSViv(o->ladder[i].tick)); av_push(row, newSVuv(o->ladder[i].h1)); av_push(row, newSVuv(o->ladder[i].h2)); |
| 240 |
4773 |
| av_push(list, newRV_noinc((SV *) row)); |
| 241 |
|
| } |
| 242 |
971 |
| (void) hv_stores(hv, "hashes", newRV_noinc((SV *) list)); |
| 243 |
971 |
| end = newHV(); |
| 244 |
971 |
| (void) hv_stores(end, "tick", newSViv(o->end_tick)); |
| 245 |
971 |
| list = newAV(); health = newAV(); |
| 246 |
8218 |
▶ | for (i = 0; i < o->nbodies; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < o->nbodies; i++) { |
7247 |
971 |
8218 |
|
| 247 |
7247 |
| av_push(list, newRV_noinc((SV *) pt_body_av(aTHX_ &o->bodies[i]))); |
| 248 |
7247 |
| av_push(health, newSViv(o->bodies[i].hp)); |
| 249 |
|
| } |
| 250 |
971 |
| (void) hv_stores(end, "bodies", newRV_noinc((SV *) list)); |
| 251 |
971 |
| (void) hv_stores(end, "health", newRV_noinc((SV *) health)); |
| 252 |
971 |
| (void) hv_stores(end, "craters", newSViv(o->end_craters)); |
| 253 |
971 |
| (void) hv_stores(hv, "end", newRV_noinc((SV *) end)); |
| 254 |
971 |
| return newRV_noinc((SV *) hv); |
| 255 |
|
| } |
| 256 |
|
| |
| 257 |
|
| MODULE = Physics::Terrain PACKAGE = Physics::Terrain |
| 258 |
|
| |
| 259 |
|
| PROTOTYPES: DISABLE |
| 260 |
|
| |
| 261 |
|
| # A field and its bodies from an option hash: seed, teams, per_team, wind, |
| 262 |
|
| # gen => {profile, W, H, ...}, sculpt => [[op, ...], ...], place => 'teams' | |
| 263 |
|
| # 'explicit' | 'none', bodies => [[seat, cx, cy_from, hp], ...]. |
| 264 |
|
| SV * |
| 265 |
|
| new(class, ...) |
| 266 |
|
| const char *class |
| 267 |
|
| PREINIT: |
| 268 |
958 |
| HV *opts = NULL; |
| 269 |
|
| struct pt_opts o; |
| 270 |
958 |
| struct pt_sculpt *ops = NULL; |
| 271 |
958 |
| struct pt_body_in *bodies = NULL; |
| 272 |
|
| struct pt_state *s; |
| 273 |
|
| AV *av; |
| 274 |
|
| HV *gen; |
| 275 |
|
| const char *place; |
| 276 |
|
| I32 i, n; |
| 277 |
958 |
| int32_t nops = 0; |
| 278 |
|
| CODE: |
| 279 |
958 |
▶ | if (items == 2 && SvROK(ST(1)) && SvTYPE(SvRV(ST(1))) == SVt_PVHV) opts = (HV *) SvRV(ST(1)); |
Branch: 3 branches
| Branch | True | False | Total |
| if (items == 2 && SvROK(ST(1)) && SvTYPE(SvRV(ST(1))) == SVt_PVHV) opts = (HV *) SvRV(ST(1)); |
0 |
958 |
958 |
| if (items == 2 && SvROK(ST(1)) && SvTYPE(SvRV(ST(1))) == SVt_PVHV) opts = (HV *) SvRV(ST(1)); |
0 |
0 |
0 |
| if (items == 2 && SvROK(ST(1)) && SvTYPE(SvRV(ST(1))) == SVt_PVHV) opts = (HV *) SvRV(ST(1)); |
0 |
0 |
0 |
|
| 280 |
958 |
▶ | else if (items > 1) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (items > 1) { |
958 |
0 |
958 |
|
| 281 |
958 |
▶ | if ((items - 1) % 2) croak("Physics::Terrain::new: odd number of options"); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((items - 1) % 2) croak("Physics::Terrain::new: odd number of options"); |
0 |
958 |
958 |
|
| 282 |
958 |
| opts = (HV *) sv_2mortal((SV *) newHV()); |
| 283 |
4689 |
▶ | for (i = 1; i < items; i += 2) (void) hv_store_ent(opts, ST(i), newSVsv(ST(i + 1)), 0); |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 1; i < items; i += 2) (void) hv_store_ent(opts, ST(i), newSVsv(ST(i + 1)), 0); |
3731 |
958 |
4689 |
|
| 284 |
0 |
| } else opts = (HV *) sv_2mortal((SV *) newHV()); |
| 285 |
958 |
| memset(&o, 0, sizeof o); |
| 286 |
958 |
| o.seed = (uint32_t) pt_int(aTHX_ opts, "seed", 1); |
| 287 |
958 |
| o.teams = (int32_t) pt_int(aTHX_ opts, "teams", 2); |
| 288 |
958 |
| o.per_team = (int32_t) pt_int(aTHX_ opts, "per_team", pt_int(aTHX_ opts, "perTeam", 4)); |
| 289 |
958 |
| o.live_cap = (int32_t) pt_int(aTHX_ opts, "live_cap", 0); |
| 290 |
958 |
| o.settle_cap = (int32_t) pt_int(aTHX_ opts, "settle_cap", 0); |
| 291 |
958 |
▶ | if (o.teams < 1 || o.teams > 4) croak("Physics::Terrain::new: teams is 1 to 4"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (o.teams < 1 || o.teams > 4) croak("Physics::Terrain::new: teams is 1 to 4"); |
958 |
0 |
958 |
| if (o.teams < 1 || o.teams > 4) croak("Physics::Terrain::new: teams is 1 to 4"); |
1 |
957 |
958 |
|
| 292 |
957 |
▶ | if (o.per_team < 1 || o.per_team > 8) croak("Physics::Terrain::new: per_team is 1 to 8"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (o.per_team < 1 || o.per_team > 8) croak("Physics::Terrain::new: per_team is 1 to 8"); |
957 |
0 |
957 |
| if (o.per_team < 1 || o.per_team > 8) croak("Physics::Terrain::new: per_team is 1 to 8"); |
0 |
957 |
957 |
|
| 293 |
|
| { |
| 294 |
957 |
| SV **w = pt_fetch(aTHX_ opts, "wind"); |
| 295 |
957 |
▶ | if (w && SvOK(*w)) { o.wind_set = 1; o.wind = (int32_t) SvIV(*w); } |
Branch: 2 branches
| Branch | True | False | Total |
| if (w && SvOK(*w)) { o.wind_set = 1; o.wind = (int32_t) SvIV(*w); } |
566 |
391 |
957 |
| if (w && SvOK(*w)) { o.wind_set = 1; o.wind = (int32_t) SvIV(*w); } |
566 |
0 |
566 |
|
| 296 |
|
| } |
| 297 |
957 |
| gen = pt_hash(aTHX_ opts, "gen"); |
| 298 |
957 |
▶ | if (gen) { o.use_gen = 1; pt_read_gen(aTHX_ gen, &o.gen); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (gen) { o.use_gen = 1; pt_read_gen(aTHX_ gen, &o.gen); } |
617 |
340 |
957 |
|
| 299 |
957 |
| av = pt_array(aTHX_ opts, "sculpt"); |
| 300 |
957 |
▶ | if (av) { ops = pt_read_sculpt(aTHX_ av, &nops); o.nsculpt = nops; o.sculpt = ops; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (av) { ops = pt_read_sculpt(aTHX_ av, &nops); o.nsculpt = nops; o.sculpt = ops; } |
568 |
389 |
957 |
|
| 301 |
956 |
| place = pt_str(aTHX_ opts, "place"); |
| 302 |
956 |
| av = pt_array(aTHX_ opts, "bodies"); |
| 303 |
956 |
▶ | if (place && strEQ(place, "none")) o.place = PT_PLACE_NONE; |
Branch: 2 branches
| Branch | True | False | Total |
| if (place && strEQ(place, "none")) o.place = PT_PLACE_NONE; |
200 |
756 |
956 |
| if (place && strEQ(place, "none")) o.place = PT_PLACE_NONE; |
152 |
48 |
200 |
|
| 304 |
804 |
▶ | else if ((place && strEQ(place, "explicit")) || (!place && av)) o.place = PT_PLACE_EXPLICIT; |
Branch: 4 branches
| Branch | True | False | Total |
| else if ((place && strEQ(place, "explicit")) || (!place && av)) o.place = PT_PLACE_EXPLICIT; |
48 |
756 |
804 |
| else if ((place && strEQ(place, "explicit")) || (!place && av)) o.place = PT_PLACE_EXPLICIT; |
15 |
33 |
48 |
| else if ((place && strEQ(place, "explicit")) || (!place && av)) o.place = PT_PLACE_EXPLICIT; |
756 |
15 |
771 |
| else if ((place && strEQ(place, "explicit")) || (!place && av)) o.place = PT_PLACE_EXPLICIT; |
534 |
222 |
756 |
|
| 305 |
237 |
▶ | else if (!place || strEQ(place, "teams")) o.place = PT_PLACE_TEAMS; |
Branch: 2 branches
| Branch | True | False | Total |
| else if (!place || strEQ(place, "teams")) o.place = PT_PLACE_TEAMS; |
15 |
222 |
237 |
| else if (!place || strEQ(place, "teams")) o.place = PT_PLACE_TEAMS; |
15 |
0 |
15 |
|
| 306 |
0 |
| else { Safefree(ops); croak("Physics::Terrain::new: place is teams, explicit or none"); } |
| 307 |
956 |
▶ | if (o.place == PT_PLACE_EXPLICIT) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (o.place == PT_PLACE_EXPLICIT) { |
567 |
389 |
956 |
|
| 308 |
567 |
▶ | n = av ? av_len(av) + 1 : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| n = av ? av_len(av) + 1 : 0; |
567 |
0 |
567 |
|
| 309 |
567 |
▶ | if (n > PT_MAX_BODIES) { Safefree(ops); croak("Physics::Terrain::new: at most %d bodies", PT_MAX_BODIES); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (n > PT_MAX_BODIES) { Safefree(ops); croak("Physics::Terrain::new: at most %d bodies", PT_MAX_BODIES); } |
0 |
567 |
567 |
|
| 310 |
567 |
▶ | Newxz(bodies, n ? n : 1, struct pt_body_in); |
Branch: 1 branch
| Branch | True | False | Total |
| Newxz(bodies, n ? n : 1, struct pt_body_in); |
567 |
0 |
567 |
|
| 311 |
1184 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
618 |
566 |
1184 |
|
| 312 |
618 |
| SV **rp = av_fetch(av, i, 0); |
| 313 |
|
| AV *row; |
| 314 |
618 |
▶ | if (!rp || !SvROK(*rp) || SvTYPE(SvRV(*rp)) != SVt_PVAV) { Safefree(ops); Safefree(bodies); croak("Physics::Terrain::new: body %d is not [seat, x, y_from, hp]", (int) i); } |
Branch: 3 branches
| Branch | True | False | Total |
| if (!rp || !SvROK(*rp) || SvTYPE(SvRV(*rp)) != SVt_PVAV) { Safefree(ops); Safefree(bodies); croak("Physics::Terrain::new: body %d is not [seat, x, y_from, hp]", (int) i); } |
618 |
0 |
618 |
| if (!rp || !SvROK(*rp) || SvTYPE(SvRV(*rp)) != SVt_PVAV) { Safefree(ops); Safefree(bodies); croak("Physics::Terrain::new: body %d is not [seat, x, y_from, hp]", (int) i); } |
618 |
0 |
618 |
| if (!rp || !SvROK(*rp) || SvTYPE(SvRV(*rp)) != SVt_PVAV) { Safefree(ops); Safefree(bodies); croak("Physics::Terrain::new: body %d is not [seat, x, y_from, hp]", (int) i); } |
0 |
618 |
618 |
|
| 315 |
618 |
| row = (AV *) SvRV(*rp); |
| 316 |
618 |
| bodies[i].seat = (int32_t) pt_row_int(aTHX_ row, 0, 0); |
| 317 |
618 |
| bodies[i].cx = (int32_t) pt_row_int(aTHX_ row, 1, 0); |
| 318 |
618 |
| bodies[i].cy_from = (int32_t) pt_row_int(aTHX_ row, 2, 0); |
| 319 |
618 |
| bodies[i].hp = (int32_t) pt_row_int(aTHX_ row, 3, 0); |
| 320 |
618 |
▶ | if (bodies[i].seat < 0 || bodies[i].seat > 3) { Safefree(ops); Safefree(bodies); croak("Physics::Terrain::new: seat is 0 to 3"); } |
Branch: 2 branches
| Branch | True | False | Total |
| if (bodies[i].seat < 0 || bodies[i].seat > 3) { Safefree(ops); Safefree(bodies); croak("Physics::Terrain::new: seat is 0 to 3"); } |
618 |
0 |
618 |
| if (bodies[i].seat < 0 || bodies[i].seat > 3) { Safefree(ops); Safefree(bodies); croak("Physics::Terrain::new: seat is 0 to 3"); } |
1 |
617 |
618 |
|
| 321 |
|
| } |
| 322 |
566 |
| o.nbodies = (int32_t) n; o.bodies = bodies; |
| 323 |
|
| } |
| 324 |
955 |
▶ | if (o.place == PT_PLACE_TEAMS && o.teams * o.per_team > PT_MAX_BODIES) { Safefree(ops); croak("Physics::Terrain::new: at most %d bodies", PT_MAX_BODIES); } |
Branch: 2 branches
| Branch | True | False | Total |
| if (o.place == PT_PLACE_TEAMS && o.teams * o.per_team > PT_MAX_BODIES) { Safefree(ops); croak("Physics::Terrain::new: at most %d bodies", PT_MAX_BODIES); } |
237 |
718 |
955 |
| if (o.place == PT_PLACE_TEAMS && o.teams * o.per_team > PT_MAX_BODIES) { Safefree(ops); croak("Physics::Terrain::new: at most %d bodies", PT_MAX_BODIES); } |
0 |
237 |
237 |
|
| 325 |
955 |
| s = (PT->state_new)(&o); |
| 326 |
955 |
| Safefree(ops); Safefree(bodies); |
| 327 |
955 |
▶ | if (!s) croak("Physics::Terrain::new: could not build the field"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!s) croak("Physics::Terrain::new: could not build the field"); |
0 |
955 |
955 |
|
| 328 |
955 |
| RETVAL = pt_wrap(aTHX_ s, class); |
| 329 |
|
| OUTPUT: |
| 330 |
|
| RETVAL |
| 331 |
|
| |
| 332 |
|
| void |
| 333 |
|
| DESTROY(self) |
| 334 |
|
| SV *self |
| 335 |
|
| PREINIT: |
| 336 |
|
| struct pt_state *s; |
| 337 |
|
| CODE: |
| 338 |
955 |
| s = pt_self(aTHX_ self, "DESTROY"); |
| 339 |
955 |
▶ | if (s) { (PT->state_free)(s); sv_setuv(SvRV(self), 0); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (s) { (PT->state_free)(s); sv_setuv(SvRV(self), 0); } |
955 |
0 |
955 |
|
| 340 |
|
| |
| 341 |
|
| IV |
| 342 |
|
| width(self) |
| 343 |
|
| SV *self |
| 344 |
|
| CODE: |
| 345 |
1 |
▶ | RETVAL = (PT->width)(pt_self(aTHX_ self, "width")); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = (PT->width)(pt_self(aTHX_ self, "width")); |
0 |
1 |
1 |
|
| 346 |
|
| OUTPUT: |
| 347 |
|
| RETVAL |
| 348 |
|
| |
| 349 |
|
| IV |
| 350 |
|
| height(self) |
| 351 |
|
| SV *self |
| 352 |
|
| CODE: |
| 353 |
1 |
▶ | RETVAL = (PT->height)(pt_self(aTHX_ self, "height")); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = (PT->height)(pt_self(aTHX_ self, "height")); |
0 |
1 |
1 |
|
| 354 |
|
| OUTPUT: |
| 355 |
|
| RETVAL |
| 356 |
|
| |
| 357 |
|
| UV |
| 358 |
|
| seed(self) |
| 359 |
|
| SV *self |
| 360 |
|
| CODE: |
| 361 |
1 |
▶ | RETVAL = (PT->seed)(pt_self(aTHX_ self, "seed")); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = (PT->seed)(pt_self(aTHX_ self, "seed")); |
0 |
1 |
1 |
|
| 362 |
|
| OUTPUT: |
| 363 |
|
| RETVAL |
| 364 |
|
| |
| 365 |
|
| IV |
| 366 |
|
| tick(self) |
| 367 |
|
| SV *self |
| 368 |
|
| CODE: |
| 369 |
0 |
▶ | RETVAL = (PT->tick)(pt_self(aTHX_ self, "tick")); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = (PT->tick)(pt_self(aTHX_ self, "tick")); |
0 |
0 |
0 |
|
| 370 |
|
| OUTPUT: |
| 371 |
|
| RETVAL |
| 372 |
|
| |
| 373 |
|
| IV |
| 374 |
|
| teams(self) |
| 375 |
|
| SV *self |
| 376 |
|
| CODE: |
| 377 |
0 |
▶ | RETVAL = (PT->teams)(pt_self(aTHX_ self, "teams")); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = (PT->teams)(pt_self(aTHX_ self, "teams")); |
0 |
0 |
0 |
|
| 378 |
|
| OUTPUT: |
| 379 |
|
| RETVAL |
| 380 |
|
| |
| 381 |
|
| IV |
| 382 |
|
| per_team(self) |
| 383 |
|
| SV *self |
| 384 |
|
| CODE: |
| 385 |
0 |
▶ | RETVAL = (PT->per_team)(pt_self(aTHX_ self, "per_team")); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = (PT->per_team)(pt_self(aTHX_ self, "per_team")); |
0 |
0 |
0 |
|
| 386 |
|
| OUTPUT: |
| 387 |
|
| RETVAL |
| 388 |
|
| |
| 389 |
|
| IV |
| 390 |
|
| solid(self, x, y) |
| 391 |
|
| SV *self |
| 392 |
|
| IV x |
| 393 |
|
| IV y |
| 394 |
|
| CODE: |
| 395 |
33289 |
▶ | RETVAL = (PT->solid)(pt_self(aTHX_ self, "solid"), (int32_t) x, (int32_t) y); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = (PT->solid)(pt_self(aTHX_ self, "solid"), (int32_t) x, (int32_t) y); |
33278 |
11 |
33289 |
|
| 396 |
|
| OUTPUT: |
| 397 |
|
| RETVAL |
| 398 |
|
| |
| 399 |
|
| # The first solid cell on the segment, both ends included: returns (hit, x, y, |
| 400 |
|
| # px, py) where px, py is the last free cell before the hit. |
| 401 |
|
| void |
| 402 |
|
| swept(self, x0, y0, x1, y1) |
| 403 |
|
| SV *self |
| 404 |
|
| IV x0 |
| 405 |
|
| IV y0 |
| 406 |
|
| IV x1 |
| 407 |
|
| IV y1 |
| 408 |
|
| PREINIT: |
| 409 |
|
| int32_t out[4]; |
| 410 |
|
| int32_t hit; |
| 411 |
|
| PPCODE: |
| 412 |
5 |
| hit = (PT->swept)(pt_self(aTHX_ self, "swept"), (int32_t) x0, (int32_t) y0, (int32_t) x1, (int32_t) y1, out); |
| 413 |
5 |
▶ | EXTEND(SP, 5); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 5); |
0 |
5 |
5 |
|
| 414 |
5 |
| mPUSHi(hit); mPUSHi(out[0]); mPUSHi(out[1]); mPUSHi(out[2]); mPUSHi(out[3]); |
| 415 |
|
| |
| 416 |
|
| IV |
| 417 |
|
| carve(self, x, y, r) |
| 418 |
|
| SV *self |
| 419 |
|
| IV x |
| 420 |
|
| IV y |
| 421 |
|
| IV r |
| 422 |
|
| CODE: |
| 423 |
48 |
▶ | RETVAL = (PT->carve)(pt_self(aTHX_ self, "carve"), (int32_t) x, (int32_t) y, (int32_t) r); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = (PT->carve)(pt_self(aTHX_ self, "carve"), (int32_t) x, (int32_t) y, (int32_t) r); |
44 |
4 |
48 |
|
| 424 |
|
| OUTPUT: |
| 425 |
|
| RETVAL |
| 426 |
|
| |
| 427 |
|
| void |
| 428 |
|
| sculpt(self, ops) |
| 429 |
|
| SV *self |
| 430 |
|
| AV *ops |
| 431 |
|
| PREINIT: |
| 432 |
|
| struct pt_sculpt *list; |
| 433 |
|
| int32_t n; |
| 434 |
|
| struct pt_state *s; |
| 435 |
|
| CODE: |
| 436 |
772 |
| s = pt_self(aTHX_ self, "sculpt"); |
| 437 |
772 |
| list = pt_read_sculpt(aTHX_ ops, &n); |
| 438 |
772 |
| (PT->sculpt)(s, n, list); |
| 439 |
772 |
| Safefree(list); |
| 440 |
|
| |
| 441 |
|
| IV |
| 442 |
|
| surface_at(self, x, y_from = 0) |
| 443 |
|
| SV *self |
| 444 |
|
| IV x |
| 445 |
|
| IV y_from |
| 446 |
|
| CODE: |
| 447 |
1 |
▶ | RETVAL = (PT->surface_at)(pt_self(aTHX_ self, "surface_at"), (int32_t) x, (int32_t) y_from); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = (PT->surface_at)(pt_self(aTHX_ self, "surface_at"), (int32_t) x, (int32_t) y_from); |
0 |
1 |
1 |
|
| 448 |
|
| OUTPUT: |
| 449 |
|
| RETVAL |
| 450 |
|
| |
| 451 |
|
| IV |
| 452 |
|
| count(self) |
| 453 |
|
| SV *self |
| 454 |
|
| CODE: |
| 455 |
52 |
▶ | RETVAL = (PT->count)(pt_self(aTHX_ self, "count")); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = (PT->count)(pt_self(aTHX_ self, "count")); |
44 |
8 |
52 |
|
| 456 |
|
| OUTPUT: |
| 457 |
|
| RETVAL |
| 458 |
|
| |
| 459 |
|
| # The mask as packed bytes: row-major, eight cells a byte, the leftmost cell |
| 460 |
|
| # in the low bit. Digest it with Digest::SHA for the mask digest. |
| 461 |
|
| SV * |
| 462 |
|
| mask(self) |
| 463 |
|
| SV *self |
| 464 |
|
| PREINIT: |
| 465 |
|
| struct pt_state *s; |
| 466 |
|
| size_t n; |
| 467 |
|
| CODE: |
| 468 |
136 |
| s = pt_self(aTHX_ self, "mask"); |
| 469 |
136 |
| n = (PT->mask_bytes)(s); |
| 470 |
136 |
| RETVAL = newSV(n + 1); |
| 471 |
136 |
| SvPOK_on(RETVAL); |
| 472 |
136 |
| (PT->mask_pack)(s, (uint8_t *) SvPVX(RETVAL)); |
| 473 |
136 |
| SvCUR_set(RETVAL, n); |
| 474 |
136 |
| *SvEND(RETVAL) = 0; |
| 475 |
|
| OUTPUT: |
| 476 |
|
| RETVAL |
| 477 |
|
| |
| 478 |
|
| # The index of the new body, or undef over the cap (error says why). |
| 479 |
|
| SV * |
| 480 |
|
| add_body(self, seat, cx, cy) |
| 481 |
|
| SV *self |
| 482 |
|
| IV seat |
| 483 |
|
| IV cx |
| 484 |
|
| IV cy |
| 485 |
|
| PREINIT: |
| 486 |
|
| int32_t i; |
| 487 |
|
| CODE: |
| 488 |
33 |
▶ | if (seat < 0 || seat > 3) croak("Physics::Terrain::add_body: seat is 0 to 3"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (seat < 0 || seat > 3) croak("Physics::Terrain::add_body: seat is 0 to 3"); |
33 |
0 |
33 |
| if (seat < 0 || seat > 3) croak("Physics::Terrain::add_body: seat is 0 to 3"); |
0 |
33 |
33 |
|
| 489 |
33 |
| i = (PT->add_body)(pt_self(aTHX_ self, "add_body"), (int32_t) seat, (int32_t) cx, (int32_t) cy); |
| 490 |
33 |
▶ | RETVAL = i < 0 ? newSV(0) : newSViv(i); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = i < 0 ? newSV(0) : newSViv(i); |
1 |
32 |
33 |
|
| 491 |
|
| OUTPUT: |
| 492 |
|
| RETVAL |
| 493 |
|
| |
| 494 |
|
| IV |
| 495 |
|
| body_count(self) |
| 496 |
|
| SV *self |
| 497 |
|
| CODE: |
| 498 |
2 |
▶ | RETVAL = (PT->body_count)(pt_self(aTHX_ self, "body_count")); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = (PT->body_count)(pt_self(aTHX_ self, "body_count")); |
0 |
2 |
2 |
|
| 499 |
|
| OUTPUT: |
| 500 |
|
| RETVAL |
| 501 |
|
| |
| 502 |
|
| SV * |
| 503 |
|
| body(self, i) |
| 504 |
|
| SV *self |
| 505 |
|
| IV i |
| 506 |
|
| PREINIT: |
| 507 |
|
| struct pt_body b; |
| 508 |
|
| CODE: |
| 509 |
278 |
▶ | if ((PT->body_get)(pt_self(aTHX_ self, "body"), (int32_t) i, &b) < 0) RETVAL = newSV(0); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((PT->body_get)(pt_self(aTHX_ self, "body"), (int32_t) i, &b) < 0) RETVAL = newSV(0); |
0 |
278 |
278 |
|
| 510 |
278 |
| else RETVAL = newRV_noinc((SV *) pt_body_hv(aTHX_ &b, i)); |
| 511 |
|
| OUTPUT: |
| 512 |
|
| RETVAL |
| 513 |
|
| |
| 514 |
|
| SV * |
| 515 |
|
| bodies(self) |
| 516 |
|
| SV *self |
| 517 |
|
| PREINIT: |
| 518 |
|
| struct pt_state *s; |
| 519 |
|
| struct pt_body b; |
| 520 |
|
| AV *list; |
| 521 |
|
| int32_t i, n; |
| 522 |
|
| CODE: |
| 523 |
95032 |
| s = pt_self(aTHX_ self, "bodies"); |
| 524 |
95032 |
| n = (PT->body_count)(s); |
| 525 |
95032 |
| list = newAV(); |
| 526 |
1615396 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
1520364 |
95032 |
1615396 |
|
| 527 |
1520364 |
| (PT->body_get)(s, i, &b); |
| 528 |
1520364 |
| av_push(list, newRV_noinc((SV *) pt_body_hv(aTHX_ &b, i))); |
| 529 |
|
| } |
| 530 |
95032 |
| RETVAL = newRV_noinc((SV *) list); |
| 531 |
|
| OUTPUT: |
| 532 |
|
| RETVAL |
| 533 |
|
| |
| 534 |
|
| IV |
| 535 |
|
| alive(self, seat = -1) |
| 536 |
|
| SV *self |
| 537 |
|
| IV seat |
| 538 |
|
| PREINIT: |
| 539 |
|
| struct pt_state *s; |
| 540 |
|
| struct pt_body b; |
| 541 |
|
| int32_t i, n; |
| 542 |
|
| CODE: |
| 543 |
0 |
| s = pt_self(aTHX_ self, "alive"); |
| 544 |
0 |
| n = (PT->body_count)(s); |
| 545 |
0 |
| RETVAL = 0; |
| 546 |
0 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
0 |
0 |
0 |
|
| 547 |
0 |
| (PT->body_get)(s, i, &b); |
| 548 |
0 |
▶ | if (b.alive && (seat < 0 || b.seat == seat)) RETVAL++; |
Branch: 3 branches
| Branch | True | False | Total |
| if (b.alive && (seat < 0 || b.seat == seat)) RETVAL++; |
0 |
0 |
0 |
| if (b.alive && (seat < 0 || b.seat == seat)) RETVAL++; |
0 |
0 |
0 |
| if (b.alive && (seat < 0 || b.seat == seat)) RETVAL++; |
0 |
0 |
0 |
|
| 549 |
|
| } |
| 550 |
|
| OUTPUT: |
| 551 |
|
| RETVAL |
| 552 |
|
| |
| 553 |
|
| # Starts a turn for body $active and returns the wind; undef when there is |
| 554 |
|
| # no such body (error says 'state'). A WIND OF -7 IS NOT A REFUSAL: the |
| 555 |
|
| # engine negates PT_ERR_STATE, which is 7, and the wind runs -20 to 20, so |
| 556 |
|
| # the two collided and one turn in forty-one came back undef with the body |
| 557 |
|
| # standing there (every client then aimed against a wind of its own; found |
| 558 |
|
| # by the app's identity test, 2 Oct 2026). The refusal is the body not |
| 559 |
|
| # existing, so that is what decides. |
| 560 |
|
| SV * |
| 561 |
|
| start_turn(self, active) |
| 562 |
|
| SV *self |
| 563 |
|
| IV active |
| 564 |
|
| PREINIT: |
| 565 |
|
| struct pt_state *s; |
| 566 |
|
| int32_t r; |
| 567 |
|
| CODE: |
| 568 |
210 |
| s = pt_self(aTHX_ self, "start_turn"); |
| 569 |
210 |
| r = (PT->start_turn)(s, (int32_t) active); |
| 570 |
210 |
▶ | RETVAL = (r == -PT_ERR_STATE && (active < 0 || active >= (PT->body_count)(s))) ? newSV(0) : newSViv(r); |
Branch: 3 branches
| Branch | True | False | Total |
| RETVAL = (r == -PT_ERR_STATE && (active < 0 || active >= (PT->body_count)(s))) ? newSV(0) : newSViv(r); |
10 |
200 |
210 |
| RETVAL = (r == -PT_ERR_STATE && (active < 0 || active >= (PT->body_count)(s))) ? newSV(0) : newSViv(r); |
10 |
0 |
10 |
| RETVAL = (r == -PT_ERR_STATE && (active < 0 || active >= (PT->body_count)(s))) ? newSV(0) : newSViv(r); |
2 |
8 |
10 |
|
| 571 |
|
| OUTPUT: |
| 572 |
|
| RETVAL |
| 573 |
|
| |
| 574 |
|
| # One tick: the held bits, and the shot when this is the tick it fires. |
| 575 |
|
| # Returns the phase after the tick: live, settle or done. |
| 576 |
|
| const char * |
| 577 |
|
| advance(self, bits = 0, shot = NULL) |
| 578 |
|
| SV *self |
| 579 |
|
| IV bits |
| 580 |
|
| SV *shot |
| 581 |
|
| PREINIT: |
| 582 |
|
| struct pt_shot sh; |
| 583 |
|
| int32_t phase; |
| 584 |
94661 |
▶ | int has = 0; |
Branch: 1 branch
| Branch | True | False | Total |
| int has = 0; |
94661 |
0 |
94661 |
|
| 585 |
|
| CODE: |
| 586 |
94661 |
▶ | if (shot && SvOK(shot)) { (void) pt_read_shot(aTHX_ shot, &sh); has = 1; } |
Branch: 2 branches
| Branch | True | False | Total |
| if (shot && SvOK(shot)) { (void) pt_read_shot(aTHX_ shot, &sh); has = 1; } |
94660 |
1 |
94661 |
| if (shot && SvOK(shot)) { (void) pt_read_shot(aTHX_ shot, &sh); has = 1; } |
201 |
94459 |
94660 |
|
| 587 |
94661 |
▶ | phase = (PT->advance)(pt_self(aTHX_ self, "advance"), (int32_t) bits, has ? &sh : NULL); |
Branch: 1 branch
| Branch | True | False | Total |
| phase = (PT->advance)(pt_self(aTHX_ self, "advance"), (int32_t) bits, has ? &sh : NULL); |
201 |
94460 |
94661 |
|
| 588 |
94661 |
▶ | RETVAL = phase == PT_PHASE_LIVE ? "live" : phase == PT_PHASE_SETTLE ? "settle" : phase == PT_PHASE_DONE ? "done" : "idle"; |
Branch: 3 branches
| Branch | True | False | Total |
| RETVAL = phase == PT_PHASE_LIVE ? "live" : phase == PT_PHASE_SETTLE ? "settle" : phase == PT_PHASE_DONE ? "done" : "idle"; |
26951 |
67710 |
94661 |
| RETVAL = phase == PT_PHASE_LIVE ? "live" : phase == PT_PHASE_SETTLE ? "settle" : phase == PT_PHASE_DONE ? "done" : "idle"; |
208 |
26743 |
26951 |
| RETVAL = phase == PT_PHASE_LIVE ? "live" : phase == PT_PHASE_SETTLE ? "settle" : phase == PT_PHASE_DONE ? "done" : "idle"; |
207 |
1 |
208 |
|
| 589 |
|
| OUTPUT: |
| 590 |
|
| RETVAL |
| 591 |
|
| |
| 592 |
|
| const char * |
| 593 |
|
| phase(self) |
| 594 |
|
| SV *self |
| 595 |
|
| PREINIT: |
| 596 |
|
| int32_t phase; |
| 597 |
|
| CODE: |
| 598 |
1 |
| phase = (PT->phase)(pt_self(aTHX_ self, "phase")); |
| 599 |
1 |
▶ | RETVAL = phase == PT_PHASE_LIVE ? "live" : phase == PT_PHASE_SETTLE ? "settle" : phase == PT_PHASE_DONE ? "done" : "idle"; |
Branch: 3 branches
| Branch | True | False | Total |
| RETVAL = phase == PT_PHASE_LIVE ? "live" : phase == PT_PHASE_SETTLE ? "settle" : phase == PT_PHASE_DONE ? "done" : "idle"; |
1 |
0 |
1 |
| RETVAL = phase == PT_PHASE_LIVE ? "live" : phase == PT_PHASE_SETTLE ? "settle" : phase == PT_PHASE_DONE ? "done" : "idle"; |
1 |
0 |
1 |
| RETVAL = phase == PT_PHASE_LIVE ? "live" : phase == PT_PHASE_SETTLE ? "settle" : phase == PT_PHASE_DONE ? "done" : "idle"; |
1 |
0 |
1 |
|
| 600 |
|
| OUTPUT: |
| 601 |
|
| RETVAL |
| 602 |
|
| |
| 603 |
|
| IV |
| 604 |
|
| turn_tick(self) |
| 605 |
|
| SV *self |
| 606 |
|
| CODE: |
| 607 |
600459 |
▶ | RETVAL = (PT->turn_tick)(pt_self(aTHX_ self, "turn_tick")); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = (PT->turn_tick)(pt_self(aTHX_ self, "turn_tick")); |
600456 |
3 |
600459 |
|
| 608 |
|
| OUTPUT: |
| 609 |
|
| RETVAL |
| 610 |
|
| |
| 611 |
|
| SV * |
| 612 |
|
| error(self) |
| 613 |
|
| SV *self |
| 614 |
|
| PREINIT: |
| 615 |
|
| const char *e; |
| 616 |
|
| CODE: |
| 617 |
3 |
| e = (PT->error_name)((PT->error)(pt_self(aTHX_ self, "error"))); |
| 618 |
3 |
▶ | RETVAL = e ? newSVpv(e, 0) : newSV(0); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = e ? newSVpv(e, 0) : newSV(0); |
2 |
1 |
3 |
|
| 619 |
|
| OUTPUT: |
| 620 |
|
| RETVAL |
| 621 |
|
| |
| 622 |
|
| SV * |
| 623 |
|
| outcome(self) |
| 624 |
|
| SV *self |
| 625 |
|
| PREINIT: |
| 626 |
|
| struct pt_outcome *o; |
| 627 |
|
| CODE: |
| 628 |
200 |
| o = (PT->outcome)(pt_self(aTHX_ self, "outcome")); |
| 629 |
200 |
▶ | if (!o) croak("Physics::Terrain::outcome: could not allocate an outcome"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!o) croak("Physics::Terrain::outcome: could not allocate an outcome"); |
0 |
200 |
200 |
|
| 630 |
200 |
| RETVAL = pt_outcome_sv(aTHX_ o); |
| 631 |
200 |
| (PT->outcome_free)(o); |
| 632 |
|
| OUTPUT: |
| 633 |
|
| RETVAL |
| 634 |
|
| |
| 635 |
|
| # A whole turn from a recorded input log [[tick, bits], ...] and a shot |
| 636 |
|
| # {tick, weapon, angle, power} or undef. Returns the outcome. |
| 637 |
|
| SV * |
| 638 |
|
| run_turn(self, active, inputs, shot = NULL) |
| 639 |
|
| SV *self |
| 640 |
|
| IV active |
| 641 |
|
| AV *inputs |
| 642 |
|
| SV *shot |
| 643 |
|
| PREINIT: |
| 644 |
|
| struct pt_input *list; |
| 645 |
|
| struct pt_shot sh; |
| 646 |
|
| struct pt_outcome *o; |
| 647 |
771 |
| IV shot_tick = -1; |
| 648 |
|
| I32 n, i; |
| 649 |
|
| struct pt_state *s; |
| 650 |
|
| CODE: |
| 651 |
771 |
| s = pt_self(aTHX_ self, "run_turn"); |
| 652 |
771 |
| n = av_len(inputs) + 1; |
| 653 |
771 |
▶ | Newxz(list, n ? n : 1, struct pt_input); |
Branch: 1 branch
| Branch | True | False | Total |
| Newxz(list, n ? n : 1, struct pt_input); |
220 |
551 |
771 |
|
| 654 |
1921 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
1150 |
771 |
1921 |
|
| 655 |
1150 |
| SV **rp = av_fetch(inputs, i, 0); |
| 656 |
|
| AV *row; |
| 657 |
1150 |
▶ | if (!rp || !SvROK(*rp) || SvTYPE(SvRV(*rp)) != SVt_PVAV) { Safefree(list); croak("Physics::Terrain::run_turn: input %d is not [tick, bits]", (int) i); } |
Branch: 3 branches
| Branch | True | False | Total |
| if (!rp || !SvROK(*rp) || SvTYPE(SvRV(*rp)) != SVt_PVAV) { Safefree(list); croak("Physics::Terrain::run_turn: input %d is not [tick, bits]", (int) i); } |
1150 |
0 |
1150 |
| if (!rp || !SvROK(*rp) || SvTYPE(SvRV(*rp)) != SVt_PVAV) { Safefree(list); croak("Physics::Terrain::run_turn: input %d is not [tick, bits]", (int) i); } |
1150 |
0 |
1150 |
| if (!rp || !SvROK(*rp) || SvTYPE(SvRV(*rp)) != SVt_PVAV) { Safefree(list); croak("Physics::Terrain::run_turn: input %d is not [tick, bits]", (int) i); } |
0 |
1150 |
1150 |
|
| 658 |
1150 |
| row = (AV *) SvRV(*rp); |
| 659 |
1150 |
| list[i].tick = (int32_t) pt_row_int(aTHX_ row, 0, 0); |
| 660 |
1150 |
| list[i].bits = (int32_t) pt_row_int(aTHX_ row, 1, 0); |
| 661 |
|
| } |
| 662 |
771 |
▶ | if (shot && SvOK(shot)) shot_tick = pt_read_shot(aTHX_ shot, &sh); |
Branch: 2 branches
| Branch | True | False | Total |
| if (shot && SvOK(shot)) shot_tick = pt_read_shot(aTHX_ shot, &sh); |
771 |
0 |
771 |
| if (shot && SvOK(shot)) shot_tick = pt_read_shot(aTHX_ shot, &sh); |
770 |
1 |
771 |
|
| 663 |
771 |
▶ | o = (PT->run_turn)(s, (int32_t) active, (int32_t) n, list, shot_tick >= 0 ? &sh : NULL, (int32_t) shot_tick); |
Branch: 1 branch
| Branch | True | False | Total |
| o = (PT->run_turn)(s, (int32_t) active, (int32_t) n, list, shot_tick >= 0 ? &sh : NULL, (int32_t) shot_tick); |
770 |
1 |
771 |
|
| 664 |
771 |
| Safefree(list); |
| 665 |
771 |
▶ | if (!o) croak("Physics::Terrain::run_turn: could not allocate an outcome"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!o) croak("Physics::Terrain::run_turn: could not allocate an outcome"); |
0 |
771 |
771 |
|
| 666 |
771 |
| RETVAL = pt_outcome_sv(aTHX_ o); |
| 667 |
771 |
| (PT->outcome_free)(o); |
| 668 |
|
| OUTPUT: |
| 669 |
|
| RETVAL |
| 670 |
|
| |
| 671 |
|
| # The per-tick state hash as two unsigned 32-bit halves. |
| 672 |
|
| void |
| 673 |
|
| hash(self) |
| 674 |
|
| SV *self |
| 675 |
|
| PREINIT: |
| 676 |
|
| uint32_t h[2]; |
| 677 |
|
| PPCODE: |
| 678 |
400 |
| (PT->hash)(pt_self(aTHX_ self, "hash"), h); |
| 679 |
400 |
▶ | EXTEND(SP, 2); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 2); |
0 |
400 |
400 |
|
| 680 |
400 |
| mPUSHu(h[0]); mPUSHu(h[1]); |
| 681 |
|
| |
| 682 |
|
| SV * |
| 683 |
|
| snapshot(self) |
| 684 |
|
| SV *self |
| 685 |
|
| PREINIT: |
| 686 |
|
| struct pt_snapshot *n; |
| 687 |
|
| CODE: |
| 688 |
201 |
| n = (PT->snapshot_new)(pt_self(aTHX_ self, "snapshot")); |
| 689 |
201 |
▶ | if (!n) croak("Physics::Terrain::snapshot: could not allocate a snapshot"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!n) croak("Physics::Terrain::snapshot: could not allocate a snapshot"); |
0 |
201 |
201 |
|
| 690 |
201 |
| RETVAL = pt_wrap(aTHX_ n, "Physics::Terrain::Snapshot"); |
| 691 |
|
| OUTPUT: |
| 692 |
|
| RETVAL |
| 693 |
|
| |
| 694 |
|
| IV |
| 695 |
|
| restore(self, snap) |
| 696 |
|
| SV *self |
| 697 |
|
| SV *snap |
| 698 |
|
| PREINIT: |
| 699 |
|
| int32_t r; |
| 700 |
|
| CODE: |
| 701 |
201 |
| r = (PT->snapshot_restore)(pt_self(aTHX_ self, "restore"), pt_snap(aTHX_ snap, "restore")); |
| 702 |
201 |
▶ | if (r == -PT_ERR_STATE) croak("Physics::Terrain::restore: the snapshot is of a field of another size"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (r == -PT_ERR_STATE) croak("Physics::Terrain::restore: the snapshot is of a field of another size"); |
1 |
200 |
201 |
|
| 703 |
200 |
▶ | if (r < 0) croak("Physics::Terrain::restore: could not restore"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (r < 0) croak("Physics::Terrain::restore: could not restore"); |
0 |
200 |
200 |
|
| 704 |
200 |
▶ | RETVAL = 1; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = 1; |
199 |
1 |
200 |
|
| 705 |
|
| OUTPUT: |
| 706 |
|
| RETVAL |
| 707 |
|
| |
| 708 |
|
| SV * |
| 709 |
|
| craters(self) |
| 710 |
|
| SV *self |
| 711 |
|
| PREINIT: |
| 712 |
|
| const struct pt_crater *c; |
| 713 |
|
| int32_t n, i; |
| 714 |
|
| AV *list, *row; |
| 715 |
|
| CODE: |
| 716 |
0 |
| n = (PT->craters)(pt_self(aTHX_ self, "craters"), &c); |
| 717 |
0 |
| list = newAV(); |
| 718 |
0 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
0 |
0 |
0 |
|
| 719 |
0 |
| row = newAV(); av_push(row, newSViv(c[i].x)); av_push(row, newSViv(c[i].y)); av_push(row, newSViv(c[i].r)); |
| 720 |
0 |
| av_push(list, newRV_noinc((SV *) row)); |
| 721 |
|
| } |
| 722 |
0 |
| RETVAL = newRV_noinc((SV *) list); |
| 723 |
|
| OUTPUT: |
| 724 |
|
| RETVAL |
| 725 |
|
| |
| 726 |
|
| SV * |
| 727 |
|
| graves(self) |
| 728 |
|
| SV *self |
| 729 |
|
| PREINIT: |
| 730 |
|
| const struct pt_grave *g; |
| 731 |
|
| int32_t n, i; |
| 732 |
|
| AV *list, *row; |
| 733 |
|
| CODE: |
| 734 |
0 |
| n = (PT->graves)(pt_self(aTHX_ self, "graves"), &g); |
| 735 |
0 |
| list = newAV(); |
| 736 |
0 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
0 |
0 |
0 |
|
| 737 |
0 |
| row = newAV(); av_push(row, newSViv(g[i].seat)); av_push(row, newSViv(g[i].x)); av_push(row, newSViv(g[i].y)); |
| 738 |
0 |
| av_push(list, newRV_noinc((SV *) row)); |
| 739 |
|
| } |
| 740 |
0 |
| RETVAL = newRV_noinc((SV *) list); |
| 741 |
|
| OUTPUT: |
| 742 |
|
| RETVAL |
| 743 |
|
| |
| 744 |
|
| # The launch vector (vx, vy) a weapon fires with at an angle and a power, |
| 745 |
|
| # without firing. A class method. |
| 746 |
|
| void |
| 747 |
|
| launch(class, weapon, angle, power) |
| 748 |
|
| SV *class |
| 749 |
|
| IV weapon |
| 750 |
|
| IV angle |
| 751 |
|
| IV power |
| 752 |
|
| PREINIT: |
| 753 |
|
| int32_t out[2]; |
| 754 |
|
| PPCODE: |
| 755 |
|
| PERL_UNUSED_VAR(class); |
| 756 |
11 |
▶ | if ((PT->launch)((int32_t) weapon, (int32_t) angle, (int32_t) power, out) < 0) croak("Physics::Terrain::launch: no weapon %d", (int) weapon); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((PT->launch)((int32_t) weapon, (int32_t) angle, (int32_t) power, out) < 0) croak("Physics::Terrain::launch: no weapon %d", (int) weapon); |
1 |
10 |
11 |
|
| 757 |
10 |
▶ | EXTEND(SP, 2); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 2); |
0 |
10 |
10 |
|
| 758 |
10 |
| mPUSHi(out[0]); mPUSHi(out[1]); |
| 759 |
|
| |
| 760 |
|
| # The weapon table, as a list of hashes. A class method. |
| 761 |
|
| SV * |
| 762 |
|
| weapons(class) |
| 763 |
|
| SV *class |
| 764 |
|
| PREINIT: |
| 765 |
|
| AV *list; |
| 766 |
|
| HV *hv; |
| 767 |
|
| int32_t i, n; |
| 768 |
|
| const struct pt_weapon *w; |
| 769 |
|
| static const char *const KINDS[] = { "shell", "bounce", "hitscan", "cluster", "drop", "death" }; |
| 770 |
|
| CODE: |
| 771 |
|
| PERL_UNUSED_VAR(class); |
| 772 |
1 |
| n = (PT->weapon_count)(); |
| 773 |
1 |
| list = newAV(); |
| 774 |
6 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
5 |
1 |
6 |
|
| 775 |
5 |
| w = (PT->weapon_get)(i); |
| 776 |
5 |
| hv = newHV(); |
| 777 |
5 |
| (void) hv_stores(hv, "id", newSVpv(w->id, 0)); |
| 778 |
5 |
| (void) hv_stores(hv, "name", newSVpv(w->name, 0)); |
| 779 |
5 |
| (void) hv_stores(hv, "kind", newSVpv(KINDS[w->kind], 0)); |
| 780 |
5 |
| (void) hv_stores(hv, "speedMax", newSViv(w->speed_max)); |
| 781 |
5 |
| (void) hv_stores(hv, "wind", newSViv(w->wind)); |
| 782 |
5 |
| (void) hv_stores(hv, "fuse", newSViv(w->fuse)); |
| 783 |
5 |
| (void) hv_stores(hv, "radius", newSViv(w->radius)); |
| 784 |
5 |
| (void) hv_stores(hv, "damage", newSViv(w->damage)); |
| 785 |
5 |
| (void) hv_stores(hv, "knock", newSViv(w->knock)); |
| 786 |
5 |
▶ | if (w->bounce) (void) hv_stores(hv, "bounce", newSViv(w->bounce)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (w->bounce) (void) hv_stores(hv, "bounce", newSViv(w->bounce)); |
1 |
4 |
5 |
|
| 787 |
5 |
▶ | if (w->friction) (void) hv_stores(hv, "friction", newSViv(w->friction)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (w->friction) (void) hv_stores(hv, "friction", newSViv(w->friction)); |
1 |
4 |
5 |
|
| 788 |
5 |
▶ | if (w->range) (void) hv_stores(hv, "range", newSViv(w->range)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (w->range) (void) hv_stores(hv, "range", newSViv(w->range)); |
1 |
4 |
5 |
|
| 789 |
5 |
▶ | if (w->count) { (void) hv_stores(hv, "count", newSViv(w->count)); (void) hv_stores(hv, "spread", newSViv(w->spread)); (void) hv_stores(hv, "pop", newSViv(w->pop)); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (w->count) { (void) hv_stores(hv, "count", newSViv(w->count)); (void) hv_stores(hv, "spread", newSViv(w->spread)); (void) hv_stores(hv, "pop", newSViv(w->pop)); } |
1 |
4 |
5 |
|
| 790 |
5 |
| av_push(list, newRV_noinc((SV *) hv)); |
| 791 |
|
| } |
| 792 |
1 |
| RETVAL = newRV_noinc((SV *) list); |
| 793 |
|
| OUTPUT: |
| 794 |
|
| RETVAL |
| 795 |
|
| |
| 796 |
|
| IV |
| 797 |
|
| abi_version(...) |
| 798 |
|
| CODE: |
| 799 |
|
| PERL_UNUSED_VAR(items); |
| 800 |
1 |
▶ | RETVAL = PT_ABI_VERSION; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = PT_ABI_VERSION; |
0 |
1 |
1 |
|
| 801 |
|
| OUTPUT: |
| 802 |
|
| RETVAL |
| 803 |
|
| |
| 804 |
|
| IV |
| 805 |
|
| LEFT(...) |
| 806 |
|
| ALIAS: |
| 807 |
|
| RIGHT = 1 |
| 808 |
|
| JUMP = 2 |
| 809 |
|
| STANDING = 3 |
| 810 |
|
| WALKING = 4 |
| 811 |
|
| FALLING = 5 |
| 812 |
|
| FLYING = 6 |
| 813 |
|
| CODE: |
| 814 |
|
| PERL_UNUSED_VAR(items); |
| 815 |
272 |
| switch (ix) { |
| 816 |
2 |
| case 0: RETVAL = PT_LEFT; break; |
| 817 |
3 |
| case 1: RETVAL = PT_RIGHT; break; |
| 818 |
2 |
| case 2: RETVAL = PT_JUMP; break; |
| 819 |
264 |
| case 3: RETVAL = PT_STANDING; break; |
| 820 |
0 |
| case 4: RETVAL = PT_WALKING; break; |
| 821 |
0 |
| case 5: RETVAL = PT_FALLING; break; |
| 822 |
1 |
| default: RETVAL = PT_FLYING; break; |
| 823 |
|
| } |
| 824 |
|
| OUTPUT: |
| 825 |
|
| RETVAL |
| 826 |
|
| |
| 827 |
|
| UV |
| 828 |
|
| _abi_ptr(...) |
| 829 |
|
| CODE: |
| 830 |
|
| PERL_UNUSED_VAR(items); |
| 831 |
1 |
▶ | RETVAL = PTR2UV(pt_abi_table()); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = PTR2UV(pt_abi_table()); |
0 |
1 |
1 |
|
| 832 |
|
| OUTPUT: |
| 833 |
|
| RETVAL |
| 834 |
|
| |
| 835 |
|
| MODULE = Physics::Terrain PACKAGE = Physics::Terrain::Snapshot |
| 836 |
|
| |
| 837 |
|
| void |
| 838 |
|
| DESTROY(self) |
| 839 |
|
| SV *self |
| 840 |
|
| PREINIT: |
| 841 |
|
| struct pt_snapshot *n; |
| 842 |
|
| CODE: |
| 843 |
201 |
| n = pt_snap(aTHX_ self, "Snapshot::DESTROY"); |
| 844 |
201 |
▶ | if (n) { (PT->snapshot_free)(n); sv_setuv(SvRV(self), 0); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (n) { (PT->snapshot_free)(n); sv_setuv(SvRV(self), 0); } |
201 |
0 |
201 |
|