-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpy-universe.py
106 lines (101 loc) · 3.87 KB
/
py-universe.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/python2
# encoding=utf8
# File name: py-universe.py
# This file is part of: pyuni
#
# LICENSE
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.1 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
# the License for the specific language governing rights and limitations
# under the License.
#
# Alternatively, the contents of this file may be used under the terms
# of the GNU General Public license (the "GPL License"), in which case
# the provisions of GPL License are applicable instead of those above.
#
# FEEDBACK & QUESTIONS
#
# For feedback and questions about pyuni please e-mail one of the
# authors named in the AUTHORS file.
########################################################################
"""
Nothing yet.
"""
from __future__ import unicode_literals, print_function, division
# global PyOpenGL flags MUST ONLY be set here.
import OpenGL
OpenGL.ERROR_ON_COPY = True
if __name__ == '__main__':
import argparse
import sys
sys.path.append("PyEngine")
import Engine.CEngine.Window as CWindow
from Engine.CEngine.Log import server as log, Severity
from Client.PythonicUniverse import PythonicUniverse
parser = argparse.ArgumentParser()
parser.add_argument(
"-p", "--profile",
dest="profile",
nargs="?",
const=True,
default=False,
metavar="FILE",
help="Run in cProfile mode. If FILE is given, the cProfile\
output is sent to that file. If FILE is omitted and --profile-shell is\
set, a default of /tmp/pyuniverse-profile is assumed."
)
parser.add_argument(
"-s", "--profile-shell",
dest="profileShell",
action="store_true",
help="In profiling mode, drop into a shell after the\
application terminated. In that shell, the profiling data will be\
available in a pstats variable called p."
)
parser.add_argument(
"-f", "--frame-count",
dest="profileFrames",
type=int,
default=0,
metavar="N",
help="Render exactly N frames and stop then."
)
args = parser.parse_args(sys.argv[1:])
log.log(Severity.Information, "Python initialized")
app = PythonicUniverse(CWindow.display)
if args.profile:
import cProfile
log.log(Severity.Warning, "Running in cProfile mode")
if args.profileShell and args.profile is True:
log.log(Severity.Warning, "No output file defined but shell requested. Defaulting to /tmp/pyuniverse-profile")
args.profile = "/tmp/pyuniverse-profile"
if args.profileFrames:
if args.profileFrames < 0:
raise ValueError("Nice try.")
app._eventLoop.setFrameCount(args.profileFrames)
log.log(Severity.Information, "Will terminate after {0} frames.".format(args.profileFrames))
if args.profile is not True:
log.log(Severity.Information, "cProfile output is going to file: {0}".format(args.profile))
cProfile.run("app.run()", filename=args.profile)
else:
cProfile.run("app.run()")
if args.profileShell:
import code
import pstats
import readline
p = pstats.Stats(args.profile)
def topTimes(n=10):
p.sort_stats("cum").print_stats(n)
namespace = {}
namespace["p"] = p
namespace["app"] = app
namespace["topTimes"] = topTimes
code.InteractiveConsole(namespace).interact("Profiling shell. Stats of the current run are available in the p object. Application state is available in the app object.")
else:
app.run()