From 13867d7fd01da26a7e43384eda188e44e15242c1 Mon Sep 17 00:00:00 2001 From: Quantum Date: Thu, 23 Aug 2018 22:05:56 -0400 Subject: [PATCH] Properly handle background objects. --- punyverse/entity.py | 10 +++++++--- punyverse/game.py | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/punyverse/entity.py b/punyverse/entity.py index f93be59..6f01352 100644 --- a/punyverse/entity.py +++ b/punyverse/entity.py @@ -18,6 +18,8 @@ G = 6.67384e-11 # Gravitation Constant class Entity(object): + background = False + def __init__(self, name, location, rotation=(0, 0, 0), direction=(0, 0, 0)): self.name = name self.location = location @@ -97,6 +99,8 @@ class Belt(Entity): class Sky(Entity): + background = True + def __init__(self, world, info): pitch = world.evaluate(info.get('pitch', 0)) yaw = world.evaluate(info.get('yaw', 0)) @@ -291,7 +295,7 @@ class SphericalBody(Body): glCallList(self.sphere_id) def _draw_atmosphere(self, cam, glMatrixBuffer=GLfloat * 16): - with glMatrix(self.location), glRestore(GL_ENABLE_BIT): + with glMatrix(self.location), glRestore(GL_ENABLE_BIT | GL_CURRENT_BIT): matrix = glMatrixBuffer() glGetFloatv(GL_MODELVIEW_MATRIX, matrix) matrix[0: 3] = [1, 0, 0] @@ -299,17 +303,17 @@ class SphericalBody(Body): matrix[8:11] = [0, 0, 1] glLoadMatrixf(matrix) - glEnable(GL_BLEND) if self.atmosphere_id: glCallList(self.atmosphere_id) if self.corona_id: x, y, z = cam.direction() glTranslatef(-x, -y, -z) + glEnable(GL_BLEND) glCallList(self.corona_id) def _draw_clouds(self): - with glMatrix(self.location, self.rotation), glRestore(GL_ENABLE_BIT): + with glMatrix(self.location, self.rotation), glRestore(GL_ENABLE_BIT | GL_CURRENT_BIT): glEnable(GL_BLEND) glEnable(GL_ALPHA_TEST) glCallList(self.cloudmap_id) diff --git a/punyverse/game.py b/punyverse/game.py index 8efb39b..131d099 100644 --- a/punyverse/game.py +++ b/punyverse/game.py @@ -406,6 +406,7 @@ class Applet(pyglet.window.Window): get_distance = entity_distance(x, y, z) if x != world.x or y != world.y or z != world.z: world.tracker.sort(key=get_distance, reverse=True) + world.tracker.sort(key=attrgetter('background'), reverse=True) world.x, world.y, world.z = x, y, z for entity in world.tracker: