From 70e12f180deaffee21add10af5140bc82b3148fe Mon Sep 17 00:00:00 2001 From: Quantum Date: Mon, 28 Oct 2013 18:01:58 -0400 Subject: [PATCH] Removed the hack module framedata. --- punyverse/entity.py | 16 ++++++++-------- punyverse/framedata.py | 1 - punyverse/game.py | 28 ++++++++++++++++++---------- punyverse/world.json | 2 +- punyverse/world.py | 13 +++++++------ 5 files changed, 34 insertions(+), 26 deletions(-) delete mode 100644 punyverse/framedata.py diff --git a/punyverse/entity.py b/punyverse/entity.py index 7fe5b54..300e788 100644 --- a/punyverse/entity.py +++ b/punyverse/entity.py @@ -1,4 +1,3 @@ -from punyverse import framedata from punyverse.orbit import KeplerOrbit from pyglet.gl import * @@ -36,16 +35,17 @@ class Body(Entity): self.cloudmap = kwargs.pop('cloudmap', 0) self.last_tick = 0 self.mass = kwargs.pop('mass', None) + self.world = kwargs.pop('world') super(Body, self).__init__(*args, **kwargs) self.initial_roll = self.rotation[2] def update(self): super(Body, self).update() - if self.last_tick != framedata.tick: - self.last_tick = framedata.tick + if self.last_tick != self.world.tick: + self.last_tick = self.world.tick pitch, yaw, roll = self.rotation - roll = (self.initial_roll + framedata.tick * self.rotation_angle) % 360 + roll = (self.initial_roll + self.world.tick * self.rotation_angle) % 360 self.rotation = pitch, yaw, roll @@ -105,15 +105,15 @@ class Satellite(Body): def update(self): super(Body, self).update() # Notice how the parent class is skipped - if self.last_tick != framedata.tick: - self.last_tick = framedata.tick + if self.last_tick != self.world.tick: + self.last_tick = self.world.tick pitch, yaw, roll = self.rotation - roll = (self.initial_roll + framedata.tick * self.rotation_angle) % 360 + roll = (self.initial_roll + self.world.tick * self.rotation_angle) % 360 self.rotation = pitch, yaw, roll self.parent.update() px, py, pz = self.parent.location - self.theta = framedata.tick * self.orbit_speed % 360 + self.theta = self.world.tick * self.orbit_speed % 360 x, z, y = self.orbit.orbit(self.theta) self.location = (x + px, y + py, z + pz) diff --git a/punyverse/framedata.py b/punyverse/framedata.py deleted file mode 100644 index 4f80743..0000000 --- a/punyverse/framedata.py +++ /dev/null @@ -1 +0,0 @@ -tick = 0 \ No newline at end of file diff --git a/punyverse/game.py b/punyverse/game.py index ea06fac..1b02c4f 100644 --- a/punyverse/game.py +++ b/punyverse/game.py @@ -22,7 +22,6 @@ except ImportError: sys.exit() from punyverse.glgeom import * -from punyverse import framedata from math import * import time @@ -56,7 +55,7 @@ class Applet(pyglet.window.Window): cam.move(self.speed) if self.running: - framedata.tick += self.tick + self.world.tick += self.tick for entity in self.world.tracker: entity.update() @@ -72,11 +71,20 @@ class Applet(pyglet.window.Window): self.orbit = True self.running = True - self.tick = 1 + self.tick = self.world.tick_length # On standard world: 10x is one day per second, 100x is 10 days, 300x is a month # 900x is a quarter, 1825 is a half year, 3650 is a year, 36500 is a decade, 365000 is a century - self.ticks = [1, 2, 4, 8, 10, 15, 25, 36, 50, 100, 300, 900, 1825, 3650, - 7300, 18250, 36500, 73000, 182500, 365000] + # and yes the individual hours and seconds look ugly + self.ticks = [20, 40, 60, # Second range + 120, 300, 600, 1200, 1800, 2700, 3600, # Minute range + 7200, 14400, 21600, 43200, 86400, # Hour range + 172800, 432000, 604800, # 2, 5, 7 days + 1209600, 2592000, # 2 week, 1 month + 5270400, 7884000, 15768000, 31536000, # 2, 3, 6, 12 months + 63072000, 157680000, 315360000, # 2, 5, 10 years + 630720000, 1576800000, 3153600000, # 20, 50, 100 years + ] + self.ticks = [i / 20 for i in self.ticks] self.__time_per_second_cache = None self.__time_per_second_value = None @@ -222,14 +230,14 @@ class Applet(pyglet.window.Window): def get_time_per_second(self): if self.__time_per_second_cache == self.tick: return self.__time_per_second_value - time = self.world.tick * self.tick * TICKS_PER_SECOND + .0 + time = self.tick * TICKS_PER_SECOND + .0 unit = 'seconds' for size, name in ((60, 'minutes'), (60, 'hours'), (24, 'days'), (365, 'years')): if time < size: break time /= size unit = name - result = '%s %s' % (time, unit) + result = '%s %s' % (round(time, 1), unit) self.__time_per_second_cache = self.tick self.__time_per_second_value = result return result @@ -321,10 +329,10 @@ class Applet(pyglet.window.Window): if self.info: ortho(width, height) - self.label.text = ('%d FPS @ (x=%.2f, y=%.2f, z=%.2f) @ %s, %s/second\n' - 'Direction(pitch=%.2f, yaw=%.2f, roll=%.2f)' % + self.label.text = ('%d FPS @ (x=%.2f, y=%.2f, z=%.2f) @ %s, %s/s\n' + 'Direction(pitch=%.2f, yaw=%.2f, roll=%.2f)\nTick: %d' % (self.fps, c.x, c.y, c.z, self.speed, self.get_time_per_second(), - c.pitch, c.yaw, c.roll)) + c.pitch, c.yaw, c.roll, self.world.tick)) self.label.draw() glPushAttrib(GL_CURRENT_BIT | GL_LINE_BIT) diff --git a/punyverse/world.json b/punyverse/world.json index b239e10..a3e377d 100644 --- a/punyverse/world.json +++ b/punyverse/world.json @@ -11,7 +11,7 @@ "model": "used to load a wavefront object instead of a textured sphere" }, "au": 10000, - "tick": 432, + "tick": 180, "length": 63.7, "bodies": { "earth": { diff --git a/punyverse/world.py b/punyverse/world.py index cff312a..51d8b7a 100644 --- a/punyverse/world.py +++ b/punyverse/world.py @@ -62,7 +62,7 @@ def load_world(file): e = lambda x: eval(str(x), {'__builtins__': None}, {'AU': root.get('au', 2000)}) tick = root.get('tick', 4320) # How many second is a tick? length = root.get('length', 4320) # Satellite distance is in km, divide by this gets in world units - world.tick = tick + world.tick_length = tick if 'start' in root: info = root['start'] @@ -103,7 +103,7 @@ def load_world(file): else: print 'Nothing to load for %s.' % name - params = {} + params = {'world': world} if parent is None: type = Body else: @@ -112,7 +112,7 @@ def load_world(file): sma = e(info.get('sma', distance)) # Semi-major axis used to calculate orbital speed if hasattr(parent, 'mass') and parent.mass is not None: period = 2 * pi * sqrt((sma * 1000) ** 3 / (G * parent.mass)) - speed = 360 / (period / tick) + speed = 360 / (period + .0) if not rotation: # Rotation = 0 assumes tidal lock rotation = period else: @@ -142,7 +142,7 @@ def load_world(file): if not cheap: atmosphere_id = compile(disk, radius, radius + size, 30, atm_texture) - object = type(object_id, (x, y, z), (pitch, yaw, roll), rotation_angle=360 / (rotation / (tick + .0)), + object = type(object_id, (x, y, z), (pitch, yaw, roll), rotation_angle=360 / (rotation + .0), atmosphere=atmosphere_id, cloudmap=cloudmap_id, background=background, **params) world.tracker.append(object) @@ -159,7 +159,7 @@ def load_world(file): if not cheap: world.tracker.append( type(compile(disk, distance, distance + size, 30, texture), (x, y, z), - (pitch, yaw, roll))) + (pitch, yaw, roll), **params)) for satellite, info in info.get('satellites', {}).iteritems(): print "Loading %s, satellite of %s." % (satellite, name) @@ -180,4 +180,5 @@ class World(object): self.x = None self.y = None self.z = None - self.tick = 1 + self.tick_length = 1 + self.tick = 0