profile requested
This commit is contained in:
parent
0d633badc7
commit
02c5a5a6b7
|
@ -71,7 +71,9 @@ class Configuration(RawConfigParser):
|
|||
set_option(section, "icon-path", "")
|
||||
set_option(section, "skip-frames", "no")
|
||||
set_option(section, "fullscreen", "no")
|
||||
set_option(section, "windowed-flag", "wi")
|
||||
set_option(section, "show-framerate", "no")
|
||||
set_option(section, "framerate-display-flag", "fr")
|
||||
set_option(section, "framerate-text-size", "12")
|
||||
set_option(section, "framerate-text-color", "0, 0, 0")
|
||||
set_option(section, "framerate-text-background", "255, 255, 255")
|
||||
|
|
|
@ -21,9 +21,10 @@ class Display(GameChild):
|
|||
def load_configuration(self):
|
||||
config = self.get_configuration("display")
|
||||
self.centered = config["centered"]
|
||||
self.fullscreen = config["fullscreen"]
|
||||
self.fullscreen_enabled = config["fullscreen"]
|
||||
self.dimensions = config["dimensions"]
|
||||
self.caption = config["caption"]
|
||||
self.windowed_flag = config["windowed-flag"]
|
||||
self.mouse_visibility = self.get_configuration("mouse", "visible")
|
||||
|
||||
def align_window(self):
|
||||
|
@ -32,10 +33,14 @@ class Display(GameChild):
|
|||
|
||||
def init_screen(self):
|
||||
flags = 0
|
||||
if self.fullscreen:
|
||||
if self.fullscreen_requested():
|
||||
flags = FULLSCREEN
|
||||
self.set_screen(flags)
|
||||
|
||||
def fullscreen_requested(self):
|
||||
return not self.check_command_line(self.windowed_flag) and \
|
||||
self.fullscreen_enabled
|
||||
|
||||
def set_screen(self, flags=0):
|
||||
self.screen = display.set_mode(self.dimensions, flags)
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from time import time as get_secs
|
||||
|
||||
from pygame import joystick as joy, key as keyboard
|
||||
from pygame import joystick as joy
|
||||
from pygame.key import get_pressed
|
||||
from pygame.locals import *
|
||||
|
||||
from GameChild import *
|
||||
|
@ -108,7 +109,7 @@ class Input(GameChild):
|
|||
return joystick.is_direction_pressed(Joystick.left)
|
||||
|
||||
def is_key_pressed(self, command):
|
||||
poll = keyboard.get_pressed()
|
||||
poll = get_pressed()
|
||||
for key in self.key_map[command]:
|
||||
if poll[key]:
|
||||
return True
|
||||
|
|
|
@ -27,9 +27,10 @@ class Mainloop(GameChild):
|
|||
self.framerate_text_size = config["framerate-text-size"]
|
||||
self.framerate_text_color = config["framerate-text-color"]
|
||||
self.framerate_text_background = config["framerate-text-background"]
|
||||
self.framerate_display_flag = config["framerate-display-flag"]
|
||||
|
||||
def init_framerate_display(self):
|
||||
if self.show_framerate:
|
||||
if self.framerate_display_active():
|
||||
screen = self.get_screen()
|
||||
self.last_framerate_count = 0
|
||||
self.framerate_topright = screen.get_rect().topright
|
||||
|
@ -39,6 +40,19 @@ class Mainloop(GameChild):
|
|||
self.font.set_bold(True)
|
||||
self.render_framerate()
|
||||
|
||||
def framerate_display_active(self):
|
||||
return self.check_command_line(self.framerate_display_flag) or \
|
||||
self.show_framerate
|
||||
|
||||
def render_framerate(self):
|
||||
text = self.font.render(str(self.last_framerate_count), False,
|
||||
self.framerate_text_color,
|
||||
self.framerate_text_background)
|
||||
rect = text.get_rect()
|
||||
rect.topright = self.framerate_topright
|
||||
self.framerate_text = text
|
||||
self.framerate_text_rect = rect
|
||||
|
||||
def run(self):
|
||||
while not self.stopping:
|
||||
self.advance_frame()
|
||||
|
@ -51,7 +65,7 @@ class Mainloop(GameChild):
|
|||
while self.frame_count > 0:
|
||||
refresh = True
|
||||
self.parent.frame()
|
||||
if self.show_framerate:
|
||||
if self.framerate_display_active():
|
||||
self.update_framerate()
|
||||
self.frame_count -= 1
|
||||
if not self.skip_frames:
|
||||
|
@ -91,14 +105,5 @@ class Mainloop(GameChild):
|
|||
self.display_surface.blit(self.framerate_text, self.framerate_text_rect)
|
||||
self.frames_this_second = count
|
||||
|
||||
def render_framerate(self):
|
||||
text = self.font.render(str(self.last_framerate_count), False,
|
||||
self.framerate_text_color,
|
||||
self.framerate_text_background)
|
||||
rect = text.get_rect()
|
||||
rect.topright = self.framerate_topright
|
||||
self.framerate_text = text
|
||||
self.framerate_text_rect = rect
|
||||
|
||||
def stop(self):
|
||||
self.stopping = True
|
||||
|
|
|
@ -16,6 +16,7 @@ class Profile(cProfile.Profile, GameChild):
|
|||
return self.check_command_line("p")
|
||||
|
||||
def end(self):
|
||||
self.disable()
|
||||
self.create_stats()
|
||||
self.dump_stats(join("stat/", strftime("%Y%m%d-%H%M_%S.stat")))
|
||||
if self.requested():
|
||||
self.disable()
|
||||
self.create_stats()
|
||||
self.dump_stats(join("stat/", strftime("%Y%m%d-%H%M_%S.stat")))
|
||||
|
|
Loading…
Reference in New Issue