示例#1
0
def main(options, args):
    """Start the engine and the game"""
    registerSounds()
    registerMusic()
    registerGraphics()
    registerEvents()
    #
    # Change theme settings
    if options.theme:
        theme.updateFromString(options.theme)
    #
    # Create the engine
    engine = startEngine(options)
    engine.linkEvent(serge.events.E_BEFORE_STOP, stoppingNow)
    #
    # Muting
    mute = serge.blocks.actors.MuteButton("mute-button", "ui", alpha=G("mute-button-alpha"))
    serge.blocks.utils.addMuteButtonToWorlds(mute, center_position=G("mute-button-position"))
    #
    if options.musicoff:
        mute.toggleSound()
    #
    # Initialise the main logic
    registerAchievements(options)
    mainscreen.main(options)
    startscreen.main(options)
    helpscreen.main(options)
    creditsscreen.main(options)
    #
    if options.debug:
        serge.builder.builder.main(engine, options.framerate)
    else:
        engine.run(options.framerate)
 def __init__(self, filename):
     """Initialise the RecordDesktop"""
     self.addLogger()
     #
     # Highly system specific!
     #
     # Find our window
     self.log.info('Looking for the main window')
     engine = serge.engine.CurrentEngine()
     #
     windows = subprocess.check_output(['wmctrl', '-lG']).splitlines()
     for window in windows:
         parts = window.split()
         x, y, width, height = parts[2:6]
         name = ' '.join(parts[7:])
         if name == engine.title:
             break
     else:
         raise ValueError('Could not find the main window!')
     #import pdb; pdb.set_trace()
     #
     # Now start the recording
     self.log.info('Starting "recordmydesktop"')
     self.child = subprocess.Popen(['recordmydesktop', '--width', width, '--height', height,
         '-x', x, '-y', y, '-o', filename, '--fps', '60'])
     
     #
     # Hook completion so we can quit
     engine.linkEvent(serge.events.E_AFTER_STOP, self.stop)
    def __init__(self, filename):
        """Initialise the RecordDesktop"""
        self.addLogger()
        #
        # Highly system specific!
        #
        # Find our window
        self.log.info("Looking for the main window")
        engine = serge.engine.CurrentEngine()
        #
        windows = subprocess.check_output(["wmctrl", "-lG"]).splitlines()
        for window in windows:
            parts = window.split()
            x, y, width, height = parts[2:6]
            name = " ".join(parts[7:])
            if name == engine.title:
                break
        else:
            raise ValueError("Could not find the main window!")
        # import pdb; pdb.set_trace()
        #
        # Now start the recording
        self.log.info('Starting "recordmydesktop"')
        self.child = subprocess.Popen(
            ["recordmydesktop", "--width", width, "--height", height, "-x", x, "-y", y, "-o", filename, "--fps", "60"]
        )

        #
        # Hook completion so we can quit
        engine.linkEvent(serge.events.E_AFTER_STOP, self.stop)
示例#4
0
    def __init__(self, filename):
        """Initialise the RecordDesktop"""
        self.addLogger()
        #
        # Highly system specific!
        #
        # Find our window
        self.log.info('Looking for the main window')
        engine = serge.engine.CurrentEngine()
        #
        windows = subprocess.check_output(['wmctrl', '-lG']).splitlines()
        for window in windows:
            parts = window.split()
            x, y, width, height = parts[2:6]
            name = ' '.join(parts[7:])
            if name == engine.title:
                break
        else:
            raise ValueError('Could not find the main window!')
        #import pdb; pdb.set_trace()
        #
        # Now start the recording
        self.log.info('Starting "recordmydesktop"')
        self.child = subprocess.Popen([
            'recordmydesktop', '--width', width, '--height', height, '-x', x,
            '-y', y, '-o', filename, '--fps', '60'
        ])

        #
        # Hook completion so we can quit
        engine.linkEvent(serge.events.E_AFTER_STOP, self.stop)
示例#5
0
def main(options, args):
    """Start the engine and the game"""
    #
    # Create the high scores
    if options.high_score:
        createHighScores(options)
    #
    # Create the engine
    engine = startEngine(options)
    engine.linkEvent(serge.events.E_BEFORE_STOP, stoppingNow)
    #
    registerSounds()
    registerMusic()
    registerGraphics()
    registerEvents()
    #
    # Record a movie
    if options.movie:
        serge.blocks.utils.RecordDesktop(options.movie)
    #
    # Change theme settings
    if options.theme:
        theme.updateFromString(options.theme)
    #
    # Muting
    mute = serge.blocks.actors.MuteButton('mute-button',
                                          'ui',
                                          alpha=G('mute-button-alpha'))
    serge.blocks.utils.addMuteButtonToWorlds(
        mute, center_position=G('mute-button-position'))
    #
    if options.musicoff:
        mute.toggleSound()
    #
    # Initialise the main logic
    registerAchievements(options)
    mainscreen.main(options)
    startscreen.main(options)
    helpscreen.main(options)
    creditsscreen.main(options)
    #
    if options.debug:
        serge.builder.builder.main(engine, options.framerate)
    else:
        engine.run(options.framerate)
示例#6
0
def getSurfaceProcessingPipeline(target, start=True):
    """Return a pair of queues to implement a surface processing pipeline
    
    An input and output queue are returned. The queues are passed a tuple of items
    and the first one is a surface which is marshalled to the target function.
    
    The function must also return a tuple, the first of which is assumed to be a surface
    which will be marshalled.
    
    """
    #
    # Create queues
    todo = SkippableQueue()
    result = SkippableQueue()
    #
    # Create the worker and start it up
    worker = multiprocessing.Process(target=pipelineProcessor,
                                     args=(todo, result, target))
    worker.daemon = True
    if start:
        worker.start()
    #
    # Make sure we go away
    def stoppingNow(obj, arg):
        """The engine is stopping"""
        engine.log.info('Cleaning up worker - sent quit signal')
        todo.put(None)
        engine.log.info('Waiting for worker to finish')
        while True:
            answer = result.get()
            if answer is None:
                engine.log.info('Worker seems to have finished')
                break

    #
    engine = serge.engine.CurrentEngine()
    if engine:
        engine.linkEvent(serge.events.E_BEFORE_STOP, stoppingNow)
    #
    return (todo, result, worker)
def getSurfaceProcessingPipeline(target, start=True):
    """Return a pair of queues to implement a surface processing pipeline
    
    An input and output queue are returned. The queues are passed a tuple of items
    and the first one is a surface which is marshalled to the target function.
    
    The function must also return a tuple, the first of which is assumed to be a surface
    which will be marshalled.
    
    """
    #
    # Create queues
    todo = SkippableQueue()
    result = SkippableQueue()
    #
    # Create the worker and start it up
    worker = multiprocessing.Process(target=pipelineProcessor, args=(todo, result, target))
    worker.daemon = True
    if start:
        worker.start()
    #
    # Make sure we go away
    def stoppingNow(obj, arg):
        """The engine is stopping"""
        engine.log.info('Cleaning up worker - sent quit signal')
        todo.put(None)
        engine.log.info('Waiting for worker to finish')
        while True:
            answer = result.get()
            if answer is None:
                engine.log.info('Worker seems to have finished')
                break
    #
    engine = serge.engine.CurrentEngine()
    if engine:
        engine.linkEvent(serge.events.E_BEFORE_STOP, stoppingNow)
    #
    return (todo, result, worker)
示例#8
0
def main(options, args, observation):
    """Start the engine and the game"""
    #
    # Set the levels to use - this allows us to switch to AI testing
    # levels rather than the main levels
    if options.test:
        import tests
        theme.setProperty('start-level', 1)
        common.levels = tests
    #
    # Check networkx install
    if not serge.blocks.utils.checkNetworkXVersion(1.8):
        return
    #
    # Create the high scores
    if options.high_score:
        createHighScores(options)
    #
    # Create the engine
    engine = startEngine(options)
    engine.linkEvent(serge.events.E_BEFORE_STOP, stoppingNow)
    engine.addWorld(common.TWEENER)
    #
    registerSounds()
    registerMusic()
    registerGraphics()
    registerEvents()
    #
    # Record a movie
    if options.movie:
        serge.blocks.utils.RecordDesktop(options.movie)
    #
    # Change theme settings
    if options.theme:
        theme.updateFromString(options.theme)
    #
    # Muting
    mute = serge.blocks.actors.MuteButton('mute-button',
                                          'ui',
                                          alpha=G('mute-button-alpha'))
    serge.blocks.utils.addMuteButtonToWorlds(
        mute, center_position=G('mute-button-position'))
    #
    if options.muted:
        mute.toggleSound()
    if options.music_off:
        serge.sound.Music.toggle()
    #
    # Initialise the main logic
    registerAchievements(options)
    mainscreen.main(options, observation)
    startscreen.main(options)
    helpscreen.main(options)
    creditsscreen.main(options)
    levelscreen.main(options)
    actionreplayscreen.main(options)
    randomlevelscreen.main(options)
    #
    if options.debug:
        serge.builder.builder.main(engine, options.framerate)
    else:
        engine.run(options.framerate)
def main(options, args):
    """Start the engine and the game"""
    #
    # For ropes and things we typically need a higher number of iterations
    serge.zone.PHYSICS_ITERATIONS = 100
    #
    # Create the engine
    engine = startEngine(options)
    engine.linkEvent(serge.events.E_BEFORE_STOP, stoppingNow)
    #
    registerSounds()
    registerMusic()
    registerGraphics()
    registerEvents()
    #
    # Change theme settings
    if options.theme:
        theme.updateFromString(options.theme)
    #
    # Muting
    mute = serge.blocks.actors.MuteButton('mute-button', 'ui', alpha=G('mute-button-alpha'))
    serge.blocks.utils.addMuteButtonToWorlds(mute, center_position=G('mute-button-position'))
    #
    if options.musicoff:
        mute.toggleSound()
    #
    # Initialise the main logic
    globals = serge.blocks.singletons.Store.registerItem('globals')  
    globals.history = history.History('history', 'history')
    globals.last_cave_name = 'RANDOM-CAVE'
    #
    registerAchievements(options)
    if options.skip:
        mainscreen.main(options)
    else:
        startscreen.main(options)
        #
        # Force a rendering of the overlay - this puts
        # up the "loading ..." screen so the user has something
        # to see while we create the cave and trees etc
        w = engine.getWorld('start-screen')
        w.log.info('Rendering overlay')
        w.renderTo(engine.getRenderer(), 1000)
        engine.getRenderer().render()
        pygame.display.flip()
    #
    helpscreen.main(options)
    creditsscreen.main(options)
    namescreen.main(options)
    collectionscreen.main(options)
    #   
    #
    if options.movie:
        serge.blocks.utils.RecordDesktop(options.movie)
    if options.debug:
        serge.builder.builder.main(engine, options.framerate)
    else:
        try:
            engine.run(options.framerate)
        except:
            # Make sure this event is raised so that any workers can be killed
            engine.processEvent((serge.events.E_BEFORE_STOP, None))
            raise
    #
    # Display profile statistic if needed
    if options.engine_profile:
        prof = engine.getProfiler()
        data = [(prof.byTag(n).get('renderActor', (0,0))[1], n) for n in prof.getTags()]
        data.sort()
        data.reverse()
        print '\n\nEngine profiling\n\nTag\tTime(s)'
        for tme, tag in data:
            print '%s\t%s' % (tag, tme)
        print '\n\n'