I noticed that Steam’s overlay, when running on a laptop, could report
my system’s battery status in-game, which is useful, since the Windows
system tray icon that I would normally rely on isn’t visible when
playing full screen.
I could also imagine scenarios where a game might want to reduce
framerate or detail when not on AC power, in order to reduce the power
burned when it is a limited resource.
So I added an API to SDL 1.3 to report power status.
Usage is fairly simple…
int seconds, percent; const SDL_PowerState state = SDL_GetPowerInfo(&seconds, &percent);
…“state” tells you where the system is getting power:
- Unknown (no power management support in the library or OS, or error).
- From a battery
- From AC power, solely.
- From AC power, charging a battery.
- From AC power, with a fully-charged battery.
For cases where a battery exists, “seconds” will be the (perhaps wildly
incorrect) estimate of seconds of battery life remaining (or -1 if we
couldn’t guess), and percent is a number from 0 to 100, representing
percentage of battery life left (or -1 if we don’t know). No battery in
the system will produce -1 for both of these values, too.
I’ve filled in implementations for Windows (should support all Win32,
Win64, and WinCE/PocketPC platforms), Linux (just /proc/apm at the
moment, but /proc/acpi and /sys/power are easy enough to fill in), Mac
OS X, and OS/2.
Presumably the Mac stuff will work on iPhone, and Nintendo DS has a stub
implementation for now (apparently you get this information through the
ARM7, and I don’t know the voodoo magic for that).
The file test/testpower.c in the patch is an example program.
I’ve only tested (or even compiled) this patch on Mac OS X. I’m looking
for comments before I commit it, including “my god man, please don’t
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed…