Quick way to test if value lies within a list of lists of ranges?

Paul McGuire ptmcg at austin.rr._bogus_.com
Fri Oct 28 00:26:29 EDT 2005


"Ben O'Steen" <bosteen at maysubdivide.org> wrote in message
news:mailman.2637.1130424453.509.python-list at python.org...
Scenario:
=========

Using PyGame in particular, I am trying to write an application that will
run a scripted timeline of events, eg at 5.5 seconds, play xxx.mp3 and put
the image of a ball on screen, at 7.8 seconds move the ball up and down.
At this point, I hear you say 'Oh, like Flash'.

Yes, well... Like Flash, but I don't want to take this app in the same
direction as Macromedia took Flash, nor do I (ever) want the two to be
compatible.

One particular need is for the timeline to be quickly traversable. If I
want to go to time=239.4 seconds, I'd like it to go there pretty much
painlessly and hopefully with one call. (Same with play, reverse and pause
really) I also want it to play for a long duration, with lots of different
items (images, audio, etc.)

<snip>

Ben -

This sounds very similar to a discrete event simulator, which uses a
timeline to track when the "next" event is supposed to occur, and advances
by events, rather than by straight elapsing of time (so that a 3 week
simulation doesn't take 3 weeks to run!).  SimPy does this very thing, and
it also has a "real-time" mode so that simulations can be watched as they
would really transpire.

The one difference is that with SimPy, you don't really script the timeline
ahead of time, but instead you script the individual events, and the
resources that the various processes have to compete/contend for, thereby
causing the events to get spread out over time.

But you might get some clues from SimPy's traversal of the event queue, and
the alternative model of building the queue dynamically while "executing" it
might give you some other ideas about your game design.  (I do recall that
SimPy's event queue can eventually grow to hold thousands of events, and a
huge speedup was accomplished a ver versions ago by using the bisect module
to insert new events at the proper location in the queue.  But this is only
relevant if you build the queue dynamically.)

-- Paul





More information about the Python-list mailing list