Added launcher generation and fixed all imports.

Signed-off-by: Xiaomao Chen <xiaomao5@live.com>
This commit is contained in:
Quantum 2013-10-29 18:52:35 -04:00
parent 118bcd02a7
commit a7ffda822e
13 changed files with 131 additions and 96 deletions

6
.gitignore vendored
View file

@ -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

24
bootloader.py Normal file
View file

@ -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)

42
launcher.py Normal file
View file

@ -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'],
}
}
)

View file

@ -1,4 +1,4 @@
from space_torus.__main__ import main
from punyverse.__main__ import main
if __name__ == '__main__':
main()

View file

@ -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])

View file

@ -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;

View file

@ -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

View file

@ -1,32 +1,25 @@
#!/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
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

View file

@ -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))

View file

@ -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)

View file

@ -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)

View file

@ -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()

View file

@ -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: