rename generateHeightMap to extractLightMap and move it to level.py. call it from the new HeightMap property on FakeChunk (xxx flesh out FakeChunk)

This commit is contained in:
David Vierra 2011-09-23 16:48:11 -10:00
parent d350d65f90
commit fa88a3d83c
3 changed files with 27 additions and 17 deletions

View File

@ -758,7 +758,9 @@ class InfdevChunk(EntityLevel):
def isCompressed(self): def isCompressed(self):
return self.isLoaded() and self.root_tag == None return self.isLoaded() and self.root_tag == None
def generateHeightMap(self):
extractLightMap(self.materials, self.Blocks, self.HeightMap)
def chunkChanged(self, calcLighting=True): def chunkChanged(self, calcLighting=True):
""" You are required to call this function after you are done modifying """ You are required to call this function after you are done modifying
the chunk. Pass False for calcLighting if you know your changes will the chunk. Pass False for calcLighting if you know your changes will
@ -770,7 +772,7 @@ class InfdevChunk(EntityLevel):
self.dirty = True; self.dirty = True;
self.needsLighting = calcLighting or self.needsLighting; self.needsLighting = calcLighting or self.needsLighting;
generateHeightMap(self); self.generateHeightMap();
if calcLighting: if calcLighting:
self.genFastLights() self.genFastLights()
@ -910,19 +912,6 @@ class InfdevChunk(EntityLevel):
ores and vegetation on next load""" ores and vegetation on next load"""
self.root_tag[Level]["TerrainPopulated"].value = val; self.root_tag[Level]["TerrainPopulated"].value = val;
def generateHeightMap(self):
self.load();
blocks = self.Blocks
heightMap = self.HeightMap
heightMap[:] = 0;
lightAbsorption = self.world.materials.lightAbsorption[blocks]
axes = lightAbsorption.nonzero()
heightMap[axes[1], axes[0]] = axes[2]; #assumes the y-indices come out in increasing order
heightMap += 1;
class dequeset(object): class dequeset(object):
def __init__(self): def __init__(self):
self.deque = deque(); self.deque = deque();

View File

@ -9,6 +9,21 @@ from mclevelbase import *
import tempfile import tempfile
from collections import defaultdict from collections import defaultdict
def extractLightMap(materials, blocks, heightMap = None):
"""Computes the HeightMap array for a chunk, which stores the lowest
y-coordinate of each column where the sunlight is still at full strength."""
if heightMap is None:
heightMap = zeros((16, 16), 'uint8')
heightMap[:] = 0;
lightAbsorption = materials.lightAbsorption[blocks]
axes = lightAbsorption.nonzero()
heightMap[axes[1], axes[0]] = axes[2]; #assumes the y-indices come out in increasing order
heightMap += 1;
return heightMap
class MCLevel(object): class MCLevel(object):
""" MCLevel is an abstract class providing many routines to the different level types, """ MCLevel is an abstract class providing many routines to the different level types,
including a common copyEntitiesFrom built on class-specific routines, and including a common copyEntitiesFrom built on class-specific routines, and
@ -143,7 +158,13 @@ class MCLevel(object):
def chunkChanged(self):pass def chunkChanged(self):pass
@property @property
def materials(self): return self.world.materials def materials(self): return self.world.materials
@property
def HeightMap(self):
if hasattr(self, "_heightMap"):
return self._heightMap
self._heightMap = extractLightMap(self.materials, self.Blocks)
return self._heightMap
f = FakeChunk() f = FakeChunk()
f.world = self; f.world = self;
f.chunkPosition = (cx, cz) f.chunkPosition = (cx, cz)

View File

@ -102,4 +102,4 @@ else:
saveFileDir = os.path.join(minecraftDir, u"saves") saveFileDir = os.path.join(minecraftDir, u"saves")
from level import MCLevel, EntityLevel from level import MCLevel, EntityLevel, extractLightMap