87 lines
2.8 KiB
Python
87 lines
2.8 KiB
Python
import os, pygame
|
|
from pygame.locals import *
|
|
|
|
from .Animation import Animation
|
|
from .Mainloop import Mainloop
|
|
from .Audio import Audio
|
|
from .Display import Display
|
|
from .Configuration import Configuration
|
|
from .Delegate import Delegate
|
|
from .Input import Input
|
|
from .ScreenGrabber import ScreenGrabber
|
|
from .Profile import Profile
|
|
from .VideoRecorder import VideoRecorder
|
|
from .Interpolator import Interpolator
|
|
from .TimeFilter import TimeFilter
|
|
|
|
class Game(Animation):
|
|
|
|
resource_path = None
|
|
|
|
def __init__(self, config_rel_path=None, type_declarations=None):
|
|
self.profile = Profile(self)
|
|
self.time_filter = TimeFilter(self)
|
|
Animation.__init__(self, self)
|
|
self.print_debug(pygame.version.ver)
|
|
self.config_rel_path = config_rel_path
|
|
self.type_declarations = type_declarations
|
|
self.set_configuration()
|
|
if self.get_configuration("display", "use-framebuffer"):
|
|
os.putenv("SDL_FBDEV", "/dev/fb0")
|
|
os.putenv("SDL_VIDEODRIVER", "fbcon")
|
|
os.putenv("SDL_NOMOUSE", "1")
|
|
pygame.init()
|
|
self.set_children()
|
|
self.subscribe(self.end, QUIT)
|
|
self.subscribe(self.end)
|
|
self.register(self.get_input().unsuppress)
|
|
self.delegate.enable()
|
|
|
|
def set_configuration(self):
|
|
self.configuration = Configuration(self.config_rel_path,
|
|
self.resource_path,
|
|
self.type_declarations)
|
|
|
|
def set_children(self):
|
|
self.delegate = Delegate(self)
|
|
self.display = Display(self)
|
|
self.mainloop = Mainloop(self)
|
|
self.input = Input(self)
|
|
self.audio = Audio(self)
|
|
self.screen_grabber = ScreenGrabber(self)
|
|
self.video_recorder = VideoRecorder(self)
|
|
self.interpolator = Interpolator(self)
|
|
|
|
def frame(self):
|
|
self.time_filter.update()
|
|
self.delegate.dispatch()
|
|
if not self.interpolator.is_gui_active():
|
|
Animation.update(self)
|
|
self.update()
|
|
else:
|
|
self.interpolator.gui.update()
|
|
self.audio.update()
|
|
if self.video_recorder.requested:
|
|
self.video_recorder.update()
|
|
|
|
def run(self):
|
|
self.mainloop.run()
|
|
|
|
def update(self):
|
|
pass
|
|
|
|
def blit(self, source, destination, area=None, special_flags=0):
|
|
self.get_screen().blit(source, destination, area, special_flags)
|
|
|
|
def get_rect(self):
|
|
return self.get_screen().get_rect()
|
|
|
|
def suppress_input_temporarily(self, length=700):
|
|
self.get_input().suppress()
|
|
self.play(self.get_input().unsuppress, delay=length, play_once=True)
|
|
|
|
def end(self, evt):
|
|
if evt.type == QUIT or self.delegate.compare(evt, "quit"):
|
|
self.mainloop.stop()
|
|
self.profile.end()
|