mirror of
https://github.com/quantum5/punyverse.git
synced 2025-04-24 13:11:57 -04:00
Removed the hack module framedata.
This commit is contained in:
parent
a9aabc7465
commit
70e12f180d
|
@ -1,4 +1,3 @@
|
||||||
from punyverse import framedata
|
|
||||||
from punyverse.orbit import KeplerOrbit
|
from punyverse.orbit import KeplerOrbit
|
||||||
|
|
||||||
from pyglet.gl import *
|
from pyglet.gl import *
|
||||||
|
@ -36,16 +35,17 @@ class Body(Entity):
|
||||||
self.cloudmap = kwargs.pop('cloudmap', 0)
|
self.cloudmap = kwargs.pop('cloudmap', 0)
|
||||||
self.last_tick = 0
|
self.last_tick = 0
|
||||||
self.mass = kwargs.pop('mass', None)
|
self.mass = kwargs.pop('mass', None)
|
||||||
|
self.world = kwargs.pop('world')
|
||||||
super(Body, self).__init__(*args, **kwargs)
|
super(Body, self).__init__(*args, **kwargs)
|
||||||
self.initial_roll = self.rotation[2]
|
self.initial_roll = self.rotation[2]
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
super(Body, self).update()
|
super(Body, self).update()
|
||||||
|
|
||||||
if self.last_tick != framedata.tick:
|
if self.last_tick != self.world.tick:
|
||||||
self.last_tick = framedata.tick
|
self.last_tick = self.world.tick
|
||||||
pitch, yaw, roll = self.rotation
|
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.rotation = pitch, yaw, roll
|
||||||
|
|
||||||
|
|
||||||
|
@ -105,15 +105,15 @@ class Satellite(Body):
|
||||||
def update(self):
|
def update(self):
|
||||||
super(Body, self).update() # Notice how the parent class is skipped
|
super(Body, self).update() # Notice how the parent class is skipped
|
||||||
|
|
||||||
if self.last_tick != framedata.tick:
|
if self.last_tick != self.world.tick:
|
||||||
self.last_tick = framedata.tick
|
self.last_tick = self.world.tick
|
||||||
pitch, yaw, roll = self.rotation
|
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.rotation = pitch, yaw, roll
|
||||||
|
|
||||||
self.parent.update()
|
self.parent.update()
|
||||||
px, py, pz = self.parent.location
|
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)
|
x, z, y = self.orbit.orbit(self.theta)
|
||||||
self.location = (x + px, y + py, z + pz)
|
self.location = (x + px, y + py, z + pz)
|
||||||
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
tick = 0
|
|
|
@ -22,7 +22,6 @@ except ImportError:
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
from punyverse.glgeom import *
|
from punyverse.glgeom import *
|
||||||
from punyverse import framedata
|
|
||||||
|
|
||||||
from math import *
|
from math import *
|
||||||
import time
|
import time
|
||||||
|
@ -56,7 +55,7 @@ class Applet(pyglet.window.Window):
|
||||||
cam.move(self.speed)
|
cam.move(self.speed)
|
||||||
|
|
||||||
if self.running:
|
if self.running:
|
||||||
framedata.tick += self.tick
|
self.world.tick += self.tick
|
||||||
for entity in self.world.tracker:
|
for entity in self.world.tracker:
|
||||||
entity.update()
|
entity.update()
|
||||||
|
|
||||||
|
@ -72,11 +71,20 @@ class Applet(pyglet.window.Window):
|
||||||
self.orbit = True
|
self.orbit = True
|
||||||
self.running = 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
|
# 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
|
# 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,
|
# and yes the individual hours and seconds look ugly
|
||||||
7300, 18250, 36500, 73000, 182500, 365000]
|
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_cache = None
|
||||||
self.__time_per_second_value = None
|
self.__time_per_second_value = None
|
||||||
|
|
||||||
|
@ -222,14 +230,14 @@ class Applet(pyglet.window.Window):
|
||||||
def get_time_per_second(self):
|
def get_time_per_second(self):
|
||||||
if self.__time_per_second_cache == self.tick:
|
if self.__time_per_second_cache == self.tick:
|
||||||
return self.__time_per_second_value
|
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'
|
unit = 'seconds'
|
||||||
for size, name in ((60, 'minutes'), (60, 'hours'), (24, 'days'), (365, 'years')):
|
for size, name in ((60, 'minutes'), (60, 'hours'), (24, 'days'), (365, 'years')):
|
||||||
if time < size:
|
if time < size:
|
||||||
break
|
break
|
||||||
time /= size
|
time /= size
|
||||||
unit = name
|
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_cache = self.tick
|
||||||
self.__time_per_second_value = result
|
self.__time_per_second_value = result
|
||||||
return result
|
return result
|
||||||
|
@ -321,10 +329,10 @@ class Applet(pyglet.window.Window):
|
||||||
if self.info:
|
if self.info:
|
||||||
ortho(width, height)
|
ortho(width, height)
|
||||||
|
|
||||||
self.label.text = ('%d FPS @ (x=%.2f, y=%.2f, z=%.2f) @ %s, %s/second\n'
|
self.label.text = ('%d FPS @ (x=%.2f, y=%.2f, z=%.2f) @ %s, %s/s\n'
|
||||||
'Direction(pitch=%.2f, yaw=%.2f, roll=%.2f)' %
|
'Direction(pitch=%.2f, yaw=%.2f, roll=%.2f)\nTick: %d' %
|
||||||
(self.fps, c.x, c.y, c.z, self.speed, self.get_time_per_second(),
|
(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()
|
self.label.draw()
|
||||||
|
|
||||||
glPushAttrib(GL_CURRENT_BIT | GL_LINE_BIT)
|
glPushAttrib(GL_CURRENT_BIT | GL_LINE_BIT)
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
"model": "used to load a wavefront object instead of a textured sphere"
|
"model": "used to load a wavefront object instead of a textured sphere"
|
||||||
},
|
},
|
||||||
"au": 10000,
|
"au": 10000,
|
||||||
"tick": 432,
|
"tick": 180,
|
||||||
"length": 63.7,
|
"length": 63.7,
|
||||||
"bodies": {
|
"bodies": {
|
||||||
"earth": {
|
"earth": {
|
||||||
|
|
|
@ -62,7 +62,7 @@ def load_world(file):
|
||||||
e = lambda x: eval(str(x), {'__builtins__': None}, {'AU': root.get('au', 2000)})
|
e = lambda x: eval(str(x), {'__builtins__': None}, {'AU': root.get('au', 2000)})
|
||||||
tick = root.get('tick', 4320) # How many second is a tick?
|
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
|
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:
|
if 'start' in root:
|
||||||
info = root['start']
|
info = root['start']
|
||||||
|
@ -103,7 +103,7 @@ def load_world(file):
|
||||||
else:
|
else:
|
||||||
print 'Nothing to load for %s.' % name
|
print 'Nothing to load for %s.' % name
|
||||||
|
|
||||||
params = {}
|
params = {'world': world}
|
||||||
if parent is None:
|
if parent is None:
|
||||||
type = Body
|
type = Body
|
||||||
else:
|
else:
|
||||||
|
@ -112,7 +112,7 @@ def load_world(file):
|
||||||
sma = e(info.get('sma', distance)) # Semi-major axis used to calculate orbital speed
|
sma = e(info.get('sma', distance)) # Semi-major axis used to calculate orbital speed
|
||||||
if hasattr(parent, 'mass') and parent.mass is not None:
|
if hasattr(parent, 'mass') and parent.mass is not None:
|
||||||
period = 2 * pi * sqrt((sma * 1000) ** 3 / (G * parent.mass))
|
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
|
if not rotation: # Rotation = 0 assumes tidal lock
|
||||||
rotation = period
|
rotation = period
|
||||||
else:
|
else:
|
||||||
|
@ -142,7 +142,7 @@ def load_world(file):
|
||||||
if not cheap:
|
if not cheap:
|
||||||
atmosphere_id = compile(disk, radius, radius + size, 30, atm_texture)
|
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)
|
atmosphere=atmosphere_id, cloudmap=cloudmap_id, background=background, **params)
|
||||||
world.tracker.append(object)
|
world.tracker.append(object)
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ def load_world(file):
|
||||||
if not cheap:
|
if not cheap:
|
||||||
world.tracker.append(
|
world.tracker.append(
|
||||||
type(compile(disk, distance, distance + size, 30, texture), (x, y, z),
|
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():
|
for satellite, info in info.get('satellites', {}).iteritems():
|
||||||
print "Loading %s, satellite of %s." % (satellite, name)
|
print "Loading %s, satellite of %s." % (satellite, name)
|
||||||
|
@ -180,4 +180,5 @@ class World(object):
|
||||||
self.x = None
|
self.x = None
|
||||||
self.y = None
|
self.y = None
|
||||||
self.z = None
|
self.z = None
|
||||||
self.tick = 1
|
self.tick_length = 1
|
||||||
|
self.tick = 0
|
||||||
|
|
Loading…
Reference in a new issue