| 1 |
{%MainUnit castleutils.pas} |
| 2 |
{ |
| 3 |
Copyright 2020-2020 Michalis Kamburelis. |
| 4 |
|
| 5 |
This file is part of "Castle Game Engine". |
| 6 |
|
| 7 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 8 |
included in this distribution, for details about the copyright. |
| 9 |
|
| 10 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 |
|
| 14 |
---------------------------------------------------------------------------- |
| 15 |
} |
| 16 |
|
| 17 |
{ Platform (TCastlePlatform) definition and helpers. } |
| 18 |
|
| 19 |
{$ifdef read_interface} |
| 20 |
|
| 21 |
type |
| 22 |
{ Possible platforms supported by CGE. See @link(Platform). } |
| 23 |
TCastlePlatform = ( |
| 24 |
cpDesktop, |
| 25 |
cpAndroid, |
| 26 |
cpIOS, |
| 27 |
cpNintendoSwitch |
| 28 |
); |
| 29 |
TCastlePlatforms = set of TCastlePlatform; |
| 30 |
|
| 31 |
const |
| 32 |
AllPlatforms = [Low(TCastlePlatform)..High(TCastlePlatform)]; |
| 33 |
|
| 34 |
{ Current platform of the compiled application. |
| 35 |
|
| 36 |
Note that you can also use compilations symbols: CASTLE_IOS, CASTLE_NINTENDO_SWITCH. |
| 37 |
And of course all the symbols defined by Pascal compilers: (for OS:) |
| 38 |
ANDROID, MSWINDOWS, UNIX, LINUX etc., (for CPU:) CPUX86_64, CPUI386, CPUAARCH64 etc. } |
| 39 |
function Platform: TCastlePlatform; |
| 40 |
|
| 41 |
function PlatformToStr(const T: TCastlePlatform): String; |
| 42 |
|
| 43 |
{ Convert string to a platform name. |
| 44 |
Case (the difference between upper and lower letters) is ignored. |
| 45 |
Raises Exception on invalid platform name. } |
| 46 |
function StrToPlatform(const S: String): TCastlePlatform; |
| 47 |
|
| 48 |
{$endif read_interface} |
| 49 |
|
| 50 |
{$ifdef read_implementation} |
| 51 |
|
| 52 |
function Platform: TCastlePlatform; |
| 53 |
begin |
| 54 |
{$if defined(CASTLE_NINTENDO_SWITCH)} |
| 55 |
{ Note that ANDROID is also defined for Nintendo Switch for now |
| 56 |
(due to a hacky way we use FPC for Nintendo Switch). |
| 57 |
So we check for CASTLE_NINTENDO_SWITCH first. } |
| 58 |
Exit(cpNintendoSwitch); |
| 59 |
{$elseif defined(ANDROID)} |
| 60 |
Exit(cpAndroid); |
| 61 |
{$elseif defined(CASTLE_IOS)} |
| 62 |
Exit(cpIOS); |
| 63 |
{$else} |
| 64 |
Exit(cpDesktop); |
| 65 |
{$endif} |
| 66 |
end; |
| 67 |
|
| 68 |
function PlatformToStr(const T: TCastlePlatform): String; |
| 69 |
const |
| 70 |
Names: array [TCastlePlatform] of String = ( |
| 71 |
'Desktop', |
| 72 |
'Android', |
| 73 |
'iOS', |
| 74 |
'Nintendo Switch' |
| 75 |
); |
| 76 |
begin |
| 77 |
Result := Names[T]; |
| 78 |
end; |
| 79 |
|
| 80 |
function StrToPlatform(const S: String): TCastlePlatform; |
| 81 |
begin |
| 82 |
for Result := Low(TCastlePlatform) to High(TCastlePlatform) do |
| 83 |
if AnsiSameText(PlatformToStr(Result), S) then |
| 84 |
Exit; |
| 85 |
raise Exception.CreateFmt('Invalid platform name "%s"', [S]); |
| 86 |
end; |
| 87 |
|
| 88 |
{$endif read_implementation} |