7#include "common/config.h"
9#include <simplesquirrel/simplesquirrel.hpp>
12#include <SDL2/SDL_clipboard.h>
13#include <SDL2/SDL_cpuinfo.h>
14#include <SDL2/SDL_power.h>
22#if defined(EVENGINE_WINDOWS) || defined(_WIN32)
28#elif defined(__APPLE__)
38 return (info && info->gpuReady()) ? info :
nullptr;
50 const char *
p = SDL_GetPlatform();
51 return p ?
p :
"Unknown";
55#if defined(EVENGINE_WINDOWS)
57#elif defined(EVENGINE_IOS)
59#elif defined(EVENGINE_MACOSX)
61#elif defined(EVENGINE_ANDROID)
63#elif defined(EVENGINE_LINUX)
71 int n = SDL_GetCPUCount();
76 int n = SDL_GetCPUCacheLineSize();
81 int mb = SDL_GetSystemRAM();
82 return mb > 0 ? mb : 0;
86#if defined(EVENGINE_WINDOWS) || defined(_WIN32)
87 PROCESS_MEMORY_COUNTERS pmc{};
88 if (GetProcessMemoryInfo(GetCurrentProcess(), &pmc,
sizeof(pmc)))
89 return static_cast<int>(pmc.WorkingSetSize / (1024ull * 1024ull));
91#elif defined(__APPLE__)
92 task_vm_info_data_t info{};
93 mach_msg_type_number_t count = TASK_VM_INFO_COUNT;
94 if (task_info(mach_task_self(), TASK_VM_INFO,
reinterpret_cast<task_info_t
>(&info), &count) ==
96 return static_cast<int>(info.phys_footprint / (1024ull * 1024ull));
99#elif defined(__linux__) || defined(EVENGINE_ANDROID) || defined(EVENGINE_LINUX)
100 std::ifstream in(
"/proc/self/status");
104 if (key ==
"VmRSS:") {
107 return static_cast<int>(kb / 1024);
110 std::getline(in, rest);
119 using clock = std::chrono::system_clock;
120 auto tp = clock::now().time_since_epoch();
121 auto us = std::chrono::duration_cast<std::chrono::microseconds>(tp).count();
122 return float(
double(us) / 1'000'000.0);
126 if (ms < 0)
throw Exception(
"System.sleepMilliseconds: ms must be >= 0");
128 SDL_Delay(
static_cast<Uint32
>(ms));
132 int secs = 0, pct = 0;
133 SDL_PowerState st = SDL_GetPowerInfo(&secs, &pct);
135 case SDL_POWERSTATE_ON_BATTERY:
return "on_battery";
136 case SDL_POWERSTATE_NO_BATTERY:
return "no_battery";
137 case SDL_POWERSTATE_CHARGING:
return "charging";
138 case SDL_POWERSTATE_CHARGED:
return "charged";
139 default:
return "unknown";
144 int secs = -1, pct = -1;
145 SDL_GetPowerInfo(&secs, &pct);
150 int secs = -1, pct = -1;
151 SDL_GetPowerInfo(&secs, &pct);
156 if (!SDL_HasClipboardText())
return {};
157 char *t = SDL_GetClipboardText();
165 if (SDL_SetClipboardText(text.c_str()) != 0)
166 throw Exception(
"System.setClipboardText failed: %s", SDL_GetError());
170 auto *info = gpuInfoOrNull();
171 return info ? info->gpuName() : std::string();
175 auto *info = gpuInfoOrNull();
176 return info ? info->gpuVendor() : std::string();
180 auto *info = gpuInfoOrNull();
181 return info ? info->gpuDeviceType() : std::string();
185 auto *info = gpuInfoOrNull();
186 return info ? info->gpuMemoryTotalMB() : 0;
189void System::expose(ssq::Table &table) {
190 auto cls = table.addClass(
name, System::create,
false);
194void System::expose(ssq::Class &
cls) {
#define Module_IMPL(ModuleName, newExpr)
virtual std::string getName() const =0
System module — OS / hardware / wall-clock / clipboard / optional GPU info. Frame timing stays on Tim...
int getProcessorCount() const
std::string getGpuName() const
GPU queries — empty/0 if Graphics not initialized yet.
std::string getGpuDeviceType() const
"discrete" | "integrated" | "virtual" | "cpu" | "other" | ""
int getPowerSecondsLeft() const
Estimated seconds of battery left (-1 if unknown).
int getProcessMemoryMB() const
Current process resident memory in megabytes (0 if unknown).
float getWallTime() const
UTC wall-clock seconds since Unix epoch (float for script).
std::string getGpuVendor() const
std::string getPlatform() const
Raw SDL platform string (e.g. "Mac OS X", "Windows").
int getCPUCacheLineSize() const
CPU L1 cache line size in bytes (0 if unknown).
std::string getOS() const
Normalized OS id for games: "Windows" | "OS X" | "Linux" | "Android" | "iOS" | "Unknown"
int getPowerPercent() const
Battery percent 0–100, or -1 if unknown.
std::string getPowerState() const
Power state string: "unknown" | "on_battery" | "no_battery" | "charging" | "charged"
std::string getClipboardText() const
int getGpuMemoryTotalMB() const
Sum of DEVICE_LOCAL heap sizes in MB (0 if unknown / not ready).
int getSystemRAM() const
System RAM in megabytes (0 if unknown).
void setClipboardText(const std::string &text)
void sleepMilliseconds(int ms)
std::string getEngineVersion() const
Engine version string (e.g. "v0.1.0").