1 /* 2 ******************************************************************************************* 3 * Dgame (a D game framework) - Copyright (c) Randy Schütt 4 * 5 * This software is provided 'as-is', without any express or implied warranty. 6 * In no event will the authors be held liable for any damages arising from 7 * the use of this software. 8 * 9 * Permission is granted to anyone to use this software for any purpose, 10 * including commercial applications, and to alter it and redistribute it 11 * freely, subject to the following restrictions: 12 * 13 * 1. The origin of this software must not be misrepresented; you must not claim 14 * that you wrote the original software. If you use this software in a product, 15 * an acknowledgment in the product documentation would be appreciated but is 16 * not required. 17 * 18 * 2. Altered source versions must be plainly marked as such, and must not be 19 * misrepresented as being the original software. 20 * 21 * 3. This notice may not be removed or altered from any source distribution. 22 ******************************************************************************************* 23 */ 24 module Dgame.System.Power; 25 26 private import derelict.sdl2.sdl; 27 28 /** 29 * The System struct contains the Power struct, 30 * which give information about your current battery 31 * and several other informations about your system, like the available RAM. 32 * 33 * Author: rschuett 34 */ 35 final abstract class System { 36 /** 37 * This structure provide support for battery lifetime if you are on a laptop etc. 38 * 39 * Author: rschuett 40 */ 41 static struct Power { 42 /** 43 * Power states 44 */ 45 enum State { 46 Unknown = SDL_POWERSTATE_UNKNOWN, /** Cannot determine power status */ 47 OnBattery = SDL_POWERSTATE_ON_BATTERY, /** Not plugged in, running on the battery */ 48 NoBattery = SDL_POWERSTATE_NO_BATTERY, /** plugged in, no battery available */ 49 Charging = SDL_POWERSTATE_CHARGING, /** plugged in, charging battery */ 50 Charged = SDL_POWERSTATE_CHARGED, /** plugged in, battery charged **/ 51 } 52 53 /** 54 * Remaining time in seconds, or -1 if cannot determine power status 55 */ 56 int seconds; 57 /** 58 * Remaining battery percent, or -1 if cannot determine power status 59 */ 60 byte percent; 61 /** 62 * Battery state 63 */ 64 State state; 65 } 66 67 /** 68 * Returns the PowerInfo structure with the currently power informations 69 * 70 * See: PowerInfo struct 71 */ 72 static Power getPowerInfo() { 73 int secs, pct; 74 SDL_PowerState state = SDL_GetPowerInfo(&secs, &pct); 75 76 return Power(secs, cast(byte) pct, cast(Power.State) state); 77 } 78 79 /** 80 * Returns the available RAM 81 */ 82 static int getRAM() { 83 return SDL_GetSystemRAM(); 84 } 85 }