mirror of
https://github.com/quantum5/punyverse.git
synced 2025-04-24 13:11:57 -04:00
Use a proper format for main module.
This commit is contained in:
parent
1b6d422447
commit
3e50d66e91
|
@ -1,55 +1,4 @@
|
|||
#!/usr/bin/python
|
||||
INITIAL_WIN_HEIGHT = 540
|
||||
INITIAL_WIN_WIDTH = 700
|
||||
WIN_TITLE = 'Punyverse'
|
||||
|
||||
|
||||
def main():
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser(prog='punyverse', description='''
|
||||
Python simulator of a puny universe.
|
||||
''')
|
||||
parser.add_argument('-d', '--high-depth', help='Use a larger depth buffer',
|
||||
const=32, default=24, dest='depth', nargs='?', type=int)
|
||||
parser.add_argument('-m', '--multisample', help='Use multisampled image, '
|
||||
'optional samples', const=2, default=0, nargs='?',
|
||||
type=int)
|
||||
parser.add_argument('-v', '--no-vsync', help='Disables vsync',
|
||||
action='store_false', dest='vsync')
|
||||
parser.add_argument('-n', '--normal', help='Enables the use of normal maps',
|
||||
action='store_true')
|
||||
args = parser.parse_args()
|
||||
|
||||
import pyglet
|
||||
pyglet.options['shadow_window'] = False
|
||||
|
||||
template = pyglet.gl.Config(depth_size=args.depth, double_buffer=True,
|
||||
sample_buffers=args.multisample > 1,
|
||||
samples=args.multisample)
|
||||
|
||||
platform = pyglet.window.get_platform()
|
||||
display = platform.get_default_display()
|
||||
screen = display.get_default_screen()
|
||||
try:
|
||||
config = screen.get_best_config(template)
|
||||
except pyglet.window.NoSuchConfigException:
|
||||
raise SystemExit('Graphics configuration not supported.')
|
||||
else:
|
||||
if hasattr(config, '_attribute_names'):
|
||||
print('OpenGL configuration:')
|
||||
for key in config._attribute_names:
|
||||
print(' %-22s %s' % (key + ':', getattr(config, key)))
|
||||
|
||||
world_options = {
|
||||
'normal': args.normal,
|
||||
}
|
||||
|
||||
from punyverse import game
|
||||
game.Applet(width=INITIAL_WIN_WIDTH, height=INITIAL_WIN_HEIGHT,
|
||||
caption=WIN_TITLE, resizable=True, vsync=args.vsync,
|
||||
config=config, world_options=world_options)
|
||||
pyglet.app.run()
|
||||
|
||||
from punyverse.main import main
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -1,4 +1,4 @@
|
|||
from punyverse.__main__ import main
|
||||
from punyverse.main import main
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
#!/usr/bin/python
|
||||
from operator import attrgetter
|
||||
from math import hypot
|
||||
from time import clock
|
||||
import time
|
||||
import os
|
||||
import time
|
||||
from math import hypot
|
||||
from operator import attrgetter
|
||||
from time import clock
|
||||
|
||||
import six
|
||||
|
||||
from punyverse.camera import Camera
|
||||
from punyverse.world import World
|
||||
from punyverse.glgeom import *
|
||||
from punyverse.entity import Asteroid
|
||||
from punyverse import texture
|
||||
from punyverse.camera import Camera
|
||||
from punyverse.entity import Asteroid
|
||||
from punyverse.glgeom import *
|
||||
from punyverse.world import World
|
||||
|
||||
try:
|
||||
from punyverse._model import model_list, load_model
|
||||
|
@ -47,8 +47,6 @@ class Applet(pyglet.window.Window):
|
|||
asteroids = ['asteroids/01.obj', 'asteroids/02.obj', 'asteroids/03.obj']
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.world_options = kwargs.pop('world_options', {})
|
||||
|
||||
super(Applet, self).__init__(*args, **kwargs)
|
||||
texture.init()
|
||||
|
||||
|
@ -94,7 +92,7 @@ class Applet(pyglet.window.Window):
|
|||
def load(self, *args, **kwargs):
|
||||
start = clock()
|
||||
self.fps = 0
|
||||
self.world = World('world.json', self._load_callback, self.world_options)
|
||||
self.world = World('world.json', self._load_callback)
|
||||
self._load_callback('Initializing game...', '', 0)
|
||||
self.speed = INITIAL_SPEED
|
||||
self.keys = set()
|
||||
|
@ -227,7 +225,7 @@ class Applet(pyglet.window.Window):
|
|||
def screenshot(self):
|
||||
image = pyglet.image.get_buffer_manager().get_color_buffer()
|
||||
if hasattr(self, '_hwnd') and not self.modifiers & key.MOD_CTRL:
|
||||
from ctypes import windll, cdll
|
||||
from ctypes import windll
|
||||
from PIL import Image
|
||||
import tempfile
|
||||
CF_BITMAP = 2
|
||||
|
|
52
punyverse/main.py
Normal file
52
punyverse/main.py
Normal file
|
@ -0,0 +1,52 @@
|
|||
import argparse
|
||||
|
||||
import pyglet
|
||||
|
||||
from punyverse import game
|
||||
|
||||
INITIAL_WIN_HEIGHT = 540
|
||||
INITIAL_WIN_WIDTH = 700
|
||||
WIN_TITLE = 'Punyverse'
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(prog='punyverse', description='''
|
||||
Python simulator of a puny universe.
|
||||
''')
|
||||
parser.add_argument('-d', '--high-depth', help='Use a larger depth buffer',
|
||||
const=32, default=24, dest='depth', nargs='?', type=int)
|
||||
parser.add_argument('-m', '--multisample', help='Use multisampled image, optional samples',
|
||||
const=2, default=0, nargs='?', type=int)
|
||||
parser.add_argument('-v', '--no-vsync', help='Disables vsync',
|
||||
action='store_false', dest='vsync')
|
||||
parser.add_argument('-n', '--normal', help='Enables the use of normal maps',
|
||||
action='store_true')
|
||||
args = parser.parse_args()
|
||||
|
||||
pyglet.options['shadow_window'] = False
|
||||
|
||||
template = pyglet.gl.Config(depth_size=args.depth, double_buffer=True,
|
||||
sample_buffers=args.multisample > 1,
|
||||
samples=args.multisample)
|
||||
|
||||
platform = pyglet.window.get_platform()
|
||||
display = platform.get_default_display()
|
||||
screen = display.get_default_screen()
|
||||
try:
|
||||
config = screen.get_best_config(template)
|
||||
except pyglet.window.NoSuchConfigException:
|
||||
raise SystemExit('Graphics configuration not supported.')
|
||||
else:
|
||||
if hasattr(config, '_attribute_names'):
|
||||
print('OpenGL configuration:')
|
||||
for key in config._attribute_names:
|
||||
print(' %-22s %s' % (key + ':', getattr(config, key)))
|
||||
|
||||
game.Applet(width=INITIAL_WIN_WIDTH, height=INITIAL_WIN_HEIGHT,
|
||||
caption=WIN_TITLE, resizable=True, vsync=args.vsync,
|
||||
config=config)
|
||||
pyglet.app.run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -20,7 +20,7 @@ def load_world(file, callback=lambda message, completion: None):
|
|||
|
||||
|
||||
class World(object):
|
||||
def __init__(self, file, callback, options=None):
|
||||
def __init__(self, file, callback):
|
||||
self.tracker = []
|
||||
self.start = (0, 0, 0)
|
||||
self.direction = (0, 0, 0)
|
||||
|
@ -31,9 +31,8 @@ class World(object):
|
|||
self.tick = 0
|
||||
|
||||
self.callback = callback
|
||||
self.options = options or {}
|
||||
self._parse(file)
|
||||
del self.callback # So it can't be used after loading finishes
|
||||
del self.callback # So it can't be used after loading finishes
|
||||
|
||||
def evaluate(self, value):
|
||||
return eval(str(value), {'__builtins__': None}, self._context)
|
||||
|
|
7
setup.py
7
setup.py
|
@ -1,6 +1,7 @@
|
|||
from __future__ import print_function
|
||||
import sys
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
from setuptools import setup, Extension
|
||||
|
||||
|
@ -55,11 +56,11 @@ setup(
|
|||
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'punyverse = punyverse.__main__:main',
|
||||
'punyverse = punyverse.main:main',
|
||||
'punyverse_small_images = punyverse.small_images:main',
|
||||
],
|
||||
'gui_scripts': [
|
||||
'punyversew = punyverse.__main__:main'
|
||||
'punyversew = punyverse.main:main'
|
||||
]
|
||||
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue