示例#1
0
文件: tank.py 项目: GuyCarver/raspi
 def curstate( self, aState ):
   ''' Set and start a new state if changed and end the previous one.
       aState is a state index. '''
   if self._curstate != aState:
     state.end(self.stateobj)
     self._curstate = aState
     state.start(self.stateobj)
示例#2
0
 def _shootStartUD(self, aState, aDT):
     ''' Decrement timer by elapsed time to switch to regular fire rate. '''
     aState['timer'] -= aDT
     #    print(aState['timer'])
     #When timer reaches 0, switch to regular shoot rate
     if aState['timer'] <= 0.0:
         self._combatstate = self._shootstate
         #We start the shoot state without ending the shootStart state
         # so we don't shut off the guns
         state.start(self._combatstate)
示例#3
0
文件: builder.py 项目: lkosewsk/redo
def _build(t):
    if (os.path.exists(t) and not state.is_generated(t)
          and not os.path.exists('%s.do' % t)):
        # an existing source file that is not marked as a generated file.
        # This step is mentioned by djb in his notes.  It turns out to be
        # important to prevent infinite recursion.  For example, a rule
        # called default.c.do could be used to try to produce hello.c,
        # which is undesirable since hello.c existed already.
        state.stamp(t)
        return  # success
    state.start(t)
    (dofile, basename, ext) = _find_do_file(t)
    if not dofile:
        raise BuildError('no rule to make %r' % t)
    state.stamp(dofile)
    tmpname = '%s.redo.tmp' % t
    unlink(tmpname)
    f = open(tmpname, 'w+')

    # this will run in the dofile's directory, so use only basenames here
    argv = ['sh', '-e',
            os.path.basename(dofile),
            os.path.basename(basename),  # target name (extension removed)
            ext,  # extension (if any), including leading dot
            os.path.basename(tmpname)  # randomized output file name
            ]
    if vars.VERBOSE:
        argv[1] += 'v'
        log_('\n')
    log('%s\n' % relpath(t, vars.STARTDIR))
    rv = subprocess.call(argv, preexec_fn=lambda: _preexec(t),
                         stdout=f.fileno())
    if rv==0:
        if os.path.exists(tmpname) and os.stat(tmpname).st_size:
            # there's a race condition here, but if the tmpfile disappears
            # at *this* point you deserve to get an error, because you're
            # doing something totally scary.
            os.rename(tmpname, t)
        else:
            unlink(tmpname)
        state.stamp(t)
    else:
        unlink(tmpname)
        state.unstamp(t)
    f.close()
    if rv != 0:
        raise BuildError('%s: exit code %d' % (t,rv))
    if vars.VERBOSE:
        log('%s (done)\n\n' % relpath(t, vars.STARTDIR))
示例#4
0
def cross(history):
    """Iterate by crossing history and history[1:]
    """
    backup = 0

    if len(history):
        yield state.start(), history[0][0], 1

        for (s1, t1), (s2, t2) in izip(history, history[1:]):
            duration = t2 - t1

            if s1 == s2:
                backup += duration
            else:
                if backup + duration <= MAX_DURATION \
                        and not state.terminal(s1):
                    yield s1, s2, backup + duration
                else:
                    yield s1, state.finish(), 1
                    yield state.start(), s2, 1
                backup = 0
        yield history[-1][0], state.finish(), 1
示例#5
0
文件: play.py 项目: wolmir/cristina
	def __init__(self):
		state.init()
		state.start()
		self.t = 0
示例#6
0
def reset(update, context):
    resetDefaultInfo()
    return start(update, context)