Investigating it now.
-FM
> This is a patch to display a simple daylight cursor on the main map. I
> find the effect interesting so I wanted to share.
> http://img141.imageshack.us/my.php?image=screenshotendgamesingulks5.png
Nice idea! I have a few comments though:
* That's not what daylight looks like: in December, for example,
Antarctica mostly never sees night. The formula is available at
http://en.wikipedia.org/wiki/Day_length ; you could compute a
"darkness map" each day and roll it around for 24 hours. Might be
slow. On the other hand, it would provide a nice visual indication of
the passage of time.
* That's not what the dark side looks like: there's that beautiful
"earth at night" mosaic you could use for the dark parts. With SDL
it's probably just a question of using the image colours rather than
(0,0,0) to combine with the alpha you compute.
* It could read time.time() and start "now"; a nice touch for people who notice.
* You know people are going to want the Moon too...
* Is performance OK on flat-out mode? It might be necessary to be able
to disable it (for older systems).
Gives it a very War Room look. "These computers give us instant access
to the state of the world." All that.
Anne
I'm working on the night image (see
http://apod.nasa.gov/apod/ap001127.html ). Unfortnately, that brings
performance issues of its own. I think I spotted what I need to do,
though.
As far as the light/dark pattern not being right, I think it's best if
we ignore that for sake of simplicity. With the way the globe gets
stretched to make a rectangle, accurate lighting would look ugly. And
it'd be a nightmare to optimize the way I did for the simple lighting.
As to starting "now", that's slightly annoying. If anyone's intersted
in figuring out the offset we'd need for 00:00:00 to be midnight UTC,
I should be able to extract that from the system time and set the
initial clock appropriately.
For the moon, let's not go borrowing trouble. One celestial body at a time.
-FM
Linux folks (and anyone else running from source) will need to update
to pygame 1.8.1 to get the pretty version. Everyone else will get the
new pygame version bundled in with the next .exe/.app.
I'm a little bothered by how the north pole and antarctica change
shape between day and night. That image just by chance makes it look
like they line up perfectly, but there's significantly less of both
(especially antarctica) in the night version. I could swap the
daylight image out for the one without sea ice, which makes antarctica
match better, but that one shows nothing at the north pole. *shrugs*
Probably doesn't make much difference either way.
It's pretty much ready to go into SVN now, I just need to know how
David wants to be listed in the changelog and copyright notice.
Granted, there's not much left of the code he sent in, but it was all
built off of that, so he deserves full credit. It's a whole lot
easier to improve an existing feature than to build it from scratch.
Oh, and before I forget (again), next time, attach the patch instead
of including it in the email body. I had to edit it by hand to remove
the extra linebreaks and add back in some missing spaces at the start
of lines. It's not a big deal this time, but I'd rather not repeat
the experience with a larger patch.
-FM
How about making the time between updated depend on the speed? So if
speed 3 is ten times faster than speed 2, it can update every ten
in-game minutes. This should allow speed 4 to work...
> As far as the light/dark pattern not being right, I think it's best if
> we ignore that for sake of simplicity. With the way the globe gets
> stretched to make a rectangle, accurate lighting would look ugly. And
> it'd be a nightmare to optimize the way I did for the simple lighting.
Actually it makes a very nice pattern: see
http://aa.usno.navy.mil/data/docs/earthview.php
It does make optimization a little more tricky. The formula doesn't
take much longer to compute than your soft edges already do. You could
compute a day/night shape once per day, or once per month, or
whatever, keep it in an array, and copy a shifted copy into the alpha
channel every time you update.
> As to starting "now", that's slightly annoying. If anyone's intersted
> in figuring out the offset we'd need for 00:00:00 to be midnight UTC,
> I should be able to extract that from the system time and set the
> initial clock appropriately.
I think it's nicer if 00:00:00 is the start of the game. But
time.gmtime() will tell you what the current GMT is, and you can just
keep that as a constant offset for the night drawing.
Anne
I think even using a fake pattern with some curve to it would greatly
improve the realism. It should not be night on the south and north
poles at the same time.
http://time.gov/timezone.cgi?Central/d/-6/java shows a nice
approximation.
I'm having a bit of difficulty trying to extract a formula for the
earth region in darkness, or the brightness of a given
latitude/longitude pair, from the information at
http://en.wikipedia.org/wiki/Day_length .
I'll probably add options for the day/night cycle and FPS before
releasing 0.29. If I scale my desktop back to 400 MHz (~XO-1 speed),
it runs fairly nicely when set at 10FPS, and slows noticably but not
catastrophically on speed 3.
If someone wants to write up a more accurate day/night pattern, go
ahead, but be warned that *you're* going to have to do the
optimization on it. I want no part of that mess, and it won't go in
until it runs fast enough.
-FM
Here's a patch.
* It displays the correct day/night regions as a function of time and
season. (Though there are some approximations.)
* It starts now, as reported by time.gmtime()
* The day/night shape is changed once a day.
* On the "slow" modes the day/night region walks around the earth; on
the fastest mode it displays only at midnight. This way you can see
time passing from the shape of the day/night region.
* Every update, unfortunately, requires a blit of the whole screen;
nonetheless it's plenty fast on my several-years-old laptop. We should
still have a mode to turn it off.
* I've never written pygame code before so there are some weirdnesses
with clipping regions I never figured out.
* I added Montreal to the list of North American cities (though only
in English as I don't know what it's called in any of the other
languages).
* Some of the class variables in the map should maybe be elsewhere.
Anne
The performance is actually not nearly as bad as I was expecting. It
didn't even really change.
Can you blur the edges slightly, like we were doing with the square
version? Even a degree or so of transition would really help with
those jagged edges.
Oh, and I'll need to know how you want to be listed in the changelog/copyright.
-FM
> The performance is actually not nearly as bad as I was expecting. It
> didn't even really change.
>
> Can you blur the edges slightly, like we were doing with the square
> version? Even a degree or so of transition would really help with
> those jagged edges.
I tried blurring a bit, but since pygame doesn't provide either
accelerated blur or gradient operations (without using surfarray and
numpy) I would have to do it pixel-by-pixel. I've attached a patch to
do that; fiddle the variable "gradient width" to adjust it, but on my
machine, by 10 or 20 pixels the slowdown was visible. As an
alternative, the patch includes simple antialiasing - essentially a
single-pixel blur - which totally removes the visible jaggies (but
fails to reproduce the real blurriness of the terminator) with minimal
slowdown.
> Oh, and I'll need to know how you want to be listed in the changelog/copyright.
"Anne M. Archibald" is good. If you're listing everyone's email
address, feel free to use this one.
Anne
It's in SVN, r877.
-FM
On 8/24/08, Anne Archibald <peridot...@gmail.com> wrote:
Since the masks are typically 800x600x4 bytes, I don't think 365 of
them is a good idea - and at least in fast mode you can already see
sizable steps as it advances by a day. You could store the information
needed to generate the mask, but the slow step is all those
single-pixel value settings. If you were willing to make the game
depend on numpy, you could use numpy to do the calculation directly
and as exactly as you felt inclined.
One possibility worth looking into is producing the mask by averaging,
say, five days' worth of masks. This won't give you a nice smooth
gradient, though, and five full-screen blits won't be cheap.
The real terminator is quite wide:
http://solarsystem.nasa.gov/multimedia/display.cfm?IM_ID=1879
But since smoothly interpolating between our daytime and nighttime
images is pretty artificial, and they don't line up, I don't know that
it's worth the trouble of trying for more realism. I think the current
setup has the look of one of those day/night clocks:
http://www.gadgetchamp.com/2007/07/27/geochron-world-clock-all-the-time-in-the-world/
I played a quick game (on Very Easy) and it's borderline distracting.
One thing it would be nice to change is that when you start fast
mode, the image jumps to midnight GMT; when it stops, the image jumps
to whatever time fast mode stops at. There's no getting around the
second one, but it would be nicer if the image just stayed at the time
of day it was at when you hit "fast".
Anne
Whe this got talked about last time, weren't we were looking at having
speed 4 just have a "perpetual twilight" look?
You could lower the cost of the averaging by just averaging the
previous mask with the current one. To change the thickness, you just
weight it towards the old or new image. I don't think it's likely to
give a very good result, but I could be wrong.
Actually, that terminator isn't all that wide. I read it as maybe 8
pixels, with a radius of 80. That gives a width of 5.7 degrees, or
roughly 13 horizontal pixels (10 vertical) at 800x600.
-FM
> Whe this got talked about last time, weren't we were looking at having
> speed 4 just have a "perpetual twilight" look?
I find the current setup - show the same time every day - rather nice:
you have a visual indication of time passing because the terminator
changes shape.
Anne
> We already depend on numpy, so if you want to calculate things with
> it, go ahead. In fact, there's a tweak in to make pygame's pixel
> arrays use numpy instead of Numeric when both are installed.
Oh! Really? I hadn't realized. Then here's a quick patch.
I compute the (sine of the) Sun's altitude above the horizon, in solar
diameters. The gradient should be from -0.5 to 0.5. Instead of just
clipping values to that range (using a linear gradient) or using some
"correct" gradient based on how much of the Sun is above the horizon,
I used a hyperbolic tangent to compress the range (it has slope 1 at
the origin but maps the real line to (-1,1)). So the gradient has
slightly elongated tails. Anyway, it works, and produces a gradient
that's mostly narrow except near the poles near equinox. And it runs
reasonably quickly (no python looping); optimizations could definitely
be done.
I also don't know whether it's safe to assume any of numpy, numarray,
or Numeric is installed, or even which one, so I have a gruesome
suspender-and-belt import. That could be cleaned up, as could the
alternative implementations, if people are happy with this one and
know more about what we can assume is installed.
Anne
-FM
On 8/26/08, Anne Archibald <peridot...@gmail.com> wrote:
-FM
On 8/26/08, Charlie Nolan <funnym...@gmail.com> wrote:
The strange effect at the poles around equinox looks believable to me,
so I wouldn't worry about it. Then again, if you want to try
something even more complex, you're certainly welcome to. Everything
else you've sent in has impressed me, so I'd be happy to take a look.
So, is it just geometry you excel at, or should I sic you on some of
the other hard problems I have in mind? :)
> I played a quick game (on Very Easy) and it's borderline distracting.
> One thing it would be nice to change is that when you start fast
> mode, the image jumps to midnight GMT; when it stops, the image jumps
> to whatever time fast mode stops at. There's no getting around the
> second one, but it would be nicer if the image just stayed at the time
> of day it was at when you hit "fast".
Attached is a patch to do this.
Once again I'm not sure the coding style is all it could be, but it
does appear to work, and provide no more jumps than necessary.
Anne
I do have one question, though. What's the point of this "if False:"
block that's been hanging around for a bit? Is it just dead code, or
is it intended to be something we can enable?
Applied the patch. Things were behaving badly on user pause, so I
added a line to force an update when the user changes the speed. r879
-FM
On 8/26/08, Anne Archibald <peridot...@gmail.com> wrote:
> Doesn't look any worse than some of the stuff I've put in.
> Complicated logic takes complicated code, there's not a lot to be done
> about it. Some high-level explanation of what you're doing and why
> wouldn't be amiss, but I'll confess to being pretty bad about that
> myself.
>
> I do have one question, though. What's the point of this "if False:"
> block that's been hanging around for a bit? Is it just dead code, or
> is it intended to be something we can enable?
The "if False:" was to enable the first attempt at blurring. There's
no real point having it there any more, as it's less accurate and
slower than the numpy-based solution. I'm afraid the antialiased
version needs to stay, though, since it's used when can_twiddle_alpha
is False.
Anne
-FM