Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Speed up sprite generation by skipping creation of too small spritesh…

…eets
  • Loading branch information...
commit 6c1b17a73c2233eeff3ace8c0a5002236fb4a2f2 1 parent 1e096da
Ivo Wetzel authored
Showing with 24 additions and 4 deletions.
  1. +24 −4 jasy/asset/SpritePacker.py
View
28 jasy/asset/SpritePacker.py
@@ -54,7 +54,15 @@ def __lt__(self, other):
# Otherwise sort against the index size
elif self.value >= other.value:
- return self.indexSize < other.indexSize
+
+ if self.indexSize < other.indexSize:
+ return True
+
+ elif self.indexSize == other.indexSize and self.sheets[0].width > other.sheets[0].width:
+ return True
+
+ else:
+ return False
else:
return False
@@ -63,7 +71,7 @@ def __gt__(self, other):
return not self < other
def __repr__(self):
- return '<PackerScore %d sheets #%d (%s) Area: %d Used: %d (%2.f%%) External: %d Count: %d Value: %2.5f>' % (self.count, self.indexSize, ', '.join(self.sizes), self.area, self.usedArea, self.efficency, self.excount, self.count ** self.count, self.value)
+ return '<PackerScore %d sheets #%d (%s) Area: %d Used: %d (%2.f%%) External: %d Count: %d Value: %2.5f>' % (self.count, self.indexSize, ', '.join(self.sizes), self.area, self.usedArea, self.efficency, self.excount - 1, self.count ** self.count, self.value)
@@ -170,12 +178,24 @@ def sortArea(img):
# by averaging the widths and heights of all images
# while taking the ones in the sorted middile higher into account
# then the ones at the outer edges of the spectirum
+
+
l = len(self.files)
mw = [(l - abs(i - l / 2)) / l * v for i, v in enumerate(sorted([i.width for i in self.files]))]
mh = [(l - abs(i - l / 2)) / l * v for i, v in enumerate(sorted([i.height for i in self.files]))]
- minWidth = math.pow(2, math.ceil(math.log(sum(mw) / l, 2)))
- minHeight = math.pow(2, math.ceil(math.log(sum(mh) / l, 2)))
+ minWidth = max(128, math.pow(2, math.ceil(math.log(sum(mw) / l, 2))))
+ minHeight = max(128, math.pow(2, math.ceil(math.log(sum(mh) / l, 2))))
+
+ #baseArea = sum([(l - abs(i - l / 2)) / l * v for i, v in enumerate(sorted([i.width * i.height for i in self.files]))])
+
+ # try to skip senseless generation of way to small sprites
+ baseArea = sum([minWidth * minHeight for i in self.files])
+ while baseArea / (minWidth * minHeight) >= 20: # bascially an estimate of the number of sheets needed
+ minWidth *= 2
+ minHeight *= 2
+
+ logging.debug('- Minimal size is %dx%dpx' % (minWidth, minHeight))
sizes = list(itertools.product([w for w in [128, 256, 512, 1024, 2048] if w >= minWidth],
[h for h in [128, 256, 512, 1024, 2048] if h >= minHeight]))
Please sign in to comment.
Something went wrong with that request. Please try again.