platform-abstraction
Use when the user asks about a platform abstraction layer, cross-platform engine code, windowing, engine filesystem, dynamic library loading, high-resolution…
от j4flmao★ 47 звёзд на GitHub
Установить platform-abstraction в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Platform Abstraction Layer — Deep Engineering Guide
Purpose
The PAL (Platform Abstraction Layer) is the layer that lets one engine codebase run on Windows, Linux, macOS, and every console generation. If it's leaky, every feature becomes a platform #ifdef. If it's designed well, 95% of engine code is pure, portable C++.
Agent Protocol
Trigger
"platform abstraction layer", "PAL", "cross-platform engine", "windowing", "engine filesystem", "dynamic library loading", "platform ifdef".
Input Context
- Target platforms
- Language and build system
- Existing libraries (SDL3, GLFW, custom)
Output Artifact
Interface design and per-platform implementation sketch. No file unless requested.
Response Format
Interface: {header}
Backends: {platform -> implementation}
Code: {snippet}
Pitfalls: {paths, unicode, threading}
1. The Contract — What the PAL Must Cover
| Concern | Platform-specific | Engine API |
|---|---|---|
| Memory | VirtualAlloc / mmap / heap | Memory::Reserve, Memory::Commit |
| Threads | CreateThread / pthread / fiber | Thread, JobSystem handles |
| Filesystem | CreateFile / open | FileSystem::Open, paths {Platform.VirtualPath} |
| Time | QueryPerformanceCounter / clock_gettime | Time::Now(), Time::Delta() |
| Windowing | Win32 / SDL / GLFW | Window, InputEvent |
| Input | RawInput / XInput / hid | InputDevice, ActionMap |
| Dynamic loading | LoadLibrary / dlopen | Module::Load |
| Console slots | device-specific | Console::WaitForDebugger |
| Render RHI | D3D12 / Vulkan / Metal | RHIDevice (see vulkan skill) |
| Networking | winsock / BSD sockets | NetworkProtocol (see netcode skill) |
Rule: every platform-only symbol lives behind an interface; leaks are forbidden (#ifdef _WIN32 inside gameplay code).
2. Abstracting the OS
2.1 The Interface Pattern
struct PAL {
// Memory
virtual MemoryPage* Reserve(uint64_t bytes) = 0;
virtual void Commit(void* p, uint64_t bytes) = 0;
// Threads
virtual Thread* CreateThread(ThreadFn, void*, size_t stack) = 0;
virtual void Sleep(uint32_t ms) = 0;
virtual uint32_t HardwareThreadCount() = 0;
// Files
virtual FileHandle* Open(const Path&, FileMode) = 0;
virtual void ReadAsync(FileHandle*, uint8_t*, size_t, IoCallback) = 0;
// Time
virtual TimePoint Now() = 0;
virtual double PeriodSeconds() = 0;
// Misc
virtual uint32_t ProcessId() = 0;
virtual void* LoadModule(const Path&) = 0;
virtual void Exit(int code) = 0;
};
extern PAL* g_platform; // set once at startup to the platform implementation
Debug-build placeholder: a NullPAL that asserts on unsupported calls keeps unsupported code from silently running.
2.2 Platform Selection
- Windows:
PlatformWindows.cpp— Win32 + DirectXMath conveniences. - Linux/BSD:
PlatformPosix.cpp— pthread,open,clock_gettime(CLOCK_MONOTONIC). - Consoles: per-SDK, behind a private porting SDK; engine build ships only one active implementation.
2.3 graceful Degradation
If a feature isn't available (e.g., energy-perf mode, large pages on older Windows), the PAL returns "unsupported" and the engine falls back — no hard crash. Platform::Capabilities struct at init reports feature flags (huge pages, GPU async, RTX, max threads, etc.).
3. The Filesystem
3.1 Two-Part Path System
The Path type has:
- Engine path (virtual):
{GameData}/levels/Zone1/lvl.map— portable, artifact-independent. - Disk path (physical): resolved per platform via mount table (
{GameData} -> D:\...\Packaged\Game\Data).
Path p = Platform::ResolveVirtual("{GameData}/shaders/lighting.hlsl");
3.2 Mount Table
{EngineRoot} -> engine-source-tree
{GameData} -> <install>/GameData
{SaveFiles} -> platform writable dir (AppData / xdg-data-home / console save)
{Temp} -> per-session scratch dir
Save dir differs per platform — the PAL owns the resolution. All asset loading goes through the mount table (no raw D:\ paths in assets).
3.3 Async & Memory-Mapped Files
See virtual-memory.md and asset-pipeline.md. Crude: ReadFile, fopen. Production: async I/O + memory mapping for big read-only assets; the PAL exposes both.
4. Time & Timing
4.1 The Clock
- Windows:
QueryPerformanceCounter(QPC), divisor = frequency. - Linux:
clock_gettime(CLOCK_MONOTONIC)(never jumps;CLOCK_MONOTONIC_RAWadditionally ignores NTP rate slewing). - Console: device-specific. Use device monotonic, never wall-clock, for sim.
struct TimePoint { uint64_t ticks; };
static TimePoint Now() { return { static_cast<uint64_t>(g_qpc) }; }
4.2 Frame Rate Control
- Frame-limiting: sleep/schedule vs busy-wait (target frame time).
- Variable vs fixed delta: the PAL reports the raw
dt, and the engine's accumulator converts to fixed-step sim (seegame-loop-and-timestep.md).
5. Threading & Fibers
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- references/filesystem.md
- references/input-devices.md
- references/modules-and-tools.md
- references/os-interface.md
- references/threading.md
- references/windowing.md
FAQ
Что делает скилл platform-abstraction?
Use when the user asks about a platform abstraction layer, cross-platform engine code, windowing, engine filesystem, dynamic library loading, high-resolution timers or platform ifdefs. Produces a PAL for Windows, Linux, macOS and consoles. Not for mobile app platform APIs (use mobile-patterns).
Как установить скилл platform-abstraction?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл platform-abstraction запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
AnthropicGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
claude-api
AnthropicReference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
algorithmic-art
AnthropicCreating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
mcp-integration
AnthropicThis skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…