GizStackGizStack
View .mdOpen in ChatGPTOpen in Claude

gizgame/talk

a player talks aloud with a game's minds (gizgame/mind) and they answer aloud, their faces moving. The minds are a service of the game's own server: an online world's room (gizgame/online) hosts them beside its world, and a game of its own hosts them in a room of talk alone (room), one cast for each player who joins. Both send what players recorded to the minds and their voices back on the same messages (gizgame/net VOICE), and a page plays a voice as it plays a line of its soundtrack (Game.speak). Push to talk (Press) is the one press of both.

gizlang
import * as Talk from "gizgame/talk";

Types

Press

gizlang
class Press { handsFree: bool; listening: bool = false; private at: f64 = -1; constructor(handsFree: bool) { this.handsFree = handsFree; } step(g: Game, quiet: bool, audience: bool): bytes throws string { const held = !quiet && g.held("talk"); const time = g.time(); if (held && this.at <0) { this.at = time; } const manual = held && time-this.at> = TAP; if (!held && this.at> = 0) { if (time-this.at <TAP) { this.handsFree = !this.handsFree; } this.at = -1; } const free = !manual && this.handsFree && !quiet && audience; g.listen(manual || free, free); this.listening = (manual || free) && g.voiced(); return g.recording(); } }

Push to talk: the action "talk" held records while it is held; a tap turns HANDS-FREE on or off, where the microphone listens by itself while the caller says someone may hear. LISTENING: a voice is being recorded now.

  • handsFree: bool
  • listening: bool
  • at: f64

Near

gizlang
type Near = { seat: i64; home: i64; at: Point3; yaw: f64; kind: i64; }

Where a seat of a talk stands: its SEAT, the player's seat whose cast it is of (HOME: its own for a player), AT and YAW in that player's game, and its KIND (coded: a record holds no text): a player's is the kind it plays now (its hero), a mind's its persona's.

  • seat: i64
  • home: i64
  • at: gizlang_geometry.Point3
  • yaw: f64
  • kind: i64

Talker

gizlang
class Talker { press = new Press(false); private session: Session<Near, Near>; private since: f64 = -1; private again: string; private told: string = ""; constructor(game: Game, hz: f64 = 10, again: string = "again") throws string { this.session = new Session<Near, Near>(hz, rules()); this.again = again; game.system("talk", { reads: [Actor.name, Transform3D.name], effects: true}, (g): void throws string => this.tick(g), PLAYING); } carry(input: bytes): bytes { return this.session.carry(input); } local(seats: Seats): void throws string { this.session.local(seats); } listening(): bool { return this.press.listening; } thinking(): bool { return this.since> = 0; } private tick(g: Game): void throws string { const hero = heroOf(g); if (hero === undefined) { return; } const kind = g.design.kinds[g.read(hero!, Actor).kind].name; const pose = g.read(hero!, Transform3D); let client = this.session.client; if (this.told !== g.language()) { this.told = g.language(); client.say(`/speak ${this.told }`); } const said = this.press.step(g, false, false); if (said.length> 0) { client.talk(said); this.since = g.time(); } client.input({ seat: -1, home: -1, at: pose.position, yaw: pose.yaw, kind: coded(kind) }); this.session.tick(); for (const v of client.voices) { const by = client.others().find(o => o.seat === v.seat); g.speak(v.data, by === undefined ? hero: nearest(g, by!.kind, pose.position) ?? hero); this.since = -1; } client.voices = []; if (this.since> = 0 && g.time()-this.since> DEADLINE) { this.since = -1; g.utter([`${this.again }-${ kind }`], hero); } } }

The page's side of a talk in GAME, a game of its own: the action "talk" held records the player, and each voice of a mind is said by the nearest actor of its kind to the hero. A turn that brings no voice in DEADLINE seconds ends in the hero's own line AGAIN (Soundtrack.lines, by its kind: AGAIN-KIND). LISTENING and THINKING say what it does.

  • press: Ref<M215.Press>
  • session: Ref<M204.Session<M215.Near, M215.Near>>
  • since: f64
  • again: string
  • told: string

Functions

constructor

gizlang
constructor(handsFree: bool)

A press that starts hands-free or not (HANDSFREE).

Effects: fail, read, write, alloc.

think

gizlang
function think<P, I>(thinkers: Thinkers, server: Server<P, I>, now: f64, seen: Vec<Sensed>, heard: Vec<Spoken>, listened: Vec<Recording>): Vec<Speech>

One tick of THINKERS, the minds of SERVER, at NOW seconds: what they SEE, the lines HEARD and the recordings LISTENED; what they say now said on the server and their voices queued on it. The voices, for the caller's own use.

coded

gizlang
function coded(name: string): i64

Kind NAME as a seat's record holds it (0: none).

Effects: fail.

rules

gizlang
function rules(): Rules<Near, Near>

How a talk's seats go on the wire: a seat stands where its last input says (an input of no kind keeps it).

Effects: fail, alloc.

room

gizlang
function room(minds: Minds, hz: f64 = 10): Seats throws string

The room of a game of its own whose players talk with MINDS (TURNS turns at once): each player who joins has its own cast of them, gone when it leaves. A line names the one it is for; one that names none is for the kind the player plays.

Effects: fail, read, write, console, io, alloc.

constructor

gizlang
constructor(game: Game, hz: f64 = 10, again: string = "again") throws string

The talk of GAME, sent HZ times a second; AGAIN names the hero's line for a turn with no answer.

Effects: fail, read, write, console, io, alloc.

Methods

Press.step

gizlang
step(g: Game, quiet: bool, audience: bool): bytes throws string

This tick's press in G (none while QUIET; hands-free only while AUDIENCE): what it ended recording, b"" none.

Effects: fail, read, write, console, io, alloc.

Talker.carry

gizlang
carry(input: bytes): bytes

The host's call (Program.net, Play carried): the talk goes to the game's server.

Effects: fail, read, write, console, io, alloc.

Talker.local

gizlang
local(seats: Seats): void throws string

The seats of a room in this program (a window's play, Site local).

Effects: fail, read, write, console, io, alloc.

Talker.listening

gizlang
listening(): bool

Whether the player is heard now.

Effects: fail, read.

Talker.thinking

gizlang
thinking(): bool

Whether a turn waits for its answer.

Effects: fail, read.