gotnull

Part 8 of 13 in Ghostveil

Letting the pillar land first

In Ghostveil's fire rooms the pit lit up and the door opened as soon as a pillar was pushed towards it. Now the room waits until the pillar has dropped, bounced and settled.

Ghostveil is a puzzle game set in a machine buried under a castle, where every room is a lock and the only thing you do inside one is walk. A few days earlier I gave the pillars a proper fall: push one into a pit and it drops, hits the bottom, bounces twice and sinks flush with the floor in just under 0.9 seconds (Dropping a stone into a pit). In the fire rooms a pit with a pillar in it becomes rune floor, so the blue fire runs through it and on to whatever it opens (The fire stops killing).

Those two disagreed about time. The fire lit the pit blue the moment the push began, while the pillar was still sliding towards the edge, and the door at the far end of the channel swung open before anything had dropped. Then, 0.36 seconds into the push, with the pillar in the air on its first bounce, the floor faded in the filled slab underneath it. Everything the push caused was on screen before the pillar had reached the pit.

Here it is now, in a small room I put together to show it: a channel from the brazier, cut by a pit, runs on to a spike floor with the door just above it.

The pit stays dark until the pillar is flush and its slab is in, and only then does the fire run through it to sink the spikes and open the door. Her next step, pressed straight after the push, waits until the door has given.

Two clocks

The rules finish a move at once. The push that sinks a pillar returns a new state with the pit already among its filled cells, and everything that reads the state (the fire, the doors, the spike floors, the floor's own drawing) used to react to it in that same frame. The fall belongs to the pillar's view, which plays it out over the next second while the rules have already moved on.

So the room now draws from a state of its own. While a pillar is dropping, the game keeps it, and the pits it fills, in a map:

  /// Pillars still dropping into their pits, and the pits: until each has
  /// settled the room is seen as before, the pit open and unlit.
  final Map<BlockView, Set<Pos>> _falling = {};
  Set<Pos> get _fallingCells => {for (final c in _falling.values) ...c};

What the room shows is the rules' state with those pits taken back out:

F^=F∖P\hat{F} = F \setminus P

Here FF is the set of filled pits in the state the rules returned, PP is the set of pits whose pillars are still dropping, and F^\hat{F} is the set of filled pits the room shows. The function that lights the channels and sets every door and spike floor works the fire out from that:

    var s = _shownPower ?? _session!.state;
    // A pit a pillar is still dropping into is not filled yet as seen
    if (_falling.isNotEmpty) {
      s = s.copyWith(filled: s.filled.difference(_fallingCells));
    }

With the pit empty the channel past it stays dark, so the door stays shut and the spikes stay up. When the fall's clock passes its end, the pillar's view calls back and the pit goes in:

  void _stoneSettled(BlockView b) {
    if (_falling.remove(b) == null) return;
    _backdrop!.setFilled(_session!.state.filled.difference(_fallingCells));
    b.backdropFilled = true;
    _refreshPower(animate: true);
  }

The difference keeps a second pillar's pit open if it was pushed in while the first was still settling. Before this, the filled slab went in whenever her move's busy time ran out, 0.16 seconds after the push's own 0.2, which is how it came to appear between the landing and the first bounce.

Holding her back

Hiding the fire has a cost. If she moves on as soon as her step is done, she can walk at a door the rules already count as open while the room still shows it shut, or onto spikes the rules have sunk that are still drawn standing. So after each move the game asks whether a falling pillar is hiding anything she could walk into:

wait if open(s,g)≠open(s^,g) for some door g,or up(s,f)≠up(s^,f) for some spike floor f\begin{gathered} \text{wait if } \text{open}(s, g) \neq \text{open}(\hat{s}, g) \text{ for some door } g, \\ \text{or } \text{up}(s, f) \neq \text{up}(\hat{s}, f) \text{ for some spike floor } f \end{gathered}

where ss is the state the rules returned, s^\hat{s} is that state with the falling pits left unfilled, open\text{open} says whether a door stands open and up\text{up} says whether a spike floor's spikes are standing.

    if (_falling.isNotEmpty) {
      final rules = _session!.rules;
      final now = r.state;
      final seen = now.copyWith(filled: now.filled.difference(_fallingCells));
      if (level.gates.any((g) => rules.isGateOpen(now, g) != rules.isGateOpen(seen, g)) ||
          _spikeFloors.keys.any((f) => rules.spikesUp(now, f) != rules.spikesUp(seen, f))) {
        busy = max(busy, stepDuration + SlabFall.doneAt + 0.05);
      }
    }

The hold covers the push's slide, the whole fall and a twentieth of a second more:

thold=d+tdone+0.05=0.2+0.8966+0.05=1.1466 st_{\text{hold}} = d + t_{\text{done}} + 0.05 = 0.2 + 0.8966 + 0.05 = 1.1466 \text{ s}

Here dd is the 0.2 seconds a step or a push takes and tdonet_{\text{done}} is when the fall is over: the last bounce lands 0.2766 seconds into the fall, the pillar rests for 0.2, sinks flush over 0.12 and its slab fades in over 0.3. Measured from the press, the pit lights at 1.0966 seconds and her next step can start at 1.1466.

Timeline from 0 to 1.3 seconds after a push. The pillar slides until 0.2, falls and bounces with impacts at 0.32, 0.428 and 0.4766, rests, sinks flush and its slab fades in until 1.0966. Before the change the pit lit, the door opened and the spikes sank at 0, and the pit slab was drawn and her next move allowed at 0.36. After it, the slab, the lit pit, the door and the spikes all come at 1.0966 and her next move at 1.1466

A press made during the hold is kept, since every press is remembered until the next free frame, so a player who pushes and presses straight on sees her step the moment the door has given. If the fire through the pit opens nothing, nothing waits: she walks on after her 0.2-second step while the pillar finishes settling behind her, and the pit lights when it is in.

Undo and reset clear the map along with everything else, and _stoneSettled ignores a pillar that is no longer in it, so a pillar rewound in the middle of its fall cannot fill a pit afterwards.

The tiles, the pillar and Fantasma are from SnowHex's Dungeon Gathering; the rooms, the fall and the rules are Ghostveil's.