Skip to content

Commit

Permalink
Sectors: Changed size from 8xINFx8 -> 8x8x8
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Nebual committed Apr 14, 2013
1 parent 79fe017 commit d2a94b1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
24 changes: 10 additions & 14 deletions world.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d2a94b1

Please sign in to comment.