From e840f5990166e5bf54b16ec9057630711c5db41c Mon Sep 17 00:00:00 2001 From: Matthias Richter Date: Tue, 17 Aug 2010 19:11:21 +0200 Subject: [PATCH] add ringbuffer documentation --- index.html | 159 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 138 insertions(+), 21 deletions(-) diff --git a/index.html b/index.html index c873cde..1721a1d 100644 --- a/index.html +++ b/index.html @@ -81,6 +81,7 @@ for the excellent LÖVE Engine.

  • class.lua: a simple and easy class system with function inheritance,
  • camera.lua: a translate-, zoom- and rotatable camera and
  • gamestate.lua: a gamestate system.
  • +
  • ringbuffer.lua: a circular container.
  • hump differs from other libraries in that every component is independent of the @@ -97,6 +98,7 @@ module by clicking these:

  • class.lua
  • camera.lua
  • gamestate.lua
  • +
  • ringbuffer.lua
  • @@ -233,23 +235,23 @@ print(a:dist(b)) -- prints 1.4142135623731

    Warning: This will change the state of all references to this vector.

    - -
    function vector:perpendicular()^ top - Get vector rotated by 90° clockwise, e.g. the vector (0,1) results in (1,0). - - -
    Sketch:Perpendicular vector
    -
    + +
    function vector:perpendicular()^ top + Get vector rotated by 90° clockwise, e.g. the vector (0,1) results in (1,0). + + +
    Sketch:Perpendicular vector
    +
    - -
    function vector:projectOn(v)^ top - Project this vector onto another one, e.g. (2,2) projected onto (1,0) results in (2,0). - - - - -
    Parameters:[vector]vVector to project onto
    Returns:Vector with direction of v and length according to projection.
    Sketch:Projected vector
    -
    + +
    function vector:projectOn(v)^ top + Project this vector onto another one, e.g. (2,2) projected onto (1,0) results in (2,0). + + + + +
    Parameters:[vector]vVector to project onto
    Returns:Vector with direction of v and length according to projection.
    Sketch:Projected vector
    +
    @@ -554,19 +556,134 @@ camera:deapply() leave() Gets called upon leaving the state. The same warning as with enter applies. update(dt) - Manully called by Gamestate.update, or automatically like love.update + Manually called by Gamestate.update, or automatically like love.update when using Gamestate.registerEvents(). draw() - Manully called by Gamestate.draw, or automatically like love.draw + Manually called by Gamestate.draw, or automatically like love.draw keypressed(key, unicode) - Manully called by Gamestate.keypressed, or automatically like love.keypressed + Manually called by Gamestate.keypressed, or automatically like love.keypressed keyreleased(key) - Manully called by Gamestate.keyreleased, or automatically like love.keyreleased + Manually called by Gamestate.keyreleased, or automatically like love.keyreleased mousereleased(x,y,btn) - Manully called by Gamestate.mousereleased, or automatically like love.mousereleased + Manually called by Gamestate.mousereleased, or automatically like love.mousereleased +
    + +

    ringbuffer.lua^ top

    +

    A circular container that can hold arbitrary items. It can be used to create Tomb Raider style + inventories, a looping music playlist, recurring dialog sequences and much more.

    + +

    ringbuffer.lua defines the following functions: + + + + + + + + + + +
    Ringbuffer(...)Create new ringbuffer
    ringbuffer:insert(item, ...)Insert items
    ringbuffer:append(item, ...)Append items to the "end"
    ringbuffer:remove()Remove item
    ringbuffer:removeAt(k)Remove item at position
    ringbuffer:get()Get item
    ringbuffer:size()Number of items in buffer
    ringbuffer:next()Get next item
    ringbuffer:prev()Get previous item

    + + +
    + function Ringbuffer(...)^ top + Create a new ringbuffer. + + +
    Parameters[optional]...:Initial items of the buffer.
    +
    + + +
    + function ringbuffer:insert(item, ...)^ top + Insert items behind current item. + + + + + +
    Parameters:item:Item to insert
    [optional]...:Additional items to insert
    Example
    rb = Ringbuffer(1,2,5,6) -- rb = {1 ,2,5,6}, rb:get() == 1
    +rb:next() -- rb = {1, 2 ,5,6}, rb:get() == 2
    +rb:insert(3,4) -- rb = {1, 2 ,3,4,5,6}, rb:get() == 2
    +rb:next() -- rb = {1,2, 3 ,4,5,6}, rb:get() == 3
    +
    + + +
    + function ringbuffer:append(item, ...)^ top + Append items to ringbuffer. +

    This is less intuitive than ringbuffer:insert(item, ...) since it appears the items are added + at a random location. Use is only recommended before using ringbuffer:next() or ringbuffer:prev().

    + + + + + +
    Parameters:item:Item to append
    [optional]...:Additional items to append
    Example
    rb = Ringbuffer(1,2,5,6) -- rb = {1 ,2,5,6}, rb:get() == 1
    +rb:next() -- rb = {1, 2 ,5,6}, rb:get() == 2
    +rb:append(3,4) -- rb = {1, 2 ,5,6,3,4}, rb:get() == 2
    +rb:next() -- rb = {1,2, 5 ,6,3,4}, rb:get() == 5
    +
    + + +
    + function ringbuffer:remove()^ top + Remove currently selected item. The next item will be selected. + + + +
    Example
    rb = Ringbuffer(1,2,3) -- rb = {1 ,2,3}, rb:get() == 1
    +rb:next() -- rb = {1, 2 ,3}, rb:get() == 2
    +rb:remove() -- rb = {1, 3 }, rb:get() == 3
    +
    + + +
    + function ringbuffer:removeAt(k)^ top + Remove item at relative position k. k may be positive or negative and + even bigger than ringbuffer:size(). + + + + +
    Parameters:[number]kRelative position of item to remove.
    Example:
    rb = Ringbuffer(1,2,3,4,5) -- rb = { 1 ,2,3,4,5}, rb:get() == 1
    +rb:removeAt(2) -- rb = { 1 ,2,4,5}, rb:get() == 1
    +rb:next() -- rb = {1, 2 ,4,5}, rb:get() == 2
    +rb:removeAt(-1) -- rb = { 2 ,4,5}, rb:get() == 2
    +
    + + +
    + function ringbuffer:get()^ top + Get currently selected item. +
    Returns: The currently selected item.
    +
    + + +
    + function ringbuffer:size()^ top +
    Returns: Number of items in the buffer.
    +
    + + +
    + function ringbuffer:next()^ top + Select next item and return it. +
    Return: Selected item after operation.
    +
    + + +
    + function ringbuffer:prev()^ top + Select previous item and return it. +
    Return: Selected item after operation.
    +
    +
    +

    License^ top