Class pyglet.image.atlas.Allocator

Rectangular area allocation algorithm.

Initialise with a given width and height, then repeatedly call alloc to retrieve free regions of the area and protect that area from future allocations.

Allocator uses a fairly simple strips-based algorithm. It performs best when rectangles are allocated in decreasing height order.

Methods

  __init__(self, width, height)
Create an Allocator of the given size.
int, int alloc(self, width, height)
Get a free area in the allocator of the given size.
float get_usage(self)
Get the fraction of area already allocated.
float get_fragmentation(self)
Get the fraction of area that's unlikely to ever be used, based on current allocation behaviour.

Method Details

__init__

(Constructor) __init__(self, width, height)
Create an Allocator of the given size.
Parameters:
width : int
Width of the allocation region.
height : int
Height of the allocation region.

alloc

alloc(self, width, height)

Get a free area in the allocator of the given size.

After calling alloc, the requested area will no longer be used. If there is not enough room to fit the given area AllocatorException is raised.

Parameters:
width : int
Width of the area to allocate.
height : int
Height of the area to allocate.
Returns:
int, int: The X and Y coordinates of the bottom-left corner of the allocated region.

get_usage

get_usage(self)

Get the fraction of area already allocated.

This method is useful for debugging and profiling only.

Returns: float

get_fragmentation

get_fragmentation(self)

Get the fraction of area that's unlikely to ever be used, based on current allocation behaviour.

This method is useful for debugging and profiling only.

Returns: float