@@ -7,7 +7,7 @@ local fixedSizeTA = setmetatable({}, baseAtlas)
77fixedSizeTA .__index = fixedSizeTA
88
99local lg = love .graphics
10- local ceil , sqrt = math.ceil , math.sqrt
10+ local ceil , floor , sqrt = math.ceil , math.sqrt , math.floor
1111
1212fixedSizeTA .new = function (width , height , padding )
1313 local self = setmetatable (baseAtlas .new (padding ), fixedSizeTA )
2626
2727fixedSizeTA .bake = function (self )
2828 if self ._dirty and not self ._hardBake then
29- local columns = ceil (sqrt (# self .images ))
29+ local columns = ceil (sqrt (self .imagesSize ))
3030 local width , height = self .width , self .height
3131 local widthPadded , heightPadded = width + self .padding , height + self .padding
32- local rows = ceil (# self .images / columns )
33- local widthCanvas , heightCanvas = columns * widthPadded , rows * heightPadded
32+
33+ local widthCanvas = columns * widthPadded
34+ if widthCanvas > self ._maxCanvasSize then
35+ columns = floor (self ._maxCanvasSize / width )
36+ widthCanvas = columns * widthPadded
37+ end
38+
39+ local rows = ceil (self .imagesSize / columns )
40+ local heightCanvas = rows * heightPadded
41+ if heightPadded > self ._maxCanvasSize then
42+ rows = floor (self ._maxCanvasSize / height )
43+ heightCanvas = rows * heightPadded
44+ end
45+
46+ if columns * rows < self .imagesSize then
47+ error (" Cannot support " .. tostring (self .imagesSize ).. " images, due to system limits of canvas size. Max allowed on this system: " .. tostring (columns * rows ))
48+ end
49+
3450 local canvas = lg .newCanvas (widthCanvas , heightCanvas , self ._canvasSettings )
3551 local maxIndex = self .imagesSize
3652 lg .push (" all" )
0 commit comments