diff --git a/openage/convert/processor/export/texture_merge.pyx b/openage/convert/processor/export/texture_merge.pyx index f726d0af02..0b134f2664 100644 --- a/openage/convert/processor/export/texture_merge.pyx +++ b/openage/convert/processor/export/texture_merge.pyx @@ -81,7 +81,7 @@ cdef void cmerge_frames(texture, packer_type=PackerType.BINPACK, cache=None) exc RowPacker(margin=MARGIN), ColumnPacker(margin=MARGIN)]) - packer.pack(frames) + packer.pack([(frame.width, frame.height) for frame in frames]) cdef int width = packer.width() cdef int height = packer.height() @@ -106,11 +106,11 @@ cdef void cmerge_frames(texture, packer_type=PackerType.BINPACK, cache=None) exc cdef int sub_h cdef list drawn_frames_meta = [] - for sub_frame in frames: + for index, sub_frame in enumerate(frames): sub_w = sub_frame.width sub_h = sub_frame.height - pos_x, pos_y = packer.pos(sub_frame) + pos_x, pos_y = packer.pos(index) spam("drawing frame %03d on atlas at %d x %d...", len(drawn_frames_meta), pos_x, pos_y) diff --git a/openage/convert/service/export/png/binpack.pxd b/openage/convert/service/export/png/binpack.pxd index ac068558ed..0efce131d3 100644 --- a/openage/convert/service/export/png/binpack.pxd +++ b/openage/convert/service/export/png/binpack.pxd @@ -7,7 +7,7 @@ cdef class Packer: cdef dict mapping cdef void pack(self, list blocks) - cdef (unsigned int, unsigned int) pos(self, block) + cdef (unsigned int, unsigned int) pos(self, int index) cdef unsigned int width(self) cdef unsigned int height(self) cdef list get_mapping_hints(self, list blocks) @@ -22,7 +22,7 @@ cdef class BestPacker: cdef void pack(self, list blocks) cdef Packer best_packer(self) - cdef (unsigned int, unsigned int) pos(self, block) + cdef (unsigned int, unsigned int) pos(self, int index) cdef unsigned int width(self) cdef unsigned int height(self) cdef list get_mapping_hints(self, list blocks) @@ -38,7 +38,7 @@ cdef class BinaryTreePacker(Packer): cdef unsigned int aspect_ratio cdef packer_node *root - cdef void fit(self, block) + cdef void fit(self, int index, block) cdef tuple get_packer_settings(self) cdef packer_node *find_node(self, packer_node *root, unsigned int width, unsigned int height) cdef packer_node *split_node(self, packer_node *node, unsigned int width, unsigned int height) diff --git a/openage/convert/service/export/png/binpack.pyx b/openage/convert/service/export/png/binpack.pyx index 31eef3f375..e5e1c27fc9 100644 --- a/openage/convert/service/export/png/binpack.pyx +++ b/openage/convert/service/export/png/binpack.pyx @@ -44,20 +44,20 @@ cdef class Packer: """ raise NotImplementedError - cdef (unsigned int, unsigned int) pos(self, block): - return self.mapping[block] + cdef (unsigned int, unsigned int) pos(self, int index): + return self.mapping[index] cdef unsigned int width(self): """ Gets the total width of the packing. """ - return max(self.pos(block)[0] + block.width for block in self.mapping) + return max(self.pos(i)[0] + block[0] for i, block in enumerate(self.mapping.values())) cdef unsigned int height(self): """ Gets the total height of the packing. """ - return max(self.pos(block)[1] + block.height for block in self.mapping) + return max(self.pos(i)[1] + block[1] for i, block in enumerate(self.mapping.values())) cdef tuple get_packer_settings(self): """ @@ -67,8 +67,9 @@ cdef class Packer: cdef list get_mapping_hints(self, list blocks): cdef list hints = [] - for block in blocks: - hints.append(self.pos(block)) + cdef int n = len(blocks) + for index in range(n): + hints.append(self.pos(index)) return hints @@ -86,7 +87,7 @@ cdef class DeterministicPacker(Packer): cdef int i cdef int n = len(blocks) for i in range(n): - self.mapping[self.blocks[i]] = self.hints[i] + self.mapping[i] = self.hints[i] cdef class BestPacker: @@ -107,8 +108,8 @@ cdef class BestPacker: cdef Packer best_packer(self): return min(self.packers, key=lambda Packer p: p.width() * p.height()) - cdef (unsigned int, unsigned int) pos(self, block): - return self.current_best.pos(block) + cdef (unsigned int, unsigned int) pos(self, int index): + return self.current_best.pos(index) cdef unsigned int width(self): return self.current_best.width() @@ -148,11 +149,11 @@ cdef class RowPacker(Packer): for row in rows: x = 0 - for block in row: - self.mapping[block] = (x, y) - x += block.width + self.margin + for index, block in enumerate(row): + self.mapping[index] = (x, y) + x += block[0] + self.margin - y += max(block.height for block in row) + self.margin + y += max(block[1] for block in row) + self.margin cdef class ColumnPacker(Packer): @@ -180,21 +181,21 @@ cdef class ColumnPacker(Packer): for column in columns: y = 0 - for block in column: - self.mapping[block] = (x, y) - y += block.height + self.margin + for index, block in enumerate(column): + self.mapping[index] = (x, y) + y += block[1] + self.margin - x += max(block.width for block in column) + self.margin + x += max(block[0] for block in column) + self.margin cdef inline (unsigned int, unsigned int, unsigned int, unsigned int) maxside_heuristic(block): """ Heuristic: Order blocks by maximum side. """ - return (max(block.width, block.height), - min(block.width, block.height), - block.height, - block.width) + return (max(block[0], block[1]), + min(block[0], block[1]), + block[1], + block[0]) cdef class BinaryTreePacker(Packer): @@ -217,41 +218,41 @@ cdef class BinaryTreePacker(Packer): self.mapping = {} self.root = NULL - for block in sorted(blocks, key=maxside_heuristic, reverse=True): - self.fit(block) + for i, block in enumerate(sorted(blocks, key=maxside_heuristic, reverse=True)): + self.fit(i, block) - cdef (unsigned int, unsigned int) pos(self, block): - node = self.mapping[block] + cdef (unsigned int, unsigned int) pos(self, int index): + node = self.mapping[index] return node[0], node[1] cdef tuple get_packer_settings(self): return (self.margin,) - cdef void fit(self, block): + cdef void fit(self, int index, block): cdef packer_node *node if self.root == NULL: self.root = malloc(sizeof(packer_node)) self.root.x = 0 self.root.y = 0 - self.root.width = block.width + self.margin - self.root.height = block.height + self.margin + self.root.width = block[0] + self.margin + self.root.height = block[1] + self.margin self.root.used = False self.root.down = NULL self.root.right = NULL node = self.find_node(self.root, - block.width + self.margin, - block.height + self.margin) + block[0] + self.margin, + block[1] + self.margin) if node != NULL: node = self.split_node(node, - block.width + self.margin, - block.height + self.margin) + block[0] + self.margin, + block[1] + self.margin) else: - node = self.grow_node(block.width + self.margin, - block.height + self.margin) + node = self.grow_node(block[0] + self.margin, + block[1] + self.margin) - self.mapping[block] = (node.x, node.y) + self.mapping[index] = (node.x, node.y) cdef packer_node *find_node(self, packer_node *root, unsigned int width, unsigned int height): if root.used: