Polyphase Game Engine
Loading...
Searching...
No Matches
System.h
Go to the documentation of this file.
1#pragma once
2
3#include "PolyphaseAPI.h"
5
6#include <string>
7#include <vector>
8#include <stdarg.h>
9
10class Stream;
11
15
16// Files
17bool SYS_DoesFileExist(const char* path, bool isAsset);
18void SYS_AcquireFileData(const char* path, bool isAsset, int32_t maxSize, char*& outData, uint32_t& outSize);
19void SYS_ReleaseFileData(char* data);
23std::string SYS_GetAbsolutePath(const std::string& relativePath);
24void SYS_ExplorerOpenDirectory(const std::string& dirPath);
25void SYS_OpenFileWithDefaultApp(const std::string& filePath);
26void SYS_SetWorkingDirectory(const std::string& dirPath);
27bool SYS_CreateDirectory(const char* dirPath);
28void SYS_RemoveDirectory(const char* dirPath);
29void SYS_OpenDirectory(const std::string& dirPath, DirEntry& outDirEntry);
31void SYS_CopyDirectory(const char* sourceDir, const char* destDir);
32// Returns true if the destination file exists after the copy. A false return
33// means the copy failed (e.g. the destination directory is unwritable —
34// OneDrive / Controlled Folder Access). Packaging MUST honour this so it never
35// silently ships a build with missing files.
36bool SYS_CopyFile(const char* sourcePath, const char* destPath);
37bool SYS_CopyDirectoryRecursive(const std::string& sourceDir,
38 const std::string& destDir);
39// Returns true if the move succeeded. A false return means the directory
40// (or part of its subtree) never moved -- callers must not update in-memory
41// state (e.g. an asset tree) as if it had. See SYS_CopyFile above.
42bool SYS_MoveDirectory(const char* sourceDir, const char* destDir);
43void SYS_MoveFile(const char* sourcePath, const char* destPath);
45void SYS_RemoveFile(const char* path);
46bool SYS_Rename(const char* oldPath, const char* newPath);
47std::vector<std::string> SYS_OpenFileDialog();
48std::string SYS_SaveFileDialog();
50std::string SYS_GetFileName(const std::string& path);
51
52// Seekable, handle-based file reading. Unlike SYS_AcquireFileData (whole-file),
53// this opens a file once and reads/seeks it in chunks — used to stream large
54// assets (e.g. background music) from disk instead of holding them resident.
55// Returns nullptr on failure (missing file, or a platform that doesn't implement
56// it — callers must handle that and degrade gracefully). `isAsset` uses the same
57// asset-path resolution as SYS_AcquireFileData. Not backed by the embedded VFS —
58// streaming requires a real on-disk file.
59struct SysFile;
60SysFile* SYS_FileOpenRead(const char* path, bool isAsset);
61uint32_t SYS_FileRead(SysFile* file, void* dst, uint32_t bytes); // bytes actually read
62bool SYS_FileSeek(SysFile* file, uint64_t absoluteOffset); // offset from file start
63void SYS_FileClose(SysFile* file);
64
65// Pulls any files the OS has dropped on the editor window since the last call
66// and moves them into outPaths. Empty on non-editor builds (DragAcceptFiles is
67// not registered) and on platforms whose windowing layer doesn't have drop
68// support wired yet (Linux XCB, Android, consoles).
69void SYS_DrainDroppedFiles(std::vector<std::string>& outPaths);
70
71// Threading — exported so native addons can use them without relinking the engine's
72// implementation. See AsyncMediaPump in the VideoPlayer addon for a reference consumer.
73POLYPHASE_API ThreadObject* SYS_CreateThread(ThreadFuncFP func, void* arg);
74POLYPHASE_API void SYS_JoinThread(ThreadObject* thread);
75POLYPHASE_API void SYS_DestroyThread(ThreadObject* thread);
77POLYPHASE_API void SYS_LockMutex(MutexObject* mutex);
78POLYPHASE_API void SYS_UnlockMutex(MutexObject* mutex);
79POLYPHASE_API void SYS_DestroyMutex(MutexObject* mutex);
80POLYPHASE_API void SYS_Sleep(uint32_t milliseconds);
81
82// Time
84
85// Process
86void SYS_Exec(const char* cmd, std::string* output = nullptr);
87
100bool SYS_ExecFull(const char* cmd, std::string* outStdout, std::string* outStderr, int* outExitCode);
101
119void SYS_ExecDetached(const char* cmd);
120
141bool SYS_KillProcessByName(const char* processName);
142
165bool SYS_SpawnDetachedExecutable(const char* exePath, const char* args);
166
167// Memory
168void* SYS_AlignedMalloc(uint32_t size, uint32_t alignment);
169void SYS_AlignedFree(void* pointer);
170std::vector<MemoryStat> SYS_GetMemoryStats();
180
181// Save / Memcard
182bool SYS_ReadSave(const char* saveName, Stream& outStream);
183bool SYS_WriteSave(const char* saveName, Stream& stream);
184bool SYS_DoesSaveExist(const char* saveName);
185bool SYS_DeleteSave(const char* saveName);
187
188// Clipboard
189void SYS_SetClipboardText(const std::string& str);
191
192// Misc
193void SYS_Log(LogSeverity severity, const char* format, va_list arg);
194POLYPHASE_API void SYS_Assert(const char* exprString, const char* fileString, uint32_t lineNumber);
195void SYS_Alert(const char* message);
198void SYS_SetWindowTitle(const char* title);
199void SYS_SetWindowIcon(const char* iconPath);
203void SYS_SetFullscreen(bool fullscreen);
205void SYS_SetWindowRect(int32_t x, int32_t y, int32_t width, int32_t height);
206void SYS_GetWindowRect(int32_t& outX, int32_t& outY, int32_t& outWidth, int32_t& outHeight);
210
212{
213 ScopedLock(MutexObject* mutex)
214 {
215 mMutex = mutex;
217 }
218
220 {
222 }
223
224 MutexObject* mMutex = nullptr;
225};
226
227#define SCOPED_LOCK(mutex) ScopedLock scopedLock(mutex)
228
Export macros for Polyphase Engine symbols.
#define POLYPHASE_API
Definition PolyphaseAPI.h:31
ThreadFuncRet(* ThreadFuncFP)(void *)
Definition SystemTypes.h:71
LogSeverity
Definition SystemTypes.h:169
ScreenOrientation
Definition SystemTypes.h:83
float SYS_GetVRAMUsage()
POLYPHASE_API uint64_t SYS_GetTimeMicroseconds()
POLYPHASE_API void SYS_UnlockMutex(MutexObject *mutex)
std::string SYS_GetAbsolutePath(const std::string &relativePath)
void SYS_RestoreWindow()
std::string SYS_GetFileName(const std::string &path)
SysFile * SYS_FileOpenRead(const char *path, bool isAsset)
Definition SystemUtils.cpp:511
bool SYS_ExecFull(const char *cmd, std::string *outStdout, std::string *outStderr, int *outExitCode)
Execute a command with full output capture.
Definition SystemUtils.cpp:342
std::string SYS_SaveFileDialog()
void SYS_CopyDirectory(const char *sourceDir, const char *destDir)
std::vector< MemoryStat > SYS_GetMemoryStats()
void SYS_CloseDirectory(DirEntry &dirEntry)
void SYS_IterateDirectory(DirEntry &dirEntry)
void SYS_MaximizeWindow()
POLYPHASE_API ThreadObject * SYS_CreateThread(ThreadFuncFP func, void *arg)
void SYS_AcquireFileData(const char *path, bool isAsset, int32_t maxSize, char *&outData, uint32_t &outSize)
uint32_t SYS_FileRead(SysFile *file, void *dst, uint32_t bytes)
Definition SystemUtils.cpp:562
POLYPHASE_API void SYS_Assert(const char *exprString, const char *fileString, uint32_t lineNumber)
std::string SYS_GetCurrentDirectoryPath()
bool SYS_DoesFileExist(const char *path, bool isAsset)
bool SYS_SpawnDetachedExecutable(const char *exePath, const char *args)
Spawn a detached, fully-independent copy of an executable.
float SYS_GetRAM2Usage()
void SYS_ExplorerOpenDirectory(const std::string &dirPath)
std::string SYS_GetPolyphasePath()
bool SYS_DoesWindowHaveFocus()
float SYS_GetRAM1Usage()
float SYS_GetTotalVRAM()
bool SYS_CreateDirectory(const char *dirPath)
void SYS_Exec(const char *cmd, std::string *output=nullptr)
float SYS_GetTotalRAM()
void SYS_SetWindowRect(int32_t x, int32_t y, int32_t width, int32_t height)
float SYS_GetCPUUsage()
bool SYS_DeleteSave(const char *saveName)
void * SYS_AlignedMalloc(uint32_t size, uint32_t alignment)
void SYS_Update()
void SYS_Alert(const char *message)
float SYS_GetRAMUsage()
void SYS_SetWindowIcon(const char *iconPath)
void SYS_SetFullscreen(bool fullscreen)
bool SYS_WriteSave(const char *saveName, Stream &stream)
void SYS_UpdateConsole()
void SYS_OpenDirectory(const std::string &dirPath, DirEntry &outDirEntry)
void SYS_AlignedFree(void *pointer)
void SYS_RemoveDirectory(const char *dirPath)
std::vector< std::string > SYS_OpenFileDialog()
POLYPHASE_API void SYS_LockMutex(MutexObject *mutex)
void SYS_SetClipboardText(const std::string &str)
void SYS_FileClose(SysFile *file)
Definition SystemUtils.cpp:588
bool SYS_MoveDirectory(const char *sourceDir, const char *destDir)
void SYS_SetScreenOrientation(ScreenOrientation orientation)
bool SYS_CopyFile(const char *sourcePath, const char *destPath)
void SYS_ExecDetached(const char *cmd)
Fire-and-forget process spawn that NEVER blocks the caller.
std::string SYS_GetClipboardText()
POLYPHASE_API void SYS_DestroyMutex(MutexObject *mutex)
void SYS_Shutdown()
ScreenOrientation SYS_GetScreenOrientation()
bool SYS_Rename(const char *oldPath, const char *newPath)
void SYS_DrainDroppedFiles(std::vector< std::string > &outPaths)
float SYS_GetTotalRAM2()
POLYPHASE_API void SYS_Sleep(uint32_t milliseconds)
void SYS_Initialize()
std::string SYS_SelectFolderDialog()
bool SYS_IsWindowMaximized()
void SYS_GetWindowRect(int32_t &outX, int32_t &outY, int32_t &outWidth, int32_t &outHeight)
void SYS_OpenFileWithDefaultApp(const std::string &filePath)
POLYPHASE_API MutexObject * SYS_CreateMutex()
void SYS_MoveFile(const char *sourcePath, const char *destPath)
bool SYS_IsFullscreen()
POLYPHASE_API void SYS_JoinThread(ThreadObject *thread)
bool SYS_CopyDirectoryRecursive(const std::string &sourceDir, const std::string &destDir)
void SYS_SetWorkingDirectory(const std::string &dirPath)
void SYS_SetWindowTitle(const char *title)
bool SYS_ReadSave(const char *saveName, Stream &outStream)
bool SYS_KillProcessByName(const char *processName)
Terminate every running process matching an image name.
void SYS_UnmountMemoryCard()
bool SYS_FileSeek(SysFile *file, uint64_t absoluteOffset)
Definition SystemUtils.cpp:577
float SYS_GetTotalRAM1()
void SYS_ReleaseFileData(char *data)
int32_t SYS_GetPlatformTier()
std::string SYS_GetExecutablePath()
void SYS_RemoveFile(const char *path)
void SYS_Log(LogSeverity severity, const char *format, va_list arg)
POLYPHASE_API void SYS_DestroyThread(ThreadObject *thread)
bool SYS_DoesSaveExist(const char *saveName)
Definition Stream.h:21
Definition SystemTypes.h:92
Definition System.h:212
ScopedLock(MutexObject *mutex)
Definition System.h:213
MutexObject * mMutex
Definition System.h:224
~ScopedLock()
Definition System.h:219
Definition SystemUtils.cpp:503