PixelBullet  0.0.1
A C++ game engine
Loading...
Searching...
No Matches
platform.h
1#pragma once
2
3#include "pixelbullet/core/platform_paths.h"
4
5#include <cstdint>
6#include <cstdlib>
7#include <ctime>
8#include <string>
9#include <string_view>
10
11namespace pixelbullet::platform
12{
13enum class HostPlatform : uint8_t
14{
15 Windows,
16 Linux
17};
18
19#if defined(_WIN32)
20inline constexpr HostPlatform current_platform = HostPlatform::Windows;
21#elif defined(__linux__)
22inline constexpr HostPlatform current_platform = HostPlatform::Linux;
23#else
24#error "Unsupported platform"
25#endif
26
27uint32_t process_id();
28std::tm to_local_time(std::time_t value);
29std::tm to_utc_time(std::time_t value);
30
31inline std::string read_environment_variable(const char* name)
32{
33 if (const char* value = std::getenv(name))
34 {
35 return value;
36 }
37
38 return {};
39}
40
41inline std::filesystem::path platform_path_component(const std::string_view windows_component, const std::string_view linux_component)
42{
43#if defined(_WIN32)
44 (void)linux_component;
45 return std::filesystem::path(windows_component);
46#else
47 (void)windows_component;
48 return std::filesystem::path(linux_component);
49#endif
50}
51
52} // namespace pixelbullet::platform