nx_multi_bundle.nx source
↩ module page · 76 lines · 3041 B
1// nx_multi_bundle.nx -- N-character measurement holder built on N v7_bundles.
2//
3// Per the multi-character cardinal: existing 28 detectors run per-character
4// unchanged. This primitive just stores N copies of nx_v7_bundle in a flat
5// array with index accessors. No detector rewrite needed — caller iterates
6// over characters and runs the same detector on each character's bundle.
7//
8// Layout: flat-array of (NX_V7_BUNDLE_FIELDS * N) i64 + header (count).
9// header: bundles[0] = character_count
10// then character i's bundle starts at offset HEADER + i * NX_V7_BUNDLE_FIELDS.
11
12// nx_safety_envelope:
13// intended_use: AUTO_APPLIED -- primitive-specific tuning queued
14// sil_target: SIL1
15// evidence: [bulk_applied_2026-05-16, see-file-comment-for-detail]
16// verdict: NOT_YET_EVALUATED
17
18import "nx_syscalls.nx"
19import "nx_v7_bundle.nx"
20
21const NX_MULTI_MAX_CHARS: i64 = 6 // D&D-party scale
22const NX_MULTI_HEADER: i64 = 1 // 1 slot for character_count
23
24// Allocate + zero-init a multi-bundle for up to max_chars characters.
25func nx_multi_bundle_alloc(max_chars: i64) -> *i64 {
26 if max_chars > NX_MULTI_MAX_CHARS { return 0 as *i64 }
27 if max_chars <= 0 { return 0 as *i64 }
28 let total_slots: i64 = NX_MULTI_HEADER + NX_V7_BUNDLE_FIELDS * max_chars
29 let raw: *i64 = (sys_mmap(total_slots * 8 + 16)) as *i64
30 var i: i64 = 0
31 while i < total_slots { raw[i] = 0; i = i + 1 }
32 return raw
33}
34
35// Set N occupied characters (header).
36func nx_multi_bundle_set_count(multi: *i64, n: i64) -> i64 {
37 if n < 0 { return 1 }
38 if n > NX_MULTI_MAX_CHARS { return 2 }
39 multi[0] = n
40 return 0
41}
42
43func nx_multi_bundle_count(multi: *i64) -> i64 {
44 return multi[0]
45}
46
47// Return pointer to character i's nx_v7_bundle. Caller treats it as
48// a normal v7_bundle and passes to existing detectors.
49func nx_multi_bundle_char(multi: *i64, i: i64) -> *i64 {
50 if i < 0 { return 0 as *i64 }
51 if i >= NX_MULTI_MAX_CHARS { return 0 as *i64 }
52 let offset: i64 = NX_MULTI_HEADER + i * NX_V7_BUNDLE_FIELDS
53 return (multi as i64 + offset * 8) as *i64
54}
55
56// Convenience setters that delegate to single-bundle helpers.
57func nx_multi_bundle_set_face(multi: *i64, char_i: i64,
58 x0: i64, y0: i64, x1: i64, y1: i64) -> i64 {
59 let b: *i64 = nx_multi_bundle_char(multi, char_i)
60 if b == (0 as *i64) { return 1 }
61 return nx_v7_bundle_set_face(b, x0, y0, x1, y1)
62}
63
64func nx_multi_bundle_set_torso(multi: *i64, char_i: i64,
65 x0: i64, y0: i64, x1: i64, y1: i64) -> i64 {
66 let b: *i64 = nx_multi_bundle_char(multi, char_i)
67 if b == (0 as *i64) { return 1 }
68 return nx_v7_bundle_set_torso(b, x0, y0, x1, y1)
69}
70
71func nx_multi_bundle_set_eye(multi: *i64, char_i: i64,
72 eye_width_px: i64, iris_radius_px: i64) -> i64 {
73 let b: *i64 = nx_multi_bundle_char(multi, char_i)
74 if b == (0 as *i64) { return 1 }
75 return nx_v7_bundle_set_eye(b, eye_width_px, iris_radius_px)
76}