Re: [pygame] time progression independent of game ticks

2007-07-20 Thread Dave LeCompte (really)
Daniel Nixon [EMAIL PROTECTED] wrote:
 What advantage does calling pygame.time.wait() have over simply
 lowering the frame rate passed to .tick()?

I should really leave this one for folks who have been deeper into the SDL
C code, but my understanding is that (at least until recently) for small
frame times (frame rates above 30 fps? I don't recall), the
tick(framerate) call tries to be accurate - and it accomplishes this by
hogging the CPU.

The wait() approach, on the other hand, guarantees that your program
yields the CPU for a certain amount of time - you don't know when wait()
will return, but the clock.tick() function gives you the timing data that
you need, anyway. (And, don't worry - it's pretty close to the amount of
time you specified, but it might be a little off.)

The results of hogging all the CPU for your own process means that other
processes end up getting starved for CPU, which isn't a good idea on
multi-processing OSes (and who knows what the players are running in the
background).

All this ends up with a little bit of a counterintuitive practice: to get
smooth behavior, call wait(), even though it's unpredictable. It'll
average out and be more consistent than trying to manage time too
precisely.


-Dave LeCompte


Re: [pygame] time progression independent of game ticks

2007-07-20 Thread Simon Wittber

On 7/20/07, Daniel Nixon [EMAIL PROTECTED] wrote:

What is the best way to go about such a thing? Use MVC and run the
model in its own thread? If that is the case what is the best way to
keep track of the passage of actual time within the model?


This may or may not help:

http://entitycrisis.blogspot.com/2007/07/general-pygame-main-loop.html

--
   :: Simon Wittber
   :: http://www.linkedin.com/in/simonwittber
   :: phone: +61.4.0135.0685
   :: jabber/msn: [EMAIL PROTECTED]


Re: [pygame] time progression independent of game ticks

2007-07-20 Thread Laura Creighton
The first time I did something like that I made a fish class which
did things like get-hungry.  Each fish stored its time of creation
and time of last feeding, mating, egg-laying etc.  Then I kept doing:


 for every fish:
   check the time of day, and update the fishes' state
   based on the time elapsed

This worked fine for a few fish.  But it did not scale.  When I had
10s of thousands of fish, I couldn't get through the whole list of
fish before too much time had passsed.  My fish were carrying too
much state around with them as well.

So I changed the design to make my fish schedule 'at this time
something interesting will happen to me' events into a queue which
was sorted by time.  Then, for every bit of time, I only had to see
if it was later than or equal to the first item in the queue, and
pop things off the queue until the first item on it was 'later than
now'.

Just in case you run into the same problem that I had.

Laura


RE: [pygame] time progression independent of game ticks

2007-07-20 Thread Chris Ashurst
Have you considered using time deltas?

Each fish instance could be initialised a timestamp of its creation, and
each iteration of the main loop you could get a timestamp of *now* and pass
it to each fish (or get each fish to get its own *now* for comparison),
which could then use Python's builtin timedelta class to work out how much
real time has passed, rather than how much game time has passed in game
ticks.

So if an instance of fish was born on 4:15pm in-game then at 4:30pm, your
fish instance will roll out the birthday cake.

I realise this may seem like more overhead, since pygame already has a clock
class, but for me, I rely on the clock class to provide a nice and friendly
way of adjusting framerate, rather than a definitive timepiece for my game.

Of course, I could just be spouting bollocks.



~Chris

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Behalf Of Daniel Nixon
Sent: Friday, July 20, 2007 00:20
To: pygame-users@seul.org
Subject: [pygame] time progression independent of game ticks


Hi list,

I'm working on a game in which the player looks after a fishtank full
of fish. Each fish ages, gestates while pregnant, grows hungrier, etc.
For arguments sake lets say 15 minutes = 1 fish year. I want this
passage of time to be independent of frame rate and iterations through
the main game loop (or do I?).

What is the best way to go about such a thing? Use MVC and run the
model in its own thread? If that is the case what is the best way to
keep track of the passage of actual time within the model?

Thanks for reading.

-- 
Regards
Daniel Nixon




CONFIDENTIAL NOTICE: This email including any attachments, contains 
confidential information belonging to the sender. It may also be 
privileged or otherwise protected by work product immunity or other 
legal rules. This information is intended only for the use of the 
individual or entity named above.  If you are not the intended 
recipient, you are hereby notified that any disclosure, copying, 
distribution or the taking of any action in reliance on the contents 
of this emailed information is strictly prohibited.  If you have 
received this email in error, please immediately notify us by 
reply email of the error and then delete this email immediately.


Re: [pygame] time progression independent of game ticks

2007-07-20 Thread Dave LeCompte (really)
Simon Wittber [EMAIL PROTECTED]
 On 7/20/07, Daniel Nixon [EMAIL PROTECTED] wrote:
 What is the best way to go about such a thing? Use MVC and run the
 model in its own thread? If that is the case what is the best way to
 keep track of the passage of actual time within the model?

 This may or may not help:

 http://entitycrisis.blogspot.com/2007/07/general-pygame-main-loop.html

In that post you say the benefits of a fixed sim tick step are not
immediately apparent, and yet the benefits to network game synchronization
is obvious.

Could you go into more detail? I don't see why fixed sim ticks are any
better than variable sim ticks for networked games.


-Dave LeCompte


Re: [pygame] time progression independent of game ticks

2007-07-20 Thread Patrick Mullen

Yeah, a time queue is the way to go, don't bother with threads.  On each
update, you can get the current time (pygame.time, or pygame.clock), and
pass that into your time queue.  The time queue, will look something like
this:

[(5.0,eat,fish1),(6.5,eat,fish2)]

At each iteration, you continue to pop() the list, calling each function
(eat) with the argument (fish1, fish2), until the item on the list has a
time that is greater than the current time.  If you spread out your
scheduling, so there aren't too many fish doing the same thing at the exact
same time, this will scale really well and be a good way to handle timed
events.

As for tracking time, I use pygame.time as well.  I've found pygame.clock to
be inaccurate in some cases, and of course it's not usable in situations
where you don't want to use pygame (server).

I store lasttime = pygame.time.time() at the start of the simulation, then
on each iteration I calculate dt = pygame.time.time()-lasttime;.  Then if I
have some sort of game timer (like your 15 minutes = 1 year) I add the
dt(real time difference) times a modifier (to get game time difference) to
the game time variable.


[pygame] suggestions for a linux mixer

2007-07-20 Thread Laura Creighton
I have an ibm thinkpad x40.  I usually run it with the sound
altogether off via a small control button it has.  And I can
turn that on again.  But somehow I keep hitting some keystroke
combination that turns it into some state where I can still get
the machine to beep, but I cannot hear any sound on, say youtube,
or on any game.

I do this about once a month.  And I have no idea what it is I do, or
more importantly how to get it undone.  If I get out kmix, everything
looks correct.  If it get out alsamixer, there are a few channels that
look empty, but turing them on does not make the sound come back.  But
I know that there is one person, and one person only, at work who can
look at my alsamixer, and do one thing, and it goes back on again.
They rest of us at the company just look at the sliders, scratch our
heads, and say -- looks fine to me, guess we have to wait until Göran
comes to work. :-(

Well, Göran is on vacation, and I would like to listen to some
videos.  Anybody got a recommendation for a linux mixer,
ideally available as a debian package, which is less subtle
than alsamixer at telling you why you have no sound?

Laura, very frustrated.


Re: [pygame] suggestions for a linux mixer

2007-07-20 Thread Laura Creighton
In a message of Fri, 20 Jul 2007 13:18:28 PDT, James Paige writes:

Wow, this is a pretty non-pygamey question, but it sounds like your 
mixer is muted. Mute status is hard to see in alsamixer, but it is down 
there at the bottom. press m to toggle it.

---
James Paige

Thank you.  It turns out that what I needed to do was to turn
mute _on_ for the headphones.  Why this is I have no idea.

Thank you, thank you.
Laura


Re: [pygame] about [EMAIL PROTECTED]

2007-07-20 Thread René Dudfield

Hi,

I've asked  the nice people at seul to look into it.

Cheers,

On 7/21/07, Laura Creighton [EMAIL PROTECTED] wrote:

I realise that the pygame mailing list is not a mailman mailing list,
but is there an equivalent to 'disable mail delivery for a while'
for whatever software we are using?  Because he's not been noticing that
he has a problem for quite a while now ...

Laura



Re: [pygame] numpy migration (again)

2007-07-20 Thread René Dudfield

Sorry, I should try to explain it a bit better.

pygame will use the array.array module instead of numeric.

Then there will be python code which will take array.array instances,
and wrap them up with numeric, or numpy instances.  This will all be
done in python.  So you can load numeric, or numpy in python, and do
all the wrapping in python.

The interface to python std arrays ie: array.array instances will be done in C.

eg. This is kind of how this function will be written:
pygame.surfarray.pixels2d(Surface): return array

def pixels2d(s):
   p = pygame.surfarray_array.pixels2d(s)
   # we pass the surface, so we can query the dimensions.
   numeric_array = make_numeric_array_from_array_array(p, s)
   return numeric_array


On 7/21/07, Greg Ewing [EMAIL PROTECTED] wrote:

René Dudfield wrote:
 Not copying unless asked to.

 python arrays are mutable, so you need to copy explicitly.  So the
 pixels calls will still work as they do now.

I still don't understand *how* this will allow Numeric
and/or numpy arrays to be used without pygame having
any dependency on those packages.

Or are you talking about the new array interface
that's coming rather than the existing array module?

--
Greg



Re: [pygame] about [EMAIL PROTECTED]

2007-07-20 Thread Luke Paireepinart

René Dudfield wrote:

... and the nice people at seul have given us the magic commands to
control the mailing list.  So the email address has been removed.

Cheers.

Ya.


Re: [pygame] time progression independent of game ticks

2007-07-20 Thread Greg Ewing

Michael George wrote:
Having recently taught a data structures course I'm forced to point out 
that for some number of fish, inserting into the queue will become a 
bottleneck,


Actually, it's not the number of fish that determines when this
will become a bottleneck, but the typical number of events in
the queue at any given moment. This is not necessarily proportional
to the number of active entities in the simulation.

Another thing is that the event-queue approach might not help
so much for an *animated* simulation. If the fish are all swimming
around on the screen, you're going to have to process them all
every frame anyway to update their positions.

But if only a small proportion of the fish are visible at a time,
and you can avoid having to simulate the motion of off-screen
fish in a detailed way, it will probably help, as long as you have
a way of quickly finding all the visible fish.

--
Greg


Re: [pygame] suggestions for a linux mixer

2007-07-20 Thread Greg Ewing

Laura Creighton wrote:

It turns out that what I needed to do was to turn
mute _on_ for the headphones.  Why this is I have no idea.


Maybe mute the headphones implies don't mute the
speaker and vice versa. Or something.

--
Greg