Module: PseudoGame.graphics.PolygonCollection

Class for storing multiple polygons in an efficient manner

Functions

PseudoGame.graphics.PolygonCollection:new () the constructor for a polygon collection
PseudoGame.graphics.PolygonCollection:add (polygon) add a polygon to the collection
PseudoGame.graphics.PolygonCollection:resize (size) make the collection be a certain size by deleting polygons if it's too big and creating new ones if it's too small
PseudoGame.graphics.PolygonCollection:remove (index) remove a polygon from the collection (this does not shift other indices)
PseudoGame.graphics.PolygonCollection:get (index) get a polygon from the collection
PseudoGame.graphics.PolygonCollection:copy_add (polygon_collection) add the polygons from another collection to this one by copying them (uses Polygon:copy so this function is bad for performance)
PseudoGame.graphics.PolygonCollection:ref_add (polygon_collection) add the polygons from another collection to this one by referencing them
PseudoGame.graphics.PolygonCollection:iter () an iterator to loop over all polygons in the collection
PseudoGame.graphics.PolygonCollection:generator () recreate all polygons in the collection while reusing the old ones (avoids table allocation so this is very good for performance)
PseudoGame.graphics.PolygonCollection:transform (transform_func) transform the vertices and vertex colors of all polygons in the collection
PseudoGame.graphics.PolygonCollection:clear () clear all polygons from this collection (does not delete the items in the table internally, so it's fine performance wise to frequently clear a collection)

Fields

pseudogame.graphics.polygoncollection.size


Functions

🔗 PseudoGame.graphics.PolygonCollection:new ()
the constructor for a polygon collection

Returns:

    PolygonCollection the newly created polygon collection
🔗 PseudoGame.graphics.PolygonCollection:add (polygon)
add a polygon to the collection

Parameters:

Name Type(s) Description
polygon Polygon the polygon to add

Returns:

    number the index of the polygon in the collection
🔗 PseudoGame.graphics.PolygonCollection:resize (size)
make the collection be a certain size by deleting polygons if it's too big and creating new ones if it's too small

Parameters:

Name Type(s) Description
size number the amount of polygons that will be in the collection
🔗 PseudoGame.graphics.PolygonCollection:remove (index)
remove a polygon from the collection (this does not shift other indices)

Parameters:

Name Type(s) Description
index number the index of the polygon that should be deleted
🔗 PseudoGame.graphics.PolygonCollection:get (index)
get a polygon from the collection

Parameters:

Name Type(s) Description
index number the index of the polygon in the collection

Returns:

    Polygon the polygon at the index in the collection
🔗 PseudoGame.graphics.PolygonCollection:copy_add (polygon_collection)
add the polygons from another collection to this one by copying them (uses Polygon:copy so this function is bad for performance)

Parameters:

Name Type(s) Description
polygon_collection PolygonCollection the collection with the polygons that should be added
🔗 PseudoGame.graphics.PolygonCollection:ref_add (polygon_collection)
add the polygons from another collection to this one by referencing them

Parameters:

Name Type(s) Description
polygon_collection PolygonCollection the collection with the polygons that should be added
🔗 PseudoGame.graphics.PolygonCollection:iter ()
an iterator to loop over all polygons in the collection

Usage:

    for polygon in mypolygoncollection:iter() do
        ...
    end
🔗 PseudoGame.graphics.PolygonCollection:generator ()
recreate all polygons in the collection while reusing the old ones (avoids table allocation so this is very good for performance)

Usage:

    local gen = polygon_collection:generator()
    for i=1,100 do
        local polygon = gen()
        -- since it reuses old polygons and creates new empty ones if there is none
        -- we don't know what vertex count the polygon has, so it makes sense to set it
        -- setting it to the number you need directly instead of setting it to 0 and adding
        -- vertices is better for performance (less (or no when reusing) memory allocation)
        -- (this is not required if you call methods like polygon:copy_data)
        polygon:resize(4)
        ...
    end
🔗 PseudoGame.graphics.PolygonCollection:transform (transform_func)
transform the vertices and vertex colors of all polygons in the collection

Parameters:

Name Type(s) Description
transform_func function a function that takes x, y, r, g, b, a and returns x, y, r, g, b, a
🔗 PseudoGame.graphics.PolygonCollection:clear ()
clear all polygons from this collection (does not delete the items in the table internally, so it's fine performance wise to frequently clear a collection)

Fields

🔗 pseudogame.graphics.polygoncollection.size
Name Type(s) Description
size number the amount of polygons in the collection
generated by LDoc 1.5.0