From d997a44264fb9977d744c7b60d81ce64c05c9df6 Mon Sep 17 00:00:00 2001 From: David Vierra Date: Sat, 3 Jan 2015 13:17:12 -1000 Subject: [PATCH] Break apart loops into cythonizable ones --- src/mcedit2/rendering/modelmesh.pyx | 60 +++++++++++++++-------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/src/mcedit2/rendering/modelmesh.pyx b/src/mcedit2/rendering/modelmesh.pyx index 5a3a39e..feb3994 100644 --- a/src/mcedit2/rendering/modelmesh.pyx +++ b/src/mcedit2/rendering/modelmesh.pyx @@ -36,38 +36,42 @@ class BlockModelMesh(object): blocktypes = self.sectionUpdate.blocktypes areaBlocks = self.sectionUpdate.areaBlocks faceQuadVerts = [] + + cdef unsigned short y, z, x, ID, meta + cdef short dx, dy, dz, + cdef unsigned short nx, ny, nz, nID - for y in xrange(1, 17): - yield - for z, x in itertools.product(xrange(1, 17), xrange(1, 17)): - ID = areaBlocks[y, z, x] - if ID == 0: - continue - meta = section.Data[y-1, z-1, x-1] + for y in range(1, 17): + for z in range(1, 17): + for x in range(1, 17): + ID = areaBlocks[y, z, x] + if ID == 0: + continue + meta = section.Data[y-1, z-1, x-1] - block = blocktypes[ID, meta] - if block.renderType != 3: # only model blocks for now - continue - nameAndState = block.internalName + block.blockState - quads = blockModels.cookedModels[nameAndState] + block = blocktypes[ID, meta] + if block.renderType != 3: # only model blocks for now + continue + nameAndState = block.internalName + block.blockState + quads = blockModels.cookedModels[nameAndState] - for face, xyzuvc, cullface in quads: - if cullface is not None: - dx, dy, dz = cullface.vector - nx = x + dx - ny = y + dy - nz = z + dz - nID = areaBlocks[ny, nz, nx] - if nID != 0: - nBlock = blocktypes[nID] - if nBlock.opaqueCube: - continue + for face, xyzuvc, cullface in quads: + if cullface is not None: + dx, dy, dz = cullface.vector + nx = x + dx + ny = y + dy + nz = z + dz + nID = areaBlocks[ny, nz, nx] + if nID != 0: + nBlock = blocktypes[nID] + if nBlock.opaqueCube: + continue - verts = numpy.array(xyzuvc) - verts.shape = 1, 4, 6 - verts[..., :3] += (x - 1, y - 1 + (cy << 4), z - 1) - faceQuadVerts.append(verts) - # log.info("Block %s:\nVertices: %s", (x-1, y-1, z-1), verts) + verts = numpy.array(xyzuvc) + verts.shape = 1, 4, 6 + verts[..., :3] += (x - 1, y - 1 + (cy << 4), z - 1) + faceQuadVerts.append(verts) + # log.info("Block %s:\nVertices: %s", (x-1, y-1, z-1), verts) # raise SystemExit if len(faceQuadVerts):