1
#####################################################################
2
# -*- coding: iso-8859-1 -*- #
5
# Copyright (C) 2006 Sami Ky�stil� #
7
# This program is free software; you can redistribute it and/or #
8
# modify it under the terms of the GNU General Public License #
9
# as published by the Free Software Foundation; either version 2 #
10
# of the License, or (at your option) any later version. #
12
# This program is distributed in the hope that it will be useful, #
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15
# GNU General Public License for more details. #
17
# You should have received a copy of the GNU General Public License #
18
# along with this program; if not, write to the Free Software #
19
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, #
20
# MA 02110-1301, USA. #
21
#####################################################################
23
from OpenGL.GL import *
24
from View import Layer
36
class DebugLayer(Layer):
37
"""A layer for showing some debug information."""
38
def __init__(self, engine):
40
#gc.set_debug(gc.DEBUG_LEAK)
42
def className(self, instance):
43
return str(instance.__class__).split(".")[1]
45
def render(self, visibility, topMost):
46
self.engine.view.setOrthogonalProjection(normalize = True)
49
font = self.engine.data.font
51
glColor3f(.25, 1, .25)
54
h = font.getHeight() * scale
56
font.render("Tasks:", (x, y), scale = scale)
57
for task in self.engine.tasks + self.engine.frameTasks:
58
font.render(self.className(task), (x + .1, y), scale = scale)
62
font.render("Layers:", (x, y), scale = scale)
63
for layer in self.engine.view.layers + self.engine.view.incoming + self.engine.view.outgoing + self.engine.view.visibility.keys():
64
font.render(self.className(layer), (x + .1, y), scale = scale)
68
font.render("Scenes:", (x, y), scale = scale)
69
if "world" in dir(self.engine.server):
70
for scene in self.engine.server.world.scenes:
71
font.render(self.className(scene), (x + .1, y), scale = scale)
75
font.render("Loaders:", (x, y), scale = scale)
76
for loader in self.engine.resource.loaders:
77
font.render(str(loader), (x + .1, y), scale = scale)
81
font.render("Input:", (x, y), scale = scale)
82
for listener in self.engine.input.mouseListeners + \
83
self.engine.input.keyListeners + \
84
self.engine.input.systemListeners + \
85
self.engine.input.priorityKeyListeners:
86
font.render(self.className(listener), (x + .1, y), scale = scale)
90
font.render("System:", (x, y), scale = scale)
91
font.render("%d threads" % threading.activeCount(), (x + .1, y), scale = scale)
93
font.render("%.2f fps" % self.engine.fpsEstimate, (x + .1, y), scale = scale)
95
font.render("%d sessions, server %s" % (len(self.engine.sessions), self.engine.server and "on" or "off"), (x + .1, y), scale = scale)
97
#font.render("%d gc objects" % len(gc.get_objects()), (x + .1, y), scale = scale)
99
#font.render("%d collected" % gc.collect(), (x + .1, y), scale = scale)
102
self.engine.view.resetProjection()
106
before = len(gc.get_objects())
108
after = len(gc.get_objects())
109
Log.debug("%d GC objects collected, total %d -> %d." % (coll, before, after))
114
for obj in gc.garbage:
121
Log.debug("Wrote a dump of %d GC garbage objects to %s." % (n, fn))
123
def debugOut(self, engine):
125
f = open("debug.log", "w+")
127
# fallback for unix (games dir read-only)
129
# evilynux - Under MacOS X, put the logs in ~/Library/Logs
130
if( os.uname()[0] == "Darwin" ):
131
logFile = open(os.path.join(Resource.getWritableResourcePath(),
132
"..", "..", "Logs", Version.appName(),
134
else: # GNU/Linux et al.
135
f = open(os.path.join(Resource.getWritableResourcePath(), 'debug.log'), "w+")
136
version = Version.version()
137
currentDir = os.getcwd()
138
dataDir = Version.dataPath()
139
translationDir = dataDir + "/translations"
140
modsDir = dataDir + "/mods"
142
f.write("Date = %s\n" % datetime.datetime.now())
143
f.write("\nVersion = %s\n" % version)
144
f.write("\nOS = %s\n" % os.name)
146
f.write("\nCurrent Directory = %s\n" % currentDir)
147
self.directoryList(f, currentDir)
149
f.write("\nData Directory = %s\n" % dataDir)
150
self.directoryList(f, dataDir)
152
zip_path = os.path.join(dataDir, 'library.zip')
153
# no library.zip on regular unix installation
154
if os.path.exists(zip_path):
155
f.write("\nLibrary.zip\n")
156
zip = zipfile.ZipFile(zip_path, 'r')
157
for info in zip.infolist():
158
fileName = info.filename
159
fileCSize = info.compress_size
160
fileSize = info.file_size
161
fileDate = datetime.datetime(*(info.date_time))
162
f.write("%s, %s, %s, %s\n" % (fileName, fileCSize, fileSize, fileDate))
164
f.write("\nTranslation Directory = %s\n" % translationDir)
165
self.directoryList(f, translationDir)
167
f.write("\nMods Directory = %s\n" % modsDir)
168
self.directoryList(f, modsDir)
170
mods = os.listdir(modsDir)
173
modDir = os.path.join(modsDir, mod)
174
if os.path.isdir(modDir):
175
f.write("\nMod Directory = %s\n" % modDir)
176
self.directoryList(f, modDir)
178
f.write("\nFretsonfire.ini\n")
179
engine.config.config.write(f)
181
# No write() in Theme
182
#f.write("\nTheme.ini\n")
183
#Theme.write(f, engine.config)
185
f.write("\nStage.ini\n")
186
stage = Stage.Stage(self, self.engine.resource.fileName("stage.ini"))
187
stage.config.write(f)
190
def directoryList(self, f, root):
191
files = os.listdir(root)
193
for fileName in files:
194
fileSize = os.path.getsize(os.path.join(root, fileName))
195
mTime = datetime.datetime.utcfromtimestamp(os.path.getmtime(os.path.join(root, fileName)))
196
cTime = datetime.datetime.utcfromtimestamp(os.path.getctime(os.path.join(root, fileName)))
197
aTime = datetime.datetime.utcfromtimestamp(os.path.getatime(os.path.join(root, fileName)))
199
f.write("%s, %s, %s, %s, %s\n" % (fileName, fileSize, mTime, cTime, aTime))