From d2a94b17a4d09bfaa1e5bdb16b019e055b706a33 Mon Sep 17 00:00:00 2001 From: Nebual Date: Sun, 14 Apr 2013 01:39:12 -0700 Subject: [PATCH] Sectors: Changed size from 8xINFx8 -> 8x8x8 This means you can build as high or low as you like, vertical travel is equivalent to horizontal travel performance wise. Also optimized world.change_sectors --- controllers.py | 2 +- world.py | 24 ++++++++++-------------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/controllers.py b/controllers.py index 7c32bff0..53cdb142 100644 --- a/controllers.py +++ b/controllers.py @@ -117,7 +117,7 @@ def __init__(self, window): def update(self, dt): sector = sectorize(self.player.position) if sector != self.sector: - self.model.change_sectors(self.sector, sector) + self.model.change_sectors(sector) # When the world is loaded, show every visible sector. if self.sector is None: self.model.process_entire_queue() diff --git a/world.py b/world.py index f38cb7b5..9d53ae9e 100644 --- a/world.py +++ b/world.py @@ -76,7 +76,7 @@ def sectorize(position): x, y, z = (x / G.SECTOR_SIZE, y / G.SECTOR_SIZE, z / G.SECTOR_SIZE) - return x, 0, z + return x, y, z class TextureGroup(pyglet.graphics.Group): @@ -108,6 +108,7 @@ def __init__(self): self.shown = {} self._shown = {} self.sectors = defaultdict(list) + self.before_set = set() self.urgent_queue = deque() self.lazy_queue = deque() @@ -286,27 +287,22 @@ def _hide_sector(self, sector): if position in self.shown: self.hide_block(position) - def change_sectors(self, before, after): - before_set = set() + def change_sectors(self, after): + before_set = self.before_set after_set = set() pad = G.VISIBLE_SECTORS_RADIUS + x, y, z = after for dx in xrange(-pad, pad + 1): - for dy in (0,): # xrange(-pad, pad + 1): + for dy in xrange(-2, 2): for dz in xrange(-pad, pad + 1): if dx ** 2 + dy ** 2 + dz ** 2 > (pad + 1) ** 2: continue - if before: - x, y, z = before - before_set.add((x + dx, y + dy, z + dz)) - if after: - x, y, z = after - after_set.add((x + dx, y + dy, z + dz)) - show = after_set - before_set - hide = before_set - after_set - for sector in show: + after_set.add((x + dx, y + dy, z + dz)) + for sector in (after_set - before_set): self.show_sector(sector) - for sector in hide: + for sector in (before_set - after_set): self.hide_sector(sector) + self.before_set = after_set def enqueue(self, func, *args, **kwargs): task = func, args, kwargs