Restore three lost C behaviors: schtick message, forced redraw, greeting (closes #13)
Three behaviors from 5.4.4 that the port dropped silently. Each is a few
lines; grouped because they are all "restore something C did".
1. sticks.c 237: the "otherwise" arm closing do_zap's switch printed
"what a bizarre schtick!", and doZap had turned it into doing nothing.
The arm is under #ifdef MASTER, not under a runtime wizard test, so in
the MASTER build this port is it printed for every player and must not
be gated on g.Wizard. WS_NOP is a case of that switch in its own right
("when WS_NOP: break;"), so "no handler ran" cannot be the trigger:
the wand of nothing does nothing quietly. C's switch covers all 14 WS_
values, so its otherwise is reachable only for an o_which outside the
table, which is what Object.hasValidWhich already screens for. All
three arms fall through to obj.Charges--, as C's do.
2. command.c 288-291: CTRL('R') is "after = FALSE; clearok(curscr, TRUE);
wrefresh(curscr);" — a forced full repaint. The port called
g.refresh(), the ordinary diffing blit, which cannot fix the only
situation the command exists for: a screen corrupted by another
program's output leaves the game's record of it still correct, so the
diff sends nothing. New Terminal.Repaint (tcell Screen.Sync, which
discards tcell's record of the terminal rather than diffing against
it), Screen.Repaint and g.repaint(), implemented in term.Tcell and in
both headless test terminals. Named for the curses operation: the
interface is the game's abstraction, not tcell's. It repaints what was
last rendered — C repainted curscr, not stdscr — so it takes no
window.
3. main.c 107-113: the startup greeting existed nowhere in the tree. New
game.Greeting, printed on stdout by cmd/rogue/main.go before
term.New(), the port's initscr(). Only the wizard wording is #ifdef
MASTER; the other is unconditional. The %d is dnum, which main.c has
just assigned to seed, so it is Params.Seed. Neither wording ends in a
newline. Two placement details the tests pin: the printf sits after
parse_opts, so a ROGUEOPTS name= is what the player is greeted by; and
it sits after the -s/-d handling and after restore(), which never
returns, so a resumed game does not announce that a dungeon is being
dug (digsNewDungeon).
Greeting parses ROGUEOPTS into a throwaway game built the way New builds
the real one, tables and home directory included: ParseOpts handles every
option, not just the one the greeting reads, and inven= is matched
against inv_t_name[], which lives on the game.
All three message strings verified byte-for-byte against origin/c-master
sticks.c and main.c. No RNG call is added on any path and nothing under
game/testdata/ changed; TestSeedCompatItemTables is green against the
untouched golden.
Mutation-proved, each behavior removed in turn with only its own test
failing: dropping the message arm fails
TestZapUnhandledWandSaysBizarreSchtick; extending the message to WS_NOP
fails TestZapWandOfNothingIsSilent; putting g.refresh() back fails
TestRedrawCommandForcesFullRepaint; swapping the two wordings, and
ignoring the ROGUEOPTS name, both fail TestGreeting; greeting on the
restore path fails TestDigsNewDungeon.
ARCHITECTURE.md 5.3 gains Repaint and why a blit cannot substitute for
it; nothing here is deliberately dropped, so section 9 is unchanged.
TODO.md gets a Completed Steps entry; Next Step deliberately not rotated,
this being out-of-band issue work.
This commit is contained in:
@@ -1488,6 +1488,8 @@ type Terminal interface {
|
||||
ReadChar() (byte, bool) // event loop → C char codes (arrows→hjkl, ^C→quit);
|
||||
// ok is false when Interrupt woke the read
|
||||
Interrupt() // wake a blocked ReadChar (signal goroutine only)
|
||||
Repaint() // forced full redraw for CTRL-R
|
||||
// (curses clearok(curscr,TRUE)+wrefresh(curscr))
|
||||
Fini() // restore the device (curses endwin) on exit
|
||||
}
|
||||
|
||||
@@ -1507,16 +1509,25 @@ func (w *Window) Printwf(format string, a ...any); func (w *Window) Inch(y, x in
|
||||
func (w *Window) Clear(); func (w *Window) Clrtoeol(); func (w *Window) Standout(on bool)
|
||||
func (s *Screen) Refresh() // blit stdscr to the device
|
||||
func (s *Screen) RefreshWin(w *Window) // blit any window
|
||||
func (s *Screen) Repaint() // force a full redraw of the device
|
||||
func (s *Screen) Fini() // tear the device down
|
||||
```
|
||||
|
||||
Ported drawing code keeps its structure: `mvaddch(y, x, ch)` →
|
||||
`g.scr.Std.MvAddCh(y, x, ch)`. Curses `mvinch` reads come from the Window
|
||||
buffer, preserving the "screen is a data structure" idiom without touching the
|
||||
real terminal. `md_readchar`'s escape decoding is deleted; tcell's `EventKey`
|
||||
provides decoded keys and we translate to the byte codes `command()` already
|
||||
handles (KeyUp → 'k', etc.). Resize is handled by tcell, which registers only
|
||||
SIGWINCH — SIGTSTP is not among the signals it takes, and is dropped (§9).
|
||||
real terminal. `Repaint` is the one drawing call that is not a blit: it is the
|
||||
`CTRL('R')` command's `clearok(curscr, TRUE)` plus `wrefresh(curscr)`,
|
||||
implemented as tcell's `Screen.Sync`, and it exists because `Render` cannot do
|
||||
its job. Both diff a new frame against the device's record of the old one and
|
||||
send nothing where they agree, which is the wrong answer precisely when the
|
||||
screen has been corrupted by something else's output — the only reason a player
|
||||
types `CTRL('R')`. Like C's, it repaints what was last drawn rather than
|
||||
re-blitting `stdscr`, so it takes no window. `md_readchar`'s escape decoding is
|
||||
deleted; tcell's `EventKey` provides decoded keys and we translate to the byte
|
||||
codes `command()` already handles (KeyUp → 'k', etc.). Resize is handled by
|
||||
tcell, which registers only SIGWINCH — SIGTSTP is not among the signals it
|
||||
takes, and is dropped (§9).
|
||||
|
||||
Signals are handled in `cmd/rogue/main.go`: one `os/signal` channel read by one
|
||||
goroutine that reads exactly one signal, so a second signal can never call
|
||||
|
||||
Reference in New Issue
Block a user