code wiki / (root) / nx_character.nx

nx_character.nx source

↩ module page · 64 lines · 3258 B

1// nx_character.nx -- A CHARACTER IS DATA (the keystone under beat-HS2 rung 1 [mind-wire] AND rung 3 [creator]: 2// the Illusion "character generator" concept on our moddable-data law). A character = a compact record of the 3// drivable parameters that make one body/person distinct: two soft-region PROFILES (size/softness/gravity), 4// body proportions, skin color, a breathe rate, a NAME, and -- the hook no incumbent has -- a PERSONA ID that 5// binds this body to a real mind (nx_persona/nx_companion_memory). Serializes to an NXCH1 pack: a shareable 6// character that flows through the CID mod economy exactly like block/morph/anatomy/scene packs. ALL INTEGER. 7// license_tier: ORIGINAL 8import "nx_syscalls.nx" 9const CHR_MAGIC_2147483648: i64 = 2147483648 10const CHR_MAGIC_4294967296: i64 = 4294967296 11 12// character record: 16 i64 slots 13// [0]=name_hash [1]=L_size [2]=L_soft [3]=L_grav [4]=R_size [5]=R_soft [6]=R_grav 14// [7]=arm_len [8]=breathe_rate [9]=persona_id [10]=skin_r [11]=skin_g [12]=skin_b [13..15]=spare 15const CHR_SLOTS: i64 = 16 16func chr_bytes() -> i64 { return CHR_SLOTS * 8 } 17 18func chr_set(rec: *i64, name: i64, lsz: i64, lsoft: i64, lgrav: i64, rsz: i64, rsoft: i64, rgrav: i64, arm: i64, breathe: i64, persona: i64, sr: i64, sg: i64, sb: i64) -> i64 { 19 rec[0] = name 20 rec[1] = lsz; rec[2] = lsoft; rec[3] = lgrav 21 rec[4] = rsz; rec[5] = rsoft; rec[6] = rgrav 22 rec[7] = arm; rec[8] = breathe; rec[9] = persona 23 rec[10] = sr; rec[11] = sg; rec[12] = sb 24 rec[13] = 0; rec[14] = 0; rec[15] = 0 25 return 0 26} 27 28// three built-in preset characters (the "random generator" seed set; distinct bodies) 29func chr_preset(rec: *i64, n: i64) -> i64 { 30 if n == 0 { return chr_set(rec, 111, 320, 26, 40, 320, 16, 40, 500, 60, 1001, 235, 190, 150) } // "Ada" 31 if n == 1 { return chr_set(rec, 222, 420, 30, 52, 420, 20, 52, 460, 44, 1002, 210, 160, 140) } // "Bea" (fuller, softer, slower breathe) 32 if n == 2 { return chr_set(rec, 333, 240, 20, 30, 240, 14, 30, 560, 80, 1003, 245, 205, 175) } // "Cleo" (smaller, firmer, quick) 33 return chr_preset(rec, 0) 34} 35 36// ---- NXCH1 pack: "NXCH" + 16 i32 LE ---- 37func chr_w32(buf: *u8, off: i64, v: i64) -> i64 { 38 buf[off] = (v & 255) as u8 39 buf[off + 1] = ((v >> 8) & 255) as u8 40 buf[off + 2] = ((v >> 16) & 255) as u8 41 buf[off + 3] = ((v >> 24) & 255) as u8 42 return 0 43} 44func chr_r32(buf: *u8, off: i64) -> i64 { 45 var v: i64 = (buf[off] as i64) | ((buf[off + 1] as i64) << 8) | ((buf[off + 2] as i64) << 16) | ((buf[off + 3] as i64) << 24) 46 if v >= CHR_MAGIC_2147483648 { v = v - CHR_MAGIC_4294967296 } 47 return v 48} 49func chr_save(rec: *i64, buf: *u8) -> i64 { 50 buf[0] = 78 as u8; buf[1] = 88 as u8; buf[2] = 67 as u8; buf[3] = 72 as u8 // "NXCH" 51 var i: i64 = 0 52 while i < CHR_SLOTS { chr_w32(buf, 4 + i * 4, rec[i]); i = i + 1 } 53 return 4 + CHR_SLOTS * 4 54} 55func chr_load(rec: *i64, buf: *u8, len: i64) -> i64 { 56 if len < 4 + CHR_SLOTS * 4 { return 0 - 1 } 57 if buf[0] as i64 != 78 { return 0 - 1 } 58 if buf[1] as i64 != 88 { return 0 - 1 } 59 if buf[2] as i64 != 67 { return 0 - 1 } 60 if buf[3] as i64 != 72 { return 0 - 1 } 61 var i: i64 = 0 62 while i < CHR_SLOTS { rec[i] = chr_r32(buf, 4 + i * 4); i = i + 1 } 63 return 0 64}