Skip to content

PolyWall

Syyrion edited this page Feb 22, 2023 · 20 revisions

A description of every function and parameter of the PolyWall class and all of its extension classes.

The Cascade Class

The Cascade class is the most primitive extension class and only manages a single value of a specific type. (Common types are Numeric, Function, and Boolean.) All parameters such as thickness, position, etc. have been given their own class instances which allows them to inherit values from other instances. Each of these classes has five functions.

  • Cascade:set(val)
    Sets the value of class to <val>. Setting <val> to nil or an invalid type will cause the class value to be cleared.

  • Cascade:get()
    Gets the class value. If the class has no value, the function will return the superclass value.

  • Cascade:rawget()
    Gets the raw class value. Ignores inheritance.

  • Cascade:define(fn)
    Defines a class's value to be a function. This function will be called every time the value needs to be assessed. The function is allowed to take arguments which can be set when calling Cascade:get(). Defining with a function that returns more than one value or a value that is of the wrong type is undefined behavior.

  • Cascade:freeze()
    Sets the value of the class to be it's closest inherited value. This function is equivalent to running:

    Cascade:set(nil)
    Cascade:set(Cascade:get())

The Channel Class

The Channel class is a special cascading class designed to handle colors.

Functions

  • Channel:setcolor(r, g, b)
    Sets the red, green, and blue channels. The alpha channel is untouched.

  • Channel:sethsv(h, s, v)
    Sets the red, green, and blue channels using the HSV color space. The alpha channel is untouched.

  • Channel:setalpha(a)
    Sets the alpha channel.

  • Channel:set(r, g, b, a)
    Sets the red, green, blue, and alpha channels.

  • Channel:get()
    Returns the red, green, blue, and alpha channels in that order.

  • Channel:rawget()
    Same as above but ignores inheritance.

  • Channel:define(fn)
    Defines the color to a function. The function is allowed to take arguments which can be set when calling Cascade:get(). The function must return 4 numbers for red, green, blue, and alpha. Returning anything else is undefined behavior.

  • Channel:freeze()
    Sets the channel to its closest inherited values.


The Vertex Class

The Vertex class is mostly just a wrapper class that packages three transformation functions and a color channel class together.

Parameters

  • Vertex.ch
  • Vertex.pol
    • The polar transformation parameter.
    • This is a cascading function class.
    • Its default value is the function:
      function (r, a) return r, a end
  • Vertex.cart
    • The cartesian transformation parameter.
    • This is a cascading function class.
    • Its default value is the function:
      function (x, y) return x, y end
  • Vertex.col
    • The color transformation parameter.
    • This is a cascading function class.
    • Its default value is the function:
      function (r, g, b, a) return r, g, b, a end

Functions

  • Vertex:result()
    Returns the r, g, b, and a channels of the channel parameter with the color transformation applied.

For more on transformation functions, visit Transformations.


The Quad Vertex Class

Parameters

These four verticies are Vertex classes.

  • QuadVertex[0]
  • QuadVertex[1]
  • QuadVertex[2]
  • QuadVertex[3]

Functions

Color Channel Management

  • QuadVertex:chsetcolor(r, g, b)
    Sets the red, green, and blue channels of all 4 verticies. The alpha channel is untouched.

  • QuadVertex:chsetalpha(a)
    Sets the alpha channel of all 4 verticies.

  • QuadVertex:chsethsv(h, s, v)
    Sets the red, green, and blue channels of all 4 verticies using the HSV color space. The alpha channel is untouched.

  • QuadVertex:chset(r, g, b, a)
    Sets the channels of all 4 verticies.

  • QuadVertex:chget()
    Returns 16 values: the red, green, blue, and alpha channel values of vertex 0, then 1, then 2, and finally 3.

  • QuadVertex:chrawget()
    Same as above but ignores inheritance.

  • QuadVertex:chdefine(fn)
    Defines all 4 verticies to a function. Definition function rules still apply.

  • QuadVertex:chfreeze()
    Sets all channels of all 4 verticies to their closest inherited values.

Polar Transformation Management

  • QuadVertex:polset(pol)
    Sets the polar transformation of all 4 verticies.

  • QuadVertex:polget()
    Returns the polar transformations of verticies 0, 1, 2, and 3 in that order.

  • QuadVertex:polrawget()
    Same as above but ignores inheritance.

  • QuadVertex:poldefine(fn)
    Defines the polar transformation function of all 4 verticies to a function. Definition function rules still apply.

  • QuadVertex:polfreeze()
    Sets the polar transformation of all 4 verticies to the closest inherited value.

Cartesian Transformation Management

  • QuadVertex:cartset(cart)
    Sets the cartesian transformation of all 4 verticies.

  • QuadVertex:cartget()
    Returns the cartesian transformations of verticies 0, 1, 2, and 3 in that order.

  • QuadVertex:cartrawget()
    Same as above but ignores inheritance.

  • QuadVertex:cartdefine(fn)
    Defines the cartesian transformation function of all 4 verticies to a function. Definition function rules still apply.

  • QuadVertex:cartfreeze()
    Sets the cartesian transformation of all 4 verticies to the closest inherited value.

Color Transformation Management

  • QuadVertex:colset(col)
    Sets the color transformation of all 4 verticies.

  • QuadVertex:colget()
    Returns the color transformations of verticies 0, 1, 2, and 3 in that order.

  • QuadVertex:colrawget()
    Same as above but ignores inheritance.

  • QuadVertex:coldefine(fn)
    Defines the color transformation function of all 4 verticies to a function. Definition function rules still apply.

  • QuadVertex:colfreeze()
    Sets the color transformation of all 4 verticies to the closest inherited value.


The Dual Limit Class

Limits determine the radial range where walls can appear. Walls always start at the origin limit (unless otherwise specified) and move towards the extent limit. If a wall's thickness or position causes it to exceed its limits, it is culled by those limits.

Parameters

These two parameters are cascading numeric classes.

  • DualLimit.origin

    • Its default value is 1600.
  • DualLimit.extent

    • Its default value is defined by the radius of the center polygon.

Functions

  • DualLimit:set(lim0, lim1)
    Sets the origin limit to <lim0> and the extent limit to <lim1>.

  • DualLimit:get()
    Returns the origin limit and the extent limit in that order.

  • DualLimit:rawget()
    Same as above but ignores inheritance.

  • DualLimit:define(lim0fn, lim1fn)
    Defines the origin limit to the function <lim0fn> and the extent limit to the function <lim1fn>.

  • DualLimit:freeze()
    Sets the origin limit and extent limit to their closest inherited values.

  • DualLimit:swap()
    Swaps the values of each limit. This causes the direction of walls to reverse.

WARNING: Swapping literally swaps the origin and extent angles so all downstream angles will also be affected.

  • DualLimit:order()
    Returns both limits in order from smaller to larger.

  • DualLimit:dir()
    Returns 1 if the origin limit is greater than or equal to the extent limit, -1 otherwise.


The Dual Angle Class

Angles determine the shape of walls. There are two, one for the left side and one for the right side of the wall. The origin angle governs the radial axis of verticies 0 and 3 while the extent angle governs the radial axis of verticies 1 and 2. Both angles can be offset by the offset parameter.

Parameters

These three parameters are cascading numeric classes.
They all have default values of 0.

  • DualAngle.origin
  • DualAngle.extent
  • DualAngle.offset

Functions

  • DualAngle:set(a0, a1, ofs)
    Sets the origin angle, extent angle, and offset parameters to <a0>, <a1>, and <ofs>, respectively.

  • DualAngle:get()
    Returns the origin angle, extent angle, and offset in that order.

  • DualAngle:rawget()
    Same as above but ignores inheritance.

  • DualAngle:define(a0fn, a1fn, ofsfn)
    Defines the origin angle, extent angle, and offset to the functions <a0fn>, <a1fn>, and <ofsfn>, respectively.

  • DualAngle:freeze()
    Sets the origin angle, extent angle, and offset to their closest inherited values.

  • DualAngle:result()
    Returns two angles, the result of the origin angle plus the offset and the extent angle plus the offset.


The PolyWall Class

The PolyWall class contains functions that operate directly on layers. They are mainly used to create, destroy, and organize layers and walls. The class also facilitates the movement and animation of walls.

Special Objects

  • PolyWall[i][j] ... [k][l]

    • Directly indexing a layer with a number returns the corresponding sublayer. If there is no sublayer, indexing returns nil. This can be chained repeatedly to access any layer from the current layer.
  • PolyWall.L

    • A table of all sublayers of the current layer. This isn't usually used in practice since directy indexing a PolyWall class with a number returns the corrsponding sublayer.
  • PolyWall.W

    • A table of all walls contained in the current layer. Every wall has a unique table as a key and a primitive layer as its value.

For more on wall keys, visit Walls

Parameters

  • PolyWall.thickness

  • PolyWall.speed

    • This is a cascading numeric class.
    • Its default value is defined by the level's current speed and difficulty multipliers.
  • PolyWall.position

    • This is a cascading numeric class
    • Unlike other parameters, position does not inherit its value from the superclass layer but the current layer's origin limit value. For example, if the current layer's origin limit is 1600 (the default) then position will inherit the value of 1600.
  • PolyWall.vertex

  • PolyWall.angle

  • PolyWall.limit

Functions

IMPORTANT: Many of the functions below are recursive. This is indicated by their first argument being the <depth> value. This value specifies how many layers deep the function should be run relative to the current layer. For example, if the depth is 2 then the function operation will performed on every layer two layers down from the current layer. Layers in between are unaffected with the exception of PolyWall:sort(depth, descending). An asterisk (*) indicates functions which are recursive.

Layer Creation and Deletion

  • PolyWall:construct(th, sp, p, r, g, b, a, pol, cart, col, a0, a1, ofs, lim0, lim1)
    Creates the most primitive layer object. In practice, this is only used by walls which don't need all features of an actual layer. This object lacks the ability to create new layers and does not contain a MockPlayer extension class.

    Parameter Initializations

    The arguments of this function are used to initialize the parameter classes with certain values and are listed below:

    Name Parameter
    <th> thickness
    <sp> speed
    <p> position
    <r> Red channel (all verticies)
    <g> Green channel (all verticies)
    <b> Blue channel (all verticies)
    <a> Alpha channel (all verticies)
    <pol> Polar transformation (all verticies)
    <cart> Cartesian transformation (all verticies)
    <col> Color transformation (all verticies)
    <a0> origin angle
    <a1> extent angle
    <ofs> offset angle
    <lim0> origin limit
    <lim1> extent limit

IMPORTANT: The arguments of this function are commonly repeated amongst other following functions that involve the creation of a wall or layer. These parameters will be listed with the same names.

  • PolyWall:new(th, sp, p, r, g, b, a, pol, cart, col, a0, a1, ofs, lim0, lim1)
    Creates a new standalone layer. This layer is disconnected from its superclass layer but still inherits its values. In practice, this function is only used once to create a root layer for other layers to branch off of.

  • PolyWall:add(n, th, sp, p, r, g, b, a, pol, cart, col, a0, a1, ofs, lim0, lim1)
    Creates a new layer with numerical index <n> and links it to the current layer.

  • PolyWall:radd(depth, n, th, sp, p, r, g, b, a, pol, cart, col, a0, a1, ofs, lim0, lim1) *
    Same as add but acts recursively.

  • PolyWall:remove(n)
    Removes layer <n> of the current layer. All sublayers and walls are also destroyed.
    Legacy name: rmLayer

  • PolyWall:rremove(depth, n)
    Similar to remove but acts recursively.

  • PolyWall:xremove(depth) *
    Removes all layers.
    Legacy name: rrmLayer

Wall Creation and Deletion

  • PolyWall:wremove(key)
    Removes a wall of the current layer with key <key>.
    Legacy name: rmWall

  • PolyWall:wxremove(depth) *
    Removes all walls.
    Legacy name: rrmWall

  • PolyWall:wall(depth, t, th, sp, p, r, g, b, a, pol, cart, col, a0, a1, ofs, lim0, lim1) *
    Creates walls. The mode <t> can be one of three strings 's', 'n', or 'd' indicating the type of wall to be spawned. If depth is zero, returns the key of the created wall.

  • PolyWall:sWall(depth, th, sp, p, r, g, b, a, pol, cart, col, a0, a1, ofs, lim0, lim1) *
    Creates a standard wall. If depth is zero, returns the instance of the created wall.

  • PolyWall:nWall(depth, th, sp, p, r, g, b, a, pol, cart, col, a0, a1, ofs, lim0, lim1) *
    Creates a non-solid wall. If depth is zero, returns the instance of the created wall.

  • PolyWall:dWall(depth, th, sp, p, r, g, b, a, pol, cart, col, a0, a1, ofs, lim0, lim1) *
    Creates a deadly wall. If depth is zero, returns the instance of the created wall.

For more on wall keys, visit Walls

  • PolyWall:pivotCap(depth, r, g, b, a, pol, cart, col, a0, a1, ofs) *
    Creates a non-solid imitation of a section of the center polygon cap.

  • PolyWall:pivotBorder(depth, r, g, b, a, pol, cart, col, a0, a1, ofs) *
    Creates a non-solid imitation of a section of the center polygon border.

  • PolyWall:hasWalls(depth) *
    Returns true if any layer <depth> layers down has one or more walls.

Layer Organization and Arrangement

  • PolyWall:template(depth, n, ...) *
    Creates <n> layers with indicies 0, 1, ... , n - 2, n - 1.

  • PolyWall:regularize(depth, shape, ofs) *
    Modifies the origin and extent angles of the layers 0, 1, ... , shape - 2, shape - 1 such that they take the shape of a regular polygon with angle offset <ofs>. Any layers that aren't included in the sequence are ignored. The <shape> parameter must be a valid side count.

  • PolyWall:distribute(depth, n, ofs) *
    Modifies the offset angles of the layers 0, 1, ... , n - 2, n - 1 such that they are evenly distributed from 0 to 2π with angle offset <ofs>.

  • PolyWall:proportionalize(depth, ofs, ...) *
    Modifies the origin and extent angles of layers in proportion to a ratio provided in the variadic (...) with angle offset <ofs>. The range of layers affected is 0, 1, ... , n - 2, n - 1 where n is the length of the ratio. The sum of all numbers in the ratio must be greater than zero but individual numbers in the ratio can equal zero. (They'll just have an arc length of zero making them invisible.)

Wall Movement and Animation

  • PolyWall:move(depth, mFrameTime) *
    Advances and updates all wall positions according to position, thickness, and direction. Any polar and cartesian transformation functions are applied, in that order.

  • PolyWall:fill(depth) *
    Updates wall colors. Any color transformations are also applied.

  • PolyWall:run(depth, mFrameTime) *
    Union of move and fill. Color transformations applied by this function have access to polar and cartesian coordinate information. A more detailed description of this functionailty is provided in Transformations.

  • PolyWall:sort(depth, descending) *
    Sorts wall CW handles such that lower numbered handles are moved to lower layers and higher numbered handles to higher layers. The order can be reversed by setting the <decending> parameter to true. Enables wall layering based on layer indicies. Only affects currently existing walls so this function should be run regularly to maintain proper layering. (However, do not run this function too frequently as it is very computationally expensive.) Layering of walls within a single layer is unstable and will very likely change. MockPlayers are also affected and will always be prioritized above walls within their own layers. Layers closer to the root layer are prioritized above deeper layers.

IMPORTANT: This is the only function that affects layers in between the current layer and all layers <depth> layers deep.