Only cook quads when needed - speeds up world list

This commit is contained in:
David Vierra 2015-01-04 10:53:31 -10:00
parent cd632c6737
commit 864990429d
3 changed files with 10 additions and 4 deletions

View File

@ -54,6 +54,7 @@ class BlockModels(object):
self.firstTextures = {} # first texture found for each block - used for icons (xxx)
self.cookedModels = {} # nameAndState -> list[(xyzuvc, cullface)]
self.cookedModelsByID = numpy.zeros((256*16, 16), dtype=list) # (id, meta) -> list[(xyzuvc, cullface)]
self.cooked = False
for i, block in enumerate(blocktypes):
if i % 100 == 0:
@ -215,6 +216,9 @@ class BlockModels(object):
return iter(self._textureNames)
def cookQuads(self, textureAtlas):
if self.cooked:
return
log.info("Cooking quads for %d models...", len(self.modelQuads))
cookedModels = {}
cdef int l, t, w, h
cdef int u1, u2, v1, v2
@ -269,8 +273,9 @@ class BlockModels(object):
cookedModels[nameAndState] = cookedQuads
ID, meta = self.blocktypes.IDsByState[nameAndState]
self.cookedModelsByID[ID, meta] = cookedQuads
self.cookedModels = cookedModels
self.cooked = True
def rotateVertices(self, rotation, variantXrot, variantYrot, variantZrot, xyzuvc):
if rotation is not None:

View File

@ -39,7 +39,10 @@ class BlockModelMesh(object):
if section is None:
return
blockModels = self.sectionUpdate.chunkUpdate.updateTask.textureAtlas.blockModels
atlas = self.sectionUpdate.chunkUpdate.updateTask.textureAtlas
blockModels = atlas.blockModels
blockModels.cookQuads(atlas)
blocktypes = self.sectionUpdate.blocktypes
areaBlocks = self.sectionUpdate.areaBlocks
data = section.Data

View File

@ -200,8 +200,6 @@ class TextureAtlas(object):
usedSize = sum(sum(width * height for _, _, _, width, height, _ in slot.textures) for slot in slots) * 4
log.info("Terrain atlas created for world %s (%d/%d kB)", util.displayName(self._filename), usedSize / 1024,
totalSize / 1024)
if self.overrideMaxSize is None:
self.blockModels.cookQuads(self)
#file("terrain-%sw-%sh.raw" % (atlasWidth, atlasHeight), "wb").write(texData.tostring())
#raise SystemExit