Cauldron2D.Sectors.View (Cauldron2D v0.2.2)

Copy Markdown View Source

Draws a sector map from a point inside it: walls, floors, ceilings and sky, and the things standing in it, nearest in front, into a Cauldron2D.Sectors.Frame.

%{frame: frame, seen: lines} =
  Cauldron2D.Sectors.View.render(frame, pictures, map, %{
    x: 1056.0, y: -3616.0, z: 41.0, angle: :math.pi() / 2,
    sectors: sectors, sides: sides, things: things
  }, sky: %{picture: sky, flat: sky_flat, columns: 1024 / (2 * :math.pi()), mid: 100.0, step: 1.0})

map is a Cauldron2D.Sectors.Map with its BSP. The view gives the eye's x, y and height z, its heading angle in radians (0 along +x), and the sectors and sides as they are now — a door's ceiling moves and a switch's picture changes, so the game passes its own copies rather than the map's. pitch moves the horizon up (> 0) or down by that many pixels. things are what stand in the sectors:

%{x:, y:, z:, sector:, picture:, offset: {left, top}, flip: false, bright: false, shimmer: false}

where z is the height of the thing's feet, offset where the picture's origin is — left texels from its left edge, top texels above its bottom row at the feet — and bright draws it unlit. A shimmer thing is drawn as a blur of what is behind it.

The result's seen is the set of line indexes some of which was drawn, for an automap.

Options

  • :sky — %{picture:, flat:, columns:, mid:, step:}: a ceiling whose picture is flat shows picture picture wrapped around the view, columns picture columns per radian, its row mid at the horizon and step rows a pixel; default none
  • :stretch — how many times taller than wide a world unit is drawn. Default 1.0
  • :contrast — light added to walls running along y and taken from walls running along x, so corners read. Default 0
  • :extra_light — light added everywhere. Default 0
  • :fixed — a light table to draw everything through instead of lighting it. Default nil
  • :light — options for Cauldron2D.Sectors.Light
  • :fov — the horizontal field of view in radians. Default π/2

Summary

Functions

Draw map as seen by eye onto frame. See the moduledoc.

Types

eye()

@type eye() :: %{
  :x => number(),
  :y => number(),
  :z => number(),
  :angle => number(),
  :sectors => tuple(),
  :sides => tuple(),
  optional(:things) => [thing()],
  optional(:pitch) => number()
}

thing()

@type thing() :: %{
  :x => number(),
  :y => number(),
  :z => number(),
  :sector => non_neg_integer(),
  :picture => non_neg_integer(),
  optional(:offset) => {number(), number()},
  optional(:flip) => boolean(),
  optional(:bright) => boolean(),
  optional(:shimmer) => boolean()
}

Functions

render(frame, pictures, map, eye, opts \\ [])

Draw map as seen by eye onto frame. See the moduledoc.