From d1bd66f463a4078db4a1b692f1402959e4339b81 Mon Sep 17 00:00:00 2001 From: Quantum Date: Tue, 29 Oct 2013 18:52:35 -0400 Subject: [PATCH] Added launcher generation and fixed all imports. --- .gitignore | 6 ++++++ bootloader.py | 24 +++++++++++++++++++++ launcher.py | 42 ++++++++++++++++++++++++++++++++++++ punyverse/__main__.pyw | 4 ++-- punyverse/_glgeom.pyx | 4 ++-- punyverse/_model.c | 37 ++++++++++++++++--------------- punyverse/_model.pyx | 2 +- punyverse/game.py | 49 ++++++++++++++++++------------------------ punyverse/glgeom.py | 15 +++++++------ punyverse/model.py | 2 +- punyverse/texture.py | 1 - punyverse/widgets.py | 33 ---------------------------- punyverse/world.py | 8 +++---- 13 files changed, 131 insertions(+), 96 deletions(-) create mode 100644 bootloader.py create mode 100644 launcher.py delete mode 100644 punyverse/widgets.py diff --git a/.gitignore b/.gitignore index 8fbed53..120a7bb 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,9 @@ punyverse/assets/textures/*_small.* punyverse/assets/textures/*/*_medium.* punyverse/assets/textures/*/*_small.* temp + +# There is a py2exe package that can execute punyverse directly +library.zip +*.exe +*.log +*.dll diff --git a/bootloader.py b/bootloader.py new file mode 100644 index 0000000..9cb3337 --- /dev/null +++ b/bootloader.py @@ -0,0 +1,24 @@ +import pyglet +import json +import os +import sys +import uuid + +def is_frozen(): + import imp + return (hasattr(sys, 'frozen') or # new py2exe + hasattr(sys, 'importers') # old py2exe + or imp.is_frozen('__main__')) # tools/freeze + +if __name__ == '__main__': + if not is_frozen(): + sys.exit('This is only meant to be ran frozen.') + + sys.path.insert(0, os.path.dirname(sys.executable)) + + import punyverse._model + import punyverse._glgeom + + with open('punyverse\__main__.py', 'r') as f: + code = f.read() + exec(code) diff --git a/launcher.py b/launcher.py new file mode 100644 index 0000000..2664caf --- /dev/null +++ b/launcher.py @@ -0,0 +1,42 @@ +from distutils.core import setup +import py2exe +from glob import glob +import sys +import os +import shutil + +sys.argv.append('py2exe') + +data = [] + +parent = os.path.dirname(__file__) +join = os.path.join + +resources = [(r'punyverse\assets\textures', ['*.*']), + (r'punyverse\assets\textures\moons', ['*.*']), + (r'punyverse\assets\models\asteroids', ['*.obj', '*.mtl']), + (r'punyverse\assets\models\satellites', ['*.jpg', '*.obj', '*.mtl']), + (r'punyverse', ['*.py', '*.json', '*.pyx', '*.pxi', '*.pyd'])] + +for res in resources: + dir, patterns = res + for pattern in patterns: + for file in glob(join(dir, pattern)): + data.append((dir, [join(parent, file)])) + +setup( + console=[{'dest_base': 'punyverse_debug', 'script': 'bootloader.py'}], + windows=[{'dest_base': 'punyverse', 'script': 'bootloader.py'}], + data_files=data, + options={'py2exe': { + 'unbuffered': True, 'optimize': 2, + 'excludes': [ + '_ssl', 'unittest', 'doctest', 'PIL', 'email', 'distutils', + 'pyglet.window.carbon', 'pyglet.window.xlib', + 'pyglet.media.drivers.alsa', + 'win32wnet', 'netbios' + ], + 'dll_excludes': ['MPR.dll', 'w9xpopen.exe'], + } + } +) diff --git a/punyverse/__main__.pyw b/punyverse/__main__.pyw index f899d31..fe82b21 100644 --- a/punyverse/__main__.pyw +++ b/punyverse/__main__.pyw @@ -1,4 +1,4 @@ -from space_torus.__main__ import main +from punyverse.__main__ import main if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/punyverse/_glgeom.pyx b/punyverse/_glgeom.pyx index 5e0813e..639d0b8 100644 --- a/punyverse/_glgeom.pyx +++ b/punyverse/_glgeom.pyx @@ -13,9 +13,9 @@ cdef extern from "Python.h": @cython.cdivision(True) cpdef torus(float major_radius, float minor_radius, int n_major, int n_minor, tuple material, int shininess=125): - ''' + """ Torus function from the OpenGL red book. - ''' + """ glPushAttrib(GL_CURRENT_BIT) glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, [material[0], material[1], material[2], material[3]]) glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [1, 1, 1, 1]) diff --git a/punyverse/_model.c b/punyverse/_model.c index e71f630..586cfa4 100644 --- a/punyverse/_model.c +++ b/punyverse/_model.c @@ -1,4 +1,4 @@ -/* Generated by Cython 0.18 on Sat Oct 26 23:48:35 2013 */ +/* Generated by Cython 0.18 on Tue Oct 29 17:52:33 2013 */ #define PY_SSIZE_T_CLEAN #include "Python.h" @@ -1532,8 +1532,9 @@ static char __pyx_k_4[] = "/"; static char __pyx_k_6[] = "Warning: material %s undefined, only %s defined."; static char __pyx_k_7[] = "Warning: no group"; static char __pyx_k_8[] = "No such file or directory: '%s'"; -static char __pyx_k_14[] = "D:\\dev\\punyverse\\punyverse\\_model.pyx"; -static char __pyx_k_15[] = "punyverse._model"; +static char __pyx_k_12[] = "punyverse.texture"; +static char __pyx_k_15[] = "D:\\dev\\punyverse\\punyverse\\_model.pyx"; +static char __pyx_k_16[] = "punyverse._model"; static char __pyx_k__Ka[] = "Ka"; static char __pyx_k__Kd[] = "Kd"; static char __pyx_k__Ks[] = "Ks"; @@ -1581,8 +1582,9 @@ static char __pyx_k__shininess[] = "shininess"; static char __pyx_k__load_model[] = "load_model"; static char __pyx_k__load_texture[] = "load_texture"; static char __pyx_k__AttributeError[] = "AttributeError"; -static PyObject *__pyx_kp_s_14; -static PyObject *__pyx_n_s_15; +static PyObject *__pyx_n_s_12; +static PyObject *__pyx_kp_s_15; +static PyObject *__pyx_n_s_16; static PyObject *__pyx_kp_s_4; static PyObject *__pyx_kp_s_6; static PyObject *__pyx_kp_s_7; @@ -1640,8 +1642,8 @@ static PyObject *__pyx_k_tuple_5; static PyObject *__pyx_k_tuple_9; static PyObject *__pyx_k_tuple_10; static PyObject *__pyx_k_tuple_11; -static PyObject *__pyx_k_tuple_12; -static PyObject *__pyx_k_codeobj_13; +static PyObject *__pyx_k_tuple_13; +static PyObject *__pyx_k_codeobj_14; /* Python wrapper */ static int __pyx_pw_9punyverse_6_model_4Face_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ @@ -10729,8 +10731,9 @@ static struct PyModuleDef __pyx_moduledef = { #endif static __Pyx_StringTabEntry __pyx_string_tab[] = { - {&__pyx_kp_s_14, __pyx_k_14, sizeof(__pyx_k_14), 0, 0, 1, 0}, - {&__pyx_n_s_15, __pyx_k_15, sizeof(__pyx_k_15), 0, 0, 1, 1}, + {&__pyx_n_s_12, __pyx_k_12, sizeof(__pyx_k_12), 0, 0, 1, 1}, + {&__pyx_kp_s_15, __pyx_k_15, sizeof(__pyx_k_15), 0, 0, 1, 0}, + {&__pyx_n_s_16, __pyx_k_16, sizeof(__pyx_k_16), 0, 0, 1, 1}, {&__pyx_kp_s_4, __pyx_k_4, sizeof(__pyx_k_4), 0, 0, 1, 0}, {&__pyx_kp_s_6, __pyx_k_6, sizeof(__pyx_k_6), 0, 0, 1, 0}, {&__pyx_kp_s_7, __pyx_k_7, sizeof(__pyx_k_7), 0, 0, 1, 0}, @@ -10865,10 +10868,10 @@ static int __Pyx_InitCachedConstants(void) { * path = os.path.join(os.path.dirname(__file__), 'assets', 'models', path) * if not isinstance(path, unicode): */ - __pyx_k_tuple_12 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__path)); if (unlikely(!__pyx_k_tuple_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_12); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_12)); - __pyx_k_codeobj_13 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_12, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_14, __pyx_n_s__load_model, 260, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_13 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__path)); if (unlikely(!__pyx_k_tuple_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_13); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_13)); + __pyx_k_codeobj_14 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_13, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_15, __pyx_n_s__load_model, 260, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -10996,7 +10999,7 @@ PyMODINIT_FUNC PyInit__model(void) /* "punyverse\_model.pyx":6 * cimport cython * - * from texture import load_texture # <<<<<<<<<<<<<< + * from punyverse.texture import load_texture # <<<<<<<<<<<<<< * include "_cyopengl.pxi" * from uuid import uuid4 */ @@ -11005,7 +11008,7 @@ PyMODINIT_FUNC PyInit__model(void) __Pyx_INCREF(((PyObject *)__pyx_n_s__load_texture)); PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__load_texture)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__load_texture)); - __pyx_t_2 = __Pyx_Import(((PyObject *)__pyx_n_s__texture), ((PyObject *)__pyx_t_1), -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_Import(((PyObject *)__pyx_n_s_12), ((PyObject *)__pyx_t_1), -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__load_texture); @@ -11026,7 +11029,7 @@ PyMODINIT_FUNC PyInit__model(void) __pyx_v_9punyverse_6_model_GLU_TESS_MAX_COORD = 1.0e150; /* "punyverse\_model.pyx":8 - * from texture import load_texture + * from punyverse.texture import load_texture * include "_cyopengl.pxi" * from uuid import uuid4 # <<<<<<<<<<<<<< * import os @@ -11069,7 +11072,7 @@ PyMODINIT_FUNC PyInit__model(void) * path = os.path.join(os.path.dirname(__file__), 'assets', 'models', path) * if not isinstance(path, unicode): */ - __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_9punyverse_6_model_1load_model, NULL, __pyx_n_s_15); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_9punyverse_6_model_1load_model, NULL, __pyx_n_s_16); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyObject_SetAttr(__pyx_m, __pyx_n_s__load_model, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; diff --git a/punyverse/_model.pyx b/punyverse/_model.pyx index 53fa708..f218400 100644 --- a/punyverse/_model.pyx +++ b/punyverse/_model.pyx @@ -3,7 +3,7 @@ from libc.stdlib cimport malloc, free, atof from libc.stdio cimport fopen, fclose, fgets, FILE cimport cython -from texture import load_texture +from punyverse.texture import load_texture include "_cyopengl.pxi" from uuid import uuid4 import os diff --git a/punyverse/game.py b/punyverse/game.py index f0b20f3..b2aa056 100644 --- a/punyverse/game.py +++ b/punyverse/game.py @@ -1,36 +1,29 @@ #!/usr/bin/python from operator import attrgetter -import sys - -from camera import Camera -from widgets import * - -try: - from _model import * -except ImportError: - from model import * -from world import * -import texture - -try: - from pyglet.gl import * - from pyglet.gl.glu import * - from pyglet.window import key, mouse - import pyglet -except ImportError: - print "Pyglet not installed correctly, or at all." - sys.exit() - -from punyverse.glgeom import * - -from math import * +from math import hypot, sqrt, atan2, degrees +from time import clock import time import random -from time import clock -INITIAL_SPEED = 0 # The initial speed of the player -TICKS_PER_SECOND = 20 # How many times to update game per second -MOUSE_SENSITIVITY = 0.3 # Mouse sensitivity, 0..1, none...hyperspeed +from punyverse.camera import Camera +from punyverse.world import load_world +from punyverse.glgeom import * +from punyverse.entity import Asteroid +from punyverse import texture + +try: + from punyverse._model import model_list, load_model +except ImportError: + from punyverse.model import model_list, load_model + +from pyglet.gl import * +from pyglet.window import key +import pyglet + + +INITIAL_SPEED = 0 # The initial speed of the player +TICKS_PER_SECOND = 20 # How many times to update game per second +MOUSE_SENSITIVITY = 0.3 # Mouse sensitivity, 0..1, none...hyperspeed MAX_DELTA = 5 SEED = int(time.time()) diff --git a/punyverse/glgeom.py b/punyverse/glgeom.py index 3a48b33..f1003d1 100644 --- a/punyverse/glgeom.py +++ b/punyverse/glgeom.py @@ -1,9 +1,10 @@ from math import * from pyglet.gl import * -from pyglet.gl.glu import * TWOPI = pi * 2 +__all__ = ['compile', 'ortho', 'frustrum', 'crosshair', 'circle', 'disk', 'sphere', 'colourball', 'torus'] + def compile(pointer, *args, **kwargs): display = glGenLists(1) @@ -76,9 +77,9 @@ def disk(rinner, router, segs, tex): def sphere(r, lats, longs, tex, lighting=True, fv4=GLfloat * 4): - ''' + """ Sphere function from the OpenGL red book. - ''' + """ sphere = gluNewQuadric() gluQuadricDrawStyle(sphere, GLU_FILL) gluQuadricTexture(sphere, True) @@ -105,9 +106,9 @@ def sphere(r, lats, longs, tex, lighting=True, fv4=GLfloat * 4): def colourball(r, lats, longs, colour, fv4=GLfloat * 4): - ''' + """ Sphere function from the OpenGL red book. - ''' + """ sphere = gluNewQuadric() glDisable(GL_BLEND) @@ -125,9 +126,9 @@ try: from _glgeom import torus except ImportError: def torus(major_radius, minor_radius, n_major, n_minor, material, shininess=125, fv4=GLfloat * 4): - ''' + """ Torus function from the OpenGL red book. - ''' + """ glPushAttrib(GL_CURRENT_BIT) glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, fv4(*material)) glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, fv4(1, 1, 1, 1)) diff --git a/punyverse/model.py b/punyverse/model.py index 0d020d7..fcaacee 100644 --- a/punyverse/model.py +++ b/punyverse/model.py @@ -63,7 +63,7 @@ def model_list(model, sx=1, sy=1, sz=1, rotation=(0, 0, 0)): if f.norms: glNormal3f(*normals[f.norms[n]]) if tex_id: - glTexCoord2f(*textures[f.texs[n]]) + glTexCoord2f(*textures[f.texs[n]][:2]) x, y, z = vertices[f.verts[n]] glVertex3f(x * sx, y * sy, z * sz) diff --git a/punyverse/texture.py b/punyverse/texture.py index 33369d4..57bd805 100644 --- a/punyverse/texture.py +++ b/punyverse/texture.py @@ -18,7 +18,6 @@ except ImportError: else: magick = True - def bgr_to_rgb(source, width, height, alpha=False, bottom_up=True): length = len(source) depth = length / (width * height) diff --git a/punyverse/widgets.py b/punyverse/widgets.py deleted file mode 100644 index 621ac1d..0000000 --- a/punyverse/widgets.py +++ /dev/null @@ -1,33 +0,0 @@ -from pyglet.gl import * - -VERTICAL = 0 -HORIZONTAL = 1 - - -def _progress_bar_vertices(x, y, w, h): - glColor3f(1, 1, 1) - glVertex2f(x, y) - glVertex2f(x + w, y) - - glColor3f(0, 0, 1) - glVertex2f(x + w, y + h) - glVertex2f(x, y + h) - - -def progress_bar(x, y, width, height, progress, min=0, max=100, type=HORIZONTAL): - glPushAttrib(GL_CURRENT_BIT | GL_LINE_BIT) - - glLineWidth(1) - glBegin(GL_LINE_LOOP) - if type == VERTICAL: - _progress_bar_vertices(x, y, width, height * max) - else: - _progress_bar_vertices(x, y, width * max, height) - glEnd() - glBegin(GL_QUADS) - if type == VERTICAL: - _progress_bar_vertices(x, y, width, height * progress) - else: - _progress_bar_vertices(x, y, width * max, height) - glEnd() - glPopAttrib() \ No newline at end of file diff --git a/punyverse/world.py b/punyverse/world.py index 6495f1e..dfafeef 100644 --- a/punyverse/world.py +++ b/punyverse/world.py @@ -1,5 +1,4 @@ from collections import OrderedDict -from functools import partial import os.path try: @@ -8,12 +7,12 @@ except ImportError: try: import simplejson as json except ImportError: - print "No compatible JSON decoder found. Translation: you're fucked." + raise SystemExit('No JSON module found') try: - from _model import model_list, load_model + from punyverse._model import model_list, load_model except ImportError: - from model import model_list, load_model + from punyverse.model import model_list, load_model from punyverse.glgeom import * from punyverse.entity import * @@ -104,6 +103,7 @@ def load_world(file): info.get('sz', scale), (0, 0, 0)) else: print 'Nothing to load for %s.' % name + return params = {'world': world, 'orbit_distance': orbit_distance} if parent is None: